@mastra/convex 0.1.0-beta.5 → 0.1.0-beta.6
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.
- package/CHANGELOG.md +218 -0
- package/dist/chunk-H5QJE733.cjs +104 -0
- package/dist/chunk-H5QJE733.cjs.map +1 -0
- package/dist/chunk-HXB4DWFE.js +73 -0
- package/dist/chunk-HXB4DWFE.js.map +1 -0
- package/dist/index.cjs +180 -281
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +168 -269
- package/dist/index.js.map +1 -1
- package/dist/schema.cjs +17 -17
- package/dist/schema.d.ts +52 -75
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +1 -1
- package/dist/server/index.cjs +14 -14
- package/dist/server/index.js +1 -1
- package/dist/storage/db/index.d.ts +57 -0
- package/dist/storage/db/index.d.ts.map +1 -0
- package/dist/storage/domains/{memory.d.ts → memory/index.d.ts} +6 -4
- package/dist/storage/domains/memory/index.d.ts.map +1 -0
- package/dist/storage/domains/{scores.d.ts → scores/index.d.ts} +11 -18
- package/dist/storage/domains/scores/index.d.ts.map +1 -0
- package/dist/storage/domains/{workflows.d.ts → workflows/index.d.ts} +6 -4
- package/dist/storage/domains/workflows/index.d.ts.map +1 -0
- package/dist/storage/index.d.ts +50 -151
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/dist/chunk-PKUUSREO.js +0 -76
- package/dist/chunk-PKUUSREO.js.map +0 -1
- package/dist/chunk-ZBUP3DS6.cjs +0 -93
- package/dist/chunk-ZBUP3DS6.cjs.map +0 -1
- package/dist/server/schema.d.ts +0 -115
- package/dist/server/schema.d.ts.map +0 -1
- package/dist/storage/domains/memory.d.ts.map +0 -1
- package/dist/storage/domains/scores.d.ts.map +0 -1
- package/dist/storage/domains/workflows.d.ts.map +0 -1
- package/dist/storage/operations.d.ts +0 -40
- package/dist/storage/operations.d.ts.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var chunkBKVR7SL7_cjs = require('./chunk-BKVR7SL7.cjs');
|
|
4
|
-
var
|
|
4
|
+
var chunkH5QJE733_cjs = require('./chunk-H5QJE733.cjs');
|
|
5
5
|
var storage = require('@mastra/core/storage');
|
|
6
6
|
var agent = require('@mastra/core/agent');
|
|
7
7
|
var error = require('@mastra/core/error');
|
|
8
8
|
var crypto = require('crypto');
|
|
9
|
+
var base = require('@mastra/core/base');
|
|
9
10
|
var vector = require('@mastra/core/vector');
|
|
10
11
|
|
|
11
12
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -75,13 +76,114 @@ var ConvexAdminClient = class {
|
|
|
75
76
|
return result;
|
|
76
77
|
}
|
|
77
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
|
|
78
171
|
var MemoryConvex = class extends storage.MemoryStorage {
|
|
79
|
-
|
|
172
|
+
#db;
|
|
173
|
+
constructor(config) {
|
|
80
174
|
super();
|
|
81
|
-
|
|
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 });
|
|
82
184
|
}
|
|
83
185
|
async getThreadById({ threadId }) {
|
|
84
|
-
const row = await this.
|
|
186
|
+
const row = await this.#db.load({
|
|
85
187
|
tableName: storage.TABLE_THREADS,
|
|
86
188
|
keys: { id: threadId }
|
|
87
189
|
});
|
|
@@ -94,7 +196,7 @@ var MemoryConvex = class extends storage.MemoryStorage {
|
|
|
94
196
|
};
|
|
95
197
|
}
|
|
96
198
|
async saveThread({ thread }) {
|
|
97
|
-
await this.
|
|
199
|
+
await this.#db.insert({
|
|
98
200
|
tableName: storage.TABLE_THREADS,
|
|
99
201
|
record: {
|
|
100
202
|
...thread,
|
|
@@ -130,21 +232,21 @@ var MemoryConvex = class extends storage.MemoryStorage {
|
|
|
130
232
|
return updated;
|
|
131
233
|
}
|
|
132
234
|
async deleteThread({ threadId }) {
|
|
133
|
-
const messages = await this.
|
|
235
|
+
const messages = await this.#db.queryTable(storage.TABLE_MESSAGES, [
|
|
134
236
|
{ field: "thread_id", value: threadId }
|
|
135
237
|
]);
|
|
136
|
-
await this.
|
|
238
|
+
await this.#db.deleteMany(
|
|
137
239
|
storage.TABLE_MESSAGES,
|
|
138
240
|
messages.map((msg) => msg.id)
|
|
139
241
|
);
|
|
140
|
-
await this.
|
|
242
|
+
await this.#db.deleteMany(storage.TABLE_THREADS, [threadId]);
|
|
141
243
|
}
|
|
142
244
|
async listThreadsByResourceId(args) {
|
|
143
245
|
const { resourceId, page = 0, perPage: perPageInput, orderBy } = args;
|
|
144
246
|
const perPage = storage.normalizePerPage(perPageInput, 100);
|
|
145
247
|
const { field, direction } = this.parseOrderBy(orderBy);
|
|
146
248
|
const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
147
|
-
const rows = await this.
|
|
249
|
+
const rows = await this.#db.queryTable(storage.TABLE_THREADS, [{ field: "resourceId", value: resourceId }]);
|
|
148
250
|
const threads = rows.map((row) => ({
|
|
149
251
|
...row,
|
|
150
252
|
metadata: typeof row.metadata === "string" ? JSON.parse(row.metadata) : row.metadata,
|
|
@@ -187,9 +289,7 @@ var MemoryConvex = class extends storage.MemoryStorage {
|
|
|
187
289
|
const { field, direction } = this.parseOrderBy(orderBy, "ASC");
|
|
188
290
|
let rows = [];
|
|
189
291
|
for (const tid of threadIds) {
|
|
190
|
-
const threadRows = await this.
|
|
191
|
-
{ field: "thread_id", value: tid }
|
|
192
|
-
]);
|
|
292
|
+
const threadRows = await this.#db.queryTable(storage.TABLE_MESSAGES, [{ field: "thread_id", value: tid }]);
|
|
193
293
|
rows.push(...threadRows);
|
|
194
294
|
}
|
|
195
295
|
if (resourceId) {
|
|
@@ -233,14 +333,14 @@ var MemoryConvex = class extends storage.MemoryStorage {
|
|
|
233
333
|
}
|
|
234
334
|
}
|
|
235
335
|
if (!target) {
|
|
236
|
-
const messageRows = await this.
|
|
336
|
+
const messageRows = await this.#db.queryTable(storage.TABLE_MESSAGES, [
|
|
237
337
|
{ field: "id", value: includeItem.id }
|
|
238
338
|
]);
|
|
239
339
|
if (messageRows.length > 0) {
|
|
240
340
|
target = messageRows[0];
|
|
241
341
|
targetThreadId = target.thread_id;
|
|
242
342
|
if (targetThreadId && !threadMessagesCache.has(targetThreadId)) {
|
|
243
|
-
const otherThreadRows = await this.
|
|
343
|
+
const otherThreadRows = await this.#db.queryTable(storage.TABLE_MESSAGES, [
|
|
244
344
|
{ field: "thread_id", value: targetThreadId }
|
|
245
345
|
]);
|
|
246
346
|
threadMessagesCache.set(targetThreadId, otherThreadRows);
|
|
@@ -283,7 +383,7 @@ var MemoryConvex = class extends storage.MemoryStorage {
|
|
|
283
383
|
if (messageIds.length === 0) {
|
|
284
384
|
return { messages: [] };
|
|
285
385
|
}
|
|
286
|
-
const rows = await this.
|
|
386
|
+
const rows = await this.#db.queryTable(storage.TABLE_MESSAGES, void 0);
|
|
287
387
|
const filtered = rows.filter((row) => messageIds.includes(row.id)).map((row) => this.parseStoredMessage(row));
|
|
288
388
|
const list = new agent.MessageList().add(filtered, "memory");
|
|
289
389
|
return { messages: list.get.all.db() };
|
|
@@ -308,7 +408,7 @@ var MemoryConvex = class extends storage.MemoryStorage {
|
|
|
308
408
|
resourceId: message.resourceId
|
|
309
409
|
};
|
|
310
410
|
});
|
|
311
|
-
await this.
|
|
411
|
+
await this.#db.batchInsert({
|
|
312
412
|
tableName: storage.TABLE_MESSAGES,
|
|
313
413
|
records: normalized
|
|
314
414
|
});
|
|
@@ -317,7 +417,7 @@ var MemoryConvex = class extends storage.MemoryStorage {
|
|
|
317
417
|
for (const threadId of threadIds) {
|
|
318
418
|
const thread = await this.getThreadById({ threadId });
|
|
319
419
|
if (thread) {
|
|
320
|
-
await this.
|
|
420
|
+
await this.#db.insert({
|
|
321
421
|
tableName: storage.TABLE_THREADS,
|
|
322
422
|
record: {
|
|
323
423
|
...thread,
|
|
@@ -336,7 +436,7 @@ var MemoryConvex = class extends storage.MemoryStorage {
|
|
|
336
436
|
messages
|
|
337
437
|
}) {
|
|
338
438
|
if (messages.length === 0) return [];
|
|
339
|
-
const existing = await this.
|
|
439
|
+
const existing = await this.#db.queryTable(storage.TABLE_MESSAGES, void 0);
|
|
340
440
|
const updated = [];
|
|
341
441
|
const affectedThreadIds = /* @__PURE__ */ new Set();
|
|
342
442
|
for (const update of messages) {
|
|
@@ -365,7 +465,7 @@ var MemoryConvex = class extends storage.MemoryStorage {
|
|
|
365
465
|
};
|
|
366
466
|
current.content = JSON.stringify(mergedContent);
|
|
367
467
|
}
|
|
368
|
-
await this.
|
|
468
|
+
await this.#db.insert({
|
|
369
469
|
tableName: storage.TABLE_MESSAGES,
|
|
370
470
|
record: current
|
|
371
471
|
});
|
|
@@ -375,7 +475,7 @@ var MemoryConvex = class extends storage.MemoryStorage {
|
|
|
375
475
|
for (const threadId of affectedThreadIds) {
|
|
376
476
|
const thread = await this.getThreadById({ threadId });
|
|
377
477
|
if (thread) {
|
|
378
|
-
await this.
|
|
478
|
+
await this.#db.insert({
|
|
379
479
|
tableName: storage.TABLE_THREADS,
|
|
380
480
|
record: {
|
|
381
481
|
...thread,
|
|
@@ -390,7 +490,7 @@ var MemoryConvex = class extends storage.MemoryStorage {
|
|
|
390
490
|
return updated;
|
|
391
491
|
}
|
|
392
492
|
async deleteMessages(messageIds) {
|
|
393
|
-
await this.
|
|
493
|
+
await this.#db.deleteMany(storage.TABLE_MESSAGES, messageIds);
|
|
394
494
|
}
|
|
395
495
|
async saveResource({ resource }) {
|
|
396
496
|
const record = {
|
|
@@ -401,14 +501,14 @@ var MemoryConvex = class extends storage.MemoryStorage {
|
|
|
401
501
|
if (resource.metadata !== void 0) {
|
|
402
502
|
record.metadata = resource.metadata;
|
|
403
503
|
}
|
|
404
|
-
await this.
|
|
504
|
+
await this.#db.insert({
|
|
405
505
|
tableName: storage.TABLE_RESOURCES,
|
|
406
506
|
record
|
|
407
507
|
});
|
|
408
508
|
return resource;
|
|
409
509
|
}
|
|
410
510
|
async getResourceById({ resourceId }) {
|
|
411
|
-
const record = await this.
|
|
511
|
+
const record = await this.#db.load({
|
|
412
512
|
tableName: storage.TABLE_RESOURCES,
|
|
413
513
|
keys: { id: resourceId }
|
|
414
514
|
});
|
|
@@ -494,12 +594,19 @@ var MemoryConvex = class extends storage.MemoryStorage {
|
|
|
494
594
|
}
|
|
495
595
|
};
|
|
496
596
|
var ScoresConvex = class extends storage.ScoresStorage {
|
|
497
|
-
|
|
597
|
+
#db;
|
|
598
|
+
constructor(config) {
|
|
498
599
|
super();
|
|
499
|
-
|
|
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 });
|
|
500
607
|
}
|
|
501
608
|
async getScoreById({ id }) {
|
|
502
|
-
const row = await this.
|
|
609
|
+
const row = await this.#db.load({
|
|
503
610
|
tableName: storage.TABLE_SCORERS,
|
|
504
611
|
keys: { id }
|
|
505
612
|
});
|
|
@@ -513,7 +620,7 @@ var ScoresConvex = class extends storage.ScoresStorage {
|
|
|
513
620
|
createdAt: now.toISOString(),
|
|
514
621
|
updatedAt: now.toISOString()
|
|
515
622
|
};
|
|
516
|
-
await this.
|
|
623
|
+
await this.#db.insert({
|
|
517
624
|
tableName: storage.TABLE_SCORERS,
|
|
518
625
|
record
|
|
519
626
|
});
|
|
@@ -564,7 +671,7 @@ var ScoresConvex = class extends storage.ScoresStorage {
|
|
|
564
671
|
new Error("page must be >= 0")
|
|
565
672
|
);
|
|
566
673
|
}
|
|
567
|
-
const rows = await this.
|
|
674
|
+
const rows = await this.#db.queryTable(storage.TABLE_SCORERS, void 0);
|
|
568
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());
|
|
569
676
|
const { perPage, page } = pagination;
|
|
570
677
|
const perPageValue = perPage === false ? filtered.length : perPage;
|
|
@@ -590,9 +697,16 @@ var ScoresConvex = class extends storage.ScoresStorage {
|
|
|
590
697
|
}
|
|
591
698
|
};
|
|
592
699
|
var WorkflowsConvex = class extends storage.WorkflowsStorage {
|
|
593
|
-
|
|
700
|
+
#db;
|
|
701
|
+
constructor(config) {
|
|
594
702
|
super();
|
|
595
|
-
|
|
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 });
|
|
596
710
|
}
|
|
597
711
|
async updateWorkflowResults({
|
|
598
712
|
workflowName,
|
|
@@ -639,11 +753,11 @@ var WorkflowsConvex = class extends storage.WorkflowsStorage {
|
|
|
639
753
|
snapshot
|
|
640
754
|
}) {
|
|
641
755
|
const now = /* @__PURE__ */ new Date();
|
|
642
|
-
const existing = await this.
|
|
756
|
+
const existing = await this.#db.load({
|
|
643
757
|
tableName: storage.TABLE_WORKFLOW_SNAPSHOT,
|
|
644
758
|
keys: { workflow_name: workflowName, run_id: runId }
|
|
645
759
|
});
|
|
646
|
-
await this.
|
|
760
|
+
await this.#db.insert({
|
|
647
761
|
tableName: storage.TABLE_WORKFLOW_SNAPSHOT,
|
|
648
762
|
record: {
|
|
649
763
|
workflow_name: workflowName,
|
|
@@ -659,7 +773,7 @@ var WorkflowsConvex = class extends storage.WorkflowsStorage {
|
|
|
659
773
|
workflowName,
|
|
660
774
|
runId
|
|
661
775
|
}) {
|
|
662
|
-
const row = await this.
|
|
776
|
+
const row = await this.#db.load({
|
|
663
777
|
tableName: storage.TABLE_WORKFLOW_SNAPSHOT,
|
|
664
778
|
keys: { workflow_name: workflowName, run_id: runId }
|
|
665
779
|
});
|
|
@@ -668,7 +782,7 @@ var WorkflowsConvex = class extends storage.WorkflowsStorage {
|
|
|
668
782
|
}
|
|
669
783
|
async listWorkflowRuns(args = {}) {
|
|
670
784
|
const { workflowName, fromDate, toDate, perPage, page, resourceId, status } = args;
|
|
671
|
-
let rows = await this.
|
|
785
|
+
let rows = await this.#db.queryTable(storage.TABLE_WORKFLOW_SNAPSHOT, void 0);
|
|
672
786
|
if (workflowName) rows = rows.filter((run) => run.workflow_name === workflowName);
|
|
673
787
|
if (resourceId) rows = rows.filter((run) => run.resourceId === resourceId);
|
|
674
788
|
if (fromDate) rows = rows.filter((run) => new Date(run.createdAt).getTime() >= fromDate.getTime());
|
|
@@ -700,7 +814,7 @@ var WorkflowsConvex = class extends storage.WorkflowsStorage {
|
|
|
700
814
|
runId,
|
|
701
815
|
workflowName
|
|
702
816
|
}) {
|
|
703
|
-
const runs = await this.
|
|
817
|
+
const runs = await this.#db.queryTable(storage.TABLE_WORKFLOW_SNAPSHOT, void 0);
|
|
704
818
|
const match = runs.find((run) => run.run_id === runId && (!workflowName || run.workflow_name === workflowName));
|
|
705
819
|
if (!match) return null;
|
|
706
820
|
return {
|
|
@@ -713,10 +827,10 @@ var WorkflowsConvex = class extends storage.WorkflowsStorage {
|
|
|
713
827
|
};
|
|
714
828
|
}
|
|
715
829
|
async deleteWorkflowRunById({ runId, workflowName }) {
|
|
716
|
-
await this.
|
|
830
|
+
await this.#db.deleteMany(storage.TABLE_WORKFLOW_SNAPSHOT, [`${workflowName}-${runId}`]);
|
|
717
831
|
}
|
|
718
832
|
async getRun(workflowName, runId) {
|
|
719
|
-
const runs = await this.
|
|
833
|
+
const runs = await this.#db.queryTable(storage.TABLE_WORKFLOW_SNAPSHOT, [
|
|
720
834
|
{ field: "workflow_name", value: workflowName }
|
|
721
835
|
]);
|
|
722
836
|
return runs.find((run) => run.run_id === runId) ?? null;
|
|
@@ -743,113 +857,24 @@ var WorkflowsConvex = class extends storage.WorkflowsStorage {
|
|
|
743
857
|
return JSON.parse(JSON.stringify(run.snapshot));
|
|
744
858
|
}
|
|
745
859
|
};
|
|
746
|
-
var StoreOperationsConvex = class extends storage.StoreOperations {
|
|
747
|
-
constructor(client) {
|
|
748
|
-
super();
|
|
749
|
-
this.client = client;
|
|
750
|
-
}
|
|
751
|
-
async hasColumn(_table, _column) {
|
|
752
|
-
return true;
|
|
753
|
-
}
|
|
754
|
-
async createTable(_args) {
|
|
755
|
-
}
|
|
756
|
-
async clearTable({ tableName }) {
|
|
757
|
-
let hasMore = true;
|
|
758
|
-
while (hasMore) {
|
|
759
|
-
const response = await this.client.callStorageRaw({
|
|
760
|
-
op: "clearTable",
|
|
761
|
-
tableName
|
|
762
|
-
});
|
|
763
|
-
hasMore = response.hasMore ?? false;
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
async dropTable({ tableName }) {
|
|
767
|
-
let hasMore = true;
|
|
768
|
-
while (hasMore) {
|
|
769
|
-
const response = await this.client.callStorageRaw({
|
|
770
|
-
op: "dropTable",
|
|
771
|
-
tableName
|
|
772
|
-
});
|
|
773
|
-
hasMore = response.hasMore ?? false;
|
|
774
|
-
}
|
|
775
|
-
}
|
|
776
|
-
async alterTable(_args) {
|
|
777
|
-
}
|
|
778
|
-
async insert({ tableName, record }) {
|
|
779
|
-
await this.client.callStorage({
|
|
780
|
-
op: "insert",
|
|
781
|
-
tableName,
|
|
782
|
-
record: this.normalizeRecord(tableName, record)
|
|
783
|
-
});
|
|
784
|
-
}
|
|
785
|
-
async batchInsert({ tableName, records }) {
|
|
786
|
-
if (records.length === 0) return;
|
|
787
|
-
await this.client.callStorage({
|
|
788
|
-
op: "batchInsert",
|
|
789
|
-
tableName,
|
|
790
|
-
records: records.map((record) => this.normalizeRecord(tableName, record))
|
|
791
|
-
});
|
|
792
|
-
}
|
|
793
|
-
async load({ tableName, keys }) {
|
|
794
|
-
const result = await this.client.callStorage({
|
|
795
|
-
op: "load",
|
|
796
|
-
tableName,
|
|
797
|
-
keys
|
|
798
|
-
});
|
|
799
|
-
return result;
|
|
800
|
-
}
|
|
801
|
-
async queryTable(tableName, filters) {
|
|
802
|
-
return this.client.callStorage({
|
|
803
|
-
op: "queryTable",
|
|
804
|
-
tableName,
|
|
805
|
-
filters
|
|
806
|
-
});
|
|
807
|
-
}
|
|
808
|
-
async deleteMany(tableName, ids) {
|
|
809
|
-
if (ids.length === 0) return;
|
|
810
|
-
await this.client.callStorage({
|
|
811
|
-
op: "deleteMany",
|
|
812
|
-
tableName,
|
|
813
|
-
ids
|
|
814
|
-
});
|
|
815
|
-
}
|
|
816
|
-
normalizeRecord(tableName, record) {
|
|
817
|
-
const normalized = { ...record };
|
|
818
|
-
if (tableName === storage.TABLE_WORKFLOW_SNAPSHOT && !normalized.id) {
|
|
819
|
-
const runId = normalized.run_id || normalized.runId;
|
|
820
|
-
const workflowName = normalized.workflow_name || normalized.workflowName;
|
|
821
|
-
normalized.id = workflowName ? `${workflowName}-${runId}` : runId;
|
|
822
|
-
}
|
|
823
|
-
if (!normalized.id) {
|
|
824
|
-
normalized.id = crypto__default.default.randomUUID();
|
|
825
|
-
}
|
|
826
|
-
for (const [key, value] of Object.entries(normalized)) {
|
|
827
|
-
if (value instanceof Date) {
|
|
828
|
-
normalized[key] = value.toISOString();
|
|
829
|
-
}
|
|
830
|
-
}
|
|
831
|
-
return normalized;
|
|
832
|
-
}
|
|
833
|
-
};
|
|
834
860
|
|
|
835
861
|
// src/storage/index.ts
|
|
862
|
+
var isClientConfig = (config) => {
|
|
863
|
+
return "client" in config;
|
|
864
|
+
};
|
|
836
865
|
var ConvexStore = class extends storage.MastraStorage {
|
|
837
|
-
|
|
838
|
-
memory;
|
|
839
|
-
workflows;
|
|
840
|
-
scores;
|
|
866
|
+
stores = {};
|
|
841
867
|
constructor(config) {
|
|
842
868
|
super({ id: config.id, name: config.name ?? "ConvexStore", disableInit: config.disableInit });
|
|
843
|
-
const client = new ConvexAdminClient(config);
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
869
|
+
const client = isClientConfig(config) ? config.client : new ConvexAdminClient(config);
|
|
870
|
+
const domainConfig = { client };
|
|
871
|
+
const memory = new MemoryConvex(domainConfig);
|
|
872
|
+
const workflows = new WorkflowsConvex(domainConfig);
|
|
873
|
+
const scores = new ScoresConvex(domainConfig);
|
|
848
874
|
this.stores = {
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
scores: this.scores
|
|
875
|
+
memory,
|
|
876
|
+
workflows,
|
|
877
|
+
scores
|
|
853
878
|
};
|
|
854
879
|
}
|
|
855
880
|
get supports() {
|
|
@@ -859,138 +884,12 @@ var ConvexStore = class extends storage.MastraStorage {
|
|
|
859
884
|
hasColumn: false,
|
|
860
885
|
createTable: false,
|
|
861
886
|
deleteMessages: true,
|
|
862
|
-
|
|
863
|
-
|
|
887
|
+
observability: false,
|
|
888
|
+
indexManagement: false,
|
|
889
|
+
listScoresBySpan: false,
|
|
890
|
+
agents: false
|
|
864
891
|
};
|
|
865
892
|
}
|
|
866
|
-
async createTable(_args) {
|
|
867
|
-
}
|
|
868
|
-
async clearTable({ tableName }) {
|
|
869
|
-
await this.operations.clearTable({ tableName });
|
|
870
|
-
}
|
|
871
|
-
async dropTable({ tableName }) {
|
|
872
|
-
await this.operations.dropTable({ tableName });
|
|
873
|
-
}
|
|
874
|
-
async alterTable(_args) {
|
|
875
|
-
}
|
|
876
|
-
async insert({ tableName, record }) {
|
|
877
|
-
await this.operations.insert({ tableName, record });
|
|
878
|
-
}
|
|
879
|
-
async batchInsert({ tableName, records }) {
|
|
880
|
-
await this.operations.batchInsert({ tableName, records });
|
|
881
|
-
}
|
|
882
|
-
async load({ tableName, keys }) {
|
|
883
|
-
return this.operations.load({ tableName, keys });
|
|
884
|
-
}
|
|
885
|
-
async getThreadById({ threadId }) {
|
|
886
|
-
return this.memory.getThreadById({ threadId });
|
|
887
|
-
}
|
|
888
|
-
async saveThread({ thread }) {
|
|
889
|
-
return this.memory.saveThread({ thread });
|
|
890
|
-
}
|
|
891
|
-
async updateThread({
|
|
892
|
-
id,
|
|
893
|
-
title,
|
|
894
|
-
metadata
|
|
895
|
-
}) {
|
|
896
|
-
return this.memory.updateThread({ id, title, metadata });
|
|
897
|
-
}
|
|
898
|
-
async deleteThread({ threadId }) {
|
|
899
|
-
await this.memory.deleteThread({ threadId });
|
|
900
|
-
}
|
|
901
|
-
async listMessages(args) {
|
|
902
|
-
return this.memory.listMessages(args);
|
|
903
|
-
}
|
|
904
|
-
async listMessagesById({ messageIds }) {
|
|
905
|
-
return this.memory.listMessagesById({ messageIds });
|
|
906
|
-
}
|
|
907
|
-
async saveMessages(args) {
|
|
908
|
-
return this.memory.saveMessages(args);
|
|
909
|
-
}
|
|
910
|
-
async updateMessages({
|
|
911
|
-
messages
|
|
912
|
-
}) {
|
|
913
|
-
return this.memory.updateMessages({ messages });
|
|
914
|
-
}
|
|
915
|
-
async deleteMessages(messageIds) {
|
|
916
|
-
await this.memory.deleteMessages(messageIds);
|
|
917
|
-
}
|
|
918
|
-
async listThreadsByResourceId(args) {
|
|
919
|
-
return this.memory.listThreadsByResourceId(args);
|
|
920
|
-
}
|
|
921
|
-
async getResourceById({ resourceId }) {
|
|
922
|
-
return this.memory.getResourceById({ resourceId });
|
|
923
|
-
}
|
|
924
|
-
async saveResource({ resource }) {
|
|
925
|
-
return this.memory.saveResource({ resource });
|
|
926
|
-
}
|
|
927
|
-
async updateResource({
|
|
928
|
-
resourceId,
|
|
929
|
-
workingMemory,
|
|
930
|
-
metadata
|
|
931
|
-
}) {
|
|
932
|
-
return this.memory.updateResource({ resourceId, workingMemory, metadata });
|
|
933
|
-
}
|
|
934
|
-
async updateWorkflowResults(params) {
|
|
935
|
-
return this.workflows.updateWorkflowResults(params);
|
|
936
|
-
}
|
|
937
|
-
async updateWorkflowState(params) {
|
|
938
|
-
return this.workflows.updateWorkflowState(params);
|
|
939
|
-
}
|
|
940
|
-
async persistWorkflowSnapshot({
|
|
941
|
-
workflowName,
|
|
942
|
-
runId,
|
|
943
|
-
resourceId,
|
|
944
|
-
snapshot
|
|
945
|
-
}) {
|
|
946
|
-
await this.workflows.persistWorkflowSnapshot({ workflowName, runId, resourceId, snapshot });
|
|
947
|
-
}
|
|
948
|
-
async loadWorkflowSnapshot({
|
|
949
|
-
workflowName,
|
|
950
|
-
runId
|
|
951
|
-
}) {
|
|
952
|
-
return this.workflows.loadWorkflowSnapshot({ workflowName, runId });
|
|
953
|
-
}
|
|
954
|
-
async listWorkflowRuns(args) {
|
|
955
|
-
return this.workflows.listWorkflowRuns(args);
|
|
956
|
-
}
|
|
957
|
-
async getWorkflowRunById({
|
|
958
|
-
runId,
|
|
959
|
-
workflowName
|
|
960
|
-
}) {
|
|
961
|
-
return this.workflows.getWorkflowRunById({ runId, workflowName });
|
|
962
|
-
}
|
|
963
|
-
async deleteWorkflowRunById({ runId, workflowName }) {
|
|
964
|
-
return this.workflows.deleteWorkflowRunById({ runId, workflowName });
|
|
965
|
-
}
|
|
966
|
-
async getScoreById({ id }) {
|
|
967
|
-
return this.scores.getScoreById({ id });
|
|
968
|
-
}
|
|
969
|
-
async saveScore(score) {
|
|
970
|
-
return this.scores.saveScore(score);
|
|
971
|
-
}
|
|
972
|
-
async listScoresByScorerId({
|
|
973
|
-
scorerId,
|
|
974
|
-
pagination,
|
|
975
|
-
entityId,
|
|
976
|
-
entityType,
|
|
977
|
-
source
|
|
978
|
-
}) {
|
|
979
|
-
return this.scores.listScoresByScorerId({ scorerId, pagination, entityId, entityType, source });
|
|
980
|
-
}
|
|
981
|
-
async listScoresByRunId({
|
|
982
|
-
runId,
|
|
983
|
-
pagination
|
|
984
|
-
}) {
|
|
985
|
-
return this.scores.listScoresByRunId({ runId, pagination });
|
|
986
|
-
}
|
|
987
|
-
async listScoresByEntityId({
|
|
988
|
-
entityId,
|
|
989
|
-
entityType,
|
|
990
|
-
pagination
|
|
991
|
-
}) {
|
|
992
|
-
return this.scores.listScoresByEntityId({ entityId, entityType, pagination });
|
|
993
|
-
}
|
|
994
893
|
};
|
|
995
894
|
var INDEX_METADATA_TABLE = "mastra_vector_indexes";
|
|
996
895
|
var ConvexVector = class extends vector.MastraVector {
|
|
@@ -1301,55 +1200,55 @@ Object.defineProperty(exports, "mastraStorage", {
|
|
|
1301
1200
|
});
|
|
1302
1201
|
Object.defineProperty(exports, "TABLE_MESSAGES", {
|
|
1303
1202
|
enumerable: true,
|
|
1304
|
-
get: function () { return
|
|
1203
|
+
get: function () { return chunkH5QJE733_cjs.TABLE_MESSAGES; }
|
|
1305
1204
|
});
|
|
1306
1205
|
Object.defineProperty(exports, "TABLE_RESOURCES", {
|
|
1307
1206
|
enumerable: true,
|
|
1308
|
-
get: function () { return
|
|
1207
|
+
get: function () { return chunkH5QJE733_cjs.TABLE_RESOURCES; }
|
|
1309
1208
|
});
|
|
1310
1209
|
Object.defineProperty(exports, "TABLE_SCORERS", {
|
|
1311
1210
|
enumerable: true,
|
|
1312
|
-
get: function () { return
|
|
1211
|
+
get: function () { return chunkH5QJE733_cjs.TABLE_SCORERS; }
|
|
1313
1212
|
});
|
|
1314
1213
|
Object.defineProperty(exports, "TABLE_THREADS", {
|
|
1315
1214
|
enumerable: true,
|
|
1316
|
-
get: function () { return
|
|
1215
|
+
get: function () { return chunkH5QJE733_cjs.TABLE_THREADS; }
|
|
1317
1216
|
});
|
|
1318
1217
|
Object.defineProperty(exports, "TABLE_WORKFLOW_SNAPSHOT", {
|
|
1319
1218
|
enumerable: true,
|
|
1320
|
-
get: function () { return
|
|
1219
|
+
get: function () { return chunkH5QJE733_cjs.TABLE_WORKFLOW_SNAPSHOT; }
|
|
1321
1220
|
});
|
|
1322
1221
|
Object.defineProperty(exports, "mastraDocumentsTable", {
|
|
1323
1222
|
enumerable: true,
|
|
1324
|
-
get: function () { return
|
|
1223
|
+
get: function () { return chunkH5QJE733_cjs.mastraDocumentsTable; }
|
|
1325
1224
|
});
|
|
1326
1225
|
Object.defineProperty(exports, "mastraMessagesTable", {
|
|
1327
1226
|
enumerable: true,
|
|
1328
|
-
get: function () { return
|
|
1227
|
+
get: function () { return chunkH5QJE733_cjs.mastraMessagesTable; }
|
|
1329
1228
|
});
|
|
1330
1229
|
Object.defineProperty(exports, "mastraResourcesTable", {
|
|
1331
1230
|
enumerable: true,
|
|
1332
|
-
get: function () { return
|
|
1231
|
+
get: function () { return chunkH5QJE733_cjs.mastraResourcesTable; }
|
|
1333
1232
|
});
|
|
1334
1233
|
Object.defineProperty(exports, "mastraScoresTable", {
|
|
1335
1234
|
enumerable: true,
|
|
1336
|
-
get: function () { return
|
|
1235
|
+
get: function () { return chunkH5QJE733_cjs.mastraScoresTable; }
|
|
1337
1236
|
});
|
|
1338
1237
|
Object.defineProperty(exports, "mastraThreadsTable", {
|
|
1339
1238
|
enumerable: true,
|
|
1340
|
-
get: function () { return
|
|
1239
|
+
get: function () { return chunkH5QJE733_cjs.mastraThreadsTable; }
|
|
1341
1240
|
});
|
|
1342
1241
|
Object.defineProperty(exports, "mastraVectorIndexesTable", {
|
|
1343
1242
|
enumerable: true,
|
|
1344
|
-
get: function () { return
|
|
1243
|
+
get: function () { return chunkH5QJE733_cjs.mastraVectorIndexesTable; }
|
|
1345
1244
|
});
|
|
1346
1245
|
Object.defineProperty(exports, "mastraVectorsTable", {
|
|
1347
1246
|
enumerable: true,
|
|
1348
|
-
get: function () { return
|
|
1247
|
+
get: function () { return chunkH5QJE733_cjs.mastraVectorsTable; }
|
|
1349
1248
|
});
|
|
1350
1249
|
Object.defineProperty(exports, "mastraWorkflowSnapshotsTable", {
|
|
1351
1250
|
enumerable: true,
|
|
1352
|
-
get: function () { return
|
|
1251
|
+
get: function () { return chunkH5QJE733_cjs.mastraWorkflowSnapshotsTable; }
|
|
1353
1252
|
});
|
|
1354
1253
|
exports.ConvexStore = ConvexStore;
|
|
1355
1254
|
exports.ConvexVector = ConvexVector;
|