@mastra/libsql 1.10.0 → 1.10.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/CHANGELOG.md +18 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-memory-overview.md +2 -1
- package/dist/docs/references/docs-memory-semantic-recall.md +68 -6
- package/dist/index.cjs +57 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +57 -9
- package/dist/index.js.map +1 -1
- package/dist/storage/db/utils.d.ts +11 -0
- package/dist/storage/db/utils.d.ts.map +1 -1
- package/dist/storage/domains/background-tasks/index.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -1170,6 +1170,33 @@ var LibSQLVector = class extends MastraVector {
|
|
|
1170
1170
|
});
|
|
1171
1171
|
}
|
|
1172
1172
|
};
|
|
1173
|
+
var safeStringify = (value) => {
|
|
1174
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
1175
|
+
const sanitize = (val) => {
|
|
1176
|
+
if (val === null || val === void 0) return val;
|
|
1177
|
+
if (typeof val === "function") return void 0;
|
|
1178
|
+
if (typeof val === "symbol") return void 0;
|
|
1179
|
+
if (typeof val === "bigint") return val.toString();
|
|
1180
|
+
if (typeof val !== "object") return val;
|
|
1181
|
+
if (seen.has(val)) return void 0;
|
|
1182
|
+
seen.add(val);
|
|
1183
|
+
if (typeof val.toJSON === "function") {
|
|
1184
|
+
return sanitize(val.toJSON());
|
|
1185
|
+
}
|
|
1186
|
+
if (Array.isArray(val)) {
|
|
1187
|
+
return val.map((item) => sanitize(item));
|
|
1188
|
+
}
|
|
1189
|
+
const result = {};
|
|
1190
|
+
for (const key of Object.keys(val)) {
|
|
1191
|
+
const sanitized = sanitize(val[key]);
|
|
1192
|
+
if (sanitized !== void 0) {
|
|
1193
|
+
result[key] = sanitized;
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
return result;
|
|
1197
|
+
};
|
|
1198
|
+
return JSON.stringify(sanitize(value)) ?? "null";
|
|
1199
|
+
};
|
|
1173
1200
|
function buildSelectColumns(tableName) {
|
|
1174
1201
|
const schema = TABLE_SCHEMAS[tableName];
|
|
1175
1202
|
return Object.keys(schema).map((col) => {
|
|
@@ -1236,12 +1263,12 @@ function prepareStatement({ tableName, record }) {
|
|
|
1236
1263
|
}
|
|
1237
1264
|
const colDef = schema[col];
|
|
1238
1265
|
if (colDef?.type === "jsonb") {
|
|
1239
|
-
return
|
|
1266
|
+
return safeStringify(v);
|
|
1240
1267
|
}
|
|
1241
1268
|
if (v instanceof Date) {
|
|
1242
1269
|
return v.toISOString();
|
|
1243
1270
|
}
|
|
1244
|
-
return typeof v === "object" ?
|
|
1271
|
+
return typeof v === "object" ? safeStringify(v) : v;
|
|
1245
1272
|
});
|
|
1246
1273
|
const placeholders = columnNames.map((col) => {
|
|
1247
1274
|
const colDef = schema[col];
|
|
@@ -1284,12 +1311,12 @@ function transformToSqlValue(value, forceJsonStringify = false) {
|
|
|
1284
1311
|
return null;
|
|
1285
1312
|
}
|
|
1286
1313
|
if (forceJsonStringify) {
|
|
1287
|
-
return
|
|
1314
|
+
return safeStringify(value);
|
|
1288
1315
|
}
|
|
1289
1316
|
if (value instanceof Date) {
|
|
1290
1317
|
return value.toISOString();
|
|
1291
1318
|
}
|
|
1292
|
-
return typeof value === "object" ?
|
|
1319
|
+
return typeof value === "object" ? safeStringify(value) : value;
|
|
1293
1320
|
}
|
|
1294
1321
|
function prepareDeleteStatement({ tableName, keys }) {
|
|
1295
1322
|
const parsedTableName = parseSqlIdentifier(tableName, "table name");
|
|
@@ -2991,11 +3018,13 @@ function rowToTask(row) {
|
|
|
2991
3018
|
runId: String(row.run_id),
|
|
2992
3019
|
result: parseJson(row.result),
|
|
2993
3020
|
error: parseJson(row.error),
|
|
3021
|
+
suspendPayload: parseJson(row.suspend_payload),
|
|
2994
3022
|
retryCount: Number(row.retry_count),
|
|
2995
3023
|
maxRetries: Number(row.max_retries),
|
|
2996
3024
|
timeoutMs: Number(row.timeout_ms),
|
|
2997
3025
|
createdAt: new Date(String(row.createdAt)),
|
|
2998
3026
|
startedAt: row.startedAt ? new Date(String(row.startedAt)) : void 0,
|
|
3027
|
+
suspendedAt: row.suspendedAt ? new Date(String(row.suspendedAt)) : void 0,
|
|
2999
3028
|
completedAt: row.completedAt ? new Date(String(row.completedAt)) : void 0
|
|
3000
3029
|
};
|
|
3001
3030
|
}
|
|
@@ -3013,6 +3042,11 @@ var BackgroundTasksLibSQL = class extends BackgroundTasksStorage {
|
|
|
3013
3042
|
tableName: TABLE_BACKGROUND_TASKS,
|
|
3014
3043
|
schema: TABLE_SCHEMAS[TABLE_BACKGROUND_TASKS]
|
|
3015
3044
|
});
|
|
3045
|
+
await this.#db.alterTable({
|
|
3046
|
+
tableName: TABLE_BACKGROUND_TASKS,
|
|
3047
|
+
schema: TABLE_SCHEMAS[TABLE_BACKGROUND_TASKS],
|
|
3048
|
+
ifNotExists: ["suspend_payload", "suspendedAt"]
|
|
3049
|
+
});
|
|
3016
3050
|
}
|
|
3017
3051
|
async dangerouslyClearAll() {
|
|
3018
3052
|
await this.#db.deleteData({ tableName: TABLE_BACKGROUND_TASKS });
|
|
@@ -3032,11 +3066,13 @@ var BackgroundTasksLibSQL = class extends BackgroundTasksStorage {
|
|
|
3032
3066
|
args: task.args,
|
|
3033
3067
|
result: task.result ?? null,
|
|
3034
3068
|
error: task.error ?? null,
|
|
3069
|
+
suspend_payload: task.suspendPayload ?? null,
|
|
3035
3070
|
retry_count: task.retryCount,
|
|
3036
3071
|
max_retries: task.maxRetries,
|
|
3037
3072
|
timeout_ms: task.timeoutMs,
|
|
3038
3073
|
createdAt: task.createdAt.toISOString(),
|
|
3039
3074
|
startedAt: task.startedAt?.toISOString() ?? null,
|
|
3075
|
+
suspendedAt: task.suspendedAt?.toISOString() ?? null,
|
|
3040
3076
|
completedAt: task.completedAt?.toISOString() ?? null
|
|
3041
3077
|
}
|
|
3042
3078
|
});
|
|
@@ -3056,6 +3092,10 @@ var BackgroundTasksLibSQL = class extends BackgroundTasksStorage {
|
|
|
3056
3092
|
setClauses.push("error = jsonb(?)");
|
|
3057
3093
|
params.push(serializeJson(update.error));
|
|
3058
3094
|
}
|
|
3095
|
+
if ("suspendPayload" in update) {
|
|
3096
|
+
setClauses.push("suspend_payload = jsonb(?)");
|
|
3097
|
+
params.push(serializeJson(update.suspendPayload));
|
|
3098
|
+
}
|
|
3059
3099
|
if ("retryCount" in update) {
|
|
3060
3100
|
setClauses.push("retry_count = ?");
|
|
3061
3101
|
params.push(update.retryCount);
|
|
@@ -3064,6 +3104,10 @@ var BackgroundTasksLibSQL = class extends BackgroundTasksStorage {
|
|
|
3064
3104
|
setClauses.push("startedAt = ?");
|
|
3065
3105
|
params.push(update.startedAt?.toISOString() ?? null);
|
|
3066
3106
|
}
|
|
3107
|
+
if ("suspendedAt" in update) {
|
|
3108
|
+
setClauses.push("suspendedAt = ?");
|
|
3109
|
+
params.push(update.suspendedAt?.toISOString() ?? null);
|
|
3110
|
+
}
|
|
3067
3111
|
if ("completedAt" in update) {
|
|
3068
3112
|
setClauses.push("completedAt = ?");
|
|
3069
3113
|
params.push(update.completedAt?.toISOString() ?? null);
|
|
@@ -3111,7 +3155,11 @@ var BackgroundTasksLibSQL = class extends BackgroundTasksStorage {
|
|
|
3111
3155
|
conditions.push("tool_name = ?");
|
|
3112
3156
|
params.push(filter.toolName);
|
|
3113
3157
|
}
|
|
3114
|
-
|
|
3158
|
+
if (filter.toolCallId) {
|
|
3159
|
+
conditions.push("tool_call_id = ?");
|
|
3160
|
+
params.push(filter.toolCallId);
|
|
3161
|
+
}
|
|
3162
|
+
const dateCol = filter.dateFilterBy === "startedAt" ? "startedAt" : filter.dateFilterBy === "suspendedAt" ? "suspendedAt" : filter.dateFilterBy === "completedAt" ? "completedAt" : "createdAt";
|
|
3115
3163
|
if (filter.fromDate) {
|
|
3116
3164
|
conditions.push(`${dateCol} >= ?`);
|
|
3117
3165
|
params.push(filter.fromDate.toISOString());
|
|
@@ -3126,7 +3174,7 @@ var BackgroundTasksLibSQL = class extends BackgroundTasksStorage {
|
|
|
3126
3174
|
args: [...params]
|
|
3127
3175
|
});
|
|
3128
3176
|
const total = Number(countResult.rows[0]?.count ?? 0);
|
|
3129
|
-
const orderCol = filter.orderBy === "startedAt" ? "startedAt" : filter.orderBy === "completedAt" ? "completedAt" : "createdAt";
|
|
3177
|
+
const orderCol = filter.orderBy === "startedAt" ? "startedAt" : filter.orderBy === "suspendedAt" ? "suspendedAt" : filter.orderBy === "completedAt" ? "completedAt" : "createdAt";
|
|
3130
3178
|
const direction = filter.orderDirection === "desc" ? "DESC" : "ASC";
|
|
3131
3179
|
let sql = `SELECT ${buildSelectColumns(TABLE_BACKGROUND_TASKS)} FROM ${TABLE_BACKGROUND_TASKS} ${where} ORDER BY ${orderCol} ${direction}`;
|
|
3132
3180
|
if (filter.perPage != null) {
|
|
@@ -3154,7 +3202,7 @@ var BackgroundTasksLibSQL = class extends BackgroundTasksStorage {
|
|
|
3154
3202
|
conditions.push(`status IN (${statuses.map(() => "?").join(", ")})`);
|
|
3155
3203
|
params.push(...statuses);
|
|
3156
3204
|
}
|
|
3157
|
-
const dateCol = filter.dateFilterBy === "startedAt" ? "startedAt" : filter.dateFilterBy === "completedAt" ? "completedAt" : "createdAt";
|
|
3205
|
+
const dateCol = filter.dateFilterBy === "startedAt" ? "startedAt" : filter.dateFilterBy === "suspendedAt" ? "suspendedAt" : filter.dateFilterBy === "completedAt" ? "completedAt" : "createdAt";
|
|
3158
3206
|
if (filter.fromDate) {
|
|
3159
3207
|
conditions.push(`${dateCol} >= ?`);
|
|
3160
3208
|
params.push(filter.fromDate.toISOString());
|
|
@@ -10584,7 +10632,7 @@ var WorkflowsLibSQL = class extends WorkflowsStorage {
|
|
|
10584
10632
|
VALUES (?, ?, jsonb(?), ?, ?)
|
|
10585
10633
|
ON CONFLICT(workflow_name, run_id)
|
|
10586
10634
|
DO UPDATE SET snapshot = excluded.snapshot, updatedAt = excluded.updatedAt`,
|
|
10587
|
-
args: [workflowName, runId,
|
|
10635
|
+
args: [workflowName, runId, safeStringify(snapshot), now, now]
|
|
10588
10636
|
});
|
|
10589
10637
|
await tx.commit();
|
|
10590
10638
|
return snapshot.context;
|
|
@@ -10621,7 +10669,7 @@ var WorkflowsLibSQL = class extends WorkflowsStorage {
|
|
|
10621
10669
|
const updatedSnapshot = { ...snapshot, ...opts };
|
|
10622
10670
|
await tx.execute({
|
|
10623
10671
|
sql: `UPDATE ${TABLE_WORKFLOW_SNAPSHOT} SET snapshot = jsonb(?) WHERE workflow_name = ? AND run_id = ?`,
|
|
10624
|
-
args: [
|
|
10672
|
+
args: [safeStringify(updatedSnapshot), workflowName, runId]
|
|
10625
10673
|
});
|
|
10626
10674
|
await tx.commit();
|
|
10627
10675
|
return updatedSnapshot;
|