@mastra/server 0.0.0-mcp-server-deploy-20250507160341 → 0.0.0-memory-system-message-error-20250813233316
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-5YGDYMRB.cjs → chunk-4CEZIJWJ.cjs} +16 -13
- 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-5AKR33BI.js +333 -0
- package/dist/chunk-5AKR33BI.js.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-EBNIUZRY.cjs +344 -0
- package/dist/chunk-EBNIUZRY.cjs.map +1 -0
- package/dist/{chunk-4JINXASC.js → chunk-G7NVCO5M.js} +7 -4
- package/dist/chunk-G7NVCO5M.js.map +1 -0
- package/dist/chunk-GX25CWC7.cjs +588 -0
- package/dist/chunk-GX25CWC7.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-AMVOS7YB.cjs → chunk-ILCWPBYQ.cjs} +14 -8
- 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-JNWFG7JP.js +476 -0
- package/dist/chunk-JNWFG7JP.js.map +1 -0
- package/dist/chunk-KXNFZXLG.cjs +484 -0
- package/dist/chunk-KXNFZXLG.cjs.map +1 -0
- package/dist/chunk-L7YG7WQH.js +151 -0
- package/dist/chunk-L7YG7WQH.js.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-RQQNZZAI.cjs +159 -0
- package/dist/chunk-RQQNZZAI.cjs.map +1 -0
- package/dist/chunk-S37KCGOR.cjs +546 -0
- package/dist/chunk-S37KCGOR.cjs.map +1 -0
- package/dist/{chunk-BPL2CBLV.js → chunk-SQ7KKIH3.js} +10 -4
- package/dist/chunk-SQ7KKIH3.js.map +1 -0
- package/dist/{chunk-3XTEV33Q.js → chunk-UVOSITKU.js} +61 -56
- package/dist/chunk-UVOSITKU.js.map +1 -0
- package/dist/{chunk-QJ3AHN64.js → chunk-Y3J45CVZ.js} +6 -3
- 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/chunk-ZKJZQN24.js +571 -0
- package/dist/chunk-ZKJZQN24.js.map +1 -0
- package/dist/index.cjs +2 -12
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -1
- 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.cjs +25 -0
- package/dist/server/a2a/store.cjs.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/store.js +23 -0
- package/dist/server/a2a/store.js.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 +68 -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 +21 -7
- package/dist/server/handlers/agents.cjs.map +1 -0
- package/dist/server/handlers/agents.d.ts +90 -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 +39 -9
- package/dist/server/handlers/memory.cjs.map +1 -0
- package/dist/server/handlers/memory.d.ts +119 -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 +42 -30
- 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 +31 -18
- package/dist/_tsup-dts-rollup.d.cts +0 -748
- package/dist/_tsup-dts-rollup.d.ts +0 -748
- package/dist/chunk-2FJURXCL.cjs +0 -213
- package/dist/chunk-3AHQ5RGN.js +0 -11
- package/dist/chunk-3EJZQ6TQ.js +0 -49
- package/dist/chunk-4BIX6GMY.cjs +0 -189
- package/dist/chunk-55HTWX4C.cjs +0 -93
- package/dist/chunk-5SWCVTNL.cjs +0 -5579
- package/dist/chunk-74DLDQTQ.cjs +0 -36
- package/dist/chunk-CHFORQ7J.cjs +0 -329
- package/dist/chunk-FOXHTOQZ.cjs +0 -324
- package/dist/chunk-HAA5T7JL.js +0 -33
- package/dist/chunk-IQTNZSFP.js +0 -312
- package/dist/chunk-OMN3UI6X.js +0 -5576
- package/dist/chunk-RBQASTUP.js +0 -203
- package/dist/chunk-SKBVVI24.cjs +0 -54
- package/dist/chunk-Y3SV5XK4.js +0 -181
- package/dist/chunk-ZLBRQFDD.cjs +0 -13
- package/dist/index.d.cts +0 -2
- 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/mcp.cjs +0 -14
- package/dist/server/handlers/mcp.d.cts +0 -2
- package/dist/server/handlers/mcp.d.ts +0 -2
- package/dist/server/handlers/mcp.js +0 -1
- 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.
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
3
|
+
var chunk4QSNRCOT_cjs = require('./chunk-4QSNRCOT.cjs');
|
|
4
|
+
var chunkRE4RPXT2_cjs = require('./chunk-RE4RPXT2.cjs');
|
|
5
|
+
var chunk7NADHFD2_cjs = require('./chunk-7NADHFD2.cjs');
|
|
6
|
+
var chunkQ7SFCCGT_cjs = require('./chunk-Q7SFCCGT.cjs');
|
|
6
7
|
|
|
7
8
|
// src/server/handlers/network.ts
|
|
8
9
|
var network_exports = {};
|
|
9
|
-
|
|
10
|
+
chunkQ7SFCCGT_cjs.__export(network_exports, {
|
|
10
11
|
generateHandler: () => generateHandler,
|
|
11
12
|
getNetworkByIdHandler: () => getNetworkByIdHandler,
|
|
12
13
|
getNetworksHandler: () => getNetworksHandler,
|
|
@@ -46,7 +47,7 @@ async function getNetworksHandler({
|
|
|
46
47
|
);
|
|
47
48
|
return serializedNetworks;
|
|
48
49
|
} catch (error) {
|
|
49
|
-
return
|
|
50
|
+
return chunkRE4RPXT2_cjs.handleError(error, "Error getting networks");
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
53
|
async function getNetworkByIdHandler({
|
|
@@ -61,7 +62,7 @@ async function getNetworkByIdHandler({
|
|
|
61
62
|
return network2.formatAgentId(routingAgent2.name) === networkId;
|
|
62
63
|
});
|
|
63
64
|
if (!network) {
|
|
64
|
-
throw new
|
|
65
|
+
throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Network not found" });
|
|
65
66
|
}
|
|
66
67
|
const routingAgent = network.getRoutingAgent();
|
|
67
68
|
const routingLLM = await routingAgent.getLLM({ runtimeContext });
|
|
@@ -87,7 +88,7 @@ async function getNetworkByIdHandler({
|
|
|
87
88
|
};
|
|
88
89
|
return serializedNetwork;
|
|
89
90
|
} catch (error) {
|
|
90
|
-
return
|
|
91
|
+
return chunkRE4RPXT2_cjs.handleError(error, "Error getting network by ID");
|
|
91
92
|
}
|
|
92
93
|
}
|
|
93
94
|
async function generateHandler({
|
|
@@ -99,14 +100,14 @@ async function generateHandler({
|
|
|
99
100
|
try {
|
|
100
101
|
const network = mastra.getNetwork(networkId);
|
|
101
102
|
if (!network) {
|
|
102
|
-
throw new
|
|
103
|
+
throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Network not found" });
|
|
103
104
|
}
|
|
104
|
-
|
|
105
|
+
chunk4QSNRCOT_cjs.validateBody({ messages: body.messages });
|
|
105
106
|
const { messages, ...rest } = body;
|
|
106
107
|
const result = await network.generate(messages, { ...rest, runtimeContext });
|
|
107
108
|
return result;
|
|
108
109
|
} catch (error) {
|
|
109
|
-
return
|
|
110
|
+
return chunkRE4RPXT2_cjs.handleError(error, "Error generating from network");
|
|
110
111
|
}
|
|
111
112
|
}
|
|
112
113
|
async function streamGenerateHandler({
|
|
@@ -118,9 +119,9 @@ async function streamGenerateHandler({
|
|
|
118
119
|
try {
|
|
119
120
|
const network = mastra.getNetwork(networkId);
|
|
120
121
|
if (!network) {
|
|
121
|
-
throw new
|
|
122
|
+
throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Network not found" });
|
|
122
123
|
}
|
|
123
|
-
|
|
124
|
+
chunk4QSNRCOT_cjs.validateBody({ messages: body.messages });
|
|
124
125
|
const { messages, output, ...rest } = body;
|
|
125
126
|
const streamResult = await network.stream(messages, {
|
|
126
127
|
output,
|
|
@@ -136,7 +137,7 @@ async function streamGenerateHandler({
|
|
|
136
137
|
});
|
|
137
138
|
return streamResponse;
|
|
138
139
|
} catch (error) {
|
|
139
|
-
return
|
|
140
|
+
return chunkRE4RPXT2_cjs.handleError(error, "Error streaming from network");
|
|
140
141
|
}
|
|
141
142
|
}
|
|
142
143
|
|
|
@@ -145,3 +146,5 @@ exports.getNetworkByIdHandler = getNetworkByIdHandler;
|
|
|
145
146
|
exports.getNetworksHandler = getNetworksHandler;
|
|
146
147
|
exports.network_exports = network_exports;
|
|
147
148
|
exports.streamGenerateHandler = streamGenerateHandler;
|
|
149
|
+
//# sourceMappingURL=chunk-4CEZIJWJ.cjs.map
|
|
150
|
+
//# sourceMappingURL=chunk-4CEZIJWJ.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/server/handlers/network.ts"],"names":["__export","handleError","network","routingAgent","HTTPException","validateBody"],"mappings":";;;;;;;;AAAA,IAAA,eAAA,GAAA;AAAAA,0BAAA,CAAA,eAAA,EAAA;AAAA,EAAA,eAAA,EAAA,MAAA,eAAA;AAAA,EAAA,qBAAA,EAAA,MAAA,qBAAA;AAAA,EAAA,kBAAA,EAAA,MAAA,kBAAA;AAAA,EAAA,qBAAA,EAAA,MAAA;AAAA,CAAA,CAAA;AAcA,eAAsB,kBAAA,CAAmB;AAAA,EACvC,MAAA;AAAA,EACA;AACF,CAAA,EAAsD;AACpD,EAAA,IAAI;AACF,IAAA,MAAM,QAAA,GAAW,OAAO,WAAA,EAAY;AAEpC,IAAA,MAAM,kBAAA,GAAqB,MAAM,OAAA,CAAQ,GAAA;AAAA,MACvC,QAAA,CAAS,GAAA,CAAI,OAAM,OAAA,KAAW;AAC5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ACnD,MAAA;AAAA,MACA,GAAG,IAAA;AAAA,MACH;AAAA,KAC+B,CAAA;AAEjC,IAAA,MAAM,iBAAiB,MAAA,GACnB,YAAA,CAAa,oBAAA,EAAqB,GAClC,aAAa,oBAAA,CAAqB;AAAA,MAChC,SAAA,EAAW,IAAA;AAAA,MACX,aAAA,EAAe,IAAA;AAAA,MACf,eAAA,EAAiB,CAAC,KAAA,KAAe;AAC/B,QAAA,OAAO,CAAA,iDAAA,EAAoD,iBAAiB,KAAA,GAAQ,KAAA,CAAM,UAAU,IAAA,CAAK,SAAA,CAAU,KAAK,CAAC,CAAA,CAAA;AAAA,MAC3H;AAAA,KACD,CAAA;AAEL,IAAA,OAAO,cAAA;AAAA,EACT,SAAS,KAAA,EAAO;AACd,IAAA,OAAOJ,6BAAA,CAAY,OAAO,8BAA8B,CAAA;AAAA,EAC1D;AACF","file":"chunk-4CEZIJWJ.cjs","sourcesContent":["import type { AgentStreamOptions } from '@mastra/core/agent';\nimport type { GenerateReturn } from '@mastra/core/llm';\nimport type { AgentNetwork } from '@mastra/core/network';\nimport type { RuntimeContext } from '@mastra/core/runtime-context';\nimport { HTTPException } from '../http-exception';\nimport type { Context } from '../types';\nimport { handleError } from './error';\nimport { validateBody } from './utils';\n\ninterface NetworkContext extends Context {\n networkId?: string;\n runtimeContext: RuntimeContext;\n}\n\nexport async function getNetworksHandler({\n mastra,\n runtimeContext,\n}: Pick<NetworkContext, 'mastra' | 'runtimeContext'>) {\n try {\n const networks = mastra.getNetworks();\n\n const serializedNetworks = await Promise.all(\n networks.map(async network => {\n const routingAgent = network.getRoutingAgent();\n const routingLLM = await routingAgent.getLLM({ runtimeContext });\n const agents = network.getAgents();\n return {\n id: network.formatAgentId(routingAgent.name),\n name: routingAgent.name,\n instructions: routingAgent.instructions,\n agents: await Promise.all(\n agents.map(async agent => {\n const llm = await agent.getLLM({ runtimeContext });\n return {\n name: agent.name,\n provider: llm?.getProvider(),\n modelId: llm?.getModelId(),\n };\n }),\n ),\n routingModel: {\n provider: routingLLM?.getProvider(),\n modelId: routingLLM?.getModelId(),\n },\n };\n }),\n );\n\n return serializedNetworks;\n } catch (error) {\n return handleError(error, 'Error getting networks');\n }\n}\n\nexport async function getNetworkByIdHandler({\n mastra,\n networkId,\n runtimeContext,\n}: Pick<NetworkContext, 'mastra' | 'networkId' | 'runtimeContext'>) {\n try {\n const networks = mastra.getNetworks();\n\n const network = networks.find(network => {\n const routingAgent = network.getRoutingAgent();\n return network.formatAgentId(routingAgent.name) === networkId;\n });\n\n if (!network) {\n throw new HTTPException(404, { message: 'Network not found' });\n }\n\n const routingAgent = network.getRoutingAgent();\n const routingLLM = await routingAgent.getLLM({ runtimeContext });\n const agents = network.getAgents();\n\n const serializedNetwork = {\n id: network.formatAgentId(routingAgent.name),\n name: routingAgent.name,\n instructions: routingAgent.instructions,\n agents: await Promise.all(\n agents.map(async agent => {\n const llm = await agent.getLLM({ runtimeContext });\n return {\n name: agent.name,\n provider: llm?.getProvider(),\n modelId: llm?.getModelId(),\n };\n }),\n ),\n routingModel: {\n provider: routingLLM?.getProvider(),\n modelId: routingLLM?.getModelId(),\n },\n };\n\n return serializedNetwork;\n } catch (error) {\n return handleError(error, 'Error getting network by ID');\n }\n}\n\nexport async function generateHandler({\n mastra,\n runtimeContext,\n networkId,\n body,\n}: NetworkContext & {\n runtimeContext: RuntimeContext;\n body: { messages?: Parameters<AgentNetwork['generate']>[0] } & Parameters<AgentNetwork['generate']>[1];\n}): Promise<GenerateReturn<any, any, any>> {\n try {\n const network = mastra.getNetwork(networkId!);\n\n if (!network) {\n throw new HTTPException(404, { message: 'Network not found' });\n }\n\n validateBody({ messages: body.messages });\n\n const { messages, ...rest } = body;\n const result = await network.generate(messages!, { ...rest, runtimeContext });\n\n return result;\n } catch (error) {\n return handleError(error, 'Error generating from network');\n }\n}\n\nexport async function streamGenerateHandler({\n mastra,\n networkId,\n body,\n runtimeContext,\n}: NetworkContext & {\n runtimeContext: RuntimeContext;\n body: { messages?: Parameters<AgentNetwork['stream']>[0] } & Parameters<AgentNetwork['stream']>[1];\n}) {\n try {\n const network = mastra.getNetwork(networkId!);\n\n if (!network) {\n throw new HTTPException(404, { message: 'Network not found' });\n }\n\n validateBody({ messages: body.messages });\n\n const { messages, output, ...rest } = body;\n const streamResult = await network.stream(messages!, {\n output: output as any,\n ...rest,\n runtimeContext,\n } as AgentStreamOptions<any, any>);\n\n const streamResponse = output\n ? streamResult.toTextStreamResponse()\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 });\n\n return streamResponse;\n } catch (error) {\n return handleError(error, 'Error streaming from network');\n }\n}\n"]}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { validateBody } from './chunk-OW4FX5TS.js';
|
|
2
|
+
import { handleError } from './chunk-CY4TP3FK.js';
|
|
3
|
+
import { __export } from './chunk-PZ5AY32C.js';
|
|
4
|
+
|
|
5
|
+
// src/server/handlers/logs.ts
|
|
6
|
+
var logs_exports = {};
|
|
7
|
+
__export(logs_exports, {
|
|
8
|
+
getLogTransports: () => getLogTransports,
|
|
9
|
+
getLogsByRunIdHandler: () => getLogsByRunIdHandler,
|
|
10
|
+
getLogsHandler: () => getLogsHandler
|
|
11
|
+
});
|
|
12
|
+
async function getLogsHandler({
|
|
13
|
+
mastra,
|
|
14
|
+
transportId,
|
|
15
|
+
params
|
|
16
|
+
}) {
|
|
17
|
+
try {
|
|
18
|
+
validateBody({ transportId });
|
|
19
|
+
const { fromDate, toDate, logLevel, filters: _filters, page, perPage } = params || {};
|
|
20
|
+
const filters = _filters ? Object.fromEntries(
|
|
21
|
+
(Array.isArray(_filters) ? _filters : [_filters]).map((attr) => {
|
|
22
|
+
const [key, value] = attr.split(":");
|
|
23
|
+
return [key, value];
|
|
24
|
+
})
|
|
25
|
+
) : void 0;
|
|
26
|
+
const logs = await mastra.getLogs(transportId, {
|
|
27
|
+
fromDate,
|
|
28
|
+
toDate,
|
|
29
|
+
logLevel,
|
|
30
|
+
filters,
|
|
31
|
+
page: page ? Number(page) : void 0,
|
|
32
|
+
perPage: perPage ? Number(perPage) : void 0
|
|
33
|
+
});
|
|
34
|
+
return logs;
|
|
35
|
+
} catch (error) {
|
|
36
|
+
return handleError(error, "Error getting logs");
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async function getLogsByRunIdHandler({
|
|
40
|
+
mastra,
|
|
41
|
+
runId,
|
|
42
|
+
transportId,
|
|
43
|
+
params
|
|
44
|
+
}) {
|
|
45
|
+
try {
|
|
46
|
+
validateBody({ runId, transportId });
|
|
47
|
+
const { fromDate, toDate, logLevel, filters: _filters, page, perPage } = params || {};
|
|
48
|
+
const filters = _filters ? Object.fromEntries(
|
|
49
|
+
(Array.isArray(_filters) ? _filters : [_filters]).map((attr) => {
|
|
50
|
+
const [key, value] = attr.split(":");
|
|
51
|
+
return [key, value];
|
|
52
|
+
})
|
|
53
|
+
) : void 0;
|
|
54
|
+
const logs = await mastra.getLogsByRunId({
|
|
55
|
+
runId,
|
|
56
|
+
transportId,
|
|
57
|
+
fromDate,
|
|
58
|
+
toDate,
|
|
59
|
+
logLevel,
|
|
60
|
+
filters,
|
|
61
|
+
page: page ? Number(page) : void 0,
|
|
62
|
+
perPage: perPage ? Number(perPage) : void 0
|
|
63
|
+
});
|
|
64
|
+
return logs;
|
|
65
|
+
} catch (error) {
|
|
66
|
+
return handleError(error, "Error getting logs by run ID");
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
async function getLogTransports({ mastra }) {
|
|
70
|
+
try {
|
|
71
|
+
const logger = mastra.getLogger();
|
|
72
|
+
const transports = logger.getTransports();
|
|
73
|
+
return {
|
|
74
|
+
transports: transports ? [...transports.keys()] : []
|
|
75
|
+
};
|
|
76
|
+
} catch (error) {
|
|
77
|
+
return handleError(error, "Error getting log Transports");
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export { getLogTransports, getLogsByRunIdHandler, getLogsHandler, logs_exports };
|
|
82
|
+
//# sourceMappingURL=chunk-4MQU6AJN.js.map
|
|
83
|
+
//# sourceMappingURL=chunk-4MQU6AJN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/server/handlers/logs.ts"],"names":[],"mappings":";;;;;AAAA,IAAA,YAAA,GAAA;AAAA,QAAA,CAAA,YAAA,EAAA;AAAA,EAAA,gBAAA,EAAA,MAAA,gBAAA;AAAA,EAAA,qBAAA,EAAA,MAAA,qBAAA;AAAA,EAAA,cAAA,EAAA,MAAA;AAAA,CAAA,CAAA;AAmBA,eAAsB,cAAA,CAAe;AAAA,EACnC,MAAA;AAAA,EACA,WAAA;AAAA,EACA;AACF,CAAA,EAMG;AACD,EAAA,IAAI;AACF,IAAA,YAAA,CAAa,EAAE,aAAa,CAAA;AAE5B,IAAA,MAAM,EAAE,QAAA,EAAU,MAAA,EAAQ,QAAA,EAAU,OAAA,EAAS,UAAU,IAAA,EAAM,OAAA,EAAQ,GAAI,MAAA,IAAU,EAAC;AAGpF,IAAA,MAAM,OAAA,GAAU,WACZ,MAAA,CAAO,WAAA;AAAA,MAAA,CACJ,KAAA,CAAM,QAAQ,QAAQ,CAAA,GAAI,WAAW,CAAC,QAAQ,CAAA,EAAG,GAAA,CAAI,CAAA,IAAA,KAAQ;AAC5D,QAAA,MAAM,CAAC,GAAA,EAAK,KAAK,CAAA,GAAI,IAAA,CAAK,MAAM,GAAG,CAAA;AACnC,QAAA,OAAO,CAAC,KAAK,KAAK,CAAA;AAAA,MACpB,CAAC;AAAA,KACH,GACA,MAAA;AAEJ,IAAA,MAAM,IAAA,GAAO,MAAM,MAAA,CAAO,OAAA,CAAQ,WAAA,EAAc;AAAA,MAC9C,QAAA;AAAA,MACA,MAAA;AAAA,MACA,QAAA;AAAA,MACA,OAAA;AAAA,MACA,IAAA,EAAM,IAAA,GAAO,MAAA,CAAO,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A,EACT,SAAS,KAAA,EAAO;AACd,IAAA,OAAO,WAAA,CAAY,OAAO,8BAA8B,CAAA;AAAA,EAC1D;AACF;AAEA,eAAsB,gBAAA,CAAiB,EAAE,MAAA,EAAO,EAAgC;AAC9E,EAAA,IAAI;AACF,IAAA,MAAM,MAAA,GAAS,OAAO,SAAA,EAAU;AAChC,IAAA,MAAM,UAAA,GAAa,OAAO,aAAA,EAAc;AAExC,IAAA,OAAO;AAAA,MACL,UAAA,EAAY,aAAa,CAAC,GAAG,WAAW,IAAA,EAAM,IAAI;AAAC,KACrD;AAAA,EACF,SAAS,KAAA,EAAO;AACd,IAAA,OAAO,WAAA,CAAY,OAAO,8BAA8B,CAAA;AAAA,EAC1D;AACF","file":"chunk-4MQU6AJN.js","sourcesContent":["import type { BaseLogMessage, LogLevel } from '@mastra/core/logger';\nimport type { Mastra } from '@mastra/core/mastra';\nimport { handleError } from './error';\nimport { validateBody } from './utils';\n\ntype LogsContext = {\n mastra: Mastra;\n transportId?: string;\n runId?: string;\n params?: {\n fromDate?: Date;\n toDate?: Date;\n logLevel?: LogLevel;\n filters?: string | string[];\n page?: number;\n perPage?: number;\n };\n};\n\nexport async function getLogsHandler({\n mastra,\n transportId,\n params,\n}: Pick<LogsContext, 'mastra' | 'transportId' | 'params'>): Promise<{\n logs: BaseLogMessage[];\n total: number;\n page: number;\n perPage: number;\n hasMore: boolean;\n}> {\n try {\n validateBody({ transportId });\n\n const { fromDate, toDate, logLevel, filters: _filters, page, perPage } = params || {};\n\n // Parse filter query parameter if present\n const filters = _filters\n ? Object.fromEntries(\n (Array.isArray(_filters) ? _filters : [_filters]).map(attr => {\n const [key, value] = attr.split(':');\n return [key, value];\n }),\n )\n : undefined;\n\n const logs = await mastra.getLogs(transportId!, {\n fromDate,\n toDate,\n logLevel,\n filters,\n page: page ? Number(page) : undefined,\n perPage: perPage ? Number(perPage) : undefined,\n });\n return logs;\n } catch (error) {\n return handleError(error, 'Error getting logs');\n }\n}\n\nexport async function getLogsByRunIdHandler({\n mastra,\n runId,\n transportId,\n params,\n}: Pick<LogsContext, 'mastra' | 'runId' | 'transportId' | 'params'>) {\n try {\n validateBody({ runId, transportId });\n\n const { fromDate, toDate, logLevel, filters: _filters, page, perPage } = params || {};\n\n // Parse filter query parameter if present\n const filters = _filters\n ? Object.fromEntries(\n (Array.isArray(_filters) ? _filters : [_filters]).map(attr => {\n const [key, value] = attr.split(':');\n return [key, value];\n }),\n )\n : undefined;\n\n const logs = await mastra.getLogsByRunId({\n runId: runId!,\n transportId: transportId!,\n fromDate,\n toDate,\n logLevel,\n filters,\n page: page ? Number(page) : undefined,\n perPage: perPage ? Number(perPage) : undefined,\n });\n return logs;\n } catch (error) {\n return handleError(error, 'Error getting logs by run ID');\n }\n}\n\nexport async function getLogTransports({ mastra }: Pick<LogsContext, 'mastra'>) {\n try {\n const logger = mastra.getLogger();\n const transports = logger.getTransports();\n\n return {\n transports: transports ? [...transports.keys()] : [],\n };\n } catch (error) {\n return handleError(error, 'Error getting log Transports');\n }\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunk7NADHFD2_cjs = require('./chunk-7NADHFD2.cjs');
|
|
4
4
|
|
|
5
5
|
// src/server/handlers/utils.ts
|
|
6
6
|
function validateBody(body) {
|
|
@@ -11,8 +11,10 @@ function validateBody(body) {
|
|
|
11
11
|
return acc;
|
|
12
12
|
}, {});
|
|
13
13
|
if (Object.keys(errorResponse).length > 0) {
|
|
14
|
-
throw new
|
|
14
|
+
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: Object.values(errorResponse)[0] });
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
exports.validateBody = validateBody;
|
|
19
|
+
//# sourceMappingURL=chunk-4QSNRCOT.cjs.map
|
|
20
|
+
//# sourceMappingURL=chunk-4QSNRCOT.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/server/handlers/utils.ts"],"names":["HTTPException"],"mappings":";;;;;AAGO,SAAS,aAAa,IAAA,EAA+B;AAC1D,EAAA,MAAM,aAAA,GAAgB,MAAA,CAAO,OAAA,CAAQ,IAAI,CAAA,CAAE,MAAA,CAA+B,CAAC,GAAA,EAAK,CAAC,GAAA,EAAK,KAAK,CAAA,KAAM;AAC/F,IAAA,IAAI,CAAC,KAAA,EAAO;AACV,MAAA,GAAA,CAAI,GAAG,CAAA,GAAI,CAAA,UAAA,EAAa,GAAG,CAAA,aAAA,CAAA;AAAA,IAC7B;AACA,IAAA,OAAO,GAAA;AAAA,EACT,CAAA,EAAG,EAAE,CAAA;AAEL,EAAA,IAAI,MAAA,CAAO,IAAA,CAAK,aAAa,CAAA,CAAE,SAAS,CAAA,EAAG;AACzC,IAAA,MAAM,IAAIA,+BAAA,CAAc,GAAA,EAAK,EAAE,OAAA,EAAS,MAAA,CAAO,MAAA,CAAO,aAAa,CAAA,CAAE,CAAC,CAAA,EAAG,CAAA;AAAA,EAC3E;AACF","file":"chunk-4QSNRCOT.cjs","sourcesContent":["import { HTTPException } from '../http-exception';\n\n// Validation helper\nexport function validateBody(body: Record<string, unknown>) {\n const errorResponse = Object.entries(body).reduce<Record<string, string>>((acc, [key, value]) => {\n if (!value) {\n acc[key] = `Argument \"${key}\" is required`;\n }\n return acc;\n }, {});\n\n if (Object.keys(errorResponse).length > 0) {\n throw new HTTPException(400, { message: Object.values(errorResponse)[0] });\n }\n}\n"]}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk4QSNRCOT_cjs = require('./chunk-4QSNRCOT.cjs');
|
|
4
|
+
var chunkRE4RPXT2_cjs = require('./chunk-RE4RPXT2.cjs');
|
|
5
|
+
var chunk7NADHFD2_cjs = require('./chunk-7NADHFD2.cjs');
|
|
6
|
+
var chunkQ7SFCCGT_cjs = require('./chunk-Q7SFCCGT.cjs');
|
|
7
|
+
var stream = require('stream');
|
|
8
|
+
|
|
9
|
+
// src/server/handlers/voice.ts
|
|
10
|
+
var voice_exports = {};
|
|
11
|
+
chunkQ7SFCCGT_cjs.__export(voice_exports, {
|
|
12
|
+
generateSpeechHandler: () => generateSpeechHandler,
|
|
13
|
+
getListenerHandler: () => getListenerHandler,
|
|
14
|
+
getSpeakersHandler: () => getSpeakersHandler,
|
|
15
|
+
transcribeSpeechHandler: () => transcribeSpeechHandler
|
|
16
|
+
});
|
|
17
|
+
async function getSpeakersHandler({ mastra, agentId }) {
|
|
18
|
+
try {
|
|
19
|
+
if (!agentId) {
|
|
20
|
+
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Agent ID is required" });
|
|
21
|
+
}
|
|
22
|
+
const agent = mastra.getAgent(agentId);
|
|
23
|
+
if (!agent) {
|
|
24
|
+
throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Agent not found" });
|
|
25
|
+
}
|
|
26
|
+
const voice = await agent.getVoice();
|
|
27
|
+
if (!voice) {
|
|
28
|
+
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Agent does not have voice capabilities" });
|
|
29
|
+
}
|
|
30
|
+
const speakers = await voice.getSpeakers();
|
|
31
|
+
return speakers;
|
|
32
|
+
} catch (error) {
|
|
33
|
+
return chunkRE4RPXT2_cjs.handleError(error, "Error getting speakers");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async function generateSpeechHandler({
|
|
37
|
+
mastra,
|
|
38
|
+
agentId,
|
|
39
|
+
body
|
|
40
|
+
}) {
|
|
41
|
+
try {
|
|
42
|
+
if (!agentId) {
|
|
43
|
+
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Agent ID is required" });
|
|
44
|
+
}
|
|
45
|
+
chunk4QSNRCOT_cjs.validateBody({
|
|
46
|
+
text: body?.text
|
|
47
|
+
});
|
|
48
|
+
const agent = mastra.getAgent(agentId);
|
|
49
|
+
if (!agent) {
|
|
50
|
+
throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Agent not found" });
|
|
51
|
+
}
|
|
52
|
+
const voice = await agent.getVoice();
|
|
53
|
+
if (!voice) {
|
|
54
|
+
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Agent does not have voice capabilities" });
|
|
55
|
+
}
|
|
56
|
+
const audioStream = await voice.speak(body.text, { speaker: body.speakerId });
|
|
57
|
+
if (!audioStream) {
|
|
58
|
+
throw new chunk7NADHFD2_cjs.HTTPException(500, { message: "Failed to generate speech" });
|
|
59
|
+
}
|
|
60
|
+
return audioStream;
|
|
61
|
+
} catch (error) {
|
|
62
|
+
return chunkRE4RPXT2_cjs.handleError(error, "Error generating speech");
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async function transcribeSpeechHandler({
|
|
66
|
+
mastra,
|
|
67
|
+
agentId,
|
|
68
|
+
body
|
|
69
|
+
}) {
|
|
70
|
+
try {
|
|
71
|
+
if (!agentId) {
|
|
72
|
+
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Agent ID is required" });
|
|
73
|
+
}
|
|
74
|
+
if (!body?.audioData) {
|
|
75
|
+
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Audio data is required" });
|
|
76
|
+
}
|
|
77
|
+
const agent = mastra.getAgent(agentId);
|
|
78
|
+
if (!agent) {
|
|
79
|
+
throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Agent not found" });
|
|
80
|
+
}
|
|
81
|
+
const voice = await agent.getVoice();
|
|
82
|
+
if (!voice) {
|
|
83
|
+
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Agent does not have voice capabilities" });
|
|
84
|
+
}
|
|
85
|
+
const audioStream = new stream.Readable();
|
|
86
|
+
audioStream.push(body.audioData);
|
|
87
|
+
audioStream.push(null);
|
|
88
|
+
const text = await voice.listen(audioStream, body.options);
|
|
89
|
+
return { text };
|
|
90
|
+
} catch (error) {
|
|
91
|
+
return chunkRE4RPXT2_cjs.handleError(error, "Error transcribing speech");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
async function getListenerHandler({ mastra, agentId }) {
|
|
95
|
+
try {
|
|
96
|
+
if (!agentId) {
|
|
97
|
+
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Agent ID is required" });
|
|
98
|
+
}
|
|
99
|
+
const agent = mastra.getAgent(agentId);
|
|
100
|
+
if (!agent) {
|
|
101
|
+
throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Agent not found" });
|
|
102
|
+
}
|
|
103
|
+
const voice = await agent.getVoice();
|
|
104
|
+
if (!voice) {
|
|
105
|
+
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Agent does not have voice capabilities" });
|
|
106
|
+
}
|
|
107
|
+
const listeners = await voice.getListener();
|
|
108
|
+
return listeners;
|
|
109
|
+
} catch (error) {
|
|
110
|
+
return chunkRE4RPXT2_cjs.handleError(error, "Error getting listeners");
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
exports.generateSpeechHandler = generateSpeechHandler;
|
|
115
|
+
exports.getListenerHandler = getListenerHandler;
|
|
116
|
+
exports.getSpeakersHandler = getSpeakersHandler;
|
|
117
|
+
exports.transcribeSpeechHandler = transcribeSpeechHandler;
|
|
118
|
+
exports.voice_exports = voice_exports;
|
|
119
|
+
//# sourceMappingURL=chunk-4US5W7PH.cjs.map
|
|
120
|
+
//# sourceMappingURL=chunk-4US5W7PH.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/server/handlers/voice.ts"],"names":["__export","HTTPException","handleError","validateBody","Readable"],"mappings":";;;;;;;;;AAAA,IAAA,aAAA,GAAA;AAAAA,0BAAA,CAAA,aAAA,EAAA;AAAA,EAAA,qBAAA,EAAA,MAAA,qBAAA;AAAA,EAAA,kBAAA,EAAA,MAAA,kBAAA;AAAA,EAAA,kBAAA,EAAA,MAAA,kBAAA;AAAA,EAAA,uBAAA,EAAA,MAAA;AAAA,CAAA,CAAA;AAeA,eAAs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,KAAA,EAAO;AACd,IAAA,OAAOC,6BAAA,CAAY,OAAO,yBAAyB,CAAA;AAAA,EACrD;AACF","file":"chunk-4US5W7PH.cjs","sourcesContent":["import { Readable } from 'stream';\nimport type { Agent } from '@mastra/core/agent';\nimport { HTTPException } from '../http-exception';\nimport type { Context } from '../types';\n\nimport { handleError } from './error';\nimport { validateBody } from './utils';\n\ninterface VoiceContext extends Context {\n agentId?: string;\n}\n\n/**\n * Get available speakers for an agent\n */\nexport async function getSpeakersHandler({ mastra, agentId }: VoiceContext) {\n try {\n if (!agentId) {\n throw new HTTPException(400, { message: 'Agent ID is required' });\n }\n\n const agent = mastra.getAgent(agentId);\n\n if (!agent) {\n throw new HTTPException(404, { message: 'Agent not found' });\n }\n\n const voice = await agent.getVoice();\n\n if (!voice) {\n throw new HTTPException(400, { message: 'Agent does not have voice capabilities' });\n }\n\n const speakers = await voice.getSpeakers();\n return speakers;\n } catch (error) {\n return handleError(error, 'Error getting speakers');\n }\n}\n\n/**\n * Generate speech from text\n */\nexport async function generateSpeechHandler({\n mastra,\n agentId,\n body,\n}: VoiceContext & {\n body?: {\n text?: string;\n speakerId?: string;\n };\n}) {\n try {\n if (!agentId) {\n throw new HTTPException(400, { message: 'Agent ID is required' });\n }\n\n validateBody({\n text: body?.text,\n });\n\n const agent = mastra.getAgent(agentId);\n\n if (!agent) {\n throw new HTTPException(404, { message: 'Agent not found' });\n }\n\n const voice = await agent.getVoice();\n\n if (!voice) {\n throw new HTTPException(400, { message: 'Agent does not have voice capabilities' });\n }\n\n const audioStream = await voice.speak(body!.text!, { speaker: body!.speakerId! });\n\n if (!audioStream) {\n throw new HTTPException(500, { message: 'Failed to generate speech' });\n }\n\n return audioStream;\n } catch (error) {\n return handleError(error, 'Error generating speech');\n }\n}\n\n/**\n * Transcribe speech to text\n */\nexport async function transcribeSpeechHandler({\n mastra,\n agentId,\n body,\n}: VoiceContext & {\n body?: {\n audioData?: Buffer;\n options?: Parameters<NonNullable<Agent['voice']>['listen']>[1];\n };\n}) {\n try {\n if (!agentId) {\n throw new HTTPException(400, { message: 'Agent ID is required' });\n }\n\n if (!body?.audioData) {\n throw new HTTPException(400, { message: 'Audio data is required' });\n }\n\n const agent = mastra.getAgent(agentId);\n\n if (!agent) {\n throw new HTTPException(404, { message: 'Agent not found' });\n }\n\n const voice = await agent.getVoice();\n\n if (!voice) {\n throw new HTTPException(400, { message: 'Agent does not have voice capabilities' });\n }\n\n const audioStream = new Readable();\n audioStream.push(body.audioData);\n audioStream.push(null);\n\n const text = await voice.listen(audioStream, body.options);\n return { text };\n } catch (error) {\n return handleError(error, 'Error transcribing speech');\n }\n}\n\n/**\n * Get available listeners for an agent\n */\nexport async function getListenerHandler({ mastra, agentId }: VoiceContext) {\n try {\n if (!agentId) {\n throw new HTTPException(400, { message: 'Agent ID is required' });\n }\n\n const agent = mastra.getAgent(agentId);\n\n if (!agent) {\n throw new HTTPException(404, { message: 'Agent not found' });\n }\n\n const voice = await agent.getVoice();\n\n if (!voice) {\n throw new HTTPException(400, { message: 'Agent does not have voice capabilities' });\n }\n\n const listeners = await voice.getListener();\n return listeners;\n } catch (error) {\n return handleError(error, 'Error getting listeners');\n }\n}\n"]}
|