@mastra/libsql 1.19.0 → 1.20.0-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/CHANGELOG.md +62 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-agents-agent-approval.md +1 -1
- package/dist/docs/references/docs-agents-networks.md +2 -2
- package/dist/docs/references/docs-memory-overview.md +2 -2
- package/dist/docs/references/docs-storage-overview.md +2 -2
- package/dist/docs/references/reference-file-based-agents-storage.md +1 -1
- package/dist/docs/references/reference-storage-composite.md +58 -0
- package/dist/docs/references/reference-storage-retention.md +1 -1
- package/dist/index.cjs +87 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +87 -36
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/experiments/index.d.ts.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +6 -0
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -4591,7 +4591,13 @@ var ExperimentsLibSQL = class extends ExperimentsStorage {
|
|
|
4591
4591
|
ifNotExists: [
|
|
4592
4592
|
"agentVersion",
|
|
4593
4593
|
"organizationId",
|
|
4594
|
-
"projectId"
|
|
4594
|
+
"projectId",
|
|
4595
|
+
"provenance",
|
|
4596
|
+
"runnerAttestation",
|
|
4597
|
+
"experimentSetId",
|
|
4598
|
+
"comparisonId",
|
|
4599
|
+
"variantId",
|
|
4600
|
+
"trialIndex"
|
|
4595
4601
|
]
|
|
4596
4602
|
});
|
|
4597
4603
|
await this.#db.alterTable({
|
|
@@ -4611,6 +4617,10 @@ var ExperimentsLibSQL = class extends ExperimentsStorage {
|
|
|
4611
4617
|
sql: `CREATE INDEX IF NOT EXISTS idx_experiments_datasetid ON "${TABLE_EXPERIMENTS}" ("datasetId")`,
|
|
4612
4618
|
args: []
|
|
4613
4619
|
},
|
|
4620
|
+
{
|
|
4621
|
+
sql: `CREATE INDEX IF NOT EXISTS idx_experiments_grouping ON "${TABLE_EXPERIMENTS}" ("experimentSetId", "comparisonId", "variantId", "trialIndex")`,
|
|
4622
|
+
args: []
|
|
4623
|
+
},
|
|
4614
4624
|
{
|
|
4615
4625
|
sql: `CREATE INDEX IF NOT EXISTS idx_experiment_results_experimentid ON "${TABLE_EXPERIMENT_RESULTS}" ("experimentId")`,
|
|
4616
4626
|
args: []
|
|
@@ -4710,6 +4720,12 @@ var ExperimentsLibSQL = class extends ExperimentsStorage {
|
|
|
4710
4720
|
name: row.name ?? void 0,
|
|
4711
4721
|
description: row.description ?? void 0,
|
|
4712
4722
|
metadata: row.metadata ? safelyParseJSON(row.metadata) : void 0,
|
|
4723
|
+
provenance: row.provenance ? safelyParseJSON(row.provenance) : null,
|
|
4724
|
+
runnerAttestation: row.runnerAttestation ? safelyParseJSON(row.runnerAttestation) : null,
|
|
4725
|
+
experimentSetId: row.experimentSetId ?? null,
|
|
4726
|
+
comparisonId: row.comparisonId ?? null,
|
|
4727
|
+
variantId: row.variantId ?? null,
|
|
4728
|
+
trialIndex: row.trialIndex != null ? row.trialIndex : null,
|
|
4713
4729
|
status: row.status,
|
|
4714
4730
|
totalItems: row.totalItems,
|
|
4715
4731
|
succeededCount: row.succeededCount,
|
|
@@ -4763,6 +4779,12 @@ var ExperimentsLibSQL = class extends ExperimentsStorage {
|
|
|
4763
4779
|
name: input.name ?? null,
|
|
4764
4780
|
description: input.description ?? null,
|
|
4765
4781
|
metadata: input.metadata ?? null,
|
|
4782
|
+
provenance: input.provenance ?? null,
|
|
4783
|
+
runnerAttestation: input.runnerAttestation ?? null,
|
|
4784
|
+
experimentSetId: input.experimentSetId ?? null,
|
|
4785
|
+
comparisonId: input.comparisonId ?? null,
|
|
4786
|
+
variantId: input.variantId ?? null,
|
|
4787
|
+
trialIndex: input.trialIndex ?? null,
|
|
4766
4788
|
status: "pending",
|
|
4767
4789
|
totalItems: input.totalItems,
|
|
4768
4790
|
succeededCount: 0,
|
|
@@ -4786,6 +4808,12 @@ var ExperimentsLibSQL = class extends ExperimentsStorage {
|
|
|
4786
4808
|
name: input.name,
|
|
4787
4809
|
description: input.description,
|
|
4788
4810
|
metadata: input.metadata,
|
|
4811
|
+
provenance: input.provenance ?? null,
|
|
4812
|
+
runnerAttestation: input.runnerAttestation ?? null,
|
|
4813
|
+
experimentSetId: input.experimentSetId ?? null,
|
|
4814
|
+
comparisonId: input.comparisonId ?? null,
|
|
4815
|
+
variantId: input.variantId ?? null,
|
|
4816
|
+
trialIndex: input.trialIndex ?? null,
|
|
4789
4817
|
status: "pending",
|
|
4790
4818
|
totalItems: input.totalItems,
|
|
4791
4819
|
succeededCount: 0,
|
|
@@ -4911,6 +4939,22 @@ var ExperimentsLibSQL = class extends ExperimentsStorage {
|
|
|
4911
4939
|
conditions.push("status = ?");
|
|
4912
4940
|
queryParams.push(args.status);
|
|
4913
4941
|
}
|
|
4942
|
+
if (args.experimentSetId !== void 0) {
|
|
4943
|
+
conditions.push("experimentSetId = ?");
|
|
4944
|
+
queryParams.push(args.experimentSetId);
|
|
4945
|
+
}
|
|
4946
|
+
if (args.comparisonId !== void 0) {
|
|
4947
|
+
conditions.push("comparisonId = ?");
|
|
4948
|
+
queryParams.push(args.comparisonId);
|
|
4949
|
+
}
|
|
4950
|
+
if (args.variantId !== void 0) {
|
|
4951
|
+
conditions.push("variantId = ?");
|
|
4952
|
+
queryParams.push(args.variantId);
|
|
4953
|
+
}
|
|
4954
|
+
if (args.trialIndex !== void 0) {
|
|
4955
|
+
conditions.push("trialIndex = ?");
|
|
4956
|
+
queryParams.push(args.trialIndex);
|
|
4957
|
+
}
|
|
4914
4958
|
if (args.filters) {
|
|
4915
4959
|
const { organizationId, projectId } = args.filters;
|
|
4916
4960
|
if (organizationId !== void 0) {
|
|
@@ -6677,14 +6721,21 @@ var MemoryLibSQL = class MemoryLibSQL extends MemoryStorage {
|
|
|
6677
6721
|
return direction === "ASC" ? String(aValue).localeCompare(String(bValue)) : String(bValue).localeCompare(String(aValue));
|
|
6678
6722
|
});
|
|
6679
6723
|
}
|
|
6680
|
-
|
|
6724
|
+
/**
|
|
6725
|
+
* Fetches included messages by ID, discovering their thread automatically.
|
|
6726
|
+
* This handles cross-thread includes where the include item doesn't specify a threadId.
|
|
6727
|
+
* When a resourceId is given, both the target lookup and the surrounding window stay
|
|
6728
|
+
* inside that resource, so an include never leaks another resource's messages.
|
|
6729
|
+
*/
|
|
6730
|
+
async _getIncludedMessages({ include, resourceId }) {
|
|
6681
6731
|
if (!include || include.length === 0) return null;
|
|
6682
6732
|
const targetIds = include.map((inc) => inc.id).filter(Boolean);
|
|
6683
6733
|
if (targetIds.length === 0) return null;
|
|
6734
|
+
const resourceCondition = resourceId ? ` AND "resourceId" = ?` : "";
|
|
6684
6735
|
const idPlaceholders = targetIds.map(() => "?").join(", ");
|
|
6685
6736
|
const targetResult = await this.#client.execute({
|
|
6686
|
-
sql: `SELECT id, thread_id, "createdAt" FROM "${TABLE_MESSAGES}" WHERE id IN (${idPlaceholders})`,
|
|
6687
|
-
args: targetIds
|
|
6737
|
+
sql: `SELECT id, thread_id, "createdAt" FROM "${TABLE_MESSAGES}" WHERE id IN (${idPlaceholders})${resourceCondition}`,
|
|
6738
|
+
args: resourceId ? [...targetIds, resourceId] : targetIds
|
|
6688
6739
|
});
|
|
6689
6740
|
if (!targetResult.rows || targetResult.rows.length === 0) return null;
|
|
6690
6741
|
const targetMap = new Map(targetResult.rows.map((r) => [r.id, {
|
|
@@ -6701,21 +6752,25 @@ var MemoryLibSQL = class MemoryLibSQL extends MemoryStorage {
|
|
|
6701
6752
|
SELECT id, content, role, type, "createdAt", thread_id, "resourceId"
|
|
6702
6753
|
FROM "${TABLE_MESSAGES}"
|
|
6703
6754
|
WHERE thread_id = ?
|
|
6704
|
-
AND "createdAt" <=
|
|
6755
|
+
AND "createdAt" <= ?${resourceCondition}
|
|
6705
6756
|
ORDER BY "createdAt" DESC, id DESC
|
|
6706
6757
|
LIMIT ?
|
|
6707
6758
|
)`);
|
|
6708
|
-
params.push(target.threadId, target.createdAt
|
|
6759
|
+
params.push(target.threadId, target.createdAt);
|
|
6760
|
+
if (resourceId) params.push(resourceId);
|
|
6761
|
+
params.push(withPreviousMessages + 1);
|
|
6709
6762
|
if (withNextMessages > 0) {
|
|
6710
6763
|
unionQueries.push(`SELECT * FROM (
|
|
6711
6764
|
SELECT id, content, role, type, "createdAt", thread_id, "resourceId"
|
|
6712
6765
|
FROM "${TABLE_MESSAGES}"
|
|
6713
6766
|
WHERE thread_id = ?
|
|
6714
|
-
AND "createdAt" >
|
|
6767
|
+
AND "createdAt" > ?${resourceCondition}
|
|
6715
6768
|
ORDER BY "createdAt" ASC, id ASC
|
|
6716
6769
|
LIMIT ?
|
|
6717
6770
|
)`);
|
|
6718
|
-
params.push(target.threadId, target.createdAt
|
|
6771
|
+
params.push(target.threadId, target.createdAt);
|
|
6772
|
+
if (resourceId) params.push(resourceId);
|
|
6773
|
+
params.push(withNextMessages);
|
|
6719
6774
|
}
|
|
6720
6775
|
}
|
|
6721
6776
|
if (unionQueries.length === 0) return null;
|
|
@@ -6811,7 +6866,10 @@ var MemoryLibSQL = class MemoryLibSQL extends MemoryStorage {
|
|
|
6811
6866
|
hasMore: false
|
|
6812
6867
|
};
|
|
6813
6868
|
if (perPage === 0 && include && include.length > 0) {
|
|
6814
|
-
const includeMessages = await this._getIncludedMessages({
|
|
6869
|
+
const includeMessages = await this._getIncludedMessages({
|
|
6870
|
+
include,
|
|
6871
|
+
resourceId
|
|
6872
|
+
});
|
|
6815
6873
|
if (!includeMessages || includeMessages.length === 0) return {
|
|
6816
6874
|
messages: [],
|
|
6817
6875
|
total: 0,
|
|
@@ -6852,7 +6910,10 @@ var MemoryLibSQL = class MemoryLibSQL extends MemoryStorage {
|
|
|
6852
6910
|
};
|
|
6853
6911
|
const messageIds = new Set(messages.map((m) => m.id));
|
|
6854
6912
|
if (include && include.length > 0) {
|
|
6855
|
-
const includeMessages = await this._getIncludedMessages({
|
|
6913
|
+
const includeMessages = await this._getIncludedMessages({
|
|
6914
|
+
include,
|
|
6915
|
+
resourceId
|
|
6916
|
+
});
|
|
6856
6917
|
if (includeMessages) {
|
|
6857
6918
|
for (const includeMsg of includeMessages) if (!messageIds.has(includeMsg.id)) {
|
|
6858
6919
|
messages.push(includeMsg);
|
|
@@ -6872,6 +6933,7 @@ var MemoryLibSQL = class MemoryLibSQL extends MemoryStorage {
|
|
|
6872
6933
|
hasMore: metadataFilter ? perPageInput !== false && offset + paginatedCount < total : perPageInput !== false && !allThreadMessagesReturned && offset + perPage < total
|
|
6873
6934
|
};
|
|
6874
6935
|
} catch (error) {
|
|
6936
|
+
if (error instanceof MastraError && error.category === ErrorCategory.USER) throw error;
|
|
6875
6937
|
const mastraError = new MastraError({
|
|
6876
6938
|
id: createStorageErrorId("LIBSQL", "LIST_MESSAGES", "FAILED"),
|
|
6877
6939
|
domain: ErrorDomain.STORAGE,
|
|
@@ -6883,25 +6945,19 @@ var MemoryLibSQL = class MemoryLibSQL extends MemoryStorage {
|
|
|
6883
6945
|
}, error);
|
|
6884
6946
|
this.logger?.error?.(mastraError.toString());
|
|
6885
6947
|
this.logger?.trackException?.(mastraError);
|
|
6886
|
-
|
|
6887
|
-
messages: [],
|
|
6888
|
-
total: 0,
|
|
6889
|
-
page,
|
|
6890
|
-
perPage: perPageForResponse,
|
|
6891
|
-
hasMore: false
|
|
6892
|
-
};
|
|
6948
|
+
throw mastraError;
|
|
6893
6949
|
}
|
|
6894
6950
|
}
|
|
6895
6951
|
async listMessagesByResourceId(args) {
|
|
6896
6952
|
const { resourceId, include, filter, perPage: perPageInput, page = 0, orderBy } = args;
|
|
6897
6953
|
if (!resourceId || typeof resourceId !== "string" || resourceId.trim().length === 0) throw new MastraError({
|
|
6898
|
-
id: createStorageErrorId("LIBSQL", "
|
|
6954
|
+
id: createStorageErrorId("LIBSQL", "LIST_MESSAGES_BY_RESOURCE_ID", "INVALID_QUERY"),
|
|
6899
6955
|
domain: ErrorDomain.STORAGE,
|
|
6900
6956
|
category: ErrorCategory.USER,
|
|
6901
6957
|
details: { resourceId: resourceId ?? "" }
|
|
6902
6958
|
}, /* @__PURE__ */ new Error("resourceId is required"));
|
|
6903
6959
|
if (page < 0) throw new MastraError({
|
|
6904
|
-
id: createStorageErrorId("LIBSQL", "
|
|
6960
|
+
id: createStorageErrorId("LIBSQL", "LIST_MESSAGES_BY_RESOURCE_ID", "INVALID_PAGE"),
|
|
6905
6961
|
domain: ErrorDomain.STORAGE,
|
|
6906
6962
|
category: ErrorCategory.USER,
|
|
6907
6963
|
details: { page }
|
|
@@ -6936,7 +6992,10 @@ var MemoryLibSQL = class MemoryLibSQL extends MemoryStorage {
|
|
|
6936
6992
|
hasMore: false
|
|
6937
6993
|
};
|
|
6938
6994
|
if (perPage === 0 && include && include.length > 0) {
|
|
6939
|
-
const includeMessages = await this._getIncludedMessages({
|
|
6995
|
+
const includeMessages = await this._getIncludedMessages({
|
|
6996
|
+
include,
|
|
6997
|
+
resourceId
|
|
6998
|
+
});
|
|
6940
6999
|
if (!includeMessages || includeMessages.length === 0) return {
|
|
6941
7000
|
messages: [],
|
|
6942
7001
|
total: 0,
|
|
@@ -6976,7 +7035,10 @@ var MemoryLibSQL = class MemoryLibSQL extends MemoryStorage {
|
|
|
6976
7035
|
};
|
|
6977
7036
|
const messageIds = new Set(messages.map((m) => m.id));
|
|
6978
7037
|
if (include && include.length > 0) {
|
|
6979
|
-
const includeMessages = await this._getIncludedMessages({
|
|
7038
|
+
const includeMessages = await this._getIncludedMessages({
|
|
7039
|
+
include,
|
|
7040
|
+
resourceId
|
|
7041
|
+
});
|
|
6980
7042
|
if (includeMessages) {
|
|
6981
7043
|
for (const includeMsg of includeMessages) if (!messageIds.has(includeMsg.id)) {
|
|
6982
7044
|
messages.push(includeMsg);
|
|
@@ -6993,21 +7055,16 @@ var MemoryLibSQL = class MemoryLibSQL extends MemoryStorage {
|
|
|
6993
7055
|
hasMore: perPageInput !== false && offset + perPage < total
|
|
6994
7056
|
};
|
|
6995
7057
|
} catch (error) {
|
|
7058
|
+
if (error instanceof MastraError && error.category === ErrorCategory.USER) throw error;
|
|
6996
7059
|
const mastraError = new MastraError({
|
|
6997
|
-
id: createStorageErrorId("LIBSQL", "
|
|
7060
|
+
id: createStorageErrorId("LIBSQL", "LIST_MESSAGES_BY_RESOURCE_ID", "FAILED"),
|
|
6998
7061
|
domain: ErrorDomain.STORAGE,
|
|
6999
7062
|
category: ErrorCategory.THIRD_PARTY,
|
|
7000
7063
|
details: { resourceId }
|
|
7001
7064
|
}, error);
|
|
7002
7065
|
this.logger?.error?.(mastraError.toString());
|
|
7003
7066
|
this.logger?.trackException?.(mastraError);
|
|
7004
|
-
|
|
7005
|
-
messages: [],
|
|
7006
|
-
total: 0,
|
|
7007
|
-
page,
|
|
7008
|
-
perPage: perPageForResponse,
|
|
7009
|
-
hasMore: false
|
|
7010
|
-
};
|
|
7067
|
+
throw mastraError;
|
|
7011
7068
|
}
|
|
7012
7069
|
}
|
|
7013
7070
|
async saveMessages({ messages }) {
|
|
@@ -7355,13 +7412,7 @@ var MemoryLibSQL = class MemoryLibSQL extends MemoryStorage {
|
|
|
7355
7412
|
}, error);
|
|
7356
7413
|
this.logger?.trackException?.(mastraError);
|
|
7357
7414
|
this.logger?.error?.(mastraError.toString());
|
|
7358
|
-
|
|
7359
|
-
threads: [],
|
|
7360
|
-
total: 0,
|
|
7361
|
-
page,
|
|
7362
|
-
perPage: perPageForResponse,
|
|
7363
|
-
hasMore: false
|
|
7364
|
-
};
|
|
7415
|
+
throw mastraError;
|
|
7365
7416
|
}
|
|
7366
7417
|
}
|
|
7367
7418
|
async saveThread({ thread }) {
|