ai 7.0.0-beta.20 → 7.0.0-beta.21
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 +6 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +49 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +49 -11
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +1 -0
- package/dist/internal/index.d.ts +1 -0
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.mjs +1 -1
- package/package.json +1 -1
- package/src/generate-text/create-stream-text-part-transform.ts +36 -0
- package/src/generate-text/execute-tool-call.ts +10 -1
- package/src/generate-text/generate-text.ts +7 -0
- package/src/generate-text/run-tools-transformation.ts +12 -16
- package/src/generate-text/stream-text.ts +17 -1
- package/src/prompt/call-settings.ts +10 -1
package/dist/internal/index.d.ts
CHANGED
package/dist/internal/index.js
CHANGED
|
@@ -153,7 +153,7 @@ var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
|
153
153
|
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
154
154
|
|
|
155
155
|
// src/version.ts
|
|
156
|
-
var VERSION = true ? "7.0.0-beta.
|
|
156
|
+
var VERSION = true ? "7.0.0-beta.21" : "0.0.0-test";
|
|
157
157
|
|
|
158
158
|
// src/util/download/download.ts
|
|
159
159
|
var download = async ({
|
package/dist/internal/index.mjs
CHANGED
|
@@ -133,7 +133,7 @@ import {
|
|
|
133
133
|
} from "@ai-sdk/provider-utils";
|
|
134
134
|
|
|
135
135
|
// src/version.ts
|
|
136
|
-
var VERSION = true ? "7.0.0-beta.
|
|
136
|
+
var VERSION = true ? "7.0.0-beta.21" : "0.0.0-test";
|
|
137
137
|
|
|
138
138
|
// src/util/download/download.ts
|
|
139
139
|
var download = async ({
|
package/package.json
CHANGED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { LanguageModelV4StreamPart } from '@ai-sdk/provider';
|
|
2
|
+
import { ProviderMetadata } from '../types/provider-metadata';
|
|
3
|
+
|
|
4
|
+
export type UglyTransformedStreamTextPart =
|
|
5
|
+
| Exclude<
|
|
6
|
+
LanguageModelV4StreamPart,
|
|
7
|
+
{
|
|
8
|
+
type: 'text-delta';
|
|
9
|
+
}
|
|
10
|
+
>
|
|
11
|
+
| {
|
|
12
|
+
type: 'text-delta';
|
|
13
|
+
id: string;
|
|
14
|
+
providerMetadata?: ProviderMetadata;
|
|
15
|
+
text: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export function createStreamTextPartTransform() {
|
|
19
|
+
return new TransformStream<
|
|
20
|
+
LanguageModelV4StreamPart,
|
|
21
|
+
UglyTransformedStreamTextPart
|
|
22
|
+
>({
|
|
23
|
+
async transform(chunk, controller) {
|
|
24
|
+
if (chunk.type === 'text-delta') {
|
|
25
|
+
controller.enqueue({
|
|
26
|
+
type: 'text-delta',
|
|
27
|
+
id: chunk.id,
|
|
28
|
+
text: chunk.delta,
|
|
29
|
+
providerMetadata: chunk.providerMetadata,
|
|
30
|
+
});
|
|
31
|
+
} else {
|
|
32
|
+
controller.enqueue(chunk);
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
}
|
|
@@ -30,6 +30,7 @@ export async function executeToolCall<TOOLS extends ToolSet>({
|
|
|
30
30
|
callId,
|
|
31
31
|
messages,
|
|
32
32
|
abortSignal,
|
|
33
|
+
toolTimeoutMs,
|
|
33
34
|
experimental_context,
|
|
34
35
|
stepNumber,
|
|
35
36
|
model,
|
|
@@ -44,6 +45,7 @@ export async function executeToolCall<TOOLS extends ToolSet>({
|
|
|
44
45
|
callId: string;
|
|
45
46
|
messages: ModelMessage[];
|
|
46
47
|
abortSignal: AbortSignal | undefined;
|
|
48
|
+
toolTimeoutMs?: number | undefined;
|
|
47
49
|
experimental_context: unknown;
|
|
48
50
|
stepNumber?: number;
|
|
49
51
|
model?: { provider: string; modelId: string };
|
|
@@ -83,6 +85,13 @@ export async function executeToolCall<TOOLS extends ToolSet>({
|
|
|
83
85
|
|
|
84
86
|
await notify({ event: baseCallbackEvent, callbacks: onToolCallStart });
|
|
85
87
|
|
|
88
|
+
const toolAbortSignal =
|
|
89
|
+
toolTimeoutMs != null
|
|
90
|
+
? abortSignal != null
|
|
91
|
+
? AbortSignal.any([abortSignal, AbortSignal.timeout(toolTimeoutMs)])
|
|
92
|
+
: AbortSignal.timeout(toolTimeoutMs)
|
|
93
|
+
: abortSignal;
|
|
94
|
+
|
|
86
95
|
const startTime = now();
|
|
87
96
|
|
|
88
97
|
try {
|
|
@@ -101,7 +110,7 @@ export async function executeToolCall<TOOLS extends ToolSet>({
|
|
|
101
110
|
options: {
|
|
102
111
|
toolCallId,
|
|
103
112
|
messages,
|
|
104
|
-
abortSignal,
|
|
113
|
+
abortSignal: toolAbortSignal,
|
|
105
114
|
experimental_context,
|
|
106
115
|
},
|
|
107
116
|
});
|
|
@@ -21,6 +21,7 @@ import { ModelMessage } from '../prompt';
|
|
|
21
21
|
import {
|
|
22
22
|
CallSettings,
|
|
23
23
|
getStepTimeoutMs,
|
|
24
|
+
getToolTimeoutMs,
|
|
24
25
|
getTotalTimeoutMs,
|
|
25
26
|
TimeoutConfiguration,
|
|
26
27
|
} from '../prompt/call-settings';
|
|
@@ -449,6 +450,7 @@ export async function generateText<
|
|
|
449
450
|
|
|
450
451
|
const totalTimeoutMs = getTotalTimeoutMs(timeout);
|
|
451
452
|
const stepTimeoutMs = getStepTimeoutMs(timeout);
|
|
453
|
+
const toolTimeoutMs = getToolTimeoutMs(timeout);
|
|
452
454
|
const stepAbortController =
|
|
453
455
|
stepTimeoutMs != null ? new AbortController() : undefined;
|
|
454
456
|
const mergedAbortSignal = mergeAbortSignals(
|
|
@@ -548,6 +550,7 @@ export async function generateText<
|
|
|
548
550
|
callId,
|
|
549
551
|
messages: initialMessages,
|
|
550
552
|
abortSignal: mergedAbortSignal,
|
|
553
|
+
toolTimeoutMs,
|
|
551
554
|
experimental_context,
|
|
552
555
|
stepNumber: 0,
|
|
553
556
|
model: modelInfo,
|
|
@@ -870,6 +873,7 @@ export async function generateText<
|
|
|
870
873
|
callId,
|
|
871
874
|
messages: stepInputMessages,
|
|
872
875
|
abortSignal: mergedAbortSignal,
|
|
876
|
+
toolTimeoutMs,
|
|
873
877
|
experimental_context,
|
|
874
878
|
stepNumber: steps.length,
|
|
875
879
|
model: stepModelInfo,
|
|
@@ -1102,6 +1106,7 @@ async function executeTools<TOOLS extends ToolSet>({
|
|
|
1102
1106
|
callId,
|
|
1103
1107
|
messages,
|
|
1104
1108
|
abortSignal,
|
|
1109
|
+
toolTimeoutMs,
|
|
1105
1110
|
experimental_context,
|
|
1106
1111
|
stepNumber,
|
|
1107
1112
|
model,
|
|
@@ -1115,6 +1120,7 @@ async function executeTools<TOOLS extends ToolSet>({
|
|
|
1115
1120
|
callId: string;
|
|
1116
1121
|
messages: ModelMessage[];
|
|
1117
1122
|
abortSignal: AbortSignal | undefined;
|
|
1123
|
+
toolTimeoutMs?: number | undefined;
|
|
1118
1124
|
experimental_context: unknown;
|
|
1119
1125
|
stepNumber: number;
|
|
1120
1126
|
model: { provider: string; modelId: string };
|
|
@@ -1131,6 +1137,7 @@ async function executeTools<TOOLS extends ToolSet>({
|
|
|
1131
1137
|
callId,
|
|
1132
1138
|
messages,
|
|
1133
1139
|
abortSignal,
|
|
1140
|
+
toolTimeoutMs,
|
|
1134
1141
|
experimental_context,
|
|
1135
1142
|
stepNumber,
|
|
1136
1143
|
model,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SharedV4Warning } from '@ai-sdk/provider';
|
|
2
2
|
import {
|
|
3
3
|
getErrorMessage,
|
|
4
4
|
IdGenerator,
|
|
@@ -11,14 +11,15 @@ import { TelemetrySettings } from '../telemetry/telemetry-settings';
|
|
|
11
11
|
import { FinishReason, LanguageModelUsage, ProviderMetadata } from '../types';
|
|
12
12
|
import { Source } from '../types/language-model';
|
|
13
13
|
import { asLanguageModelUsage } from '../types/usage';
|
|
14
|
+
import { UglyTransformedStreamTextPart } from './create-stream-text-part-transform';
|
|
14
15
|
import { executeToolCall } from './execute-tool-call';
|
|
16
|
+
import { DefaultGeneratedFileWithType, GeneratedFile } from './generated-file';
|
|
17
|
+
import { isApprovalNeeded } from './is-approval-needed';
|
|
18
|
+
import { parseToolCall } from './parse-tool-call';
|
|
15
19
|
import {
|
|
16
20
|
StreamTextOnToolCallFinishCallback,
|
|
17
21
|
StreamTextOnToolCallStartCallback,
|
|
18
22
|
} from './stream-text';
|
|
19
|
-
import { DefaultGeneratedFileWithType, GeneratedFile } from './generated-file';
|
|
20
|
-
import { isApprovalNeeded } from './is-approval-needed';
|
|
21
|
-
import { parseToolCall } from './parse-tool-call';
|
|
22
23
|
import { ToolApprovalRequestOutput } from './tool-approval-request-output';
|
|
23
24
|
import { TypedToolCall } from './tool-call';
|
|
24
25
|
import { ToolCallRepairFunction } from './tool-call-repair-function';
|
|
@@ -122,6 +123,7 @@ export function runToolsTransformation<TOOLS extends ToolSet>({
|
|
|
122
123
|
messages,
|
|
123
124
|
abortSignal,
|
|
124
125
|
repairToolCall,
|
|
126
|
+
toolTimeoutMs,
|
|
125
127
|
experimental_context,
|
|
126
128
|
generateId,
|
|
127
129
|
stepNumber,
|
|
@@ -131,13 +133,14 @@ export function runToolsTransformation<TOOLS extends ToolSet>({
|
|
|
131
133
|
executeToolInTelemetryContext,
|
|
132
134
|
}: {
|
|
133
135
|
tools: TOOLS | undefined;
|
|
134
|
-
generatorStream: ReadableStream<
|
|
136
|
+
generatorStream: ReadableStream<UglyTransformedStreamTextPart>;
|
|
135
137
|
telemetry: TelemetrySettings | undefined;
|
|
136
138
|
callId: string;
|
|
137
139
|
system: string | SystemModelMessage | Array<SystemModelMessage> | undefined;
|
|
138
140
|
messages: ModelMessage[];
|
|
139
141
|
abortSignal: AbortSignal | undefined;
|
|
140
142
|
repairToolCall: ToolCallRepairFunction<TOOLS> | undefined;
|
|
143
|
+
toolTimeoutMs?: number | undefined;
|
|
141
144
|
experimental_context: unknown;
|
|
142
145
|
generateId: IdGenerator;
|
|
143
146
|
stepNumber?: number;
|
|
@@ -192,11 +195,11 @@ export function runToolsTransformation<TOOLS extends ToolSet>({
|
|
|
192
195
|
|
|
193
196
|
// forward stream
|
|
194
197
|
const forwardStream = new TransformStream<
|
|
195
|
-
|
|
198
|
+
UglyTransformedStreamTextPart,
|
|
196
199
|
SingleRequestTextStreamPart<TOOLS>
|
|
197
200
|
>({
|
|
198
201
|
async transform(
|
|
199
|
-
chunk:
|
|
202
|
+
chunk: UglyTransformedStreamTextPart,
|
|
200
203
|
controller: TransformStreamDefaultController<
|
|
201
204
|
SingleRequestTextStreamPart<TOOLS>
|
|
202
205
|
>,
|
|
@@ -207,6 +210,7 @@ export function runToolsTransformation<TOOLS extends ToolSet>({
|
|
|
207
210
|
// forward:
|
|
208
211
|
case 'stream-start':
|
|
209
212
|
case 'text-start':
|
|
213
|
+
case 'text-delta':
|
|
210
214
|
case 'text-end':
|
|
211
215
|
case 'reasoning-start':
|
|
212
216
|
case 'reasoning-end':
|
|
@@ -221,15 +225,6 @@ export function runToolsTransformation<TOOLS extends ToolSet>({
|
|
|
221
225
|
break;
|
|
222
226
|
}
|
|
223
227
|
|
|
224
|
-
case 'text-delta':
|
|
225
|
-
controller.enqueue({
|
|
226
|
-
type: 'text-delta',
|
|
227
|
-
id: chunk.id,
|
|
228
|
-
text: chunk.delta,
|
|
229
|
-
providerMetadata: chunk.providerMetadata,
|
|
230
|
-
});
|
|
231
|
-
break;
|
|
232
|
-
|
|
233
228
|
case 'reasoning-delta':
|
|
234
229
|
controller.enqueue({
|
|
235
230
|
type: 'reasoning-delta',
|
|
@@ -364,6 +359,7 @@ export function runToolsTransformation<TOOLS extends ToolSet>({
|
|
|
364
359
|
callId,
|
|
365
360
|
messages,
|
|
366
361
|
abortSignal,
|
|
362
|
+
toolTimeoutMs,
|
|
367
363
|
experimental_context,
|
|
368
364
|
stepNumber,
|
|
369
365
|
model,
|
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
CallSettings,
|
|
22
22
|
getChunkTimeoutMs,
|
|
23
23
|
getStepTimeoutMs,
|
|
24
|
+
getToolTimeoutMs,
|
|
24
25
|
getTotalTimeoutMs,
|
|
25
26
|
TimeoutConfiguration,
|
|
26
27
|
} from '../prompt/call-settings';
|
|
@@ -82,6 +83,7 @@ import type {
|
|
|
82
83
|
} from './callback-events';
|
|
83
84
|
import { collectToolApprovals } from './collect-tool-approvals';
|
|
84
85
|
import { ContentPart } from './content-part';
|
|
86
|
+
import { createStreamTextPartTransform } from './create-stream-text-part-transform';
|
|
85
87
|
import { executeToolCall } from './execute-tool-call';
|
|
86
88
|
import { Output, text } from './output';
|
|
87
89
|
import {
|
|
@@ -530,6 +532,7 @@ export function streamText<
|
|
|
530
532
|
const totalTimeoutMs = getTotalTimeoutMs(timeout);
|
|
531
533
|
const stepTimeoutMs = getStepTimeoutMs(timeout);
|
|
532
534
|
const chunkTimeoutMs = getChunkTimeoutMs(timeout);
|
|
535
|
+
const toolTimeoutMs = getToolTimeoutMs(timeout);
|
|
533
536
|
const stepAbortController =
|
|
534
537
|
stepTimeoutMs != null ? new AbortController() : undefined;
|
|
535
538
|
const chunkAbortController =
|
|
@@ -550,6 +553,7 @@ export function streamText<
|
|
|
550
553
|
stepAbortController,
|
|
551
554
|
chunkTimeoutMs,
|
|
552
555
|
chunkAbortController,
|
|
556
|
+
toolTimeoutMs,
|
|
553
557
|
system,
|
|
554
558
|
prompt,
|
|
555
559
|
messages,
|
|
@@ -729,6 +733,7 @@ class DefaultStreamTextResult<TOOLS extends ToolSet, OUTPUT extends Output>
|
|
|
729
733
|
stepAbortController,
|
|
730
734
|
chunkTimeoutMs,
|
|
731
735
|
chunkAbortController,
|
|
736
|
+
toolTimeoutMs,
|
|
732
737
|
system,
|
|
733
738
|
prompt,
|
|
734
739
|
messages,
|
|
@@ -771,6 +776,7 @@ class DefaultStreamTextResult<TOOLS extends ToolSet, OUTPUT extends Output>
|
|
|
771
776
|
stepAbortController: AbortController | undefined;
|
|
772
777
|
chunkTimeoutMs: number | undefined;
|
|
773
778
|
chunkAbortController: AbortController | undefined;
|
|
779
|
+
toolTimeoutMs: number | undefined;
|
|
774
780
|
system: Prompt['system'];
|
|
775
781
|
prompt: Prompt['prompt'];
|
|
776
782
|
messages: Prompt['messages'];
|
|
@@ -1352,6 +1358,7 @@ class DefaultStreamTextResult<TOOLS extends ToolSet, OUTPUT extends Output>
|
|
|
1352
1358
|
callId,
|
|
1353
1359
|
messages: initialMessages,
|
|
1354
1360
|
abortSignal,
|
|
1361
|
+
toolTimeoutMs,
|
|
1355
1362
|
experimental_context,
|
|
1356
1363
|
stepNumber: recordedSteps.length,
|
|
1357
1364
|
model: modelInfo,
|
|
@@ -1573,7 +1580,11 @@ class DefaultStreamTextResult<TOOLS extends ToolSet, OUTPUT extends Output>
|
|
|
1573
1580
|
});
|
|
1574
1581
|
|
|
1575
1582
|
const stepStartTimestampMs = now();
|
|
1576
|
-
const {
|
|
1583
|
+
const {
|
|
1584
|
+
stream: languageModelStream,
|
|
1585
|
+
response,
|
|
1586
|
+
request,
|
|
1587
|
+
} = await retry(async () =>
|
|
1577
1588
|
stepModel.doStream({
|
|
1578
1589
|
...callSettings,
|
|
1579
1590
|
tools: stepTools,
|
|
@@ -1587,6 +1598,10 @@ class DefaultStreamTextResult<TOOLS extends ToolSet, OUTPUT extends Output>
|
|
|
1587
1598
|
}),
|
|
1588
1599
|
);
|
|
1589
1600
|
|
|
1601
|
+
const stream = languageModelStream.pipeThrough(
|
|
1602
|
+
createStreamTextPartTransform(),
|
|
1603
|
+
);
|
|
1604
|
+
|
|
1590
1605
|
const streamWithToolResults = runToolsTransformation({
|
|
1591
1606
|
tools,
|
|
1592
1607
|
generatorStream: stream,
|
|
@@ -1596,6 +1611,7 @@ class DefaultStreamTextResult<TOOLS extends ToolSet, OUTPUT extends Output>
|
|
|
1596
1611
|
messages: stepInputMessages,
|
|
1597
1612
|
repairToolCall,
|
|
1598
1613
|
abortSignal,
|
|
1614
|
+
toolTimeoutMs,
|
|
1599
1615
|
experimental_context,
|
|
1600
1616
|
generateId,
|
|
1601
1617
|
stepNumber: recordedSteps.length,
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
export type TimeoutConfiguration =
|
|
9
9
|
| number
|
|
10
|
-
| { totalMs?: number; stepMs?: number; chunkMs?: number };
|
|
10
|
+
| { totalMs?: number; stepMs?: number; chunkMs?: number; toolMs?: number };
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Extracts the total timeout value in milliseconds from a TimeoutConfiguration.
|
|
@@ -58,6 +58,15 @@ export function getChunkTimeoutMs(
|
|
|
58
58
|
return timeout.chunkMs;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
+
export function getToolTimeoutMs(
|
|
62
|
+
timeout: TimeoutConfiguration | undefined,
|
|
63
|
+
): number | undefined {
|
|
64
|
+
if (timeout == null || typeof timeout === 'number') {
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
return timeout.toolMs;
|
|
68
|
+
}
|
|
69
|
+
|
|
61
70
|
export type CallSettings = {
|
|
62
71
|
/**
|
|
63
72
|
* Maximum number of tokens to generate.
|