@mastra/convex 0.0.0-feat-improve-processors-20251205191721 → 0.0.0-feat-mcp-embedded-docs-tools-clean-20260102135536

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 +787 -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-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 +188 -303
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.js +172 -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} +12 -19
  35. package/dist/storage/domains/scores/index.d.ts.map +1 -0
  36. package/dist/storage/domains/{workflows.d.ts → workflows/index.d.ts} +13 -13
  37. package/dist/storage/domains/workflows/index.d.ts.map +1 -0
  38. package/dist/storage/index.d.ts +74 -153
  39. package/dist/storage/index.d.ts.map +1 -1
  40. package/package.json +17 -7
  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.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 chunkH5QJE733_cjs = require('./chunk-H5QJE733.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,
@@ -173,7 +276,7 @@ var MemoryConvex = class extends storage.MemoryStorage {
173
276
  if (threadIds.length === 0 || threadIds.some((id) => !id.trim())) {
174
277
  throw new error.MastraError(
175
278
  {
176
- id: "CONVEX_STORAGE_LIST_MESSAGES_INVALID_THREAD_ID",
279
+ id: storage.createStorageErrorId("CONVEX", "LIST_MESSAGES", "INVALID_THREAD_ID"),
177
280
  domain: error.ErrorDomain.STORAGE,
178
281
  category: error.ErrorCategory.USER,
179
282
  details: { threadId: Array.isArray(threadId) ? threadId.join(",") : threadId }
@@ -186,23 +289,13 @@ var MemoryConvex = class extends storage.MemoryStorage {
186
289
  const { field, direction } = this.parseOrderBy(orderBy, "ASC");
187
290
  let rows = [];
188
291
  for (const tid of threadIds) {
189
- const threadRows = await this.operations.queryTable(storage.TABLE_MESSAGES, [
190
- { field: "thread_id", value: tid }
191
- ]);
292
+ const threadRows = await this.#db.queryTable(storage.TABLE_MESSAGES, [{ field: "thread_id", value: tid }]);
192
293
  rows.push(...threadRows);
193
294
  }
194
295
  if (resourceId) {
195
296
  rows = rows.filter((row) => row.resourceId === resourceId);
196
297
  }
197
- if (filter?.dateRange) {
198
- const { start, end } = filter.dateRange;
199
- rows = rows.filter((row) => {
200
- const created = new Date(row.createdAt).getTime();
201
- if (start && created < start.getTime()) return false;
202
- if (end && created > end.getTime()) return false;
203
- return true;
204
- });
205
- }
298
+ rows = storage.filterByDateRange(rows, (row) => new Date(row.createdAt), filter?.dateRange);
206
299
  rows.sort((a, b) => {
207
300
  const aValue = field === "createdAt" || field === "updatedAt" ? new Date(a[field]).getTime() : a[field];
208
301
  const bValue = field === "createdAt" || field === "updatedAt" ? new Date(b[field]).getTime() : b[field];
@@ -232,14 +325,14 @@ var MemoryConvex = class extends storage.MemoryStorage {
232
325
  }
233
326
  }
234
327
  if (!target) {
235
- const messageRows = await this.operations.queryTable(storage.TABLE_MESSAGES, [
328
+ const messageRows = await this.#db.queryTable(storage.TABLE_MESSAGES, [
236
329
  { field: "id", value: includeItem.id }
237
330
  ]);
238
331
  if (messageRows.length > 0) {
239
332
  target = messageRows[0];
240
333
  targetThreadId = target.thread_id;
241
334
  if (targetThreadId && !threadMessagesCache.has(targetThreadId)) {
242
- const otherThreadRows = await this.operations.queryTable(storage.TABLE_MESSAGES, [
335
+ const otherThreadRows = await this.#db.queryTable(storage.TABLE_MESSAGES, [
243
336
  { field: "thread_id", value: targetThreadId }
244
337
  ]);
245
338
  threadMessagesCache.set(targetThreadId, otherThreadRows);
@@ -282,7 +375,7 @@ var MemoryConvex = class extends storage.MemoryStorage {
282
375
  if (messageIds.length === 0) {
283
376
  return { messages: [] };
284
377
  }
285
- const rows = await this.operations.queryTable(storage.TABLE_MESSAGES, void 0);
378
+ const rows = await this.#db.queryTable(storage.TABLE_MESSAGES, void 0);
286
379
  const filtered = rows.filter((row) => messageIds.includes(row.id)).map((row) => this.parseStoredMessage(row));
287
380
  const list = new agent.MessageList().add(filtered, "memory");
288
381
  return { messages: list.get.all.db() };
@@ -307,7 +400,7 @@ var MemoryConvex = class extends storage.MemoryStorage {
307
400
  resourceId: message.resourceId
308
401
  };
309
402
  });
310
- await this.operations.batchInsert({
403
+ await this.#db.batchInsert({
311
404
  tableName: storage.TABLE_MESSAGES,
312
405
  records: normalized
313
406
  });
@@ -316,7 +409,7 @@ var MemoryConvex = class extends storage.MemoryStorage {
316
409
  for (const threadId of threadIds) {
317
410
  const thread = await this.getThreadById({ threadId });
318
411
  if (thread) {
319
- await this.operations.insert({
412
+ await this.#db.insert({
320
413
  tableName: storage.TABLE_THREADS,
321
414
  record: {
322
415
  ...thread,
@@ -335,7 +428,7 @@ var MemoryConvex = class extends storage.MemoryStorage {
335
428
  messages
336
429
  }) {
337
430
  if (messages.length === 0) return [];
338
- const existing = await this.operations.queryTable(storage.TABLE_MESSAGES, void 0);
431
+ const existing = await this.#db.queryTable(storage.TABLE_MESSAGES, void 0);
339
432
  const updated = [];
340
433
  const affectedThreadIds = /* @__PURE__ */ new Set();
341
434
  for (const update of messages) {
@@ -364,7 +457,7 @@ var MemoryConvex = class extends storage.MemoryStorage {
364
457
  };
365
458
  current.content = JSON.stringify(mergedContent);
366
459
  }
367
- await this.operations.insert({
460
+ await this.#db.insert({
368
461
  tableName: storage.TABLE_MESSAGES,
369
462
  record: current
370
463
  });
@@ -374,7 +467,7 @@ var MemoryConvex = class extends storage.MemoryStorage {
374
467
  for (const threadId of affectedThreadIds) {
375
468
  const thread = await this.getThreadById({ threadId });
376
469
  if (thread) {
377
- await this.operations.insert({
470
+ await this.#db.insert({
378
471
  tableName: storage.TABLE_THREADS,
379
472
  record: {
380
473
  ...thread,
@@ -389,7 +482,7 @@ var MemoryConvex = class extends storage.MemoryStorage {
389
482
  return updated;
390
483
  }
391
484
  async deleteMessages(messageIds) {
392
- await this.operations.deleteMany(storage.TABLE_MESSAGES, messageIds);
485
+ await this.#db.deleteMany(storage.TABLE_MESSAGES, messageIds);
393
486
  }
394
487
  async saveResource({ resource }) {
395
488
  const record = {
@@ -400,14 +493,14 @@ var MemoryConvex = class extends storage.MemoryStorage {
400
493
  if (resource.metadata !== void 0) {
401
494
  record.metadata = resource.metadata;
402
495
  }
403
- await this.operations.insert({
496
+ await this.#db.insert({
404
497
  tableName: storage.TABLE_RESOURCES,
405
498
  record
406
499
  });
407
500
  return resource;
408
501
  }
409
502
  async getResourceById({ resourceId }) {
410
- const record = await this.operations.load({
503
+ const record = await this.#db.load({
411
504
  tableName: storage.TABLE_RESOURCES,
412
505
  keys: { id: resourceId }
413
506
  });
@@ -493,12 +586,19 @@ var MemoryConvex = class extends storage.MemoryStorage {
493
586
  }
494
587
  };
495
588
  var ScoresConvex = class extends storage.ScoresStorage {
496
- constructor(operations) {
589
+ #db;
590
+ constructor(config) {
497
591
  super();
498
- this.operations = operations;
592
+ const client = resolveConvexConfig(config);
593
+ this.#db = new ConvexDB(client);
594
+ }
595
+ async init() {
596
+ }
597
+ async dangerouslyClearAll() {
598
+ await this.#db.clearTable({ tableName: storage.TABLE_SCORERS });
499
599
  }
500
600
  async getScoreById({ id }) {
501
- const row = await this.operations.load({
601
+ const row = await this.#db.load({
502
602
  tableName: storage.TABLE_SCORERS,
503
603
  keys: { id }
504
604
  });
@@ -512,7 +612,7 @@ var ScoresConvex = class extends storage.ScoresStorage {
512
612
  createdAt: now.toISOString(),
513
613
  updatedAt: now.toISOString()
514
614
  };
515
- await this.operations.insert({
615
+ await this.#db.insert({
516
616
  tableName: storage.TABLE_SCORERS,
517
617
  record
518
618
  });
@@ -556,14 +656,14 @@ var ScoresConvex = class extends storage.ScoresStorage {
556
656
  if (pagination.page < 0) {
557
657
  throw new error.MastraError(
558
658
  {
559
- id: "CONVEX_STORAGE_INVALID_PAGINATION",
659
+ id: storage.createStorageErrorId("CONVEX", "LIST_SCORES", "INVALID_PAGINATION"),
560
660
  domain: error.ErrorDomain.STORAGE,
561
661
  category: error.ErrorCategory.USER
562
662
  },
563
663
  new Error("page must be >= 0")
564
664
  );
565
665
  }
566
- const rows = await this.operations.queryTable(storage.TABLE_SCORERS, void 0);
666
+ const rows = await this.#db.queryTable(storage.TABLE_SCORERS, void 0);
567
667
  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());
568
668
  const { perPage, page } = pagination;
569
669
  const perPageValue = perPage === false ? filtered.length : perPage;
@@ -589,9 +689,16 @@ var ScoresConvex = class extends storage.ScoresStorage {
589
689
  }
590
690
  };
591
691
  var WorkflowsConvex = class extends storage.WorkflowsStorage {
592
- constructor(operations) {
692
+ #db;
693
+ constructor(config) {
593
694
  super();
594
- this.operations = operations;
695
+ const client = resolveConvexConfig(config);
696
+ this.#db = new ConvexDB(client);
697
+ }
698
+ async init() {
699
+ }
700
+ async dangerouslyClearAll() {
701
+ await this.#db.clearTable({ tableName: storage.TABLE_WORKFLOW_SNAPSHOT });
595
702
  }
596
703
  async updateWorkflowResults({
597
704
  workflowName,
@@ -638,11 +745,11 @@ var WorkflowsConvex = class extends storage.WorkflowsStorage {
638
745
  snapshot
639
746
  }) {
640
747
  const now = /* @__PURE__ */ new Date();
641
- const existing = await this.operations.load({
748
+ const existing = await this.#db.load({
642
749
  tableName: storage.TABLE_WORKFLOW_SNAPSHOT,
643
750
  keys: { workflow_name: workflowName, run_id: runId }
644
751
  });
645
- await this.operations.insert({
752
+ await this.#db.insert({
646
753
  tableName: storage.TABLE_WORKFLOW_SNAPSHOT,
647
754
  record: {
648
755
  workflow_name: workflowName,
@@ -658,7 +765,7 @@ var WorkflowsConvex = class extends storage.WorkflowsStorage {
658
765
  workflowName,
659
766
  runId
660
767
  }) {
661
- const row = await this.operations.load({
768
+ const row = await this.#db.load({
662
769
  tableName: storage.TABLE_WORKFLOW_SNAPSHOT,
663
770
  keys: { workflow_name: workflowName, run_id: runId }
664
771
  });
@@ -667,7 +774,7 @@ var WorkflowsConvex = class extends storage.WorkflowsStorage {
667
774
  }
668
775
  async listWorkflowRuns(args = {}) {
669
776
  const { workflowName, fromDate, toDate, perPage, page, resourceId, status } = args;
670
- let rows = await this.operations.queryTable(storage.TABLE_WORKFLOW_SNAPSHOT, void 0);
777
+ let rows = await this.#db.queryTable(storage.TABLE_WORKFLOW_SNAPSHOT, void 0);
671
778
  if (workflowName) rows = rows.filter((run) => run.workflow_name === workflowName);
672
779
  if (resourceId) rows = rows.filter((run) => run.resourceId === resourceId);
673
780
  if (fromDate) rows = rows.filter((run) => new Date(run.createdAt).getTime() >= fromDate.getTime());
@@ -699,7 +806,7 @@ var WorkflowsConvex = class extends storage.WorkflowsStorage {
699
806
  runId,
700
807
  workflowName
701
808
  }) {
702
- const runs = await this.operations.queryTable(storage.TABLE_WORKFLOW_SNAPSHOT, void 0);
809
+ const runs = await this.#db.queryTable(storage.TABLE_WORKFLOW_SNAPSHOT, void 0);
703
810
  const match = runs.find((run) => run.run_id === runId && (!workflowName || run.workflow_name === workflowName));
704
811
  if (!match) return null;
705
812
  return {
@@ -711,8 +818,11 @@ var WorkflowsConvex = class extends storage.WorkflowsStorage {
711
818
  resourceId: match.resourceId
712
819
  };
713
820
  }
821
+ async deleteWorkflowRunById({ runId, workflowName }) {
822
+ await this.#db.deleteMany(storage.TABLE_WORKFLOW_SNAPSHOT, [`${workflowName}-${runId}`]);
823
+ }
714
824
  async getRun(workflowName, runId) {
715
- const runs = await this.operations.queryTable(storage.TABLE_WORKFLOW_SNAPSHOT, [
825
+ const runs = await this.#db.queryTable(storage.TABLE_WORKFLOW_SNAPSHOT, [
716
826
  { field: "workflow_name", value: workflowName }
717
827
  ]);
718
828
  return runs.find((run) => run.run_id === runId) ?? null;
@@ -739,251 +849,26 @@ var WorkflowsConvex = class extends storage.WorkflowsStorage {
739
849
  return JSON.parse(JSON.stringify(run.snapshot));
740
850
  }
741
851
  };
742
- var StoreOperationsConvex = class extends storage.StoreOperations {
743
- constructor(client) {
744
- super();
745
- this.client = client;
746
- }
747
- async hasColumn(_table, _column) {
748
- return true;
749
- }
750
- async createTable(_args) {
751
- }
752
- async clearTable({ tableName }) {
753
- let hasMore = true;
754
- while (hasMore) {
755
- const response = await this.client.callStorageRaw({
756
- op: "clearTable",
757
- tableName
758
- });
759
- hasMore = response.hasMore ?? false;
760
- }
761
- }
762
- async dropTable({ tableName }) {
763
- let hasMore = true;
764
- while (hasMore) {
765
- const response = await this.client.callStorageRaw({
766
- op: "dropTable",
767
- tableName
768
- });
769
- hasMore = response.hasMore ?? false;
770
- }
771
- }
772
- async alterTable(_args) {
773
- }
774
- async insert({ tableName, record }) {
775
- await this.client.callStorage({
776
- op: "insert",
777
- tableName,
778
- record: this.normalizeRecord(tableName, record)
779
- });
780
- }
781
- async batchInsert({ tableName, records }) {
782
- if (records.length === 0) return;
783
- await this.client.callStorage({
784
- op: "batchInsert",
785
- tableName,
786
- records: records.map((record) => this.normalizeRecord(tableName, record))
787
- });
788
- }
789
- async load({ tableName, keys }) {
790
- const result = await this.client.callStorage({
791
- op: "load",
792
- tableName,
793
- keys
794
- });
795
- return result;
796
- }
797
- async queryTable(tableName, filters) {
798
- return this.client.callStorage({
799
- op: "queryTable",
800
- tableName,
801
- filters
802
- });
803
- }
804
- async deleteMany(tableName, ids) {
805
- if (ids.length === 0) return;
806
- await this.client.callStorage({
807
- op: "deleteMany",
808
- tableName,
809
- ids
810
- });
811
- }
812
- normalizeRecord(tableName, record) {
813
- const normalized = { ...record };
814
- if (tableName === storage.TABLE_WORKFLOW_SNAPSHOT && !normalized.id) {
815
- const runId = normalized.run_id || normalized.runId;
816
- const workflowName = normalized.workflow_name || normalized.workflowName;
817
- normalized.id = workflowName ? `${workflowName}-${runId}` : runId;
818
- }
819
- if (!normalized.id) {
820
- normalized.id = crypto__default.default.randomUUID();
821
- }
822
- for (const [key, value] of Object.entries(normalized)) {
823
- if (value instanceof Date) {
824
- normalized[key] = value.toISOString();
825
- }
826
- }
827
- return normalized;
828
- }
829
- };
830
852
 
831
853
  // src/storage/index.ts
854
+ var isClientConfig = (config) => {
855
+ return "client" in config;
856
+ };
832
857
  var ConvexStore = class extends storage.MastraStorage {
833
- operations;
834
- memory;
835
- workflows;
836
- scores;
858
+ stores = {};
837
859
  constructor(config) {
838
- super({ id: config.id, name: config.name ?? "ConvexStore" });
839
- const client = new ConvexAdminClient(config);
840
- this.operations = new StoreOperationsConvex(client);
841
- this.memory = new MemoryConvex(this.operations);
842
- this.workflows = new WorkflowsConvex(this.operations);
843
- this.scores = new ScoresConvex(this.operations);
860
+ super({ id: config.id, name: config.name ?? "ConvexStore", disableInit: config.disableInit });
861
+ const client = isClientConfig(config) ? config.client : new ConvexAdminClient(config);
862
+ const domainConfig = { client };
863
+ const memory = new MemoryConvex(domainConfig);
864
+ const workflows = new WorkflowsConvex(domainConfig);
865
+ const scores = new ScoresConvex(domainConfig);
844
866
  this.stores = {
845
- operations: this.operations,
846
- memory: this.memory,
847
- workflows: this.workflows,
848
- scores: this.scores
849
- };
850
- }
851
- get supports() {
852
- return {
853
- selectByIncludeResourceScope: true,
854
- resourceWorkingMemory: true,
855
- hasColumn: false,
856
- createTable: false,
857
- deleteMessages: true,
858
- observabilityInstance: false,
859
- listScoresBySpan: false
867
+ memory,
868
+ workflows,
869
+ scores
860
870
  };
861
871
  }
862
- async createTable(_args) {
863
- }
864
- async clearTable({ tableName }) {
865
- await this.operations.clearTable({ tableName });
866
- }
867
- async dropTable({ tableName }) {
868
- await this.operations.dropTable({ tableName });
869
- }
870
- async alterTable(_args) {
871
- }
872
- async insert({ tableName, record }) {
873
- await this.operations.insert({ tableName, record });
874
- }
875
- async batchInsert({ tableName, records }) {
876
- await this.operations.batchInsert({ tableName, records });
877
- }
878
- async load({ tableName, keys }) {
879
- return this.operations.load({ tableName, keys });
880
- }
881
- async getThreadById({ threadId }) {
882
- return this.memory.getThreadById({ threadId });
883
- }
884
- async saveThread({ thread }) {
885
- return this.memory.saveThread({ thread });
886
- }
887
- async updateThread({
888
- id,
889
- title,
890
- metadata
891
- }) {
892
- return this.memory.updateThread({ id, title, metadata });
893
- }
894
- async deleteThread({ threadId }) {
895
- await this.memory.deleteThread({ threadId });
896
- }
897
- async listMessages(args) {
898
- return this.memory.listMessages(args);
899
- }
900
- async listMessagesById({ messageIds }) {
901
- return this.memory.listMessagesById({ messageIds });
902
- }
903
- async saveMessages(args) {
904
- return this.memory.saveMessages(args);
905
- }
906
- async updateMessages({
907
- messages
908
- }) {
909
- return this.memory.updateMessages({ messages });
910
- }
911
- async deleteMessages(messageIds) {
912
- await this.memory.deleteMessages(messageIds);
913
- }
914
- async listThreadsByResourceId(args) {
915
- return this.memory.listThreadsByResourceId(args);
916
- }
917
- async getResourceById({ resourceId }) {
918
- return this.memory.getResourceById({ resourceId });
919
- }
920
- async saveResource({ resource }) {
921
- return this.memory.saveResource({ resource });
922
- }
923
- async updateResource({
924
- resourceId,
925
- workingMemory,
926
- metadata
927
- }) {
928
- return this.memory.updateResource({ resourceId, workingMemory, metadata });
929
- }
930
- async updateWorkflowResults(params) {
931
- return this.workflows.updateWorkflowResults(params);
932
- }
933
- async updateWorkflowState(params) {
934
- return this.workflows.updateWorkflowState(params);
935
- }
936
- async persistWorkflowSnapshot({
937
- workflowName,
938
- runId,
939
- resourceId,
940
- snapshot
941
- }) {
942
- await this.workflows.persistWorkflowSnapshot({ workflowName, runId, resourceId, snapshot });
943
- }
944
- async loadWorkflowSnapshot({
945
- workflowName,
946
- runId
947
- }) {
948
- return this.workflows.loadWorkflowSnapshot({ workflowName, runId });
949
- }
950
- async listWorkflowRuns(args) {
951
- return this.workflows.listWorkflowRuns(args);
952
- }
953
- async getWorkflowRunById({
954
- runId,
955
- workflowName
956
- }) {
957
- return this.workflows.getWorkflowRunById({ 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
872
  };
988
873
  var INDEX_METADATA_TABLE = "mastra_vector_indexes";
989
874
  var ConvexVector = class extends vector.MastraVector {
@@ -1288,61 +1173,61 @@ function cosineSimilarity(a, b) {
1288
1173
  return dot / (Math.sqrt(magA) * Math.sqrt(magB));
1289
1174
  }
1290
1175
 
1176
+ Object.defineProperty(exports, "mastraStorage", {
1177
+ enumerable: true,
1178
+ get: function () { return chunkBKVR7SL7_cjs.mastraStorage; }
1179
+ });
1291
1180
  Object.defineProperty(exports, "TABLE_MESSAGES", {
1292
1181
  enumerable: true,
1293
- get: function () { return chunkQKN2PWR2_cjs.TABLE_MESSAGES; }
1182
+ get: function () { return chunkH5QJE733_cjs.TABLE_MESSAGES; }
1294
1183
  });
1295
1184
  Object.defineProperty(exports, "TABLE_RESOURCES", {
1296
1185
  enumerable: true,
1297
- get: function () { return chunkQKN2PWR2_cjs.TABLE_RESOURCES; }
1186
+ get: function () { return chunkH5QJE733_cjs.TABLE_RESOURCES; }
1298
1187
  });
1299
1188
  Object.defineProperty(exports, "TABLE_SCORERS", {
1300
1189
  enumerable: true,
1301
- get: function () { return chunkQKN2PWR2_cjs.TABLE_SCORERS; }
1190
+ get: function () { return chunkH5QJE733_cjs.TABLE_SCORERS; }
1302
1191
  });
1303
1192
  Object.defineProperty(exports, "TABLE_THREADS", {
1304
1193
  enumerable: true,
1305
- get: function () { return chunkQKN2PWR2_cjs.TABLE_THREADS; }
1194
+ get: function () { return chunkH5QJE733_cjs.TABLE_THREADS; }
1306
1195
  });
1307
1196
  Object.defineProperty(exports, "TABLE_WORKFLOW_SNAPSHOT", {
1308
1197
  enumerable: true,
1309
- get: function () { return chunkQKN2PWR2_cjs.TABLE_WORKFLOW_SNAPSHOT; }
1198
+ get: function () { return chunkH5QJE733_cjs.TABLE_WORKFLOW_SNAPSHOT; }
1310
1199
  });
1311
1200
  Object.defineProperty(exports, "mastraDocumentsTable", {
1312
1201
  enumerable: true,
1313
- get: function () { return chunkQKN2PWR2_cjs.mastraDocumentsTable; }
1202
+ get: function () { return chunkH5QJE733_cjs.mastraDocumentsTable; }
1314
1203
  });
1315
1204
  Object.defineProperty(exports, "mastraMessagesTable", {
1316
1205
  enumerable: true,
1317
- get: function () { return chunkQKN2PWR2_cjs.mastraMessagesTable; }
1206
+ get: function () { return chunkH5QJE733_cjs.mastraMessagesTable; }
1318
1207
  });
1319
1208
  Object.defineProperty(exports, "mastraResourcesTable", {
1320
1209
  enumerable: true,
1321
- get: function () { return chunkQKN2PWR2_cjs.mastraResourcesTable; }
1210
+ get: function () { return chunkH5QJE733_cjs.mastraResourcesTable; }
1322
1211
  });
1323
1212
  Object.defineProperty(exports, "mastraScoresTable", {
1324
1213
  enumerable: true,
1325
- get: function () { return chunkQKN2PWR2_cjs.mastraScoresTable; }
1326
- });
1327
- Object.defineProperty(exports, "mastraStorage", {
1328
- enumerable: true,
1329
- get: function () { return chunkQKN2PWR2_cjs.mastraStorage; }
1214
+ get: function () { return chunkH5QJE733_cjs.mastraScoresTable; }
1330
1215
  });
1331
1216
  Object.defineProperty(exports, "mastraThreadsTable", {
1332
1217
  enumerable: true,
1333
- get: function () { return chunkQKN2PWR2_cjs.mastraThreadsTable; }
1218
+ get: function () { return chunkH5QJE733_cjs.mastraThreadsTable; }
1334
1219
  });
1335
1220
  Object.defineProperty(exports, "mastraVectorIndexesTable", {
1336
1221
  enumerable: true,
1337
- get: function () { return chunkQKN2PWR2_cjs.mastraVectorIndexesTable; }
1222
+ get: function () { return chunkH5QJE733_cjs.mastraVectorIndexesTable; }
1338
1223
  });
1339
1224
  Object.defineProperty(exports, "mastraVectorsTable", {
1340
1225
  enumerable: true,
1341
- get: function () { return chunkQKN2PWR2_cjs.mastraVectorsTable; }
1226
+ get: function () { return chunkH5QJE733_cjs.mastraVectorsTable; }
1342
1227
  });
1343
1228
  Object.defineProperty(exports, "mastraWorkflowSnapshotsTable", {
1344
1229
  enumerable: true,
1345
- get: function () { return chunkQKN2PWR2_cjs.mastraWorkflowSnapshotsTable; }
1230
+ get: function () { return chunkH5QJE733_cjs.mastraWorkflowSnapshotsTable; }
1346
1231
  });
1347
1232
  exports.ConvexStore = ConvexStore;
1348
1233
  exports.ConvexVector = ConvexVector;