@mastra/ai-sdk 0.0.0-monorepo-binary-20251013210052 → 0.0.0-netlify-no-bundle-20251127120354
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 +449 -3
- package/README.md +65 -1
- package/dist/__tests__/__fixtures__/network.stream.d.ts +2329 -0
- package/dist/__tests__/__fixtures__/network.stream.d.ts.map +1 -0
- package/dist/chat-route.d.ts +52 -2
- package/dist/chat-route.d.ts.map +1 -1
- package/dist/convert-messages.d.ts +10 -0
- package/dist/convert-messages.d.ts.map +1 -0
- package/dist/convert-streams.d.ts +82 -0
- package/dist/convert-streams.d.ts.map +1 -0
- package/dist/helpers.d.ts +3 -4
- package/dist/helpers.d.ts.map +1 -1
- package/dist/index.cjs +512 -117
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +512 -118
- package/dist/index.js.map +1 -1
- package/dist/network-route.d.ts +1 -1
- package/dist/network-route.d.ts.map +1 -1
- package/dist/to-ai-sdk-format.d.ts +15 -13
- package/dist/to-ai-sdk-format.d.ts.map +1 -1
- package/dist/transformers.d.ts +179 -27
- package/dist/transformers.d.ts.map +1 -1
- package/dist/ui.cjs +16 -0
- package/dist/ui.cjs.map +1 -0
- package/dist/ui.d.ts +2 -0
- package/dist/ui.d.ts.map +1 -0
- package/dist/ui.js +13 -0
- package/dist/ui.js.map +1 -0
- package/dist/utils.d.ts +11 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/workflow-route.d.ts +4 -2
- package/dist/workflow-route.d.ts.map +1 -1
- package/package.json +22 -7
package/dist/index.js
CHANGED
|
@@ -3,6 +3,58 @@ import { createUIMessageStream, createUIMessageStreamResponse } from 'ai';
|
|
|
3
3
|
import { DefaultGeneratedFile, DefaultGeneratedFileWithType } from '@mastra/core/stream';
|
|
4
4
|
|
|
5
5
|
// src/chat-route.ts
|
|
6
|
+
|
|
7
|
+
// src/utils.ts
|
|
8
|
+
var isDataChunkType = (chunk) => {
|
|
9
|
+
return chunk && typeof chunk === "object" && "type" in chunk && chunk.type?.startsWith("data-");
|
|
10
|
+
};
|
|
11
|
+
var isMastraTextStreamChunk = (chunk) => {
|
|
12
|
+
return chunk && typeof chunk === "object" && "type" in chunk && typeof chunk.type === "string" && [
|
|
13
|
+
"text-start",
|
|
14
|
+
"text-delta",
|
|
15
|
+
"text-end",
|
|
16
|
+
"reasoning-start",
|
|
17
|
+
"reasoning-delta",
|
|
18
|
+
"reasoning-end",
|
|
19
|
+
"file",
|
|
20
|
+
"source",
|
|
21
|
+
"tool-input-start",
|
|
22
|
+
"tool-input-delta",
|
|
23
|
+
"tool-call",
|
|
24
|
+
"tool-result",
|
|
25
|
+
"tool-error",
|
|
26
|
+
"error",
|
|
27
|
+
"start-step",
|
|
28
|
+
"finish-step",
|
|
29
|
+
"start",
|
|
30
|
+
"finish",
|
|
31
|
+
"abort",
|
|
32
|
+
"tool-input-end",
|
|
33
|
+
"raw"
|
|
34
|
+
].includes(chunk.type);
|
|
35
|
+
};
|
|
36
|
+
function safeParseErrorObject(obj) {
|
|
37
|
+
if (typeof obj !== "object" || obj === null) {
|
|
38
|
+
return String(obj);
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
const stringified = JSON.stringify(obj);
|
|
42
|
+
if (stringified === "{}") {
|
|
43
|
+
return String(obj);
|
|
44
|
+
}
|
|
45
|
+
return stringified;
|
|
46
|
+
} catch {
|
|
47
|
+
return String(obj);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
var isAgentExecutionDataChunkType = (chunk) => {
|
|
51
|
+
return chunk && typeof chunk === "object" && "type" in chunk && chunk.type?.startsWith("agent-execution-event-") && "payload" in chunk && typeof chunk.payload === "object" && "type" in chunk.payload && chunk.payload.type?.startsWith("data-");
|
|
52
|
+
};
|
|
53
|
+
var isWorkflowExecutionDataChunkType = (chunk) => {
|
|
54
|
+
return chunk && typeof chunk === "object" && "type" in chunk && chunk.type?.startsWith("workflow-execution-event-") && "payload" in chunk && typeof chunk.payload === "object" && "type" in chunk.payload && chunk.payload.type?.startsWith("data-");
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// src/helpers.ts
|
|
6
58
|
function convertMastraChunkToAISDKv5({
|
|
7
59
|
chunk,
|
|
8
60
|
mode = "stream"
|
|
@@ -111,6 +163,28 @@ function convertMastraChunkToAISDKv5({
|
|
|
111
163
|
toolName: chunk.payload.toolName,
|
|
112
164
|
input: chunk.payload.args
|
|
113
165
|
};
|
|
166
|
+
case "tool-call-approval":
|
|
167
|
+
return {
|
|
168
|
+
type: "data-tool-call-approval",
|
|
169
|
+
id: chunk.payload.toolCallId,
|
|
170
|
+
data: {
|
|
171
|
+
runId: chunk.runId,
|
|
172
|
+
toolCallId: chunk.payload.toolCallId,
|
|
173
|
+
toolName: chunk.payload.toolName,
|
|
174
|
+
args: chunk.payload.args
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
case "tool-call-suspended":
|
|
178
|
+
return {
|
|
179
|
+
type: "data-tool-call-suspended",
|
|
180
|
+
id: chunk.payload.toolCallId,
|
|
181
|
+
data: {
|
|
182
|
+
runId: chunk.runId,
|
|
183
|
+
toolCallId: chunk.payload.toolCallId,
|
|
184
|
+
toolName: chunk.payload.toolName,
|
|
185
|
+
suspendPayload: chunk.payload.suspendPayload
|
|
186
|
+
}
|
|
187
|
+
};
|
|
114
188
|
case "tool-call-input-streaming-start":
|
|
115
189
|
return {
|
|
116
190
|
type: "tool-input-start",
|
|
@@ -201,6 +275,13 @@ function convertMastraChunkToAISDKv5({
|
|
|
201
275
|
type: "object",
|
|
202
276
|
object: chunk.object
|
|
203
277
|
};
|
|
278
|
+
case "tripwire":
|
|
279
|
+
return {
|
|
280
|
+
type: "data-tripwire",
|
|
281
|
+
data: {
|
|
282
|
+
tripwireReason: chunk.payload.tripwireReason
|
|
283
|
+
}
|
|
284
|
+
};
|
|
204
285
|
default:
|
|
205
286
|
if (chunk.type && "payload" in chunk && chunk.payload) {
|
|
206
287
|
return {
|
|
@@ -208,6 +289,9 @@ function convertMastraChunkToAISDKv5({
|
|
|
208
289
|
...chunk.payload || {}
|
|
209
290
|
};
|
|
210
291
|
}
|
|
292
|
+
if ("type" in chunk && chunk.type?.startsWith("data-")) {
|
|
293
|
+
return chunk;
|
|
294
|
+
}
|
|
211
295
|
return;
|
|
212
296
|
}
|
|
213
297
|
}
|
|
@@ -221,7 +305,7 @@ function convertFullStreamChunkToUIMessageStream({
|
|
|
221
305
|
sendFinish,
|
|
222
306
|
responseMessageId
|
|
223
307
|
}) {
|
|
224
|
-
const partType = part
|
|
308
|
+
const partType = part?.type;
|
|
225
309
|
switch (partType) {
|
|
226
310
|
case "text-start": {
|
|
227
311
|
return {
|
|
@@ -253,6 +337,14 @@ function convertFullStreamChunkToUIMessageStream({
|
|
|
253
337
|
};
|
|
254
338
|
}
|
|
255
339
|
case "reasoning-delta": {
|
|
340
|
+
if (sendReasoning) {
|
|
341
|
+
return {
|
|
342
|
+
type: "reasoning-delta",
|
|
343
|
+
id: part.id,
|
|
344
|
+
delta: part.text,
|
|
345
|
+
...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {}
|
|
346
|
+
};
|
|
347
|
+
}
|
|
256
348
|
return;
|
|
257
349
|
}
|
|
258
350
|
case "reasoning-end": {
|
|
@@ -270,6 +362,25 @@ function convertFullStreamChunkToUIMessageStream({
|
|
|
270
362
|
};
|
|
271
363
|
}
|
|
272
364
|
case "source": {
|
|
365
|
+
if (sendSources && part.sourceType === "url") {
|
|
366
|
+
return {
|
|
367
|
+
type: "source-url",
|
|
368
|
+
sourceId: part.id,
|
|
369
|
+
url: part.url,
|
|
370
|
+
title: part.title,
|
|
371
|
+
...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {}
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
if (sendSources && part.sourceType === "document") {
|
|
375
|
+
return {
|
|
376
|
+
type: "source-document",
|
|
377
|
+
sourceId: part.id,
|
|
378
|
+
mediaType: part.mediaType,
|
|
379
|
+
title: part.title,
|
|
380
|
+
filename: part.filename,
|
|
381
|
+
...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {}
|
|
382
|
+
};
|
|
383
|
+
}
|
|
273
384
|
return;
|
|
274
385
|
}
|
|
275
386
|
case "tool-input-start": {
|
|
@@ -327,6 +438,14 @@ function convertFullStreamChunkToUIMessageStream({
|
|
|
327
438
|
toolCallId: part.toolCallId,
|
|
328
439
|
payload: part.output
|
|
329
440
|
};
|
|
441
|
+
} else if (isDataChunkType(part.output)) {
|
|
442
|
+
if (!("data" in part.output)) {
|
|
443
|
+
throw new Error(
|
|
444
|
+
`UI Messages require a data property when using data- prefixed chunks
|
|
445
|
+
${JSON.stringify(part)}`
|
|
446
|
+
);
|
|
447
|
+
}
|
|
448
|
+
return part.output;
|
|
330
449
|
}
|
|
331
450
|
return;
|
|
332
451
|
}
|
|
@@ -352,21 +471,23 @@ function convertFullStreamChunkToUIMessageStream({
|
|
|
352
471
|
return { type: "finish-step" };
|
|
353
472
|
}
|
|
354
473
|
case "start": {
|
|
355
|
-
{
|
|
474
|
+
if (sendStart) {
|
|
356
475
|
return {
|
|
357
476
|
type: "start",
|
|
358
477
|
...messageMetadataValue != null ? { messageMetadata: messageMetadataValue } : {},
|
|
359
478
|
...responseMessageId != null ? { messageId: responseMessageId } : {}
|
|
360
479
|
};
|
|
361
480
|
}
|
|
481
|
+
return;
|
|
362
482
|
}
|
|
363
483
|
case "finish": {
|
|
364
|
-
{
|
|
484
|
+
if (sendFinish) {
|
|
365
485
|
return {
|
|
366
486
|
type: "finish",
|
|
367
487
|
...messageMetadataValue != null ? { messageMetadata: messageMetadataValue } : {}
|
|
368
488
|
};
|
|
369
489
|
}
|
|
490
|
+
return;
|
|
370
491
|
}
|
|
371
492
|
case "abort": {
|
|
372
493
|
return part;
|
|
@@ -378,14 +499,25 @@ function convertFullStreamChunkToUIMessageStream({
|
|
|
378
499
|
return;
|
|
379
500
|
}
|
|
380
501
|
default: {
|
|
381
|
-
|
|
382
|
-
|
|
502
|
+
if (isDataChunkType(part)) {
|
|
503
|
+
if (!("data" in part)) {
|
|
504
|
+
throw new Error(
|
|
505
|
+
`UI Messages require a data property when using data- prefixed chunks
|
|
506
|
+
${JSON.stringify(part)}`
|
|
507
|
+
);
|
|
508
|
+
}
|
|
509
|
+
return part;
|
|
510
|
+
}
|
|
511
|
+
return;
|
|
383
512
|
}
|
|
384
513
|
}
|
|
385
514
|
}
|
|
386
515
|
|
|
387
516
|
// src/transformers.ts
|
|
388
|
-
|
|
517
|
+
var PRIMITIVE_CACHE_SYMBOL = Symbol("primitive-cache");
|
|
518
|
+
function WorkflowStreamToAISDKTransformer({
|
|
519
|
+
includeTextStreamParts
|
|
520
|
+
} = {}) {
|
|
389
521
|
const bufferedWorkflows = /* @__PURE__ */ new Map();
|
|
390
522
|
return new TransformStream({
|
|
391
523
|
start(controller) {
|
|
@@ -399,7 +531,7 @@ function WorkflowStreamToAISDKTransformer() {
|
|
|
399
531
|
});
|
|
400
532
|
},
|
|
401
533
|
transform(chunk, controller) {
|
|
402
|
-
const transformed = transformWorkflow(chunk, bufferedWorkflows);
|
|
534
|
+
const transformed = transformWorkflow(chunk, bufferedWorkflows, false, includeTextStreamParts);
|
|
403
535
|
if (transformed) controller.enqueue(transformed);
|
|
404
536
|
}
|
|
405
537
|
});
|
|
@@ -423,20 +555,37 @@ function AgentNetworkToAISDKTransformer() {
|
|
|
423
555
|
}
|
|
424
556
|
});
|
|
425
557
|
}
|
|
426
|
-
function AgentStreamToAISDKTransformer(
|
|
558
|
+
function AgentStreamToAISDKTransformer({
|
|
559
|
+
lastMessageId,
|
|
560
|
+
sendStart,
|
|
561
|
+
sendFinish,
|
|
562
|
+
sendReasoning,
|
|
563
|
+
sendSources,
|
|
564
|
+
messageMetadata,
|
|
565
|
+
onError
|
|
566
|
+
}) {
|
|
427
567
|
let bufferedSteps = /* @__PURE__ */ new Map();
|
|
568
|
+
let tripwireOccurred = false;
|
|
569
|
+
let finishEventSent = false;
|
|
428
570
|
return new TransformStream({
|
|
429
571
|
transform(chunk, controller) {
|
|
572
|
+
if (chunk.type === "tripwire") {
|
|
573
|
+
tripwireOccurred = true;
|
|
574
|
+
}
|
|
575
|
+
if (chunk.type === "finish") {
|
|
576
|
+
finishEventSent = true;
|
|
577
|
+
}
|
|
430
578
|
const part = convertMastraChunkToAISDKv5({ chunk, mode: "stream" });
|
|
431
579
|
const transformedChunk = convertFullStreamChunkToUIMessageStream({
|
|
432
580
|
part,
|
|
433
|
-
sendReasoning
|
|
434
|
-
sendSources
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
581
|
+
sendReasoning,
|
|
582
|
+
sendSources,
|
|
583
|
+
messageMetadataValue: messageMetadata?.({ part }),
|
|
584
|
+
sendStart,
|
|
585
|
+
sendFinish,
|
|
586
|
+
responseMessageId: lastMessageId,
|
|
587
|
+
onError(error) {
|
|
588
|
+
return onError ? onError(error) : safeParseErrorObject(error);
|
|
440
589
|
}
|
|
441
590
|
});
|
|
442
591
|
if (transformedChunk) {
|
|
@@ -456,6 +605,14 @@ function AgentStreamToAISDKTransformer() {
|
|
|
456
605
|
controller.enqueue(transformedChunk);
|
|
457
606
|
}
|
|
458
607
|
}
|
|
608
|
+
},
|
|
609
|
+
flush(controller) {
|
|
610
|
+
if (tripwireOccurred && !finishEventSent && sendFinish) {
|
|
611
|
+
controller.enqueue({
|
|
612
|
+
type: "finish",
|
|
613
|
+
finishReason: "other"
|
|
614
|
+
});
|
|
615
|
+
}
|
|
459
616
|
}
|
|
460
617
|
});
|
|
461
618
|
}
|
|
@@ -595,7 +752,7 @@ function transformAgent(payload, bufferedSteps) {
|
|
|
595
752
|
}
|
|
596
753
|
return null;
|
|
597
754
|
}
|
|
598
|
-
function transformWorkflow(payload, bufferedWorkflows, isNested) {
|
|
755
|
+
function transformWorkflow(payload, bufferedWorkflows, isNested, includeTextStreamParts) {
|
|
599
756
|
switch (payload.type) {
|
|
600
757
|
case "workflow-start":
|
|
601
758
|
bufferedWorkflows.set(payload.runId, {
|
|
@@ -618,7 +775,9 @@ function transformWorkflow(payload, bufferedWorkflows, isNested) {
|
|
|
618
775
|
name: payload.payload.id,
|
|
619
776
|
status: payload.payload.status,
|
|
620
777
|
input: payload.payload.payload ?? null,
|
|
621
|
-
output: null
|
|
778
|
+
output: null,
|
|
779
|
+
suspendPayload: null,
|
|
780
|
+
resumePayload: null
|
|
622
781
|
};
|
|
623
782
|
bufferedWorkflows.set(payload.runId, current);
|
|
624
783
|
return {
|
|
@@ -651,6 +810,27 @@ function transformWorkflow(payload, bufferedWorkflows, isNested) {
|
|
|
651
810
|
}
|
|
652
811
|
};
|
|
653
812
|
}
|
|
813
|
+
case "workflow-step-suspended": {
|
|
814
|
+
const current = bufferedWorkflows.get(payload.runId);
|
|
815
|
+
if (!current) return null;
|
|
816
|
+
current.steps[payload.payload.id] = {
|
|
817
|
+
...current.steps[payload.payload.id],
|
|
818
|
+
status: payload.payload.status,
|
|
819
|
+
suspendPayload: payload.payload.suspendPayload ?? null,
|
|
820
|
+
resumePayload: payload.payload.resumePayload ?? null,
|
|
821
|
+
output: null
|
|
822
|
+
};
|
|
823
|
+
return {
|
|
824
|
+
type: isNested ? "data-tool-workflow" : "data-workflow",
|
|
825
|
+
id: payload.runId,
|
|
826
|
+
data: {
|
|
827
|
+
name: current.name,
|
|
828
|
+
status: "suspended",
|
|
829
|
+
steps: current.steps,
|
|
830
|
+
output: null
|
|
831
|
+
}
|
|
832
|
+
};
|
|
833
|
+
}
|
|
654
834
|
case "workflow-finish": {
|
|
655
835
|
const current = bufferedWorkflows.get(payload.runId);
|
|
656
836
|
if (!current) return null;
|
|
@@ -665,175 +845,275 @@ function transformWorkflow(payload, bufferedWorkflows, isNested) {
|
|
|
665
845
|
}
|
|
666
846
|
};
|
|
667
847
|
}
|
|
668
|
-
|
|
848
|
+
case "workflow-step-output": {
|
|
849
|
+
const output = payload.payload.output;
|
|
850
|
+
if (includeTextStreamParts && output && isMastraTextStreamChunk(output)) {
|
|
851
|
+
const part = convertMastraChunkToAISDKv5({ chunk: output, mode: "stream" });
|
|
852
|
+
const transformedChunk = convertFullStreamChunkToUIMessageStream({
|
|
853
|
+
part,
|
|
854
|
+
onError(error) {
|
|
855
|
+
return safeParseErrorObject(error);
|
|
856
|
+
}
|
|
857
|
+
});
|
|
858
|
+
return transformedChunk;
|
|
859
|
+
}
|
|
860
|
+
if (output && isDataChunkType(output)) {
|
|
861
|
+
if (!("data" in output)) {
|
|
862
|
+
throw new Error(
|
|
863
|
+
`UI Messages require a data property when using data- prefixed chunks
|
|
864
|
+
${JSON.stringify(output)}`
|
|
865
|
+
);
|
|
866
|
+
}
|
|
867
|
+
return output;
|
|
868
|
+
}
|
|
669
869
|
return null;
|
|
870
|
+
}
|
|
871
|
+
default: {
|
|
872
|
+
if (isDataChunkType(payload)) {
|
|
873
|
+
if (!("data" in payload)) {
|
|
874
|
+
throw new Error(
|
|
875
|
+
`UI Messages require a data property when using data- prefixed chunks
|
|
876
|
+
${JSON.stringify(payload)}`
|
|
877
|
+
);
|
|
878
|
+
}
|
|
879
|
+
return payload;
|
|
880
|
+
}
|
|
881
|
+
return null;
|
|
882
|
+
}
|
|
670
883
|
}
|
|
671
884
|
}
|
|
672
885
|
function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
673
886
|
switch (payload.type) {
|
|
674
887
|
case "routing-agent-start": {
|
|
675
|
-
if (!bufferedNetworks.has(payload.
|
|
676
|
-
bufferedNetworks.set(payload.
|
|
677
|
-
name: payload.payload.
|
|
678
|
-
steps: []
|
|
888
|
+
if (!bufferedNetworks.has(payload.runId)) {
|
|
889
|
+
bufferedNetworks.set(payload.runId, {
|
|
890
|
+
name: payload.payload.networkId,
|
|
891
|
+
steps: [],
|
|
892
|
+
usage: null,
|
|
893
|
+
output: null
|
|
679
894
|
});
|
|
680
895
|
}
|
|
896
|
+
const current = bufferedNetworks.get(payload.runId);
|
|
897
|
+
current.steps.push({
|
|
898
|
+
id: payload.payload.runId,
|
|
899
|
+
name: payload.payload.agentId,
|
|
900
|
+
status: "running",
|
|
901
|
+
iteration: payload.payload.inputData.iteration,
|
|
902
|
+
input: {
|
|
903
|
+
task: payload.payload.inputData.task,
|
|
904
|
+
threadId: payload.payload.inputData.threadId,
|
|
905
|
+
threadResourceId: payload.payload.inputData.threadResourceId
|
|
906
|
+
},
|
|
907
|
+
output: "",
|
|
908
|
+
task: null,
|
|
909
|
+
suspendPayload: null,
|
|
910
|
+
resumePayload: null,
|
|
911
|
+
[PRIMITIVE_CACHE_SYMBOL]: /* @__PURE__ */ new Map()
|
|
912
|
+
});
|
|
681
913
|
return {
|
|
682
914
|
type: isNested ? "data-tool-network" : "data-network",
|
|
683
|
-
id: payload.
|
|
915
|
+
id: payload.runId,
|
|
684
916
|
data: {
|
|
685
|
-
name: bufferedNetworks.get(payload.
|
|
917
|
+
name: bufferedNetworks.get(payload.runId).name,
|
|
686
918
|
status: "running",
|
|
687
|
-
|
|
919
|
+
usage: null,
|
|
920
|
+
steps: bufferedNetworks.get(payload.runId).steps,
|
|
688
921
|
output: null
|
|
689
922
|
}
|
|
690
923
|
};
|
|
691
924
|
}
|
|
925
|
+
case "routing-agent-text-start": {
|
|
926
|
+
const current = bufferedNetworks.get(payload.runId);
|
|
927
|
+
if (!current) return null;
|
|
928
|
+
return {
|
|
929
|
+
type: "text-start",
|
|
930
|
+
id: payload.runId
|
|
931
|
+
};
|
|
932
|
+
}
|
|
933
|
+
case "routing-agent-text-delta": {
|
|
934
|
+
const current = bufferedNetworks.get(payload.runId);
|
|
935
|
+
if (!current) return null;
|
|
936
|
+
return {
|
|
937
|
+
type: "text-delta",
|
|
938
|
+
id: payload.runId,
|
|
939
|
+
delta: payload.payload.text
|
|
940
|
+
};
|
|
941
|
+
}
|
|
692
942
|
case "agent-execution-start": {
|
|
693
|
-
const current = bufferedNetworks.get(payload.
|
|
943
|
+
const current = bufferedNetworks.get(payload.runId);
|
|
944
|
+
if (!current) return null;
|
|
694
945
|
current.steps.push({
|
|
946
|
+
id: payload.payload.runId,
|
|
695
947
|
name: payload.payload.agentId,
|
|
696
948
|
status: "running",
|
|
697
|
-
|
|
698
|
-
|
|
949
|
+
iteration: payload.payload.args?.iteration ?? 0,
|
|
950
|
+
input: { prompt: payload.payload.args?.prompt ?? "" },
|
|
951
|
+
output: null,
|
|
952
|
+
task: null,
|
|
953
|
+
suspendPayload: null,
|
|
954
|
+
resumePayload: null,
|
|
955
|
+
[PRIMITIVE_CACHE_SYMBOL]: /* @__PURE__ */ new Map()
|
|
699
956
|
});
|
|
700
|
-
bufferedNetworks.set(payload.
|
|
957
|
+
bufferedNetworks.set(payload.runId, current);
|
|
701
958
|
return {
|
|
702
959
|
type: isNested ? "data-tool-network" : "data-network",
|
|
703
|
-
id: payload.
|
|
960
|
+
id: payload.runId,
|
|
704
961
|
data: {
|
|
705
|
-
|
|
706
|
-
status: "running"
|
|
707
|
-
steps: current.steps,
|
|
708
|
-
output: null
|
|
962
|
+
...current,
|
|
963
|
+
status: "running"
|
|
709
964
|
}
|
|
710
965
|
};
|
|
711
966
|
}
|
|
712
967
|
case "workflow-execution-start": {
|
|
713
|
-
const current = bufferedNetworks.get(payload.
|
|
968
|
+
const current = bufferedNetworks.get(payload.runId);
|
|
969
|
+
if (!current) return null;
|
|
714
970
|
current.steps.push({
|
|
715
|
-
|
|
971
|
+
id: payload.payload.runId,
|
|
972
|
+
name: payload.payload.workflowId,
|
|
716
973
|
status: "running",
|
|
717
|
-
|
|
718
|
-
|
|
974
|
+
iteration: payload.payload.args?.iteration ?? 0,
|
|
975
|
+
input: { prompt: payload.payload.args?.prompt ?? "" },
|
|
976
|
+
output: null,
|
|
977
|
+
task: null,
|
|
978
|
+
suspendPayload: null,
|
|
979
|
+
resumePayload: null,
|
|
980
|
+
[PRIMITIVE_CACHE_SYMBOL]: /* @__PURE__ */ new Map()
|
|
719
981
|
});
|
|
720
|
-
bufferedNetworks.set(payload.
|
|
982
|
+
bufferedNetworks.set(payload.runId, current);
|
|
721
983
|
return {
|
|
722
984
|
type: isNested ? "data-tool-network" : "data-network",
|
|
723
|
-
id: payload.
|
|
985
|
+
id: payload.runId,
|
|
724
986
|
data: {
|
|
725
|
-
|
|
726
|
-
status: "running"
|
|
727
|
-
steps: current.steps,
|
|
728
|
-
output: null
|
|
987
|
+
...current,
|
|
988
|
+
status: "running"
|
|
729
989
|
}
|
|
730
990
|
};
|
|
731
991
|
}
|
|
732
992
|
case "tool-execution-start": {
|
|
733
|
-
const current = bufferedNetworks.get(payload.
|
|
993
|
+
const current = bufferedNetworks.get(payload.runId);
|
|
994
|
+
if (!current) return null;
|
|
734
995
|
current.steps.push({
|
|
996
|
+
id: payload.payload.args.toolCallId,
|
|
735
997
|
name: payload.payload.args?.toolName,
|
|
736
998
|
status: "running",
|
|
999
|
+
iteration: payload.payload.args?.iteration ? Number(payload.payload.args.iteration) : 0,
|
|
1000
|
+
task: {
|
|
1001
|
+
id: payload.payload.args?.toolName
|
|
1002
|
+
},
|
|
737
1003
|
input: payload.payload.args?.args || null,
|
|
738
|
-
output: null
|
|
1004
|
+
output: null,
|
|
1005
|
+
suspendPayload: null,
|
|
1006
|
+
resumePayload: null,
|
|
1007
|
+
[PRIMITIVE_CACHE_SYMBOL]: /* @__PURE__ */ new Map()
|
|
739
1008
|
});
|
|
740
|
-
bufferedNetworks.set(payload.
|
|
1009
|
+
bufferedNetworks.set(payload.runId, current);
|
|
741
1010
|
return {
|
|
742
1011
|
type: isNested ? "data-tool-network" : "data-network",
|
|
743
|
-
id: payload.
|
|
1012
|
+
id: payload.runId,
|
|
744
1013
|
data: {
|
|
745
|
-
|
|
746
|
-
status: "running"
|
|
747
|
-
steps: current.steps,
|
|
748
|
-
output: null
|
|
1014
|
+
...current,
|
|
1015
|
+
status: "running"
|
|
749
1016
|
}
|
|
750
1017
|
};
|
|
751
1018
|
}
|
|
752
1019
|
case "agent-execution-end": {
|
|
753
1020
|
const current = bufferedNetworks.get(payload.runId);
|
|
754
1021
|
if (!current) return null;
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
1022
|
+
const stepId = payload.payload.runId;
|
|
1023
|
+
const step = current.steps.find((step2) => step2.id === stepId);
|
|
1024
|
+
if (!step) {
|
|
1025
|
+
return null;
|
|
1026
|
+
}
|
|
1027
|
+
step.status = "success";
|
|
1028
|
+
step.output = payload.payload.result;
|
|
761
1029
|
return {
|
|
762
1030
|
type: isNested ? "data-tool-network" : "data-network",
|
|
763
1031
|
id: payload.runId,
|
|
764
1032
|
data: {
|
|
765
|
-
|
|
1033
|
+
...current,
|
|
1034
|
+
usage: payload.payload?.usage ?? current.usage,
|
|
766
1035
|
status: "running",
|
|
767
|
-
|
|
768
|
-
output: payload.payload.result ?? null
|
|
1036
|
+
output: payload.payload.result ?? current.output
|
|
769
1037
|
}
|
|
770
1038
|
};
|
|
771
1039
|
}
|
|
772
1040
|
case "tool-execution-end": {
|
|
773
1041
|
const current = bufferedNetworks.get(payload.runId);
|
|
774
1042
|
if (!current) return null;
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
1043
|
+
const stepId = payload.payload.toolCallId;
|
|
1044
|
+
const step = current.steps.find((step2) => step2.id === stepId);
|
|
1045
|
+
if (!step) {
|
|
1046
|
+
return null;
|
|
1047
|
+
}
|
|
1048
|
+
step.status = "success";
|
|
1049
|
+
step.output = payload.payload.result;
|
|
781
1050
|
return {
|
|
782
1051
|
type: isNested ? "data-tool-network" : "data-network",
|
|
783
1052
|
id: payload.runId,
|
|
784
1053
|
data: {
|
|
785
|
-
|
|
1054
|
+
...current,
|
|
786
1055
|
status: "running",
|
|
787
|
-
|
|
788
|
-
output: payload.payload.result ?? null
|
|
1056
|
+
output: payload.payload.result ?? current.output
|
|
789
1057
|
}
|
|
790
1058
|
};
|
|
791
1059
|
}
|
|
792
1060
|
case "workflow-execution-end": {
|
|
793
1061
|
const current = bufferedNetworks.get(payload.runId);
|
|
794
1062
|
if (!current) return null;
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
1063
|
+
const stepId = payload.payload.runId;
|
|
1064
|
+
const step = current.steps.find((step2) => step2.id === stepId);
|
|
1065
|
+
if (!step) {
|
|
1066
|
+
return null;
|
|
1067
|
+
}
|
|
1068
|
+
step.status = "success";
|
|
1069
|
+
step.output = payload.payload.result;
|
|
801
1070
|
return {
|
|
802
1071
|
type: isNested ? "data-tool-network" : "data-network",
|
|
803
1072
|
id: payload.runId,
|
|
804
1073
|
data: {
|
|
805
|
-
|
|
1074
|
+
...current,
|
|
1075
|
+
usage: payload.payload?.usage ?? current.usage,
|
|
806
1076
|
status: "running",
|
|
807
|
-
|
|
808
|
-
output: payload.payload.result ?? null
|
|
1077
|
+
output: payload.payload.result ?? current.output
|
|
809
1078
|
}
|
|
810
1079
|
};
|
|
811
1080
|
}
|
|
812
1081
|
case "routing-agent-end": {
|
|
813
|
-
const current = bufferedNetworks.get(payload.
|
|
1082
|
+
const current = bufferedNetworks.get(payload.runId);
|
|
814
1083
|
if (!current) return null;
|
|
1084
|
+
const stepId = payload.payload.runId;
|
|
1085
|
+
const step = current.steps.find((step2) => step2.id === stepId);
|
|
1086
|
+
if (!step) {
|
|
1087
|
+
return null;
|
|
1088
|
+
}
|
|
1089
|
+
step.status = "success";
|
|
1090
|
+
step.task = {
|
|
1091
|
+
id: payload.payload.primitiveId,
|
|
1092
|
+
type: payload.payload.primitiveType,
|
|
1093
|
+
name: payload.payload.task,
|
|
1094
|
+
reason: payload.payload.selectionReason
|
|
1095
|
+
};
|
|
1096
|
+
step.output = payload.payload.result;
|
|
815
1097
|
return {
|
|
816
1098
|
type: isNested ? "data-tool-network" : "data-network",
|
|
817
|
-
id: payload.
|
|
1099
|
+
id: payload.runId,
|
|
818
1100
|
data: {
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
output: payload.payload?.result ?? null
|
|
1101
|
+
...current,
|
|
1102
|
+
usage: payload.payload?.usage ?? current.usage,
|
|
1103
|
+
output: payload.payload?.result ?? current.output
|
|
823
1104
|
}
|
|
824
1105
|
};
|
|
825
1106
|
}
|
|
826
1107
|
case "network-execution-event-step-finish": {
|
|
827
|
-
const current = bufferedNetworks.get(payload.
|
|
1108
|
+
const current = bufferedNetworks.get(payload.runId);
|
|
828
1109
|
if (!current) return null;
|
|
829
1110
|
return {
|
|
830
1111
|
type: isNested ? "data-tool-network" : "data-network",
|
|
831
|
-
id: payload.
|
|
1112
|
+
id: payload.runId,
|
|
832
1113
|
data: {
|
|
833
|
-
|
|
1114
|
+
...current,
|
|
834
1115
|
status: "finished",
|
|
835
|
-
|
|
836
|
-
output: payload.payload?.result ?? null
|
|
1116
|
+
output: payload.payload?.result ?? current.output
|
|
837
1117
|
}
|
|
838
1118
|
};
|
|
839
1119
|
}
|
|
@@ -844,36 +1124,121 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
844
1124
|
type: isNested ? "data-tool-network" : "data-network",
|
|
845
1125
|
id: payload.runId,
|
|
846
1126
|
data: {
|
|
847
|
-
|
|
1127
|
+
...current,
|
|
1128
|
+
usage: payload.payload?.usage ?? current.usage,
|
|
848
1129
|
status: "finished",
|
|
849
|
-
|
|
850
|
-
output: payload.payload?.result ?? null
|
|
1130
|
+
output: payload.payload?.result ?? current.output
|
|
851
1131
|
}
|
|
852
1132
|
};
|
|
853
1133
|
}
|
|
854
|
-
default:
|
|
1134
|
+
default: {
|
|
1135
|
+
if (payload.type.startsWith("agent-execution-event-")) {
|
|
1136
|
+
const stepId = payload.payload.runId;
|
|
1137
|
+
const current = bufferedNetworks.get(payload.runId);
|
|
1138
|
+
if (!current) return null;
|
|
1139
|
+
const step = current.steps.find((step2) => step2.id === stepId);
|
|
1140
|
+
if (!step) {
|
|
1141
|
+
return null;
|
|
1142
|
+
}
|
|
1143
|
+
step[PRIMITIVE_CACHE_SYMBOL] = step[PRIMITIVE_CACHE_SYMBOL] || /* @__PURE__ */ new Map();
|
|
1144
|
+
const result = transformAgent(payload.payload, step[PRIMITIVE_CACHE_SYMBOL]);
|
|
1145
|
+
if (result) {
|
|
1146
|
+
const { request, response, ...data } = result.data;
|
|
1147
|
+
step.task = data;
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
if (payload.type.startsWith("workflow-execution-event-")) {
|
|
1151
|
+
const stepId = payload.payload.runId;
|
|
1152
|
+
const current = bufferedNetworks.get(payload.runId);
|
|
1153
|
+
if (!current) return null;
|
|
1154
|
+
const step = current.steps.find((step2) => step2.id === stepId);
|
|
1155
|
+
if (!step) {
|
|
1156
|
+
return null;
|
|
1157
|
+
}
|
|
1158
|
+
step[PRIMITIVE_CACHE_SYMBOL] = step[PRIMITIVE_CACHE_SYMBOL] || /* @__PURE__ */ new Map();
|
|
1159
|
+
const result = transformWorkflow(payload.payload, step[PRIMITIVE_CACHE_SYMBOL]);
|
|
1160
|
+
if (result && "data" in result) {
|
|
1161
|
+
const data = result.data;
|
|
1162
|
+
step.task = data;
|
|
1163
|
+
if (data.name && step.task) {
|
|
1164
|
+
step.task.id = data.name;
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
if (isDataChunkType(payload)) {
|
|
1169
|
+
if (!("data" in payload)) {
|
|
1170
|
+
throw new Error(
|
|
1171
|
+
`UI Messages require a data property when using data- prefixed chunks
|
|
1172
|
+
${JSON.stringify(payload)}`
|
|
1173
|
+
);
|
|
1174
|
+
}
|
|
1175
|
+
const { type, data } = payload;
|
|
1176
|
+
return { type, data };
|
|
1177
|
+
}
|
|
1178
|
+
if (isAgentExecutionDataChunkType(payload)) {
|
|
1179
|
+
if (!("data" in payload.payload)) {
|
|
1180
|
+
throw new Error(
|
|
1181
|
+
`UI Messages require a data property when using data- prefixed chunks
|
|
1182
|
+
${JSON.stringify(payload)}`
|
|
1183
|
+
);
|
|
1184
|
+
}
|
|
1185
|
+
const { type, data } = payload.payload;
|
|
1186
|
+
return { type, data };
|
|
1187
|
+
}
|
|
1188
|
+
if (isWorkflowExecutionDataChunkType(payload)) {
|
|
1189
|
+
if (!("data" in payload.payload)) {
|
|
1190
|
+
throw new Error(
|
|
1191
|
+
`UI Messages require a data property when using data- prefixed chunks
|
|
1192
|
+
${JSON.stringify(payload)}`
|
|
1193
|
+
);
|
|
1194
|
+
}
|
|
1195
|
+
const { type, data } = payload.payload;
|
|
1196
|
+
return { type, data };
|
|
1197
|
+
}
|
|
855
1198
|
return null;
|
|
1199
|
+
}
|
|
856
1200
|
}
|
|
857
1201
|
}
|
|
858
1202
|
|
|
859
|
-
// src/
|
|
860
|
-
function
|
|
1203
|
+
// src/convert-streams.ts
|
|
1204
|
+
function toAISdkV5Stream(stream, options = {
|
|
1205
|
+
from: "agent",
|
|
1206
|
+
sendStart: true,
|
|
1207
|
+
sendFinish: true
|
|
1208
|
+
}) {
|
|
861
1209
|
const from = options?.from;
|
|
862
1210
|
if (from === "workflow") {
|
|
863
|
-
|
|
1211
|
+
const includeTextStreamParts = options?.includeTextStreamParts ?? true;
|
|
1212
|
+
return stream.pipeThrough(
|
|
1213
|
+
WorkflowStreamToAISDKTransformer({ includeTextStreamParts })
|
|
1214
|
+
);
|
|
864
1215
|
}
|
|
865
1216
|
if (from === "network") {
|
|
866
1217
|
return stream.pipeThrough(AgentNetworkToAISDKTransformer());
|
|
867
1218
|
}
|
|
868
1219
|
const agentReadable = "fullStream" in stream ? stream.fullStream : stream;
|
|
869
|
-
return agentReadable.pipeThrough(
|
|
1220
|
+
return agentReadable.pipeThrough(
|
|
1221
|
+
AgentStreamToAISDKTransformer({
|
|
1222
|
+
lastMessageId: options?.lastMessageId,
|
|
1223
|
+
sendStart: options?.sendStart,
|
|
1224
|
+
sendFinish: options?.sendFinish,
|
|
1225
|
+
sendReasoning: options?.sendReasoning,
|
|
1226
|
+
sendSources: options?.sendSources,
|
|
1227
|
+
messageMetadata: options?.messageMetadata,
|
|
1228
|
+
onError: options?.onError
|
|
1229
|
+
})
|
|
1230
|
+
);
|
|
870
1231
|
}
|
|
871
1232
|
|
|
872
1233
|
// src/chat-route.ts
|
|
873
1234
|
function chatRoute({
|
|
874
1235
|
path = "/chat/:agentId",
|
|
875
1236
|
agent,
|
|
876
|
-
defaultOptions
|
|
1237
|
+
defaultOptions,
|
|
1238
|
+
sendStart = true,
|
|
1239
|
+
sendFinish = true,
|
|
1240
|
+
sendReasoning = false,
|
|
1241
|
+
sendSources = false
|
|
877
1242
|
}) {
|
|
878
1243
|
if (!agent && !path.includes("/:agentId")) {
|
|
879
1244
|
throw new Error("Path must include :agentId to route to the correct agent or pass the agent explicitly");
|
|
@@ -974,7 +1339,7 @@ function chatRoute({
|
|
|
974
1339
|
handler: async (c) => {
|
|
975
1340
|
const { messages, ...rest } = await c.req.json();
|
|
976
1341
|
const mastra = c.get("mastra");
|
|
977
|
-
const
|
|
1342
|
+
const requestContext = c.get("requestContext");
|
|
978
1343
|
let agentToUse = agent;
|
|
979
1344
|
if (!agent) {
|
|
980
1345
|
const agentId = c.req.param("agentId");
|
|
@@ -985,24 +1350,36 @@ function chatRoute({
|
|
|
985
1350
|
`Fixed agent ID was set together with an agentId path parameter. This can lead to unexpected behavior.`
|
|
986
1351
|
);
|
|
987
1352
|
}
|
|
988
|
-
if (
|
|
989
|
-
mastra.getLogger()?.warn(`"
|
|
1353
|
+
if (requestContext && defaultOptions?.requestContext) {
|
|
1354
|
+
mastra.getLogger()?.warn(`"requestContext" set in the route options will be overridden by the request's "requestContext".`);
|
|
990
1355
|
}
|
|
991
1356
|
if (!agentToUse) {
|
|
992
1357
|
throw new Error("Agent ID is required");
|
|
993
1358
|
}
|
|
994
|
-
const agentObj = mastra.
|
|
1359
|
+
const agentObj = mastra.getAgentById(agentToUse);
|
|
995
1360
|
if (!agentObj) {
|
|
996
1361
|
throw new Error(`Agent ${agentToUse} not found`);
|
|
997
1362
|
}
|
|
998
1363
|
const result = await agentObj.stream(messages, {
|
|
999
1364
|
...defaultOptions,
|
|
1000
1365
|
...rest,
|
|
1001
|
-
|
|
1366
|
+
requestContext: requestContext || defaultOptions?.requestContext
|
|
1002
1367
|
});
|
|
1368
|
+
let lastMessageId;
|
|
1369
|
+
if (messages.length > 0 && messages[messages.length - 1].role === "assistant") {
|
|
1370
|
+
lastMessageId = messages[messages.length - 1].id;
|
|
1371
|
+
}
|
|
1003
1372
|
const uiMessageStream = createUIMessageStream({
|
|
1373
|
+
originalMessages: messages,
|
|
1004
1374
|
execute: async ({ writer }) => {
|
|
1005
|
-
for await (const part of
|
|
1375
|
+
for await (const part of toAISdkV5Stream(result, {
|
|
1376
|
+
from: "agent",
|
|
1377
|
+
lastMessageId,
|
|
1378
|
+
sendStart,
|
|
1379
|
+
sendFinish,
|
|
1380
|
+
sendReasoning,
|
|
1381
|
+
sendSources
|
|
1382
|
+
})) {
|
|
1006
1383
|
writer.write(part);
|
|
1007
1384
|
}
|
|
1008
1385
|
}
|
|
@@ -1015,7 +1392,8 @@ function chatRoute({
|
|
|
1015
1392
|
}
|
|
1016
1393
|
function workflowRoute({
|
|
1017
1394
|
path = "/api/workflows/:workflowId/stream",
|
|
1018
|
-
workflow
|
|
1395
|
+
workflow,
|
|
1396
|
+
includeTextStreamParts = true
|
|
1019
1397
|
}) {
|
|
1020
1398
|
if (!workflow && !path.includes("/:workflowId")) {
|
|
1021
1399
|
throw new Error("Path must include :workflowId to route to the correct workflow or pass the workflow explicitly");
|
|
@@ -1042,9 +1420,13 @@ function workflowRoute({
|
|
|
1042
1420
|
schema: {
|
|
1043
1421
|
type: "object",
|
|
1044
1422
|
properties: {
|
|
1423
|
+
runId: { type: "string" },
|
|
1424
|
+
resourceId: { type: "string" },
|
|
1045
1425
|
inputData: { type: "object", additionalProperties: true },
|
|
1046
|
-
|
|
1047
|
-
|
|
1426
|
+
resumeData: { type: "object", additionalProperties: true },
|
|
1427
|
+
requestContext: { type: "object", additionalProperties: true },
|
|
1428
|
+
tracingOptions: { type: "object", additionalProperties: true },
|
|
1429
|
+
step: { type: "string" }
|
|
1048
1430
|
}
|
|
1049
1431
|
}
|
|
1050
1432
|
}
|
|
@@ -1062,8 +1444,9 @@ function workflowRoute({
|
|
|
1062
1444
|
}
|
|
1063
1445
|
},
|
|
1064
1446
|
handler: async (c) => {
|
|
1065
|
-
const { inputData, ...rest } = await c.req.json();
|
|
1447
|
+
const { runId, resourceId, inputData, resumeData, ...rest } = await c.req.json();
|
|
1066
1448
|
const mastra = c.get("mastra");
|
|
1449
|
+
const requestContext = c.get("requestContext");
|
|
1067
1450
|
let workflowToUse = workflow;
|
|
1068
1451
|
if (!workflow) {
|
|
1069
1452
|
const workflowId = c.req.param("workflowId");
|
|
@@ -1077,15 +1460,20 @@ function workflowRoute({
|
|
|
1077
1460
|
if (!workflowToUse) {
|
|
1078
1461
|
throw new Error("Workflow ID is required");
|
|
1079
1462
|
}
|
|
1080
|
-
const workflowObj = mastra.
|
|
1463
|
+
const workflowObj = mastra.getWorkflowById(workflowToUse);
|
|
1081
1464
|
if (!workflowObj) {
|
|
1082
1465
|
throw new Error(`Workflow ${workflowToUse} not found`);
|
|
1083
1466
|
}
|
|
1084
|
-
|
|
1085
|
-
|
|
1467
|
+
if (requestContext && rest.requestContext) {
|
|
1468
|
+
mastra.getLogger()?.warn(
|
|
1469
|
+
`"requestContext" from the request body will be ignored because "requestContext" is already set in the route options.`
|
|
1470
|
+
);
|
|
1471
|
+
}
|
|
1472
|
+
const run = await workflowObj.createRun({ runId, resourceId, ...rest });
|
|
1473
|
+
const stream = resumeData ? run.resumeStream({ resumeData, ...rest, requestContext: requestContext || rest.requestContext }) : run.stream({ inputData, ...rest, requestContext: requestContext || rest.requestContext });
|
|
1086
1474
|
const uiMessageStream = createUIMessageStream({
|
|
1087
1475
|
execute: async ({ writer }) => {
|
|
1088
|
-
for await (const part of
|
|
1476
|
+
for await (const part of toAISdkV5Stream(stream, { from: "workflow", includeTextStreamParts })) {
|
|
1089
1477
|
writer.write(part);
|
|
1090
1478
|
}
|
|
1091
1479
|
}
|
|
@@ -1125,13 +1513,12 @@ function networkRoute({
|
|
|
1125
1513
|
type: "object",
|
|
1126
1514
|
properties: {
|
|
1127
1515
|
messages: { type: "array", items: { type: "object" } },
|
|
1128
|
-
|
|
1516
|
+
requestContext: { type: "object", additionalProperties: true },
|
|
1129
1517
|
runId: { type: "string" },
|
|
1130
1518
|
maxSteps: { type: "number" },
|
|
1131
1519
|
threadId: { type: "string" },
|
|
1132
1520
|
resourceId: { type: "string" },
|
|
1133
1521
|
modelSettings: { type: "object", additionalProperties: true },
|
|
1134
|
-
telemetry: { type: "object", additionalProperties: true },
|
|
1135
1522
|
tools: { type: "array", items: { type: "object" } }
|
|
1136
1523
|
},
|
|
1137
1524
|
required: ["messages"]
|
|
@@ -1170,7 +1557,7 @@ function networkRoute({
|
|
|
1170
1557
|
if (!agentToUse) {
|
|
1171
1558
|
throw new Error("Agent ID is required");
|
|
1172
1559
|
}
|
|
1173
|
-
const agentObj = mastra.
|
|
1560
|
+
const agentObj = mastra.getAgentById(agentToUse);
|
|
1174
1561
|
if (!agentObj) {
|
|
1175
1562
|
throw new Error(`Agent ${agentToUse} not found`);
|
|
1176
1563
|
}
|
|
@@ -1180,7 +1567,7 @@ function networkRoute({
|
|
|
1180
1567
|
});
|
|
1181
1568
|
const uiMessageStream = createUIMessageStream({
|
|
1182
1569
|
execute: async ({ writer }) => {
|
|
1183
|
-
for await (const part of
|
|
1570
|
+
for await (const part of toAISdkV5Stream(result, { from: "network" })) {
|
|
1184
1571
|
writer.write(part);
|
|
1185
1572
|
}
|
|
1186
1573
|
}
|
|
@@ -1190,6 +1577,13 @@ function networkRoute({
|
|
|
1190
1577
|
});
|
|
1191
1578
|
}
|
|
1192
1579
|
|
|
1193
|
-
|
|
1580
|
+
// src/to-ai-sdk-format.ts
|
|
1581
|
+
function toAISdkFormat() {
|
|
1582
|
+
throw new Error(
|
|
1583
|
+
'toAISdkFormat() has been deprecated. Please use toAISdkStream() instead.\n\nMigration:\n import { toAISdkFormat } from "@mastra/ai-sdk";\n // Change to:\n import { toAISdkStream } from "@mastra/ai-sdk";\n\nThe function signature remains the same.'
|
|
1584
|
+
);
|
|
1585
|
+
}
|
|
1586
|
+
|
|
1587
|
+
export { chatRoute, networkRoute, toAISdkFormat, toAISdkV5Stream as toAISdkStream, workflowRoute };
|
|
1194
1588
|
//# sourceMappingURL=index.js.map
|
|
1195
1589
|
//# sourceMappingURL=index.js.map
|