@brizz/sdk 0.2.0 → 0.2.1

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.
Files changed (45) hide show
  1. package/CHANGELOG.md +430 -0
  2. package/LICENSE +194 -20
  3. package/README.md +36 -1
  4. package/dist/{chunk-B5IY6O4N.js → chunk-6OYS2GR3.js} +1 -1
  5. package/dist/{chunk-WC573FCI.cjs → chunk-C5OT6GAQ.cjs} +10 -2
  6. package/dist/{chunk-Y4HNUX3Q.js → chunk-CZDPIJTO.js} +8 -0
  7. package/dist/{chunk-EZCNPWKM.js → chunk-GITAPIVL.js} +9 -9
  8. package/dist/{chunk-NF52RMLW.cjs → chunk-IWSFMCHH.cjs} +5 -1
  9. package/dist/{chunk-GISL4K6Z.js → chunk-JMX23OHO.js} +4 -0
  10. package/dist/{chunk-5HCG3JKU.js → chunk-KJSZPKSN.js} +5 -5
  11. package/dist/{chunk-RD4XCYKT.cjs → chunk-P5OONZTF.cjs} +3 -3
  12. package/dist/{chunk-CNVK5RA3.cjs → chunk-QXHGMS5A.cjs} +13 -13
  13. package/dist/{chunk-4QNEI7VZ.cjs → chunk-UF4GMVEY.cjs} +142 -142
  14. package/dist/eve.cjs +2 -3
  15. package/dist/eve.js +1 -2
  16. package/dist/google-genai-6S5E7GZ4.cjs +10 -0
  17. package/dist/{google-genai-3ERJNC7Q.js → google-genai-H6TMOKRX.js} +2 -3
  18. package/dist/google-genai.cjs +3 -4
  19. package/dist/google-genai.js +2 -3
  20. package/dist/index.cjs +590 -299
  21. package/dist/index.js +371 -80
  22. package/dist/{mcp-5ERVMLSA.cjs → mcp-6LNVYVJQ.cjs} +39 -40
  23. package/dist/{mcp-EJAJTGIC.js → mcp-YTBE75NP.js} +5 -6
  24. package/dist/session.cjs +4 -5
  25. package/dist/session.js +3 -4
  26. package/dist/types/cjs/internal/instrumentation/auto-init.d.ts +0 -7
  27. package/dist/types/cjs/internal/instrumentation/registry.d.ts +2 -0
  28. package/dist/types/cjs/internal/instrumentation/vercel-ai/index.d.ts +28 -0
  29. package/dist/types/cjs/internal/instrumentation/vercel-ai/model-call-end.d.ts +1 -0
  30. package/dist/types/cjs/internal/sdk.d.ts +1 -0
  31. package/dist/types/cjs/internal/semantic-conventions.d.ts +2 -0
  32. package/dist/types/esm/internal/instrumentation/auto-init.d.ts +0 -7
  33. package/dist/types/esm/internal/instrumentation/registry.d.ts +2 -0
  34. package/dist/types/esm/internal/instrumentation/vercel-ai/index.d.ts +28 -0
  35. package/dist/types/esm/internal/instrumentation/vercel-ai/model-call-end.d.ts +1 -0
  36. package/dist/types/esm/internal/sdk.d.ts +1 -0
  37. package/dist/types/esm/internal/semantic-conventions.d.ts +2 -0
  38. package/package.json +28 -23
  39. package/dist/chunk-3RG5ZIWI.js +0 -10
  40. package/dist/chunk-6QXPHZEO.cjs +0 -130
  41. package/dist/chunk-GABRGNAU.js +0 -130
  42. package/dist/chunk-OBGZSXTJ.cjs +0 -10
  43. package/dist/google-genai-GVCKSJMR.cjs +0 -11
  44. package/dist/interrupt-36U5562Z.cjs +0 -12
  45. package/dist/interrupt-6BSXUK3O.js +0 -12
package/dist/index.js CHANGED
@@ -39,31 +39,14 @@ import {
39
39
  withServiceName,
40
40
  withSessionId,
41
41
  withUser
42
- } from "./chunk-EZCNPWKM.js";
42
+ } from "./chunk-GITAPIVL.js";
43
43
  import {
44
44
  configure,
45
45
  getSDKVersion
46
- } from "./chunk-5HCG3JKU.js";
47
- import {
48
- bindToBrizz,
49
- brizzTracerProvider,
50
- ensureContextManager,
51
- getTracerProvider,
52
- registerTracerProvider,
53
- setPrivateTracerProvider
54
- } from "./chunk-TDPQDITP.js";
55
- import {
56
- DEFAULT_LOG_LEVEL,
57
- LogLevel,
58
- getLogLevel,
59
- logger,
60
- parseLogLevel,
61
- setLogLevel
62
- } from "./chunk-Y4HNUX3Q.js";
63
- import {
64
- InterruptPropagator
65
- } from "./chunk-GABRGNAU.js";
46
+ } from "./chunk-KJSZPKSN.js";
66
47
  import {
48
+ AI_SDK_OTEL_SCOPE,
49
+ APPROVALS,
67
50
  BRIZZ,
68
51
  ERROR_TYPE,
69
52
  GEN_AI_CONVERSATION_ID,
@@ -79,6 +62,7 @@ import {
79
62
  GEN_AI_USAGE_INPUT_TOKENS,
80
63
  GEN_AI_USAGE_OUTPUT_TOKENS,
81
64
  INTERNAL_EVENT_PREFIX,
65
+ INTERRUPT_TOOLS,
82
66
  ORGANIZATION_DOMAIN,
83
67
  ORGANIZATION_NAME,
84
68
  PROPERTIES_CONTEXT_KEY,
@@ -86,10 +70,24 @@ import {
86
70
  SESSION_ID,
87
71
  USER_EMAIL,
88
72
  USER_NAME
89
- } from "./chunk-GISL4K6Z.js";
73
+ } from "./chunk-JMX23OHO.js";
90
74
  import {
91
- __require
92
- } from "./chunk-3RG5ZIWI.js";
75
+ bindToBrizz,
76
+ brizzTracerProvider,
77
+ ensureContextManager,
78
+ getTracerProvider,
79
+ registerTracerProvider,
80
+ setPrivateTracerProvider
81
+ } from "./chunk-TDPQDITP.js";
82
+ import {
83
+ DEFAULT_LOG_LEVEL,
84
+ LogLevel,
85
+ __require,
86
+ getLogLevel,
87
+ logger,
88
+ parseLogLevel,
89
+ setLogLevel
90
+ } from "./chunk-CZDPIJTO.js";
93
91
 
94
92
  // src/internal/instrumentation/auto-init.ts
95
93
  import { registerInstrumentations } from "@opentelemetry/instrumentation";
@@ -710,7 +708,7 @@ function loadGenAIInstrumentations() {
710
708
  function loadMCPInstrumentation() {
711
709
  void (async () => {
712
710
  try {
713
- const { MCPInstrumentation } = await import("./mcp-EJAJTGIC.js");
711
+ const { MCPInstrumentation } = await import("./mcp-YTBE75NP.js");
714
712
  const mcp = new MCPInstrumentation({ exceptionLogger });
715
713
  registerInstrumentations({ instrumentations: [mcp], tracerProvider: brizzTracerProvider });
716
714
  logger.debug("Auto-loaded MCP instrumentation");
@@ -763,7 +761,7 @@ function loadVertexAIInstrumentation() {
763
761
  function loadGoogleGenAIInstrumentation() {
764
762
  void (async () => {
765
763
  try {
766
- const { GoogleGenAIInstrumentation } = await import("./google-genai-3ERJNC7Q.js");
764
+ const { GoogleGenAIInstrumentation } = await import("./google-genai-H6TMOKRX.js");
767
765
  const googleGenAI = new GoogleGenAIInstrumentation({ exceptionLogger });
768
766
  registerInstrumentations({
769
767
  instrumentations: [googleGenAI],
@@ -777,53 +775,6 @@ function loadGoogleGenAIInstrumentation() {
777
775
  }
778
776
  })();
779
777
  }
780
- function selectTelemetryRegister(ai) {
781
- const register = ai.registerTelemetry ?? ai.registerTelemetryIntegration;
782
- return typeof register === "function" ? register : void 0;
783
- }
784
- function loadVercelAITelemetry() {
785
- void (async () => {
786
- try {
787
- const ai = await import("ai");
788
- const register = selectTelemetryRegister(ai);
789
- if (!register) {
790
- logger.debug(
791
- "AI SDK present but lacks a telemetry-registration hook (needs ai@>=6); skipping"
792
- );
793
- return;
794
- }
795
- const isV7 = typeof ai.registerTelemetry === "function";
796
- const integrations = [];
797
- const { createInterruptIntegration } = await import("./interrupt-6BSXUK3O.js");
798
- integrations.push(createInterruptIntegration());
799
- let otelCollectorLoaded = false;
800
- try {
801
- const otel = await import("@ai-sdk/otel");
802
- if (typeof otel.LegacyOpenTelemetry === "function") {
803
- integrations.push(
804
- new otel.LegacyOpenTelemetry({ tracer: brizzTracerProvider.getTracer("ai") })
805
- );
806
- otelCollectorLoaded = true;
807
- }
808
- } catch {
809
- }
810
- if (!otelCollectorLoaded) {
811
- const message = "AI SDK present but @ai-sdk/otel is missing or unusable; install it (npm install @ai-sdk/otel) to capture AI SDK spans on ai@>=7";
812
- if (isV7) {
813
- logger.warn(message);
814
- } else {
815
- logger.debug(message);
816
- }
817
- }
818
- register(...integrations);
819
- logger.debug("Auto-loaded Vercel AI telemetry");
820
- } catch (error) {
821
- logger.debug(
822
- `Vercel AI telemetry not loaded (install ai@>=6 to capture AI SDK telemetry): ${String(error)}`
823
- );
824
- }
825
- })();
826
- }
827
778
  function autoInitializeInstrumentations() {
828
779
  try {
829
780
  const genAIInstrumentations = loadGenAIInstrumentations();
@@ -832,7 +783,6 @@ function autoInitializeInstrumentations() {
832
783
  loadTypeSafeInstrumentation();
833
784
  loadVertexAIInstrumentation();
834
785
  loadGoogleGenAIInstrumentation();
835
- loadVercelAITelemetry();
836
786
  logger.info(
837
787
  `Auto-initialization complete: ${genAIInstrumentations.length} GenAI instrumentations`
838
788
  );
@@ -845,7 +795,7 @@ function autoInitializeInstrumentations() {
845
795
  var autoInstrumentationsLoaded = autoInitializeInstrumentations();
846
796
 
847
797
  // src/internal/sdk.ts
848
- import { metrics, trace as trace4 } from "@opentelemetry/api";
798
+ import { metrics, trace as trace5 } from "@opentelemetry/api";
849
799
  import { registerInstrumentations as registerInstrumentations2 } from "@opentelemetry/instrumentation";
850
800
  import {
851
801
  defaultResource,
@@ -1306,7 +1256,7 @@ var InstrumentationRegistry = class _InstrumentationRegistry {
1306
1256
  const genaiModule = this.manualModules.google_genai;
1307
1257
  void (async () => {
1308
1258
  try {
1309
- const { GoogleGenAIInstrumentation } = await import("./google-genai-3ERJNC7Q.js");
1259
+ const { GoogleGenAIInstrumentation } = await import("./google-genai-H6TMOKRX.js");
1310
1260
  const genaiInst = new GoogleGenAIInstrumentation({ exceptionLogger: exceptionLogger2 });
1311
1261
  genaiInst.manuallyInstrument(genaiModule);
1312
1262
  logger.debug("Manual instrumentation enabled for Google GenAI");
@@ -1321,7 +1271,7 @@ var InstrumentationRegistry = class _InstrumentationRegistry {
1321
1271
  const mcpModules = this.manualModules.mcp;
1322
1272
  void (async () => {
1323
1273
  try {
1324
- const { MCPInstrumentation } = await import("./mcp-EJAJTGIC.js");
1274
+ const { MCPInstrumentation } = await import("./mcp-YTBE75NP.js");
1325
1275
  const instrumentation = new MCPInstrumentation({ exceptionLogger: exceptionLogger2 });
1326
1276
  instrumentation.manuallyInstrument(mcpModules);
1327
1277
  logger.debug("Manual instrumentation enabled for MCP");
@@ -1357,6 +1307,184 @@ var InstrumentationRegistry = class _InstrumentationRegistry {
1357
1307
  }
1358
1308
  };
1359
1309
 
1310
+ // src/internal/instrumentation/vercel-ai/interrupt.ts
1311
+ import { trace as trace3 } from "@opentelemetry/api";
1312
+ var INNER_OPERATION_IDS = /* @__PURE__ */ new Set([
1313
+ "ai.generateText.doGenerate",
1314
+ "ai.streamText.doStream"
1315
+ ]);
1316
+ function isLegacyModelCallSpan(span) {
1317
+ if (INNER_OPERATION_IDS.has(span.name)) {
1318
+ return true;
1319
+ }
1320
+ const opId = span.attributes["ai.operationId"];
1321
+ return typeof opId === "string" && INNER_OPERATION_IDS.has(opId);
1322
+ }
1323
+ function isGenAIModelCallSpan(span) {
1324
+ return span.instrumentationScope?.name === AI_SDK_OTEL_SCOPE && span.attributes["gen_ai.operation.name"] === "chat";
1325
+ }
1326
+ var MAX_PENDING_ENTRIES = 1024;
1327
+ var pendingByParentSpanId = /* @__PURE__ */ new Map();
1328
+ var needsApprovalToolNames = /* @__PURE__ */ new Set();
1329
+ var versionState = { sawActiveSpan: false };
1330
+ function setPending(parentSpanId, value) {
1331
+ pendingByParentSpanId.set(parentSpanId, value);
1332
+ evictOldest(pendingByParentSpanId);
1333
+ }
1334
+ function extractInterruptTools(tools) {
1335
+ if (!tools || typeof tools !== "object") {
1336
+ return [];
1337
+ }
1338
+ return Object.entries(tools).filter(
1339
+ ([, t]) => !!t && typeof t === "object" && t.needsApproval
1340
+ ).map(([name]) => name);
1341
+ }
1342
+ function parsePromptToolNames(raw) {
1343
+ if (!Array.isArray(raw)) {
1344
+ return null;
1345
+ }
1346
+ const names = [];
1347
+ for (const element of raw) {
1348
+ if (typeof element !== "string") {
1349
+ continue;
1350
+ }
1351
+ try {
1352
+ const parsed = JSON.parse(element);
1353
+ if (parsed && typeof parsed.name === "string") {
1354
+ names.push(parsed.name);
1355
+ }
1356
+ } catch {
1357
+ }
1358
+ }
1359
+ return names.length > 0 ? names : null;
1360
+ }
1361
+ var verdictsByToolCallId = /* @__PURE__ */ new Map();
1362
+ function recordVerdicts(messages) {
1363
+ if (!Array.isArray(messages)) {
1364
+ return;
1365
+ }
1366
+ const parts = messages.flatMap((message) => {
1367
+ const content = message?.content;
1368
+ return Array.isArray(content) ? content : [];
1369
+ });
1370
+ const askedOf = /* @__PURE__ */ new Map();
1371
+ for (const part of parts) {
1372
+ if (part?.type === "tool-approval-request" && part.isAutomatic !== true) {
1373
+ askedOf.set(part.approvalId, part.toolCallId);
1374
+ }
1375
+ }
1376
+ for (const part of parts) {
1377
+ const toolCallId = part?.type === "tool-approval-response" && askedOf.get(part.approvalId);
1378
+ if (typeof toolCallId === "string" && typeof part.approved === "boolean") {
1379
+ verdictsByToolCallId.set(toolCallId, part.approved);
1380
+ evictOldest(verdictsByToolCallId);
1381
+ }
1382
+ }
1383
+ }
1384
+ function verdictsForRequest(inputMessages) {
1385
+ if (typeof inputMessages !== "string" || verdictsByToolCallId.size === 0) {
1386
+ return void 0;
1387
+ }
1388
+ let messages;
1389
+ try {
1390
+ messages = JSON.parse(inputMessages);
1391
+ } catch {
1392
+ return void 0;
1393
+ }
1394
+ if (!Array.isArray(messages)) {
1395
+ return void 0;
1396
+ }
1397
+ const verdicts = {};
1398
+ for (const message of [...messages].reverse()) {
1399
+ const { role, parts } = message ?? {};
1400
+ if (role === "assistant" || role === "system") {
1401
+ break;
1402
+ }
1403
+ for (const part of Array.isArray(parts) ? parts : []) {
1404
+ const approved = part?.type === "tool_call_response" && typeof part.id === "string" ? verdictsByToolCallId.get(part.id) : void 0;
1405
+ if (approved !== void 0) {
1406
+ verdicts[part.id] = approved;
1407
+ }
1408
+ }
1409
+ }
1410
+ return Object.keys(verdicts).length > 0 ? JSON.stringify(verdicts) : void 0;
1411
+ }
1412
+ function evictOldest(map) {
1413
+ while (map.size > MAX_PENDING_ENTRIES) {
1414
+ const oldest = map.keys().next().value;
1415
+ if (oldest === void 0) {
1416
+ break;
1417
+ }
1418
+ map.delete(oldest);
1419
+ }
1420
+ }
1421
+ function createInterruptIntegration() {
1422
+ const onStart = (event) => {
1423
+ recordVerdicts(event.messages);
1424
+ for (const name of extractInterruptTools(event.tools)) {
1425
+ needsApprovalToolNames.add(name);
1426
+ }
1427
+ };
1428
+ const onStepStart = (event) => {
1429
+ const span = trace3.getActiveSpan();
1430
+ if (span) {
1431
+ versionState.sawActiveSpan = true;
1432
+ }
1433
+ const names = extractInterruptTools(event.tools);
1434
+ if (names.length === 0) {
1435
+ return;
1436
+ }
1437
+ for (const name of names) {
1438
+ needsApprovalToolNames.add(name);
1439
+ }
1440
+ if (!span) {
1441
+ return;
1442
+ }
1443
+ const value = JSON.stringify(names);
1444
+ span.setAttribute(INTERRUPT_TOOLS, value);
1445
+ setPending(span.spanContext().spanId, value);
1446
+ };
1447
+ return {
1448
+ onStart,
1449
+ onStepStart
1450
+ };
1451
+ }
1452
+ var InterruptPropagator = class {
1453
+ onStart(span, _parentContext) {
1454
+ if (isGenAIModelCallSpan(span)) {
1455
+ const verdicts = verdictsForRequest(span.attributes["gen_ai.input.messages"]);
1456
+ if (verdicts) {
1457
+ span.setAttribute(APPROVALS, verdicts);
1458
+ }
1459
+ return;
1460
+ }
1461
+ if (!isLegacyModelCallSpan(span)) {
1462
+ return;
1463
+ }
1464
+ const parentSpanId = span.parentSpanContext?.spanId;
1465
+ const stashed = parentSpanId && pendingByParentSpanId.get(parentSpanId);
1466
+ if (stashed) {
1467
+ span.setAttribute(INTERRUPT_TOOLS, stashed);
1468
+ pendingByParentSpanId.delete(parentSpanId);
1469
+ return;
1470
+ }
1471
+ if (versionState.sawActiveSpan || needsApprovalToolNames.size === 0) {
1472
+ return;
1473
+ }
1474
+ const scoped = parsePromptToolNames(span.attributes["ai.prompt.tools"]);
1475
+ const names = scoped === null ? [...needsApprovalToolNames] : scoped.filter((n) => needsApprovalToolNames.has(n));
1476
+ if (names.length > 0) {
1477
+ span.setAttribute(INTERRUPT_TOOLS, JSON.stringify(names));
1478
+ }
1479
+ }
1480
+ onEnd() {
1481
+ }
1482
+ async shutdown() {
1483
+ }
1484
+ async forceFlush() {
1485
+ }
1486
+ };
1487
+
1360
1488
  // src/internal/log/logging.ts
1361
1489
  import { SeverityNumber } from "@opentelemetry/api";
1362
1490
  import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-http";
@@ -2158,6 +2286,165 @@ function getMetricsReader() {
2158
2286
  return MetricsModule.getInstance().getMetricsReader();
2159
2287
  }
2160
2288
 
2289
+ // src/internal/instrumentation/vercel-ai/model-call-end.ts
2290
+ var NO_USAGE = {
2291
+ inputTokens: void 0,
2292
+ inputTokenDetails: {
2293
+ noCacheTokens: void 0,
2294
+ cacheReadTokens: void 0,
2295
+ cacheWriteTokens: void 0
2296
+ },
2297
+ outputTokens: void 0,
2298
+ outputTokenDetails: { textTokens: void 0, reasoningTokens: void 0 },
2299
+ totalTokens: void 0
2300
+ };
2301
+ function endUnreportedModelCalls(collector) {
2302
+ const hooks = collector;
2303
+ if (!hasModelCallHooks(hooks)) {
2304
+ logger.debug("@ai-sdk/otel lacks the model-call hooks; failed streamed calls stay untraced");
2305
+ return collector;
2306
+ }
2307
+ const { onStepEnd, onLanguageModelCallStart, onLanguageModelCallEnd } = hooks;
2308
+ hooks.onStepEnd = (event) => {
2309
+ if (!event.durableContext) {
2310
+ onLanguageModelCallEnd.call(hooks, modelCallEndOf(event));
2311
+ }
2312
+ return onStepEnd.call(hooks, event);
2313
+ };
2314
+ hooks.onLanguageModelCallStart = (event) => {
2315
+ if (!event.durableContext) {
2316
+ onLanguageModelCallEnd.call(hooks, failedAttemptBefore(event));
2317
+ }
2318
+ return onLanguageModelCallStart.call(hooks, event);
2319
+ };
2320
+ return collector;
2321
+ }
2322
+ function hasModelCallHooks(hooks) {
2323
+ return typeof hooks.onStepEnd === "function" && typeof hooks.onLanguageModelCallStart === "function" && typeof hooks.onLanguageModelCallEnd === "function";
2324
+ }
2325
+ function modelCallEndOf(step) {
2326
+ return {
2327
+ callId: step.callId,
2328
+ provider: step.model.provider,
2329
+ modelId: step.response.modelId,
2330
+ finishReason: step.finishReason,
2331
+ usage: step.usage,
2332
+ content: step.content,
2333
+ responseId: step.response.id,
2334
+ providerMetadata: step.providerMetadata,
2335
+ request: { url: step.request.url },
2336
+ performance: { ...step.performance, timeToFirstOutputMs: void 0 },
2337
+ timestamp: step.timestamp
2338
+ };
2339
+ }
2340
+ function failedAttemptBefore(retry) {
2341
+ return {
2342
+ callId: retry.callId,
2343
+ provider: retry.provider,
2344
+ modelId: retry.modelId,
2345
+ finishReason: "error",
2346
+ usage: NO_USAGE,
2347
+ content: [],
2348
+ responseId: "",
2349
+ performance: {
2350
+ responseTimeMs: 0,
2351
+ effectiveOutputTokensPerSecond: 0,
2352
+ outputTokensPerSecond: void 0,
2353
+ inputTokensPerSecond: void 0,
2354
+ effectiveTotalTokensPerSecond: 0,
2355
+ timeToFirstOutputMs: void 0
2356
+ },
2357
+ timestamp: retry.timestamp
2358
+ };
2359
+ }
2360
+
2361
+ // src/internal/instrumentation/vercel-ai/index.ts
2362
+ var importInstalled = {
2363
+ ai: () => import("ai").catch(() => void 0),
2364
+ otel: () => import("@ai-sdk/otel").catch(() => void 0)
2365
+ };
2366
+ var registration = { done: false };
2367
+ function registerAISdkTelemetry({ collector, modules }, load = importInstalled) {
2368
+ if (registration.done) {
2369
+ return;
2370
+ }
2371
+ const ai = modules?.ai;
2372
+ const otel = modules?.aiOtel;
2373
+ if (ai && (otel || !collector || typeof ai.registerTelemetry !== "function")) {
2374
+ registerIntegrations(ai, otel, collector);
2375
+ return;
2376
+ }
2377
+ if (ai) {
2378
+ logger.debug(
2379
+ "instrumentModules has ai but not aiOtel; pass aiOtel too to trace a call made right after Brizz.initialize()"
2380
+ );
2381
+ }
2382
+ return registerInstalled(collector, load, ai, otel);
2383
+ }
2384
+ async function registerInstalled(collector, load, suppliedAi, suppliedOtel) {
2385
+ try {
2386
+ const ai = suppliedAi ?? await load.ai();
2387
+ const otel = collector && typeof ai?.registerTelemetry === "function" ? suppliedOtel ?? await load.otel() : void 0;
2388
+ registerIntegrations(ai, otel, collector);
2389
+ } catch (error) {
2390
+ logger.debug(`Vercel AI telemetry not registered: ${String(error)}`);
2391
+ }
2392
+ }
2393
+ function registerIntegrations(ai, otel, collector) {
2394
+ try {
2395
+ if (registration.done) {
2396
+ return;
2397
+ }
2398
+ if (!ai) {
2399
+ logger.debug("AI SDK not installed; install ai@>=6 to capture AI SDK telemetry");
2400
+ return;
2401
+ }
2402
+ const register = callable(ai.registerTelemetry) ?? callable(ai.registerTelemetryIntegration);
2403
+ if (!register) {
2404
+ logger.debug(
2405
+ "AI SDK present but lacks a telemetry-registration hook (needs ai@>=6); skipping"
2406
+ );
2407
+ return;
2408
+ }
2409
+ const integrations = [createInterruptIntegration()];
2410
+ if (register === ai.registerTelemetry && collector) {
2411
+ const openTelemetry = createCollector(otel?.OpenTelemetry);
2412
+ if (openTelemetry) {
2413
+ integrations.push(openTelemetry);
2414
+ } else {
2415
+ logger.warn(
2416
+ "AI SDK present but @ai-sdk/otel is missing or unusable; install it (npm install @ai-sdk/otel) to capture AI SDK spans on ai@>=7"
2417
+ );
2418
+ }
2419
+ }
2420
+ register(...integrations);
2421
+ registration.done = true;
2422
+ } catch (error) {
2423
+ logger.debug(`Vercel AI telemetry not registered: ${String(error)}`);
2424
+ }
2425
+ }
2426
+ function createCollector(OpenTelemetry) {
2427
+ if (typeof OpenTelemetry !== "function") {
2428
+ return void 0;
2429
+ }
2430
+ try {
2431
+ return endUnreportedModelCalls(
2432
+ new OpenTelemetry({
2433
+ tracer: brizzTracerProvider.getTracer(AI_SDK_OTEL_SCOPE),
2434
+ // Records the model's tool-choice decisions (`ai.decision.*`).
2435
+ experimental_decision: true,
2436
+ // Carries the price the Vercel AI Gateway billed.
2437
+ providerMetadata: true
2438
+ })
2439
+ );
2440
+ } catch {
2441
+ return void 0;
2442
+ }
2443
+ }
2444
+ function callable(hook) {
2445
+ return typeof hook === "function" ? hook : void 0;
2446
+ }
2447
+
2161
2448
  // src/internal/trace/tracing.ts
2162
2449
  import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";
2163
2450
 
@@ -2541,7 +2828,7 @@ function getSpanProcessor() {
2541
2828
  }
2542
2829
 
2543
2830
  // src/internal/trace/decision-call.ts
2544
- import { SpanKind as SpanKind2, SpanStatusCode as SpanStatusCode3, context as context6, trace as trace3 } from "@opentelemetry/api";
2831
+ import { SpanKind as SpanKind2, SpanStatusCode as SpanStatusCode3, context as context6, trace as trace4 } from "@opentelemetry/api";
2545
2832
  import { suppressTracing } from "@opentelemetry/core";
2546
2833
  var tracer = brizzTracerProvider.getTracer("@brizz/sdk/decision-call", getSDKVersion());
2547
2834
  function decisionCall(options, callback) {
@@ -2549,7 +2836,7 @@ function decisionCall(options, callback) {
2549
2836
  if (!span) {
2550
2837
  return callback(describeResultOn(void 0, options.provider));
2551
2838
  }
2552
- const callbackContext = suppressTracing(trace3.setSpan(context6.active(), span));
2839
+ const callbackContext = suppressTracing(trace4.setSpan(context6.active(), span));
2553
2840
  let result;
2554
2841
  try {
2555
2842
  result = context6.with(
@@ -2700,7 +2987,7 @@ function resolveMcpSessionTracking(configured) {
2700
2987
  }
2701
2988
  var BRIZZ_OWNED = /* @__PURE__ */ Symbol.for("brizz.sdk.ownedTracerProvider");
2702
2989
  function globalTracerDelegate() {
2703
- const global = trace4.getTracerProvider();
2990
+ const global = trace5.getTracerProvider();
2704
2991
  return typeof global.getDelegate === "function" ? global.getDelegate() : global;
2705
2992
  }
2706
2993
  var _Brizz = class __Brizz {
@@ -2915,6 +3202,10 @@ var _Brizz = class __Brizz {
2915
3202
  this.initializeModules(resolvedConfig);
2916
3203
  this.setupInstrumentation(options);
2917
3204
  this.createAndStartProviders(options, resolvedConfig);
3205
+ void registerAISdkTelemetry({
3206
+ collector: !options.disableAiSdkCollector,
3207
+ modules: options.instrumentModules
3208
+ });
2918
3209
  this._initialized = true;
2919
3210
  logger.info("Brizz SDK initialization completed successfully", {
2920
3211
  moduleSystem: this.detectModuleSystem()