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

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.cjs CHANGED
@@ -1,10 +1,12 @@
1
1
  'use strict';
2
2
 
3
- var chunkQKN2PWR2_cjs = require('./chunk-QKN2PWR2.cjs');
3
+ var chunkBKVR7SL7_cjs = require('./chunk-BKVR7SL7.cjs');
4
+ var chunkZBUP3DS6_cjs = require('./chunk-ZBUP3DS6.cjs');
4
5
  var storage = require('@mastra/core/storage');
5
6
  var agent = require('@mastra/core/agent');
6
7
  var error = require('@mastra/core/error');
7
8
  var crypto = require('crypto');
9
+ var base = require('@mastra/core/base');
8
10
  var vector = require('@mastra/core/vector');
9
11
 
10
12
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
@@ -74,13 +76,114 @@ var ConvexAdminClient = class {
74
76
  return result;
75
77
  }
76
78
  };
79
+ function resolveConvexConfig(config) {
80
+ if ("client" in config) {
81
+ return config.client;
82
+ }
83
+ return new ConvexAdminClient(config);
84
+ }
85
+ var ConvexDB = class extends base.MastraBase {
86
+ constructor(client) {
87
+ super({ name: "convex-db" });
88
+ this.client = client;
89
+ }
90
+ async hasColumn(_table, _column) {
91
+ return true;
92
+ }
93
+ async clearTable({ tableName }) {
94
+ let hasMore = true;
95
+ while (hasMore) {
96
+ const response = await this.client.callStorageRaw({
97
+ op: "clearTable",
98
+ tableName
99
+ });
100
+ hasMore = response.hasMore ?? false;
101
+ }
102
+ }
103
+ async dropTable({ tableName }) {
104
+ let hasMore = true;
105
+ while (hasMore) {
106
+ const response = await this.client.callStorageRaw({
107
+ op: "dropTable",
108
+ tableName
109
+ });
110
+ hasMore = response.hasMore ?? false;
111
+ }
112
+ }
113
+ async insert({ tableName, record }) {
114
+ await this.client.callStorage({
115
+ op: "insert",
116
+ tableName,
117
+ record: this.normalizeRecord(tableName, record)
118
+ });
119
+ }
120
+ async batchInsert({ tableName, records }) {
121
+ if (records.length === 0) return;
122
+ await this.client.callStorage({
123
+ op: "batchInsert",
124
+ tableName,
125
+ records: records.map((record) => this.normalizeRecord(tableName, record))
126
+ });
127
+ }
128
+ async load({ tableName, keys }) {
129
+ const result = await this.client.callStorage({
130
+ op: "load",
131
+ tableName,
132
+ keys
133
+ });
134
+ return result;
135
+ }
136
+ async queryTable(tableName, filters) {
137
+ return this.client.callStorage({
138
+ op: "queryTable",
139
+ tableName,
140
+ filters
141
+ });
142
+ }
143
+ async deleteMany(tableName, ids) {
144
+ if (ids.length === 0) return;
145
+ await this.client.callStorage({
146
+ op: "deleteMany",
147
+ tableName,
148
+ ids
149
+ });
150
+ }
151
+ normalizeRecord(tableName, record) {
152
+ const normalized = { ...record };
153
+ if (tableName === storage.TABLE_WORKFLOW_SNAPSHOT && !normalized.id) {
154
+ const runId = normalized.run_id || normalized.runId;
155
+ const workflowName = normalized.workflow_name || normalized.workflowName;
156
+ normalized.id = workflowName ? `${workflowName}-${runId}` : runId;
157
+ }
158
+ if (!normalized.id) {
159
+ normalized.id = crypto__default.default.randomUUID();
160
+ }
161
+ for (const [key, value] of Object.entries(normalized)) {
162
+ if (value instanceof Date) {
163
+ normalized[key] = value.toISOString();
164
+ }
165
+ }
166
+ return normalized;
167
+ }
168
+ };
169
+
170
+ // src/storage/domains/memory/index.ts
77
171
  var MemoryConvex = class extends storage.MemoryStorage {
78
- constructor(operations) {
172
+ #db;
173
+ constructor(config) {
79
174
  super();
80
- this.operations = operations;
175
+ const client = resolveConvexConfig(config);
176
+ this.#db = new ConvexDB(client);
177
+ }
178
+ async init() {
179
+ }
180
+ async dangerouslyClearAll() {
181
+ await this.#db.clearTable({ tableName: storage.TABLE_THREADS });
182
+ await this.#db.clearTable({ tableName: storage.TABLE_MESSAGES });
183
+ await this.#db.clearTable({ tableName: storage.TABLE_RESOURCES });
81
184
  }
82
185
  async getThreadById({ threadId }) {
83
- const row = await this.operations.load({
186
+ const row = await this.#db.load({
84
187
  tableName: storage.TABLE_THREADS,
85
188
  keys: { id: threadId }
86
189
  });
@@ -93,7 +196,7 @@ var MemoryConvex = class extends storage.MemoryStorage {
93
196
  };
94
197
  }
95
198
  async saveThread({ thread }) {
96
- await this.operations.insert({
199
+ await this.#db.insert({
97
200
  tableName: storage.TABLE_THREADS,
98
201
  record: {
99
202
  ...thread,
@@ -110,7 +213,7 @@ var MemoryConvex = class extends storage.MemoryStorage {
110
213
  const existing = await this.getThreadById({ threadId: id });
111
214
  if (!existing) {
112
215
  throw new error.MastraError({
113
- id: "CONVEX_STORAGE_THREAD_NOT_FOUND",
216
+ id: storage.createStorageErrorId("CONVEX", "UPDATE_THREAD", "THREAD_NOT_FOUND"),
114
217
  domain: error.ErrorDomain.STORAGE,
115
218
  category: error.ErrorCategory.USER,
116
219
  text: `Thread ${id} not found`
@@ -129,21 +232,21 @@ var MemoryConvex = class extends storage.MemoryStorage {
129
232
  return updated;
130
233
  }
131
234
  async deleteThread({ threadId }) {
132
- const messages = await this.operations.queryTable(storage.TABLE_MESSAGES, [
235
+ const messages = await this.#db.queryTable(storage.TABLE_MESSAGES, [
133
236
  { field: "thread_id", value: threadId }
134
237
  ]);
135
- await this.operations.deleteMany(
238
+ await this.#db.deleteMany(
136
239
  storage.TABLE_MESSAGES,
137
240
  messages.map((msg) => msg.id)
138
241
  );
139
- await this.operations.deleteMany(storage.TABLE_THREADS, [threadId]);
242
+ await this.#db.deleteMany(storage.TABLE_THREADS, [threadId]);
140
243
  }
141
244
  async listThreadsByResourceId(args) {
142
245
  const { resourceId, page = 0, perPage: perPageInput, orderBy } = args;
143
246
  const perPage = storage.normalizePerPage(perPageInput, 100);
144
247
  const { field, direction } = this.parseOrderBy(orderBy);
145
248
  const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
146
- const rows = await this.operations.queryTable(storage.TABLE_THREADS, [{ field: "resourceId", value: resourceId }]);
249
+ const rows = await this.#db.queryTable(storage.TABLE_THREADS, [{ field: "resourceId", value: resourceId }]);
147
250
  const threads = rows.map((row) => ({
148
251
  ...row,
149
252
  metadata: typeof row.metadata === "string" ? JSON.parse(row.metadata) : row.metadata,
@@ -169,23 +272,26 @@ var MemoryConvex = class extends storage.MemoryStorage {
169
272
  }
170
273
  async listMessages(args) {
171
274
  const { threadId, resourceId, include, filter, perPage: perPageInput, page = 0, orderBy } = args;
172
- if (!threadId.trim()) {
275
+ const threadIds = Array.isArray(threadId) ? threadId : [threadId];
276
+ if (threadIds.length === 0 || threadIds.some((id) => !id.trim())) {
173
277
  throw new error.MastraError(
174
278
  {
175
- id: "CONVEX_STORAGE_LIST_MESSAGES_INVALID_THREAD_ID",
279
+ id: storage.createStorageErrorId("CONVEX", "LIST_MESSAGES", "INVALID_THREAD_ID"),
176
280
  domain: error.ErrorDomain.STORAGE,
177
281
  category: error.ErrorCategory.USER,
178
- details: { threadId }
282
+ details: { threadId: Array.isArray(threadId) ? threadId.join(",") : threadId }
179
283
  },
180
- new Error("threadId must be a non-empty string")
284
+ new Error("threadId must be a non-empty string or array of non-empty strings")
181
285
  );
182
286
  }
183
287
  const perPage = storage.normalizePerPage(perPageInput, 40);
184
288
  const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
185
289
  const { field, direction } = this.parseOrderBy(orderBy, "ASC");
186
- let rows = await this.operations.queryTable(storage.TABLE_MESSAGES, [
187
- { field: "thread_id", value: threadId }
188
- ]);
290
+ let rows = [];
291
+ for (const tid of threadIds) {
292
+ const threadRows = await this.#db.queryTable(storage.TABLE_MESSAGES, [{ field: "thread_id", value: tid }]);
293
+ rows.push(...threadRows);
294
+ }
189
295
  if (resourceId) {
190
296
  rows = rows.filter((row) => row.resourceId === resourceId);
191
297
  }
@@ -212,21 +318,41 @@ var MemoryConvex = class extends storage.MemoryStorage {
212
318
  const messageIds = new Set(messages.map((msg) => msg.id));
213
319
  if (include && include.length > 0) {
214
320
  const threadMessagesCache = /* @__PURE__ */ new Map();
215
- threadMessagesCache.set(threadId, rows);
321
+ for (const tid of threadIds) {
322
+ const tidRows = rows.filter((r) => r.thread_id === tid);
323
+ threadMessagesCache.set(tid, tidRows);
324
+ }
216
325
  for (const includeItem of include) {
217
- const targetThreadId = includeItem.threadId || threadId;
218
- if (!threadMessagesCache.has(targetThreadId)) {
219
- const otherThreadRows = await this.operations.queryTable(storage.TABLE_MESSAGES, [
220
- { field: "thread_id", value: targetThreadId }
326
+ let targetThreadId;
327
+ let target;
328
+ for (const [tid, cachedRows] of threadMessagesCache) {
329
+ target = cachedRows.find((row) => row.id === includeItem.id);
330
+ if (target) {
331
+ targetThreadId = tid;
332
+ break;
333
+ }
334
+ }
335
+ if (!target) {
336
+ const messageRows = await this.#db.queryTable(storage.TABLE_MESSAGES, [
337
+ { field: "id", value: includeItem.id }
221
338
  ]);
222
- threadMessagesCache.set(targetThreadId, otherThreadRows);
339
+ if (messageRows.length > 0) {
340
+ target = messageRows[0];
341
+ targetThreadId = target.thread_id;
342
+ if (targetThreadId && !threadMessagesCache.has(targetThreadId)) {
343
+ const otherThreadRows = await this.#db.queryTable(storage.TABLE_MESSAGES, [
344
+ { field: "thread_id", value: targetThreadId }
345
+ ]);
346
+ threadMessagesCache.set(targetThreadId, otherThreadRows);
347
+ }
348
+ }
223
349
  }
224
- const targetThreadRows = threadMessagesCache.get(targetThreadId) || [];
225
- const target = targetThreadRows.find((row) => row.id === includeItem.id);
226
- if (target && !messageIds.has(target.id)) {
350
+ if (!target || !targetThreadId) continue;
351
+ if (!messageIds.has(target.id)) {
227
352
  messages.push(this.parseStoredMessage(target));
228
353
  messageIds.add(target.id);
229
354
  }
355
+ const targetThreadRows = threadMessagesCache.get(targetThreadId) || [];
230
356
  await this.addContextMessages({
231
357
  includeItem,
232
358
  allMessages: targetThreadRows,
@@ -257,7 +383,7 @@ var MemoryConvex = class extends storage.MemoryStorage {
257
383
  if (messageIds.length === 0) {
258
384
  return { messages: [] };
259
385
  }
260
- const rows = await this.operations.queryTable(storage.TABLE_MESSAGES, void 0);
386
+ const rows = await this.#db.queryTable(storage.TABLE_MESSAGES, void 0);
261
387
  const filtered = rows.filter((row) => messageIds.includes(row.id)).map((row) => this.parseStoredMessage(row));
262
388
  const list = new agent.MessageList().add(filtered, "memory");
263
389
  return { messages: list.get.all.db() };
@@ -282,7 +408,7 @@ var MemoryConvex = class extends storage.MemoryStorage {
282
408
  resourceId: message.resourceId
283
409
  };
284
410
  });
285
- await this.operations.batchInsert({
411
+ await this.#db.batchInsert({
286
412
  tableName: storage.TABLE_MESSAGES,
287
413
  records: normalized
288
414
  });
@@ -291,7 +417,7 @@ var MemoryConvex = class extends storage.MemoryStorage {
291
417
  for (const threadId of threadIds) {
292
418
  const thread = await this.getThreadById({ threadId });
293
419
  if (thread) {
294
- await this.operations.insert({
420
+ await this.#db.insert({
295
421
  tableName: storage.TABLE_THREADS,
296
422
  record: {
297
423
  ...thread,
@@ -310,7 +436,7 @@ var MemoryConvex = class extends storage.MemoryStorage {
310
436
  messages
311
437
  }) {
312
438
  if (messages.length === 0) return [];
313
- const existing = await this.operations.queryTable(storage.TABLE_MESSAGES, void 0);
439
+ const existing = await this.#db.queryTable(storage.TABLE_MESSAGES, void 0);
314
440
  const updated = [];
315
441
  const affectedThreadIds = /* @__PURE__ */ new Set();
316
442
  for (const update of messages) {
@@ -339,7 +465,7 @@ var MemoryConvex = class extends storage.MemoryStorage {
339
465
  };
340
466
  current.content = JSON.stringify(mergedContent);
341
467
  }
342
- await this.operations.insert({
468
+ await this.#db.insert({
343
469
  tableName: storage.TABLE_MESSAGES,
344
470
  record: current
345
471
  });
@@ -349,7 +475,7 @@ var MemoryConvex = class extends storage.MemoryStorage {
349
475
  for (const threadId of affectedThreadIds) {
350
476
  const thread = await this.getThreadById({ threadId });
351
477
  if (thread) {
352
- await this.operations.insert({
478
+ await this.#db.insert({
353
479
  tableName: storage.TABLE_THREADS,
354
480
  record: {
355
481
  ...thread,
@@ -364,7 +490,7 @@ var MemoryConvex = class extends storage.MemoryStorage {
364
490
  return updated;
365
491
  }
366
492
  async deleteMessages(messageIds) {
367
- await this.operations.deleteMany(storage.TABLE_MESSAGES, messageIds);
493
+ await this.#db.deleteMany(storage.TABLE_MESSAGES, messageIds);
368
494
  }
369
495
  async saveResource({ resource }) {
370
496
  const record = {
@@ -375,14 +501,14 @@ var MemoryConvex = class extends storage.MemoryStorage {
375
501
  if (resource.metadata !== void 0) {
376
502
  record.metadata = resource.metadata;
377
503
  }
378
- await this.operations.insert({
504
+ await this.#db.insert({
379
505
  tableName: storage.TABLE_RESOURCES,
380
506
  record
381
507
  });
382
508
  return resource;
383
509
  }
384
510
  async getResourceById({ resourceId }) {
385
- const record = await this.operations.load({
511
+ const record = await this.#db.load({
386
512
  tableName: storage.TABLE_RESOURCES,
387
513
  keys: { id: resourceId }
388
514
  });
@@ -468,12 +594,19 @@ var MemoryConvex = class extends storage.MemoryStorage {
468
594
  }
469
595
  };
470
596
  var ScoresConvex = class extends storage.ScoresStorage {
471
- constructor(operations) {
597
+ #db;
598
+ constructor(config) {
472
599
  super();
473
- this.operations = operations;
600
+ const client = resolveConvexConfig(config);
601
+ this.#db = new ConvexDB(client);
602
+ }
603
+ async init() {
604
+ }
605
+ async dangerouslyClearAll() {
606
+ await this.#db.clearTable({ tableName: storage.TABLE_SCORERS });
474
607
  }
475
608
  async getScoreById({ id }) {
476
- const row = await this.operations.load({
609
+ const row = await this.#db.load({
477
610
  tableName: storage.TABLE_SCORERS,
478
611
  keys: { id }
479
612
  });
@@ -487,7 +620,7 @@ var ScoresConvex = class extends storage.ScoresStorage {
487
620
  createdAt: now.toISOString(),
488
621
  updatedAt: now.toISOString()
489
622
  };
490
- await this.operations.insert({
623
+ await this.#db.insert({
491
624
  tableName: storage.TABLE_SCORERS,
492
625
  record
493
626
  });
@@ -531,14 +664,14 @@ var ScoresConvex = class extends storage.ScoresStorage {
531
664
  if (pagination.page < 0) {
532
665
  throw new error.MastraError(
533
666
  {
534
- id: "CONVEX_STORAGE_INVALID_PAGINATION",
667
+ id: storage.createStorageErrorId("CONVEX", "LIST_SCORES", "INVALID_PAGINATION"),
535
668
  domain: error.ErrorDomain.STORAGE,
536
669
  category: error.ErrorCategory.USER
537
670
  },
538
671
  new Error("page must be >= 0")
539
672
  );
540
673
  }
541
- const rows = await this.operations.queryTable(storage.TABLE_SCORERS, void 0);
674
+ const rows = await this.#db.queryTable(storage.TABLE_SCORERS, void 0);
542
675
  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());
543
676
  const { perPage, page } = pagination;
544
677
  const perPageValue = perPage === false ? filtered.length : perPage;
@@ -564,9 +697,16 @@ var ScoresConvex = class extends storage.ScoresStorage {
564
697
  }
565
698
  };
566
699
  var WorkflowsConvex = class extends storage.WorkflowsStorage {
567
- constructor(operations) {
700
+ #db;
701
+ constructor(config) {
568
702
  super();
569
- this.operations = operations;
703
+ const client = resolveConvexConfig(config);
704
+ this.#db = new ConvexDB(client);
705
+ }
706
+ async init() {
707
+ }
708
+ async dangerouslyClearAll() {
709
+ await this.#db.clearTable({ tableName: storage.TABLE_WORKFLOW_SNAPSHOT });
570
710
  }
571
711
  async updateWorkflowResults({
572
712
  workflowName,
@@ -613,11 +753,11 @@ var WorkflowsConvex = class extends storage.WorkflowsStorage {
613
753
  snapshot
614
754
  }) {
615
755
  const now = /* @__PURE__ */ new Date();
616
- const existing = await this.operations.load({
756
+ const existing = await this.#db.load({
617
757
  tableName: storage.TABLE_WORKFLOW_SNAPSHOT,
618
758
  keys: { workflow_name: workflowName, run_id: runId }
619
759
  });
620
- await this.operations.insert({
760
+ await this.#db.insert({
621
761
  tableName: storage.TABLE_WORKFLOW_SNAPSHOT,
622
762
  record: {
623
763
  workflow_name: workflowName,
@@ -633,7 +773,7 @@ var WorkflowsConvex = class extends storage.WorkflowsStorage {
633
773
  workflowName,
634
774
  runId
635
775
  }) {
636
- const row = await this.operations.load({
776
+ const row = await this.#db.load({
637
777
  tableName: storage.TABLE_WORKFLOW_SNAPSHOT,
638
778
  keys: { workflow_name: workflowName, run_id: runId }
639
779
  });
@@ -642,7 +782,7 @@ var WorkflowsConvex = class extends storage.WorkflowsStorage {
642
782
  }
643
783
  async listWorkflowRuns(args = {}) {
644
784
  const { workflowName, fromDate, toDate, perPage, page, resourceId, status } = args;
645
- let rows = await this.operations.queryTable(storage.TABLE_WORKFLOW_SNAPSHOT, void 0);
785
+ let rows = await this.#db.queryTable(storage.TABLE_WORKFLOW_SNAPSHOT, void 0);
646
786
  if (workflowName) rows = rows.filter((run) => run.workflow_name === workflowName);
647
787
  if (resourceId) rows = rows.filter((run) => run.resourceId === resourceId);
648
788
  if (fromDate) rows = rows.filter((run) => new Date(run.createdAt).getTime() >= fromDate.getTime());
@@ -674,7 +814,7 @@ var WorkflowsConvex = class extends storage.WorkflowsStorage {
674
814
  runId,
675
815
  workflowName
676
816
  }) {
677
- const runs = await this.operations.queryTable(storage.TABLE_WORKFLOW_SNAPSHOT, void 0);
817
+ const runs = await this.#db.queryTable(storage.TABLE_WORKFLOW_SNAPSHOT, void 0);
678
818
  const match = runs.find((run) => run.run_id === runId && (!workflowName || run.workflow_name === workflowName));
679
819
  if (!match) return null;
680
820
  return {
@@ -686,8 +826,11 @@ var WorkflowsConvex = class extends storage.WorkflowsStorage {
686
826
  resourceId: match.resourceId
687
827
  };
688
828
  }
829
+ async deleteWorkflowRunById({ runId, workflowName }) {
830
+ await this.#db.deleteMany(storage.TABLE_WORKFLOW_SNAPSHOT, [`${workflowName}-${runId}`]);
831
+ }
689
832
  async getRun(workflowName, runId) {
690
- const runs = await this.operations.queryTable(storage.TABLE_WORKFLOW_SNAPSHOT, [
833
+ const runs = await this.#db.queryTable(storage.TABLE_WORKFLOW_SNAPSHOT, [
691
834
  { field: "workflow_name", value: workflowName }
692
835
  ]);
693
836
  return runs.find((run) => run.run_id === runId) ?? null;
@@ -714,110 +857,20 @@ var WorkflowsConvex = class extends storage.WorkflowsStorage {
714
857
  return JSON.parse(JSON.stringify(run.snapshot));
715
858
  }
716
859
  };
717
- var StoreOperationsConvex = class extends storage.StoreOperations {
718
- constructor(client) {
719
- super();
720
- this.client = client;
721
- }
722
- async hasColumn(_table, _column) {
723
- return true;
724
- }
725
- async createTable(_args) {
726
- }
727
- async clearTable({ tableName }) {
728
- let hasMore = true;
729
- while (hasMore) {
730
- const response = await this.client.callStorageRaw({
731
- op: "clearTable",
732
- tableName
733
- });
734
- hasMore = response.hasMore ?? false;
735
- }
736
- }
737
- async dropTable({ tableName }) {
738
- let hasMore = true;
739
- while (hasMore) {
740
- const response = await this.client.callStorageRaw({
741
- op: "dropTable",
742
- tableName
743
- });
744
- hasMore = response.hasMore ?? false;
745
- }
746
- }
747
- async alterTable(_args) {
748
- }
749
- async insert({ tableName, record }) {
750
- await this.client.callStorage({
751
- op: "insert",
752
- tableName,
753
- record: this.normalizeRecord(tableName, record)
754
- });
755
- }
756
- async batchInsert({ tableName, records }) {
757
- if (records.length === 0) return;
758
- await this.client.callStorage({
759
- op: "batchInsert",
760
- tableName,
761
- records: records.map((record) => this.normalizeRecord(tableName, record))
762
- });
763
- }
764
- async load({ tableName, keys }) {
765
- const result = await this.client.callStorage({
766
- op: "load",
767
- tableName,
768
- keys
769
- });
770
- return result;
771
- }
772
- async queryTable(tableName, filters) {
773
- return this.client.callStorage({
774
- op: "queryTable",
775
- tableName,
776
- filters
777
- });
778
- }
779
- async deleteMany(tableName, ids) {
780
- if (ids.length === 0) return;
781
- await this.client.callStorage({
782
- op: "deleteMany",
783
- tableName,
784
- ids
785
- });
786
- }
787
- normalizeRecord(tableName, record) {
788
- const normalized = { ...record };
789
- if (tableName === storage.TABLE_WORKFLOW_SNAPSHOT && !normalized.id) {
790
- const runId = normalized.run_id || normalized.runId;
791
- const workflowName = normalized.workflow_name || normalized.workflowName;
792
- normalized.id = workflowName ? `${workflowName}-${runId}` : runId;
793
- }
794
- if (!normalized.id) {
795
- normalized.id = crypto__default.default.randomUUID();
796
- }
797
- for (const [key, value] of Object.entries(normalized)) {
798
- if (value instanceof Date) {
799
- normalized[key] = value.toISOString();
800
- }
801
- }
802
- return normalized;
803
- }
804
- };
805
860
 
806
861
  // src/storage/index.ts
807
862
  var ConvexStore = class extends storage.MastraStorage {
808
- operations;
809
863
  memory;
810
864
  workflows;
811
865
  scores;
812
866
  constructor(config) {
813
- super({ id: config.id, name: config.name ?? "ConvexStore" });
867
+ super({ id: config.id, name: config.name ?? "ConvexStore", disableInit: config.disableInit });
814
868
  const client = new ConvexAdminClient(config);
815
- this.operations = new StoreOperationsConvex(client);
816
- this.memory = new MemoryConvex(this.operations);
817
- this.workflows = new WorkflowsConvex(this.operations);
818
- this.scores = new ScoresConvex(this.operations);
869
+ const domainConfig = { client };
870
+ this.memory = new MemoryConvex(domainConfig);
871
+ this.workflows = new WorkflowsConvex(domainConfig);
872
+ this.scores = new ScoresConvex(domainConfig);
819
873
  this.stores = {
820
- operations: this.operations,
821
874
  memory: this.memory,
822
875
  workflows: this.workflows,
823
876
  scores: this.scores
@@ -834,25 +887,6 @@ var ConvexStore = class extends storage.MastraStorage {
834
887
  listScoresBySpan: false
835
888
  };
836
889
  }
837
- async createTable(_args) {
838
- }
839
- async clearTable({ tableName }) {
840
- await this.operations.clearTable({ tableName });
841
- }
842
- async dropTable({ tableName }) {
843
- await this.operations.dropTable({ tableName });
844
- }
845
- async alterTable(_args) {
846
- }
847
- async insert({ tableName, record }) {
848
- await this.operations.insert({ tableName, record });
849
- }
850
- async batchInsert({ tableName, records }) {
851
- await this.operations.batchInsert({ tableName, records });
852
- }
853
- async load({ tableName, keys }) {
854
- return this.operations.load({ tableName, keys });
855
- }
856
890
  async getThreadById({ threadId }) {
857
891
  return this.memory.getThreadById({ threadId });
858
892
  }
@@ -931,6 +965,9 @@ var ConvexStore = class extends storage.MastraStorage {
931
965
  }) {
932
966
  return this.workflows.getWorkflowRunById({ runId, workflowName });
933
967
  }
968
+ async deleteWorkflowRunById({ runId, workflowName }) {
969
+ return this.workflows.deleteWorkflowRunById({ runId, workflowName });
970
+ }
934
971
  async getScoreById({ id }) {
935
972
  return this.scores.getScoreById({ id });
936
973
  }
@@ -1263,61 +1300,61 @@ function cosineSimilarity(a, b) {
1263
1300
  return dot / (Math.sqrt(magA) * Math.sqrt(magB));
1264
1301
  }
1265
1302
 
1303
+ Object.defineProperty(exports, "mastraStorage", {
1304
+ enumerable: true,
1305
+ get: function () { return chunkBKVR7SL7_cjs.mastraStorage; }
1306
+ });
1266
1307
  Object.defineProperty(exports, "TABLE_MESSAGES", {
1267
1308
  enumerable: true,
1268
- get: function () { return chunkQKN2PWR2_cjs.TABLE_MESSAGES; }
1309
+ get: function () { return chunkZBUP3DS6_cjs.TABLE_MESSAGES; }
1269
1310
  });
1270
1311
  Object.defineProperty(exports, "TABLE_RESOURCES", {
1271
1312
  enumerable: true,
1272
- get: function () { return chunkQKN2PWR2_cjs.TABLE_RESOURCES; }
1313
+ get: function () { return chunkZBUP3DS6_cjs.TABLE_RESOURCES; }
1273
1314
  });
1274
1315
  Object.defineProperty(exports, "TABLE_SCORERS", {
1275
1316
  enumerable: true,
1276
- get: function () { return chunkQKN2PWR2_cjs.TABLE_SCORERS; }
1317
+ get: function () { return chunkZBUP3DS6_cjs.TABLE_SCORERS; }
1277
1318
  });
1278
1319
  Object.defineProperty(exports, "TABLE_THREADS", {
1279
1320
  enumerable: true,
1280
- get: function () { return chunkQKN2PWR2_cjs.TABLE_THREADS; }
1321
+ get: function () { return chunkZBUP3DS6_cjs.TABLE_THREADS; }
1281
1322
  });
1282
1323
  Object.defineProperty(exports, "TABLE_WORKFLOW_SNAPSHOT", {
1283
1324
  enumerable: true,
1284
- get: function () { return chunkQKN2PWR2_cjs.TABLE_WORKFLOW_SNAPSHOT; }
1325
+ get: function () { return chunkZBUP3DS6_cjs.TABLE_WORKFLOW_SNAPSHOT; }
1285
1326
  });
1286
1327
  Object.defineProperty(exports, "mastraDocumentsTable", {
1287
1328
  enumerable: true,
1288
- get: function () { return chunkQKN2PWR2_cjs.mastraDocumentsTable; }
1329
+ get: function () { return chunkZBUP3DS6_cjs.mastraDocumentsTable; }
1289
1330
  });
1290
1331
  Object.defineProperty(exports, "mastraMessagesTable", {
1291
1332
  enumerable: true,
1292
- get: function () { return chunkQKN2PWR2_cjs.mastraMessagesTable; }
1333
+ get: function () { return chunkZBUP3DS6_cjs.mastraMessagesTable; }
1293
1334
  });
1294
1335
  Object.defineProperty(exports, "mastraResourcesTable", {
1295
1336
  enumerable: true,
1296
- get: function () { return chunkQKN2PWR2_cjs.mastraResourcesTable; }
1337
+ get: function () { return chunkZBUP3DS6_cjs.mastraResourcesTable; }
1297
1338
  });
1298
1339
  Object.defineProperty(exports, "mastraScoresTable", {
1299
1340
  enumerable: true,
1300
- get: function () { return chunkQKN2PWR2_cjs.mastraScoresTable; }
1301
- });
1302
- Object.defineProperty(exports, "mastraStorage", {
1303
- enumerable: true,
1304
- get: function () { return chunkQKN2PWR2_cjs.mastraStorage; }
1341
+ get: function () { return chunkZBUP3DS6_cjs.mastraScoresTable; }
1305
1342
  });
1306
1343
  Object.defineProperty(exports, "mastraThreadsTable", {
1307
1344
  enumerable: true,
1308
- get: function () { return chunkQKN2PWR2_cjs.mastraThreadsTable; }
1345
+ get: function () { return chunkZBUP3DS6_cjs.mastraThreadsTable; }
1309
1346
  });
1310
1347
  Object.defineProperty(exports, "mastraVectorIndexesTable", {
1311
1348
  enumerable: true,
1312
- get: function () { return chunkQKN2PWR2_cjs.mastraVectorIndexesTable; }
1349
+ get: function () { return chunkZBUP3DS6_cjs.mastraVectorIndexesTable; }
1313
1350
  });
1314
1351
  Object.defineProperty(exports, "mastraVectorsTable", {
1315
1352
  enumerable: true,
1316
- get: function () { return chunkQKN2PWR2_cjs.mastraVectorsTable; }
1353
+ get: function () { return chunkZBUP3DS6_cjs.mastraVectorsTable; }
1317
1354
  });
1318
1355
  Object.defineProperty(exports, "mastraWorkflowSnapshotsTable", {
1319
1356
  enumerable: true,
1320
- get: function () { return chunkQKN2PWR2_cjs.mastraWorkflowSnapshotsTable; }
1357
+ get: function () { return chunkZBUP3DS6_cjs.mastraWorkflowSnapshotsTable; }
1321
1358
  });
1322
1359
  exports.ConvexStore = ConvexStore;
1323
1360
  exports.ConvexVector = ConvexVector;