@mastra/convex 0.0.0-feat-add-query-option-to-playground-20251209160219 → 0.0.0-feat-8782-cf-bindings-20260102164434

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 +679 -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 +182 -303
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.js +166 -287
  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} +6 -4
  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 +16 -6
  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,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,
@@ -180,23 +283,13 @@ var MemoryConvex = class extends MemoryStorage {
180
283
  const { field, direction } = this.parseOrderBy(orderBy, "ASC");
181
284
  let rows = [];
182
285
  for (const tid of threadIds) {
183
- const threadRows = await this.operations.queryTable(TABLE_MESSAGES, [
184
- { field: "thread_id", value: tid }
185
- ]);
286
+ const threadRows = await this.#db.queryTable(TABLE_MESSAGES, [{ field: "thread_id", value: tid }]);
186
287
  rows.push(...threadRows);
187
288
  }
188
289
  if (resourceId) {
189
290
  rows = rows.filter((row) => row.resourceId === resourceId);
190
291
  }
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
- }
292
+ rows = filterByDateRange(rows, (row) => new Date(row.createdAt), filter?.dateRange);
200
293
  rows.sort((a, b) => {
201
294
  const aValue = field === "createdAt" || field === "updatedAt" ? new Date(a[field]).getTime() : a[field];
202
295
  const bValue = field === "createdAt" || field === "updatedAt" ? new Date(b[field]).getTime() : b[field];
@@ -226,14 +319,14 @@ var MemoryConvex = class extends MemoryStorage {
226
319
  }
227
320
  }
228
321
  if (!target) {
229
- const messageRows = await this.operations.queryTable(TABLE_MESSAGES, [
322
+ const messageRows = await this.#db.queryTable(TABLE_MESSAGES, [
230
323
  { field: "id", value: includeItem.id }
231
324
  ]);
232
325
  if (messageRows.length > 0) {
233
326
  target = messageRows[0];
234
327
  targetThreadId = target.thread_id;
235
328
  if (targetThreadId && !threadMessagesCache.has(targetThreadId)) {
236
- const otherThreadRows = await this.operations.queryTable(TABLE_MESSAGES, [
329
+ const otherThreadRows = await this.#db.queryTable(TABLE_MESSAGES, [
237
330
  { field: "thread_id", value: targetThreadId }
238
331
  ]);
239
332
  threadMessagesCache.set(targetThreadId, otherThreadRows);
@@ -276,7 +369,7 @@ var MemoryConvex = class extends MemoryStorage {
276
369
  if (messageIds.length === 0) {
277
370
  return { messages: [] };
278
371
  }
279
- const rows = await this.operations.queryTable(TABLE_MESSAGES, void 0);
372
+ const rows = await this.#db.queryTable(TABLE_MESSAGES, void 0);
280
373
  const filtered = rows.filter((row) => messageIds.includes(row.id)).map((row) => this.parseStoredMessage(row));
281
374
  const list = new MessageList().add(filtered, "memory");
282
375
  return { messages: list.get.all.db() };
@@ -301,7 +394,7 @@ var MemoryConvex = class extends MemoryStorage {
301
394
  resourceId: message.resourceId
302
395
  };
303
396
  });
304
- await this.operations.batchInsert({
397
+ await this.#db.batchInsert({
305
398
  tableName: TABLE_MESSAGES,
306
399
  records: normalized
307
400
  });
@@ -310,7 +403,7 @@ var MemoryConvex = class extends MemoryStorage {
310
403
  for (const threadId of threadIds) {
311
404
  const thread = await this.getThreadById({ threadId });
312
405
  if (thread) {
313
- await this.operations.insert({
406
+ await this.#db.insert({
314
407
  tableName: TABLE_THREADS,
315
408
  record: {
316
409
  ...thread,
@@ -329,7 +422,7 @@ var MemoryConvex = class extends MemoryStorage {
329
422
  messages
330
423
  }) {
331
424
  if (messages.length === 0) return [];
332
- const existing = await this.operations.queryTable(TABLE_MESSAGES, void 0);
425
+ const existing = await this.#db.queryTable(TABLE_MESSAGES, void 0);
333
426
  const updated = [];
334
427
  const affectedThreadIds = /* @__PURE__ */ new Set();
335
428
  for (const update of messages) {
@@ -358,7 +451,7 @@ var MemoryConvex = class extends MemoryStorage {
358
451
  };
359
452
  current.content = JSON.stringify(mergedContent);
360
453
  }
361
- await this.operations.insert({
454
+ await this.#db.insert({
362
455
  tableName: TABLE_MESSAGES,
363
456
  record: current
364
457
  });
@@ -368,7 +461,7 @@ var MemoryConvex = class extends MemoryStorage {
368
461
  for (const threadId of affectedThreadIds) {
369
462
  const thread = await this.getThreadById({ threadId });
370
463
  if (thread) {
371
- await this.operations.insert({
464
+ await this.#db.insert({
372
465
  tableName: TABLE_THREADS,
373
466
  record: {
374
467
  ...thread,
@@ -383,7 +476,7 @@ var MemoryConvex = class extends MemoryStorage {
383
476
  return updated;
384
477
  }
385
478
  async deleteMessages(messageIds) {
386
- await this.operations.deleteMany(TABLE_MESSAGES, messageIds);
479
+ await this.#db.deleteMany(TABLE_MESSAGES, messageIds);
387
480
  }
388
481
  async saveResource({ resource }) {
389
482
  const record = {
@@ -394,14 +487,14 @@ var MemoryConvex = class extends MemoryStorage {
394
487
  if (resource.metadata !== void 0) {
395
488
  record.metadata = resource.metadata;
396
489
  }
397
- await this.operations.insert({
490
+ await this.#db.insert({
398
491
  tableName: TABLE_RESOURCES,
399
492
  record
400
493
  });
401
494
  return resource;
402
495
  }
403
496
  async getResourceById({ resourceId }) {
404
- const record = await this.operations.load({
497
+ const record = await this.#db.load({
405
498
  tableName: TABLE_RESOURCES,
406
499
  keys: { id: resourceId }
407
500
  });
@@ -487,12 +580,19 @@ var MemoryConvex = class extends MemoryStorage {
487
580
  }
488
581
  };
489
582
  var ScoresConvex = class extends ScoresStorage {
490
- constructor(operations) {
583
+ #db;
584
+ constructor(config) {
491
585
  super();
492
- this.operations = operations;
586
+ const client = resolveConvexConfig(config);
587
+ this.#db = new ConvexDB(client);
588
+ }
589
+ async init() {
590
+ }
591
+ async dangerouslyClearAll() {
592
+ await this.#db.clearTable({ tableName: TABLE_SCORERS });
493
593
  }
494
594
  async getScoreById({ id }) {
495
- const row = await this.operations.load({
595
+ const row = await this.#db.load({
496
596
  tableName: TABLE_SCORERS,
497
597
  keys: { id }
498
598
  });
@@ -506,7 +606,7 @@ var ScoresConvex = class extends ScoresStorage {
506
606
  createdAt: now.toISOString(),
507
607
  updatedAt: now.toISOString()
508
608
  };
509
- await this.operations.insert({
609
+ await this.#db.insert({
510
610
  tableName: TABLE_SCORERS,
511
611
  record
512
612
  });
@@ -557,7 +657,7 @@ var ScoresConvex = class extends ScoresStorage {
557
657
  new Error("page must be >= 0")
558
658
  );
559
659
  }
560
- const rows = await this.operations.queryTable(TABLE_SCORERS, void 0);
660
+ const rows = await this.#db.queryTable(TABLE_SCORERS, void 0);
561
661
  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
662
  const { perPage, page } = pagination;
563
663
  const perPageValue = perPage === false ? filtered.length : perPage;
@@ -583,9 +683,16 @@ var ScoresConvex = class extends ScoresStorage {
583
683
  }
584
684
  };
585
685
  var WorkflowsConvex = class extends WorkflowsStorage {
586
- constructor(operations) {
686
+ #db;
687
+ constructor(config) {
587
688
  super();
588
- this.operations = operations;
689
+ const client = resolveConvexConfig(config);
690
+ this.#db = new ConvexDB(client);
691
+ }
692
+ async init() {
693
+ }
694
+ async dangerouslyClearAll() {
695
+ await this.#db.clearTable({ tableName: TABLE_WORKFLOW_SNAPSHOT });
589
696
  }
590
697
  async updateWorkflowResults({
591
698
  workflowName,
@@ -632,11 +739,11 @@ var WorkflowsConvex = class extends WorkflowsStorage {
632
739
  snapshot
633
740
  }) {
634
741
  const now = /* @__PURE__ */ new Date();
635
- const existing = await this.operations.load({
742
+ const existing = await this.#db.load({
636
743
  tableName: TABLE_WORKFLOW_SNAPSHOT,
637
744
  keys: { workflow_name: workflowName, run_id: runId }
638
745
  });
639
- await this.operations.insert({
746
+ await this.#db.insert({
640
747
  tableName: TABLE_WORKFLOW_SNAPSHOT,
641
748
  record: {
642
749
  workflow_name: workflowName,
@@ -652,7 +759,7 @@ var WorkflowsConvex = class extends WorkflowsStorage {
652
759
  workflowName,
653
760
  runId
654
761
  }) {
655
- const row = await this.operations.load({
762
+ const row = await this.#db.load({
656
763
  tableName: TABLE_WORKFLOW_SNAPSHOT,
657
764
  keys: { workflow_name: workflowName, run_id: runId }
658
765
  });
@@ -661,7 +768,7 @@ var WorkflowsConvex = class extends WorkflowsStorage {
661
768
  }
662
769
  async listWorkflowRuns(args = {}) {
663
770
  const { workflowName, fromDate, toDate, perPage, page, resourceId, status } = args;
664
- let rows = await this.operations.queryTable(TABLE_WORKFLOW_SNAPSHOT, void 0);
771
+ let rows = await this.#db.queryTable(TABLE_WORKFLOW_SNAPSHOT, void 0);
665
772
  if (workflowName) rows = rows.filter((run) => run.workflow_name === workflowName);
666
773
  if (resourceId) rows = rows.filter((run) => run.resourceId === resourceId);
667
774
  if (fromDate) rows = rows.filter((run) => new Date(run.createdAt).getTime() >= fromDate.getTime());
@@ -693,7 +800,7 @@ var WorkflowsConvex = class extends WorkflowsStorage {
693
800
  runId,
694
801
  workflowName
695
802
  }) {
696
- const runs = await this.operations.queryTable(TABLE_WORKFLOW_SNAPSHOT, void 0);
803
+ const runs = await this.#db.queryTable(TABLE_WORKFLOW_SNAPSHOT, void 0);
697
804
  const match = runs.find((run) => run.run_id === runId && (!workflowName || run.workflow_name === workflowName));
698
805
  if (!match) return null;
699
806
  return {
@@ -706,10 +813,10 @@ var WorkflowsConvex = class extends WorkflowsStorage {
706
813
  };
707
814
  }
708
815
  async deleteWorkflowRunById({ runId, workflowName }) {
709
- await this.operations.deleteMany(TABLE_WORKFLOW_SNAPSHOT, [`${workflowName}-${runId}`]);
816
+ await this.#db.deleteMany(TABLE_WORKFLOW_SNAPSHOT, [`${workflowName}-${runId}`]);
710
817
  }
711
818
  async getRun(workflowName, runId) {
712
- const runs = await this.operations.queryTable(TABLE_WORKFLOW_SNAPSHOT, [
819
+ const runs = await this.#db.queryTable(TABLE_WORKFLOW_SNAPSHOT, [
713
820
  { field: "workflow_name", value: workflowName }
714
821
  ]);
715
822
  return runs.find((run) => run.run_id === runId) ?? null;
@@ -736,254 +843,26 @@ var WorkflowsConvex = class extends WorkflowsStorage {
736
843
  return JSON.parse(JSON.stringify(run.snapshot));
737
844
  }
738
845
  };
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
846
 
828
847
  // src/storage/index.ts
848
+ var isClientConfig = (config) => {
849
+ return "client" in config;
850
+ };
829
851
  var ConvexStore = class extends MastraStorage {
830
- operations;
831
- memory;
832
- workflows;
833
- scores;
852
+ stores = {};
834
853
  constructor(config) {
835
854
  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);
855
+ const client = isClientConfig(config) ? config.client : new ConvexAdminClient(config);
856
+ const domainConfig = { client };
857
+ const memory = new MemoryConvex(domainConfig);
858
+ const workflows = new WorkflowsConvex(domainConfig);
859
+ const scores = new ScoresConvex(domainConfig);
841
860
  this.stores = {
842
- operations: this.operations,
843
- memory: this.memory,
844
- workflows: this.workflows,
845
- scores: this.scores
861
+ memory,
862
+ workflows,
863
+ scores
846
864
  };
847
865
  }
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
866
  };
988
867
  var INDEX_METADATA_TABLE = "mastra_vector_indexes";
989
868
  var ConvexVector = class extends MastraVector {