@mastra/server 0.0.0-trigger-playground-ui-package-20250506151043 → 0.0.0-vector-sources-20250516175436

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.
Files changed (70) hide show
  1. package/README.md +48 -135
  2. package/dist/_tsup-dts-rollup.d.cts +161 -13
  3. package/dist/_tsup-dts-rollup.d.ts +161 -13
  4. package/dist/{chunk-4JINXASC.js → chunk-55DOQLP6.js} +5 -4
  5. package/dist/{chunk-QN4KF3BH.cjs → chunk-57CJTIPW.cjs} +2 -2
  6. package/dist/chunk-5SN4U5AC.cjs +508 -0
  7. package/dist/{chunk-ZLBRQFDD.cjs → chunk-64U3UDTH.cjs} +2 -2
  8. package/dist/chunk-75ZPJI57.cjs +9 -0
  9. package/dist/{chunk-M56ECCHK.cjs → chunk-BNEY4P4P.cjs} +20 -19
  10. package/dist/{chunk-QJ3AHN64.js → chunk-C7564HUT.js} +4 -3
  11. package/dist/{chunk-4BIX6GMY.cjs → chunk-D4IRYCUI.cjs} +72 -26
  12. package/dist/{chunk-RBQASTUP.js → chunk-DJJIUEL2.js} +13 -5
  13. package/dist/{chunk-3XTEV33Q.js → chunk-EJO45KYT.js} +19 -16
  14. package/dist/{chunk-L7XE5QTW.js → chunk-H5PTF3Y4.js} +1 -1
  15. package/dist/{chunk-Q6SHQECN.js → chunk-HFWCEP5S.js} +4 -3
  16. package/dist/{chunk-3EJZQ6TQ.js → chunk-HWZVAG3H.js} +3 -3
  17. package/dist/{chunk-CHFORQ7J.cjs → chunk-I2B73Y4I.cjs} +60 -57
  18. package/dist/chunk-LIVAK2DM.js +2001 -0
  19. package/dist/{chunk-3AHQ5RGN.js → chunk-M5ABIP7D.js} +1 -1
  20. package/dist/{chunk-AMVOS7YB.cjs → chunk-MHKNLNAN.cjs} +9 -8
  21. package/dist/{chunk-OWNA6I2H.js → chunk-MIQYDLLM.js} +28 -11
  22. package/dist/chunk-MLKGABMK.js +7 -0
  23. package/dist/{chunk-TRDNDNGQ.js → chunk-NYN7KFXL.js} +1 -7
  24. package/dist/{chunk-FV45V6WC.cjs → chunk-OCWPVYNI.cjs} +0 -7
  25. package/dist/{chunk-SKBVVI24.cjs → chunk-OGCNNUHF.cjs} +9 -9
  26. package/dist/{chunk-BPL2CBLV.js → chunk-OR3CIE2H.js} +3 -2
  27. package/dist/chunk-P6SCPDYW.js +500 -0
  28. package/dist/{chunk-5JNVY6DU.js → chunk-TJKLBTFB.js} +20 -8
  29. package/dist/{chunk-M2RXDCPV.cjs → chunk-UCTEMO2Q.cjs} +76 -59
  30. package/dist/{chunk-5YGDYMRB.cjs → chunk-VPNDC2DI.cjs} +14 -13
  31. package/dist/{chunk-Y3SV5XK4.js → chunk-WUC6LSTW.js} +54 -8
  32. package/dist/{chunk-2FJURXCL.cjs → chunk-Y7UWRW5X.cjs} +43 -35
  33. package/dist/{chunk-55HTWX4C.cjs → chunk-YBVOQN4M.cjs} +20 -19
  34. package/dist/chunk-YWLUOY3D.cjs +2004 -0
  35. package/dist/{chunk-D3G23FP3.cjs → chunk-ZE5AAC4I.cjs} +37 -25
  36. package/dist/server/handlers/a2a.cjs +30 -0
  37. package/dist/server/handlers/a2a.d.cts +6 -0
  38. package/dist/server/handlers/a2a.d.ts +6 -0
  39. package/dist/server/handlers/a2a.js +1 -0
  40. package/dist/server/handlers/agents.cjs +7 -7
  41. package/dist/server/handlers/agents.js +1 -1
  42. package/dist/server/handlers/error.cjs +2 -2
  43. package/dist/server/handlers/error.js +1 -1
  44. package/dist/server/handlers/logs.cjs +4 -4
  45. package/dist/server/handlers/logs.js +1 -1
  46. package/dist/server/handlers/memory.cjs +9 -9
  47. package/dist/server/handlers/memory.js +1 -1
  48. package/dist/server/handlers/network.cjs +5 -5
  49. package/dist/server/handlers/network.js +1 -1
  50. package/dist/server/handlers/telemetry.cjs +3 -3
  51. package/dist/server/handlers/telemetry.js +1 -1
  52. package/dist/server/handlers/tools.cjs +5 -5
  53. package/dist/server/handlers/tools.js +1 -1
  54. package/dist/server/handlers/utils.cjs +2 -2
  55. package/dist/server/handlers/utils.js +1 -1
  56. package/dist/server/handlers/vNextWorkflows.cjs +11 -11
  57. package/dist/server/handlers/vNextWorkflows.js +1 -1
  58. package/dist/server/handlers/vector.cjs +7 -7
  59. package/dist/server/handlers/vector.js +1 -1
  60. package/dist/server/handlers/voice.cjs +4 -4
  61. package/dist/server/handlers/voice.js +1 -1
  62. package/dist/server/handlers/workflows.cjs +11 -11
  63. package/dist/server/handlers/workflows.js +1 -1
  64. package/dist/server/handlers.cjs +28 -23
  65. package/dist/server/handlers.d.cts +1 -0
  66. package/dist/server/handlers.d.ts +1 -0
  67. package/dist/server/handlers.js +11 -10
  68. package/package.json +7 -5
  69. package/dist/chunk-5SWCVTNL.cjs +0 -5579
  70. package/dist/chunk-OMN3UI6X.js +0 -5576
@@ -0,0 +1,508 @@
1
+ 'use strict';
2
+
3
+ var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
4
+ var a2a = require('@mastra/core/a2a');
5
+ var zod = require('zod');
6
+
7
+ // src/server/handlers/a2a.ts
8
+ var a2a_exports = {};
9
+ chunk75ZPJI57_cjs.__export(a2a_exports, {
10
+ getAgentCardByIdHandler: () => getAgentCardByIdHandler,
11
+ getAgentExecutionHandler: () => getAgentExecutionHandler,
12
+ handleTaskCancel: () => handleTaskCancel,
13
+ handleTaskGet: () => handleTaskGet,
14
+ handleTaskSend: () => handleTaskSend,
15
+ handleTaskSendSubscribe: () => handleTaskSendSubscribe
16
+ });
17
+ function normalizeError(error, reqId, taskId, logger) {
18
+ let a2aError;
19
+ if (error instanceof a2a.A2AError) {
20
+ a2aError = error;
21
+ } else if (error instanceof Error) {
22
+ a2aError = a2a.A2AError.internalError(error.message, { stack: error.stack });
23
+ } else {
24
+ a2aError = a2a.A2AError.internalError("An unknown error occurred.", error);
25
+ }
26
+ if (taskId && !a2aError.taskId) {
27
+ a2aError.taskId = taskId;
28
+ }
29
+ logger?.error(`Error processing request (Task: ${a2aError.taskId ?? "N/A"}, ReqID: ${reqId ?? "N/A"}):`, a2aError);
30
+ return createErrorResponse(reqId, a2aError.toJSONRPCError());
31
+ }
32
+ function createErrorResponse(id, error) {
33
+ return {
34
+ jsonrpc: "2.0",
35
+ id,
36
+ // Can be null if request ID was invalid/missing
37
+ error
38
+ };
39
+ }
40
+ function createSuccessResponse(id, result) {
41
+ if (!id) {
42
+ throw a2a.A2AError.internalError("Cannot create success response for null ID.");
43
+ }
44
+ return {
45
+ jsonrpc: "2.0",
46
+ id,
47
+ result
48
+ };
49
+ }
50
+ function convertToCoreMessage(message) {
51
+ return {
52
+ role: message.role === "user" ? "user" : "assistant",
53
+ content: message.parts.map((msg) => convertToCoreMessagePart(msg))
54
+ };
55
+ }
56
+ function convertToCoreMessagePart(part) {
57
+ switch (part.type) {
58
+ case "text":
59
+ return {
60
+ type: "text",
61
+ text: part.text
62
+ };
63
+ case "file":
64
+ return {
65
+ type: "file",
66
+ data: new URL(part.file.uri),
67
+ mimeType: part.file.mimeType
68
+ };
69
+ case "data":
70
+ throw new Error("Data parts are not supported in core messages");
71
+ }
72
+ }
73
+
74
+ // src/server/a2a/store.ts
75
+ var InMemoryTaskStore = class {
76
+ store = /* @__PURE__ */ new Map();
77
+ activeCancellations = /* @__PURE__ */ new Set();
78
+ async load({ agentId, taskId }) {
79
+ const entry = this.store.get(`${agentId}-${taskId}`);
80
+ if (!entry) {
81
+ return null;
82
+ }
83
+ return { task: { ...entry.task }, history: [...entry.history] };
84
+ }
85
+ async save({ agentId, data }) {
86
+ const key = `${agentId}-${data.task.id}`;
87
+ if (!data.task.id) {
88
+ throw new Error("Task ID is required");
89
+ }
90
+ this.store.set(key, {
91
+ task: { ...data.task },
92
+ history: [...data.history]
93
+ });
94
+ }
95
+ };
96
+
97
+ // src/server/a2a/tasks.ts
98
+ function isTaskStatusUpdate(update) {
99
+ return "state" in update && !("parts" in update);
100
+ }
101
+ function isArtifactUpdate(update) {
102
+ return "parts" in update;
103
+ }
104
+ function applyUpdateToTaskAndHistory(current, update) {
105
+ let newTask = structuredClone(current.task);
106
+ let newHistory = structuredClone(current.history);
107
+ if (isTaskStatusUpdate(update)) {
108
+ newTask.status = {
109
+ ...newTask.status,
110
+ // Keep existing properties if not overwritten
111
+ ...update,
112
+ // Apply updates
113
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
114
+ };
115
+ if (update.message?.role === "agent") {
116
+ newHistory.push(update.message);
117
+ }
118
+ } else if (isArtifactUpdate(update)) {
119
+ if (!newTask.artifacts) {
120
+ newTask.artifacts = [];
121
+ } else {
122
+ newTask.artifacts = [...newTask.artifacts];
123
+ }
124
+ const existingIndex = update.index ?? -1;
125
+ let replaced = false;
126
+ if (existingIndex >= 0 && existingIndex < newTask.artifacts.length) {
127
+ const existingArtifact = newTask.artifacts[existingIndex];
128
+ if (update.append) {
129
+ const appendedArtifact = JSON.parse(JSON.stringify(existingArtifact));
130
+ appendedArtifact.parts.push(...update.parts);
131
+ if (update.metadata) {
132
+ appendedArtifact.metadata = {
133
+ ...appendedArtifact.metadata || {},
134
+ ...update.metadata
135
+ };
136
+ }
137
+ if (update.lastChunk !== void 0) appendedArtifact.lastChunk = update.lastChunk;
138
+ if (update.description) appendedArtifact.description = update.description;
139
+ newTask.artifacts[existingIndex] = appendedArtifact;
140
+ replaced = true;
141
+ } else {
142
+ newTask.artifacts[existingIndex] = { ...update };
143
+ replaced = true;
144
+ }
145
+ } else if (update.name) {
146
+ const namedIndex = newTask.artifacts.findIndex((a) => a.name === update.name);
147
+ if (namedIndex >= 0) {
148
+ newTask.artifacts[namedIndex] = { ...update };
149
+ replaced = true;
150
+ }
151
+ }
152
+ if (!replaced) {
153
+ newTask.artifacts.push({ ...update });
154
+ if (newTask.artifacts.some((a) => a.index !== void 0)) {
155
+ newTask.artifacts.sort((a, b) => (a.index ?? 0) - (b.index ?? 0));
156
+ }
157
+ }
158
+ }
159
+ return { task: newTask, history: newHistory };
160
+ }
161
+ async function loadOrCreateTaskAndHistory({
162
+ agentId,
163
+ taskId,
164
+ taskStore,
165
+ message,
166
+ sessionId,
167
+ metadata,
168
+ logger
169
+ }) {
170
+ const data = await taskStore.load({ agentId, taskId });
171
+ if (!data) {
172
+ const initialTask = {
173
+ id: taskId,
174
+ sessionId,
175
+ status: {
176
+ state: "submitted",
177
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
178
+ message: null
179
+ },
180
+ artifacts: [],
181
+ metadata
182
+ };
183
+ const initialData = {
184
+ task: initialTask,
185
+ history: [message]
186
+ };
187
+ logger?.info(`[Task ${taskId}] Created new task and history.`);
188
+ await taskStore.save({ agentId, data: initialData });
189
+ return initialData;
190
+ }
191
+ logger?.info(`[Task ${taskId}] Loaded existing task and history.`);
192
+ let updatedData = {
193
+ task: data.task,
194
+ history: [...data.history, message]
195
+ };
196
+ const { status } = data.task;
197
+ const finalStates = ["completed", "failed", "canceled"];
198
+ if (finalStates.includes(status.state)) {
199
+ logger?.warn(`[Task ${taskId}] Received message for task in final state ${status.state}. Restarting.`);
200
+ updatedData = applyUpdateToTaskAndHistory(updatedData, {
201
+ state: "submitted",
202
+ message: null
203
+ });
204
+ } else if (status.state === "input-required") {
205
+ logger?.info(`[Task ${taskId}] Changing state from 'input-required' to 'working'.`);
206
+ updatedData = applyUpdateToTaskAndHistory(updatedData, { state: "working" });
207
+ } else if (status.state === "working") {
208
+ logger?.warn(`[Task ${taskId}] Received message while already 'working'. Proceeding.`);
209
+ }
210
+ await taskStore.save({ agentId, data: updatedData });
211
+ return {
212
+ task: { ...updatedData.task },
213
+ history: [...updatedData.history]
214
+ };
215
+ }
216
+ function createTaskContext({
217
+ task,
218
+ userMessage,
219
+ history,
220
+ activeCancellations
221
+ }) {
222
+ return {
223
+ task: structuredClone(task),
224
+ userMessage,
225
+ history: structuredClone(history),
226
+ isCancelled: () => activeCancellations.has(task.id)
227
+ };
228
+ }
229
+
230
+ // src/server/handlers/a2a.ts
231
+ var taskSendParamsSchema = zod.z.object({
232
+ id: zod.z.string().min(1, "Invalid or missing task ID (params.id)."),
233
+ message: zod.z.object({
234
+ parts: zod.z.array(
235
+ zod.z.object({
236
+ type: zod.z.enum(["text"]),
237
+ text: zod.z.string()
238
+ })
239
+ )
240
+ })
241
+ });
242
+ async function getAgentCardByIdHandler({
243
+ mastra,
244
+ agentId,
245
+ executionUrl = `/a2a/${agentId}`,
246
+ provider = {
247
+ organization: "Mastra",
248
+ url: "https://mastra.ai"
249
+ },
250
+ version = "1.0",
251
+ runtimeContext
252
+ }) {
253
+ const agent = mastra.getAgent(agentId);
254
+ if (!agent) {
255
+ throw new Error(`Agent with ID ${agentId} not found`);
256
+ }
257
+ const [instructions, tools] = await Promise.all([
258
+ agent.getInstructions({ runtimeContext }),
259
+ agent.getTools({ runtimeContext })
260
+ ]);
261
+ const agentCard = {
262
+ name: agent.id || agentId,
263
+ description: instructions,
264
+ url: executionUrl,
265
+ provider,
266
+ version,
267
+ capabilities: {
268
+ streaming: true,
269
+ // All agents support streaming
270
+ pushNotifications: false,
271
+ stateTransitionHistory: false
272
+ },
273
+ defaultInputModes: ["text"],
274
+ defaultOutputModes: ["text"],
275
+ // Convert agent tools to skills format for A2A protocol
276
+ skills: Object.entries(tools).map(([toolId, tool]) => ({
277
+ id: toolId,
278
+ name: toolId,
279
+ description: tool.description || `Tool: ${toolId}`,
280
+ // Optional fields
281
+ tags: ["tool"]
282
+ }))
283
+ };
284
+ return agentCard;
285
+ }
286
+ function validateTaskSendParams(params) {
287
+ try {
288
+ taskSendParamsSchema.parse(params);
289
+ } catch (error) {
290
+ if (error instanceof zod.z.ZodError) {
291
+ throw a2a.A2AError.invalidParams(error.errors[0].message);
292
+ }
293
+ throw error;
294
+ }
295
+ }
296
+ async function handleTaskSend({
297
+ requestId,
298
+ params,
299
+ taskStore,
300
+ agent,
301
+ logger,
302
+ runtimeContext
303
+ }) {
304
+ validateTaskSendParams(params);
305
+ const agentId = agent.id;
306
+ const { id: taskId, message, sessionId, metadata } = params;
307
+ let currentData = await loadOrCreateTaskAndHistory({
308
+ taskId,
309
+ taskStore,
310
+ agentId,
311
+ message,
312
+ sessionId,
313
+ metadata
314
+ });
315
+ createTaskContext({
316
+ task: currentData.task,
317
+ userMessage: message,
318
+ history: currentData.history,
319
+ activeCancellations: taskStore.activeCancellations
320
+ });
321
+ try {
322
+ const { text } = await agent.generate([convertToCoreMessage(message)], {
323
+ runId: taskId,
324
+ runtimeContext
325
+ });
326
+ currentData = applyUpdateToTaskAndHistory(currentData, {
327
+ state: "completed",
328
+ message: {
329
+ role: "agent",
330
+ parts: [
331
+ {
332
+ type: "text",
333
+ text
334
+ }
335
+ ]
336
+ }
337
+ });
338
+ await taskStore.save({ agentId, data: currentData });
339
+ } catch (handlerError) {
340
+ const failureStatusUpdate = {
341
+ state: "failed",
342
+ message: {
343
+ role: "agent",
344
+ parts: [
345
+ {
346
+ type: "text",
347
+ text: `Handler failed: ${handlerError instanceof Error ? handlerError.message : String(handlerError)}`
348
+ }
349
+ ]
350
+ }
351
+ };
352
+ currentData = applyUpdateToTaskAndHistory(currentData, failureStatusUpdate);
353
+ try {
354
+ await taskStore.save({ agentId, data: currentData });
355
+ } catch (saveError) {
356
+ logger?.error(`Failed to save task ${taskId} after handler error:`, saveError?.message);
357
+ }
358
+ return normalizeError(handlerError, requestId, taskId, logger);
359
+ }
360
+ return createSuccessResponse(requestId, currentData.task);
361
+ }
362
+ async function handleTaskGet({
363
+ requestId,
364
+ taskStore,
365
+ agentId,
366
+ taskId
367
+ }) {
368
+ const task = await taskStore.load({ agentId, taskId });
369
+ if (!task) {
370
+ throw a2a.A2AError.taskNotFound(taskId);
371
+ }
372
+ return createSuccessResponse(requestId, task);
373
+ }
374
+ async function* handleTaskSendSubscribe({
375
+ requestId,
376
+ params,
377
+ taskStore,
378
+ agent,
379
+ logger,
380
+ runtimeContext
381
+ }) {
382
+ yield createSuccessResponse(requestId, {
383
+ state: "working",
384
+ message: {
385
+ role: "agent",
386
+ parts: [{ type: "text", text: "Generating response..." }]
387
+ }
388
+ });
389
+ let result;
390
+ try {
391
+ result = await handleTaskSend({
392
+ requestId,
393
+ params,
394
+ taskStore,
395
+ agent,
396
+ runtimeContext,
397
+ logger
398
+ });
399
+ } catch (err) {
400
+ if (!(err instanceof a2a.A2AError)) {
401
+ throw err;
402
+ }
403
+ result = createErrorResponse(requestId, err.toJSONRPCError());
404
+ }
405
+ yield result;
406
+ }
407
+ async function handleTaskCancel({
408
+ requestId,
409
+ taskStore,
410
+ agentId,
411
+ taskId,
412
+ logger
413
+ }) {
414
+ let data = await taskStore.load({
415
+ agentId,
416
+ taskId
417
+ });
418
+ if (!data) {
419
+ throw a2a.A2AError.taskNotFound(taskId);
420
+ }
421
+ const finalStates = ["completed", "failed", "canceled"];
422
+ if (finalStates.includes(data.task.status.state)) {
423
+ logger?.info(`Task ${taskId} already in final state ${data.task.status.state}, cannot cancel.`);
424
+ return createSuccessResponse(requestId, data.task);
425
+ }
426
+ taskStore.activeCancellations.add(taskId);
427
+ const cancelUpdate = {
428
+ state: "canceled",
429
+ message: {
430
+ role: "agent",
431
+ parts: [{ type: "text", text: "Task cancelled by request." }]
432
+ }
433
+ };
434
+ data = applyUpdateToTaskAndHistory(data, cancelUpdate);
435
+ await taskStore.save({ agentId, data });
436
+ taskStore.activeCancellations.delete(taskId);
437
+ return createSuccessResponse(requestId, data.task);
438
+ }
439
+ async function getAgentExecutionHandler({
440
+ requestId,
441
+ mastra,
442
+ agentId,
443
+ runtimeContext,
444
+ method,
445
+ params,
446
+ taskStore = new InMemoryTaskStore(),
447
+ logger
448
+ }) {
449
+ const agent = mastra.getAgent(agentId);
450
+ let taskId;
451
+ try {
452
+ taskId = params.id;
453
+ switch (method) {
454
+ case "tasks/send": {
455
+ const result2 = await handleTaskSend({
456
+ requestId,
457
+ params,
458
+ taskStore,
459
+ agent,
460
+ runtimeContext
461
+ });
462
+ return result2;
463
+ }
464
+ case "tasks/sendSubscribe":
465
+ const result = await handleTaskSendSubscribe({
466
+ requestId,
467
+ taskStore,
468
+ params,
469
+ agent,
470
+ runtimeContext
471
+ });
472
+ return result;
473
+ case "tasks/get": {
474
+ const result2 = await handleTaskGet({
475
+ requestId,
476
+ taskStore,
477
+ agentId,
478
+ taskId
479
+ });
480
+ return result2;
481
+ }
482
+ case "tasks/cancel": {
483
+ const result2 = await handleTaskCancel({
484
+ requestId,
485
+ taskStore,
486
+ agentId,
487
+ taskId
488
+ });
489
+ return result2;
490
+ }
491
+ default:
492
+ throw a2a.A2AError.methodNotFound(method);
493
+ }
494
+ } catch (error) {
495
+ if (error instanceof a2a.A2AError && taskId && !error.taskId) {
496
+ error.taskId = taskId;
497
+ }
498
+ return normalizeError(error, requestId, taskId, logger);
499
+ }
500
+ }
501
+
502
+ exports.a2a_exports = a2a_exports;
503
+ exports.getAgentCardByIdHandler = getAgentCardByIdHandler;
504
+ exports.getAgentExecutionHandler = getAgentExecutionHandler;
505
+ exports.handleTaskCancel = handleTaskCancel;
506
+ exports.handleTaskGet = handleTaskGet;
507
+ exports.handleTaskSend = handleTaskSend;
508
+ exports.handleTaskSendSubscribe = handleTaskSendSubscribe;
@@ -1,11 +1,11 @@
1
1
  'use strict';
2
2
 
3
- var chunkFV45V6WC_cjs = require('./chunk-FV45V6WC.cjs');
3
+ var chunkOCWPVYNI_cjs = require('./chunk-OCWPVYNI.cjs');
4
4
 
5
5
  // src/server/handlers/error.ts
6
6
  function handleError(error, defaultMessage) {
7
7
  const apiError = error;
8
- throw new chunkFV45V6WC_cjs.HTTPException(apiError.status || 500, {
8
+ throw new chunkOCWPVYNI_cjs.HTTPException(apiError.status || 500, {
9
9
  message: apiError.message || defaultMessage
10
10
  });
11
11
  }
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __export = (target, all) => {
5
+ for (var name in all)
6
+ __defProp(target, name, { get: all[name], enumerable: true });
7
+ };
8
+
9
+ exports.__export = __export;
@@ -1,11 +1,12 @@
1
1
  'use strict';
2
2
 
3
- var chunkZLBRQFDD_cjs = require('./chunk-ZLBRQFDD.cjs');
4
- var chunkFV45V6WC_cjs = require('./chunk-FV45V6WC.cjs');
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
- chunkFV45V6WC_cjs.__export(vector_exports, {
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 chunkFV45V6WC_cjs.HTTPException(400, { message: "Vector name is required" });
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 chunkFV45V6WC_cjs.HTTPException(404, { message: `Vector store ${vectorName} not found` });
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 chunkFV45V6WC_cjs.HTTPException(400, { message: "Invalid request index. indexName and vectors array are required." });
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 chunkZLBRQFDD_cjs.handleError(error, "Error upserting vectors");
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 chunkFV45V6WC_cjs.HTTPException(400, {
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 chunkFV45V6WC_cjs.HTTPException(400, { message: "Invalid metric. Must be one of: cosine, euclidean, dotproduct" });
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 chunkZLBRQFDD_cjs.handleError(error, "Error creating index");
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 chunkFV45V6WC_cjs.HTTPException(400, { message: "Invalid request query. indexName and queryVector array are required." });
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 chunkZLBRQFDD_cjs.handleError(error, "Error querying vectors");
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 chunkZLBRQFDD_cjs.handleError(error, "Error listing indexes");
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 chunkFV45V6WC_cjs.HTTPException(400, { message: "Index name is required" });
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 chunkZLBRQFDD_cjs.handleError(error, "Error describing index");
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 chunkFV45V6WC_cjs.HTTPException(400, { message: "Index name is required" });
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 chunkZLBRQFDD_cjs.handleError(error, "Error deleting index");
119
+ return chunk64U3UDTH_cjs.handleError(error, "Error deleting index");
119
120
  }
120
121
  }
121
122
 
@@ -1,6 +1,7 @@
1
- import { validateBody } from './chunk-L7XE5QTW.js';
2
- import { handleError } from './chunk-3AHQ5RGN.js';
3
- import { __export, HTTPException } from './chunk-TRDNDNGQ.js';
1
+ import { validateBody } from './chunk-H5PTF3Y4.js';
2
+ import { handleError } from './chunk-M5ABIP7D.js';
3
+ import { HTTPException } from './chunk-NYN7KFXL.js';
4
+ import { __export } from './chunk-MLKGABMK.js';
4
5
 
5
6
  // src/server/handlers/network.ts
6
7
  var network_exports = {};