import { a as TokenUsage, i as ModelPricingTable } from "./cost-CiXR1eKW.cjs"; import { h as GenAiProviderName } from "./semconv-BdR5pWDh.cjs"; import { J as GenAiMetadata, c as AgentOutputFormat, o as AgentInputProvenance, s as AgentMemoryOperation } from "./agent-security-EHGwg_6t.cjs"; import { a as GenAiResponseInput, i as GenAiRequestInput, l as GenAiWorkflowInput, s as GenAiToolInput, t as GenAiAgentInput } from "./attributes-DDx3HQe8.cjs"; import { a as GenAiMessage, o as GenAiMessagePart } from "./events-BVFNSOAk.cjs"; import { Attributes, Context, Link, Span, TimeInput, Tracer } from "@opentelemetry/api"; //#region src/observer/types.d.ts /** Tool identity (name/type/description/call id) without the content fields. */ type GenAiToolIdentity = Omit; /** Fields shared by every `*.start` event. */ interface SpanStart { /** Correlates this start with its `*.end` and names it as a parent. */ id: string; /** * Parent entity id. When absent — or when the parent span is no longer open — * the observer falls back to {@link GenAiObserverOptions.resolveParentContext} * and otherwise starts a root span. */ parentId?: string; /** Span start time; defaults to the current clock. */ startTime?: TimeInput; /** Links to other spans, e.g. the interrupted run this one resumes. */ links?: Link[]; } /** Fields shared by every `*.end` event. */ interface SpanEnd { /** The `id` of the matching `*.start`. */ id: string; /** Span end time; defaults to the current clock. */ endTime?: TimeInput; /** Error that terminated the operation; sets ERROR status and records it. */ error?: unknown; } /** Start of a workflow (aggregate parent — never carries token usage). */ interface WorkflowStartEvent extends SpanStart { type: 'workflow.start'; workflow: GenAiWorkflowInput; } interface WorkflowEndEvent extends SpanEnd { type: 'workflow.end'; } /** Start of an agent invocation (aggregate parent — never carries token usage). */ interface AgentStartEvent extends SpanStart { type: 'agent.start'; agent: GenAiAgentInput; provider?: GenAiProviderName; /** * Opt-in content — the operation's own input, written only when * `exportContent` returns it. * * A root span with no content is what makes a trace list read as empty: the * list shows roots, so the prompt has to be on the root and not only on the * `chat` child that consumed it. */ inputMessages?: GenAiMessage[] | string; /** Opt-in content — written only when `exportContent` returns it. */ systemInstructions?: GenAiMessagePart[] | string; /** * A remote agent call is a CLIENT span and keeps `gen_ai.agent.id`; an * in-process agent is INTERNAL and drops it per spec breaking change #242. */ remote?: boolean; } interface AgentEndEvent extends SpanEnd { type: 'agent.end'; /** * Opt-in content — the operation's final output, written only when * `exportContent` returns it. See {@link AgentStartEvent.inputMessages}. */ outputMessages?: GenAiMessage[] | string; } /** Start of a single model inference call (a leaf — carries token usage). */ interface ChatStartEvent extends SpanStart { type: 'chat.start'; /** Request-side attributes; `operation` defaults to `chat`. */ request: GenAiRequestInput; /** Opt-in content — written only when `exportContent` returns it. */ inputMessages?: GenAiMessage[] | string; /** Opt-in content — written only when `exportContent` returns it. */ systemInstructions?: GenAiMessagePart[] | string; } interface ChatEndEvent extends SpanEnd { type: 'chat.end'; response?: GenAiResponseInput; /** Leaf token usage → `gen_ai.usage.*` (and estimated `gen_ai.usage.cost.usd`). */ usage?: TokenUsage; /** Model id for cost estimation; defaults to `response.model`. */ costModel?: string; /** Opt-in content — written only when `exportContent` returns it. */ outputMessages?: GenAiMessage[] | string; /** * Streaming-performance extensions for this model call. `timeToFirstChunk` * belongs on {@link ChatEndEvent.response} (it is the spec attribute); the * fields here are the autotel extensions recorded on finish. */ streaming?: ChatStreamTiming; } /** * Streaming-performance fields written on a `chat.end` span (all seconds / * tokens-per-second). All are autotel extensions — see `streaming.ts`. */ interface ChatStreamTiming { /** Total response time, seconds → `gen_ai.response.time_to_finish`. */ timeToFinish?: number; /** Throughput → `gen_ai.response.output_tokens_per_second`. */ outputTokensPerSecond?: number; /** Mean inter-chunk gap, seconds → `gen_ai.response.time_per_output_chunk`. */ timePerOutputChunk?: number; } /** Start of a tool execution. */ interface ToolStartEvent extends SpanStart { type: 'tool.start'; tool: GenAiToolIdentity; /** Opt-in content — written only when `exportContent` returns it. */ callArguments?: unknown; } interface ToolEndEvent extends SpanEnd { type: 'tool.end'; /** Opt-in content — written only when `exportContent` returns it. */ callResult?: unknown; } /** Record a bounded plan-step snapshot on the parent span (no chain-of-thought). */ interface PlanStepEvent { type: 'plan.step'; parentId: string; stepIndex: number; toolIntents?: string[]; policyIds?: string[]; summary?: string; } /** Stamp input provenance on the parent span. */ interface InputProvenanceEvent { type: 'input.provenance'; parentId: string; provenance: AgentInputProvenance; } /** Record agent memory access without logging raw content. */ interface MemoryAccessEvent { type: 'memory.access'; parentId: string; operation: AgentMemoryOperation; isolationKey: string; contentHash?: string; } /** Characterize rendered output for XSS/exfil triage (no raw output). */ interface RenderOutputEvent { type: 'render.output'; parentId: string; format?: AgentOutputFormat; containsUrl?: boolean; urlCount?: number; } /** Discriminated union of every event the observer understands. */ type GenAiObserverEvent = WorkflowStartEvent | WorkflowEndEvent | AgentStartEvent | AgentEndEvent | ChatStartEvent | ChatEndEvent | ToolStartEvent | ToolEndEvent | PlanStepEvent | InputProvenanceEvent | MemoryAccessEvent | RenderOutputEvent; /** The subscriber returned by {@link createGenAiObserver}. */ type GenAiObserver = (event: GenAiObserverEvent) => void; interface GenAiObserverOptions { /** * Tracer to emit spans on. Defaults to the global `autotel-genai/observer` * tracer. Pass an application-owned tracer to share one configuration. */ tracer?: Tracer; /** * Privacy gate for sensitive content. Receives a shallow copy of each * content-bearing event; return it (optionally redacted) to export its * content, or `undefined` to omit content from that event. When this option * is absent, **no** content (messages, tool arguments/results) is ever * written to spans — only identifiers, model/provider, usage, and durations. */ exportContent?: (event: GenAiObserverEvent) => GenAiObserverEvent | undefined; /** * Resolve an OpenTelemetry parent context for an event that has no tracked * parent. Return a context to attach the span to one you choose (e.g. the * incoming request), or `undefined` to keep it a detached root. * * Without this option the span attaches to whatever context is already * active, which is what puts a model call inside the span the caller opened * around it. Provide it only when the ambient context is the wrong parent, * such as an event stream delivered from a queue or a background worker. */ resolveParentContext?: (event: GenAiObserverEvent) => Context | undefined; /** * Called with the live {@link Span} immediately after each `*.start` event * opens it, keyed by the event `id`. Lets a caller enter the span's context * later — e.g. to make provider HTTP calls or a tool's nested `generateText` * children of the span — without the observer keeping it active on the * ambient context. */ onSpanStart?: (id: string, span: Span) => void; /** * `gen_ai.usage.cost.usd` pricing for this observer, merged over the * registered prices. autotel ships no prices, so every model you want a * cost for needs one here or in `registerModelPricing`. Without a matching entry the cost attribute is absent and * `gen_ai.usage.cost.unpriced_model` names the model instead. * * For prices that apply process-wide, prefer `registerModelPricing` from * `autotel-genai/cost` — one call, every cost site. */ pricing?: ModelPricingTable; } //#endregion //#region src/observer/observer.d.ts declare function createGenAiObserver(options?: GenAiObserverOptions): GenAiObserver; //#endregion //#region src/observer/span-registry.d.ts declare class SpanRegistry { private readonly entries; /** Record an open span and the parent it was started under. */ add(id: string, span: Span, parentId: string | undefined): void; /** The open span for `id`, if any (used to parent a starting child). */ spanFor(id: string): Span | undefined; /** Remove and return the open span for `id`. */ take(id: string): Span | undefined; /** * Close every still-open descendant of `parentId` as ERROR — their terminal * event never arrived because the parent ended first. Depth-first, so the * deepest leaks close before their own parents. */ reapDescendants(parentId: string, message: string, endTime?: TimeInput): void; /** Count of spans still open — for tests and leak assertions. */ get openCount(): number; } //#endregion //#region src/observer/ai-sdk.d.ts /** AI SDK usage object — canonical (v5) or legacy (v4) field names. */ interface AiSdkUsage { inputTokens?: number; outputTokens?: number; promptTokens?: number; completionTokens?: number; reasoningTokens?: number; cachedInputTokens?: number; } interface AiSdkToolCall { toolCallId?: string; toolName?: string; input?: unknown; args?: unknown; } interface AiSdkToolResult { toolCallId?: string; toolName?: string; output?: unknown; result?: unknown; } /** One AI SDK step (also the shape of a single-call result). */ interface AiSdkStep { usage?: AiSdkUsage; finishReason?: string; response?: { id?: string; modelId?: string; timestamp?: Date | number; }; toolCalls?: AiSdkToolCall[]; toolResults?: AiSdkToolResult[]; } /** An AI SDK `generateText`/`streamText` result. */ interface AiSdkResult extends AiSdkStep { steps?: AiSdkStep[]; } interface ObserveAiSdkOptions { /** Base span id; per-step and per-tool ids derive from it. */ id: string; parentId?: string; /** AI SDK provider id (e.g. `openai`, `amazon-bedrock`); normalized for you. */ provider?: string; /** Request model — used for the span name and as the cost model. */ model?: string; } declare function observeAiSdkResult(observe: GenAiObserver, result: AiSdkResult, options: ObserveAiSdkOptions): void; //#endregion //#region src/observer/ai-sdk-messages.d.ts interface ModelMessageView { role?: string | undefined; content?: string | readonly ContentPartView[] | undefined; } interface ContentPartView { type?: string | undefined; /** text / reasoning */ text?: string | undefined; /** tool-call */ toolCallId?: string | undefined; toolName?: string | undefined; input?: unknown | undefined; /** tool-result */ output?: unknown | undefined; /** image / file */ mediaType?: string | undefined; /** image / file raw bytes — deliberately never inlined onto spans */ data?: unknown | undefined; } /** * The AI SDK's `Instructions`: a string, one system message, or a list of them. * * System content travels here, not in `messages` - `allowSystemInMessages` is * off by default, so a prompt assembled the normal way carries no system role * at all. */ type InstructionsView = string | ModelMessageView | readonly ModelMessageView[] | undefined; /** Result of converting an AI SDK prompt: messages plus split-out system parts. */ interface ConvertedPrompt { messages: GenAiMessage[]; systemInstructions?: GenAiMessagePart[]; } /** * Convert an AI SDK prompt to GenAI input messages. * * System content is recorded separately per the conventions, and reaches us two * ways: as the event's own `instructions` (the normal case), and - only when * the caller set `allowSystemInMessages` - as `system` entries in `messages`. * Both are collected, instructions first, which is the order the SDK assembles * the prompt in. */ declare function promptToGenAiMessages(messages?: readonly ModelMessageView[], instructions?: InstructionsView): ConvertedPrompt; /** * Convert the `ContentPart[]` of a model response into a single GenAI output * message (always `assistant`), optionally tagged with a `finish_reason`. */ declare function contentToGenAiMessage(content?: readonly ContentPartView[], finishReason?: string): GenAiMessage | undefined; //#endregion //#region src/observer/ai-sdk-fields.d.ts /** Every AI SDK token-usage field name we understand (v4 + v5, flat + nested). */ interface AiSdkUsageFields { inputTokens?: number | undefined; outputTokens?: number | undefined; /** v4 aliases. */ promptTokens?: number | undefined; completionTokens?: number | undefined; /** Embedding usage. */ tokens?: number | undefined; /** Flat v5 detail fields. */ reasoningTokens?: number | undefined; cachedInputTokens?: number | undefined; /** Nested v5 detail fields. */ inputTokenDetails?: { cacheReadTokens?: number | undefined; cacheWriteTokens?: number | undefined; } | undefined; outputTokenDetails?: { reasoningTokens?: number | undefined; } | undefined; } /** Map any AI SDK usage fields to {@link TokenUsage}; `undefined` if all empty. */ declare function toTokenUsage(usage: AiSdkUsageFields | undefined): TokenUsage | undefined; /** Normalize an optional AI SDK provider id to a canonical `gen_ai` provider. */ declare function normalizeProvider(provider: string | undefined): GenAiProviderName | undefined; /** Request-side fields shared by the lifecycle and channel model-call events. */ interface AiSdkRequestFields { provider?: string; modelId?: string; temperature?: number; maxOutputTokens?: number; topP?: number; topK?: number; frequencyPenalty?: number; presencePenalty?: number; stopSequences?: string[]; seed?: number; } /** Build the `chat` request attributes from a model-call start event. */ declare function toChatRequest(event: AiSdkRequestFields): GenAiRequestInput; //#endregion //#region src/observer/ai-sdk-telemetry.d.ts interface OperationStartEvent { callId: string; /** e.g. `'ai.generateText'`, `'ai.streamText'`, `'ai.embed'`. */ operationId?: string | undefined; provider?: string | undefined; modelId?: string | undefined; /** From telemetry settings — used as the agent name. */ functionId?: string | undefined; /** * Call-level context already filtered by the SDK. Only `userId` and * `sessionId` are recorded (`user.id`, `gen_ai.conversation.id`). */ runtimeContext?: Record | undefined; /** The operation's own prompt — stamped on the `invoke_agent` root. */ messages?: readonly ModelMessageView[] | undefined; /** * System content, which is where it lives: `allowSystemInMessages` is off by * default, so `messages` carries no system role and this is the only place a * normal call states its instructions. */ instructions?: InstructionsView; /** Per-call opt-out; either side being `false` suppresses that side. */ recordInputs?: boolean | undefined; } interface LanguageModelCallStartEventView { callId: string; provider?: string | undefined; modelId?: string | undefined; temperature?: number | undefined; maxOutputTokens?: number | undefined; topP?: number | undefined; topK?: number | undefined; frequencyPenalty?: number | undefined; presencePenalty?: number | undefined; stopSequences?: string[] | undefined; seed?: number | undefined; /** Standardized prompt messages (when content capture is on). */ messages?: readonly ModelMessageView[] | undefined; /** The system content of the standardized prompt; see the note above. */ instructions?: InstructionsView; /** Whether the SDK call permits recording inputs (default true). */ recordInputs?: boolean | undefined; } interface LanguageModelCallEndEventView { callId: string; provider?: string | undefined; modelId?: string | undefined; responseId?: string | undefined; finishReason?: string | undefined; usage?: AiSdkUsageFields | undefined; /** Output content parts (when content capture is on). */ content?: readonly ContentPartView[] | undefined; /** Whether the SDK call permits recording outputs (default true). */ recordOutputs?: boolean | undefined; performance?: { responseTimeMs?: number | undefined; effectiveOutputTokensPerSecond?: number | undefined; timeToFirstOutputMs?: number | undefined; } | undefined; } interface ToolCallView { toolCallId?: string | undefined; toolName?: string | undefined; input?: unknown | undefined; } interface ToolExecutionStartEventView { callId: string; toolCall: ToolCallView; recordInputs?: boolean | undefined; } interface ToolOutputView { type?: string | undefined; output?: unknown | undefined; error?: unknown | undefined; } interface ToolExecutionEndEventView { callId: string; toolCall: ToolCallView; toolOutput: ToolOutputView; recordOutputs?: boolean | undefined; } interface ObjectStepStartEventView { callId: string; provider?: string | undefined; modelId?: string | undefined; } interface ObjectStepEndEventView { callId: string; finishReason?: string | undefined; response?: { id?: string | undefined; modelId?: string | undefined; } | undefined; usage?: AiSdkUsageFields | undefined; objectText?: string | undefined; /** Whether the SDK call permits recording outputs (default true). */ recordOutputs?: boolean | undefined; msToFirstChunk?: number | undefined; } interface OperationEndEventView { callId: string; /** * The content of the operation's *first* step. On a multi-step tool loop * that is the tool-call preamble, not the answer — prefer * {@link OperationEndEventView.finalStep}. */ content?: readonly ContentPartView[] | undefined; /** The last step of the loop: the content that answers the prompt. */ finalStep?: { content?: readonly ContentPartView[] | undefined; finishReason?: string | undefined; } | undefined; finishReason?: string | undefined; /** Per-call opt-out; either side being `false` suppresses that side. */ recordOutputs?: boolean | undefined; } interface AbortEventView { callId: string; reason?: unknown | undefined; } interface EmbeddingModelCallStartEventView { callId: string; embedCallId?: string | undefined; provider?: string | undefined; modelId?: string | undefined; } interface EmbeddingModelCallEndEventView { callId: string; embedCallId?: string | undefined; provider?: string | undefined; modelId?: string | undefined; usage?: { tokens?: number | undefined; } | undefined; } /** A JSON tree: how the AI SDK types a provider's `providerMetadata`. */ type JsonValue = string | number | boolean | null | readonly JsonValue[] | { readonly [key: string]: JsonValue; }; /** * What a provider returned beside the standardised response: the finish * reason in the provider's own words and its `providerMetadata`, neither of * which reach the lifecycle events. Handed to * {@link AutotelTelemetryOptions.providerAttributes}. */ interface ProviderResponseView { /** Normalised `gen_ai.provider.name`, e.g. `aws.bedrock`. */ provider?: string; modelId?: string; /** The provider's finish reason before the AI SDK unified it. */ rawFinishReason?: string; providerMetadata?: { readonly [provider: string]: JsonValue; }; } /** * The subset of the AI SDK `Telemetry` interface this integration implements. * The returned object is assignable to the SDK's `Telemetry` type. */ interface AutotelTelemetryIntegration { onStart(event: OperationStartEvent): void; onLanguageModelCallStart(event: LanguageModelCallStartEventView): void; onLanguageModelCallEnd(event: LanguageModelCallEndEventView): void; onToolExecutionStart(event: ToolExecutionStartEventView): void; onToolExecutionEnd(event: ToolExecutionEndEventView): void; onObjectStepStart(event: ObjectStepStartEventView): void; onObjectStepEnd(event: ObjectStepEndEventView): void; onEmbedStart(event: EmbeddingModelCallStartEventView): void; onEmbedEnd(event: EmbeddingModelCallEndEventView): void; onEnd(event: OperationEndEventView): void; onAbort(event: AbortEventView): void; onError(event: unknown): void; executeLanguageModelCall(options: { callId: string; execute: () => PromiseLike; }): PromiseLike; executeTool(options: { callId: string; toolCallId: string; execute: () => PromiseLike; }): PromiseLike; } interface AutotelTelemetryOptions { /** * Tracer to emit spans on. Defaults to the global `autotel-genai/observer` * tracer. Pass an application-owned tracer to share one configuration. */ tracer?: Tracer; /** * Privacy gate applied to all captured content (prompts, responses, tool * arguments/results) before it is written to a span. Receives each * content-bearing observer event; return it (optionally redacted) to keep its * content, or `undefined` to drop that event's content. Only consulted when * {@link AutotelTelemetryOptions.captureContent} is enabled. */ exportContent?: (event: GenAiObserverEvent) => GenAiObserverEvent | undefined; /** * Capture prompt/response message content (`gen_ai.input.messages`, * `gen_ai.output.messages`, `gen_ai.system_instructions`) and tool * arguments/results. **Off by default** for privacy. When `true`, content is * still filtered through {@link AutotelTelemetryOptions.exportContent} if you * provide one (redact there); with no `exportContent`, all approved content is * written. The AI SDK's per-call `recordInputs` / `recordOutputs` are still * honored — either being `false` suppresses that side. */ captureContent?: boolean; /** * Resolve an OpenTelemetry parent context for an operation that has no * tracked parent — e.g. attach the `invoke_agent` root to the incoming * request span. Return `undefined` to keep it a root. */ resolveParentContext?: (event: GenAiObserverEvent) => Context | undefined; /** * `gen_ai.usage.cost.usd` pricing for this integration, merged over the * registered prices. For process-wide prices prefer `registerModelPricing` from * `autotel-genai/cost`. See {@link GenAiObserverOptions.pricing}. */ pricing?: ModelPricingTable; /** * Provider-specific attributes for a `chat` span, from what the provider * returned beside the standard response (its raw finish reason and * `providerMetadata`). `autotel-bedrock` supplies one for Bedrock's stop * reason and guardrail trace. Return `undefined` to add nothing. */ providerAttributes?: (response: ProviderResponseView) => Attributes | undefined; } /** * Create an AI SDK telemetry integration that streams canonical `gen_ai.*` * spans (with cost + streaming timing) for every AI SDK operation. * * @example * ```ts * import { registerTelemetry } from 'ai'; * import { autotelTelemetry } from 'autotel-genai/observer'; * * registerTelemetry(autotelTelemetry()); * ``` */ declare function autotelTelemetry(options?: AutotelTelemetryOptions): AutotelTelemetryIntegration; //#endregion //#region src/observer/ai-sdk-channel.d.ts interface SubscribeAiTelemetryOptions { /** Tracer to emit spans on. Defaults to the global observer tracer. */ tracer?: Tracer; /** * Capture prompt/response content and tool arguments/results. Off by default. * @see {@link import('./ai-sdk-telemetry.js').AutotelTelemetryOptions.captureContent} */ captureContent?: boolean; /** Privacy gate for captured content (redact or drop per event). */ exportContent?: (event: GenAiObserverEvent) => GenAiObserverEvent | undefined; /** Resolve an OTel parent context for otherwise-root operations. */ resolveParentContext?: (event: GenAiObserverEvent) => Context | undefined; } /** * Subscribe to the `ai:telemetry` tracing channel and emit canonical `gen_ai.*` * spans. Returns an unsubscribe function (a no-op on unsupported runtimes). */ declare function subscribeAiTelemetry(options?: SubscribeAiTelemetryOptions): () => void; //#endregion //#region src/values.d.ts /** * Reading values that arrive from outside: an LLM SDK's result object, a * telemetry channel message, an error someone threw. Nothing about them is known until one * of these asks, and each answers with the type it looked for or `undefined`. * * This is the boundary. The `typeof` checks and the `unknown` parameters below * are what a boundary is made of; past it, the instrumentation works with types. * * Internal - not exported from the package entry points. */ /** An object whose fields have not been read yet. */ interface UnknownRecord { [key: string]: unknown; } /** The value as an object, or undefined when it is anything else. */ declare function asRecord(value: unknown): UnknownRecord | undefined; /** The string the value carries, or undefined when it carries anything else. */ declare function asString(value: unknown): string | undefined; /** A string with something in it - a blank one counts as absent. */ declare function nonEmptyString(value: unknown): string | undefined; /** * The number the value carries. A numeric string counts: a backend's JSON * routinely sends counts, timestamps and durations as strings. */ declare function asNumber(value: unknown): number | undefined; /** The boolean the value carries, or undefined when it carries anything else. */ declare function asBoolean(value: unknown): boolean | undefined; /** Whether the value is callable. */ declare function isFunction(value: unknown): value is (...args: never[]) => unknown; /** One field of a value, when the value is an object at all. */ declare function readProperty(source: unknown, key: string): unknown; //#endregion //#region src/observer/langchain.d.ts /** LangChain `Serialized` — the identity of a chain/LLM/tool. */ interface Serialized { id?: string[]; name?: string; kwargs?: UnknownRecord; } interface LLMGeneration { generationInfo?: UnknownRecord; message?: { usage_metadata?: GenAiMetadata; response_metadata?: GenAiMetadata; }; } /** LangChain `LLMResult` — what an LLM/chat-model run returns. */ interface LLMResult { generations?: LLMGeneration[][]; llmOutput?: UnknownRecord; } /** The subset of LangChain's `CallbackHandlerMethods` this adapter implements. */ interface LangChainObserverHandler { handleChainStart(chain: Serialized, inputs: unknown, runId: string, parentRunId?: string, tags?: string[], metadata?: GenAiMetadata, runType?: string, runName?: string): void; handleChainEnd(outputs: unknown, runId: string): void; handleChainError(error: unknown, runId: string): void; handleLLMStart(llm: Serialized, prompts: string[], runId: string, parentRunId?: string, extraParams?: GenAiMetadata): void; handleChatModelStart(llm: Serialized, messages: unknown, runId: string, parentRunId?: string, extraParams?: GenAiMetadata): void; handleLLMEnd(output: LLMResult, runId: string): void; handleLLMError(error: unknown, runId: string): void; handleToolStart(tool: Serialized, input: string, runId: string, parentRunId?: string, tags?: string[], metadata?: GenAiMetadata, runName?: string): void; handleToolEnd(output: unknown, runId: string): void; handleToolError(error: unknown, runId: string): void; } interface LangChainObserverOptions { /** * Decide whether a chain run becomes an `invoke_agent` span. The default * skips LangChain/LangGraph plumbing (Runnable*, ChannelWrite, Branch, * prompts, `__start__`/`__end__`) so only the graph and its named nodes show; * children of a skipped chain reparent to the nearest kept ancestor. */ skipChain?: (name: string) => boolean; } declare function createLangChainObserver(observe: GenAiObserver, options?: LangChainObserverOptions): LangChainObserverHandler; //#endregion //#region src/observer/mastra.d.ts /** Mastra `UsageStats`. */ interface MastraUsage { inputTokens?: number; outputTokens?: number; inputDetails?: { cacheRead?: number; cacheWrite?: number; }; outputDetails?: { reasoning?: number; }; } /** * The union of every Mastra span-attribute field this adapter reads. Mastra * types these per span type; flattening them here keeps the adapter dependency * free, and every field stays optional because only some types carry it. * * The span's `attributes` field is declared `unknown` rather than this type: * Mastra's own union of per-type attribute interfaces has no member in common * with a flattened view, so declaring it would make a real `ExportedSpan` * unassignable and force every caller into a cast. `span.type` is the * discriminant, and each branch reads only the fields that type carries. */ interface MastraSpanAttributes { model?: string; provider?: string; responseModel?: string; responseId?: string; finishReason?: string; streaming?: boolean; completionStartTime?: Date; usage?: MastraUsage; serverAddress?: string; serverPort?: number; parameters?: { maxOutputTokens?: number; temperature?: number; topP?: number; topK?: number; frequencyPenalty?: number; presencePenalty?: number; stopSequences?: string[]; seed?: number; }; toolDescription?: string; toolCallId?: string; } /** The subset of Mastra's `ExportedSpan` this adapter reads. */ interface MastraExportedSpan { id: string; parentSpanId?: string; name: string; type: string; entityName?: string; startTime: Date; endTime?: Date; isEvent: boolean; /** Narrowed to {@link MastraSpanAttributes} per span type — see the note there. */ attributes?: unknown; input?: unknown; output?: unknown; errorInfo?: { message?: string; }; } /** Mastra's `TracingEvent`. */ interface MastraTracingEvent { type: 'span_started' | 'span_updated' | 'span_ended'; exportedSpan: MastraExportedSpan; } /** The subset of Mastra's `ObservabilityExporter` this adapter implements. */ interface MastraObserverExporter { name: string; exportTracingEvent(event: MastraTracingEvent): Promise; flush(): Promise; shutdown(): Promise; } interface MastraObserverOptions { /** Exporter name Mastra logs against. Defaults to `autotel`. */ name?: string; /** * Drop an additional supported Mastra span from the emitted tree. Unsupported * plumbing spans are always dropped because this adapter has no canonical * mapping for them. Children of every dropped span reparent to the nearest * kept ancestor. */ skipSpan?: (span: MastraExportedSpan) => boolean; } declare function createMastraObserver(observe: GenAiObserver, options?: MastraObserverOptions): MastraObserverExporter; //#endregion export { ChatEndEvent as A, ToolStartEvent as B, AiSdkUsage as C, createGenAiObserver as D, SpanRegistry as E, GenAiObserverOptions as F, WorkflowStartEvent as H, GenAiToolIdentity as I, SpanEnd as L, ChatStreamTiming as M, GenAiObserver as N, AgentEndEvent as O, GenAiObserverEvent as P, SpanStart as R, AiSdkToolResult as S, observeAiSdkResult as T, WorkflowEndEvent as V, contentToGenAiMessage as _, createMastraObserver as a, AiSdkStep as b, createLangChainObserver as c, AutotelTelemetryIntegration as d, AutotelTelemetryOptions as f, ConvertedPrompt as g, autotelTelemetry as h, MastraTracingEvent as i, ChatStartEvent as j, AgentStartEvent as k, SubscribeAiTelemetryOptions as l, ProviderResponseView as m, MastraObserverExporter as n, LangChainObserverHandler as o, JsonValue as p, MastraObserverOptions as r, LangChainObserverOptions as s, MastraExportedSpan as t, subscribeAiTelemetry as u, promptToGenAiMessages as v, ObserveAiSdkOptions as w, AiSdkToolCall as x, AiSdkResult as y, ToolEndEvent as z };