ai 6.0.302 → 6.0.304

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,29 @@
1
1
  # ai
2
2
 
3
+ ## 6.0.304
4
+
5
+ ### Patch Changes
6
+
7
+ - fade070: fix: resume interrupted chat streams when the page becomes visible again
8
+
9
+ `useChat` with `resume: true` no longer starts a second resume request on mount when the chat is already submitted or streaming, e.g. when remounting with a shared `Chat` instance mid-stream.
10
+
11
+ - 8e74de0: fix(ai): update tool outputs in the message containing the matching tool call
12
+ - a5c9cca: fix(ai): prevent duplicate message parts when resuming replayed streams
13
+ - 7888841: fix(ai): update streaming chat messages by stable ID
14
+ - e466fb0: fix(ai): reject approved tool calls without results before sending later context to providers
15
+
16
+ ## 6.0.303
17
+
18
+ ### Patch Changes
19
+
20
+ - c0350be: fix(ai): prevent global type conflicts across SDK versions
21
+ - 88aa201: fix(ai): wait for chat stream cleanup when stopping
22
+ - 8444abe: fix(ai): discard unrelated message state when reading resumed streams
23
+ - Updated dependencies [897cb0c]
24
+ - Updated dependencies [7719e88]
25
+ - @ai-sdk/gateway@3.0.212
26
+
3
27
  ## 6.0.302
4
28
 
5
29
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -3305,7 +3305,15 @@ interface TelemetryIntegration {
3305
3305
  onFinish?: Listener<OnFinishEvent<ToolSet>>;
3306
3306
  }
3307
3307
 
3308
+ declare const aiSdkGlobalsKey: unique symbol;
3308
3309
  declare global {
3310
+ interface AISDKGlobalTypes {
3311
+ [aiSdkGlobalsKey]: {
3312
+ provider: ProviderV3;
3313
+ logWarnings: LogWarningsFunction;
3314
+ telemetry: TelemetryIntegration;
3315
+ };
3316
+ }
3309
3317
  /**
3310
3318
  * The default provider to use for the AI SDK.
3311
3319
  * String model ids are resolved to the default provider and model id.
@@ -3314,7 +3322,7 @@ declare global {
3314
3322
  *
3315
3323
  * @see https://ai-sdk.dev/docs/ai-sdk-core/provider-management#global-provider-configuration
3316
3324
  */
3317
- var AI_SDK_DEFAULT_PROVIDER: ProviderV3 | undefined;
3325
+ var AI_SDK_DEFAULT_PROVIDER: AISDKGlobalTypes[keyof AISDKGlobalTypes]['provider'] | undefined;
3318
3326
  /**
3319
3327
  * The warning logger to use for the AI SDK.
3320
3328
  *
@@ -3322,7 +3330,7 @@ declare global {
3322
3330
  *
3323
3331
  * If set to false, no warnings are logged.
3324
3332
  */
3325
- var AI_SDK_LOG_WARNINGS: LogWarningsFunction | undefined | false;
3333
+ var AI_SDK_LOG_WARNINGS: AISDKGlobalTypes[keyof AISDKGlobalTypes]['logWarnings'] | undefined | false;
3326
3334
  /**
3327
3335
  * Globally registered telemetry integrations for the AI SDK.
3328
3336
  *
@@ -3332,7 +3340,7 @@ declare global {
3332
3340
  * Prefer using `registerTelemetryIntegration()` from `'ai'` instead of
3333
3341
  * assigning this directly.
3334
3342
  */
3335
- var AI_SDK_TELEMETRY_INTEGRATIONS: TelemetryIntegration[] | undefined;
3343
+ var AI_SDK_TELEMETRY_INTEGRATIONS: Array<AISDKGlobalTypes[keyof AISDKGlobalTypes]['telemetry']> | undefined;
3336
3344
  }
3337
3345
 
3338
3346
  type ToolLoopAgentOnStepFinishCallback<TOOLS extends ToolSet = {}> = (stepResult: OnStepFinishEvent<TOOLS>) => Promise<void> | void;
@@ -3669,6 +3677,12 @@ declare function callCompletionApi({ api, prompt, credentials, headers, body, st
3669
3677
  * @template UI_MESSAGE - The UI message type extending UIMessage
3670
3678
  */
3671
3679
  interface ChatTransport<UI_MESSAGE extends UIMessage> {
3680
+ /**
3681
+ * Whether reconnecting returns the complete response from its beginning.
3682
+ * Complete replays must reset the streaming message state before processing
3683
+ * the first start chunk.
3684
+ */
3685
+ readonly resumeStreamIsReplay?: boolean;
3672
3686
  /**
3673
3687
  * Sends messages to the chat API endpoint and returns a streaming response.
3674
3688
  *
@@ -3897,6 +3911,8 @@ declare abstract class AbstractChat<UI_MESSAGE extends UIMessage> {
3897
3911
  private activeResumeRequest;
3898
3912
  private resumableStreamState;
3899
3913
  private jobExecutor;
3914
+ private activeStopCount;
3915
+ private stopGeneration;
3900
3916
  constructor({ generateId, id, transport, messageMetadataSchema, dataPartSchemas, state, onError, onToolCall, onFinish, onData, sendAutomaticallyWhen, }: Omit<ChatInit<UI_MESSAGE>, 'messages'> & {
3901
3917
  state: ChatState<UI_MESSAGE>;
3902
3918
  });
@@ -3959,12 +3975,15 @@ declare abstract class AbstractChat<UI_MESSAGE extends UIMessage> {
3959
3975
  /** @deprecated Use addToolOutput */
3960
3976
  addToolResult: ChatAddToolOutputFunction<UI_MESSAGE>;
3961
3977
  /**
3962
- * Abort the current request immediately, keep the generated tokens if any.
3978
+ * Abort the current request, keep the generated tokens if any, and wait for
3979
+ * the request pipeline to finish.
3963
3980
  */
3964
3981
  stop: () => Promise<void>;
3965
3982
  private shouldSendAutomatically;
3983
+ private runAutomaticRequest;
3966
3984
  private makeRequestForToolApproval;
3967
3985
  private makeRequest;
3986
+ private makeRequestImpl;
3968
3987
  }
3969
3988
 
3970
3989
  declare function convertFileListToFileUIParts(files: FileList | undefined): Promise<Array<FileUIPart>>;
@@ -4091,7 +4110,15 @@ declare abstract class HttpChatTransport<UI_MESSAGE extends UIMessage> implement
4091
4110
  }
4092
4111
 
4093
4112
  declare class DefaultChatTransport<UI_MESSAGE extends UIMessage> extends HttpChatTransport<UI_MESSAGE> {
4094
- constructor(options?: HttpChatTransportInitOptions<UI_MESSAGE>);
4113
+ readonly resumeStreamIsReplay: boolean;
4114
+ constructor({ resumeStreamIsReplay, ...options }?: HttpChatTransportInitOptions<UI_MESSAGE> & {
4115
+ /**
4116
+ * Whether resumed streams replay the response from the beginning.
4117
+ * Defaults to true. Set to false for endpoints that only continue the
4118
+ * interrupted response, even when they emit a start chunk.
4119
+ */
4120
+ resumeStreamIsReplay?: boolean;
4121
+ });
4095
4122
  protected processResponseStream(stream: ReadableStream<Uint8Array<ArrayBufferLike>>): ReadableStream<UIMessageChunk>;
4096
4123
  }
4097
4124
 
@@ -5484,8 +5511,10 @@ type Job = () => Promise<void>;
5484
5511
  declare class SerialJobExecutor {
5485
5512
  private queue;
5486
5513
  private isProcessing;
5514
+ private idleWaiters;
5487
5515
  private processQueue;
5488
5516
  run(job: Job): Promise<void>;
5517
+ waitForIdle(): Promise<void>;
5489
5518
  }
5490
5519
 
5491
5520
  /**
package/dist/index.d.ts CHANGED
@@ -3305,7 +3305,15 @@ interface TelemetryIntegration {
3305
3305
  onFinish?: Listener<OnFinishEvent<ToolSet>>;
3306
3306
  }
3307
3307
 
3308
+ declare const aiSdkGlobalsKey: unique symbol;
3308
3309
  declare global {
3310
+ interface AISDKGlobalTypes {
3311
+ [aiSdkGlobalsKey]: {
3312
+ provider: ProviderV3;
3313
+ logWarnings: LogWarningsFunction;
3314
+ telemetry: TelemetryIntegration;
3315
+ };
3316
+ }
3309
3317
  /**
3310
3318
  * The default provider to use for the AI SDK.
3311
3319
  * String model ids are resolved to the default provider and model id.
@@ -3314,7 +3322,7 @@ declare global {
3314
3322
  *
3315
3323
  * @see https://ai-sdk.dev/docs/ai-sdk-core/provider-management#global-provider-configuration
3316
3324
  */
3317
- var AI_SDK_DEFAULT_PROVIDER: ProviderV3 | undefined;
3325
+ var AI_SDK_DEFAULT_PROVIDER: AISDKGlobalTypes[keyof AISDKGlobalTypes]['provider'] | undefined;
3318
3326
  /**
3319
3327
  * The warning logger to use for the AI SDK.
3320
3328
  *
@@ -3322,7 +3330,7 @@ declare global {
3322
3330
  *
3323
3331
  * If set to false, no warnings are logged.
3324
3332
  */
3325
- var AI_SDK_LOG_WARNINGS: LogWarningsFunction | undefined | false;
3333
+ var AI_SDK_LOG_WARNINGS: AISDKGlobalTypes[keyof AISDKGlobalTypes]['logWarnings'] | undefined | false;
3326
3334
  /**
3327
3335
  * Globally registered telemetry integrations for the AI SDK.
3328
3336
  *
@@ -3332,7 +3340,7 @@ declare global {
3332
3340
  * Prefer using `registerTelemetryIntegration()` from `'ai'` instead of
3333
3341
  * assigning this directly.
3334
3342
  */
3335
- var AI_SDK_TELEMETRY_INTEGRATIONS: TelemetryIntegration[] | undefined;
3343
+ var AI_SDK_TELEMETRY_INTEGRATIONS: Array<AISDKGlobalTypes[keyof AISDKGlobalTypes]['telemetry']> | undefined;
3336
3344
  }
3337
3345
 
3338
3346
  type ToolLoopAgentOnStepFinishCallback<TOOLS extends ToolSet = {}> = (stepResult: OnStepFinishEvent<TOOLS>) => Promise<void> | void;
@@ -3669,6 +3677,12 @@ declare function callCompletionApi({ api, prompt, credentials, headers, body, st
3669
3677
  * @template UI_MESSAGE - The UI message type extending UIMessage
3670
3678
  */
3671
3679
  interface ChatTransport<UI_MESSAGE extends UIMessage> {
3680
+ /**
3681
+ * Whether reconnecting returns the complete response from its beginning.
3682
+ * Complete replays must reset the streaming message state before processing
3683
+ * the first start chunk.
3684
+ */
3685
+ readonly resumeStreamIsReplay?: boolean;
3672
3686
  /**
3673
3687
  * Sends messages to the chat API endpoint and returns a streaming response.
3674
3688
  *
@@ -3897,6 +3911,8 @@ declare abstract class AbstractChat<UI_MESSAGE extends UIMessage> {
3897
3911
  private activeResumeRequest;
3898
3912
  private resumableStreamState;
3899
3913
  private jobExecutor;
3914
+ private activeStopCount;
3915
+ private stopGeneration;
3900
3916
  constructor({ generateId, id, transport, messageMetadataSchema, dataPartSchemas, state, onError, onToolCall, onFinish, onData, sendAutomaticallyWhen, }: Omit<ChatInit<UI_MESSAGE>, 'messages'> & {
3901
3917
  state: ChatState<UI_MESSAGE>;
3902
3918
  });
@@ -3959,12 +3975,15 @@ declare abstract class AbstractChat<UI_MESSAGE extends UIMessage> {
3959
3975
  /** @deprecated Use addToolOutput */
3960
3976
  addToolResult: ChatAddToolOutputFunction<UI_MESSAGE>;
3961
3977
  /**
3962
- * Abort the current request immediately, keep the generated tokens if any.
3978
+ * Abort the current request, keep the generated tokens if any, and wait for
3979
+ * the request pipeline to finish.
3963
3980
  */
3964
3981
  stop: () => Promise<void>;
3965
3982
  private shouldSendAutomatically;
3983
+ private runAutomaticRequest;
3966
3984
  private makeRequestForToolApproval;
3967
3985
  private makeRequest;
3986
+ private makeRequestImpl;
3968
3987
  }
3969
3988
 
3970
3989
  declare function convertFileListToFileUIParts(files: FileList | undefined): Promise<Array<FileUIPart>>;
@@ -4091,7 +4110,15 @@ declare abstract class HttpChatTransport<UI_MESSAGE extends UIMessage> implement
4091
4110
  }
4092
4111
 
4093
4112
  declare class DefaultChatTransport<UI_MESSAGE extends UIMessage> extends HttpChatTransport<UI_MESSAGE> {
4094
- constructor(options?: HttpChatTransportInitOptions<UI_MESSAGE>);
4113
+ readonly resumeStreamIsReplay: boolean;
4114
+ constructor({ resumeStreamIsReplay, ...options }?: HttpChatTransportInitOptions<UI_MESSAGE> & {
4115
+ /**
4116
+ * Whether resumed streams replay the response from the beginning.
4117
+ * Defaults to true. Set to false for endpoints that only continue the
4118
+ * interrupted response, even when they emit a start chunk.
4119
+ */
4120
+ resumeStreamIsReplay?: boolean;
4121
+ });
4095
4122
  protected processResponseStream(stream: ReadableStream<Uint8Array<ArrayBufferLike>>): ReadableStream<UIMessageChunk>;
4096
4123
  }
4097
4124
 
@@ -5484,8 +5511,10 @@ type Job = () => Promise<void>;
5484
5511
  declare class SerialJobExecutor {
5485
5512
  private queue;
5486
5513
  private isProcessing;
5514
+ private idleWaiters;
5487
5515
  private processQueue;
5488
5516
  run(job: Job): Promise<void>;
5517
+ waitForIdle(): Promise<void>;
5489
5518
  }
5490
5519
 
5491
5520
  /**