@mastra/convex 0.0.0-top-level-fix-20251211111608 → 0.0.0-type-testing-20260120105120

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 (48) hide show
  1. package/CHANGELOG.md +754 -5
  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-H5QJE733.cjs +104 -0
  6. package/dist/chunk-H5QJE733.cjs.map +1 -0
  7. package/dist/chunk-HXB4DWFE.js +73 -0
  8. package/dist/chunk-HXB4DWFE.js.map +1 -0
  9. package/dist/{chunk-NZCHEPNU.js → chunk-KSAPIIEJ.js} +5 -65
  10. package/dist/chunk-KSAPIIEJ.js.map +1 -0
  11. package/dist/docs/README.md +32 -0
  12. package/dist/docs/SKILL.md +46 -0
  13. package/dist/docs/SOURCE_MAP.json +63 -0
  14. package/dist/docs/storage/01-reference.md +140 -0
  15. package/dist/docs/vectors/01-reference.md +240 -0
  16. package/dist/index.cjs +208 -306
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.js +192 -290
  19. package/dist/index.js.map +1 -1
  20. package/dist/schema.cjs +72 -0
  21. package/dist/schema.cjs.map +1 -0
  22. package/dist/{server/schema.d.ts → schema.d.ts} +14 -1
  23. package/dist/schema.d.ts.map +1 -0
  24. package/dist/schema.js +3 -0
  25. package/dist/schema.js.map +1 -0
  26. package/dist/server/index.cjs +19 -18
  27. package/dist/server/index.d.ts +1 -1
  28. package/dist/server/index.d.ts.map +1 -1
  29. package/dist/server/index.js +2 -1
  30. package/dist/storage/db/index.d.ts +57 -0
  31. package/dist/storage/db/index.d.ts.map +1 -0
  32. package/dist/storage/domains/{memory.d.ts → memory/index.d.ts} +8 -6
  33. package/dist/storage/domains/memory/index.d.ts.map +1 -0
  34. package/dist/storage/domains/{scores.d.ts → scores/index.d.ts} +11 -18
  35. package/dist/storage/domains/scores/index.d.ts.map +1 -0
  36. package/dist/storage/domains/{workflows.d.ts → workflows/index.d.ts} +9 -13
  37. package/dist/storage/domains/workflows/index.d.ts.map +1 -0
  38. package/dist/storage/index.d.ts +54 -157
  39. package/dist/storage/index.d.ts.map +1 -1
  40. package/package.json +19 -9
  41. package/dist/chunk-NZCHEPNU.js.map +0 -1
  42. package/dist/chunk-QKN2PWR2.cjs.map +0 -1
  43. package/dist/server/schema.d.ts.map +0 -1
  44. package/dist/storage/domains/memory.d.ts.map +0 -1
  45. package/dist/storage/domains/scores.d.ts.map +0 -1
  46. package/dist/storage/domains/workflows.d.ts.map +0 -1
  47. package/dist/storage/operations.d.ts +0 -40
  48. 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, createStorageErrorId, 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-HXB4DWFE.js';
3
+ import { MastraStorage, MemoryStorage, TABLE_THREADS, TABLE_MESSAGES, TABLE_RESOURCES, createStorageErrorId, normalizePerPage, calculatePagination, filterByDateRange, 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,
@@ -123,27 +226,50 @@ 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
- async listThreadsByResourceId(args) {
136
- const { resourceId, page = 0, perPage: perPageInput, orderBy } = args;
238
+ async listThreads(args) {
239
+ const { page = 0, perPage: perPageInput, orderBy, filter } = args;
240
+ try {
241
+ this.validatePaginationInput(page, perPageInput ?? 100);
242
+ } catch (error) {
243
+ throw new MastraError(
244
+ {
245
+ id: createStorageErrorId("CONVEX", "LIST_THREADS", "INVALID_PAGE"),
246
+ domain: ErrorDomain.STORAGE,
247
+ category: ErrorCategory.USER,
248
+ details: { page, ...perPageInput !== void 0 && { perPage: perPageInput } }
249
+ },
250
+ error instanceof Error ? error : new Error("Invalid pagination parameters")
251
+ );
252
+ }
137
253
  const perPage = normalizePerPage(perPageInput, 100);
138
254
  const { field, direction } = this.parseOrderBy(orderBy);
139
255
  const { offset, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
140
- const rows = await this.operations.queryTable(TABLE_THREADS, [{ field: "resourceId", value: resourceId }]);
141
- const threads = rows.map((row) => ({
256
+ const queryFilters = [];
257
+ if (filter?.resourceId) {
258
+ queryFilters.push({ field: "resourceId", value: filter.resourceId });
259
+ }
260
+ const rows = await this.#db.queryTable(TABLE_THREADS, queryFilters);
261
+ let threads = rows.map((row) => ({
142
262
  ...row,
143
263
  metadata: typeof row.metadata === "string" ? JSON.parse(row.metadata) : row.metadata,
144
264
  createdAt: new Date(row.createdAt),
145
265
  updatedAt: new Date(row.updatedAt)
146
266
  }));
267
+ if (filter?.metadata && Object.keys(filter.metadata).length > 0) {
268
+ threads = threads.filter((thread) => {
269
+ if (!thread.metadata) return false;
270
+ return Object.entries(filter.metadata).every(([key, value]) => thread.metadata[key] === value);
271
+ });
272
+ }
147
273
  threads.sort((a, b) => {
148
274
  const aValue = a[field];
149
275
  const bValue = b[field];
@@ -180,23 +306,13 @@ var MemoryConvex = class extends MemoryStorage {
180
306
  const { field, direction } = this.parseOrderBy(orderBy, "ASC");
181
307
  let rows = [];
182
308
  for (const tid of threadIds) {
183
- const threadRows = await this.operations.queryTable(TABLE_MESSAGES, [
184
- { field: "thread_id", value: tid }
185
- ]);
309
+ const threadRows = await this.#db.queryTable(TABLE_MESSAGES, [{ field: "thread_id", value: tid }]);
186
310
  rows.push(...threadRows);
187
311
  }
188
312
  if (resourceId) {
189
313
  rows = rows.filter((row) => row.resourceId === resourceId);
190
314
  }
191
- if (filter?.dateRange) {
192
- const { start, end } = filter.dateRange;
193
- rows = rows.filter((row) => {
194
- const created = new Date(row.createdAt).getTime();
195
- if (start && created < start.getTime()) return false;
196
- if (end && created > end.getTime()) return false;
197
- return true;
198
- });
199
- }
315
+ rows = filterByDateRange(rows, (row) => new Date(row.createdAt), filter?.dateRange);
200
316
  rows.sort((a, b) => {
201
317
  const aValue = field === "createdAt" || field === "updatedAt" ? new Date(a[field]).getTime() : a[field];
202
318
  const bValue = field === "createdAt" || field === "updatedAt" ? new Date(b[field]).getTime() : b[field];
@@ -226,14 +342,14 @@ var MemoryConvex = class extends MemoryStorage {
226
342
  }
227
343
  }
228
344
  if (!target) {
229
- const messageRows = await this.operations.queryTable(TABLE_MESSAGES, [
345
+ const messageRows = await this.#db.queryTable(TABLE_MESSAGES, [
230
346
  { field: "id", value: includeItem.id }
231
347
  ]);
232
348
  if (messageRows.length > 0) {
233
349
  target = messageRows[0];
234
350
  targetThreadId = target.thread_id;
235
351
  if (targetThreadId && !threadMessagesCache.has(targetThreadId)) {
236
- const otherThreadRows = await this.operations.queryTable(TABLE_MESSAGES, [
352
+ const otherThreadRows = await this.#db.queryTable(TABLE_MESSAGES, [
237
353
  { field: "thread_id", value: targetThreadId }
238
354
  ]);
239
355
  threadMessagesCache.set(targetThreadId, otherThreadRows);
@@ -276,7 +392,7 @@ var MemoryConvex = class extends MemoryStorage {
276
392
  if (messageIds.length === 0) {
277
393
  return { messages: [] };
278
394
  }
279
- const rows = await this.operations.queryTable(TABLE_MESSAGES, void 0);
395
+ const rows = await this.#db.queryTable(TABLE_MESSAGES, void 0);
280
396
  const filtered = rows.filter((row) => messageIds.includes(row.id)).map((row) => this.parseStoredMessage(row));
281
397
  const list = new MessageList().add(filtered, "memory");
282
398
  return { messages: list.get.all.db() };
@@ -301,7 +417,7 @@ var MemoryConvex = class extends MemoryStorage {
301
417
  resourceId: message.resourceId
302
418
  };
303
419
  });
304
- await this.operations.batchInsert({
420
+ await this.#db.batchInsert({
305
421
  tableName: TABLE_MESSAGES,
306
422
  records: normalized
307
423
  });
@@ -310,7 +426,7 @@ var MemoryConvex = class extends MemoryStorage {
310
426
  for (const threadId of threadIds) {
311
427
  const thread = await this.getThreadById({ threadId });
312
428
  if (thread) {
313
- await this.operations.insert({
429
+ await this.#db.insert({
314
430
  tableName: TABLE_THREADS,
315
431
  record: {
316
432
  ...thread,
@@ -329,7 +445,7 @@ var MemoryConvex = class extends MemoryStorage {
329
445
  messages
330
446
  }) {
331
447
  if (messages.length === 0) return [];
332
- const existing = await this.operations.queryTable(TABLE_MESSAGES, void 0);
448
+ const existing = await this.#db.queryTable(TABLE_MESSAGES, void 0);
333
449
  const updated = [];
334
450
  const affectedThreadIds = /* @__PURE__ */ new Set();
335
451
  for (const update of messages) {
@@ -358,7 +474,7 @@ var MemoryConvex = class extends MemoryStorage {
358
474
  };
359
475
  current.content = JSON.stringify(mergedContent);
360
476
  }
361
- await this.operations.insert({
477
+ await this.#db.insert({
362
478
  tableName: TABLE_MESSAGES,
363
479
  record: current
364
480
  });
@@ -368,7 +484,7 @@ var MemoryConvex = class extends MemoryStorage {
368
484
  for (const threadId of affectedThreadIds) {
369
485
  const thread = await this.getThreadById({ threadId });
370
486
  if (thread) {
371
- await this.operations.insert({
487
+ await this.#db.insert({
372
488
  tableName: TABLE_THREADS,
373
489
  record: {
374
490
  ...thread,
@@ -383,7 +499,7 @@ var MemoryConvex = class extends MemoryStorage {
383
499
  return updated;
384
500
  }
385
501
  async deleteMessages(messageIds) {
386
- await this.operations.deleteMany(TABLE_MESSAGES, messageIds);
502
+ await this.#db.deleteMany(TABLE_MESSAGES, messageIds);
387
503
  }
388
504
  async saveResource({ resource }) {
389
505
  const record = {
@@ -394,14 +510,14 @@ var MemoryConvex = class extends MemoryStorage {
394
510
  if (resource.metadata !== void 0) {
395
511
  record.metadata = resource.metadata;
396
512
  }
397
- await this.operations.insert({
513
+ await this.#db.insert({
398
514
  tableName: TABLE_RESOURCES,
399
515
  record
400
516
  });
401
517
  return resource;
402
518
  }
403
519
  async getResourceById({ resourceId }) {
404
- const record = await this.operations.load({
520
+ const record = await this.#db.load({
405
521
  tableName: TABLE_RESOURCES,
406
522
  keys: { id: resourceId }
407
523
  });
@@ -487,12 +603,19 @@ var MemoryConvex = class extends MemoryStorage {
487
603
  }
488
604
  };
489
605
  var ScoresConvex = class extends ScoresStorage {
490
- constructor(operations) {
606
+ #db;
607
+ constructor(config) {
491
608
  super();
492
- this.operations = operations;
609
+ const client = resolveConvexConfig(config);
610
+ this.#db = new ConvexDB(client);
611
+ }
612
+ async init() {
613
+ }
614
+ async dangerouslyClearAll() {
615
+ await this.#db.clearTable({ tableName: TABLE_SCORERS });
493
616
  }
494
617
  async getScoreById({ id }) {
495
- const row = await this.operations.load({
618
+ const row = await this.#db.load({
496
619
  tableName: TABLE_SCORERS,
497
620
  keys: { id }
498
621
  });
@@ -506,7 +629,7 @@ var ScoresConvex = class extends ScoresStorage {
506
629
  createdAt: now.toISOString(),
507
630
  updatedAt: now.toISOString()
508
631
  };
509
- await this.operations.insert({
632
+ await this.#db.insert({
510
633
  tableName: TABLE_SCORERS,
511
634
  record
512
635
  });
@@ -557,7 +680,7 @@ var ScoresConvex = class extends ScoresStorage {
557
680
  new Error("page must be >= 0")
558
681
  );
559
682
  }
560
- const rows = await this.operations.queryTable(TABLE_SCORERS, void 0);
683
+ const rows = await this.#db.queryTable(TABLE_SCORERS, void 0);
561
684
  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());
562
685
  const { perPage, page } = pagination;
563
686
  const perPageValue = perPage === false ? filtered.length : perPage;
@@ -583,9 +706,16 @@ var ScoresConvex = class extends ScoresStorage {
583
706
  }
584
707
  };
585
708
  var WorkflowsConvex = class extends WorkflowsStorage {
586
- constructor(operations) {
709
+ #db;
710
+ constructor(config) {
587
711
  super();
588
- this.operations = operations;
712
+ const client = resolveConvexConfig(config);
713
+ this.#db = new ConvexDB(client);
714
+ }
715
+ async init() {
716
+ }
717
+ async dangerouslyClearAll() {
718
+ await this.#db.clearTable({ tableName: TABLE_WORKFLOW_SNAPSHOT });
589
719
  }
590
720
  async updateWorkflowResults({
591
721
  workflowName,
@@ -632,11 +762,11 @@ var WorkflowsConvex = class extends WorkflowsStorage {
632
762
  snapshot
633
763
  }) {
634
764
  const now = /* @__PURE__ */ new Date();
635
- const existing = await this.operations.load({
765
+ const existing = await this.#db.load({
636
766
  tableName: TABLE_WORKFLOW_SNAPSHOT,
637
767
  keys: { workflow_name: workflowName, run_id: runId }
638
768
  });
639
- await this.operations.insert({
769
+ await this.#db.insert({
640
770
  tableName: TABLE_WORKFLOW_SNAPSHOT,
641
771
  record: {
642
772
  workflow_name: workflowName,
@@ -652,7 +782,7 @@ var WorkflowsConvex = class extends WorkflowsStorage {
652
782
  workflowName,
653
783
  runId
654
784
  }) {
655
- const row = await this.operations.load({
785
+ const row = await this.#db.load({
656
786
  tableName: TABLE_WORKFLOW_SNAPSHOT,
657
787
  keys: { workflow_name: workflowName, run_id: runId }
658
788
  });
@@ -661,7 +791,7 @@ var WorkflowsConvex = class extends WorkflowsStorage {
661
791
  }
662
792
  async listWorkflowRuns(args = {}) {
663
793
  const { workflowName, fromDate, toDate, perPage, page, resourceId, status } = args;
664
- let rows = await this.operations.queryTable(TABLE_WORKFLOW_SNAPSHOT, void 0);
794
+ let rows = await this.#db.queryTable(TABLE_WORKFLOW_SNAPSHOT, void 0);
665
795
  if (workflowName) rows = rows.filter((run) => run.workflow_name === workflowName);
666
796
  if (resourceId) rows = rows.filter((run) => run.resourceId === resourceId);
667
797
  if (fromDate) rows = rows.filter((run) => new Date(run.createdAt).getTime() >= fromDate.getTime());
@@ -693,7 +823,7 @@ var WorkflowsConvex = class extends WorkflowsStorage {
693
823
  runId,
694
824
  workflowName
695
825
  }) {
696
- const runs = await this.operations.queryTable(TABLE_WORKFLOW_SNAPSHOT, void 0);
826
+ const runs = await this.#db.queryTable(TABLE_WORKFLOW_SNAPSHOT, void 0);
697
827
  const match = runs.find((run) => run.run_id === runId && (!workflowName || run.workflow_name === workflowName));
698
828
  if (!match) return null;
699
829
  return {
@@ -706,10 +836,10 @@ var WorkflowsConvex = class extends WorkflowsStorage {
706
836
  };
707
837
  }
708
838
  async deleteWorkflowRunById({ runId, workflowName }) {
709
- await this.operations.deleteMany(TABLE_WORKFLOW_SNAPSHOT, [`${workflowName}-${runId}`]);
839
+ await this.#db.deleteMany(TABLE_WORKFLOW_SNAPSHOT, [`${workflowName}-${runId}`]);
710
840
  }
711
841
  async getRun(workflowName, runId) {
712
- const runs = await this.operations.queryTable(TABLE_WORKFLOW_SNAPSHOT, [
842
+ const runs = await this.#db.queryTable(TABLE_WORKFLOW_SNAPSHOT, [
713
843
  { field: "workflow_name", value: workflowName }
714
844
  ]);
715
845
  return runs.find((run) => run.run_id === runId) ?? null;
@@ -736,254 +866,26 @@ var WorkflowsConvex = class extends WorkflowsStorage {
736
866
  return JSON.parse(JSON.stringify(run.snapshot));
737
867
  }
738
868
  };
739
- var StoreOperationsConvex = class extends StoreOperations {
740
- constructor(client) {
741
- super();
742
- this.client = client;
743
- }
744
- async hasColumn(_table, _column) {
745
- return true;
746
- }
747
- async createTable(_args) {
748
- }
749
- async clearTable({ tableName }) {
750
- let hasMore = true;
751
- while (hasMore) {
752
- const response = await this.client.callStorageRaw({
753
- op: "clearTable",
754
- tableName
755
- });
756
- hasMore = response.hasMore ?? false;
757
- }
758
- }
759
- async dropTable({ tableName }) {
760
- let hasMore = true;
761
- while (hasMore) {
762
- const response = await this.client.callStorageRaw({
763
- op: "dropTable",
764
- tableName
765
- });
766
- hasMore = response.hasMore ?? false;
767
- }
768
- }
769
- async alterTable(_args) {
770
- }
771
- async insert({ tableName, record }) {
772
- await this.client.callStorage({
773
- op: "insert",
774
- tableName,
775
- record: this.normalizeRecord(tableName, record)
776
- });
777
- }
778
- async batchInsert({ tableName, records }) {
779
- if (records.length === 0) return;
780
- await this.client.callStorage({
781
- op: "batchInsert",
782
- tableName,
783
- records: records.map((record) => this.normalizeRecord(tableName, record))
784
- });
785
- }
786
- async load({ tableName, keys }) {
787
- const result = await this.client.callStorage({
788
- op: "load",
789
- tableName,
790
- keys
791
- });
792
- return result;
793
- }
794
- async queryTable(tableName, filters) {
795
- return this.client.callStorage({
796
- op: "queryTable",
797
- tableName,
798
- filters
799
- });
800
- }
801
- async deleteMany(tableName, ids) {
802
- if (ids.length === 0) return;
803
- await this.client.callStorage({
804
- op: "deleteMany",
805
- tableName,
806
- ids
807
- });
808
- }
809
- normalizeRecord(tableName, record) {
810
- const normalized = { ...record };
811
- if (tableName === TABLE_WORKFLOW_SNAPSHOT && !normalized.id) {
812
- const runId = normalized.run_id || normalized.runId;
813
- const workflowName = normalized.workflow_name || normalized.workflowName;
814
- normalized.id = workflowName ? `${workflowName}-${runId}` : runId;
815
- }
816
- if (!normalized.id) {
817
- normalized.id = crypto.randomUUID();
818
- }
819
- for (const [key, value] of Object.entries(normalized)) {
820
- if (value instanceof Date) {
821
- normalized[key] = value.toISOString();
822
- }
823
- }
824
- return normalized;
825
- }
826
- };
827
869
 
828
870
  // src/storage/index.ts
871
+ var isClientConfig = (config) => {
872
+ return "client" in config;
873
+ };
829
874
  var ConvexStore = class extends MastraStorage {
830
- operations;
831
- memory;
832
- workflows;
833
- scores;
875
+ stores = {};
834
876
  constructor(config) {
835
877
  super({ id: config.id, name: config.name ?? "ConvexStore", disableInit: config.disableInit });
836
- const client = new ConvexAdminClient(config);
837
- this.operations = new StoreOperationsConvex(client);
838
- this.memory = new MemoryConvex(this.operations);
839
- this.workflows = new WorkflowsConvex(this.operations);
840
- this.scores = new ScoresConvex(this.operations);
878
+ const client = isClientConfig(config) ? config.client : new ConvexAdminClient(config);
879
+ const domainConfig = { client };
880
+ const memory = new MemoryConvex(domainConfig);
881
+ const workflows = new WorkflowsConvex(domainConfig);
882
+ const scores = new ScoresConvex(domainConfig);
841
883
  this.stores = {
842
- operations: this.operations,
843
- memory: this.memory,
844
- workflows: this.workflows,
845
- scores: this.scores
884
+ memory,
885
+ workflows,
886
+ scores
846
887
  };
847
888
  }
848
- get supports() {
849
- return {
850
- selectByIncludeResourceScope: true,
851
- resourceWorkingMemory: true,
852
- hasColumn: false,
853
- createTable: false,
854
- deleteMessages: true,
855
- observabilityInstance: false,
856
- listScoresBySpan: false
857
- };
858
- }
859
- async createTable(_args) {
860
- }
861
- async clearTable({ tableName }) {
862
- await this.operations.clearTable({ tableName });
863
- }
864
- async dropTable({ tableName }) {
865
- await this.operations.dropTable({ tableName });
866
- }
867
- async alterTable(_args) {
868
- }
869
- async insert({ tableName, record }) {
870
- await this.operations.insert({ tableName, record });
871
- }
872
- async batchInsert({ tableName, records }) {
873
- await this.operations.batchInsert({ tableName, records });
874
- }
875
- async load({ tableName, keys }) {
876
- return this.operations.load({ tableName, keys });
877
- }
878
- async getThreadById({ threadId }) {
879
- return this.memory.getThreadById({ threadId });
880
- }
881
- async saveThread({ thread }) {
882
- return this.memory.saveThread({ thread });
883
- }
884
- async updateThread({
885
- id,
886
- title,
887
- metadata
888
- }) {
889
- return this.memory.updateThread({ id, title, metadata });
890
- }
891
- async deleteThread({ threadId }) {
892
- await this.memory.deleteThread({ threadId });
893
- }
894
- async listMessages(args) {
895
- return this.memory.listMessages(args);
896
- }
897
- async listMessagesById({ messageIds }) {
898
- return this.memory.listMessagesById({ messageIds });
899
- }
900
- async saveMessages(args) {
901
- return this.memory.saveMessages(args);
902
- }
903
- async updateMessages({
904
- messages
905
- }) {
906
- return this.memory.updateMessages({ messages });
907
- }
908
- async deleteMessages(messageIds) {
909
- await this.memory.deleteMessages(messageIds);
910
- }
911
- async listThreadsByResourceId(args) {
912
- return this.memory.listThreadsByResourceId(args);
913
- }
914
- async getResourceById({ resourceId }) {
915
- return this.memory.getResourceById({ resourceId });
916
- }
917
- async saveResource({ resource }) {
918
- return this.memory.saveResource({ resource });
919
- }
920
- async updateResource({
921
- resourceId,
922
- workingMemory,
923
- metadata
924
- }) {
925
- return this.memory.updateResource({ resourceId, workingMemory, metadata });
926
- }
927
- async updateWorkflowResults(params) {
928
- return this.workflows.updateWorkflowResults(params);
929
- }
930
- async updateWorkflowState(params) {
931
- return this.workflows.updateWorkflowState(params);
932
- }
933
- async persistWorkflowSnapshot({
934
- workflowName,
935
- runId,
936
- resourceId,
937
- snapshot
938
- }) {
939
- await this.workflows.persistWorkflowSnapshot({ workflowName, runId, resourceId, snapshot });
940
- }
941
- async loadWorkflowSnapshot({
942
- workflowName,
943
- runId
944
- }) {
945
- return this.workflows.loadWorkflowSnapshot({ workflowName, runId });
946
- }
947
- async listWorkflowRuns(args) {
948
- return this.workflows.listWorkflowRuns(args);
949
- }
950
- async getWorkflowRunById({
951
- runId,
952
- workflowName
953
- }) {
954
- return this.workflows.getWorkflowRunById({ runId, workflowName });
955
- }
956
- async deleteWorkflowRunById({ runId, workflowName }) {
957
- return this.workflows.deleteWorkflowRunById({ runId, workflowName });
958
- }
959
- async getScoreById({ id }) {
960
- return this.scores.getScoreById({ id });
961
- }
962
- async saveScore(score) {
963
- return this.scores.saveScore(score);
964
- }
965
- async listScoresByScorerId({
966
- scorerId,
967
- pagination,
968
- entityId,
969
- entityType,
970
- source
971
- }) {
972
- return this.scores.listScoresByScorerId({ scorerId, pagination, entityId, entityType, source });
973
- }
974
- async listScoresByRunId({
975
- runId,
976
- pagination
977
- }) {
978
- return this.scores.listScoresByRunId({ runId, pagination });
979
- }
980
- async listScoresByEntityId({
981
- entityId,
982
- entityType,
983
- pagination
984
- }) {
985
- return this.scores.listScoresByEntityId({ entityId, entityType, pagination });
986
- }
987
889
  };
988
890
  var INDEX_METADATA_TABLE = "mastra_vector_indexes";
989
891
  var ConvexVector = class extends MastraVector {