@mastra/convex 0.0.0-top-level-fix-20251211111608 → 0.0.0-unified-workspace-snapshot-20260128233410
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 +884 -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-FTVDAP6U.cjs +113 -0
- package/dist/chunk-FTVDAP6U.cjs.map +1 -0
- package/dist/chunk-G5FLGAPE.js +82 -0
- package/dist/chunk-G5FLGAPE.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 +146 -0
- package/dist/docs/vectors/01-reference.md +240 -0
- package/dist/index.cjs +221 -307
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +205 -291
- 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} +38 -3
- 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 +66 -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 +56 -159
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +23 -13
- 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 chunkFTVDAP6U_cjs = require('./chunk-FTVDAP6U.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,127 @@ 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 createTable({
|
|
94
|
+
tableName,
|
|
95
|
+
schema: _schema
|
|
96
|
+
}) {
|
|
97
|
+
this.logger.debug(`ConvexDB: createTable called for ${tableName} (schema managed server-side)`);
|
|
98
|
+
}
|
|
99
|
+
async alterTable({
|
|
100
|
+
tableName,
|
|
101
|
+
schema: _schema,
|
|
102
|
+
ifNotExists: _ifNotExists
|
|
103
|
+
}) {
|
|
104
|
+
this.logger.debug(`ConvexDB: alterTable called for ${tableName} (schema managed server-side)`);
|
|
105
|
+
}
|
|
106
|
+
async clearTable({ tableName }) {
|
|
107
|
+
let hasMore = true;
|
|
108
|
+
while (hasMore) {
|
|
109
|
+
const response = await this.client.callStorageRaw({
|
|
110
|
+
op: "clearTable",
|
|
111
|
+
tableName
|
|
112
|
+
});
|
|
113
|
+
hasMore = response.hasMore ?? false;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
async dropTable({ tableName }) {
|
|
117
|
+
let hasMore = true;
|
|
118
|
+
while (hasMore) {
|
|
119
|
+
const response = await this.client.callStorageRaw({
|
|
120
|
+
op: "dropTable",
|
|
121
|
+
tableName
|
|
122
|
+
});
|
|
123
|
+
hasMore = response.hasMore ?? false;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
async insert({ tableName, record }) {
|
|
127
|
+
await this.client.callStorage({
|
|
128
|
+
op: "insert",
|
|
129
|
+
tableName,
|
|
130
|
+
record: this.normalizeRecord(tableName, record)
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
async batchInsert({ tableName, records }) {
|
|
134
|
+
if (records.length === 0) return;
|
|
135
|
+
await this.client.callStorage({
|
|
136
|
+
op: "batchInsert",
|
|
137
|
+
tableName,
|
|
138
|
+
records: records.map((record) => this.normalizeRecord(tableName, record))
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
async load({ tableName, keys }) {
|
|
142
|
+
const result = await this.client.callStorage({
|
|
143
|
+
op: "load",
|
|
144
|
+
tableName,
|
|
145
|
+
keys
|
|
146
|
+
});
|
|
147
|
+
return result;
|
|
148
|
+
}
|
|
149
|
+
async queryTable(tableName, filters) {
|
|
150
|
+
return this.client.callStorage({
|
|
151
|
+
op: "queryTable",
|
|
152
|
+
tableName,
|
|
153
|
+
filters
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
async deleteMany(tableName, ids) {
|
|
157
|
+
if (ids.length === 0) return;
|
|
158
|
+
await this.client.callStorage({
|
|
159
|
+
op: "deleteMany",
|
|
160
|
+
tableName,
|
|
161
|
+
ids
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
normalizeRecord(tableName, record) {
|
|
165
|
+
const normalized = { ...record };
|
|
166
|
+
if (tableName === storage.TABLE_WORKFLOW_SNAPSHOT && !normalized.id) {
|
|
167
|
+
const runId = normalized.run_id || normalized.runId;
|
|
168
|
+
const workflowName = normalized.workflow_name || normalized.workflowName;
|
|
169
|
+
normalized.id = workflowName ? `${workflowName}-${runId}` : runId;
|
|
170
|
+
}
|
|
171
|
+
if (!normalized.id) {
|
|
172
|
+
normalized.id = crypto__default.default.randomUUID();
|
|
173
|
+
}
|
|
174
|
+
for (const [key, value] of Object.entries(normalized)) {
|
|
175
|
+
if (value instanceof Date) {
|
|
176
|
+
normalized[key] = value.toISOString();
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return normalized;
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
// src/storage/domains/memory/index.ts
|
|
77
184
|
var MemoryConvex = class extends storage.MemoryStorage {
|
|
78
|
-
|
|
185
|
+
#db;
|
|
186
|
+
constructor(config) {
|
|
79
187
|
super();
|
|
80
|
-
|
|
188
|
+
const client = resolveConvexConfig(config);
|
|
189
|
+
this.#db = new ConvexDB(client);
|
|
190
|
+
}
|
|
191
|
+
async init() {
|
|
192
|
+
}
|
|
193
|
+
async dangerouslyClearAll() {
|
|
194
|
+
await this.#db.clearTable({ tableName: storage.TABLE_THREADS });
|
|
195
|
+
await this.#db.clearTable({ tableName: storage.TABLE_MESSAGES });
|
|
196
|
+
await this.#db.clearTable({ tableName: storage.TABLE_RESOURCES });
|
|
81
197
|
}
|
|
82
198
|
async getThreadById({ threadId }) {
|
|
83
|
-
const row = await this.
|
|
199
|
+
const row = await this.#db.load({
|
|
84
200
|
tableName: storage.TABLE_THREADS,
|
|
85
201
|
keys: { id: threadId }
|
|
86
202
|
});
|
|
@@ -93,7 +209,7 @@ var MemoryConvex = class extends storage.MemoryStorage {
|
|
|
93
209
|
};
|
|
94
210
|
}
|
|
95
211
|
async saveThread({ thread }) {
|
|
96
|
-
await this.
|
|
212
|
+
await this.#db.insert({
|
|
97
213
|
tableName: storage.TABLE_THREADS,
|
|
98
214
|
record: {
|
|
99
215
|
...thread,
|
|
@@ -129,27 +245,50 @@ var MemoryConvex = class extends storage.MemoryStorage {
|
|
|
129
245
|
return updated;
|
|
130
246
|
}
|
|
131
247
|
async deleteThread({ threadId }) {
|
|
132
|
-
const messages = await this.
|
|
248
|
+
const messages = await this.#db.queryTable(storage.TABLE_MESSAGES, [
|
|
133
249
|
{ field: "thread_id", value: threadId }
|
|
134
250
|
]);
|
|
135
|
-
await this.
|
|
251
|
+
await this.#db.deleteMany(
|
|
136
252
|
storage.TABLE_MESSAGES,
|
|
137
253
|
messages.map((msg) => msg.id)
|
|
138
254
|
);
|
|
139
|
-
await this.
|
|
255
|
+
await this.#db.deleteMany(storage.TABLE_THREADS, [threadId]);
|
|
140
256
|
}
|
|
141
|
-
async
|
|
142
|
-
const {
|
|
257
|
+
async listThreads(args) {
|
|
258
|
+
const { page = 0, perPage: perPageInput, orderBy, filter } = args;
|
|
259
|
+
try {
|
|
260
|
+
this.validatePaginationInput(page, perPageInput ?? 100);
|
|
261
|
+
} catch (error$1) {
|
|
262
|
+
throw new error.MastraError(
|
|
263
|
+
{
|
|
264
|
+
id: storage.createStorageErrorId("CONVEX", "LIST_THREADS", "INVALID_PAGE"),
|
|
265
|
+
domain: error.ErrorDomain.STORAGE,
|
|
266
|
+
category: error.ErrorCategory.USER,
|
|
267
|
+
details: { page, ...perPageInput !== void 0 && { perPage: perPageInput } }
|
|
268
|
+
},
|
|
269
|
+
error$1 instanceof Error ? error$1 : new Error("Invalid pagination parameters")
|
|
270
|
+
);
|
|
271
|
+
}
|
|
143
272
|
const perPage = storage.normalizePerPage(perPageInput, 100);
|
|
144
273
|
const { field, direction } = this.parseOrderBy(orderBy);
|
|
145
274
|
const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
146
|
-
const
|
|
147
|
-
|
|
275
|
+
const queryFilters = [];
|
|
276
|
+
if (filter?.resourceId) {
|
|
277
|
+
queryFilters.push({ field: "resourceId", value: filter.resourceId });
|
|
278
|
+
}
|
|
279
|
+
const rows = await this.#db.queryTable(storage.TABLE_THREADS, queryFilters);
|
|
280
|
+
let threads = rows.map((row) => ({
|
|
148
281
|
...row,
|
|
149
282
|
metadata: typeof row.metadata === "string" ? JSON.parse(row.metadata) : row.metadata,
|
|
150
283
|
createdAt: new Date(row.createdAt),
|
|
151
284
|
updatedAt: new Date(row.updatedAt)
|
|
152
285
|
}));
|
|
286
|
+
if (filter?.metadata && Object.keys(filter.metadata).length > 0) {
|
|
287
|
+
threads = threads.filter((thread) => {
|
|
288
|
+
if (!thread.metadata) return false;
|
|
289
|
+
return Object.entries(filter.metadata).every(([key, value]) => thread.metadata[key] === value);
|
|
290
|
+
});
|
|
291
|
+
}
|
|
153
292
|
threads.sort((a, b) => {
|
|
154
293
|
const aValue = a[field];
|
|
155
294
|
const bValue = b[field];
|
|
@@ -186,23 +325,13 @@ var MemoryConvex = class extends storage.MemoryStorage {
|
|
|
186
325
|
const { field, direction } = this.parseOrderBy(orderBy, "ASC");
|
|
187
326
|
let rows = [];
|
|
188
327
|
for (const tid of threadIds) {
|
|
189
|
-
const threadRows = await this.
|
|
190
|
-
{ field: "thread_id", value: tid }
|
|
191
|
-
]);
|
|
328
|
+
const threadRows = await this.#db.queryTable(storage.TABLE_MESSAGES, [{ field: "thread_id", value: tid }]);
|
|
192
329
|
rows.push(...threadRows);
|
|
193
330
|
}
|
|
194
331
|
if (resourceId) {
|
|
195
332
|
rows = rows.filter((row) => row.resourceId === resourceId);
|
|
196
333
|
}
|
|
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
|
-
}
|
|
334
|
+
rows = storage.filterByDateRange(rows, (row) => new Date(row.createdAt), filter?.dateRange);
|
|
206
335
|
rows.sort((a, b) => {
|
|
207
336
|
const aValue = field === "createdAt" || field === "updatedAt" ? new Date(a[field]).getTime() : a[field];
|
|
208
337
|
const bValue = field === "createdAt" || field === "updatedAt" ? new Date(b[field]).getTime() : b[field];
|
|
@@ -232,14 +361,14 @@ var MemoryConvex = class extends storage.MemoryStorage {
|
|
|
232
361
|
}
|
|
233
362
|
}
|
|
234
363
|
if (!target) {
|
|
235
|
-
const messageRows = await this.
|
|
364
|
+
const messageRows = await this.#db.queryTable(storage.TABLE_MESSAGES, [
|
|
236
365
|
{ field: "id", value: includeItem.id }
|
|
237
366
|
]);
|
|
238
367
|
if (messageRows.length > 0) {
|
|
239
368
|
target = messageRows[0];
|
|
240
369
|
targetThreadId = target.thread_id;
|
|
241
370
|
if (targetThreadId && !threadMessagesCache.has(targetThreadId)) {
|
|
242
|
-
const otherThreadRows = await this.
|
|
371
|
+
const otherThreadRows = await this.#db.queryTable(storage.TABLE_MESSAGES, [
|
|
243
372
|
{ field: "thread_id", value: targetThreadId }
|
|
244
373
|
]);
|
|
245
374
|
threadMessagesCache.set(targetThreadId, otherThreadRows);
|
|
@@ -282,7 +411,7 @@ var MemoryConvex = class extends storage.MemoryStorage {
|
|
|
282
411
|
if (messageIds.length === 0) {
|
|
283
412
|
return { messages: [] };
|
|
284
413
|
}
|
|
285
|
-
const rows = await this.
|
|
414
|
+
const rows = await this.#db.queryTable(storage.TABLE_MESSAGES, void 0);
|
|
286
415
|
const filtered = rows.filter((row) => messageIds.includes(row.id)).map((row) => this.parseStoredMessage(row));
|
|
287
416
|
const list = new agent.MessageList().add(filtered, "memory");
|
|
288
417
|
return { messages: list.get.all.db() };
|
|
@@ -307,7 +436,7 @@ var MemoryConvex = class extends storage.MemoryStorage {
|
|
|
307
436
|
resourceId: message.resourceId
|
|
308
437
|
};
|
|
309
438
|
});
|
|
310
|
-
await this.
|
|
439
|
+
await this.#db.batchInsert({
|
|
311
440
|
tableName: storage.TABLE_MESSAGES,
|
|
312
441
|
records: normalized
|
|
313
442
|
});
|
|
@@ -316,7 +445,7 @@ var MemoryConvex = class extends storage.MemoryStorage {
|
|
|
316
445
|
for (const threadId of threadIds) {
|
|
317
446
|
const thread = await this.getThreadById({ threadId });
|
|
318
447
|
if (thread) {
|
|
319
|
-
await this.
|
|
448
|
+
await this.#db.insert({
|
|
320
449
|
tableName: storage.TABLE_THREADS,
|
|
321
450
|
record: {
|
|
322
451
|
...thread,
|
|
@@ -335,7 +464,7 @@ var MemoryConvex = class extends storage.MemoryStorage {
|
|
|
335
464
|
messages
|
|
336
465
|
}) {
|
|
337
466
|
if (messages.length === 0) return [];
|
|
338
|
-
const existing = await this.
|
|
467
|
+
const existing = await this.#db.queryTable(storage.TABLE_MESSAGES, void 0);
|
|
339
468
|
const updated = [];
|
|
340
469
|
const affectedThreadIds = /* @__PURE__ */ new Set();
|
|
341
470
|
for (const update of messages) {
|
|
@@ -364,7 +493,7 @@ var MemoryConvex = class extends storage.MemoryStorage {
|
|
|
364
493
|
};
|
|
365
494
|
current.content = JSON.stringify(mergedContent);
|
|
366
495
|
}
|
|
367
|
-
await this.
|
|
496
|
+
await this.#db.insert({
|
|
368
497
|
tableName: storage.TABLE_MESSAGES,
|
|
369
498
|
record: current
|
|
370
499
|
});
|
|
@@ -374,7 +503,7 @@ var MemoryConvex = class extends storage.MemoryStorage {
|
|
|
374
503
|
for (const threadId of affectedThreadIds) {
|
|
375
504
|
const thread = await this.getThreadById({ threadId });
|
|
376
505
|
if (thread) {
|
|
377
|
-
await this.
|
|
506
|
+
await this.#db.insert({
|
|
378
507
|
tableName: storage.TABLE_THREADS,
|
|
379
508
|
record: {
|
|
380
509
|
...thread,
|
|
@@ -389,7 +518,7 @@ var MemoryConvex = class extends storage.MemoryStorage {
|
|
|
389
518
|
return updated;
|
|
390
519
|
}
|
|
391
520
|
async deleteMessages(messageIds) {
|
|
392
|
-
await this.
|
|
521
|
+
await this.#db.deleteMany(storage.TABLE_MESSAGES, messageIds);
|
|
393
522
|
}
|
|
394
523
|
async saveResource({ resource }) {
|
|
395
524
|
const record = {
|
|
@@ -400,14 +529,14 @@ var MemoryConvex = class extends storage.MemoryStorage {
|
|
|
400
529
|
if (resource.metadata !== void 0) {
|
|
401
530
|
record.metadata = resource.metadata;
|
|
402
531
|
}
|
|
403
|
-
await this.
|
|
532
|
+
await this.#db.insert({
|
|
404
533
|
tableName: storage.TABLE_RESOURCES,
|
|
405
534
|
record
|
|
406
535
|
});
|
|
407
536
|
return resource;
|
|
408
537
|
}
|
|
409
538
|
async getResourceById({ resourceId }) {
|
|
410
|
-
const record = await this.
|
|
539
|
+
const record = await this.#db.load({
|
|
411
540
|
tableName: storage.TABLE_RESOURCES,
|
|
412
541
|
keys: { id: resourceId }
|
|
413
542
|
});
|
|
@@ -493,12 +622,19 @@ var MemoryConvex = class extends storage.MemoryStorage {
|
|
|
493
622
|
}
|
|
494
623
|
};
|
|
495
624
|
var ScoresConvex = class extends storage.ScoresStorage {
|
|
496
|
-
|
|
625
|
+
#db;
|
|
626
|
+
constructor(config) {
|
|
497
627
|
super();
|
|
498
|
-
|
|
628
|
+
const client = resolveConvexConfig(config);
|
|
629
|
+
this.#db = new ConvexDB(client);
|
|
630
|
+
}
|
|
631
|
+
async init() {
|
|
632
|
+
}
|
|
633
|
+
async dangerouslyClearAll() {
|
|
634
|
+
await this.#db.clearTable({ tableName: storage.TABLE_SCORERS });
|
|
499
635
|
}
|
|
500
636
|
async getScoreById({ id }) {
|
|
501
|
-
const row = await this.
|
|
637
|
+
const row = await this.#db.load({
|
|
502
638
|
tableName: storage.TABLE_SCORERS,
|
|
503
639
|
keys: { id }
|
|
504
640
|
});
|
|
@@ -512,7 +648,7 @@ var ScoresConvex = class extends storage.ScoresStorage {
|
|
|
512
648
|
createdAt: now.toISOString(),
|
|
513
649
|
updatedAt: now.toISOString()
|
|
514
650
|
};
|
|
515
|
-
await this.
|
|
651
|
+
await this.#db.insert({
|
|
516
652
|
tableName: storage.TABLE_SCORERS,
|
|
517
653
|
record
|
|
518
654
|
});
|
|
@@ -563,7 +699,7 @@ var ScoresConvex = class extends storage.ScoresStorage {
|
|
|
563
699
|
new Error("page must be >= 0")
|
|
564
700
|
);
|
|
565
701
|
}
|
|
566
|
-
const rows = await this.
|
|
702
|
+
const rows = await this.#db.queryTable(storage.TABLE_SCORERS, void 0);
|
|
567
703
|
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
704
|
const { perPage, page } = pagination;
|
|
569
705
|
const perPageValue = perPage === false ? filtered.length : perPage;
|
|
@@ -589,9 +725,16 @@ var ScoresConvex = class extends storage.ScoresStorage {
|
|
|
589
725
|
}
|
|
590
726
|
};
|
|
591
727
|
var WorkflowsConvex = class extends storage.WorkflowsStorage {
|
|
592
|
-
|
|
728
|
+
#db;
|
|
729
|
+
constructor(config) {
|
|
593
730
|
super();
|
|
594
|
-
|
|
731
|
+
const client = resolveConvexConfig(config);
|
|
732
|
+
this.#db = new ConvexDB(client);
|
|
733
|
+
}
|
|
734
|
+
async init() {
|
|
735
|
+
}
|
|
736
|
+
async dangerouslyClearAll() {
|
|
737
|
+
await this.#db.clearTable({ tableName: storage.TABLE_WORKFLOW_SNAPSHOT });
|
|
595
738
|
}
|
|
596
739
|
async updateWorkflowResults({
|
|
597
740
|
workflowName,
|
|
@@ -638,11 +781,11 @@ var WorkflowsConvex = class extends storage.WorkflowsStorage {
|
|
|
638
781
|
snapshot
|
|
639
782
|
}) {
|
|
640
783
|
const now = /* @__PURE__ */ new Date();
|
|
641
|
-
const existing = await this.
|
|
784
|
+
const existing = await this.#db.load({
|
|
642
785
|
tableName: storage.TABLE_WORKFLOW_SNAPSHOT,
|
|
643
786
|
keys: { workflow_name: workflowName, run_id: runId }
|
|
644
787
|
});
|
|
645
|
-
await this.
|
|
788
|
+
await this.#db.insert({
|
|
646
789
|
tableName: storage.TABLE_WORKFLOW_SNAPSHOT,
|
|
647
790
|
record: {
|
|
648
791
|
workflow_name: workflowName,
|
|
@@ -658,7 +801,7 @@ var WorkflowsConvex = class extends storage.WorkflowsStorage {
|
|
|
658
801
|
workflowName,
|
|
659
802
|
runId
|
|
660
803
|
}) {
|
|
661
|
-
const row = await this.
|
|
804
|
+
const row = await this.#db.load({
|
|
662
805
|
tableName: storage.TABLE_WORKFLOW_SNAPSHOT,
|
|
663
806
|
keys: { workflow_name: workflowName, run_id: runId }
|
|
664
807
|
});
|
|
@@ -667,7 +810,7 @@ var WorkflowsConvex = class extends storage.WorkflowsStorage {
|
|
|
667
810
|
}
|
|
668
811
|
async listWorkflowRuns(args = {}) {
|
|
669
812
|
const { workflowName, fromDate, toDate, perPage, page, resourceId, status } = args;
|
|
670
|
-
let rows = await this.
|
|
813
|
+
let rows = await this.#db.queryTable(storage.TABLE_WORKFLOW_SNAPSHOT, void 0);
|
|
671
814
|
if (workflowName) rows = rows.filter((run) => run.workflow_name === workflowName);
|
|
672
815
|
if (resourceId) rows = rows.filter((run) => run.resourceId === resourceId);
|
|
673
816
|
if (fromDate) rows = rows.filter((run) => new Date(run.createdAt).getTime() >= fromDate.getTime());
|
|
@@ -699,7 +842,7 @@ var WorkflowsConvex = class extends storage.WorkflowsStorage {
|
|
|
699
842
|
runId,
|
|
700
843
|
workflowName
|
|
701
844
|
}) {
|
|
702
|
-
const runs = await this.
|
|
845
|
+
const runs = await this.#db.queryTable(storage.TABLE_WORKFLOW_SNAPSHOT, void 0);
|
|
703
846
|
const match = runs.find((run) => run.run_id === runId && (!workflowName || run.workflow_name === workflowName));
|
|
704
847
|
if (!match) return null;
|
|
705
848
|
return {
|
|
@@ -712,10 +855,10 @@ var WorkflowsConvex = class extends storage.WorkflowsStorage {
|
|
|
712
855
|
};
|
|
713
856
|
}
|
|
714
857
|
async deleteWorkflowRunById({ runId, workflowName }) {
|
|
715
|
-
await this.
|
|
858
|
+
await this.#db.deleteMany(storage.TABLE_WORKFLOW_SNAPSHOT, [`${workflowName}-${runId}`]);
|
|
716
859
|
}
|
|
717
860
|
async getRun(workflowName, runId) {
|
|
718
|
-
const runs = await this.
|
|
861
|
+
const runs = await this.#db.queryTable(storage.TABLE_WORKFLOW_SNAPSHOT, [
|
|
719
862
|
{ field: "workflow_name", value: workflowName }
|
|
720
863
|
]);
|
|
721
864
|
return runs.find((run) => run.run_id === runId) ?? null;
|
|
@@ -742,254 +885,25 @@ var WorkflowsConvex = class extends storage.WorkflowsStorage {
|
|
|
742
885
|
return JSON.parse(JSON.stringify(run.snapshot));
|
|
743
886
|
}
|
|
744
887
|
};
|
|
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
888
|
|
|
834
889
|
// src/storage/index.ts
|
|
835
|
-
var
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
scores;
|
|
890
|
+
var isClientConfig = (config) => {
|
|
891
|
+
return "client" in config;
|
|
892
|
+
};
|
|
893
|
+
var ConvexStore = class extends storage.MastraCompositeStore {
|
|
840
894
|
constructor(config) {
|
|
841
895
|
super({ id: config.id, name: config.name ?? "ConvexStore", disableInit: config.disableInit });
|
|
842
|
-
const client = new ConvexAdminClient(config);
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
896
|
+
const client = isClientConfig(config) ? config.client : new ConvexAdminClient(config);
|
|
897
|
+
const domainConfig = { client };
|
|
898
|
+
const memory = new MemoryConvex(domainConfig);
|
|
899
|
+
const workflows = new WorkflowsConvex(domainConfig);
|
|
900
|
+
const scores = new ScoresConvex(domainConfig);
|
|
847
901
|
this.stores = {
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
scores: this.scores
|
|
902
|
+
memory,
|
|
903
|
+
workflows,
|
|
904
|
+
scores
|
|
852
905
|
};
|
|
853
906
|
}
|
|
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
907
|
};
|
|
994
908
|
var INDEX_METADATA_TABLE = "mastra_vector_indexes";
|
|
995
909
|
var ConvexVector = class extends vector.MastraVector {
|
|
@@ -1294,61 +1208,61 @@ function cosineSimilarity(a, b) {
|
|
|
1294
1208
|
return dot / (Math.sqrt(magA) * Math.sqrt(magB));
|
|
1295
1209
|
}
|
|
1296
1210
|
|
|
1211
|
+
Object.defineProperty(exports, "mastraStorage", {
|
|
1212
|
+
enumerable: true,
|
|
1213
|
+
get: function () { return chunkBKVR7SL7_cjs.mastraStorage; }
|
|
1214
|
+
});
|
|
1297
1215
|
Object.defineProperty(exports, "TABLE_MESSAGES", {
|
|
1298
1216
|
enumerable: true,
|
|
1299
|
-
get: function () { return
|
|
1217
|
+
get: function () { return chunkFTVDAP6U_cjs.TABLE_MESSAGES; }
|
|
1300
1218
|
});
|
|
1301
1219
|
Object.defineProperty(exports, "TABLE_RESOURCES", {
|
|
1302
1220
|
enumerable: true,
|
|
1303
|
-
get: function () { return
|
|
1221
|
+
get: function () { return chunkFTVDAP6U_cjs.TABLE_RESOURCES; }
|
|
1304
1222
|
});
|
|
1305
1223
|
Object.defineProperty(exports, "TABLE_SCORERS", {
|
|
1306
1224
|
enumerable: true,
|
|
1307
|
-
get: function () { return
|
|
1225
|
+
get: function () { return chunkFTVDAP6U_cjs.TABLE_SCORERS; }
|
|
1308
1226
|
});
|
|
1309
1227
|
Object.defineProperty(exports, "TABLE_THREADS", {
|
|
1310
1228
|
enumerable: true,
|
|
1311
|
-
get: function () { return
|
|
1229
|
+
get: function () { return chunkFTVDAP6U_cjs.TABLE_THREADS; }
|
|
1312
1230
|
});
|
|
1313
1231
|
Object.defineProperty(exports, "TABLE_WORKFLOW_SNAPSHOT", {
|
|
1314
1232
|
enumerable: true,
|
|
1315
|
-
get: function () { return
|
|
1233
|
+
get: function () { return chunkFTVDAP6U_cjs.TABLE_WORKFLOW_SNAPSHOT; }
|
|
1316
1234
|
});
|
|
1317
1235
|
Object.defineProperty(exports, "mastraDocumentsTable", {
|
|
1318
1236
|
enumerable: true,
|
|
1319
|
-
get: function () { return
|
|
1237
|
+
get: function () { return chunkFTVDAP6U_cjs.mastraDocumentsTable; }
|
|
1320
1238
|
});
|
|
1321
1239
|
Object.defineProperty(exports, "mastraMessagesTable", {
|
|
1322
1240
|
enumerable: true,
|
|
1323
|
-
get: function () { return
|
|
1241
|
+
get: function () { return chunkFTVDAP6U_cjs.mastraMessagesTable; }
|
|
1324
1242
|
});
|
|
1325
1243
|
Object.defineProperty(exports, "mastraResourcesTable", {
|
|
1326
1244
|
enumerable: true,
|
|
1327
|
-
get: function () { return
|
|
1245
|
+
get: function () { return chunkFTVDAP6U_cjs.mastraResourcesTable; }
|
|
1328
1246
|
});
|
|
1329
1247
|
Object.defineProperty(exports, "mastraScoresTable", {
|
|
1330
1248
|
enumerable: true,
|
|
1331
|
-
get: function () { return
|
|
1332
|
-
});
|
|
1333
|
-
Object.defineProperty(exports, "mastraStorage", {
|
|
1334
|
-
enumerable: true,
|
|
1335
|
-
get: function () { return chunkQKN2PWR2_cjs.mastraStorage; }
|
|
1249
|
+
get: function () { return chunkFTVDAP6U_cjs.mastraScoresTable; }
|
|
1336
1250
|
});
|
|
1337
1251
|
Object.defineProperty(exports, "mastraThreadsTable", {
|
|
1338
1252
|
enumerable: true,
|
|
1339
|
-
get: function () { return
|
|
1253
|
+
get: function () { return chunkFTVDAP6U_cjs.mastraThreadsTable; }
|
|
1340
1254
|
});
|
|
1341
1255
|
Object.defineProperty(exports, "mastraVectorIndexesTable", {
|
|
1342
1256
|
enumerable: true,
|
|
1343
|
-
get: function () { return
|
|
1257
|
+
get: function () { return chunkFTVDAP6U_cjs.mastraVectorIndexesTable; }
|
|
1344
1258
|
});
|
|
1345
1259
|
Object.defineProperty(exports, "mastraVectorsTable", {
|
|
1346
1260
|
enumerable: true,
|
|
1347
|
-
get: function () { return
|
|
1261
|
+
get: function () { return chunkFTVDAP6U_cjs.mastraVectorsTable; }
|
|
1348
1262
|
});
|
|
1349
1263
|
Object.defineProperty(exports, "mastraWorkflowSnapshotsTable", {
|
|
1350
1264
|
enumerable: true,
|
|
1351
|
-
get: function () { return
|
|
1265
|
+
get: function () { return chunkFTVDAP6U_cjs.mastraWorkflowSnapshotsTable; }
|
|
1352
1266
|
});
|
|
1353
1267
|
exports.ConvexStore = ConvexStore;
|
|
1354
1268
|
exports.ConvexVector = ConvexVector;
|