@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.
Files changed (99) hide show
  1. package/dist/_tsup-dts-rollup.d.cts +1107 -0
  2. package/dist/_tsup-dts-rollup.d.ts +1107 -0
  3. package/dist/chunk-2KZFMI6P.cjs +37 -0
  4. package/dist/chunk-2SLFAFTR.cjs +148 -0
  5. package/dist/chunk-3CNDE7QY.cjs +308 -0
  6. package/dist/chunk-4D66QEKC.js +81 -0
  7. package/dist/chunk-5PQQ42EZ.js +320 -0
  8. package/dist/chunk-75ZPJI57.cjs +9 -0
  9. package/dist/chunk-7TP2LX5L.cjs +129 -0
  10. package/dist/chunk-B2PAS2IB.cjs +514 -0
  11. package/dist/chunk-BK4XT6EG.js +270 -0
  12. package/dist/chunk-CCGRCYWJ.cjs +18 -0
  13. package/dist/chunk-CRCR3ZUK.js +142 -0
  14. package/dist/chunk-FRVBFMO2.cjs +128 -0
  15. package/dist/chunk-G7KH752Y.cjs +145 -0
  16. package/dist/chunk-GHC4YV6R.js +504 -0
  17. package/dist/chunk-H7DMHBKY.js +498 -0
  18. package/dist/chunk-JMLYCXMK.cjs +332 -0
  19. package/dist/chunk-KHZKYUNR.js +112 -0
  20. package/dist/chunk-KOHWJYJT.js +296 -0
  21. package/dist/chunk-LCM566I4.js +35 -0
  22. package/dist/chunk-LF7P5PLR.js +14 -0
  23. package/dist/chunk-LI436ITD.cjs +2042 -0
  24. package/dist/chunk-LRCAAFUA.js +122 -0
  25. package/dist/chunk-LZ3VJXSO.cjs +278 -0
  26. package/dist/chunk-MEGCYGBU.js +2039 -0
  27. package/dist/chunk-MLKGABMK.js +7 -0
  28. package/dist/chunk-PZQDCRPV.cjs +16 -0
  29. package/dist/chunk-QGX47B5D.cjs +86 -0
  30. package/dist/chunk-RG473F6Y.js +141 -0
  31. package/dist/chunk-RHSWAXKB.cjs +118 -0
  32. package/dist/chunk-RSEO4XPX.js +16 -0
  33. package/dist/chunk-SDPGVWQJ.cjs +512 -0
  34. package/dist/chunk-WNVFNNWN.js +121 -0
  35. package/dist/index.cjs +2 -0
  36. package/dist/index.d.cts +1 -0
  37. package/dist/index.d.ts +1 -0
  38. package/dist/index.js +1 -0
  39. package/dist/server/handlers/a2a.cjs +30 -0
  40. package/dist/server/handlers/a2a.d.cts +6 -0
  41. package/dist/server/handlers/a2a.d.ts +6 -0
  42. package/dist/server/handlers/a2a.js +1 -0
  43. package/dist/server/handlers/agents.cjs +30 -0
  44. package/dist/server/handlers/agents.d.cts +6 -0
  45. package/dist/server/handlers/agents.d.ts +6 -0
  46. package/dist/server/handlers/agents.js +1 -0
  47. package/dist/server/handlers/error.cjs +10 -0
  48. package/dist/server/handlers/error.d.cts +1 -0
  49. package/dist/server/handlers/error.d.ts +1 -0
  50. package/dist/server/handlers/error.js +1 -0
  51. package/dist/server/handlers/legacyWorkflows.cjs +46 -0
  52. package/dist/server/handlers/legacyWorkflows.d.cts +10 -0
  53. package/dist/server/handlers/legacyWorkflows.d.ts +10 -0
  54. package/dist/server/handlers/legacyWorkflows.js +1 -0
  55. package/dist/server/handlers/logs.cjs +18 -0
  56. package/dist/server/handlers/logs.d.cts +3 -0
  57. package/dist/server/handlers/logs.d.ts +3 -0
  58. package/dist/server/handlers/logs.js +1 -0
  59. package/dist/server/handlers/memory.cjs +46 -0
  60. package/dist/server/handlers/memory.d.cts +10 -0
  61. package/dist/server/handlers/memory.d.ts +10 -0
  62. package/dist/server/handlers/memory.js +1 -0
  63. package/dist/server/handlers/network.cjs +22 -0
  64. package/dist/server/handlers/network.d.cts +4 -0
  65. package/dist/server/handlers/network.d.ts +4 -0
  66. package/dist/server/handlers/network.js +1 -0
  67. package/dist/server/handlers/telemetry.cjs +14 -0
  68. package/dist/server/handlers/telemetry.d.cts +2 -0
  69. package/dist/server/handlers/telemetry.d.ts +2 -0
  70. package/dist/server/handlers/telemetry.js +1 -0
  71. package/dist/server/handlers/tools.cjs +22 -0
  72. package/dist/server/handlers/tools.d.cts +4 -0
  73. package/dist/server/handlers/tools.d.ts +4 -0
  74. package/dist/server/handlers/tools.js +1 -0
  75. package/dist/server/handlers/utils.cjs +10 -0
  76. package/dist/server/handlers/utils.d.cts +1 -0
  77. package/dist/server/handlers/utils.d.ts +1 -0
  78. package/dist/server/handlers/utils.js +1 -0
  79. package/dist/server/handlers/vNextNetwork.cjs +218 -0
  80. package/dist/server/handlers/vNextNetwork.d.cts +6 -0
  81. package/dist/server/handlers/vNextNetwork.d.ts +6 -0
  82. package/dist/server/handlers/vNextNetwork.js +211 -0
  83. package/dist/server/handlers/vector.cjs +30 -0
  84. package/dist/server/handlers/vector.d.cts +6 -0
  85. package/dist/server/handlers/vector.d.ts +6 -0
  86. package/dist/server/handlers/vector.js +1 -0
  87. package/dist/server/handlers/voice.cjs +22 -0
  88. package/dist/server/handlers/voice.d.cts +4 -0
  89. package/dist/server/handlers/voice.d.ts +4 -0
  90. package/dist/server/handlers/voice.js +1 -0
  91. package/dist/server/handlers/workflows.cjs +62 -0
  92. package/dist/server/handlers/workflows.d.cts +14 -0
  93. package/dist/server/handlers/workflows.d.ts +14 -0
  94. package/dist/server/handlers/workflows.js +1 -0
  95. package/dist/server/handlers.cjs +60 -0
  96. package/dist/server/handlers.d.cts +11 -0
  97. package/dist/server/handlers.d.ts +11 -0
  98. package/dist/server/handlers.js +11 -0
  99. package/package.json +3 -3
@@ -0,0 +1,512 @@
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
+ agentId,
302
+ logger,
303
+ runtimeContext
304
+ }) {
305
+ validateTaskSendParams(params);
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
+ agentId,
380
+ logger,
381
+ runtimeContext
382
+ }) {
383
+ yield createSuccessResponse(requestId, {
384
+ state: "working",
385
+ message: {
386
+ role: "agent",
387
+ parts: [{ type: "text", text: "Generating response..." }]
388
+ }
389
+ });
390
+ let result;
391
+ try {
392
+ result = await handleTaskSend({
393
+ requestId,
394
+ params,
395
+ taskStore,
396
+ agent,
397
+ agentId,
398
+ runtimeContext,
399
+ logger
400
+ });
401
+ } catch (err) {
402
+ if (!(err instanceof a2a.A2AError)) {
403
+ throw err;
404
+ }
405
+ result = createErrorResponse(requestId, err.toJSONRPCError());
406
+ }
407
+ yield result;
408
+ }
409
+ async function handleTaskCancel({
410
+ requestId,
411
+ taskStore,
412
+ agentId,
413
+ taskId,
414
+ logger
415
+ }) {
416
+ let data = await taskStore.load({
417
+ agentId,
418
+ taskId
419
+ });
420
+ if (!data) {
421
+ throw a2a.A2AError.taskNotFound(taskId);
422
+ }
423
+ const finalStates = ["completed", "failed", "canceled"];
424
+ if (finalStates.includes(data.task.status.state)) {
425
+ logger?.info(`Task ${taskId} already in final state ${data.task.status.state}, cannot cancel.`);
426
+ return createSuccessResponse(requestId, data.task);
427
+ }
428
+ taskStore.activeCancellations.add(taskId);
429
+ const cancelUpdate = {
430
+ state: "canceled",
431
+ message: {
432
+ role: "agent",
433
+ parts: [{ type: "text", text: "Task cancelled by request." }]
434
+ }
435
+ };
436
+ data = applyUpdateToTaskAndHistory(data, cancelUpdate);
437
+ await taskStore.save({ agentId, data });
438
+ taskStore.activeCancellations.delete(taskId);
439
+ return createSuccessResponse(requestId, data.task);
440
+ }
441
+ async function getAgentExecutionHandler({
442
+ requestId,
443
+ mastra,
444
+ agentId,
445
+ runtimeContext,
446
+ method,
447
+ params,
448
+ taskStore = new InMemoryTaskStore(),
449
+ logger
450
+ }) {
451
+ const agent = mastra.getAgent(agentId);
452
+ let taskId;
453
+ try {
454
+ taskId = params.id;
455
+ switch (method) {
456
+ case "tasks/send": {
457
+ const result2 = await handleTaskSend({
458
+ requestId,
459
+ params,
460
+ taskStore,
461
+ agent,
462
+ agentId,
463
+ runtimeContext
464
+ });
465
+ return result2;
466
+ }
467
+ case "tasks/sendSubscribe":
468
+ const result = await handleTaskSendSubscribe({
469
+ requestId,
470
+ taskStore,
471
+ params,
472
+ agent,
473
+ agentId,
474
+ runtimeContext
475
+ });
476
+ return result;
477
+ case "tasks/get": {
478
+ const result2 = await handleTaskGet({
479
+ requestId,
480
+ taskStore,
481
+ agentId,
482
+ taskId
483
+ });
484
+ return result2;
485
+ }
486
+ case "tasks/cancel": {
487
+ const result2 = await handleTaskCancel({
488
+ requestId,
489
+ taskStore,
490
+ agentId,
491
+ taskId
492
+ });
493
+ return result2;
494
+ }
495
+ default:
496
+ throw a2a.A2AError.methodNotFound(method);
497
+ }
498
+ } catch (error) {
499
+ if (error instanceof a2a.A2AError && taskId && !error.taskId) {
500
+ error.taskId = taskId;
501
+ }
502
+ return normalizeError(error, requestId, taskId, logger);
503
+ }
504
+ }
505
+
506
+ exports.a2a_exports = a2a_exports;
507
+ exports.getAgentCardByIdHandler = getAgentCardByIdHandler;
508
+ exports.getAgentExecutionHandler = getAgentExecutionHandler;
509
+ exports.handleTaskCancel = handleTaskCancel;
510
+ exports.handleTaskGet = handleTaskGet;
511
+ exports.handleTaskSend = handleTaskSend;
512
+ exports.handleTaskSendSubscribe = handleTaskSendSubscribe;
@@ -0,0 +1,121 @@
1
+ import { handleError } from './chunk-LF7P5PLR.js';
2
+ import { HTTPException } from './chunk-LCM566I4.js';
3
+ import { __export } from './chunk-MLKGABMK.js';
4
+
5
+ // src/server/handlers/vector.ts
6
+ var vector_exports = {};
7
+ __export(vector_exports, {
8
+ createIndex: () => createIndex,
9
+ deleteIndex: () => deleteIndex,
10
+ describeIndex: () => describeIndex,
11
+ listIndexes: () => listIndexes,
12
+ queryVectors: () => queryVectors,
13
+ upsertVectors: () => upsertVectors
14
+ });
15
+ function getVector(mastra, vectorName) {
16
+ if (!vectorName) {
17
+ throw new HTTPException(400, { message: "Vector name is required" });
18
+ }
19
+ const vector = mastra.getVector(vectorName);
20
+ if (!vector) {
21
+ throw new HTTPException(404, { message: `Vector store ${vectorName} not found` });
22
+ }
23
+ return vector;
24
+ }
25
+ async function upsertVectors({ mastra, vectorName, index }) {
26
+ try {
27
+ if (!index?.indexName || !index?.vectors || !Array.isArray(index.vectors)) {
28
+ throw new HTTPException(400, { message: "Invalid request index. indexName and vectors array are required." });
29
+ }
30
+ const vector = getVector(mastra, vectorName);
31
+ const result = await vector.upsert(index);
32
+ return { ids: result };
33
+ } catch (error) {
34
+ return handleError(error, "Error upserting vectors");
35
+ }
36
+ }
37
+ async function createIndex({
38
+ mastra,
39
+ vectorName,
40
+ index
41
+ }) {
42
+ try {
43
+ const { indexName, dimension, metric } = index;
44
+ if (!indexName || typeof dimension !== "number" || dimension <= 0) {
45
+ throw new HTTPException(400, {
46
+ message: "Invalid request index, indexName and positive dimension number are required."
47
+ });
48
+ }
49
+ if (metric && !["cosine", "euclidean", "dotproduct"].includes(metric)) {
50
+ throw new HTTPException(400, { message: "Invalid metric. Must be one of: cosine, euclidean, dotproduct" });
51
+ }
52
+ const vector = getVector(mastra, vectorName);
53
+ await vector.createIndex({ indexName, dimension, metric });
54
+ return { success: true };
55
+ } catch (error) {
56
+ return handleError(error, "Error creating index");
57
+ }
58
+ }
59
+ async function queryVectors({
60
+ mastra,
61
+ vectorName,
62
+ query
63
+ }) {
64
+ try {
65
+ if (!query?.indexName || !query?.queryVector || !Array.isArray(query.queryVector)) {
66
+ throw new HTTPException(400, { message: "Invalid request query. indexName and queryVector array are required." });
67
+ }
68
+ const vector = getVector(mastra, vectorName);
69
+ const results = await vector.query(query);
70
+ return results;
71
+ } catch (error) {
72
+ return handleError(error, "Error querying vectors");
73
+ }
74
+ }
75
+ async function listIndexes({ mastra, vectorName }) {
76
+ try {
77
+ const vector = getVector(mastra, vectorName);
78
+ const indexes = await vector.listIndexes();
79
+ return indexes.filter(Boolean);
80
+ } catch (error) {
81
+ return handleError(error, "Error listing indexes");
82
+ }
83
+ }
84
+ async function describeIndex({
85
+ mastra,
86
+ vectorName,
87
+ indexName
88
+ }) {
89
+ try {
90
+ if (!indexName) {
91
+ throw new HTTPException(400, { message: "Index name is required" });
92
+ }
93
+ const vector = getVector(mastra, vectorName);
94
+ const stats = await vector.describeIndex({ indexName });
95
+ return {
96
+ dimension: stats.dimension,
97
+ count: stats.count,
98
+ metric: stats.metric?.toLowerCase()
99
+ };
100
+ } catch (error) {
101
+ return handleError(error, "Error describing index");
102
+ }
103
+ }
104
+ async function deleteIndex({
105
+ mastra,
106
+ vectorName,
107
+ indexName
108
+ }) {
109
+ try {
110
+ if (!indexName) {
111
+ throw new HTTPException(400, { message: "Index name is required" });
112
+ }
113
+ const vector = getVector(mastra, vectorName);
114
+ await vector.deleteIndex({ indexName });
115
+ return { success: true };
116
+ } catch (error) {
117
+ return handleError(error, "Error deleting index");
118
+ }
119
+ }
120
+
121
+ export { createIndex, deleteIndex, describeIndex, listIndexes, queryVectors, upsertVectors, vector_exports };
package/dist/index.cjs ADDED
@@ -0,0 +1,2 @@
1
+ 'use strict';
2
+
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,30 @@
1
+ 'use strict';
2
+
3
+ var chunkSDPGVWQJ_cjs = require('../../chunk-SDPGVWQJ.cjs');
4
+
5
+
6
+
7
+ Object.defineProperty(exports, "getAgentCardByIdHandler", {
8
+ enumerable: true,
9
+ get: function () { return chunkSDPGVWQJ_cjs.getAgentCardByIdHandler; }
10
+ });
11
+ Object.defineProperty(exports, "getAgentExecutionHandler", {
12
+ enumerable: true,
13
+ get: function () { return chunkSDPGVWQJ_cjs.getAgentExecutionHandler; }
14
+ });
15
+ Object.defineProperty(exports, "handleTaskCancel", {
16
+ enumerable: true,
17
+ get: function () { return chunkSDPGVWQJ_cjs.handleTaskCancel; }
18
+ });
19
+ Object.defineProperty(exports, "handleTaskGet", {
20
+ enumerable: true,
21
+ get: function () { return chunkSDPGVWQJ_cjs.handleTaskGet; }
22
+ });
23
+ Object.defineProperty(exports, "handleTaskSend", {
24
+ enumerable: true,
25
+ get: function () { return chunkSDPGVWQJ_cjs.handleTaskSend; }
26
+ });
27
+ Object.defineProperty(exports, "handleTaskSendSubscribe", {
28
+ enumerable: true,
29
+ get: function () { return chunkSDPGVWQJ_cjs.handleTaskSendSubscribe; }
30
+ });
@@ -0,0 +1,6 @@
1
+ export { getAgentCardByIdHandler } from '../../_tsup-dts-rollup.cjs';
2
+ export { handleTaskSend } from '../../_tsup-dts-rollup.cjs';
3
+ export { handleTaskGet } from '../../_tsup-dts-rollup.cjs';
4
+ export { handleTaskSendSubscribe } from '../../_tsup-dts-rollup.cjs';
5
+ export { handleTaskCancel } from '../../_tsup-dts-rollup.cjs';
6
+ export { getAgentExecutionHandler } from '../../_tsup-dts-rollup.cjs';
@@ -0,0 +1,6 @@
1
+ export { getAgentCardByIdHandler } from '../../_tsup-dts-rollup.js';
2
+ export { handleTaskSend } from '../../_tsup-dts-rollup.js';
3
+ export { handleTaskGet } from '../../_tsup-dts-rollup.js';
4
+ export { handleTaskSendSubscribe } from '../../_tsup-dts-rollup.js';
5
+ export { handleTaskCancel } from '../../_tsup-dts-rollup.js';
6
+ export { getAgentExecutionHandler } from '../../_tsup-dts-rollup.js';
@@ -0,0 +1 @@
1
+ export { getAgentCardByIdHandler, getAgentExecutionHandler, handleTaskCancel, handleTaskGet, handleTaskSend, handleTaskSendSubscribe } from '../../chunk-GHC4YV6R.js';