@mastra/server 0.0.1-alpha.6 → 0.10.0

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.
Files changed (79) hide show
  1. package/{LICENSE → LICENSE.md} +3 -1
  2. package/README.md +48 -135
  3. package/dist/_tsup-dts-rollup.d.cts +305 -52
  4. package/dist/_tsup-dts-rollup.d.ts +305 -52
  5. package/dist/{chunk-4JINXASC.js → chunk-55DOQLP6.js} +5 -4
  6. package/dist/{chunk-QN4KF3BH.cjs → chunk-57CJTIPW.cjs} +2 -2
  7. package/dist/chunk-5SN4U5AC.cjs +508 -0
  8. package/dist/{chunk-ZLBRQFDD.cjs → chunk-64U3UDTH.cjs} +2 -2
  9. package/dist/chunk-6B4OMWT6.cjs +343 -0
  10. package/dist/chunk-75ZPJI57.cjs +9 -0
  11. package/dist/{chunk-VB7KH62D.cjs → chunk-7DLZLWJV.cjs} +16 -12
  12. package/dist/{chunk-M56ECCHK.cjs → chunk-BNEY4P4P.cjs} +20 -19
  13. package/dist/{chunk-2YONKUWB.js → chunk-C7564HUT.js} +58 -33
  14. package/dist/chunk-D4IRYCUI.cjs +235 -0
  15. package/dist/{chunk-RBQASTUP.js → chunk-DJJIUEL2.js} +13 -5
  16. package/dist/{chunk-L7XE5QTW.js → chunk-H5PTF3Y4.js} +1 -1
  17. package/dist/{chunk-3RVHWGWO.js → chunk-HFWCEP5S.js} +6 -12
  18. package/dist/chunk-LIVAK2DM.js +2001 -0
  19. package/dist/{chunk-3AHQ5RGN.js → chunk-M5ABIP7D.js} +1 -1
  20. package/dist/{chunk-CWSDZEZG.cjs → chunk-MHKNLNAN.cjs} +15 -12
  21. package/dist/chunk-MLKGABMK.js +7 -0
  22. package/dist/{chunk-TRDNDNGQ.js → chunk-NYN7KFXL.js} +1 -7
  23. package/dist/{chunk-FV45V6WC.cjs → chunk-OCWPVYNI.cjs} +0 -7
  24. package/dist/{chunk-DVPP5S6I.js → chunk-OR3CIE2H.js} +9 -6
  25. package/dist/chunk-P6SCPDYW.js +500 -0
  26. package/dist/chunk-QY36IPTP.js +331 -0
  27. package/dist/{chunk-YNSGUC2O.js → chunk-TJKLBTFB.js} +23 -7
  28. package/dist/chunk-VPNDC2DI.cjs +148 -0
  29. package/dist/{chunk-ILW7XYNJ.js → chunk-W7VCKPAD.js} +84 -60
  30. package/dist/{chunk-2JQC6JWP.js → chunk-WFBJJNCK.js} +10 -6
  31. package/dist/chunk-WUC6LSTW.js +227 -0
  32. package/dist/{chunk-2FJURXCL.cjs → chunk-Y7UWRW5X.cjs} +43 -35
  33. package/dist/{chunk-A7DF4ETD.cjs → chunk-YBVOQN4M.cjs} +22 -28
  34. package/dist/chunk-YIOVBYZH.cjs +332 -0
  35. package/dist/chunk-YWLUOY3D.cjs +2004 -0
  36. package/dist/{chunk-4C3EPMMF.cjs → chunk-ZE5AAC4I.cjs} +40 -24
  37. package/dist/server/handlers/a2a.cjs +30 -0
  38. package/dist/server/handlers/a2a.d.cts +6 -0
  39. package/dist/server/handlers/a2a.d.ts +6 -0
  40. package/dist/server/handlers/a2a.js +1 -0
  41. package/dist/server/handlers/agents.cjs +7 -7
  42. package/dist/server/handlers/agents.js +1 -1
  43. package/dist/server/handlers/error.cjs +2 -2
  44. package/dist/server/handlers/error.js +1 -1
  45. package/dist/server/handlers/legacyWorkflows.cjs +46 -0
  46. package/dist/server/handlers/legacyWorkflows.d.cts +10 -0
  47. package/dist/server/handlers/legacyWorkflows.d.ts +10 -0
  48. package/dist/server/handlers/legacyWorkflows.js +1 -0
  49. package/dist/server/handlers/logs.cjs +4 -4
  50. package/dist/server/handlers/logs.js +1 -1
  51. package/dist/server/handlers/memory.cjs +9 -9
  52. package/dist/server/handlers/memory.js +1 -1
  53. package/dist/server/handlers/network.cjs +5 -5
  54. package/dist/server/handlers/network.js +1 -1
  55. package/dist/server/handlers/telemetry.cjs +3 -3
  56. package/dist/server/handlers/telemetry.js +1 -1
  57. package/dist/server/handlers/tools.cjs +5 -5
  58. package/dist/server/handlers/tools.js +1 -1
  59. package/dist/server/handlers/utils.cjs +2 -2
  60. package/dist/server/handlers/utils.js +1 -1
  61. package/dist/server/handlers/vector.cjs +7 -7
  62. package/dist/server/handlers/vector.js +1 -1
  63. package/dist/server/handlers/voice.cjs +4 -4
  64. package/dist/server/handlers/voice.js +1 -1
  65. package/dist/server/handlers/workflows.cjs +13 -13
  66. package/dist/server/handlers/workflows.d.cts +2 -2
  67. package/dist/server/handlers/workflows.d.ts +2 -2
  68. package/dist/server/handlers/workflows.js +1 -1
  69. package/dist/server/handlers.cjs +33 -23
  70. package/dist/server/handlers.d.cts +2 -0
  71. package/dist/server/handlers.d.ts +2 -0
  72. package/dist/server/handlers.js +11 -9
  73. package/package.json +9 -7
  74. package/dist/chunk-5JOF627H.cjs +0 -123
  75. package/dist/chunk-BMA2ORRT.js +0 -152
  76. package/dist/chunk-GV52BII2.cjs +0 -160
  77. package/dist/chunk-QH6XWSXP.cjs +0 -5579
  78. package/dist/chunk-VK6FX47H.js +0 -5576
  79. package/dist/chunk-X37I6GZT.cjs +0 -308
@@ -1,46 +1,46 @@
1
1
  'use strict';
2
2
 
3
- var chunkX37I6GZT_cjs = require('../../chunk-X37I6GZT.cjs');
3
+ var chunk6B4OMWT6_cjs = require('../../chunk-6B4OMWT6.cjs');
4
4
 
5
5
 
6
6
 
7
- Object.defineProperty(exports, "createRunHandler", {
7
+ Object.defineProperty(exports, "createWorkflowRunHandler", {
8
8
  enumerable: true,
9
- get: function () { return chunkX37I6GZT_cjs.createRunHandler; }
9
+ get: function () { return chunk6B4OMWT6_cjs.createWorkflowRunHandler; }
10
10
  });
11
11
  Object.defineProperty(exports, "getWorkflowByIdHandler", {
12
12
  enumerable: true,
13
- get: function () { return chunkX37I6GZT_cjs.getWorkflowByIdHandler; }
13
+ get: function () { return chunk6B4OMWT6_cjs.getWorkflowByIdHandler; }
14
14
  });
15
- Object.defineProperty(exports, "getWorkflowRunHandler", {
15
+ Object.defineProperty(exports, "getWorkflowRunByIdHandler", {
16
16
  enumerable: true,
17
- get: function () { return chunkX37I6GZT_cjs.getWorkflowRunHandler; }
17
+ get: function () { return chunk6B4OMWT6_cjs.getWorkflowRunByIdHandler; }
18
18
  });
19
19
  Object.defineProperty(exports, "getWorkflowRunsHandler", {
20
20
  enumerable: true,
21
- get: function () { return chunkX37I6GZT_cjs.getWorkflowRunsHandler; }
21
+ get: function () { return chunk6B4OMWT6_cjs.getWorkflowRunsHandler; }
22
22
  });
23
23
  Object.defineProperty(exports, "getWorkflowsHandler", {
24
24
  enumerable: true,
25
- get: function () { return chunkX37I6GZT_cjs.getWorkflowsHandler; }
25
+ get: function () { return chunk6B4OMWT6_cjs.getWorkflowsHandler; }
26
26
  });
27
27
  Object.defineProperty(exports, "resumeAsyncWorkflowHandler", {
28
28
  enumerable: true,
29
- get: function () { return chunkX37I6GZT_cjs.resumeAsyncWorkflowHandler; }
29
+ get: function () { return chunk6B4OMWT6_cjs.resumeAsyncWorkflowHandler; }
30
30
  });
31
31
  Object.defineProperty(exports, "resumeWorkflowHandler", {
32
32
  enumerable: true,
33
- get: function () { return chunkX37I6GZT_cjs.resumeWorkflowHandler; }
33
+ get: function () { return chunk6B4OMWT6_cjs.resumeWorkflowHandler; }
34
34
  });
35
35
  Object.defineProperty(exports, "startAsyncWorkflowHandler", {
36
36
  enumerable: true,
37
- get: function () { return chunkX37I6GZT_cjs.startAsyncWorkflowHandler; }
37
+ get: function () { return chunk6B4OMWT6_cjs.startAsyncWorkflowHandler; }
38
38
  });
39
39
  Object.defineProperty(exports, "startWorkflowRunHandler", {
40
40
  enumerable: true,
41
- get: function () { return chunkX37I6GZT_cjs.startWorkflowRunHandler; }
41
+ get: function () { return chunk6B4OMWT6_cjs.startWorkflowRunHandler; }
42
42
  });
43
43
  Object.defineProperty(exports, "watchWorkflowHandler", {
44
44
  enumerable: true,
45
- get: function () { return chunkX37I6GZT_cjs.watchWorkflowHandler; }
45
+ get: function () { return chunk6B4OMWT6_cjs.watchWorkflowHandler; }
46
46
  });
@@ -1,8 +1,8 @@
1
1
  export { getWorkflowsHandler } from '../../_tsup-dts-rollup.cjs';
2
2
  export { getWorkflowByIdHandler } from '../../_tsup-dts-rollup.cjs';
3
+ export { getWorkflowRunByIdHandler } from '../../_tsup-dts-rollup.cjs';
4
+ export { createWorkflowRunHandler } from '../../_tsup-dts-rollup.cjs';
3
5
  export { startAsyncWorkflowHandler } from '../../_tsup-dts-rollup.cjs';
4
- export { getWorkflowRunHandler } from '../../_tsup-dts-rollup.cjs';
5
- export { createRunHandler } from '../../_tsup-dts-rollup.cjs';
6
6
  export { startWorkflowRunHandler } from '../../_tsup-dts-rollup.cjs';
7
7
  export { watchWorkflowHandler } from '../../_tsup-dts-rollup.cjs';
8
8
  export { resumeAsyncWorkflowHandler } from '../../_tsup-dts-rollup.cjs';
@@ -1,8 +1,8 @@
1
1
  export { getWorkflowsHandler } from '../../_tsup-dts-rollup.js';
2
2
  export { getWorkflowByIdHandler } from '../../_tsup-dts-rollup.js';
3
+ export { getWorkflowRunByIdHandler } from '../../_tsup-dts-rollup.js';
4
+ export { createWorkflowRunHandler } from '../../_tsup-dts-rollup.js';
3
5
  export { startAsyncWorkflowHandler } from '../../_tsup-dts-rollup.js';
4
- export { getWorkflowRunHandler } from '../../_tsup-dts-rollup.js';
5
- export { createRunHandler } from '../../_tsup-dts-rollup.js';
6
6
  export { startWorkflowRunHandler } from '../../_tsup-dts-rollup.js';
7
7
  export { watchWorkflowHandler } from '../../_tsup-dts-rollup.js';
8
8
  export { resumeAsyncWorkflowHandler } from '../../_tsup-dts-rollup.js';
@@ -1 +1 @@
1
- export { createRunHandler, getWorkflowByIdHandler, getWorkflowRunHandler, getWorkflowRunsHandler, getWorkflowsHandler, resumeAsyncWorkflowHandler, resumeWorkflowHandler, startAsyncWorkflowHandler, startWorkflowRunHandler, watchWorkflowHandler } from '../../chunk-ILW7XYNJ.js';
1
+ export { createWorkflowRunHandler, getWorkflowByIdHandler, getWorkflowRunByIdHandler, getWorkflowRunsHandler, getWorkflowsHandler, resumeAsyncWorkflowHandler, resumeWorkflowHandler, startAsyncWorkflowHandler, startWorkflowRunHandler, watchWorkflowHandler } from '../../chunk-QY36IPTP.js';
@@ -1,50 +1,60 @@
1
1
  'use strict';
2
2
 
3
- var chunk4C3EPMMF_cjs = require('../chunk-4C3EPMMF.cjs');
4
- var chunkM56ECCHK_cjs = require('../chunk-M56ECCHK.cjs');
5
- var chunkA7DF4ETD_cjs = require('../chunk-A7DF4ETD.cjs');
6
- var chunkX37I6GZT_cjs = require('../chunk-X37I6GZT.cjs');
7
- var chunkGV52BII2_cjs = require('../chunk-GV52BII2.cjs');
8
- var chunkVB7KH62D_cjs = require('../chunk-VB7KH62D.cjs');
9
- var chunk2FJURXCL_cjs = require('../chunk-2FJURXCL.cjs');
10
- var chunk5JOF627H_cjs = require('../chunk-5JOF627H.cjs');
11
- var chunkCWSDZEZG_cjs = require('../chunk-CWSDZEZG.cjs');
3
+ var chunkVPNDC2DI_cjs = require('../chunk-VPNDC2DI.cjs');
4
+ var chunkMHKNLNAN_cjs = require('../chunk-MHKNLNAN.cjs');
5
+ var chunkZE5AAC4I_cjs = require('../chunk-ZE5AAC4I.cjs');
6
+ var chunkBNEY4P4P_cjs = require('../chunk-BNEY4P4P.cjs');
7
+ var chunkYBVOQN4M_cjs = require('../chunk-YBVOQN4M.cjs');
8
+ var chunk6B4OMWT6_cjs = require('../chunk-6B4OMWT6.cjs');
9
+ var chunk5SN4U5AC_cjs = require('../chunk-5SN4U5AC.cjs');
10
+ var chunkD4IRYCUI_cjs = require('../chunk-D4IRYCUI.cjs');
11
+ var chunkYIOVBYZH_cjs = require('../chunk-YIOVBYZH.cjs');
12
+ var chunk7DLZLWJV_cjs = require('../chunk-7DLZLWJV.cjs');
13
+ var chunkY7UWRW5X_cjs = require('../chunk-Y7UWRW5X.cjs');
12
14
 
13
15
 
14
16
 
17
+ Object.defineProperty(exports, "network", {
18
+ enumerable: true,
19
+ get: function () { return chunkVPNDC2DI_cjs.network_exports; }
20
+ });
21
+ Object.defineProperty(exports, "telemetry", {
22
+ enumerable: true,
23
+ get: function () { return chunkMHKNLNAN_cjs.telemetry_exports; }
24
+ });
15
25
  Object.defineProperty(exports, "tools", {
16
26
  enumerable: true,
17
- get: function () { return chunk4C3EPMMF_cjs.tools_exports; }
27
+ get: function () { return chunkZE5AAC4I_cjs.tools_exports; }
18
28
  });
19
29
  Object.defineProperty(exports, "vector", {
20
30
  enumerable: true,
21
- get: function () { return chunkM56ECCHK_cjs.vector_exports; }
31
+ get: function () { return chunkBNEY4P4P_cjs.vector_exports; }
22
32
  });
23
33
  Object.defineProperty(exports, "voice", {
24
34
  enumerable: true,
25
- get: function () { return chunkA7DF4ETD_cjs.voice_exports; }
35
+ get: function () { return chunkYBVOQN4M_cjs.voice_exports; }
26
36
  });
27
37
  Object.defineProperty(exports, "workflows", {
28
38
  enumerable: true,
29
- get: function () { return chunkX37I6GZT_cjs.workflows_exports; }
39
+ get: function () { return chunk6B4OMWT6_cjs.workflows_exports; }
30
40
  });
31
- Object.defineProperty(exports, "agents", {
41
+ Object.defineProperty(exports, "a2a", {
32
42
  enumerable: true,
33
- get: function () { return chunkGV52BII2_cjs.agents_exports; }
43
+ get: function () { return chunk5SN4U5AC_cjs.a2a_exports; }
34
44
  });
35
- Object.defineProperty(exports, "logs", {
45
+ Object.defineProperty(exports, "agents", {
36
46
  enumerable: true,
37
- get: function () { return chunkVB7KH62D_cjs.logs_exports; }
47
+ get: function () { return chunkD4IRYCUI_cjs.agents_exports; }
38
48
  });
39
- Object.defineProperty(exports, "memory", {
49
+ Object.defineProperty(exports, "legacyWorkflows", {
40
50
  enumerable: true,
41
- get: function () { return chunk2FJURXCL_cjs.memory_exports; }
51
+ get: function () { return chunkYIOVBYZH_cjs.legacyWorkflows_exports; }
42
52
  });
43
- Object.defineProperty(exports, "network", {
53
+ Object.defineProperty(exports, "logs", {
44
54
  enumerable: true,
45
- get: function () { return chunk5JOF627H_cjs.network_exports; }
55
+ get: function () { return chunk7DLZLWJV_cjs.logs_exports; }
46
56
  });
47
- Object.defineProperty(exports, "telemetry", {
57
+ Object.defineProperty(exports, "memory", {
48
58
  enumerable: true,
49
- get: function () { return chunkCWSDZEZG_cjs.telemetry_exports; }
59
+ get: function () { return chunkY7UWRW5X_cjs.memory_exports; }
50
60
  });
@@ -1,9 +1,11 @@
1
1
  export { agents } from '../_tsup-dts-rollup.cjs';
2
+ export { a2a } from '../_tsup-dts-rollup.cjs';
2
3
  export { logs } from '../_tsup-dts-rollup.cjs';
3
4
  export { memory } from '../_tsup-dts-rollup.cjs';
4
5
  export { network } from '../_tsup-dts-rollup.cjs';
5
6
  export { telemetry } from '../_tsup-dts-rollup.cjs';
6
7
  export { tools } from '../_tsup-dts-rollup.cjs';
8
+ export { legacyWorkflows } from '../_tsup-dts-rollup.cjs';
7
9
  export { workflows } from '../_tsup-dts-rollup.cjs';
8
10
  export { vector } from '../_tsup-dts-rollup.cjs';
9
11
  export { voice } from '../_tsup-dts-rollup.cjs';
@@ -1,9 +1,11 @@
1
1
  export { agents } from '../_tsup-dts-rollup.js';
2
+ export { a2a } from '../_tsup-dts-rollup.js';
2
3
  export { logs } from '../_tsup-dts-rollup.js';
3
4
  export { memory } from '../_tsup-dts-rollup.js';
4
5
  export { network } from '../_tsup-dts-rollup.js';
5
6
  export { telemetry } from '../_tsup-dts-rollup.js';
6
7
  export { tools } from '../_tsup-dts-rollup.js';
8
+ export { legacyWorkflows } from '../_tsup-dts-rollup.js';
7
9
  export { workflows } from '../_tsup-dts-rollup.js';
8
10
  export { vector } from '../_tsup-dts-rollup.js';
9
11
  export { voice } from '../_tsup-dts-rollup.js';
@@ -1,9 +1,11 @@
1
- export { tools_exports as tools } from '../chunk-YNSGUC2O.js';
2
- export { vector_exports as vector } from '../chunk-4JINXASC.js';
3
- export { voice_exports as voice } from '../chunk-3RVHWGWO.js';
4
- export { workflows_exports as workflows } from '../chunk-ILW7XYNJ.js';
5
- export { agents_exports as agents } from '../chunk-BMA2ORRT.js';
6
- export { logs_exports as logs } from '../chunk-2JQC6JWP.js';
7
- export { memory_exports as memory } from '../chunk-RBQASTUP.js';
8
- export { network_exports as network } from '../chunk-2YONKUWB.js';
9
- export { telemetry_exports as telemetry } from '../chunk-DVPP5S6I.js';
1
+ export { network_exports as network } from '../chunk-C7564HUT.js';
2
+ export { telemetry_exports as telemetry } from '../chunk-OR3CIE2H.js';
3
+ export { tools_exports as tools } from '../chunk-TJKLBTFB.js';
4
+ export { vector_exports as vector } from '../chunk-55DOQLP6.js';
5
+ export { voice_exports as voice } from '../chunk-HFWCEP5S.js';
6
+ export { workflows_exports as workflows } from '../chunk-QY36IPTP.js';
7
+ export { a2a_exports as a2a } from '../chunk-P6SCPDYW.js';
8
+ export { agents_exports as agents } from '../chunk-WUC6LSTW.js';
9
+ export { legacyWorkflows_exports as legacyWorkflows } from '../chunk-W7VCKPAD.js';
10
+ export { logs_exports as logs } from '../chunk-WFBJJNCK.js';
11
+ export { memory_exports as memory } from '../chunk-DJJIUEL2.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/server",
3
- "version": "0.0.1-alpha.6",
3
+ "version": "0.10.0",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "files": [
@@ -43,23 +43,25 @@
43
43
  },
44
44
  "keywords": [],
45
45
  "author": "",
46
- "license": "ISC",
46
+ "license": "Elastic-2.0",
47
47
  "dependencies": {},
48
48
  "peerDependencies": {
49
- "@mastra/core": "^0.8.0-alpha.8"
49
+ "@mastra/core": "^0.10.0",
50
+ "zod": "^3.0.0"
50
51
  },
51
52
  "devDependencies": {
52
53
  "@ai-sdk/openai": "^1.3.2",
53
- "@microsoft/api-extractor": "^7.52.1",
54
+ "@microsoft/api-extractor": "^7.52.5",
54
55
  "@types/node": "^20.17.27",
55
56
  "eslint": "^9.23.0",
56
57
  "superjson": "^2.2.2",
57
58
  "tsup": "^8.4.0",
58
59
  "typescript": "^5.8.2",
59
60
  "vitest": "^2.1.9",
60
- "zod-to-json-schema": "^3.24.3",
61
- "@mastra/core": "0.8.0-alpha.8",
62
- "@internal/lint": "0.0.1"
61
+ "zod": "^3.24.3",
62
+ "zod-to-json-schema": "^3.24.5",
63
+ "@internal/lint": "0.0.6",
64
+ "@mastra/core": "0.10.0"
63
65
  },
64
66
  "scripts": {
65
67
  "build": "tsup src/index.ts src/server/handlers.ts src/server/handlers/*.ts !src/server/handlers/*.test.ts --format esm,cjs --clean --experimental-dts --treeshake=smallest --splitting",
@@ -1,123 +0,0 @@
1
- 'use strict';
2
-
3
- var chunkQN4KF3BH_cjs = require('./chunk-QN4KF3BH.cjs');
4
- var chunkZLBRQFDD_cjs = require('./chunk-ZLBRQFDD.cjs');
5
- var chunkFV45V6WC_cjs = require('./chunk-FV45V6WC.cjs');
6
-
7
- // src/server/handlers/network.ts
8
- var network_exports = {};
9
- chunkFV45V6WC_cjs.__export(network_exports, {
10
- generateHandler: () => generateHandler,
11
- getNetworkByIdHandler: () => getNetworkByIdHandler,
12
- getNetworksHandler: () => getNetworksHandler,
13
- streamGenerateHandler: () => streamGenerateHandler
14
- });
15
- async function getNetworksHandler({ mastra }) {
16
- try {
17
- const networks = mastra.getNetworks();
18
- const serializedNetworks = networks.map((network) => {
19
- const routingAgent = network.getRoutingAgent();
20
- const agents = network.getAgents();
21
- return {
22
- id: network.formatAgentId(routingAgent.name),
23
- name: routingAgent.name,
24
- instructions: routingAgent.instructions,
25
- agents: agents.map((agent) => ({
26
- name: agent.name,
27
- provider: agent.llm?.getProvider(),
28
- modelId: agent.llm?.getModelId()
29
- })),
30
- routingModel: {
31
- provider: routingAgent.llm?.getProvider(),
32
- modelId: routingAgent.llm?.getModelId()
33
- }
34
- };
35
- });
36
- return serializedNetworks;
37
- } catch (error) {
38
- return chunkZLBRQFDD_cjs.handleError(error, "Error getting networks");
39
- }
40
- }
41
- async function getNetworkByIdHandler({ mastra, networkId }) {
42
- try {
43
- const networks = mastra.getNetworks();
44
- const network = networks.find((network2) => {
45
- const routingAgent2 = network2.getRoutingAgent();
46
- return network2.formatAgentId(routingAgent2.name) === networkId;
47
- });
48
- if (!network) {
49
- throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Network not found" });
50
- }
51
- const routingAgent = network.getRoutingAgent();
52
- const agents = network.getAgents();
53
- const serializedNetwork = {
54
- id: network.formatAgentId(routingAgent.name),
55
- name: routingAgent.name,
56
- instructions: routingAgent.instructions,
57
- agents: agents.map((agent) => ({
58
- name: agent.name,
59
- provider: agent.llm?.getProvider(),
60
- modelId: agent.llm?.getModelId()
61
- })),
62
- routingModel: {
63
- provider: routingAgent.llm?.getProvider(),
64
- modelId: routingAgent.llm?.getModelId()
65
- }
66
- };
67
- return serializedNetwork;
68
- } catch (error) {
69
- return chunkZLBRQFDD_cjs.handleError(error, "Error getting network by ID");
70
- }
71
- }
72
- async function generateHandler({
73
- mastra,
74
- networkId,
75
- body
76
- }) {
77
- try {
78
- const network = mastra.getNetwork(networkId);
79
- if (!network) {
80
- throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Network not found" });
81
- }
82
- chunkQN4KF3BH_cjs.validateBody({ messages: body.messages });
83
- const { messages, ...rest } = body;
84
- const result = await network.generate(messages, rest);
85
- return result;
86
- } catch (error) {
87
- return chunkZLBRQFDD_cjs.handleError(error, "Error generating from network");
88
- }
89
- }
90
- async function streamGenerateHandler({
91
- mastra,
92
- networkId,
93
- body
94
- }) {
95
- try {
96
- const network = mastra.getNetwork(networkId);
97
- if (!network) {
98
- throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Network not found" });
99
- }
100
- chunkQN4KF3BH_cjs.validateBody({ messages: body.messages });
101
- const { messages, output, ...rest } = body;
102
- const streamResult = await network.stream(messages, {
103
- output,
104
- ...rest
105
- });
106
- const streamResponse = output ? streamResult.toTextStreamResponse() : streamResult.toDataStreamResponse({
107
- sendUsage: true,
108
- sendReasoning: true,
109
- getErrorMessage: (error) => {
110
- return `An error occurred while processing your request. ${error instanceof Error ? error.message : JSON.stringify(error)}`;
111
- }
112
- });
113
- return streamResponse;
114
- } catch (error) {
115
- return chunkZLBRQFDD_cjs.handleError(error, "Error streaming from network");
116
- }
117
- }
118
-
119
- exports.generateHandler = generateHandler;
120
- exports.getNetworkByIdHandler = getNetworkByIdHandler;
121
- exports.getNetworksHandler = getNetworksHandler;
122
- exports.network_exports = network_exports;
123
- exports.streamGenerateHandler = streamGenerateHandler;
@@ -1,152 +0,0 @@
1
- import { stringify, esm_default } from './chunk-VK6FX47H.js';
2
- import { validateBody } from './chunk-L7XE5QTW.js';
3
- import { handleError } from './chunk-3AHQ5RGN.js';
4
- import { __export, HTTPException } from './chunk-TRDNDNGQ.js';
5
-
6
- // src/server/handlers/agents.ts
7
- var agents_exports = {};
8
- __export(agents_exports, {
9
- generateHandler: () => generateHandler,
10
- getAgentByIdHandler: () => getAgentByIdHandler,
11
- getAgentsHandler: () => getAgentsHandler,
12
- getEvalsByAgentIdHandler: () => getEvalsByAgentIdHandler,
13
- getLiveEvalsByAgentIdHandler: () => getLiveEvalsByAgentIdHandler,
14
- streamGenerateHandler: () => streamGenerateHandler
15
- });
16
- async function getAgentsHandler({ mastra }) {
17
- try {
18
- const agents = mastra.getAgents();
19
- const serializedAgents = Object.entries(agents).reduce((acc, [_id, _agent]) => {
20
- const agent = _agent;
21
- const serializedAgentTools = Object.entries(agent?.tools || {}).reduce((acc2, [key, tool]) => {
22
- const _tool = tool;
23
- acc2[key] = {
24
- ..._tool,
25
- inputSchema: _tool.inputSchema ? stringify(esm_default(_tool.inputSchema)) : void 0,
26
- outputSchema: _tool.outputSchema ? stringify(esm_default(_tool.outputSchema)) : void 0
27
- };
28
- return acc2;
29
- }, {});
30
- acc[_id] = {
31
- name: agent.name,
32
- instructions: agent.instructions,
33
- tools: serializedAgentTools,
34
- provider: agent.llm?.getProvider(),
35
- modelId: agent.llm?.getModelId()
36
- };
37
- return acc;
38
- }, {});
39
- return serializedAgents;
40
- } catch (error) {
41
- return handleError(error, "Error getting agents");
42
- }
43
- }
44
- async function getAgentByIdHandler({ mastra, agentId }) {
45
- try {
46
- const agent = mastra.getAgent(agentId);
47
- if (!agent) {
48
- throw new HTTPException(404, { message: "Agent not found" });
49
- }
50
- const serializedAgentTools = Object.entries(agent?.tools || {}).reduce((acc, [key, tool]) => {
51
- const _tool = tool;
52
- acc[key] = {
53
- ..._tool,
54
- inputSchema: _tool.inputSchema ? stringify(esm_default(_tool.inputSchema)) : void 0,
55
- outputSchema: _tool.outputSchema ? stringify(esm_default(_tool.outputSchema)) : void 0
56
- };
57
- return acc;
58
- }, {});
59
- return {
60
- name: agent.name,
61
- instructions: agent.instructions,
62
- tools: serializedAgentTools,
63
- provider: agent.llm?.getProvider(),
64
- modelId: agent.llm?.getModelId()
65
- };
66
- } catch (error) {
67
- return handleError(error, "Error getting agent");
68
- }
69
- }
70
- async function getEvalsByAgentIdHandler({ mastra, agentId }) {
71
- try {
72
- const agent = mastra.getAgent(agentId);
73
- const evals = await mastra.getStorage()?.__getEvalsByAgentName?.(agent.name, "test") || [];
74
- return {
75
- id: agentId,
76
- name: agent.name,
77
- instructions: agent.instructions,
78
- evals
79
- };
80
- } catch (error) {
81
- return handleError(error, "Error getting test evals");
82
- }
83
- }
84
- async function getLiveEvalsByAgentIdHandler({ mastra, agentId }) {
85
- try {
86
- const agent = mastra.getAgent(agentId);
87
- const evals = await mastra.getStorage()?.__getEvalsByAgentName?.(agent.name, "live") || [];
88
- return {
89
- id: agentId,
90
- name: agent.name,
91
- instructions: agent.instructions,
92
- evals
93
- };
94
- } catch (error) {
95
- return handleError(error, "Error getting live evals");
96
- }
97
- }
98
- async function generateHandler({
99
- mastra,
100
- agentId,
101
- body
102
- }) {
103
- try {
104
- const agent = mastra.getAgent(agentId);
105
- if (!agent) {
106
- throw new HTTPException(404, { message: "Agent not found" });
107
- }
108
- const { messages, resourceId, resourceid, ...rest } = body;
109
- const finalResourceId = resourceId ?? resourceid;
110
- validateBody({ messages });
111
- const result = await agent.generate(messages, {
112
- ...rest,
113
- // @ts-expect-error TODO fix types
114
- resourceId: finalResourceId
115
- });
116
- return result;
117
- } catch (error) {
118
- return handleError(error, "Error generating from agent");
119
- }
120
- }
121
- async function streamGenerateHandler({
122
- mastra,
123
- agentId,
124
- body
125
- }) {
126
- try {
127
- const agent = mastra.getAgent(agentId);
128
- if (!agent) {
129
- throw new HTTPException(404, { message: "Agent not found" });
130
- }
131
- const { messages, resourceId, resourceid, ...rest } = body;
132
- const finalResourceId = resourceId ?? resourceid;
133
- validateBody({ messages });
134
- const streamResult = await agent.stream(messages, {
135
- ...rest,
136
- // @ts-expect-error TODO fix types
137
- resourceId: finalResourceId
138
- });
139
- const streamResponse = rest.output ? streamResult.toTextStreamResponse() : streamResult.toDataStreamResponse({
140
- sendUsage: true,
141
- sendReasoning: true,
142
- getErrorMessage: (error) => {
143
- return `An error occurred while processing your request. ${error instanceof Error ? error.message : JSON.stringify(error)}`;
144
- }
145
- });
146
- return streamResponse;
147
- } catch (error) {
148
- throw new HTTPException(error?.status ?? 500, { message: error?.message ?? "Error streaming from agent" });
149
- }
150
- }
151
-
152
- export { agents_exports, generateHandler, getAgentByIdHandler, getAgentsHandler, getEvalsByAgentIdHandler, getLiveEvalsByAgentIdHandler, streamGenerateHandler };