@mastra/server 0.0.0-message-ordering-20250415215612 → 0.0.0-message-list-update-20250715150321
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +11 -42
- package/README.md +48 -135
- package/dist/_tsup-dts-rollup.d.cts +604 -70
- package/dist/_tsup-dts-rollup.d.ts +604 -70
- package/dist/{chunk-FV45V6WC.cjs → chunk-2KZFMI6P.cjs} +1 -7
- package/dist/chunk-2SLFAFTR.cjs +148 -0
- package/dist/chunk-3CNDE7QY.cjs +308 -0
- package/dist/chunk-4D66QEKC.js +81 -0
- package/dist/{chunk-OPP7H5TW.js → chunk-5PQQ42EZ.js} +83 -68
- package/dist/chunk-75ZPJI57.cjs +9 -0
- package/dist/{chunk-M56ECCHK.cjs → chunk-7TP2LX5L.cjs} +20 -19
- package/dist/chunk-B2PAS2IB.cjs +514 -0
- package/dist/chunk-BK4XT6EG.js +270 -0
- package/dist/{chunk-QN4KF3BH.cjs → chunk-CCGRCYWJ.cjs} +2 -2
- package/dist/{chunk-YANVFOYA.js → chunk-CRCR3ZUK.js} +56 -34
- package/dist/{chunk-PDC4ZBQW.cjs → chunk-FRVBFMO2.cjs} +28 -26
- package/dist/{chunk-CWSDZEZG.cjs → chunk-G7KH752Y.cjs} +18 -12
- package/dist/chunk-GHC4YV6R.js +504 -0
- package/dist/chunk-H7DMHBKY.js +498 -0
- package/dist/chunk-JMLYCXMK.cjs +332 -0
- package/dist/{chunk-3RVHWGWO.js → chunk-KHZKYUNR.js} +36 -19
- package/dist/{chunk-RBQASTUP.js → chunk-KOHWJYJT.js} +120 -27
- package/dist/{chunk-TRDNDNGQ.js → chunk-LCM566I4.js} +2 -7
- package/dist/chunk-LF7P5PLR.js +14 -0
- package/dist/chunk-LI436ITD.cjs +2042 -0
- package/dist/{chunk-UV4WTEH4.js → chunk-LRCAAFUA.js} +11 -9
- package/dist/chunk-LZ3VJXSO.cjs +278 -0
- package/dist/chunk-MEGCYGBU.js +2039 -0
- package/dist/chunk-MLKGABMK.js +7 -0
- package/dist/chunk-PZQDCRPV.cjs +16 -0
- package/dist/chunk-QGX47B5D.cjs +86 -0
- package/dist/{chunk-DVPP5S6I.js → chunk-RG473F6Y.js} +14 -8
- package/dist/chunk-RHSWAXKB.cjs +118 -0
- package/dist/{chunk-L7XE5QTW.js → chunk-RSEO4XPX.js} +1 -1
- package/dist/chunk-SDPGVWQJ.cjs +512 -0
- package/dist/{chunk-4JINXASC.js → chunk-WNVFNNWN.js} +5 -4
- 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 +17 -9
- package/dist/server/handlers/memory.d.cts +2 -0
- package/dist/server/handlers/memory.d.ts +2 -0
- 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/vNextNetwork.cjs +218 -0
- package/dist/server/handlers/vNextNetwork.d.cts +6 -0
- package/dist/server/handlers/vNextNetwork.d.ts +6 -0
- package/dist/server/handlers/vNextNetwork.js +211 -0
- 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 +29 -13
- package/dist/server/handlers/workflows.d.cts +6 -2
- package/dist/server/handlers/workflows.d.ts +6 -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 +15 -14
- package/dist/chunk-2FJURXCL.cjs +0 -213
- package/dist/chunk-3AHQ5RGN.js +0 -11
- package/dist/chunk-3EJZQ6TQ.js +0 -49
- package/dist/chunk-67WTHYAV.js +0 -156
- package/dist/chunk-A7DF4ETD.cjs +0 -100
- package/dist/chunk-B64YROKU.cjs +0 -317
- package/dist/chunk-JLDXUWK7.cjs +0 -126
- package/dist/chunk-QH6XWSXP.cjs +0 -5579
- package/dist/chunk-SKBVVI24.cjs +0 -54
- package/dist/chunk-VK6FX47H.js +0 -5576
- package/dist/chunk-Z46X3YCB.cjs +0 -164
- package/dist/chunk-ZLBRQFDD.cjs +0 -13
|
@@ -1,25 +1,26 @@
|
|
|
1
|
-
import { stringify, esm_default } from './chunk-
|
|
2
|
-
import { handleError } from './chunk-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { stringify, esm_default } from './chunk-MEGCYGBU.js';
|
|
2
|
+
import { handleError } from './chunk-LF7P5PLR.js';
|
|
3
|
+
import { HTTPException } from './chunk-LCM566I4.js';
|
|
4
|
+
import { __export } from './chunk-MLKGABMK.js';
|
|
5
|
+
import { ReadableStream } from 'stream/web';
|
|
5
6
|
|
|
6
|
-
// src/server/handlers/
|
|
7
|
-
var
|
|
8
|
-
__export(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
7
|
+
// src/server/handlers/legacyWorkflows.ts
|
|
8
|
+
var legacyWorkflows_exports = {};
|
|
9
|
+
__export(legacyWorkflows_exports, {
|
|
10
|
+
createLegacyWorkflowRunHandler: () => createLegacyWorkflowRunHandler,
|
|
11
|
+
getLegacyWorkflowByIdHandler: () => getLegacyWorkflowByIdHandler,
|
|
12
|
+
getLegacyWorkflowRunHandler: () => getLegacyWorkflowRunHandler,
|
|
13
|
+
getLegacyWorkflowRunsHandler: () => getLegacyWorkflowRunsHandler,
|
|
14
|
+
getLegacyWorkflowsHandler: () => getLegacyWorkflowsHandler,
|
|
15
|
+
resumeAsyncLegacyWorkflowHandler: () => resumeAsyncLegacyWorkflowHandler,
|
|
16
|
+
resumeLegacyWorkflowHandler: () => resumeLegacyWorkflowHandler,
|
|
17
|
+
startAsyncLegacyWorkflowHandler: () => startAsyncLegacyWorkflowHandler,
|
|
18
|
+
startLegacyWorkflowRunHandler: () => startLegacyWorkflowRunHandler,
|
|
19
|
+
watchLegacyWorkflowHandler: () => watchLegacyWorkflowHandler
|
|
19
20
|
});
|
|
20
|
-
async function
|
|
21
|
+
async function getLegacyWorkflowsHandler({ mastra }) {
|
|
21
22
|
try {
|
|
22
|
-
const workflows = mastra.
|
|
23
|
+
const workflows = mastra.legacy_getWorkflows({ serialized: false });
|
|
23
24
|
const _workflows = Object.entries(workflows).reduce((acc, [key, workflow]) => {
|
|
24
25
|
if (workflow.isNested) return acc;
|
|
25
26
|
acc[key] = {
|
|
@@ -32,7 +33,9 @@ async function getWorkflowsHandler({ mastra }) {
|
|
|
32
33
|
steps: Object.entries(workflow.steps).reduce((acc2, [key2, step]) => {
|
|
33
34
|
const _step = step;
|
|
34
35
|
acc2[key2] = {
|
|
35
|
-
|
|
36
|
+
id: _step.id,
|
|
37
|
+
description: _step.description,
|
|
38
|
+
workflowId: _step.workflowId,
|
|
36
39
|
inputSchema: _step.inputSchema ? stringify(esm_default(_step.inputSchema)) : void 0,
|
|
37
40
|
outputSchema: _step.outputSchema ? stringify(esm_default(_step.outputSchema)) : void 0
|
|
38
41
|
};
|
|
@@ -43,15 +46,15 @@ async function getWorkflowsHandler({ mastra }) {
|
|
|
43
46
|
}, {});
|
|
44
47
|
return _workflows;
|
|
45
48
|
} catch (error) {
|
|
46
|
-
|
|
49
|
+
return handleError(error, "error getting workflows");
|
|
47
50
|
}
|
|
48
51
|
}
|
|
49
|
-
async function
|
|
52
|
+
async function getLegacyWorkflowByIdHandler({ mastra, workflowId }) {
|
|
50
53
|
try {
|
|
51
54
|
if (!workflowId) {
|
|
52
55
|
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
53
56
|
}
|
|
54
|
-
const workflow = mastra.
|
|
57
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
55
58
|
if (!workflow) {
|
|
56
59
|
throw new HTTPException(404, { message: "Workflow not found" });
|
|
57
60
|
}
|
|
@@ -65,7 +68,9 @@ async function getWorkflowByIdHandler({ mastra, workflowId }) {
|
|
|
65
68
|
steps: Object.entries(workflow.steps).reduce((acc, [key, step]) => {
|
|
66
69
|
const _step = step;
|
|
67
70
|
acc[key] = {
|
|
68
|
-
|
|
71
|
+
id: _step.id,
|
|
72
|
+
description: _step.description,
|
|
73
|
+
workflowId: _step.workflowId,
|
|
69
74
|
inputSchema: _step.inputSchema ? stringify(esm_default(_step.inputSchema)) : void 0,
|
|
70
75
|
outputSchema: _step.outputSchema ? stringify(esm_default(_step.outputSchema)) : void 0
|
|
71
76
|
};
|
|
@@ -73,12 +78,12 @@ async function getWorkflowByIdHandler({ mastra, workflowId }) {
|
|
|
73
78
|
}, {})
|
|
74
79
|
};
|
|
75
80
|
} catch (error) {
|
|
76
|
-
|
|
81
|
+
return handleError(error, "error getting workflow by id");
|
|
77
82
|
}
|
|
78
83
|
}
|
|
79
|
-
async function
|
|
84
|
+
async function startAsyncLegacyWorkflowHandler({
|
|
80
85
|
mastra,
|
|
81
|
-
|
|
86
|
+
runtimeContext,
|
|
82
87
|
workflowId,
|
|
83
88
|
runId,
|
|
84
89
|
triggerData
|
|
@@ -87,32 +92,32 @@ async function startAsyncWorkflowHandler({
|
|
|
87
92
|
if (!workflowId) {
|
|
88
93
|
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
89
94
|
}
|
|
90
|
-
const workflow = mastra.
|
|
95
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
91
96
|
if (!workflow) {
|
|
92
97
|
throw new HTTPException(404, { message: "Workflow not found" });
|
|
93
98
|
}
|
|
94
99
|
if (!runId) {
|
|
95
|
-
const
|
|
96
|
-
const result2 = await start({
|
|
100
|
+
const newRun = workflow.createRun();
|
|
101
|
+
const result2 = await newRun.start({
|
|
97
102
|
triggerData,
|
|
98
|
-
|
|
103
|
+
runtimeContext
|
|
99
104
|
});
|
|
100
105
|
return result2;
|
|
101
106
|
}
|
|
102
|
-
const run = workflow.
|
|
107
|
+
const run = workflow.getMemoryRun(runId);
|
|
103
108
|
if (!run) {
|
|
104
109
|
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
105
110
|
}
|
|
106
111
|
const result = await run.start({
|
|
107
112
|
triggerData,
|
|
108
|
-
|
|
113
|
+
runtimeContext
|
|
109
114
|
});
|
|
110
115
|
return result;
|
|
111
116
|
} catch (error) {
|
|
112
|
-
|
|
117
|
+
return handleError(error, "error starting workflow");
|
|
113
118
|
}
|
|
114
119
|
}
|
|
115
|
-
async function
|
|
120
|
+
async function getLegacyWorkflowRunHandler({
|
|
116
121
|
mastra,
|
|
117
122
|
workflowId,
|
|
118
123
|
runId
|
|
@@ -124,20 +129,20 @@ async function getWorkflowRunHandler({
|
|
|
124
129
|
if (!runId) {
|
|
125
130
|
throw new HTTPException(400, { message: "Run ID is required" });
|
|
126
131
|
}
|
|
127
|
-
const workflow = mastra.
|
|
132
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
128
133
|
if (!workflow) {
|
|
129
134
|
throw new HTTPException(404, { message: "Workflow not found" });
|
|
130
135
|
}
|
|
131
|
-
const run = workflow.getRun(runId);
|
|
136
|
+
const run = await workflow.getRun(runId);
|
|
132
137
|
if (!run) {
|
|
133
138
|
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
134
139
|
}
|
|
135
140
|
return run;
|
|
136
141
|
} catch (error) {
|
|
137
|
-
|
|
142
|
+
return handleError(error, "error getting workflow run");
|
|
138
143
|
}
|
|
139
144
|
}
|
|
140
|
-
async function
|
|
145
|
+
async function createLegacyWorkflowRunHandler({
|
|
141
146
|
mastra,
|
|
142
147
|
workflowId,
|
|
143
148
|
runId: prevRunId
|
|
@@ -146,19 +151,19 @@ async function createRunHandler({
|
|
|
146
151
|
if (!workflowId) {
|
|
147
152
|
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
148
153
|
}
|
|
149
|
-
const workflow = mastra.
|
|
154
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
150
155
|
if (!workflow) {
|
|
151
156
|
throw new HTTPException(404, { message: "Workflow not found" });
|
|
152
157
|
}
|
|
153
|
-
const
|
|
154
|
-
return { runId };
|
|
158
|
+
const newRun = workflow.createRun({ runId: prevRunId });
|
|
159
|
+
return { runId: newRun.runId };
|
|
155
160
|
} catch (error) {
|
|
156
|
-
|
|
161
|
+
return handleError(error, "error creating workflow run");
|
|
157
162
|
}
|
|
158
163
|
}
|
|
159
|
-
async function
|
|
164
|
+
async function startLegacyWorkflowRunHandler({
|
|
160
165
|
mastra,
|
|
161
|
-
|
|
166
|
+
runtimeContext,
|
|
162
167
|
workflowId,
|
|
163
168
|
runId,
|
|
164
169
|
triggerData
|
|
@@ -170,21 +175,21 @@ async function startWorkflowRunHandler({
|
|
|
170
175
|
if (!runId) {
|
|
171
176
|
throw new HTTPException(400, { message: "runId required to start run" });
|
|
172
177
|
}
|
|
173
|
-
const workflow = mastra.
|
|
174
|
-
const run = workflow.
|
|
178
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
179
|
+
const run = workflow.getMemoryRun(runId);
|
|
175
180
|
if (!run) {
|
|
176
181
|
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
177
182
|
}
|
|
178
|
-
|
|
183
|
+
void run.start({
|
|
179
184
|
triggerData,
|
|
180
|
-
|
|
185
|
+
runtimeContext
|
|
181
186
|
});
|
|
182
187
|
return { message: "Workflow run started" };
|
|
183
188
|
} catch (e) {
|
|
184
189
|
return handleError(e, "Error starting workflow run");
|
|
185
190
|
}
|
|
186
191
|
}
|
|
187
|
-
async function
|
|
192
|
+
async function watchLegacyWorkflowHandler({
|
|
188
193
|
mastra,
|
|
189
194
|
workflowId,
|
|
190
195
|
runId
|
|
@@ -196,8 +201,8 @@ async function watchWorkflowHandler({
|
|
|
196
201
|
if (!runId) {
|
|
197
202
|
throw new HTTPException(400, { message: "runId required to watch workflow" });
|
|
198
203
|
}
|
|
199
|
-
const workflow = mastra.
|
|
200
|
-
const run = workflow.
|
|
204
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
205
|
+
const run = workflow.getMemoryRun(runId);
|
|
201
206
|
if (!run) {
|
|
202
207
|
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
203
208
|
}
|
|
@@ -213,8 +218,10 @@ async function watchWorkflowHandler({
|
|
|
213
218
|
asyncRef = null;
|
|
214
219
|
}
|
|
215
220
|
asyncRef = setImmediate(() => {
|
|
216
|
-
|
|
221
|
+
const runDone = Object.values(activePathsObj).every((value) => value.status !== "executing");
|
|
222
|
+
if (runDone) {
|
|
217
223
|
controller.close();
|
|
224
|
+
unwatch?.();
|
|
218
225
|
}
|
|
219
226
|
});
|
|
220
227
|
});
|
|
@@ -228,12 +235,12 @@ async function watchWorkflowHandler({
|
|
|
228
235
|
return handleError(error, "Error watching workflow");
|
|
229
236
|
}
|
|
230
237
|
}
|
|
231
|
-
async function
|
|
238
|
+
async function resumeAsyncLegacyWorkflowHandler({
|
|
232
239
|
mastra,
|
|
233
240
|
workflowId,
|
|
234
241
|
runId,
|
|
235
242
|
body,
|
|
236
|
-
|
|
243
|
+
runtimeContext
|
|
237
244
|
}) {
|
|
238
245
|
try {
|
|
239
246
|
if (!workflowId) {
|
|
@@ -242,27 +249,27 @@ async function resumeAsyncWorkflowHandler({
|
|
|
242
249
|
if (!runId) {
|
|
243
250
|
throw new HTTPException(400, { message: "runId required to resume workflow" });
|
|
244
251
|
}
|
|
245
|
-
const workflow = mastra.
|
|
246
|
-
const run = workflow.
|
|
252
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
253
|
+
const run = workflow.getMemoryRun(runId);
|
|
247
254
|
if (!run) {
|
|
248
255
|
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
249
256
|
}
|
|
250
257
|
const result = await run.resume({
|
|
251
258
|
stepId: body.stepId,
|
|
252
259
|
context: body.context,
|
|
253
|
-
|
|
260
|
+
runtimeContext
|
|
254
261
|
});
|
|
255
262
|
return result;
|
|
256
263
|
} catch (error) {
|
|
257
264
|
return handleError(error, "Error resuming workflow step");
|
|
258
265
|
}
|
|
259
266
|
}
|
|
260
|
-
async function
|
|
267
|
+
async function resumeLegacyWorkflowHandler({
|
|
261
268
|
mastra,
|
|
262
269
|
workflowId,
|
|
263
270
|
runId,
|
|
264
271
|
body,
|
|
265
|
-
|
|
272
|
+
runtimeContext
|
|
266
273
|
}) {
|
|
267
274
|
try {
|
|
268
275
|
if (!workflowId) {
|
|
@@ -271,28 +278,36 @@ async function resumeWorkflowHandler({
|
|
|
271
278
|
if (!runId) {
|
|
272
279
|
throw new HTTPException(400, { message: "runId required to resume workflow" });
|
|
273
280
|
}
|
|
274
|
-
const workflow = mastra.
|
|
275
|
-
const run = workflow.
|
|
281
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
282
|
+
const run = workflow.getMemoryRun(runId);
|
|
276
283
|
if (!run) {
|
|
277
284
|
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
278
285
|
}
|
|
279
|
-
|
|
286
|
+
void run.resume({
|
|
280
287
|
stepId: body.stepId,
|
|
281
288
|
context: body.context,
|
|
282
|
-
|
|
289
|
+
runtimeContext
|
|
283
290
|
});
|
|
284
291
|
return { message: "Workflow run resumed" };
|
|
285
292
|
} catch (error) {
|
|
286
293
|
return handleError(error, "Error resuming workflow");
|
|
287
294
|
}
|
|
288
295
|
}
|
|
289
|
-
async function
|
|
296
|
+
async function getLegacyWorkflowRunsHandler({
|
|
297
|
+
mastra,
|
|
298
|
+
workflowId,
|
|
299
|
+
fromDate,
|
|
300
|
+
toDate,
|
|
301
|
+
limit,
|
|
302
|
+
offset,
|
|
303
|
+
resourceId
|
|
304
|
+
}) {
|
|
290
305
|
try {
|
|
291
306
|
if (!workflowId) {
|
|
292
307
|
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
293
308
|
}
|
|
294
|
-
const workflow = mastra.
|
|
295
|
-
const workflowRuns = await workflow.getWorkflowRuns() || {
|
|
309
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
310
|
+
const workflowRuns = await workflow.getWorkflowRuns({ fromDate, toDate, limit, offset, resourceId }) || {
|
|
296
311
|
runs: [],
|
|
297
312
|
total: 0
|
|
298
313
|
};
|
|
@@ -302,4 +317,4 @@ async function getWorkflowRunsHandler({ mastra, workflowId }) {
|
|
|
302
317
|
}
|
|
303
318
|
}
|
|
304
319
|
|
|
305
|
-
export {
|
|
320
|
+
export { createLegacyWorkflowRunHandler, getLegacyWorkflowByIdHandler, getLegacyWorkflowRunHandler, getLegacyWorkflowRunsHandler, getLegacyWorkflowsHandler, legacyWorkflows_exports, resumeAsyncLegacyWorkflowHandler, resumeLegacyWorkflowHandler, startAsyncLegacyWorkflowHandler, startLegacyWorkflowRunHandler, watchLegacyWorkflowHandler };
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunkPZQDCRPV_cjs = require('./chunk-PZQDCRPV.cjs');
|
|
4
|
+
var chunk2KZFMI6P_cjs = require('./chunk-2KZFMI6P.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 chunk2KZFMI6P_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 chunk2KZFMI6P_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 chunk2KZFMI6P_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 chunkPZQDCRPV_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 chunk2KZFMI6P_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 chunk2KZFMI6P_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 chunkPZQDCRPV_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 chunk2KZFMI6P_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 chunkPZQDCRPV_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 chunkPZQDCRPV_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 chunk2KZFMI6P_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 chunkPZQDCRPV_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 chunk2KZFMI6P_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 chunkPZQDCRPV_cjs.handleError(error, "Error deleting index");
|
|
119
120
|
}
|
|
120
121
|
}
|
|
121
122
|
|