@ai-sdk/workflow 1.0.0-canary.72 → 1.0.0-canary.74
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 +14 -0
- package/dist/index.mjs +21 -19
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/providers/mock.ts +8 -8
- package/src/to-ui-message-chunk.ts +8 -8
- package/src/workflow-chat-transport.ts +15 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @ai-sdk/workflow
|
|
2
2
|
|
|
3
|
+
## 1.0.0-canary.74
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- ai@7.0.0-canary.157
|
|
8
|
+
|
|
9
|
+
## 1.0.0-canary.73
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [023550e]
|
|
14
|
+
- Updated dependencies [e92fc45]
|
|
15
|
+
- ai@7.0.0-canary.156
|
|
16
|
+
|
|
3
17
|
## 1.0.0-canary.72
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/dist/index.mjs
CHANGED
|
@@ -1945,16 +1945,16 @@ function toUIMessageChunk(part) {
|
|
|
1945
1945
|
case "raw":
|
|
1946
1946
|
return void 0;
|
|
1947
1947
|
default: {
|
|
1948
|
-
const
|
|
1949
|
-
if (
|
|
1948
|
+
const passthroughPart = part;
|
|
1949
|
+
if (passthroughPart.type === "tool-approval-request") {
|
|
1950
1950
|
return {
|
|
1951
1951
|
type: "tool-approval-request",
|
|
1952
|
-
approvalId:
|
|
1953
|
-
toolCallId:
|
|
1952
|
+
approvalId: passthroughPart.approvalId,
|
|
1953
|
+
toolCallId: passthroughPart.toolCallId
|
|
1954
1954
|
};
|
|
1955
1955
|
}
|
|
1956
|
-
if (
|
|
1957
|
-
return
|
|
1956
|
+
if (passthroughPart.type === "finish-step" || passthroughPart.type === "start-step" || passthroughPart.type === "tool-output-denied") {
|
|
1957
|
+
return passthroughPart;
|
|
1958
1958
|
}
|
|
1959
1959
|
return void 0;
|
|
1960
1960
|
}
|
|
@@ -2053,7 +2053,7 @@ var WorkflowChatTransport = class {
|
|
|
2053
2053
|
messageId
|
|
2054
2054
|
}) : void 0;
|
|
2055
2055
|
const url = (_a = requestConfig == null ? void 0 : requestConfig.api) != null ? _a : this.api;
|
|
2056
|
-
const
|
|
2056
|
+
const response = await this.fetch(url, {
|
|
2057
2057
|
method: "POST",
|
|
2058
2058
|
body: JSON.stringify(
|
|
2059
2059
|
(_b = requestConfig == null ? void 0 : requestConfig.body) != null ? _b : { messages, ...options.body }
|
|
@@ -2062,21 +2062,21 @@ var WorkflowChatTransport = class {
|
|
|
2062
2062
|
credentials: requestConfig == null ? void 0 : requestConfig.credentials,
|
|
2063
2063
|
signal: abortSignal
|
|
2064
2064
|
});
|
|
2065
|
-
if (!
|
|
2065
|
+
if (!response.ok || !response.body) {
|
|
2066
2066
|
throw new Error(
|
|
2067
|
-
`Failed to fetch chat: ${
|
|
2067
|
+
`Failed to fetch chat: ${response.status} ${await response.text()}`
|
|
2068
2068
|
);
|
|
2069
2069
|
}
|
|
2070
|
-
const workflowRunId =
|
|
2070
|
+
const workflowRunId = response.headers.get("x-workflow-run-id");
|
|
2071
2071
|
if (!workflowRunId) {
|
|
2072
2072
|
throw new Error(
|
|
2073
2073
|
'Workflow run ID not found in "x-workflow-run-id" response header'
|
|
2074
2074
|
);
|
|
2075
2075
|
}
|
|
2076
|
-
await ((_c = this.onChatSendMessage) == null ? void 0 : _c.call(this,
|
|
2076
|
+
await ((_c = this.onChatSendMessage) == null ? void 0 : _c.call(this, response, options));
|
|
2077
2077
|
try {
|
|
2078
2078
|
const chunkStream = parseJsonEventStream({
|
|
2079
|
-
stream:
|
|
2079
|
+
stream: response.body,
|
|
2080
2080
|
schema: uiMessageChunkSchema
|
|
2081
2081
|
});
|
|
2082
2082
|
for await (const chunk of createAsyncIterableStream(chunkStream)) {
|
|
@@ -2111,8 +2111,8 @@ var WorkflowChatTransport = class {
|
|
|
2111
2111
|
* @throws Error if the reconnection request fails or returns a non-OK status
|
|
2112
2112
|
*/
|
|
2113
2113
|
async reconnectToStream(options) {
|
|
2114
|
-
const
|
|
2115
|
-
return convertAsyncIteratorToReadableStream(
|
|
2114
|
+
const reconnectIterator = this.reconnectToStreamIterator(options);
|
|
2115
|
+
return convertAsyncIteratorToReadableStream(reconnectIterator);
|
|
2116
2116
|
}
|
|
2117
2117
|
async *reconnectToStreamIterator(options, workflowRunId, initialChunkIndex = 0) {
|
|
2118
2118
|
var _a, _b;
|
|
@@ -2135,20 +2135,22 @@ var WorkflowChatTransport = class {
|
|
|
2135
2135
|
while (!gotFinish) {
|
|
2136
2136
|
const startIndex = useExplicitStartIndex ? explicitStartIndex : replayFromStart ? 0 : chunkIndex;
|
|
2137
2137
|
const url = `${baseUrl}?startIndex=${startIndex}`;
|
|
2138
|
-
const
|
|
2138
|
+
const response = await this.fetch(url, {
|
|
2139
2139
|
headers: requestConfig == null ? void 0 : requestConfig.headers,
|
|
2140
2140
|
credentials: requestConfig == null ? void 0 : requestConfig.credentials,
|
|
2141
2141
|
signal: options.abortSignal
|
|
2142
2142
|
});
|
|
2143
|
-
if (!
|
|
2143
|
+
if (!response.ok || !response.body) {
|
|
2144
2144
|
throw new Error(
|
|
2145
|
-
`Failed to fetch chat: ${
|
|
2145
|
+
`Failed to fetch chat: ${response.status} ${await response.text()}`
|
|
2146
2146
|
);
|
|
2147
2147
|
}
|
|
2148
2148
|
if (useExplicitStartIndex && explicitStartIndex > 0) {
|
|
2149
2149
|
chunkIndex = explicitStartIndex;
|
|
2150
2150
|
} else if (useExplicitStartIndex && explicitStartIndex < 0) {
|
|
2151
|
-
const tailIndexHeader =
|
|
2151
|
+
const tailIndexHeader = response.headers.get(
|
|
2152
|
+
"x-workflow-stream-tail-index"
|
|
2153
|
+
);
|
|
2152
2154
|
const tailIndex = tailIndexHeader !== null ? parseInt(tailIndexHeader, 10) : NaN;
|
|
2153
2155
|
if (!Number.isNaN(tailIndex)) {
|
|
2154
2156
|
chunkIndex = Math.max(0, tailIndex + 1 + explicitStartIndex);
|
|
@@ -2162,7 +2164,7 @@ var WorkflowChatTransport = class {
|
|
|
2162
2164
|
useExplicitStartIndex = false;
|
|
2163
2165
|
try {
|
|
2164
2166
|
const chunkStream = parseJsonEventStream({
|
|
2165
|
-
stream:
|
|
2167
|
+
stream: response.body,
|
|
2166
2168
|
schema: uiMessageChunkSchema
|
|
2167
2169
|
});
|
|
2168
2170
|
for await (const chunk of createAsyncIterableStream(chunkStream)) {
|