@mastra/libsql 1.27.0 → 1.27.1-alpha.1
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/_types/@internal_core/dist/knowledge-compat/index.d.ts +48 -50
- package/dist/_types/@internal_core/dist/memory/index.d.ts +12 -15
- package/dist/docs/SKILL.md +2 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-agents-human-in-the-loop.md +27 -5
- package/dist/docs/references/docs-agents-networks.md +1 -1
- package/dist/docs/references/docs-memory-memory-processors.md +7 -7
- package/dist/docs/references/docs-memory-message-history.md +8 -5
- package/dist/docs/references/docs-memory-multi-user-threads.md +1 -1
- package/dist/docs/references/docs-memory-overview.md +6 -0
- package/dist/docs/references/docs-memory-semantic-recall.md +7 -3
- package/dist/docs/references/docs-memory-working-memory.md +2 -2
- package/dist/docs/references/docs-signals-overview.md +94 -0
- package/dist/docs/references/docs-storage.md +1 -1
- package/dist/docs/references/docs-studio-editor.md +39 -23
- package/dist/docs/references/integrations-channels-github.md +2 -2
- package/dist/docs/references/integrations-databases-dynamodb.md +4 -4
- package/dist/docs/references/reference-core-mastra-class.md +7 -5
- package/dist/docs/references/reference-memory-memory-class.md +5 -5
- package/dist/docs/references/reference-rag-retrieval.md +24 -13
- package/dist/docs/references/reference-storage-retention.md +1 -1
- package/dist/docs/references/reference-vectors-libsql.md +1 -1
- package/dist/index.cjs +137 -105
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +137 -105
- package/dist/index.js.map +1 -1
- package/dist/storage/db/index.d.ts +12 -0
- package/dist/storage/db/index.d.ts.map +1 -1
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/domains/observability/index.d.ts +2 -1
- package/dist/storage/domains/observability/index.d.ts.map +1 -1
- package/dist/storage/domains/workflows/index.d.ts +9 -3
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/package.json +10 -10
package/dist/index.cjs
CHANGED
|
@@ -14,7 +14,7 @@ let _mastra_core_features = require("@mastra/core/features");
|
|
|
14
14
|
let _mastra_core_agent = require("@mastra/core/agent");
|
|
15
15
|
let _mastra_core_evals = require("@mastra/core/evals");
|
|
16
16
|
let _mastra_core_storage_domains_skills = require("@mastra/core/storage/domains/skills");
|
|
17
|
-
|
|
17
|
+
// src/shared/file-transaction-gate.ts
|
|
18
18
|
/** Interactive transactions open in this process, per database file. */
|
|
19
19
|
const openTransactions = /* @__PURE__ */ new Map();
|
|
20
20
|
/** The database file a local `file:` url points at, or `undefined` for anything else. */
|
|
@@ -151,8 +151,7 @@ function gateIfLocalFile(client, url, options) {
|
|
|
151
151
|
const key = localDatabaseFileKey(url);
|
|
152
152
|
return key ? gateLocalFileClient(client, key, options) : client;
|
|
153
153
|
}
|
|
154
|
-
|
|
155
|
-
//#region src/shared/reset-after-busy-client.ts
|
|
154
|
+
// src/shared/reset-after-busy-client.ts
|
|
156
155
|
function isBusy(error) {
|
|
157
156
|
return error?.code === "SQLITE_BUSY";
|
|
158
157
|
}
|
|
@@ -355,8 +354,7 @@ function resetConnectionsAfterBusy(client, { afterReset, maxWaitMs = 5e3 } = {})
|
|
|
355
354
|
}
|
|
356
355
|
} });
|
|
357
356
|
}
|
|
358
|
-
|
|
359
|
-
//#region src/shared/single-connection-client.ts
|
|
357
|
+
// src/shared/single-connection-client.ts
|
|
360
358
|
/**
|
|
361
359
|
* Whether `@libsql/client` backs this database with exactly one connection.
|
|
362
360
|
*
|
|
@@ -434,8 +432,7 @@ function gateSingleConnectionClient(client) {
|
|
|
434
432
|
}
|
|
435
433
|
} });
|
|
436
434
|
}
|
|
437
|
-
|
|
438
|
-
//#region src/vector/filter.ts
|
|
435
|
+
// src/vector/filter.ts
|
|
439
436
|
/**
|
|
440
437
|
* Translates MongoDB-style filters to LibSQL compatible filters.
|
|
441
438
|
*
|
|
@@ -481,8 +478,7 @@ var LibSQLFilterTranslator = class extends _mastra_core_vector_filter.BaseFilter
|
|
|
481
478
|
return result;
|
|
482
479
|
}
|
|
483
480
|
};
|
|
484
|
-
|
|
485
|
-
//#region src/vector/sql-builder.ts
|
|
481
|
+
// src/vector/sql-builder.ts
|
|
486
482
|
const createBasicOperator = (symbol) => {
|
|
487
483
|
return (key, value) => {
|
|
488
484
|
const jsonPath = getJsonPath(key);
|
|
@@ -772,7 +768,7 @@ function handleLogicalOperator(key, value, parentPath) {
|
|
|
772
768
|
const values = [];
|
|
773
769
|
const joinOperator = key === "$or" || key === "$nor" ? "OR" : "AND";
|
|
774
770
|
const joined = (Array.isArray(value) ? value.flatMap((f) => {
|
|
775
|
-
const branch = (
|
|
771
|
+
const branch = (f ? Object.entries(f) : []).map(([k, v]) => buildCondition$1(k, v, key));
|
|
776
772
|
if (branch.length <= 1) return branch;
|
|
777
773
|
return [{
|
|
778
774
|
sql: `(${branch.map((c) => c.sql).join(" AND ")})`,
|
|
@@ -816,8 +812,7 @@ const processOperator = (key, operator, operatorValue) => {
|
|
|
816
812
|
values: Array.isArray(transformed) ? transformed : [transformed]
|
|
817
813
|
};
|
|
818
814
|
};
|
|
819
|
-
|
|
820
|
-
//#region src/vector/write-lock.ts
|
|
815
|
+
// src/vector/write-lock.ts
|
|
821
816
|
const databaseWriteChains = /* @__PURE__ */ new Map();
|
|
822
817
|
async function getLocalFileDatabaseKey({ url, syncUrl, cwd }) {
|
|
823
818
|
if (!url.startsWith("file:") || url.includes(":memory:") || syncUrl) return;
|
|
@@ -841,8 +836,7 @@ function withLocalFileDatabaseWriteLock(key, fn) {
|
|
|
841
836
|
});
|
|
842
837
|
return result;
|
|
843
838
|
}
|
|
844
|
-
|
|
845
|
-
//#region src/vector/index.ts
|
|
839
|
+
// src/vector/index.ts
|
|
846
840
|
var LibSQLVector = class extends _mastra_core_vector.MastraVector {
|
|
847
841
|
turso;
|
|
848
842
|
maxRetries;
|
|
@@ -1460,8 +1454,7 @@ var LibSQLVector = class extends _mastra_core_vector.MastraVector {
|
|
|
1460
1454
|
});
|
|
1461
1455
|
}
|
|
1462
1456
|
};
|
|
1463
|
-
|
|
1464
|
-
//#region src/storage/db/write-lock.ts
|
|
1457
|
+
// src/storage/db/write-lock.ts
|
|
1465
1458
|
/**
|
|
1466
1459
|
* Per-client write serialization.
|
|
1467
1460
|
*
|
|
@@ -1497,8 +1490,7 @@ function withClientWriteLock(client, fn) {
|
|
|
1497
1490
|
clientWriteChains.set(client, result.then(() => void 0, () => void 0));
|
|
1498
1491
|
return result;
|
|
1499
1492
|
}
|
|
1500
|
-
|
|
1501
|
-
//#region src/storage/db/run-fencing.ts
|
|
1493
|
+
// src/storage/db/run-fencing.ts
|
|
1502
1494
|
/**
|
|
1503
1495
|
* Epoch milliseconds on the database clock. `julianday('now')` rather than
|
|
1504
1496
|
* `unixepoch('subsec')`, which needs SQLite 3.42 on the server.
|
|
@@ -1565,8 +1557,7 @@ function withRunFence(client, check, write) {
|
|
|
1565
1557
|
});
|
|
1566
1558
|
});
|
|
1567
1559
|
}
|
|
1568
|
-
|
|
1569
|
-
//#region src/storage/db/utils.ts
|
|
1560
|
+
// src/storage/db/utils.ts
|
|
1570
1561
|
const MAX_DEPTH = 100;
|
|
1571
1562
|
/**
|
|
1572
1563
|
* Safely serializes a value to JSON string with pre-sanitization.
|
|
@@ -1839,8 +1830,7 @@ function transformFromSqlRow({ tableName, sqlRow }) {
|
|
|
1839
1830
|
}
|
|
1840
1831
|
return result;
|
|
1841
1832
|
}
|
|
1842
|
-
|
|
1843
|
-
//#region src/storage/db/index.ts
|
|
1833
|
+
// src/storage/db/index.ts
|
|
1844
1834
|
/**
|
|
1845
1835
|
* Default SQLite `busy_timeout` (ms) for local LibSQL connections. Chosen to
|
|
1846
1836
|
* comfortably exceed the write-retry backoff window so contended writes block
|
|
@@ -2069,6 +2059,41 @@ var LibSQLDB = class extends _mastra_core_base.MastraBase {
|
|
|
2069
2059
|
});
|
|
2070
2060
|
}
|
|
2071
2061
|
/**
|
|
2062
|
+
* Updates multiple records in one write batch, with the same retry behavior as
|
|
2063
|
+
* {@link batchUpdate}. Returns, in input order, whether each update changed a row,
|
|
2064
|
+
* so callers can put extra conditions in `keys` (for example `{ endedAt: null }`).
|
|
2065
|
+
*/
|
|
2066
|
+
async batchUpdateReportingChanges({ tableName, updates }) {
|
|
2067
|
+
return this.executeWriteOperationWithRetry(async () => {
|
|
2068
|
+
const changed = updates.map(() => false);
|
|
2069
|
+
const statements = [];
|
|
2070
|
+
const statementIndexes = [];
|
|
2071
|
+
for (const [index, { keys, data }] of updates.entries()) {
|
|
2072
|
+
const filteredData = await this.filterRecordToKnownColumns(tableName, data);
|
|
2073
|
+
if (Object.keys(filteredData).length === 0) continue;
|
|
2074
|
+
statements.push(prepareUpdateStatement({
|
|
2075
|
+
tableName,
|
|
2076
|
+
updates: filteredData,
|
|
2077
|
+
keys
|
|
2078
|
+
}));
|
|
2079
|
+
statementIndexes.push(index);
|
|
2080
|
+
}
|
|
2081
|
+
if (statements.length === 0) return changed;
|
|
2082
|
+
(await withClientWriteLock(this.client, () => this.client.batch(statements, "write"))).forEach((result, i) => {
|
|
2083
|
+
const index = statementIndexes[i];
|
|
2084
|
+
if (index !== void 0) changed[index] = result.rowsAffected > 0;
|
|
2085
|
+
});
|
|
2086
|
+
return changed;
|
|
2087
|
+
}, `batch update in table ${tableName}`).catch((error) => {
|
|
2088
|
+
throw new _mastra_core_error.MastraError({
|
|
2089
|
+
id: (0, _mastra_core_storage.createStorageErrorId)("LIBSQL", "BATCH_UPDATE_REPORTING_CHANGES", "FAILED"),
|
|
2090
|
+
domain: _mastra_core_error.ErrorDomain.STORAGE,
|
|
2091
|
+
category: _mastra_core_error.ErrorCategory.THIRD_PARTY,
|
|
2092
|
+
details: { tableName }
|
|
2093
|
+
}, error);
|
|
2094
|
+
});
|
|
2095
|
+
}
|
|
2096
|
+
/**
|
|
2072
2097
|
* Internal batch delete implementation without retry logic.
|
|
2073
2098
|
* Each record can be deleted based on single or composite keys.
|
|
2074
2099
|
*/
|
|
@@ -2201,7 +2226,7 @@ var LibSQLDB = class extends _mastra_core_base.MastraBase {
|
|
|
2201
2226
|
* @returns The total count of matching records
|
|
2202
2227
|
*/
|
|
2203
2228
|
async selectTotalCount({ tableName, whereClause }) {
|
|
2204
|
-
const statement = `SELECT COUNT(*) as count FROM ${(0, _mastra_core_utils.parseSqlIdentifier)(tableName, "table name")} ${whereClause ?
|
|
2229
|
+
const statement = `SELECT COUNT(*) as count FROM ${(0, _mastra_core_utils.parseSqlIdentifier)(tableName, "table name")} ${whereClause ? whereClause.sql : ""}`;
|
|
2205
2230
|
const result = await this.client.execute({
|
|
2206
2231
|
sql: statement,
|
|
2207
2232
|
args: whereClause?.args ?? []
|
|
@@ -2573,8 +2598,7 @@ MIGRATION REQUIRED: Duplicate spans detected in ${_mastra_core_storage.TABLE_SPA
|
|
|
2573
2598
|
await this.client.execute(`CREATE INDEX IF NOT EXISTS "${parsedIndex}" ON "${parsedTable}" ("${parsedColumn}")`);
|
|
2574
2599
|
}
|
|
2575
2600
|
};
|
|
2576
|
-
|
|
2577
|
-
//#region src/storage/domains/agents/index.ts
|
|
2601
|
+
// src/storage/domains/agents/index.ts
|
|
2578
2602
|
var AgentsLibSQL = class extends _mastra_core_storage.AgentsStorage {
|
|
2579
2603
|
#db;
|
|
2580
2604
|
#client;
|
|
@@ -3318,8 +3342,7 @@ var AgentsLibSQL = class extends _mastra_core_storage.AgentsStorage {
|
|
|
3318
3342
|
};
|
|
3319
3343
|
}
|
|
3320
3344
|
};
|
|
3321
|
-
|
|
3322
|
-
//#region src/storage/retention.ts
|
|
3345
|
+
// src/storage/retention.ts
|
|
3323
3346
|
async function ensureAnchorIndex(db, target, logger) {
|
|
3324
3347
|
if (!target.indexed) return;
|
|
3325
3348
|
try {
|
|
@@ -3359,8 +3382,7 @@ function resolveTargets({ policies, descriptor, order }) {
|
|
|
3359
3382
|
order
|
|
3360
3383
|
});
|
|
3361
3384
|
}
|
|
3362
|
-
|
|
3363
|
-
//#region src/storage/domains/background-tasks/index.ts
|
|
3385
|
+
// src/storage/domains/background-tasks/index.ts
|
|
3364
3386
|
function serializeJson(v) {
|
|
3365
3387
|
if (v === void 0) return null;
|
|
3366
3388
|
let serialized;
|
|
@@ -3685,8 +3707,7 @@ var BackgroundTasksLibSQL = class BackgroundTasksLibSQL extends _mastra_core_sto
|
|
|
3685
3707
|
return Number(result.rows[0]?.count ?? 0);
|
|
3686
3708
|
}
|
|
3687
3709
|
};
|
|
3688
|
-
|
|
3689
|
-
//#region src/storage/domains/blobs/index.ts
|
|
3710
|
+
// src/storage/domains/blobs/index.ts
|
|
3690
3711
|
var BlobsLibSQL = class extends _mastra_core_storage.BlobStore {
|
|
3691
3712
|
#db;
|
|
3692
3713
|
#client;
|
|
@@ -3784,8 +3805,7 @@ var BlobsLibSQL = class extends _mastra_core_storage.BlobStore {
|
|
|
3784
3805
|
};
|
|
3785
3806
|
}
|
|
3786
3807
|
};
|
|
3787
|
-
|
|
3788
|
-
//#region src/storage/domains/channels/index.ts
|
|
3808
|
+
// src/storage/domains/channels/index.ts
|
|
3789
3809
|
var ChannelsLibSQL = class extends _mastra_core_storage.ChannelsStorage {
|
|
3790
3810
|
#db;
|
|
3791
3811
|
#client;
|
|
@@ -3933,8 +3953,7 @@ var ChannelsLibSQL = class extends _mastra_core_storage.ChannelsStorage {
|
|
|
3933
3953
|
};
|
|
3934
3954
|
}
|
|
3935
3955
|
};
|
|
3936
|
-
|
|
3937
|
-
//#region src/storage/domains/utils.ts
|
|
3956
|
+
// src/storage/domains/utils.ts
|
|
3938
3957
|
/**
|
|
3939
3958
|
* Build additional `AND col = ?` conditions for a tenancy read-scope filter.
|
|
3940
3959
|
* Returned in the shape expected by libsql's parameterized SQL builders.
|
|
@@ -3975,8 +3994,7 @@ function buildScopedWhere(idColumn, idValue, filters) {
|
|
|
3975
3994
|
args: [idValue, ...params]
|
|
3976
3995
|
};
|
|
3977
3996
|
}
|
|
3978
|
-
|
|
3979
|
-
//#region src/storage/domains/datasets/index.ts
|
|
3997
|
+
// src/storage/domains/datasets/index.ts
|
|
3980
3998
|
/** Serialize a value for a jsonb column. Returns null for null/undefined. */
|
|
3981
3999
|
function jsonbArg(value) {
|
|
3982
4000
|
return value === void 0 || value === null ? null : JSON.stringify(value);
|
|
@@ -5244,8 +5262,7 @@ var DatasetsLibSQL = class extends _mastra_core_storage.DatasetsStorage {
|
|
|
5244
5262
|
}
|
|
5245
5263
|
}
|
|
5246
5264
|
};
|
|
5247
|
-
|
|
5248
|
-
//#region src/storage/domains/experiments/index.ts
|
|
5265
|
+
// src/storage/domains/experiments/index.ts
|
|
5249
5266
|
const DEFAULT_PRUNE_BATCH_SIZE = 1e3;
|
|
5250
5267
|
const TAGS_IS_JSON = `CASE typeof(tags) WHEN 'blob' THEN 1 WHEN 'text' THEN json_valid(tags) ELSE 0 END`;
|
|
5251
5268
|
var ExperimentsLibSQL = class extends _mastra_core_storage.ExperimentsStorage {
|
|
@@ -6099,8 +6116,7 @@ var ExperimentsLibSQL = class extends _mastra_core_storage.ExperimentsStorage {
|
|
|
6099
6116
|
}
|
|
6100
6117
|
}
|
|
6101
6118
|
};
|
|
6102
|
-
|
|
6103
|
-
//#region src/storage/domains/favorites/index.ts
|
|
6119
|
+
// src/storage/domains/favorites/index.ts
|
|
6104
6120
|
/**
|
|
6105
6121
|
* Maps a favorite entity type to its parent entity table.
|
|
6106
6122
|
*/
|
|
@@ -6353,8 +6369,7 @@ var FavoritesLibSQL = class extends _mastra_core_storage.FavoritesStorage {
|
|
|
6353
6369
|
}
|
|
6354
6370
|
}
|
|
6355
6371
|
};
|
|
6356
|
-
|
|
6357
|
-
//#region src/storage/domains/harness/index.ts
|
|
6372
|
+
// src/storage/domains/harness/index.ts
|
|
6358
6373
|
const toDate$1 = (value) => new Date(value);
|
|
6359
6374
|
const toOptionalDate = (value) => {
|
|
6360
6375
|
if (value == null) return void 0;
|
|
@@ -6498,8 +6513,7 @@ var HarnessLibSQL = class HarnessLibSQL extends _mastra_core_storage.HarnessStor
|
|
|
6498
6513
|
})).map(rowToSession);
|
|
6499
6514
|
}
|
|
6500
6515
|
};
|
|
6501
|
-
|
|
6502
|
-
//#region ../../packages/_internal-core/dist/knowledge-compat/index.js
|
|
6516
|
+
// ../../packages/_internal-core/dist/knowledge-compat/index.js
|
|
6503
6517
|
const KNOWLEDGE_V2_CORE_FEATURE = "knowledge-v2";
|
|
6504
6518
|
/** Hard cap on scope nodes returned by one `listScopeNodes` read. */
|
|
6505
6519
|
const MAX_KNOWLEDGE_SCOPE_NODES = 1e3;
|
|
@@ -7133,8 +7147,7 @@ function createKnowledgeV2CoreLoader(features, loadStorageModule) {
|
|
|
7133
7147
|
return knowledgeV2Core;
|
|
7134
7148
|
};
|
|
7135
7149
|
}
|
|
7136
|
-
|
|
7137
|
-
//#region src/storage/domains/knowledge/index.ts
|
|
7150
|
+
// src/storage/domains/knowledge/index.ts
|
|
7138
7151
|
const loadKnowledgeV2Core = createKnowledgeV2CoreLoader(_mastra_core_features.coreFeatures, () => import("@mastra/core/storage"));
|
|
7139
7152
|
async function assertKnowledgeDescriptionWithinBoundCompat(description) {
|
|
7140
7153
|
const { assertKnowledgeDescriptionWithinBound } = await loadKnowledgeV2Core();
|
|
@@ -8469,8 +8482,7 @@ var KnowledgeLibSQL = class extends _mastra_core_storage.KnowledgeStorage {
|
|
|
8469
8482
|
});
|
|
8470
8483
|
}
|
|
8471
8484
|
};
|
|
8472
|
-
|
|
8473
|
-
//#region src/storage/domains/mcp-clients/index.ts
|
|
8485
|
+
// src/storage/domains/mcp-clients/index.ts
|
|
8474
8486
|
var MCPClientsLibSQL = class extends _mastra_core_storage.MCPClientsStorage {
|
|
8475
8487
|
#db;
|
|
8476
8488
|
#client;
|
|
@@ -8893,8 +8905,7 @@ var MCPClientsLibSQL = class extends _mastra_core_storage.MCPClientsStorage {
|
|
|
8893
8905
|
};
|
|
8894
8906
|
}
|
|
8895
8907
|
};
|
|
8896
|
-
|
|
8897
|
-
//#region src/storage/domains/mcp-servers/index.ts
|
|
8908
|
+
// src/storage/domains/mcp-servers/index.ts
|
|
8898
8909
|
var MCPServersLibSQL = class extends _mastra_core_storage.MCPServersStorage {
|
|
8899
8910
|
#db;
|
|
8900
8911
|
#client;
|
|
@@ -9324,8 +9335,7 @@ var MCPServersLibSQL = class extends _mastra_core_storage.MCPServersStorage {
|
|
|
9324
9335
|
};
|
|
9325
9336
|
}
|
|
9326
9337
|
};
|
|
9327
|
-
|
|
9328
|
-
//#region ../../packages/_internal-core/dist/memory/index.js
|
|
9338
|
+
// ../../packages/_internal-core/dist/memory/index.js
|
|
9329
9339
|
/**
|
|
9330
9340
|
* Shared rules for observational memory lifecycle writes. Every storage adapter applies
|
|
9331
9341
|
* these inside its own atomic section (lock, transaction, or conditional update), so the
|
|
@@ -9410,8 +9420,7 @@ function isAppendOnlySince(storedObservations, snapshotObservations) {
|
|
|
9410
9420
|
const snapshot = snapshotObservations ?? "";
|
|
9411
9421
|
return stored === snapshot || stored.startsWith(snapshot);
|
|
9412
9422
|
}
|
|
9413
|
-
|
|
9414
|
-
//#region src/storage/domains/memory/index.ts
|
|
9423
|
+
// src/storage/domains/memory/index.ts
|
|
9415
9424
|
/**
|
|
9416
9425
|
* Local constant for the observational memory table name.
|
|
9417
9426
|
* Defined locally to avoid a static import that crashes on older @mastra/core
|
|
@@ -11773,8 +11782,7 @@ var MemoryLibSQL = class MemoryLibSQL extends _mastra_core_storage.MemoryStorage
|
|
|
11773
11782
|
}
|
|
11774
11783
|
}
|
|
11775
11784
|
};
|
|
11776
|
-
|
|
11777
|
-
//#region src/storage/domains/notifications/index.ts
|
|
11785
|
+
// src/storage/domains/notifications/index.ts
|
|
11778
11786
|
/** Ids per UPDATE statement — keeps bind parameters well under SQLite's per-statement limit. */
|
|
11779
11787
|
const BULK_ID_BATCH_SIZE = 500;
|
|
11780
11788
|
const statusTimestamp = (status, now) => {
|
|
@@ -12145,8 +12153,7 @@ var NotificationsLibSQL = class NotificationsLibSQL extends _mastra_core_storage
|
|
|
12145
12153
|
return row ? rowToNotification(row) : void 0;
|
|
12146
12154
|
}
|
|
12147
12155
|
};
|
|
12148
|
-
|
|
12149
|
-
//#region src/storage/domains/observability/index.ts
|
|
12156
|
+
// src/storage/domains/observability/index.ts
|
|
12150
12157
|
var ObservabilityLibSQL = class ObservabilityLibSQL extends _mastra_core_storage.ObservabilityStorage {
|
|
12151
12158
|
/**
|
|
12152
12159
|
* Spans are the only physical table; traces are derived from them. Spans
|
|
@@ -12591,24 +12598,27 @@ var ObservabilityLibSQL = class ObservabilityLibSQL extends _mastra_core_storage
|
|
|
12591
12598
|
}, error);
|
|
12592
12599
|
}
|
|
12593
12600
|
}
|
|
12594
|
-
|
|
12601
|
+
#toSpanUpdates(records) {
|
|
12595
12602
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
12603
|
+
return records.map((record) => {
|
|
12604
|
+
const data = { ...record.updates };
|
|
12605
|
+
if (data.endedAt instanceof Date) data.endedAt = data.endedAt.toISOString();
|
|
12606
|
+
if (data.startedAt instanceof Date) data.startedAt = data.startedAt.toISOString();
|
|
12607
|
+
data.updatedAt = now;
|
|
12608
|
+
return {
|
|
12609
|
+
keys: {
|
|
12610
|
+
spanId: record.spanId,
|
|
12611
|
+
traceId: record.traceId
|
|
12612
|
+
},
|
|
12613
|
+
data
|
|
12614
|
+
};
|
|
12615
|
+
});
|
|
12616
|
+
}
|
|
12617
|
+
async batchUpdateSpans(args) {
|
|
12596
12618
|
try {
|
|
12597
12619
|
return this.#db.batchUpdate({
|
|
12598
12620
|
tableName: _mastra_core_storage.TABLE_SPANS,
|
|
12599
|
-
updates: args.records
|
|
12600
|
-
const data = { ...record.updates };
|
|
12601
|
-
if (data.endedAt instanceof Date) data.endedAt = data.endedAt.toISOString();
|
|
12602
|
-
if (data.startedAt instanceof Date) data.startedAt = data.startedAt.toISOString();
|
|
12603
|
-
data.updatedAt = now;
|
|
12604
|
-
return {
|
|
12605
|
-
keys: {
|
|
12606
|
-
spanId: record.spanId,
|
|
12607
|
-
traceId: record.traceId
|
|
12608
|
-
},
|
|
12609
|
-
data
|
|
12610
|
-
};
|
|
12611
|
-
})
|
|
12621
|
+
updates: this.#toSpanUpdates(args.records)
|
|
12612
12622
|
});
|
|
12613
12623
|
} catch (error) {
|
|
12614
12624
|
throw new _mastra_core_error.MastraError({
|
|
@@ -12618,6 +12628,30 @@ var ObservabilityLibSQL = class ObservabilityLibSQL extends _mastra_core_storage
|
|
|
12618
12628
|
}, error);
|
|
12619
12629
|
}
|
|
12620
12630
|
}
|
|
12631
|
+
async batchUpdateUnendedSpans(args) {
|
|
12632
|
+
try {
|
|
12633
|
+
const changed = await this.#db.batchUpdateReportingChanges({
|
|
12634
|
+
tableName: _mastra_core_storage.TABLE_SPANS,
|
|
12635
|
+
updates: this.#toSpanUpdates(args.records).map((update) => ({
|
|
12636
|
+
...update,
|
|
12637
|
+
keys: {
|
|
12638
|
+
...update.keys,
|
|
12639
|
+
endedAt: null
|
|
12640
|
+
}
|
|
12641
|
+
}))
|
|
12642
|
+
});
|
|
12643
|
+
return { updated: args.records.filter((_, index) => changed[index]).map(({ traceId, spanId }) => ({
|
|
12644
|
+
traceId,
|
|
12645
|
+
spanId
|
|
12646
|
+
})) };
|
|
12647
|
+
} catch (error) {
|
|
12648
|
+
throw new _mastra_core_error.MastraError({
|
|
12649
|
+
id: (0, _mastra_core_storage.createStorageErrorId)("LIBSQL", "BATCH_UPDATE_UNENDED_SPANS", "FAILED"),
|
|
12650
|
+
domain: _mastra_core_error.ErrorDomain.STORAGE,
|
|
12651
|
+
category: _mastra_core_error.ErrorCategory.USER
|
|
12652
|
+
}, error);
|
|
12653
|
+
}
|
|
12654
|
+
}
|
|
12621
12655
|
async batchDeleteTraces(args) {
|
|
12622
12656
|
this.assertUnscopedBatchDeleteTraces(args);
|
|
12623
12657
|
try {
|
|
@@ -12635,8 +12669,7 @@ var ObservabilityLibSQL = class ObservabilityLibSQL extends _mastra_core_storage
|
|
|
12635
12669
|
}
|
|
12636
12670
|
}
|
|
12637
12671
|
};
|
|
12638
|
-
|
|
12639
|
-
//#region src/storage/domains/prompt-blocks/index.ts
|
|
12672
|
+
// src/storage/domains/prompt-blocks/index.ts
|
|
12640
12673
|
var PromptBlocksLibSQL = class extends _mastra_core_storage.PromptBlocksStorage {
|
|
12641
12674
|
#db;
|
|
12642
12675
|
#client;
|
|
@@ -13062,8 +13095,7 @@ var PromptBlocksLibSQL = class extends _mastra_core_storage.PromptBlocksStorage
|
|
|
13062
13095
|
};
|
|
13063
13096
|
}
|
|
13064
13097
|
};
|
|
13065
|
-
|
|
13066
|
-
//#region src/storage/domains/schedules/index.ts
|
|
13098
|
+
// src/storage/domains/schedules/index.ts
|
|
13067
13099
|
function parseJson$1(val) {
|
|
13068
13100
|
if (val == null) return void 0;
|
|
13069
13101
|
if (typeof val === "string") try {
|
|
@@ -13411,8 +13443,7 @@ var SchedulesLibSQL = class SchedulesLibSQL extends _mastra_core_storage.Schedul
|
|
|
13411
13443
|
})).rows.map((r) => rowToTrigger(r));
|
|
13412
13444
|
}
|
|
13413
13445
|
};
|
|
13414
|
-
|
|
13415
|
-
//#region src/storage/domains/scorer-definitions/index.ts
|
|
13446
|
+
// src/storage/domains/scorer-definitions/index.ts
|
|
13416
13447
|
var ScorerDefinitionsLibSQL = class extends _mastra_core_storage.ScorerDefinitionsStorage {
|
|
13417
13448
|
#db;
|
|
13418
13449
|
#client;
|
|
@@ -13839,8 +13870,7 @@ var ScorerDefinitionsLibSQL = class extends _mastra_core_storage.ScorerDefinitio
|
|
|
13839
13870
|
};
|
|
13840
13871
|
}
|
|
13841
13872
|
};
|
|
13842
|
-
|
|
13843
|
-
//#region src/storage/domains/scores/index.ts
|
|
13873
|
+
// src/storage/domains/scores/index.ts
|
|
13844
13874
|
/** Appends multi-tenant scope conditions (`?` placeholders). Mutates inputs. */
|
|
13845
13875
|
function appendTenancyConditions(conditions, args, filters) {
|
|
13846
13876
|
if (filters?.organizationId !== void 0) {
|
|
@@ -14176,8 +14206,7 @@ var ScoresLibSQL = class ScoresLibSQL extends _mastra_core_storage.ScoresStorage
|
|
|
14176
14206
|
}
|
|
14177
14207
|
}
|
|
14178
14208
|
};
|
|
14179
|
-
|
|
14180
|
-
//#region src/storage/domains/skills/index.ts
|
|
14209
|
+
// src/storage/domains/skills/index.ts
|
|
14181
14210
|
/**
|
|
14182
14211
|
* Config fields that live on version rows (from StorageSkillSnapshotType).
|
|
14183
14212
|
*/
|
|
@@ -14743,8 +14772,7 @@ var SkillsLibSQL = class extends _mastra_core_storage.SkillsStorage {
|
|
|
14743
14772
|
};
|
|
14744
14773
|
}
|
|
14745
14774
|
};
|
|
14746
|
-
|
|
14747
|
-
//#region src/storage/domains/thread-state/index.ts
|
|
14775
|
+
// src/storage/domains/thread-state/index.ts
|
|
14748
14776
|
/**
|
|
14749
14777
|
* LibSQL implementation of {@link ThreadStateStorage}.
|
|
14750
14778
|
*
|
|
@@ -14876,8 +14904,7 @@ var ThreadStateLibSQL = class ThreadStateLibSQL extends _mastra_core_storage.Thr
|
|
|
14876
14904
|
}
|
|
14877
14905
|
}
|
|
14878
14906
|
};
|
|
14879
|
-
|
|
14880
|
-
//#region src/storage/domains/tool-provider-connections/index.ts
|
|
14907
|
+
// src/storage/domains/tool-provider-connections/index.ts
|
|
14881
14908
|
function normaliseScope(raw) {
|
|
14882
14909
|
const value = raw == null ? "per-author" : String(raw);
|
|
14883
14910
|
if (value === "shared") return "shared";
|
|
@@ -15087,8 +15114,7 @@ var ToolProviderConnectionsLibSQL = class extends _mastra_core_storage.ToolProvi
|
|
|
15087
15114
|
}
|
|
15088
15115
|
}
|
|
15089
15116
|
};
|
|
15090
|
-
|
|
15091
|
-
//#region src/storage/domains/workflow-definitions/index.ts
|
|
15117
|
+
// src/storage/domains/workflow-definitions/index.ts
|
|
15092
15118
|
function parseJson(val, column, rowId) {
|
|
15093
15119
|
if (val == null) return void 0;
|
|
15094
15120
|
if (typeof val === "string") try {
|
|
@@ -15256,8 +15282,7 @@ var WorkflowDefinitionsLibSQL = class extends _mastra_core_storage.WorkflowDefin
|
|
|
15256
15282
|
});
|
|
15257
15283
|
}
|
|
15258
15284
|
};
|
|
15259
|
-
|
|
15260
|
-
//#region src/storage/domains/workflows/index.ts
|
|
15285
|
+
// src/storage/domains/workflows/index.ts
|
|
15261
15286
|
const RUN_OWNER_COLUMNS = `generation, ownerId, leaseExpiresAt, ${DB_NOW_MS} AS nowMs`;
|
|
15262
15287
|
function toRunOwnershipRecord(runId, row) {
|
|
15263
15288
|
const leaseExpiresAt = row.leaseExpiresAt === null ? null : Number(row.leaseExpiresAt);
|
|
@@ -15315,6 +15340,9 @@ var WorkflowsLibSQL = class WorkflowsLibSQL extends _mastra_core_storage.Workflo
|
|
|
15315
15340
|
supportsConcurrentUpdates() {
|
|
15316
15341
|
return true;
|
|
15317
15342
|
}
|
|
15343
|
+
supportsGuardedSnapshotWrites() {
|
|
15344
|
+
return true;
|
|
15345
|
+
}
|
|
15318
15346
|
parseWorkflowRun(row) {
|
|
15319
15347
|
let parsedSnapshot = row.snapshot;
|
|
15320
15348
|
if (typeof parsedSnapshot === "string") try {
|
|
@@ -15588,7 +15616,7 @@ var WorkflowsLibSQL = class WorkflowsLibSQL extends _mastra_core_storage.Workflo
|
|
|
15588
15616
|
}
|
|
15589
15617
|
}), "updateWorkflowState");
|
|
15590
15618
|
}
|
|
15591
|
-
async persistWorkflowSnapshot({ workflowName, runId, resourceId, snapshot, createdAt, updatedAt, fence }) {
|
|
15619
|
+
async persistWorkflowSnapshot({ workflowName, runId, resourceId, snapshot, createdAt, updatedAt, fence, expectedStatus }) {
|
|
15592
15620
|
const now = /* @__PURE__ */ new Date();
|
|
15593
15621
|
const createdAtValue = (createdAt ?? now).toISOString();
|
|
15594
15622
|
const updatedAtValue = (updatedAt ?? now).toISOString();
|
|
@@ -15596,21 +15624,30 @@ var WorkflowsLibSQL = class WorkflowsLibSQL extends _mastra_core_storage.Workflo
|
|
|
15596
15624
|
workflowName,
|
|
15597
15625
|
runId
|
|
15598
15626
|
});
|
|
15627
|
+
const expected = expectedStatus === void 0 ? [] : Array.isArray(expectedStatus) ? expectedStatus : [expectedStatus];
|
|
15628
|
+
const guard = expectedStatus === void 0 ? "" : expected.length ? ` WHERE json_extract(${_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT}.snapshot, '$.status') IN (${expected.map(() => "?").join(", ")})` : " WHERE 0";
|
|
15599
15629
|
const check = this.#runFenceCheck(fence, runId, "persistWorkflowSnapshot");
|
|
15600
|
-
await this.executeWithRetry(() => withRunFence(this.#client, check, (writer) => writer.execute({
|
|
15630
|
+
return (await this.executeWithRetry(() => withRunFence(this.#client, check, (writer) => writer.execute({
|
|
15601
15631
|
sql: `INSERT INTO ${_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT} (workflow_name, run_id, resourceId, snapshot, createdAt, updatedAt)
|
|
15602
15632
|
VALUES (?, ?, ?, jsonb(?), ?, ?)
|
|
15603
15633
|
ON CONFLICT(workflow_name, run_id)
|
|
15604
|
-
DO UPDATE SET resourceId = COALESCE(excluded.resourceId, ${_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT}.resourceId), snapshot = excluded.snapshot, updatedAt = excluded.updatedAt`,
|
|
15634
|
+
DO UPDATE SET resourceId = COALESCE(excluded.resourceId, ${_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT}.resourceId), snapshot = excluded.snapshot, updatedAt = excluded.updatedAt${guard}`,
|
|
15605
15635
|
args: [
|
|
15606
15636
|
workflowName,
|
|
15607
15637
|
runId,
|
|
15608
15638
|
resourceId ?? null,
|
|
15609
15639
|
safeStringify(snapshot),
|
|
15610
15640
|
createdAtValue,
|
|
15611
|
-
updatedAtValue
|
|
15641
|
+
updatedAtValue,
|
|
15642
|
+
...expected
|
|
15612
15643
|
]
|
|
15613
|
-
})), "persistWorkflowSnapshot");
|
|
15644
|
+
})), "persistWorkflowSnapshot")).rowsAffected > 0;
|
|
15645
|
+
}
|
|
15646
|
+
async loadWorkflowRunStatus({ workflowName, runId }) {
|
|
15647
|
+
return (await this.#client.execute({
|
|
15648
|
+
sql: `SELECT json_extract(snapshot, '$.status') AS status FROM ${_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT} WHERE workflow_name = ? AND run_id = ?`,
|
|
15649
|
+
args: [workflowName, runId]
|
|
15650
|
+
})).rows?.[0]?.status ?? null;
|
|
15614
15651
|
}
|
|
15615
15652
|
async loadWorkflowSnapshot({ workflowName, runId }) {
|
|
15616
15653
|
this.logger.debug("Loading workflow snapshot", {
|
|
@@ -15738,8 +15775,7 @@ var WorkflowsLibSQL = class WorkflowsLibSQL extends _mastra_core_storage.Workflo
|
|
|
15738
15775
|
}
|
|
15739
15776
|
}
|
|
15740
15777
|
};
|
|
15741
|
-
|
|
15742
|
-
//#region src/storage/domains/workspaces/index.ts
|
|
15778
|
+
// src/storage/domains/workspaces/index.ts
|
|
15743
15779
|
/**
|
|
15744
15780
|
* Config fields that live on version rows (from StorageWorkspaceSnapshotType).
|
|
15745
15781
|
*/
|
|
@@ -16228,8 +16264,7 @@ var WorkspacesLibSQL = class extends _mastra_core_storage.WorkspacesStorage {
|
|
|
16228
16264
|
};
|
|
16229
16265
|
}
|
|
16230
16266
|
};
|
|
16231
|
-
|
|
16232
|
-
//#region src/storage/factory-storage.ts
|
|
16267
|
+
// src/storage/factory-storage.ts
|
|
16233
16268
|
const IDENTIFIER_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
16234
16269
|
const COLUMN_DDL = {
|
|
16235
16270
|
text: "TEXT",
|
|
@@ -16644,8 +16679,7 @@ var LibSQLFactoryStorage = class extends _mastra_core_storage.FactoryStorage {
|
|
|
16644
16679
|
}
|
|
16645
16680
|
}
|
|
16646
16681
|
};
|
|
16647
|
-
|
|
16648
|
-
//#region src/storage/index.ts
|
|
16682
|
+
// src/storage/index.ts
|
|
16649
16683
|
const REMOTE_INIT_CONCURRENCY = 5;
|
|
16650
16684
|
const REMOTE_INIT_MAX_ATTEMPTS = 3;
|
|
16651
16685
|
const DEFAULT_LOCAL_CACHE_SIZE = -16e3;
|
|
@@ -16862,8 +16896,7 @@ var LibSQLStore = class extends _mastra_core_storage.MastraCompositeStore {
|
|
|
16862
16896
|
if (!this.client.closed) await this.client.close();
|
|
16863
16897
|
}
|
|
16864
16898
|
};
|
|
16865
|
-
|
|
16866
|
-
//#region src/vector/prompt.ts
|
|
16899
|
+
// src/vector/prompt.ts
|
|
16867
16900
|
/**
|
|
16868
16901
|
* Vector store specific prompt that details supported operators and examples.
|
|
16869
16902
|
* This prompt helps users construct valid filters for LibSQL Vector.
|
|
@@ -16965,7 +16998,6 @@ Example Complex Query:
|
|
|
16965
16998
|
]}
|
|
16966
16999
|
]
|
|
16967
17000
|
}`;
|
|
16968
|
-
//#endregion
|
|
16969
17001
|
exports.AgentsLibSQL = AgentsLibSQL;
|
|
16970
17002
|
exports.BackgroundTasksLibSQL = BackgroundTasksLibSQL;
|
|
16971
17003
|
exports.BlobsLibSQL = BlobsLibSQL;
|