@mastra/server 0.0.0-mastra-3171-llamaindex-pin-20250423175211 → 0.0.0-mastra-2452-core-tracing-sentry-20250507205331
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/README.md +50 -135
- package/dist/_tsup-dts-rollup.d.cts +108 -11
- package/dist/_tsup-dts-rollup.d.ts +108 -11
- package/dist/{chunk-LFOBHRFO.js → chunk-3XTEV33Q.js} +16 -4
- package/dist/{chunk-CWUJ6DED.cjs → chunk-55HTWX4C.cjs} +1 -6
- package/dist/{chunk-FPIWDH5Y.cjs → chunk-5YGDYMRB.cjs} +48 -27
- package/dist/{chunk-HCOPJZ4A.cjs → chunk-6Q7UXAYJ.cjs} +67 -33
- package/dist/{chunk-7IWQE76Z.cjs → chunk-AMVOS7YB.cjs} +4 -2
- package/dist/{chunk-WTHDCRMY.js → chunk-BPL2CBLV.js} +4 -2
- package/dist/{chunk-TZK63M5N.cjs → chunk-CHFORQ7J.cjs} +16 -4
- package/dist/{chunk-R4J7XQYU.js → chunk-GVBJ5I2S.js} +65 -31
- package/dist/chunk-M2RXDCPV.cjs +324 -0
- package/dist/chunk-OWNA6I2H.js +312 -0
- package/dist/{chunk-YE2P6K2L.js → chunk-Q6SHQECN.js} +1 -6
- package/dist/{chunk-RE6YL32K.js → chunk-QJ3AHN64.js} +48 -27
- package/dist/server/handlers/agents.cjs +7 -7
- package/dist/server/handlers/agents.js +1 -1
- package/dist/server/handlers/network.cjs +5 -5
- package/dist/server/handlers/network.js +1 -1
- package/dist/server/handlers/telemetry.cjs +3 -3
- package/dist/server/handlers/telemetry.js +1 -1
- package/dist/server/handlers/vNextWorkflows.cjs +46 -0
- package/dist/server/handlers/vNextWorkflows.d.cts +10 -0
- package/dist/server/handlers/vNextWorkflows.d.ts +10 -0
- package/dist/server/handlers/vNextWorkflows.js +1 -0
- package/dist/server/handlers/voice.cjs +4 -4
- package/dist/server/handlers/voice.js +1 -1
- package/dist/server/handlers/workflows.cjs +11 -11
- package/dist/server/handlers/workflows.js +1 -1
- package/dist/server/handlers.cjs +15 -10
- package/dist/server/handlers.d.cts +1 -0
- package/dist/server/handlers.d.ts +1 -0
- package/dist/server/handlers.js +6 -5
- package/package.json +6 -6
|
@@ -9,9 +9,13 @@ import type { Mastra } from '@mastra/core/mastra';
|
|
|
9
9
|
import type { MastraMemory } from '@mastra/core/memory';
|
|
10
10
|
import { Message } from 'ai';
|
|
11
11
|
import { MessageType } from '@mastra/core/memory';
|
|
12
|
+
import { NewStep } from '@mastra/core/workflows/vNext';
|
|
13
|
+
import type { NewWorkflow } from '@mastra/core/workflows/vNext';
|
|
12
14
|
import type { QueryResult } from '@mastra/core/vector';
|
|
13
15
|
import { ReadableStream as ReadableStream_2 } from 'node:stream/web';
|
|
14
|
-
import
|
|
16
|
+
import { RuntimeContext } from '@mastra/core/runtime-context';
|
|
17
|
+
import type { RuntimeContext as RuntimeContext_2 } from '@mastra/core/di';
|
|
18
|
+
import { SerializedStepFlowEntry } from '@mastra/core/workflows/vNext';
|
|
15
19
|
import { Step } from '@mastra/core/workflows';
|
|
16
20
|
import { StepExecutionContext } from '@mastra/core/workflows';
|
|
17
21
|
import { StepGraph } from '@mastra/core/workflows';
|
|
@@ -20,8 +24,11 @@ import type { ToolAction } from '@mastra/core/tools';
|
|
|
20
24
|
import type { VercelTool } from '@mastra/core/tools';
|
|
21
25
|
import type { Workflow } from '@mastra/core/workflows';
|
|
22
26
|
import { WorkflowContext as WorkflowContext_2 } from '@mastra/core/workflows';
|
|
27
|
+
import { WorkflowResult } from '@mastra/core/workflows/vNext';
|
|
23
28
|
import { WorkflowRunResult } from '@mastra/core/workflows';
|
|
24
29
|
import type { WorkflowRuns } from '@mastra/core/storage';
|
|
30
|
+
import { ZodType } from 'zod';
|
|
31
|
+
import { ZodTypeDef } from 'zod';
|
|
25
32
|
|
|
26
33
|
export declare namespace agents {
|
|
27
34
|
export {
|
|
@@ -67,6 +74,10 @@ export declare function createThreadHandler({ mastra, agentId, body, }: Pick<Mem
|
|
|
67
74
|
};
|
|
68
75
|
}): Promise<StorageThreadType>;
|
|
69
76
|
|
|
77
|
+
export declare function createVNextWorkflowRunHandler({ mastra, workflowId, runId: prevRunId, }: Pick<VNextWorkflowContext, 'mastra' | 'workflowId' | 'runId'>): Promise<{
|
|
78
|
+
runId: string;
|
|
79
|
+
}>;
|
|
80
|
+
|
|
70
81
|
export declare function deleteIndex({ mastra, vectorName, indexName, }: Pick<VectorContext, 'mastra' | 'vectorName'> & {
|
|
71
82
|
indexName?: string;
|
|
72
83
|
}): Promise<{
|
|
@@ -103,6 +114,7 @@ export declare function generateHandler({ mastra, runtimeContext, agentId, body,
|
|
|
103
114
|
agentId: string;
|
|
104
115
|
body: GetBody<'generate'> & {
|
|
105
116
|
resourceid?: string;
|
|
117
|
+
runtimeContext?: Record<string, unknown>;
|
|
106
118
|
};
|
|
107
119
|
}): Promise<GenerateTextResult<any, any>>;
|
|
108
120
|
|
|
@@ -121,11 +133,10 @@ export declare function generateSpeechHandler({ mastra, agentId, body, }: VoiceC
|
|
|
121
133
|
text?: string;
|
|
122
134
|
speakerId?: string;
|
|
123
135
|
};
|
|
124
|
-
}): Promise<
|
|
125
|
-
audioData: Buffer<ArrayBuffer>;
|
|
126
|
-
}>;
|
|
136
|
+
}): Promise<NodeJS.ReadableStream>;
|
|
127
137
|
|
|
128
|
-
export declare function getAgentByIdHandler({ mastra, agentId }: Context & {
|
|
138
|
+
export declare function getAgentByIdHandler({ mastra, runtimeContext, agentId, }: Context & {
|
|
139
|
+
runtimeContext: RuntimeContext;
|
|
129
140
|
agentId: string;
|
|
130
141
|
}): Promise<{
|
|
131
142
|
name: any;
|
|
@@ -135,7 +146,9 @@ export declare function getAgentByIdHandler({ mastra, agentId }: Context & {
|
|
|
135
146
|
modelId: string;
|
|
136
147
|
}>;
|
|
137
148
|
|
|
138
|
-
export declare function getAgentsHandler({ mastra }: Context
|
|
149
|
+
export declare function getAgentsHandler({ mastra, runtimeContext }: Context & {
|
|
150
|
+
runtimeContext: RuntimeContext;
|
|
151
|
+
}): Promise<any>;
|
|
139
152
|
|
|
140
153
|
declare type GetBody<T extends keyof Agent & {
|
|
141
154
|
[K in keyof Agent]: Agent[K] extends (...args: any) => any ? K : never;
|
|
@@ -143,7 +156,8 @@ declare type GetBody<T extends keyof Agent & {
|
|
|
143
156
|
messages: Parameters<Agent[T]>[0];
|
|
144
157
|
} & Parameters<Agent[T]>[1];
|
|
145
158
|
|
|
146
|
-
export declare function getEvalsByAgentIdHandler({ mastra, agentId }: Context & {
|
|
159
|
+
export declare function getEvalsByAgentIdHandler({ mastra, runtimeContext, agentId, }: Context & {
|
|
160
|
+
runtimeContext: RuntimeContext;
|
|
147
161
|
agentId: string;
|
|
148
162
|
}): Promise<{
|
|
149
163
|
id: string;
|
|
@@ -152,7 +166,8 @@ export declare function getEvalsByAgentIdHandler({ mastra, agentId }: Context &
|
|
|
152
166
|
evals: EvalRow[];
|
|
153
167
|
}>;
|
|
154
168
|
|
|
155
|
-
export declare function getLiveEvalsByAgentIdHandler({ mastra, agentId }: Context & {
|
|
169
|
+
export declare function getLiveEvalsByAgentIdHandler({ mastra, runtimeContext, agentId, }: Context & {
|
|
170
|
+
runtimeContext: RuntimeContext;
|
|
156
171
|
agentId: string;
|
|
157
172
|
}): Promise<{
|
|
158
173
|
id: string;
|
|
@@ -178,7 +193,7 @@ export declare function getMessagesHandler({ mastra, agentId, threadId, }: Pick<
|
|
|
178
193
|
uiMessages: Message[];
|
|
179
194
|
}>;
|
|
180
195
|
|
|
181
|
-
export declare function getNetworkByIdHandler({ mastra, networkId }: Pick<NetworkContext, 'mastra' | 'networkId'>): Promise<{
|
|
196
|
+
export declare function getNetworkByIdHandler({ mastra, networkId, runtimeContext, }: Pick<NetworkContext, 'mastra' | 'networkId' | 'runtimeContext'>): Promise<{
|
|
182
197
|
id: string;
|
|
183
198
|
name: string;
|
|
184
199
|
instructions: string;
|
|
@@ -193,7 +208,7 @@ export declare function getNetworkByIdHandler({ mastra, networkId }: Pick<Networ
|
|
|
193
208
|
};
|
|
194
209
|
}>;
|
|
195
210
|
|
|
196
|
-
export declare function getNetworksHandler({ mastra }: Pick<NetworkContext, 'mastra'>): Promise<{
|
|
211
|
+
export declare function getNetworksHandler({ mastra, runtimeContext, }: Pick<NetworkContext, 'mastra' | 'runtimeContext'>): Promise<{
|
|
197
212
|
id: string;
|
|
198
213
|
name: string;
|
|
199
214
|
instructions: string;
|
|
@@ -225,6 +240,26 @@ export declare function getToolByIdHandler({ tools, toolId }: Pick<ToolsContext,
|
|
|
225
240
|
|
|
226
241
|
export declare function getToolsHandler({ tools }: Pick<ToolsContext, 'tools'>): Promise<Record<string, any>>;
|
|
227
242
|
|
|
243
|
+
export declare function getVNextWorkflowByIdHandler({ mastra, workflowId }: VNextWorkflowContext): Promise<{
|
|
244
|
+
steps: any;
|
|
245
|
+
name: string | undefined;
|
|
246
|
+
stepGraph: SerializedStepFlowEntry[];
|
|
247
|
+
inputSchema: string | undefined;
|
|
248
|
+
outputSchema: string | undefined;
|
|
249
|
+
}>;
|
|
250
|
+
|
|
251
|
+
export declare function getVNextWorkflowRunByIdHandler({ mastra, workflowId, runId, }: Pick<VNextWorkflowContext, 'mastra' | 'workflowId' | 'runId'>): Promise<ReturnType<NewWorkflow['getWorkflowRunById']>>;
|
|
252
|
+
|
|
253
|
+
export declare function getVNextWorkflowRunsHandler({ mastra, workflowId, fromDate, toDate, limit, offset, resourceId, }: VNextWorkflowContext & {
|
|
254
|
+
fromDate?: Date;
|
|
255
|
+
toDate?: Date;
|
|
256
|
+
limit?: number;
|
|
257
|
+
offset?: number;
|
|
258
|
+
resourceId?: string;
|
|
259
|
+
}): Promise<WorkflowRuns>;
|
|
260
|
+
|
|
261
|
+
export declare function getVNextWorkflowsHandler({ mastra }: VNextWorkflowContext): Promise<any>;
|
|
262
|
+
|
|
228
263
|
export declare function getWorkflowByIdHandler({ mastra, workflowId }: WorkflowContext): Promise<{
|
|
229
264
|
stepGraph: StepGraph;
|
|
230
265
|
stepSubscriberGraph: Record<string, StepGraph>;
|
|
@@ -237,7 +272,13 @@ export declare function getWorkflowByIdHandler({ mastra, workflowId }: WorkflowC
|
|
|
237
272
|
|
|
238
273
|
export declare function getWorkflowRunHandler({ mastra, workflowId, runId, }: Pick<WorkflowContext, 'mastra' | 'workflowId' | 'runId'>): Promise<ReturnType<Workflow['getRun']>>;
|
|
239
274
|
|
|
240
|
-
export declare function getWorkflowRunsHandler({ mastra, workflowId }: WorkflowContext
|
|
275
|
+
export declare function getWorkflowRunsHandler({ mastra, workflowId, fromDate, toDate, limit, offset, resourceId, }: WorkflowContext & {
|
|
276
|
+
fromDate?: Date;
|
|
277
|
+
toDate?: Date;
|
|
278
|
+
limit?: number;
|
|
279
|
+
offset?: number;
|
|
280
|
+
resourceId?: string;
|
|
281
|
+
}): Promise<WorkflowRuns>;
|
|
241
282
|
|
|
242
283
|
export declare function getWorkflowsHandler({ mastra }: WorkflowContext): Promise<any>;
|
|
243
284
|
|
|
@@ -350,6 +391,7 @@ export declare namespace network {
|
|
|
350
391
|
|
|
351
392
|
declare interface NetworkContext extends Context {
|
|
352
393
|
networkId?: string;
|
|
394
|
+
runtimeContext: RuntimeContext;
|
|
353
395
|
}
|
|
354
396
|
|
|
355
397
|
declare interface QueryRequest {
|
|
@@ -366,6 +408,14 @@ export declare function queryVectors({ mastra, vectorName, query, }: Pick<Vector
|
|
|
366
408
|
|
|
367
409
|
declare type RedirectStatusCode = 300 | 301 | 302 | 303 | 304 | DeprecatedStatusCode | 307 | 308;
|
|
368
410
|
|
|
411
|
+
export declare function resumeAsyncVNextWorkflowHandler({ mastra, workflowId, runId, body, runtimeContext, }: VNextWorkflowContext & {
|
|
412
|
+
body: {
|
|
413
|
+
step: string | string[];
|
|
414
|
+
resumeData?: unknown;
|
|
415
|
+
};
|
|
416
|
+
runtimeContext?: RuntimeContext_2;
|
|
417
|
+
}): Promise<WorkflowResult<ZodType<any, ZodTypeDef, any>, NewStep<string, any, any, any, any>[]>>;
|
|
418
|
+
|
|
369
419
|
export declare function resumeAsyncWorkflowHandler({ mastra, workflowId, runId, body, runtimeContext, }: WorkflowContext & {
|
|
370
420
|
body: {
|
|
371
421
|
stepId: string;
|
|
@@ -374,6 +424,16 @@ export declare function resumeAsyncWorkflowHandler({ mastra, workflowId, runId,
|
|
|
374
424
|
runtimeContext: RuntimeContext;
|
|
375
425
|
}): Promise<Omit<WorkflowRunResult<any, Step<string, any, any, StepExecutionContext<any, WorkflowContext_2<any, Step<string, any, any, any>[], Record<string, any>>>>[], any>, "runId"> | undefined>;
|
|
376
426
|
|
|
427
|
+
export declare function resumeVNextWorkflowHandler({ mastra, workflowId, runId, body, runtimeContext, }: VNextWorkflowContext & {
|
|
428
|
+
body: {
|
|
429
|
+
step: string | string[];
|
|
430
|
+
resumeData?: unknown;
|
|
431
|
+
};
|
|
432
|
+
runtimeContext?: RuntimeContext_2;
|
|
433
|
+
}): Promise<{
|
|
434
|
+
message: string;
|
|
435
|
+
}>;
|
|
436
|
+
|
|
377
437
|
export declare function resumeWorkflowHandler({ mastra, workflowId, runId, body, runtimeContext, }: WorkflowContext & {
|
|
378
438
|
body: {
|
|
379
439
|
stepId: string;
|
|
@@ -392,11 +452,23 @@ export declare function saveMessagesHandler({ mastra, agentId, body, }: Pick<Mem
|
|
|
392
452
|
|
|
393
453
|
declare type ServerErrorStatusCode = 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511;
|
|
394
454
|
|
|
455
|
+
export declare function startAsyncVNextWorkflowHandler({ mastra, runtimeContext, workflowId, runId, inputData, }: Pick<VNextWorkflowContext, 'mastra' | 'workflowId' | 'runId'> & {
|
|
456
|
+
inputData?: unknown;
|
|
457
|
+
runtimeContext?: RuntimeContext_2;
|
|
458
|
+
}): Promise<WorkflowResult<ZodType<any, ZodTypeDef, any>, NewStep<string, any, any, any, any>[]>>;
|
|
459
|
+
|
|
395
460
|
export declare function startAsyncWorkflowHandler({ mastra, runtimeContext, workflowId, runId, triggerData, }: Pick<WorkflowContext, 'mastra' | 'workflowId' | 'runId'> & {
|
|
396
461
|
triggerData?: unknown;
|
|
397
462
|
runtimeContext: RuntimeContext;
|
|
398
463
|
}): Promise<WorkflowRunResult<any, Step<string, any, any, StepExecutionContext<any, WorkflowContext_2<any, Step<string, any, any, any>[], Record<string, any>>>>[], any>>;
|
|
399
464
|
|
|
465
|
+
export declare function startVNextWorkflowRunHandler({ mastra, runtimeContext, workflowId, runId, inputData, }: Pick<VNextWorkflowContext, 'mastra' | 'workflowId' | 'runId'> & {
|
|
466
|
+
inputData?: unknown;
|
|
467
|
+
runtimeContext?: RuntimeContext_2;
|
|
468
|
+
}): Promise<{
|
|
469
|
+
message: string;
|
|
470
|
+
}>;
|
|
471
|
+
|
|
400
472
|
export declare function startWorkflowRunHandler({ mastra, runtimeContext, workflowId, runId, triggerData, }: Pick<WorkflowContext, 'mastra' | 'workflowId' | 'runId'> & {
|
|
401
473
|
triggerData?: unknown;
|
|
402
474
|
runtimeContext: RuntimeContext;
|
|
@@ -428,6 +500,7 @@ export declare function streamGenerateHandler({ mastra, runtimeContext, agentId,
|
|
|
428
500
|
agentId: string;
|
|
429
501
|
body: GetBody<'stream'> & {
|
|
430
502
|
resourceid?: string;
|
|
503
|
+
runtimeContext?: string;
|
|
431
504
|
};
|
|
432
505
|
}): Promise<Response | undefined>;
|
|
433
506
|
|
|
@@ -454,6 +527,8 @@ declare interface TelemetryContext extends Context {
|
|
|
454
527
|
page?: number;
|
|
455
528
|
perPage?: number;
|
|
456
529
|
attribute?: string | string[];
|
|
530
|
+
fromDate?: Date;
|
|
531
|
+
toDate?: Date;
|
|
457
532
|
};
|
|
458
533
|
}
|
|
459
534
|
|
|
@@ -536,6 +611,26 @@ declare interface VectorContext extends Context {
|
|
|
536
611
|
vectorName?: string;
|
|
537
612
|
}
|
|
538
613
|
|
|
614
|
+
declare interface VNextWorkflowContext extends Context {
|
|
615
|
+
workflowId?: string;
|
|
616
|
+
runId?: string;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
export declare namespace vNextWorkflows {
|
|
620
|
+
export {
|
|
621
|
+
getVNextWorkflowsHandler,
|
|
622
|
+
getVNextWorkflowByIdHandler,
|
|
623
|
+
getVNextWorkflowRunByIdHandler,
|
|
624
|
+
createVNextWorkflowRunHandler,
|
|
625
|
+
startAsyncVNextWorkflowHandler,
|
|
626
|
+
startVNextWorkflowRunHandler,
|
|
627
|
+
watchVNextWorkflowHandler,
|
|
628
|
+
resumeAsyncVNextWorkflowHandler,
|
|
629
|
+
resumeVNextWorkflowHandler,
|
|
630
|
+
getVNextWorkflowRunsHandler
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
|
|
539
634
|
export declare namespace voice {
|
|
540
635
|
export {
|
|
541
636
|
getSpeakersHandler,
|
|
@@ -548,6 +643,8 @@ declare interface VoiceContext extends Context {
|
|
|
548
643
|
agentId?: string;
|
|
549
644
|
}
|
|
550
645
|
|
|
646
|
+
export declare function watchVNextWorkflowHandler({ mastra, workflowId, runId, }: Pick<VNextWorkflowContext, 'mastra' | 'workflowId' | 'runId'>): Promise<ReadableStream_2<string>>;
|
|
647
|
+
|
|
551
648
|
export declare function watchWorkflowHandler({ mastra, workflowId, runId, }: Pick<WorkflowContext, 'mastra' | 'workflowId' | 'runId'>): Promise<ReadableStream_2<string>>;
|
|
552
649
|
|
|
553
650
|
declare interface WorkflowContext extends Context {
|
|
@@ -32,7 +32,9 @@ async function getWorkflowsHandler({ mastra }) {
|
|
|
32
32
|
steps: Object.entries(workflow.steps).reduce((acc2, [key2, step]) => {
|
|
33
33
|
const _step = step;
|
|
34
34
|
acc2[key2] = {
|
|
35
|
-
|
|
35
|
+
id: _step.id,
|
|
36
|
+
description: _step.description,
|
|
37
|
+
workflowId: _step.workflowId,
|
|
36
38
|
inputSchema: _step.inputSchema ? stringify(esm_default(_step.inputSchema)) : void 0,
|
|
37
39
|
outputSchema: _step.outputSchema ? stringify(esm_default(_step.outputSchema)) : void 0
|
|
38
40
|
};
|
|
@@ -65,7 +67,9 @@ async function getWorkflowByIdHandler({ mastra, workflowId }) {
|
|
|
65
67
|
steps: Object.entries(workflow.steps).reduce((acc, [key, step]) => {
|
|
66
68
|
const _step = step;
|
|
67
69
|
acc[key] = {
|
|
68
|
-
|
|
70
|
+
id: _step.id,
|
|
71
|
+
description: _step.description,
|
|
72
|
+
workflowId: _step.workflowId,
|
|
69
73
|
inputSchema: _step.inputSchema ? stringify(esm_default(_step.inputSchema)) : void 0,
|
|
70
74
|
outputSchema: _step.outputSchema ? stringify(esm_default(_step.outputSchema)) : void 0
|
|
71
75
|
};
|
|
@@ -286,13 +290,21 @@ async function resumeWorkflowHandler({
|
|
|
286
290
|
return handleError(error, "Error resuming workflow");
|
|
287
291
|
}
|
|
288
292
|
}
|
|
289
|
-
async function getWorkflowRunsHandler({
|
|
293
|
+
async function getWorkflowRunsHandler({
|
|
294
|
+
mastra,
|
|
295
|
+
workflowId,
|
|
296
|
+
fromDate,
|
|
297
|
+
toDate,
|
|
298
|
+
limit,
|
|
299
|
+
offset,
|
|
300
|
+
resourceId
|
|
301
|
+
}) {
|
|
290
302
|
try {
|
|
291
303
|
if (!workflowId) {
|
|
292
304
|
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
293
305
|
}
|
|
294
306
|
const workflow = mastra.getWorkflow(workflowId);
|
|
295
|
-
const workflowRuns = await workflow.getWorkflowRuns() || {
|
|
307
|
+
const workflowRuns = await workflow.getWorkflowRuns({ fromDate, toDate, limit, offset, resourceId }) || {
|
|
296
308
|
runs: [],
|
|
297
309
|
total: 0
|
|
298
310
|
};
|
|
@@ -53,12 +53,7 @@ async function generateSpeechHandler({
|
|
|
53
53
|
if (!audioStream) {
|
|
54
54
|
throw new chunkFV45V6WC_cjs.HTTPException(500, { message: "Failed to generate speech" });
|
|
55
55
|
}
|
|
56
|
-
|
|
57
|
-
for await (const chunk of audioStream) {
|
|
58
|
-
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
59
|
-
}
|
|
60
|
-
const audioData = Buffer.concat(chunks);
|
|
61
|
-
return { audioData };
|
|
56
|
+
return audioStream;
|
|
62
57
|
} catch (error) {
|
|
63
58
|
return chunkZLBRQFDD_cjs.handleError(error, "Error generating speech");
|
|
64
59
|
}
|
|
@@ -12,33 +12,48 @@ chunkFV45V6WC_cjs.__export(network_exports, {
|
|
|
12
12
|
getNetworksHandler: () => getNetworksHandler,
|
|
13
13
|
streamGenerateHandler: () => streamGenerateHandler
|
|
14
14
|
});
|
|
15
|
-
async function getNetworksHandler({
|
|
15
|
+
async function getNetworksHandler({
|
|
16
|
+
mastra,
|
|
17
|
+
runtimeContext
|
|
18
|
+
}) {
|
|
16
19
|
try {
|
|
17
20
|
const networks = mastra.getNetworks();
|
|
18
|
-
const serializedNetworks =
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
21
|
+
const serializedNetworks = await Promise.all(
|
|
22
|
+
networks.map(async (network) => {
|
|
23
|
+
const routingAgent = network.getRoutingAgent();
|
|
24
|
+
const routingLLM = await routingAgent.getLLM({ runtimeContext });
|
|
25
|
+
const agents = network.getAgents();
|
|
26
|
+
return {
|
|
27
|
+
id: network.formatAgentId(routingAgent.name),
|
|
28
|
+
name: routingAgent.name,
|
|
29
|
+
instructions: routingAgent.instructions,
|
|
30
|
+
agents: await Promise.all(
|
|
31
|
+
agents.map(async (agent) => {
|
|
32
|
+
const llm = await agent.getLLM({ runtimeContext });
|
|
33
|
+
return {
|
|
34
|
+
name: agent.name,
|
|
35
|
+
provider: llm?.getProvider(),
|
|
36
|
+
modelId: llm?.getModelId()
|
|
37
|
+
};
|
|
38
|
+
})
|
|
39
|
+
),
|
|
40
|
+
routingModel: {
|
|
41
|
+
provider: routingLLM?.getProvider(),
|
|
42
|
+
modelId: routingLLM?.getModelId()
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
})
|
|
46
|
+
);
|
|
36
47
|
return serializedNetworks;
|
|
37
48
|
} catch (error) {
|
|
38
49
|
return chunkZLBRQFDD_cjs.handleError(error, "Error getting networks");
|
|
39
50
|
}
|
|
40
51
|
}
|
|
41
|
-
async function getNetworkByIdHandler({
|
|
52
|
+
async function getNetworkByIdHandler({
|
|
53
|
+
mastra,
|
|
54
|
+
networkId,
|
|
55
|
+
runtimeContext
|
|
56
|
+
}) {
|
|
42
57
|
try {
|
|
43
58
|
const networks = mastra.getNetworks();
|
|
44
59
|
const network = networks.find((network2) => {
|
|
@@ -49,19 +64,25 @@ async function getNetworkByIdHandler({ mastra, networkId }) {
|
|
|
49
64
|
throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Network not found" });
|
|
50
65
|
}
|
|
51
66
|
const routingAgent = network.getRoutingAgent();
|
|
67
|
+
const routingLLM = await routingAgent.getLLM({ runtimeContext });
|
|
52
68
|
const agents = network.getAgents();
|
|
53
69
|
const serializedNetwork = {
|
|
54
70
|
id: network.formatAgentId(routingAgent.name),
|
|
55
71
|
name: routingAgent.name,
|
|
56
72
|
instructions: routingAgent.instructions,
|
|
57
|
-
agents:
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
73
|
+
agents: await Promise.all(
|
|
74
|
+
agents.map(async (agent) => {
|
|
75
|
+
const llm = await agent.getLLM({ runtimeContext });
|
|
76
|
+
return {
|
|
77
|
+
name: agent.name,
|
|
78
|
+
provider: llm?.getProvider(),
|
|
79
|
+
modelId: llm?.getModelId()
|
|
80
|
+
};
|
|
81
|
+
})
|
|
82
|
+
),
|
|
62
83
|
routingModel: {
|
|
63
|
-
provider:
|
|
64
|
-
modelId:
|
|
84
|
+
provider: routingLLM?.getProvider(),
|
|
85
|
+
modelId: routingLLM?.getModelId()
|
|
65
86
|
}
|
|
66
87
|
};
|
|
67
88
|
return serializedNetwork;
|
|
@@ -4,6 +4,7 @@ var chunk5SWCVTNL_cjs = require('./chunk-5SWCVTNL.cjs');
|
|
|
4
4
|
var chunkQN4KF3BH_cjs = require('./chunk-QN4KF3BH.cjs');
|
|
5
5
|
var chunkZLBRQFDD_cjs = require('./chunk-ZLBRQFDD.cjs');
|
|
6
6
|
var chunkFV45V6WC_cjs = require('./chunk-FV45V6WC.cjs');
|
|
7
|
+
var runtimeContext = require('@mastra/core/runtime-context');
|
|
7
8
|
|
|
8
9
|
// src/server/handlers/agents.ts
|
|
9
10
|
var agents_exports = {};
|
|
@@ -15,27 +16,35 @@ chunkFV45V6WC_cjs.__export(agents_exports, {
|
|
|
15
16
|
getLiveEvalsByAgentIdHandler: () => getLiveEvalsByAgentIdHandler,
|
|
16
17
|
streamGenerateHandler: () => streamGenerateHandler
|
|
17
18
|
});
|
|
18
|
-
async function getAgentsHandler({ mastra }) {
|
|
19
|
+
async function getAgentsHandler({ mastra, runtimeContext }) {
|
|
19
20
|
try {
|
|
20
21
|
const agents = mastra.getAgents();
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
const serializedAgentsMap = await Promise.all(
|
|
23
|
+
Object.entries(agents).map(async ([id, agent]) => {
|
|
24
|
+
const instructions = await agent.getInstructions({ runtimeContext });
|
|
25
|
+
const tools = await agent.getTools({ runtimeContext });
|
|
26
|
+
const llm = await agent.getLLM({ runtimeContext });
|
|
27
|
+
const serializedAgentTools = Object.entries(tools || {}).reduce((acc, [key, tool]) => {
|
|
28
|
+
const _tool = tool;
|
|
29
|
+
acc[key] = {
|
|
30
|
+
..._tool,
|
|
31
|
+
inputSchema: _tool.inputSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(_tool.inputSchema)) : void 0,
|
|
32
|
+
outputSchema: _tool.outputSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(_tool.outputSchema)) : void 0
|
|
33
|
+
};
|
|
34
|
+
return acc;
|
|
35
|
+
}, {});
|
|
36
|
+
return {
|
|
37
|
+
id,
|
|
38
|
+
name: agent.name,
|
|
39
|
+
instructions,
|
|
40
|
+
tools: serializedAgentTools,
|
|
41
|
+
provider: llm?.getProvider(),
|
|
42
|
+
modelId: llm?.getModelId()
|
|
29
43
|
};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
instructions: agent.instructions,
|
|
35
|
-
tools: serializedAgentTools,
|
|
36
|
-
provider: agent.llm?.getProvider(),
|
|
37
|
-
modelId: agent.llm?.getModelId()
|
|
38
|
-
};
|
|
44
|
+
})
|
|
45
|
+
);
|
|
46
|
+
const serializedAgents = serializedAgentsMap.reduce((acc, { id, ...rest }) => {
|
|
47
|
+
acc[id] = rest;
|
|
39
48
|
return acc;
|
|
40
49
|
}, {});
|
|
41
50
|
return serializedAgents;
|
|
@@ -43,13 +52,18 @@ async function getAgentsHandler({ mastra }) {
|
|
|
43
52
|
return chunkZLBRQFDD_cjs.handleError(error, "Error getting agents");
|
|
44
53
|
}
|
|
45
54
|
}
|
|
46
|
-
async function getAgentByIdHandler({
|
|
55
|
+
async function getAgentByIdHandler({
|
|
56
|
+
mastra,
|
|
57
|
+
runtimeContext,
|
|
58
|
+
agentId
|
|
59
|
+
}) {
|
|
47
60
|
try {
|
|
48
61
|
const agent = mastra.getAgent(agentId);
|
|
49
62
|
if (!agent) {
|
|
50
63
|
throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Agent not found" });
|
|
51
64
|
}
|
|
52
|
-
const
|
|
65
|
+
const tools = await agent.getTools({ runtimeContext });
|
|
66
|
+
const serializedAgentTools = Object.entries(tools || {}).reduce((acc, [key, tool]) => {
|
|
53
67
|
const _tool = tool;
|
|
54
68
|
acc[key] = {
|
|
55
69
|
..._tool,
|
|
@@ -58,39 +72,51 @@ async function getAgentByIdHandler({ mastra, agentId }) {
|
|
|
58
72
|
};
|
|
59
73
|
return acc;
|
|
60
74
|
}, {});
|
|
75
|
+
const instructions = await agent.getInstructions({ runtimeContext });
|
|
76
|
+
const llm = await agent.getLLM({ runtimeContext });
|
|
61
77
|
return {
|
|
62
78
|
name: agent.name,
|
|
63
|
-
instructions
|
|
79
|
+
instructions,
|
|
64
80
|
tools: serializedAgentTools,
|
|
65
|
-
provider:
|
|
66
|
-
modelId:
|
|
81
|
+
provider: llm?.getProvider(),
|
|
82
|
+
modelId: llm?.getModelId()
|
|
67
83
|
};
|
|
68
84
|
} catch (error) {
|
|
69
85
|
return chunkZLBRQFDD_cjs.handleError(error, "Error getting agent");
|
|
70
86
|
}
|
|
71
87
|
}
|
|
72
|
-
async function getEvalsByAgentIdHandler({
|
|
88
|
+
async function getEvalsByAgentIdHandler({
|
|
89
|
+
mastra,
|
|
90
|
+
runtimeContext,
|
|
91
|
+
agentId
|
|
92
|
+
}) {
|
|
73
93
|
try {
|
|
74
94
|
const agent = mastra.getAgent(agentId);
|
|
75
95
|
const evals = await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, "test") || [];
|
|
96
|
+
const instructions = await agent.getInstructions({ runtimeContext });
|
|
76
97
|
return {
|
|
77
98
|
id: agentId,
|
|
78
99
|
name: agent.name,
|
|
79
|
-
instructions
|
|
100
|
+
instructions,
|
|
80
101
|
evals
|
|
81
102
|
};
|
|
82
103
|
} catch (error) {
|
|
83
104
|
return chunkZLBRQFDD_cjs.handleError(error, "Error getting test evals");
|
|
84
105
|
}
|
|
85
106
|
}
|
|
86
|
-
async function getLiveEvalsByAgentIdHandler({
|
|
107
|
+
async function getLiveEvalsByAgentIdHandler({
|
|
108
|
+
mastra,
|
|
109
|
+
runtimeContext,
|
|
110
|
+
agentId
|
|
111
|
+
}) {
|
|
87
112
|
try {
|
|
88
113
|
const agent = mastra.getAgent(agentId);
|
|
89
114
|
const evals = await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, "live") || [];
|
|
115
|
+
const instructions = await agent.getInstructions({ runtimeContext });
|
|
90
116
|
return {
|
|
91
117
|
id: agentId,
|
|
92
118
|
name: agent.name,
|
|
93
|
-
instructions
|
|
119
|
+
instructions,
|
|
94
120
|
evals
|
|
95
121
|
};
|
|
96
122
|
} catch (error) {
|
|
@@ -99,7 +125,7 @@ async function getLiveEvalsByAgentIdHandler({ mastra, agentId }) {
|
|
|
99
125
|
}
|
|
100
126
|
async function generateHandler({
|
|
101
127
|
mastra,
|
|
102
|
-
runtimeContext,
|
|
128
|
+
runtimeContext: runtimeContext$1,
|
|
103
129
|
agentId,
|
|
104
130
|
body
|
|
105
131
|
}) {
|
|
@@ -108,14 +134,18 @@ async function generateHandler({
|
|
|
108
134
|
if (!agent) {
|
|
109
135
|
throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Agent not found" });
|
|
110
136
|
}
|
|
111
|
-
const { messages, resourceId, resourceid, ...rest } = body;
|
|
137
|
+
const { messages, resourceId, resourceid, runtimeContext: agentRuntimeContext, ...rest } = body;
|
|
112
138
|
const finalResourceId = resourceId ?? resourceid;
|
|
139
|
+
const finalRuntimeContext = new runtimeContext.RuntimeContext([
|
|
140
|
+
...Array.from(runtimeContext$1.entries()),
|
|
141
|
+
...Array.from(Object.entries(agentRuntimeContext ?? {}))
|
|
142
|
+
]);
|
|
113
143
|
chunkQN4KF3BH_cjs.validateBody({ messages });
|
|
114
144
|
const result = await agent.generate(messages, {
|
|
115
145
|
...rest,
|
|
116
146
|
// @ts-expect-error TODO fix types
|
|
117
147
|
resourceId: finalResourceId,
|
|
118
|
-
runtimeContext
|
|
148
|
+
runtimeContext: finalRuntimeContext
|
|
119
149
|
});
|
|
120
150
|
return result;
|
|
121
151
|
} catch (error) {
|
|
@@ -124,7 +154,7 @@ async function generateHandler({
|
|
|
124
154
|
}
|
|
125
155
|
async function streamGenerateHandler({
|
|
126
156
|
mastra,
|
|
127
|
-
runtimeContext,
|
|
157
|
+
runtimeContext: runtimeContext$1,
|
|
128
158
|
agentId,
|
|
129
159
|
body
|
|
130
160
|
}) {
|
|
@@ -133,14 +163,18 @@ async function streamGenerateHandler({
|
|
|
133
163
|
if (!agent) {
|
|
134
164
|
throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Agent not found" });
|
|
135
165
|
}
|
|
136
|
-
const { messages, resourceId, resourceid, ...rest } = body;
|
|
166
|
+
const { messages, resourceId, resourceid, runtimeContext: agentRuntimeContext, ...rest } = body;
|
|
137
167
|
const finalResourceId = resourceId ?? resourceid;
|
|
168
|
+
const finalRuntimeContext = new runtimeContext.RuntimeContext([
|
|
169
|
+
...Array.from(runtimeContext$1.entries()),
|
|
170
|
+
...Array.from(Object.entries(agentRuntimeContext ?? {}))
|
|
171
|
+
]);
|
|
138
172
|
chunkQN4KF3BH_cjs.validateBody({ messages });
|
|
139
173
|
const streamResult = await agent.stream(messages, {
|
|
140
174
|
...rest,
|
|
141
175
|
// @ts-expect-error TODO fix types
|
|
142
176
|
resourceId: finalResourceId,
|
|
143
|
-
runtimeContext
|
|
177
|
+
runtimeContext: finalRuntimeContext
|
|
144
178
|
});
|
|
145
179
|
const streamResponse = rest.output ? streamResult.toTextStreamResponse() : streamResult.toDataStreamResponse({
|
|
146
180
|
sendUsage: true,
|
|
@@ -22,7 +22,7 @@ async function getTelemetryHandler({ mastra, body }) {
|
|
|
22
22
|
if (!body) {
|
|
23
23
|
throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Body is required" });
|
|
24
24
|
}
|
|
25
|
-
const { name, scope, page, perPage, attribute } = body;
|
|
25
|
+
const { name, scope, page, perPage, attribute, fromDate, toDate } = body;
|
|
26
26
|
const attributes = attribute ? Object.fromEntries(
|
|
27
27
|
(Array.isArray(attribute) ? attribute : [attribute]).map((attr) => {
|
|
28
28
|
const [key, value] = attr.split(":");
|
|
@@ -34,7 +34,9 @@ async function getTelemetryHandler({ mastra, body }) {
|
|
|
34
34
|
scope,
|
|
35
35
|
page: Number(page ?? 0),
|
|
36
36
|
perPage: Number(perPage ?? 100),
|
|
37
|
-
attributes
|
|
37
|
+
attributes,
|
|
38
|
+
fromDate: fromDate ? new Date(fromDate) : void 0,
|
|
39
|
+
toDate: toDate ? new Date(toDate) : void 0
|
|
38
40
|
});
|
|
39
41
|
return traces;
|
|
40
42
|
} catch (error2) {
|
|
@@ -20,7 +20,7 @@ async function getTelemetryHandler({ mastra, body }) {
|
|
|
20
20
|
if (!body) {
|
|
21
21
|
throw new HTTPException(400, { message: "Body is required" });
|
|
22
22
|
}
|
|
23
|
-
const { name, scope, page, perPage, attribute } = body;
|
|
23
|
+
const { name, scope, page, perPage, attribute, fromDate, toDate } = body;
|
|
24
24
|
const attributes = attribute ? Object.fromEntries(
|
|
25
25
|
(Array.isArray(attribute) ? attribute : [attribute]).map((attr) => {
|
|
26
26
|
const [key, value] = attr.split(":");
|
|
@@ -32,7 +32,9 @@ async function getTelemetryHandler({ mastra, body }) {
|
|
|
32
32
|
scope,
|
|
33
33
|
page: Number(page ?? 0),
|
|
34
34
|
perPage: Number(perPage ?? 100),
|
|
35
|
-
attributes
|
|
35
|
+
attributes,
|
|
36
|
+
fromDate: fromDate ? new Date(fromDate) : void 0,
|
|
37
|
+
toDate: toDate ? new Date(toDate) : void 0
|
|
36
38
|
});
|
|
37
39
|
return traces;
|
|
38
40
|
} catch (error2) {
|