ai 6.0.109 → 6.0.111

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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # ai
2
2
 
3
+ ## 6.0.111
4
+
5
+ ### Patch Changes
6
+
7
+ - 2129c82: feat(ai): register global telemetry integrations
8
+
9
+ ## 6.0.110
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [1b01ec1]
14
+ - Updated dependencies [8df8e11]
15
+ - @ai-sdk/gateway@3.0.63
16
+
3
17
  ## 6.0.109
4
18
 
5
19
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1079,17 +1079,22 @@ type OnFinishEvent<TOOLS extends ToolSet = ToolSet> = StepResult<TOOLS> & {
1079
1079
  readonly metadata: Record<string, unknown> | undefined;
1080
1080
  };
1081
1081
 
1082
+ /**
1083
+ * A callback function that can be used to notify listeners.
1084
+ */
1085
+ type Listener<EVENT> = (event: EVENT) => PromiseLike<void> | void;
1086
+
1082
1087
  /**
1083
1088
  * Implement this interface to create custom telemetry integrations.
1084
1089
  * Methods can be sync or return a PromiseLike.
1085
1090
  */
1086
- interface TelemetryIntegration<TOOLS extends ToolSet = ToolSet, OUTPUT extends Output = Output> {
1087
- onStart?(event: OnStartEvent<TOOLS, OUTPUT>): PromiseLike<void> | void;
1088
- onStepStart?(event: OnStepStartEvent<TOOLS, OUTPUT>): PromiseLike<void> | void;
1089
- onToolCallStart?(event: OnToolCallStartEvent<TOOLS>): PromiseLike<void> | void;
1090
- onToolCallFinish?(event: OnToolCallFinishEvent<TOOLS>): PromiseLike<void> | void;
1091
- onStepFinish?(event: OnStepFinishEvent<TOOLS>): PromiseLike<void> | void;
1092
- onFinish?(event: OnFinishEvent<TOOLS>): PromiseLike<void> | void;
1091
+ interface TelemetryIntegration {
1092
+ onStart?: Listener<OnStartEvent<ToolSet, Output>>;
1093
+ onStepStart?: Listener<OnStepStartEvent<ToolSet, Output>>;
1094
+ onToolCallStart?: Listener<OnToolCallStartEvent<ToolSet>>;
1095
+ onToolCallFinish?: Listener<OnToolCallFinishEvent<ToolSet>>;
1096
+ onStepFinish?: Listener<OnStepFinishEvent<ToolSet>>;
1097
+ onFinish?: Listener<OnFinishEvent<ToolSet>>;
1093
1098
  }
1094
1099
 
1095
1100
  /**
package/dist/index.d.ts CHANGED
@@ -1079,17 +1079,22 @@ type OnFinishEvent<TOOLS extends ToolSet = ToolSet> = StepResult<TOOLS> & {
1079
1079
  readonly metadata: Record<string, unknown> | undefined;
1080
1080
  };
1081
1081
 
1082
+ /**
1083
+ * A callback function that can be used to notify listeners.
1084
+ */
1085
+ type Listener<EVENT> = (event: EVENT) => PromiseLike<void> | void;
1086
+
1082
1087
  /**
1083
1088
  * Implement this interface to create custom telemetry integrations.
1084
1089
  * Methods can be sync or return a PromiseLike.
1085
1090
  */
1086
- interface TelemetryIntegration<TOOLS extends ToolSet = ToolSet, OUTPUT extends Output = Output> {
1087
- onStart?(event: OnStartEvent<TOOLS, OUTPUT>): PromiseLike<void> | void;
1088
- onStepStart?(event: OnStepStartEvent<TOOLS, OUTPUT>): PromiseLike<void> | void;
1089
- onToolCallStart?(event: OnToolCallStartEvent<TOOLS>): PromiseLike<void> | void;
1090
- onToolCallFinish?(event: OnToolCallFinishEvent<TOOLS>): PromiseLike<void> | void;
1091
- onStepFinish?(event: OnStepFinishEvent<TOOLS>): PromiseLike<void> | void;
1092
- onFinish?(event: OnFinishEvent<TOOLS>): PromiseLike<void> | void;
1091
+ interface TelemetryIntegration {
1092
+ onStart?: Listener<OnStartEvent<ToolSet, Output>>;
1093
+ onStepStart?: Listener<OnStepStartEvent<ToolSet, Output>>;
1094
+ onToolCallStart?: Listener<OnToolCallStartEvent<ToolSet>>;
1095
+ onToolCallFinish?: Listener<OnToolCallFinishEvent<ToolSet>>;
1096
+ onStepFinish?: Listener<OnStepFinishEvent<ToolSet>>;
1097
+ onFinish?: Listener<OnFinishEvent<ToolSet>>;
1093
1098
  }
1094
1099
 
1095
1100
  /**
package/dist/index.js CHANGED
@@ -633,6 +633,8 @@ function asArray(value) {
633
633
  // src/util/notify.ts
634
634
  async function notify(options) {
635
635
  for (const callback of asArray(options.callbacks)) {
636
+ if (callback == null)
637
+ continue;
636
638
  try {
637
639
  await callback(options.event);
638
640
  } catch (_ignored) {
@@ -1228,7 +1230,7 @@ var import_provider_utils3 = require("@ai-sdk/provider-utils");
1228
1230
  var import_provider_utils4 = require("@ai-sdk/provider-utils");
1229
1231
 
1230
1232
  // src/version.ts
1231
- var VERSION = true ? "6.0.109" : "0.0.0-test";
1233
+ var VERSION = true ? "6.0.111" : "0.0.0-test";
1232
1234
 
1233
1235
  // src/util/download/download.ts
1234
1236
  var download = async ({
@@ -2434,6 +2436,65 @@ function stringifyForTelemetry(prompt) {
2434
2436
  );
2435
2437
  }
2436
2438
 
2439
+ // src/telemetry/telemetry-integration-registry.ts
2440
+ function registerTelemetryIntegration(integration) {
2441
+ if (!globalThis.AI_SDK_TELEMETRY_INTEGRATIONS) {
2442
+ globalThis.AI_SDK_TELEMETRY_INTEGRATIONS = [];
2443
+ }
2444
+ globalThis.AI_SDK_TELEMETRY_INTEGRATIONS.push(integration);
2445
+ }
2446
+ function getGlobalTelemetryIntegrations() {
2447
+ var _a21;
2448
+ return (_a21 = globalThis.AI_SDK_TELEMETRY_INTEGRATIONS) != null ? _a21 : [];
2449
+ }
2450
+
2451
+ // src/telemetry/get-global-telemetry-integration.ts
2452
+ function bindTelemetryIntegration(integration) {
2453
+ var _a21, _b, _c, _d, _e, _f;
2454
+ return {
2455
+ onStart: (_a21 = integration.onStart) == null ? void 0 : _a21.bind(integration),
2456
+ onStepStart: (_b = integration.onStepStart) == null ? void 0 : _b.bind(integration),
2457
+ onToolCallStart: (_c = integration.onToolCallStart) == null ? void 0 : _c.bind(integration),
2458
+ onToolCallFinish: (_d = integration.onToolCallFinish) == null ? void 0 : _d.bind(integration),
2459
+ onStepFinish: (_e = integration.onStepFinish) == null ? void 0 : _e.bind(integration),
2460
+ onFinish: (_f = integration.onFinish) == null ? void 0 : _f.bind(integration)
2461
+ };
2462
+ }
2463
+ function getGlobalTelemetryIntegration() {
2464
+ const globalIntegrations = getGlobalTelemetryIntegrations();
2465
+ return (integrations) => {
2466
+ const localIntegrations = asArray(integrations);
2467
+ const allIntegrations = [...globalIntegrations, ...localIntegrations];
2468
+ function createTelemetryComposite(getListenerFromIntegration) {
2469
+ const listeners = allIntegrations.map(getListenerFromIntegration).filter(Boolean);
2470
+ return async (event) => {
2471
+ for (const listener of listeners) {
2472
+ try {
2473
+ await listener(event);
2474
+ } catch (_ignored) {
2475
+ }
2476
+ }
2477
+ };
2478
+ }
2479
+ return {
2480
+ onStart: createTelemetryComposite((integration) => integration.onStart),
2481
+ onStepStart: createTelemetryComposite(
2482
+ (integration) => integration.onStepStart
2483
+ ),
2484
+ onToolCallStart: createTelemetryComposite(
2485
+ (integration) => integration.onToolCallStart
2486
+ ),
2487
+ onToolCallFinish: createTelemetryComposite(
2488
+ (integration) => integration.onToolCallFinish
2489
+ ),
2490
+ onStepFinish: createTelemetryComposite(
2491
+ (integration) => integration.onStepFinish
2492
+ ),
2493
+ onFinish: createTelemetryComposite((integration) => integration.onFinish)
2494
+ };
2495
+ };
2496
+ }
2497
+
2437
2498
  // src/types/usage.ts
2438
2499
  function asLanguageModelUsage(usage) {
2439
2500
  return {
@@ -4052,6 +4113,7 @@ async function generateText({
4052
4113
  ...settings
4053
4114
  }) {
4054
4115
  const model = resolveLanguageModel(modelArg);
4116
+ const createGlobalTelemetry = getGlobalTelemetryIntegration();
4055
4117
  const stopConditions = asArray(stopWhen);
4056
4118
  const totalTimeoutMs = getTotalTimeoutMs(timeout);
4057
4119
  const stepTimeoutMs = getStepTimeoutMs(timeout);
@@ -4082,6 +4144,7 @@ async function generateText({
4082
4144
  prompt,
4083
4145
  messages
4084
4146
  });
4147
+ const globalTelemetry = createGlobalTelemetry(telemetry == null ? void 0 : telemetry.integrations);
4085
4148
  await notify({
4086
4149
  event: {
4087
4150
  model: modelInfo,
@@ -4111,7 +4174,10 @@ async function generateText({
4111
4174
  metadata: telemetry == null ? void 0 : telemetry.metadata,
4112
4175
  experimental_context
4113
4176
  },
4114
- callbacks: onStart
4177
+ callbacks: [
4178
+ onStart,
4179
+ globalTelemetry.onStart
4180
+ ]
4115
4181
  });
4116
4182
  const tracer = getTracer(telemetry);
4117
4183
  try {
@@ -4156,8 +4222,14 @@ async function generateText({
4156
4222
  experimental_context,
4157
4223
  stepNumber: 0,
4158
4224
  model: modelInfo,
4159
- onToolCallStart,
4160
- onToolCallFinish
4225
+ onToolCallStart: [
4226
+ onToolCallStart,
4227
+ globalTelemetry.onToolCallStart
4228
+ ],
4229
+ onToolCallFinish: [
4230
+ onToolCallFinish,
4231
+ globalTelemetry.onToolCallFinish
4232
+ ]
4161
4233
  });
4162
4234
  const toolContent = [];
4163
4235
  for (const output2 of toolOutputs) {
@@ -4283,7 +4355,10 @@ async function generateText({
4283
4355
  metadata: telemetry == null ? void 0 : telemetry.metadata,
4284
4356
  experimental_context
4285
4357
  },
4286
- callbacks: onStepStart
4358
+ callbacks: [
4359
+ onStepStart,
4360
+ globalTelemetry.onStepStart
4361
+ ]
4287
4362
  });
4288
4363
  currentModelResponse = await retry(
4289
4364
  () => {
@@ -4461,8 +4536,14 @@ async function generateText({
4461
4536
  experimental_context,
4462
4537
  stepNumber: steps.length,
4463
4538
  model: stepModelInfo,
4464
- onToolCallStart,
4465
- onToolCallFinish
4539
+ onToolCallStart: [
4540
+ onToolCallStart,
4541
+ globalTelemetry.onToolCallStart
4542
+ ],
4543
+ onToolCallFinish: [
4544
+ onToolCallFinish,
4545
+ globalTelemetry.onToolCallFinish
4546
+ ]
4466
4547
  })
4467
4548
  );
4468
4549
  }
@@ -4529,7 +4610,10 @@ async function generateText({
4529
4610
  model: stepModelInfo.modelId
4530
4611
  });
4531
4612
  steps.push(currentStepResult);
4532
- await notify({ event: currentStepResult, callbacks: onStepFinish });
4613
+ await notify({
4614
+ event: currentStepResult,
4615
+ callbacks: [onStepFinish, globalTelemetry.onStepFinish]
4616
+ });
4533
4617
  } finally {
4534
4618
  if (stepTimeoutId != null) {
4535
4619
  clearTimeout(stepTimeoutId);
@@ -4610,7 +4694,10 @@ async function generateText({
4610
4694
  steps,
4611
4695
  totalUsage
4612
4696
  },
4613
- callbacks: onFinish
4697
+ callbacks: [
4698
+ onFinish,
4699
+ globalTelemetry.onFinish
4700
+ ]
4614
4701
  });
4615
4702
  let resolvedOutput;
4616
4703
  if (lastStep.finishReason === "stop") {
@@ -6501,6 +6588,8 @@ var DefaultStreamTextResult = class {
6501
6588
  this.outputSpecification = output;
6502
6589
  this.includeRawChunks = includeRawChunks;
6503
6590
  this.tools = tools;
6591
+ const createGlobalTelemetry = getGlobalTelemetryIntegration();
6592
+ const globalTelemetry = createGlobalTelemetry(telemetry == null ? void 0 : telemetry.integrations);
6504
6593
  let stepFinish;
6505
6594
  let recordedContent = [];
6506
6595
  const recordedResponseMessages = [];
@@ -6648,7 +6737,10 @@ var DefaultStreamTextResult = class {
6648
6737
  },
6649
6738
  providerMetadata: part.providerMetadata
6650
6739
  });
6651
- await notify({ event: currentStepResult, callbacks: onStepFinish });
6740
+ await notify({
6741
+ event: currentStepResult,
6742
+ callbacks: [onStepFinish, globalTelemetry.onStepFinish]
6743
+ });
6652
6744
  logWarnings({
6653
6745
  warnings: recordedWarnings,
6654
6746
  provider: modelInfo.provider,
@@ -6712,7 +6804,10 @@ var DefaultStreamTextResult = class {
6712
6804
  providerMetadata: finalStep.providerMetadata,
6713
6805
  steps: recordedSteps
6714
6806
  },
6715
- callbacks: onFinish
6807
+ callbacks: [
6808
+ onFinish,
6809
+ globalTelemetry.onFinish
6810
+ ]
6716
6811
  });
6717
6812
  rootSpan.setAttributes(
6718
6813
  await selectTelemetryAttributes({
@@ -6869,7 +6964,10 @@ var DefaultStreamTextResult = class {
6869
6964
  ...callbackTelemetryProps,
6870
6965
  experimental_context
6871
6966
  },
6872
- callbacks: onStart
6967
+ callbacks: [
6968
+ onStart,
6969
+ globalTelemetry.onStart
6970
+ ]
6873
6971
  });
6874
6972
  const initialMessages = initialPrompt.messages;
6875
6973
  const initialResponseMessages = [];
@@ -6919,8 +7017,14 @@ var DefaultStreamTextResult = class {
6919
7017
  experimental_context,
6920
7018
  stepNumber: recordedSteps.length,
6921
7019
  model: modelInfo,
6922
- onToolCallStart,
6923
- onToolCallFinish,
7020
+ onToolCallStart: [
7021
+ onToolCallStart,
7022
+ globalTelemetry.onToolCallStart
7023
+ ],
7024
+ onToolCallFinish: [
7025
+ onToolCallFinish,
7026
+ globalTelemetry.onToolCallFinish
7027
+ ],
6924
7028
  onPreliminaryToolResult: (result2) => {
6925
7029
  toolExecutionStepStreamController == null ? void 0 : toolExecutionStepStreamController.enqueue(result2);
6926
7030
  }
@@ -7071,7 +7175,10 @@ var DefaultStreamTextResult = class {
7071
7175
  ...callbackTelemetryProps,
7072
7176
  experimental_context
7073
7177
  },
7074
- callbacks: onStepStart
7178
+ callbacks: [
7179
+ onStepStart,
7180
+ globalTelemetry.onStepStart
7181
+ ]
7075
7182
  });
7076
7183
  const {
7077
7184
  result: { stream: stream2, response, request },
@@ -7147,8 +7254,14 @@ var DefaultStreamTextResult = class {
7147
7254
  generateId: generateId2,
7148
7255
  stepNumber: recordedSteps.length,
7149
7256
  model: stepModelInfo,
7150
- onToolCallStart,
7151
- onToolCallFinish
7257
+ onToolCallStart: [
7258
+ onToolCallStart,
7259
+ globalTelemetry.onToolCallStart
7260
+ ],
7261
+ onToolCallFinish: [
7262
+ onToolCallFinish,
7263
+ globalTelemetry.onToolCallFinish
7264
+ ]
7152
7265
  });
7153
7266
  const stepRequest = ((_i = include == null ? void 0 : include.requestBody) != null ? _i : true) ? request != null ? request : {} : { ...request, body: void 0 };
7154
7267
  const stepToolCalls = [];
@@ -13292,27 +13405,6 @@ var TextStreamChatTransport = class extends HttpChatTransport {
13292
13405
  });
13293
13406
  }
13294
13407
  };
13295
-
13296
- // src/telemetry/telemetry-integration-registry.ts
13297
- function registerTelemetryIntegration(integration) {
13298
- if (!globalThis.AI_SDK_TELEMETRY_INTEGRATIONS) {
13299
- globalThis.AI_SDK_TELEMETRY_INTEGRATIONS = [];
13300
- }
13301
- globalThis.AI_SDK_TELEMETRY_INTEGRATIONS.push(integration);
13302
- }
13303
-
13304
- // src/telemetry/get-global-telemetry-integration.ts
13305
- function bindTelemetryIntegration(integration) {
13306
- var _a21, _b, _c, _d, _e, _f;
13307
- return {
13308
- onStart: (_a21 = integration.onStart) == null ? void 0 : _a21.bind(integration),
13309
- onStepStart: (_b = integration.onStepStart) == null ? void 0 : _b.bind(integration),
13310
- onToolCallStart: (_c = integration.onToolCallStart) == null ? void 0 : _c.bind(integration),
13311
- onToolCallFinish: (_d = integration.onToolCallFinish) == null ? void 0 : _d.bind(integration),
13312
- onStepFinish: (_e = integration.onStepFinish) == null ? void 0 : _e.bind(integration),
13313
- onFinish: (_f = integration.onFinish) == null ? void 0 : _f.bind(integration)
13314
- };
13315
- }
13316
13408
  // Annotate the CommonJS export names for ESM import in node:
13317
13409
  0 && (module.exports = {
13318
13410
  AISDKError,