@mastra/ai-sdk 0.0.0-dynamic-model-router-20251009231604 → 0.0.0-dynamic-model-router-20251010230835
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 +40 -3
- package/dist/chat-route.d.ts.map +1 -1
- package/dist/helpers.d.ts +11 -1
- package/dist/helpers.d.ts.map +1 -1
- package/dist/index.cjs +259 -70
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +259 -70
- package/dist/index.js.map +1 -1
- package/dist/to-ai-sdk-format.d.ts +2 -30
- package/dist/to-ai-sdk-format.d.ts.map +1 -1
- package/dist/transformers.d.ts +86 -0
- package/dist/transformers.d.ts.map +1 -0
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,11 +1,48 @@
|
|
|
1
1
|
# @mastra/ai-sdk
|
|
2
2
|
|
|
3
|
-
## 0.0.0-dynamic-model-router-
|
|
3
|
+
## 0.0.0-dynamic-model-router-20251010230835
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Update peer dependencies to match core package version bump (0.20.3) ([#8614](https://github.com/mastra-ai/mastra/pull/8614))
|
|
4
8
|
|
|
5
9
|
### Patch Changes
|
|
6
10
|
|
|
7
|
-
-
|
|
8
|
-
|
|
11
|
+
- pass runtimeContext to agent stream options in chatRoute ([#8641](https://github.com/mastra-ai/mastra/pull/8641))
|
|
12
|
+
|
|
13
|
+
- Update peer dependencies to match core package version bump (0.21.0) ([#8619](https://github.com/mastra-ai/mastra/pull/8619))
|
|
14
|
+
|
|
15
|
+
- Update peer dependencies to match core package version bump (0.21.0) ([#8557](https://github.com/mastra-ai/mastra/pull/8557))
|
|
16
|
+
|
|
17
|
+
- Update peer dependencies to match core package version bump (0.21.0) ([#8626](https://github.com/mastra-ai/mastra/pull/8626))
|
|
18
|
+
|
|
19
|
+
- Update peer dependencies to match core package version bump (0.21.0) ([#8686](https://github.com/mastra-ai/mastra/pull/8686))
|
|
20
|
+
|
|
21
|
+
- nested ai-sdk workflows and networks streaming support ([#8614](https://github.com/mastra-ai/mastra/pull/8614))
|
|
22
|
+
|
|
23
|
+
- Updated dependencies [[`1ed9670`](https://github.com/mastra-ai/mastra/commit/1ed9670d3ca50cb60dc2e517738c5eef3968ed27), [`b5a66b7`](https://github.com/mastra-ai/mastra/commit/b5a66b748a14fc8b3f63b04642ddb9621fbcc9e0), [`37a2314`](https://github.com/mastra-ai/mastra/commit/37a23148e0e5a3b40d4f9f098b194671a8a49faf), [`7b1ef57`](https://github.com/mastra-ai/mastra/commit/7b1ef57fc071c2aa2a2e32905b18cd88719c5a39), [`ee68e82`](https://github.com/mastra-ai/mastra/commit/ee68e8289ea4408d29849e899bc6e78b3bd4e843), [`228228b`](https://github.com/mastra-ai/mastra/commit/228228b0b1de9291cb8887587f5cea1a8757ebad), [`ea33930`](https://github.com/mastra-ai/mastra/commit/ea339301e82d6318257720d811b043014ee44064), [`b5a66b7`](https://github.com/mastra-ai/mastra/commit/b5a66b748a14fc8b3f63b04642ddb9621fbcc9e0), [`135d6f2`](https://github.com/mastra-ai/mastra/commit/135d6f22a326ed1dffff858700669dff09d2c9eb), [`59d036d`](https://github.com/mastra-ai/mastra/commit/59d036d4c2706b430b0e3f1f1e0ee853ce16ca04)]:
|
|
24
|
+
- @mastra/core@0.0.0-dynamic-model-router-20251010230835
|
|
25
|
+
|
|
26
|
+
## 0.2.0-alpha.0
|
|
27
|
+
|
|
28
|
+
### Minor Changes
|
|
29
|
+
|
|
30
|
+
- Update peer dependencies to match core package version bump (0.20.3) ([#8614](https://github.com/mastra-ai/mastra/pull/8614))
|
|
31
|
+
|
|
32
|
+
### Patch Changes
|
|
33
|
+
|
|
34
|
+
- Update peer dependencies to match core package version bump (0.21.0) ([#8619](https://github.com/mastra-ai/mastra/pull/8619))
|
|
35
|
+
|
|
36
|
+
- Update peer dependencies to match core package version bump (0.21.0) ([#8557](https://github.com/mastra-ai/mastra/pull/8557))
|
|
37
|
+
|
|
38
|
+
- Update peer dependencies to match core package version bump (0.21.0) ([#8626](https://github.com/mastra-ai/mastra/pull/8626))
|
|
39
|
+
|
|
40
|
+
- Update peer dependencies to match core package version bump (0.21.0) ([#8686](https://github.com/mastra-ai/mastra/pull/8686))
|
|
41
|
+
|
|
42
|
+
- nested ai-sdk workflows and networks streaming support ([#8614](https://github.com/mastra-ai/mastra/pull/8614))
|
|
43
|
+
|
|
44
|
+
- Updated dependencies [[`b5a66b7`](https://github.com/mastra-ai/mastra/commit/b5a66b748a14fc8b3f63b04642ddb9621fbcc9e0), [`7b1ef57`](https://github.com/mastra-ai/mastra/commit/7b1ef57fc071c2aa2a2e32905b18cd88719c5a39), [`ee68e82`](https://github.com/mastra-ai/mastra/commit/ee68e8289ea4408d29849e899bc6e78b3bd4e843), [`228228b`](https://github.com/mastra-ai/mastra/commit/228228b0b1de9291cb8887587f5cea1a8757ebad), [`ea33930`](https://github.com/mastra-ai/mastra/commit/ea339301e82d6318257720d811b043014ee44064), [`b5a66b7`](https://github.com/mastra-ai/mastra/commit/b5a66b748a14fc8b3f63b04642ddb9621fbcc9e0), [`135d6f2`](https://github.com/mastra-ai/mastra/commit/135d6f22a326ed1dffff858700669dff09d2c9eb), [`59d036d`](https://github.com/mastra-ai/mastra/commit/59d036d4c2706b430b0e3f1f1e0ee853ce16ca04)]:
|
|
45
|
+
- @mastra/core@0.21.0-alpha.0
|
|
9
46
|
|
|
10
47
|
## 0.1.1
|
|
11
48
|
|
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":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"chat-route.d.ts","sourceRoot":"","sources":["../src/chat-route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAEhE,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAIxD,MAAM,MAAM,gBAAgB,CAAC,MAAM,SAAS,YAAY,GAAG,SAAS,IAAI;IACtE,cAAc,CAAC,EAAE,qBAAqB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACzD,GAAG,CACA;IACE,IAAI,EAAE,GAAG,MAAM,WAAW,MAAM,EAAE,CAAC;IACnC,KAAK,CAAC,EAAE,KAAK,CAAC;CACf,GACD;IACE,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,CACJ,CAAC;AAEF,wBAAgB,SAAS,CAAC,MAAM,SAAS,YAAY,GAAG,SAAS,EAAE,EACjE,IAAuB,EACvB,KAAK,EACL,cAAc,GACf,EAAE,gBAAgB,CAAC,MAAM,CAAC,GAAG,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAuJhE"}
|
package/dist/helpers.d.ts
CHANGED
|
@@ -7,6 +7,16 @@ export type ToolAgentChunkType = {
|
|
|
7
7
|
toolCallId: string;
|
|
8
8
|
payload: any;
|
|
9
9
|
};
|
|
10
|
+
export type ToolWorkflowChunkType = {
|
|
11
|
+
type: 'tool-workflow';
|
|
12
|
+
toolCallId: string;
|
|
13
|
+
payload: any;
|
|
14
|
+
};
|
|
15
|
+
export type ToolNetworkChunkType = {
|
|
16
|
+
type: 'tool-network';
|
|
17
|
+
toolCallId: string;
|
|
18
|
+
payload: any;
|
|
19
|
+
};
|
|
10
20
|
export declare function convertMastraChunkToAISDKv5<OUTPUT extends OutputSchema = undefined>({ chunk, mode, }: {
|
|
11
21
|
chunk: ChunkType<OUTPUT>;
|
|
12
22
|
mode?: 'generate' | 'stream';
|
|
@@ -24,5 +34,5 @@ export declare function convertFullStreamChunkToUIMessageStream<UI_MESSAGE exten
|
|
|
24
34
|
sendStart?: boolean;
|
|
25
35
|
sendFinish?: boolean;
|
|
26
36
|
responseMessageId?: string;
|
|
27
|
-
}): InferUIMessageChunk<UI_MESSAGE> | ToolAgentChunkType | undefined;
|
|
37
|
+
}): InferUIMessageChunk<UI_MESSAGE> | ToolAgentChunkType | ToolWorkflowChunkType | ToolNetworkChunkType | undefined;
|
|
28
38
|
//# 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,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,KAAK,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAE7E,OAAO,KAAK,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,cAAc,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAEpG,MAAM,MAAM,eAAe,CAAC,MAAM,SAAS,YAAY,GAAG,SAAS,IAC/D,cAAc,CAAC,OAAO,CAAC,GACvB,gBAAgB,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC,GAC7C,SAAS,CAAC;AAEd,MAAM,MAAM,kBAAkB,GAAG;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,GAAG,CAAA;CAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,KAAK,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAE7E,OAAO,KAAK,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,cAAc,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAEpG,MAAM,MAAM,eAAe,CAAC,MAAM,SAAS,YAAY,GAAG,SAAS,IAC/D,cAAc,CAAC,OAAO,CAAC,GACvB,gBAAgB,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC,GAC7C,SAAS,CAAC;AAEd,MAAM,MAAM,kBAAkB,GAAG;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,GAAG,CAAA;CAAE,CAAC;AAC1F,MAAM,MAAM,qBAAqB,GAAG;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,GAAG,CAAA;CAAE,CAAC;AAChG,MAAM,MAAM,oBAAoB,GAAG;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,GAAG,CAAA;CAAE,CAAC;AAE9F,wBAAgB,2BAA2B,CAAC,MAAM,SAAS,YAAY,GAAG,SAAS,EAAE,EACnF,KAAK,EACL,IAAe,GAChB,EAAE;IACD,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IACzB,IAAI,CAAC,EAAE,UAAU,GAAG,QAAQ,CAAC;CAC9B,GAAG,eAAe,CAAC,MAAM,CAAC,CAkN1B;AAED,wBAAgB,uCAAuC,CAAC,UAAU,SAAS,SAAS,EAAE,EACpF,IAAI,EACJ,oBAAoB,EACpB,aAAa,EACb,WAAW,EACX,OAAO,EACP,SAAS,EACT,UAAU,EACV,iBAAiB,GAClB,EAAE;IAED,IAAI,EAAE,cAAc,CAAC,OAAO,CAAC,GAAG;QAAE,IAAI,EAAE,aAAa,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,GAAG,CAAA;KAAE,CAAC;IACzF,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,CAAC;IACpC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,GAAG,mBAAmB,CAAC,UAAU,CAAC,GAAG,kBAAkB,GAAG,qBAAqB,GAAG,oBAAoB,GAAG,SAAS,CAyNlH"}
|
package/dist/index.cjs
CHANGED
|
@@ -317,6 +317,18 @@ function convertFullStreamChunkToUIMessageStream({
|
|
|
317
317
|
toolCallId: part.toolCallId,
|
|
318
318
|
payload: part.output
|
|
319
319
|
};
|
|
320
|
+
} else if (part.output.from === "WORKFLOW") {
|
|
321
|
+
return {
|
|
322
|
+
type: "tool-workflow",
|
|
323
|
+
toolCallId: part.toolCallId,
|
|
324
|
+
payload: part.output
|
|
325
|
+
};
|
|
326
|
+
} else if (part.output.from === "NETWORK") {
|
|
327
|
+
return {
|
|
328
|
+
type: "tool-network",
|
|
329
|
+
toolCallId: part.toolCallId,
|
|
330
|
+
payload: part.output
|
|
331
|
+
};
|
|
320
332
|
}
|
|
321
333
|
return;
|
|
322
334
|
}
|
|
@@ -374,9 +386,9 @@ function convertFullStreamChunkToUIMessageStream({
|
|
|
374
386
|
}
|
|
375
387
|
}
|
|
376
388
|
|
|
377
|
-
// src/
|
|
389
|
+
// src/transformers.ts
|
|
378
390
|
function WorkflowStreamToAISDKTransformer() {
|
|
379
|
-
const
|
|
391
|
+
const bufferedWorkflows = /* @__PURE__ */ new Map();
|
|
380
392
|
return new TransformStream({
|
|
381
393
|
start(controller) {
|
|
382
394
|
controller.enqueue({
|
|
@@ -397,73 +409,8 @@ function WorkflowStreamToAISDKTransformer() {
|
|
|
397
409
|
});
|
|
398
410
|
},
|
|
399
411
|
transform(chunk, controller) {
|
|
400
|
-
|
|
401
|
-
if (
|
|
402
|
-
workflowName = chunk.payload.workflowId;
|
|
403
|
-
controller.enqueue({
|
|
404
|
-
data: JSON.stringify({
|
|
405
|
-
type: "data-workflow",
|
|
406
|
-
id: chunk.runId,
|
|
407
|
-
data: {
|
|
408
|
-
name: workflowName,
|
|
409
|
-
status: "running",
|
|
410
|
-
steps: {},
|
|
411
|
-
output: null
|
|
412
|
-
}
|
|
413
|
-
})
|
|
414
|
-
});
|
|
415
|
-
} else if (chunk.type === "workflow-step-start") {
|
|
416
|
-
steps[chunk.payload.id] = {
|
|
417
|
-
// TODO swap with name
|
|
418
|
-
name: chunk.payload.id,
|
|
419
|
-
status: chunk.payload.status,
|
|
420
|
-
input: chunk.payload.payload ?? null,
|
|
421
|
-
output: null
|
|
422
|
-
};
|
|
423
|
-
controller.enqueue({
|
|
424
|
-
data: JSON.stringify({
|
|
425
|
-
type: "data-workflow",
|
|
426
|
-
id: chunk.runId,
|
|
427
|
-
data: {
|
|
428
|
-
name: workflowName,
|
|
429
|
-
status: "running",
|
|
430
|
-
steps,
|
|
431
|
-
output: null
|
|
432
|
-
}
|
|
433
|
-
})
|
|
434
|
-
});
|
|
435
|
-
} else if (chunk.type === "workflow-step-result") {
|
|
436
|
-
steps[chunk.payload.id] = {
|
|
437
|
-
...steps[chunk.payload.id],
|
|
438
|
-
status: chunk.payload.status,
|
|
439
|
-
output: chunk.payload.output ?? null
|
|
440
|
-
};
|
|
441
|
-
controller.enqueue({
|
|
442
|
-
data: JSON.stringify({
|
|
443
|
-
type: "data-workflow",
|
|
444
|
-
id: chunk.runId,
|
|
445
|
-
data: {
|
|
446
|
-
name: workflowName,
|
|
447
|
-
status: "running",
|
|
448
|
-
steps,
|
|
449
|
-
output: null
|
|
450
|
-
}
|
|
451
|
-
})
|
|
452
|
-
});
|
|
453
|
-
} else if (chunk.type === "workflow-finish") {
|
|
454
|
-
controller.enqueue({
|
|
455
|
-
data: JSON.stringify({
|
|
456
|
-
type: "data-workflow",
|
|
457
|
-
id: chunk.runId,
|
|
458
|
-
data: {
|
|
459
|
-
name: workflowName,
|
|
460
|
-
steps,
|
|
461
|
-
output: chunk.payload.output ?? null,
|
|
462
|
-
status: chunk.payload.workflowStatus
|
|
463
|
-
}
|
|
464
|
-
})
|
|
465
|
-
});
|
|
466
|
-
}
|
|
412
|
+
const transformed = transformWorkflow(chunk, bufferedWorkflows);
|
|
413
|
+
if (transformed) controller.enqueue(transformed);
|
|
467
414
|
}
|
|
468
415
|
});
|
|
469
416
|
}
|
|
@@ -488,6 +435,14 @@ function AgentStreamToAISDKTransformer() {
|
|
|
488
435
|
const payload = transformedChunk.payload;
|
|
489
436
|
const agentTransformed = transformAgent(payload, bufferedSteps);
|
|
490
437
|
if (agentTransformed) controller.enqueue(agentTransformed);
|
|
438
|
+
} else if (transformedChunk.type === "tool-workflow") {
|
|
439
|
+
const payload = transformedChunk.payload;
|
|
440
|
+
const workflowChunk = transformWorkflow(payload, bufferedSteps);
|
|
441
|
+
if (workflowChunk) controller.enqueue(workflowChunk);
|
|
442
|
+
} else if (transformedChunk.type === "tool-network") {
|
|
443
|
+
const payload = transformedChunk.payload;
|
|
444
|
+
const networkChunk = transformNetwork(payload, bufferedSteps);
|
|
445
|
+
if (networkChunk) controller.enqueue(networkChunk);
|
|
491
446
|
} else {
|
|
492
447
|
controller.enqueue(transformedChunk);
|
|
493
448
|
}
|
|
@@ -631,6 +586,235 @@ function transformAgent(payload, bufferedSteps) {
|
|
|
631
586
|
}
|
|
632
587
|
return null;
|
|
633
588
|
}
|
|
589
|
+
function transformWorkflow(payload, bufferedWorkflows) {
|
|
590
|
+
switch (payload.type) {
|
|
591
|
+
case "workflow-start":
|
|
592
|
+
bufferedWorkflows.set(payload.runId, {
|
|
593
|
+
name: payload.payload.workflowId,
|
|
594
|
+
steps: {}
|
|
595
|
+
});
|
|
596
|
+
return {
|
|
597
|
+
type: "data-workflow",
|
|
598
|
+
id: payload.runId,
|
|
599
|
+
data: {
|
|
600
|
+
name: bufferedWorkflows.get(payload.runId).name,
|
|
601
|
+
status: "running",
|
|
602
|
+
steps: bufferedWorkflows.get(payload.runId).steps,
|
|
603
|
+
output: null
|
|
604
|
+
}
|
|
605
|
+
};
|
|
606
|
+
case "workflow-step-start": {
|
|
607
|
+
const current = bufferedWorkflows.get(payload.runId) || { name: "", steps: {} };
|
|
608
|
+
current.steps[payload.payload.id] = {
|
|
609
|
+
name: payload.payload.id,
|
|
610
|
+
status: payload.payload.status,
|
|
611
|
+
input: payload.payload.payload ?? null,
|
|
612
|
+
output: null
|
|
613
|
+
};
|
|
614
|
+
bufferedWorkflows.set(payload.runId, current);
|
|
615
|
+
return {
|
|
616
|
+
type: "data-workflow",
|
|
617
|
+
id: payload.runId,
|
|
618
|
+
data: {
|
|
619
|
+
name: current.name,
|
|
620
|
+
status: "running",
|
|
621
|
+
steps: current.steps,
|
|
622
|
+
output: null
|
|
623
|
+
}
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
case "workflow-step-result": {
|
|
627
|
+
const current = bufferedWorkflows.get(payload.runId);
|
|
628
|
+
if (!current) return null;
|
|
629
|
+
current.steps[payload.payload.id] = {
|
|
630
|
+
...current.steps[payload.payload.id],
|
|
631
|
+
status: payload.payload.status,
|
|
632
|
+
output: payload.payload.output ?? null
|
|
633
|
+
};
|
|
634
|
+
return {
|
|
635
|
+
type: "data-workflow",
|
|
636
|
+
id: payload.runId,
|
|
637
|
+
data: {
|
|
638
|
+
name: current.name,
|
|
639
|
+
status: "running",
|
|
640
|
+
steps: current.steps,
|
|
641
|
+
output: null
|
|
642
|
+
}
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
case "workflow-finish": {
|
|
646
|
+
const current = bufferedWorkflows.get(payload.runId);
|
|
647
|
+
if (!current) return null;
|
|
648
|
+
return {
|
|
649
|
+
type: "data-workflow",
|
|
650
|
+
id: payload.runId,
|
|
651
|
+
data: {
|
|
652
|
+
name: current.name,
|
|
653
|
+
steps: current.steps,
|
|
654
|
+
output: payload.payload.output ?? null,
|
|
655
|
+
status: payload.payload.workflowStatus
|
|
656
|
+
}
|
|
657
|
+
};
|
|
658
|
+
}
|
|
659
|
+
default:
|
|
660
|
+
return null;
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
function transformNetwork(payload, bufferedNetworks) {
|
|
664
|
+
switch (payload.type) {
|
|
665
|
+
case "routing-agent-start": {
|
|
666
|
+
bufferedNetworks.set(payload.payload.runId, {
|
|
667
|
+
name: payload.payload.agentId,
|
|
668
|
+
steps: []
|
|
669
|
+
});
|
|
670
|
+
return {
|
|
671
|
+
type: "data-network",
|
|
672
|
+
id: payload.payload.runId,
|
|
673
|
+
data: {
|
|
674
|
+
name: bufferedNetworks.get(payload.payload.runId).name,
|
|
675
|
+
status: "running",
|
|
676
|
+
steps: bufferedNetworks.get(payload.payload.runId).steps,
|
|
677
|
+
output: null
|
|
678
|
+
}
|
|
679
|
+
};
|
|
680
|
+
}
|
|
681
|
+
case "agent-execution-start": {
|
|
682
|
+
const current = bufferedNetworks.get(payload.payload.runId) || { name: "", steps: [] };
|
|
683
|
+
current.steps.push({
|
|
684
|
+
name: payload.payload.agentId,
|
|
685
|
+
status: "running",
|
|
686
|
+
input: payload.payload.args || null,
|
|
687
|
+
output: null
|
|
688
|
+
});
|
|
689
|
+
bufferedNetworks.set(payload.payload.runId, current);
|
|
690
|
+
return {
|
|
691
|
+
type: "data-network",
|
|
692
|
+
id: payload.payload.runId,
|
|
693
|
+
data: {
|
|
694
|
+
name: current.name,
|
|
695
|
+
status: "running",
|
|
696
|
+
steps: current.steps,
|
|
697
|
+
output: null
|
|
698
|
+
}
|
|
699
|
+
};
|
|
700
|
+
}
|
|
701
|
+
case "workflow-execution-start": {
|
|
702
|
+
const current = bufferedNetworks.get(payload.payload.runId) || { name: "", steps: [] };
|
|
703
|
+
current.steps.push({
|
|
704
|
+
name: payload.payload.name,
|
|
705
|
+
status: "running",
|
|
706
|
+
input: payload.payload.args || null,
|
|
707
|
+
output: null
|
|
708
|
+
});
|
|
709
|
+
bufferedNetworks.set(payload.payload.runId, current);
|
|
710
|
+
return {
|
|
711
|
+
type: "data-network",
|
|
712
|
+
id: payload.payload.runId,
|
|
713
|
+
data: {
|
|
714
|
+
name: current.name,
|
|
715
|
+
status: "running",
|
|
716
|
+
steps: current.steps,
|
|
717
|
+
output: null
|
|
718
|
+
}
|
|
719
|
+
};
|
|
720
|
+
}
|
|
721
|
+
case "tool-execution-start": {
|
|
722
|
+
const current = bufferedNetworks.get(payload.payload.runId) || { name: "", steps: [] };
|
|
723
|
+
current.steps.push({
|
|
724
|
+
name: payload.payload.args?.toolName,
|
|
725
|
+
status: "running",
|
|
726
|
+
input: payload.payload.args?.args || null,
|
|
727
|
+
output: null
|
|
728
|
+
});
|
|
729
|
+
bufferedNetworks.set(payload.payload.runId, current);
|
|
730
|
+
return {
|
|
731
|
+
type: "data-network",
|
|
732
|
+
id: payload.payload.runId,
|
|
733
|
+
data: {
|
|
734
|
+
name: current.name,
|
|
735
|
+
status: "running",
|
|
736
|
+
steps: current.steps,
|
|
737
|
+
output: null
|
|
738
|
+
}
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
case "agent-execution-end":
|
|
742
|
+
case "tool-execution-end": {
|
|
743
|
+
const current = bufferedNetworks.get(payload.runId);
|
|
744
|
+
if (!current) return null;
|
|
745
|
+
return {
|
|
746
|
+
type: "data-network",
|
|
747
|
+
id: payload.runId,
|
|
748
|
+
data: {
|
|
749
|
+
name: current.name,
|
|
750
|
+
status: "running",
|
|
751
|
+
steps: current.steps,
|
|
752
|
+
output: null
|
|
753
|
+
}
|
|
754
|
+
};
|
|
755
|
+
}
|
|
756
|
+
case "workflow-execution-end": {
|
|
757
|
+
const current = bufferedNetworks.get(payload.runId);
|
|
758
|
+
if (!current) return null;
|
|
759
|
+
return {
|
|
760
|
+
type: "data-network",
|
|
761
|
+
id: payload.runId,
|
|
762
|
+
data: {
|
|
763
|
+
name: current.name,
|
|
764
|
+
status: "running",
|
|
765
|
+
steps: current.steps,
|
|
766
|
+
output: null
|
|
767
|
+
}
|
|
768
|
+
};
|
|
769
|
+
}
|
|
770
|
+
case "routing-agent-end": {
|
|
771
|
+
const current = bufferedNetworks.get(payload.payload.runId);
|
|
772
|
+
if (!current) return null;
|
|
773
|
+
return {
|
|
774
|
+
type: "data-network",
|
|
775
|
+
id: payload.payload.runId,
|
|
776
|
+
data: {
|
|
777
|
+
name: current.name,
|
|
778
|
+
status: "finished",
|
|
779
|
+
steps: current.steps,
|
|
780
|
+
output: payload.payload?.result ?? null
|
|
781
|
+
}
|
|
782
|
+
};
|
|
783
|
+
}
|
|
784
|
+
case "network-execution-event-step-finish": {
|
|
785
|
+
const current = bufferedNetworks.get(payload.payload.runId);
|
|
786
|
+
if (!current) return null;
|
|
787
|
+
return {
|
|
788
|
+
type: "data-network",
|
|
789
|
+
id: payload.payload.runId,
|
|
790
|
+
data: {
|
|
791
|
+
name: current.name,
|
|
792
|
+
status: "finished",
|
|
793
|
+
steps: current.steps,
|
|
794
|
+
output: payload.payload?.result ?? null
|
|
795
|
+
}
|
|
796
|
+
};
|
|
797
|
+
}
|
|
798
|
+
case "network-execution-event-finish": {
|
|
799
|
+
const current = bufferedNetworks.get(payload.runId);
|
|
800
|
+
if (!current) return null;
|
|
801
|
+
return {
|
|
802
|
+
type: "data-network",
|
|
803
|
+
id: payload.runId,
|
|
804
|
+
data: {
|
|
805
|
+
name: current.name,
|
|
806
|
+
status: "finished",
|
|
807
|
+
steps: current.steps,
|
|
808
|
+
output: payload.payload?.result ?? null
|
|
809
|
+
}
|
|
810
|
+
};
|
|
811
|
+
}
|
|
812
|
+
default:
|
|
813
|
+
return null;
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
// src/to-ai-sdk-format.ts
|
|
634
818
|
function toAISdkFormat(stream) {
|
|
635
819
|
return stream.fullStream.pipeThrough(AgentStreamToAISDKTransformer());
|
|
636
820
|
}
|
|
@@ -740,6 +924,7 @@ function chatRoute({
|
|
|
740
924
|
handler: async (c) => {
|
|
741
925
|
const { messages, ...rest } = await c.req.json();
|
|
742
926
|
const mastra = c.get("mastra");
|
|
927
|
+
const runtimeContext = c.get("runtimeContext");
|
|
743
928
|
let agentToUse = agent;
|
|
744
929
|
if (!agent) {
|
|
745
930
|
const agentId = c.req.param("agentId");
|
|
@@ -750,6 +935,9 @@ function chatRoute({
|
|
|
750
935
|
`Fixed agent ID was set together with an agentId path parameter. This can lead to unexpected behavior.`
|
|
751
936
|
);
|
|
752
937
|
}
|
|
938
|
+
if (runtimeContext && defaultOptions?.runtimeContext) {
|
|
939
|
+
mastra.getLogger()?.warn(`"runtimeContext" set in the route options will be overridden by the request's "runtimeContext".`);
|
|
940
|
+
}
|
|
753
941
|
if (!agentToUse) {
|
|
754
942
|
throw new Error("Agent ID is required");
|
|
755
943
|
}
|
|
@@ -759,7 +947,8 @@ function chatRoute({
|
|
|
759
947
|
}
|
|
760
948
|
const result = await agentObj.stream(messages, {
|
|
761
949
|
...defaultOptions,
|
|
762
|
-
...rest
|
|
950
|
+
...rest,
|
|
951
|
+
runtimeContext: runtimeContext || defaultOptions?.runtimeContext
|
|
763
952
|
});
|
|
764
953
|
const uiMessageStream = ai.createUIMessageStream({
|
|
765
954
|
execute: async ({ writer }) => {
|