@mastra/libsql 1.8.1-alpha.1 → 1.8.2-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 +20 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +233 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +234 -3
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/background-tasks/index.d.ts +18 -0
- package/dist/storage/domains/background-tasks/index.d.ts.map +1 -0
- package/dist/storage/index.d.ts +2 -1
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @mastra/libsql
|
|
2
2
|
|
|
3
|
+
## 1.8.2-alpha.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Add `BackgroundTasksStorage` domain implementation so `@mastra/core` background task execution works with any storage adapter. ([#15307](https://github.com/mastra-ai/mastra/pull/15307))
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`d63ffdb`](https://github.com/mastra-ai/mastra/commit/d63ffdbb2c11e76fe5ea45faab44bc15460f010c)]:
|
|
10
|
+
- @mastra/core@1.25.1-alpha.0
|
|
11
|
+
|
|
12
|
+
## 1.8.1
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Fixed "column does not exist" errors when using experiment review features on databases created before the review pipeline was introduced. Startup now automatically migrates older experiment tables to the latest schema. ([#15304](https://github.com/mastra-ai/mastra/pull/15304))
|
|
17
|
+
|
|
18
|
+
- Added `entityVersionId`, `parentEntityVersionId`, and `rootEntityVersionId` columns to observability storage tables (spans, metrics, scores, feedback, logs) for filtering and grouping traces by entity version. Added ALTER TABLE migrations for existing databases. Added `targetType`, `targetId`, `agentVersion`, and `status` filters to `listExperiments`, and `traceId` and `status` filters to `listExperimentResults`. ([#15317](https://github.com/mastra-ai/mastra/pull/15317))
|
|
19
|
+
|
|
20
|
+
- Updated dependencies [[`87df955`](https://github.com/mastra-ai/mastra/commit/87df955c028660c075873fd5d74af28233ce32eb), [`8fad147`](https://github.com/mastra-ai/mastra/commit/8fad14759804179c8e080ce4d9dec6ef1a808b31), [`582644c`](https://github.com/mastra-ai/mastra/commit/582644c4a87f83b4f245a84d72b9e8590585012e), [`cbdf3e1`](https://github.com/mastra-ai/mastra/commit/cbdf3e12b3d0c30a6e5347be658e2009648c130a), [`8fe46d3`](https://github.com/mastra-ai/mastra/commit/8fe46d354027f3f0f0846e64219772348de106dd), [`18c67db`](https://github.com/mastra-ai/mastra/commit/18c67dbb9c9ebc26f26f65f7d3ff836e5691ef46), [`4ba3bb1`](https://github.com/mastra-ai/mastra/commit/4ba3bb1e465ad2ddaba3bbf2bc47e0faec32985e), [`5d84914`](https://github.com/mastra-ai/mastra/commit/5d84914e0e520c642a40329b210b413fcd139898), [`8dcc77e`](https://github.com/mastra-ai/mastra/commit/8dcc77e78a5340f5848f74b9e9f1b3da3513c1f5), [`aa67fc5`](https://github.com/mastra-ai/mastra/commit/aa67fc59ee8a5eeff1f23eb05970b8d7a536c8ff), [`fd2f314`](https://github.com/mastra-ai/mastra/commit/fd2f31473d3449b6b97e837ef8641264377f41a7), [`fa8140b`](https://github.com/mastra-ai/mastra/commit/fa8140bcd4251d2e3ac85fdc5547dfc4f372b5be), [`190f452`](https://github.com/mastra-ai/mastra/commit/190f45258b0640e2adfc8219fa3258cdc5b8f071), [`e80fead`](https://github.com/mastra-ai/mastra/commit/e80fead1412cc0d1b2f7d6a1ce5017d9e0098ff7), [`0287b64`](https://github.com/mastra-ai/mastra/commit/0287b644a5c3272755cf3112e71338106664103b), [`7e7bf60`](https://github.com/mastra-ai/mastra/commit/7e7bf606886bf374a6f9d4ca9b09dd83d0533372), [`184907d`](https://github.com/mastra-ai/mastra/commit/184907d775d8609c03c26e78ccaf37315f3aa287), [`075e91a`](https://github.com/mastra-ai/mastra/commit/075e91a4549baf46ad7a42a6a8ac8dfa78cc09e6), [`0c4cd13`](https://github.com/mastra-ai/mastra/commit/0c4cd131931c04ac5405373c932a242dbe88edd6), [`b16a753`](https://github.com/mastra-ai/mastra/commit/b16a753d5748440248d7df82e29bb987a9c8386c)]:
|
|
21
|
+
- @mastra/core@1.25.0
|
|
22
|
+
|
|
3
23
|
## 1.8.1-alpha.1
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/dist/docs/SKILL.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -2884,6 +2884,235 @@ var AgentsLibSQL = class extends storage.AgentsStorage {
|
|
|
2884
2884
|
};
|
|
2885
2885
|
}
|
|
2886
2886
|
};
|
|
2887
|
+
function serializeJson(v) {
|
|
2888
|
+
if (typeof v === "object" && v != null) return JSON.stringify(v);
|
|
2889
|
+
return v ?? null;
|
|
2890
|
+
}
|
|
2891
|
+
function parseJson(val) {
|
|
2892
|
+
if (val == null) return void 0;
|
|
2893
|
+
if (typeof val === "string") {
|
|
2894
|
+
try {
|
|
2895
|
+
return JSON.parse(val);
|
|
2896
|
+
} catch {
|
|
2897
|
+
return val;
|
|
2898
|
+
}
|
|
2899
|
+
}
|
|
2900
|
+
return val;
|
|
2901
|
+
}
|
|
2902
|
+
function rowToTask(row) {
|
|
2903
|
+
return {
|
|
2904
|
+
id: String(row.id),
|
|
2905
|
+
status: String(row.status),
|
|
2906
|
+
toolName: String(row.tool_name),
|
|
2907
|
+
toolCallId: String(row.tool_call_id),
|
|
2908
|
+
args: parseJson(row.args) ?? {},
|
|
2909
|
+
agentId: String(row.agent_id),
|
|
2910
|
+
threadId: row.thread_id != null ? String(row.thread_id) : void 0,
|
|
2911
|
+
resourceId: row.resource_id != null ? String(row.resource_id) : void 0,
|
|
2912
|
+
runId: String(row.run_id),
|
|
2913
|
+
result: parseJson(row.result),
|
|
2914
|
+
error: parseJson(row.error),
|
|
2915
|
+
retryCount: Number(row.retry_count),
|
|
2916
|
+
maxRetries: Number(row.max_retries),
|
|
2917
|
+
timeoutMs: Number(row.timeout_ms),
|
|
2918
|
+
createdAt: new Date(String(row.createdAt)),
|
|
2919
|
+
startedAt: row.startedAt ? new Date(String(row.startedAt)) : void 0,
|
|
2920
|
+
completedAt: row.completedAt ? new Date(String(row.completedAt)) : void 0
|
|
2921
|
+
};
|
|
2922
|
+
}
|
|
2923
|
+
var BackgroundTasksLibSQL = class extends storage.BackgroundTasksStorage {
|
|
2924
|
+
#db;
|
|
2925
|
+
#client;
|
|
2926
|
+
constructor(config) {
|
|
2927
|
+
super();
|
|
2928
|
+
const client = resolveClient(config);
|
|
2929
|
+
this.#client = client;
|
|
2930
|
+
this.#db = new LibSQLDB({ client, maxRetries: config.maxRetries, initialBackoffMs: config.initialBackoffMs });
|
|
2931
|
+
}
|
|
2932
|
+
async init() {
|
|
2933
|
+
await this.#db.createTable({
|
|
2934
|
+
tableName: storage.TABLE_BACKGROUND_TASKS,
|
|
2935
|
+
schema: storage.TABLE_SCHEMAS[storage.TABLE_BACKGROUND_TASKS]
|
|
2936
|
+
});
|
|
2937
|
+
}
|
|
2938
|
+
async dangerouslyClearAll() {
|
|
2939
|
+
await this.#db.deleteData({ tableName: storage.TABLE_BACKGROUND_TASKS });
|
|
2940
|
+
}
|
|
2941
|
+
async createTask(task) {
|
|
2942
|
+
await this.#db.insert({
|
|
2943
|
+
tableName: storage.TABLE_BACKGROUND_TASKS,
|
|
2944
|
+
record: {
|
|
2945
|
+
id: task.id,
|
|
2946
|
+
tool_call_id: task.toolCallId,
|
|
2947
|
+
tool_name: task.toolName,
|
|
2948
|
+
agent_id: task.agentId,
|
|
2949
|
+
thread_id: task.threadId ?? null,
|
|
2950
|
+
resource_id: task.resourceId ?? null,
|
|
2951
|
+
run_id: task.runId,
|
|
2952
|
+
status: task.status,
|
|
2953
|
+
args: task.args,
|
|
2954
|
+
result: task.result ?? null,
|
|
2955
|
+
error: task.error ?? null,
|
|
2956
|
+
retry_count: task.retryCount,
|
|
2957
|
+
max_retries: task.maxRetries,
|
|
2958
|
+
timeout_ms: task.timeoutMs,
|
|
2959
|
+
createdAt: task.createdAt.toISOString(),
|
|
2960
|
+
startedAt: task.startedAt?.toISOString() ?? null,
|
|
2961
|
+
completedAt: task.completedAt?.toISOString() ?? null
|
|
2962
|
+
}
|
|
2963
|
+
});
|
|
2964
|
+
}
|
|
2965
|
+
async updateTask(taskId, update) {
|
|
2966
|
+
const setClauses = [];
|
|
2967
|
+
const params = [];
|
|
2968
|
+
if ("status" in update) {
|
|
2969
|
+
setClauses.push("status = ?");
|
|
2970
|
+
params.push(update.status);
|
|
2971
|
+
}
|
|
2972
|
+
if ("result" in update) {
|
|
2973
|
+
setClauses.push("result = jsonb(?)");
|
|
2974
|
+
params.push(serializeJson(update.result));
|
|
2975
|
+
}
|
|
2976
|
+
if ("error" in update) {
|
|
2977
|
+
setClauses.push("error = jsonb(?)");
|
|
2978
|
+
params.push(serializeJson(update.error));
|
|
2979
|
+
}
|
|
2980
|
+
if ("retryCount" in update) {
|
|
2981
|
+
setClauses.push("retry_count = ?");
|
|
2982
|
+
params.push(update.retryCount);
|
|
2983
|
+
}
|
|
2984
|
+
if ("startedAt" in update) {
|
|
2985
|
+
setClauses.push("startedAt = ?");
|
|
2986
|
+
params.push(update.startedAt?.toISOString() ?? null);
|
|
2987
|
+
}
|
|
2988
|
+
if ("completedAt" in update) {
|
|
2989
|
+
setClauses.push("completedAt = ?");
|
|
2990
|
+
params.push(update.completedAt?.toISOString() ?? null);
|
|
2991
|
+
}
|
|
2992
|
+
if (setClauses.length === 0) return;
|
|
2993
|
+
params.push(taskId);
|
|
2994
|
+
await this.#client.execute({
|
|
2995
|
+
sql: `UPDATE ${storage.TABLE_BACKGROUND_TASKS} SET ${setClauses.join(", ")} WHERE id = ?`,
|
|
2996
|
+
args: params
|
|
2997
|
+
});
|
|
2998
|
+
}
|
|
2999
|
+
async getTask(taskId) {
|
|
3000
|
+
const result = await this.#client.execute({
|
|
3001
|
+
sql: `SELECT ${buildSelectColumns(storage.TABLE_BACKGROUND_TASKS)} FROM ${storage.TABLE_BACKGROUND_TASKS} WHERE id = ?`,
|
|
3002
|
+
args: [taskId]
|
|
3003
|
+
});
|
|
3004
|
+
const row = result.rows[0];
|
|
3005
|
+
return row ? rowToTask(row) : null;
|
|
3006
|
+
}
|
|
3007
|
+
async listTasks(filter) {
|
|
3008
|
+
const conditions = [];
|
|
3009
|
+
const params = [];
|
|
3010
|
+
if (filter.status) {
|
|
3011
|
+
const statuses = Array.isArray(filter.status) ? filter.status : [filter.status];
|
|
3012
|
+
conditions.push(`status IN (${statuses.map(() => "?").join(", ")})`);
|
|
3013
|
+
params.push(...statuses);
|
|
3014
|
+
}
|
|
3015
|
+
if (filter.agentId) {
|
|
3016
|
+
conditions.push("agent_id = ?");
|
|
3017
|
+
params.push(filter.agentId);
|
|
3018
|
+
}
|
|
3019
|
+
if (filter.threadId) {
|
|
3020
|
+
conditions.push("thread_id = ?");
|
|
3021
|
+
params.push(filter.threadId);
|
|
3022
|
+
}
|
|
3023
|
+
if (filter.runId) {
|
|
3024
|
+
conditions.push("run_id = ?");
|
|
3025
|
+
params.push(filter.runId);
|
|
3026
|
+
}
|
|
3027
|
+
if (filter.resourceId) {
|
|
3028
|
+
conditions.push("resource_id = ?");
|
|
3029
|
+
params.push(filter.resourceId);
|
|
3030
|
+
}
|
|
3031
|
+
if (filter.toolName) {
|
|
3032
|
+
conditions.push("tool_name = ?");
|
|
3033
|
+
params.push(filter.toolName);
|
|
3034
|
+
}
|
|
3035
|
+
const dateCol = filter.dateFilterBy === "startedAt" ? "startedAt" : filter.dateFilterBy === "completedAt" ? "completedAt" : "createdAt";
|
|
3036
|
+
if (filter.fromDate) {
|
|
3037
|
+
conditions.push(`${dateCol} >= ?`);
|
|
3038
|
+
params.push(filter.fromDate.toISOString());
|
|
3039
|
+
}
|
|
3040
|
+
if (filter.toDate) {
|
|
3041
|
+
conditions.push(`${dateCol} < ?`);
|
|
3042
|
+
params.push(filter.toDate.toISOString());
|
|
3043
|
+
}
|
|
3044
|
+
const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
3045
|
+
const countResult = await this.#client.execute({
|
|
3046
|
+
sql: `SELECT COUNT(*) as count FROM ${storage.TABLE_BACKGROUND_TASKS} ${where}`,
|
|
3047
|
+
args: [...params]
|
|
3048
|
+
});
|
|
3049
|
+
const total = Number(countResult.rows[0]?.count ?? 0);
|
|
3050
|
+
const orderCol = filter.orderBy === "startedAt" ? "startedAt" : filter.orderBy === "completedAt" ? "completedAt" : "createdAt";
|
|
3051
|
+
const direction = filter.orderDirection === "desc" ? "DESC" : "ASC";
|
|
3052
|
+
let sql = `SELECT ${buildSelectColumns(storage.TABLE_BACKGROUND_TASKS)} FROM ${storage.TABLE_BACKGROUND_TASKS} ${where} ORDER BY ${orderCol} ${direction}`;
|
|
3053
|
+
if (filter.perPage != null) {
|
|
3054
|
+
sql += " LIMIT ?";
|
|
3055
|
+
params.push(filter.perPage);
|
|
3056
|
+
if (filter.page != null) {
|
|
3057
|
+
sql += " OFFSET ?";
|
|
3058
|
+
params.push(filter.page * filter.perPage);
|
|
3059
|
+
}
|
|
3060
|
+
}
|
|
3061
|
+
const result = await this.#client.execute({ sql, args: params });
|
|
3062
|
+
return { tasks: result.rows.map((row) => rowToTask(row)), total };
|
|
3063
|
+
}
|
|
3064
|
+
async deleteTask(taskId) {
|
|
3065
|
+
await this.#client.execute({
|
|
3066
|
+
sql: `DELETE FROM ${storage.TABLE_BACKGROUND_TASKS} WHERE id = ?`,
|
|
3067
|
+
args: [taskId]
|
|
3068
|
+
});
|
|
3069
|
+
}
|
|
3070
|
+
async deleteTasks(filter) {
|
|
3071
|
+
const conditions = [];
|
|
3072
|
+
const params = [];
|
|
3073
|
+
if (filter.status) {
|
|
3074
|
+
const statuses = Array.isArray(filter.status) ? filter.status : [filter.status];
|
|
3075
|
+
conditions.push(`status IN (${statuses.map(() => "?").join(", ")})`);
|
|
3076
|
+
params.push(...statuses);
|
|
3077
|
+
}
|
|
3078
|
+
const dateCol = filter.dateFilterBy === "startedAt" ? "startedAt" : filter.dateFilterBy === "completedAt" ? "completedAt" : "createdAt";
|
|
3079
|
+
if (filter.fromDate) {
|
|
3080
|
+
conditions.push(`${dateCol} >= ?`);
|
|
3081
|
+
params.push(filter.fromDate.toISOString());
|
|
3082
|
+
}
|
|
3083
|
+
if (filter.toDate) {
|
|
3084
|
+
conditions.push(`${dateCol} < ?`);
|
|
3085
|
+
params.push(filter.toDate.toISOString());
|
|
3086
|
+
}
|
|
3087
|
+
if (filter.agentId) {
|
|
3088
|
+
conditions.push("agent_id = ?");
|
|
3089
|
+
params.push(filter.agentId);
|
|
3090
|
+
}
|
|
3091
|
+
if (filter.runId) {
|
|
3092
|
+
conditions.push("run_id = ?");
|
|
3093
|
+
params.push(filter.runId);
|
|
3094
|
+
}
|
|
3095
|
+
if (conditions.length === 0) return;
|
|
3096
|
+
await this.#client.execute({
|
|
3097
|
+
sql: `DELETE FROM ${storage.TABLE_BACKGROUND_TASKS} WHERE ${conditions.join(" AND ")}`,
|
|
3098
|
+
args: params
|
|
3099
|
+
});
|
|
3100
|
+
}
|
|
3101
|
+
async getRunningCount() {
|
|
3102
|
+
const result = await this.#client.execute({
|
|
3103
|
+
sql: `SELECT COUNT(*) as count FROM ${storage.TABLE_BACKGROUND_TASKS} WHERE status = 'running'`,
|
|
3104
|
+
args: []
|
|
3105
|
+
});
|
|
3106
|
+
return Number(result.rows[0]?.count ?? 0);
|
|
3107
|
+
}
|
|
3108
|
+
async getRunningCountByAgent(agentId) {
|
|
3109
|
+
const result = await this.#client.execute({
|
|
3110
|
+
sql: `SELECT COUNT(*) as count FROM ${storage.TABLE_BACKGROUND_TASKS} WHERE status = 'running' AND agent_id = ?`,
|
|
3111
|
+
args: [agentId]
|
|
3112
|
+
});
|
|
3113
|
+
return Number(result.rows[0]?.count ?? 0);
|
|
3114
|
+
}
|
|
3115
|
+
};
|
|
2887
3116
|
var BlobsLibSQL = class extends storage.BlobStore {
|
|
2888
3117
|
#db;
|
|
2889
3118
|
#client;
|
|
@@ -10639,6 +10868,7 @@ var LibSQLStore = class extends storage.MastraCompositeStore {
|
|
|
10639
10868
|
const workspaces = new WorkspacesLibSQL(domainConfig);
|
|
10640
10869
|
const skills = new SkillsLibSQL(domainConfig);
|
|
10641
10870
|
const blobs = new BlobsLibSQL(domainConfig);
|
|
10871
|
+
const backgroundTasks = new BackgroundTasksLibSQL(domainConfig);
|
|
10642
10872
|
this.stores = {
|
|
10643
10873
|
scores,
|
|
10644
10874
|
workflows,
|
|
@@ -10653,7 +10883,8 @@ var LibSQLStore = class extends storage.MastraCompositeStore {
|
|
|
10653
10883
|
mcpServers,
|
|
10654
10884
|
workspaces,
|
|
10655
10885
|
skills,
|
|
10656
|
-
blobs
|
|
10886
|
+
blobs,
|
|
10887
|
+
backgroundTasks
|
|
10657
10888
|
};
|
|
10658
10889
|
}
|
|
10659
10890
|
};
|
|
@@ -10758,6 +10989,7 @@ Example Complex Query:
|
|
|
10758
10989
|
}`;
|
|
10759
10990
|
|
|
10760
10991
|
exports.AgentsLibSQL = AgentsLibSQL;
|
|
10992
|
+
exports.BackgroundTasksLibSQL = BackgroundTasksLibSQL;
|
|
10761
10993
|
exports.BlobsLibSQL = BlobsLibSQL;
|
|
10762
10994
|
exports.DatasetsLibSQL = DatasetsLibSQL;
|
|
10763
10995
|
exports.DefaultStorage = LibSQLStore;
|