@mastra/server 0.10.13 → 0.10.15-alpha.0
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 +1107 -0
- package/dist/_tsup-dts-rollup.d.ts +1107 -0
- package/dist/chunk-2KZFMI6P.cjs +37 -0
- package/dist/chunk-2SLFAFTR.cjs +148 -0
- package/dist/chunk-3CNDE7QY.cjs +308 -0
- package/dist/chunk-4D66QEKC.js +81 -0
- package/dist/chunk-5PQQ42EZ.js +320 -0
- package/dist/chunk-75ZPJI57.cjs +9 -0
- package/dist/chunk-7TP2LX5L.cjs +129 -0
- package/dist/chunk-B2PAS2IB.cjs +514 -0
- package/dist/chunk-BK4XT6EG.js +270 -0
- package/dist/chunk-CCGRCYWJ.cjs +18 -0
- package/dist/chunk-CRCR3ZUK.js +142 -0
- package/dist/chunk-FRVBFMO2.cjs +128 -0
- package/dist/chunk-G7KH752Y.cjs +145 -0
- package/dist/chunk-GHC4YV6R.js +504 -0
- package/dist/chunk-H7DMHBKY.js +498 -0
- package/dist/chunk-JMLYCXMK.cjs +332 -0
- package/dist/chunk-KHZKYUNR.js +112 -0
- package/dist/chunk-KOHWJYJT.js +296 -0
- package/dist/chunk-LCM566I4.js +35 -0
- package/dist/chunk-LF7P5PLR.js +14 -0
- package/dist/chunk-LI436ITD.cjs +2042 -0
- package/dist/chunk-LRCAAFUA.js +122 -0
- 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-RG473F6Y.js +141 -0
- package/dist/chunk-RHSWAXKB.cjs +118 -0
- package/dist/chunk-RSEO4XPX.js +16 -0
- package/dist/chunk-SDPGVWQJ.cjs +512 -0
- package/dist/chunk-WNVFNNWN.js +121 -0
- package/dist/index.cjs +2 -0
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -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 +30 -0
- package/dist/server/handlers/agents.d.cts +6 -0
- package/dist/server/handlers/agents.d.ts +6 -0
- package/dist/server/handlers/agents.js +1 -0
- package/dist/server/handlers/error.cjs +10 -0
- package/dist/server/handlers/error.d.cts +1 -0
- package/dist/server/handlers/error.d.ts +1 -0
- package/dist/server/handlers/error.js +1 -0
- 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 +18 -0
- package/dist/server/handlers/logs.d.cts +3 -0
- package/dist/server/handlers/logs.d.ts +3 -0
- package/dist/server/handlers/logs.js +1 -0
- package/dist/server/handlers/memory.cjs +46 -0
- package/dist/server/handlers/memory.d.cts +10 -0
- package/dist/server/handlers/memory.d.ts +10 -0
- package/dist/server/handlers/memory.js +1 -0
- package/dist/server/handlers/network.cjs +22 -0
- package/dist/server/handlers/network.d.cts +4 -0
- package/dist/server/handlers/network.d.ts +4 -0
- package/dist/server/handlers/network.js +1 -0
- package/dist/server/handlers/telemetry.cjs +14 -0
- package/dist/server/handlers/telemetry.d.cts +2 -0
- package/dist/server/handlers/telemetry.d.ts +2 -0
- package/dist/server/handlers/telemetry.js +1 -0
- package/dist/server/handlers/tools.cjs +22 -0
- package/dist/server/handlers/tools.d.cts +4 -0
- package/dist/server/handlers/tools.d.ts +4 -0
- package/dist/server/handlers/tools.js +1 -0
- package/dist/server/handlers/utils.cjs +10 -0
- package/dist/server/handlers/utils.d.cts +1 -0
- package/dist/server/handlers/utils.d.ts +1 -0
- package/dist/server/handlers/utils.js +1 -0
- 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 +30 -0
- package/dist/server/handlers/vector.d.cts +6 -0
- package/dist/server/handlers/vector.d.ts +6 -0
- package/dist/server/handlers/vector.js +1 -0
- package/dist/server/handlers/voice.cjs +22 -0
- package/dist/server/handlers/voice.d.cts +4 -0
- package/dist/server/handlers/voice.d.ts +4 -0
- package/dist/server/handlers/voice.js +1 -0
- package/dist/server/handlers/workflows.cjs +62 -0
- package/dist/server/handlers/workflows.d.cts +14 -0
- package/dist/server/handlers/workflows.d.ts +14 -0
- package/dist/server/handlers/workflows.js +1 -0
- package/dist/server/handlers.cjs +60 -0
- package/dist/server/handlers.d.cts +11 -0
- package/dist/server/handlers.d.ts +11 -0
- package/dist/server/handlers.js +11 -0
- package/package.json +3 -3
|
@@ -0,0 +1,320 @@
|
|
|
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';
|
|
6
|
+
|
|
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
|
|
20
|
+
});
|
|
21
|
+
async function getLegacyWorkflowsHandler({ mastra }) {
|
|
22
|
+
try {
|
|
23
|
+
const workflows = mastra.legacy_getWorkflows({ serialized: false });
|
|
24
|
+
const _workflows = Object.entries(workflows).reduce((acc, [key, workflow]) => {
|
|
25
|
+
if (workflow.isNested) return acc;
|
|
26
|
+
acc[key] = {
|
|
27
|
+
stepGraph: workflow.stepGraph,
|
|
28
|
+
stepSubscriberGraph: workflow.stepSubscriberGraph,
|
|
29
|
+
serializedStepGraph: workflow.serializedStepGraph,
|
|
30
|
+
serializedStepSubscriberGraph: workflow.serializedStepSubscriberGraph,
|
|
31
|
+
name: workflow.name,
|
|
32
|
+
triggerSchema: workflow.triggerSchema ? stringify(esm_default(workflow.triggerSchema)) : void 0,
|
|
33
|
+
steps: Object.entries(workflow.steps).reduce((acc2, [key2, step]) => {
|
|
34
|
+
const _step = step;
|
|
35
|
+
acc2[key2] = {
|
|
36
|
+
id: _step.id,
|
|
37
|
+
description: _step.description,
|
|
38
|
+
workflowId: _step.workflowId,
|
|
39
|
+
inputSchema: _step.inputSchema ? stringify(esm_default(_step.inputSchema)) : void 0,
|
|
40
|
+
outputSchema: _step.outputSchema ? stringify(esm_default(_step.outputSchema)) : void 0
|
|
41
|
+
};
|
|
42
|
+
return acc2;
|
|
43
|
+
}, {})
|
|
44
|
+
};
|
|
45
|
+
return acc;
|
|
46
|
+
}, {});
|
|
47
|
+
return _workflows;
|
|
48
|
+
} catch (error) {
|
|
49
|
+
return handleError(error, "error getting workflows");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async function getLegacyWorkflowByIdHandler({ mastra, workflowId }) {
|
|
53
|
+
try {
|
|
54
|
+
if (!workflowId) {
|
|
55
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
56
|
+
}
|
|
57
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
58
|
+
if (!workflow) {
|
|
59
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
stepGraph: workflow.stepGraph,
|
|
63
|
+
stepSubscriberGraph: workflow.stepSubscriberGraph,
|
|
64
|
+
serializedStepGraph: workflow.serializedStepGraph,
|
|
65
|
+
serializedStepSubscriberGraph: workflow.serializedStepSubscriberGraph,
|
|
66
|
+
name: workflow.name,
|
|
67
|
+
triggerSchema: workflow.triggerSchema ? stringify(esm_default(workflow.triggerSchema)) : void 0,
|
|
68
|
+
steps: Object.entries(workflow.steps).reduce((acc, [key, step]) => {
|
|
69
|
+
const _step = step;
|
|
70
|
+
acc[key] = {
|
|
71
|
+
id: _step.id,
|
|
72
|
+
description: _step.description,
|
|
73
|
+
workflowId: _step.workflowId,
|
|
74
|
+
inputSchema: _step.inputSchema ? stringify(esm_default(_step.inputSchema)) : void 0,
|
|
75
|
+
outputSchema: _step.outputSchema ? stringify(esm_default(_step.outputSchema)) : void 0
|
|
76
|
+
};
|
|
77
|
+
return acc;
|
|
78
|
+
}, {})
|
|
79
|
+
};
|
|
80
|
+
} catch (error) {
|
|
81
|
+
return handleError(error, "error getting workflow by id");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async function startAsyncLegacyWorkflowHandler({
|
|
85
|
+
mastra,
|
|
86
|
+
runtimeContext,
|
|
87
|
+
workflowId,
|
|
88
|
+
runId,
|
|
89
|
+
triggerData
|
|
90
|
+
}) {
|
|
91
|
+
try {
|
|
92
|
+
if (!workflowId) {
|
|
93
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
94
|
+
}
|
|
95
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
96
|
+
if (!workflow) {
|
|
97
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
98
|
+
}
|
|
99
|
+
if (!runId) {
|
|
100
|
+
const newRun = workflow.createRun();
|
|
101
|
+
const result2 = await newRun.start({
|
|
102
|
+
triggerData,
|
|
103
|
+
runtimeContext
|
|
104
|
+
});
|
|
105
|
+
return result2;
|
|
106
|
+
}
|
|
107
|
+
const run = workflow.getMemoryRun(runId);
|
|
108
|
+
if (!run) {
|
|
109
|
+
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
110
|
+
}
|
|
111
|
+
const result = await run.start({
|
|
112
|
+
triggerData,
|
|
113
|
+
runtimeContext
|
|
114
|
+
});
|
|
115
|
+
return result;
|
|
116
|
+
} catch (error) {
|
|
117
|
+
return handleError(error, "error starting workflow");
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
async function getLegacyWorkflowRunHandler({
|
|
121
|
+
mastra,
|
|
122
|
+
workflowId,
|
|
123
|
+
runId
|
|
124
|
+
}) {
|
|
125
|
+
try {
|
|
126
|
+
if (!workflowId) {
|
|
127
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
128
|
+
}
|
|
129
|
+
if (!runId) {
|
|
130
|
+
throw new HTTPException(400, { message: "Run ID is required" });
|
|
131
|
+
}
|
|
132
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
133
|
+
if (!workflow) {
|
|
134
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
135
|
+
}
|
|
136
|
+
const run = await workflow.getRun(runId);
|
|
137
|
+
if (!run) {
|
|
138
|
+
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
139
|
+
}
|
|
140
|
+
return run;
|
|
141
|
+
} catch (error) {
|
|
142
|
+
return handleError(error, "error getting workflow run");
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
async function createLegacyWorkflowRunHandler({
|
|
146
|
+
mastra,
|
|
147
|
+
workflowId,
|
|
148
|
+
runId: prevRunId
|
|
149
|
+
}) {
|
|
150
|
+
try {
|
|
151
|
+
if (!workflowId) {
|
|
152
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
153
|
+
}
|
|
154
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
155
|
+
if (!workflow) {
|
|
156
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
157
|
+
}
|
|
158
|
+
const newRun = workflow.createRun({ runId: prevRunId });
|
|
159
|
+
return { runId: newRun.runId };
|
|
160
|
+
} catch (error) {
|
|
161
|
+
return handleError(error, "error creating workflow run");
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
async function startLegacyWorkflowRunHandler({
|
|
165
|
+
mastra,
|
|
166
|
+
runtimeContext,
|
|
167
|
+
workflowId,
|
|
168
|
+
runId,
|
|
169
|
+
triggerData
|
|
170
|
+
}) {
|
|
171
|
+
try {
|
|
172
|
+
if (!workflowId) {
|
|
173
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
174
|
+
}
|
|
175
|
+
if (!runId) {
|
|
176
|
+
throw new HTTPException(400, { message: "runId required to start run" });
|
|
177
|
+
}
|
|
178
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
179
|
+
const run = workflow.getMemoryRun(runId);
|
|
180
|
+
if (!run) {
|
|
181
|
+
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
182
|
+
}
|
|
183
|
+
void run.start({
|
|
184
|
+
triggerData,
|
|
185
|
+
runtimeContext
|
|
186
|
+
});
|
|
187
|
+
return { message: "Workflow run started" };
|
|
188
|
+
} catch (e) {
|
|
189
|
+
return handleError(e, "Error starting workflow run");
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
async function watchLegacyWorkflowHandler({
|
|
193
|
+
mastra,
|
|
194
|
+
workflowId,
|
|
195
|
+
runId
|
|
196
|
+
}) {
|
|
197
|
+
try {
|
|
198
|
+
if (!workflowId) {
|
|
199
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
200
|
+
}
|
|
201
|
+
if (!runId) {
|
|
202
|
+
throw new HTTPException(400, { message: "runId required to watch workflow" });
|
|
203
|
+
}
|
|
204
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
205
|
+
const run = workflow.getMemoryRun(runId);
|
|
206
|
+
if (!run) {
|
|
207
|
+
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
208
|
+
}
|
|
209
|
+
let unwatch;
|
|
210
|
+
let asyncRef = null;
|
|
211
|
+
const stream = new ReadableStream({
|
|
212
|
+
start(controller) {
|
|
213
|
+
unwatch = run.watch(({ activePaths, runId: runId2, timestamp, results }) => {
|
|
214
|
+
const activePathsObj = Object.fromEntries(activePaths);
|
|
215
|
+
controller.enqueue(JSON.stringify({ activePaths: activePathsObj, runId: runId2, timestamp, results }));
|
|
216
|
+
if (asyncRef) {
|
|
217
|
+
clearImmediate(asyncRef);
|
|
218
|
+
asyncRef = null;
|
|
219
|
+
}
|
|
220
|
+
asyncRef = setImmediate(() => {
|
|
221
|
+
const runDone = Object.values(activePathsObj).every((value) => value.status !== "executing");
|
|
222
|
+
if (runDone) {
|
|
223
|
+
controller.close();
|
|
224
|
+
unwatch?.();
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
},
|
|
229
|
+
cancel() {
|
|
230
|
+
unwatch?.();
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
return stream;
|
|
234
|
+
} catch (error) {
|
|
235
|
+
return handleError(error, "Error watching workflow");
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
async function resumeAsyncLegacyWorkflowHandler({
|
|
239
|
+
mastra,
|
|
240
|
+
workflowId,
|
|
241
|
+
runId,
|
|
242
|
+
body,
|
|
243
|
+
runtimeContext
|
|
244
|
+
}) {
|
|
245
|
+
try {
|
|
246
|
+
if (!workflowId) {
|
|
247
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
248
|
+
}
|
|
249
|
+
if (!runId) {
|
|
250
|
+
throw new HTTPException(400, { message: "runId required to resume workflow" });
|
|
251
|
+
}
|
|
252
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
253
|
+
const run = workflow.getMemoryRun(runId);
|
|
254
|
+
if (!run) {
|
|
255
|
+
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
256
|
+
}
|
|
257
|
+
const result = await run.resume({
|
|
258
|
+
stepId: body.stepId,
|
|
259
|
+
context: body.context,
|
|
260
|
+
runtimeContext
|
|
261
|
+
});
|
|
262
|
+
return result;
|
|
263
|
+
} catch (error) {
|
|
264
|
+
return handleError(error, "Error resuming workflow step");
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
async function resumeLegacyWorkflowHandler({
|
|
268
|
+
mastra,
|
|
269
|
+
workflowId,
|
|
270
|
+
runId,
|
|
271
|
+
body,
|
|
272
|
+
runtimeContext
|
|
273
|
+
}) {
|
|
274
|
+
try {
|
|
275
|
+
if (!workflowId) {
|
|
276
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
277
|
+
}
|
|
278
|
+
if (!runId) {
|
|
279
|
+
throw new HTTPException(400, { message: "runId required to resume workflow" });
|
|
280
|
+
}
|
|
281
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
282
|
+
const run = workflow.getMemoryRun(runId);
|
|
283
|
+
if (!run) {
|
|
284
|
+
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
285
|
+
}
|
|
286
|
+
void run.resume({
|
|
287
|
+
stepId: body.stepId,
|
|
288
|
+
context: body.context,
|
|
289
|
+
runtimeContext
|
|
290
|
+
});
|
|
291
|
+
return { message: "Workflow run resumed" };
|
|
292
|
+
} catch (error) {
|
|
293
|
+
return handleError(error, "Error resuming workflow");
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
async function getLegacyWorkflowRunsHandler({
|
|
297
|
+
mastra,
|
|
298
|
+
workflowId,
|
|
299
|
+
fromDate,
|
|
300
|
+
toDate,
|
|
301
|
+
limit,
|
|
302
|
+
offset,
|
|
303
|
+
resourceId
|
|
304
|
+
}) {
|
|
305
|
+
try {
|
|
306
|
+
if (!workflowId) {
|
|
307
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
308
|
+
}
|
|
309
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
310
|
+
const workflowRuns = await workflow.getWorkflowRuns({ fromDate, toDate, limit, offset, resourceId }) || {
|
|
311
|
+
runs: [],
|
|
312
|
+
total: 0
|
|
313
|
+
};
|
|
314
|
+
return workflowRuns;
|
|
315
|
+
} catch (error) {
|
|
316
|
+
return handleError(error, "Error getting workflow runs");
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
export { createLegacyWorkflowRunHandler, getLegacyWorkflowByIdHandler, getLegacyWorkflowRunHandler, getLegacyWorkflowRunsHandler, getLegacyWorkflowsHandler, legacyWorkflows_exports, resumeAsyncLegacyWorkflowHandler, resumeLegacyWorkflowHandler, startAsyncLegacyWorkflowHandler, startLegacyWorkflowRunHandler, watchLegacyWorkflowHandler };
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkPZQDCRPV_cjs = require('./chunk-PZQDCRPV.cjs');
|
|
4
|
+
var chunk2KZFMI6P_cjs = require('./chunk-2KZFMI6P.cjs');
|
|
5
|
+
var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
|
|
6
|
+
|
|
7
|
+
// src/server/handlers/vector.ts
|
|
8
|
+
var vector_exports = {};
|
|
9
|
+
chunk75ZPJI57_cjs.__export(vector_exports, {
|
|
10
|
+
createIndex: () => createIndex,
|
|
11
|
+
deleteIndex: () => deleteIndex,
|
|
12
|
+
describeIndex: () => describeIndex,
|
|
13
|
+
listIndexes: () => listIndexes,
|
|
14
|
+
queryVectors: () => queryVectors,
|
|
15
|
+
upsertVectors: () => upsertVectors
|
|
16
|
+
});
|
|
17
|
+
function getVector(mastra, vectorName) {
|
|
18
|
+
if (!vectorName) {
|
|
19
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Vector name is required" });
|
|
20
|
+
}
|
|
21
|
+
const vector = mastra.getVector(vectorName);
|
|
22
|
+
if (!vector) {
|
|
23
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: `Vector store ${vectorName} not found` });
|
|
24
|
+
}
|
|
25
|
+
return vector;
|
|
26
|
+
}
|
|
27
|
+
async function upsertVectors({ mastra, vectorName, index }) {
|
|
28
|
+
try {
|
|
29
|
+
if (!index?.indexName || !index?.vectors || !Array.isArray(index.vectors)) {
|
|
30
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Invalid request index. indexName and vectors array are required." });
|
|
31
|
+
}
|
|
32
|
+
const vector = getVector(mastra, vectorName);
|
|
33
|
+
const result = await vector.upsert(index);
|
|
34
|
+
return { ids: result };
|
|
35
|
+
} catch (error) {
|
|
36
|
+
return chunkPZQDCRPV_cjs.handleError(error, "Error upserting vectors");
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async function createIndex({
|
|
40
|
+
mastra,
|
|
41
|
+
vectorName,
|
|
42
|
+
index
|
|
43
|
+
}) {
|
|
44
|
+
try {
|
|
45
|
+
const { indexName, dimension, metric } = index;
|
|
46
|
+
if (!indexName || typeof dimension !== "number" || dimension <= 0) {
|
|
47
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, {
|
|
48
|
+
message: "Invalid request index, indexName and positive dimension number are required."
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (metric && !["cosine", "euclidean", "dotproduct"].includes(metric)) {
|
|
52
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Invalid metric. Must be one of: cosine, euclidean, dotproduct" });
|
|
53
|
+
}
|
|
54
|
+
const vector = getVector(mastra, vectorName);
|
|
55
|
+
await vector.createIndex({ indexName, dimension, metric });
|
|
56
|
+
return { success: true };
|
|
57
|
+
} catch (error) {
|
|
58
|
+
return chunkPZQDCRPV_cjs.handleError(error, "Error creating index");
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
async function queryVectors({
|
|
62
|
+
mastra,
|
|
63
|
+
vectorName,
|
|
64
|
+
query
|
|
65
|
+
}) {
|
|
66
|
+
try {
|
|
67
|
+
if (!query?.indexName || !query?.queryVector || !Array.isArray(query.queryVector)) {
|
|
68
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Invalid request query. indexName and queryVector array are required." });
|
|
69
|
+
}
|
|
70
|
+
const vector = getVector(mastra, vectorName);
|
|
71
|
+
const results = await vector.query(query);
|
|
72
|
+
return results;
|
|
73
|
+
} catch (error) {
|
|
74
|
+
return chunkPZQDCRPV_cjs.handleError(error, "Error querying vectors");
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
async function listIndexes({ mastra, vectorName }) {
|
|
78
|
+
try {
|
|
79
|
+
const vector = getVector(mastra, vectorName);
|
|
80
|
+
const indexes = await vector.listIndexes();
|
|
81
|
+
return indexes.filter(Boolean);
|
|
82
|
+
} catch (error) {
|
|
83
|
+
return chunkPZQDCRPV_cjs.handleError(error, "Error listing indexes");
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async function describeIndex({
|
|
87
|
+
mastra,
|
|
88
|
+
vectorName,
|
|
89
|
+
indexName
|
|
90
|
+
}) {
|
|
91
|
+
try {
|
|
92
|
+
if (!indexName) {
|
|
93
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Index name is required" });
|
|
94
|
+
}
|
|
95
|
+
const vector = getVector(mastra, vectorName);
|
|
96
|
+
const stats = await vector.describeIndex({ indexName });
|
|
97
|
+
return {
|
|
98
|
+
dimension: stats.dimension,
|
|
99
|
+
count: stats.count,
|
|
100
|
+
metric: stats.metric?.toLowerCase()
|
|
101
|
+
};
|
|
102
|
+
} catch (error) {
|
|
103
|
+
return chunkPZQDCRPV_cjs.handleError(error, "Error describing index");
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
async function deleteIndex({
|
|
107
|
+
mastra,
|
|
108
|
+
vectorName,
|
|
109
|
+
indexName
|
|
110
|
+
}) {
|
|
111
|
+
try {
|
|
112
|
+
if (!indexName) {
|
|
113
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Index name is required" });
|
|
114
|
+
}
|
|
115
|
+
const vector = getVector(mastra, vectorName);
|
|
116
|
+
await vector.deleteIndex({ indexName });
|
|
117
|
+
return { success: true };
|
|
118
|
+
} catch (error) {
|
|
119
|
+
return chunkPZQDCRPV_cjs.handleError(error, "Error deleting index");
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
exports.createIndex = createIndex;
|
|
124
|
+
exports.deleteIndex = deleteIndex;
|
|
125
|
+
exports.describeIndex = describeIndex;
|
|
126
|
+
exports.listIndexes = listIndexes;
|
|
127
|
+
exports.queryVectors = queryVectors;
|
|
128
|
+
exports.upsertVectors = upsertVectors;
|
|
129
|
+
exports.vector_exports = vector_exports;
|