@mastra/deployer 0.2.2 → 0.2.3
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/dist/_tsup-dts-rollup.d.cts +14 -32
- package/dist/_tsup-dts-rollup.d.ts +14 -32
- package/dist/server/index.cjs +463 -5
- package/dist/server/index.js +463 -5
- package/package.json +2 -2
|
@@ -7,14 +7,12 @@ import type { IDeployer } from '@mastra/core/deployer';
|
|
|
7
7
|
import { InputOption } from 'rollup';
|
|
8
8
|
import { InputOptions } from 'rollup';
|
|
9
9
|
import type { Logger } from '@mastra/core/logger';
|
|
10
|
-
import { Logger as Logger_2 } from '@mastra/core';
|
|
11
|
-
import { Mastra } from '@mastra/core
|
|
12
|
-
import type { Mastra as Mastra_2 } from '@mastra/core';
|
|
10
|
+
import type { Logger as Logger_2 } from '@mastra/core';
|
|
11
|
+
import type { Mastra } from '@mastra/core';
|
|
13
12
|
import { MastraBase } from '@mastra/core/base';
|
|
14
13
|
import { MastraBundler } from '@mastra/core/bundler';
|
|
15
14
|
import type { MastraDeployer } from '@mastra/core';
|
|
16
|
-
import {
|
|
17
|
-
import { MastraVector } from '@mastra/core/vector';
|
|
15
|
+
import type { MastraVector } from '@mastra/core/vector';
|
|
18
16
|
import { OutputOptions } from 'rollup';
|
|
19
17
|
import { Plugin } from 'rollup';
|
|
20
18
|
import { PluginContext } from 'rollup';
|
|
@@ -25,12 +23,8 @@ import { RollupBuild } from 'rollup';
|
|
|
25
23
|
import { RollupOutput } from 'rollup';
|
|
26
24
|
import { RollupWatcher } from 'rollup';
|
|
27
25
|
import { ServerType } from '@hono/node-server';
|
|
28
|
-
import { Step } from '@mastra/core';
|
|
29
|
-
import { StepExecutionContext } from '@mastra/core';
|
|
30
26
|
import { Transform } from 'stream';
|
|
31
27
|
import { TypedResponse } from 'hono';
|
|
32
|
-
import { Workflow } from '@mastra/core/workflows';
|
|
33
|
-
import { WorkflowContext } from '@mastra/core';
|
|
34
28
|
|
|
35
29
|
export declare function aliasHono(): Plugin;
|
|
36
30
|
|
|
@@ -101,7 +95,7 @@ export { createChildProcessLogger }
|
|
|
101
95
|
export { createChildProcessLogger as createChildProcessLogger_alias_1 }
|
|
102
96
|
export { createChildProcessLogger as createChildProcessLogger_alias_2 }
|
|
103
97
|
|
|
104
|
-
export declare function createHonoServer(mastra:
|
|
98
|
+
export declare function createHonoServer(mastra: Mastra, options?: {
|
|
105
99
|
playground?: boolean;
|
|
106
100
|
swaggerUI?: boolean;
|
|
107
101
|
apiReqLogs?: boolean;
|
|
@@ -112,7 +106,7 @@ export declare function createHonoServer(mastra: Mastra_2, options?: {
|
|
|
112
106
|
|
|
113
107
|
export declare function createIndex(c: Context): Promise<Response>;
|
|
114
108
|
|
|
115
|
-
export declare function createNodeServer(mastra:
|
|
109
|
+
export declare function createNodeServer(mastra: Mastra, options?: {
|
|
116
110
|
playground?: boolean;
|
|
117
111
|
swaggerUI?: boolean;
|
|
118
112
|
apiReqLogs?: boolean;
|
|
@@ -217,6 +211,8 @@ export { FileService as FileService_alias_2 }
|
|
|
217
211
|
|
|
218
212
|
export declare function generateHandler(c: Context): Promise<Response>;
|
|
219
213
|
|
|
214
|
+
export declare function generateHandler_alias_1(c: Context): Promise<Response>;
|
|
215
|
+
|
|
220
216
|
export declare function generateSystemPromptHandler(c: Context): Promise<Response>;
|
|
221
217
|
|
|
222
218
|
export declare function getAgentByIdHandler(c: Context): Promise<Response>;
|
|
@@ -258,6 +254,10 @@ export declare function getMemoryStatusHandler(c: Context): Promise<Response>;
|
|
|
258
254
|
|
|
259
255
|
export declare function getMessagesHandler(c: Context): Promise<Response>;
|
|
260
256
|
|
|
257
|
+
export declare function getNetworkByIdHandler(c: Context): Promise<Response>;
|
|
258
|
+
|
|
259
|
+
export declare function getNetworksHandler(c: Context): Promise<Response>;
|
|
260
|
+
|
|
261
261
|
/**
|
|
262
262
|
* Get available speakers for an agent
|
|
263
263
|
*/
|
|
@@ -310,26 +310,6 @@ export declare function listenHandler(c: Context): Promise<Response>;
|
|
|
310
310
|
|
|
311
311
|
export declare function listIndexes(c: Context): Promise<Response>;
|
|
312
312
|
|
|
313
|
-
export declare const mastra: Mastra<{
|
|
314
|
-
weatherAgent: any;
|
|
315
|
-
}, Record<string, Workflow<Step<string, any, any, StepExecutionContext<any, WorkflowContext<any, Step<string, any, any, any>[], Record<string, any>>>>[], any>>, Record<string, MastraVector>, Record<string, MastraTTS>, Logger_2>;
|
|
316
|
-
|
|
317
|
-
export declare const mastra_alias_1: Mastra<{
|
|
318
|
-
weatherAgent: any;
|
|
319
|
-
}, Record<string, Workflow<Step<string, any, any, StepExecutionContext<any, WorkflowContext<any, Step<string, any, any, any>[], Record<string, any>>>>[], any>>, Record<string, MastraVector>, Record<string, MastraTTS>, Logger_2>;
|
|
320
|
-
|
|
321
|
-
export declare const mastra_alias_2: Mastra<{
|
|
322
|
-
weatherAgent: any;
|
|
323
|
-
}, Record<string, Workflow<Step<string, any, any, StepExecutionContext<any, WorkflowContext<any, Step<string, any, any, any>[], Record<string, any>>>>[], any>>, Record<string, MastraVector>, Record<string, MastraTTS>, Logger_2>;
|
|
324
|
-
|
|
325
|
-
export declare const mastra_alias_3: Mastra<{
|
|
326
|
-
weatherAgent: any;
|
|
327
|
-
}, Record<string, Workflow<Step<string, any, any, StepExecutionContext<any, WorkflowContext<any, Step<string, any, any, any>[], Record<string, any>>>>[], any>>, Record<string, MastraVector>, Record<string, MastraTTS>, Logger_2>;
|
|
328
|
-
|
|
329
|
-
export declare const mastra_alias_4: Mastra<{
|
|
330
|
-
weatherAgent: any;
|
|
331
|
-
}, Record<string, Workflow<Step<string, any, any, StepExecutionContext<any, WorkflowContext<any, Step<string, any, any, any>[], Record<string, any>>>>[], any>>, Record<string, MastraVector>, Record<string, MastraTTS>, Logger_2>;
|
|
332
|
-
|
|
333
313
|
declare type NormalizedInputOptions = Omit<Partial<InputOptions>, 'plugins' | 'input' | 'external'> & {
|
|
334
314
|
plugins?: Plugin[];
|
|
335
315
|
input: InputOption;
|
|
@@ -392,6 +372,8 @@ export declare function startWorkflowRunHandler(c: Context): Promise<Response>;
|
|
|
392
372
|
|
|
393
373
|
export declare function streamGenerateHandler(c: Context): Promise<Response | undefined>;
|
|
394
374
|
|
|
375
|
+
export declare function streamGenerateHandler_alias_1(c: Context): Promise<Response | undefined>;
|
|
376
|
+
|
|
395
377
|
export declare function tsConfigPaths({ tsConfigPath, respectCoreModule }?: PluginOptions): Plugin;
|
|
396
378
|
|
|
397
379
|
export declare function updateThreadHandler(c: Context): Promise<Response>;
|
|
@@ -407,7 +389,7 @@ export declare function validate(file: string): Promise<void>;
|
|
|
407
389
|
export declare function validateBody(body: Record<string, unknown>): void;
|
|
408
390
|
|
|
409
391
|
declare type Variables = {
|
|
410
|
-
mastra:
|
|
392
|
+
mastra: Mastra;
|
|
411
393
|
clients: Set<{
|
|
412
394
|
controller: ReadableStreamDefaultController;
|
|
413
395
|
}>;
|
|
@@ -7,14 +7,12 @@ import type { IDeployer } from '@mastra/core/deployer';
|
|
|
7
7
|
import { InputOption } from 'rollup';
|
|
8
8
|
import { InputOptions } from 'rollup';
|
|
9
9
|
import type { Logger } from '@mastra/core/logger';
|
|
10
|
-
import { Logger as Logger_2 } from '@mastra/core';
|
|
11
|
-
import { Mastra } from '@mastra/core
|
|
12
|
-
import type { Mastra as Mastra_2 } from '@mastra/core';
|
|
10
|
+
import type { Logger as Logger_2 } from '@mastra/core';
|
|
11
|
+
import type { Mastra } from '@mastra/core';
|
|
13
12
|
import { MastraBase } from '@mastra/core/base';
|
|
14
13
|
import { MastraBundler } from '@mastra/core/bundler';
|
|
15
14
|
import type { MastraDeployer } from '@mastra/core';
|
|
16
|
-
import {
|
|
17
|
-
import { MastraVector } from '@mastra/core/vector';
|
|
15
|
+
import type { MastraVector } from '@mastra/core/vector';
|
|
18
16
|
import { OutputOptions } from 'rollup';
|
|
19
17
|
import { Plugin } from 'rollup';
|
|
20
18
|
import { PluginContext } from 'rollup';
|
|
@@ -25,12 +23,8 @@ import { RollupBuild } from 'rollup';
|
|
|
25
23
|
import { RollupOutput } from 'rollup';
|
|
26
24
|
import { RollupWatcher } from 'rollup';
|
|
27
25
|
import { ServerType } from '@hono/node-server';
|
|
28
|
-
import { Step } from '@mastra/core';
|
|
29
|
-
import { StepExecutionContext } from '@mastra/core';
|
|
30
26
|
import { Transform } from 'stream';
|
|
31
27
|
import { TypedResponse } from 'hono';
|
|
32
|
-
import { Workflow } from '@mastra/core/workflows';
|
|
33
|
-
import { WorkflowContext } from '@mastra/core';
|
|
34
28
|
|
|
35
29
|
export declare function aliasHono(): Plugin;
|
|
36
30
|
|
|
@@ -101,7 +95,7 @@ export { createChildProcessLogger }
|
|
|
101
95
|
export { createChildProcessLogger as createChildProcessLogger_alias_1 }
|
|
102
96
|
export { createChildProcessLogger as createChildProcessLogger_alias_2 }
|
|
103
97
|
|
|
104
|
-
export declare function createHonoServer(mastra:
|
|
98
|
+
export declare function createHonoServer(mastra: Mastra, options?: {
|
|
105
99
|
playground?: boolean;
|
|
106
100
|
swaggerUI?: boolean;
|
|
107
101
|
apiReqLogs?: boolean;
|
|
@@ -112,7 +106,7 @@ export declare function createHonoServer(mastra: Mastra_2, options?: {
|
|
|
112
106
|
|
|
113
107
|
export declare function createIndex(c: Context): Promise<Response>;
|
|
114
108
|
|
|
115
|
-
export declare function createNodeServer(mastra:
|
|
109
|
+
export declare function createNodeServer(mastra: Mastra, options?: {
|
|
116
110
|
playground?: boolean;
|
|
117
111
|
swaggerUI?: boolean;
|
|
118
112
|
apiReqLogs?: boolean;
|
|
@@ -217,6 +211,8 @@ export { FileService as FileService_alias_2 }
|
|
|
217
211
|
|
|
218
212
|
export declare function generateHandler(c: Context): Promise<Response>;
|
|
219
213
|
|
|
214
|
+
export declare function generateHandler_alias_1(c: Context): Promise<Response>;
|
|
215
|
+
|
|
220
216
|
export declare function generateSystemPromptHandler(c: Context): Promise<Response>;
|
|
221
217
|
|
|
222
218
|
export declare function getAgentByIdHandler(c: Context): Promise<Response>;
|
|
@@ -258,6 +254,10 @@ export declare function getMemoryStatusHandler(c: Context): Promise<Response>;
|
|
|
258
254
|
|
|
259
255
|
export declare function getMessagesHandler(c: Context): Promise<Response>;
|
|
260
256
|
|
|
257
|
+
export declare function getNetworkByIdHandler(c: Context): Promise<Response>;
|
|
258
|
+
|
|
259
|
+
export declare function getNetworksHandler(c: Context): Promise<Response>;
|
|
260
|
+
|
|
261
261
|
/**
|
|
262
262
|
* Get available speakers for an agent
|
|
263
263
|
*/
|
|
@@ -310,26 +310,6 @@ export declare function listenHandler(c: Context): Promise<Response>;
|
|
|
310
310
|
|
|
311
311
|
export declare function listIndexes(c: Context): Promise<Response>;
|
|
312
312
|
|
|
313
|
-
export declare const mastra: Mastra<{
|
|
314
|
-
weatherAgent: any;
|
|
315
|
-
}, Record<string, Workflow<Step<string, any, any, StepExecutionContext<any, WorkflowContext<any, Step<string, any, any, any>[], Record<string, any>>>>[], any>>, Record<string, MastraVector>, Record<string, MastraTTS>, Logger_2>;
|
|
316
|
-
|
|
317
|
-
export declare const mastra_alias_1: Mastra<{
|
|
318
|
-
weatherAgent: any;
|
|
319
|
-
}, Record<string, Workflow<Step<string, any, any, StepExecutionContext<any, WorkflowContext<any, Step<string, any, any, any>[], Record<string, any>>>>[], any>>, Record<string, MastraVector>, Record<string, MastraTTS>, Logger_2>;
|
|
320
|
-
|
|
321
|
-
export declare const mastra_alias_2: Mastra<{
|
|
322
|
-
weatherAgent: any;
|
|
323
|
-
}, Record<string, Workflow<Step<string, any, any, StepExecutionContext<any, WorkflowContext<any, Step<string, any, any, any>[], Record<string, any>>>>[], any>>, Record<string, MastraVector>, Record<string, MastraTTS>, Logger_2>;
|
|
324
|
-
|
|
325
|
-
export declare const mastra_alias_3: Mastra<{
|
|
326
|
-
weatherAgent: any;
|
|
327
|
-
}, Record<string, Workflow<Step<string, any, any, StepExecutionContext<any, WorkflowContext<any, Step<string, any, any, any>[], Record<string, any>>>>[], any>>, Record<string, MastraVector>, Record<string, MastraTTS>, Logger_2>;
|
|
328
|
-
|
|
329
|
-
export declare const mastra_alias_4: Mastra<{
|
|
330
|
-
weatherAgent: any;
|
|
331
|
-
}, Record<string, Workflow<Step<string, any, any, StepExecutionContext<any, WorkflowContext<any, Step<string, any, any, any>[], Record<string, any>>>>[], any>>, Record<string, MastraVector>, Record<string, MastraTTS>, Logger_2>;
|
|
332
|
-
|
|
333
313
|
declare type NormalizedInputOptions = Omit<Partial<InputOptions>, 'plugins' | 'input' | 'external'> & {
|
|
334
314
|
plugins?: Plugin[];
|
|
335
315
|
input: InputOption;
|
|
@@ -392,6 +372,8 @@ export declare function startWorkflowRunHandler(c: Context): Promise<Response>;
|
|
|
392
372
|
|
|
393
373
|
export declare function streamGenerateHandler(c: Context): Promise<Response | undefined>;
|
|
394
374
|
|
|
375
|
+
export declare function streamGenerateHandler_alias_1(c: Context): Promise<Response | undefined>;
|
|
376
|
+
|
|
395
377
|
export declare function tsConfigPaths({ tsConfigPath, respectCoreModule }?: PluginOptions): Plugin;
|
|
396
378
|
|
|
397
379
|
export declare function updateThreadHandler(c: Context): Promise<Response>;
|
|
@@ -407,7 +389,7 @@ export declare function validate(file: string): Promise<void>;
|
|
|
407
389
|
export declare function validateBody(body: Record<string, unknown>): void;
|
|
408
390
|
|
|
409
391
|
declare type Variables = {
|
|
410
|
-
mastra:
|
|
392
|
+
mastra: Mastra;
|
|
411
393
|
clients: Set<{
|
|
412
394
|
controller: ReadableStreamDefaultController;
|
|
413
395
|
}>;
|
package/dist/server/index.cjs
CHANGED
|
@@ -3247,6 +3247,113 @@ async function getMessagesHandler(c2) {
|
|
|
3247
3247
|
return handleError(error, "Error getting messages");
|
|
3248
3248
|
}
|
|
3249
3249
|
}
|
|
3250
|
+
async function getNetworksHandler(c2) {
|
|
3251
|
+
try {
|
|
3252
|
+
const mastra = c2.get("mastra");
|
|
3253
|
+
const networks = mastra.getNetworks();
|
|
3254
|
+
const serializedNetworks = networks.map((network) => {
|
|
3255
|
+
const routingAgent = network.getRoutingAgent();
|
|
3256
|
+
const agents = network.getAgents();
|
|
3257
|
+
return {
|
|
3258
|
+
id: network.formatAgentId(routingAgent.name),
|
|
3259
|
+
name: routingAgent.name,
|
|
3260
|
+
instructions: routingAgent.instructions,
|
|
3261
|
+
agents: agents.map((agent) => ({
|
|
3262
|
+
name: agent.name,
|
|
3263
|
+
provider: agent.llm?.getProvider(),
|
|
3264
|
+
modelId: agent.llm?.getModelId()
|
|
3265
|
+
})),
|
|
3266
|
+
routingModel: {
|
|
3267
|
+
provider: routingAgent.llm?.getProvider(),
|
|
3268
|
+
modelId: routingAgent.llm?.getModelId()
|
|
3269
|
+
}
|
|
3270
|
+
};
|
|
3271
|
+
});
|
|
3272
|
+
return c2.json(serializedNetworks);
|
|
3273
|
+
} catch (error) {
|
|
3274
|
+
return handleError(error, "Error getting networks");
|
|
3275
|
+
}
|
|
3276
|
+
}
|
|
3277
|
+
async function getNetworkByIdHandler(c2) {
|
|
3278
|
+
try {
|
|
3279
|
+
const mastra = c2.get("mastra");
|
|
3280
|
+
const networkId = c2.req.param("networkId");
|
|
3281
|
+
const networks = mastra.getNetworks();
|
|
3282
|
+
const network = networks.find((network2) => {
|
|
3283
|
+
const routingAgent2 = network2.getRoutingAgent();
|
|
3284
|
+
return network2.formatAgentId(routingAgent2.name) === networkId;
|
|
3285
|
+
});
|
|
3286
|
+
if (!network) {
|
|
3287
|
+
return c2.json({ error: "Network not found" }, 404);
|
|
3288
|
+
}
|
|
3289
|
+
const routingAgent = network.getRoutingAgent();
|
|
3290
|
+
const agents = network.getAgents();
|
|
3291
|
+
const serializedNetwork = {
|
|
3292
|
+
id: network.formatAgentId(routingAgent.name),
|
|
3293
|
+
name: routingAgent.name,
|
|
3294
|
+
instructions: routingAgent.instructions,
|
|
3295
|
+
agents: agents.map((agent) => ({
|
|
3296
|
+
name: agent.name,
|
|
3297
|
+
provider: agent.llm?.getProvider(),
|
|
3298
|
+
modelId: agent.llm?.getModelId()
|
|
3299
|
+
})),
|
|
3300
|
+
routingModel: {
|
|
3301
|
+
provider: routingAgent.llm?.getProvider(),
|
|
3302
|
+
modelId: routingAgent.llm?.getModelId()
|
|
3303
|
+
}
|
|
3304
|
+
};
|
|
3305
|
+
return c2.json(serializedNetwork);
|
|
3306
|
+
} catch (error) {
|
|
3307
|
+
return handleError(error, "Error getting network by ID");
|
|
3308
|
+
}
|
|
3309
|
+
}
|
|
3310
|
+
async function generateHandler2(c2) {
|
|
3311
|
+
try {
|
|
3312
|
+
const mastra = c2.get("mastra");
|
|
3313
|
+
const networkId = c2.req.param("networkId");
|
|
3314
|
+
const network = mastra.getNetwork(networkId);
|
|
3315
|
+
if (!network) {
|
|
3316
|
+
throw new httpException.HTTPException(404, { message: "Network not found" });
|
|
3317
|
+
}
|
|
3318
|
+
const { messages, threadId, resourceid, resourceId, output, runId, ...rest } = await c2.req.json();
|
|
3319
|
+
validateBody({ messages });
|
|
3320
|
+
const finalResourceId = resourceId ?? resourceid;
|
|
3321
|
+
const result = await network.generate(messages, { threadId, resourceId: finalResourceId, output, runId, ...rest });
|
|
3322
|
+
return c2.json(result);
|
|
3323
|
+
} catch (error) {
|
|
3324
|
+
return handleError(error, "Error generating from network");
|
|
3325
|
+
}
|
|
3326
|
+
}
|
|
3327
|
+
async function streamGenerateHandler2(c2) {
|
|
3328
|
+
try {
|
|
3329
|
+
const mastra = c2.get("mastra");
|
|
3330
|
+
const networkId = c2.req.param("networkId");
|
|
3331
|
+
const network = mastra.getNetwork(networkId);
|
|
3332
|
+
if (!network) {
|
|
3333
|
+
throw new httpException.HTTPException(404, { message: "Network not found" });
|
|
3334
|
+
}
|
|
3335
|
+
const { messages, threadId, resourceid, resourceId, output, runId, ...rest } = await c2.req.json();
|
|
3336
|
+
validateBody({ messages });
|
|
3337
|
+
const finalResourceId = resourceId ?? resourceid;
|
|
3338
|
+
const streamResult = await network.stream(messages, {
|
|
3339
|
+
threadId,
|
|
3340
|
+
resourceId: finalResourceId,
|
|
3341
|
+
output,
|
|
3342
|
+
runId,
|
|
3343
|
+
...rest
|
|
3344
|
+
});
|
|
3345
|
+
const streamResponse = output ? streamResult.toTextStreamResponse() : streamResult.toDataStreamResponse({
|
|
3346
|
+
sendUsage: true,
|
|
3347
|
+
sendReasoning: true,
|
|
3348
|
+
getErrorMessage: (error) => {
|
|
3349
|
+
return `An error occurred while processing your request. ${error instanceof Error ? error.message : JSON.stringify(error)}`;
|
|
3350
|
+
}
|
|
3351
|
+
});
|
|
3352
|
+
return streamResponse;
|
|
3353
|
+
} catch (error) {
|
|
3354
|
+
return handleError(error, "Error streaming from network");
|
|
3355
|
+
}
|
|
3356
|
+
}
|
|
3250
3357
|
async function generateSystemPromptHandler(c2) {
|
|
3251
3358
|
try {
|
|
3252
3359
|
const agentId = c2.req.param("agentId");
|
|
@@ -3615,7 +3722,7 @@ async function speakHandler(c2) {
|
|
|
3615
3722
|
}
|
|
3616
3723
|
const { input, options } = await c2.req.json();
|
|
3617
3724
|
await validateBody({ input });
|
|
3618
|
-
const audioStream = await agent.speak(input, options);
|
|
3725
|
+
const audioStream = await agent.voice.speak(input, options);
|
|
3619
3726
|
c2.header("Content-Type", `audio/${options.filetype ?? "mp3"}`);
|
|
3620
3727
|
c2.header("Transfer-Encoding", "chunked");
|
|
3621
3728
|
return c2.body(audioStream);
|
|
@@ -3628,18 +3735,33 @@ async function listenHandler(c2) {
|
|
|
3628
3735
|
const mastra = c2.get("mastra");
|
|
3629
3736
|
const agentId = c2.req.param("agentId");
|
|
3630
3737
|
const agent = mastra.getAgent(agentId);
|
|
3738
|
+
const logger2 = mastra.getLogger();
|
|
3631
3739
|
if (!agent) {
|
|
3632
3740
|
throw new httpException.HTTPException(404, { message: "Agent not found" });
|
|
3633
3741
|
}
|
|
3634
3742
|
if (!agent.voice) {
|
|
3635
3743
|
throw new httpException.HTTPException(400, { message: "Agent does not have voice capabilities" });
|
|
3636
3744
|
}
|
|
3637
|
-
const
|
|
3745
|
+
const formData = await c2.req.formData();
|
|
3746
|
+
const audioFile = formData.get("audio");
|
|
3747
|
+
const options = formData.get("options");
|
|
3748
|
+
if (!audioFile || !(audioFile instanceof File)) {
|
|
3749
|
+
throw new httpException.HTTPException(400, { message: "Audio file is required" });
|
|
3750
|
+
}
|
|
3751
|
+
const audioData = await audioFile.arrayBuffer();
|
|
3638
3752
|
const audioStream = new stream.Readable();
|
|
3639
3753
|
audioStream.push(Buffer.from(audioData));
|
|
3640
3754
|
audioStream.push(null);
|
|
3641
|
-
|
|
3642
|
-
|
|
3755
|
+
let parsedOptions;
|
|
3756
|
+
try {
|
|
3757
|
+
parsedOptions = options ? JSON.parse(options) : {};
|
|
3758
|
+
} catch (error) {
|
|
3759
|
+
if (error instanceof SyntaxError) {
|
|
3760
|
+
logger2.error("Invalid JSON in options:", error);
|
|
3761
|
+
}
|
|
3762
|
+
parsedOptions = {};
|
|
3763
|
+
}
|
|
3764
|
+
const transcription = await agent.voice.listen(audioStream, parsedOptions);
|
|
3643
3765
|
return c2.json({ text: transcription });
|
|
3644
3766
|
} catch (error) {
|
|
3645
3767
|
return handleError(error, "Error transcribing speech");
|
|
@@ -4025,6 +4147,139 @@ async function createHonoServer(mastra, options = {}) {
|
|
|
4025
4147
|
}),
|
|
4026
4148
|
getAgentsHandler
|
|
4027
4149
|
);
|
|
4150
|
+
app.get(
|
|
4151
|
+
"/api/networks",
|
|
4152
|
+
h({
|
|
4153
|
+
description: "Get all available networks",
|
|
4154
|
+
tags: ["networks"],
|
|
4155
|
+
responses: {
|
|
4156
|
+
200: {
|
|
4157
|
+
description: "List of all networks"
|
|
4158
|
+
}
|
|
4159
|
+
}
|
|
4160
|
+
}),
|
|
4161
|
+
getNetworksHandler
|
|
4162
|
+
);
|
|
4163
|
+
app.get(
|
|
4164
|
+
"/api/networks/:networkId",
|
|
4165
|
+
h({
|
|
4166
|
+
description: "Get network by ID",
|
|
4167
|
+
tags: ["networks"],
|
|
4168
|
+
parameters: [
|
|
4169
|
+
{
|
|
4170
|
+
name: "networkId",
|
|
4171
|
+
in: "path",
|
|
4172
|
+
required: true,
|
|
4173
|
+
schema: { type: "string" }
|
|
4174
|
+
}
|
|
4175
|
+
],
|
|
4176
|
+
responses: {
|
|
4177
|
+
200: {
|
|
4178
|
+
description: "Network details"
|
|
4179
|
+
},
|
|
4180
|
+
404: {
|
|
4181
|
+
description: "Network not found"
|
|
4182
|
+
}
|
|
4183
|
+
}
|
|
4184
|
+
}),
|
|
4185
|
+
getNetworkByIdHandler
|
|
4186
|
+
);
|
|
4187
|
+
app.post(
|
|
4188
|
+
"/api/networks/:networkId/generate",
|
|
4189
|
+
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
4190
|
+
h({
|
|
4191
|
+
description: "Generate a response from a network",
|
|
4192
|
+
tags: ["networks"],
|
|
4193
|
+
parameters: [
|
|
4194
|
+
{
|
|
4195
|
+
name: "networkId",
|
|
4196
|
+
in: "path",
|
|
4197
|
+
required: true,
|
|
4198
|
+
schema: { type: "string" }
|
|
4199
|
+
}
|
|
4200
|
+
],
|
|
4201
|
+
requestBody: {
|
|
4202
|
+
required: true,
|
|
4203
|
+
content: {
|
|
4204
|
+
"application/json": {
|
|
4205
|
+
schema: {
|
|
4206
|
+
type: "object",
|
|
4207
|
+
properties: {
|
|
4208
|
+
input: {
|
|
4209
|
+
oneOf: [
|
|
4210
|
+
{ type: "string" },
|
|
4211
|
+
{
|
|
4212
|
+
type: "array",
|
|
4213
|
+
items: { type: "object" }
|
|
4214
|
+
}
|
|
4215
|
+
],
|
|
4216
|
+
description: "Input for the network, can be a string or an array of CoreMessage objects"
|
|
4217
|
+
}
|
|
4218
|
+
},
|
|
4219
|
+
required: ["input"]
|
|
4220
|
+
}
|
|
4221
|
+
}
|
|
4222
|
+
}
|
|
4223
|
+
},
|
|
4224
|
+
responses: {
|
|
4225
|
+
200: {
|
|
4226
|
+
description: "Generated response"
|
|
4227
|
+
},
|
|
4228
|
+
404: {
|
|
4229
|
+
description: "Network not found"
|
|
4230
|
+
}
|
|
4231
|
+
}
|
|
4232
|
+
}),
|
|
4233
|
+
generateHandler2
|
|
4234
|
+
);
|
|
4235
|
+
app.post(
|
|
4236
|
+
"/api/networks/:networkId/stream",
|
|
4237
|
+
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
4238
|
+
h({
|
|
4239
|
+
description: "Generate a response from a network",
|
|
4240
|
+
tags: ["networks"],
|
|
4241
|
+
parameters: [
|
|
4242
|
+
{
|
|
4243
|
+
name: "networkId",
|
|
4244
|
+
in: "path",
|
|
4245
|
+
required: true,
|
|
4246
|
+
schema: { type: "string" }
|
|
4247
|
+
}
|
|
4248
|
+
],
|
|
4249
|
+
requestBody: {
|
|
4250
|
+
required: true,
|
|
4251
|
+
content: {
|
|
4252
|
+
"application/json": {
|
|
4253
|
+
schema: {
|
|
4254
|
+
type: "object",
|
|
4255
|
+
properties: {
|
|
4256
|
+
input: {
|
|
4257
|
+
oneOf: [
|
|
4258
|
+
{ type: "string" },
|
|
4259
|
+
{
|
|
4260
|
+
type: "array",
|
|
4261
|
+
items: { type: "object" }
|
|
4262
|
+
}
|
|
4263
|
+
],
|
|
4264
|
+
description: "Input for the network, can be a string or an array of CoreMessage objects"
|
|
4265
|
+
}
|
|
4266
|
+
},
|
|
4267
|
+
required: ["input"]
|
|
4268
|
+
}
|
|
4269
|
+
}
|
|
4270
|
+
}
|
|
4271
|
+
},
|
|
4272
|
+
responses: {
|
|
4273
|
+
200: {
|
|
4274
|
+
description: "Generated response"
|
|
4275
|
+
},
|
|
4276
|
+
404: {
|
|
4277
|
+
description: "Network not found"
|
|
4278
|
+
}
|
|
4279
|
+
}
|
|
4280
|
+
}),
|
|
4281
|
+
streamGenerateHandler2
|
|
4282
|
+
);
|
|
4028
4283
|
app.get(
|
|
4029
4284
|
"/api/agents/:agentId",
|
|
4030
4285
|
h({
|
|
@@ -4310,6 +4565,54 @@ async function createHonoServer(mastra, options = {}) {
|
|
|
4310
4565
|
);
|
|
4311
4566
|
app.get(
|
|
4312
4567
|
"/api/agents/:agentId/speakers",
|
|
4568
|
+
async (c2, next) => {
|
|
4569
|
+
c2.header("Deprecation", "true");
|
|
4570
|
+
c2.header("Warning", '299 - "This endpoint is deprecated, use /api/agents/:agentId/voice/speakers instead"');
|
|
4571
|
+
c2.header("Link", '</api/agents/:agentId/voice/speakers>; rel="successor-version"');
|
|
4572
|
+
return next();
|
|
4573
|
+
},
|
|
4574
|
+
h({
|
|
4575
|
+
description: "[DEPRECATED] Use /api/agents/:agentId/voice/speakers instead. Get available speakers for an agent",
|
|
4576
|
+
tags: ["agents"],
|
|
4577
|
+
parameters: [
|
|
4578
|
+
{
|
|
4579
|
+
name: "agentId",
|
|
4580
|
+
in: "path",
|
|
4581
|
+
required: true,
|
|
4582
|
+
schema: { type: "string" }
|
|
4583
|
+
}
|
|
4584
|
+
],
|
|
4585
|
+
responses: {
|
|
4586
|
+
200: {
|
|
4587
|
+
description: "List of available speakers",
|
|
4588
|
+
content: {
|
|
4589
|
+
"application/json": {
|
|
4590
|
+
schema: {
|
|
4591
|
+
type: "array",
|
|
4592
|
+
items: {
|
|
4593
|
+
type: "object",
|
|
4594
|
+
description: "Speaker information depending on the voice provider",
|
|
4595
|
+
properties: {
|
|
4596
|
+
voiceId: { type: "string" }
|
|
4597
|
+
},
|
|
4598
|
+
additionalProperties: true
|
|
4599
|
+
}
|
|
4600
|
+
}
|
|
4601
|
+
}
|
|
4602
|
+
}
|
|
4603
|
+
},
|
|
4604
|
+
400: {
|
|
4605
|
+
description: "Agent does not have voice capabilities"
|
|
4606
|
+
},
|
|
4607
|
+
404: {
|
|
4608
|
+
description: "Agent not found"
|
|
4609
|
+
}
|
|
4610
|
+
}
|
|
4611
|
+
}),
|
|
4612
|
+
getSpeakersHandler
|
|
4613
|
+
);
|
|
4614
|
+
app.get(
|
|
4615
|
+
"/api/agents/:agentId/voice/speakers",
|
|
4313
4616
|
h({
|
|
4314
4617
|
description: "Get available speakers for an agent",
|
|
4315
4618
|
tags: ["agents"],
|
|
@@ -4353,6 +4656,82 @@ async function createHonoServer(mastra, options = {}) {
|
|
|
4353
4656
|
app.post(
|
|
4354
4657
|
"/api/agents/:agentId/speak",
|
|
4355
4658
|
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
4659
|
+
async (c2, next) => {
|
|
4660
|
+
c2.header("Deprecation", "true");
|
|
4661
|
+
c2.header("Warning", '299 - "This endpoint is deprecated, use /api/agents/:agentId/voice/speak instead"');
|
|
4662
|
+
c2.header("Link", '</api/agents/:agentId/voice/speak>; rel="successor-version"');
|
|
4663
|
+
return next();
|
|
4664
|
+
},
|
|
4665
|
+
h({
|
|
4666
|
+
description: "[DEPRECATED] Use /api/agents/:agentId/voice/speak instead. Convert text to speech using the agent's voice provider",
|
|
4667
|
+
tags: ["agents"],
|
|
4668
|
+
parameters: [
|
|
4669
|
+
{
|
|
4670
|
+
name: "agentId",
|
|
4671
|
+
in: "path",
|
|
4672
|
+
required: true,
|
|
4673
|
+
schema: { type: "string" }
|
|
4674
|
+
}
|
|
4675
|
+
],
|
|
4676
|
+
requestBody: {
|
|
4677
|
+
required: true,
|
|
4678
|
+
content: {
|
|
4679
|
+
"application/json": {
|
|
4680
|
+
schema: {
|
|
4681
|
+
type: "object",
|
|
4682
|
+
properties: {
|
|
4683
|
+
text: {
|
|
4684
|
+
type: "string",
|
|
4685
|
+
description: "Text to convert to speech"
|
|
4686
|
+
},
|
|
4687
|
+
options: {
|
|
4688
|
+
type: "object",
|
|
4689
|
+
description: "Provider-specific options for speech generation",
|
|
4690
|
+
properties: {
|
|
4691
|
+
speaker: {
|
|
4692
|
+
type: "string",
|
|
4693
|
+
description: "Speaker ID to use for speech generation"
|
|
4694
|
+
}
|
|
4695
|
+
},
|
|
4696
|
+
additionalProperties: true
|
|
4697
|
+
}
|
|
4698
|
+
},
|
|
4699
|
+
required: ["text"]
|
|
4700
|
+
}
|
|
4701
|
+
}
|
|
4702
|
+
}
|
|
4703
|
+
},
|
|
4704
|
+
responses: {
|
|
4705
|
+
200: {
|
|
4706
|
+
description: "Audio stream",
|
|
4707
|
+
content: {
|
|
4708
|
+
"audio/mpeg": {
|
|
4709
|
+
schema: {
|
|
4710
|
+
format: "binary",
|
|
4711
|
+
description: "Audio stream containing the generated speech"
|
|
4712
|
+
}
|
|
4713
|
+
},
|
|
4714
|
+
"audio/*": {
|
|
4715
|
+
schema: {
|
|
4716
|
+
format: "binary",
|
|
4717
|
+
description: "Audio stream depending on the provider"
|
|
4718
|
+
}
|
|
4719
|
+
}
|
|
4720
|
+
}
|
|
4721
|
+
},
|
|
4722
|
+
400: {
|
|
4723
|
+
description: "Agent does not have voice capabilities or invalid request"
|
|
4724
|
+
},
|
|
4725
|
+
404: {
|
|
4726
|
+
description: "Agent not found"
|
|
4727
|
+
}
|
|
4728
|
+
}
|
|
4729
|
+
}),
|
|
4730
|
+
speakHandler
|
|
4731
|
+
);
|
|
4732
|
+
app.post(
|
|
4733
|
+
"/api/agents/:agentId/voice/speak",
|
|
4734
|
+
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
4356
4735
|
h({
|
|
4357
4736
|
description: "Convert text to speech using the agent's voice provider",
|
|
4358
4737
|
tags: ["agents"],
|
|
@@ -4382,6 +4761,11 @@ async function createHonoServer(mastra, options = {}) {
|
|
|
4382
4761
|
speaker: {
|
|
4383
4762
|
type: "string",
|
|
4384
4763
|
description: "Speaker ID to use for speech generation"
|
|
4764
|
+
},
|
|
4765
|
+
options: {
|
|
4766
|
+
type: "object",
|
|
4767
|
+
description: "Provider-specific options for speech generation",
|
|
4768
|
+
additionalProperties: true
|
|
4385
4769
|
}
|
|
4386
4770
|
},
|
|
4387
4771
|
additionalProperties: true
|
|
@@ -4427,8 +4811,14 @@ async function createHonoServer(mastra, options = {}) {
|
|
|
4427
4811
|
maxSize: 10 * 1024 * 1024
|
|
4428
4812
|
// 10 MB for audio files
|
|
4429
4813
|
}),
|
|
4814
|
+
async (c2, next) => {
|
|
4815
|
+
c2.header("Deprecation", "true");
|
|
4816
|
+
c2.header("Warning", '299 - "This endpoint is deprecated, use /api/agents/:agentId/voice/listen instead"');
|
|
4817
|
+
c2.header("Link", '</api/agents/:agentId/voice/listen>; rel="successor-version"');
|
|
4818
|
+
return next();
|
|
4819
|
+
},
|
|
4430
4820
|
h({
|
|
4431
|
-
description: "Convert speech to text using the agent's voice provider. Additional provider-specific options can be passed as query parameters.",
|
|
4821
|
+
description: "[DEPRECATED] Use /api/agents/:agentId/voice/listen instead. Convert speech to text using the agent's voice provider. Additional provider-specific options can be passed as query parameters.",
|
|
4432
4822
|
tags: ["agents"],
|
|
4433
4823
|
parameters: [
|
|
4434
4824
|
{
|
|
@@ -4476,6 +4866,74 @@ async function createHonoServer(mastra, options = {}) {
|
|
|
4476
4866
|
}),
|
|
4477
4867
|
listenHandler
|
|
4478
4868
|
);
|
|
4869
|
+
app.post(
|
|
4870
|
+
"/api/agents/:agentId/voice/listen",
|
|
4871
|
+
bodyLimit.bodyLimit({
|
|
4872
|
+
...bodyLimitOptions,
|
|
4873
|
+
maxSize: 10 * 1024 * 1024
|
|
4874
|
+
// 10 MB for audio files
|
|
4875
|
+
}),
|
|
4876
|
+
h({
|
|
4877
|
+
description: "Convert speech to text using the agent's voice provider. Additional provider-specific options can be passed as query parameters.",
|
|
4878
|
+
tags: ["agents"],
|
|
4879
|
+
parameters: [
|
|
4880
|
+
{
|
|
4881
|
+
name: "agentId",
|
|
4882
|
+
in: "path",
|
|
4883
|
+
required: true,
|
|
4884
|
+
schema: { type: "string" }
|
|
4885
|
+
}
|
|
4886
|
+
],
|
|
4887
|
+
requestBody: {
|
|
4888
|
+
required: true,
|
|
4889
|
+
content: {
|
|
4890
|
+
"multipart/form-data": {
|
|
4891
|
+
schema: {
|
|
4892
|
+
type: "object",
|
|
4893
|
+
required: ["audio"],
|
|
4894
|
+
properties: {
|
|
4895
|
+
audio: {
|
|
4896
|
+
type: "string",
|
|
4897
|
+
format: "binary",
|
|
4898
|
+
description: "Audio data stream to transcribe (supports various formats depending on provider like mp3, wav, webm, flac)"
|
|
4899
|
+
},
|
|
4900
|
+
options: {
|
|
4901
|
+
type: "object",
|
|
4902
|
+
description: "Provider-specific options for speech-to-text",
|
|
4903
|
+
additionalProperties: true
|
|
4904
|
+
}
|
|
4905
|
+
}
|
|
4906
|
+
}
|
|
4907
|
+
}
|
|
4908
|
+
}
|
|
4909
|
+
},
|
|
4910
|
+
responses: {
|
|
4911
|
+
200: {
|
|
4912
|
+
description: "Transcription result",
|
|
4913
|
+
content: {
|
|
4914
|
+
"application/json": {
|
|
4915
|
+
schema: {
|
|
4916
|
+
type: "object",
|
|
4917
|
+
properties: {
|
|
4918
|
+
text: {
|
|
4919
|
+
type: "string",
|
|
4920
|
+
description: "Transcribed text"
|
|
4921
|
+
}
|
|
4922
|
+
}
|
|
4923
|
+
}
|
|
4924
|
+
}
|
|
4925
|
+
}
|
|
4926
|
+
},
|
|
4927
|
+
400: {
|
|
4928
|
+
description: "Agent does not have voice capabilities or invalid request"
|
|
4929
|
+
},
|
|
4930
|
+
404: {
|
|
4931
|
+
description: "Agent not found"
|
|
4932
|
+
}
|
|
4933
|
+
}
|
|
4934
|
+
}),
|
|
4935
|
+
listenHandler
|
|
4936
|
+
);
|
|
4479
4937
|
app.post(
|
|
4480
4938
|
"/api/agents/:agentId/tools/:toolId/execute",
|
|
4481
4939
|
bodyLimit.bodyLimit(bodyLimitOptions),
|
package/dist/server/index.js
CHANGED
|
@@ -3241,6 +3241,113 @@ async function getMessagesHandler(c2) {
|
|
|
3241
3241
|
return handleError(error, "Error getting messages");
|
|
3242
3242
|
}
|
|
3243
3243
|
}
|
|
3244
|
+
async function getNetworksHandler(c2) {
|
|
3245
|
+
try {
|
|
3246
|
+
const mastra = c2.get("mastra");
|
|
3247
|
+
const networks = mastra.getNetworks();
|
|
3248
|
+
const serializedNetworks = networks.map((network) => {
|
|
3249
|
+
const routingAgent = network.getRoutingAgent();
|
|
3250
|
+
const agents = network.getAgents();
|
|
3251
|
+
return {
|
|
3252
|
+
id: network.formatAgentId(routingAgent.name),
|
|
3253
|
+
name: routingAgent.name,
|
|
3254
|
+
instructions: routingAgent.instructions,
|
|
3255
|
+
agents: agents.map((agent) => ({
|
|
3256
|
+
name: agent.name,
|
|
3257
|
+
provider: agent.llm?.getProvider(),
|
|
3258
|
+
modelId: agent.llm?.getModelId()
|
|
3259
|
+
})),
|
|
3260
|
+
routingModel: {
|
|
3261
|
+
provider: routingAgent.llm?.getProvider(),
|
|
3262
|
+
modelId: routingAgent.llm?.getModelId()
|
|
3263
|
+
}
|
|
3264
|
+
};
|
|
3265
|
+
});
|
|
3266
|
+
return c2.json(serializedNetworks);
|
|
3267
|
+
} catch (error) {
|
|
3268
|
+
return handleError(error, "Error getting networks");
|
|
3269
|
+
}
|
|
3270
|
+
}
|
|
3271
|
+
async function getNetworkByIdHandler(c2) {
|
|
3272
|
+
try {
|
|
3273
|
+
const mastra = c2.get("mastra");
|
|
3274
|
+
const networkId = c2.req.param("networkId");
|
|
3275
|
+
const networks = mastra.getNetworks();
|
|
3276
|
+
const network = networks.find((network2) => {
|
|
3277
|
+
const routingAgent2 = network2.getRoutingAgent();
|
|
3278
|
+
return network2.formatAgentId(routingAgent2.name) === networkId;
|
|
3279
|
+
});
|
|
3280
|
+
if (!network) {
|
|
3281
|
+
return c2.json({ error: "Network not found" }, 404);
|
|
3282
|
+
}
|
|
3283
|
+
const routingAgent = network.getRoutingAgent();
|
|
3284
|
+
const agents = network.getAgents();
|
|
3285
|
+
const serializedNetwork = {
|
|
3286
|
+
id: network.formatAgentId(routingAgent.name),
|
|
3287
|
+
name: routingAgent.name,
|
|
3288
|
+
instructions: routingAgent.instructions,
|
|
3289
|
+
agents: agents.map((agent) => ({
|
|
3290
|
+
name: agent.name,
|
|
3291
|
+
provider: agent.llm?.getProvider(),
|
|
3292
|
+
modelId: agent.llm?.getModelId()
|
|
3293
|
+
})),
|
|
3294
|
+
routingModel: {
|
|
3295
|
+
provider: routingAgent.llm?.getProvider(),
|
|
3296
|
+
modelId: routingAgent.llm?.getModelId()
|
|
3297
|
+
}
|
|
3298
|
+
};
|
|
3299
|
+
return c2.json(serializedNetwork);
|
|
3300
|
+
} catch (error) {
|
|
3301
|
+
return handleError(error, "Error getting network by ID");
|
|
3302
|
+
}
|
|
3303
|
+
}
|
|
3304
|
+
async function generateHandler2(c2) {
|
|
3305
|
+
try {
|
|
3306
|
+
const mastra = c2.get("mastra");
|
|
3307
|
+
const networkId = c2.req.param("networkId");
|
|
3308
|
+
const network = mastra.getNetwork(networkId);
|
|
3309
|
+
if (!network) {
|
|
3310
|
+
throw new HTTPException(404, { message: "Network not found" });
|
|
3311
|
+
}
|
|
3312
|
+
const { messages, threadId, resourceid, resourceId, output, runId, ...rest } = await c2.req.json();
|
|
3313
|
+
validateBody({ messages });
|
|
3314
|
+
const finalResourceId = resourceId ?? resourceid;
|
|
3315
|
+
const result = await network.generate(messages, { threadId, resourceId: finalResourceId, output, runId, ...rest });
|
|
3316
|
+
return c2.json(result);
|
|
3317
|
+
} catch (error) {
|
|
3318
|
+
return handleError(error, "Error generating from network");
|
|
3319
|
+
}
|
|
3320
|
+
}
|
|
3321
|
+
async function streamGenerateHandler2(c2) {
|
|
3322
|
+
try {
|
|
3323
|
+
const mastra = c2.get("mastra");
|
|
3324
|
+
const networkId = c2.req.param("networkId");
|
|
3325
|
+
const network = mastra.getNetwork(networkId);
|
|
3326
|
+
if (!network) {
|
|
3327
|
+
throw new HTTPException(404, { message: "Network not found" });
|
|
3328
|
+
}
|
|
3329
|
+
const { messages, threadId, resourceid, resourceId, output, runId, ...rest } = await c2.req.json();
|
|
3330
|
+
validateBody({ messages });
|
|
3331
|
+
const finalResourceId = resourceId ?? resourceid;
|
|
3332
|
+
const streamResult = await network.stream(messages, {
|
|
3333
|
+
threadId,
|
|
3334
|
+
resourceId: finalResourceId,
|
|
3335
|
+
output,
|
|
3336
|
+
runId,
|
|
3337
|
+
...rest
|
|
3338
|
+
});
|
|
3339
|
+
const streamResponse = output ? streamResult.toTextStreamResponse() : streamResult.toDataStreamResponse({
|
|
3340
|
+
sendUsage: true,
|
|
3341
|
+
sendReasoning: true,
|
|
3342
|
+
getErrorMessage: (error) => {
|
|
3343
|
+
return `An error occurred while processing your request. ${error instanceof Error ? error.message : JSON.stringify(error)}`;
|
|
3344
|
+
}
|
|
3345
|
+
});
|
|
3346
|
+
return streamResponse;
|
|
3347
|
+
} catch (error) {
|
|
3348
|
+
return handleError(error, "Error streaming from network");
|
|
3349
|
+
}
|
|
3350
|
+
}
|
|
3244
3351
|
async function generateSystemPromptHandler(c2) {
|
|
3245
3352
|
try {
|
|
3246
3353
|
const agentId = c2.req.param("agentId");
|
|
@@ -3609,7 +3716,7 @@ async function speakHandler(c2) {
|
|
|
3609
3716
|
}
|
|
3610
3717
|
const { input, options } = await c2.req.json();
|
|
3611
3718
|
await validateBody({ input });
|
|
3612
|
-
const audioStream = await agent.speak(input, options);
|
|
3719
|
+
const audioStream = await agent.voice.speak(input, options);
|
|
3613
3720
|
c2.header("Content-Type", `audio/${options.filetype ?? "mp3"}`);
|
|
3614
3721
|
c2.header("Transfer-Encoding", "chunked");
|
|
3615
3722
|
return c2.body(audioStream);
|
|
@@ -3622,18 +3729,33 @@ async function listenHandler(c2) {
|
|
|
3622
3729
|
const mastra = c2.get("mastra");
|
|
3623
3730
|
const agentId = c2.req.param("agentId");
|
|
3624
3731
|
const agent = mastra.getAgent(agentId);
|
|
3732
|
+
const logger2 = mastra.getLogger();
|
|
3625
3733
|
if (!agent) {
|
|
3626
3734
|
throw new HTTPException(404, { message: "Agent not found" });
|
|
3627
3735
|
}
|
|
3628
3736
|
if (!agent.voice) {
|
|
3629
3737
|
throw new HTTPException(400, { message: "Agent does not have voice capabilities" });
|
|
3630
3738
|
}
|
|
3631
|
-
const
|
|
3739
|
+
const formData = await c2.req.formData();
|
|
3740
|
+
const audioFile = formData.get("audio");
|
|
3741
|
+
const options = formData.get("options");
|
|
3742
|
+
if (!audioFile || !(audioFile instanceof File)) {
|
|
3743
|
+
throw new HTTPException(400, { message: "Audio file is required" });
|
|
3744
|
+
}
|
|
3745
|
+
const audioData = await audioFile.arrayBuffer();
|
|
3632
3746
|
const audioStream = new Readable();
|
|
3633
3747
|
audioStream.push(Buffer.from(audioData));
|
|
3634
3748
|
audioStream.push(null);
|
|
3635
|
-
|
|
3636
|
-
|
|
3749
|
+
let parsedOptions;
|
|
3750
|
+
try {
|
|
3751
|
+
parsedOptions = options ? JSON.parse(options) : {};
|
|
3752
|
+
} catch (error) {
|
|
3753
|
+
if (error instanceof SyntaxError) {
|
|
3754
|
+
logger2.error("Invalid JSON in options:", error);
|
|
3755
|
+
}
|
|
3756
|
+
parsedOptions = {};
|
|
3757
|
+
}
|
|
3758
|
+
const transcription = await agent.voice.listen(audioStream, parsedOptions);
|
|
3637
3759
|
return c2.json({ text: transcription });
|
|
3638
3760
|
} catch (error) {
|
|
3639
3761
|
return handleError(error, "Error transcribing speech");
|
|
@@ -4019,6 +4141,139 @@ async function createHonoServer(mastra, options = {}) {
|
|
|
4019
4141
|
}),
|
|
4020
4142
|
getAgentsHandler
|
|
4021
4143
|
);
|
|
4144
|
+
app.get(
|
|
4145
|
+
"/api/networks",
|
|
4146
|
+
h({
|
|
4147
|
+
description: "Get all available networks",
|
|
4148
|
+
tags: ["networks"],
|
|
4149
|
+
responses: {
|
|
4150
|
+
200: {
|
|
4151
|
+
description: "List of all networks"
|
|
4152
|
+
}
|
|
4153
|
+
}
|
|
4154
|
+
}),
|
|
4155
|
+
getNetworksHandler
|
|
4156
|
+
);
|
|
4157
|
+
app.get(
|
|
4158
|
+
"/api/networks/:networkId",
|
|
4159
|
+
h({
|
|
4160
|
+
description: "Get network by ID",
|
|
4161
|
+
tags: ["networks"],
|
|
4162
|
+
parameters: [
|
|
4163
|
+
{
|
|
4164
|
+
name: "networkId",
|
|
4165
|
+
in: "path",
|
|
4166
|
+
required: true,
|
|
4167
|
+
schema: { type: "string" }
|
|
4168
|
+
}
|
|
4169
|
+
],
|
|
4170
|
+
responses: {
|
|
4171
|
+
200: {
|
|
4172
|
+
description: "Network details"
|
|
4173
|
+
},
|
|
4174
|
+
404: {
|
|
4175
|
+
description: "Network not found"
|
|
4176
|
+
}
|
|
4177
|
+
}
|
|
4178
|
+
}),
|
|
4179
|
+
getNetworkByIdHandler
|
|
4180
|
+
);
|
|
4181
|
+
app.post(
|
|
4182
|
+
"/api/networks/:networkId/generate",
|
|
4183
|
+
bodyLimit(bodyLimitOptions),
|
|
4184
|
+
h({
|
|
4185
|
+
description: "Generate a response from a network",
|
|
4186
|
+
tags: ["networks"],
|
|
4187
|
+
parameters: [
|
|
4188
|
+
{
|
|
4189
|
+
name: "networkId",
|
|
4190
|
+
in: "path",
|
|
4191
|
+
required: true,
|
|
4192
|
+
schema: { type: "string" }
|
|
4193
|
+
}
|
|
4194
|
+
],
|
|
4195
|
+
requestBody: {
|
|
4196
|
+
required: true,
|
|
4197
|
+
content: {
|
|
4198
|
+
"application/json": {
|
|
4199
|
+
schema: {
|
|
4200
|
+
type: "object",
|
|
4201
|
+
properties: {
|
|
4202
|
+
input: {
|
|
4203
|
+
oneOf: [
|
|
4204
|
+
{ type: "string" },
|
|
4205
|
+
{
|
|
4206
|
+
type: "array",
|
|
4207
|
+
items: { type: "object" }
|
|
4208
|
+
}
|
|
4209
|
+
],
|
|
4210
|
+
description: "Input for the network, can be a string or an array of CoreMessage objects"
|
|
4211
|
+
}
|
|
4212
|
+
},
|
|
4213
|
+
required: ["input"]
|
|
4214
|
+
}
|
|
4215
|
+
}
|
|
4216
|
+
}
|
|
4217
|
+
},
|
|
4218
|
+
responses: {
|
|
4219
|
+
200: {
|
|
4220
|
+
description: "Generated response"
|
|
4221
|
+
},
|
|
4222
|
+
404: {
|
|
4223
|
+
description: "Network not found"
|
|
4224
|
+
}
|
|
4225
|
+
}
|
|
4226
|
+
}),
|
|
4227
|
+
generateHandler2
|
|
4228
|
+
);
|
|
4229
|
+
app.post(
|
|
4230
|
+
"/api/networks/:networkId/stream",
|
|
4231
|
+
bodyLimit(bodyLimitOptions),
|
|
4232
|
+
h({
|
|
4233
|
+
description: "Generate a response from a network",
|
|
4234
|
+
tags: ["networks"],
|
|
4235
|
+
parameters: [
|
|
4236
|
+
{
|
|
4237
|
+
name: "networkId",
|
|
4238
|
+
in: "path",
|
|
4239
|
+
required: true,
|
|
4240
|
+
schema: { type: "string" }
|
|
4241
|
+
}
|
|
4242
|
+
],
|
|
4243
|
+
requestBody: {
|
|
4244
|
+
required: true,
|
|
4245
|
+
content: {
|
|
4246
|
+
"application/json": {
|
|
4247
|
+
schema: {
|
|
4248
|
+
type: "object",
|
|
4249
|
+
properties: {
|
|
4250
|
+
input: {
|
|
4251
|
+
oneOf: [
|
|
4252
|
+
{ type: "string" },
|
|
4253
|
+
{
|
|
4254
|
+
type: "array",
|
|
4255
|
+
items: { type: "object" }
|
|
4256
|
+
}
|
|
4257
|
+
],
|
|
4258
|
+
description: "Input for the network, can be a string or an array of CoreMessage objects"
|
|
4259
|
+
}
|
|
4260
|
+
},
|
|
4261
|
+
required: ["input"]
|
|
4262
|
+
}
|
|
4263
|
+
}
|
|
4264
|
+
}
|
|
4265
|
+
},
|
|
4266
|
+
responses: {
|
|
4267
|
+
200: {
|
|
4268
|
+
description: "Generated response"
|
|
4269
|
+
},
|
|
4270
|
+
404: {
|
|
4271
|
+
description: "Network not found"
|
|
4272
|
+
}
|
|
4273
|
+
}
|
|
4274
|
+
}),
|
|
4275
|
+
streamGenerateHandler2
|
|
4276
|
+
);
|
|
4022
4277
|
app.get(
|
|
4023
4278
|
"/api/agents/:agentId",
|
|
4024
4279
|
h({
|
|
@@ -4304,6 +4559,54 @@ async function createHonoServer(mastra, options = {}) {
|
|
|
4304
4559
|
);
|
|
4305
4560
|
app.get(
|
|
4306
4561
|
"/api/agents/:agentId/speakers",
|
|
4562
|
+
async (c2, next) => {
|
|
4563
|
+
c2.header("Deprecation", "true");
|
|
4564
|
+
c2.header("Warning", '299 - "This endpoint is deprecated, use /api/agents/:agentId/voice/speakers instead"');
|
|
4565
|
+
c2.header("Link", '</api/agents/:agentId/voice/speakers>; rel="successor-version"');
|
|
4566
|
+
return next();
|
|
4567
|
+
},
|
|
4568
|
+
h({
|
|
4569
|
+
description: "[DEPRECATED] Use /api/agents/:agentId/voice/speakers instead. Get available speakers for an agent",
|
|
4570
|
+
tags: ["agents"],
|
|
4571
|
+
parameters: [
|
|
4572
|
+
{
|
|
4573
|
+
name: "agentId",
|
|
4574
|
+
in: "path",
|
|
4575
|
+
required: true,
|
|
4576
|
+
schema: { type: "string" }
|
|
4577
|
+
}
|
|
4578
|
+
],
|
|
4579
|
+
responses: {
|
|
4580
|
+
200: {
|
|
4581
|
+
description: "List of available speakers",
|
|
4582
|
+
content: {
|
|
4583
|
+
"application/json": {
|
|
4584
|
+
schema: {
|
|
4585
|
+
type: "array",
|
|
4586
|
+
items: {
|
|
4587
|
+
type: "object",
|
|
4588
|
+
description: "Speaker information depending on the voice provider",
|
|
4589
|
+
properties: {
|
|
4590
|
+
voiceId: { type: "string" }
|
|
4591
|
+
},
|
|
4592
|
+
additionalProperties: true
|
|
4593
|
+
}
|
|
4594
|
+
}
|
|
4595
|
+
}
|
|
4596
|
+
}
|
|
4597
|
+
},
|
|
4598
|
+
400: {
|
|
4599
|
+
description: "Agent does not have voice capabilities"
|
|
4600
|
+
},
|
|
4601
|
+
404: {
|
|
4602
|
+
description: "Agent not found"
|
|
4603
|
+
}
|
|
4604
|
+
}
|
|
4605
|
+
}),
|
|
4606
|
+
getSpeakersHandler
|
|
4607
|
+
);
|
|
4608
|
+
app.get(
|
|
4609
|
+
"/api/agents/:agentId/voice/speakers",
|
|
4307
4610
|
h({
|
|
4308
4611
|
description: "Get available speakers for an agent",
|
|
4309
4612
|
tags: ["agents"],
|
|
@@ -4347,6 +4650,82 @@ async function createHonoServer(mastra, options = {}) {
|
|
|
4347
4650
|
app.post(
|
|
4348
4651
|
"/api/agents/:agentId/speak",
|
|
4349
4652
|
bodyLimit(bodyLimitOptions),
|
|
4653
|
+
async (c2, next) => {
|
|
4654
|
+
c2.header("Deprecation", "true");
|
|
4655
|
+
c2.header("Warning", '299 - "This endpoint is deprecated, use /api/agents/:agentId/voice/speak instead"');
|
|
4656
|
+
c2.header("Link", '</api/agents/:agentId/voice/speak>; rel="successor-version"');
|
|
4657
|
+
return next();
|
|
4658
|
+
},
|
|
4659
|
+
h({
|
|
4660
|
+
description: "[DEPRECATED] Use /api/agents/:agentId/voice/speak instead. Convert text to speech using the agent's voice provider",
|
|
4661
|
+
tags: ["agents"],
|
|
4662
|
+
parameters: [
|
|
4663
|
+
{
|
|
4664
|
+
name: "agentId",
|
|
4665
|
+
in: "path",
|
|
4666
|
+
required: true,
|
|
4667
|
+
schema: { type: "string" }
|
|
4668
|
+
}
|
|
4669
|
+
],
|
|
4670
|
+
requestBody: {
|
|
4671
|
+
required: true,
|
|
4672
|
+
content: {
|
|
4673
|
+
"application/json": {
|
|
4674
|
+
schema: {
|
|
4675
|
+
type: "object",
|
|
4676
|
+
properties: {
|
|
4677
|
+
text: {
|
|
4678
|
+
type: "string",
|
|
4679
|
+
description: "Text to convert to speech"
|
|
4680
|
+
},
|
|
4681
|
+
options: {
|
|
4682
|
+
type: "object",
|
|
4683
|
+
description: "Provider-specific options for speech generation",
|
|
4684
|
+
properties: {
|
|
4685
|
+
speaker: {
|
|
4686
|
+
type: "string",
|
|
4687
|
+
description: "Speaker ID to use for speech generation"
|
|
4688
|
+
}
|
|
4689
|
+
},
|
|
4690
|
+
additionalProperties: true
|
|
4691
|
+
}
|
|
4692
|
+
},
|
|
4693
|
+
required: ["text"]
|
|
4694
|
+
}
|
|
4695
|
+
}
|
|
4696
|
+
}
|
|
4697
|
+
},
|
|
4698
|
+
responses: {
|
|
4699
|
+
200: {
|
|
4700
|
+
description: "Audio stream",
|
|
4701
|
+
content: {
|
|
4702
|
+
"audio/mpeg": {
|
|
4703
|
+
schema: {
|
|
4704
|
+
format: "binary",
|
|
4705
|
+
description: "Audio stream containing the generated speech"
|
|
4706
|
+
}
|
|
4707
|
+
},
|
|
4708
|
+
"audio/*": {
|
|
4709
|
+
schema: {
|
|
4710
|
+
format: "binary",
|
|
4711
|
+
description: "Audio stream depending on the provider"
|
|
4712
|
+
}
|
|
4713
|
+
}
|
|
4714
|
+
}
|
|
4715
|
+
},
|
|
4716
|
+
400: {
|
|
4717
|
+
description: "Agent does not have voice capabilities or invalid request"
|
|
4718
|
+
},
|
|
4719
|
+
404: {
|
|
4720
|
+
description: "Agent not found"
|
|
4721
|
+
}
|
|
4722
|
+
}
|
|
4723
|
+
}),
|
|
4724
|
+
speakHandler
|
|
4725
|
+
);
|
|
4726
|
+
app.post(
|
|
4727
|
+
"/api/agents/:agentId/voice/speak",
|
|
4728
|
+
bodyLimit(bodyLimitOptions),
|
|
4350
4729
|
h({
|
|
4351
4730
|
description: "Convert text to speech using the agent's voice provider",
|
|
4352
4731
|
tags: ["agents"],
|
|
@@ -4376,6 +4755,11 @@ async function createHonoServer(mastra, options = {}) {
|
|
|
4376
4755
|
speaker: {
|
|
4377
4756
|
type: "string",
|
|
4378
4757
|
description: "Speaker ID to use for speech generation"
|
|
4758
|
+
},
|
|
4759
|
+
options: {
|
|
4760
|
+
type: "object",
|
|
4761
|
+
description: "Provider-specific options for speech generation",
|
|
4762
|
+
additionalProperties: true
|
|
4379
4763
|
}
|
|
4380
4764
|
},
|
|
4381
4765
|
additionalProperties: true
|
|
@@ -4421,8 +4805,14 @@ async function createHonoServer(mastra, options = {}) {
|
|
|
4421
4805
|
maxSize: 10 * 1024 * 1024
|
|
4422
4806
|
// 10 MB for audio files
|
|
4423
4807
|
}),
|
|
4808
|
+
async (c2, next) => {
|
|
4809
|
+
c2.header("Deprecation", "true");
|
|
4810
|
+
c2.header("Warning", '299 - "This endpoint is deprecated, use /api/agents/:agentId/voice/listen instead"');
|
|
4811
|
+
c2.header("Link", '</api/agents/:agentId/voice/listen>; rel="successor-version"');
|
|
4812
|
+
return next();
|
|
4813
|
+
},
|
|
4424
4814
|
h({
|
|
4425
|
-
description: "Convert speech to text using the agent's voice provider. Additional provider-specific options can be passed as query parameters.",
|
|
4815
|
+
description: "[DEPRECATED] Use /api/agents/:agentId/voice/listen instead. Convert speech to text using the agent's voice provider. Additional provider-specific options can be passed as query parameters.",
|
|
4426
4816
|
tags: ["agents"],
|
|
4427
4817
|
parameters: [
|
|
4428
4818
|
{
|
|
@@ -4470,6 +4860,74 @@ async function createHonoServer(mastra, options = {}) {
|
|
|
4470
4860
|
}),
|
|
4471
4861
|
listenHandler
|
|
4472
4862
|
);
|
|
4863
|
+
app.post(
|
|
4864
|
+
"/api/agents/:agentId/voice/listen",
|
|
4865
|
+
bodyLimit({
|
|
4866
|
+
...bodyLimitOptions,
|
|
4867
|
+
maxSize: 10 * 1024 * 1024
|
|
4868
|
+
// 10 MB for audio files
|
|
4869
|
+
}),
|
|
4870
|
+
h({
|
|
4871
|
+
description: "Convert speech to text using the agent's voice provider. Additional provider-specific options can be passed as query parameters.",
|
|
4872
|
+
tags: ["agents"],
|
|
4873
|
+
parameters: [
|
|
4874
|
+
{
|
|
4875
|
+
name: "agentId",
|
|
4876
|
+
in: "path",
|
|
4877
|
+
required: true,
|
|
4878
|
+
schema: { type: "string" }
|
|
4879
|
+
}
|
|
4880
|
+
],
|
|
4881
|
+
requestBody: {
|
|
4882
|
+
required: true,
|
|
4883
|
+
content: {
|
|
4884
|
+
"multipart/form-data": {
|
|
4885
|
+
schema: {
|
|
4886
|
+
type: "object",
|
|
4887
|
+
required: ["audio"],
|
|
4888
|
+
properties: {
|
|
4889
|
+
audio: {
|
|
4890
|
+
type: "string",
|
|
4891
|
+
format: "binary",
|
|
4892
|
+
description: "Audio data stream to transcribe (supports various formats depending on provider like mp3, wav, webm, flac)"
|
|
4893
|
+
},
|
|
4894
|
+
options: {
|
|
4895
|
+
type: "object",
|
|
4896
|
+
description: "Provider-specific options for speech-to-text",
|
|
4897
|
+
additionalProperties: true
|
|
4898
|
+
}
|
|
4899
|
+
}
|
|
4900
|
+
}
|
|
4901
|
+
}
|
|
4902
|
+
}
|
|
4903
|
+
},
|
|
4904
|
+
responses: {
|
|
4905
|
+
200: {
|
|
4906
|
+
description: "Transcription result",
|
|
4907
|
+
content: {
|
|
4908
|
+
"application/json": {
|
|
4909
|
+
schema: {
|
|
4910
|
+
type: "object",
|
|
4911
|
+
properties: {
|
|
4912
|
+
text: {
|
|
4913
|
+
type: "string",
|
|
4914
|
+
description: "Transcribed text"
|
|
4915
|
+
}
|
|
4916
|
+
}
|
|
4917
|
+
}
|
|
4918
|
+
}
|
|
4919
|
+
}
|
|
4920
|
+
},
|
|
4921
|
+
400: {
|
|
4922
|
+
description: "Agent does not have voice capabilities or invalid request"
|
|
4923
|
+
},
|
|
4924
|
+
404: {
|
|
4925
|
+
description: "Agent not found"
|
|
4926
|
+
}
|
|
4927
|
+
}
|
|
4928
|
+
}),
|
|
4929
|
+
listenHandler
|
|
4930
|
+
);
|
|
4473
4931
|
app.post(
|
|
4474
4932
|
"/api/agents/:agentId/tools/:toolId/execute",
|
|
4475
4933
|
bodyLimit(bodyLimitOptions),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/deployer",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -95,7 +95,7 @@
|
|
|
95
95
|
"rollup-plugin-node-externals": "^8.0.0",
|
|
96
96
|
"typescript-paths": "^1.5.1",
|
|
97
97
|
"zod": "^3.24.2",
|
|
98
|
-
"@mastra/core": "^0.6.
|
|
98
|
+
"@mastra/core": "^0.6.3"
|
|
99
99
|
},
|
|
100
100
|
"devDependencies": {
|
|
101
101
|
"@hono/node-server": "^1.13.8",
|