ai 6.0.13 → 6.0.15
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 +12 -0
- package/dist/index.d.mts +23 -5
- package/dist/index.d.ts +23 -5
- package/dist/index.js +60 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +60 -10
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +5 -0
- package/dist/internal/index.d.ts +5 -0
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.mjs +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# ai
|
|
2
2
|
|
|
3
|
+
## 6.0.15
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 3a73fb3: Include abort reason in stream chunks and document the new field
|
|
8
|
+
|
|
9
|
+
## 6.0.14
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 3f9453f: feat(ai): add timeout option to generateText, streamText, and Agent
|
|
14
|
+
|
|
3
15
|
## 6.0.13
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1006,6 +1006,11 @@ type CallSettings = {
|
|
|
1006
1006
|
*/
|
|
1007
1007
|
abortSignal?: AbortSignal;
|
|
1008
1008
|
/**
|
|
1009
|
+
Timeout in milliseconds. The call will be aborted if it takes longer
|
|
1010
|
+
than the specified timeout. Can be used alongside abortSignal.
|
|
1011
|
+
*/
|
|
1012
|
+
timeout?: number;
|
|
1013
|
+
/**
|
|
1009
1014
|
Additional HTTP headers to be sent with the request.
|
|
1010
1015
|
Only applicable for HTTP-based providers.
|
|
1011
1016
|
*/
|
|
@@ -1317,6 +1322,7 @@ If set and supported by the model, calls will generate deterministic results.
|
|
|
1317
1322
|
|
|
1318
1323
|
@param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
|
|
1319
1324
|
@param abortSignal - An optional abort signal that can be used to cancel the call.
|
|
1325
|
+
@param timeout - An optional timeout in milliseconds. The call will be aborted if it takes longer than the specified timeout.
|
|
1320
1326
|
@param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
|
|
1321
1327
|
|
|
1322
1328
|
@param experimental_generateMessageId - Generate a unique ID for each message.
|
|
@@ -1327,7 +1333,7 @@ If set and supported by the model, calls will generate deterministic results.
|
|
|
1327
1333
|
@returns
|
|
1328
1334
|
A result object that contains the generated text, the results of the tool calls, and additional information.
|
|
1329
1335
|
*/
|
|
1330
|
-
declare function generateText<TOOLS extends ToolSet, OUTPUT extends Output = Output<string, string>>({ model: modelArg, tools, toolChoice, system, prompt, messages, maxRetries: maxRetriesArg, abortSignal, headers, stopWhen, experimental_output, output, experimental_telemetry: telemetry, providerOptions, experimental_activeTools, activeTools, experimental_prepareStep, prepareStep, experimental_repairToolCall: repairToolCall, experimental_download: download, experimental_context, _internal: { generateId, currentDate, }, onStepFinish, onFinish, ...settings }: CallSettings & Prompt & {
|
|
1336
|
+
declare function generateText<TOOLS extends ToolSet, OUTPUT extends Output = Output<string, string>>({ model: modelArg, tools, toolChoice, system, prompt, messages, maxRetries: maxRetriesArg, abortSignal, timeout, headers, stopWhen, experimental_output, output, experimental_telemetry: telemetry, providerOptions, experimental_activeTools, activeTools, experimental_prepareStep, prepareStep, experimental_repairToolCall: repairToolCall, experimental_download: download, experimental_context, _internal: { generateId, currentDate, }, onStepFinish, onFinish, ...settings }: CallSettings & Prompt & {
|
|
1331
1337
|
/**
|
|
1332
1338
|
The language model to use.
|
|
1333
1339
|
*/
|
|
@@ -1988,6 +1994,7 @@ declare const uiMessageChunkSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
1988
1994
|
messageMetadata?: unknown;
|
|
1989
1995
|
} | {
|
|
1990
1996
|
type: "abort";
|
|
1997
|
+
reason?: string | undefined;
|
|
1991
1998
|
} | {
|
|
1992
1999
|
type: "message-metadata";
|
|
1993
2000
|
messageMetadata: unknown;
|
|
@@ -2111,6 +2118,7 @@ type UIMessageChunk<METADATA = unknown, DATA_TYPES extends UIDataTypes = UIDataT
|
|
|
2111
2118
|
messageMetadata?: METADATA;
|
|
2112
2119
|
} | {
|
|
2113
2120
|
type: 'abort';
|
|
2121
|
+
reason?: string;
|
|
2114
2122
|
} | {
|
|
2115
2123
|
type: 'message-metadata';
|
|
2116
2124
|
messageMetadata: METADATA;
|
|
@@ -2500,6 +2508,7 @@ type TextStreamPart<TOOLS extends ToolSet> = {
|
|
|
2500
2508
|
totalUsage: LanguageModelUsage;
|
|
2501
2509
|
} | {
|
|
2502
2510
|
type: 'abort';
|
|
2511
|
+
reason?: string;
|
|
2503
2512
|
} | {
|
|
2504
2513
|
type: 'error';
|
|
2505
2514
|
error: unknown;
|
|
@@ -2611,6 +2620,7 @@ If set and supported by the model, calls will generate deterministic results.
|
|
|
2611
2620
|
|
|
2612
2621
|
@param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
|
|
2613
2622
|
@param abortSignal - An optional abort signal that can be used to cancel the call.
|
|
2623
|
+
@param timeout - An optional timeout in milliseconds. The call will be aborted if it takes longer than the specified timeout.
|
|
2614
2624
|
@param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
|
|
2615
2625
|
|
|
2616
2626
|
@param onChunk - Callback that is called for each chunk of the stream. The stream processing will pause until the callback promise is resolved.
|
|
@@ -2621,7 +2631,7 @@ If set and supported by the model, calls will generate deterministic results.
|
|
|
2621
2631
|
@return
|
|
2622
2632
|
A result object for accessing different stream types and additional information.
|
|
2623
2633
|
*/
|
|
2624
|
-
declare function streamText<TOOLS extends ToolSet, OUTPUT extends Output = Output<string, string>>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, headers, stopWhen, experimental_output, output, experimental_telemetry: telemetry, prepareStep, providerOptions, experimental_activeTools, activeTools, experimental_repairToolCall: repairToolCall, experimental_transform: transform, experimental_download: download, includeRawChunks, onChunk, onError, onFinish, onAbort, onStepFinish, experimental_context, _internal: { now, generateId, currentDate, }, ...settings }: CallSettings & Prompt & {
|
|
2634
|
+
declare function streamText<TOOLS extends ToolSet, OUTPUT extends Output = Output<string, string>>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, timeout, headers, stopWhen, experimental_output, output, experimental_telemetry: telemetry, prepareStep, providerOptions, experimental_activeTools, activeTools, experimental_repairToolCall: repairToolCall, experimental_transform: transform, experimental_download: download, includeRawChunks, onChunk, onError, onFinish, onAbort, onStepFinish, experimental_context, _internal: { now, generateId, currentDate, }, ...settings }: CallSettings & Prompt & {
|
|
2625
2635
|
/**
|
|
2626
2636
|
The language model to use.
|
|
2627
2637
|
*/
|
|
@@ -2784,6 +2794,10 @@ type AgentCallParameters<CALL_OPTIONS> = ([CALL_OPTIONS] extends [never] ? {
|
|
|
2784
2794
|
* Abort signal.
|
|
2785
2795
|
*/
|
|
2786
2796
|
abortSignal?: AbortSignal;
|
|
2797
|
+
/**
|
|
2798
|
+
* Timeout in milliseconds.
|
|
2799
|
+
*/
|
|
2800
|
+
timeout?: number;
|
|
2787
2801
|
};
|
|
2788
2802
|
/**
|
|
2789
2803
|
* Parameters for streaming an output from an agent.
|
|
@@ -2979,11 +2993,11 @@ declare class ToolLoopAgent<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OU
|
|
|
2979
2993
|
/**
|
|
2980
2994
|
* Generates an output from the agent (non-streaming).
|
|
2981
2995
|
*/
|
|
2982
|
-
generate({ abortSignal, ...options }: AgentCallParameters<CALL_OPTIONS>): Promise<GenerateTextResult<TOOLS, OUTPUT>>;
|
|
2996
|
+
generate({ abortSignal, timeout, ...options }: AgentCallParameters<CALL_OPTIONS>): Promise<GenerateTextResult<TOOLS, OUTPUT>>;
|
|
2983
2997
|
/**
|
|
2984
2998
|
* Streams an output from the agent (streaming).
|
|
2985
2999
|
*/
|
|
2986
|
-
stream({ abortSignal, experimental_transform, ...options }: AgentStreamParameters<CALL_OPTIONS, TOOLS>): Promise<StreamTextResult<TOOLS, OUTPUT>>;
|
|
3000
|
+
stream({ abortSignal, timeout, experimental_transform, ...options }: AgentStreamParameters<CALL_OPTIONS, TOOLS>): Promise<StreamTextResult<TOOLS, OUTPUT>>;
|
|
2987
3001
|
}
|
|
2988
3002
|
|
|
2989
3003
|
/**
|
|
@@ -3008,6 +3022,7 @@ declare function createAgentUIStreamResponse<CALL_OPTIONS = never, TOOLS extends
|
|
|
3008
3022
|
agent: Agent<CALL_OPTIONS, TOOLS, OUTPUT>;
|
|
3009
3023
|
uiMessages: unknown[];
|
|
3010
3024
|
abortSignal?: AbortSignal;
|
|
3025
|
+
timeout?: number;
|
|
3011
3026
|
options?: CALL_OPTIONS;
|
|
3012
3027
|
experimental_transform?: StreamTextTransform<TOOLS> | Array<StreamTextTransform<TOOLS>>;
|
|
3013
3028
|
} & UIMessageStreamResponseInit & UIMessageStreamOptions<UIMessage<MESSAGE_METADATA, never, InferUITools<TOOLS>>>): Promise<Response>;
|
|
@@ -3718,15 +3733,17 @@ declare const UI_MESSAGE_STREAM_HEADERS: {
|
|
|
3718
3733
|
* @param agent - The agent to run.
|
|
3719
3734
|
* @param uiMessages - The input UI messages.
|
|
3720
3735
|
* @param abortSignal - The abort signal. Optional.
|
|
3736
|
+
* @param timeout - Timeout in milliseconds. Optional.
|
|
3721
3737
|
* @param options - The options for the agent.
|
|
3722
3738
|
* @param experimental_transform - The stream transformations. Optional.
|
|
3723
3739
|
*
|
|
3724
3740
|
* @returns The UI message stream.
|
|
3725
3741
|
*/
|
|
3726
|
-
declare function createAgentUIStream<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUTPUT extends Output = never, MESSAGE_METADATA = unknown>({ agent, uiMessages, options, abortSignal, experimental_transform, ...uiMessageStreamOptions }: {
|
|
3742
|
+
declare function createAgentUIStream<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUTPUT extends Output = never, MESSAGE_METADATA = unknown>({ agent, uiMessages, options, abortSignal, timeout, experimental_transform, ...uiMessageStreamOptions }: {
|
|
3727
3743
|
agent: Agent<CALL_OPTIONS, TOOLS, OUTPUT>;
|
|
3728
3744
|
uiMessages: unknown[];
|
|
3729
3745
|
abortSignal?: AbortSignal;
|
|
3746
|
+
timeout?: number;
|
|
3730
3747
|
options?: CALL_OPTIONS;
|
|
3731
3748
|
experimental_transform?: StreamTextTransform<TOOLS> | Array<StreamTextTransform<TOOLS>>;
|
|
3732
3749
|
} & UIMessageStreamOptions<UIMessage<MESSAGE_METADATA, never, InferUITools<TOOLS>>>): Promise<AsyncIterableStream<InferUIMessageChunk<UIMessage<MESSAGE_METADATA, never, InferUITools<TOOLS>>>>>;
|
|
@@ -3742,6 +3759,7 @@ declare function pipeAgentUIStreamToResponse<CALL_OPTIONS = never, TOOLS extends
|
|
|
3742
3759
|
agent: Agent<CALL_OPTIONS, TOOLS, OUTPUT>;
|
|
3743
3760
|
uiMessages: unknown[];
|
|
3744
3761
|
abortSignal?: AbortSignal;
|
|
3762
|
+
timeout?: number;
|
|
3745
3763
|
options?: CALL_OPTIONS;
|
|
3746
3764
|
experimental_transform?: StreamTextTransform<TOOLS> | Array<StreamTextTransform<TOOLS>>;
|
|
3747
3765
|
} & UIMessageStreamResponseInit & UIMessageStreamOptions<UIMessage<MESSAGE_METADATA, never, InferUITools<TOOLS>>>): Promise<void>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1006,6 +1006,11 @@ type CallSettings = {
|
|
|
1006
1006
|
*/
|
|
1007
1007
|
abortSignal?: AbortSignal;
|
|
1008
1008
|
/**
|
|
1009
|
+
Timeout in milliseconds. The call will be aborted if it takes longer
|
|
1010
|
+
than the specified timeout. Can be used alongside abortSignal.
|
|
1011
|
+
*/
|
|
1012
|
+
timeout?: number;
|
|
1013
|
+
/**
|
|
1009
1014
|
Additional HTTP headers to be sent with the request.
|
|
1010
1015
|
Only applicable for HTTP-based providers.
|
|
1011
1016
|
*/
|
|
@@ -1317,6 +1322,7 @@ If set and supported by the model, calls will generate deterministic results.
|
|
|
1317
1322
|
|
|
1318
1323
|
@param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
|
|
1319
1324
|
@param abortSignal - An optional abort signal that can be used to cancel the call.
|
|
1325
|
+
@param timeout - An optional timeout in milliseconds. The call will be aborted if it takes longer than the specified timeout.
|
|
1320
1326
|
@param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
|
|
1321
1327
|
|
|
1322
1328
|
@param experimental_generateMessageId - Generate a unique ID for each message.
|
|
@@ -1327,7 +1333,7 @@ If set and supported by the model, calls will generate deterministic results.
|
|
|
1327
1333
|
@returns
|
|
1328
1334
|
A result object that contains the generated text, the results of the tool calls, and additional information.
|
|
1329
1335
|
*/
|
|
1330
|
-
declare function generateText<TOOLS extends ToolSet, OUTPUT extends Output = Output<string, string>>({ model: modelArg, tools, toolChoice, system, prompt, messages, maxRetries: maxRetriesArg, abortSignal, headers, stopWhen, experimental_output, output, experimental_telemetry: telemetry, providerOptions, experimental_activeTools, activeTools, experimental_prepareStep, prepareStep, experimental_repairToolCall: repairToolCall, experimental_download: download, experimental_context, _internal: { generateId, currentDate, }, onStepFinish, onFinish, ...settings }: CallSettings & Prompt & {
|
|
1336
|
+
declare function generateText<TOOLS extends ToolSet, OUTPUT extends Output = Output<string, string>>({ model: modelArg, tools, toolChoice, system, prompt, messages, maxRetries: maxRetriesArg, abortSignal, timeout, headers, stopWhen, experimental_output, output, experimental_telemetry: telemetry, providerOptions, experimental_activeTools, activeTools, experimental_prepareStep, prepareStep, experimental_repairToolCall: repairToolCall, experimental_download: download, experimental_context, _internal: { generateId, currentDate, }, onStepFinish, onFinish, ...settings }: CallSettings & Prompt & {
|
|
1331
1337
|
/**
|
|
1332
1338
|
The language model to use.
|
|
1333
1339
|
*/
|
|
@@ -1988,6 +1994,7 @@ declare const uiMessageChunkSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
1988
1994
|
messageMetadata?: unknown;
|
|
1989
1995
|
} | {
|
|
1990
1996
|
type: "abort";
|
|
1997
|
+
reason?: string | undefined;
|
|
1991
1998
|
} | {
|
|
1992
1999
|
type: "message-metadata";
|
|
1993
2000
|
messageMetadata: unknown;
|
|
@@ -2111,6 +2118,7 @@ type UIMessageChunk<METADATA = unknown, DATA_TYPES extends UIDataTypes = UIDataT
|
|
|
2111
2118
|
messageMetadata?: METADATA;
|
|
2112
2119
|
} | {
|
|
2113
2120
|
type: 'abort';
|
|
2121
|
+
reason?: string;
|
|
2114
2122
|
} | {
|
|
2115
2123
|
type: 'message-metadata';
|
|
2116
2124
|
messageMetadata: METADATA;
|
|
@@ -2500,6 +2508,7 @@ type TextStreamPart<TOOLS extends ToolSet> = {
|
|
|
2500
2508
|
totalUsage: LanguageModelUsage;
|
|
2501
2509
|
} | {
|
|
2502
2510
|
type: 'abort';
|
|
2511
|
+
reason?: string;
|
|
2503
2512
|
} | {
|
|
2504
2513
|
type: 'error';
|
|
2505
2514
|
error: unknown;
|
|
@@ -2611,6 +2620,7 @@ If set and supported by the model, calls will generate deterministic results.
|
|
|
2611
2620
|
|
|
2612
2621
|
@param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
|
|
2613
2622
|
@param abortSignal - An optional abort signal that can be used to cancel the call.
|
|
2623
|
+
@param timeout - An optional timeout in milliseconds. The call will be aborted if it takes longer than the specified timeout.
|
|
2614
2624
|
@param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
|
|
2615
2625
|
|
|
2616
2626
|
@param onChunk - Callback that is called for each chunk of the stream. The stream processing will pause until the callback promise is resolved.
|
|
@@ -2621,7 +2631,7 @@ If set and supported by the model, calls will generate deterministic results.
|
|
|
2621
2631
|
@return
|
|
2622
2632
|
A result object for accessing different stream types and additional information.
|
|
2623
2633
|
*/
|
|
2624
|
-
declare function streamText<TOOLS extends ToolSet, OUTPUT extends Output = Output<string, string>>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, headers, stopWhen, experimental_output, output, experimental_telemetry: telemetry, prepareStep, providerOptions, experimental_activeTools, activeTools, experimental_repairToolCall: repairToolCall, experimental_transform: transform, experimental_download: download, includeRawChunks, onChunk, onError, onFinish, onAbort, onStepFinish, experimental_context, _internal: { now, generateId, currentDate, }, ...settings }: CallSettings & Prompt & {
|
|
2634
|
+
declare function streamText<TOOLS extends ToolSet, OUTPUT extends Output = Output<string, string>>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, timeout, headers, stopWhen, experimental_output, output, experimental_telemetry: telemetry, prepareStep, providerOptions, experimental_activeTools, activeTools, experimental_repairToolCall: repairToolCall, experimental_transform: transform, experimental_download: download, includeRawChunks, onChunk, onError, onFinish, onAbort, onStepFinish, experimental_context, _internal: { now, generateId, currentDate, }, ...settings }: CallSettings & Prompt & {
|
|
2625
2635
|
/**
|
|
2626
2636
|
The language model to use.
|
|
2627
2637
|
*/
|
|
@@ -2784,6 +2794,10 @@ type AgentCallParameters<CALL_OPTIONS> = ([CALL_OPTIONS] extends [never] ? {
|
|
|
2784
2794
|
* Abort signal.
|
|
2785
2795
|
*/
|
|
2786
2796
|
abortSignal?: AbortSignal;
|
|
2797
|
+
/**
|
|
2798
|
+
* Timeout in milliseconds.
|
|
2799
|
+
*/
|
|
2800
|
+
timeout?: number;
|
|
2787
2801
|
};
|
|
2788
2802
|
/**
|
|
2789
2803
|
* Parameters for streaming an output from an agent.
|
|
@@ -2979,11 +2993,11 @@ declare class ToolLoopAgent<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OU
|
|
|
2979
2993
|
/**
|
|
2980
2994
|
* Generates an output from the agent (non-streaming).
|
|
2981
2995
|
*/
|
|
2982
|
-
generate({ abortSignal, ...options }: AgentCallParameters<CALL_OPTIONS>): Promise<GenerateTextResult<TOOLS, OUTPUT>>;
|
|
2996
|
+
generate({ abortSignal, timeout, ...options }: AgentCallParameters<CALL_OPTIONS>): Promise<GenerateTextResult<TOOLS, OUTPUT>>;
|
|
2983
2997
|
/**
|
|
2984
2998
|
* Streams an output from the agent (streaming).
|
|
2985
2999
|
*/
|
|
2986
|
-
stream({ abortSignal, experimental_transform, ...options }: AgentStreamParameters<CALL_OPTIONS, TOOLS>): Promise<StreamTextResult<TOOLS, OUTPUT>>;
|
|
3000
|
+
stream({ abortSignal, timeout, experimental_transform, ...options }: AgentStreamParameters<CALL_OPTIONS, TOOLS>): Promise<StreamTextResult<TOOLS, OUTPUT>>;
|
|
2987
3001
|
}
|
|
2988
3002
|
|
|
2989
3003
|
/**
|
|
@@ -3008,6 +3022,7 @@ declare function createAgentUIStreamResponse<CALL_OPTIONS = never, TOOLS extends
|
|
|
3008
3022
|
agent: Agent<CALL_OPTIONS, TOOLS, OUTPUT>;
|
|
3009
3023
|
uiMessages: unknown[];
|
|
3010
3024
|
abortSignal?: AbortSignal;
|
|
3025
|
+
timeout?: number;
|
|
3011
3026
|
options?: CALL_OPTIONS;
|
|
3012
3027
|
experimental_transform?: StreamTextTransform<TOOLS> | Array<StreamTextTransform<TOOLS>>;
|
|
3013
3028
|
} & UIMessageStreamResponseInit & UIMessageStreamOptions<UIMessage<MESSAGE_METADATA, never, InferUITools<TOOLS>>>): Promise<Response>;
|
|
@@ -3718,15 +3733,17 @@ declare const UI_MESSAGE_STREAM_HEADERS: {
|
|
|
3718
3733
|
* @param agent - The agent to run.
|
|
3719
3734
|
* @param uiMessages - The input UI messages.
|
|
3720
3735
|
* @param abortSignal - The abort signal. Optional.
|
|
3736
|
+
* @param timeout - Timeout in milliseconds. Optional.
|
|
3721
3737
|
* @param options - The options for the agent.
|
|
3722
3738
|
* @param experimental_transform - The stream transformations. Optional.
|
|
3723
3739
|
*
|
|
3724
3740
|
* @returns The UI message stream.
|
|
3725
3741
|
*/
|
|
3726
|
-
declare function createAgentUIStream<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUTPUT extends Output = never, MESSAGE_METADATA = unknown>({ agent, uiMessages, options, abortSignal, experimental_transform, ...uiMessageStreamOptions }: {
|
|
3742
|
+
declare function createAgentUIStream<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUTPUT extends Output = never, MESSAGE_METADATA = unknown>({ agent, uiMessages, options, abortSignal, timeout, experimental_transform, ...uiMessageStreamOptions }: {
|
|
3727
3743
|
agent: Agent<CALL_OPTIONS, TOOLS, OUTPUT>;
|
|
3728
3744
|
uiMessages: unknown[];
|
|
3729
3745
|
abortSignal?: AbortSignal;
|
|
3746
|
+
timeout?: number;
|
|
3730
3747
|
options?: CALL_OPTIONS;
|
|
3731
3748
|
experimental_transform?: StreamTextTransform<TOOLS> | Array<StreamTextTransform<TOOLS>>;
|
|
3732
3749
|
} & UIMessageStreamOptions<UIMessage<MESSAGE_METADATA, never, InferUITools<TOOLS>>>): Promise<AsyncIterableStream<InferUIMessageChunk<UIMessage<MESSAGE_METADATA, never, InferUITools<TOOLS>>>>>;
|
|
@@ -3742,6 +3759,7 @@ declare function pipeAgentUIStreamToResponse<CALL_OPTIONS = never, TOOLS extends
|
|
|
3742
3759
|
agent: Agent<CALL_OPTIONS, TOOLS, OUTPUT>;
|
|
3743
3760
|
uiMessages: unknown[];
|
|
3744
3761
|
abortSignal?: AbortSignal;
|
|
3762
|
+
timeout?: number;
|
|
3745
3763
|
options?: CALL_OPTIONS;
|
|
3746
3764
|
experimental_transform?: StreamTextTransform<TOOLS> | Array<StreamTextTransform<TOOLS>>;
|
|
3747
3765
|
} & UIMessageStreamResponseInit & UIMessageStreamOptions<UIMessage<MESSAGE_METADATA, never, InferUITools<TOOLS>>>): Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -1001,7 +1001,7 @@ var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
|
1001
1001
|
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
1002
1002
|
|
|
1003
1003
|
// src/version.ts
|
|
1004
|
-
var VERSION = true ? "6.0.
|
|
1004
|
+
var VERSION = true ? "6.0.15" : "0.0.0-test";
|
|
1005
1005
|
|
|
1006
1006
|
// src/util/download/download.ts
|
|
1007
1007
|
var download = async ({ url }) => {
|
|
@@ -3582,6 +3582,34 @@ async function toResponseMessages({
|
|
|
3582
3582
|
return responseMessages;
|
|
3583
3583
|
}
|
|
3584
3584
|
|
|
3585
|
+
// src/util/merge-abort-signals.ts
|
|
3586
|
+
function mergeAbortSignals(...signals) {
|
|
3587
|
+
const validSignals = signals.filter(
|
|
3588
|
+
(signal) => signal != null
|
|
3589
|
+
);
|
|
3590
|
+
if (validSignals.length === 0) {
|
|
3591
|
+
return void 0;
|
|
3592
|
+
}
|
|
3593
|
+
if (validSignals.length === 1) {
|
|
3594
|
+
return validSignals[0];
|
|
3595
|
+
}
|
|
3596
|
+
const controller = new AbortController();
|
|
3597
|
+
for (const signal of validSignals) {
|
|
3598
|
+
if (signal.aborted) {
|
|
3599
|
+
controller.abort(signal.reason);
|
|
3600
|
+
return controller.signal;
|
|
3601
|
+
}
|
|
3602
|
+
signal.addEventListener(
|
|
3603
|
+
"abort",
|
|
3604
|
+
() => {
|
|
3605
|
+
controller.abort(signal.reason);
|
|
3606
|
+
},
|
|
3607
|
+
{ once: true }
|
|
3608
|
+
);
|
|
3609
|
+
}
|
|
3610
|
+
return controller.signal;
|
|
3611
|
+
}
|
|
3612
|
+
|
|
3585
3613
|
// src/generate-text/generate-text.ts
|
|
3586
3614
|
var originalGenerateId = (0, import_provider_utils15.createIdGenerator)({
|
|
3587
3615
|
prefix: "aitxt",
|
|
@@ -3596,6 +3624,7 @@ async function generateText({
|
|
|
3596
3624
|
messages,
|
|
3597
3625
|
maxRetries: maxRetriesArg,
|
|
3598
3626
|
abortSignal,
|
|
3627
|
+
timeout,
|
|
3599
3628
|
headers,
|
|
3600
3629
|
stopWhen = stepCountIs(1),
|
|
3601
3630
|
experimental_output,
|
|
@@ -3619,9 +3648,13 @@ async function generateText({
|
|
|
3619
3648
|
}) {
|
|
3620
3649
|
const model = resolveLanguageModel(modelArg);
|
|
3621
3650
|
const stopConditions = asArray(stopWhen);
|
|
3651
|
+
const mergedAbortSignal = mergeAbortSignals(
|
|
3652
|
+
abortSignal,
|
|
3653
|
+
timeout != null ? AbortSignal.timeout(timeout) : void 0
|
|
3654
|
+
);
|
|
3622
3655
|
const { maxRetries, retry } = prepareRetries({
|
|
3623
3656
|
maxRetries: maxRetriesArg,
|
|
3624
|
-
abortSignal
|
|
3657
|
+
abortSignal: mergedAbortSignal
|
|
3625
3658
|
});
|
|
3626
3659
|
const callSettings = prepareCallSettings(settings);
|
|
3627
3660
|
const headersWithUserAgent = (0, import_provider_utils15.withUserAgentSuffix)(
|
|
@@ -3678,7 +3711,7 @@ async function generateText({
|
|
|
3678
3711
|
tracer,
|
|
3679
3712
|
telemetry,
|
|
3680
3713
|
messages: initialMessages,
|
|
3681
|
-
abortSignal,
|
|
3714
|
+
abortSignal: mergedAbortSignal,
|
|
3682
3715
|
experimental_context
|
|
3683
3716
|
});
|
|
3684
3717
|
const toolContent = [];
|
|
@@ -3824,7 +3857,7 @@ async function generateText({
|
|
|
3824
3857
|
responseFormat: await (output == null ? void 0 : output.responseFormat),
|
|
3825
3858
|
prompt: promptMessages,
|
|
3826
3859
|
providerOptions: stepProviderOptions,
|
|
3827
|
-
abortSignal,
|
|
3860
|
+
abortSignal: mergedAbortSignal,
|
|
3828
3861
|
headers: headersWithUserAgent
|
|
3829
3862
|
});
|
|
3830
3863
|
const responseData = {
|
|
@@ -3900,7 +3933,7 @@ async function generateText({
|
|
|
3900
3933
|
input: toolCall.input,
|
|
3901
3934
|
toolCallId: toolCall.toolCallId,
|
|
3902
3935
|
messages: stepInputMessages,
|
|
3903
|
-
abortSignal,
|
|
3936
|
+
abortSignal: mergedAbortSignal,
|
|
3904
3937
|
experimental_context
|
|
3905
3938
|
});
|
|
3906
3939
|
}
|
|
@@ -3944,7 +3977,7 @@ async function generateText({
|
|
|
3944
3977
|
tracer,
|
|
3945
3978
|
telemetry,
|
|
3946
3979
|
messages: stepInputMessages,
|
|
3947
|
-
abortSignal,
|
|
3980
|
+
abortSignal: mergedAbortSignal,
|
|
3948
3981
|
experimental_context
|
|
3949
3982
|
})
|
|
3950
3983
|
);
|
|
@@ -4620,7 +4653,8 @@ var uiMessageChunkSchema = (0, import_provider_utils16.lazySchema)(
|
|
|
4620
4653
|
messageMetadata: import_v47.z.unknown().optional()
|
|
4621
4654
|
}),
|
|
4622
4655
|
import_v47.z.strictObject({
|
|
4623
|
-
type: import_v47.z.literal("abort")
|
|
4656
|
+
type: import_v47.z.literal("abort"),
|
|
4657
|
+
reason: import_v47.z.string().optional()
|
|
4624
4658
|
}),
|
|
4625
4659
|
import_v47.z.strictObject({
|
|
4626
4660
|
type: import_v47.z.literal("message-metadata"),
|
|
@@ -5674,6 +5708,7 @@ function streamText({
|
|
|
5674
5708
|
messages,
|
|
5675
5709
|
maxRetries,
|
|
5676
5710
|
abortSignal,
|
|
5711
|
+
timeout,
|
|
5677
5712
|
headers,
|
|
5678
5713
|
stopWhen = stepCountIs(1),
|
|
5679
5714
|
experimental_output,
|
|
@@ -5708,7 +5743,10 @@ function streamText({
|
|
|
5708
5743
|
headers,
|
|
5709
5744
|
settings,
|
|
5710
5745
|
maxRetries,
|
|
5711
|
-
abortSignal
|
|
5746
|
+
abortSignal: mergeAbortSignals(
|
|
5747
|
+
abortSignal,
|
|
5748
|
+
timeout != null ? AbortSignal.timeout(timeout) : void 0
|
|
5749
|
+
),
|
|
5712
5750
|
system,
|
|
5713
5751
|
prompt,
|
|
5714
5752
|
messages,
|
|
@@ -6078,7 +6116,13 @@ var DefaultStreamTextResult = class {
|
|
|
6078
6116
|
async pull(controller) {
|
|
6079
6117
|
function abort() {
|
|
6080
6118
|
onAbort == null ? void 0 : onAbort({ steps: recordedSteps });
|
|
6081
|
-
controller.enqueue({
|
|
6119
|
+
controller.enqueue({
|
|
6120
|
+
type: "abort",
|
|
6121
|
+
// The `reason` is usually of type DOMException, but it can also be of any type,
|
|
6122
|
+
// so we use getErrorMessage for serialization because it is already designed to accept values of the unknown type.
|
|
6123
|
+
// See: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/reason
|
|
6124
|
+
...(abortSignal == null ? void 0 : abortSignal.reason) !== void 0 ? { reason: (0, import_provider24.getErrorMessage)(abortSignal.reason) } : {}
|
|
6125
|
+
});
|
|
6082
6126
|
controller.close();
|
|
6083
6127
|
}
|
|
6084
6128
|
try {
|
|
@@ -7204,11 +7248,13 @@ var ToolLoopAgent = class {
|
|
|
7204
7248
|
*/
|
|
7205
7249
|
async generate({
|
|
7206
7250
|
abortSignal,
|
|
7251
|
+
timeout,
|
|
7207
7252
|
...options
|
|
7208
7253
|
}) {
|
|
7209
7254
|
return generateText({
|
|
7210
7255
|
...await this.prepareCall(options),
|
|
7211
|
-
abortSignal
|
|
7256
|
+
abortSignal,
|
|
7257
|
+
timeout
|
|
7212
7258
|
});
|
|
7213
7259
|
}
|
|
7214
7260
|
/**
|
|
@@ -7216,12 +7262,14 @@ var ToolLoopAgent = class {
|
|
|
7216
7262
|
*/
|
|
7217
7263
|
async stream({
|
|
7218
7264
|
abortSignal,
|
|
7265
|
+
timeout,
|
|
7219
7266
|
experimental_transform,
|
|
7220
7267
|
...options
|
|
7221
7268
|
}) {
|
|
7222
7269
|
return streamText({
|
|
7223
7270
|
...await this.prepareCall(options),
|
|
7224
7271
|
abortSignal,
|
|
7272
|
+
timeout,
|
|
7225
7273
|
experimental_transform
|
|
7226
7274
|
});
|
|
7227
7275
|
}
|
|
@@ -7975,6 +8023,7 @@ async function createAgentUIStream({
|
|
|
7975
8023
|
uiMessages,
|
|
7976
8024
|
options,
|
|
7977
8025
|
abortSignal,
|
|
8026
|
+
timeout,
|
|
7978
8027
|
experimental_transform,
|
|
7979
8028
|
...uiMessageStreamOptions
|
|
7980
8029
|
}) {
|
|
@@ -7989,6 +8038,7 @@ async function createAgentUIStream({
|
|
|
7989
8038
|
prompt: modelMessages,
|
|
7990
8039
|
options,
|
|
7991
8040
|
abortSignal,
|
|
8041
|
+
timeout,
|
|
7992
8042
|
experimental_transform
|
|
7993
8043
|
});
|
|
7994
8044
|
return result.toUIMessageStream(uiMessageStreamOptions);
|