ai 6.0.38 → 6.0.40

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.40
4
+
5
+ ### Patch Changes
6
+
7
+ - ab57783: Add usage information to onFinish callback in useChat
8
+
9
+ ## 6.0.39
10
+
11
+ ### Patch Changes
12
+
13
+ - 4e28ba0: fix(ai): propagate providerMetadata during input-streaming state
14
+
15
+ Provider-executed tools (like MCP tools) need to send metadata during the streaming phase, but the implementation only set `callProviderMetadata` when `part.state === "input-available"`. This fix removes the overly-restrictive state check and adds `callProviderMetadata` to the input-streaming state types and schemas.
16
+
3
17
  ## 6.0.38
4
18
 
5
19
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1417,6 +1417,7 @@ type UIToolInvocation<TOOL extends UITool | Tool> = {
1417
1417
  input: DeepPartial<asUITool<TOOL>['input']> | undefined;
1418
1418
  output?: never;
1419
1419
  errorText?: never;
1420
+ callProviderMetadata?: ProviderMetadata;
1420
1421
  approval?: never;
1421
1422
  } | {
1422
1423
  state: 'input-available';
@@ -1508,6 +1509,7 @@ type DynamicToolUIPart = {
1508
1509
  input: unknown | undefined;
1509
1510
  output?: never;
1510
1511
  errorText?: never;
1512
+ callProviderMetadata?: ProviderMetadata;
1511
1513
  approval?: never;
1512
1514
  } | {
1513
1515
  state: 'input-available';
@@ -1654,6 +1656,7 @@ declare const uiMessageChunkSchema: _ai_sdk_provider_utils.LazySchema<{
1654
1656
  toolCallId: string;
1655
1657
  toolName: string;
1656
1658
  providerExecuted?: boolean | undefined;
1659
+ providerMetadata?: _ai_sdk_provider.SharedV3ProviderMetadata | undefined;
1657
1660
  dynamic?: boolean | undefined;
1658
1661
  title?: string | undefined;
1659
1662
  } | {
@@ -1746,6 +1749,7 @@ declare const uiMessageChunkSchema: _ai_sdk_provider_utils.LazySchema<{
1746
1749
  } | {
1747
1750
  type: "finish";
1748
1751
  finishReason?: "length" | "error" | "stop" | "content-filter" | "tool-calls" | "other" | undefined;
1752
+ usage?: LanguageModelUsage | undefined;
1749
1753
  messageMetadata?: unknown;
1750
1754
  } | {
1751
1755
  type: "abort";
@@ -1835,6 +1839,7 @@ type UIMessageChunk<METADATA = unknown, DATA_TYPES extends UIDataTypes = UIDataT
1835
1839
  toolCallId: string;
1836
1840
  toolName: string;
1837
1841
  providerExecuted?: boolean;
1842
+ providerMetadata?: ProviderMetadata;
1838
1843
  dynamic?: boolean;
1839
1844
  title?: string;
1840
1845
  } | {
@@ -1870,6 +1875,7 @@ type UIMessageChunk<METADATA = unknown, DATA_TYPES extends UIDataTypes = UIDataT
1870
1875
  } | {
1871
1876
  type: 'finish';
1872
1877
  finishReason?: FinishReason;
1878
+ usage?: LanguageModelUsage;
1873
1879
  messageMetadata?: METADATA;
1874
1880
  } | {
1875
1881
  type: 'abort';
@@ -3213,6 +3219,7 @@ type ChatOnDataCallback<UI_MESSAGE extends UIMessage> = (dataPart: DataUIPart<In
3213
3219
  * @param isDisconnect Indicates whether the request has been ended by a network error.
3214
3220
  * @param isError Indicates whether the request has been ended by an error.
3215
3221
  * @param finishReason The reason why the generation finished.
3222
+ * @param usage Token usage information for the response.
3216
3223
  */
3217
3224
  type ChatOnFinishCallback<UI_MESSAGE extends UIMessage> = (options: {
3218
3225
  message: UI_MESSAGE;
@@ -3221,6 +3228,7 @@ type ChatOnFinishCallback<UI_MESSAGE extends UIMessage> = (options: {
3221
3228
  isDisconnect: boolean;
3222
3229
  isError: boolean;
3223
3230
  finishReason?: FinishReason;
3231
+ usage?: LanguageModelUsage;
3224
3232
  }) => void;
3225
3233
  interface ChatInit<UI_MESSAGE extends UIMessage> {
3226
3234
  /**
package/dist/index.d.ts CHANGED
@@ -1417,6 +1417,7 @@ type UIToolInvocation<TOOL extends UITool | Tool> = {
1417
1417
  input: DeepPartial<asUITool<TOOL>['input']> | undefined;
1418
1418
  output?: never;
1419
1419
  errorText?: never;
1420
+ callProviderMetadata?: ProviderMetadata;
1420
1421
  approval?: never;
1421
1422
  } | {
1422
1423
  state: 'input-available';
@@ -1508,6 +1509,7 @@ type DynamicToolUIPart = {
1508
1509
  input: unknown | undefined;
1509
1510
  output?: never;
1510
1511
  errorText?: never;
1512
+ callProviderMetadata?: ProviderMetadata;
1511
1513
  approval?: never;
1512
1514
  } | {
1513
1515
  state: 'input-available';
@@ -1654,6 +1656,7 @@ declare const uiMessageChunkSchema: _ai_sdk_provider_utils.LazySchema<{
1654
1656
  toolCallId: string;
1655
1657
  toolName: string;
1656
1658
  providerExecuted?: boolean | undefined;
1659
+ providerMetadata?: _ai_sdk_provider.SharedV3ProviderMetadata | undefined;
1657
1660
  dynamic?: boolean | undefined;
1658
1661
  title?: string | undefined;
1659
1662
  } | {
@@ -1746,6 +1749,7 @@ declare const uiMessageChunkSchema: _ai_sdk_provider_utils.LazySchema<{
1746
1749
  } | {
1747
1750
  type: "finish";
1748
1751
  finishReason?: "length" | "error" | "stop" | "content-filter" | "tool-calls" | "other" | undefined;
1752
+ usage?: LanguageModelUsage | undefined;
1749
1753
  messageMetadata?: unknown;
1750
1754
  } | {
1751
1755
  type: "abort";
@@ -1835,6 +1839,7 @@ type UIMessageChunk<METADATA = unknown, DATA_TYPES extends UIDataTypes = UIDataT
1835
1839
  toolCallId: string;
1836
1840
  toolName: string;
1837
1841
  providerExecuted?: boolean;
1842
+ providerMetadata?: ProviderMetadata;
1838
1843
  dynamic?: boolean;
1839
1844
  title?: string;
1840
1845
  } | {
@@ -1870,6 +1875,7 @@ type UIMessageChunk<METADATA = unknown, DATA_TYPES extends UIDataTypes = UIDataT
1870
1875
  } | {
1871
1876
  type: 'finish';
1872
1877
  finishReason?: FinishReason;
1878
+ usage?: LanguageModelUsage;
1873
1879
  messageMetadata?: METADATA;
1874
1880
  } | {
1875
1881
  type: 'abort';
@@ -3213,6 +3219,7 @@ type ChatOnDataCallback<UI_MESSAGE extends UIMessage> = (dataPart: DataUIPart<In
3213
3219
  * @param isDisconnect Indicates whether the request has been ended by a network error.
3214
3220
  * @param isError Indicates whether the request has been ended by an error.
3215
3221
  * @param finishReason The reason why the generation finished.
3222
+ * @param usage Token usage information for the response.
3216
3223
  */
3217
3224
  type ChatOnFinishCallback<UI_MESSAGE extends UIMessage> = (options: {
3218
3225
  message: UI_MESSAGE;
@@ -3221,6 +3228,7 @@ type ChatOnFinishCallback<UI_MESSAGE extends UIMessage> = (options: {
3221
3228
  isDisconnect: boolean;
3222
3229
  isError: boolean;
3223
3230
  finishReason?: FinishReason;
3231
+ usage?: LanguageModelUsage;
3224
3232
  }) => void;
3225
3233
  interface ChatInit<UI_MESSAGE extends UIMessage> {
3226
3234
  /**