@ai-sdk/workflow 1.0.65 → 1.0.67
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 +15 -0
- package/dist/index.js +51 -10
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/do-stream-step.ts +58 -9
- package/src/providers/mock-function-wrapper.ts +91 -4
- package/src/providers/mock.ts +2 -92
- package/src/stream-text-iterator.ts +34 -14
- package/src/workflow-agent.ts +19 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @ai-sdk/workflow
|
|
2
2
|
|
|
3
|
+
## 1.0.67
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- e3325bd: Fix `WorkflowAgent` timeout handling by enforcing absolute deadlines inside durable model-call steps and routing timeouts through abort handling.
|
|
8
|
+
|
|
9
|
+
## 1.0.66
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- c661693: Fix the Workflow integration test harness by aligning `@workflow/vitest` with the installed Workflow runtime.
|
|
14
|
+
- Updated dependencies [0782259]
|
|
15
|
+
- Updated dependencies [2fd1214]
|
|
16
|
+
- ai@7.0.66
|
|
17
|
+
|
|
3
18
|
## 1.0.65
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// src/workflow-agent.ts
|
|
2
2
|
import {
|
|
3
3
|
getErrorMessage,
|
|
4
|
+
isAbortError as isAbortError2,
|
|
4
5
|
validateTypes,
|
|
5
6
|
withUserAgentSuffix
|
|
6
7
|
} from "@ai-sdk/provider-utils";
|
|
@@ -12,7 +13,6 @@ import {
|
|
|
12
13
|
createRestrictedTelemetryDispatcher as createRestrictedTelemetryDispatcher2,
|
|
13
14
|
collectToolApprovals,
|
|
14
15
|
convertToLanguageModelPrompt,
|
|
15
|
-
mergeAbortSignals,
|
|
16
16
|
mergeCallbacks,
|
|
17
17
|
standardizePrompt,
|
|
18
18
|
validateApprovedToolApprovals
|
|
@@ -74,6 +74,7 @@ import {
|
|
|
74
74
|
import { createRestrictedTelemetryDispatcher } from "ai/internal";
|
|
75
75
|
|
|
76
76
|
// src/do-stream-step.ts
|
|
77
|
+
import { isAbortError } from "@ai-sdk/provider-utils";
|
|
77
78
|
import {
|
|
78
79
|
experimental_streamLanguageModelCall as streamModelCall,
|
|
79
80
|
gateway
|
|
@@ -165,6 +166,12 @@ function resolveSerializableTools(tools) {
|
|
|
165
166
|
// src/do-stream-step.ts
|
|
166
167
|
async function doStreamStep(conversationPrompt, modelInit, writable, serializedTools, options) {
|
|
167
168
|
"use step";
|
|
169
|
+
var _a;
|
|
170
|
+
const timeout = (options == null ? void 0 : options.timeoutAt) == null ? void 0 : options.timeoutAt - Date.now();
|
|
171
|
+
if (((_a = options == null ? void 0 : options.abortSignal) == null ? void 0 : _a.aborted) || timeout != null && timeout <= 0) {
|
|
172
|
+
return { aborted: true };
|
|
173
|
+
}
|
|
174
|
+
const abortSignal = timeout == null ? options == null ? void 0 : options.abortSignal : (options == null ? void 0 : options.abortSignal) == null ? AbortSignal.timeout(timeout) : AbortSignal.any([options.abortSignal, AbortSignal.timeout(timeout)]);
|
|
168
175
|
const model = typeof modelInit === "string" ? gateway.languageModel(modelInit) : modelInit;
|
|
169
176
|
const tools = serializedTools ? resolveSerializableTools(serializedTools) : void 0;
|
|
170
177
|
const output = (options == null ? void 0 : options.responseFormat) == null ? void 0 : {
|
|
@@ -182,7 +189,7 @@ async function doStreamStep(conversationPrompt, modelInit, writable, serializedT
|
|
|
182
189
|
return void 0;
|
|
183
190
|
}
|
|
184
191
|
};
|
|
185
|
-
const
|
|
192
|
+
const modelStream = await streamModelCall({
|
|
186
193
|
model,
|
|
187
194
|
// streamModelCall expects Prompt (ModelMessage[]) but we pass the
|
|
188
195
|
// pre-converted LanguageModelV4Prompt. standardizePrompt inside
|
|
@@ -193,7 +200,7 @@ async function doStreamStep(conversationPrompt, modelInit, writable, serializedT
|
|
|
193
200
|
toolChoice: options == null ? void 0 : options.toolChoice,
|
|
194
201
|
includeRawChunks: options == null ? void 0 : options.includeRawChunks,
|
|
195
202
|
providerOptions: options == null ? void 0 : options.providerOptions,
|
|
196
|
-
abortSignal
|
|
203
|
+
abortSignal,
|
|
197
204
|
headers: options == null ? void 0 : options.headers,
|
|
198
205
|
reasoning: options == null ? void 0 : options.reasoning,
|
|
199
206
|
output,
|
|
@@ -206,7 +213,15 @@ async function doStreamStep(conversationPrompt, modelInit, writable, serializedT
|
|
|
206
213
|
stopSequences: options == null ? void 0 : options.stopSequences,
|
|
207
214
|
seed: options == null ? void 0 : options.seed,
|
|
208
215
|
repairToolCall: options == null ? void 0 : options.repairToolCall
|
|
216
|
+
}).then((result) => result.stream).catch((error) => {
|
|
217
|
+
if ((abortSignal == null ? void 0 : abortSignal.aborted) && isAbortError(error)) {
|
|
218
|
+
return void 0;
|
|
219
|
+
}
|
|
220
|
+
throw error;
|
|
209
221
|
});
|
|
222
|
+
if (modelStream == null) {
|
|
223
|
+
return { aborted: true };
|
|
224
|
+
}
|
|
210
225
|
const toolCalls = [];
|
|
211
226
|
const providerExecutedToolResults = /* @__PURE__ */ new Map();
|
|
212
227
|
let finish;
|
|
@@ -280,9 +295,17 @@ async function doStreamStep(conversationPrompt, modelInit, writable, serializedT
|
|
|
280
295
|
await writer.write(part);
|
|
281
296
|
}
|
|
282
297
|
}
|
|
298
|
+
} catch (error) {
|
|
299
|
+
if ((abortSignal == null ? void 0 : abortSignal.aborted) && isAbortError(error)) {
|
|
300
|
+
return { aborted: true };
|
|
301
|
+
}
|
|
302
|
+
throw error;
|
|
283
303
|
} finally {
|
|
284
304
|
writer == null ? void 0 : writer.releaseLock();
|
|
285
305
|
}
|
|
306
|
+
if ((abortSignal == null ? void 0 : abortSignal.aborted) || (options == null ? void 0 : options.timeoutAt) != null && options.timeoutAt <= Date.now()) {
|
|
307
|
+
return { aborted: true };
|
|
308
|
+
}
|
|
286
309
|
return {
|
|
287
310
|
toolCalls,
|
|
288
311
|
finish,
|
|
@@ -339,6 +362,7 @@ async function* streamTextIterator({
|
|
|
339
362
|
toolsContext,
|
|
340
363
|
telemetry,
|
|
341
364
|
includeRawChunks = false,
|
|
365
|
+
timeoutAt,
|
|
342
366
|
repairToolCall,
|
|
343
367
|
responseFormat,
|
|
344
368
|
experimental_sandbox: sandbox
|
|
@@ -357,6 +381,7 @@ async function* streamTextIterator({
|
|
|
357
381
|
let stepNumber = 0;
|
|
358
382
|
let lastStep;
|
|
359
383
|
let lastStepWasToolCalls = false;
|
|
384
|
+
let wasAborted = false;
|
|
360
385
|
const telemetryDispatcher = createRestrictedTelemetryDispatcher({
|
|
361
386
|
telemetry,
|
|
362
387
|
includeRuntimeContext: telemetry == null ? void 0 : telemetry.includeRuntimeContext,
|
|
@@ -472,7 +497,7 @@ async function* streamTextIterator({
|
|
|
472
497
|
providerOptions: currentGenerationSettings.providerOptions,
|
|
473
498
|
headers: currentGenerationSettings.headers
|
|
474
499
|
}));
|
|
475
|
-
const
|
|
500
|
+
const streamStepResult = await doStreamStep(
|
|
476
501
|
conversationPrompt,
|
|
477
502
|
currentModel,
|
|
478
503
|
writable,
|
|
@@ -481,10 +506,16 @@ async function* streamTextIterator({
|
|
|
481
506
|
...currentGenerationSettings,
|
|
482
507
|
toolChoice: currentToolChoice,
|
|
483
508
|
includeRawChunks,
|
|
509
|
+
timeoutAt,
|
|
484
510
|
repairToolCall,
|
|
485
511
|
responseFormat
|
|
486
512
|
}
|
|
487
513
|
);
|
|
514
|
+
if (streamStepResult.aborted) {
|
|
515
|
+
wasAborted = true;
|
|
516
|
+
break;
|
|
517
|
+
}
|
|
518
|
+
const { toolCalls, finish, raw, providerExecutedToolResults } = streamStepResult;
|
|
488
519
|
const step = buildStepResult(raw, toolCalls, finish, {
|
|
489
520
|
stepNumber,
|
|
490
521
|
runtimeContext: currentRuntimeContext,
|
|
@@ -600,6 +631,9 @@ async function* streamTextIterator({
|
|
|
600
631
|
experimental_sandbox: sandbox
|
|
601
632
|
};
|
|
602
633
|
}
|
|
634
|
+
if (wasAborted) {
|
|
635
|
+
return { aborted: true, messages: conversationPrompt };
|
|
636
|
+
}
|
|
603
637
|
return conversationPrompt;
|
|
604
638
|
}
|
|
605
639
|
function getModelInfo(model) {
|
|
@@ -1108,10 +1142,8 @@ var WorkflowAgent = class {
|
|
|
1108
1142
|
supportedUrls: {},
|
|
1109
1143
|
download
|
|
1110
1144
|
});
|
|
1111
|
-
const effectiveAbortSignal =
|
|
1112
|
-
|
|
1113
|
-
options.timeout
|
|
1114
|
-
);
|
|
1145
|
+
const effectiveAbortSignal = (_r = options.abortSignal) != null ? _r : effectiveGenerationSettings.abortSignal;
|
|
1146
|
+
const timeoutAt = options.timeout == null ? void 0 : Date.now() + options.timeout;
|
|
1115
1147
|
const mergedGenerationSettings = {
|
|
1116
1148
|
...effectiveGenerationSettings,
|
|
1117
1149
|
...options.maxOutputTokens !== void 0 && {
|
|
@@ -1397,6 +1429,7 @@ var WorkflowAgent = class {
|
|
|
1397
1429
|
toolsContext,
|
|
1398
1430
|
telemetry: effectiveTelemetry,
|
|
1399
1431
|
includeRawChunks: (_A = options.includeRawChunks) != null ? _A : false,
|
|
1432
|
+
timeoutAt,
|
|
1400
1433
|
repairToolCall: (_C = (_B = options.repairToolCall) != null ? _B : options.experimental_repairToolCall) != null ? _C : this.repairToolCall,
|
|
1401
1434
|
responseFormat: await ((_E = (_D = options.output) != null ? _D : this.output) == null ? void 0 : _E.responseFormat),
|
|
1402
1435
|
experimental_sandbox: sandbox
|
|
@@ -1700,11 +1733,19 @@ var WorkflowAgent = class {
|
|
|
1700
1733
|
}
|
|
1701
1734
|
}
|
|
1702
1735
|
if (result.done) {
|
|
1703
|
-
|
|
1736
|
+
if (Array.isArray(result.value)) {
|
|
1737
|
+
finalMessages = result.value;
|
|
1738
|
+
} else {
|
|
1739
|
+
finalMessages = result.value.messages;
|
|
1740
|
+
wasAborted = true;
|
|
1741
|
+
if (options.onAbort) {
|
|
1742
|
+
await options.onAbort({ steps });
|
|
1743
|
+
}
|
|
1744
|
+
}
|
|
1704
1745
|
}
|
|
1705
1746
|
} catch (error) {
|
|
1706
1747
|
encounteredError = error;
|
|
1707
|
-
if (error
|
|
1748
|
+
if (isAbortError2(error)) {
|
|
1708
1749
|
wasAborted = true;
|
|
1709
1750
|
if (options.onAbort) {
|
|
1710
1751
|
await options.onAbort({ steps });
|