ai 3.3.38 → 3.3.39

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,12 @@
1
1
  # ai
2
2
 
3
+ ## 3.3.39
4
+
5
+ ### Patch Changes
6
+
7
+ - 33cf3e1: feat (ai/core): add providerMetadata to StepResult
8
+ - 17ee757: feat (ai/core): add onStepFinish callback to generateText
9
+
3
10
  ## 3.3.38
4
11
 
5
12
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1356,6 +1356,12 @@ type StepResult<TOOLS extends Record<string, CoreTool>> = {
1356
1356
  Additional response information.
1357
1357
  */
1358
1358
  readonly response: LanguageModelResponseMetadataWithHeaders;
1359
+ /**
1360
+ Additional provider-specific metadata. They are passed through
1361
+ from the provider to the AI SDK and enable provider-specific
1362
+ results that can be fully encapsulated in the provider.
1363
+ */
1364
+ readonly experimental_providerMetadata: ProviderMetadata | undefined;
1359
1365
  };
1360
1366
 
1361
1367
  /**
@@ -1479,10 +1485,12 @@ If set and supported by the model, calls will generate deterministic results.
1479
1485
 
1480
1486
  @param maxSteps - Maximum number of sequential LLM calls (steps), e.g. when you use tool calls.
1481
1487
 
1488
+ @param onStepFinish - Callback that is called when each step (LLM call) is finished, including intermediate steps.
1489
+
1482
1490
  @returns
1483
1491
  A result object that contains the generated text, the results of the tool calls, and additional information.
1484
1492
  */
1485
- declare function generateText<TOOLS extends Record<string, CoreTool>>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, headers, maxAutomaticRoundtrips, maxToolRoundtrips, maxSteps, experimental_telemetry: telemetry, experimental_providerMetadata: providerMetadata, _internal: { generateId, currentDate, }, ...settings }: CallSettings & Prompt & {
1493
+ declare function generateText<TOOLS extends Record<string, CoreTool>>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, headers, maxAutomaticRoundtrips, maxToolRoundtrips, maxSteps, experimental_telemetry: telemetry, experimental_providerMetadata: providerMetadata, _internal: { generateId, currentDate, }, onStepFinish, ...settings }: CallSettings & Prompt & {
1486
1494
  /**
1487
1495
  The language model to use.
1488
1496
  */
@@ -1532,6 +1540,10 @@ to the provider from the AI SDK and enable provider-specific
1532
1540
  functionality that can be fully encapsulated in the provider.
1533
1541
  */
1534
1542
  experimental_providerMetadata?: ProviderMetadata;
1543
+ /**
1544
+ Callback that is called when each step (LLM call) is finished, including intermediate steps.
1545
+ */
1546
+ onStepFinish?: (event: StepResult<TOOLS>) => Promise<void> | void;
1535
1547
  /**
1536
1548
  * Internal. For test use only. May change without notice.
1537
1549
  */
@@ -1800,6 +1812,7 @@ If set and supported by the model, calls will generate deterministic results.
1800
1812
  @param maxSteps - Maximum number of sequential LLM calls (steps), e.g. when you use tool calls.
1801
1813
 
1802
1814
  @param onChunk - Callback that is called for each chunk of the stream. The stream processing will pause until the callback promise is resolved.
1815
+ @param onStepFinish - Callback that is called when each step (LLM call) is finished, including intermediate steps.
1803
1816
  @param onFinish - Callback that is called when the LLM response and all request tool executions
1804
1817
  (for tools that have an `execute` function) are finished.
1805
1818
 
@@ -1867,18 +1880,14 @@ Callback that is called for each chunk of the stream. The stream processing will
1867
1880
  /**
1868
1881
  Callback that is called when the LLM response and all request tool executions
1869
1882
  (for tools that have an `execute` function) are finished.
1883
+
1884
+ The usage is the combined usage of all steps.
1870
1885
  */
1871
1886
  onFinish?: (event: StepResult<TOOLS> & {
1872
1887
  /**
1873
1888
  Details for all steps.
1874
1889
  */
1875
1890
  steps: StepResult<TOOLS>[];
1876
- /**
1877
- Additional provider-specific metadata. They are passed through
1878
- from the provider to the AI SDK and enable provider-specific
1879
- results that can be fully encapsulated in the provider.
1880
- */
1881
- readonly experimental_providerMetadata: ProviderMetadata | undefined;
1882
1891
  }) => Promise<void> | void;
1883
1892
  /**
1884
1893
  Callback that is called when each step (LLM call) is finished, including intermediate steps.
package/dist/index.d.ts CHANGED
@@ -1356,6 +1356,12 @@ type StepResult<TOOLS extends Record<string, CoreTool>> = {
1356
1356
  Additional response information.
1357
1357
  */
1358
1358
  readonly response: LanguageModelResponseMetadataWithHeaders;
1359
+ /**
1360
+ Additional provider-specific metadata. They are passed through
1361
+ from the provider to the AI SDK and enable provider-specific
1362
+ results that can be fully encapsulated in the provider.
1363
+ */
1364
+ readonly experimental_providerMetadata: ProviderMetadata | undefined;
1359
1365
  };
1360
1366
 
1361
1367
  /**
@@ -1479,10 +1485,12 @@ If set and supported by the model, calls will generate deterministic results.
1479
1485
 
1480
1486
  @param maxSteps - Maximum number of sequential LLM calls (steps), e.g. when you use tool calls.
1481
1487
 
1488
+ @param onStepFinish - Callback that is called when each step (LLM call) is finished, including intermediate steps.
1489
+
1482
1490
  @returns
1483
1491
  A result object that contains the generated text, the results of the tool calls, and additional information.
1484
1492
  */
1485
- declare function generateText<TOOLS extends Record<string, CoreTool>>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, headers, maxAutomaticRoundtrips, maxToolRoundtrips, maxSteps, experimental_telemetry: telemetry, experimental_providerMetadata: providerMetadata, _internal: { generateId, currentDate, }, ...settings }: CallSettings & Prompt & {
1493
+ declare function generateText<TOOLS extends Record<string, CoreTool>>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, headers, maxAutomaticRoundtrips, maxToolRoundtrips, maxSteps, experimental_telemetry: telemetry, experimental_providerMetadata: providerMetadata, _internal: { generateId, currentDate, }, onStepFinish, ...settings }: CallSettings & Prompt & {
1486
1494
  /**
1487
1495
  The language model to use.
1488
1496
  */
@@ -1532,6 +1540,10 @@ to the provider from the AI SDK and enable provider-specific
1532
1540
  functionality that can be fully encapsulated in the provider.
1533
1541
  */
1534
1542
  experimental_providerMetadata?: ProviderMetadata;
1543
+ /**
1544
+ Callback that is called when each step (LLM call) is finished, including intermediate steps.
1545
+ */
1546
+ onStepFinish?: (event: StepResult<TOOLS>) => Promise<void> | void;
1535
1547
  /**
1536
1548
  * Internal. For test use only. May change without notice.
1537
1549
  */
@@ -1800,6 +1812,7 @@ If set and supported by the model, calls will generate deterministic results.
1800
1812
  @param maxSteps - Maximum number of sequential LLM calls (steps), e.g. when you use tool calls.
1801
1813
 
1802
1814
  @param onChunk - Callback that is called for each chunk of the stream. The stream processing will pause until the callback promise is resolved.
1815
+ @param onStepFinish - Callback that is called when each step (LLM call) is finished, including intermediate steps.
1803
1816
  @param onFinish - Callback that is called when the LLM response and all request tool executions
1804
1817
  (for tools that have an `execute` function) are finished.
1805
1818
 
@@ -1867,18 +1880,14 @@ Callback that is called for each chunk of the stream. The stream processing will
1867
1880
  /**
1868
1881
  Callback that is called when the LLM response and all request tool executions
1869
1882
  (for tools that have an `execute` function) are finished.
1883
+
1884
+ The usage is the combined usage of all steps.
1870
1885
  */
1871
1886
  onFinish?: (event: StepResult<TOOLS> & {
1872
1887
  /**
1873
1888
  Details for all steps.
1874
1889
  */
1875
1890
  steps: StepResult<TOOLS>[];
1876
- /**
1877
- Additional provider-specific metadata. They are passed through
1878
- from the provider to the AI SDK and enable provider-specific
1879
- results that can be fully encapsulated in the provider.
1880
- */
1881
- readonly experimental_providerMetadata: ProviderMetadata | undefined;
1882
1891
  }) => Promise<void> | void;
1883
1892
  /**
1884
1893
  Callback that is called when each step (LLM call) is finished, including intermediate steps.
package/dist/index.js CHANGED
@@ -3059,6 +3059,7 @@ async function generateText({
3059
3059
  generateId: generateId3 = originalGenerateId3,
3060
3060
  currentDate = () => /* @__PURE__ */ new Date()
3061
3061
  } = {},
3062
+ onStepFinish,
3062
3063
  ...settings
3063
3064
  }) {
3064
3065
  var _a11;
@@ -3220,7 +3221,7 @@ async function generateText({
3220
3221
  usage.completionTokens += currentUsage.completionTokens;
3221
3222
  usage.promptTokens += currentUsage.promptTokens;
3222
3223
  usage.totalTokens += currentUsage.totalTokens;
3223
- steps.push({
3224
+ const currentStep = {
3224
3225
  text: (_b = currentModelResponse.text) != null ? _b : "",
3225
3226
  toolCalls: currentToolCalls,
3226
3227
  toolResults: currentToolResults,
@@ -3231,8 +3232,11 @@ async function generateText({
3231
3232
  response: {
3232
3233
  ...currentModelResponse.response,
3233
3234
  headers: (_c = currentModelResponse.rawResponse) == null ? void 0 : _c.headers
3234
- }
3235
- });
3235
+ },
3236
+ experimental_providerMetadata: currentModelResponse.providerMetadata
3237
+ };
3238
+ steps.push(currentStep);
3239
+ await (onStepFinish == null ? void 0 : onStepFinish(currentStep));
3236
3240
  const newResponseMessages = toResponseMessages({
3237
3241
  text: currentModelResponse.text,
3238
3242
  toolCalls: currentToolCalls,
@@ -4098,7 +4102,8 @@ var DefaultStreamTextResult = class {
4098
4102
  warnings: self.warnings,
4099
4103
  logprobs: stepLogProbs,
4100
4104
  response: stepResponse,
4101
- rawResponse: self.rawResponse
4105
+ rawResponse: self.rawResponse,
4106
+ experimental_providerMetadata: stepProviderMetadata
4102
4107
  };
4103
4108
  stepResults.push(stepResult);
4104
4109
  await (onStepFinish == null ? void 0 : onStepFinish(stepResult));