@mastra/server 0.0.0-remove-cloud-span-transform-20250425214156 → 0.0.0-scorers-api-v2-20250801171841
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/LICENSE.md +11 -42
- package/README.md +48 -135
- package/dist/chunk-2XIJW7SV.cjs +310 -0
- package/dist/chunk-2XIJW7SV.cjs.map +1 -0
- package/dist/chunk-4CEZIJWJ.cjs +150 -0
- package/dist/chunk-4CEZIJWJ.cjs.map +1 -0
- package/dist/chunk-4MQU6AJN.js +83 -0
- package/dist/chunk-4MQU6AJN.js.map +1 -0
- package/dist/{chunk-QN4KF3BH.cjs → chunk-4QSNRCOT.cjs} +4 -2
- package/dist/chunk-4QSNRCOT.cjs.map +1 -0
- package/dist/chunk-4US5W7PH.cjs +120 -0
- package/dist/chunk-4US5W7PH.cjs.map +1 -0
- package/dist/chunk-7FHF55WA.js +2041 -0
- package/dist/chunk-7FHF55WA.js.map +1 -0
- package/dist/{chunk-FV45V6WC.cjs → chunk-7NADHFD2.cjs} +3 -7
- package/dist/chunk-7NADHFD2.cjs.map +1 -0
- package/dist/chunk-BED2O446.cjs +88 -0
- package/dist/chunk-BED2O446.cjs.map +1 -0
- package/dist/chunk-BUOJL3MN.js +529 -0
- package/dist/chunk-BUOJL3MN.js.map +1 -0
- package/dist/chunk-CY4TP3FK.js +16 -0
- package/dist/chunk-CY4TP3FK.js.map +1 -0
- package/dist/{chunk-4JINXASC.js → chunk-G7NVCO5M.js} +7 -4
- package/dist/chunk-G7NVCO5M.js.map +1 -0
- package/dist/chunk-GASWM5HJ.cjs +514 -0
- package/dist/chunk-GASWM5HJ.cjs.map +1 -0
- package/dist/{chunk-Q6SHQECN.js → chunk-HWHKM67I.js} +36 -10
- package/dist/chunk-HWHKM67I.js.map +1 -0
- package/dist/chunk-HXIOPAHT.js +541 -0
- package/dist/chunk-HXIOPAHT.js.map +1 -0
- package/dist/{chunk-7IWQE76Z.cjs → chunk-ILCWPBYQ.cjs} +18 -10
- package/dist/chunk-ILCWPBYQ.cjs.map +1 -0
- package/dist/chunk-JGVY3KWV.cjs +334 -0
- package/dist/chunk-JGVY3KWV.cjs.map +1 -0
- package/dist/chunk-LRUH33B4.cjs +2044 -0
- package/dist/chunk-LRUH33B4.cjs.map +1 -0
- package/dist/{chunk-TRDNDNGQ.js → chunk-MMROOK5J.js} +4 -7
- package/dist/chunk-MMROOK5J.js.map +1 -0
- package/dist/{chunk-M56ECCHK.cjs → chunk-NCS2OXX6.cjs} +22 -19
- package/dist/chunk-NCS2OXX6.cjs.map +1 -0
- package/dist/{chunk-D3G23FP3.cjs → chunk-O4I563YW.cjs} +26 -22
- package/dist/chunk-O4I563YW.cjs.map +1 -0
- package/dist/{chunk-L7XE5QTW.js → chunk-OW4FX5TS.js} +3 -1
- package/dist/chunk-OW4FX5TS.js.map +1 -0
- package/dist/chunk-PZ5AY32C.js +9 -0
- package/dist/chunk-PZ5AY32C.js.map +1 -0
- package/dist/chunk-Q7SFCCGT.cjs +11 -0
- package/dist/chunk-Q7SFCCGT.cjs.map +1 -0
- package/dist/chunk-RE4RPXT2.cjs +18 -0
- package/dist/chunk-RE4RPXT2.cjs.map +1 -0
- package/dist/chunk-S37KCGOR.cjs +546 -0
- package/dist/chunk-S37KCGOR.cjs.map +1 -0
- package/dist/{chunk-WTHDCRMY.js → chunk-SQ7KKIH3.js} +14 -6
- package/dist/chunk-SQ7KKIH3.js.map +1 -0
- package/dist/chunk-TRWPUPGD.js +506 -0
- package/dist/chunk-TRWPUPGD.js.map +1 -0
- package/dist/chunk-TXAQU2XN.js +151 -0
- package/dist/chunk-TXAQU2XN.js.map +1 -0
- package/dist/{chunk-LFOBHRFO.js → chunk-UVOSITKU.js} +76 -59
- package/dist/chunk-UVOSITKU.js.map +1 -0
- package/dist/chunk-VIGPWTDA.cjs +159 -0
- package/dist/chunk-VIGPWTDA.cjs.map +1 -0
- package/dist/chunk-VOY6MGKA.js +301 -0
- package/dist/chunk-VOY6MGKA.js.map +1 -0
- package/dist/chunk-X5SDJOY6.cjs +557 -0
- package/dist/chunk-X5SDJOY6.cjs.map +1 -0
- package/dist/{chunk-RE6YL32K.js → chunk-Y3J45CVZ.js} +54 -30
- package/dist/chunk-Y3J45CVZ.js.map +1 -0
- package/dist/{chunk-5JNVY6DU.js → chunk-YS66MFDY.js} +9 -5
- package/dist/chunk-YS66MFDY.js.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/server/a2a/protocol.d.ts +8 -0
- package/dist/server/a2a/protocol.d.ts.map +1 -0
- package/dist/server/a2a/store.d.ts +14 -0
- package/dist/server/a2a/store.d.ts.map +1 -0
- package/dist/server/a2a/tasks.d.ts +20 -0
- package/dist/server/a2a/tasks.d.ts.map +1 -0
- package/dist/server/handlers/a2a.cjs +32 -0
- package/dist/server/handlers/a2a.cjs.map +1 -0
- package/dist/server/handlers/a2a.d.ts +66 -0
- package/dist/server/handlers/a2a.d.ts.map +1 -0
- package/dist/server/handlers/a2a.js +3 -0
- package/dist/server/handlers/a2a.js.map +1 -0
- package/dist/server/handlers/agents.cjs +13 -7
- package/dist/server/handlers/agents.cjs.map +1 -0
- package/dist/server/handlers/agents.d.ts +81 -6
- package/dist/server/handlers/agents.d.ts.map +1 -0
- package/dist/server/handlers/agents.js +3 -1
- package/dist/server/handlers/agents.js.map +1 -0
- package/dist/server/handlers/error.cjs +4 -2
- package/dist/server/handlers/error.cjs.map +1 -0
- package/dist/server/handlers/error.d.ts +2 -1
- package/dist/server/handlers/error.d.ts.map +1 -0
- package/dist/server/handlers/error.js +3 -1
- package/dist/server/handlers/error.js.map +1 -0
- package/dist/server/handlers/legacyWorkflows.cjs +48 -0
- package/dist/server/handlers/legacyWorkflows.cjs.map +1 -0
- package/dist/server/handlers/legacyWorkflows.d.ts +59 -0
- package/dist/server/handlers/legacyWorkflows.d.ts.map +1 -0
- package/dist/server/handlers/legacyWorkflows.js +3 -0
- package/dist/server/handlers/legacyWorkflows.js.map +1 -0
- package/dist/server/handlers/logs.cjs +6 -4
- package/dist/server/handlers/logs.cjs.map +1 -0
- package/dist/server/handlers/logs.d.ts +34 -3
- package/dist/server/handlers/logs.d.ts.map +1 -0
- package/dist/server/handlers/logs.js +3 -1
- package/dist/server/handlers/logs.js.map +1 -0
- package/dist/server/handlers/memory.cjs +35 -9
- package/dist/server/handlers/memory.cjs.map +1 -0
- package/dist/server/handlers/memory.d.ts +113 -8
- package/dist/server/handlers/memory.d.ts.map +1 -0
- package/dist/server/handlers/memory.js +3 -1
- package/dist/server/handlers/memory.js.map +1 -0
- package/dist/server/handlers/network.cjs +7 -5
- package/dist/server/handlers/network.cjs.map +1 -0
- package/dist/server/handlers/network.d.ts +50 -4
- package/dist/server/handlers/network.d.ts.map +1 -0
- package/dist/server/handlers/network.js +3 -1
- package/dist/server/handlers/network.js.map +1 -0
- package/dist/server/handlers/scores.cjs +32 -0
- package/dist/server/handlers/scores.cjs.map +1 -0
- package/dist/server/handlers/scores.d.ts +49 -0
- package/dist/server/handlers/scores.d.ts.map +1 -0
- package/dist/server/handlers/scores.js +3 -0
- package/dist/server/handlers/scores.js.map +1 -0
- package/dist/server/handlers/telemetry.cjs +5 -3
- package/dist/server/handlers/telemetry.cjs.map +1 -0
- package/dist/server/handlers/telemetry.d.ts +32 -2
- package/dist/server/handlers/telemetry.d.ts.map +1 -0
- package/dist/server/handlers/telemetry.js +3 -1
- package/dist/server/handlers/telemetry.js.map +1 -0
- package/dist/server/handlers/tools.cjs +7 -5
- package/dist/server/handlers/tools.cjs.map +1 -0
- package/dist/server/handlers/tools.d.ts +21 -4
- package/dist/server/handlers/tools.d.ts.map +1 -0
- package/dist/server/handlers/tools.js +3 -1
- package/dist/server/handlers/tools.js.map +1 -0
- package/dist/server/handlers/utils.cjs +4 -2
- package/dist/server/handlers/utils.cjs.map +1 -0
- package/dist/server/handlers/utils.d.ts +2 -1
- package/dist/server/handlers/utils.d.ts.map +1 -0
- package/dist/server/handlers/utils.js +3 -1
- package/dist/server/handlers/utils.js.map +1 -0
- package/dist/server/handlers/vNextNetwork.cjs +220 -0
- package/dist/server/handlers/vNextNetwork.cjs.map +1 -0
- package/dist/server/handlers/vNextNetwork.d.ts +179 -0
- package/dist/server/handlers/vNextNetwork.d.ts.map +1 -0
- package/dist/server/handlers/vNextNetwork.js +213 -0
- package/dist/server/handlers/vNextNetwork.js.map +1 -0
- package/dist/server/handlers/vector.cjs +9 -7
- package/dist/server/handlers/vector.cjs.map +1 -0
- package/dist/server/handlers/vector.d.ts +51 -6
- package/dist/server/handlers/vector.d.ts.map +1 -0
- package/dist/server/handlers/vector.js +3 -1
- package/dist/server/handlers/vector.js.map +1 -0
- package/dist/server/handlers/voice.cjs +10 -4
- package/dist/server/handlers/voice.cjs.map +1 -0
- package/dist/server/handlers/voice.d.ts +39 -3
- package/dist/server/handlers/voice.d.ts.map +1 -0
- package/dist/server/handlers/voice.js +3 -1
- package/dist/server/handlers/voice.js.map +1 -0
- package/dist/server/handlers/workflows.cjs +35 -13
- package/dist/server/handlers/workflows.cjs.map +1 -0
- package/dist/server/handlers/workflows.d.ts +88 -10
- package/dist/server/handlers/workflows.d.ts.map +1 -0
- package/dist/server/handlers/workflows.js +3 -1
- package/dist/server/handlers/workflows.js.map +1 -0
- package/dist/server/handlers.cjs +41 -29
- package/dist/server/handlers.cjs.map +1 -0
- package/dist/server/handlers.d.ts +13 -10
- package/dist/server/handlers.d.ts.map +1 -0
- package/dist/server/handlers.js +14 -10
- package/dist/server/handlers.js.map +1 -0
- package/dist/server/http-exception.d.ts +87 -0
- package/dist/server/http-exception.d.ts.map +1 -0
- package/dist/server/types.d.ts +10 -0
- package/dist/server/types.d.ts.map +1 -0
- package/package.json +17 -15
- package/dist/_tsup-dts-rollup.d.cts +0 -648
- package/dist/_tsup-dts-rollup.d.ts +0 -648
- package/dist/chunk-2FJURXCL.cjs +0 -213
- package/dist/chunk-3AHQ5RGN.js +0 -11
- package/dist/chunk-3EJZQ6TQ.js +0 -49
- package/dist/chunk-55HTWX4C.cjs +0 -93
- package/dist/chunk-5SWCVTNL.cjs +0 -5579
- package/dist/chunk-B66WVPGJ.js +0 -297
- package/dist/chunk-FPIWDH5Y.cjs +0 -126
- package/dist/chunk-HCOPJZ4A.cjs +0 -164
- package/dist/chunk-OMN3UI6X.js +0 -5576
- package/dist/chunk-R4J7XQYU.js +0 -156
- package/dist/chunk-RBQASTUP.js +0 -203
- package/dist/chunk-SKBVVI24.cjs +0 -54
- package/dist/chunk-TZK63M5N.cjs +0 -317
- package/dist/chunk-ZHNKYTNS.cjs +0 -309
- package/dist/chunk-ZLBRQFDD.cjs +0 -13
- package/dist/index.d.cts +0 -1
- package/dist/server/handlers/agents.d.cts +0 -6
- package/dist/server/handlers/error.d.cts +0 -1
- package/dist/server/handlers/logs.d.cts +0 -3
- package/dist/server/handlers/memory.d.cts +0 -8
- package/dist/server/handlers/network.d.cts +0 -4
- package/dist/server/handlers/telemetry.d.cts +0 -2
- package/dist/server/handlers/tools.d.cts +0 -4
- package/dist/server/handlers/utils.d.cts +0 -1
- package/dist/server/handlers/vNextWorkflows.cjs +0 -46
- package/dist/server/handlers/vNextWorkflows.d.cts +0 -10
- package/dist/server/handlers/vNextWorkflows.d.ts +0 -10
- package/dist/server/handlers/vNextWorkflows.js +0 -1
- package/dist/server/handlers/vector.d.cts +0 -6
- package/dist/server/handlers/voice.d.cts +0 -3
- package/dist/server/handlers/workflows.d.cts +0 -10
- package/dist/server/handlers.d.cts +0 -10
package/LICENSE.md
CHANGED
|
@@ -1,46 +1,15 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Apache License 2.0
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2025
|
|
3
|
+
Copyright (c) 2025 Kepler Software, Inc.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
you may not use this file except in compliance with the License.
|
|
7
|
+
You may obtain a copy of the License at
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
The licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject to the limitations and conditions below
|
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
You may not alter, remove, or obscure any licensing, copyright, or other notices of the licensor in the software. Any use of the licensor’s trademarks is subject to applicable law.
|
|
17
|
-
|
|
18
|
-
**Patents**
|
|
19
|
-
The licensor grants you a license, under any patent claims the licensor can license, or becomes able to license, to make, have made, use, sell, offer for sale, import and have imported the software, in each case subject to the limitations and conditions in this license. This license does not cover any patent claims that you cause to be infringed by modifications or additions to the software. If you or your company make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
|
|
20
|
-
|
|
21
|
-
**Notices**
|
|
22
|
-
You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms.
|
|
23
|
-
|
|
24
|
-
If you modify the software, you must include in any modified copies of the software prominent notices stating that you have modified the software.
|
|
25
|
-
|
|
26
|
-
**No Other Rights**
|
|
27
|
-
These terms do not imply any licenses other than those expressly granted in these terms.
|
|
28
|
-
|
|
29
|
-
**Termination**
|
|
30
|
-
If you use the software in violation of these terms, such use is not licensed, and your licenses will automatically terminate. If the licensor provides you with a notice of your violation, and you cease all violation of this license no later than 30 days after you receive that notice, your licenses will be reinstated retroactively. However, if you violate these terms after such reinstatement, any additional violation of these terms will cause your licenses to terminate automatically and permanently.
|
|
31
|
-
|
|
32
|
-
**No Liability**
|
|
33
|
-
As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.
|
|
34
|
-
|
|
35
|
-
**Definitions**
|
|
36
|
-
The _licensor_ is the entity offering these terms, and the _software_ is the software the licensor makes available under these terms, including any portion of it.
|
|
37
|
-
|
|
38
|
-
_you_ refers to the individual or entity agreeing to these terms.
|
|
39
|
-
|
|
40
|
-
_your company_ is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. _control_ means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
|
|
41
|
-
|
|
42
|
-
_your licenses_ are all the licenses granted to you for the software under these terms.
|
|
43
|
-
|
|
44
|
-
_use_ means anything you do with the software requiring one of your licenses.
|
|
45
|
-
|
|
46
|
-
_trademark_ means trademarks, service marks, and similar rights.
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
See the License for the specific language governing permissions and
|
|
15
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,159 +1,72 @@
|
|
|
1
|
-
# @mastra/
|
|
1
|
+
# @mastra/server
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Typed HTTP handlers and utilities for exposing a `Mastra` instance over HTTP.
|
|
4
|
+
This package powers `mastra dev` and can be added to your own server to provide
|
|
5
|
+
REST and streaming endpoints for agents, workflows, telemetry and more.
|
|
4
6
|
|
|
5
7
|
## Installation
|
|
6
8
|
|
|
7
9
|
```bash
|
|
8
|
-
npm install @mastra/
|
|
10
|
+
npm install @mastra/server
|
|
9
11
|
```
|
|
10
12
|
|
|
11
|
-
## Overview
|
|
12
|
-
|
|
13
|
-
The `@mastra/deployer` package provides the foundational deployment infrastructure for Mastra applications. It handles:
|
|
14
|
-
|
|
15
|
-
- Project building and bundling
|
|
16
|
-
- Dependency management
|
|
17
|
-
- Environment configuration
|
|
18
|
-
- Development and production deployments
|
|
19
|
-
|
|
20
13
|
## Usage
|
|
21
14
|
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
The handlers are framework agnostic functions which accept a `Mastra` instance
|
|
16
|
+
and a request context. They are typically mounted under a URL prefix within your
|
|
17
|
+
web framework of choice:
|
|
24
18
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
19
|
+
```typescript
|
|
20
|
+
import { Hono } from 'hono';
|
|
21
|
+
import { handlers } from '@mastra/server';
|
|
22
|
+
import { mastra } from './mastra-instance';
|
|
23
|
+
|
|
24
|
+
const app = new Hono();
|
|
25
|
+
|
|
26
|
+
app.get('/mastra/agents', ctx => handlers.agents.getAgentsHandler({ mastra, runtimeContext: ctx }));
|
|
27
|
+
app.post('/mastra/agents/:id/generate', async ctx => {
|
|
28
|
+
const body = await ctx.req.json();
|
|
29
|
+
return handlers.agents.generateHandler({
|
|
30
|
+
mastra,
|
|
31
|
+
runtimeContext: ctx,
|
|
32
|
+
agentId: ctx.req.param('id'),
|
|
33
|
+
body,
|
|
34
|
+
});
|
|
29
35
|
});
|
|
30
36
|
|
|
31
|
-
//
|
|
32
|
-
await deployer.install();
|
|
33
|
-
|
|
34
|
-
// Write package.json
|
|
35
|
-
await deployer.writePackageJson();
|
|
36
|
-
|
|
37
|
-
// Get Mastra instance
|
|
38
|
-
const { mastra } = await deployer.getMastra();
|
|
37
|
+
// Mount additional handlers as required
|
|
39
38
|
```
|
|
40
39
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
### Required Parameters
|
|
44
|
-
|
|
45
|
-
- `dir`: Project directory path
|
|
46
|
-
- `type`: Deployment type ('Deploy' or 'Dev')
|
|
40
|
+
Running `mastra dev` starts a local development UI at
|
|
41
|
+
`http://localhost:3000` using these handlers.
|
|
47
42
|
|
|
48
|
-
##
|
|
43
|
+
## Available Handler Groups
|
|
49
44
|
|
|
50
|
-
|
|
45
|
+
- **Agents** - list defined agents, retrieve metadata, and run `generate`
|
|
46
|
+
or `stream`.
|
|
47
|
+
- **Workflows** - start and inspect workflow runs.
|
|
48
|
+
- **Tools** - discover tools available to the `Mastra` instance.
|
|
49
|
+
- **Memory** - interact with configured memory stores.
|
|
50
|
+
- **Logs** - query runtime logs when a supporting logger transport is used.
|
|
51
|
+
- **Telemetry** - expose metrics produced by the telemetry subsystem.
|
|
52
|
+
- **Networks** - interact with agent networks.
|
|
53
|
+
- **Vector / Voice** - endpoints related to vector stores and voice synthesis.
|
|
51
54
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
- Manages project dependencies
|
|
55
|
+
Handlers return JSON serialisable data and throw an `HTTPException` (subclass of
|
|
56
|
+
`Error`) when a failure should result in a non-2xx HTTP status.
|
|
55
57
|
|
|
56
|
-
|
|
58
|
+
## OpenAPI Spec Generation
|
|
57
59
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
- Version management for @mastra packages
|
|
60
|
+
The local OpenAPI specification used by the CLI playground and similar tools can
|
|
61
|
+
be refreshed by running:
|
|
61
62
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
- Support for multiple environment files:
|
|
65
|
-
- `.env`
|
|
66
|
-
- `.env.development`
|
|
67
|
-
- `.env.local`
|
|
68
|
-
- Environment variable validation and processing
|
|
69
|
-
|
|
70
|
-
### Build Process
|
|
71
|
-
|
|
72
|
-
- Project bundling
|
|
73
|
-
- Asset management
|
|
74
|
-
- Source code transformation
|
|
75
|
-
|
|
76
|
-
### Development Support
|
|
77
|
-
|
|
78
|
-
- Development server configuration
|
|
79
|
-
- Hot reloading capabilities
|
|
80
|
-
- Debug logging
|
|
81
|
-
|
|
82
|
-
## Project Structure
|
|
83
|
-
|
|
84
|
-
The deployer creates and manages the following structure:
|
|
85
|
-
|
|
86
|
-
```
|
|
87
|
-
your-project/
|
|
88
|
-
├── .mastra/
|
|
89
|
-
│ ├── package.json
|
|
90
|
-
│ ├── mastra.mjs
|
|
91
|
-
│ └── index.mjs
|
|
92
|
-
├── .env
|
|
93
|
-
├── .env.development
|
|
94
|
-
├── .env.local
|
|
95
|
-
└── package.json
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
## Package.json Management
|
|
99
|
-
|
|
100
|
-
The deployer automatically manages dependencies in the `.mastra/package.json`:
|
|
101
|
-
|
|
102
|
-
```json
|
|
103
|
-
{
|
|
104
|
-
"name": "server",
|
|
105
|
-
"version": "1.0.0",
|
|
106
|
-
"type": "module",
|
|
107
|
-
"dependencies": {
|
|
108
|
-
"@mastra/loggers": "latest",
|
|
109
|
-
"hono": "4.6.17",
|
|
110
|
-
"@hono/node-server": "^1.13.7",
|
|
111
|
-
"superjson": "^2.2.2",
|
|
112
|
-
"zod-to-json-schema": "^3.24.1"
|
|
113
|
-
}
|
|
114
|
-
}
|
|
63
|
+
```bash
|
|
64
|
+
pnpm run pull:openapispec
|
|
115
65
|
```
|
|
116
66
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
### `install()`
|
|
120
|
-
|
|
121
|
-
Installs and updates project dependencies.
|
|
122
|
-
|
|
123
|
-
### `writePackageJson()`
|
|
124
|
-
|
|
125
|
-
Generates or updates the package.json in the .mastra directory.
|
|
126
|
-
|
|
127
|
-
### `getMastra()`
|
|
128
|
-
|
|
129
|
-
Returns the Mastra instance for the project.
|
|
130
|
-
|
|
131
|
-
### `getMastraPath()`
|
|
132
|
-
|
|
133
|
-
Returns the path to the .mastra directory.
|
|
134
|
-
|
|
135
|
-
## Error Handling
|
|
136
|
-
|
|
137
|
-
The deployer includes comprehensive error handling for:
|
|
138
|
-
|
|
139
|
-
- Dependency installation failures
|
|
140
|
-
- File system operations
|
|
141
|
-
- Environment configuration issues
|
|
142
|
-
- Build process errors
|
|
143
|
-
|
|
144
|
-
## Logging
|
|
145
|
-
|
|
146
|
-
Built-in logging support through @mastra/core:
|
|
147
|
-
|
|
148
|
-
- Debug information
|
|
149
|
-
- Installation progress
|
|
150
|
-
- Build status
|
|
151
|
-
- Error reporting
|
|
67
|
+
within the `@mastra/server` directory.
|
|
152
68
|
|
|
153
|
-
##
|
|
69
|
+
## License
|
|
154
70
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
- Deployer implementations:
|
|
158
|
-
- `@mastra/deployer-cloudflare`
|
|
159
|
-
- Other platform-specific deployers
|
|
71
|
+
Released under the Elastic License 2.0. The full license text is available in
|
|
72
|
+
this repository.
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkLRUH33B4_cjs = require('./chunk-LRUH33B4.cjs');
|
|
4
|
+
var chunk4QSNRCOT_cjs = require('./chunk-4QSNRCOT.cjs');
|
|
5
|
+
var chunkRE4RPXT2_cjs = require('./chunk-RE4RPXT2.cjs');
|
|
6
|
+
var chunk7NADHFD2_cjs = require('./chunk-7NADHFD2.cjs');
|
|
7
|
+
var chunkQ7SFCCGT_cjs = require('./chunk-Q7SFCCGT.cjs');
|
|
8
|
+
var runtimeContext = require('@mastra/core/runtime-context');
|
|
9
|
+
|
|
10
|
+
// src/server/handlers/agents.ts
|
|
11
|
+
var agents_exports = {};
|
|
12
|
+
chunkQ7SFCCGT_cjs.__export(agents_exports, {
|
|
13
|
+
generateHandler: () => generateHandler,
|
|
14
|
+
getAgentByIdHandler: () => getAgentByIdHandler,
|
|
15
|
+
getAgentsHandler: () => getAgentsHandler,
|
|
16
|
+
getEvalsByAgentIdHandler: () => getEvalsByAgentIdHandler,
|
|
17
|
+
getLiveEvalsByAgentIdHandler: () => getLiveEvalsByAgentIdHandler,
|
|
18
|
+
streamGenerateHandler: () => streamGenerateHandler,
|
|
19
|
+
streamVNextGenerateHandler: () => streamVNextGenerateHandler
|
|
20
|
+
});
|
|
21
|
+
async function getAgentsHandler({ mastra, runtimeContext }) {
|
|
22
|
+
try {
|
|
23
|
+
const agents = mastra.getAgents();
|
|
24
|
+
const serializedAgentsMap = await Promise.all(
|
|
25
|
+
Object.entries(agents).map(async ([id, agent]) => {
|
|
26
|
+
const instructions = await agent.getInstructions({ runtimeContext });
|
|
27
|
+
const tools = await agent.getTools({ runtimeContext });
|
|
28
|
+
const llm = await agent.getLLM({ runtimeContext });
|
|
29
|
+
const defaultGenerateOptions = await agent.getDefaultGenerateOptions({ runtimeContext });
|
|
30
|
+
const defaultStreamOptions = await agent.getDefaultStreamOptions({ runtimeContext });
|
|
31
|
+
const serializedAgentTools = Object.entries(tools || {}).reduce((acc, [key, tool]) => {
|
|
32
|
+
const _tool = tool;
|
|
33
|
+
acc[key] = {
|
|
34
|
+
..._tool,
|
|
35
|
+
inputSchema: _tool.inputSchema ? chunkLRUH33B4_cjs.stringify(chunkLRUH33B4_cjs.esm_default(_tool.inputSchema)) : void 0,
|
|
36
|
+
outputSchema: _tool.outputSchema ? chunkLRUH33B4_cjs.stringify(chunkLRUH33B4_cjs.esm_default(_tool.outputSchema)) : void 0
|
|
37
|
+
};
|
|
38
|
+
return acc;
|
|
39
|
+
}, {});
|
|
40
|
+
let serializedAgentWorkflows = {};
|
|
41
|
+
if ("getWorkflows" in agent) {
|
|
42
|
+
const logger = mastra.getLogger();
|
|
43
|
+
try {
|
|
44
|
+
const workflows = await agent.getWorkflows({ runtimeContext });
|
|
45
|
+
serializedAgentWorkflows = Object.entries(workflows || {}).reduce((acc, [key, workflow]) => {
|
|
46
|
+
return {
|
|
47
|
+
...acc,
|
|
48
|
+
[key]: {
|
|
49
|
+
name: workflow.name
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}, {});
|
|
53
|
+
} catch (error) {
|
|
54
|
+
logger.error("Error getting workflows for agent", { agentName: agent.name, error });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
id,
|
|
59
|
+
name: agent.name,
|
|
60
|
+
instructions,
|
|
61
|
+
tools: serializedAgentTools,
|
|
62
|
+
workflows: serializedAgentWorkflows,
|
|
63
|
+
provider: llm?.getProvider(),
|
|
64
|
+
modelId: llm?.getModelId(),
|
|
65
|
+
defaultGenerateOptions,
|
|
66
|
+
defaultStreamOptions
|
|
67
|
+
};
|
|
68
|
+
})
|
|
69
|
+
);
|
|
70
|
+
const serializedAgents = serializedAgentsMap.reduce((acc, { id, ...rest }) => {
|
|
71
|
+
acc[id] = rest;
|
|
72
|
+
return acc;
|
|
73
|
+
}, {});
|
|
74
|
+
return serializedAgents;
|
|
75
|
+
} catch (error) {
|
|
76
|
+
return chunkRE4RPXT2_cjs.handleError(error, "Error getting agents");
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
async function getAgentByIdHandler({
|
|
80
|
+
mastra,
|
|
81
|
+
runtimeContext,
|
|
82
|
+
agentId,
|
|
83
|
+
isPlayground = false
|
|
84
|
+
}) {
|
|
85
|
+
try {
|
|
86
|
+
const agent = mastra.getAgent(agentId);
|
|
87
|
+
if (!agent) {
|
|
88
|
+
throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Agent not found" });
|
|
89
|
+
}
|
|
90
|
+
const tools = await agent.getTools({ runtimeContext });
|
|
91
|
+
const serializedAgentTools = Object.entries(tools || {}).reduce((acc, [key, tool]) => {
|
|
92
|
+
const _tool = tool;
|
|
93
|
+
acc[key] = {
|
|
94
|
+
..._tool,
|
|
95
|
+
inputSchema: _tool.inputSchema ? chunkLRUH33B4_cjs.stringify(chunkLRUH33B4_cjs.esm_default(_tool.inputSchema)) : void 0,
|
|
96
|
+
outputSchema: _tool.outputSchema ? chunkLRUH33B4_cjs.stringify(chunkLRUH33B4_cjs.esm_default(_tool.outputSchema)) : void 0
|
|
97
|
+
};
|
|
98
|
+
return acc;
|
|
99
|
+
}, {});
|
|
100
|
+
let serializedAgentWorkflows = {};
|
|
101
|
+
if ("getWorkflows" in agent) {
|
|
102
|
+
const logger = mastra.getLogger();
|
|
103
|
+
try {
|
|
104
|
+
const workflows = await agent.getWorkflows({ runtimeContext });
|
|
105
|
+
serializedAgentWorkflows = Object.entries(workflows || {}).reduce((acc, [key, workflow]) => {
|
|
106
|
+
return {
|
|
107
|
+
...acc,
|
|
108
|
+
[key]: {
|
|
109
|
+
name: workflow.name,
|
|
110
|
+
steps: Object.entries(workflow.steps).reduce((acc2, [key2, step]) => {
|
|
111
|
+
return {
|
|
112
|
+
...acc2,
|
|
113
|
+
[key2]: {
|
|
114
|
+
id: step.id,
|
|
115
|
+
description: step.description
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
}, {})
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
}, {});
|
|
122
|
+
} catch (error) {
|
|
123
|
+
logger.error("Error getting workflows for agent", { agentName: agent.name, error });
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
let proxyRuntimeContext = runtimeContext;
|
|
127
|
+
if (isPlayground) {
|
|
128
|
+
proxyRuntimeContext = new Proxy(runtimeContext, {
|
|
129
|
+
get(target, prop) {
|
|
130
|
+
if (prop === "get") {
|
|
131
|
+
return function(key) {
|
|
132
|
+
const value = target.get(key);
|
|
133
|
+
return value ?? `<${key}>`;
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
return Reflect.get(target, prop);
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
const instructions = await agent.getInstructions({ runtimeContext: proxyRuntimeContext });
|
|
141
|
+
const llm = await agent.getLLM({ runtimeContext });
|
|
142
|
+
const defaultGenerateOptions = await agent.getDefaultGenerateOptions({ runtimeContext: proxyRuntimeContext });
|
|
143
|
+
const defaultStreamOptions = await agent.getDefaultStreamOptions({ runtimeContext: proxyRuntimeContext });
|
|
144
|
+
return {
|
|
145
|
+
name: agent.name,
|
|
146
|
+
instructions,
|
|
147
|
+
tools: serializedAgentTools,
|
|
148
|
+
workflows: serializedAgentWorkflows,
|
|
149
|
+
provider: llm?.getProvider(),
|
|
150
|
+
modelId: llm?.getModelId(),
|
|
151
|
+
defaultGenerateOptions,
|
|
152
|
+
defaultStreamOptions
|
|
153
|
+
};
|
|
154
|
+
} catch (error) {
|
|
155
|
+
return chunkRE4RPXT2_cjs.handleError(error, "Error getting agent");
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
async function getEvalsByAgentIdHandler({
|
|
159
|
+
mastra,
|
|
160
|
+
runtimeContext,
|
|
161
|
+
agentId
|
|
162
|
+
}) {
|
|
163
|
+
try {
|
|
164
|
+
const agent = mastra.getAgent(agentId);
|
|
165
|
+
const evals = await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, "test") || [];
|
|
166
|
+
const instructions = await agent.getInstructions({ runtimeContext });
|
|
167
|
+
return {
|
|
168
|
+
id: agentId,
|
|
169
|
+
name: agent.name,
|
|
170
|
+
instructions,
|
|
171
|
+
evals
|
|
172
|
+
};
|
|
173
|
+
} catch (error) {
|
|
174
|
+
return chunkRE4RPXT2_cjs.handleError(error, "Error getting test evals");
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
async function getLiveEvalsByAgentIdHandler({
|
|
178
|
+
mastra,
|
|
179
|
+
runtimeContext,
|
|
180
|
+
agentId
|
|
181
|
+
}) {
|
|
182
|
+
try {
|
|
183
|
+
const agent = mastra.getAgent(agentId);
|
|
184
|
+
const evals = await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, "live") || [];
|
|
185
|
+
const instructions = await agent.getInstructions({ runtimeContext });
|
|
186
|
+
return {
|
|
187
|
+
id: agentId,
|
|
188
|
+
name: agent.name,
|
|
189
|
+
instructions,
|
|
190
|
+
evals
|
|
191
|
+
};
|
|
192
|
+
} catch (error) {
|
|
193
|
+
return chunkRE4RPXT2_cjs.handleError(error, "Error getting live evals");
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
async function generateHandler({
|
|
197
|
+
mastra,
|
|
198
|
+
runtimeContext: runtimeContext$1,
|
|
199
|
+
agentId,
|
|
200
|
+
body,
|
|
201
|
+
abortSignal
|
|
202
|
+
}) {
|
|
203
|
+
try {
|
|
204
|
+
const agent = mastra.getAgent(agentId);
|
|
205
|
+
if (!agent) {
|
|
206
|
+
throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Agent not found" });
|
|
207
|
+
}
|
|
208
|
+
const { messages, resourceId, resourceid, runtimeContext: agentRuntimeContext, ...rest } = body;
|
|
209
|
+
const finalResourceId = resourceId ?? resourceid;
|
|
210
|
+
const finalRuntimeContext = new runtimeContext.RuntimeContext([
|
|
211
|
+
...Array.from(runtimeContext$1.entries()),
|
|
212
|
+
...Array.from(Object.entries(agentRuntimeContext ?? {}))
|
|
213
|
+
]);
|
|
214
|
+
chunk4QSNRCOT_cjs.validateBody({ messages });
|
|
215
|
+
const result = await agent.generate(messages, {
|
|
216
|
+
...rest,
|
|
217
|
+
// @ts-expect-error TODO fix types
|
|
218
|
+
resourceId: finalResourceId,
|
|
219
|
+
runtimeContext: finalRuntimeContext,
|
|
220
|
+
signal: abortSignal
|
|
221
|
+
});
|
|
222
|
+
return result;
|
|
223
|
+
} catch (error) {
|
|
224
|
+
return chunkRE4RPXT2_cjs.handleError(error, "Error generating from agent");
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
async function streamGenerateHandler({
|
|
228
|
+
mastra,
|
|
229
|
+
runtimeContext: runtimeContext$1,
|
|
230
|
+
agentId,
|
|
231
|
+
body,
|
|
232
|
+
abortSignal
|
|
233
|
+
}) {
|
|
234
|
+
try {
|
|
235
|
+
const agent = mastra.getAgent(agentId);
|
|
236
|
+
if (!agent) {
|
|
237
|
+
throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Agent not found" });
|
|
238
|
+
}
|
|
239
|
+
const { messages, resourceId, resourceid, runtimeContext: agentRuntimeContext, ...rest } = body;
|
|
240
|
+
const finalResourceId = resourceId ?? resourceid;
|
|
241
|
+
const finalRuntimeContext = new runtimeContext.RuntimeContext([
|
|
242
|
+
...Array.from(runtimeContext$1.entries()),
|
|
243
|
+
...Array.from(Object.entries(agentRuntimeContext ?? {}))
|
|
244
|
+
]);
|
|
245
|
+
chunk4QSNRCOT_cjs.validateBody({ messages });
|
|
246
|
+
const streamResult = await agent.stream(messages, {
|
|
247
|
+
...rest,
|
|
248
|
+
// @ts-expect-error TODO fix types
|
|
249
|
+
resourceId: finalResourceId,
|
|
250
|
+
runtimeContext: finalRuntimeContext,
|
|
251
|
+
signal: abortSignal
|
|
252
|
+
});
|
|
253
|
+
const streamResponse = rest.output ? streamResult.toTextStreamResponse({
|
|
254
|
+
headers: {
|
|
255
|
+
"Transfer-Encoding": "chunked"
|
|
256
|
+
}
|
|
257
|
+
}) : streamResult.toDataStreamResponse({
|
|
258
|
+
sendUsage: true,
|
|
259
|
+
sendReasoning: true,
|
|
260
|
+
getErrorMessage: (error) => {
|
|
261
|
+
return `An error occurred while processing your request. ${error instanceof Error ? error.message : JSON.stringify(error)}`;
|
|
262
|
+
},
|
|
263
|
+
headers: {
|
|
264
|
+
"Transfer-Encoding": "chunked"
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
return streamResponse;
|
|
268
|
+
} catch (error) {
|
|
269
|
+
return chunkRE4RPXT2_cjs.handleError(error, "error streaming agent response");
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
function streamVNextGenerateHandler({
|
|
273
|
+
mastra,
|
|
274
|
+
runtimeContext: runtimeContext$1,
|
|
275
|
+
agentId,
|
|
276
|
+
body,
|
|
277
|
+
abortSignal
|
|
278
|
+
}) {
|
|
279
|
+
try {
|
|
280
|
+
const agent = mastra.getAgent(agentId);
|
|
281
|
+
if (!agent) {
|
|
282
|
+
throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Agent not found" });
|
|
283
|
+
}
|
|
284
|
+
const { messages, runtimeContext: agentRuntimeContext, ...rest } = body;
|
|
285
|
+
const finalRuntimeContext = new runtimeContext.RuntimeContext([
|
|
286
|
+
...Array.from(runtimeContext$1.entries()),
|
|
287
|
+
...Array.from(Object.entries(agentRuntimeContext ?? {}))
|
|
288
|
+
]);
|
|
289
|
+
chunk4QSNRCOT_cjs.validateBody({ messages });
|
|
290
|
+
const streamResult = agent.streamVNext(messages, {
|
|
291
|
+
...rest,
|
|
292
|
+
runtimeContext: finalRuntimeContext,
|
|
293
|
+
abortSignal
|
|
294
|
+
});
|
|
295
|
+
return streamResult;
|
|
296
|
+
} catch (error) {
|
|
297
|
+
return chunkRE4RPXT2_cjs.handleError(error, "error streaming agent response");
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
exports.agents_exports = agents_exports;
|
|
302
|
+
exports.generateHandler = generateHandler;
|
|
303
|
+
exports.getAgentByIdHandler = getAgentByIdHandler;
|
|
304
|
+
exports.getAgentsHandler = getAgentsHandler;
|
|
305
|
+
exports.getEvalsByAgentIdHandler = getEvalsByAgentIdHandler;
|
|
306
|
+
exports.getLiveEvalsByAgentIdHandler = getLiveEvalsByAgentIdHandler;
|
|
307
|
+
exports.streamGenerateHandler = streamGenerateHandler;
|
|
308
|
+
exports.streamVNextGenerateHandler = streamVNextGenerateHandler;
|
|
309
|
+
//# sourceMappingURL=chunk-2XIJW7SV.cjs.map
|
|
310
|
+
//# sourceMappingURL=chunk-2XIJW7SV.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/server/handlers/agents.ts"],"names":["__export","stringify","esm_default","handleError","HTTPException","acc","key","runtimeContext","RuntimeContext","validateBody"],"mappings":";;;;;;;;;;AAAA,IAAA,cAAA,GAAA;AAAAA,0BAAA,CAAA,cAAA,EAAA;AAAA,EAAA,eAAA,EAAA,MAAA,eAAA;AAAA,EAAA,mBAAA,EAAA,MAAA,mBAAA;AAAA,EAAA,gBAAA,EAAA,MAAA,gBAAA;AAAA,EAAA,wBAAA,EAAA,MAAA,wBAAA;AAAA,EAAA,4BAAA,EAAA,MAAA,4BAAA;AAAA,EAAA,qBAAA,EAAA,MAAA,qBAAA;AAAA,EAAA,0BAAA,EAAA,MAAA;AAAA,CAAA,CAAA;AAiBA,eAAsB,gBAAA,CAAiB,EAAE,MAAA,EAAQ,cAAA,EAAe,EAAiD;AAC/G,EAAA,IAAI;AACF,IAAA,MAAM,MAAA,GAAS,OAAO,SA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AAA,CAAwC;AAAA,MACtE,GAAG,KAAA,CAAM,IAAA,CAAKD,gBAAA,CAAe,SAAS,CAAA;AAAA,MACtC,GAAG,MAAM,IAAA,CAAK,MAAA,CAAO,QAAQ,mBAAA,IAAuB,EAAE,CAAC;AAAA,KACxD,CAAA;AAED,IAAAE,8BAAA,CAAa,EAAE,UAAU,CAAA;AAEzB,IAAA,MAAM,YAAA,GAAe,KAAA,CAAM,WAAA,CAAY,QAAA,EAAU;AAAA,MAC/C,GAAG,IAAA;AAAA,MACH,cAAA,EAAgB,mBAAA;AAAA,MAChB;AAAA,KACD,CAAA;AAED,IAAA,OAAO,YAAA;AAAA,EACT,SAAS,KAAA,EAAO;AACd,IAAA,OAAON,6BAAA,CAAY,OAAO,gCAAgC,CAAA;AAAA,EAC5D;AACF","file":"chunk-2XIJW7SV.cjs","sourcesContent":["import type { Agent } from '@mastra/core/agent';\nimport { RuntimeContext } from '@mastra/core/runtime-context';\nimport { stringify } from 'superjson';\nimport zodToJsonSchema from 'zod-to-json-schema';\nimport { HTTPException } from '../http-exception';\nimport type { Context } from '../types';\n\nimport { handleError } from './error';\nimport { 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\n// Agent handlers\nexport async function getAgentsHandler({ mastra, runtimeContext }: Context & { runtimeContext: RuntimeContext }) {\n try {\n const agents = mastra.getAgents();\n\n const serializedAgentsMap = await Promise.all(\n Object.entries(agents).map(async ([id, agent]) => {\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\n const serializedAgentTools = Object.entries(tools || {}).reduce<any>((acc, [key, tool]) => {\n const _tool = tool as any;\n acc[key] = {\n ..._tool,\n inputSchema: _tool.inputSchema ? stringify(zodToJsonSchema(_tool.inputSchema)) : undefined,\n outputSchema: _tool.outputSchema ? stringify(zodToJsonSchema(_tool.outputSchema)) : undefined,\n };\n return acc;\n }, {});\n\n let serializedAgentWorkflows = {};\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<any>((acc, [key, workflow]) => {\n return {\n ...acc,\n [key]: {\n name: workflow.name,\n },\n };\n }, {});\n } catch (error) {\n logger.error('Error getting workflows for agent', { agentName: agent.name, error });\n }\n }\n\n return {\n id,\n name: agent.name,\n instructions,\n tools: serializedAgentTools,\n workflows: serializedAgentWorkflows,\n provider: llm?.getProvider(),\n modelId: llm?.getModelId(),\n defaultGenerateOptions: defaultGenerateOptions as any,\n defaultStreamOptions: defaultStreamOptions as any,\n };\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\nexport async function getAgentByIdHandler({\n mastra,\n runtimeContext,\n agentId,\n isPlayground = false,\n}: Context & { isPlayground?: boolean; runtimeContext: RuntimeContext; agentId: string }) {\n try {\n const agent = mastra.getAgent(agentId);\n\n if (!agent) {\n throw new HTTPException(404, { message: 'Agent not found' });\n }\n\n const tools = await agent.getTools({ runtimeContext });\n\n const serializedAgentTools = Object.entries(tools || {}).reduce<any>((acc, [key, tool]) => {\n const _tool = tool as any;\n acc[key] = {\n ..._tool,\n inputSchema: _tool.inputSchema ? stringify(zodToJsonSchema(_tool.inputSchema)) : undefined,\n outputSchema: _tool.outputSchema ? stringify(zodToJsonSchema(_tool.outputSchema)) : undefined,\n };\n return acc;\n }, {});\n\n let serializedAgentWorkflows = {};\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<any>((acc, [key, workflow]) => {\n return {\n ...acc,\n [key]: {\n name: workflow.name,\n steps: Object.entries(workflow.steps).reduce<any>((acc, [key, step]) => {\n return {\n ...acc,\n [key]: {\n id: step.id,\n description: step.description,\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 return {\n name: agent.name,\n instructions,\n tools: serializedAgentTools,\n workflows: serializedAgentWorkflows,\n provider: llm?.getProvider(),\n modelId: llm?.getModelId(),\n defaultGenerateOptions: defaultGenerateOptions as any,\n defaultStreamOptions: defaultStreamOptions as any,\n };\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 = mastra.getAgent(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 = mastra.getAgent(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 generateHandler({\n mastra,\n runtimeContext,\n agentId,\n body,\n abortSignal,\n}: Context & {\n runtimeContext: RuntimeContext;\n agentId: string;\n body: GetBody<'generate'> & {\n // @deprecated use resourceId\n resourceid?: string;\n runtimeContext?: Record<string, unknown>;\n };\n abortSignal?: AbortSignal;\n}) {\n try {\n const agent = mastra.getAgent(agentId);\n\n if (!agent) {\n throw new HTTPException(404, { message: 'Agent not found' });\n }\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.generate(messages, {\n ...rest,\n // @ts-expect-error TODO fix types\n resourceId: finalResourceId,\n runtimeContext: finalRuntimeContext,\n signal: abortSignal,\n });\n\n return result;\n } catch (error) {\n return handleError(error, 'Error generating from agent');\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 // @deprecated use resourceId\n resourceid?: string;\n runtimeContext?: string;\n };\n abortSignal?: AbortSignal;\n}): Promise<Response | undefined> {\n try {\n const agent = mastra.getAgent(agentId);\n\n if (!agent) {\n throw new HTTPException(404, { message: 'Agent not found' });\n }\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.stream(messages, {\n ...rest,\n // @ts-expect-error TODO fix types\n resourceId: finalResourceId,\n runtimeContext: finalRuntimeContext,\n signal: abortSignal,\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 function streamVNextGenerateHandler({\n mastra,\n runtimeContext,\n agentId,\n body,\n abortSignal,\n}: Context & {\n runtimeContext: RuntimeContext;\n agentId: string;\n body: GetBody<'streamVNext'> & {\n runtimeContext?: string;\n };\n abortSignal?: AbortSignal;\n}): ReturnType<Agent['streamVNext']> {\n try {\n const agent = mastra.getAgent(agentId);\n\n if (!agent) {\n throw new HTTPException(404, { message: 'Agent not found' });\n }\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.streamVNext(messages, {\n ...rest,\n runtimeContext: finalRuntimeContext,\n abortSignal,\n });\n\n return streamResult;\n } catch (error) {\n return handleError(error, 'error streaming agent response');\n }\n}\n"]}
|