@mastra/ai-sdk 1.4.0 → 1.4.1-alpha.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 +22 -0
- package/dist/chat-route.d.ts +15 -0
- package/dist/chat-route.d.ts.map +1 -1
- package/dist/helpers.d.ts +12 -5
- package/dist/helpers.d.ts.map +1 -1
- package/dist/index.cjs +232 -87
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +232 -87
- package/dist/index.js.map +1 -1
- package/dist/transformers.d.ts +85 -81
- package/dist/transformers.d.ts.map +1 -1
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @mastra/ai-sdk
|
|
2
2
|
|
|
3
|
+
## 1.4.1-alpha.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fixed workflow streaming in @mastra/ai-sdk so intermediate `data-workflow` parts stop repeating every completed step output. Added `data-workflow-step` parts with the full payload for the step that just changed, which reduces stream size for long-running workflows while preserving final workflow outputs. ([#15218](https://github.com/mastra-ai/mastra/pull/15218))
|
|
8
|
+
|
|
9
|
+
If your UI reads live step outputs during workflow execution, it should now consume `data-workflow-step` parts in addition to `data-workflow`. Final workflow snapshots still include the full step outputs.
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`3d83d06`](https://github.com/mastra-ai/mastra/commit/3d83d06f776f00fb5f4163dddd32a030c5c20844), [`7e0e63e`](https://github.com/mastra-ai/mastra/commit/7e0e63e2e485e84442351f4c7a79a424c83539dc), [`9467ea8`](https://github.com/mastra-ai/mastra/commit/9467ea87695749a53dfc041576410ebf9ee7bb67), [`7338d94`](https://github.com/mastra-ai/mastra/commit/7338d949380cf68b095342e8e42610dc51d557c1)]:
|
|
12
|
+
- @mastra/core@1.26.0-alpha.2
|
|
13
|
+
|
|
14
|
+
## 1.4.1-alpha.0
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Fixed tool call approvals in AI SDK v6: `handleChatStream` now automatically routes to `resumeStream` when the AI SDK v6 native approval flow is used on the client (no extra server-side wiring required). The v6 stream now emits native `tool-approval-request` parts so `useChat` can surface approval UI and call `addToolApprovalResponse()`, while also emitting the existing `data-tool-call-approval` chunk for backwards compatibility. ([#15345](https://github.com/mastra-ai/mastra/pull/15345))
|
|
19
|
+
|
|
20
|
+
- Fixed AI SDK v6 tool approval streams so requireApproval works with handleChatStream and AssistantChatTransport. ([#15345](https://github.com/mastra-ai/mastra/pull/15345))
|
|
21
|
+
|
|
22
|
+
- Updated dependencies [[`d63ffdb`](https://github.com/mastra-ai/mastra/commit/d63ffdbb2c11e76fe5ea45faab44bc15460f010c)]:
|
|
23
|
+
- @mastra/core@1.25.1-alpha.0
|
|
24
|
+
|
|
3
25
|
## 1.4.0
|
|
4
26
|
|
|
5
27
|
### Minor Changes
|
package/dist/chat-route.d.ts
CHANGED
|
@@ -4,6 +4,21 @@ import type { AgentExecutionOptions } from '@mastra/core/agent';
|
|
|
4
4
|
import type { Mastra } from '@mastra/core/mastra';
|
|
5
5
|
import { registerApiRoute } from '@mastra/core/server';
|
|
6
6
|
import type { SupportedUIMessage, V5UIMessage, V5UIMessageStream, V6UIMessage, V6UIMessageStream } from './public-types.js';
|
|
7
|
+
/**
|
|
8
|
+
* Scans a v6 UIMessage array for an 'approval-responded' tool part in the
|
|
9
|
+
* last trailing assistant message only. When found, splits the composite
|
|
10
|
+
* approvalId ("${runId}::${toolCallId}") to recover the runId needed for
|
|
11
|
+
* resumeStream.
|
|
12
|
+
*
|
|
13
|
+
* Only the last trailing assistant message is inspected so that approval
|
|
14
|
+
* responses from earlier turns are never re-processed.
|
|
15
|
+
*
|
|
16
|
+
* Returns null when no approval response is present (normal chat turn).
|
|
17
|
+
*/
|
|
18
|
+
export declare function extractV6NativeApproval(messages: V6UIMessage[]): {
|
|
19
|
+
resumeData: Record<string, unknown>;
|
|
20
|
+
runId: string;
|
|
21
|
+
} | null;
|
|
7
22
|
export type ChatStreamHandlerParams<UI_MESSAGE extends SupportedUIMessage = SupportedUIMessage, OUTPUT = undefined> = AgentExecutionOptions<OUTPUT> & {
|
|
8
23
|
messages: UI_MESSAGE[];
|
|
9
24
|
resumeData?: Record<string, any>;
|
package/dist/chat-route.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-route.d.ts","sourceRoot":"","sources":["../src/chat-route.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,sBAAsB,IAAI,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"chat-route.d.ts","sourceRoot":"","sources":["../src/chat-route.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,sBAAsB,IAAI,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAM9F,OAAO,KAAK,EAAE,sBAAsB,IAAI,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC1F,OAAO,KAAK,EAAE,qBAAqB,EAA6B,MAAM,oBAAoB,CAAC;AAC3F,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAElD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAGvD,OAAO,KAAK,EACV,kBAAkB,EAClB,WAAW,EACX,iBAAiB,EACjB,WAAW,EACX,iBAAiB,EAClB,MAAM,gBAAgB,CAAC;AAExB;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,WAAW,EAAE,GACtB;IAAE,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CA+B/D;AAED,MAAM,MAAM,uBAAuB,CACjC,UAAU,SAAS,kBAAkB,GAAG,kBAAkB,EAC1D,MAAM,G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E,KAAK,CAAC;CACf,GACD;IACE,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,CACJ,GAAG;IACA,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,wBAAgB,SAAS,CAAC,MAAM,GAAG,SAAS,EAAE,EAC5C,IAAuB,EACvB,KAAK,EACL,cAAc,EACd,OAAc,EACd,YAAY,EACZ,SAAgB,EAChB,UAAiB,EACjB,aAAqB,EACrB,WAAmB,GACpB,EAAE,gBAAgB,CAAC,MAAM,CAAC,GAAG,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAkNhE"}
|
package/dist/helpers.d.ts
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import type { InferUIMessageChunk, ObjectStreamPart, TextStreamPart, ToolSet, UIMessage, FinishReason } from './_types/@internal_ai-sdk-v5/dist/index.js';
|
|
2
|
-
import type { FinishReason as FinishReasonV6 } from './_types/@internal_ai-v6/dist/index.js';
|
|
2
|
+
import type { FinishReason as FinishReasonV6, InferUIMessageChunk as InferUIMessageChunkV6, ToolApprovalRequest, UIMessage as UIMessageV6 } from './_types/@internal_ai-v6/dist/index.js';
|
|
3
3
|
import type { DataChunkType, ChunkType, MastraFinishReason } from '@mastra/core/stream';
|
|
4
|
+
/**
|
|
5
|
+
* Separator used to encode both runId and toolCallId into a single approvalId string.
|
|
6
|
+
* Chosen because neither runId nor toolCallId can contain ":" in normal usage
|
|
7
|
+
* (UUIDs are hex + hyphens; provider tool call IDs are alphanumeric + underscores).
|
|
8
|
+
* The server splits on this separator to recover the runId for resumeStream.
|
|
9
|
+
*/
|
|
10
|
+
export declare const APPROVAL_ID_SEPARATOR = "::";
|
|
4
11
|
/**
|
|
5
12
|
* Maps Mastra's extended finish reasons to AI SDK-compatible values.
|
|
6
13
|
* 'tripwire' and 'retry' are Mastra-specific reasons for processor scenarios,
|
|
7
14
|
* which are mapped to 'other' for AI SDK compatibility.
|
|
8
15
|
*/
|
|
9
16
|
export declare function toAISDKFinishReason(reason: MastraFinishReason): FinishReason;
|
|
10
|
-
export type OutputChunkType<OUTPUT = undefined> = TextStreamPart<ToolSet> | ObjectStreamPart<Partial<OUTPUT>> | DataChunkType | undefined;
|
|
17
|
+
export type OutputChunkType<OUTPUT = undefined> = TextStreamPart<ToolSet> | ObjectStreamPart<Partial<OUTPUT>> | ToolApprovalRequest | DataChunkType | undefined;
|
|
11
18
|
export type ToolAgentChunkType = {
|
|
12
19
|
type: 'tool-agent';
|
|
13
20
|
toolCallId: string;
|
|
@@ -40,9 +47,9 @@ export declare function toAISDKFinishReasonV6(reason: MastraFinishReason): Finis
|
|
|
40
47
|
export declare function convertMastraChunkToAISDKv6<OUTPUT = undefined>({ chunk, mode, }: {
|
|
41
48
|
chunk: ChunkType<OUTPUT>;
|
|
42
49
|
mode?: 'generate' | 'stream';
|
|
43
|
-
}): OutputChunkType<OUTPUT
|
|
50
|
+
}): OutputChunkType<OUTPUT> | OutputChunkType<OUTPUT>[];
|
|
44
51
|
export declare function convertFullStreamChunkToUIMessageStream<UI_MESSAGE extends UIMessage>({ part, messageMetadataValue, sendReasoning, sendSources, onError, sendStart, sendFinish, responseMessageId, }: {
|
|
45
|
-
part: TextStreamPart<ToolSet> | DataChunkType | {
|
|
52
|
+
part: TextStreamPart<ToolSet> | DataChunkType | ToolApprovalRequest | {
|
|
46
53
|
type: 'tool-output';
|
|
47
54
|
toolCallId: string;
|
|
48
55
|
output: any;
|
|
@@ -54,6 +61,6 @@ export declare function convertFullStreamChunkToUIMessageStream<UI_MESSAGE exten
|
|
|
54
61
|
sendStart?: boolean;
|
|
55
62
|
sendFinish?: boolean;
|
|
56
63
|
responseMessageId?: string;
|
|
57
|
-
}): InferUIMessageChunk<UI_MESSAGE> | ToolAgentChunkType | ToolWorkflowChunkType | ToolNetworkChunkType | undefined;
|
|
64
|
+
}): InferUIMessageChunk<UI_MESSAGE> | InferUIMessageChunkV6<UIMessageV6> | ToolAgentChunkType | ToolWorkflowChunkType | ToolNetworkChunkType | undefined;
|
|
58
65
|
export {};
|
|
59
66
|
//# sourceMappingURL=helpers.d.ts.map
|
package/dist/helpers.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EAEnB,gBAAgB,EAChB,cAAc,EACd,OAAO,EACP,SAAS,EACT,YAAY,EACb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAEV,YAAY,IAAI,cAAc,
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EAEnB,gBAAgB,EAChB,cAAc,EACd,OAAO,EACP,SAAS,EACT,YAAY,EACb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAEV,YAAY,IAAI,cAAc,EAC9B,mBAAmB,IAAI,qBAAqB,EAE5C,mBAAmB,EACnB,SAAS,IAAI,WAAW,EACzB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAGxF;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,OAAO,CAAC;AAE1C;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,kBAAkB,GAAG,YAAY,CAK5E;AAED,MAAM,MAAM,eAAe,CAAC,MAAM,GAAG,SAAS,IAC1C,cAAc,CAAC,OAAO,CAAC,GACvB,gBAAgB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GACjC,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11616
|
};
|
|
11617
11617
|
|
|
11618
11618
|
// src/helpers.ts
|
|
11619
|
+
var APPROVAL_ID_SEPARATOR = "::";
|
|
11619
11620
|
function toAISDKFinishReason(reason) {
|
|
11620
11621
|
if (reason === "tripwire" || reason === "retry") {
|
|
11621
11622
|
return "other";
|
|
@@ -11952,6 +11953,27 @@ function convertMastraChunkToAISDKv6({
|
|
|
11952
11953
|
chunk,
|
|
11953
11954
|
mode = "stream"
|
|
11954
11955
|
}) {
|
|
11956
|
+
if (chunk.type === "tool-call-approval") {
|
|
11957
|
+
return [
|
|
11958
|
+
{
|
|
11959
|
+
type: "tool-approval-request",
|
|
11960
|
+
approvalId: `${chunk.runId}${APPROVAL_ID_SEPARATOR}${chunk.payload.toolCallId}`,
|
|
11961
|
+
toolCallId: chunk.payload.toolCallId
|
|
11962
|
+
},
|
|
11963
|
+
{
|
|
11964
|
+
type: "data-tool-call-approval",
|
|
11965
|
+
id: chunk.payload.toolCallId,
|
|
11966
|
+
data: {
|
|
11967
|
+
state: "data-tool-call-approval",
|
|
11968
|
+
runId: chunk.runId,
|
|
11969
|
+
toolCallId: chunk.payload.toolCallId,
|
|
11970
|
+
toolName: chunk.payload.toolName,
|
|
11971
|
+
args: chunk.payload.args,
|
|
11972
|
+
resumeSchema: chunk.payload.resumeSchema
|
|
11973
|
+
}
|
|
11974
|
+
}
|
|
11975
|
+
];
|
|
11976
|
+
}
|
|
11955
11977
|
return convertMastraChunkToAISDKBase({
|
|
11956
11978
|
chunk,
|
|
11957
11979
|
mode,
|
|
@@ -12082,6 +12104,13 @@ function convertFullStreamChunkToUIMessageStream({
|
|
|
12082
12104
|
...part.dynamic != null ? { dynamic: part.dynamic } : {}
|
|
12083
12105
|
};
|
|
12084
12106
|
}
|
|
12107
|
+
case "tool-approval-request": {
|
|
12108
|
+
return {
|
|
12109
|
+
type: "tool-approval-request",
|
|
12110
|
+
approvalId: part.approvalId,
|
|
12111
|
+
toolCallId: part.toolCallId
|
|
12112
|
+
};
|
|
12113
|
+
}
|
|
12085
12114
|
case "tool-result": {
|
|
12086
12115
|
return {
|
|
12087
12116
|
type: "tool-output-available",
|
|
@@ -12190,6 +12219,45 @@ function convertFullStreamChunkToUIMessageStream({
|
|
|
12190
12219
|
|
|
12191
12220
|
// src/transformers.ts
|
|
12192
12221
|
var PRIMITIVE_CACHE_SYMBOL = /* @__PURE__ */ Symbol("primitive-cache");
|
|
12222
|
+
function cloneWorkflowStep(step, includeOutput) {
|
|
12223
|
+
return {
|
|
12224
|
+
name: step.name,
|
|
12225
|
+
status: step.status,
|
|
12226
|
+
input: step.input,
|
|
12227
|
+
output: includeOutput ? step.output : null,
|
|
12228
|
+
suspendPayload: step.suspendPayload,
|
|
12229
|
+
resumePayload: step.resumePayload
|
|
12230
|
+
};
|
|
12231
|
+
}
|
|
12232
|
+
function serializeWorkflowSteps(steps, { includeOutputs }) {
|
|
12233
|
+
return Object.fromEntries(Object.entries(steps).map(([id, step]) => [id, cloneWorkflowStep(step, includeOutputs)]));
|
|
12234
|
+
}
|
|
12235
|
+
function createWorkflowDataPart(args) {
|
|
12236
|
+
const { current, isNested, runId, status, includeOutputs = false, output = null } = args;
|
|
12237
|
+
return {
|
|
12238
|
+
type: isNested ? "data-tool-workflow" : "data-workflow",
|
|
12239
|
+
id: runId,
|
|
12240
|
+
data: {
|
|
12241
|
+
name: current.name,
|
|
12242
|
+
status,
|
|
12243
|
+
steps: serializeWorkflowSteps(current.steps, { includeOutputs }),
|
|
12244
|
+
output
|
|
12245
|
+
}
|
|
12246
|
+
};
|
|
12247
|
+
}
|
|
12248
|
+
function createWorkflowStepDataPart(args) {
|
|
12249
|
+
const { current, isNested, runId, status, stepId } = args;
|
|
12250
|
+
return {
|
|
12251
|
+
type: isNested ? "data-tool-workflow-step" : "data-workflow-step",
|
|
12252
|
+
id: `${runId}:${stepId}`,
|
|
12253
|
+
data: {
|
|
12254
|
+
name: current.name,
|
|
12255
|
+
status,
|
|
12256
|
+
stepId,
|
|
12257
|
+
step: cloneWorkflowStep(current.steps[stepId], true)
|
|
12258
|
+
}
|
|
12259
|
+
};
|
|
12260
|
+
}
|
|
12193
12261
|
function createWorkflowStreamToAISDKTransformer(convertMastraChunkToAISDK, {
|
|
12194
12262
|
includeTextStreamParts,
|
|
12195
12263
|
sendReasoning,
|
|
@@ -12219,7 +12287,15 @@ function createWorkflowStreamToAISDKTransformer(convertMastraChunkToAISDK, {
|
|
|
12219
12287
|
},
|
|
12220
12288
|
convertMastraChunkToAISDK
|
|
12221
12289
|
);
|
|
12222
|
-
if (transformed)
|
|
12290
|
+
if (transformed) {
|
|
12291
|
+
if (Array.isArray(transformed)) {
|
|
12292
|
+
for (const item of transformed) {
|
|
12293
|
+
controller.enqueue(item);
|
|
12294
|
+
}
|
|
12295
|
+
} else {
|
|
12296
|
+
controller.enqueue(transformed);
|
|
12297
|
+
}
|
|
12298
|
+
}
|
|
12223
12299
|
}
|
|
12224
12300
|
});
|
|
12225
12301
|
}
|
|
@@ -12307,41 +12383,64 @@ function createAgentStreamToAISDKTransformer(convertMastraChunkToAISDK, {
|
|
|
12307
12383
|
});
|
|
12308
12384
|
}
|
|
12309
12385
|
const part = convertMastraChunkToAISDK({ chunk, mode: "stream" });
|
|
12310
|
-
const
|
|
12311
|
-
|
|
12312
|
-
|
|
12313
|
-
|
|
12314
|
-
|
|
12315
|
-
|
|
12316
|
-
|
|
12317
|
-
|
|
12318
|
-
|
|
12319
|
-
|
|
12386
|
+
const enqueueTransformedPart = (p) => {
|
|
12387
|
+
const transformedChunk = convertFullStreamChunkToUIMessageStream({
|
|
12388
|
+
part: p,
|
|
12389
|
+
sendReasoning,
|
|
12390
|
+
sendSources,
|
|
12391
|
+
messageMetadataValue: p ? messageMetadata?.({ part: p }) : void 0,
|
|
12392
|
+
sendStart,
|
|
12393
|
+
sendFinish,
|
|
12394
|
+
responseMessageId: lastMessageId,
|
|
12395
|
+
onError(error) {
|
|
12396
|
+
return onError ? onError(error) : safeParseErrorObject(error);
|
|
12397
|
+
}
|
|
12398
|
+
});
|
|
12399
|
+
if (transformedChunk) {
|
|
12400
|
+
if (transformedChunk.type === "tool-agent") {
|
|
12401
|
+
const payload = transformedChunk.payload;
|
|
12402
|
+
const agentTransformed = transformAgent(payload, bufferedSteps);
|
|
12403
|
+
if (agentTransformed) controller.enqueue(agentTransformed);
|
|
12404
|
+
} else if (transformedChunk.type === "tool-workflow") {
|
|
12405
|
+
const payload = transformedChunk.payload;
|
|
12406
|
+
const workflowChunk = transformWorkflow(
|
|
12407
|
+
payload,
|
|
12408
|
+
bufferedSteps,
|
|
12409
|
+
true,
|
|
12410
|
+
void 0,
|
|
12411
|
+
void 0,
|
|
12412
|
+
convertMastraChunkToAISDK
|
|
12413
|
+
);
|
|
12414
|
+
if (workflowChunk) {
|
|
12415
|
+
if (Array.isArray(workflowChunk)) {
|
|
12416
|
+
for (const item of workflowChunk) {
|
|
12417
|
+
controller.enqueue(item);
|
|
12418
|
+
}
|
|
12419
|
+
} else {
|
|
12420
|
+
controller.enqueue(workflowChunk);
|
|
12421
|
+
}
|
|
12422
|
+
}
|
|
12423
|
+
} else if (transformedChunk.type === "tool-network") {
|
|
12424
|
+
const payload = transformedChunk.payload;
|
|
12425
|
+
const networkChunk = transformNetwork(payload, bufferedSteps, true);
|
|
12426
|
+
if (Array.isArray(networkChunk)) {
|
|
12427
|
+
for (const c of networkChunk) {
|
|
12428
|
+
if (c) controller.enqueue(c);
|
|
12429
|
+
}
|
|
12430
|
+
} else if (networkChunk) {
|
|
12431
|
+
controller.enqueue(networkChunk);
|
|
12432
|
+
}
|
|
12433
|
+
} else {
|
|
12434
|
+
controller.enqueue(transformedChunk);
|
|
12435
|
+
}
|
|
12320
12436
|
}
|
|
12321
|
-
}
|
|
12322
|
-
if (
|
|
12323
|
-
|
|
12324
|
-
|
|
12325
|
-
const agentTransformed = transformAgent(payload, bufferedSteps);
|
|
12326
|
-
if (agentTransformed) controller.enqueue(agentTransformed);
|
|
12327
|
-
} else if (transformedChunk.type === "tool-workflow") {
|
|
12328
|
-
const payload = transformedChunk.payload;
|
|
12329
|
-
const workflowChunk = transformWorkflow(
|
|
12330
|
-
payload,
|
|
12331
|
-
bufferedSteps,
|
|
12332
|
-
true,
|
|
12333
|
-
void 0,
|
|
12334
|
-
void 0,
|
|
12335
|
-
convertMastraChunkToAISDK
|
|
12336
|
-
);
|
|
12337
|
-
if (workflowChunk) controller.enqueue(workflowChunk);
|
|
12338
|
-
} else if (transformedChunk.type === "tool-network") {
|
|
12339
|
-
const payload = transformedChunk.payload;
|
|
12340
|
-
const networkChunk = transformNetwork(payload, bufferedSteps, true);
|
|
12341
|
-
if (networkChunk) controller.enqueue(networkChunk);
|
|
12342
|
-
} else {
|
|
12343
|
-
controller.enqueue(transformedChunk);
|
|
12437
|
+
};
|
|
12438
|
+
if (Array.isArray(part)) {
|
|
12439
|
+
for (const p of part) {
|
|
12440
|
+
enqueueTransformedPart(p);
|
|
12344
12441
|
}
|
|
12442
|
+
} else {
|
|
12443
|
+
enqueueTransformedPart(part);
|
|
12345
12444
|
}
|
|
12346
12445
|
},
|
|
12347
12446
|
flush(controller) {
|
|
@@ -12594,16 +12693,12 @@ function transformWorkflow(payload, bufferedWorkflows, isNested, includeTextStre
|
|
|
12594
12693
|
name: payload.payload.workflowId,
|
|
12595
12694
|
steps: {}
|
|
12596
12695
|
});
|
|
12597
|
-
return {
|
|
12598
|
-
|
|
12599
|
-
|
|
12600
|
-
|
|
12601
|
-
|
|
12602
|
-
|
|
12603
|
-
steps: bufferedWorkflows.get(payload.runId).steps,
|
|
12604
|
-
output: null
|
|
12605
|
-
}
|
|
12606
|
-
};
|
|
12696
|
+
return createWorkflowDataPart({
|
|
12697
|
+
current: bufferedWorkflows.get(payload.runId),
|
|
12698
|
+
isNested,
|
|
12699
|
+
runId: payload.runId,
|
|
12700
|
+
status: "running"
|
|
12701
|
+
});
|
|
12607
12702
|
case "workflow-step-start": {
|
|
12608
12703
|
const current = bufferedWorkflows.get(payload.runId) || { name: "", steps: {} };
|
|
12609
12704
|
current.steps[payload.payload.id] = {
|
|
@@ -12615,16 +12710,12 @@ function transformWorkflow(payload, bufferedWorkflows, isNested, includeTextStre
|
|
|
12615
12710
|
resumePayload: null
|
|
12616
12711
|
};
|
|
12617
12712
|
bufferedWorkflows.set(payload.runId, current);
|
|
12618
|
-
return {
|
|
12619
|
-
|
|
12620
|
-
|
|
12621
|
-
|
|
12622
|
-
|
|
12623
|
-
|
|
12624
|
-
steps: current.steps,
|
|
12625
|
-
output: null
|
|
12626
|
-
}
|
|
12627
|
-
};
|
|
12713
|
+
return createWorkflowDataPart({
|
|
12714
|
+
current,
|
|
12715
|
+
isNested,
|
|
12716
|
+
runId: payload.runId,
|
|
12717
|
+
status: "running"
|
|
12718
|
+
});
|
|
12628
12719
|
}
|
|
12629
12720
|
case "workflow-step-result": {
|
|
12630
12721
|
const current = bufferedWorkflows.get(payload.runId);
|
|
@@ -12634,16 +12725,21 @@ function transformWorkflow(payload, bufferedWorkflows, isNested, includeTextStre
|
|
|
12634
12725
|
status: payload.payload.status,
|
|
12635
12726
|
output: payload.payload.output ?? null
|
|
12636
12727
|
};
|
|
12637
|
-
return
|
|
12638
|
-
|
|
12639
|
-
|
|
12640
|
-
|
|
12641
|
-
|
|
12728
|
+
return [
|
|
12729
|
+
createWorkflowDataPart({
|
|
12730
|
+
current,
|
|
12731
|
+
isNested,
|
|
12732
|
+
runId: payload.runId,
|
|
12733
|
+
status: "running"
|
|
12734
|
+
}),
|
|
12735
|
+
createWorkflowStepDataPart({
|
|
12736
|
+
current,
|
|
12737
|
+
isNested,
|
|
12738
|
+
runId: payload.runId,
|
|
12642
12739
|
status: "running",
|
|
12643
|
-
|
|
12644
|
-
|
|
12645
|
-
|
|
12646
|
-
};
|
|
12740
|
+
stepId: payload.payload.id
|
|
12741
|
+
})
|
|
12742
|
+
];
|
|
12647
12743
|
}
|
|
12648
12744
|
case "workflow-step-suspended": {
|
|
12649
12745
|
const current = bufferedWorkflows.get(payload.runId);
|
|
@@ -12655,35 +12751,50 @@ function transformWorkflow(payload, bufferedWorkflows, isNested, includeTextStre
|
|
|
12655
12751
|
resumePayload: payload.payload.resumePayload ?? null,
|
|
12656
12752
|
output: null
|
|
12657
12753
|
};
|
|
12658
|
-
return
|
|
12659
|
-
|
|
12660
|
-
|
|
12661
|
-
|
|
12662
|
-
|
|
12754
|
+
return [
|
|
12755
|
+
createWorkflowDataPart({
|
|
12756
|
+
current,
|
|
12757
|
+
isNested,
|
|
12758
|
+
runId: payload.runId,
|
|
12759
|
+
status: "suspended"
|
|
12760
|
+
}),
|
|
12761
|
+
createWorkflowStepDataPart({
|
|
12762
|
+
current,
|
|
12763
|
+
isNested,
|
|
12764
|
+
runId: payload.runId,
|
|
12663
12765
|
status: "suspended",
|
|
12664
|
-
|
|
12665
|
-
|
|
12666
|
-
|
|
12667
|
-
};
|
|
12766
|
+
stepId: payload.payload.id
|
|
12767
|
+
})
|
|
12768
|
+
];
|
|
12668
12769
|
}
|
|
12669
12770
|
case "workflow-finish": {
|
|
12670
12771
|
const current = bufferedWorkflows.get(payload.runId);
|
|
12671
12772
|
if (!current) return null;
|
|
12672
|
-
return {
|
|
12673
|
-
|
|
12674
|
-
|
|
12675
|
-
|
|
12676
|
-
|
|
12677
|
-
|
|
12678
|
-
|
|
12679
|
-
|
|
12680
|
-
}
|
|
12681
|
-
};
|
|
12773
|
+
return createWorkflowDataPart({
|
|
12774
|
+
current,
|
|
12775
|
+
isNested,
|
|
12776
|
+
runId: payload.runId,
|
|
12777
|
+
status: payload.payload.workflowStatus,
|
|
12778
|
+
includeOutputs: true,
|
|
12779
|
+
output: payload.payload.output ?? null
|
|
12780
|
+
});
|
|
12682
12781
|
}
|
|
12683
12782
|
case "workflow-step-output": {
|
|
12684
12783
|
const output = payload.payload.output;
|
|
12685
12784
|
if (includeTextStreamParts && output && isMastraTextStreamChunk(output)) {
|
|
12686
12785
|
const part = convertMastraChunkToAISDK({ chunk: output, mode: "stream" });
|
|
12786
|
+
if (Array.isArray(part)) {
|
|
12787
|
+
return part.map(
|
|
12788
|
+
(p) => convertFullStreamChunkToUIMessageStream({
|
|
12789
|
+
part: p,
|
|
12790
|
+
sendReasoning: streamOptions?.sendReasoning,
|
|
12791
|
+
sendSources: streamOptions?.sendSources,
|
|
12792
|
+
onError(error) {
|
|
12793
|
+
return safeParseErrorObject(error);
|
|
12794
|
+
}
|
|
12795
|
+
})
|
|
12796
|
+
).filter(Boolean);
|
|
12797
|
+
}
|
|
12687
12798
|
const transformedChunk = convertFullStreamChunkToUIMessageStream({
|
|
12688
12799
|
part,
|
|
12689
12800
|
sendReasoning: streamOptions?.sendReasoning,
|
|
@@ -13051,15 +13162,16 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
13051
13162
|
}
|
|
13052
13163
|
step[PRIMITIVE_CACHE_SYMBOL] = step[PRIMITIVE_CACHE_SYMBOL] || /* @__PURE__ */ new Map();
|
|
13053
13164
|
const result = transformWorkflow(payload.payload, step[PRIMITIVE_CACHE_SYMBOL]);
|
|
13054
|
-
|
|
13055
|
-
|
|
13165
|
+
const workflowResult = Array.isArray(result) ? result.find((item) => item?.type === "data-workflow" || item?.type === "data-tool-workflow") : result;
|
|
13166
|
+
if (workflowResult && "data" in workflowResult) {
|
|
13167
|
+
const data = workflowResult.data;
|
|
13056
13168
|
step.task = data;
|
|
13057
13169
|
if (data.name && step.task) {
|
|
13058
13170
|
step.task.id = data.name;
|
|
13059
13171
|
}
|
|
13060
13172
|
}
|
|
13061
13173
|
bufferedNetworks.set(payload.runId, current);
|
|
13062
|
-
|
|
13174
|
+
const networkChunk = {
|
|
13063
13175
|
type: isNested ? "data-tool-network" : "data-network",
|
|
13064
13176
|
id: payload.runId,
|
|
13065
13177
|
data: {
|
|
@@ -13067,6 +13179,10 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
13067
13179
|
status: "running"
|
|
13068
13180
|
}
|
|
13069
13181
|
};
|
|
13182
|
+
if (Array.isArray(result)) {
|
|
13183
|
+
return [networkChunk, ...result.filter((r) => r != null)];
|
|
13184
|
+
}
|
|
13185
|
+
return networkChunk;
|
|
13070
13186
|
}
|
|
13071
13187
|
if (isDataChunkType(payload)) {
|
|
13072
13188
|
if (!("data" in payload)) {
|
|
@@ -13181,6 +13297,32 @@ function toAISdkStream(stream, options = {
|
|
|
13181
13297
|
}
|
|
13182
13298
|
|
|
13183
13299
|
// src/chat-route.ts
|
|
13300
|
+
function extractV6NativeApproval(messages) {
|
|
13301
|
+
let lastAssistantMsg;
|
|
13302
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
13303
|
+
const message = messages[i];
|
|
13304
|
+
if (message.role === "assistant") {
|
|
13305
|
+
lastAssistantMsg = message;
|
|
13306
|
+
break;
|
|
13307
|
+
}
|
|
13308
|
+
}
|
|
13309
|
+
if (!lastAssistantMsg) return null;
|
|
13310
|
+
for (const part of lastAssistantMsg.parts ?? []) {
|
|
13311
|
+
if (!isToolUIPart2(part) || part.state !== "approval-responded") continue;
|
|
13312
|
+
const lastSep = part.approval.id.lastIndexOf(APPROVAL_ID_SEPARATOR);
|
|
13313
|
+
if (lastSep === -1) continue;
|
|
13314
|
+
const runId = part.approval.id.slice(0, lastSep);
|
|
13315
|
+
if (!runId) continue;
|
|
13316
|
+
return {
|
|
13317
|
+
resumeData: {
|
|
13318
|
+
approved: part.approval.approved,
|
|
13319
|
+
...part.approval.reason != null ? { reason: part.approval.reason } : {}
|
|
13320
|
+
},
|
|
13321
|
+
runId
|
|
13322
|
+
};
|
|
13323
|
+
}
|
|
13324
|
+
return null;
|
|
13325
|
+
}
|
|
13184
13326
|
async function handleChatStream({
|
|
13185
13327
|
mastra,
|
|
13186
13328
|
agentId,
|
|
@@ -13206,6 +13348,9 @@ async function handleChatStream({
|
|
|
13206
13348
|
if (!Array.isArray(messages)) {
|
|
13207
13349
|
throw new Error("Messages must be an array of UIMessage objects");
|
|
13208
13350
|
}
|
|
13351
|
+
const nativeApproval = version === "v6" && !resumeData ? extractV6NativeApproval(messages) : null;
|
|
13352
|
+
const effectiveResumeData = nativeApproval?.resumeData ?? resumeData;
|
|
13353
|
+
const effectiveRunId = nativeApproval?.runId ?? runId;
|
|
13209
13354
|
let lastMessageId;
|
|
13210
13355
|
let messagesToSend = messages;
|
|
13211
13356
|
if (messages.length > 0) {
|
|
@@ -13227,11 +13372,11 @@ async function handleChatStream({
|
|
|
13227
13372
|
const baseOptions = {
|
|
13228
13373
|
...defaultOptionsRest,
|
|
13229
13374
|
...restOptions,
|
|
13230
|
-
...
|
|
13375
|
+
...effectiveRunId && { runId: effectiveRunId },
|
|
13231
13376
|
requestContext: requestContext || defaultOptions3?.requestContext,
|
|
13232
13377
|
...Object.keys(mergedProviderOptions).length > 0 && { providerOptions: mergedProviderOptions }
|
|
13233
13378
|
};
|
|
13234
|
-
const result =
|
|
13379
|
+
const result = effectiveResumeData ? structuredOutput ? await agentObj.resumeStream(effectiveResumeData, { ...baseOptions, structuredOutput }) : await agentObj.resumeStream(effectiveResumeData, baseOptions) : structuredOutput ? await agentObj.stream(messagesToSend, { ...baseOptions, structuredOutput }) : await agentObj.stream(messagesToSend, baseOptions);
|
|
13235
13380
|
if (version === "v6") {
|
|
13236
13381
|
return createUIMessageStream2({
|
|
13237
13382
|
originalMessages: messages,
|