@mastra/libsql 1.12.1 → 1.13.0-alpha.0
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 +35 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-agent-builder-overview.md +1 -0
- package/dist/docs/references/docs-agents-agent-approval.md +2 -2
- package/dist/docs/references/docs-memory-working-memory.md +2 -2
- package/dist/docs/references/reference-core-mastra-class.md +28 -0
- package/dist/docs/references/reference-storage-composite.md +34 -2
- package/dist/docs/references/reference-storage-libsql.md +1 -1
- package/dist/index.cjs +342 -89
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +342 -91
- package/dist/index.js.map +1 -1
- package/dist/storage/db/index.d.ts.map +1 -1
- package/dist/storage/db/write-lock.d.ts +8 -0
- package/dist/storage/db/write-lock.d.ts.map +1 -0
- package/dist/storage/domains/harness/index.d.ts +13 -0
- package/dist/storage/domains/harness/index.d.ts.map +1 -0
- package/dist/storage/domains/thread-state/index.d.ts +29 -0
- package/dist/storage/domains/thread-state/index.d.ts.map +1 -0
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +3 -1
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +8 -7
package/dist/index.cjs
CHANGED
|
@@ -1426,6 +1426,21 @@ function transformFromSqlRow({
|
|
|
1426
1426
|
return result;
|
|
1427
1427
|
}
|
|
1428
1428
|
|
|
1429
|
+
// src/storage/db/write-lock.ts
|
|
1430
|
+
var clientWriteChains = /* @__PURE__ */ new WeakMap();
|
|
1431
|
+
function withClientWriteLock(client, fn) {
|
|
1432
|
+
const previous = clientWriteChains.get(client) ?? Promise.resolve();
|
|
1433
|
+
const result = previous.then(fn, fn);
|
|
1434
|
+
clientWriteChains.set(
|
|
1435
|
+
client,
|
|
1436
|
+
result.then(
|
|
1437
|
+
() => void 0,
|
|
1438
|
+
() => void 0
|
|
1439
|
+
)
|
|
1440
|
+
);
|
|
1441
|
+
return result;
|
|
1442
|
+
}
|
|
1443
|
+
|
|
1429
1444
|
// src/storage/db/index.ts
|
|
1430
1445
|
function resolveClient(config) {
|
|
1431
1446
|
if ("client" in config) {
|
|
@@ -1525,11 +1540,14 @@ var LibSQLDB = class extends base.MastraBase {
|
|
|
1525
1540
|
}) {
|
|
1526
1541
|
const filteredRecord = await this.filterRecordToKnownColumns(tableName, record);
|
|
1527
1542
|
if (Object.keys(filteredRecord).length === 0) return;
|
|
1528
|
-
await
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1543
|
+
await withClientWriteLock(
|
|
1544
|
+
this.client,
|
|
1545
|
+
() => this.client.execute(
|
|
1546
|
+
prepareStatement({
|
|
1547
|
+
tableName,
|
|
1548
|
+
record: filteredRecord
|
|
1549
|
+
})
|
|
1550
|
+
)
|
|
1533
1551
|
);
|
|
1534
1552
|
}
|
|
1535
1553
|
/**
|
|
@@ -1552,7 +1570,10 @@ var LibSQLDB = class extends base.MastraBase {
|
|
|
1552
1570
|
}) {
|
|
1553
1571
|
const filteredData = await this.filterRecordToKnownColumns(tableName, data);
|
|
1554
1572
|
if (Object.keys(filteredData).length === 0) return;
|
|
1555
|
-
await
|
|
1573
|
+
await withClientWriteLock(
|
|
1574
|
+
this.client,
|
|
1575
|
+
() => this.client.execute(prepareUpdateStatement({ tableName, updates: filteredData, keys }))
|
|
1576
|
+
);
|
|
1556
1577
|
}
|
|
1557
1578
|
/**
|
|
1558
1579
|
* Updates a record in the specified table with automatic retry on lock errors.
|
|
@@ -1577,7 +1598,7 @@ var LibSQLDB = class extends base.MastraBase {
|
|
|
1577
1598
|
const nonEmptyRecords = filteredRecords.filter((r) => Object.keys(r).length > 0);
|
|
1578
1599
|
if (nonEmptyRecords.length === 0) return;
|
|
1579
1600
|
const batchStatements = nonEmptyRecords.map((r) => prepareStatement({ tableName, record: r }));
|
|
1580
|
-
await this.client.batch(batchStatements, "write");
|
|
1601
|
+
await withClientWriteLock(this.client, () => this.client.batch(batchStatements, "write"));
|
|
1581
1602
|
}
|
|
1582
1603
|
/**
|
|
1583
1604
|
* Inserts multiple records in a single batch transaction with automatic retry on lock errors.
|
|
@@ -1629,7 +1650,7 @@ var LibSQLDB = class extends base.MastraBase {
|
|
|
1629
1650
|
keys
|
|
1630
1651
|
})
|
|
1631
1652
|
);
|
|
1632
|
-
await this.client.batch(batchStatements, "write");
|
|
1653
|
+
await withClientWriteLock(this.client, () => this.client.batch(batchStatements, "write"));
|
|
1633
1654
|
}
|
|
1634
1655
|
/**
|
|
1635
1656
|
* Updates multiple records in a single batch transaction with automatic retry on lock errors.
|
|
@@ -1673,7 +1694,7 @@ var LibSQLDB = class extends base.MastraBase {
|
|
|
1673
1694
|
keys: keyObj
|
|
1674
1695
|
})
|
|
1675
1696
|
);
|
|
1676
|
-
await this.client.batch(batchStatements, "write");
|
|
1697
|
+
await withClientWriteLock(this.client, () => this.client.batch(batchStatements, "write"));
|
|
1677
1698
|
}
|
|
1678
1699
|
/**
|
|
1679
1700
|
* Deletes multiple records in a single batch transaction with automatic retry on lock errors.
|
|
@@ -1709,7 +1730,7 @@ var LibSQLDB = class extends base.MastraBase {
|
|
|
1709
1730
|
* Internal single-record delete implementation without retry logic.
|
|
1710
1731
|
*/
|
|
1711
1732
|
async doDelete({ tableName, keys }) {
|
|
1712
|
-
await this.client.execute(prepareDeleteStatement({ tableName, keys }));
|
|
1733
|
+
await withClientWriteLock(this.client, () => this.client.execute(prepareDeleteStatement({ tableName, keys })));
|
|
1713
1734
|
}
|
|
1714
1735
|
/**
|
|
1715
1736
|
* Deletes a single record from the specified table with automatic retry on lock errors.
|
|
@@ -2233,7 +2254,7 @@ Note: This migration may take some time for large tables.
|
|
|
2233
2254
|
async deleteData({ tableName }) {
|
|
2234
2255
|
const parsedTableName = utils.parseSqlIdentifier(tableName, "table name");
|
|
2235
2256
|
try {
|
|
2236
|
-
await this.client.execute(`DELETE FROM ${parsedTableName}`);
|
|
2257
|
+
await withClientWriteLock(this.client, () => this.client.execute(`DELETE FROM ${parsedTableName}`));
|
|
2237
2258
|
} catch (e) {
|
|
2238
2259
|
const mastraError = new error.MastraError(
|
|
2239
2260
|
{
|
|
@@ -5313,6 +5334,126 @@ var FavoritesLibSQL = class extends storage.FavoritesStorage {
|
|
|
5313
5334
|
}
|
|
5314
5335
|
}
|
|
5315
5336
|
};
|
|
5337
|
+
var toDate = (value) => new Date(value);
|
|
5338
|
+
var toOptionalDate = (value) => {
|
|
5339
|
+
if (value == null) return void 0;
|
|
5340
|
+
return toDate(value);
|
|
5341
|
+
};
|
|
5342
|
+
function cloneJson(value) {
|
|
5343
|
+
return value === void 0 ? void 0 : structuredClone(value);
|
|
5344
|
+
}
|
|
5345
|
+
function hydratePendingItem(item) {
|
|
5346
|
+
const record = {
|
|
5347
|
+
id: item.id,
|
|
5348
|
+
kind: item.kind,
|
|
5349
|
+
status: item.status,
|
|
5350
|
+
sessionId: item.sessionId,
|
|
5351
|
+
createdAt: toDate(item.createdAt),
|
|
5352
|
+
updatedAt: toDate(item.updatedAt)
|
|
5353
|
+
};
|
|
5354
|
+
if (item.runId !== void 0) record.runId = item.runId;
|
|
5355
|
+
if (item.traceId !== void 0) record.traceId = item.traceId;
|
|
5356
|
+
if (item.runtimeCompatibilityGeneration !== void 0) {
|
|
5357
|
+
record.runtimeCompatibilityGeneration = item.runtimeCompatibilityGeneration;
|
|
5358
|
+
}
|
|
5359
|
+
if (item.payload !== void 0) record.payload = cloneJson(item.payload);
|
|
5360
|
+
if (item.response !== void 0) record.response = cloneJson(item.response);
|
|
5361
|
+
return record;
|
|
5362
|
+
}
|
|
5363
|
+
function rowToSession(row) {
|
|
5364
|
+
const record = {
|
|
5365
|
+
id: row.id,
|
|
5366
|
+
ownerId: row.ownerId,
|
|
5367
|
+
resourceId: row.resourceId,
|
|
5368
|
+
threadId: row.threadId,
|
|
5369
|
+
origin: row.origin,
|
|
5370
|
+
modeId: row.modeId,
|
|
5371
|
+
modelId: row.modelId,
|
|
5372
|
+
createdAt: toDate(row.createdAt),
|
|
5373
|
+
lastActivityAt: toDate(row.lastActivityAt)
|
|
5374
|
+
};
|
|
5375
|
+
if (row.parentSessionId != null) record.parentSessionId = row.parentSessionId;
|
|
5376
|
+
if (row.subagentDepth != null) record.subagentDepth = row.subagentDepth;
|
|
5377
|
+
if (row.source != null) record.source = { ...row.source, type: row.source.type };
|
|
5378
|
+
if (row.runtimeCompatibilityGeneration != null) {
|
|
5379
|
+
record.runtimeCompatibilityGeneration = row.runtimeCompatibilityGeneration;
|
|
5380
|
+
}
|
|
5381
|
+
if (row.title != null) record.title = row.title;
|
|
5382
|
+
if (row.metadata != null) record.metadata = cloneJson(row.metadata);
|
|
5383
|
+
if (row.state != null) record.state = cloneJson(row.state);
|
|
5384
|
+
if (row.pending != null) record.pending = row.pending.map(hydratePendingItem);
|
|
5385
|
+
const closingAt = toOptionalDate(row.closingAt);
|
|
5386
|
+
const closeDeadlineAt = toOptionalDate(row.closeDeadlineAt);
|
|
5387
|
+
const closedAt = toOptionalDate(row.closedAt);
|
|
5388
|
+
const deletedAt = toOptionalDate(row.deletedAt);
|
|
5389
|
+
if (closingAt) record.closingAt = closingAt;
|
|
5390
|
+
if (closeDeadlineAt) record.closeDeadlineAt = closeDeadlineAt;
|
|
5391
|
+
if (closedAt) record.closedAt = closedAt;
|
|
5392
|
+
if (deletedAt) record.deletedAt = deletedAt;
|
|
5393
|
+
return record;
|
|
5394
|
+
}
|
|
5395
|
+
function sessionToRecord(record) {
|
|
5396
|
+
return {
|
|
5397
|
+
id: record.id,
|
|
5398
|
+
ownerId: record.ownerId,
|
|
5399
|
+
resourceId: record.resourceId,
|
|
5400
|
+
threadId: record.threadId,
|
|
5401
|
+
parentSessionId: record.parentSessionId ?? null,
|
|
5402
|
+
subagentDepth: record.subagentDepth ?? null,
|
|
5403
|
+
source: record.source ?? null,
|
|
5404
|
+
origin: record.origin,
|
|
5405
|
+
runtimeCompatibilityGeneration: record.runtimeCompatibilityGeneration ?? null,
|
|
5406
|
+
modeId: record.modeId,
|
|
5407
|
+
modelId: record.modelId,
|
|
5408
|
+
title: record.title ?? null,
|
|
5409
|
+
metadata: record.metadata ?? null,
|
|
5410
|
+
state: record.state ?? null,
|
|
5411
|
+
pending: record.pending ?? null,
|
|
5412
|
+
createdAt: record.createdAt,
|
|
5413
|
+
lastActivityAt: record.lastActivityAt,
|
|
5414
|
+
closingAt: record.closingAt ?? null,
|
|
5415
|
+
closeDeadlineAt: record.closeDeadlineAt ?? null,
|
|
5416
|
+
closedAt: record.closedAt ?? null,
|
|
5417
|
+
deletedAt: record.deletedAt ?? null
|
|
5418
|
+
};
|
|
5419
|
+
}
|
|
5420
|
+
var HarnessLibSQL = class extends storage.HarnessStorage {
|
|
5421
|
+
#db;
|
|
5422
|
+
constructor(config) {
|
|
5423
|
+
super();
|
|
5424
|
+
const client = resolveClient(config);
|
|
5425
|
+
this.#db = new LibSQLDB({ client, maxRetries: config.maxRetries, initialBackoffMs: config.initialBackoffMs });
|
|
5426
|
+
}
|
|
5427
|
+
async init() {
|
|
5428
|
+
await this.#db.createTable({
|
|
5429
|
+
tableName: storage.TABLE_HARNESS_SESSIONS,
|
|
5430
|
+
schema: storage.TABLE_SCHEMAS[storage.TABLE_HARNESS_SESSIONS]
|
|
5431
|
+
});
|
|
5432
|
+
}
|
|
5433
|
+
async dangerouslyClearAll() {
|
|
5434
|
+
await this.#db.deleteData({ tableName: storage.TABLE_HARNESS_SESSIONS });
|
|
5435
|
+
}
|
|
5436
|
+
async loadSession(sessionId) {
|
|
5437
|
+
const row = await this.#db.select({
|
|
5438
|
+
tableName: storage.TABLE_HARNESS_SESSIONS,
|
|
5439
|
+
keys: { id: sessionId }
|
|
5440
|
+
});
|
|
5441
|
+
return row ? rowToSession(row) : null;
|
|
5442
|
+
}
|
|
5443
|
+
async saveSession(record) {
|
|
5444
|
+
await this.#db.insert({
|
|
5445
|
+
tableName: storage.TABLE_HARNESS_SESSIONS,
|
|
5446
|
+
record: sessionToRecord(record)
|
|
5447
|
+
});
|
|
5448
|
+
}
|
|
5449
|
+
async listSessions() {
|
|
5450
|
+
const rows = await this.#db.selectMany({
|
|
5451
|
+
tableName: storage.TABLE_HARNESS_SESSIONS,
|
|
5452
|
+
orderBy: '"lastActivityAt" DESC'
|
|
5453
|
+
});
|
|
5454
|
+
return rows.map(rowToSession);
|
|
5455
|
+
}
|
|
5456
|
+
};
|
|
5316
5457
|
var MCPClientsLibSQL = class extends storage.MCPClientsStorage {
|
|
5317
5458
|
#db;
|
|
5318
5459
|
#client;
|
|
@@ -11280,6 +11421,99 @@ var SkillsLibSQL = class extends storage.SkillsStorage {
|
|
|
11280
11421
|
};
|
|
11281
11422
|
}
|
|
11282
11423
|
};
|
|
11424
|
+
var ThreadStateLibSQL = class extends storage.ThreadStateStorage {
|
|
11425
|
+
#db;
|
|
11426
|
+
#client;
|
|
11427
|
+
constructor(config) {
|
|
11428
|
+
super();
|
|
11429
|
+
const client = resolveClient(config);
|
|
11430
|
+
this.#client = client;
|
|
11431
|
+
this.#db = new LibSQLDB({ client, maxRetries: config.maxRetries, initialBackoffMs: config.initialBackoffMs });
|
|
11432
|
+
}
|
|
11433
|
+
async init() {
|
|
11434
|
+
await this.#db.createTable({
|
|
11435
|
+
tableName: storage.TABLE_THREAD_STATE,
|
|
11436
|
+
schema: storage.THREAD_STATE_SCHEMA,
|
|
11437
|
+
compositePrimaryKey: ["threadId", "type"]
|
|
11438
|
+
});
|
|
11439
|
+
}
|
|
11440
|
+
async dangerouslyClearAll() {
|
|
11441
|
+
try {
|
|
11442
|
+
await this.#client.execute(`DELETE FROM "${storage.TABLE_THREAD_STATE}"`);
|
|
11443
|
+
} catch (error$1) {
|
|
11444
|
+
throw new error.MastraError(
|
|
11445
|
+
{
|
|
11446
|
+
id: storage.createStorageErrorId("LIBSQL", "THREAD_STATE_CLEAR_ALL", "FAILED"),
|
|
11447
|
+
domain: error.ErrorDomain.STORAGE,
|
|
11448
|
+
category: error.ErrorCategory.THIRD_PARTY
|
|
11449
|
+
},
|
|
11450
|
+
error$1
|
|
11451
|
+
);
|
|
11452
|
+
}
|
|
11453
|
+
}
|
|
11454
|
+
async getState({ threadId, type }) {
|
|
11455
|
+
try {
|
|
11456
|
+
const result = await this.#client.execute({
|
|
11457
|
+
sql: `SELECT "value" FROM "${storage.TABLE_THREAD_STATE}" WHERE "threadId" = ? AND "type" = ? LIMIT 1`,
|
|
11458
|
+
args: [threadId, type]
|
|
11459
|
+
});
|
|
11460
|
+
const raw = result.rows?.[0]?.value;
|
|
11461
|
+
if (raw === void 0 || raw === null) return void 0;
|
|
11462
|
+
return typeof raw === "string" ? JSON.parse(raw) : raw;
|
|
11463
|
+
} catch (error$1) {
|
|
11464
|
+
throw new error.MastraError(
|
|
11465
|
+
{
|
|
11466
|
+
id: storage.createStorageErrorId("LIBSQL", "THREAD_STATE_GET", "FAILED"),
|
|
11467
|
+
domain: error.ErrorDomain.STORAGE,
|
|
11468
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
11469
|
+
details: { threadId, type }
|
|
11470
|
+
},
|
|
11471
|
+
error$1
|
|
11472
|
+
);
|
|
11473
|
+
}
|
|
11474
|
+
}
|
|
11475
|
+
async setState({ threadId, type, value }) {
|
|
11476
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
11477
|
+
const serialized = JSON.stringify(value ?? null);
|
|
11478
|
+
try {
|
|
11479
|
+
await this.#client.execute({
|
|
11480
|
+
sql: `INSERT INTO "${storage.TABLE_THREAD_STATE}" ("threadId", "type", "value", "createdAt", "updatedAt")
|
|
11481
|
+
VALUES (?, ?, ?, ?, ?)
|
|
11482
|
+
ON CONFLICT ("threadId", "type")
|
|
11483
|
+
DO UPDATE SET "value" = excluded."value", "updatedAt" = excluded."updatedAt"`,
|
|
11484
|
+
args: [threadId, type, serialized, now, now]
|
|
11485
|
+
});
|
|
11486
|
+
} catch (error$1) {
|
|
11487
|
+
throw new error.MastraError(
|
|
11488
|
+
{
|
|
11489
|
+
id: storage.createStorageErrorId("LIBSQL", "THREAD_STATE_SET", "FAILED"),
|
|
11490
|
+
domain: error.ErrorDomain.STORAGE,
|
|
11491
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
11492
|
+
details: { threadId, type }
|
|
11493
|
+
},
|
|
11494
|
+
error$1
|
|
11495
|
+
);
|
|
11496
|
+
}
|
|
11497
|
+
}
|
|
11498
|
+
async deleteState({ threadId, type }) {
|
|
11499
|
+
try {
|
|
11500
|
+
await this.#client.execute({
|
|
11501
|
+
sql: `DELETE FROM "${storage.TABLE_THREAD_STATE}" WHERE "threadId" = ? AND "type" = ?`,
|
|
11502
|
+
args: [threadId, type]
|
|
11503
|
+
});
|
|
11504
|
+
} catch (error$1) {
|
|
11505
|
+
throw new error.MastraError(
|
|
11506
|
+
{
|
|
11507
|
+
id: storage.createStorageErrorId("LIBSQL", "THREAD_STATE_DELETE", "FAILED"),
|
|
11508
|
+
domain: error.ErrorDomain.STORAGE,
|
|
11509
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
11510
|
+
details: { threadId, type }
|
|
11511
|
+
},
|
|
11512
|
+
error$1
|
|
11513
|
+
);
|
|
11514
|
+
}
|
|
11515
|
+
}
|
|
11516
|
+
};
|
|
11283
11517
|
function normaliseScope(raw) {
|
|
11284
11518
|
const value = raw == null ? "per-author" : String(raw);
|
|
11285
11519
|
if (value === "shared") return "shared";
|
|
@@ -11551,89 +11785,102 @@ var WorkflowsLibSQL = class extends storage.WorkflowsStorage {
|
|
|
11551
11785
|
result,
|
|
11552
11786
|
requestContext
|
|
11553
11787
|
}) {
|
|
11554
|
-
return this.executeWithRetry(
|
|
11555
|
-
|
|
11556
|
-
|
|
11557
|
-
|
|
11558
|
-
|
|
11559
|
-
|
|
11560
|
-
|
|
11561
|
-
|
|
11562
|
-
|
|
11563
|
-
|
|
11564
|
-
|
|
11565
|
-
|
|
11566
|
-
|
|
11567
|
-
|
|
11568
|
-
|
|
11569
|
-
|
|
11570
|
-
|
|
11571
|
-
|
|
11572
|
-
|
|
11573
|
-
|
|
11574
|
-
|
|
11575
|
-
|
|
11576
|
-
|
|
11577
|
-
|
|
11578
|
-
|
|
11579
|
-
|
|
11580
|
-
|
|
11581
|
-
|
|
11582
|
-
|
|
11583
|
-
|
|
11584
|
-
|
|
11585
|
-
|
|
11788
|
+
return this.executeWithRetry(
|
|
11789
|
+
() => (
|
|
11790
|
+
// Serialize the interactive transaction against all other writes on the shared
|
|
11791
|
+
// connection so a concurrent autocommit write can't leak into this open BEGIN.
|
|
11792
|
+
withClientWriteLock(this.#client, async () => {
|
|
11793
|
+
const tx = await this.#client.transaction("write");
|
|
11794
|
+
try {
|
|
11795
|
+
const existingSnapshotResult = await tx.execute({
|
|
11796
|
+
sql: `SELECT json(snapshot) as snapshot FROM ${storage.TABLE_WORKFLOW_SNAPSHOT} WHERE workflow_name = ? AND run_id = ?`,
|
|
11797
|
+
args: [workflowName, runId]
|
|
11798
|
+
});
|
|
11799
|
+
let snapshot;
|
|
11800
|
+
if (!existingSnapshotResult.rows?.[0]) {
|
|
11801
|
+
snapshot = {
|
|
11802
|
+
context: {},
|
|
11803
|
+
activePaths: [],
|
|
11804
|
+
timestamp: Date.now(),
|
|
11805
|
+
suspendedPaths: {},
|
|
11806
|
+
activeStepsPath: {},
|
|
11807
|
+
resumeLabels: {},
|
|
11808
|
+
serializedStepGraph: [],
|
|
11809
|
+
status: "pending",
|
|
11810
|
+
value: {},
|
|
11811
|
+
waitingPaths: {},
|
|
11812
|
+
runId,
|
|
11813
|
+
requestContext: {}
|
|
11814
|
+
};
|
|
11815
|
+
} else {
|
|
11816
|
+
const existingSnapshot = existingSnapshotResult.rows[0].snapshot;
|
|
11817
|
+
snapshot = typeof existingSnapshot === "string" ? JSON.parse(existingSnapshot) : existingSnapshot;
|
|
11818
|
+
}
|
|
11819
|
+
storage.mergeWorkflowStepResult({ snapshot, stepId, result, requestContext });
|
|
11820
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
11821
|
+
await tx.execute({
|
|
11822
|
+
sql: `INSERT INTO ${storage.TABLE_WORKFLOW_SNAPSHOT} (workflow_name, run_id, snapshot, createdAt, updatedAt)
|
|
11586
11823
|
VALUES (?, ?, jsonb(?), ?, ?)
|
|
11587
11824
|
ON CONFLICT(workflow_name, run_id)
|
|
11588
11825
|
DO UPDATE SET snapshot = excluded.snapshot, updatedAt = excluded.updatedAt`,
|
|
11589
|
-
|
|
11590
|
-
|
|
11591
|
-
|
|
11592
|
-
|
|
11593
|
-
|
|
11594
|
-
|
|
11595
|
-
|
|
11596
|
-
|
|
11597
|
-
|
|
11598
|
-
|
|
11599
|
-
|
|
11826
|
+
args: [workflowName, runId, safeStringify(snapshot), now, now]
|
|
11827
|
+
});
|
|
11828
|
+
await tx.commit();
|
|
11829
|
+
return snapshot.context;
|
|
11830
|
+
} catch (error) {
|
|
11831
|
+
if (!tx.closed) {
|
|
11832
|
+
await tx.rollback();
|
|
11833
|
+
}
|
|
11834
|
+
throw error;
|
|
11835
|
+
}
|
|
11836
|
+
})
|
|
11837
|
+
),
|
|
11838
|
+
"updateWorkflowResults"
|
|
11839
|
+
);
|
|
11600
11840
|
}
|
|
11601
11841
|
async updateWorkflowState({
|
|
11602
11842
|
workflowName,
|
|
11603
11843
|
runId,
|
|
11604
11844
|
opts
|
|
11605
11845
|
}) {
|
|
11606
|
-
return this.executeWithRetry(
|
|
11607
|
-
|
|
11608
|
-
|
|
11609
|
-
|
|
11610
|
-
|
|
11611
|
-
|
|
11612
|
-
|
|
11613
|
-
|
|
11614
|
-
|
|
11615
|
-
|
|
11616
|
-
|
|
11617
|
-
|
|
11618
|
-
|
|
11619
|
-
|
|
11620
|
-
|
|
11621
|
-
|
|
11622
|
-
|
|
11623
|
-
|
|
11624
|
-
|
|
11625
|
-
|
|
11626
|
-
|
|
11627
|
-
|
|
11628
|
-
|
|
11629
|
-
|
|
11630
|
-
|
|
11631
|
-
|
|
11632
|
-
|
|
11633
|
-
|
|
11634
|
-
|
|
11635
|
-
|
|
11636
|
-
|
|
11846
|
+
return this.executeWithRetry(
|
|
11847
|
+
() => (
|
|
11848
|
+
// Serialize the interactive transaction against all other writes on the shared
|
|
11849
|
+
// connection so a concurrent autocommit write can't leak into this open BEGIN.
|
|
11850
|
+
withClientWriteLock(this.#client, async () => {
|
|
11851
|
+
const tx = await this.#client.transaction("write");
|
|
11852
|
+
try {
|
|
11853
|
+
const existingSnapshotResult = await tx.execute({
|
|
11854
|
+
sql: `SELECT json(snapshot) as snapshot FROM ${storage.TABLE_WORKFLOW_SNAPSHOT} WHERE workflow_name = ? AND run_id = ?`,
|
|
11855
|
+
args: [workflowName, runId]
|
|
11856
|
+
});
|
|
11857
|
+
if (!existingSnapshotResult.rows?.[0]) {
|
|
11858
|
+
await tx.rollback();
|
|
11859
|
+
return void 0;
|
|
11860
|
+
}
|
|
11861
|
+
const existingSnapshot = existingSnapshotResult.rows[0].snapshot;
|
|
11862
|
+
const snapshot = typeof existingSnapshot === "string" ? JSON.parse(existingSnapshot) : existingSnapshot;
|
|
11863
|
+
if (!snapshot || !snapshot?.context) {
|
|
11864
|
+
await tx.rollback();
|
|
11865
|
+
throw new Error(`Snapshot not found for runId ${runId}`);
|
|
11866
|
+
}
|
|
11867
|
+
const updatedSnapshot = { ...snapshot, ...opts };
|
|
11868
|
+
await tx.execute({
|
|
11869
|
+
sql: `UPDATE ${storage.TABLE_WORKFLOW_SNAPSHOT} SET snapshot = jsonb(?) WHERE workflow_name = ? AND run_id = ?`,
|
|
11870
|
+
args: [safeStringify(updatedSnapshot), workflowName, runId]
|
|
11871
|
+
});
|
|
11872
|
+
await tx.commit();
|
|
11873
|
+
return updatedSnapshot;
|
|
11874
|
+
} catch (error) {
|
|
11875
|
+
if (!tx.closed) {
|
|
11876
|
+
await tx.rollback();
|
|
11877
|
+
}
|
|
11878
|
+
throw error;
|
|
11879
|
+
}
|
|
11880
|
+
})
|
|
11881
|
+
),
|
|
11882
|
+
"updateWorkflowState"
|
|
11883
|
+
);
|
|
11637
11884
|
}
|
|
11638
11885
|
async persistWorkflowSnapshot({
|
|
11639
11886
|
workflowName,
|
|
@@ -11727,7 +11974,7 @@ var WorkflowsLibSQL = class extends storage.WorkflowsStorage {
|
|
|
11727
11974
|
async listWorkflowRuns({
|
|
11728
11975
|
workflowName,
|
|
11729
11976
|
fromDate,
|
|
11730
|
-
toDate,
|
|
11977
|
+
toDate: toDate2,
|
|
11731
11978
|
page,
|
|
11732
11979
|
perPage,
|
|
11733
11980
|
resourceId,
|
|
@@ -11748,9 +11995,9 @@ var WorkflowsLibSQL = class extends storage.WorkflowsStorage {
|
|
|
11748
11995
|
conditions.push("createdAt >= ?");
|
|
11749
11996
|
args.push(fromDate.toISOString());
|
|
11750
11997
|
}
|
|
11751
|
-
if (
|
|
11998
|
+
if (toDate2) {
|
|
11752
11999
|
conditions.push("createdAt <= ?");
|
|
11753
|
-
args.push(
|
|
12000
|
+
args.push(toDate2.toISOString());
|
|
11754
12001
|
}
|
|
11755
12002
|
if (resourceId) {
|
|
11756
12003
|
const hasResourceId = await this.#db.hasColumn(storage.TABLE_WORKFLOW_SNAPSHOT, "resourceId");
|
|
@@ -12407,8 +12654,10 @@ var LibSQLStore = class extends storage.MastraCompositeStore {
|
|
|
12407
12654
|
const blobs = new BlobsLibSQL(domainConfig);
|
|
12408
12655
|
const backgroundTasks = new BackgroundTasksLibSQL(domainConfig);
|
|
12409
12656
|
const schedules = new SchedulesLibSQL(domainConfig);
|
|
12657
|
+
const harness = new HarnessLibSQL(domainConfig);
|
|
12410
12658
|
const toolProviderConnections = new ToolProviderConnectionsLibSQL(domainConfig);
|
|
12411
12659
|
const notifications = new NotificationsLibSQL(domainConfig);
|
|
12660
|
+
const threadState = new ThreadStateLibSQL(domainConfig);
|
|
12412
12661
|
this.stores = {
|
|
12413
12662
|
scores,
|
|
12414
12663
|
workflows,
|
|
@@ -12428,8 +12677,10 @@ var LibSQLStore = class extends storage.MastraCompositeStore {
|
|
|
12428
12677
|
blobs,
|
|
12429
12678
|
backgroundTasks,
|
|
12430
12679
|
schedules,
|
|
12680
|
+
harness,
|
|
12431
12681
|
toolProviderConnections,
|
|
12432
|
-
notifications
|
|
12682
|
+
notifications,
|
|
12683
|
+
threadState
|
|
12433
12684
|
};
|
|
12434
12685
|
}
|
|
12435
12686
|
async applyLocalPragmas() {
|
|
@@ -12626,6 +12877,7 @@ exports.DatasetsLibSQL = DatasetsLibSQL;
|
|
|
12626
12877
|
exports.DefaultStorage = LibSQLStore;
|
|
12627
12878
|
exports.ExperimentsLibSQL = ExperimentsLibSQL;
|
|
12628
12879
|
exports.FavoritesLibSQL = FavoritesLibSQL;
|
|
12880
|
+
exports.HarnessLibSQL = HarnessLibSQL;
|
|
12629
12881
|
exports.LIBSQL_PROMPT = LIBSQL_PROMPT;
|
|
12630
12882
|
exports.LibSQLStore = LibSQLStore;
|
|
12631
12883
|
exports.LibSQLVector = LibSQLVector;
|
|
@@ -12639,6 +12891,7 @@ exports.SchedulesLibSQL = SchedulesLibSQL;
|
|
|
12639
12891
|
exports.ScorerDefinitionsLibSQL = ScorerDefinitionsLibSQL;
|
|
12640
12892
|
exports.ScoresLibSQL = ScoresLibSQL;
|
|
12641
12893
|
exports.SkillsLibSQL = SkillsLibSQL;
|
|
12894
|
+
exports.ThreadStateLibSQL = ThreadStateLibSQL;
|
|
12642
12895
|
exports.ToolProviderConnectionsLibSQL = ToolProviderConnectionsLibSQL;
|
|
12643
12896
|
exports.WorkflowsLibSQL = WorkflowsLibSQL;
|
|
12644
12897
|
exports.WorkspacesLibSQL = WorkspacesLibSQL;
|