@mastra/server 0.0.0-fix-core-reasoning-parts-20251015155834 → 0.0.0-fix-writer-workflow-resumestream-20251022161252
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 +100 -3
- package/dist/{chunk-JSLAYFEW.js → chunk-CFBJQKRE.js} +88 -70
- package/dist/chunk-CFBJQKRE.js.map +1 -0
- package/dist/{chunk-FWO7VQDC.js → chunk-CVOGYUL7.js} +2254 -255
- package/dist/chunk-CVOGYUL7.js.map +1 -0
- package/dist/{chunk-BZLZFHAT.cjs → chunk-HZJTM3OQ.cjs} +88 -69
- package/dist/chunk-HZJTM3OQ.cjs.map +1 -0
- package/dist/{chunk-3LTO44EP.cjs → chunk-JTXOSCJQ.cjs} +30 -5
- package/dist/chunk-JTXOSCJQ.cjs.map +1 -0
- package/dist/{chunk-OEOGYAQC.js → chunk-MH2EOSRX.js} +30 -5
- package/dist/chunk-MH2EOSRX.js.map +1 -0
- package/dist/{chunk-XVPBGW6Y.cjs → chunk-QU6N55W6.cjs} +9 -9
- package/dist/{chunk-XVPBGW6Y.cjs.map → chunk-QU6N55W6.cjs.map} +1 -1
- package/dist/{chunk-MQDBNHBT.cjs → chunk-RJX63KSA.cjs} +85 -36
- package/dist/chunk-RJX63KSA.cjs.map +1 -0
- package/dist/{chunk-SIW6CYO3.js → chunk-SHWNNZBL.js} +7 -7
- package/dist/{chunk-SIW6CYO3.js.map → chunk-SHWNNZBL.js.map} +1 -1
- package/dist/{chunk-FZNS32WJ.js → chunk-TOCYBDP2.js} +4 -4
- package/dist/{chunk-FZNS32WJ.js.map → chunk-TOCYBDP2.js.map} +1 -1
- package/dist/{chunk-OYL5TBJW.cjs → chunk-X6C7BUWN.cjs} +4 -4
- package/dist/{chunk-OYL5TBJW.cjs.map → chunk-X6C7BUWN.cjs.map} +1 -1
- package/dist/{chunk-DB63UMTV.js → chunk-XXPCYVTH.js} +84 -37
- package/dist/chunk-XXPCYVTH.js.map +1 -0
- package/dist/{chunk-7HDOBOGG.cjs → chunk-YKENCZQ2.cjs} +2268 -269
- package/dist/chunk-YKENCZQ2.cjs.map +1 -0
- package/dist/server/handlers/agent-builder.cjs +16 -16
- package/dist/server/handlers/agent-builder.d.ts +1 -1
- package/dist/server/handlers/agent-builder.d.ts.map +1 -1
- package/dist/server/handlers/agent-builder.js +1 -1
- package/dist/server/handlers/agents.cjs +23 -19
- package/dist/server/handlers/agents.d.ts +4 -0
- package/dist/server/handlers/agents.d.ts.map +1 -1
- package/dist/server/handlers/agents.js +1 -1
- package/dist/server/handlers/memory.cjs +16 -16
- package/dist/server/handlers/memory.d.ts.map +1 -1
- package/dist/server/handlers/memory.js +1 -1
- package/dist/server/handlers/workflows.cjs +27 -19
- package/dist/server/handlers/workflows.d.ts +10 -4
- package/dist/server/handlers/workflows.d.ts.map +1 -1
- package/dist/server/handlers/workflows.js +1 -1
- package/dist/server/handlers.cjs +8 -8
- package/dist/server/handlers.js +4 -4
- package/dist/{token-53CFGXUO.cjs → token-375W3LEI.cjs} +10 -10
- package/dist/{token-53CFGXUO.cjs.map → token-375W3LEI.cjs.map} +1 -1
- package/dist/{token-WAEKDUVY.js → token-C3IMNCC4.js} +8 -8
- package/dist/{token-WAEKDUVY.js.map → token-C3IMNCC4.js.map} +1 -1
- package/dist/token-util-CV3RRG6K.cjs +9 -0
- package/dist/{token-util-S4A355II.cjs.map → token-util-CV3RRG6K.cjs.map} +1 -1
- package/dist/token-util-E5QO2RCL.js +7 -0
- package/dist/{token-util-LY37VCIN.js.map → token-util-E5QO2RCL.js.map} +1 -1
- package/package.json +8 -8
- package/dist/chunk-3LTO44EP.cjs.map +0 -1
- package/dist/chunk-7HDOBOGG.cjs.map +0 -1
- package/dist/chunk-BZLZFHAT.cjs.map +0 -1
- package/dist/chunk-DB63UMTV.js.map +0 -1
- package/dist/chunk-FWO7VQDC.js.map +0 -1
- package/dist/chunk-JSLAYFEW.js.map +0 -1
- package/dist/chunk-MQDBNHBT.cjs.map +0 -1
- package/dist/chunk-OEOGYAQC.js.map +0 -1
- package/dist/token-util-LY37VCIN.js +0 -7
- package/dist/token-util-S4A355II.cjs +0 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,11 +1,108 @@
|
|
|
1
1
|
# @mastra/server
|
|
2
2
|
|
|
3
|
-
## 0.0.0-fix-
|
|
3
|
+
## 0.0.0-fix-writer-workflow-resumestream-20251022161252
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
- Updated dependencies [[`
|
|
8
|
-
- @mastra/core@0.0.0-fix-
|
|
7
|
+
- Updated dependencies [[`92b18cd`](https://github.com/mastra-ai/mastra/commit/92b18cd443bbfd1194c7f8aea727ef1f8cf1db2d)]:
|
|
8
|
+
- @mastra/core@0.0.0-fix-writer-workflow-resumestream-20251022161252
|
|
9
|
+
|
|
10
|
+
## 0.22.1
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Get agent registered on a parent agent via API ([#9106](https://github.com/mastra-ai/mastra/pull/9106))
|
|
15
|
+
|
|
16
|
+
- Updated dependencies []:
|
|
17
|
+
- @mastra/core@0.22.1
|
|
18
|
+
|
|
19
|
+
## 0.22.1-alpha.0
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- Get agent registered on a parent agent via API ([#9106](https://github.com/mastra-ai/mastra/pull/9106))
|
|
24
|
+
|
|
25
|
+
- Updated dependencies []:
|
|
26
|
+
- @mastra/core@0.22.1-alpha.0
|
|
27
|
+
|
|
28
|
+
## 0.22.0
|
|
29
|
+
|
|
30
|
+
### Minor Changes
|
|
31
|
+
|
|
32
|
+
- Consolidate streamVNext logic into stream, move old stream function into streamLegacy ([#9092](https://github.com/mastra-ai/mastra/pull/9092))
|
|
33
|
+
|
|
34
|
+
- Update peer dependencies to match core package version bump (0.21.2) ([#9038](https://github.com/mastra-ai/mastra/pull/9038))
|
|
35
|
+
|
|
36
|
+
- Update peer dependencies to match core package version bump (0.22.0) ([#9092](https://github.com/mastra-ai/mastra/pull/9092))
|
|
37
|
+
|
|
38
|
+
- Update peer dependencies to match core package version bump (0.21.2) ([#9021](https://github.com/mastra-ai/mastra/pull/9021))
|
|
39
|
+
|
|
40
|
+
### Patch Changes
|
|
41
|
+
|
|
42
|
+
- Updated `watch` and `watchAsync` methods to use proper function overloads instead of generic conditional types, ensuring compatibility with the base Run class signatures. ([#9048](https://github.com/mastra-ai/mastra/pull/9048))
|
|
43
|
+
|
|
44
|
+
- Generate a title for Agent.network() threads ([#8853](https://github.com/mastra-ai/mastra/pull/8853))
|
|
45
|
+
|
|
46
|
+
- Fix custom metadata preservation in UIMessages when loading threads. The `getMessagesHandler` now converts `messagesV2` (V2 format with metadata) instead of `messages` (V1 format without metadata) to AIV5.UI format. Also updates the abstract `MastraMemory.query()` return type to include `messagesV2` for proper type safety. ([#9029](https://github.com/mastra-ai/mastra/pull/9029))
|
|
47
|
+
|
|
48
|
+
- Fix provider tools for popular providers and add support for anthropic/claude skills. ([#9038](https://github.com/mastra-ai/mastra/pull/9038))
|
|
49
|
+
|
|
50
|
+
- Show agent tool output better in playground ([#9021](https://github.com/mastra-ai/mastra/pull/9021))
|
|
51
|
+
|
|
52
|
+
- Update peerdeps to 0.23.0-0 ([#9043](https://github.com/mastra-ai/mastra/pull/9043))
|
|
53
|
+
|
|
54
|
+
- Updated dependencies [[`c67ca32`](https://github.com/mastra-ai/mastra/commit/c67ca32e3c2cf69bfc146580770c720220ca44ac), [`efb5ed9`](https://github.com/mastra-ai/mastra/commit/efb5ed946ae7f410bc68c9430beb4b010afd25ec), [`dbc9e12`](https://github.com/mastra-ai/mastra/commit/dbc9e1216ba575ba59ead4afb727a01215f7de4f), [`99e41b9`](https://github.com/mastra-ai/mastra/commit/99e41b94957cdd25137d3ac12e94e8b21aa01b68), [`c28833c`](https://github.com/mastra-ai/mastra/commit/c28833c5b6d8e10eeffd7f7d39129d53b8bca240), [`8ea07b4`](https://github.com/mastra-ai/mastra/commit/8ea07b4bdc73e4218437dbb6dcb0f4b23e745a44), [`ba201b8`](https://github.com/mastra-ai/mastra/commit/ba201b8f8feac4c72350f2dbd52c13c7297ba7b0), [`f053e89`](https://github.com/mastra-ai/mastra/commit/f053e89160dbd0bd3333fc3492f68231b5c7c349), [`4fc4136`](https://github.com/mastra-ai/mastra/commit/4fc413652866a8d2240694fddb2562e9edbb70df), [`b78e04d`](https://github.com/mastra-ai/mastra/commit/b78e04d935a16ecb1e59c5c96e564903527edddd), [`d10baf5`](https://github.com/mastra-ai/mastra/commit/d10baf5a3c924f2a6654e23a3e318ed03f189b76), [`038c55a`](https://github.com/mastra-ai/mastra/commit/038c55a7090fc1b1513a966386d3072617f836ac), [`182f045`](https://github.com/mastra-ai/mastra/commit/182f0458f25bd70aa774e64fd923c8a483eddbf1), [`9a1a485`](https://github.com/mastra-ai/mastra/commit/9a1a4859b855e37239f652bf14b1ecd1029b8c4e), [`9257233`](https://github.com/mastra-ai/mastra/commit/9257233c4ffce09b2bedc2a9adbd70d7a83fa8e2), [`7620d2b`](https://github.com/mastra-ai/mastra/commit/7620d2bddeb4fae4c3c0a0b4e672969795fca11a), [`b2365f0`](https://github.com/mastra-ai/mastra/commit/b2365f038dd4c5f06400428b224af963f399ad50), [`0f1a4c9`](https://github.com/mastra-ai/mastra/commit/0f1a4c984fb4b104b2f0b63ba18c9fa77f567700), [`9029ba3`](https://github.com/mastra-ai/mastra/commit/9029ba34459c8859fed4c6b73efd8e2d0021e7ba), [`426cc56`](https://github.com/mastra-ai/mastra/commit/426cc561c85ae76a112ded2385532a91f9f9f074), [`00931fb`](https://github.com/mastra-ai/mastra/commit/00931fb1a21aa42c4fbc20c2c40dd62466b8fc8f), [`e473bfe`](https://github.com/mastra-ai/mastra/commit/e473bfe416c0b8e876973c2b6a6f13c394b7a93f), [`b78e04d`](https://github.com/mastra-ai/mastra/commit/b78e04d935a16ecb1e59c5c96e564903527edddd), [`2db6160`](https://github.com/mastra-ai/mastra/commit/2db6160e2022ff8827c15d30157e684683b934b5), [`8aeea37`](https://github.com/mastra-ai/mastra/commit/8aeea37efdde347c635a67fed56794943b7f74ec), [`02fe153`](https://github.com/mastra-ai/mastra/commit/02fe15351d6021d214da48ec982a0e9e4150bcee), [`648e2ca`](https://github.com/mastra-ai/mastra/commit/648e2ca42da54838c6ccbdaadc6fadd808fa6b86), [`74567b3`](https://github.com/mastra-ai/mastra/commit/74567b3d237ae3915cd0bca3cf55fa0a64e4e4a4), [`b65c5e0`](https://github.com/mastra-ai/mastra/commit/b65c5e0fe6f3c390a9a8bbcf69304d972c3a4afb), [`15a1733`](https://github.com/mastra-ai/mastra/commit/15a1733074cee8bd37370e1af34cd818e89fa7ac), [`fc2a774`](https://github.com/mastra-ai/mastra/commit/fc2a77468981aaddc3e77f83f0c4ad4a4af140da), [`4e08933`](https://github.com/mastra-ai/mastra/commit/4e08933625464dfde178347af5b6278fcf34188e)]:
|
|
55
|
+
- @mastra/core@0.22.0
|
|
56
|
+
|
|
57
|
+
## 0.22.0-alpha.1
|
|
58
|
+
|
|
59
|
+
### Minor Changes
|
|
60
|
+
|
|
61
|
+
- Consolidate streamVNext logic into stream, move old stream function into streamLegacy ([#9092](https://github.com/mastra-ai/mastra/pull/9092))
|
|
62
|
+
|
|
63
|
+
- Update peer dependencies to match core package version bump (0.21.2) ([#9038](https://github.com/mastra-ai/mastra/pull/9038))
|
|
64
|
+
|
|
65
|
+
- Update peer dependencies to match core package version bump (0.22.0) ([#9092](https://github.com/mastra-ai/mastra/pull/9092))
|
|
66
|
+
|
|
67
|
+
- Update peer dependencies to match core package version bump (0.21.2) ([#9021](https://github.com/mastra-ai/mastra/pull/9021))
|
|
68
|
+
|
|
69
|
+
### Patch Changes
|
|
70
|
+
|
|
71
|
+
- Updated `watch` and `watchAsync` methods to use proper function overloads instead of generic conditional types, ensuring compatibility with the base Run class signatures. ([#9048](https://github.com/mastra-ai/mastra/pull/9048))
|
|
72
|
+
|
|
73
|
+
- Fix custom metadata preservation in UIMessages when loading threads. The `getMessagesHandler` now converts `messagesV2` (V2 format with metadata) instead of `messages` (V1 format without metadata) to AIV5.UI format. Also updates the abstract `MastraMemory.query()` return type to include `messagesV2` for proper type safety. ([#9029](https://github.com/mastra-ai/mastra/pull/9029))
|
|
74
|
+
|
|
75
|
+
- Fix provider tools for popular providers and add support for anthropic/claude skills. ([#9038](https://github.com/mastra-ai/mastra/pull/9038))
|
|
76
|
+
|
|
77
|
+
- Show agent tool output better in playground ([#9021](https://github.com/mastra-ai/mastra/pull/9021))
|
|
78
|
+
|
|
79
|
+
- Update peerdeps to 0.23.0-0 ([#9043](https://github.com/mastra-ai/mastra/pull/9043))
|
|
80
|
+
|
|
81
|
+
- Updated dependencies [[`efb5ed9`](https://github.com/mastra-ai/mastra/commit/efb5ed946ae7f410bc68c9430beb4b010afd25ec), [`8ea07b4`](https://github.com/mastra-ai/mastra/commit/8ea07b4bdc73e4218437dbb6dcb0f4b23e745a44), [`ba201b8`](https://github.com/mastra-ai/mastra/commit/ba201b8f8feac4c72350f2dbd52c13c7297ba7b0), [`4fc4136`](https://github.com/mastra-ai/mastra/commit/4fc413652866a8d2240694fddb2562e9edbb70df), [`b78e04d`](https://github.com/mastra-ai/mastra/commit/b78e04d935a16ecb1e59c5c96e564903527edddd), [`d10baf5`](https://github.com/mastra-ai/mastra/commit/d10baf5a3c924f2a6654e23a3e318ed03f189b76), [`038c55a`](https://github.com/mastra-ai/mastra/commit/038c55a7090fc1b1513a966386d3072617f836ac), [`182f045`](https://github.com/mastra-ai/mastra/commit/182f0458f25bd70aa774e64fd923c8a483eddbf1), [`7620d2b`](https://github.com/mastra-ai/mastra/commit/7620d2bddeb4fae4c3c0a0b4e672969795fca11a), [`b2365f0`](https://github.com/mastra-ai/mastra/commit/b2365f038dd4c5f06400428b224af963f399ad50), [`9029ba3`](https://github.com/mastra-ai/mastra/commit/9029ba34459c8859fed4c6b73efd8e2d0021e7ba), [`426cc56`](https://github.com/mastra-ai/mastra/commit/426cc561c85ae76a112ded2385532a91f9f9f074), [`00931fb`](https://github.com/mastra-ai/mastra/commit/00931fb1a21aa42c4fbc20c2c40dd62466b8fc8f), [`e473bfe`](https://github.com/mastra-ai/mastra/commit/e473bfe416c0b8e876973c2b6a6f13c394b7a93f), [`b78e04d`](https://github.com/mastra-ai/mastra/commit/b78e04d935a16ecb1e59c5c96e564903527edddd), [`648e2ca`](https://github.com/mastra-ai/mastra/commit/648e2ca42da54838c6ccbdaadc6fadd808fa6b86), [`b65c5e0`](https://github.com/mastra-ai/mastra/commit/b65c5e0fe6f3c390a9a8bbcf69304d972c3a4afb)]:
|
|
82
|
+
- @mastra/core@0.22.0-alpha.1
|
|
83
|
+
|
|
84
|
+
## 0.21.2-alpha.0
|
|
85
|
+
|
|
86
|
+
### Patch Changes
|
|
87
|
+
|
|
88
|
+
- Generate a title for Agent.network() threads ([#8853](https://github.com/mastra-ai/mastra/pull/8853))
|
|
89
|
+
|
|
90
|
+
- Updated dependencies [[`c67ca32`](https://github.com/mastra-ai/mastra/commit/c67ca32e3c2cf69bfc146580770c720220ca44ac), [`dbc9e12`](https://github.com/mastra-ai/mastra/commit/dbc9e1216ba575ba59ead4afb727a01215f7de4f), [`99e41b9`](https://github.com/mastra-ai/mastra/commit/99e41b94957cdd25137d3ac12e94e8b21aa01b68), [`c28833c`](https://github.com/mastra-ai/mastra/commit/c28833c5b6d8e10eeffd7f7d39129d53b8bca240), [`f053e89`](https://github.com/mastra-ai/mastra/commit/f053e89160dbd0bd3333fc3492f68231b5c7c349), [`9a1a485`](https://github.com/mastra-ai/mastra/commit/9a1a4859b855e37239f652bf14b1ecd1029b8c4e), [`9257233`](https://github.com/mastra-ai/mastra/commit/9257233c4ffce09b2bedc2a9adbd70d7a83fa8e2), [`0f1a4c9`](https://github.com/mastra-ai/mastra/commit/0f1a4c984fb4b104b2f0b63ba18c9fa77f567700), [`2db6160`](https://github.com/mastra-ai/mastra/commit/2db6160e2022ff8827c15d30157e684683b934b5), [`8aeea37`](https://github.com/mastra-ai/mastra/commit/8aeea37efdde347c635a67fed56794943b7f74ec), [`02fe153`](https://github.com/mastra-ai/mastra/commit/02fe15351d6021d214da48ec982a0e9e4150bcee), [`74567b3`](https://github.com/mastra-ai/mastra/commit/74567b3d237ae3915cd0bca3cf55fa0a64e4e4a4), [`15a1733`](https://github.com/mastra-ai/mastra/commit/15a1733074cee8bd37370e1af34cd818e89fa7ac), [`fc2a774`](https://github.com/mastra-ai/mastra/commit/fc2a77468981aaddc3e77f83f0c4ad4a4af140da), [`4e08933`](https://github.com/mastra-ai/mastra/commit/4e08933625464dfde178347af5b6278fcf34188e)]:
|
|
91
|
+
- @mastra/core@0.21.2-alpha.0
|
|
92
|
+
|
|
93
|
+
## 0.21.1
|
|
94
|
+
|
|
95
|
+
### Patch Changes
|
|
96
|
+
|
|
97
|
+
- Updated dependencies [[`ca85c93`](https://github.com/mastra-ai/mastra/commit/ca85c932b232e6ad820c811ec176d98e68c59b0a), [`a1d40f8`](https://github.com/mastra-ai/mastra/commit/a1d40f88d4ce42c4508774ad22e38ac582157af2), [`01c4a25`](https://github.com/mastra-ai/mastra/commit/01c4a2506c514d5e861c004d3d2fb3791c6391f3), [`cce8aad`](https://github.com/mastra-ai/mastra/commit/cce8aad878a0dd98e5647680f3765caba0b1701c)]:
|
|
98
|
+
- @mastra/core@0.21.1
|
|
99
|
+
|
|
100
|
+
## 0.21.1-alpha.0
|
|
101
|
+
|
|
102
|
+
### Patch Changes
|
|
103
|
+
|
|
104
|
+
- Updated dependencies [[`ca85c93`](https://github.com/mastra-ai/mastra/commit/ca85c932b232e6ad820c811ec176d98e68c59b0a), [`a1d40f8`](https://github.com/mastra-ai/mastra/commit/a1d40f88d4ce42c4508774ad22e38ac582157af2), [`01c4a25`](https://github.com/mastra-ai/mastra/commit/01c4a2506c514d5e861c004d3d2fb3791c6391f3), [`cce8aad`](https://github.com/mastra-ai/mastra/commit/cce8aad878a0dd98e5647680f3765caba0b1701c)]:
|
|
105
|
+
- @mastra/core@0.21.1-alpha.0
|
|
9
106
|
|
|
10
107
|
## 0.21.0
|
|
11
108
|
|
|
@@ -15,6 +15,7 @@ __export(agents_exports, {
|
|
|
15
15
|
generateHandler: () => generateHandler,
|
|
16
16
|
generateLegacyHandler: () => generateLegacyHandler,
|
|
17
17
|
getAgentByIdHandler: () => getAgentByIdHandler,
|
|
18
|
+
getAgentFromSystem: () => getAgentFromSystem,
|
|
18
19
|
getAgentsHandler: () => getAgentsHandler,
|
|
19
20
|
getEvalsByAgentIdHandler: () => getEvalsByAgentIdHandler,
|
|
20
21
|
getLiveEvalsByAgentIdHandler: () => getLiveEvalsByAgentIdHandler,
|
|
@@ -34,20 +35,39 @@ async function getSerializedAgentTools(tools) {
|
|
|
34
35
|
const _tool = tool;
|
|
35
36
|
const toolId = _tool.id ?? `tool-${key}`;
|
|
36
37
|
let inputSchemaForReturn = void 0;
|
|
37
|
-
if (_tool.inputSchema) {
|
|
38
|
-
if (_tool.inputSchema && typeof _tool.inputSchema === "object" && "jsonSchema" in _tool.inputSchema) {
|
|
39
|
-
inputSchemaForReturn = stringify(_tool.inputSchema.jsonSchema);
|
|
40
|
-
} else if (_tool.inputSchema) {
|
|
41
|
-
inputSchemaForReturn = stringify(zodToJsonSchema(_tool.inputSchema));
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
38
|
let outputSchemaForReturn = void 0;
|
|
45
|
-
|
|
46
|
-
if (_tool.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
39
|
+
try {
|
|
40
|
+
if (_tool.inputSchema) {
|
|
41
|
+
if (_tool.inputSchema && typeof _tool.inputSchema === "object" && "jsonSchema" in _tool.inputSchema) {
|
|
42
|
+
inputSchemaForReturn = stringify(_tool.inputSchema.jsonSchema);
|
|
43
|
+
} else if (typeof _tool.inputSchema === "function") {
|
|
44
|
+
const inputSchema = _tool.inputSchema();
|
|
45
|
+
if (inputSchema && inputSchema.jsonSchema) {
|
|
46
|
+
inputSchemaForReturn = stringify(inputSchema.jsonSchema);
|
|
47
|
+
}
|
|
48
|
+
} else if (_tool.inputSchema) {
|
|
49
|
+
inputSchemaForReturn = stringify(zodToJsonSchema(_tool.inputSchema));
|
|
50
|
+
}
|
|
50
51
|
}
|
|
52
|
+
if (_tool.outputSchema) {
|
|
53
|
+
if (_tool.outputSchema && typeof _tool.outputSchema === "object" && "jsonSchema" in _tool.outputSchema) {
|
|
54
|
+
outputSchemaForReturn = stringify(_tool.outputSchema.jsonSchema);
|
|
55
|
+
} else if (typeof _tool.outputSchema === "function") {
|
|
56
|
+
const outputSchema = _tool.outputSchema();
|
|
57
|
+
if (outputSchema && outputSchema.jsonSchema) {
|
|
58
|
+
outputSchemaForReturn = stringify(outputSchema.jsonSchema);
|
|
59
|
+
}
|
|
60
|
+
} else if (_tool.outputSchema) {
|
|
61
|
+
outputSchemaForReturn = stringify(
|
|
62
|
+
zodToJsonSchema(_tool.outputSchema)
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
} catch (error) {
|
|
67
|
+
console.error(`Error getting serialized tool`, {
|
|
68
|
+
toolId: _tool.id,
|
|
69
|
+
error
|
|
70
|
+
});
|
|
51
71
|
}
|
|
52
72
|
acc[key] = {
|
|
53
73
|
..._tool,
|
|
@@ -145,6 +165,39 @@ async function formatAgentList({
|
|
|
145
165
|
modelList
|
|
146
166
|
};
|
|
147
167
|
}
|
|
168
|
+
async function getAgentFromSystem({ mastra, agentId }) {
|
|
169
|
+
const logger = mastra.getLogger();
|
|
170
|
+
if (!agentId) {
|
|
171
|
+
throw new HTTPException(400, { message: "Agent ID is required" });
|
|
172
|
+
}
|
|
173
|
+
let agent;
|
|
174
|
+
try {
|
|
175
|
+
agent = mastra.getAgent(agentId);
|
|
176
|
+
} catch (error) {
|
|
177
|
+
logger.debug("Error getting agent from mastra, searching agents for agent", error);
|
|
178
|
+
}
|
|
179
|
+
if (!agent) {
|
|
180
|
+
logger.debug(`Agent ${agentId} not found, looking through sub-agents`);
|
|
181
|
+
const agents = mastra.getAgents();
|
|
182
|
+
if (Object.keys(agents || {}).length) {
|
|
183
|
+
for (const [_, ag] of Object.entries(agents)) {
|
|
184
|
+
try {
|
|
185
|
+
const subAgents = await ag.listAgents();
|
|
186
|
+
if (subAgents[agentId]) {
|
|
187
|
+
agent = subAgents[agentId];
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
} catch (error) {
|
|
191
|
+
logger.debug("Error getting agent from agent", error);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (!agent) {
|
|
197
|
+
throw new HTTPException(404, { message: `Agent with name ${agentId} not found` });
|
|
198
|
+
}
|
|
199
|
+
return agent;
|
|
200
|
+
}
|
|
148
201
|
async function getAgentsHandler({
|
|
149
202
|
mastra,
|
|
150
203
|
runtimeContext
|
|
@@ -258,10 +311,7 @@ async function getAgentByIdHandler({
|
|
|
258
311
|
isPlayground = false
|
|
259
312
|
}) {
|
|
260
313
|
try {
|
|
261
|
-
const agent = mastra
|
|
262
|
-
if (!agent) {
|
|
263
|
-
throw new HTTPException(404, { message: "Agent not found" });
|
|
264
|
-
}
|
|
314
|
+
const agent = await getAgentFromSystem({ mastra, agentId });
|
|
265
315
|
return formatAgent({ mastra, agent, runtimeContext, isPlayground });
|
|
266
316
|
} catch (error) {
|
|
267
317
|
return handleError(error, "Error getting agent");
|
|
@@ -273,7 +323,7 @@ async function getEvalsByAgentIdHandler({
|
|
|
273
323
|
agentId
|
|
274
324
|
}) {
|
|
275
325
|
try {
|
|
276
|
-
const agent = mastra
|
|
326
|
+
const agent = await getAgentFromSystem({ mastra, agentId });
|
|
277
327
|
const evals = await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, "test") || [];
|
|
278
328
|
const instructions = await agent.getInstructions({ runtimeContext });
|
|
279
329
|
return {
|
|
@@ -292,7 +342,7 @@ async function getLiveEvalsByAgentIdHandler({
|
|
|
292
342
|
agentId
|
|
293
343
|
}) {
|
|
294
344
|
try {
|
|
295
|
-
const agent = mastra
|
|
345
|
+
const agent = await getAgentFromSystem({ mastra, agentId });
|
|
296
346
|
const evals = await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, "live") || [];
|
|
297
347
|
const instructions = await agent.getInstructions({ runtimeContext });
|
|
298
348
|
return {
|
|
@@ -313,10 +363,7 @@ async function generateLegacyHandler({
|
|
|
313
363
|
abortSignal
|
|
314
364
|
}) {
|
|
315
365
|
try {
|
|
316
|
-
const agent = mastra
|
|
317
|
-
if (!agent) {
|
|
318
|
-
throw new HTTPException(404, { message: "Agent not found" });
|
|
319
|
-
}
|
|
366
|
+
const agent = await getAgentFromSystem({ mastra, agentId });
|
|
320
367
|
sanitizeBody(body, ["tools"]);
|
|
321
368
|
const { messages, resourceId, resourceid, runtimeContext: agentRuntimeContext, ...rest } = body;
|
|
322
369
|
const finalResourceId = resourceId ?? resourceid;
|
|
@@ -345,10 +392,7 @@ async function generateHandler({
|
|
|
345
392
|
abortSignal
|
|
346
393
|
}) {
|
|
347
394
|
try {
|
|
348
|
-
const agent = mastra
|
|
349
|
-
if (!agent) {
|
|
350
|
-
throw new HTTPException(404, { message: "Agent not found" });
|
|
351
|
-
}
|
|
395
|
+
const agent = await getAgentFromSystem({ mastra, agentId });
|
|
352
396
|
sanitizeBody(body, ["tools"]);
|
|
353
397
|
const { messages, runtimeContext: agentRuntimeContext, ...rest } = body;
|
|
354
398
|
const finalRuntimeContext = new RuntimeContext([
|
|
@@ -375,10 +419,7 @@ async function streamGenerateLegacyHandler({
|
|
|
375
419
|
abortSignal
|
|
376
420
|
}) {
|
|
377
421
|
try {
|
|
378
|
-
const agent = mastra
|
|
379
|
-
if (!agent) {
|
|
380
|
-
throw new HTTPException(404, { message: "Agent not found" });
|
|
381
|
-
}
|
|
422
|
+
const agent = await getAgentFromSystem({ mastra, agentId });
|
|
382
423
|
const { messages, resourceId, resourceid, runtimeContext: agentRuntimeContext, ...rest } = body;
|
|
383
424
|
const finalResourceId = resourceId ?? resourceid;
|
|
384
425
|
const finalRuntimeContext = new RuntimeContext([
|
|
@@ -412,7 +453,7 @@ async function streamGenerateLegacyHandler({
|
|
|
412
453
|
return handleError(error, "error streaming agent response");
|
|
413
454
|
}
|
|
414
455
|
}
|
|
415
|
-
function streamGenerateHandler({
|
|
456
|
+
async function streamGenerateHandler({
|
|
416
457
|
mastra,
|
|
417
458
|
runtimeContext,
|
|
418
459
|
agentId,
|
|
@@ -420,10 +461,7 @@ function streamGenerateHandler({
|
|
|
420
461
|
abortSignal
|
|
421
462
|
}) {
|
|
422
463
|
try {
|
|
423
|
-
const agent = mastra
|
|
424
|
-
if (!agent) {
|
|
425
|
-
throw new HTTPException(404, { message: "Agent not found" });
|
|
426
|
-
}
|
|
464
|
+
const agent = await getAgentFromSystem({ mastra, agentId });
|
|
427
465
|
sanitizeBody(body, ["tools"]);
|
|
428
466
|
const { messages, runtimeContext: agentRuntimeContext, ...rest } = body;
|
|
429
467
|
const finalRuntimeContext = new RuntimeContext([
|
|
@@ -442,7 +480,7 @@ function streamGenerateHandler({
|
|
|
442
480
|
return handleError(error, "error streaming agent response");
|
|
443
481
|
}
|
|
444
482
|
}
|
|
445
|
-
function approveToolCallHandler({
|
|
483
|
+
async function approveToolCallHandler({
|
|
446
484
|
mastra,
|
|
447
485
|
runtimeContext,
|
|
448
486
|
agentId,
|
|
@@ -450,10 +488,7 @@ function approveToolCallHandler({
|
|
|
450
488
|
abortSignal
|
|
451
489
|
}) {
|
|
452
490
|
try {
|
|
453
|
-
const agent = mastra
|
|
454
|
-
if (!agent) {
|
|
455
|
-
throw new HTTPException(404, { message: "Agent not found" });
|
|
456
|
-
}
|
|
491
|
+
const agent = await getAgentFromSystem({ mastra, agentId });
|
|
457
492
|
sanitizeBody(body, ["tools"]);
|
|
458
493
|
const { runId, runtimeContext: agentRuntimeContext, ...rest } = body;
|
|
459
494
|
const finalRuntimeContext = new RuntimeContext([
|
|
@@ -472,7 +507,7 @@ function approveToolCallHandler({
|
|
|
472
507
|
return handleError(error, "error streaming agent response");
|
|
473
508
|
}
|
|
474
509
|
}
|
|
475
|
-
function declineToolCallHandler({
|
|
510
|
+
async function declineToolCallHandler({
|
|
476
511
|
mastra,
|
|
477
512
|
runtimeContext,
|
|
478
513
|
agentId,
|
|
@@ -480,10 +515,7 @@ function declineToolCallHandler({
|
|
|
480
515
|
abortSignal
|
|
481
516
|
}) {
|
|
482
517
|
try {
|
|
483
|
-
const agent = mastra
|
|
484
|
-
if (!agent) {
|
|
485
|
-
throw new HTTPException(404, { message: "Agent not found" });
|
|
486
|
-
}
|
|
518
|
+
const agent = await getAgentFromSystem({ mastra, agentId });
|
|
487
519
|
sanitizeBody(body, ["tools"]);
|
|
488
520
|
const { runId, runtimeContext: agentRuntimeContext, ...rest } = body;
|
|
489
521
|
const finalRuntimeContext = new RuntimeContext([
|
|
@@ -502,7 +534,7 @@ function declineToolCallHandler({
|
|
|
502
534
|
return handleError(error, "error streaming agent response");
|
|
503
535
|
}
|
|
504
536
|
}
|
|
505
|
-
function streamNetworkHandler({
|
|
537
|
+
async function streamNetworkHandler({
|
|
506
538
|
mastra,
|
|
507
539
|
runtimeContext,
|
|
508
540
|
agentId,
|
|
@@ -510,10 +542,7 @@ function streamNetworkHandler({
|
|
|
510
542
|
// abortSignal,
|
|
511
543
|
}) {
|
|
512
544
|
try {
|
|
513
|
-
const agent = mastra
|
|
514
|
-
if (!agent) {
|
|
515
|
-
throw new HTTPException(404, { message: "Agent not found" });
|
|
516
|
-
}
|
|
545
|
+
const agent = await getAgentFromSystem({ mastra, agentId });
|
|
517
546
|
sanitizeBody(body, ["tools"]);
|
|
518
547
|
const { messages, runtimeContext: agentRuntimeContext, ...rest } = body;
|
|
519
548
|
const finalRuntimeContext = new RuntimeContext([
|
|
@@ -525,7 +554,8 @@ function streamNetworkHandler({
|
|
|
525
554
|
...rest,
|
|
526
555
|
memory: {
|
|
527
556
|
thread: rest.thread ?? "",
|
|
528
|
-
resource: rest.resourceId ?? ""
|
|
557
|
+
resource: rest.resourceId ?? "",
|
|
558
|
+
options: rest.memory?.options ?? {}
|
|
529
559
|
},
|
|
530
560
|
runtimeContext: finalRuntimeContext
|
|
531
561
|
});
|
|
@@ -542,10 +572,7 @@ async function streamUIMessageHandler({
|
|
|
542
572
|
abortSignal
|
|
543
573
|
}) {
|
|
544
574
|
try {
|
|
545
|
-
const agent = mastra
|
|
546
|
-
if (!agent) {
|
|
547
|
-
throw new HTTPException(404, { message: "Agent not found" });
|
|
548
|
-
}
|
|
575
|
+
const agent = await getAgentFromSystem({ mastra, agentId });
|
|
549
576
|
sanitizeBody(body, ["tools"]);
|
|
550
577
|
const { messages, runtimeContext: agentRuntimeContext, ...rest } = body;
|
|
551
578
|
const finalRuntimeContext = new RuntimeContext([
|
|
@@ -570,10 +597,7 @@ async function updateAgentModelHandler({
|
|
|
570
597
|
body
|
|
571
598
|
}) {
|
|
572
599
|
try {
|
|
573
|
-
const agent = mastra
|
|
574
|
-
if (!agent) {
|
|
575
|
-
throw new HTTPException(404, { message: "Agent not found" });
|
|
576
|
-
}
|
|
600
|
+
const agent = await getAgentFromSystem({ mastra, agentId });
|
|
577
601
|
const { modelId, provider } = body;
|
|
578
602
|
const newModel = `${provider}/${modelId}`;
|
|
579
603
|
agent.__updateModel({ model: newModel });
|
|
@@ -588,10 +612,7 @@ async function reorderAgentModelListHandler({
|
|
|
588
612
|
body
|
|
589
613
|
}) {
|
|
590
614
|
try {
|
|
591
|
-
const agent = mastra
|
|
592
|
-
if (!agent) {
|
|
593
|
-
throw new HTTPException(404, { message: "Agent not found" });
|
|
594
|
-
}
|
|
615
|
+
const agent = await getAgentFromSystem({ mastra, agentId });
|
|
595
616
|
const modelList = await agent.getModelList();
|
|
596
617
|
if (!modelList || modelList.length === 0) {
|
|
597
618
|
throw new HTTPException(400, { message: "Agent model list is not found or empty" });
|
|
@@ -609,10 +630,7 @@ async function updateAgentModelInModelListHandler({
|
|
|
609
630
|
body
|
|
610
631
|
}) {
|
|
611
632
|
try {
|
|
612
|
-
const agent = mastra
|
|
613
|
-
if (!agent) {
|
|
614
|
-
throw new HTTPException(404, { message: "Agent not found" });
|
|
615
|
-
}
|
|
633
|
+
const agent = await getAgentFromSystem({ mastra, agentId });
|
|
616
634
|
const { model: bodyModel, maxRetries, enabled } = body;
|
|
617
635
|
if (!modelConfigId) {
|
|
618
636
|
throw new HTTPException(400, { message: "Model id is required" });
|
|
@@ -657,6 +675,6 @@ async function getProvidersHandler() {
|
|
|
657
675
|
}
|
|
658
676
|
}
|
|
659
677
|
|
|
660
|
-
export { agents_exports, approveToolCallHandler, declineToolCallHandler, generateHandler, generateLegacyHandler, getAgentByIdHandler, getAgentsHandler, getEvalsByAgentIdHandler, getLiveEvalsByAgentIdHandler, getProvidersHandler, getSerializedAgentTools, getSerializedProcessors, reorderAgentModelListHandler, streamGenerateHandler, streamGenerateLegacyHandler, streamNetworkHandler, streamUIMessageHandler, updateAgentModelHandler, updateAgentModelInModelListHandler };
|
|
661
|
-
//# sourceMappingURL=chunk-
|
|
662
|
-
//# sourceMappingURL=chunk-
|
|
678
|
+
export { agents_exports, approveToolCallHandler, declineToolCallHandler, generateHandler, generateLegacyHandler, getAgentByIdHandler, getAgentFromSystem, getAgentsHandler, getEvalsByAgentIdHandler, getLiveEvalsByAgentIdHandler, getProvidersHandler, getSerializedAgentTools, getSerializedProcessors, reorderAgentModelListHandler, streamGenerateHandler, streamGenerateLegacyHandler, streamNetworkHandler, streamUIMessageHandler, updateAgentModelHandler, updateAgentModelInModelListHandler };
|
|
679
|
+
//# sourceMappingURL=chunk-CFBJQKRE.js.map
|
|
680
|
+
//# sourceMappingURL=chunk-CFBJQKRE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/server/handlers/agents.ts"],"names":["agent","acc","key"],"mappings":";;;;;;;;;;AAAA,IAAA,cAAA,GAAA;AAAA,QAAA,CAAA,cAAA,EAAA;AAAA,EAA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;AAE9E,IAAA,OAAO,EAAE,SAAS,oBAAA,EAAqB;AAAA,EACzC,SAAS,KAAA,EAAO;AACd,IAAA,OAAO,WAAA,CAAY,OAAO,2BAA2B,CAAA;AAAA,EACvD;AACF;AAEA,eAAsB,mBAAA,GAAsB;AAC1C,EAAA,IAAI;AACF,IAAA,MAAM,SAAA,GAAY,MAAA,CAAO,OAAA,CAAQ,iBAAiB,CAAA,CAAE,IAAI,CAAC,CAAC,EAAA,EAAI,QAAQ,CAAA,KAAM;AAE1E,MAAA,MAAM,OAAA,GAAU,KAAA,CAAM,OAAA,CAAQ,QAAA,CAAS,YAAY,IAAI,QAAA,CAAS,YAAA,GAAe,CAAC,QAAA,CAAS,YAAY,CAAA;AACrG,MAAA,MAAM,SAAA,GAAY,QAAQ,KAAA,CAAM,CAAA,MAAA,KAAU,CAAC,CAAC,OAAA,CAAQ,GAAA,CAAI,MAAM,CAAC,CAAA;AAE/D,MAAA,OAAO;AAAA,QACL,EAAA;AAAA,QACA,MAAM,QAAA,CAAS,IAAA;AAAA,QACf,QAAQ,QAAA,CAAS,YAAA;AAAA,QACjB,SAAA;AAAA,QACA,QAAQ,QAAA,CAAS,MAAA;AAAA,QACjB,MAAA,EAAQ,CAAC,GAAG,QAAA,CAAS,MAAM;AAAA;AAAA,OAC7B;AAAA,IACF,CAAC,CAAA;AAED,IAAA,OAAO,EAAE,SAAA,EAAU;AAAA,EACrB,SAAS,KAAA,EAAO;AACd,IAAA,OAAO,WAAA,CAAY,OAAO,0BAA0B,CAAA;AAAA,EACtD;AACF","file":"chunk-CFBJQKRE.js","sourcesContent":["import type { Agent, AgentModelManagerConfig } from '@mastra/core/agent';\nimport { PROVIDER_REGISTRY } from '@mastra/core/llm';\nimport type { SystemMessage } from '@mastra/core/llm';\nimport type { InputProcessor, OutputProcessor } from '@mastra/core/processors';\nimport { RuntimeContext } from '@mastra/core/runtime-context';\nimport { zodToJsonSchema } from '@mastra/core/utils/zod-to-json';\nimport { stringify } from 'superjson';\n\nimport type {\n StreamTextOnFinishCallback,\n StreamTextOnStepFinishCallback,\n} from '../../../../core/dist/llm/model/base.types';\nimport { HTTPException } from '../http-exception';\nimport type { Context } from '../types';\n\nimport { handleError } from './error';\nimport { sanitizeBody, validateBody } from './utils';\n\ntype GetBody<\n T extends keyof Agent & { [K in keyof Agent]: Agent[K] extends (...args: any) => any ? K : never }[keyof Agent],\n> = {\n messages: Parameters<Agent[T]>[0];\n} & Parameters<Agent[T]>[1];\n\ntype GetHITLBody<\n T extends keyof Agent & { [K in keyof Agent]: Agent[K] extends (...args: any) => any ? K : never }[keyof Agent],\n> = Parameters<Agent[T]>[0];\n\nexport interface SerializedProcessor {\n name: string;\n}\n\nexport interface SerializedTool {\n id: string;\n description?: string;\n inputSchema?: string;\n outputSchema?: string;\n requireApproval?: boolean;\n}\n\nexport interface SerializedWorkflow {\n name: string;\n steps?: Record<string, { id: string; description?: string }>;\n}\n\nexport interface SerializedAgent {\n name: string;\n instructions?: SystemMessage;\n tools: Record<string, SerializedTool>;\n agents: Record<string, SerializedAgentDefinition>;\n workflows: Record<string, SerializedWorkflow>;\n inputProcessors: SerializedProcessor[];\n outputProcessors: SerializedProcessor[];\n provider?: string;\n modelId?: string;\n modelVersion?: string;\n modelList?: Array<\n Omit<AgentModelManagerConfig, 'model'> & {\n model: {\n modelId: string;\n provider: string;\n modelVersion: string;\n };\n }\n >;\n // We can't use the true types here because they are not serializable\n defaultGenerateOptions?: Record<string, unknown>;\n defaultStreamOptions?: Record<string, unknown>;\n}\n\nexport interface SerializedAgentWithId extends SerializedAgent {\n id: string;\n}\n\nexport async function getSerializedAgentTools(tools: Record<string, unknown>): Promise<Record<string, SerializedTool>> {\n return Object.entries(tools || {}).reduce<Record<string, SerializedTool>>((acc, [key, tool]) => {\n const _tool = tool as {\n id?: string;\n description?: string;\n inputSchema?: { jsonSchema?: unknown } | unknown;\n outputSchema?: { jsonSchema?: unknown } | unknown;\n };\n\n const toolId = _tool.id ?? `tool-${key}`;\n\n let inputSchemaForReturn: string | undefined = undefined;\n let outputSchemaForReturn: string | undefined = undefined;\n\n try {\n if (_tool.inputSchema) {\n if (_tool.inputSchema && typeof _tool.inputSchema === 'object' && 'jsonSchema' in _tool.inputSchema) {\n inputSchemaForReturn = stringify(_tool.inputSchema.jsonSchema);\n } else if (typeof _tool.inputSchema === 'function') {\n const inputSchema = _tool.inputSchema();\n if (inputSchema && inputSchema.jsonSchema) {\n inputSchemaForReturn = stringify(inputSchema.jsonSchema);\n }\n } else if (_tool.inputSchema) {\n inputSchemaForReturn = stringify(zodToJsonSchema(_tool.inputSchema as Parameters<typeof zodToJsonSchema>[0]));\n }\n }\n\n if (_tool.outputSchema) {\n if (_tool.outputSchema && typeof _tool.outputSchema === 'object' && 'jsonSchema' in _tool.outputSchema) {\n outputSchemaForReturn = stringify(_tool.outputSchema.jsonSchema);\n } else if (typeof _tool.outputSchema === 'function') {\n const outputSchema = _tool.outputSchema();\n if (outputSchema && outputSchema.jsonSchema) {\n outputSchemaForReturn = stringify(outputSchema.jsonSchema);\n }\n } else if (_tool.outputSchema) {\n outputSchemaForReturn = stringify(\n zodToJsonSchema(_tool.outputSchema as Parameters<typeof zodToJsonSchema>[0]),\n );\n }\n }\n } catch (error) {\n console.error(`Error getting serialized tool`, {\n toolId: _tool.id,\n error,\n });\n }\n\n acc[key] = {\n ..._tool,\n id: toolId,\n inputSchema: inputSchemaForReturn,\n outputSchema: outputSchemaForReturn,\n };\n return acc;\n }, {});\n}\n\nexport function getSerializedProcessors(processors: (InputProcessor | OutputProcessor)[]): SerializedProcessor[] {\n return processors.map(processor => {\n // Processors are class instances or objects with a name property\n // Use the name property if available, otherwise fall back to constructor name\n return {\n name: processor.name || processor.constructor.name,\n };\n });\n}\n\ninterface SerializedAgentDefinition {\n id: string;\n name: string;\n}\n\nasync function getSerializedAgentDefinition({\n agent,\n runtimeContext,\n}: {\n agent: Agent;\n runtimeContext: RuntimeContext;\n}): Promise<Record<string, SerializedAgentDefinition>> {\n let serializedAgentAgents: Record<string, SerializedAgentDefinition> = {};\n\n if ('listAgents' in agent) {\n const agents = await agent.listAgents({ runtimeContext });\n serializedAgentAgents = Object.entries(agents || {}).reduce<Record<string, SerializedAgentDefinition>>(\n (acc, [key, agent]) => {\n return {\n ...acc,\n [key]: { id: agent.id, name: agent.name },\n };\n },\n {},\n );\n }\n return serializedAgentAgents;\n}\n\nasync function formatAgentList({\n id,\n mastra,\n agent,\n runtimeContext,\n}: {\n id: string;\n mastra: Context['mastra'];\n agent: Agent;\n runtimeContext: RuntimeContext;\n}): Promise<SerializedAgentWithId> {\n const instructions = await agent.getInstructions({ runtimeContext });\n const tools = await agent.getTools({ runtimeContext });\n const llm = await agent.getLLM({ runtimeContext });\n const defaultGenerateOptions = await agent.getDefaultGenerateOptions({ runtimeContext });\n const defaultStreamOptions = await agent.getDefaultStreamOptions({ runtimeContext });\n const serializedAgentTools = await getSerializedAgentTools(tools);\n\n let serializedAgentWorkflows: Record<\n string,\n { name: string; steps?: Record<string, { id: string; description?: string }> }\n > = {};\n\n if ('getWorkflows' in agent) {\n const logger = mastra.getLogger();\n try {\n const workflows = await agent.getWorkflows({ runtimeContext });\n serializedAgentWorkflows = Object.entries(workflows || {}).reduce<\n Record<string, { name: string; steps?: Record<string, { id: string; description?: string }> }>\n >((acc, [key, workflow]) => {\n return {\n ...acc,\n [key]: {\n name: workflow.name || 'Unnamed workflow',\n },\n };\n }, {});\n } catch (error) {\n logger.error('Error getting workflows for agent', { agentName: agent.name, error });\n }\n }\n\n const serializedAgentAgents = await getSerializedAgentDefinition({ agent, runtimeContext });\n\n // Get and serialize processors\n const inputProcessors = await agent.getInputProcessors(runtimeContext);\n const outputProcessors = await agent.getOutputProcessors(runtimeContext);\n const serializedInputProcessors = getSerializedProcessors(inputProcessors);\n const serializedOutputProcessors = getSerializedProcessors(outputProcessors);\n\n const model = llm?.getModel();\n const models = await agent.getModelList(runtimeContext);\n const modelList = models?.map(md => ({\n ...md,\n model: {\n modelId: md.model.modelId,\n provider: md.model.provider,\n modelVersion: md.model.specificationVersion,\n },\n }));\n\n return {\n id,\n name: agent.name,\n instructions,\n agents: serializedAgentAgents,\n tools: serializedAgentTools,\n workflows: serializedAgentWorkflows,\n inputProcessors: serializedInputProcessors,\n outputProcessors: serializedOutputProcessors,\n provider: llm?.getProvider(),\n modelId: llm?.getModelId(),\n modelVersion: model?.specificationVersion,\n defaultGenerateOptions,\n defaultStreamOptions,\n modelList,\n };\n}\n\nexport async function getAgentFromSystem({ mastra, agentId }: { mastra: Context['mastra']; agentId: string }) {\n const logger = mastra.getLogger();\n\n if (!agentId) {\n throw new HTTPException(400, { message: 'Agent ID is required' });\n }\n\n let agent;\n\n try {\n agent = mastra.getAgent(agentId);\n } catch (error) {\n logger.debug('Error getting agent from mastra, searching agents for agent', error);\n }\n\n if (!agent) {\n logger.debug(`Agent ${agentId} not found, looking through sub-agents`);\n const agents = mastra.getAgents();\n if (Object.keys(agents || {}).length) {\n for (const [_, ag] of Object.entries(agents)) {\n try {\n const subAgents = await ag.listAgents();\n\n if (subAgents[agentId]) {\n agent = subAgents[agentId];\n break;\n }\n } catch (error) {\n logger.debug('Error getting agent from agent', error);\n }\n }\n }\n }\n\n if (!agent) {\n throw new HTTPException(404, { message: `Agent with name ${agentId} not found` });\n }\n\n return agent;\n}\n\n// Agent handlers\nexport async function getAgentsHandler({\n mastra,\n runtimeContext,\n}: Context & { runtimeContext: RuntimeContext }): Promise<Record<string, SerializedAgent>> {\n try {\n const agents = mastra.getAgents();\n\n const serializedAgentsMap = await Promise.all(\n Object.entries(agents).map(async ([id, agent]) => {\n return formatAgentList({ id, mastra, agent, runtimeContext });\n }),\n );\n\n const serializedAgents = serializedAgentsMap.reduce<\n Record<string, Omit<(typeof serializedAgentsMap)[number], 'id'>>\n >((acc, { id, ...rest }) => {\n acc[id] = rest;\n return acc;\n }, {});\n\n return serializedAgents;\n } catch (error) {\n return handleError(error, 'Error getting agents');\n }\n}\n\nasync function formatAgent({\n mastra,\n agent,\n runtimeContext,\n isPlayground,\n}: {\n mastra: Context['mastra'];\n agent: Agent;\n runtimeContext: RuntimeContext;\n isPlayground: boolean;\n}): Promise<SerializedAgent> {\n const tools = await agent.getTools({ runtimeContext });\n\n const serializedAgentTools = await getSerializedAgentTools(tools);\n\n let serializedAgentWorkflows: Record<\n string,\n { name: string; steps: Record<string, { id: string; description?: string }> }\n > = {};\n\n if ('getWorkflows' in agent) {\n const logger = mastra.getLogger();\n try {\n const workflows = await agent.getWorkflows({ runtimeContext });\n\n serializedAgentWorkflows = Object.entries(workflows || {}).reduce<\n Record<string, { name: string; steps: Record<string, { id: string; description?: string }> }>\n >((acc, [key, workflow]) => {\n return {\n ...acc,\n [key]: {\n name: workflow.name || 'Unnamed workflow',\n steps: Object.entries(workflow.steps).reduce<Record<string, { id: string; description?: string }>>(\n (acc, [key, step]) => {\n return {\n ...acc,\n [key]: {\n id: step.id,\n description: step.description,\n },\n };\n },\n {},\n ),\n },\n };\n }, {});\n } catch (error) {\n logger.error('Error getting workflows for agent', { agentName: agent.name, error });\n }\n }\n\n let proxyRuntimeContext = runtimeContext;\n if (isPlayground) {\n proxyRuntimeContext = new Proxy(runtimeContext, {\n get(target, prop) {\n if (prop === 'get') {\n return function (key: string) {\n const value = target.get(key);\n return value ?? `<${key}>`;\n };\n }\n return Reflect.get(target, prop);\n },\n });\n }\n\n const instructions = await agent.getInstructions({ runtimeContext: proxyRuntimeContext });\n const llm = await agent.getLLM({ runtimeContext });\n const defaultGenerateOptions = await agent.getDefaultGenerateOptions({ runtimeContext: proxyRuntimeContext });\n const defaultStreamOptions = await agent.getDefaultStreamOptions({ runtimeContext: proxyRuntimeContext });\n\n const model = llm?.getModel();\n const models = await agent.getModelList(runtimeContext);\n const modelList = models?.map(md => ({\n ...md,\n model: {\n modelId: md.model.modelId,\n provider: md.model.provider,\n modelVersion: md.model.specificationVersion,\n },\n }));\n\n const serializedAgentAgents = await getSerializedAgentDefinition({ agent, runtimeContext: proxyRuntimeContext });\n\n // Get and serialize processors\n const inputProcessors = await agent.getInputProcessors(proxyRuntimeContext);\n const outputProcessors = await agent.getOutputProcessors(proxyRuntimeContext);\n const serializedInputProcessors = getSerializedProcessors(inputProcessors);\n const serializedOutputProcessors = getSerializedProcessors(outputProcessors);\n\n return {\n name: agent.name,\n instructions,\n tools: serializedAgentTools,\n agents: serializedAgentAgents,\n workflows: serializedAgentWorkflows,\n inputProcessors: serializedInputProcessors,\n outputProcessors: serializedOutputProcessors,\n provider: llm?.getProvider(),\n modelId: llm?.getModelId(),\n modelVersion: model?.specificationVersion,\n modelList,\n defaultGenerateOptions,\n defaultStreamOptions,\n };\n}\n\nexport async function getAgentByIdHandler({\n mastra,\n runtimeContext,\n agentId,\n isPlayground = false,\n}: Context & { isPlayground?: boolean; runtimeContext: RuntimeContext; agentId: string }): Promise<\n SerializedAgent | ReturnType<typeof handleError>\n> {\n try {\n const agent = await getAgentFromSystem({ mastra, agentId });\n\n return formatAgent({ mastra, agent, runtimeContext, isPlayground });\n } catch (error) {\n return handleError(error, 'Error getting agent');\n }\n}\n\nexport async function getEvalsByAgentIdHandler({\n mastra,\n runtimeContext,\n agentId,\n}: Context & { runtimeContext: RuntimeContext; agentId: string }) {\n try {\n const agent = await getAgentFromSystem({ mastra, agentId });\n const evals = (await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, 'test')) || [];\n const instructions = await agent.getInstructions({ runtimeContext });\n return {\n id: agentId,\n name: agent.name,\n instructions,\n evals,\n };\n } catch (error) {\n return handleError(error, 'Error getting test evals');\n }\n}\n\nexport async function getLiveEvalsByAgentIdHandler({\n mastra,\n runtimeContext,\n agentId,\n}: Context & { runtimeContext: RuntimeContext; agentId: string }) {\n try {\n const agent = await getAgentFromSystem({ mastra, agentId });\n const evals = (await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, 'live')) || [];\n const instructions = await agent.getInstructions({ runtimeContext });\n\n return {\n id: agentId,\n name: agent.name,\n instructions,\n evals,\n };\n } catch (error) {\n return handleError(error, 'Error getting live evals');\n }\n}\n\nexport async function generateLegacyHandler({\n mastra,\n runtimeContext,\n agentId,\n body,\n abortSignal,\n}: Context & {\n runtimeContext: RuntimeContext;\n agentId: string;\n body: GetBody<'generateLegacy'> & {\n // @deprecated use resourceId\n resourceid?: string;\n runtimeContext?: Record<string, unknown>;\n };\n abortSignal?: AbortSignal;\n}) {\n try {\n const agent = await getAgentFromSystem({ mastra, agentId });\n\n // UI Frameworks may send \"client tools\" in the body,\n // but it interferes with llm providers tool handling, so we remove them\n sanitizeBody(body, ['tools']);\n\n const { messages, resourceId, resourceid, runtimeContext: agentRuntimeContext, ...rest } = body;\n // Use resourceId if provided, fall back to resourceid (deprecated)\n const finalResourceId = resourceId ?? resourceid;\n\n const finalRuntimeContext = new RuntimeContext<Record<string, unknown>>([\n ...Array.from(runtimeContext.entries()),\n ...Array.from(Object.entries(agentRuntimeContext ?? {})),\n ]);\n\n validateBody({ messages });\n\n const result = await agent.generateLegacy(messages, {\n ...rest,\n abortSignal,\n // @ts-expect-error TODO fix types\n resourceId: finalResourceId,\n runtimeContext: finalRuntimeContext,\n });\n\n return result;\n } catch (error) {\n return handleError(error, 'Error generating from agent');\n }\n}\n\nexport async function generateHandler({\n mastra,\n runtimeContext,\n agentId,\n body,\n abortSignal,\n}: Context & {\n runtimeContext: RuntimeContext;\n agentId: string;\n body: GetBody<'generate'> & {\n runtimeContext?: Record<string, unknown>;\n format?: 'mastra' | 'aisdk';\n };\n abortSignal?: AbortSignal;\n}): Promise<ReturnType<Agent['generate']>> {\n try {\n const agent = await getAgentFromSystem({ mastra, agentId });\n\n // UI Frameworks may send \"client tools\" in the body,\n // but it interferes with llm providers tool handling, so we remove them\n sanitizeBody(body, ['tools']);\n\n const { messages, runtimeContext: agentRuntimeContext, ...rest } = body;\n\n const finalRuntimeContext = new RuntimeContext<Record<string, unknown>>([\n ...Array.from(runtimeContext.entries()),\n ...Array.from(Object.entries(agentRuntimeContext ?? {})),\n ]);\n\n validateBody({ messages });\n\n const result = await agent.generate(messages, {\n ...rest,\n runtimeContext: finalRuntimeContext,\n format: rest.format || 'mastra',\n abortSignal,\n });\n\n return result;\n } catch (error) {\n return handleError(error, 'Error generating from agent');\n }\n}\n\nexport async function streamGenerateLegacyHandler({\n mastra,\n runtimeContext,\n agentId,\n body,\n abortSignal,\n}: Context & {\n runtimeContext: RuntimeContext;\n agentId: string;\n body: GetBody<'streamLegacy'> & {\n // @deprecated use resourceId\n resourceid?: string;\n runtimeContext?: string;\n };\n abortSignal?: AbortSignal;\n}): Promise<Response | undefined> {\n try {\n const agent = await getAgentFromSystem({ mastra, agentId });\n\n const { messages, resourceId, resourceid, runtimeContext: agentRuntimeContext, ...rest } = body;\n // Use resourceId if provided, fall back to resourceid (deprecated)\n const finalResourceId = resourceId ?? resourceid;\n\n const finalRuntimeContext = new RuntimeContext<Record<string, unknown>>([\n ...Array.from(runtimeContext.entries()),\n ...Array.from(Object.entries(agentRuntimeContext ?? {})),\n ]);\n\n validateBody({ messages });\n\n const streamResult = await agent.streamLegacy(messages, {\n ...rest,\n abortSignal,\n // @ts-expect-error TODO fix types\n resourceId: finalResourceId,\n runtimeContext: finalRuntimeContext,\n });\n\n const streamResponse = rest.output\n ? streamResult.toTextStreamResponse({\n headers: {\n 'Transfer-Encoding': 'chunked',\n },\n })\n : streamResult.toDataStreamResponse({\n sendUsage: true,\n sendReasoning: true,\n getErrorMessage: (error: any) => {\n return `An error occurred while processing your request. ${error instanceof Error ? error.message : JSON.stringify(error)}`;\n },\n headers: {\n 'Transfer-Encoding': 'chunked',\n },\n });\n\n return streamResponse;\n } catch (error) {\n return handleError(error, 'error streaming agent response');\n }\n}\n\nexport async function streamGenerateHandler({\n mastra,\n runtimeContext,\n agentId,\n body,\n abortSignal,\n}: Context & {\n runtimeContext: RuntimeContext;\n agentId: string;\n body: GetBody<'stream'> & {\n runtimeContext?: string;\n format?: 'aisdk' | 'mastra';\n };\n abortSignal?: AbortSignal;\n}): ReturnType<Agent['stream']> {\n try {\n const agent = await getAgentFromSystem({ mastra, agentId });\n\n // UI Frameworks may send \"client tools\" in the body,\n // but it interferes with llm providers tool handling, so we remove them\n sanitizeBody(body, ['tools']);\n\n const { messages, runtimeContext: agentRuntimeContext, ...rest } = body;\n const finalRuntimeContext = new RuntimeContext<Record<string, unknown>>([\n ...Array.from(runtimeContext.entries()),\n ...Array.from(Object.entries(agentRuntimeContext ?? {})),\n ]);\n\n validateBody({ messages });\n\n const streamResult = agent.stream(messages, {\n ...rest,\n runtimeContext: finalRuntimeContext,\n abortSignal,\n format: body.format ?? 'mastra',\n });\n\n return streamResult;\n } catch (error) {\n return handleError(error, 'error streaming agent response');\n }\n}\n\nexport async function approveToolCallHandler({\n mastra,\n runtimeContext,\n agentId,\n body,\n abortSignal,\n}: Context & {\n runtimeContext: RuntimeContext;\n agentId: string;\n body: GetHITLBody<'approveToolCall'> & {\n runtimeContext?: string;\n format?: 'aisdk' | 'mastra';\n };\n abortSignal?: AbortSignal;\n}): ReturnType<Agent['approveToolCall']> {\n try {\n const agent = await getAgentFromSystem({ mastra, agentId });\n\n // UI Frameworks may send \"client tools\" in the body,\n // but it interferes with llm providers tool handling, so we remove them\n sanitizeBody(body, ['tools']);\n\n const { runId, runtimeContext: agentRuntimeContext, ...rest } = body;\n\n const finalRuntimeContext = new RuntimeContext<Record<string, unknown>>([\n ...Array.from(runtimeContext.entries()),\n ...Array.from(Object.entries(agentRuntimeContext ?? {})),\n ]);\n\n const streamResult = agent.approveToolCall({\n ...rest,\n runId,\n runtimeContext: finalRuntimeContext,\n abortSignal,\n format: body.format ?? 'mastra',\n });\n\n return streamResult;\n } catch (error) {\n return handleError(error, 'error streaming agent response');\n }\n}\n\nexport async function declineToolCallHandler({\n mastra,\n runtimeContext,\n agentId,\n body,\n abortSignal,\n}: Context & {\n runtimeContext: RuntimeContext;\n agentId: string;\n body: GetHITLBody<'declineToolCall'> & {\n runtimeContext?: string;\n format?: 'aisdk' | 'mastra';\n };\n abortSignal?: AbortSignal;\n}): ReturnType<Agent['declineToolCall']> {\n try {\n const agent = await getAgentFromSystem({ mastra, agentId });\n\n // UI Frameworks may send \"client tools\" in the body,\n // but it interferes with llm providers tool handling, so we remove them\n sanitizeBody(body, ['tools']);\n\n const { runId, runtimeContext: agentRuntimeContext, ...rest } = body;\n\n const finalRuntimeContext = new RuntimeContext<Record<string, unknown>>([\n ...Array.from(runtimeContext.entries()),\n ...Array.from(Object.entries(agentRuntimeContext ?? {})),\n ]);\n\n const streamResult = agent.declineToolCall({\n ...rest,\n runId,\n runtimeContext: finalRuntimeContext,\n abortSignal,\n format: body.format ?? 'mastra',\n });\n\n return streamResult;\n } catch (error) {\n return handleError(error, 'error streaming agent response');\n }\n}\n\nexport async function streamNetworkHandler({\n mastra,\n runtimeContext,\n agentId,\n body,\n // abortSignal,\n}: Context & {\n runtimeContext: RuntimeContext;\n agentId: string;\n body: GetBody<'network'> & {\n thread?: string;\n resourceId?: string;\n };\n // abortSignal?: AbortSignal;\n}): ReturnType<Agent['network']> {\n try {\n const agent = await getAgentFromSystem({ mastra, agentId });\n\n // UI Frameworks may send \"client tools\" in the body,\n // but it interferes with llm providers tool handling, so we remove them\n sanitizeBody(body, ['tools']);\n\n const { messages, runtimeContext: agentRuntimeContext, ...rest } = body;\n const finalRuntimeContext = new RuntimeContext<Record<string, unknown>>([\n ...Array.from(runtimeContext.entries()),\n ...Array.from(Object.entries(agentRuntimeContext ?? {})),\n ]);\n\n validateBody({ messages });\n\n const streamResult = agent.network(messages, {\n ...rest,\n memory: {\n thread: rest.thread ?? '',\n resource: rest.resourceId ?? '',\n options: rest.memory?.options ?? {},\n },\n runtimeContext: finalRuntimeContext,\n });\n\n return streamResult;\n } catch (error) {\n return handleError(error, 'error streaming agent loop response');\n }\n}\n\nexport async function streamUIMessageHandler({\n mastra,\n runtimeContext,\n agentId,\n body,\n abortSignal,\n}: Context & {\n runtimeContext: RuntimeContext;\n agentId: string;\n body: GetBody<'stream'> & {\n runtimeContext?: string;\n onStepFinish?: StreamTextOnStepFinishCallback<any>;\n onFinish?: StreamTextOnFinishCallback<any>;\n output?: undefined;\n };\n abortSignal?: AbortSignal;\n}): Promise<Response | undefined> {\n try {\n const agent = await getAgentFromSystem({ mastra, agentId });\n\n // UI Frameworks may send \"client tools\" in the body,\n // but it interferes with llm providers tool handling, so we remove them\n sanitizeBody(body, ['tools']);\n\n const { messages, runtimeContext: agentRuntimeContext, ...rest } = body;\n const finalRuntimeContext = new RuntimeContext<Record<string, unknown>>([\n ...Array.from(runtimeContext.entries()),\n ...Array.from(Object.entries(agentRuntimeContext ?? {})),\n ]);\n\n validateBody({ messages });\n\n const streamResult = await agent.stream(messages, {\n ...rest,\n runtimeContext: finalRuntimeContext,\n abortSignal,\n format: 'aisdk',\n });\n\n return streamResult.toUIMessageStreamResponse();\n } catch (error) {\n return handleError(error, 'error streaming agent response');\n }\n}\n\nexport async function updateAgentModelHandler({\n mastra,\n agentId,\n body,\n}: Context & {\n agentId: string;\n body: {\n modelId: string;\n provider: string;\n };\n}): Promise<{ message: string }> {\n try {\n const agent = await getAgentFromSystem({ mastra, agentId });\n\n const { modelId, provider } = body;\n\n // Use the universal Mastra router format: provider/model\n const newModel = `${provider}/${modelId}`;\n\n agent.__updateModel({ model: newModel });\n\n return { message: 'Agent model updated' };\n } catch (error) {\n return handleError(error, 'error updating agent model');\n }\n}\n\nexport async function reorderAgentModelListHandler({\n mastra,\n agentId,\n body,\n}: Context & {\n agentId: string;\n body: {\n reorderedModelIds: Array<string>;\n };\n}): Promise<{ message: string }> {\n try {\n const agent = await getAgentFromSystem({ mastra, agentId });\n\n const modelList = await agent.getModelList();\n if (!modelList || modelList.length === 0) {\n throw new HTTPException(400, { message: 'Agent model list is not found or empty' });\n }\n\n agent.reorderModels(body.reorderedModelIds);\n\n return { message: 'Model list reordered' };\n } catch (error) {\n return handleError(error, 'error reordering model list');\n }\n}\n\nexport async function updateAgentModelInModelListHandler({\n mastra,\n agentId,\n modelConfigId,\n body,\n}: Context & {\n agentId: string;\n modelConfigId: string;\n body: {\n model?: {\n modelId: string;\n provider: string;\n };\n maxRetries?: number;\n enabled?: boolean;\n };\n}): Promise<{ message: string }> {\n try {\n const agent = await getAgentFromSystem({ mastra, agentId });\n\n const { model: bodyModel, maxRetries, enabled } = body;\n\n if (!modelConfigId) {\n throw new HTTPException(400, { message: 'Model id is required' });\n }\n\n const modelList = await agent.getModelList();\n if (!modelList || modelList.length === 0) {\n throw new HTTPException(400, { message: 'Agent model list is not found or empty' });\n }\n\n const modelToUpdate = modelList.find(m => m.id === modelConfigId);\n if (!modelToUpdate) {\n throw new HTTPException(400, { message: 'Model to update is not found in agent model list' });\n }\n\n let model: string | undefined;\n if (bodyModel) {\n const { modelId, provider } = bodyModel;\n // Use the universal Mastra router format: provider/model\n model = `${provider}/${modelId}`;\n }\n\n agent.updateModelInModelList({ id: modelConfigId, model, maxRetries, enabled });\n\n return { message: 'Model list updated' };\n } catch (error) {\n return handleError(error, 'error updating model list');\n }\n}\n\nexport async function getProvidersHandler() {\n try {\n const providers = Object.entries(PROVIDER_REGISTRY).map(([id, provider]) => {\n // Check if the provider is connected by checking for its API key env var(s)\n const envVars = Array.isArray(provider.apiKeyEnvVar) ? provider.apiKeyEnvVar : [provider.apiKeyEnvVar];\n const connected = envVars.every(envVar => !!process.env[envVar]);\n\n return {\n id,\n name: provider.name,\n envVar: provider.apiKeyEnvVar,\n connected,\n docUrl: provider.docUrl,\n models: [...provider.models], // Convert readonly array to regular array\n };\n });\n\n return { providers };\n } catch (error) {\n return handleError(error, 'error fetching providers');\n }\n}\n"]}
|