@ai-sdk/workflow 1.0.70 → 2.0.1
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 +26 -0
- package/README.md +1 -1
- package/dist/index.d.ts +28 -10
- package/dist/index.js +31 -6
- package/dist/index.js.map +1 -1
- package/package.json +8 -7
- package/src/do-stream-step.ts +10 -2
- package/src/normalize-ui-message-stream.ts +10 -0
- package/src/stream-text-iterator.ts +1 -1
- package/src/to-ui-message-chunk.ts +40 -14
- package/src/workflow-agent.ts +1 -1
- package/src/workflow-chat-transport.ts +10 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# @ai-sdk/workflow
|
|
2
2
|
|
|
3
|
+
## 2.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 4233a40: Resume transformed WorkflowAgent streams using UI message chunk indexes.
|
|
8
|
+
- Updated dependencies [9a37469]
|
|
9
|
+
- ai@7.0.71
|
|
10
|
+
|
|
11
|
+
## 2.0.0
|
|
12
|
+
|
|
13
|
+
### Major Changes
|
|
14
|
+
|
|
15
|
+
- 3238c04: Upgrade to Workflow 5 and drop Workflow 4 support. Applications must now install Workflow 5, which is currently available under the `beta` tag.
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- d3cc3fe: Clear partial UI message parts when a WorkflowAgent model-call step is retried.
|
|
20
|
+
- Updated dependencies [e6087c9]
|
|
21
|
+
- Updated dependencies [9566914]
|
|
22
|
+
- Updated dependencies [b181020]
|
|
23
|
+
- Updated dependencies [7054073]
|
|
24
|
+
- Updated dependencies [a828527]
|
|
25
|
+
- Updated dependencies [d3cc3fe]
|
|
26
|
+
- @ai-sdk/provider-utils@5.0.28
|
|
27
|
+
- ai@7.0.70
|
|
28
|
+
|
|
3
29
|
## 1.0.70
|
|
4
30
|
|
|
5
31
|
### Patch Changes
|
package/README.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { LanguageModelV4, LanguageModelV4CallOptions, SharedV4ProviderOptions, LanguageModelV4Prompt, LanguageModelV4StreamPart } from '@ai-sdk/provider';
|
|
2
2
|
import { Context, HasRequiredKey, InferToolSetContext } from '@ai-sdk/provider-utils';
|
|
3
|
-
import { ToolSet, LanguageModel, Instructions, ToolChoice, TelemetryOptions as TelemetryOptions$1, StopCondition, ActiveTools, LanguageModelResponseMetadata, LanguageModelUsage, FinishReason, ToolCallRepairFunction, Experimental_SandboxSession, ModelMessage, StepResult, GenerateTextOnStepEndCallback,
|
|
4
|
-
export {
|
|
3
|
+
import { ToolSet, Experimental_LanguageModelStreamPart, LanguageModel, Instructions, ToolChoice, TelemetryOptions as TelemetryOptions$1, StopCondition, ActiveTools, LanguageModelResponseMetadata, LanguageModelUsage, FinishReason, ToolCallRepairFunction, Experimental_SandboxSession, ModelMessage, StepResult, GenerateTextOnStepEndCallback, UIMessage, UIMessageChunk, ChatTransport, PrepareSendMessagesRequest, PrepareReconnectToStreamRequest, ChatRequestOptions } from 'ai';
|
|
4
|
+
export { Output, ToolCallRepairFunction } from 'ai';
|
|
5
|
+
|
|
6
|
+
type ModelCallStreamPart<TTools extends ToolSet = ToolSet> = Experimental_LanguageModelStreamPart<TTools> | {
|
|
7
|
+
type: 'reset-step';
|
|
8
|
+
};
|
|
5
9
|
|
|
6
10
|
/**
|
|
7
11
|
* Shared types for AI SDK V4.
|
|
@@ -658,7 +662,7 @@ type WorkflowAgentStreamOptions<TTools extends ToolSet = ToolSet, TRuntimeContex
|
|
|
658
662
|
* });
|
|
659
663
|
* ```
|
|
660
664
|
*/
|
|
661
|
-
writable?: WritableStream<
|
|
665
|
+
writable?: WritableStream<ModelCallStreamPart<ToolSet>>;
|
|
662
666
|
/**
|
|
663
667
|
* Condition for stopping the generation when there are tool results in the last step.
|
|
664
668
|
* When the condition is an array, any of the conditions can be met to stop the generation.
|
|
@@ -995,12 +999,24 @@ declare class WorkflowAgent<TBaseTools extends ToolSet = ToolSet, TRuntimeContex
|
|
|
995
999
|
* Convert a single ModelCallStreamPart to a UIMessageChunk.
|
|
996
1000
|
* Returns undefined for parts that don't map to UI chunks.
|
|
997
1001
|
*/
|
|
998
|
-
declare function toUIMessageChunk(part:
|
|
1002
|
+
declare function toUIMessageChunk(part: ModelCallStreamPart<ToolSet>): UIMessageChunk | undefined;
|
|
999
1003
|
/**
|
|
1000
1004
|
* Create a TransformStream that converts ModelCallStreamPart to UIMessageChunk.
|
|
1001
1005
|
* Wraps toUIMessageChunk with start/start-step/finish-step lifecycle chunks.
|
|
1006
|
+
*
|
|
1007
|
+
* When resuming a stream, provide `uiStartIndex` and replay the source
|
|
1008
|
+
* ModelCallStreamPart stream from index 0. The transform will omit the UI
|
|
1009
|
+
* chunks that the client has already received. Raw model stream parts and UI
|
|
1010
|
+
* message chunks do not have a one-to-one relationship, so a UI chunk index
|
|
1011
|
+
* must not be used as the source stream's start index.
|
|
1002
1012
|
*/
|
|
1003
|
-
declare function createModelCallToUIChunkTransform(
|
|
1013
|
+
declare function createModelCallToUIChunkTransform({ uiStartIndex, }?: {
|
|
1014
|
+
/**
|
|
1015
|
+
* Number of transformed UIMessageChunks to omit from the output.
|
|
1016
|
+
* Must be a non-negative safe integer.
|
|
1017
|
+
*/
|
|
1018
|
+
uiStartIndex?: number;
|
|
1019
|
+
}): TransformStream<ModelCallStreamPart<ToolSet>, UIMessageChunk>;
|
|
1004
1020
|
|
|
1005
1021
|
interface SendMessagesOptions<UI_MESSAGE extends UIMessage> {
|
|
1006
1022
|
trigger: 'submit-message' | 'regenerate-message';
|
|
@@ -1014,7 +1030,8 @@ interface ReconnectToStreamOptions {
|
|
|
1014
1030
|
abortSignal?: AbortSignal;
|
|
1015
1031
|
/**
|
|
1016
1032
|
* Override the `startIndex` for this reconnection.
|
|
1017
|
-
* Negative values read from the end
|
|
1033
|
+
* Negative values read from the end when the server's durable stream and
|
|
1034
|
+
* tail-index header use the same UIMessageChunk index space.
|
|
1018
1035
|
* When omitted, falls back to the constructor's `initialStartIndex`.
|
|
1019
1036
|
*/
|
|
1020
1037
|
startIndex?: number;
|
|
@@ -1065,9 +1082,10 @@ interface WorkflowChatTransportOptions<UI_MESSAGE extends UIMessage> {
|
|
|
1065
1082
|
/**
|
|
1066
1083
|
* Default `startIndex` to use when reconnecting to a stream without a known
|
|
1067
1084
|
* chunk position (i.e. the initial reconnection, not a retry).
|
|
1068
|
-
* Negative values read from the end of
|
|
1069
|
-
* last 10 chunks), which is useful for resuming a chat UI
|
|
1070
|
-
* refresh without replaying the full conversation.
|
|
1085
|
+
* Negative values read from the end of a durable UIMessageChunk stream (e.g.
|
|
1086
|
+
* `-10` fetches the last 10 chunks), which is useful for resuming a chat UI
|
|
1087
|
+
* after a page refresh without replaying the full conversation. Raw
|
|
1088
|
+
* ModelCallStreamPart streams do not support negative UI chunk indexes.
|
|
1071
1089
|
*
|
|
1072
1090
|
* Can be overridden per-call via `ReconnectToStreamOptions.startIndex`.
|
|
1073
1091
|
*
|
|
@@ -1209,4 +1227,4 @@ declare class WorkflowChatTransport<UI_MESSAGE extends UIMessage> implements Cha
|
|
|
1209
1227
|
*/
|
|
1210
1228
|
declare function normalizeUIMessageStreamParts(source: AsyncIterable<UIMessageChunk>): AsyncGenerator<UIMessageChunk>;
|
|
1211
1229
|
|
|
1212
|
-
export { type CompatibleLanguageModel, type DownloadFunction, type GenerationSettings, type InferWorkflowAgentTools, type InferWorkflowAgentUIMessage, type OutputSpecification, type PrepareCallCallback, type PrepareCallOptions, type PrepareCallResult, type PrepareStepCallback, type PrepareStepInfo, type PrepareStepResult, type ProviderOptions, type ReconnectToStreamOptions, type SendMessagesOptions, type StreamTextTransform, type TelemetryOptions, WorkflowAgent, type WorkflowAgentOnAbortCallback, type WorkflowAgentOnEndCallback, type WorkflowAgentOnErrorCallback, type WorkflowAgentOnFinishCallback, type WorkflowAgentOnStartCallback, type WorkflowAgentOnStepEndCallback, type WorkflowAgentOnStepFinishCallback, type WorkflowAgentOnStepStartCallback, type WorkflowAgentOnToolExecutionEndCallback, type WorkflowAgentOnToolExecutionStartCallback, type WorkflowAgentOptions, type WorkflowAgentStreamOptions, type WorkflowAgentStreamResult, WorkflowChatTransport, type WorkflowChatTransportOptions, createModelCallToUIChunkTransform, normalizeUIMessageStreamParts, toUIMessageChunk };
|
|
1230
|
+
export { type CompatibleLanguageModel, type DownloadFunction, type GenerationSettings, type InferWorkflowAgentTools, type InferWorkflowAgentUIMessage, type ModelCallStreamPart, type OutputSpecification, type PrepareCallCallback, type PrepareCallOptions, type PrepareCallResult, type PrepareStepCallback, type PrepareStepInfo, type PrepareStepResult, type ProviderOptions, type ReconnectToStreamOptions, type SendMessagesOptions, type StreamTextTransform, type TelemetryOptions, WorkflowAgent, type WorkflowAgentOnAbortCallback, type WorkflowAgentOnEndCallback, type WorkflowAgentOnErrorCallback, type WorkflowAgentOnFinishCallback, type WorkflowAgentOnStartCallback, type WorkflowAgentOnStepEndCallback, type WorkflowAgentOnStepFinishCallback, type WorkflowAgentOnStepStartCallback, type WorkflowAgentOnToolExecutionEndCallback, type WorkflowAgentOnToolExecutionStartCallback, type WorkflowAgentOptions, type WorkflowAgentStreamOptions, type WorkflowAgentStreamResult, WorkflowChatTransport, type WorkflowChatTransportOptions, createModelCallToUIChunkTransform, normalizeUIMessageStreamParts, toUIMessageChunk };
|
package/dist/index.js
CHANGED
|
@@ -245,6 +245,7 @@ async function doStreamStep(conversationPrompt, modelInit, writable, serializedT
|
|
|
245
245
|
let hasTerminalError = false;
|
|
246
246
|
const writer = writable == null ? void 0 : writable.getWriter();
|
|
247
247
|
try {
|
|
248
|
+
await (writer == null ? void 0 : writer.write({ type: "reset-step" }));
|
|
248
249
|
for await (const part of modelStream) {
|
|
249
250
|
switch (part.type) {
|
|
250
251
|
case "text-delta":
|
|
@@ -2119,6 +2120,8 @@ async function executeTool(toolCall, tools, messages, context, download, sandbox
|
|
|
2119
2120
|
function toUIMessageChunk(part) {
|
|
2120
2121
|
var _a;
|
|
2121
2122
|
switch (part.type) {
|
|
2123
|
+
case "reset-step":
|
|
2124
|
+
return { type: "reset-step" };
|
|
2122
2125
|
case "text-start":
|
|
2123
2126
|
return {
|
|
2124
2127
|
type: "text-start",
|
|
@@ -2262,20 +2265,31 @@ function toUIMessageChunk(part) {
|
|
|
2262
2265
|
}
|
|
2263
2266
|
}
|
|
2264
2267
|
}
|
|
2265
|
-
function createModelCallToUIChunkTransform(
|
|
2268
|
+
function createModelCallToUIChunkTransform({
|
|
2269
|
+
uiStartIndex = 0
|
|
2270
|
+
} = {}) {
|
|
2271
|
+
if (!Number.isSafeInteger(uiStartIndex) || uiStartIndex < 0) {
|
|
2272
|
+
throw new RangeError("uiStartIndex must be a non-negative safe integer");
|
|
2273
|
+
}
|
|
2274
|
+
let uiChunkIndex = 0;
|
|
2275
|
+
const enqueue = (controller, chunk) => {
|
|
2276
|
+
if (uiChunkIndex++ >= uiStartIndex) {
|
|
2277
|
+
controller.enqueue(chunk);
|
|
2278
|
+
}
|
|
2279
|
+
};
|
|
2266
2280
|
return new TransformStream({
|
|
2267
2281
|
start: (controller) => {
|
|
2268
|
-
|
|
2269
|
-
|
|
2282
|
+
enqueue(controller, { type: "start" });
|
|
2283
|
+
enqueue(controller, { type: "start-step" });
|
|
2270
2284
|
},
|
|
2271
2285
|
flush: (controller) => {
|
|
2272
|
-
|
|
2273
|
-
|
|
2286
|
+
enqueue(controller, { type: "finish-step" });
|
|
2287
|
+
enqueue(controller, { type: "finish" });
|
|
2274
2288
|
},
|
|
2275
2289
|
transform: (part, controller) => {
|
|
2276
2290
|
const uiChunk = toUIMessageChunk(part);
|
|
2277
2291
|
if (uiChunk) {
|
|
2278
|
-
|
|
2292
|
+
enqueue(controller, uiChunk);
|
|
2279
2293
|
}
|
|
2280
2294
|
}
|
|
2281
2295
|
});
|
|
@@ -2324,6 +2338,13 @@ async function* normalizeUIMessageStreamParts(source) {
|
|
|
2324
2338
|
const reasoning = newPartFrameState();
|
|
2325
2339
|
for await (const chunk of source) {
|
|
2326
2340
|
switch (chunk.type) {
|
|
2341
|
+
case "reset-step":
|
|
2342
|
+
text.open.clear();
|
|
2343
|
+
text.ended.clear();
|
|
2344
|
+
reasoning.open.clear();
|
|
2345
|
+
reasoning.ended.clear();
|
|
2346
|
+
yield chunk;
|
|
2347
|
+
break;
|
|
2327
2348
|
case "finish-step":
|
|
2328
2349
|
text.open.clear();
|
|
2329
2350
|
text.ended.clear();
|
|
@@ -2381,6 +2402,10 @@ function createOrphanFilter() {
|
|
|
2381
2402
|
}
|
|
2382
2403
|
function shouldDrop(chunk) {
|
|
2383
2404
|
switch (chunk.type) {
|
|
2405
|
+
case "reset-step":
|
|
2406
|
+
seenStartedIds.clear();
|
|
2407
|
+
seenStartedToolCallIds.clear();
|
|
2408
|
+
return false;
|
|
2384
2409
|
case "text-start":
|
|
2385
2410
|
case "reasoning-start":
|
|
2386
2411
|
seenStartedIds.add(chunk.id);
|