ai 6.0.301 → 6.0.303

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,30 @@
1
1
  # ai
2
2
 
3
+ ## 6.0.303
4
+
5
+ ### Patch Changes
6
+
7
+ - c0350be: fix(ai): prevent global type conflicts across SDK versions
8
+ - 88aa201: fix(ai): wait for chat stream cleanup when stopping
9
+ - 8444abe: fix(ai): discard unrelated message state when reading resumed streams
10
+ - Updated dependencies [897cb0c]
11
+ - Updated dependencies [7719e88]
12
+ - @ai-sdk/gateway@3.0.212
13
+
14
+ ## 6.0.302
15
+
16
+ ### Patch Changes
17
+
18
+ - 5430af1: fix(ai): preserve V2 provider-reported total tokens in raw usage
19
+ - f8d8324: fix(ai): publish the latest error after repeated failed stream resume attempts
20
+ - 5df41a7: fix(ai): prevent unavailable tools, including tools named after Object.prototype properties, from exposing persisted output to models
21
+ - 6a12ead: fix(ai): avoid duplicate slashes in chat reconnect URLs
22
+ - Updated dependencies [bedd5bb]
23
+ - Updated dependencies [6dd6693]
24
+ - Updated dependencies [5607cb2]
25
+ - Updated dependencies [fca8a28]
26
+ - @ai-sdk/gateway@3.0.211
27
+
3
28
  ## 6.0.301
4
29
 
5
30
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1836,6 +1836,13 @@ type ToolUIPart<TOOLS extends UITools = UITools> = ValueOf<{
1836
1836
  }>;
1837
1837
  type DynamicToolUIPart = {
1838
1838
  type: 'dynamic-tool';
1839
+ /**
1840
+ * `false` when a static tool part was normalized to a dynamic tool part
1841
+ * because its current tool schema was unavailable or incompatible.
1842
+ *
1843
+ * This preserves its static origin across persistence boundaries.
1844
+ */
1845
+ dynamic?: false;
1839
1846
  /**
1840
1847
  * Name of the tool that is being called.
1841
1848
  */
@@ -3298,7 +3305,15 @@ interface TelemetryIntegration {
3298
3305
  onFinish?: Listener<OnFinishEvent<ToolSet>>;
3299
3306
  }
3300
3307
 
3308
+ declare const aiSdkGlobalsKey: unique symbol;
3301
3309
  declare global {
3310
+ interface AISDKGlobalTypes {
3311
+ [aiSdkGlobalsKey]: {
3312
+ provider: ProviderV3;
3313
+ logWarnings: LogWarningsFunction;
3314
+ telemetry: TelemetryIntegration;
3315
+ };
3316
+ }
3302
3317
  /**
3303
3318
  * The default provider to use for the AI SDK.
3304
3319
  * String model ids are resolved to the default provider and model id.
@@ -3307,7 +3322,7 @@ declare global {
3307
3322
  *
3308
3323
  * @see https://ai-sdk.dev/docs/ai-sdk-core/provider-management#global-provider-configuration
3309
3324
  */
3310
- var AI_SDK_DEFAULT_PROVIDER: ProviderV3 | undefined;
3325
+ var AI_SDK_DEFAULT_PROVIDER: AISDKGlobalTypes[keyof AISDKGlobalTypes]['provider'] | undefined;
3311
3326
  /**
3312
3327
  * The warning logger to use for the AI SDK.
3313
3328
  *
@@ -3315,7 +3330,7 @@ declare global {
3315
3330
  *
3316
3331
  * If set to false, no warnings are logged.
3317
3332
  */
3318
- var AI_SDK_LOG_WARNINGS: LogWarningsFunction | undefined | false;
3333
+ var AI_SDK_LOG_WARNINGS: AISDKGlobalTypes[keyof AISDKGlobalTypes]['logWarnings'] | undefined | false;
3319
3334
  /**
3320
3335
  * Globally registered telemetry integrations for the AI SDK.
3321
3336
  *
@@ -3325,7 +3340,7 @@ declare global {
3325
3340
  * Prefer using `registerTelemetryIntegration()` from `'ai'` instead of
3326
3341
  * assigning this directly.
3327
3342
  */
3328
- var AI_SDK_TELEMETRY_INTEGRATIONS: TelemetryIntegration[] | undefined;
3343
+ var AI_SDK_TELEMETRY_INTEGRATIONS: Array<AISDKGlobalTypes[keyof AISDKGlobalTypes]['telemetry']> | undefined;
3329
3344
  }
3330
3345
 
3331
3346
  type ToolLoopAgentOnStepFinishCallback<TOOLS extends ToolSet = {}> = (stepResult: OnStepFinishEvent<TOOLS>) => Promise<void> | void;
@@ -3890,6 +3905,8 @@ declare abstract class AbstractChat<UI_MESSAGE extends UIMessage> {
3890
3905
  private activeResumeRequest;
3891
3906
  private resumableStreamState;
3892
3907
  private jobExecutor;
3908
+ private activeStopCount;
3909
+ private stopGeneration;
3893
3910
  constructor({ generateId, id, transport, messageMetadataSchema, dataPartSchemas, state, onError, onToolCall, onFinish, onData, sendAutomaticallyWhen, }: Omit<ChatInit<UI_MESSAGE>, 'messages'> & {
3894
3911
  state: ChatState<UI_MESSAGE>;
3895
3912
  });
@@ -3952,12 +3969,15 @@ declare abstract class AbstractChat<UI_MESSAGE extends UIMessage> {
3952
3969
  /** @deprecated Use addToolOutput */
3953
3970
  addToolResult: ChatAddToolOutputFunction<UI_MESSAGE>;
3954
3971
  /**
3955
- * Abort the current request immediately, keep the generated tokens if any.
3972
+ * Abort the current request, keep the generated tokens if any, and wait for
3973
+ * the request pipeline to finish.
3956
3974
  */
3957
3975
  stop: () => Promise<void>;
3958
3976
  private shouldSendAutomatically;
3977
+ private runAutomaticRequest;
3959
3978
  private makeRequestForToolApproval;
3960
3979
  private makeRequest;
3980
+ private makeRequestImpl;
3961
3981
  }
3962
3982
 
3963
3983
  declare function convertFileListToFileUIParts(files: FileList | undefined): Promise<Array<FileUIPart>>;
@@ -5477,8 +5497,10 @@ type Job = () => Promise<void>;
5477
5497
  declare class SerialJobExecutor {
5478
5498
  private queue;
5479
5499
  private isProcessing;
5500
+ private idleWaiters;
5480
5501
  private processQueue;
5481
5502
  run(job: Job): Promise<void>;
5503
+ waitForIdle(): Promise<void>;
5482
5504
  }
5483
5505
 
5484
5506
  /**
package/dist/index.d.ts CHANGED
@@ -1836,6 +1836,13 @@ type ToolUIPart<TOOLS extends UITools = UITools> = ValueOf<{
1836
1836
  }>;
1837
1837
  type DynamicToolUIPart = {
1838
1838
  type: 'dynamic-tool';
1839
+ /**
1840
+ * `false` when a static tool part was normalized to a dynamic tool part
1841
+ * because its current tool schema was unavailable or incompatible.
1842
+ *
1843
+ * This preserves its static origin across persistence boundaries.
1844
+ */
1845
+ dynamic?: false;
1839
1846
  /**
1840
1847
  * Name of the tool that is being called.
1841
1848
  */
@@ -3298,7 +3305,15 @@ interface TelemetryIntegration {
3298
3305
  onFinish?: Listener<OnFinishEvent<ToolSet>>;
3299
3306
  }
3300
3307
 
3308
+ declare const aiSdkGlobalsKey: unique symbol;
3301
3309
  declare global {
3310
+ interface AISDKGlobalTypes {
3311
+ [aiSdkGlobalsKey]: {
3312
+ provider: ProviderV3;
3313
+ logWarnings: LogWarningsFunction;
3314
+ telemetry: TelemetryIntegration;
3315
+ };
3316
+ }
3302
3317
  /**
3303
3318
  * The default provider to use for the AI SDK.
3304
3319
  * String model ids are resolved to the default provider and model id.
@@ -3307,7 +3322,7 @@ declare global {
3307
3322
  *
3308
3323
  * @see https://ai-sdk.dev/docs/ai-sdk-core/provider-management#global-provider-configuration
3309
3324
  */
3310
- var AI_SDK_DEFAULT_PROVIDER: ProviderV3 | undefined;
3325
+ var AI_SDK_DEFAULT_PROVIDER: AISDKGlobalTypes[keyof AISDKGlobalTypes]['provider'] | undefined;
3311
3326
  /**
3312
3327
  * The warning logger to use for the AI SDK.
3313
3328
  *
@@ -3315,7 +3330,7 @@ declare global {
3315
3330
  *
3316
3331
  * If set to false, no warnings are logged.
3317
3332
  */
3318
- var AI_SDK_LOG_WARNINGS: LogWarningsFunction | undefined | false;
3333
+ var AI_SDK_LOG_WARNINGS: AISDKGlobalTypes[keyof AISDKGlobalTypes]['logWarnings'] | undefined | false;
3319
3334
  /**
3320
3335
  * Globally registered telemetry integrations for the AI SDK.
3321
3336
  *
@@ -3325,7 +3340,7 @@ declare global {
3325
3340
  * Prefer using `registerTelemetryIntegration()` from `'ai'` instead of
3326
3341
  * assigning this directly.
3327
3342
  */
3328
- var AI_SDK_TELEMETRY_INTEGRATIONS: TelemetryIntegration[] | undefined;
3343
+ var AI_SDK_TELEMETRY_INTEGRATIONS: Array<AISDKGlobalTypes[keyof AISDKGlobalTypes]['telemetry']> | undefined;
3329
3344
  }
3330
3345
 
3331
3346
  type ToolLoopAgentOnStepFinishCallback<TOOLS extends ToolSet = {}> = (stepResult: OnStepFinishEvent<TOOLS>) => Promise<void> | void;
@@ -3890,6 +3905,8 @@ declare abstract class AbstractChat<UI_MESSAGE extends UIMessage> {
3890
3905
  private activeResumeRequest;
3891
3906
  private resumableStreamState;
3892
3907
  private jobExecutor;
3908
+ private activeStopCount;
3909
+ private stopGeneration;
3893
3910
  constructor({ generateId, id, transport, messageMetadataSchema, dataPartSchemas, state, onError, onToolCall, onFinish, onData, sendAutomaticallyWhen, }: Omit<ChatInit<UI_MESSAGE>, 'messages'> & {
3894
3911
  state: ChatState<UI_MESSAGE>;
3895
3912
  });
@@ -3952,12 +3969,15 @@ declare abstract class AbstractChat<UI_MESSAGE extends UIMessage> {
3952
3969
  /** @deprecated Use addToolOutput */
3953
3970
  addToolResult: ChatAddToolOutputFunction<UI_MESSAGE>;
3954
3971
  /**
3955
- * Abort the current request immediately, keep the generated tokens if any.
3972
+ * Abort the current request, keep the generated tokens if any, and wait for
3973
+ * the request pipeline to finish.
3956
3974
  */
3957
3975
  stop: () => Promise<void>;
3958
3976
  private shouldSendAutomatically;
3977
+ private runAutomaticRequest;
3959
3978
  private makeRequestForToolApproval;
3960
3979
  private makeRequest;
3980
+ private makeRequestImpl;
3961
3981
  }
3962
3982
 
3963
3983
  declare function convertFileListToFileUIParts(files: FileList | undefined): Promise<Array<FileUIPart>>;
@@ -5477,8 +5497,10 @@ type Job = () => Promise<void>;
5477
5497
  declare class SerialJobExecutor {
5478
5498
  private queue;
5479
5499
  private isProcessing;
5500
+ private idleWaiters;
5480
5501
  private processQueue;
5481
5502
  run(job: Job): Promise<void>;
5503
+ waitForIdle(): Promise<void>;
5482
5504
  }
5483
5505
 
5484
5506
  /**