@sentry/server-utils 11.19.0 → 11.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/chunks/config.js +28 -0
- package/build/cjs/chunks/config.js.map +1 -1
- package/build/cjs/chunks/exports.js +6 -0
- package/build/cjs/index.js +424 -73
- package/build/cjs/index.js.map +1 -1
- package/build/esm/ai/tanstack-ai/constants.js +11 -0
- package/build/esm/ai/tanstack-ai/constants.js.map +1 -0
- package/build/esm/ai/tanstack-ai/index.js +206 -0
- package/build/esm/ai/tanstack-ai/index.js.map +1 -0
- package/build/esm/ai/tanstack-ai/utils.js +81 -0
- package/build/esm/ai/tanstack-ai/utils.js.map +1 -0
- package/build/esm/ai/vercel-ai/index.js +1 -12
- package/build/esm/ai/vercel-ai/index.js.map +1 -1
- package/build/esm/index.js +2 -1
- package/build/esm/index.js.map +1 -1
- package/build/esm/integrations/nitro/captureTracingEvents.js +4 -3
- package/build/esm/integrations/nitro/captureTracingEvents.js.map +1 -1
- package/build/esm/integrations/nitro/index.js +2 -2
- package/build/esm/integrations/nitro/index.js.map +1 -1
- package/build/esm/integrations/openai-compatible.js.map +1 -1
- package/build/esm/integrations/tanstack-ai.js +59 -0
- package/build/esm/integrations/tanstack-ai.js.map +1 -0
- package/build/esm/integrations/vercel-ai/vercel-ai-dc-subscriber.js +70 -42
- package/build/esm/integrations/vercel-ai/vercel-ai-dc-subscriber.js.map +1 -1
- package/build/esm/integrations/vercel-ai/vercel-ai-orchestrion-subscriber.js +21 -16
- package/build/esm/integrations/vercel-ai/vercel-ai-orchestrion-subscriber.js.map +1 -1
- package/build/esm/orchestrion/channels.js +2 -0
- package/build/esm/orchestrion/channels.js.map +1 -1
- package/build/esm/orchestrion/config/index.js +2 -0
- package/build/esm/orchestrion/config/index.js.map +1 -1
- package/build/esm/orchestrion/config/tanstack-ai.js +19 -0
- package/build/esm/orchestrion/config/tanstack-ai.js.map +1 -0
- package/build/esm/package.json +1 -1
- package/build/types/ai/tanstack-ai/constants.d.ts +8 -0
- package/build/types/ai/tanstack-ai/constants.d.ts.map +1 -0
- package/build/types/ai/tanstack-ai/index.d.ts +18 -0
- package/build/types/ai/tanstack-ai/index.d.ts.map +1 -0
- package/build/types/ai/tanstack-ai/types.d.ts +127 -0
- package/build/types/ai/tanstack-ai/types.d.ts.map +1 -0
- package/build/types/ai/tanstack-ai/utils.d.ts +21 -0
- package/build/types/ai/tanstack-ai/utils.d.ts.map +1 -0
- package/build/types/ai/vercel-ai/index.d.ts +0 -6
- package/build/types/ai/vercel-ai/index.d.ts.map +1 -1
- package/build/types/index.d.ts +2 -0
- package/build/types/index.d.ts.map +1 -1
- package/build/types/integrations/nitro/captureTracingEvents.d.ts +3 -1
- package/build/types/integrations/nitro/captureTracingEvents.d.ts.map +1 -1
- package/build/types/integrations/nitro/index.d.ts +6 -0
- package/build/types/integrations/nitro/index.d.ts.map +1 -1
- package/build/types/integrations/openai-compatible.d.ts.map +1 -1
- package/build/types/integrations/tanstack-ai.d.ts +18 -0
- package/build/types/integrations/tanstack-ai.d.ts.map +1 -0
- package/build/types/integrations/vercel-ai/vercel-ai-dc-subscriber.d.ts.map +1 -1
- package/build/types/orchestrion/channels.d.ts +1 -0
- package/build/types/orchestrion/channels.d.ts.map +1 -1
- package/build/types/orchestrion/config/index.d.ts.map +1 -1
- package/build/types/orchestrion/config/tanstack-ai.d.ts +17 -0
- package/build/types/orchestrion/config/tanstack-ai.d.ts.map +1 -0
- package/package.json +3 -3
|
@@ -147,8 +147,8 @@ function deferStreamTextOperationEnd(span, data, end) {
|
|
|
147
147
|
const streamResult = data.result;
|
|
148
148
|
(async () => {
|
|
149
149
|
try {
|
|
150
|
-
const [usage, text, objectOutcome, toolCalls, finishReason, response] = await Promise.all([
|
|
151
|
-
streamResult.
|
|
150
|
+
const [usage, text, objectOutcome, toolCalls, finishReason, response, steps, providerMetadata] = await Promise.all([
|
|
151
|
+
streamResult.usage,
|
|
152
152
|
streamResult.text,
|
|
153
153
|
type === "streamObject" ? Promise.resolve(streamResult.object).then((value) => ({ value }), (error) => ({
|
|
154
154
|
value: void 0,
|
|
@@ -156,26 +156,28 @@ function deferStreamTextOperationEnd(span, data, end) {
|
|
|
156
156
|
})) : { value: void 0 },
|
|
157
157
|
streamResult.toolCalls,
|
|
158
158
|
streamResult.finishReason,
|
|
159
|
-
streamResult.response
|
|
159
|
+
streamResult.response,
|
|
160
|
+
streamResult.steps,
|
|
161
|
+
streamResult.providerMetadata
|
|
160
162
|
]);
|
|
163
|
+
const result = {
|
|
164
|
+
usage,
|
|
165
|
+
toolCalls,
|
|
166
|
+
finishReason,
|
|
167
|
+
response,
|
|
168
|
+
steps,
|
|
169
|
+
providerMetadata
|
|
170
|
+
};
|
|
161
171
|
if ("error" in objectOutcome) {
|
|
162
|
-
message.result =
|
|
163
|
-
usage,
|
|
164
|
-
toolCalls,
|
|
165
|
-
finishReason,
|
|
166
|
-
response
|
|
167
|
-
};
|
|
172
|
+
message.result = result;
|
|
168
173
|
enrichSpanOnEnd(span, message);
|
|
169
174
|
end(objectOutcome.error);
|
|
170
175
|
return;
|
|
171
176
|
}
|
|
172
177
|
const object = objectOutcome.value;
|
|
173
178
|
data.result = {
|
|
174
|
-
|
|
175
|
-
text: text ?? (isObjectLike(object) ? JSON.stringify(object) : object)
|
|
176
|
-
toolCalls,
|
|
177
|
-
finishReason,
|
|
178
|
-
response
|
|
179
|
+
...result,
|
|
180
|
+
text: text ?? (isObjectLike(object) ? JSON.stringify(object) : object)
|
|
179
181
|
};
|
|
180
182
|
end();
|
|
181
183
|
} catch (error) {
|
|
@@ -184,9 +186,12 @@ function deferStreamTextOperationEnd(span, data, end) {
|
|
|
184
186
|
})();
|
|
185
187
|
return true;
|
|
186
188
|
}
|
|
187
|
-
/**
|
|
189
|
+
/**
|
|
190
|
+
* A streamed result exposes its aggregates as promises; a settled result does not. Reading `totalUsage`
|
|
191
|
+
* would create a promise that rejects unobserved when the stream aborts.
|
|
192
|
+
*/
|
|
188
193
|
function isStreamingResult(result) {
|
|
189
|
-
return isObjectLike(result) && (isThenable(result.
|
|
194
|
+
return isObjectLike(result) && (isThenable(result.steps) || isThenable(result.usage));
|
|
190
195
|
}
|
|
191
196
|
function isThenable(value) {
|
|
192
197
|
return isObjectLike(value) && typeof value.then === "function";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vercel-ai-orchestrion-subscriber.js","names":[],"sources":["../../../../src/integrations/vercel-ai/vercel-ai-orchestrion-subscriber.ts"],"sourcesContent":["/* eslint-disable max-lines */\nimport type { Span } from '@sentry/core';\nimport {\n addNonEnumerableProperty,\n debug,\n getActiveSpan,\n isObjectLike,\n SPAN_STATUS_ERROR,\n withActiveSpan,\n} from '@sentry/core';\nimport { DEBUG_BUILD } from '../../debug-build';\nimport type { OrchestrionChannelContext } from '../../orchestrion/types';\nimport { CHANNELS } from '../../orchestrion/channels';\nimport { bindTracingChannelToSpan, type TracingChannelPayloadWithSpan } from '../../tracing-channel';\nimport type { GenAiSpanResult } from '../../ai/core/span-hooks';\nimport {\n captureToolError,\n clearOperationCallId,\n clearOperationId,\n createSpanFromMessage,\n enrichSpanOnEnd,\n runVercelAiSpanEnd,\n streamedResultToChannelResult,\n type VercelAiChannelMessage,\n type VercelAiChannelOptions,\n type VercelAiTracingChannelFactory,\n} from './vercel-ai-dc-subscriber';\nimport { asString, isReadableStream, tapModelCallStream } from './util';\n\n/**\n * v4, v5 & v6 channel adapter for the Vercel AI (`ai`) SDK.\n *\n * `ai` >= 7 publishes a normalized `ai:telemetry` tracing channel natively\n * (consumed by `subscribeVercelAiTracingChannel`). v4/v5/v6 have no such channel, so\n * orchestrion injects `orchestrion:ai:*` channels around the top-level\n * functions (see `orchestrion/config/index.ts`). The injected channels carry only the\n * wrapped call's `{ arguments, result, error }` — NOT v7's normalized `event`\n * object — so this adapter reconstructs an equivalent {@link VercelAiChannelMessage}\n * from each version's argument/result shapes and delegates to the SAME span-building core\n * (`createSpanFromMessage` / `enrichSpanOnEnd`) the v7 subscriber uses, so the\n * emitted spans are identical between v4, v5, v6 and v7. The shared core reads both v4-style\n * (`promptTokens`/`completionTokens`) and v5+-style (`inputTokens`/`outputTokens`) token names.\n *\n * The model call (`languageModelCall` / `generate_content` span) has no\n * injectable definition in `ai`. On v5/v6 we wrap `resolveLanguageModel` (the\n * single chokepoint every model call flows through) and monkey-patch\n * `doGenerate`/`doStream` on the returned model. v4 has no `resolveLanguageModel`\n * — the passed `LanguageModelV1` (`specificationVersion: 'v1'`) is called directly —\n * so we patch its `doGenerate`/`doStream` at the operation start instead (see\n * `buildOperationSpan`), gated on `'v1'` so it never touches v5/v6 models.\n *\n * Tool-call spans differ by version: v6 exposes a per-call `executeToolCall`\n * function orchestrion wraps into its own channel. v4/v5 have no such export (only a\n * batch `executeTools`), so instead we monkey-patch each tool's `execute` from\n * the operation's `tools`. On v6 that patch is inert: `executeToolCall` runs\n * `execute` inside its own tool-call span (the active async context), so the\n * patch sees that span as its parent and skips — only v4/v5 (where the parent is\n * the enclosing `invoke_agent` span) emit the patched span, so v6 never\n * double-counts tool spans.\n */\n\n/** Builds the normalized message for a channel from the wrapped call's first-arg options. */\ntype MessageBuilder = (options: Record<string, unknown>, telemetry: Record<string, unknown>) => VercelAiChannelMessage;\n\n/** A resolved `ai` language model — has `doGenerate`/`doStream` and identity fields. */\ninterface ResolvedModel {\n modelId?: string;\n provider?: string;\n doGenerate?: (...args: unknown[]) => Promise<unknown>;\n doStream?: (...args: unknown[]) => Promise<unknown>;\n}\n\nconst PATCHED = Symbol('SentryVercelAiModelPatched');\nconst TOOL_PATCHED = Symbol('SentryVercelAiToolPatched');\n\n/** A resolved model with our patch bookkeeping (idempotency flag). */\ntype PatchableModel = ResolvedModel & { [PATCHED]?: boolean };\n\n/** A tool definition off an operation's `tools`, with our patch bookkeeping. */\ntype PatchableTool = { execute?: (...args: unknown[]) => unknown; [TOOL_PATCHED]?: boolean };\n\n// Per-operation correlation id. No Date/random (unavailable / non-deterministic) — a counter is enough.\nlet callIdCounter = 0;\nfunction nextCallId(): string {\n return `v6-${++callIdCounter}`;\n}\n\n// The message built on `start` for each operation, keyed by the (stable-identity) channel context, so\n// the `beforeSpanEnd` handler can enrich the span from the settled result and clear the `callId` maps.\nconst messages = new WeakMap<object, VercelAiChannelMessage>();\n// The spans we opened for top-level operations, and each one's `callId`. A model call resolves its\n// parent against this set (so it never mis-attributes to the enclosing `main`/user span) and reads the\n// parent's `callId` so its span can be named after the operation (e.g. `ai.streamText.doStream`).\nconst operationSpans = new WeakSet<Span>();\n// Tool-call spans — only v6's `executeToolCall` channel opens these. The v5 tool-`execute` patch\n// consults this to avoid double-counting: `executeToolCall` runs `execute` inside its span (which is\n// therefore the active parent), so a resolved parent in this set means v6 already spanned the call.\nconst toolCallSpans = new WeakSet<Span>();\nconst callIdBySpan = new WeakMap<Span, string>();\n// The operation's per-call recording flags (`experimental_telemetry.recordInputs/recordOutputs`), keyed by\n// its span. A model call carries no telemetry of its own, so it inherits the enclosing operation's flags —\n// otherwise a per-call `recordInputs: true` would record inputs on the `invoke_agent` span but not on the\n// child `generate_content` span (whose event would fall back to the global default). v7's channel forwards\n// these flags on every event, so this keeps v6 identical.\nconst recordingBySpan = new WeakMap<Span, ReturnType<typeof recording>>();\n// The operation's `experimental_telemetry.metadata`, keyed by its span, so the model-call span records it\n// too. The OTel integration put it on both, but not on tool-call spans.\nconst telemetryMetadataBySpan = new WeakMap<Span, unknown>();\ninterface OperationErrorInfo {\n // The span active when the operation was invoked (its call site, e.g. the enclosing request/`main` span).\n // When an operation's error bubbles out unhandled it reaches the global handler outside any span, so — as\n // the OTel path does — we stamp this span onto the error (in `beforeSpanEnd`) so the unhandled-rejection\n // handler can restore it and correlate the captured error to the operation's trace.\n callSiteSpan: Span | undefined;\n // Whether a thrown tool error bubbles out of the `ai` call (v4). On v4 a tool-`execute` rejection is\n // wrapped in `AI_ToolExecutionError` and re-thrown, so it reaches the user's own error handling (or our\n // global handlers) — capturing it at the tool span too would double-report it, matching how the OTel path\n // leaves v4 tool errors to bubble. On v5 `executeTools` swallows the rejection into `tool-error` content,\n // so it never surfaces and we must capture it ourselves (see `failSpan`).\n toolErrorsBubbleToCaller: boolean;\n}\n// Per-operation error-handling info, keyed by the operation span (see `OperationErrorInfo`).\nconst operationErrorInfoBySpan = new WeakMap<Span, OperationErrorInfo>();\n\n// The `experimental_telemetry` objects we swapped in to suppress `ai`'s native OTel spans (see\n// `suppressNativeTelemetry`). Our skip logic treats `isEnabled === false` as \"user disabled telemetry,\n// emit no span\"; without this set, a call whose options object we already neutralized — or a user-shared\n// telemetry object we replaced on a prior call — would be misread as user-disabled and lose its span.\nconst suppressedTelemetry = new WeakSet<object>();\n\nlet subscribed = false;\n\n/**\n * Subscribe the v6 orchestrion channel adapter. Safe to always call: inert on\n * `ai` >= 7 (those channels are never published) and when orchestrion injection\n * isn't active. Idempotent.\n *\n * `tracingChannel` is the platform-provided factory (the same one passed to\n * `subscribeVercelAiTracingChannel`); `options` pins the recording settings at\n * subscribe time so we never look the integration up per event.\n */\nexport function subscribeVercelAiOrchestrionChannels(\n tracingChannel: VercelAiTracingChannelFactory,\n options: VercelAiChannelOptions = {},\n): void {\n if (subscribed) {\n return;\n }\n subscribed = true;\n\n try {\n bindOperation(tracingChannel, CHANNELS.VERCEL_AI_GENERATE_TEXT, buildTextMessage('generateText'), options);\n bindOperation(tracingChannel, CHANNELS.VERCEL_AI_STREAM_TEXT, buildTextMessage('streamText'), options);\n bindOperation(tracingChannel, CHANNELS.VERCEL_AI_STREAM_OBJECT, buildTextMessage('streamObject'), options);\n bindOperation(tracingChannel, CHANNELS.VERCEL_AI_GENERATE_OBJECT, buildTextMessage('generateObject'), options);\n bindOperation(\n tracingChannel,\n CHANNELS.VERCEL_AI_EMBED,\n (callOptions, telemetry) => ({\n type: 'embed',\n event: {\n callId: nextCallId(),\n ...modelFields(callOptions.model),\n maxRetries: callOptions.maxRetries,\n value: callOptions.value,\n telemetryMetadata: telemetry.metadata,\n ...recording(telemetry),\n },\n }),\n options,\n );\n bindOperation(\n tracingChannel,\n CHANNELS.VERCEL_AI_EMBED_MANY,\n // `embedMany` takes a `values` array (vs `embed`'s single `value`); the shared core reads it as the\n // embeddings input, matching the OTel path's batch `ai.embedMany` span.\n (callOptions, telemetry) => ({\n type: 'embedMany',\n event: {\n callId: nextCallId(),\n ...modelFields(callOptions.model),\n maxRetries: callOptions.maxRetries,\n values: callOptions.values,\n telemetryMetadata: telemetry.metadata,\n ...recording(telemetry),\n },\n }),\n options,\n );\n bindOperation(\n tracingChannel,\n CHANNELS.VERCEL_AI_EXECUTE_TOOL_CALL,\n (callOptions, telemetry) => ({\n type: 'executeTool',\n // v6 carries the tool definitions on the executeToolCall args (a record keyed by name);\n // the shared core reads the matching tool's `description` for the span.\n event: {\n callId: nextCallId(),\n toolCall: callOptions.toolCall,\n tools: callOptions.tools,\n ...recording(telemetry),\n },\n }),\n options,\n );\n subscribeResolveLanguageModel(tracingChannel, CHANNELS.VERCEL_AI_RESOLVE_LANGUAGE_MODEL, options);\n } catch {\n DEBUG_BUILD && debug.log('Vercel AI channel subscription failed.');\n }\n}\n\n/**\n * Bind one operation channel: `getSpan` opens a span from the message reconstructed out of the wrapped\n * call's first argument; `beforeSpanEnd` enriches it from the settled result (tokens, output messages,\n * finish reasons, …) before the helper ends the span.\n *\n * An operation whose `experimental_telemetry.isEnabled` is explicitly `false` is skipped entirely (no\n * span): the orchestrion channel fires regardless of that flag, whereas v7's native `ai:telemetry`\n * channel is simply not published in that case — so we reproduce v7's \"no telemetry → no span\".\n */\nfunction bindOperation(\n tracingChannel: VercelAiTracingChannelFactory,\n channelName: string,\n build: MessageBuilder,\n options: VercelAiChannelOptions,\n): void {\n const channel = tracingChannel<OrchestrionChannelContext>(channelName);\n\n // Build the operation span from the wrapped call's first argument and track it (so a model call can\n // resolve it as its parent). `bindTracingChannelToSpan` calls this once at channel `start` and makes\n // the returned span the active async context for the operation's duration — that active span is what\n // `resolveModelCallParent` reads. It also sets `data._sentrySpan`, so we don't here.\n const buildOperationSpan = (data: TracingChannelPayloadWithSpan<OrchestrionChannelContext>): Span | undefined => {\n const callOptions = isObjectLike(data.arguments[0]) ? data.arguments[0] : {};\n const telemetry = isObjectLike(callOptions.experimental_telemetry) ? callOptions.experimental_telemetry : {};\n // `isEnabled === false` means the user opted out — emit no span. But `isEnabled` is also `false` on\n // the telemetry object we swap in to suppress native spans, so don't mistake our own object for a\n // user opt-out (which would drop the span on a call whose options we already neutralized).\n if (telemetry.isEnabled === false && !suppressedTelemetry.has(telemetry)) {\n return undefined;\n }\n const message = build(callOptions, telemetry);\n // Stop `ai` from emitting its own native OTel spans for this call — we build the equivalent spans\n // from the channels, so the SDK's would be duplicates. Reads above have already captured everything\n // we need off `telemetry`.\n suppressNativeTelemetry(callOptions, telemetry);\n // The span active here is the operation's call site — `bindTracingChannelToSpan` only makes the\n // operation span active *after* this returns — so this is the span we later restore for a bubbled error.\n const callSiteSpan = getActiveSpan();\n const span = createSpanFromMessage(message, options);\n if (span) {\n messages.set(data, message);\n operationSpans.add(span);\n // `'v1'` models are v4 (v5/v6 are `'v2'`), where a thrown tool error bubbles out of the call rather\n // than being swallowed into `tool-error` content — so its tool spans must not self-capture the error.\n const isV4 = isObjectLike(callOptions.model) && callOptions.model.specificationVersion === 'v1';\n operationErrorInfoBySpan.set(span, { callSiteSpan, toolErrorsBubbleToCaller: isV4 });\n // v6's `executeToolCall` span: tracked so the v5 tool-`execute` patch can recognize (and skip)\n // tool calls it runs, since that patch sees this span as its active parent (see `patchToolExecute`).\n if (message.type === 'executeTool') {\n toolCallSpans.add(span);\n }\n const callId = asString(message.event.callId);\n if (callId) {\n callIdBySpan.set(span, callId);\n }\n recordingBySpan.set(span, recording(telemetry));\n telemetryMetadataBySpan.set(span, telemetry.metadata);\n // v5 has no `executeToolCall` channel, so patch each tool's `execute` to emit the tool-call span.\n // Inert on v6 (guarded inside `patchToolExecute` when the parent is `executeToolCall`'s own span).\n if (isObjectLike(callOptions.tools)) {\n patchOperationTools(callOptions.tools, options);\n }\n // v4 has no `resolveLanguageModel` chokepoint — the passed `LanguageModelV1` is called directly — so\n // patch its `doGenerate`/`doStream` here, at the operation start, instead. v5/v6 models are patched via\n // `resolveLanguageModel`, so restricting to v4 keeps this strictly additive and avoids double-patching.\n // Embedding models are also `'v1'` but expose no `doGenerate`/`doStream`, so the patch is a no-op for\n // `embed`/`embedMany`.\n if (isV4) {\n patchModelMethods(callOptions.model as PatchableModel, options);\n }\n }\n return span;\n };\n\n bindTracingChannelToSpan(\n channel,\n (data: TracingChannelPayloadWithSpan<OrchestrionChannelContext>) => buildOperationSpan(data),\n {\n beforeSpanEnd: (span, data) => {\n const message = messages.get(data);\n if (!message) {\n return;\n }\n // The helper's `error` handler already set the span status; only enrich from a successful result.\n if ('error' in data) {\n // The error bubbles out of the `ai` call. If nothing handles it before our global handler, that\n // handler runs outside any span — so stamp the operation's call-site span onto the error, letting\n // the unhandled-rejection handler restore it and correlate the report to this trace. This mirrors\n // the OTel path; it's a no-op when the error is handled earlier (e.g. a framework error handler).\n const callSiteSpan = operationErrorInfoBySpan.get(span)?.callSiteSpan;\n if (callSiteSpan && isObjectLike(data.error)) {\n addNonEnumerableProperty(data.error, '_sentry_active_span', callSiteSpan);\n }\n } else {\n // v6's `executeToolCall` returns the tool result/error object directly, whereas the shared core\n // (matching v7) expects it nested under `output`; wrap it so tool-error detection works.\n message.result = message.type === 'executeTool' ? { output: data.result } : data.result;\n enrichSpanOnEnd(span, message);\n }\n const isStream = message.type === 'streamText' || message.type === 'streamObject';\n runVercelAiSpanEnd(\n span,\n 'error' in data ? { error: data.error } : { response: isStream ? undefined : message.result },\n );\n // A `streamText`/`streamObject` model call runs after this (synchronously-returning) operation's\n // span has already ended, so its `callId` entry must outlive the operation — it's cleared once the\n // model call settles (see `patchModelMethod`). Every other operation can clear here.\n if (!isStream) {\n clearOperationId(message);\n }\n messages.delete(data);\n },\n // `streamText`/`streamObject` return synchronously, so their operation span would otherwise end\n // before the stream drains — losing the aggregate usage/output. Defer the end and await the result's\n // completion promises (`totalUsage`/`text`/…, which resolve on drain), mirroring how v7's channel\n // defers the operation span on the SDK's total-usage promise.\n deferSpanEnd: ({ span, data, end }) => deferStreamTextOperationEnd(span, data, end),\n },\n );\n}\n\n/**\n * Keep a streamed `streamText`/`streamObject` operation span open until the stream drains, then enrich it\n * from the result's completion promises (usage/output/finish reason) and end it. `streamObject` resolves\n * `object` rather than `text`; `getOutputMessages` reads `text`, so a resolved object is stringified into\n * that field. Returns `false` for anything that isn't a streamed result, so the helper ends the span as usual.\n *\n * `streamObject`'s `object` rejects when the output fails schema validation, even though the model call\n * succeeded and `usage` resolved. It's awaited separately so that case still records the token usage on\n * the span before ending it as an error.\n */\nfunction deferStreamTextOperationEnd(\n span: Span,\n data: TracingChannelPayloadWithSpan<OrchestrionChannelContext>,\n end: (error?: unknown) => void,\n): boolean {\n const message = messages.get(data);\n const type = message?.type;\n if (\n !message ||\n (type !== 'streamText' && type !== 'streamObject') ||\n 'error' in data ||\n !isStreamingResult(data.result)\n ) {\n return false;\n }\n\n const streamResult = data.result;\n void (async () => {\n try {\n const [usage, text, objectOutcome, toolCalls, finishReason, response] = await Promise.all([\n streamResult.totalUsage ?? streamResult.usage,\n streamResult.text,\n // Settle `object` into an outcome so a validation failure can't short-circuit the usage read.\n type === 'streamObject'\n ? Promise.resolve(streamResult.object).then(\n value => ({ value }),\n (error: unknown) => ({ value: undefined, error }),\n )\n : { value: undefined },\n streamResult.toolCalls,\n streamResult.finishReason,\n streamResult.response,\n ]);\n if ('error' in objectOutcome) {\n // The model call itself succeeded, so keep its usage on the span; `beforeSpanEnd` skips\n // enrichment once `end(error)` marks the payload as errored.\n message.result = { usage, toolCalls, finishReason, response };\n enrichSpanOnEnd(span, message);\n end(objectOutcome.error);\n return;\n }\n const object = objectOutcome.value;\n // Feed the resolved values back through the shared enrichment: `beforeSpanEnd` reads `data.result`.\n data.result = {\n usage,\n text: text ?? (isObjectLike(object) ? JSON.stringify(object) : object),\n toolCalls,\n finishReason,\n response,\n };\n end();\n } catch (error) {\n end(error);\n }\n })();\n\n return true;\n}\n\n/** A streamed result exposes its aggregates as promises (`totalUsage`/`usage`); a settled result does not. */\nfunction isStreamingResult(result: unknown): result is Record<string, PromiseLike<unknown> | undefined> {\n return isObjectLike(result) && (isThenable(result.totalUsage) || isThenable(result.usage));\n}\n\nfunction isThenable(value: unknown): boolean {\n return isObjectLike(value) && typeof value.then === 'function';\n}\n\n/**\n * Neutralize `ai`'s native OpenTelemetry instrumentation for this call by pointing\n * `experimental_telemetry` at a copy with `isEnabled: false`. `ai`'s `getTracer` then returns its\n * internal no-op tracer, so it never creates (nor sets active) the duplicate `ai.*` spans we'd\n * otherwise have to drop.\n *\n * Only a call that explicitly enabled telemetry emits native spans — otherwise `ai` already uses its\n * no-op tracer, so there's nothing to suppress and we leave the user's options untouched. When\n * `isEnabled === true`, `telemetry` is `callOptions.experimental_telemetry` and `callOptions` is the\n * real first argument the SDK will read, so the reassignment takes effect for the wrapped call. We\n * replace rather than mutate in place, so a telemetry object the user shares across calls keeps its own\n * `isEnabled: true`; the replacement is tracked in `suppressedTelemetry` so our skip logic doesn't\n * later read it back as a user opt-out.\n */\nfunction suppressNativeTelemetry(callOptions: Record<string, unknown>, telemetry: Record<string, unknown>): void {\n if (telemetry.isEnabled !== true) {\n return;\n }\n const suppressed = { ...telemetry, isEnabled: false };\n suppressedTelemetry.add(suppressed);\n callOptions.experimental_telemetry = suppressed;\n}\n\n/**\n * `resolveLanguageModel` returns the model every call flows through. We don't span it — on `end` we\n * monkey-patch `doGenerate`/`doStream` on the returned model so each invocation produces a\n * `languageModelCall` span parented to the enclosing invoke_agent span.\n */\nfunction subscribeResolveLanguageModel(\n tracingChannel: VercelAiTracingChannelFactory,\n channelName: string,\n options: VercelAiChannelOptions,\n): void {\n tracingChannel<OrchestrionChannelContext>(channelName).subscribe({\n end(rawCtx) {\n const ctx = rawCtx;\n if (!isObjectLike(ctx.result)) {\n return;\n }\n // Patch the model's `doGenerate`/`doStream` once. The model call recovers its parent from the\n // active async context at call time (the operation span `bindTracingChannelToSpan` bound), which\n // propagates into the model call for `streamText` too, so there is nothing to capture on the model here.\n patchModelMethods(ctx.result, options);\n },\n start() {\n /* no-op */\n },\n asyncStart() {\n /* no-op */\n },\n asyncEnd() {\n /* no-op */\n },\n error() {\n /* no-op */\n },\n });\n}\n\n/**\n * Pick the invoke_agent span a model call should hang under: the operation span that\n * `bindTracingChannelToSpan` planted as the active async context for the enclosing operation.\n *\n * Because we suppress `ai`'s native telemetry (so it never installs its own span as active), the active\n * span inside `doGenerate`/`doStream` is our operation span. The `operationSpans` gate makes this return\n * `undefined` when the active span isn't one of ours — e.g. telemetry was disabled for the call so we\n * opened no operation span and the active span is the user's enclosing span — so the model call is\n * skipped rather than mis-parented.\n *\n * This covers `generateText`/`embed` (whose model call is awaited inside the operation body) and\n * `streamText` alike — `ai` initiates the stream synchronously within the operation's bound context, so\n * the later `doStream` continuation restores the same active span even though the operation's span has\n * already ended. The per-operation binding also disambiguates concurrent calls that share one model\n * instance (a single mutable slot on the shared model could not — it would hold whichever operation\n * resolved the model last).\n */\nfunction resolveModelCallParent(): Span | undefined {\n const active = getActiveSpan();\n return active && operationSpans.has(active) ? active : undefined;\n}\n\n/**\n * Idempotently patch a resolved model's `doGenerate`/`doStream` so each invocation emits a\n * `languageModelCall` span. Shared by the v5/v6 `resolveLanguageModel` path and the v4 path (which\n * patches the passed model at the operation start, as v4 has no `resolveLanguageModel`).\n */\nfunction patchModelMethods(model: PatchableModel, options: VercelAiChannelOptions): void {\n if (model[PATCHED]) {\n return;\n }\n model[PATCHED] = true;\n patchModelMethod(model, 'doGenerate', options);\n patchModelMethod(model, 'doStream', options);\n}\n\nfunction patchModelMethod(\n model: PatchableModel,\n method: 'doGenerate' | 'doStream',\n options: VercelAiChannelOptions,\n): void {\n const original = model[method];\n if (typeof original !== 'function') {\n return;\n }\n model[method] = function (this: unknown, ...args: unknown[]): Promise<unknown> {\n const parent = resolveModelCallParent();\n // No enclosing operation span (e.g. telemetry disabled for the call) → don't open a model-call span.\n if (!parent) {\n return Promise.resolve(original.apply(this, args));\n }\n\n const callArgs = isObjectLike(args[0]) ? args[0] : {};\n // Carry the operation's `callId` so the shared core can name the span after it\n // (`ai.generateText.doGenerate` / `ai.streamText.doStream`).\n const callId = callIdBySpan.get(parent);\n const message: VercelAiChannelMessage = {\n type: 'languageModelCall',\n event: {\n callId,\n provider: model.provider,\n modelId: model.modelId,\n // v4 nests the tool list under `mode.tools` (the `LanguageModelV1` call shape); v5+ passes a\n // top-level `tools` array. Reading both keeps `tool.definitions` populated on the model-call span.\n tools: callArgs.tools ?? (isObjectLike(callArgs.mode) ? callArgs.mode.tools : undefined),\n messages: callArgs.prompt,\n telemetryMetadata: telemetryMetadataBySpan.get(parent),\n // Inherit the enclosing operation's per-call recording flags so inputs/tools/outputs are recorded on\n // the model-call span whenever they are on the parent `invoke_agent` span.\n ...recordingBySpan.get(parent),\n },\n };\n const span = withActiveSpan(parent, () => createSpanFromMessage(message, options));\n // `languageModelCall` always opens a span; the guard just keeps the wrapper safe if that changes.\n if (!span) {\n return Promise.resolve(original.apply(this, args));\n }\n\n // `streamText` ends its operation span synchronously, so its `callId` entry was deliberately left in\n // place for this later model call; drop it now that we've used it.\n const clearStreamCallId = (): void => {\n if (method === 'doStream' && callId) {\n clearOperationCallId(callId);\n }\n };\n\n // Both the synchronous throw and the async rejection of the model call must end the span with an\n // error status (an `async` `doGenerate`/`doStream` that throws rejects rather than throwing here).\n const failSpan = (error: unknown): never => {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: error instanceof Error ? error.message : 'unknown_error' });\n endSpan(span, { error });\n clearStreamCallId();\n throw error;\n };\n\n try {\n const result = Promise.resolve(original.apply(this, args));\n return result.then(value => {\n // A streamed model call resolves to `{ stream, ... }` before the stream is consumed, so its\n // usage/finish/output only arrive as the stream drains. Tap it (same helper as the v7 path) and\n // defer ending this model-call span until then. The parent `invoke_agent` span is enriched\n // separately by `deferStreamTextOperationEnd`, which awaits the operation's own result promises.\n if (method === 'doStream' && isObjectLike(value) && isReadableStream(value.stream)) {\n value.stream = tapModelCallStream(\n span,\n value.stream,\n final => {\n message.result = { ...value, ...streamedResultToChannelResult(final) };\n enrichSpanOnEnd(span, message);\n endSpan(span, {});\n clearStreamCallId();\n },\n error => {\n span.setStatus({\n code: SPAN_STATUS_ERROR,\n message: error instanceof Error ? error.message : 'unknown_error',\n });\n endSpan(span, { error });\n clearStreamCallId();\n },\n );\n\n return value;\n }\n // `doGenerate` (and any non-stream result) settles with the full result; end here, start/end\n // bracket the call to match the channel timing.\n message.result = value;\n enrichSpanOnEnd(span, message);\n endSpan(span, { response: value });\n clearStreamCallId();\n\n return value;\n }, failSpan);\n } catch (error) {\n return failSpan(error);\n }\n };\n}\n\n/**\n * Patch every executable tool on an operation's `tools` (a record keyed by tool name) so each\n * invocation emits a `gen_ai.execute_tool` span. v5 routes tool execution through the batch\n * `executeTools`, which binds `tool.execute` at call time — so replacing the `execute` property here\n * (before the call runs) is picked up. Tools without an `execute` (client-side tools) are skipped,\n * matching `executeTools`.\n */\nfunction patchOperationTools(tools: Record<string, unknown>, options: VercelAiChannelOptions): void {\n // This runs inside the channel `start` transform (no upstream try/catch), so a throw here would break\n // the user's `ai` call. Instrumentation must never do that — degrade to no tool span instead.\n try {\n for (const [toolName, tool] of Object.entries(tools)) {\n if (isObjectLike(tool)) {\n patchToolExecute(toolName, tool, tools, options);\n }\n }\n } catch {\n DEBUG_BUILD && debug.log('Vercel AI tool patching failed.');\n }\n}\n\nfunction patchToolExecute(\n toolName: string,\n tool: PatchableTool,\n tools: Record<string, unknown>,\n options: VercelAiChannelOptions,\n): void {\n const original = tool.execute;\n if (typeof original !== 'function' || tool[TOOL_PATCHED]) {\n return;\n }\n tool[TOOL_PATCHED] = true;\n tool.execute = function (this: unknown, input: unknown, ...rest: unknown[]): unknown {\n // Skip if there's no enclosing operation span (telemetry disabled for the call), or if that parent\n // is itself a tool-call span — the latter means v6's `executeToolCall` already opened a span for\n // this call and is running `execute` inside it, so spanning again here would double-count. On v5\n // the parent is the enclosing `invoke_agent` operation span, so we proceed.\n const parent = resolveModelCallParent();\n if (!parent || toolCallSpans.has(parent)) {\n return original.apply(this, [input, ...rest]);\n }\n\n // v5 passes `{ toolCallId, messages, abortSignal, ... }` as the second argument to `execute`.\n const callOptions = isObjectLike(rest[0]) ? rest[0] : {};\n const message: VercelAiChannelMessage = {\n type: 'executeTool',\n event: {\n callId: callIdBySpan.get(parent),\n toolCall: { toolName, toolCallId: asString(callOptions.toolCallId), input },\n // The `tools` record (keyed by name) lets the shared core backfill the tool's `description`.\n tools,\n // Inherit the enclosing operation's per-call recording flags so tool inputs/outputs are recorded\n // whenever they are on the parent `invoke_agent` span.\n ...recordingBySpan.get(parent),\n },\n };\n const span = withActiveSpan(parent, () => createSpanFromMessage(message, options));\n // `executeTool` always opens a span; the guard just keeps the wrapper safe if that changes.\n if (!span) {\n return original.apply(this, [input, ...rest]);\n }\n\n // v5's `executeTools` catches a thrown tool error and turns it into `tool-error` content rather than\n // rejecting, so the user never sees a rejection — we must capture it here. On v4 the rejection bubbles\n // out of the call and reaches the user's error handling (or our global handlers), so we only mark the\n // span and leave the capture to them, avoiding a duplicate report. Rethrow either way so `executeTools`\n // still produces its `tool-error` result (v5) and the rejection propagates (v4).\n const failSpan = (error: unknown): never => {\n if (operationErrorInfoBySpan.get(parent)?.toolErrorsBubbleToCaller) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: error instanceof Error ? error.message : 'tool_error' });\n } else {\n captureToolError(span, message, error);\n }\n endSpan(span, { error });\n throw error;\n };\n\n try {\n const result = Promise.resolve(original.apply(this, [input, ...rest]));\n return result.then(value => {\n // The shared core (matching v6/v7) expects the tool result nested under `output`.\n message.result = { output: value };\n enrichSpanOnEnd(span, message);\n endSpan(span, { response: message.result });\n return value;\n }, failSpan);\n } catch (error) {\n return failSpan(error);\n }\n };\n}\n\nfunction endSpan(span: Span, result: GenAiSpanResult<unknown>): void {\n runVercelAiSpanEnd(span, result);\n span.end();\n}\n\nfunction buildTextMessage(type: 'generateText' | 'streamText' | 'streamObject' | 'generateObject'): MessageBuilder {\n return (options, telemetry) => ({\n type,\n event: {\n callId: nextCallId(),\n operationId: `ai.${type}`,\n functionId: asString(telemetry.functionId),\n ...modelFields(options.model),\n maxRetries: options.maxRetries,\n // The `ai` SDK takes the system prompt as a top-level `system` option (all of v4/v5/v6); the\n // shared core lifts `event.instructions` into the system-instructions attribute, matching v7's\n // native channel (which carries it as a distinct field rather than inside the messages array).\n instructions: options.system,\n // Normalize to the message-array shape the shared core (and v7's channel) expects: a bare string\n // `prompt` becomes a single user message, matching the SDK's own normalization.\n messages: normalizePromptMessages(options),\n // v7's native start event carries `providerOptions`; the shared core reads the OpenAI\n // Conversations API id from it.\n providerOptions: options.providerOptions,\n telemetryMetadata: telemetry.metadata,\n ...recording(telemetry),\n },\n });\n}\n\nfunction normalizePromptMessages(options: Record<string, unknown>): unknown {\n if (Array.isArray(options.messages)) {\n return options.messages;\n }\n if (typeof options.prompt === 'string') {\n return [{ role: 'user', content: options.prompt }];\n }\n return options.messages ?? options.prompt;\n}\n\nfunction recording(telemetry: Record<string, unknown>): { recordInputs: unknown; recordOutputs: unknown } {\n // Match the OTel integration's per-call default: an explicit `recordInputs`/`recordOutputs` wins, but a\n // call that merely enables telemetry (`isEnabled: true`, no explicit flags) defaults both to `true`.\n // Unlike v7's native `ai:telemetry` channel, the orchestrion channels expose `isEnabled`, so — as noted\n // in `resolveRecording` — we CAN reproduce that default here (the native-channel subscriber cannot).\n const enabledDefault = telemetry.isEnabled === true ? true : undefined;\n return {\n recordInputs: telemetry.recordInputs ?? enabledDefault,\n recordOutputs: telemetry.recordOutputs ?? enabledDefault,\n };\n}\n\nfunction modelFields(model: unknown): { provider?: string; modelId?: string } {\n return { provider: modelField(model, 'provider'), modelId: modelField(model, 'modelId') };\n}\n\nfunction modelField(model: unknown, field: 'modelId' | 'provider'): string | undefined {\n return isObjectLike(model) ? asString(model[field]) : undefined;\n}\n"],"mappings":";;;;;;;;AAwEA,MAAM,UAAU,OAAO,4BAA4B;AACnD,MAAM,eAAe,OAAO,2BAA2B;AASvD,IAAI,gBAAgB;AACpB,SAAS,aAAqB;CAC5B,OAAO,MAAM,EAAE;AACjB;AAIA,MAAM,2BAAW,IAAI,QAAwC;AAI7D,MAAM,iCAAiB,IAAI,QAAc;AAIzC,MAAM,gCAAgB,IAAI,QAAc;AACxC,MAAM,+BAAe,IAAI,QAAsB;AAM/C,MAAM,kCAAkB,IAAI,QAA4C;AAGxE,MAAM,0CAA0B,IAAI,QAAuB;AAe3D,MAAM,2CAA2B,IAAI,QAAkC;AAMvE,MAAM,sCAAsB,IAAI,QAAgB;AAEhD,IAAI,aAAa;;;;;;;;;;AAWjB,SAAgB,qCACd,gBACA,UAAkC,CAAC,GAC7B;CACN,IAAI,YACF;CAEF,aAAa;CAEb,IAAI;EACF,cAAc,gBAAgB,SAAS,yBAAyB,iBAAiB,cAAc,GAAG,OAAO;EACzG,cAAc,gBAAgB,SAAS,uBAAuB,iBAAiB,YAAY,GAAG,OAAO;EACrG,cAAc,gBAAgB,SAAS,yBAAyB,iBAAiB,cAAc,GAAG,OAAO;EACzG,cAAc,gBAAgB,SAAS,2BAA2B,iBAAiB,gBAAgB,GAAG,OAAO;EAC7G,cACE,gBACA,SAAS,kBACR,aAAa,eAAe;GAC3B,MAAM;GACN,OAAO;IACL,QAAQ,WAAW;IACnB,GAAG,YAAY,YAAY,KAAK;IAChC,YAAY,YAAY;IACxB,OAAO,YAAY;IACnB,mBAAmB,UAAU;IAC7B,GAAG,UAAU,SAAS;GACxB;EACF,IACA,OACF;EACA,cACE,gBACA,SAAS,uBAGR,aAAa,eAAe;GAC3B,MAAM;GACN,OAAO;IACL,QAAQ,WAAW;IACnB,GAAG,YAAY,YAAY,KAAK;IAChC,YAAY,YAAY;IACxB,QAAQ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zB,mBAAmB,UAAU;GAC7B,GAAG,UAAU,SAAS;EACxB;CACF;AACF;AAEA,SAAS,wBAAwB,SAA2C;CAC1E,IAAI,MAAM,QAAQ,QAAQ,QAAQ,GAChC,OAAO,QAAQ;CAEjB,IAAI,OAAO,QAAQ,WAAW,UAC5B,OAAO,CAAC;EAAE,MAAM;EAAQ,SAAS,QAAQ;CAAO,CAAC;CAEnD,OAAO,QAAQ,YAAY,QAAQ;AACrC;AAEA,SAAS,UAAU,WAAuF;CAKxG,MAAM,iBAAiB,UAAU,cAAc,OAAO,OAAO,KAAA;CAC7D,OAAO;EACL,cAAc,UAAU,gBAAgB;EACxC,eAAe,UAAU,iBAAiB;CAC5C;AACF;AAEA,SAAS,YAAY,OAAyD;CAC5E,OAAO;EAAE,UAAU,WAAW,OAAO,UAAU;EAAG,SAAS,WAAW,OAAO,SAAS;CAAE;AAC1F;AAEA,SAAS,WAAW,OAAgB,OAAmD;CACrF,OAAO,aAAa,KAAK,IAAI,SAAS,MAAM,MAAM,IAAI,KAAA;AACxD"}
|
|
1
|
+
{"version":3,"file":"vercel-ai-orchestrion-subscriber.js","names":[],"sources":["../../../../src/integrations/vercel-ai/vercel-ai-orchestrion-subscriber.ts"],"sourcesContent":["/* eslint-disable max-lines */\nimport type { Span } from '@sentry/core';\nimport {\n addNonEnumerableProperty,\n debug,\n getActiveSpan,\n isObjectLike,\n SPAN_STATUS_ERROR,\n withActiveSpan,\n} from '@sentry/core';\nimport { DEBUG_BUILD } from '../../debug-build';\nimport type { OrchestrionChannelContext } from '../../orchestrion/types';\nimport { CHANNELS } from '../../orchestrion/channels';\nimport { bindTracingChannelToSpan, type TracingChannelPayloadWithSpan } from '../../tracing-channel';\nimport type { GenAiSpanResult } from '../../ai/core/span-hooks';\nimport {\n captureToolError,\n clearOperationCallId,\n clearOperationId,\n createSpanFromMessage,\n enrichSpanOnEnd,\n runVercelAiSpanEnd,\n streamedResultToChannelResult,\n type VercelAiChannelMessage,\n type VercelAiChannelOptions,\n type VercelAiTracingChannelFactory,\n} from './vercel-ai-dc-subscriber';\nimport { asString, isReadableStream, tapModelCallStream } from './util';\n\n/**\n * v4, v5 & v6 channel adapter for the Vercel AI (`ai`) SDK.\n *\n * `ai` >= 7 publishes a normalized `ai:telemetry` tracing channel natively\n * (consumed by `subscribeVercelAiTracingChannel`). v4/v5/v6 have no such channel, so\n * orchestrion injects `orchestrion:ai:*` channels around the top-level\n * functions (see `orchestrion/config/index.ts`). The injected channels carry only the\n * wrapped call's `{ arguments, result, error }` — NOT v7's normalized `event`\n * object — so this adapter reconstructs an equivalent {@link VercelAiChannelMessage}\n * from each version's argument/result shapes and delegates to the SAME span-building core\n * (`createSpanFromMessage` / `enrichSpanOnEnd`) the v7 subscriber uses, so the\n * emitted spans are identical between v4, v5, v6 and v7. The shared core reads both v4-style\n * (`promptTokens`/`completionTokens`) and v5+-style (`inputTokens`/`outputTokens`) token names.\n *\n * The model call (`languageModelCall` / `generate_content` span) has no\n * injectable definition in `ai`. On v5/v6 we wrap `resolveLanguageModel` (the\n * single chokepoint every model call flows through) and monkey-patch\n * `doGenerate`/`doStream` on the returned model. v4 has no `resolveLanguageModel`\n * — the passed `LanguageModelV1` (`specificationVersion: 'v1'`) is called directly —\n * so we patch its `doGenerate`/`doStream` at the operation start instead (see\n * `buildOperationSpan`), gated on `'v1'` so it never touches v5/v6 models.\n *\n * Tool-call spans differ by version: v6 exposes a per-call `executeToolCall`\n * function orchestrion wraps into its own channel. v4/v5 have no such export (only a\n * batch `executeTools`), so instead we monkey-patch each tool's `execute` from\n * the operation's `tools`. On v6 that patch is inert: `executeToolCall` runs\n * `execute` inside its own tool-call span (the active async context), so the\n * patch sees that span as its parent and skips — only v4/v5 (where the parent is\n * the enclosing `invoke_agent` span) emit the patched span, so v6 never\n * double-counts tool spans.\n */\n\n/** Builds the normalized message for a channel from the wrapped call's first-arg options. */\ntype MessageBuilder = (options: Record<string, unknown>, telemetry: Record<string, unknown>) => VercelAiChannelMessage;\n\n/** A resolved `ai` language model — has `doGenerate`/`doStream` and identity fields. */\ninterface ResolvedModel {\n modelId?: string;\n provider?: string;\n doGenerate?: (...args: unknown[]) => Promise<unknown>;\n doStream?: (...args: unknown[]) => Promise<unknown>;\n}\n\nconst PATCHED = Symbol('SentryVercelAiModelPatched');\nconst TOOL_PATCHED = Symbol('SentryVercelAiToolPatched');\n\n/** A resolved model with our patch bookkeeping (idempotency flag). */\ntype PatchableModel = ResolvedModel & { [PATCHED]?: boolean };\n\n/** A tool definition off an operation's `tools`, with our patch bookkeeping. */\ntype PatchableTool = { execute?: (...args: unknown[]) => unknown; [TOOL_PATCHED]?: boolean };\n\n// Per-operation correlation id. No Date/random (unavailable / non-deterministic) — a counter is enough.\nlet callIdCounter = 0;\nfunction nextCallId(): string {\n return `v6-${++callIdCounter}`;\n}\n\n// The message built on `start` for each operation, keyed by the (stable-identity) channel context, so\n// the `beforeSpanEnd` handler can enrich the span from the settled result and clear the `callId` maps.\nconst messages = new WeakMap<object, VercelAiChannelMessage>();\n// The spans we opened for top-level operations, and each one's `callId`. A model call resolves its\n// parent against this set (so it never mis-attributes to the enclosing `main`/user span) and reads the\n// parent's `callId` so its span can be named after the operation (e.g. `ai.streamText.doStream`).\nconst operationSpans = new WeakSet<Span>();\n// Tool-call spans — only v6's `executeToolCall` channel opens these. The v5 tool-`execute` patch\n// consults this to avoid double-counting: `executeToolCall` runs `execute` inside its span (which is\n// therefore the active parent), so a resolved parent in this set means v6 already spanned the call.\nconst toolCallSpans = new WeakSet<Span>();\nconst callIdBySpan = new WeakMap<Span, string>();\n// The operation's per-call recording flags (`experimental_telemetry.recordInputs/recordOutputs`), keyed by\n// its span. A model call carries no telemetry of its own, so it inherits the enclosing operation's flags —\n// otherwise a per-call `recordInputs: true` would record inputs on the `invoke_agent` span but not on the\n// child `generate_content` span (whose event would fall back to the global default). v7's channel forwards\n// these flags on every event, so this keeps v6 identical.\nconst recordingBySpan = new WeakMap<Span, ReturnType<typeof recording>>();\n// The operation's `experimental_telemetry.metadata`, keyed by its span, so the model-call span records it\n// too. The OTel integration put it on both, but not on tool-call spans.\nconst telemetryMetadataBySpan = new WeakMap<Span, unknown>();\ninterface OperationErrorInfo {\n // The span active when the operation was invoked (its call site, e.g. the enclosing request/`main` span).\n // When an operation's error bubbles out unhandled it reaches the global handler outside any span, so — as\n // the OTel path does — we stamp this span onto the error (in `beforeSpanEnd`) so the unhandled-rejection\n // handler can restore it and correlate the captured error to the operation's trace.\n callSiteSpan: Span | undefined;\n // Whether a thrown tool error bubbles out of the `ai` call (v4). On v4 a tool-`execute` rejection is\n // wrapped in `AI_ToolExecutionError` and re-thrown, so it reaches the user's own error handling (or our\n // global handlers) — capturing it at the tool span too would double-report it, matching how the OTel path\n // leaves v4 tool errors to bubble. On v5 `executeTools` swallows the rejection into `tool-error` content,\n // so it never surfaces and we must capture it ourselves (see `failSpan`).\n toolErrorsBubbleToCaller: boolean;\n}\n// Per-operation error-handling info, keyed by the operation span (see `OperationErrorInfo`).\nconst operationErrorInfoBySpan = new WeakMap<Span, OperationErrorInfo>();\n\n// The `experimental_telemetry` objects we swapped in to suppress `ai`'s native OTel spans (see\n// `suppressNativeTelemetry`). Our skip logic treats `isEnabled === false` as \"user disabled telemetry,\n// emit no span\"; without this set, a call whose options object we already neutralized — or a user-shared\n// telemetry object we replaced on a prior call — would be misread as user-disabled and lose its span.\nconst suppressedTelemetry = new WeakSet<object>();\n\nlet subscribed = false;\n\n/**\n * Subscribe the v6 orchestrion channel adapter. Safe to always call: inert on\n * `ai` >= 7 (those channels are never published) and when orchestrion injection\n * isn't active. Idempotent.\n *\n * `tracingChannel` is the platform-provided factory (the same one passed to\n * `subscribeVercelAiTracingChannel`); `options` pins the recording settings at\n * subscribe time so we never look the integration up per event.\n */\nexport function subscribeVercelAiOrchestrionChannels(\n tracingChannel: VercelAiTracingChannelFactory,\n options: VercelAiChannelOptions = {},\n): void {\n if (subscribed) {\n return;\n }\n subscribed = true;\n\n try {\n bindOperation(tracingChannel, CHANNELS.VERCEL_AI_GENERATE_TEXT, buildTextMessage('generateText'), options);\n bindOperation(tracingChannel, CHANNELS.VERCEL_AI_STREAM_TEXT, buildTextMessage('streamText'), options);\n bindOperation(tracingChannel, CHANNELS.VERCEL_AI_STREAM_OBJECT, buildTextMessage('streamObject'), options);\n bindOperation(tracingChannel, CHANNELS.VERCEL_AI_GENERATE_OBJECT, buildTextMessage('generateObject'), options);\n bindOperation(\n tracingChannel,\n CHANNELS.VERCEL_AI_EMBED,\n (callOptions, telemetry) => ({\n type: 'embed',\n event: {\n callId: nextCallId(),\n ...modelFields(callOptions.model),\n maxRetries: callOptions.maxRetries,\n value: callOptions.value,\n telemetryMetadata: telemetry.metadata,\n ...recording(telemetry),\n },\n }),\n options,\n );\n bindOperation(\n tracingChannel,\n CHANNELS.VERCEL_AI_EMBED_MANY,\n // `embedMany` takes a `values` array (vs `embed`'s single `value`); the shared core reads it as the\n // embeddings input, matching the OTel path's batch `ai.embedMany` span.\n (callOptions, telemetry) => ({\n type: 'embedMany',\n event: {\n callId: nextCallId(),\n ...modelFields(callOptions.model),\n maxRetries: callOptions.maxRetries,\n values: callOptions.values,\n telemetryMetadata: telemetry.metadata,\n ...recording(telemetry),\n },\n }),\n options,\n );\n bindOperation(\n tracingChannel,\n CHANNELS.VERCEL_AI_EXECUTE_TOOL_CALL,\n (callOptions, telemetry) => ({\n type: 'executeTool',\n // v6 carries the tool definitions on the executeToolCall args (a record keyed by name);\n // the shared core reads the matching tool's `description` for the span.\n event: {\n callId: nextCallId(),\n toolCall: callOptions.toolCall,\n tools: callOptions.tools,\n ...recording(telemetry),\n },\n }),\n options,\n );\n subscribeResolveLanguageModel(tracingChannel, CHANNELS.VERCEL_AI_RESOLVE_LANGUAGE_MODEL, options);\n } catch {\n DEBUG_BUILD && debug.log('Vercel AI channel subscription failed.');\n }\n}\n\n/**\n * Bind one operation channel: `getSpan` opens a span from the message reconstructed out of the wrapped\n * call's first argument; `beforeSpanEnd` enriches it from the settled result (tokens, output messages,\n * finish reasons, …) before the helper ends the span.\n *\n * An operation whose `experimental_telemetry.isEnabled` is explicitly `false` is skipped entirely (no\n * span): the orchestrion channel fires regardless of that flag, whereas v7's native `ai:telemetry`\n * channel is simply not published in that case — so we reproduce v7's \"no telemetry → no span\".\n */\nfunction bindOperation(\n tracingChannel: VercelAiTracingChannelFactory,\n channelName: string,\n build: MessageBuilder,\n options: VercelAiChannelOptions,\n): void {\n const channel = tracingChannel<OrchestrionChannelContext>(channelName);\n\n // Build the operation span from the wrapped call's first argument and track it (so a model call can\n // resolve it as its parent). `bindTracingChannelToSpan` calls this once at channel `start` and makes\n // the returned span the active async context for the operation's duration — that active span is what\n // `resolveModelCallParent` reads. It also sets `data._sentrySpan`, so we don't here.\n const buildOperationSpan = (data: TracingChannelPayloadWithSpan<OrchestrionChannelContext>): Span | undefined => {\n const callOptions = isObjectLike(data.arguments[0]) ? data.arguments[0] : {};\n const telemetry = isObjectLike(callOptions.experimental_telemetry) ? callOptions.experimental_telemetry : {};\n // `isEnabled === false` means the user opted out — emit no span. But `isEnabled` is also `false` on\n // the telemetry object we swap in to suppress native spans, so don't mistake our own object for a\n // user opt-out (which would drop the span on a call whose options we already neutralized).\n if (telemetry.isEnabled === false && !suppressedTelemetry.has(telemetry)) {\n return undefined;\n }\n const message = build(callOptions, telemetry);\n // Stop `ai` from emitting its own native OTel spans for this call — we build the equivalent spans\n // from the channels, so the SDK's would be duplicates. Reads above have already captured everything\n // we need off `telemetry`.\n suppressNativeTelemetry(callOptions, telemetry);\n // The span active here is the operation's call site — `bindTracingChannelToSpan` only makes the\n // operation span active *after* this returns — so this is the span we later restore for a bubbled error.\n const callSiteSpan = getActiveSpan();\n const span = createSpanFromMessage(message, options);\n if (span) {\n messages.set(data, message);\n operationSpans.add(span);\n // `'v1'` models are v4 (v5/v6 are `'v2'`), where a thrown tool error bubbles out of the call rather\n // than being swallowed into `tool-error` content — so its tool spans must not self-capture the error.\n const isV4 = isObjectLike(callOptions.model) && callOptions.model.specificationVersion === 'v1';\n operationErrorInfoBySpan.set(span, { callSiteSpan, toolErrorsBubbleToCaller: isV4 });\n // v6's `executeToolCall` span: tracked so the v5 tool-`execute` patch can recognize (and skip)\n // tool calls it runs, since that patch sees this span as its active parent (see `patchToolExecute`).\n if (message.type === 'executeTool') {\n toolCallSpans.add(span);\n }\n const callId = asString(message.event.callId);\n if (callId) {\n callIdBySpan.set(span, callId);\n }\n recordingBySpan.set(span, recording(telemetry));\n telemetryMetadataBySpan.set(span, telemetry.metadata);\n // v5 has no `executeToolCall` channel, so patch each tool's `execute` to emit the tool-call span.\n // Inert on v6 (guarded inside `patchToolExecute` when the parent is `executeToolCall`'s own span).\n if (isObjectLike(callOptions.tools)) {\n patchOperationTools(callOptions.tools, options);\n }\n // v4 has no `resolveLanguageModel` chokepoint — the passed `LanguageModelV1` is called directly — so\n // patch its `doGenerate`/`doStream` here, at the operation start, instead. v5/v6 models are patched via\n // `resolveLanguageModel`, so restricting to v4 keeps this strictly additive and avoids double-patching.\n // Embedding models are also `'v1'` but expose no `doGenerate`/`doStream`, so the patch is a no-op for\n // `embed`/`embedMany`.\n if (isV4) {\n patchModelMethods(callOptions.model as PatchableModel, options);\n }\n }\n return span;\n };\n\n bindTracingChannelToSpan(\n channel,\n (data: TracingChannelPayloadWithSpan<OrchestrionChannelContext>) => buildOperationSpan(data),\n {\n beforeSpanEnd: (span, data) => {\n const message = messages.get(data);\n if (!message) {\n return;\n }\n // The helper's `error` handler already set the span status; only enrich from a successful result.\n if ('error' in data) {\n // The error bubbles out of the `ai` call. If nothing handles it before our global handler, that\n // handler runs outside any span — so stamp the operation's call-site span onto the error, letting\n // the unhandled-rejection handler restore it and correlate the report to this trace. This mirrors\n // the OTel path; it's a no-op when the error is handled earlier (e.g. a framework error handler).\n const callSiteSpan = operationErrorInfoBySpan.get(span)?.callSiteSpan;\n if (callSiteSpan && isObjectLike(data.error)) {\n addNonEnumerableProperty(data.error, '_sentry_active_span', callSiteSpan);\n }\n } else {\n // v6's `executeToolCall` returns the tool result/error object directly, whereas the shared core\n // (matching v7) expects it nested under `output`; wrap it so tool-error detection works.\n message.result = message.type === 'executeTool' ? { output: data.result } : data.result;\n enrichSpanOnEnd(span, message);\n }\n const isStream = message.type === 'streamText' || message.type === 'streamObject';\n runVercelAiSpanEnd(\n span,\n 'error' in data ? { error: data.error } : { response: isStream ? undefined : message.result },\n );\n // A `streamText`/`streamObject` model call runs after this (synchronously-returning) operation's\n // span has already ended, so its `callId` entry must outlive the operation — it's cleared once the\n // model call settles (see `patchModelMethod`). Every other operation can clear here.\n if (!isStream) {\n clearOperationId(message);\n }\n messages.delete(data);\n },\n // `streamText`/`streamObject` return synchronously, so their operation span would otherwise end\n // before the stream drains — losing the aggregate usage/output. Defer the end and await the result's\n // completion promises (`steps`/`text`/…, which resolve on drain), mirroring how v7's channel\n // defers the operation span on the SDK's total-usage promise.\n deferSpanEnd: ({ span, data, end }) => deferStreamTextOperationEnd(span, data, end),\n },\n );\n}\n\n/**\n * Keep a streamed `streamText`/`streamObject` operation span open until the stream drains, then enrich it\n * from the result's completion promises (usage/output/finish reason) and end it. `streamObject` resolves\n * `object` rather than `text`; `getOutputMessages` reads `text`, so a resolved object is stringified into\n * that field. Returns `false` for anything that isn't a streamed result, so the helper ends the span as usual.\n *\n * `streamObject`'s `object` rejects when the output fails schema validation, even though the model call\n * succeeded and `usage` resolved. It's awaited separately so that case still records the token usage on\n * the span before ending it as an error.\n */\nfunction deferStreamTextOperationEnd(\n span: Span,\n data: TracingChannelPayloadWithSpan<OrchestrionChannelContext>,\n end: (error?: unknown) => void,\n): boolean {\n const message = messages.get(data);\n const type = message?.type;\n if (\n !message ||\n (type !== 'streamText' && type !== 'streamObject') ||\n 'error' in data ||\n !isStreamingResult(data.result)\n ) {\n return false;\n }\n\n const streamResult = data.result;\n void (async () => {\n try {\n const [usage, text, objectOutcome, toolCalls, finishReason, response, steps, providerMetadata] =\n await Promise.all([\n streamResult.usage,\n streamResult.text,\n // Settle `object` into an outcome so a validation failure can't short-circuit the usage read.\n type === 'streamObject'\n ? Promise.resolve(streamResult.object).then(\n value => ({ value }),\n (error: unknown) => ({ value: undefined, error }),\n )\n : { value: undefined },\n streamResult.toolCalls,\n streamResult.finishReason,\n streamResult.response,\n streamResult.steps,\n streamResult.providerMetadata,\n ]);\n const result = { usage, toolCalls, finishReason, response, steps, providerMetadata };\n if ('error' in objectOutcome) {\n // The model call itself succeeded, so keep its usage on the span; `beforeSpanEnd` skips\n // enrichment once `end(error)` marks the payload as errored.\n message.result = result;\n enrichSpanOnEnd(span, message);\n end(objectOutcome.error);\n return;\n }\n const object = objectOutcome.value;\n // Feed the resolved values back through the shared enrichment: `beforeSpanEnd` reads `data.result`.\n data.result = { ...result, text: text ?? (isObjectLike(object) ? JSON.stringify(object) : object) };\n end();\n } catch (error) {\n end(error);\n }\n })();\n\n return true;\n}\n\n/**\n * A streamed result exposes its aggregates as promises; a settled result does not. Reading `totalUsage`\n * would create a promise that rejects unobserved when the stream aborts.\n */\nfunction isStreamingResult(result: unknown): result is Record<string, PromiseLike<unknown> | undefined> {\n return isObjectLike(result) && (isThenable(result.steps) || isThenable(result.usage));\n}\n\nfunction isThenable(value: unknown): boolean {\n return isObjectLike(value) && typeof value.then === 'function';\n}\n\n/**\n * Neutralize `ai`'s native OpenTelemetry instrumentation for this call by pointing\n * `experimental_telemetry` at a copy with `isEnabled: false`. `ai`'s `getTracer` then returns its\n * internal no-op tracer, so it never creates (nor sets active) the duplicate `ai.*` spans we'd\n * otherwise have to drop.\n *\n * Only a call that explicitly enabled telemetry emits native spans — otherwise `ai` already uses its\n * no-op tracer, so there's nothing to suppress and we leave the user's options untouched. When\n * `isEnabled === true`, `telemetry` is `callOptions.experimental_telemetry` and `callOptions` is the\n * real first argument the SDK will read, so the reassignment takes effect for the wrapped call. We\n * replace rather than mutate in place, so a telemetry object the user shares across calls keeps its own\n * `isEnabled: true`; the replacement is tracked in `suppressedTelemetry` so our skip logic doesn't\n * later read it back as a user opt-out.\n */\nfunction suppressNativeTelemetry(callOptions: Record<string, unknown>, telemetry: Record<string, unknown>): void {\n if (telemetry.isEnabled !== true) {\n return;\n }\n const suppressed = { ...telemetry, isEnabled: false };\n suppressedTelemetry.add(suppressed);\n callOptions.experimental_telemetry = suppressed;\n}\n\n/**\n * `resolveLanguageModel` returns the model every call flows through. We don't span it — on `end` we\n * monkey-patch `doGenerate`/`doStream` on the returned model so each invocation produces a\n * `languageModelCall` span parented to the enclosing invoke_agent span.\n */\nfunction subscribeResolveLanguageModel(\n tracingChannel: VercelAiTracingChannelFactory,\n channelName: string,\n options: VercelAiChannelOptions,\n): void {\n tracingChannel<OrchestrionChannelContext>(channelName).subscribe({\n end(rawCtx) {\n const ctx = rawCtx;\n if (!isObjectLike(ctx.result)) {\n return;\n }\n // Patch the model's `doGenerate`/`doStream` once. The model call recovers its parent from the\n // active async context at call time (the operation span `bindTracingChannelToSpan` bound), which\n // propagates into the model call for `streamText` too, so there is nothing to capture on the model here.\n patchModelMethods(ctx.result, options);\n },\n start() {\n /* no-op */\n },\n asyncStart() {\n /* no-op */\n },\n asyncEnd() {\n /* no-op */\n },\n error() {\n /* no-op */\n },\n });\n}\n\n/**\n * Pick the invoke_agent span a model call should hang under: the operation span that\n * `bindTracingChannelToSpan` planted as the active async context for the enclosing operation.\n *\n * Because we suppress `ai`'s native telemetry (so it never installs its own span as active), the active\n * span inside `doGenerate`/`doStream` is our operation span. The `operationSpans` gate makes this return\n * `undefined` when the active span isn't one of ours — e.g. telemetry was disabled for the call so we\n * opened no operation span and the active span is the user's enclosing span — so the model call is\n * skipped rather than mis-parented.\n *\n * This covers `generateText`/`embed` (whose model call is awaited inside the operation body) and\n * `streamText` alike — `ai` initiates the stream synchronously within the operation's bound context, so\n * the later `doStream` continuation restores the same active span even though the operation's span has\n * already ended. The per-operation binding also disambiguates concurrent calls that share one model\n * instance (a single mutable slot on the shared model could not — it would hold whichever operation\n * resolved the model last).\n */\nfunction resolveModelCallParent(): Span | undefined {\n const active = getActiveSpan();\n return active && operationSpans.has(active) ? active : undefined;\n}\n\n/**\n * Idempotently patch a resolved model's `doGenerate`/`doStream` so each invocation emits a\n * `languageModelCall` span. Shared by the v5/v6 `resolveLanguageModel` path and the v4 path (which\n * patches the passed model at the operation start, as v4 has no `resolveLanguageModel`).\n */\nfunction patchModelMethods(model: PatchableModel, options: VercelAiChannelOptions): void {\n if (model[PATCHED]) {\n return;\n }\n model[PATCHED] = true;\n patchModelMethod(model, 'doGenerate', options);\n patchModelMethod(model, 'doStream', options);\n}\n\nfunction patchModelMethod(\n model: PatchableModel,\n method: 'doGenerate' | 'doStream',\n options: VercelAiChannelOptions,\n): void {\n const original = model[method];\n if (typeof original !== 'function') {\n return;\n }\n model[method] = function (this: unknown, ...args: unknown[]): Promise<unknown> {\n const parent = resolveModelCallParent();\n // No enclosing operation span (e.g. telemetry disabled for the call) → don't open a model-call span.\n if (!parent) {\n return Promise.resolve(original.apply(this, args));\n }\n\n const callArgs = isObjectLike(args[0]) ? args[0] : {};\n // Carry the operation's `callId` so the shared core can name the span after it\n // (`ai.generateText.doGenerate` / `ai.streamText.doStream`).\n const callId = callIdBySpan.get(parent);\n const message: VercelAiChannelMessage = {\n type: 'languageModelCall',\n event: {\n callId,\n provider: model.provider,\n modelId: model.modelId,\n // v4 nests the tool list under `mode.tools` (the `LanguageModelV1` call shape); v5+ passes a\n // top-level `tools` array. Reading both keeps `tool.definitions` populated on the model-call span.\n tools: callArgs.tools ?? (isObjectLike(callArgs.mode) ? callArgs.mode.tools : undefined),\n messages: callArgs.prompt,\n telemetryMetadata: telemetryMetadataBySpan.get(parent),\n // Inherit the enclosing operation's per-call recording flags so inputs/tools/outputs are recorded on\n // the model-call span whenever they are on the parent `invoke_agent` span.\n ...recordingBySpan.get(parent),\n },\n };\n const span = withActiveSpan(parent, () => createSpanFromMessage(message, options));\n // `languageModelCall` always opens a span; the guard just keeps the wrapper safe if that changes.\n if (!span) {\n return Promise.resolve(original.apply(this, args));\n }\n\n // `streamText` ends its operation span synchronously, so its `callId` entry was deliberately left in\n // place for this later model call; drop it now that we've used it.\n const clearStreamCallId = (): void => {\n if (method === 'doStream' && callId) {\n clearOperationCallId(callId);\n }\n };\n\n // Both the synchronous throw and the async rejection of the model call must end the span with an\n // error status (an `async` `doGenerate`/`doStream` that throws rejects rather than throwing here).\n const failSpan = (error: unknown): never => {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: error instanceof Error ? error.message : 'unknown_error' });\n endSpan(span, { error });\n clearStreamCallId();\n throw error;\n };\n\n try {\n const result = Promise.resolve(original.apply(this, args));\n return result.then(value => {\n // A streamed model call resolves to `{ stream, ... }` before the stream is consumed, so its\n // usage/finish/output only arrive as the stream drains. Tap it (same helper as the v7 path) and\n // defer ending this model-call span until then. The parent `invoke_agent` span is enriched\n // separately by `deferStreamTextOperationEnd`, which awaits the operation's own result promises.\n if (method === 'doStream' && isObjectLike(value) && isReadableStream(value.stream)) {\n value.stream = tapModelCallStream(\n span,\n value.stream,\n final => {\n message.result = { ...value, ...streamedResultToChannelResult(final) };\n enrichSpanOnEnd(span, message);\n endSpan(span, {});\n clearStreamCallId();\n },\n error => {\n span.setStatus({\n code: SPAN_STATUS_ERROR,\n message: error instanceof Error ? error.message : 'unknown_error',\n });\n endSpan(span, { error });\n clearStreamCallId();\n },\n );\n\n return value;\n }\n // `doGenerate` (and any non-stream result) settles with the full result; end here, start/end\n // bracket the call to match the channel timing.\n message.result = value;\n enrichSpanOnEnd(span, message);\n endSpan(span, { response: value });\n clearStreamCallId();\n\n return value;\n }, failSpan);\n } catch (error) {\n return failSpan(error);\n }\n };\n}\n\n/**\n * Patch every executable tool on an operation's `tools` (a record keyed by tool name) so each\n * invocation emits a `gen_ai.execute_tool` span. v5 routes tool execution through the batch\n * `executeTools`, which binds `tool.execute` at call time — so replacing the `execute` property here\n * (before the call runs) is picked up. Tools without an `execute` (client-side tools) are skipped,\n * matching `executeTools`.\n */\nfunction patchOperationTools(tools: Record<string, unknown>, options: VercelAiChannelOptions): void {\n // This runs inside the channel `start` transform (no upstream try/catch), so a throw here would break\n // the user's `ai` call. Instrumentation must never do that — degrade to no tool span instead.\n try {\n for (const [toolName, tool] of Object.entries(tools)) {\n if (isObjectLike(tool)) {\n patchToolExecute(toolName, tool, tools, options);\n }\n }\n } catch {\n DEBUG_BUILD && debug.log('Vercel AI tool patching failed.');\n }\n}\n\nfunction patchToolExecute(\n toolName: string,\n tool: PatchableTool,\n tools: Record<string, unknown>,\n options: VercelAiChannelOptions,\n): void {\n const original = tool.execute;\n if (typeof original !== 'function' || tool[TOOL_PATCHED]) {\n return;\n }\n tool[TOOL_PATCHED] = true;\n tool.execute = function (this: unknown, input: unknown, ...rest: unknown[]): unknown {\n // Skip if there's no enclosing operation span (telemetry disabled for the call), or if that parent\n // is itself a tool-call span — the latter means v6's `executeToolCall` already opened a span for\n // this call and is running `execute` inside it, so spanning again here would double-count. On v5\n // the parent is the enclosing `invoke_agent` operation span, so we proceed.\n const parent = resolveModelCallParent();\n if (!parent || toolCallSpans.has(parent)) {\n return original.apply(this, [input, ...rest]);\n }\n\n // v5 passes `{ toolCallId, messages, abortSignal, ... }` as the second argument to `execute`.\n const callOptions = isObjectLike(rest[0]) ? rest[0] : {};\n const message: VercelAiChannelMessage = {\n type: 'executeTool',\n event: {\n callId: callIdBySpan.get(parent),\n toolCall: { toolName, toolCallId: asString(callOptions.toolCallId), input },\n // The `tools` record (keyed by name) lets the shared core backfill the tool's `description`.\n tools,\n // Inherit the enclosing operation's per-call recording flags so tool inputs/outputs are recorded\n // whenever they are on the parent `invoke_agent` span.\n ...recordingBySpan.get(parent),\n },\n };\n const span = withActiveSpan(parent, () => createSpanFromMessage(message, options));\n // `executeTool` always opens a span; the guard just keeps the wrapper safe if that changes.\n if (!span) {\n return original.apply(this, [input, ...rest]);\n }\n\n // v5's `executeTools` catches a thrown tool error and turns it into `tool-error` content rather than\n // rejecting, so the user never sees a rejection — we must capture it here. On v4 the rejection bubbles\n // out of the call and reaches the user's error handling (or our global handlers), so we only mark the\n // span and leave the capture to them, avoiding a duplicate report. Rethrow either way so `executeTools`\n // still produces its `tool-error` result (v5) and the rejection propagates (v4).\n const failSpan = (error: unknown): never => {\n if (operationErrorInfoBySpan.get(parent)?.toolErrorsBubbleToCaller) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: error instanceof Error ? error.message : 'tool_error' });\n } else {\n captureToolError(span, message, error);\n }\n endSpan(span, { error });\n throw error;\n };\n\n try {\n const result = Promise.resolve(original.apply(this, [input, ...rest]));\n return result.then(value => {\n // The shared core (matching v6/v7) expects the tool result nested under `output`.\n message.result = { output: value };\n enrichSpanOnEnd(span, message);\n endSpan(span, { response: message.result });\n return value;\n }, failSpan);\n } catch (error) {\n return failSpan(error);\n }\n };\n}\n\nfunction endSpan(span: Span, result: GenAiSpanResult<unknown>): void {\n runVercelAiSpanEnd(span, result);\n span.end();\n}\n\nfunction buildTextMessage(type: 'generateText' | 'streamText' | 'streamObject' | 'generateObject'): MessageBuilder {\n return (options, telemetry) => ({\n type,\n event: {\n callId: nextCallId(),\n operationId: `ai.${type}`,\n functionId: asString(telemetry.functionId),\n ...modelFields(options.model),\n maxRetries: options.maxRetries,\n // The `ai` SDK takes the system prompt as a top-level `system` option (all of v4/v5/v6); the\n // shared core lifts `event.instructions` into the system-instructions attribute, matching v7's\n // native channel (which carries it as a distinct field rather than inside the messages array).\n instructions: options.system,\n // Normalize to the message-array shape the shared core (and v7's channel) expects: a bare string\n // `prompt` becomes a single user message, matching the SDK's own normalization.\n messages: normalizePromptMessages(options),\n // v7's native start event carries `providerOptions`; the shared core reads the OpenAI\n // Conversations API id from it.\n providerOptions: options.providerOptions,\n telemetryMetadata: telemetry.metadata,\n ...recording(telemetry),\n },\n });\n}\n\nfunction normalizePromptMessages(options: Record<string, unknown>): unknown {\n if (Array.isArray(options.messages)) {\n return options.messages;\n }\n if (typeof options.prompt === 'string') {\n return [{ role: 'user', content: options.prompt }];\n }\n return options.messages ?? options.prompt;\n}\n\nfunction recording(telemetry: Record<string, unknown>): { recordInputs: unknown; recordOutputs: unknown } {\n // Match the OTel integration's per-call default: an explicit `recordInputs`/`recordOutputs` wins, but a\n // call that merely enables telemetry (`isEnabled: true`, no explicit flags) defaults both to `true`.\n // Unlike v7's native `ai:telemetry` channel, the orchestrion channels expose `isEnabled`, so — as noted\n // in `resolveRecording` — we CAN reproduce that default here (the native-channel subscriber cannot).\n const enabledDefault = telemetry.isEnabled === true ? true : undefined;\n return {\n recordInputs: telemetry.recordInputs ?? enabledDefault,\n recordOutputs: telemetry.recordOutputs ?? enabledDefault,\n };\n}\n\nfunction modelFields(model: unknown): { provider?: string; modelId?: string } {\n return { provider: modelField(model, 'provider'), modelId: modelField(model, 'modelId') };\n}\n\nfunction modelField(model: unknown, field: 'modelId' | 'provider'): string | undefined {\n return isObjectLike(model) ? asString(model[field]) : undefined;\n}\n"],"mappings":";;;;;;;;AAwEA,MAAM,UAAU,OAAO,4BAA4B;AACnD,MAAM,eAAe,OAAO,2BAA2B;AASvD,IAAI,gBAAgB;AACpB,SAAS,aAAqB;CAC5B,OAAO,MAAM,EAAE;AACjB;AAIA,MAAM,2BAAW,IAAI,QAAwC;AAI7D,MAAM,iCAAiB,IAAI,QAAc;AAIzC,MAAM,gCAAgB,IAAI,QAAc;AACxC,MAAM,+BAAe,IAAI,QAAsB;AAM/C,MAAM,kCAAkB,IAAI,QAA4C;AAGxE,MAAM,0CAA0B,IAAI,QAAuB;AAe3D,MAAM,2CAA2B,IAAI,QAAkC;AAMvE,MAAM,sCAAsB,IAAI,QAAgB;AAEhD,IAAI,aAAa;;;;;;;;;;AAWjB,SAAgB,qCACd,gBACA,UAAkC,CAAC,GAC7B;CACN,IAAI,YACF;CAEF,aAAa;CAEb,IAAI;EACF,cAAc,gBAAgB,SAAS,yBAAyB,iBAAiB,cAAc,GAAG,OAAO;EACzG,cAAc,gBAAgB,SAAS,uBAAuB,iBAAiB,YAAY,GAAG,OAAO;EACrG,cAAc,gB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
|
import { prismaChannels } from "./config/prisma.js";
|
|
39
39
|
import { redisChannels } from "./config/redis.js";
|
|
40
40
|
import { remixChannels } from "./config/remix.js";
|
|
41
|
+
import { tanstackAiChannels } from "./config/tanstack-ai.js";
|
|
41
42
|
import { tediousChannels } from "./config/tedious.js";
|
|
42
43
|
import { togetherAiChannels } from "./config/together-ai.js";
|
|
43
44
|
import { typesafeChannels } from "./config/typesafe.js";
|
|
@@ -100,6 +101,7 @@ const CHANNELS = {
|
|
|
100
101
|
...prismaChannels,
|
|
101
102
|
...redisChannels,
|
|
102
103
|
...remixChannels,
|
|
104
|
+
...tanstackAiChannels,
|
|
103
105
|
...tediousChannels,
|
|
104
106
|
...togetherAiChannels,
|
|
105
107
|
...typesafeChannels,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"channels.js","names":[],"sources":["../../../src/orchestrion/channels.ts"],"sourcesContent":["import { amqplibChannels } from './config/amqplib';\nimport { anthropicAiChannels } from './config/anthropic-ai';\nimport { awsSdkChannels } from './config/aws-sdk';\nimport { clickhouseChannels } from './config/clickhouse';\nimport { cronChannels } from './config/cron';\nimport { dataloaderChannels } from './config/dataloader';\nimport { expressChannels } from './config/express';\nimport { firebaseChannels } from './config/firebase';\nimport { genericPoolChannels } from './config/generic-pool';\nimport { googleGenAiChannels } from './config/google-genai';\nimport { graphqlChannels } from './config/graphql';\nimport { groqChannels } from './config/groq';\nimport { hapiChannels } from './config/hapi';\nimport { honoChannels } from './config/hono';\nimport { ioredisChannels } from './config/ioredis';\nimport { kafkajsChannels } from './config/kafkajs';\nimport { knexChannels } from './config/knex';\nimport { koaChannels } from './config/koa';\nimport { langchainChannels } from './config/langchain';\nimport { langgraphChannels } from './config/langgraph';\nimport { lruMemoizerChannels } from './config/lru-memoizer';\nimport { mastraChannels } from './config/mastra';\nimport { mcpServerChannels } from './config/mcp-server';\nimport { mistralChannels } from './config/mistral';\nimport { mongodbChannels } from './config/mongodb';\nimport { mongooseChannels } from './config/mongoose';\nimport { mysql2Channels } from './config/mysql2';\nimport { mysqlChannels } from './config/mysql';\nimport { neonChannels } from './config/neon';\nimport { nestjsChannels } from './config/nestjs';\nimport { nodeCronChannels } from './config/node-cron';\nimport { nodeScheduleChannels } from './config/node-schedule';\nimport { openaiChannels } from './config/openai';\nimport { pgChannels } from './config/pg';\nimport { piAiChannels } from './config/pi-ai';\nimport { piDurableChannels } from './config/pi-durable';\nimport { postgresJsChannels } from './config/postgres';\nimport { prismaChannels } from './config/prisma';\nimport { redisChannels } from './config/redis';\nimport { remixChannels } from './config/remix';\nimport { tediousChannels } from './config/tedious';\nimport { togetherAiChannels } from './config/together-ai';\nimport { typesafeChannels } from './config/typesafe';\nimport { vercelAiChannels } from './config/vercel-ai';\n\n/**\n * Fully-qualified `diagnostics_channel` names that orchestrion publishes to.\n *\n * Orchestrion's transform always prefixes the configured `channelName` with\n * `orchestrion:${module.name}:`. So a config of\n * `{ channelName: 'query', module: { name: 'mysql' } }`\n * publishes to `orchestrion:mysql:query`.\n *\n * Subscribers (`integrations/<lib>/tracing-channel.ts`) consume the full\n * prefixed string from this map; the config files set only the unprefixed\n * suffix in `channelName`. Keeping both pieces in one file is what guarantees\n * they don't drift apart and silently stop firing.\n *\n * Kept sorted alphabetically by module so concurrent additions insert at different\n * points rather than all appending to the end (fewer merge conflicts).\n */\nexport const CHANNELS = {\n ...amqplibChannels,\n ...anthropicAiChannels,\n ...awsSdkChannels,\n ...clickhouseChannels,\n ...cronChannels,\n ...dataloaderChannels,\n ...expressChannels,\n ...firebaseChannels,\n ...genericPoolChannels,\n ...googleGenAiChannels,\n ...graphqlChannels,\n ...groqChannels,\n ...hapiChannels,\n ...honoChannels,\n ...ioredisChannels,\n ...kafkajsChannels,\n ...knexChannels,\n ...koaChannels,\n ...langchainChannels,\n ...langgraphChannels,\n ...lruMemoizerChannels,\n ...mastraChannels,\n ...mcpServerChannels,\n ...mistralChannels,\n ...mongodbChannels,\n ...mongooseChannels,\n ...mysql2Channels,\n ...mysqlChannels,\n ...neonChannels,\n ...nestjsChannels,\n ...nodeCronChannels,\n ...nodeScheduleChannels,\n ...openaiChannels,\n ...pgChannels,\n ...piAiChannels,\n ...piDurableChannels,\n ...postgresJsChannels,\n ...prismaChannels,\n ...redisChannels,\n ...remixChannels,\n ...tediousChannels,\n ...togetherAiChannels,\n ...typesafeChannels,\n ...vercelAiChannels,\n} as const;\n\nexport type ChannelName = (typeof CHANNELS)[keyof typeof CHANNELS];\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"channels.js","names":[],"sources":["../../../src/orchestrion/channels.ts"],"sourcesContent":["import { amqplibChannels } from './config/amqplib';\nimport { anthropicAiChannels } from './config/anthropic-ai';\nimport { awsSdkChannels } from './config/aws-sdk';\nimport { clickhouseChannels } from './config/clickhouse';\nimport { cronChannels } from './config/cron';\nimport { dataloaderChannels } from './config/dataloader';\nimport { expressChannels } from './config/express';\nimport { firebaseChannels } from './config/firebase';\nimport { genericPoolChannels } from './config/generic-pool';\nimport { googleGenAiChannels } from './config/google-genai';\nimport { graphqlChannels } from './config/graphql';\nimport { groqChannels } from './config/groq';\nimport { hapiChannels } from './config/hapi';\nimport { honoChannels } from './config/hono';\nimport { ioredisChannels } from './config/ioredis';\nimport { kafkajsChannels } from './config/kafkajs';\nimport { knexChannels } from './config/knex';\nimport { koaChannels } from './config/koa';\nimport { langchainChannels } from './config/langchain';\nimport { langgraphChannels } from './config/langgraph';\nimport { lruMemoizerChannels } from './config/lru-memoizer';\nimport { mastraChannels } from './config/mastra';\nimport { mcpServerChannels } from './config/mcp-server';\nimport { mistralChannels } from './config/mistral';\nimport { mongodbChannels } from './config/mongodb';\nimport { mongooseChannels } from './config/mongoose';\nimport { mysql2Channels } from './config/mysql2';\nimport { mysqlChannels } from './config/mysql';\nimport { neonChannels } from './config/neon';\nimport { nestjsChannels } from './config/nestjs';\nimport { nodeCronChannels } from './config/node-cron';\nimport { nodeScheduleChannels } from './config/node-schedule';\nimport { openaiChannels } from './config/openai';\nimport { pgChannels } from './config/pg';\nimport { piAiChannels } from './config/pi-ai';\nimport { piDurableChannels } from './config/pi-durable';\nimport { postgresJsChannels } from './config/postgres';\nimport { prismaChannels } from './config/prisma';\nimport { redisChannels } from './config/redis';\nimport { remixChannels } from './config/remix';\nimport { tanstackAiChannels } from './config/tanstack-ai';\nimport { tediousChannels } from './config/tedious';\nimport { togetherAiChannels } from './config/together-ai';\nimport { typesafeChannels } from './config/typesafe';\nimport { vercelAiChannels } from './config/vercel-ai';\n\n/**\n * Fully-qualified `diagnostics_channel` names that orchestrion publishes to.\n *\n * Orchestrion's transform always prefixes the configured `channelName` with\n * `orchestrion:${module.name}:`. So a config of\n * `{ channelName: 'query', module: { name: 'mysql' } }`\n * publishes to `orchestrion:mysql:query`.\n *\n * Subscribers (`integrations/<lib>/tracing-channel.ts`) consume the full\n * prefixed string from this map; the config files set only the unprefixed\n * suffix in `channelName`. Keeping both pieces in one file is what guarantees\n * they don't drift apart and silently stop firing.\n *\n * Kept sorted alphabetically by module so concurrent additions insert at different\n * points rather than all appending to the end (fewer merge conflicts).\n */\nexport const CHANNELS = {\n ...amqplibChannels,\n ...anthropicAiChannels,\n ...awsSdkChannels,\n ...clickhouseChannels,\n ...cronChannels,\n ...dataloaderChannels,\n ...expressChannels,\n ...firebaseChannels,\n ...genericPoolChannels,\n ...googleGenAiChannels,\n ...graphqlChannels,\n ...groqChannels,\n ...hapiChannels,\n ...honoChannels,\n ...ioredisChannels,\n ...kafkajsChannels,\n ...knexChannels,\n ...koaChannels,\n ...langchainChannels,\n ...langgraphChannels,\n ...lruMemoizerChannels,\n ...mastraChannels,\n ...mcpServerChannels,\n ...mistralChannels,\n ...mongodbChannels,\n ...mongooseChannels,\n ...mysql2Channels,\n ...mysqlChannels,\n ...neonChannels,\n ...nestjsChannels,\n ...nodeCronChannels,\n ...nodeScheduleChannels,\n ...openaiChannels,\n ...pgChannels,\n ...piAiChannels,\n ...piDurableChannels,\n ...postgresJsChannels,\n ...prismaChannels,\n ...redisChannels,\n ...remixChannels,\n ...tanstackAiChannels,\n ...tediousChannels,\n ...togetherAiChannels,\n ...typesafeChannels,\n ...vercelAiChannels,\n} as const;\n\nexport type ChannelName = (typeof CHANNELS)[keyof typeof CHANNELS];\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8DA,MAAa,WAAW;CACtB,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;AACL"}
|
|
@@ -41,6 +41,7 @@ import { prismaConfig } from "./prisma.js";
|
|
|
41
41
|
import { redisConfig } from "./redis.js";
|
|
42
42
|
import { remixChannels, remixConfig } from "./remix.js";
|
|
43
43
|
import { remixV3Channels, remixV3Config } from "./remix-v3.js";
|
|
44
|
+
import { tanstackAiConfig } from "./tanstack-ai.js";
|
|
44
45
|
import { tediousConfig } from "./tedious.js";
|
|
45
46
|
import { togetherAiConfig } from "./together-ai.js";
|
|
46
47
|
import { typesafeConfig } from "./typesafe.js";
|
|
@@ -104,6 +105,7 @@ const SENTRY_INSTRUMENTATIONS = [
|
|
|
104
105
|
...redisConfig,
|
|
105
106
|
...remixConfig,
|
|
106
107
|
...remixV3Config,
|
|
108
|
+
...tanstackAiConfig,
|
|
107
109
|
...tediousConfig,
|
|
108
110
|
...togetherAiConfig,
|
|
109
111
|
...typesafeConfig,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../../src/orchestrion/config/index.ts"],"sourcesContent":["import type { InstrumentationConfig } from '../apmTypes';\n\nimport { uniq } from '@sentry/core';\n\nimport { awsSdkConfig } from './aws-sdk';\nimport { amqplibConfig } from './amqplib';\nimport { anthropicAiConfig } from './anthropic-ai';\nimport { clickhouseConfig } from './clickhouse';\nimport { cronConfig } from './cron';\nimport { dataloaderConfig } from './dataloader';\nimport { expressConfig } from './express';\nimport { firebaseConfig } from './firebase';\nimport { genericPoolConfig } from './generic-pool';\nimport { googleGenAiConfig } from './google-genai';\nimport { graphqlConfig } from './graphql';\nimport { groqConfig } from './groq';\nimport { hapiConfig } from './hapi';\nimport { honoConfig } from './hono';\nimport { ioredisConfig } from './ioredis';\nimport { kafkajsConfig } from './kafkajs';\nimport { knexConfig } from './knex';\nimport { koaConfig } from './koa';\nimport { langchainConfig } from './langchain';\nimport { langgraphConfig } from './langgraph';\nimport { lruMemoizerConfig } from './lru-memoizer';\nimport { flueConfig } from './flue';\nimport { mastraConfig } from './mastra';\nimport { piAiConfig } from './pi-ai';\nimport { piDurableConfig } from './pi-durable';\nimport { mcpServerConfig } from './mcp-server';\nimport { mistralConfig } from './mistral';\nimport { mongodbConfig } from './mongodb';\nimport { mongooseConfig } from './mongoose';\nimport { mysql2Config } from './mysql2';\nimport { mysqlConfig } from './mysql';\nimport { neonConfig } from './neon';\nimport { nestjsConfig } from './nestjs';\nimport { nitroConfig } from './nitro';\nimport { nodeCronConfig } from './node-cron';\nimport { nodeScheduleConfig } from './node-schedule';\nimport { openaiConfig } from './openai';\nimport { pgConfig } from './pg';\nimport { postgresJsConfig } from './postgres';\nimport { prismaConfig } from './prisma';\nimport { redisConfig } from './redis';\nimport { remixConfig } from './remix';\nimport { remixV3Config } from './remix-v3';\nimport { tediousConfig } from './tedious';\nimport { togetherAiConfig } from './together-ai';\nimport { typesafeConfig } from './typesafe';\nimport { vercelAiConfig } from './vercel-ai';\n// Kept sorted alphabetically by module so concurrent additions insert at different\n// points rather than all appending to the end (fewer merge conflicts).\n\n/**\n * The orchestrion code-transform configs. Every instrumentable library is here\n * so the transform is all-or-nothing: whenever orchestrion is enabled, all of\n * these are injected. The channel LISTENERS may live elsewhere (e.g. the NestJS\n * one lives in `@sentry/nestjs`), but the config that decides what gets\n * transformed is centralized here.\n *\n * This module MUST stay pure, stateless data. It is loaded in more than one realm\n * at once — the build-time bundler plugin inlines it into the server chunk, while\n * `@sentry/server-runtime-injection`'s external `register` loads its own copy from\n * `node_modules` at runtime. Two identical, side-effect-free arrays are harmless;\n * any module-level mutable state here would silently diverge between those copies.\n */\nexport const SENTRY_INSTRUMENTATIONS: InstrumentationConfig[] = [\n ...amqplibConfig,\n ...anthropicAiConfig,\n ...awsSdkConfig,\n ...clickhouseConfig,\n ...cronConfig,\n ...dataloaderConfig,\n ...expressConfig,\n ...firebaseConfig,\n ...genericPoolConfig,\n ...googleGenAiConfig,\n ...graphqlConfig,\n ...groqConfig,\n ...hapiConfig,\n ...honoConfig,\n ...ioredisConfig,\n ...kafkajsConfig,\n ...knexConfig,\n ...koaConfig,\n ...langchainConfig,\n ...langgraphConfig,\n ...lruMemoizerConfig,\n ...flueConfig,\n ...mastraConfig,\n ...mcpServerConfig,\n ...mistralConfig,\n ...mongodbConfig,\n ...mongooseConfig,\n ...mysql2Config,\n ...mysqlConfig,\n ...neonConfig,\n ...nestjsConfig,\n ...nitroConfig,\n ...nodeCronConfig,\n ...nodeScheduleConfig,\n ...openaiConfig,\n ...pgConfig,\n ...piAiConfig,\n ...piDurableConfig,\n ...postgresJsConfig,\n ...prismaConfig,\n ...redisConfig,\n ...remixConfig,\n ...remixV3Config,\n ...tediousConfig,\n ...togetherAiConfig,\n ...typesafeConfig,\n ...vercelAiConfig,\n];\n\n/**\n * The subset of {@link SENTRY_INSTRUMENTATIONS} the RUNTIME loader\n * (`@sentry/server-runtime-injection`'s `register`, reached via `--import` or\n * `Sentry.init()`) can actually apply.\n *\n * Registration-only configs (native-channel libraries such as `ai` v7,\n * `ioredis`, `@redis/client`, `mysql2`, `mongoose`) carry the custom\n * `MODULE_REGISTRATION_TRANSFORM` operator. That operator is wired into the\n * BUNDLER plugins only (see `orchestrion/bundler/moduleInjectedTransform.ts`,\n * applied via `bundler/options.ts`'s `customTransforms`); the runtime loader's\n * `initialize()` receives no custom transforms. Attempting one of these at\n * runtime therefore throws `TypeError: transform is not a function`, which the\n * loader misreports as the always-on \"`@sentry/server-runtime-injection` was\n * bundled ... loads uninstrumented\" warning even though nothing is wrong.\n *\n * Excluding them at runtime is correct, not just a way to silence the warning:\n * these libraries publish their own tracing channels, and their integrations\n * subscribe through `setupOnce()` / `waitForTracingChannelBinding`,\n * independently of the module-injected snippet. That snippet only fires\n * `orchestrion.module-injected`, which drives the `setup()` /\n * `invokeOrchestrionInstrumentation` path; for a native-channel version that\n * path subscribes to the injected `orchestrion:*` channels the library never\n * publishes — a no-op. So running these at runtime would add no spans. The\n * snippet earns its keep only on the BUNDLER path — notably bundler-only SDKs\n * (e.g. `@sentry/cloudflare`) that discover a loaded module via that event to\n * instantiate its integration factory. `@sentry/node` registers its\n * integrations statically, so it does not need it.\n */\nexport const SENTRY_RUNTIME_INSTRUMENTATIONS: InstrumentationConfig[] = SENTRY_INSTRUMENTATIONS.filter(\n config => !config.transform,\n);\n\n/**\n * The unique set of package names instrumented by `SENTRY_INSTRUMENTATIONS`\n * merged with any caller-provided `instrumentations` (e.g. `['mysql']`).\n *\n * Bundler plugins MUST ensure these are actually bundled rather than\n * externalized: an externalized dependency is resolved from `node_modules` at\n * runtime and never passes through the code transform's `onLoad`, so its\n * diagnostics_channel calls are silently never injected. This includes a\n * plugin's custom `instrumentations`, otherwise those extra packages can stay\n * externalized and their transform never runs.\n */\nexport function instrumentedModuleNames(instrumentations: InstrumentationConfig[] = []): string[] {\n return [\n ...uniq([...SENTRY_INSTRUMENTATIONS, ...instrumentations].map(i => i.module.name)),\n // Additional things that need to be bundled but are not covered by the above\n // Remix needs to bundle this so @remix-run/server-runtime is _also_ bundled\n '@remix-run/node',\n ];\n}\n\n/** The instrumented module names from the default Sentry config, with no custom additions. */\nexport const INSTRUMENTED_MODULE_NAMES: string[] = instrumentedModuleNames();\n\n/**\n * The package names the SDK instruments through the orchestrion module transform (its\n * diagnostics-channel injection). Pass these to a server bundler's \"keep external\" option so the\n * packages load through Node's module loader — the only path the transform can hook — instead of\n * being inlined into the server bundle. A framework that has no Sentry bundler plugin (e.g. eve, via\n * `build.externalDependencies`) is the main caller; a listed package the app doesn't use is simply\n * ignored by the bundler.\n *\n * Unlike {@link INSTRUMENTED_MODULE_NAMES}, this is the plain instrumented set with no bundler-only\n * additions — those force a helper package to be *bundled*, the opposite of keeping it external.\n */\nexport function getInstrumentedModuleNames(): string[] {\n return uniq(SENTRY_INSTRUMENTATIONS.map(instrumentation => instrumentation.module.name));\n}\n\n/**\n * Returns `external` with any instrumented packages removed, so a bundler that\n * uses an \"external\" denylist (esbuild, Bun, Rollup) still bundles — and thus\n * transforms — them. Matches an exact package name (`'mysql'`) or a subpath\n * (`'mysql/lib/...'`); wildcard/other patterns are left untouched. `undefined`\n * is returned unchanged.\n *\n * Pass `moduleNames` from `instrumentedModuleNames(options.instrumentations)` so\n * custom instrumentations are stripped too; it defaults to the Sentry config\n * list. (Vite uses an `ssr.noExternal` allowlist instead, so it consumes\n * `instrumentedModuleNames` directly rather than this helper.)\n */\nexport function withoutInstrumentedExternals(\n external: readonly string[] | undefined,\n moduleNames: string[] = INSTRUMENTED_MODULE_NAMES,\n): string[] | undefined {\n if (!external) {\n return undefined;\n }\n return external.filter(entry => !moduleNames.some(name => entry === name || entry.startsWith(`${name}/`)));\n}\n\n// This is exported so that the nestjs package can use it to subscribe to the channels.\nexport { nestjsChannels } from './nestjs';\n// This is exported so that the remix package can use it to subscribe to the channels.\nexport { remixChannels } from './remix';\n// Exported so the remix package can subscribe to the Remix 3 channels, and hand only these configs to\n// the browser transform.\nexport { remixV3Channels, remixV3Config } from './remix-v3';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmEA,MAAa,0BAAmD;CAC9D,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;AACL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,MAAa,kCAA2D,wBAAwB,QAC9F,WAAU,CAAC,OAAO,SACpB;;;;;;;;;;;;AAaA,SAAgB,wBAAwB,mBAA4C,CAAC,GAAa;CAChG,OAAO,CACL,GAAG,KAAK,CAAC,GAAG,yBAAyB,GAAG,gBAAgB,CAAC,CAAC,KAAI,MAAK,EAAE,OAAO,IAAI,CAAC,GAGjF,iBACF;AACF;;AAGA,MAAa,4BAAsC,wBAAwB;;;;;;;;;;;;AAa3E,SAAgB,6BAAuC;CACrD,OAAO,KAAK,wBAAwB,KAAI,oBAAmB,gBAAgB,OAAO,IAAI,CAAC;AACzF;;;;;;;;;;;;;AAcA,SAAgB,6BACd,UACA,cAAwB,2BACF;CACtB,IAAI,CAAC,UACH;CAEF,OAAO,SAAS,QAAO,UAAS,CAAC,YAAY,MAAK,SAAQ,UAAU,QAAQ,MAAM,WAAW,GAAG,KAAK,EAAE,CAAC,CAAC;AAC3G"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../../src/orchestrion/config/index.ts"],"sourcesContent":["import type { InstrumentationConfig } from '../apmTypes';\n\nimport { uniq } from '@sentry/core';\n\nimport { awsSdkConfig } from './aws-sdk';\nimport { amqplibConfig } from './amqplib';\nimport { anthropicAiConfig } from './anthropic-ai';\nimport { clickhouseConfig } from './clickhouse';\nimport { cronConfig } from './cron';\nimport { dataloaderConfig } from './dataloader';\nimport { expressConfig } from './express';\nimport { firebaseConfig } from './firebase';\nimport { genericPoolConfig } from './generic-pool';\nimport { googleGenAiConfig } from './google-genai';\nimport { graphqlConfig } from './graphql';\nimport { groqConfig } from './groq';\nimport { hapiConfig } from './hapi';\nimport { honoConfig } from './hono';\nimport { ioredisConfig } from './ioredis';\nimport { kafkajsConfig } from './kafkajs';\nimport { knexConfig } from './knex';\nimport { koaConfig } from './koa';\nimport { langchainConfig } from './langchain';\nimport { langgraphConfig } from './langgraph';\nimport { lruMemoizerConfig } from './lru-memoizer';\nimport { flueConfig } from './flue';\nimport { mastraConfig } from './mastra';\nimport { piAiConfig } from './pi-ai';\nimport { piDurableConfig } from './pi-durable';\nimport { mcpServerConfig } from './mcp-server';\nimport { mistralConfig } from './mistral';\nimport { mongodbConfig } from './mongodb';\nimport { mongooseConfig } from './mongoose';\nimport { mysql2Config } from './mysql2';\nimport { mysqlConfig } from './mysql';\nimport { neonConfig } from './neon';\nimport { nestjsConfig } from './nestjs';\nimport { nitroConfig } from './nitro';\nimport { nodeCronConfig } from './node-cron';\nimport { nodeScheduleConfig } from './node-schedule';\nimport { openaiConfig } from './openai';\nimport { pgConfig } from './pg';\nimport { postgresJsConfig } from './postgres';\nimport { prismaConfig } from './prisma';\nimport { redisConfig } from './redis';\nimport { remixConfig } from './remix';\nimport { remixV3Config } from './remix-v3';\nimport { tanstackAiConfig } from './tanstack-ai';\nimport { tediousConfig } from './tedious';\nimport { togetherAiConfig } from './together-ai';\nimport { typesafeConfig } from './typesafe';\nimport { vercelAiConfig } from './vercel-ai';\n// Kept sorted alphabetically by module so concurrent additions insert at different\n// points rather than all appending to the end (fewer merge conflicts).\n\n/**\n * The orchestrion code-transform configs. Every instrumentable library is here\n * so the transform is all-or-nothing: whenever orchestrion is enabled, all of\n * these are injected. The channel LISTENERS may live elsewhere (e.g. the NestJS\n * one lives in `@sentry/nestjs`), but the config that decides what gets\n * transformed is centralized here.\n *\n * This module MUST stay pure, stateless data. It is loaded in more than one realm\n * at once — the build-time bundler plugin inlines it into the server chunk, while\n * `@sentry/server-runtime-injection`'s external `register` loads its own copy from\n * `node_modules` at runtime. Two identical, side-effect-free arrays are harmless;\n * any module-level mutable state here would silently diverge between those copies.\n */\nexport const SENTRY_INSTRUMENTATIONS: InstrumentationConfig[] = [\n ...amqplibConfig,\n ...anthropicAiConfig,\n ...awsSdkConfig,\n ...clickhouseConfig,\n ...cronConfig,\n ...dataloaderConfig,\n ...expressConfig,\n ...firebaseConfig,\n ...genericPoolConfig,\n ...googleGenAiConfig,\n ...graphqlConfig,\n ...groqConfig,\n ...hapiConfig,\n ...honoConfig,\n ...ioredisConfig,\n ...kafkajsConfig,\n ...knexConfig,\n ...koaConfig,\n ...langchainConfig,\n ...langgraphConfig,\n ...lruMemoizerConfig,\n ...flueConfig,\n ...mastraConfig,\n ...mcpServerConfig,\n ...mistralConfig,\n ...mongodbConfig,\n ...mongooseConfig,\n ...mysql2Config,\n ...mysqlConfig,\n ...neonConfig,\n ...nestjsConfig,\n ...nitroConfig,\n ...nodeCronConfig,\n ...nodeScheduleConfig,\n ...openaiConfig,\n ...pgConfig,\n ...piAiConfig,\n ...piDurableConfig,\n ...postgresJsConfig,\n ...prismaConfig,\n ...redisConfig,\n ...remixConfig,\n ...remixV3Config,\n ...tanstackAiConfig,\n ...tediousConfig,\n ...togetherAiConfig,\n ...typesafeConfig,\n ...vercelAiConfig,\n];\n\n/**\n * The subset of {@link SENTRY_INSTRUMENTATIONS} the RUNTIME loader\n * (`@sentry/server-runtime-injection`'s `register`, reached via `--import` or\n * `Sentry.init()`) can actually apply.\n *\n * Registration-only configs (native-channel libraries such as `ai` v7,\n * `ioredis`, `@redis/client`, `mysql2`, `mongoose`) carry the custom\n * `MODULE_REGISTRATION_TRANSFORM` operator. That operator is wired into the\n * BUNDLER plugins only (see `orchestrion/bundler/moduleInjectedTransform.ts`,\n * applied via `bundler/options.ts`'s `customTransforms`); the runtime loader's\n * `initialize()` receives no custom transforms. Attempting one of these at\n * runtime therefore throws `TypeError: transform is not a function`, which the\n * loader misreports as the always-on \"`@sentry/server-runtime-injection` was\n * bundled ... loads uninstrumented\" warning even though nothing is wrong.\n *\n * Excluding them at runtime is correct, not just a way to silence the warning:\n * these libraries publish their own tracing channels, and their integrations\n * subscribe through `setupOnce()` / `waitForTracingChannelBinding`,\n * independently of the module-injected snippet. That snippet only fires\n * `orchestrion.module-injected`, which drives the `setup()` /\n * `invokeOrchestrionInstrumentation` path; for a native-channel version that\n * path subscribes to the injected `orchestrion:*` channels the library never\n * publishes — a no-op. So running these at runtime would add no spans. The\n * snippet earns its keep only on the BUNDLER path — notably bundler-only SDKs\n * (e.g. `@sentry/cloudflare`) that discover a loaded module via that event to\n * instantiate its integration factory. `@sentry/node` registers its\n * integrations statically, so it does not need it.\n */\nexport const SENTRY_RUNTIME_INSTRUMENTATIONS: InstrumentationConfig[] = SENTRY_INSTRUMENTATIONS.filter(\n config => !config.transform,\n);\n\n/**\n * The unique set of package names instrumented by `SENTRY_INSTRUMENTATIONS`\n * merged with any caller-provided `instrumentations` (e.g. `['mysql']`).\n *\n * Bundler plugins MUST ensure these are actually bundled rather than\n * externalized: an externalized dependency is resolved from `node_modules` at\n * runtime and never passes through the code transform's `onLoad`, so its\n * diagnostics_channel calls are silently never injected. This includes a\n * plugin's custom `instrumentations`, otherwise those extra packages can stay\n * externalized and their transform never runs.\n */\nexport function instrumentedModuleNames(instrumentations: InstrumentationConfig[] = []): string[] {\n return [\n ...uniq([...SENTRY_INSTRUMENTATIONS, ...instrumentations].map(i => i.module.name)),\n // Additional things that need to be bundled but are not covered by the above\n // Remix needs to bundle this so @remix-run/server-runtime is _also_ bundled\n '@remix-run/node',\n ];\n}\n\n/** The instrumented module names from the default Sentry config, with no custom additions. */\nexport const INSTRUMENTED_MODULE_NAMES: string[] = instrumentedModuleNames();\n\n/**\n * The package names the SDK instruments through the orchestrion module transform (its\n * diagnostics-channel injection). Pass these to a server bundler's \"keep external\" option so the\n * packages load through Node's module loader — the only path the transform can hook — instead of\n * being inlined into the server bundle. A framework that has no Sentry bundler plugin (e.g. eve, via\n * `build.externalDependencies`) is the main caller; a listed package the app doesn't use is simply\n * ignored by the bundler.\n *\n * Unlike {@link INSTRUMENTED_MODULE_NAMES}, this is the plain instrumented set with no bundler-only\n * additions — those force a helper package to be *bundled*, the opposite of keeping it external.\n */\nexport function getInstrumentedModuleNames(): string[] {\n return uniq(SENTRY_INSTRUMENTATIONS.map(instrumentation => instrumentation.module.name));\n}\n\n/**\n * Returns `external` with any instrumented packages removed, so a bundler that\n * uses an \"external\" denylist (esbuild, Bun, Rollup) still bundles — and thus\n * transforms — them. Matches an exact package name (`'mysql'`) or a subpath\n * (`'mysql/lib/...'`); wildcard/other patterns are left untouched. `undefined`\n * is returned unchanged.\n *\n * Pass `moduleNames` from `instrumentedModuleNames(options.instrumentations)` so\n * custom instrumentations are stripped too; it defaults to the Sentry config\n * list. (Vite uses an `ssr.noExternal` allowlist instead, so it consumes\n * `instrumentedModuleNames` directly rather than this helper.)\n */\nexport function withoutInstrumentedExternals(\n external: readonly string[] | undefined,\n moduleNames: string[] = INSTRUMENTED_MODULE_NAMES,\n): string[] | undefined {\n if (!external) {\n return undefined;\n }\n return external.filter(entry => !moduleNames.some(name => entry === name || entry.startsWith(`${name}/`)));\n}\n\n// This is exported so that the nestjs package can use it to subscribe to the channels.\nexport { nestjsChannels } from './nestjs';\n// This is exported so that the remix package can use it to subscribe to the channels.\nexport { remixChannels } from './remix';\n// Exported so the remix package can subscribe to the Remix 3 channels, and hand only these configs to\n// the browser transform.\nexport { remixV3Channels, remixV3Config } from './remix-v3';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoEA,MAAa,0BAAmD;CAC9D,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;AACL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,MAAa,kCAA2D,wBAAwB,QAC9F,WAAU,CAAC,OAAO,SACpB;;;;;;;;;;;;AAaA,SAAgB,wBAAwB,mBAA4C,CAAC,GAAa;CAChG,OAAO,CACL,GAAG,KAAK,CAAC,GAAG,yBAAyB,GAAG,gBAAgB,CAAC,CAAC,KAAI,MAAK,EAAE,OAAO,IAAI,CAAC,GAGjF,iBACF;AACF;;AAGA,MAAa,4BAAsC,wBAAwB;;;;;;;;;;;;AAa3E,SAAgB,6BAAuC;CACrD,OAAO,KAAK,wBAAwB,KAAI,oBAAmB,gBAAgB,OAAO,IAAI,CAAC;AACzF;;;;;;;;;;;;;AAcA,SAAgB,6BACd,UACA,cAAwB,2BACF;CACtB,IAAI,CAAC,UACH;CAEF,OAAO,SAAS,QAAO,UAAS,CAAC,YAAY,MAAK,SAAQ,UAAU,QAAQ,MAAM,WAAW,GAAG,KAAK,EAAE,CAAC,CAAC;AAC3G"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { getModuleNames } from "./module-names.js";
|
|
2
|
+
// src/orchestrion/config/tanstack-ai.ts
|
|
3
|
+
const tanstackAiConfig = [{
|
|
4
|
+
channelName: "chat",
|
|
5
|
+
module: {
|
|
6
|
+
name: "@tanstack/ai",
|
|
7
|
+
versionRange: ">=1.0.0 <2.0.0",
|
|
8
|
+
filePath: "dist/esm/activities/chat/index.js"
|
|
9
|
+
},
|
|
10
|
+
functionQuery: {
|
|
11
|
+
functionName: "chat",
|
|
12
|
+
kind: "Sync"
|
|
13
|
+
}
|
|
14
|
+
}];
|
|
15
|
+
const tanstackAiModuleNames = getModuleNames(tanstackAiConfig);
|
|
16
|
+
const tanstackAiChannels = { TANSTACK_AI_CHAT: "orchestrion:@tanstack/ai:chat" };
|
|
17
|
+
export { tanstackAiChannels, tanstackAiConfig, tanstackAiModuleNames };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=tanstack-ai.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tanstack-ai.js","names":[],"sources":["../../../../src/orchestrion/config/tanstack-ai.ts"],"sourcesContent":["import type { InstrumentationConfig } from '../apmTypes';\nimport { getModuleNames } from './module-names';\n\n// `chat()` takes its middleware per call, and `@tanstack/ai` has no global middleware registry, so\n// the integration changes the options of each call. `chat` returns a stream or a promise, depending\n// on `stream`, but it runs nothing before it returns, so `Sync` is enough: we only need `start`.\nexport const tanstackAiConfig = [\n {\n channelName: 'chat',\n module: { name: '@tanstack/ai', versionRange: '>=1.0.0 <2.0.0', filePath: 'dist/esm/activities/chat/index.js' },\n functionQuery: { functionName: 'chat', kind: 'Sync' },\n },\n] satisfies InstrumentationConfig[];\n\nexport const tanstackAiModuleNames = getModuleNames(tanstackAiConfig);\n\nexport const tanstackAiChannels = {\n TANSTACK_AI_CHAT: 'orchestrion:@tanstack/ai:chat',\n} as const;\n"],"mappings":";;AAMA,MAAa,mBAAmB,CAC9B;CACE,aAAa;CACb,QAAQ;EAAE,MAAM;EAAgB,cAAc;EAAkB,UAAU;CAAoC;CAC9G,eAAe;EAAE,cAAc;EAAQ,MAAM;CAAO;AACtD,CACF;AAEA,MAAa,wBAAwB,eAAe,gBAAgB;AAEpE,MAAa,qBAAqB,EAChC,kBAAkB,gCACpB"}
|
package/build/esm/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"type":"module","version":"11.
|
|
1
|
+
{"type":"module","version":"11.21.0","sideEffects":false}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const TANSTACK_AI_INTEGRATION_NAME: 'TanStackAI';
|
|
2
|
+
export declare const TANSTACK_AI_ORIGIN = "auto.ai.tanstack_ai";
|
|
3
|
+
/**
|
|
4
|
+
* Marks our middleware, so a `chat()` call that already has it does not get a second one.
|
|
5
|
+
* `Symbol.for`, so that two copies of the SDK in one process see each other's middleware.
|
|
6
|
+
*/
|
|
7
|
+
export declare const TANSTACK_AI_MIDDLEWARE_BRAND: unique symbol;
|
|
8
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../src/ai/tanstack-ai/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,4BAA4B,EAAG,YAAqB,CAAC;AAElE,eAAO,MAAM,kBAAkB,wBAAwB,CAAC;AAExD;;;GAGG;AACH,eAAO,MAAM,4BAA4B,eAA8C,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { GenAiSpanHooks } from '../core/span-hooks';
|
|
2
|
+
import type { GenAiCallOptions } from '../core/utils';
|
|
3
|
+
import type { TanstackAICallInfo, TanstackAIChatMiddleware } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* `call` is the options object of the `chat()` call. The recording options run when `chat()` is
|
|
6
|
+
* called. The hooks run for every span (`invoke_agent`, `chat` and `execute_tool`) while the run is
|
|
7
|
+
* read, which can be in another async context than the call. `onSpanEnd` gets the `error` of a
|
|
8
|
+
* failed run or tool.
|
|
9
|
+
*/
|
|
10
|
+
export type TanstackAIOptions = GenAiCallOptions<TanstackAICallInfo> & GenAiSpanHooks<TanstackAICallInfo>;
|
|
11
|
+
/**
|
|
12
|
+
* Makes the chat middleware for one `chat()` call. Call it when `chat()` is called: the parent of the
|
|
13
|
+
* `invoke_agent` span is the span that is active then, and the recording options are decided then.
|
|
14
|
+
* The middleware cannot make its spans active, so the spans of other work in the run do not nest
|
|
15
|
+
* below them.
|
|
16
|
+
*/
|
|
17
|
+
export declare function createTanstackAIMiddleware(options: TanstackAIOptions, call: TanstackAICallInfo): TanstackAIChatMiddleware;
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ai/tanstack-ai/index.ts"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAGzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAGtD,OAAO,KAAK,EACV,kBAAkB,EAClB,wBAAwB,EAGzB,MAAM,SAAS,CAAC;AAGjB;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,GAAG,gBAAgB,CAAC,kBAAkB,CAAC,GAAG,cAAc,CAAC,kBAAkB,CAAC,CAAC;AAK1G;;;;;GAKG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,iBAAiB,EAC1B,IAAI,EAAE,kBAAkB,GACvB,wBAAwB,CAiQ1B"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The parts of the `@tanstack/ai` 1.x chat middleware contract that we use. `@tanstack/ai` is not a
|
|
3
|
+
* dependency of this package, so these mirror `ChatMiddleware`, `ChatMiddlewareContext` and
|
|
4
|
+
* `ChatMiddlewareConfig`.
|
|
5
|
+
*/
|
|
6
|
+
import type { TANSTACK_AI_MIDDLEWARE_BRAND } from './constants';
|
|
7
|
+
/** The options of a `chat()` call. The recording options and the span hooks get this object. */
|
|
8
|
+
export interface TanstackAICallInfo {
|
|
9
|
+
threadId?: string;
|
|
10
|
+
stream?: boolean;
|
|
11
|
+
outputSchema?: unknown;
|
|
12
|
+
middleware?: unknown;
|
|
13
|
+
[key: string]: unknown;
|
|
14
|
+
}
|
|
15
|
+
/** Mirrors `TokenUsage`. */
|
|
16
|
+
export interface TanstackAIUsage {
|
|
17
|
+
promptTokens?: number;
|
|
18
|
+
completionTokens?: number;
|
|
19
|
+
totalTokens?: number;
|
|
20
|
+
promptTokensDetails?: {
|
|
21
|
+
cachedTokens?: number;
|
|
22
|
+
cacheWriteTokens?: number;
|
|
23
|
+
};
|
|
24
|
+
completionTokensDetails?: {
|
|
25
|
+
reasoningTokens?: number;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export interface TanstackAITool {
|
|
29
|
+
name: string;
|
|
30
|
+
description?: string;
|
|
31
|
+
inputSchema?: unknown;
|
|
32
|
+
execute?: unknown;
|
|
33
|
+
}
|
|
34
|
+
/** Mirrors `ModelMessage`. */
|
|
35
|
+
export interface TanstackAIModelMessage {
|
|
36
|
+
role: 'user' | 'assistant' | 'tool';
|
|
37
|
+
content: string | null | Array<{
|
|
38
|
+
type: string;
|
|
39
|
+
content?: string;
|
|
40
|
+
}>;
|
|
41
|
+
toolCalls?: Array<{
|
|
42
|
+
id: string;
|
|
43
|
+
function?: {
|
|
44
|
+
name: string;
|
|
45
|
+
arguments: string;
|
|
46
|
+
};
|
|
47
|
+
}>;
|
|
48
|
+
toolCallId?: string;
|
|
49
|
+
}
|
|
50
|
+
export type TanstackAISystemPrompt = string | {
|
|
51
|
+
content: string;
|
|
52
|
+
};
|
|
53
|
+
export interface TanstackAIMiddlewareContext {
|
|
54
|
+
phase: string;
|
|
55
|
+
/** The adapter name, for example `openai-chat`. */
|
|
56
|
+
provider: string;
|
|
57
|
+
model: string;
|
|
58
|
+
threadId: string;
|
|
59
|
+
subagentName?: string;
|
|
60
|
+
/** The metadata of the current model call. TanStack sets it when the model call starts. */
|
|
61
|
+
callMetadata?: {
|
|
62
|
+
model?: string;
|
|
63
|
+
responseId?: string;
|
|
64
|
+
source?: {
|
|
65
|
+
provider?: string;
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
signal?: AbortSignal;
|
|
69
|
+
}
|
|
70
|
+
export interface TanstackAIMiddlewareConfig {
|
|
71
|
+
messages: TanstackAIModelMessage[];
|
|
72
|
+
/** The messages sent to the provider, when a middleware makes them different from `messages`. */
|
|
73
|
+
providerMessages?: TanstackAIModelMessage[];
|
|
74
|
+
systemPrompts: TanstackAISystemPrompt[];
|
|
75
|
+
tools: TanstackAITool[];
|
|
76
|
+
modelOptions?: Record<string, unknown>;
|
|
77
|
+
}
|
|
78
|
+
/** A stream chunk: an AG-UI event, discriminated by `type`. */
|
|
79
|
+
export interface TanstackAIChunk {
|
|
80
|
+
type: string;
|
|
81
|
+
delta?: string;
|
|
82
|
+
model?: string;
|
|
83
|
+
responseId?: string;
|
|
84
|
+
finishReason?: string | null;
|
|
85
|
+
toolCallId?: string;
|
|
86
|
+
toolCallName?: string;
|
|
87
|
+
input?: unknown;
|
|
88
|
+
/** `{ type: 'interrupt' }` on the `RUN_FINISHED` chunk of a run that stops at an interrupt. */
|
|
89
|
+
outcome?: {
|
|
90
|
+
type: string;
|
|
91
|
+
};
|
|
92
|
+
/** The error of a `RUN_ERROR` chunk. */
|
|
93
|
+
error?: {
|
|
94
|
+
message: string;
|
|
95
|
+
code?: string;
|
|
96
|
+
};
|
|
97
|
+
message?: string;
|
|
98
|
+
code?: string;
|
|
99
|
+
}
|
|
100
|
+
export interface TanstackAIToolCallHookContext {
|
|
101
|
+
toolName: string;
|
|
102
|
+
toolCallId: string;
|
|
103
|
+
args: unknown;
|
|
104
|
+
tool?: TanstackAITool;
|
|
105
|
+
}
|
|
106
|
+
export interface TanstackAIAfterToolCallInfo {
|
|
107
|
+
toolCallId: string;
|
|
108
|
+
ok: boolean;
|
|
109
|
+
result?: unknown;
|
|
110
|
+
error?: unknown;
|
|
111
|
+
}
|
|
112
|
+
export interface TanstackAIChatMiddleware {
|
|
113
|
+
name: string;
|
|
114
|
+
[TANSTACK_AI_MIDDLEWARE_BRAND]: true;
|
|
115
|
+
onConfig(ctx: TanstackAIMiddlewareContext, config: TanstackAIMiddlewareConfig): void;
|
|
116
|
+
onChunk(ctx: TanstackAIMiddlewareContext, chunk: TanstackAIChunk): void;
|
|
117
|
+
onInterruptBoundary(ctx: TanstackAIMiddlewareContext): void;
|
|
118
|
+
onUsage(ctx: TanstackAIMiddlewareContext, usage: TanstackAIUsage): void;
|
|
119
|
+
onGuardToolCall(ctx: TanstackAIMiddlewareContext, hookCtx: TanstackAIToolCallHookContext): void;
|
|
120
|
+
onAfterToolCall(ctx: TanstackAIMiddlewareContext, info: TanstackAIAfterToolCallInfo): void;
|
|
121
|
+
onFinish(ctx: TanstackAIMiddlewareContext): void;
|
|
122
|
+
onAbort(ctx: TanstackAIMiddlewareContext): void;
|
|
123
|
+
onError(ctx: TanstackAIMiddlewareContext, info: {
|
|
124
|
+
error: unknown;
|
|
125
|
+
}): void;
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/ai/tanstack-ai/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAC;AAEhE,gGAAgG;AAChG,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC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