@mastra/convex 0.0.0-top-level-fix-20251211111608 → 0.0.0-type-testing-20260120105120
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +754 -5
- package/README.md +1 -1
- package/dist/{chunk-QKN2PWR2.cjs → chunk-BKVR7SL7.cjs} +2 -89
- package/dist/chunk-BKVR7SL7.cjs.map +1 -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/{chunk-NZCHEPNU.js → chunk-KSAPIIEJ.js} +5 -65
- package/dist/chunk-KSAPIIEJ.js.map +1 -0
- package/dist/docs/README.md +32 -0
- package/dist/docs/SKILL.md +46 -0
- package/dist/docs/SOURCE_MAP.json +63 -0
- package/dist/docs/storage/01-reference.md +140 -0
- package/dist/docs/vectors/01-reference.md +240 -0
- package/dist/index.cjs +208 -306
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +192 -290
- package/dist/index.js.map +1 -1
- package/dist/schema.cjs +72 -0
- package/dist/schema.cjs.map +1 -0
- package/dist/{server/schema.d.ts → schema.d.ts} +14 -1
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +3 -0
- package/dist/schema.js.map +1 -0
- package/dist/server/index.cjs +19 -18
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +2 -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} +8 -6
- 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} +9 -13
- package/dist/storage/domains/workflows/index.d.ts.map +1 -0
- package/dist/storage/index.d.ts +54 -157
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +19 -9
- package/dist/chunk-NZCHEPNU.js.map +0 -1
- package/dist/chunk-QKN2PWR2.cjs.map +0 -1
- 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,10 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
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
|
-
|
|
172
|
+
#db;
|
|
173
|
+
constructor(config) {
|
|
79
174
|
super();
|
|
80
|
-
|
|
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.
|
|
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.
|
|
199
|
+
await this.#db.insert({
|
|
97
200
|
tableName: storage.TABLE_THREADS,
|
|
98
201
|
record: {
|
|
99
202
|
...thread,
|
|
@@ -129,27 +232,50 @@ var MemoryConvex = class extends storage.MemoryStorage {
|
|
|
129
232
|
return updated;
|
|
130
233
|
}
|
|
131
234
|
async deleteThread({ threadId }) {
|
|
132
|
-
const messages = await this.
|
|
235
|
+
const messages = await this.#db.queryTable(storage.TABLE_MESSAGES, [
|
|
133
236
|
{ field: "thread_id", value: threadId }
|
|
134
237
|
]);
|
|
135
|
-
await this.
|
|
238
|
+
await this.#db.deleteMany(
|
|
136
239
|
storage.TABLE_MESSAGES,
|
|
137
240
|
messages.map((msg) => msg.id)
|
|
138
241
|
);
|
|
139
|
-
await this.
|
|
242
|
+
await this.#db.deleteMany(storage.TABLE_THREADS, [threadId]);
|
|
140
243
|
}
|
|
141
|
-
async
|
|
142
|
-
const {
|
|
244
|
+
async listThreads(args) {
|
|
245
|
+
const { page = 0, perPage: perPageInput, orderBy, filter } = args;
|
|
246
|
+
try {
|
|
247
|
+
this.validatePaginationInput(page, perPageInput ?? 100);
|
|
248
|
+
} catch (error$1) {
|
|
249
|
+
throw new error.MastraError(
|
|
250
|
+
{
|
|
251
|
+
id: storage.createStorageErrorId("CONVEX", "LIST_THREADS", "INVALID_PAGE"),
|
|
252
|
+
domain: error.ErrorDomain.STORAGE,
|
|
253
|
+
category: error.ErrorCategory.USER,
|
|
254
|
+
details: { page, ...perPageInput !== void 0 && { perPage: perPageInput } }
|
|
255
|
+
},
|
|
256
|
+
error$1 instanceof Error ? error$1 : new Error("Invalid pagination parameters")
|
|
257
|
+
);
|
|
258
|
+
}
|
|
143
259
|
const perPage = storage.normalizePerPage(perPageInput, 100);
|
|
144
260
|
const { field, direction } = this.parseOrderBy(orderBy);
|
|
145
261
|
const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
146
|
-
const
|
|
147
|
-
|
|
262
|
+
const queryFilters = [];
|
|
263
|
+
if (filter?.resourceId) {
|
|
264
|
+
queryFilters.push({ field: "resourceId", value: filter.resourceId });
|
|
265
|
+
}
|
|
266
|
+
const rows = await this.#db.queryTable(storage.TABLE_THREADS, queryFilters);
|
|
267
|
+
let threads = rows.map((row) => ({
|
|
148
268
|
...row,
|
|
149
269
|
metadata: typeof row.metadata === "string" ? JSON.parse(row.metadata) : row.metadata,
|
|
150
270
|
createdAt: new Date(row.createdAt),
|
|
151
271
|
updatedAt: new Date(row.updatedAt)
|
|
152
272
|
}));
|
|
273
|
+
if (filter?.metadata && Object.keys(filter.metadata).length > 0) {
|
|
274
|
+
threads = threads.filter((thread) => {
|
|
275
|
+
if (!thread.metadata) return false;
|
|
276
|
+
return Object.entries(filter.metadata).every(([key, value]) => thread.metadata[key] === value);
|
|
277
|
+
});
|
|
278
|
+
}
|
|
153
279
|
threads.sort((a, b) => {
|
|
154
280
|
const aValue = a[field];
|
|
155
281
|
const bValue = b[field];
|
|
@@ -186,23 +312,13 @@ var MemoryConvex = class extends storage.MemoryStorage {
|
|
|
186
312
|
const { field, direction } = this.parseOrderBy(orderBy, "ASC");
|
|
187
313
|
let rows = [];
|
|
188
314
|
for (const tid of threadIds) {
|
|
189
|
-
const threadRows = await this.
|
|
190
|
-
{ field: "thread_id", value: tid }
|
|
191
|
-
]);
|
|
315
|
+
const threadRows = await this.#db.queryTable(storage.TABLE_MESSAGES, [{ field: "thread_id", value: tid }]);
|
|
192
316
|
rows.push(...threadRows);
|
|
193
317
|
}
|
|
194
318
|
if (resourceId) {
|
|
195
319
|
rows = rows.filter((row) => row.resourceId === resourceId);
|
|
196
320
|
}
|
|
197
|
-
|
|
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
|
-
}
|
|
321
|
+
rows = storage.filterByDateRange(rows, (row) => new Date(row.createdAt), filter?.dateRange);
|
|
206
322
|
rows.sort((a, b) => {
|
|
207
323
|
const aValue = field === "createdAt" || field === "updatedAt" ? new Date(a[field]).getTime() : a[field];
|
|
208
324
|
const bValue = field === "createdAt" || field === "updatedAt" ? new Date(b[field]).getTime() : b[field];
|
|
@@ -232,14 +348,14 @@ var MemoryConvex = class extends storage.MemoryStorage {
|
|
|
232
348
|
}
|
|
233
349
|
}
|
|
234
350
|
if (!target) {
|
|
235
|
-
const messageRows = await this.
|
|
351
|
+
const messageRows = await this.#db.queryTable(storage.TABLE_MESSAGES, [
|
|
236
352
|
{ field: "id", value: includeItem.id }
|
|
237
353
|
]);
|
|
238
354
|
if (messageRows.length > 0) {
|
|
239
355
|
target = messageRows[0];
|
|
240
356
|
targetThreadId = target.thread_id;
|
|
241
357
|
if (targetThreadId && !threadMessagesCache.has(targetThreadId)) {
|
|
242
|
-
const otherThreadRows = await this.
|
|
358
|
+
const otherThreadRows = await this.#db.queryTable(storage.TABLE_MESSAGES, [
|
|
243
359
|
{ field: "thread_id", value: targetThreadId }
|
|
244
360
|
]);
|
|
245
361
|
threadMessagesCache.set(targetThreadId, otherThreadRows);
|
|
@@ -282,7 +398,7 @@ var MemoryConvex = class extends storage.MemoryStorage {
|
|
|
282
398
|
if (messageIds.length === 0) {
|
|
283
399
|
return { messages: [] };
|
|
284
400
|
}
|
|
285
|
-
const rows = await this.
|
|
401
|
+
const rows = await this.#db.queryTable(storage.TABLE_MESSAGES, void 0);
|
|
286
402
|
const filtered = rows.filter((row) => messageIds.includes(row.id)).map((row) => this.parseStoredMessage(row));
|
|
287
403
|
const list = new agent.MessageList().add(filtered, "memory");
|
|
288
404
|
return { messages: list.get.all.db() };
|
|
@@ -307,7 +423,7 @@ var MemoryConvex = class extends storage.MemoryStorage {
|
|
|
307
423
|
resourceId: message.resourceId
|
|
308
424
|
};
|
|
309
425
|
});
|
|
310
|
-
await this.
|
|
426
|
+
await this.#db.batchInsert({
|
|
311
427
|
tableName: storage.TABLE_MESSAGES,
|
|
312
428
|
records: normalized
|
|
313
429
|
});
|
|
@@ -316,7 +432,7 @@ var MemoryConvex = class extends storage.MemoryStorage {
|
|
|
316
432
|
for (const threadId of threadIds) {
|
|
317
433
|
const thread = await this.getThreadById({ threadId });
|
|
318
434
|
if (thread) {
|
|
319
|
-
await this.
|
|
435
|
+
await this.#db.insert({
|
|
320
436
|
tableName: storage.TABLE_THREADS,
|
|
321
437
|
record: {
|
|
322
438
|
...thread,
|
|
@@ -335,7 +451,7 @@ var MemoryConvex = class extends storage.MemoryStorage {
|
|
|
335
451
|
messages
|
|
336
452
|
}) {
|
|
337
453
|
if (messages.length === 0) return [];
|
|
338
|
-
const existing = await this.
|
|
454
|
+
const existing = await this.#db.queryTable(storage.TABLE_MESSAGES, void 0);
|
|
339
455
|
const updated = [];
|
|
340
456
|
const affectedThreadIds = /* @__PURE__ */ new Set();
|
|
341
457
|
for (const update of messages) {
|
|
@@ -364,7 +480,7 @@ var MemoryConvex = class extends storage.MemoryStorage {
|
|
|
364
480
|
};
|
|
365
481
|
current.content = JSON.stringify(mergedContent);
|
|
366
482
|
}
|
|
367
|
-
await this.
|
|
483
|
+
await this.#db.insert({
|
|
368
484
|
tableName: storage.TABLE_MESSAGES,
|
|
369
485
|
record: current
|
|
370
486
|
});
|
|
@@ -374,7 +490,7 @@ var MemoryConvex = class extends storage.MemoryStorage {
|
|
|
374
490
|
for (const threadId of affectedThreadIds) {
|
|
375
491
|
const thread = await this.getThreadById({ threadId });
|
|
376
492
|
if (thread) {
|
|
377
|
-
await this.
|
|
493
|
+
await this.#db.insert({
|
|
378
494
|
tableName: storage.TABLE_THREADS,
|
|
379
495
|
record: {
|
|
380
496
|
...thread,
|
|
@@ -389,7 +505,7 @@ var MemoryConvex = class extends storage.MemoryStorage {
|
|
|
389
505
|
return updated;
|
|
390
506
|
}
|
|
391
507
|
async deleteMessages(messageIds) {
|
|
392
|
-
await this.
|
|
508
|
+
await this.#db.deleteMany(storage.TABLE_MESSAGES, messageIds);
|
|
393
509
|
}
|
|
394
510
|
async saveResource({ resource }) {
|
|
395
511
|
const record = {
|
|
@@ -400,14 +516,14 @@ var MemoryConvex = class extends storage.MemoryStorage {
|
|
|
400
516
|
if (resource.metadata !== void 0) {
|
|
401
517
|
record.metadata = resource.metadata;
|
|
402
518
|
}
|
|
403
|
-
await this.
|
|
519
|
+
await this.#db.insert({
|
|
404
520
|
tableName: storage.TABLE_RESOURCES,
|
|
405
521
|
record
|
|
406
522
|
});
|
|
407
523
|
return resource;
|
|
408
524
|
}
|
|
409
525
|
async getResourceById({ resourceId }) {
|
|
410
|
-
const record = await this.
|
|
526
|
+
const record = await this.#db.load({
|
|
411
527
|
tableName: storage.TABLE_RESOURCES,
|
|
412
528
|
keys: { id: resourceId }
|
|
413
529
|
});
|
|
@@ -493,12 +609,19 @@ var MemoryConvex = class extends storage.MemoryStorage {
|
|
|
493
609
|
}
|
|
494
610
|
};
|
|
495
611
|
var ScoresConvex = class extends storage.ScoresStorage {
|
|
496
|
-
|
|
612
|
+
#db;
|
|
613
|
+
constructor(config) {
|
|
497
614
|
super();
|
|
498
|
-
|
|
615
|
+
const client = resolveConvexConfig(config);
|
|
616
|
+
this.#db = new ConvexDB(client);
|
|
617
|
+
}
|
|
618
|
+
async init() {
|
|
619
|
+
}
|
|
620
|
+
async dangerouslyClearAll() {
|
|
621
|
+
await this.#db.clearTable({ tableName: storage.TABLE_SCORERS });
|
|
499
622
|
}
|
|
500
623
|
async getScoreById({ id }) {
|
|
501
|
-
const row = await this.
|
|
624
|
+
const row = await this.#db.load({
|
|
502
625
|
tableName: storage.TABLE_SCORERS,
|
|
503
626
|
keys: { id }
|
|
504
627
|
});
|
|
@@ -512,7 +635,7 @@ var ScoresConvex = class extends storage.ScoresStorage {
|
|
|
512
635
|
createdAt: now.toISOString(),
|
|
513
636
|
updatedAt: now.toISOString()
|
|
514
637
|
};
|
|
515
|
-
await this.
|
|
638
|
+
await this.#db.insert({
|
|
516
639
|
tableName: storage.TABLE_SCORERS,
|
|
517
640
|
record
|
|
518
641
|
});
|
|
@@ -563,7 +686,7 @@ var ScoresConvex = class extends storage.ScoresStorage {
|
|
|
563
686
|
new Error("page must be >= 0")
|
|
564
687
|
);
|
|
565
688
|
}
|
|
566
|
-
const rows = await this.
|
|
689
|
+
const rows = await this.#db.queryTable(storage.TABLE_SCORERS, void 0);
|
|
567
690
|
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
691
|
const { perPage, page } = pagination;
|
|
569
692
|
const perPageValue = perPage === false ? filtered.length : perPage;
|
|
@@ -589,9 +712,16 @@ var ScoresConvex = class extends storage.ScoresStorage {
|
|
|
589
712
|
}
|
|
590
713
|
};
|
|
591
714
|
var WorkflowsConvex = class extends storage.WorkflowsStorage {
|
|
592
|
-
|
|
715
|
+
#db;
|
|
716
|
+
constructor(config) {
|
|
593
717
|
super();
|
|
594
|
-
|
|
718
|
+
const client = resolveConvexConfig(config);
|
|
719
|
+
this.#db = new ConvexDB(client);
|
|
720
|
+
}
|
|
721
|
+
async init() {
|
|
722
|
+
}
|
|
723
|
+
async dangerouslyClearAll() {
|
|
724
|
+
await this.#db.clearTable({ tableName: storage.TABLE_WORKFLOW_SNAPSHOT });
|
|
595
725
|
}
|
|
596
726
|
async updateWorkflowResults({
|
|
597
727
|
workflowName,
|
|
@@ -638,11 +768,11 @@ var WorkflowsConvex = class extends storage.WorkflowsStorage {
|
|
|
638
768
|
snapshot
|
|
639
769
|
}) {
|
|
640
770
|
const now = /* @__PURE__ */ new Date();
|
|
641
|
-
const existing = await this.
|
|
771
|
+
const existing = await this.#db.load({
|
|
642
772
|
tableName: storage.TABLE_WORKFLOW_SNAPSHOT,
|
|
643
773
|
keys: { workflow_name: workflowName, run_id: runId }
|
|
644
774
|
});
|
|
645
|
-
await this.
|
|
775
|
+
await this.#db.insert({
|
|
646
776
|
tableName: storage.TABLE_WORKFLOW_SNAPSHOT,
|
|
647
777
|
record: {
|
|
648
778
|
workflow_name: workflowName,
|
|
@@ -658,7 +788,7 @@ var WorkflowsConvex = class extends storage.WorkflowsStorage {
|
|
|
658
788
|
workflowName,
|
|
659
789
|
runId
|
|
660
790
|
}) {
|
|
661
|
-
const row = await this.
|
|
791
|
+
const row = await this.#db.load({
|
|
662
792
|
tableName: storage.TABLE_WORKFLOW_SNAPSHOT,
|
|
663
793
|
keys: { workflow_name: workflowName, run_id: runId }
|
|
664
794
|
});
|
|
@@ -667,7 +797,7 @@ var WorkflowsConvex = class extends storage.WorkflowsStorage {
|
|
|
667
797
|
}
|
|
668
798
|
async listWorkflowRuns(args = {}) {
|
|
669
799
|
const { workflowName, fromDate, toDate, perPage, page, resourceId, status } = args;
|
|
670
|
-
let rows = await this.
|
|
800
|
+
let rows = await this.#db.queryTable(storage.TABLE_WORKFLOW_SNAPSHOT, void 0);
|
|
671
801
|
if (workflowName) rows = rows.filter((run) => run.workflow_name === workflowName);
|
|
672
802
|
if (resourceId) rows = rows.filter((run) => run.resourceId === resourceId);
|
|
673
803
|
if (fromDate) rows = rows.filter((run) => new Date(run.createdAt).getTime() >= fromDate.getTime());
|
|
@@ -699,7 +829,7 @@ var WorkflowsConvex = class extends storage.WorkflowsStorage {
|
|
|
699
829
|
runId,
|
|
700
830
|
workflowName
|
|
701
831
|
}) {
|
|
702
|
-
const runs = await this.
|
|
832
|
+
const runs = await this.#db.queryTable(storage.TABLE_WORKFLOW_SNAPSHOT, void 0);
|
|
703
833
|
const match = runs.find((run) => run.run_id === runId && (!workflowName || run.workflow_name === workflowName));
|
|
704
834
|
if (!match) return null;
|
|
705
835
|
return {
|
|
@@ -712,10 +842,10 @@ var WorkflowsConvex = class extends storage.WorkflowsStorage {
|
|
|
712
842
|
};
|
|
713
843
|
}
|
|
714
844
|
async deleteWorkflowRunById({ runId, workflowName }) {
|
|
715
|
-
await this.
|
|
845
|
+
await this.#db.deleteMany(storage.TABLE_WORKFLOW_SNAPSHOT, [`${workflowName}-${runId}`]);
|
|
716
846
|
}
|
|
717
847
|
async getRun(workflowName, runId) {
|
|
718
|
-
const runs = await this.
|
|
848
|
+
const runs = await this.#db.queryTable(storage.TABLE_WORKFLOW_SNAPSHOT, [
|
|
719
849
|
{ field: "workflow_name", value: workflowName }
|
|
720
850
|
]);
|
|
721
851
|
return runs.find((run) => run.run_id === runId) ?? null;
|
|
@@ -742,254 +872,26 @@ var WorkflowsConvex = class extends storage.WorkflowsStorage {
|
|
|
742
872
|
return JSON.parse(JSON.stringify(run.snapshot));
|
|
743
873
|
}
|
|
744
874
|
};
|
|
745
|
-
var StoreOperationsConvex = class extends storage.StoreOperations {
|
|
746
|
-
constructor(client) {
|
|
747
|
-
super();
|
|
748
|
-
this.client = client;
|
|
749
|
-
}
|
|
750
|
-
async hasColumn(_table, _column) {
|
|
751
|
-
return true;
|
|
752
|
-
}
|
|
753
|
-
async createTable(_args) {
|
|
754
|
-
}
|
|
755
|
-
async clearTable({ tableName }) {
|
|
756
|
-
let hasMore = true;
|
|
757
|
-
while (hasMore) {
|
|
758
|
-
const response = await this.client.callStorageRaw({
|
|
759
|
-
op: "clearTable",
|
|
760
|
-
tableName
|
|
761
|
-
});
|
|
762
|
-
hasMore = response.hasMore ?? false;
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
async dropTable({ tableName }) {
|
|
766
|
-
let hasMore = true;
|
|
767
|
-
while (hasMore) {
|
|
768
|
-
const response = await this.client.callStorageRaw({
|
|
769
|
-
op: "dropTable",
|
|
770
|
-
tableName
|
|
771
|
-
});
|
|
772
|
-
hasMore = response.hasMore ?? false;
|
|
773
|
-
}
|
|
774
|
-
}
|
|
775
|
-
async alterTable(_args) {
|
|
776
|
-
}
|
|
777
|
-
async insert({ tableName, record }) {
|
|
778
|
-
await this.client.callStorage({
|
|
779
|
-
op: "insert",
|
|
780
|
-
tableName,
|
|
781
|
-
record: this.normalizeRecord(tableName, record)
|
|
782
|
-
});
|
|
783
|
-
}
|
|
784
|
-
async batchInsert({ tableName, records }) {
|
|
785
|
-
if (records.length === 0) return;
|
|
786
|
-
await this.client.callStorage({
|
|
787
|
-
op: "batchInsert",
|
|
788
|
-
tableName,
|
|
789
|
-
records: records.map((record) => this.normalizeRecord(tableName, record))
|
|
790
|
-
});
|
|
791
|
-
}
|
|
792
|
-
async load({ tableName, keys }) {
|
|
793
|
-
const result = await this.client.callStorage({
|
|
794
|
-
op: "load",
|
|
795
|
-
tableName,
|
|
796
|
-
keys
|
|
797
|
-
});
|
|
798
|
-
return result;
|
|
799
|
-
}
|
|
800
|
-
async queryTable(tableName, filters) {
|
|
801
|
-
return this.client.callStorage({
|
|
802
|
-
op: "queryTable",
|
|
803
|
-
tableName,
|
|
804
|
-
filters
|
|
805
|
-
});
|
|
806
|
-
}
|
|
807
|
-
async deleteMany(tableName, ids) {
|
|
808
|
-
if (ids.length === 0) return;
|
|
809
|
-
await this.client.callStorage({
|
|
810
|
-
op: "deleteMany",
|
|
811
|
-
tableName,
|
|
812
|
-
ids
|
|
813
|
-
});
|
|
814
|
-
}
|
|
815
|
-
normalizeRecord(tableName, record) {
|
|
816
|
-
const normalized = { ...record };
|
|
817
|
-
if (tableName === storage.TABLE_WORKFLOW_SNAPSHOT && !normalized.id) {
|
|
818
|
-
const runId = normalized.run_id || normalized.runId;
|
|
819
|
-
const workflowName = normalized.workflow_name || normalized.workflowName;
|
|
820
|
-
normalized.id = workflowName ? `${workflowName}-${runId}` : runId;
|
|
821
|
-
}
|
|
822
|
-
if (!normalized.id) {
|
|
823
|
-
normalized.id = crypto__default.default.randomUUID();
|
|
824
|
-
}
|
|
825
|
-
for (const [key, value] of Object.entries(normalized)) {
|
|
826
|
-
if (value instanceof Date) {
|
|
827
|
-
normalized[key] = value.toISOString();
|
|
828
|
-
}
|
|
829
|
-
}
|
|
830
|
-
return normalized;
|
|
831
|
-
}
|
|
832
|
-
};
|
|
833
875
|
|
|
834
876
|
// src/storage/index.ts
|
|
877
|
+
var isClientConfig = (config) => {
|
|
878
|
+
return "client" in config;
|
|
879
|
+
};
|
|
835
880
|
var ConvexStore = class extends storage.MastraStorage {
|
|
836
|
-
|
|
837
|
-
memory;
|
|
838
|
-
workflows;
|
|
839
|
-
scores;
|
|
881
|
+
stores = {};
|
|
840
882
|
constructor(config) {
|
|
841
883
|
super({ id: config.id, name: config.name ?? "ConvexStore", disableInit: config.disableInit });
|
|
842
|
-
const client = new ConvexAdminClient(config);
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
884
|
+
const client = isClientConfig(config) ? config.client : new ConvexAdminClient(config);
|
|
885
|
+
const domainConfig = { client };
|
|
886
|
+
const memory = new MemoryConvex(domainConfig);
|
|
887
|
+
const workflows = new WorkflowsConvex(domainConfig);
|
|
888
|
+
const scores = new ScoresConvex(domainConfig);
|
|
847
889
|
this.stores = {
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
scores: this.scores
|
|
890
|
+
memory,
|
|
891
|
+
workflows,
|
|
892
|
+
scores
|
|
852
893
|
};
|
|
853
894
|
}
|
|
854
|
-
get supports() {
|
|
855
|
-
return {
|
|
856
|
-
selectByIncludeResourceScope: true,
|
|
857
|
-
resourceWorkingMemory: true,
|
|
858
|
-
hasColumn: false,
|
|
859
|
-
createTable: false,
|
|
860
|
-
deleteMessages: true,
|
|
861
|
-
observabilityInstance: false,
|
|
862
|
-
listScoresBySpan: false
|
|
863
|
-
};
|
|
864
|
-
}
|
|
865
|
-
async createTable(_args) {
|
|
866
|
-
}
|
|
867
|
-
async clearTable({ tableName }) {
|
|
868
|
-
await this.operations.clearTable({ tableName });
|
|
869
|
-
}
|
|
870
|
-
async dropTable({ tableName }) {
|
|
871
|
-
await this.operations.dropTable({ tableName });
|
|
872
|
-
}
|
|
873
|
-
async alterTable(_args) {
|
|
874
|
-
}
|
|
875
|
-
async insert({ tableName, record }) {
|
|
876
|
-
await this.operations.insert({ tableName, record });
|
|
877
|
-
}
|
|
878
|
-
async batchInsert({ tableName, records }) {
|
|
879
|
-
await this.operations.batchInsert({ tableName, records });
|
|
880
|
-
}
|
|
881
|
-
async load({ tableName, keys }) {
|
|
882
|
-
return this.operations.load({ tableName, keys });
|
|
883
|
-
}
|
|
884
|
-
async getThreadById({ threadId }) {
|
|
885
|
-
return this.memory.getThreadById({ threadId });
|
|
886
|
-
}
|
|
887
|
-
async saveThread({ thread }) {
|
|
888
|
-
return this.memory.saveThread({ thread });
|
|
889
|
-
}
|
|
890
|
-
async updateThread({
|
|
891
|
-
id,
|
|
892
|
-
title,
|
|
893
|
-
metadata
|
|
894
|
-
}) {
|
|
895
|
-
return this.memory.updateThread({ id, title, metadata });
|
|
896
|
-
}
|
|
897
|
-
async deleteThread({ threadId }) {
|
|
898
|
-
await this.memory.deleteThread({ threadId });
|
|
899
|
-
}
|
|
900
|
-
async listMessages(args) {
|
|
901
|
-
return this.memory.listMessages(args);
|
|
902
|
-
}
|
|
903
|
-
async listMessagesById({ messageIds }) {
|
|
904
|
-
return this.memory.listMessagesById({ messageIds });
|
|
905
|
-
}
|
|
906
|
-
async saveMessages(args) {
|
|
907
|
-
return this.memory.saveMessages(args);
|
|
908
|
-
}
|
|
909
|
-
async updateMessages({
|
|
910
|
-
messages
|
|
911
|
-
}) {
|
|
912
|
-
return this.memory.updateMessages({ messages });
|
|
913
|
-
}
|
|
914
|
-
async deleteMessages(messageIds) {
|
|
915
|
-
await this.memory.deleteMessages(messageIds);
|
|
916
|
-
}
|
|
917
|
-
async listThreadsByResourceId(args) {
|
|
918
|
-
return this.memory.listThreadsByResourceId(args);
|
|
919
|
-
}
|
|
920
|
-
async getResourceById({ resourceId }) {
|
|
921
|
-
return this.memory.getResourceById({ resourceId });
|
|
922
|
-
}
|
|
923
|
-
async saveResource({ resource }) {
|
|
924
|
-
return this.memory.saveResource({ resource });
|
|
925
|
-
}
|
|
926
|
-
async updateResource({
|
|
927
|
-
resourceId,
|
|
928
|
-
workingMemory,
|
|
929
|
-
metadata
|
|
930
|
-
}) {
|
|
931
|
-
return this.memory.updateResource({ resourceId, workingMemory, metadata });
|
|
932
|
-
}
|
|
933
|
-
async updateWorkflowResults(params) {
|
|
934
|
-
return this.workflows.updateWorkflowResults(params);
|
|
935
|
-
}
|
|
936
|
-
async updateWorkflowState(params) {
|
|
937
|
-
return this.workflows.updateWorkflowState(params);
|
|
938
|
-
}
|
|
939
|
-
async persistWorkflowSnapshot({
|
|
940
|
-
workflowName,
|
|
941
|
-
runId,
|
|
942
|
-
resourceId,
|
|
943
|
-
snapshot
|
|
944
|
-
}) {
|
|
945
|
-
await this.workflows.persistWorkflowSnapshot({ workflowName, runId, resourceId, snapshot });
|
|
946
|
-
}
|
|
947
|
-
async loadWorkflowSnapshot({
|
|
948
|
-
workflowName,
|
|
949
|
-
runId
|
|
950
|
-
}) {
|
|
951
|
-
return this.workflows.loadWorkflowSnapshot({ workflowName, runId });
|
|
952
|
-
}
|
|
953
|
-
async listWorkflowRuns(args) {
|
|
954
|
-
return this.workflows.listWorkflowRuns(args);
|
|
955
|
-
}
|
|
956
|
-
async getWorkflowRunById({
|
|
957
|
-
runId,
|
|
958
|
-
workflowName
|
|
959
|
-
}) {
|
|
960
|
-
return this.workflows.getWorkflowRunById({ runId, workflowName });
|
|
961
|
-
}
|
|
962
|
-
async deleteWorkflowRunById({ runId, workflowName }) {
|
|
963
|
-
return this.workflows.deleteWorkflowRunById({ runId, workflowName });
|
|
964
|
-
}
|
|
965
|
-
async getScoreById({ id }) {
|
|
966
|
-
return this.scores.getScoreById({ id });
|
|
967
|
-
}
|
|
968
|
-
async saveScore(score) {
|
|
969
|
-
return this.scores.saveScore(score);
|
|
970
|
-
}
|
|
971
|
-
async listScoresByScorerId({
|
|
972
|
-
scorerId,
|
|
973
|
-
pagination,
|
|
974
|
-
entityId,
|
|
975
|
-
entityType,
|
|
976
|
-
source
|
|
977
|
-
}) {
|
|
978
|
-
return this.scores.listScoresByScorerId({ scorerId, pagination, entityId, entityType, source });
|
|
979
|
-
}
|
|
980
|
-
async listScoresByRunId({
|
|
981
|
-
runId,
|
|
982
|
-
pagination
|
|
983
|
-
}) {
|
|
984
|
-
return this.scores.listScoresByRunId({ runId, pagination });
|
|
985
|
-
}
|
|
986
|
-
async listScoresByEntityId({
|
|
987
|
-
entityId,
|
|
988
|
-
entityType,
|
|
989
|
-
pagination
|
|
990
|
-
}) {
|
|
991
|
-
return this.scores.listScoresByEntityId({ entityId, entityType, pagination });
|
|
992
|
-
}
|
|
993
895
|
};
|
|
994
896
|
var INDEX_METADATA_TABLE = "mastra_vector_indexes";
|
|
995
897
|
var ConvexVector = class extends vector.MastraVector {
|
|
@@ -1294,61 +1196,61 @@ function cosineSimilarity(a, b) {
|
|
|
1294
1196
|
return dot / (Math.sqrt(magA) * Math.sqrt(magB));
|
|
1295
1197
|
}
|
|
1296
1198
|
|
|
1199
|
+
Object.defineProperty(exports, "mastraStorage", {
|
|
1200
|
+
enumerable: true,
|
|
1201
|
+
get: function () { return chunkBKVR7SL7_cjs.mastraStorage; }
|
|
1202
|
+
});
|
|
1297
1203
|
Object.defineProperty(exports, "TABLE_MESSAGES", {
|
|
1298
1204
|
enumerable: true,
|
|
1299
|
-
get: function () { return
|
|
1205
|
+
get: function () { return chunkH5QJE733_cjs.TABLE_MESSAGES; }
|
|
1300
1206
|
});
|
|
1301
1207
|
Object.defineProperty(exports, "TABLE_RESOURCES", {
|
|
1302
1208
|
enumerable: true,
|
|
1303
|
-
get: function () { return
|
|
1209
|
+
get: function () { return chunkH5QJE733_cjs.TABLE_RESOURCES; }
|
|
1304
1210
|
});
|
|
1305
1211
|
Object.defineProperty(exports, "TABLE_SCORERS", {
|
|
1306
1212
|
enumerable: true,
|
|
1307
|
-
get: function () { return
|
|
1213
|
+
get: function () { return chunkH5QJE733_cjs.TABLE_SCORERS; }
|
|
1308
1214
|
});
|
|
1309
1215
|
Object.defineProperty(exports, "TABLE_THREADS", {
|
|
1310
1216
|
enumerable: true,
|
|
1311
|
-
get: function () { return
|
|
1217
|
+
get: function () { return chunkH5QJE733_cjs.TABLE_THREADS; }
|
|
1312
1218
|
});
|
|
1313
1219
|
Object.defineProperty(exports, "TABLE_WORKFLOW_SNAPSHOT", {
|
|
1314
1220
|
enumerable: true,
|
|
1315
|
-
get: function () { return
|
|
1221
|
+
get: function () { return chunkH5QJE733_cjs.TABLE_WORKFLOW_SNAPSHOT; }
|
|
1316
1222
|
});
|
|
1317
1223
|
Object.defineProperty(exports, "mastraDocumentsTable", {
|
|
1318
1224
|
enumerable: true,
|
|
1319
|
-
get: function () { return
|
|
1225
|
+
get: function () { return chunkH5QJE733_cjs.mastraDocumentsTable; }
|
|
1320
1226
|
});
|
|
1321
1227
|
Object.defineProperty(exports, "mastraMessagesTable", {
|
|
1322
1228
|
enumerable: true,
|
|
1323
|
-
get: function () { return
|
|
1229
|
+
get: function () { return chunkH5QJE733_cjs.mastraMessagesTable; }
|
|
1324
1230
|
});
|
|
1325
1231
|
Object.defineProperty(exports, "mastraResourcesTable", {
|
|
1326
1232
|
enumerable: true,
|
|
1327
|
-
get: function () { return
|
|
1233
|
+
get: function () { return chunkH5QJE733_cjs.mastraResourcesTable; }
|
|
1328
1234
|
});
|
|
1329
1235
|
Object.defineProperty(exports, "mastraScoresTable", {
|
|
1330
1236
|
enumerable: true,
|
|
1331
|
-
get: function () { return
|
|
1332
|
-
});
|
|
1333
|
-
Object.defineProperty(exports, "mastraStorage", {
|
|
1334
|
-
enumerable: true,
|
|
1335
|
-
get: function () { return chunkQKN2PWR2_cjs.mastraStorage; }
|
|
1237
|
+
get: function () { return chunkH5QJE733_cjs.mastraScoresTable; }
|
|
1336
1238
|
});
|
|
1337
1239
|
Object.defineProperty(exports, "mastraThreadsTable", {
|
|
1338
1240
|
enumerable: true,
|
|
1339
|
-
get: function () { return
|
|
1241
|
+
get: function () { return chunkH5QJE733_cjs.mastraThreadsTable; }
|
|
1340
1242
|
});
|
|
1341
1243
|
Object.defineProperty(exports, "mastraVectorIndexesTable", {
|
|
1342
1244
|
enumerable: true,
|
|
1343
|
-
get: function () { return
|
|
1245
|
+
get: function () { return chunkH5QJE733_cjs.mastraVectorIndexesTable; }
|
|
1344
1246
|
});
|
|
1345
1247
|
Object.defineProperty(exports, "mastraVectorsTable", {
|
|
1346
1248
|
enumerable: true,
|
|
1347
|
-
get: function () { return
|
|
1249
|
+
get: function () { return chunkH5QJE733_cjs.mastraVectorsTable; }
|
|
1348
1250
|
});
|
|
1349
1251
|
Object.defineProperty(exports, "mastraWorkflowSnapshotsTable", {
|
|
1350
1252
|
enumerable: true,
|
|
1351
|
-
get: function () { return
|
|
1253
|
+
get: function () { return chunkH5QJE733_cjs.mastraWorkflowSnapshotsTable; }
|
|
1352
1254
|
});
|
|
1353
1255
|
exports.ConvexStore = ConvexStore;
|
|
1354
1256
|
exports.ConvexVector = ConvexVector;
|