import { Stack } from 'crumbtrail-core';
type InstallVariantKind = "js" | "otlp" | "infra";
/** JS/TS stacks that install crumbtrail-core directly. */
declare const JS_STACKS: readonly Stack[];
/** JS backends that additionally wire the crumbtrail-node middleware. */
declare const BACKEND_JS_STACKS: readonly Stack[];
/** Non-JS backends wired via their existing OpenTelemetry exporter. */
declare const OTLP_STACKS: readonly Stack[];
/** Evidence sources that are not yet a first-class ingest target. */
declare const INFRA_STACKS: readonly Stack[];
interface StackInstall {
stack: Stack;
kind: InstallVariantKind;
/** True for express/hono/node — they also need the backend middleware note. */
backendJs: boolean;
/** True for infra evidence sources — surfaced as "coming soon". */
comingSoon: boolean;
}
/** Classify a single stack into its install variant. Total over all 18 stacks. */
declare function getInstallVariant(stack: Stack): StackInstall;
/** The classification table for every supported stack (handy for tests/UI). */
declare function allStackInstalls(): StackInstall[];
interface EndpointKey {
/** Live ingest endpoint (the cloud origin / dashboard origin). */
endpoint: string;
/**
* Live ingest key. Used only by the OTLP path (an env-var header, not source)
* and left available for callers. The JS agent prompt is hands-off — it reads
* the key from an env var and never bakes this literal into source.
*/
apiKey: string;
}
interface KeyEnvRef {
/** The env var the user sets to their ingest key. */
envVar: string;
/** The code expression the SDK init reads it from. */
expr: string;
}
/**
* The env-var reference the SDK reads its ingest key from, per stack. Client
* bundlers only expose a var under a framework-specific PUBLIC prefix (Next →
* NEXT_PUBLIC_, Vite-based React/Vue/Svelte/Vite → VITE_); backends read a plain
* server var. This is the single source of truth for the hands-off key posture —
* the key lives in the user's env, never inlined into committed source.
*/
declare function keyEnvRef(stack: Stack): KeyEnvRef;
/**
* The crumbtrail-node backend note shown under for the backend-JS
* stacks. Uses ONLY the real crumbtrail-node exports — no invented names:
* • Express is the only stack with framework middleware
* (createCrumbtrailExpressMiddleware / createCrumbtrailExpressErrorMiddleware).
* • Hono / Node ship no framework middleware, so they open a headless session
* with autoCapture and record server-side errors against it.
*/
declare function buildBackendJsNote(stack: Stack): string;
/**
* Single source of truth for what Crumbtrail's OTLP/HTTP receiver accepts.
* `buildOtlpSnippets` (the wizard guidance) is asserted against these facts, so
* compression, endpoint path suffix and auth header names cannot drift apart.
*
* Nothing here is invented: the paths, protocols, auth headers, and session
* attribute all match the live ingest routes the hosted Crumbtrail cloud
* serves. The collector recipes that used to be cross-checked here left with
* `crumbtrail-node`'s server.
*/
interface OtlpCapabilityFacts {
/** Signal paths the receiver serves; exporters append these to the endpoint. */
readonly paths: readonly ["/v1/traces", "/v1/logs"];
/** OTLP/HTTP wire protocols accepted (both, as of the protobuf+gzip parity CP). */
readonly protocols: readonly ["http/protobuf", "http/json"];
/** Auth header names honored equivalently by the receiver. */
readonly authHeaders: readonly ["X-Crumbtrail-Auth", "Authorization: Bearer"];
/** Content-Encoding posture: "none" recommended for collectors; gzip accepted. */
readonly compression: {
readonly recommended: "none";
readonly accepted: readonly ["none", "gzip"];
};
/** Resource/span attribute that files spans/logs into a Crumbtrail session. */
readonly sessionAttribute: "crumbtrail.session.id";
}
declare const OTLP_CAPABILITY_FACTS: OtlpCapabilityFacts;
/**
* The `X-Crumbtrail-Auth=` value for `OTEL_EXPORTER_OTLP_HEADERS`.
* OTEL parses that env var as comma-separated `name=value` pairs; the value is
* used verbatim, so a plain key needs no escaping here.
*/
declare function otlpAuthHeaderValue(apiKey: string): string;
/**
* The Bearer form for `OTEL_EXPORTER_OTLP_HEADERS`. The space between `Bearer`
* and the token MUST be percent-encoded (`%20`) — an unescaped space breaks
* OTEL's `name=value` header parsing and silently drops auth. This is the fix
* for the previously wrong `Authorization=Bearer ` guidance.
*/
declare function otlpBearerHeaderValue(apiKey: string): string;
interface OtlpSnippets {
/** OTLP endpoint + protocol + compression env vars pointed at the cloud origin. */
env: string;
/** Auth header carried by the exporter (X-Crumbtrail-Auth or Bearer). */
authHeader: string;
/** Optional resource attribute that joins spans/logs to a known session. */
sessionAttr: string;
/** The app this telemetry belongs to. One ingest key covers a whole project,
* so under a project key the key names no app and this is the only thing
* that can. The receiver reads the standard `service.name` resource
* attribute, which every OTLP SDK sets from this variable. */
serviceName: string;
/** Human note about the appended /v1/traces + /v1/logs paths. */
note: string;
}
/**
* Build the OTLP setup snippets for a non-JS backend. Uses ONLY the real,
* documented names — no invented env vars or headers, and everything is derived
* from OTLP_CAPABILITY_FACTS so it can never drift from the collector recipes:
* • OTEL_EXPORTER_OTLP_ENDPOINT → the cloud origin (exporter appends paths)
* • OTEL_EXPORTER_OTLP_PROTOCOL → http/protobuf or http/json
* • OTEL_EXPORTER_OTLP_HEADERS → X-Crumbtrail-Auth= (or Bearer%20)
* • OTEL_EXPORTER_OTLP_COMPRESSION→ none (recommended) — gzip is accepted too
* • OTEL_RESOURCE_ATTRIBUTES → optionally crumbtrail.session.id=
* • OTEL_SERVICE_NAME → the app this telemetry belongs to
* Verified against docs/integrations/* and the ingest routes.
*/
declare function buildOtlpSnippets({ endpoint, apiKey, serviceName, }: EndpointKey & {
serviceName?: string | null;
}): OtlpSnippets;
/**
* Build the "Install via AI" agent prompt — a copyable block that instructs a
* coding agent to run the correct setup for the stack, initialize with
* PRESET_PASSIVE (JS), wire backend middleware when applicable, change nothing
* else, and verify the build. Hands-off with the key: the JS prompt tells the
* agent to read the key from a framework-correct env var (which the user sets)
* and NEVER to hard-code it, so a live credential can't land in committed source.
* The prompt never carries the key value. It tells the reader to set the
* framework/server environment variable and has the coding agent read it there.
*
* `keyEnv` overrides how the JS prompt names the key var. `keyEnvRef(stack)` only
* knows the coarse stack (nextjs/react/vue/svelte/vite/server), so callers with a
* finer notion of the framework — e.g. the CLI, which distinguishes Astro's
* `PUBLIC_` prefix and Expo/React Native's `EXPO_PUBLIC_` (`process.env`, not
* `import.meta.env`) — pass the exact ref so the prompt matches the injected code.
*/
interface AgentPromptOptions {
/**
* Override the env var / expression pair the prompt names. The CLI passes the
* recipe's exact ref so the prompt names the same variable the injected
* snippet reads (Astro's PUBLIC_, Expo's EXPO_PUBLIC_), which the coarse
* Stack alone cannot distinguish.
*/
keyEnv?: KeyEnvRef;
/**
* Which app in the project this install is, as it was provisioned.
*
* One ingest key covers a whole project, so the key cannot say which app a
* session came from; the init call does. Every path that writes the init
* block itself already passes this (see `serviceLines` in inject/snippets.ts,
* and the dashboard's own copyable snippet). The agent prompt was the one
* that did not, so an install done by handing this text to a coding agent
* produced sessions filed against the project and no app, which is a state
* the product renders as unattributed and the wizard's confirm step, which
* matches arriving sessions by service, can never see.
*
* Absent means the prompt uses `` and tells the reader to
* replace it with a stable name before running the app.
*/
serviceName?: string | null;
/**
* Backend origins this app calls, as the caller already resolved them.
*
* The prompt used to hardcode `networkCorrelationAllowedOrigins: []` and then
* ask the agent to go and find the origins — while the CLI, in the same run,
* had already read them out of the repo and put them in every snippet it
* writes itself. The hand-off path was the one that threw that work away, so
* an install done by pasting this prompt produced a frontend and a backend
* whose evidence never joined.
*
* Empty or absent keeps the empty list plus the instruction to fill it in:
* an origin is never guessed here, because listing one the app does not call
* sends trace context to a third party.
*/
backendOrigins?: readonly string[] | null;
}
declare function buildAgentPrompt(stack: Stack, keys: EndpointKey, opts?: AgentPromptOptions): string;
export { type AgentPromptOptions, BACKEND_JS_STACKS, type EndpointKey, INFRA_STACKS, type InstallVariantKind, JS_STACKS, type KeyEnvRef, OTLP_CAPABILITY_FACTS, OTLP_STACKS, type OtlpCapabilityFacts, type OtlpSnippets, type StackInstall, allStackInstalls, buildAgentPrompt, buildBackendJsNote, buildOtlpSnippets, getInstallVariant, keyEnvRef, otlpAuthHeaderValue, otlpBearerHeaderValue };