@mastra/convex 1.7.3-alpha.0 → 1.7.3
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/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/reference-vectors-convex.md +1 -3
- package/dist/index.cjs +247 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +248 -37
- package/dist/index.js.map +1 -1
- package/dist/server/index.cjs +1 -1
- package/dist/server/index.js +1 -1
- package/dist/server/run-fencing.d.ts +14 -0
- package/dist/server/run-fencing.d.ts.map +1 -0
- package/dist/server/storage.d.ts +2 -2
- package/dist/server/storage.d.ts.map +1 -1
- package/dist/{server-DozOFGfO.js → server-B8RSiOmu.js} +152 -2
- package/dist/server-B8RSiOmu.js.map +1 -0
- package/dist/{server-cdXFJzWz.cjs → server-Bcgr5CcA.cjs} +152 -2
- package/dist/server-Bcgr5CcA.cjs.map +1 -0
- package/dist/storage/client.d.ts +3 -3
- package/dist/storage/client.d.ts.map +1 -1
- package/dist/storage/db/index.d.ts +5 -1
- package/dist/storage/db/index.d.ts.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +17 -7
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/domains/workflows/index.d.ts +16 -5
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/storage/run-fencing.d.ts +28 -0
- package/dist/storage/run-fencing.d.ts.map +1 -0
- package/dist/storage/types.d.ts +75 -1
- package/dist/storage/types.d.ts.map +1 -1
- package/package.json +6 -6
- package/dist/server-DozOFGfO.js.map +0 -1
- package/dist/server-cdXFJzWz.cjs.map +0 -1
package/dist/docs/SKILL.md
CHANGED
|
@@ -387,7 +387,6 @@ const results = await vectorStore.query({
|
|
|
387
387
|
|
|
388
388
|
| Operator | Description |
|
|
389
389
|
| -------- | --------------------- |
|
|
390
|
-
| `$eq` | Equal to |
|
|
391
390
|
| `$ne` | Not equal to |
|
|
392
391
|
| `$gt` | Greater than |
|
|
393
392
|
| `$gte` | Greater than or equal |
|
|
@@ -400,10 +399,9 @@ const results = await vectorStore.query({
|
|
|
400
399
|
|
|
401
400
|
## Architecture
|
|
402
401
|
|
|
403
|
-
`ConvexVector` stores
|
|
402
|
+
`ConvexVector` stores each index in its own table named `mastra_vector_{indexName}`. Each record has the following structure:
|
|
404
403
|
|
|
405
404
|
- `id`: Unique vector identifier
|
|
406
|
-
- `indexName`: Name of the index
|
|
407
405
|
- `embedding`: The vector data (array of floats)
|
|
408
406
|
- `metadata`: Optional JSON metadata
|
|
409
407
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_server = require("./server-
|
|
2
|
+
const require_server = require("./server-Bcgr5CcA.cjs");
|
|
3
3
|
const require_schema = require("./schema.cjs");
|
|
4
4
|
let _mastra_core_cache = require("@mastra/core/cache");
|
|
5
5
|
let _mastra_core_storage = require("@mastra/core/storage");
|
|
@@ -254,6 +254,154 @@ var ConvexAdminClient = class {
|
|
|
254
254
|
}
|
|
255
255
|
};
|
|
256
256
|
//#endregion
|
|
257
|
+
//#region src/storage/run-fencing.ts
|
|
258
|
+
const READ_OPS = /* @__PURE__ */ new Set([
|
|
259
|
+
"load",
|
|
260
|
+
"loadMany",
|
|
261
|
+
"queryTable",
|
|
262
|
+
"omGetLatest",
|
|
263
|
+
"omGetHistory",
|
|
264
|
+
"listDueSchedules",
|
|
265
|
+
"listScheduleTriggers"
|
|
266
|
+
]);
|
|
267
|
+
async function callRunClaim(client, request, operation) {
|
|
268
|
+
try {
|
|
269
|
+
return await client.callStorageRaw(request);
|
|
270
|
+
} catch (error) {
|
|
271
|
+
const { code, message } = error;
|
|
272
|
+
if (code === _mastra_core_storage.RUN_FENCE_CONFLICT_ERROR_ID && request.op === "fenced") throw new _mastra_core_storage.RunFenceConflictError(request.fence, operation);
|
|
273
|
+
if (typeof message === "string" && message.startsWith(`Unsupported operation ${request.op}`)) throw new Error(`The deployed Convex storage function does not support run fencing (${request.op}). Redeploy your Convex functions with the installed version of @mastra/convex.`, { cause: error });
|
|
274
|
+
throw error;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
/** Sends writes inside a fenced operation, so each is applied only while `check.fence` holds the run. */
|
|
278
|
+
var FencedStorageCaller = class {
|
|
279
|
+
client;
|
|
280
|
+
check;
|
|
281
|
+
constructor(client, check) {
|
|
282
|
+
this.client = client;
|
|
283
|
+
this.check = check;
|
|
284
|
+
}
|
|
285
|
+
callStorageRaw(request) {
|
|
286
|
+
if (READ_OPS.has(request.op)) return this.client.callStorageRaw(request);
|
|
287
|
+
return callRunClaim(this.client, {
|
|
288
|
+
op: "fenced",
|
|
289
|
+
tableName: this.check.claims,
|
|
290
|
+
fence: toFence(this.check.fence),
|
|
291
|
+
request
|
|
292
|
+
}, this.check.operation);
|
|
293
|
+
}
|
|
294
|
+
async callStorage(request) {
|
|
295
|
+
return (await this.callStorageRaw(request)).result;
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
/** The client, or one that fences every write when `check` is set. */
|
|
299
|
+
function fencedCaller(client, check) {
|
|
300
|
+
return check ? new FencedStorageCaller(client, check) : client;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Rejects a fenced write that turns out to have nothing to write when its
|
|
304
|
+
* fence is no longer current, as the write itself would have been rejected.
|
|
305
|
+
*/
|
|
306
|
+
async function assertRunFence(client, check) {
|
|
307
|
+
if (!check) return;
|
|
308
|
+
await callRunClaim(client, {
|
|
309
|
+
op: "fenced",
|
|
310
|
+
tableName: check.claims,
|
|
311
|
+
fence: toFence(check.fence)
|
|
312
|
+
}, check.operation);
|
|
313
|
+
}
|
|
314
|
+
function toFence({ runId, generation, ownerId }) {
|
|
315
|
+
return {
|
|
316
|
+
runId,
|
|
317
|
+
generation,
|
|
318
|
+
ownerId
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
function toRecord(claim, now) {
|
|
322
|
+
if (!claim) return null;
|
|
323
|
+
const { runId, generation, ownerId, leaseExpiresAt } = claim;
|
|
324
|
+
return {
|
|
325
|
+
runId,
|
|
326
|
+
generation,
|
|
327
|
+
ownerId,
|
|
328
|
+
leaseExpiresAt: leaseExpiresAt === null ? null : new Date(leaseExpiresAt),
|
|
329
|
+
live: leaseExpiresAt !== null && leaseExpiresAt > now
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
async function ownerOperation(client, request) {
|
|
333
|
+
const { result } = await callRunClaim(client, request, request.op);
|
|
334
|
+
return {
|
|
335
|
+
applied: result.applied,
|
|
336
|
+
record: toRecord(result.claim, result.now)
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
async function claimRunOwnership(client, { runId, ownerId, leaseMs, force, expectedGeneration }) {
|
|
340
|
+
const { applied, record } = await ownerOperation(client, {
|
|
341
|
+
op: "claimRunOwnership",
|
|
342
|
+
tableName: _mastra_core_storage.TABLE_WORKFLOW_RUN_OWNERS,
|
|
343
|
+
runId,
|
|
344
|
+
ownerId,
|
|
345
|
+
leaseMs,
|
|
346
|
+
force: force ?? false,
|
|
347
|
+
...expectedGeneration !== void 0 ? { expectedGeneration } : {}
|
|
348
|
+
});
|
|
349
|
+
return applied ? {
|
|
350
|
+
acquired: true,
|
|
351
|
+
record
|
|
352
|
+
} : {
|
|
353
|
+
acquired: false,
|
|
354
|
+
record
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
async function renewRunOwnership(client, { leaseMs, ...fence }) {
|
|
358
|
+
const { applied, record } = await ownerOperation(client, {
|
|
359
|
+
op: "renewRunOwnership",
|
|
360
|
+
tableName: _mastra_core_storage.TABLE_WORKFLOW_RUN_OWNERS,
|
|
361
|
+
fence: toFence(fence),
|
|
362
|
+
leaseMs
|
|
363
|
+
});
|
|
364
|
+
return applied ? {
|
|
365
|
+
renewed: true,
|
|
366
|
+
record
|
|
367
|
+
} : {
|
|
368
|
+
renewed: false,
|
|
369
|
+
record
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
async function releaseRunOwnership(client, fence) {
|
|
373
|
+
const { applied } = await ownerOperation(client, {
|
|
374
|
+
op: "releaseRunOwnership",
|
|
375
|
+
tableName: _mastra_core_storage.TABLE_WORKFLOW_RUN_OWNERS,
|
|
376
|
+
fence: toFence(fence)
|
|
377
|
+
});
|
|
378
|
+
return applied;
|
|
379
|
+
}
|
|
380
|
+
async function getRunOwnership(client, runId) {
|
|
381
|
+
const { record } = await ownerOperation(client, {
|
|
382
|
+
op: "getRunOwnership",
|
|
383
|
+
tableName: _mastra_core_storage.TABLE_WORKFLOW_RUN_OWNERS,
|
|
384
|
+
runId
|
|
385
|
+
});
|
|
386
|
+
return record;
|
|
387
|
+
}
|
|
388
|
+
async function raiseRunFence(client, fence) {
|
|
389
|
+
const { applied } = await ownerOperation(client, {
|
|
390
|
+
op: "raiseRunFence",
|
|
391
|
+
tableName: _mastra_core_storage.TABLE_MEMORY_RUN_FENCES,
|
|
392
|
+
fence: toFence(fence)
|
|
393
|
+
});
|
|
394
|
+
return applied;
|
|
395
|
+
}
|
|
396
|
+
async function retireRunFence(client, fence) {
|
|
397
|
+
const { applied } = await ownerOperation(client, {
|
|
398
|
+
op: "retireRunFence",
|
|
399
|
+
tableName: _mastra_core_storage.TABLE_MEMORY_RUN_FENCES,
|
|
400
|
+
fence: toFence(fence)
|
|
401
|
+
});
|
|
402
|
+
return applied;
|
|
403
|
+
}
|
|
404
|
+
//#endregion
|
|
257
405
|
//#region src/storage/types.ts
|
|
258
406
|
/**
|
|
259
407
|
* Observational memory table name. Defined locally (not value-imported from
|
|
@@ -272,11 +420,17 @@ function resolveConvexConfig(config) {
|
|
|
272
420
|
if ("client" in config) return config.client;
|
|
273
421
|
return new ConvexAdminClient(config);
|
|
274
422
|
}
|
|
275
|
-
var ConvexDB = class extends _mastra_core_base.MastraBase {
|
|
423
|
+
var ConvexDB = class ConvexDB extends _mastra_core_base.MastraBase {
|
|
424
|
+
adminClient;
|
|
276
425
|
client;
|
|
277
|
-
constructor(
|
|
426
|
+
constructor(adminClient, check) {
|
|
278
427
|
super({ name: "convex-db" });
|
|
279
|
-
this.
|
|
428
|
+
this.adminClient = adminClient;
|
|
429
|
+
this.client = fencedCaller(adminClient, check);
|
|
430
|
+
}
|
|
431
|
+
/** This store with every write applied only while `check.fence` holds the run, or itself without a check. */
|
|
432
|
+
fenced(check) {
|
|
433
|
+
return check ? new ConvexDB(this.adminClient, check) : this;
|
|
280
434
|
}
|
|
281
435
|
async hasColumn(_table, _column) {
|
|
282
436
|
return true;
|
|
@@ -1025,10 +1179,32 @@ var MemoryConvex = class extends _mastra_core_storage.MemoryStorage {
|
|
|
1025
1179
|
supportsObservationalMemory = true;
|
|
1026
1180
|
supportsObservationalMemoryHistorySearch = true;
|
|
1027
1181
|
#db;
|
|
1182
|
+
#client;
|
|
1028
1183
|
constructor(config) {
|
|
1029
1184
|
super();
|
|
1030
|
-
|
|
1031
|
-
this.#db = new ConvexDB(client);
|
|
1185
|
+
this.#client = resolveConvexConfig(config);
|
|
1186
|
+
this.#db = new ConvexDB(this.#client);
|
|
1187
|
+
}
|
|
1188
|
+
supportsRunFencing() {
|
|
1189
|
+
return true;
|
|
1190
|
+
}
|
|
1191
|
+
async raiseRunFence(fence) {
|
|
1192
|
+
return raiseRunFence(this.#client, fence);
|
|
1193
|
+
}
|
|
1194
|
+
async retireRunFence(fence) {
|
|
1195
|
+
return retireRunFence(this.#client, fence);
|
|
1196
|
+
}
|
|
1197
|
+
#runFenceCheck(fence, operation) {
|
|
1198
|
+
const resolved = (0, _mastra_core_storage.resolveRunFence)(this, fence);
|
|
1199
|
+
return resolved && {
|
|
1200
|
+
claims: _mastra_core_storage.TABLE_MEMORY_RUN_FENCES,
|
|
1201
|
+
fence: resolved,
|
|
1202
|
+
operation
|
|
1203
|
+
};
|
|
1204
|
+
}
|
|
1205
|
+
/** The store to write through: fenced when the write carries or inherits a fence. */
|
|
1206
|
+
#dbFor(fence, operation) {
|
|
1207
|
+
return this.#db.fenced(this.#runFenceCheck(fence, operation));
|
|
1032
1208
|
}
|
|
1033
1209
|
async init() {}
|
|
1034
1210
|
async dangerouslyClearAll() {
|
|
@@ -1036,6 +1212,7 @@ var MemoryConvex = class extends _mastra_core_storage.MemoryStorage {
|
|
|
1036
1212
|
await this.#db.clearTable({ tableName: _mastra_core_storage.TABLE_MESSAGES });
|
|
1037
1213
|
await this.#db.clearTable({ tableName: _mastra_core_storage.TABLE_RESOURCES });
|
|
1038
1214
|
await this.#db.clearTable({ tableName: TABLE_OBSERVATIONAL_MEMORY$1 });
|
|
1215
|
+
await this.#db.clearTable({ tableName: _mastra_core_storage.TABLE_MEMORY_RUN_FENCES });
|
|
1039
1216
|
}
|
|
1040
1217
|
async getThreadById({ threadId, resourceId }) {
|
|
1041
1218
|
const row = await this.#db.load({
|
|
@@ -1045,8 +1222,8 @@ var MemoryConvex = class extends _mastra_core_storage.MemoryStorage {
|
|
|
1045
1222
|
if (!row || resourceId !== void 0 && row.resourceId !== resourceId) return null;
|
|
1046
1223
|
return parseStoredThread(row);
|
|
1047
1224
|
}
|
|
1048
|
-
async saveThread({ thread }) {
|
|
1049
|
-
await this.#
|
|
1225
|
+
async saveThread({ thread, fence }) {
|
|
1226
|
+
await this.#dbFor(fence, "saveThread").insert({
|
|
1050
1227
|
tableName: _mastra_core_storage.TABLE_THREADS,
|
|
1051
1228
|
record: {
|
|
1052
1229
|
...thread,
|
|
@@ -1055,8 +1232,8 @@ var MemoryConvex = class extends _mastra_core_storage.MemoryStorage {
|
|
|
1055
1232
|
});
|
|
1056
1233
|
return thread;
|
|
1057
1234
|
}
|
|
1058
|
-
async updateThread({ id, title, metadata }) {
|
|
1059
|
-
const updated = await this.#
|
|
1235
|
+
async updateThread({ id, title, metadata, fence }) {
|
|
1236
|
+
const updated = await this.#dbFor(fence, "updateThread").updateThread({
|
|
1060
1237
|
id,
|
|
1061
1238
|
title,
|
|
1062
1239
|
metadata,
|
|
@@ -1246,8 +1423,9 @@ var MemoryConvex = class extends _mastra_core_storage.MemoryStorage {
|
|
|
1246
1423
|
const filtered = (await this.#db.loadMany(_mastra_core_storage.TABLE_MESSAGES, messageIds)).map((row) => this.parseStoredMessage(row));
|
|
1247
1424
|
return { messages: new _mastra_core_agent.MessageList().add(filtered, "memory").get.all.db() };
|
|
1248
1425
|
}
|
|
1249
|
-
async saveMessages({ messages }) {
|
|
1426
|
+
async saveMessages({ messages, fence }) {
|
|
1250
1427
|
if (messages.length === 0) return { messages: [] };
|
|
1428
|
+
const db = this.#dbFor(fence, "saveMessages");
|
|
1251
1429
|
const normalized = messages.map((message) => {
|
|
1252
1430
|
if (!message.threadId) throw new Error("Thread ID is required");
|
|
1253
1431
|
if (!message.resourceId) throw new Error("Resource ID is required");
|
|
@@ -1262,21 +1440,23 @@ var MemoryConvex = class extends _mastra_core_storage.MemoryStorage {
|
|
|
1262
1440
|
resourceId: message.resourceId
|
|
1263
1441
|
};
|
|
1264
1442
|
});
|
|
1265
|
-
await
|
|
1443
|
+
await db.batchInsert({
|
|
1266
1444
|
tableName: _mastra_core_storage.TABLE_MESSAGES,
|
|
1267
1445
|
records: normalized
|
|
1268
1446
|
});
|
|
1269
1447
|
const threadIds = [...new Set(messages.map((m) => m.threadId).filter(Boolean))];
|
|
1270
1448
|
const now = /* @__PURE__ */ new Date();
|
|
1271
|
-
for (const threadId of threadIds) await
|
|
1449
|
+
for (const threadId of threadIds) await db.patch({
|
|
1272
1450
|
tableName: _mastra_core_storage.TABLE_THREADS,
|
|
1273
1451
|
id: threadId,
|
|
1274
1452
|
record: { updatedAt: now.toISOString() }
|
|
1275
1453
|
});
|
|
1276
1454
|
return { messages: new _mastra_core_agent.MessageList().add(messages, "memory").get.all.db() };
|
|
1277
1455
|
}
|
|
1278
|
-
async updateMessages({ messages }) {
|
|
1456
|
+
async updateMessages({ messages, fence }) {
|
|
1279
1457
|
if (messages.length === 0) return [];
|
|
1458
|
+
const check = this.#runFenceCheck(fence, "updateMessages");
|
|
1459
|
+
const db = this.#db.fenced(check);
|
|
1280
1460
|
const existingRows = await this.#db.loadMany(_mastra_core_storage.TABLE_MESSAGES, messages.map((message) => message.id));
|
|
1281
1461
|
const existing = new Map(existingRows.map((row) => [row.id, row]));
|
|
1282
1462
|
const updated = [];
|
|
@@ -1304,22 +1484,26 @@ var MemoryConvex = class extends _mastra_core_storage.MemoryStorage {
|
|
|
1304
1484
|
};
|
|
1305
1485
|
current.content = JSON.stringify(mergedContent);
|
|
1306
1486
|
}
|
|
1307
|
-
await
|
|
1487
|
+
await db.insert({
|
|
1308
1488
|
tableName: _mastra_core_storage.TABLE_MESSAGES,
|
|
1309
1489
|
record: current
|
|
1310
1490
|
});
|
|
1311
1491
|
updated.push(this.parseStoredMessage(current));
|
|
1312
1492
|
}
|
|
1493
|
+
if (updated.length === 0) {
|
|
1494
|
+
await assertRunFence(this.#client, check);
|
|
1495
|
+
return updated;
|
|
1496
|
+
}
|
|
1313
1497
|
const now = /* @__PURE__ */ new Date();
|
|
1314
|
-
for (const threadId of affectedThreadIds) await
|
|
1498
|
+
for (const threadId of affectedThreadIds) await db.patch({
|
|
1315
1499
|
tableName: _mastra_core_storage.TABLE_THREADS,
|
|
1316
1500
|
id: threadId,
|
|
1317
1501
|
record: { updatedAt: now.toISOString() }
|
|
1318
1502
|
});
|
|
1319
1503
|
return updated;
|
|
1320
1504
|
}
|
|
1321
|
-
async deleteMessages(messageIds) {
|
|
1322
|
-
await this.#
|
|
1505
|
+
async deleteMessages(messageIds, options) {
|
|
1506
|
+
await this.#dbFor(options?.fence, "deleteMessages").deleteMany(_mastra_core_storage.TABLE_MESSAGES, messageIds);
|
|
1323
1507
|
}
|
|
1324
1508
|
async saveResource({ resource }) {
|
|
1325
1509
|
const record = {
|
|
@@ -1342,9 +1526,9 @@ var MemoryConvex = class extends _mastra_core_storage.MemoryStorage {
|
|
|
1342
1526
|
if (!record) return null;
|
|
1343
1527
|
return parseStoredResource(record);
|
|
1344
1528
|
}
|
|
1345
|
-
async updateResource({ resourceId, workingMemory, metadata }) {
|
|
1529
|
+
async updateResource({ resourceId, workingMemory, metadata, fence }) {
|
|
1346
1530
|
const now = /* @__PURE__ */ new Date();
|
|
1347
|
-
return parseStoredResource(await this.#
|
|
1531
|
+
return parseStoredResource(await this.#dbFor(fence, "updateResource").updateResource({
|
|
1348
1532
|
resourceId,
|
|
1349
1533
|
workingMemory,
|
|
1350
1534
|
metadata,
|
|
@@ -1604,7 +1788,7 @@ var MemoryConvex = class extends _mastra_core_storage.MemoryStorage {
|
|
|
1604
1788
|
assertActiveObservationsApplied(await this.commitActiveObservations(input), input.id);
|
|
1605
1789
|
}
|
|
1606
1790
|
async commitActiveObservations(input) {
|
|
1607
|
-
return await this.#
|
|
1791
|
+
return await this.#dbFor(void 0, "commitActiveObservations").omUpdateActive({
|
|
1608
1792
|
id: input.id,
|
|
1609
1793
|
observations: input.observations,
|
|
1610
1794
|
tokenCount: input.tokenCount,
|
|
@@ -1633,7 +1817,7 @@ var MemoryConvex = class extends _mastra_core_storage.MemoryStorage {
|
|
|
1633
1817
|
extractedValues: input.chunk.extractedValues,
|
|
1634
1818
|
extractionFailures: input.chunk.extractionFailures
|
|
1635
1819
|
};
|
|
1636
|
-
return await this.#
|
|
1820
|
+
return await this.#dbFor(void 0, "appendBufferedObservations").omAppendBufferedChunk({
|
|
1637
1821
|
id: input.id,
|
|
1638
1822
|
chunk,
|
|
1639
1823
|
lastBufferedAtTime: input.lastBufferedAtTime ? toISO(input.lastBufferedAtTime) : void 0,
|
|
@@ -1644,7 +1828,7 @@ var MemoryConvex = class extends _mastra_core_storage.MemoryStorage {
|
|
|
1644
1828
|
};
|
|
1645
1829
|
}
|
|
1646
1830
|
async swapBufferedToActive(input) {
|
|
1647
|
-
return this.#
|
|
1831
|
+
return this.#dbFor(void 0, "swapBufferedToActive").omSwapBuffered({
|
|
1648
1832
|
id: input.id,
|
|
1649
1833
|
activationRatio: input.activationRatio,
|
|
1650
1834
|
messageTokensThreshold: input.messageTokensThreshold,
|
|
@@ -1674,7 +1858,7 @@ var MemoryConvex = class extends _mastra_core_storage.MemoryStorage {
|
|
|
1674
1858
|
};
|
|
1675
1859
|
}
|
|
1676
1860
|
async createReflectionGeneration(input) {
|
|
1677
|
-
const doc = await this.#
|
|
1861
|
+
const doc = await this.#dbFor(void 0, "createReflectionGeneration").omCreateReflectionGeneration({
|
|
1678
1862
|
currentRecord: this.#serializeCurrentRecord(input.currentRecord),
|
|
1679
1863
|
newId: input.newRecordId ?? crypto.randomUUID(),
|
|
1680
1864
|
reflection: input.reflection,
|
|
@@ -1684,7 +1868,7 @@ var MemoryConvex = class extends _mastra_core_storage.MemoryStorage {
|
|
|
1684
1868
|
return doc ? parseStoredOMRecord(doc) : input.currentRecord;
|
|
1685
1869
|
}
|
|
1686
1870
|
async updateBufferedReflection(input) {
|
|
1687
|
-
await this.#
|
|
1871
|
+
await this.#dbFor(void 0, "updateBufferedReflection").omUpdateBufferedReflection({
|
|
1688
1872
|
id: input.id,
|
|
1689
1873
|
reflection: input.reflection,
|
|
1690
1874
|
tokenCount: input.tokenCount,
|
|
@@ -1694,7 +1878,7 @@ var MemoryConvex = class extends _mastra_core_storage.MemoryStorage {
|
|
|
1694
1878
|
});
|
|
1695
1879
|
}
|
|
1696
1880
|
async swapBufferedReflectionToActive(input) {
|
|
1697
|
-
const doc = await this.#
|
|
1881
|
+
const doc = await this.#dbFor(void 0, "swapBufferedReflectionToActive").omSwapBufferedReflection({
|
|
1698
1882
|
currentRecord: this.#serializeCurrentRecord(input.currentRecord),
|
|
1699
1883
|
newId: input.newRecordId ?? crypto.randomUUID(),
|
|
1700
1884
|
tokenCount: input.tokenCount,
|
|
@@ -2090,25 +2274,52 @@ var ScoresConvex = class extends _mastra_core_storage.ScoresStorage {
|
|
|
2090
2274
|
//#region src/storage/domains/workflows/index.ts
|
|
2091
2275
|
var WorkflowsConvex = class extends _mastra_core_storage.WorkflowsStorage {
|
|
2092
2276
|
#db;
|
|
2277
|
+
#client;
|
|
2093
2278
|
constructor(config) {
|
|
2094
2279
|
super();
|
|
2095
|
-
|
|
2096
|
-
this.#db = new ConvexDB(client);
|
|
2280
|
+
this.#client = resolveConvexConfig(config);
|
|
2281
|
+
this.#db = new ConvexDB(this.#client);
|
|
2097
2282
|
}
|
|
2098
2283
|
supportsConcurrentUpdates() {
|
|
2099
2284
|
return true;
|
|
2100
2285
|
}
|
|
2286
|
+
supportsRunFencing() {
|
|
2287
|
+
return true;
|
|
2288
|
+
}
|
|
2101
2289
|
async init() {}
|
|
2102
2290
|
async dangerouslyClearAll() {
|
|
2103
2291
|
await this.#db.clearTable({ tableName: _mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT });
|
|
2292
|
+
await this.#db.clearTable({ tableName: _mastra_core_storage.TABLE_WORKFLOW_RUN_OWNERS });
|
|
2293
|
+
}
|
|
2294
|
+
/** The store to write a run through: fenced when the write carries or inherits a fence. */
|
|
2295
|
+
#dbFor(fence, runId, operation) {
|
|
2296
|
+
const resolved = (0, _mastra_core_storage.resolveRunFence)(this, fence, runId);
|
|
2297
|
+
const check = resolved && {
|
|
2298
|
+
claims: _mastra_core_storage.TABLE_WORKFLOW_RUN_OWNERS,
|
|
2299
|
+
fence: resolved,
|
|
2300
|
+
operation
|
|
2301
|
+
};
|
|
2302
|
+
return this.#db.fenced(check);
|
|
2303
|
+
}
|
|
2304
|
+
async claimRunOwnership(args) {
|
|
2305
|
+
return claimRunOwnership(this.#client, args);
|
|
2306
|
+
}
|
|
2307
|
+
async renewRunOwnership(args) {
|
|
2308
|
+
return renewRunOwnership(this.#client, args);
|
|
2104
2309
|
}
|
|
2105
|
-
async
|
|
2106
|
-
return this.#
|
|
2310
|
+
async releaseRunOwnership(fence) {
|
|
2311
|
+
return releaseRunOwnership(this.#client, fence);
|
|
2107
2312
|
}
|
|
2108
|
-
async
|
|
2109
|
-
return this.#
|
|
2313
|
+
async getRunOwnership({ runId }) {
|
|
2314
|
+
return getRunOwnership(this.#client, runId);
|
|
2110
2315
|
}
|
|
2111
|
-
async
|
|
2316
|
+
async updateWorkflowResults({ fence, ...args }) {
|
|
2317
|
+
return this.#dbFor(fence, args.runId, "updateWorkflowResults").mergeWorkflowStepResult(args);
|
|
2318
|
+
}
|
|
2319
|
+
async updateWorkflowState({ fence, ...args }) {
|
|
2320
|
+
return this.#dbFor(fence, args.runId, "updateWorkflowState").mergeWorkflowState(args);
|
|
2321
|
+
}
|
|
2322
|
+
async persistWorkflowSnapshot({ workflowName, runId, resourceId, snapshot, createdAt, updatedAt, fence }) {
|
|
2112
2323
|
const now = /* @__PURE__ */ new Date();
|
|
2113
2324
|
const existing = await this.#db.load({
|
|
2114
2325
|
tableName: _mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT,
|
|
@@ -2117,7 +2328,7 @@ var WorkflowsConvex = class extends _mastra_core_storage.WorkflowsStorage {
|
|
|
2117
2328
|
run_id: runId
|
|
2118
2329
|
}
|
|
2119
2330
|
});
|
|
2120
|
-
await this.#
|
|
2331
|
+
await this.#dbFor(fence, runId, "persistWorkflowSnapshot").insert({
|
|
2121
2332
|
tableName: _mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT,
|
|
2122
2333
|
record: {
|
|
2123
2334
|
workflow_name: workflowName,
|
|
@@ -2199,8 +2410,8 @@ var WorkflowsConvex = class extends _mastra_core_storage.WorkflowsStorage {
|
|
|
2199
2410
|
resourceId: match.resourceId
|
|
2200
2411
|
};
|
|
2201
2412
|
}
|
|
2202
|
-
async deleteWorkflowRunById({ runId, workflowName }) {
|
|
2203
|
-
await this.#
|
|
2413
|
+
async deleteWorkflowRunById({ runId, workflowName, fence }) {
|
|
2414
|
+
await this.#dbFor(fence, runId, "deleteWorkflowRunById").deleteMany(_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT, [`${workflowName}-${runId}`]);
|
|
2204
2415
|
}
|
|
2205
2416
|
async getRun(workflowName, runId) {
|
|
2206
2417
|
return this.#db.load({
|