@mastra/server 0.0.0-bundle-dynamic-imports-20250424001248 → 0.0.0-cli-debug-20250611094457
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 +48 -135
- package/dist/_tsup-dts-rollup.d.cts +331 -42
- package/dist/_tsup-dts-rollup.d.ts +331 -42
- package/dist/{chunk-4JINXASC.js → chunk-55DOQLP6.js} +5 -4
- package/dist/{chunk-QN4KF3BH.cjs → chunk-57CJTIPW.cjs} +2 -2
- package/dist/{chunk-ZLBRQFDD.cjs → chunk-64U3UDTH.cjs} +2 -2
- package/dist/chunk-6F2H7Y45.js +255 -0
- package/dist/{chunk-2FJURXCL.cjs → chunk-6TJSHFCJ.cjs} +44 -36
- package/dist/chunk-75ZPJI57.cjs +9 -0
- package/dist/chunk-7IBZ4L35.js +344 -0
- package/dist/{chunk-7IWQE76Z.cjs → chunk-B4MQFJ7G.cjs} +16 -10
- package/dist/{chunk-WTHDCRMY.js → chunk-BFOA2QQY.js} +12 -6
- package/dist/{chunk-M56ECCHK.cjs → chunk-BNEY4P4P.cjs} +20 -19
- package/dist/{chunk-RE6YL32K.js → chunk-C7564HUT.js} +52 -30
- package/dist/{chunk-55HTWX4C.cjs → chunk-CMMOIUFC.cjs} +40 -19
- package/dist/{chunk-Q6SHQECN.js → chunk-CP55EVBK.js} +24 -4
- package/dist/chunk-GHC4YV6R.js +504 -0
- package/dist/{chunk-L7XE5QTW.js → chunk-H5PTF3Y4.js} +1 -1
- package/dist/{chunk-5JNVY6DU.js → chunk-HYP7B2TL.js} +7 -5
- package/dist/{chunk-RBQASTUP.js → chunk-I7KJZNX5.js} +14 -6
- package/dist/chunk-IMBY5XUG.cjs +86 -0
- package/dist/chunk-JEWNMAYQ.cjs +263 -0
- package/dist/chunk-JKF6PRPU.cjs +357 -0
- package/dist/{chunk-3AHQ5RGN.js → chunk-M5ABIP7D.js} +1 -1
- package/dist/chunk-MLKGABMK.js +7 -0
- package/dist/{chunk-TRDNDNGQ.js → chunk-NYN7KFXL.js} +1 -7
- package/dist/{chunk-FV45V6WC.cjs → chunk-OCWPVYNI.cjs} +0 -7
- package/dist/chunk-QLG2PFHE.js +81 -0
- package/dist/chunk-SDPGVWQJ.cjs +512 -0
- package/dist/{chunk-LFOBHRFO.js → chunk-TEZOEGR4.js} +69 -54
- package/dist/{chunk-D3G23FP3.cjs → chunk-TJO277H7.cjs} +24 -22
- package/dist/chunk-UZ7FJ66C.cjs +332 -0
- package/dist/{chunk-FPIWDH5Y.cjs → chunk-VPNDC2DI.cjs} +62 -40
- package/dist/chunk-WKWHYFX4.js +2001 -0
- package/dist/chunk-XUGQSVZ4.cjs +2004 -0
- package/dist/server/handlers/a2a.cjs +30 -0
- package/dist/server/handlers/a2a.d.cts +6 -0
- package/dist/server/handlers/a2a.d.ts +6 -0
- package/dist/server/handlers/a2a.js +1 -0
- package/dist/server/handlers/agents.cjs +7 -7
- package/dist/server/handlers/agents.js +1 -1
- package/dist/server/handlers/error.cjs +2 -2
- package/dist/server/handlers/error.js +1 -1
- package/dist/server/handlers/legacyWorkflows.cjs +46 -0
- package/dist/server/handlers/legacyWorkflows.d.cts +10 -0
- package/dist/server/handlers/legacyWorkflows.d.ts +10 -0
- package/dist/server/handlers/legacyWorkflows.js +1 -0
- package/dist/server/handlers/logs.cjs +4 -4
- package/dist/server/handlers/logs.js +1 -1
- package/dist/server/handlers/memory.cjs +9 -9
- package/dist/server/handlers/memory.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/tools.cjs +5 -5
- package/dist/server/handlers/tools.js +1 -1
- package/dist/server/handlers/utils.cjs +2 -2
- package/dist/server/handlers/utils.js +1 -1
- package/dist/server/handlers/vector.cjs +7 -7
- package/dist/server/handlers/vector.js +1 -1
- package/dist/server/handlers/voice.cjs +8 -4
- package/dist/server/handlers/voice.d.cts +1 -0
- package/dist/server/handlers/voice.d.ts +1 -0
- package/dist/server/handlers/voice.js +1 -1
- package/dist/server/handlers/workflows.cjs +17 -13
- package/dist/server/handlers/workflows.d.cts +3 -2
- package/dist/server/handlers/workflows.d.ts +3 -2
- package/dist/server/handlers/workflows.js +1 -1
- package/dist/server/handlers.cjs +33 -23
- package/dist/server/handlers.d.cts +2 -0
- package/dist/server/handlers.d.ts +2 -0
- package/dist/server/handlers.js +11 -9
- package/package.json +12 -10
- package/dist/chunk-3EJZQ6TQ.js +0 -49
- package/dist/chunk-5SWCVTNL.cjs +0 -5579
- package/dist/chunk-HCOPJZ4A.cjs +0 -164
- package/dist/chunk-OMN3UI6X.js +0 -5576
- package/dist/chunk-R4J7XQYU.js +0 -156
- package/dist/chunk-SKBVVI24.cjs +0 -54
- package/dist/chunk-TZK63M5N.cjs +0 -317
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
import { stringify, esm_default } from './chunk-WKWHYFX4.js';
|
|
2
|
+
import { handleError } from './chunk-M5ABIP7D.js';
|
|
3
|
+
import { HTTPException } from './chunk-NYN7KFXL.js';
|
|
4
|
+
import { __export } from './chunk-MLKGABMK.js';
|
|
5
|
+
import { ReadableStream } from 'stream/web';
|
|
6
|
+
|
|
7
|
+
// src/server/handlers/workflows.ts
|
|
8
|
+
var workflows_exports = {};
|
|
9
|
+
__export(workflows_exports, {
|
|
10
|
+
createWorkflowRunHandler: () => createWorkflowRunHandler,
|
|
11
|
+
getWorkflowByIdHandler: () => getWorkflowByIdHandler,
|
|
12
|
+
getWorkflowRunByIdHandler: () => getWorkflowRunByIdHandler,
|
|
13
|
+
getWorkflowRunsHandler: () => getWorkflowRunsHandler,
|
|
14
|
+
getWorkflowsHandler: () => getWorkflowsHandler,
|
|
15
|
+
resumeAsyncWorkflowHandler: () => resumeAsyncWorkflowHandler,
|
|
16
|
+
resumeWorkflowHandler: () => resumeWorkflowHandler,
|
|
17
|
+
startAsyncWorkflowHandler: () => startAsyncWorkflowHandler,
|
|
18
|
+
startWorkflowRunHandler: () => startWorkflowRunHandler,
|
|
19
|
+
streamWorkflowHandler: () => streamWorkflowHandler,
|
|
20
|
+
watchWorkflowHandler: () => watchWorkflowHandler
|
|
21
|
+
});
|
|
22
|
+
async function getWorkflowsHandler({ mastra }) {
|
|
23
|
+
try {
|
|
24
|
+
const workflows = mastra.getWorkflows({ serialized: false });
|
|
25
|
+
const _workflows = Object.entries(workflows).reduce((acc, [key, workflow]) => {
|
|
26
|
+
acc[key] = {
|
|
27
|
+
name: workflow.name,
|
|
28
|
+
description: workflow.description,
|
|
29
|
+
steps: Object.entries(workflow.steps).reduce((acc2, [key2, step]) => {
|
|
30
|
+
acc2[key2] = {
|
|
31
|
+
id: step.id,
|
|
32
|
+
description: step.description,
|
|
33
|
+
inputSchema: step.inputSchema ? stringify(esm_default(step.inputSchema)) : void 0,
|
|
34
|
+
outputSchema: step.outputSchema ? stringify(esm_default(step.outputSchema)) : void 0,
|
|
35
|
+
resumeSchema: step.resumeSchema ? stringify(esm_default(step.resumeSchema)) : void 0,
|
|
36
|
+
suspendSchema: step.suspendSchema ? stringify(esm_default(step.suspendSchema)) : void 0
|
|
37
|
+
};
|
|
38
|
+
return acc2;
|
|
39
|
+
}, {}),
|
|
40
|
+
stepGraph: workflow.serializedStepGraph,
|
|
41
|
+
inputSchema: workflow.inputSchema ? stringify(esm_default(workflow.inputSchema)) : void 0,
|
|
42
|
+
outputSchema: workflow.outputSchema ? stringify(esm_default(workflow.outputSchema)) : void 0
|
|
43
|
+
};
|
|
44
|
+
return acc;
|
|
45
|
+
}, {});
|
|
46
|
+
return _workflows;
|
|
47
|
+
} catch (error) {
|
|
48
|
+
throw new HTTPException(500, { message: error?.message || "Error getting workflows" });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async function getWorkflowByIdHandler({ mastra, workflowId }) {
|
|
52
|
+
try {
|
|
53
|
+
if (!workflowId) {
|
|
54
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
55
|
+
}
|
|
56
|
+
const workflow = mastra.getWorkflow(workflowId);
|
|
57
|
+
if (!workflow) {
|
|
58
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
steps: Object.entries(workflow.steps).reduce((acc, [key, step]) => {
|
|
62
|
+
acc[key] = {
|
|
63
|
+
id: step.id,
|
|
64
|
+
description: step.description,
|
|
65
|
+
inputSchema: step.inputSchema ? stringify(esm_default(step.inputSchema)) : void 0,
|
|
66
|
+
outputSchema: step.outputSchema ? stringify(esm_default(step.outputSchema)) : void 0,
|
|
67
|
+
resumeSchema: step.resumeSchema ? stringify(esm_default(step.resumeSchema)) : void 0,
|
|
68
|
+
suspendSchema: step.suspendSchema ? stringify(esm_default(step.suspendSchema)) : void 0
|
|
69
|
+
};
|
|
70
|
+
return acc;
|
|
71
|
+
}, {}),
|
|
72
|
+
name: workflow.name,
|
|
73
|
+
description: workflow.description,
|
|
74
|
+
stepGraph: workflow.serializedStepGraph,
|
|
75
|
+
inputSchema: workflow.inputSchema ? stringify(esm_default(workflow.inputSchema)) : void 0,
|
|
76
|
+
outputSchema: workflow.outputSchema ? stringify(esm_default(workflow.outputSchema)) : void 0
|
|
77
|
+
};
|
|
78
|
+
} catch (error) {
|
|
79
|
+
throw new HTTPException(500, { message: error?.message || "Error getting workflow" });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
async function getWorkflowRunByIdHandler({
|
|
83
|
+
mastra,
|
|
84
|
+
workflowId,
|
|
85
|
+
runId
|
|
86
|
+
}) {
|
|
87
|
+
try {
|
|
88
|
+
if (!workflowId) {
|
|
89
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
90
|
+
}
|
|
91
|
+
if (!runId) {
|
|
92
|
+
throw new HTTPException(400, { message: "Run ID is required" });
|
|
93
|
+
}
|
|
94
|
+
const workflow = mastra.getWorkflow(workflowId);
|
|
95
|
+
if (!workflow) {
|
|
96
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
97
|
+
}
|
|
98
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
99
|
+
if (!run) {
|
|
100
|
+
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
101
|
+
}
|
|
102
|
+
return run;
|
|
103
|
+
} catch (error) {
|
|
104
|
+
throw new HTTPException(500, { message: error?.message || "Error getting workflow run" });
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
async function createWorkflowRunHandler({
|
|
108
|
+
mastra,
|
|
109
|
+
workflowId,
|
|
110
|
+
runId: prevRunId
|
|
111
|
+
}) {
|
|
112
|
+
try {
|
|
113
|
+
if (!workflowId) {
|
|
114
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
115
|
+
}
|
|
116
|
+
const workflow = mastra.getWorkflow(workflowId);
|
|
117
|
+
if (!workflow) {
|
|
118
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
119
|
+
}
|
|
120
|
+
const run = workflow.createRun({ runId: prevRunId });
|
|
121
|
+
return { runId: run.runId };
|
|
122
|
+
} catch (error) {
|
|
123
|
+
throw new HTTPException(500, { message: error?.message || "Error creating workflow run" });
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
async function startAsyncWorkflowHandler({
|
|
127
|
+
mastra,
|
|
128
|
+
runtimeContext,
|
|
129
|
+
workflowId,
|
|
130
|
+
runId,
|
|
131
|
+
inputData
|
|
132
|
+
}) {
|
|
133
|
+
try {
|
|
134
|
+
if (!workflowId) {
|
|
135
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
136
|
+
}
|
|
137
|
+
const workflow = mastra.getWorkflow(workflowId);
|
|
138
|
+
if (!workflow) {
|
|
139
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
140
|
+
}
|
|
141
|
+
const _run = workflow.createRun({ runId });
|
|
142
|
+
const result = await _run.start({
|
|
143
|
+
inputData,
|
|
144
|
+
runtimeContext
|
|
145
|
+
});
|
|
146
|
+
return result;
|
|
147
|
+
} catch (error) {
|
|
148
|
+
throw new HTTPException(500, { message: error?.message || "Error executing workflow" });
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
async function startWorkflowRunHandler({
|
|
152
|
+
mastra,
|
|
153
|
+
runtimeContext,
|
|
154
|
+
workflowId,
|
|
155
|
+
runId,
|
|
156
|
+
inputData
|
|
157
|
+
}) {
|
|
158
|
+
try {
|
|
159
|
+
if (!workflowId) {
|
|
160
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
161
|
+
}
|
|
162
|
+
if (!runId) {
|
|
163
|
+
throw new HTTPException(400, { message: "runId required to start run" });
|
|
164
|
+
}
|
|
165
|
+
const workflow = mastra.getWorkflow(workflowId);
|
|
166
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
167
|
+
if (!run) {
|
|
168
|
+
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
169
|
+
}
|
|
170
|
+
const _run = workflow.createRun({ runId });
|
|
171
|
+
void _run.start({
|
|
172
|
+
inputData,
|
|
173
|
+
runtimeContext
|
|
174
|
+
});
|
|
175
|
+
return { message: "Workflow run started" };
|
|
176
|
+
} catch (e) {
|
|
177
|
+
return handleError(e, "Error starting workflow run");
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
async function watchWorkflowHandler({
|
|
181
|
+
mastra,
|
|
182
|
+
workflowId,
|
|
183
|
+
runId
|
|
184
|
+
}) {
|
|
185
|
+
try {
|
|
186
|
+
if (!workflowId) {
|
|
187
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
188
|
+
}
|
|
189
|
+
if (!runId) {
|
|
190
|
+
throw new HTTPException(400, { message: "runId required to watch workflow" });
|
|
191
|
+
}
|
|
192
|
+
const workflow = mastra.getWorkflow(workflowId);
|
|
193
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
194
|
+
if (!run) {
|
|
195
|
+
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
196
|
+
}
|
|
197
|
+
const _run = workflow.createRun({ runId });
|
|
198
|
+
let unwatch;
|
|
199
|
+
let asyncRef = null;
|
|
200
|
+
const stream = new ReadableStream({
|
|
201
|
+
start(controller) {
|
|
202
|
+
unwatch = _run.watch(({ type, payload, eventTimestamp }) => {
|
|
203
|
+
controller.enqueue(JSON.stringify({ type, payload, eventTimestamp, runId }));
|
|
204
|
+
if (asyncRef) {
|
|
205
|
+
clearImmediate(asyncRef);
|
|
206
|
+
asyncRef = null;
|
|
207
|
+
}
|
|
208
|
+
asyncRef = setImmediate(async () => {
|
|
209
|
+
const runDone = payload.workflowState.status !== "running";
|
|
210
|
+
if (runDone) {
|
|
211
|
+
controller.close();
|
|
212
|
+
unwatch?.();
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
},
|
|
217
|
+
cancel() {
|
|
218
|
+
unwatch?.();
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
return stream;
|
|
222
|
+
} catch (error) {
|
|
223
|
+
return handleError(error, "Error watching workflow");
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
function streamWorkflowHandler({
|
|
227
|
+
mastra,
|
|
228
|
+
runtimeContext,
|
|
229
|
+
workflowId,
|
|
230
|
+
runId,
|
|
231
|
+
inputData
|
|
232
|
+
}) {
|
|
233
|
+
try {
|
|
234
|
+
if (!workflowId) {
|
|
235
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
236
|
+
}
|
|
237
|
+
if (!runId) {
|
|
238
|
+
throw new HTTPException(400, { message: "runId required to resume workflow" });
|
|
239
|
+
}
|
|
240
|
+
const workflow = mastra.getWorkflow(workflowId);
|
|
241
|
+
if (!workflow) {
|
|
242
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
243
|
+
}
|
|
244
|
+
const run = workflow.createRun({ runId });
|
|
245
|
+
const result = run.stream({
|
|
246
|
+
inputData,
|
|
247
|
+
runtimeContext
|
|
248
|
+
});
|
|
249
|
+
return result;
|
|
250
|
+
} catch (error) {
|
|
251
|
+
return handleError(error, "Error executing workflow");
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
async function resumeAsyncWorkflowHandler({
|
|
255
|
+
mastra,
|
|
256
|
+
workflowId,
|
|
257
|
+
runId,
|
|
258
|
+
body,
|
|
259
|
+
runtimeContext
|
|
260
|
+
}) {
|
|
261
|
+
try {
|
|
262
|
+
if (!workflowId) {
|
|
263
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
264
|
+
}
|
|
265
|
+
if (!runId) {
|
|
266
|
+
throw new HTTPException(400, { message: "runId required to resume workflow" });
|
|
267
|
+
}
|
|
268
|
+
if (!body.step) {
|
|
269
|
+
throw new HTTPException(400, { message: "step required to resume workflow" });
|
|
270
|
+
}
|
|
271
|
+
const workflow = mastra.getWorkflow(workflowId);
|
|
272
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
273
|
+
if (!run) {
|
|
274
|
+
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
275
|
+
}
|
|
276
|
+
const _run = workflow.createRun({ runId });
|
|
277
|
+
const result = await _run.resume({
|
|
278
|
+
step: body.step,
|
|
279
|
+
resumeData: body.resumeData,
|
|
280
|
+
runtimeContext
|
|
281
|
+
});
|
|
282
|
+
return result;
|
|
283
|
+
} catch (error) {
|
|
284
|
+
return handleError(error, "Error resuming workflow step");
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
async function resumeWorkflowHandler({
|
|
288
|
+
mastra,
|
|
289
|
+
workflowId,
|
|
290
|
+
runId,
|
|
291
|
+
body,
|
|
292
|
+
runtimeContext
|
|
293
|
+
}) {
|
|
294
|
+
try {
|
|
295
|
+
if (!workflowId) {
|
|
296
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
297
|
+
}
|
|
298
|
+
if (!runId) {
|
|
299
|
+
throw new HTTPException(400, { message: "runId required to resume workflow" });
|
|
300
|
+
}
|
|
301
|
+
if (!body.step) {
|
|
302
|
+
throw new HTTPException(400, { message: "step required to resume workflow" });
|
|
303
|
+
}
|
|
304
|
+
const workflow = mastra.getWorkflow(workflowId);
|
|
305
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
306
|
+
if (!run) {
|
|
307
|
+
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
308
|
+
}
|
|
309
|
+
const _run = workflow.createRun({ runId });
|
|
310
|
+
void _run.resume({
|
|
311
|
+
step: body.step,
|
|
312
|
+
resumeData: body.resumeData,
|
|
313
|
+
runtimeContext
|
|
314
|
+
});
|
|
315
|
+
return { message: "Workflow run resumed" };
|
|
316
|
+
} catch (error) {
|
|
317
|
+
return handleError(error, "Error resuming workflow");
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
async function getWorkflowRunsHandler({
|
|
321
|
+
mastra,
|
|
322
|
+
workflowId,
|
|
323
|
+
fromDate,
|
|
324
|
+
toDate,
|
|
325
|
+
limit,
|
|
326
|
+
offset,
|
|
327
|
+
resourceId
|
|
328
|
+
}) {
|
|
329
|
+
try {
|
|
330
|
+
if (!workflowId) {
|
|
331
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
332
|
+
}
|
|
333
|
+
const workflow = mastra.getWorkflow(workflowId);
|
|
334
|
+
const workflowRuns = await workflow.getWorkflowRuns({ fromDate, toDate, limit, offset, resourceId }) || {
|
|
335
|
+
runs: [],
|
|
336
|
+
total: 0
|
|
337
|
+
};
|
|
338
|
+
return workflowRuns;
|
|
339
|
+
} catch (error) {
|
|
340
|
+
return handleError(error, "Error getting workflow runs");
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
export { createWorkflowRunHandler, getWorkflowByIdHandler, getWorkflowRunByIdHandler, getWorkflowRunsHandler, getWorkflowsHandler, resumeAsyncWorkflowHandler, resumeWorkflowHandler, startAsyncWorkflowHandler, startWorkflowRunHandler, streamWorkflowHandler, watchWorkflowHandler, workflows_exports };
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunk64U3UDTH_cjs = require('./chunk-64U3UDTH.cjs');
|
|
4
|
+
var chunkOCWPVYNI_cjs = require('./chunk-OCWPVYNI.cjs');
|
|
5
|
+
var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
|
|
5
6
|
|
|
6
7
|
// src/server/handlers/telemetry.ts
|
|
7
8
|
var telemetry_exports = {};
|
|
8
|
-
|
|
9
|
+
chunk75ZPJI57_cjs.__export(telemetry_exports, {
|
|
9
10
|
getTelemetryHandler: () => getTelemetryHandler,
|
|
10
11
|
storeTelemetryHandler: () => storeTelemetryHandler
|
|
11
12
|
});
|
|
@@ -14,15 +15,15 @@ async function getTelemetryHandler({ mastra, body }) {
|
|
|
14
15
|
const telemetry = mastra.getTelemetry();
|
|
15
16
|
const storage = mastra.getStorage();
|
|
16
17
|
if (!telemetry) {
|
|
17
|
-
throw new
|
|
18
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Telemetry is not initialized" });
|
|
18
19
|
}
|
|
19
20
|
if (!storage) {
|
|
20
|
-
|
|
21
|
+
return [];
|
|
21
22
|
}
|
|
22
23
|
if (!body) {
|
|
23
|
-
throw new
|
|
24
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Body is required" });
|
|
24
25
|
}
|
|
25
|
-
const { name, scope, page, perPage, attribute } = body;
|
|
26
|
+
const { name, scope, page, perPage, attribute, fromDate, toDate } = body;
|
|
26
27
|
const attributes = attribute ? Object.fromEntries(
|
|
27
28
|
(Array.isArray(attribute) ? attribute : [attribute]).map((attr) => {
|
|
28
29
|
const [key, value] = attr.split(":");
|
|
@@ -34,11 +35,13 @@ async function getTelemetryHandler({ mastra, body }) {
|
|
|
34
35
|
scope,
|
|
35
36
|
page: Number(page ?? 0),
|
|
36
37
|
perPage: Number(perPage ?? 100),
|
|
37
|
-
attributes
|
|
38
|
+
attributes,
|
|
39
|
+
fromDate: fromDate ? new Date(fromDate) : void 0,
|
|
40
|
+
toDate: toDate ? new Date(toDate) : void 0
|
|
38
41
|
});
|
|
39
42
|
return traces;
|
|
40
43
|
} catch (error2) {
|
|
41
|
-
return
|
|
44
|
+
return chunk64U3UDTH_cjs.handleError(error2, "Error getting telemetry");
|
|
42
45
|
}
|
|
43
46
|
}
|
|
44
47
|
async function storeTelemetryHandler({ mastra, body }) {
|
|
@@ -46,7 +49,10 @@ async function storeTelemetryHandler({ mastra, body }) {
|
|
|
46
49
|
const storage = mastra.getStorage();
|
|
47
50
|
const logger = mastra.getLogger();
|
|
48
51
|
if (!storage) {
|
|
49
|
-
|
|
52
|
+
return {
|
|
53
|
+
status: "error",
|
|
54
|
+
message: "Storage is not initialized"
|
|
55
|
+
};
|
|
50
56
|
}
|
|
51
57
|
const now = /* @__PURE__ */ new Date();
|
|
52
58
|
const items = body?.resourceSpans?.[0]?.scopeSpans;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { handleError } from './chunk-
|
|
2
|
-
import {
|
|
1
|
+
import { handleError } from './chunk-M5ABIP7D.js';
|
|
2
|
+
import { HTTPException } from './chunk-NYN7KFXL.js';
|
|
3
|
+
import { __export } from './chunk-MLKGABMK.js';
|
|
3
4
|
|
|
4
5
|
// src/server/handlers/telemetry.ts
|
|
5
6
|
var telemetry_exports = {};
|
|
@@ -15,12 +16,12 @@ async function getTelemetryHandler({ mastra, body }) {
|
|
|
15
16
|
throw new HTTPException(400, { message: "Telemetry is not initialized" });
|
|
16
17
|
}
|
|
17
18
|
if (!storage) {
|
|
18
|
-
|
|
19
|
+
return [];
|
|
19
20
|
}
|
|
20
21
|
if (!body) {
|
|
21
22
|
throw new HTTPException(400, { message: "Body is required" });
|
|
22
23
|
}
|
|
23
|
-
const { name, scope, page, perPage, attribute } = body;
|
|
24
|
+
const { name, scope, page, perPage, attribute, fromDate, toDate } = body;
|
|
24
25
|
const attributes = attribute ? Object.fromEntries(
|
|
25
26
|
(Array.isArray(attribute) ? attribute : [attribute]).map((attr) => {
|
|
26
27
|
const [key, value] = attr.split(":");
|
|
@@ -32,7 +33,9 @@ async function getTelemetryHandler({ mastra, body }) {
|
|
|
32
33
|
scope,
|
|
33
34
|
page: Number(page ?? 0),
|
|
34
35
|
perPage: Number(perPage ?? 100),
|
|
35
|
-
attributes
|
|
36
|
+
attributes,
|
|
37
|
+
fromDate: fromDate ? new Date(fromDate) : void 0,
|
|
38
|
+
toDate: toDate ? new Date(toDate) : void 0
|
|
36
39
|
});
|
|
37
40
|
return traces;
|
|
38
41
|
} catch (error2) {
|
|
@@ -44,7 +47,10 @@ async function storeTelemetryHandler({ mastra, body }) {
|
|
|
44
47
|
const storage = mastra.getStorage();
|
|
45
48
|
const logger = mastra.getLogger();
|
|
46
49
|
if (!storage) {
|
|
47
|
-
|
|
50
|
+
return {
|
|
51
|
+
status: "error",
|
|
52
|
+
message: "Storage is not initialized"
|
|
53
|
+
};
|
|
48
54
|
}
|
|
49
55
|
const now = /* @__PURE__ */ new Date();
|
|
50
56
|
const items = body?.resourceSpans?.[0]?.scopeSpans;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunk64U3UDTH_cjs = require('./chunk-64U3UDTH.cjs');
|
|
4
|
+
var chunkOCWPVYNI_cjs = require('./chunk-OCWPVYNI.cjs');
|
|
5
|
+
var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
|
|
5
6
|
|
|
6
7
|
// src/server/handlers/vector.ts
|
|
7
8
|
var vector_exports = {};
|
|
8
|
-
|
|
9
|
+
chunk75ZPJI57_cjs.__export(vector_exports, {
|
|
9
10
|
createIndex: () => createIndex,
|
|
10
11
|
deleteIndex: () => deleteIndex,
|
|
11
12
|
describeIndex: () => describeIndex,
|
|
@@ -15,24 +16,24 @@ chunkFV45V6WC_cjs.__export(vector_exports, {
|
|
|
15
16
|
});
|
|
16
17
|
function getVector(mastra, vectorName) {
|
|
17
18
|
if (!vectorName) {
|
|
18
|
-
throw new
|
|
19
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Vector name is required" });
|
|
19
20
|
}
|
|
20
21
|
const vector = mastra.getVector(vectorName);
|
|
21
22
|
if (!vector) {
|
|
22
|
-
throw new
|
|
23
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: `Vector store ${vectorName} not found` });
|
|
23
24
|
}
|
|
24
25
|
return vector;
|
|
25
26
|
}
|
|
26
27
|
async function upsertVectors({ mastra, vectorName, index }) {
|
|
27
28
|
try {
|
|
28
29
|
if (!index?.indexName || !index?.vectors || !Array.isArray(index.vectors)) {
|
|
29
|
-
throw new
|
|
30
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Invalid request index. indexName and vectors array are required." });
|
|
30
31
|
}
|
|
31
32
|
const vector = getVector(mastra, vectorName);
|
|
32
33
|
const result = await vector.upsert(index);
|
|
33
34
|
return { ids: result };
|
|
34
35
|
} catch (error) {
|
|
35
|
-
return
|
|
36
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error upserting vectors");
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
39
|
async function createIndex({
|
|
@@ -43,18 +44,18 @@ async function createIndex({
|
|
|
43
44
|
try {
|
|
44
45
|
const { indexName, dimension, metric } = index;
|
|
45
46
|
if (!indexName || typeof dimension !== "number" || dimension <= 0) {
|
|
46
|
-
throw new
|
|
47
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, {
|
|
47
48
|
message: "Invalid request index, indexName and positive dimension number are required."
|
|
48
49
|
});
|
|
49
50
|
}
|
|
50
51
|
if (metric && !["cosine", "euclidean", "dotproduct"].includes(metric)) {
|
|
51
|
-
throw new
|
|
52
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Invalid metric. Must be one of: cosine, euclidean, dotproduct" });
|
|
52
53
|
}
|
|
53
54
|
const vector = getVector(mastra, vectorName);
|
|
54
55
|
await vector.createIndex({ indexName, dimension, metric });
|
|
55
56
|
return { success: true };
|
|
56
57
|
} catch (error) {
|
|
57
|
-
return
|
|
58
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error creating index");
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
61
|
async function queryVectors({
|
|
@@ -64,13 +65,13 @@ async function queryVectors({
|
|
|
64
65
|
}) {
|
|
65
66
|
try {
|
|
66
67
|
if (!query?.indexName || !query?.queryVector || !Array.isArray(query.queryVector)) {
|
|
67
|
-
throw new
|
|
68
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Invalid request query. indexName and queryVector array are required." });
|
|
68
69
|
}
|
|
69
70
|
const vector = getVector(mastra, vectorName);
|
|
70
71
|
const results = await vector.query(query);
|
|
71
72
|
return results;
|
|
72
73
|
} catch (error) {
|
|
73
|
-
return
|
|
74
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error querying vectors");
|
|
74
75
|
}
|
|
75
76
|
}
|
|
76
77
|
async function listIndexes({ mastra, vectorName }) {
|
|
@@ -79,7 +80,7 @@ async function listIndexes({ mastra, vectorName }) {
|
|
|
79
80
|
const indexes = await vector.listIndexes();
|
|
80
81
|
return indexes.filter(Boolean);
|
|
81
82
|
} catch (error) {
|
|
82
|
-
return
|
|
83
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error listing indexes");
|
|
83
84
|
}
|
|
84
85
|
}
|
|
85
86
|
async function describeIndex({
|
|
@@ -89,17 +90,17 @@ async function describeIndex({
|
|
|
89
90
|
}) {
|
|
90
91
|
try {
|
|
91
92
|
if (!indexName) {
|
|
92
|
-
throw new
|
|
93
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Index name is required" });
|
|
93
94
|
}
|
|
94
95
|
const vector = getVector(mastra, vectorName);
|
|
95
|
-
const stats = await vector.describeIndex(indexName);
|
|
96
|
+
const stats = await vector.describeIndex({ indexName });
|
|
96
97
|
return {
|
|
97
98
|
dimension: stats.dimension,
|
|
98
99
|
count: stats.count,
|
|
99
100
|
metric: stats.metric?.toLowerCase()
|
|
100
101
|
};
|
|
101
102
|
} catch (error) {
|
|
102
|
-
return
|
|
103
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error describing index");
|
|
103
104
|
}
|
|
104
105
|
}
|
|
105
106
|
async function deleteIndex({
|
|
@@ -109,13 +110,13 @@ async function deleteIndex({
|
|
|
109
110
|
}) {
|
|
110
111
|
try {
|
|
111
112
|
if (!indexName) {
|
|
112
|
-
throw new
|
|
113
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Index name is required" });
|
|
113
114
|
}
|
|
114
115
|
const vector = getVector(mastra, vectorName);
|
|
115
|
-
await vector.deleteIndex(indexName);
|
|
116
|
+
await vector.deleteIndex({ indexName });
|
|
116
117
|
return { success: true };
|
|
117
118
|
} catch (error) {
|
|
118
|
-
return
|
|
119
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error deleting index");
|
|
119
120
|
}
|
|
120
121
|
}
|
|
121
122
|
|