import { a as TokenUsage, t as EstimateCostOptions } from "./cost-CiXR1eKW.js"; import { h as GenAiProviderName } from "./semconv-BdR5pWDh.js"; import { n as GenAiAttributeMap } from "./attributes-xDXxzr8D.js"; import { Attributes } from "@opentelemetry/api"; import { TraceContext } from "autotel"; //#region src/ai-sdk-bridge.d.ts /** Legacy AI SDK (`LegacyOpenTelemetry`) attribute keys we understand. */ export declare const AI_SDK_ATTR: { readonly MODEL_ID: 'ai.model.id'; readonly MODEL_PROVIDER: 'ai.model.provider'; readonly RESPONSE_MODEL: 'ai.response.model'; readonly RESPONSE_ID: 'ai.response.id'; readonly RESPONSE_FINISH_REASON: 'ai.response.finishReason'; readonly USAGE_PROMPT_TOKENS: 'ai.usage.promptTokens'; readonly USAGE_INPUT_TOKENS: 'ai.usage.inputTokens'; readonly USAGE_COMPLETION_TOKENS: 'ai.usage.completionTokens'; readonly USAGE_OUTPUT_TOKENS: 'ai.usage.outputTokens'; readonly USAGE_CACHED_INPUT_TOKENS: 'ai.usage.cachedInputTokens'; readonly USAGE_REASONING_TOKENS: 'ai.usage.reasoningTokens'; readonly SETTINGS_MAX_TOKENS: 'ai.settings.maxOutputTokens'; readonly TELEMETRY_FUNCTION_ID: 'ai.telemetry.functionId'; }; /** * Normalize an AI SDK provider id (e.g. `openai.chat`, `amazon-bedrock`, * `google.generative-ai`) to a canonical `gen_ai.provider.name` value. Returns * the original string when it isn't a known provider. */ export declare function normalizeAiSdkProvider(provider: string): GenAiProviderName; /** * Extract {@link TokenUsage} from a span's attributes, reading canonical * `gen_ai.usage.*` first and falling back to legacy `ai.usage.*`. Returns * `undefined` when no token counts are present. */ export declare function extractAiSdkUsage(attributes: Attributes): TokenUsage | undefined; /** Read the request model from canonical or legacy attributes. */ export declare function extractAiSdkModel(attributes: Attributes): string | undefined; /** * Rewrite legacy `ai.*` telemetry attributes to canonical `gen_ai.*`. Pass the * attributes of an AI SDK span emitted by `LegacyOpenTelemetry` (or an older * SDK version); returns a fresh map with the canonical keys. Unknown keys are * dropped — this is a focused mapper, not a passthrough. */ export declare function mapAiSdkAttributes(attributes: Attributes): GenAiAttributeMap; /** * Estimate the USD cost of an AI SDK call from a span's attributes (model + * usage, canonical or legacy). Returns `undefined` when model or usage is * missing, or the model has no known pricing. */ export declare function estimateAiSdkCost(attributes: Attributes, options?: EstimateCostOptions): number | undefined; /** * Estimate cost from AI SDK span attributes and record it as * `gen_ai.usage.cost.usd` on your own wrapping trace context. Useful when you * wrap a `generateText`/`streamText` call in an autotel span and want cost on * the parent. Returns the estimated cost, or `undefined`. */ export declare function recordAiSdkCost(ctx: Pick, attributes: Attributes, options?: EstimateCostOptions): number | undefined; /** Marks a span as having passed through an autotel-aware `enrichSpan`. */ export declare const AUTOTEL_ENRICHED_ATTR = "autotel.enriched"; /** Span kinds the `@ai-sdk/otel` `OpenTelemetry` integration emits. */ export type AiSdkSpanType = 'operation' | 'step' | 'languageModel' | 'tool' | 'embedding' | 'reranking'; /** The context `@ai-sdk/otel` passes to an `enrichSpan` callback. */ export interface AiSdkEnrichContext { spanType: AiSdkSpanType; operationId: string; callId: string; runtimeContext?: Record; } export interface AutotelEnrichOptions { /** * Map the enrich context to extra span attributes — e.g. promote * `runtimeContext` fields (sessionId, tenantId) onto the span. Returns * `undefined` to add nothing for that span. */ attributes?: (ctx: AiSdkEnrichContext) => Record | undefined; } /** * Build an `enrichSpan` callback for the `@ai-sdk/otel` `OpenTelemetry` * integration. It stamps an autotel provenance marker and merges any attributes * your `attributes` mapper returns: * * ```ts * import { registerTelemetry } from 'ai'; * import { OpenTelemetry } from '@ai-sdk/otel'; * import { autotelEnrich } from 'autotel-genai/ai-sdk'; * * registerTelemetry(new OpenTelemetry({ enrichSpan: autotelEnrich() })); * ``` * * Important: `enrichSpan` **cannot add cost**. The AI SDK only passes * `{ spanType, operationId, callId, runtimeContext }` to the callback — no token * usage and no resolved model — and its own attributes override custom keys. For * `gen_ai.usage.cost.usd` on the model span, use `autotelTelemetry()` from * `autotel-genai/observer` (it owns span creation), or price spans after the * fact with {@link estimateAiSdkCost}. `autotel-devtools` also prices `gen_ai` * spans on render regardless of which integration emitted them. */ export declare function autotelEnrich(options?: AutotelEnrichOptions): (ctx: AiSdkEnrichContext) => Record; //#endregion