@mastra/convex 0.0.0-netlify-no-bundle-20251127120354 → 0.0.0-new-button-export-20251219133013

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 (42) hide show
  1. package/CHANGELOG.md +303 -3
  2. package/README.md +1 -1
  3. package/dist/{chunk-QKN2PWR2.cjs → chunk-BKVR7SL7.cjs} +2 -89
  4. package/dist/chunk-BKVR7SL7.cjs.map +1 -0
  5. package/dist/{chunk-NZCHEPNU.js → chunk-KSAPIIEJ.js} +5 -65
  6. package/dist/chunk-KSAPIIEJ.js.map +1 -0
  7. package/dist/chunk-PKUUSREO.js +76 -0
  8. package/dist/chunk-PKUUSREO.js.map +1 -0
  9. package/dist/chunk-ZBUP3DS6.cjs +93 -0
  10. package/dist/chunk-ZBUP3DS6.cjs.map +1 -0
  11. package/dist/index.cjs +217 -180
  12. package/dist/index.cjs.map +1 -1
  13. package/dist/index.js +201 -164
  14. package/dist/index.js.map +1 -1
  15. package/dist/schema.cjs +72 -0
  16. package/dist/schema.cjs.map +1 -0
  17. package/dist/schema.d.ts +151 -0
  18. package/dist/schema.d.ts.map +1 -0
  19. package/dist/schema.js +3 -0
  20. package/dist/schema.js.map +1 -0
  21. package/dist/server/index.cjs +19 -18
  22. package/dist/server/index.d.ts +1 -1
  23. package/dist/server/index.d.ts.map +1 -1
  24. package/dist/server/index.js +2 -1
  25. package/dist/storage/db/index.d.ts +57 -0
  26. package/dist/storage/db/index.d.ts.map +1 -0
  27. package/dist/storage/domains/{memory.d.ts → memory/index.d.ts} +6 -4
  28. package/dist/storage/domains/memory/index.d.ts.map +1 -0
  29. package/dist/storage/domains/{scores.d.ts → scores/index.d.ts} +8 -6
  30. package/dist/storage/domains/scores/index.d.ts.map +1 -0
  31. package/dist/storage/domains/{workflows.d.ts → workflows/index.d.ts} +13 -13
  32. package/dist/storage/domains/workflows/index.d.ts.map +1 -0
  33. package/dist/storage/index.d.ts +29 -39
  34. package/dist/storage/index.d.ts.map +1 -1
  35. package/package.json +15 -6
  36. package/dist/chunk-NZCHEPNU.js.map +0 -1
  37. package/dist/chunk-QKN2PWR2.cjs.map +0 -1
  38. package/dist/storage/domains/memory.d.ts.map +0 -1
  39. package/dist/storage/domains/scores.d.ts.map +0 -1
  40. package/dist/storage/domains/workflows.d.ts.map +0 -1
  41. package/dist/storage/operations.d.ts +0 -40
  42. package/dist/storage/operations.d.ts.map +0 -1
package/dist/index.js CHANGED
@@ -1,8 +1,10 @@
1
- export { TABLE_MESSAGES, TABLE_RESOURCES, TABLE_SCORERS, TABLE_THREADS, TABLE_WORKFLOW_SNAPSHOT, mastraDocumentsTable, mastraMessagesTable, mastraResourcesTable, mastraScoresTable, mastraStorage, mastraThreadsTable, mastraVectorIndexesTable, mastraVectorsTable, mastraWorkflowSnapshotsTable } from './chunk-NZCHEPNU.js';
2
- import { MastraStorage, StoreOperations, TABLE_WORKFLOW_SNAPSHOT, MemoryStorage, TABLE_THREADS, TABLE_MESSAGES, normalizePerPage, calculatePagination, safelyParseJSON, TABLE_RESOURCES, WorkflowsStorage, ScoresStorage, TABLE_SCORERS } from '@mastra/core/storage';
1
+ export { mastraStorage } from './chunk-KSAPIIEJ.js';
2
+ export { TABLE_MESSAGES, TABLE_RESOURCES, TABLE_SCORERS, TABLE_THREADS, TABLE_WORKFLOW_SNAPSHOT, mastraDocumentsTable, mastraMessagesTable, mastraResourcesTable, mastraScoresTable, mastraThreadsTable, mastraVectorIndexesTable, mastraVectorsTable, mastraWorkflowSnapshotsTable } from './chunk-PKUUSREO.js';
3
+ import { MastraStorage, MemoryStorage, TABLE_THREADS, TABLE_MESSAGES, TABLE_RESOURCES, createStorageErrorId, normalizePerPage, calculatePagination, safelyParseJSON, WorkflowsStorage, TABLE_WORKFLOW_SNAPSHOT, ScoresStorage, TABLE_SCORERS } from '@mastra/core/storage';
3
4
  import { MessageList } from '@mastra/core/agent';
4
5
  import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
5
6
  import crypto from 'crypto';
7
+ import { MastraBase } from '@mastra/core/base';
6
8
  import { MastraVector } from '@mastra/core/vector';
7
9
 
8
10
  // src/storage/client.ts
@@ -68,13 +70,114 @@ var ConvexAdminClient = class {
68
70
  return result;
69
71
  }
70
72
  };
73
+ function resolveConvexConfig(config) {
74
+ if ("client" in config) {
75
+ return config.client;
76
+ }
77
+ return new ConvexAdminClient(config);
78
+ }
79
+ var ConvexDB = class extends MastraBase {
80
+ constructor(client) {
81
+ super({ name: "convex-db" });
82
+ this.client = client;
83
+ }
84
+ async hasColumn(_table, _column) {
85
+ return true;
86
+ }
87
+ async clearTable({ tableName }) {
88
+ let hasMore = true;
89
+ while (hasMore) {
90
+ const response = await this.client.callStorageRaw({
91
+ op: "clearTable",
92
+ tableName
93
+ });
94
+ hasMore = response.hasMore ?? false;
95
+ }
96
+ }
97
+ async dropTable({ tableName }) {
98
+ let hasMore = true;
99
+ while (hasMore) {
100
+ const response = await this.client.callStorageRaw({
101
+ op: "dropTable",
102
+ tableName
103
+ });
104
+ hasMore = response.hasMore ?? false;
105
+ }
106
+ }
107
+ async insert({ tableName, record }) {
108
+ await this.client.callStorage({
109
+ op: "insert",
110
+ tableName,
111
+ record: this.normalizeRecord(tableName, record)
112
+ });
113
+ }
114
+ async batchInsert({ tableName, records }) {
115
+ if (records.length === 0) return;
116
+ await this.client.callStorage({
117
+ op: "batchInsert",
118
+ tableName,
119
+ records: records.map((record) => this.normalizeRecord(tableName, record))
120
+ });
121
+ }
122
+ async load({ tableName, keys }) {
123
+ const result = await this.client.callStorage({
124
+ op: "load",
125
+ tableName,
126
+ keys
127
+ });
128
+ return result;
129
+ }
130
+ async queryTable(tableName, filters) {
131
+ return this.client.callStorage({
132
+ op: "queryTable",
133
+ tableName,
134
+ filters
135
+ });
136
+ }
137
+ async deleteMany(tableName, ids) {
138
+ if (ids.length === 0) return;
139
+ await this.client.callStorage({
140
+ op: "deleteMany",
141
+ tableName,
142
+ ids
143
+ });
144
+ }
145
+ normalizeRecord(tableName, record) {
146
+ const normalized = { ...record };
147
+ if (tableName === TABLE_WORKFLOW_SNAPSHOT && !normalized.id) {
148
+ const runId = normalized.run_id || normalized.runId;
149
+ const workflowName = normalized.workflow_name || normalized.workflowName;
150
+ normalized.id = workflowName ? `${workflowName}-${runId}` : runId;
151
+ }
152
+ if (!normalized.id) {
153
+ normalized.id = crypto.randomUUID();
154
+ }
155
+ for (const [key, value] of Object.entries(normalized)) {
156
+ if (value instanceof Date) {
157
+ normalized[key] = value.toISOString();
158
+ }
159
+ }
160
+ return normalized;
161
+ }
162
+ };
163
+
164
+ // src/storage/domains/memory/index.ts
71
165
  var MemoryConvex = class extends MemoryStorage {
72
- constructor(operations) {
166
+ #db;
167
+ constructor(config) {
73
168
  super();
74
- this.operations = operations;
169
+ const client = resolveConvexConfig(config);
170
+ this.#db = new ConvexDB(client);
171
+ }
172
+ async init() {
173
+ }
174
+ async dangerouslyClearAll() {
175
+ await this.#db.clearTable({ tableName: TABLE_THREADS });
176
+ await this.#db.clearTable({ tableName: TABLE_MESSAGES });
177
+ await this.#db.clearTable({ tableName: TABLE_RESOURCES });
75
178
  }
76
179
  async getThreadById({ threadId }) {
77
- const row = await this.operations.load({
180
+ const row = await this.#db.load({
78
181
  tableName: TABLE_THREADS,
79
182
  keys: { id: threadId }
80
183
  });
@@ -87,7 +190,7 @@ var MemoryConvex = class extends MemoryStorage {
87
190
  };
88
191
  }
89
192
  async saveThread({ thread }) {
90
- await this.operations.insert({
193
+ await this.#db.insert({
91
194
  tableName: TABLE_THREADS,
92
195
  record: {
93
196
  ...thread,
@@ -104,7 +207,7 @@ var MemoryConvex = class extends MemoryStorage {
104
207
  const existing = await this.getThreadById({ threadId: id });
105
208
  if (!existing) {
106
209
  throw new MastraError({
107
- id: "CONVEX_STORAGE_THREAD_NOT_FOUND",
210
+ id: createStorageErrorId("CONVEX", "UPDATE_THREAD", "THREAD_NOT_FOUND"),
108
211
  domain: ErrorDomain.STORAGE,
109
212
  category: ErrorCategory.USER,
110
213
  text: `Thread ${id} not found`
@@ -123,21 +226,21 @@ var MemoryConvex = class extends MemoryStorage {
123
226
  return updated;
124
227
  }
125
228
  async deleteThread({ threadId }) {
126
- const messages = await this.operations.queryTable(TABLE_MESSAGES, [
229
+ const messages = await this.#db.queryTable(TABLE_MESSAGES, [
127
230
  { field: "thread_id", value: threadId }
128
231
  ]);
129
- await this.operations.deleteMany(
232
+ await this.#db.deleteMany(
130
233
  TABLE_MESSAGES,
131
234
  messages.map((msg) => msg.id)
132
235
  );
133
- await this.operations.deleteMany(TABLE_THREADS, [threadId]);
236
+ await this.#db.deleteMany(TABLE_THREADS, [threadId]);
134
237
  }
135
238
  async listThreadsByResourceId(args) {
136
239
  const { resourceId, page = 0, perPage: perPageInput, orderBy } = args;
137
240
  const perPage = normalizePerPage(perPageInput, 100);
138
241
  const { field, direction } = this.parseOrderBy(orderBy);
139
242
  const { offset, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
140
- const rows = await this.operations.queryTable(TABLE_THREADS, [{ field: "resourceId", value: resourceId }]);
243
+ const rows = await this.#db.queryTable(TABLE_THREADS, [{ field: "resourceId", value: resourceId }]);
141
244
  const threads = rows.map((row) => ({
142
245
  ...row,
143
246
  metadata: typeof row.metadata === "string" ? JSON.parse(row.metadata) : row.metadata,
@@ -163,23 +266,26 @@ var MemoryConvex = class extends MemoryStorage {
163
266
  }
164
267
  async listMessages(args) {
165
268
  const { threadId, resourceId, include, filter, perPage: perPageInput, page = 0, orderBy } = args;
166
- if (!threadId.trim()) {
269
+ const threadIds = Array.isArray(threadId) ? threadId : [threadId];
270
+ if (threadIds.length === 0 || threadIds.some((id) => !id.trim())) {
167
271
  throw new MastraError(
168
272
  {
169
- id: "CONVEX_STORAGE_LIST_MESSAGES_INVALID_THREAD_ID",
273
+ id: createStorageErrorId("CONVEX", "LIST_MESSAGES", "INVALID_THREAD_ID"),
170
274
  domain: ErrorDomain.STORAGE,
171
275
  category: ErrorCategory.USER,
172
- details: { threadId }
276
+ details: { threadId: Array.isArray(threadId) ? threadId.join(",") : threadId }
173
277
  },
174
- new Error("threadId must be a non-empty string")
278
+ new Error("threadId must be a non-empty string or array of non-empty strings")
175
279
  );
176
280
  }
177
281
  const perPage = normalizePerPage(perPageInput, 40);
178
282
  const { offset, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
179
283
  const { field, direction } = this.parseOrderBy(orderBy, "ASC");
180
- let rows = await this.operations.queryTable(TABLE_MESSAGES, [
181
- { field: "thread_id", value: threadId }
182
- ]);
284
+ let rows = [];
285
+ for (const tid of threadIds) {
286
+ const threadRows = await this.#db.queryTable(TABLE_MESSAGES, [{ field: "thread_id", value: tid }]);
287
+ rows.push(...threadRows);
288
+ }
183
289
  if (resourceId) {
184
290
  rows = rows.filter((row) => row.resourceId === resourceId);
185
291
  }
@@ -206,21 +312,41 @@ var MemoryConvex = class extends MemoryStorage {
206
312
  const messageIds = new Set(messages.map((msg) => msg.id));
207
313
  if (include && include.length > 0) {
208
314
  const threadMessagesCache = /* @__PURE__ */ new Map();
209
- threadMessagesCache.set(threadId, rows);
315
+ for (const tid of threadIds) {
316
+ const tidRows = rows.filter((r) => r.thread_id === tid);
317
+ threadMessagesCache.set(tid, tidRows);
318
+ }
210
319
  for (const includeItem of include) {
211
- const targetThreadId = includeItem.threadId || threadId;
212
- if (!threadMessagesCache.has(targetThreadId)) {
213
- const otherThreadRows = await this.operations.queryTable(TABLE_MESSAGES, [
214
- { field: "thread_id", value: targetThreadId }
320
+ let targetThreadId;
321
+ let target;
322
+ for (const [tid, cachedRows] of threadMessagesCache) {
323
+ target = cachedRows.find((row) => row.id === includeItem.id);
324
+ if (target) {
325
+ targetThreadId = tid;
326
+ break;
327
+ }
328
+ }
329
+ if (!target) {
330
+ const messageRows = await this.#db.queryTable(TABLE_MESSAGES, [
331
+ { field: "id", value: includeItem.id }
215
332
  ]);
216
- threadMessagesCache.set(targetThreadId, otherThreadRows);
333
+ if (messageRows.length > 0) {
334
+ target = messageRows[0];
335
+ targetThreadId = target.thread_id;
336
+ if (targetThreadId && !threadMessagesCache.has(targetThreadId)) {
337
+ const otherThreadRows = await this.#db.queryTable(TABLE_MESSAGES, [
338
+ { field: "thread_id", value: targetThreadId }
339
+ ]);
340
+ threadMessagesCache.set(targetThreadId, otherThreadRows);
341
+ }
342
+ }
217
343
  }
218
- const targetThreadRows = threadMessagesCache.get(targetThreadId) || [];
219
- const target = targetThreadRows.find((row) => row.id === includeItem.id);
220
- if (target && !messageIds.has(target.id)) {
344
+ if (!target || !targetThreadId) continue;
345
+ if (!messageIds.has(target.id)) {
221
346
  messages.push(this.parseStoredMessage(target));
222
347
  messageIds.add(target.id);
223
348
  }
349
+ const targetThreadRows = threadMessagesCache.get(targetThreadId) || [];
224
350
  await this.addContextMessages({
225
351
  includeItem,
226
352
  allMessages: targetThreadRows,
@@ -251,7 +377,7 @@ var MemoryConvex = class extends MemoryStorage {
251
377
  if (messageIds.length === 0) {
252
378
  return { messages: [] };
253
379
  }
254
- const rows = await this.operations.queryTable(TABLE_MESSAGES, void 0);
380
+ const rows = await this.#db.queryTable(TABLE_MESSAGES, void 0);
255
381
  const filtered = rows.filter((row) => messageIds.includes(row.id)).map((row) => this.parseStoredMessage(row));
256
382
  const list = new MessageList().add(filtered, "memory");
257
383
  return { messages: list.get.all.db() };
@@ -276,7 +402,7 @@ var MemoryConvex = class extends MemoryStorage {
276
402
  resourceId: message.resourceId
277
403
  };
278
404
  });
279
- await this.operations.batchInsert({
405
+ await this.#db.batchInsert({
280
406
  tableName: TABLE_MESSAGES,
281
407
  records: normalized
282
408
  });
@@ -285,7 +411,7 @@ var MemoryConvex = class extends MemoryStorage {
285
411
  for (const threadId of threadIds) {
286
412
  const thread = await this.getThreadById({ threadId });
287
413
  if (thread) {
288
- await this.operations.insert({
414
+ await this.#db.insert({
289
415
  tableName: TABLE_THREADS,
290
416
  record: {
291
417
  ...thread,
@@ -304,7 +430,7 @@ var MemoryConvex = class extends MemoryStorage {
304
430
  messages
305
431
  }) {
306
432
  if (messages.length === 0) return [];
307
- const existing = await this.operations.queryTable(TABLE_MESSAGES, void 0);
433
+ const existing = await this.#db.queryTable(TABLE_MESSAGES, void 0);
308
434
  const updated = [];
309
435
  const affectedThreadIds = /* @__PURE__ */ new Set();
310
436
  for (const update of messages) {
@@ -333,7 +459,7 @@ var MemoryConvex = class extends MemoryStorage {
333
459
  };
334
460
  current.content = JSON.stringify(mergedContent);
335
461
  }
336
- await this.operations.insert({
462
+ await this.#db.insert({
337
463
  tableName: TABLE_MESSAGES,
338
464
  record: current
339
465
  });
@@ -343,7 +469,7 @@ var MemoryConvex = class extends MemoryStorage {
343
469
  for (const threadId of affectedThreadIds) {
344
470
  const thread = await this.getThreadById({ threadId });
345
471
  if (thread) {
346
- await this.operations.insert({
472
+ await this.#db.insert({
347
473
  tableName: TABLE_THREADS,
348
474
  record: {
349
475
  ...thread,
@@ -358,7 +484,7 @@ var MemoryConvex = class extends MemoryStorage {
358
484
  return updated;
359
485
  }
360
486
  async deleteMessages(messageIds) {
361
- await this.operations.deleteMany(TABLE_MESSAGES, messageIds);
487
+ await this.#db.deleteMany(TABLE_MESSAGES, messageIds);
362
488
  }
363
489
  async saveResource({ resource }) {
364
490
  const record = {
@@ -369,14 +495,14 @@ var MemoryConvex = class extends MemoryStorage {
369
495
  if (resource.metadata !== void 0) {
370
496
  record.metadata = resource.metadata;
371
497
  }
372
- await this.operations.insert({
498
+ await this.#db.insert({
373
499
  tableName: TABLE_RESOURCES,
374
500
  record
375
501
  });
376
502
  return resource;
377
503
  }
378
504
  async getResourceById({ resourceId }) {
379
- const record = await this.operations.load({
505
+ const record = await this.#db.load({
380
506
  tableName: TABLE_RESOURCES,
381
507
  keys: { id: resourceId }
382
508
  });
@@ -462,12 +588,19 @@ var MemoryConvex = class extends MemoryStorage {
462
588
  }
463
589
  };
464
590
  var ScoresConvex = class extends ScoresStorage {
465
- constructor(operations) {
591
+ #db;
592
+ constructor(config) {
466
593
  super();
467
- this.operations = operations;
594
+ const client = resolveConvexConfig(config);
595
+ this.#db = new ConvexDB(client);
596
+ }
597
+ async init() {
598
+ }
599
+ async dangerouslyClearAll() {
600
+ await this.#db.clearTable({ tableName: TABLE_SCORERS });
468
601
  }
469
602
  async getScoreById({ id }) {
470
- const row = await this.operations.load({
603
+ const row = await this.#db.load({
471
604
  tableName: TABLE_SCORERS,
472
605
  keys: { id }
473
606
  });
@@ -481,7 +614,7 @@ var ScoresConvex = class extends ScoresStorage {
481
614
  createdAt: now.toISOString(),
482
615
  updatedAt: now.toISOString()
483
616
  };
484
- await this.operations.insert({
617
+ await this.#db.insert({
485
618
  tableName: TABLE_SCORERS,
486
619
  record
487
620
  });
@@ -525,14 +658,14 @@ var ScoresConvex = class extends ScoresStorage {
525
658
  if (pagination.page < 0) {
526
659
  throw new MastraError(
527
660
  {
528
- id: "CONVEX_STORAGE_INVALID_PAGINATION",
661
+ id: createStorageErrorId("CONVEX", "LIST_SCORES", "INVALID_PAGINATION"),
529
662
  domain: ErrorDomain.STORAGE,
530
663
  category: ErrorCategory.USER
531
664
  },
532
665
  new Error("page must be >= 0")
533
666
  );
534
667
  }
535
- const rows = await this.operations.queryTable(TABLE_SCORERS, void 0);
668
+ const rows = await this.#db.queryTable(TABLE_SCORERS, void 0);
536
669
  const filtered = rows.filter((row) => filters.scorerId ? row.scorerId === filters.scorerId : true).filter((row) => filters.entityId ? row.entityId === filters.entityId : true).filter((row) => filters.entityType ? row.entityType === filters.entityType : true).filter((row) => filters.runId ? row.runId === filters.runId : true).filter((row) => filters.source ? row.source === filters.source : true).sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime());
537
670
  const { perPage, page } = pagination;
538
671
  const perPageValue = perPage === false ? filtered.length : perPage;
@@ -558,9 +691,16 @@ var ScoresConvex = class extends ScoresStorage {
558
691
  }
559
692
  };
560
693
  var WorkflowsConvex = class extends WorkflowsStorage {
561
- constructor(operations) {
694
+ #db;
695
+ constructor(config) {
562
696
  super();
563
- this.operations = operations;
697
+ const client = resolveConvexConfig(config);
698
+ this.#db = new ConvexDB(client);
699
+ }
700
+ async init() {
701
+ }
702
+ async dangerouslyClearAll() {
703
+ await this.#db.clearTable({ tableName: TABLE_WORKFLOW_SNAPSHOT });
564
704
  }
565
705
  async updateWorkflowResults({
566
706
  workflowName,
@@ -607,11 +747,11 @@ var WorkflowsConvex = class extends WorkflowsStorage {
607
747
  snapshot
608
748
  }) {
609
749
  const now = /* @__PURE__ */ new Date();
610
- const existing = await this.operations.load({
750
+ const existing = await this.#db.load({
611
751
  tableName: TABLE_WORKFLOW_SNAPSHOT,
612
752
  keys: { workflow_name: workflowName, run_id: runId }
613
753
  });
614
- await this.operations.insert({
754
+ await this.#db.insert({
615
755
  tableName: TABLE_WORKFLOW_SNAPSHOT,
616
756
  record: {
617
757
  workflow_name: workflowName,
@@ -627,7 +767,7 @@ var WorkflowsConvex = class extends WorkflowsStorage {
627
767
  workflowName,
628
768
  runId
629
769
  }) {
630
- const row = await this.operations.load({
770
+ const row = await this.#db.load({
631
771
  tableName: TABLE_WORKFLOW_SNAPSHOT,
632
772
  keys: { workflow_name: workflowName, run_id: runId }
633
773
  });
@@ -636,7 +776,7 @@ var WorkflowsConvex = class extends WorkflowsStorage {
636
776
  }
637
777
  async listWorkflowRuns(args = {}) {
638
778
  const { workflowName, fromDate, toDate, perPage, page, resourceId, status } = args;
639
- let rows = await this.operations.queryTable(TABLE_WORKFLOW_SNAPSHOT, void 0);
779
+ let rows = await this.#db.queryTable(TABLE_WORKFLOW_SNAPSHOT, void 0);
640
780
  if (workflowName) rows = rows.filter((run) => run.workflow_name === workflowName);
641
781
  if (resourceId) rows = rows.filter((run) => run.resourceId === resourceId);
642
782
  if (fromDate) rows = rows.filter((run) => new Date(run.createdAt).getTime() >= fromDate.getTime());
@@ -668,7 +808,7 @@ var WorkflowsConvex = class extends WorkflowsStorage {
668
808
  runId,
669
809
  workflowName
670
810
  }) {
671
- const runs = await this.operations.queryTable(TABLE_WORKFLOW_SNAPSHOT, void 0);
811
+ const runs = await this.#db.queryTable(TABLE_WORKFLOW_SNAPSHOT, void 0);
672
812
  const match = runs.find((run) => run.run_id === runId && (!workflowName || run.workflow_name === workflowName));
673
813
  if (!match) return null;
674
814
  return {
@@ -680,8 +820,11 @@ var WorkflowsConvex = class extends WorkflowsStorage {
680
820
  resourceId: match.resourceId
681
821
  };
682
822
  }
823
+ async deleteWorkflowRunById({ runId, workflowName }) {
824
+ await this.#db.deleteMany(TABLE_WORKFLOW_SNAPSHOT, [`${workflowName}-${runId}`]);
825
+ }
683
826
  async getRun(workflowName, runId) {
684
- const runs = await this.operations.queryTable(TABLE_WORKFLOW_SNAPSHOT, [
827
+ const runs = await this.#db.queryTable(TABLE_WORKFLOW_SNAPSHOT, [
685
828
  { field: "workflow_name", value: workflowName }
686
829
  ]);
687
830
  return runs.find((run) => run.run_id === runId) ?? null;
@@ -708,110 +851,20 @@ var WorkflowsConvex = class extends WorkflowsStorage {
708
851
  return JSON.parse(JSON.stringify(run.snapshot));
709
852
  }
710
853
  };
711
- var StoreOperationsConvex = class extends StoreOperations {
712
- constructor(client) {
713
- super();
714
- this.client = client;
715
- }
716
- async hasColumn(_table, _column) {
717
- return true;
718
- }
719
- async createTable(_args) {
720
- }
721
- async clearTable({ tableName }) {
722
- let hasMore = true;
723
- while (hasMore) {
724
- const response = await this.client.callStorageRaw({
725
- op: "clearTable",
726
- tableName
727
- });
728
- hasMore = response.hasMore ?? false;
729
- }
730
- }
731
- async dropTable({ tableName }) {
732
- let hasMore = true;
733
- while (hasMore) {
734
- const response = await this.client.callStorageRaw({
735
- op: "dropTable",
736
- tableName
737
- });
738
- hasMore = response.hasMore ?? false;
739
- }
740
- }
741
- async alterTable(_args) {
742
- }
743
- async insert({ tableName, record }) {
744
- await this.client.callStorage({
745
- op: "insert",
746
- tableName,
747
- record: this.normalizeRecord(tableName, record)
748
- });
749
- }
750
- async batchInsert({ tableName, records }) {
751
- if (records.length === 0) return;
752
- await this.client.callStorage({
753
- op: "batchInsert",
754
- tableName,
755
- records: records.map((record) => this.normalizeRecord(tableName, record))
756
- });
757
- }
758
- async load({ tableName, keys }) {
759
- const result = await this.client.callStorage({
760
- op: "load",
761
- tableName,
762
- keys
763
- });
764
- return result;
765
- }
766
- async queryTable(tableName, filters) {
767
- return this.client.callStorage({
768
- op: "queryTable",
769
- tableName,
770
- filters
771
- });
772
- }
773
- async deleteMany(tableName, ids) {
774
- if (ids.length === 0) return;
775
- await this.client.callStorage({
776
- op: "deleteMany",
777
- tableName,
778
- ids
779
- });
780
- }
781
- normalizeRecord(tableName, record) {
782
- const normalized = { ...record };
783
- if (tableName === TABLE_WORKFLOW_SNAPSHOT && !normalized.id) {
784
- const runId = normalized.run_id || normalized.runId;
785
- const workflowName = normalized.workflow_name || normalized.workflowName;
786
- normalized.id = workflowName ? `${workflowName}-${runId}` : runId;
787
- }
788
- if (!normalized.id) {
789
- normalized.id = crypto.randomUUID();
790
- }
791
- for (const [key, value] of Object.entries(normalized)) {
792
- if (value instanceof Date) {
793
- normalized[key] = value.toISOString();
794
- }
795
- }
796
- return normalized;
797
- }
798
- };
799
854
 
800
855
  // src/storage/index.ts
801
856
  var ConvexStore = class extends MastraStorage {
802
- operations;
803
857
  memory;
804
858
  workflows;
805
859
  scores;
806
860
  constructor(config) {
807
- super({ id: config.id, name: config.name ?? "ConvexStore" });
861
+ super({ id: config.id, name: config.name ?? "ConvexStore", disableInit: config.disableInit });
808
862
  const client = new ConvexAdminClient(config);
809
- this.operations = new StoreOperationsConvex(client);
810
- this.memory = new MemoryConvex(this.operations);
811
- this.workflows = new WorkflowsConvex(this.operations);
812
- this.scores = new ScoresConvex(this.operations);
863
+ const domainConfig = { client };
864
+ this.memory = new MemoryConvex(domainConfig);
865
+ this.workflows = new WorkflowsConvex(domainConfig);
866
+ this.scores = new ScoresConvex(domainConfig);
813
867
  this.stores = {
814
- operations: this.operations,
815
868
  memory: this.memory,
816
869
  workflows: this.workflows,
817
870
  scores: this.scores
@@ -828,25 +881,6 @@ var ConvexStore = class extends MastraStorage {
828
881
  listScoresBySpan: false
829
882
  };
830
883
  }
831
- async createTable(_args) {
832
- }
833
- async clearTable({ tableName }) {
834
- await this.operations.clearTable({ tableName });
835
- }
836
- async dropTable({ tableName }) {
837
- await this.operations.dropTable({ tableName });
838
- }
839
- async alterTable(_args) {
840
- }
841
- async insert({ tableName, record }) {
842
- await this.operations.insert({ tableName, record });
843
- }
844
- async batchInsert({ tableName, records }) {
845
- await this.operations.batchInsert({ tableName, records });
846
- }
847
- async load({ tableName, keys }) {
848
- return this.operations.load({ tableName, keys });
849
- }
850
884
  async getThreadById({ threadId }) {
851
885
  return this.memory.getThreadById({ threadId });
852
886
  }
@@ -925,6 +959,9 @@ var ConvexStore = class extends MastraStorage {
925
959
  }) {
926
960
  return this.workflows.getWorkflowRunById({ runId, workflowName });
927
961
  }
962
+ async deleteWorkflowRunById({ runId, workflowName }) {
963
+ return this.workflows.deleteWorkflowRunById({ runId, workflowName });
964
+ }
928
965
  async getScoreById({ id }) {
929
966
  return this.scores.getScoreById({ id });
930
967
  }