@ai-sdk/workflow 2.0.0 → 2.0.3
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 +20 -0
- package/dist/index.d.ts +19 -5
- package/dist/index.js +17 -6
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/to-ui-message-chunk.ts +35 -9
- package/src/workflow-chat-transport.ts +6 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @ai-sdk/workflow
|
|
2
2
|
|
|
3
|
+
## 2.0.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- ai@7.0.73
|
|
8
|
+
|
|
9
|
+
## 2.0.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- ai@7.0.72
|
|
14
|
+
|
|
15
|
+
## 2.0.1
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- 4233a40: Resume transformed WorkflowAgent streams using UI message chunk indexes.
|
|
20
|
+
- Updated dependencies [9a37469]
|
|
21
|
+
- ai@7.0.71
|
|
22
|
+
|
|
3
23
|
## 2.0.0
|
|
4
24
|
|
|
5
25
|
### Major Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1003,8 +1003,20 @@ declare function toUIMessageChunk(part: ModelCallStreamPart<ToolSet>): UIMessage
|
|
|
1003
1003
|
/**
|
|
1004
1004
|
* Create a TransformStream that converts ModelCallStreamPart to UIMessageChunk.
|
|
1005
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.
|
|
1006
1012
|
*/
|
|
1007
|
-
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>;
|
|
1008
1020
|
|
|
1009
1021
|
interface SendMessagesOptions<UI_MESSAGE extends UIMessage> {
|
|
1010
1022
|
trigger: 'submit-message' | 'regenerate-message';
|
|
@@ -1018,7 +1030,8 @@ interface ReconnectToStreamOptions {
|
|
|
1018
1030
|
abortSignal?: AbortSignal;
|
|
1019
1031
|
/**
|
|
1020
1032
|
* Override the `startIndex` for this reconnection.
|
|
1021
|
-
* 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.
|
|
1022
1035
|
* When omitted, falls back to the constructor's `initialStartIndex`.
|
|
1023
1036
|
*/
|
|
1024
1037
|
startIndex?: number;
|
|
@@ -1069,9 +1082,10 @@ interface WorkflowChatTransportOptions<UI_MESSAGE extends UIMessage> {
|
|
|
1069
1082
|
/**
|
|
1070
1083
|
* Default `startIndex` to use when reconnecting to a stream without a known
|
|
1071
1084
|
* chunk position (i.e. the initial reconnection, not a retry).
|
|
1072
|
-
* Negative values read from the end of
|
|
1073
|
-
* last 10 chunks), which is useful for resuming a chat UI
|
|
1074
|
-
* 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.
|
|
1075
1089
|
*
|
|
1076
1090
|
* Can be overridden per-call via `ReconnectToStreamOptions.startIndex`.
|
|
1077
1091
|
*
|
package/dist/index.js
CHANGED
|
@@ -2265,20 +2265,31 @@ function toUIMessageChunk(part) {
|
|
|
2265
2265
|
}
|
|
2266
2266
|
}
|
|
2267
2267
|
}
|
|
2268
|
-
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
|
+
};
|
|
2269
2280
|
return new TransformStream({
|
|
2270
2281
|
start: (controller) => {
|
|
2271
|
-
|
|
2272
|
-
|
|
2282
|
+
enqueue(controller, { type: "start" });
|
|
2283
|
+
enqueue(controller, { type: "start-step" });
|
|
2273
2284
|
},
|
|
2274
2285
|
flush: (controller) => {
|
|
2275
|
-
|
|
2276
|
-
|
|
2286
|
+
enqueue(controller, { type: "finish-step" });
|
|
2287
|
+
enqueue(controller, { type: "finish" });
|
|
2277
2288
|
},
|
|
2278
2289
|
transform: (part, controller) => {
|
|
2279
2290
|
const uiChunk = toUIMessageChunk(part);
|
|
2280
2291
|
if (uiChunk) {
|
|
2281
|
-
|
|
2292
|
+
enqueue(controller, uiChunk);
|
|
2282
2293
|
}
|
|
2283
2294
|
}
|
|
2284
2295
|
});
|