@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/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createClient } from '@libsql/client';
|
|
2
2
|
import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
|
|
3
|
-
import { createVectorErrorId, AgentsStorage, AGENTS_SCHEMA, TABLE_AGENTS, AGENT_VERSIONS_SCHEMA, TABLE_AGENT_VERSIONS, createStorageErrorId, normalizePerPage, calculatePagination, BlobStore, TABLE_SKILL_BLOBS, SKILL_BLOBS_SCHEMA, DatasetsStorage, DATASETS_SCHEMA, TABLE_DATASETS, DATASET_ITEMS_SCHEMA, TABLE_DATASET_ITEMS, DATASET_VERSIONS_SCHEMA, TABLE_DATASET_VERSIONS, ensureDate, safelyParseJSON, TABLE_EXPERIMENT_RESULTS, TABLE_EXPERIMENTS, ExperimentsStorage, EXPERIMENTS_SCHEMA, EXPERIMENT_RESULTS_SCHEMA, MCPClientsStorage, MCP_CLIENTS_SCHEMA, TABLE_MCP_CLIENTS, MCP_CLIENT_VERSIONS_SCHEMA, TABLE_MCP_CLIENT_VERSIONS, MCPServersStorage, MCP_SERVERS_SCHEMA, TABLE_MCP_SERVERS, MCP_SERVER_VERSIONS_SCHEMA, TABLE_MCP_SERVER_VERSIONS, MemoryStorage,
|
|
3
|
+
import { createVectorErrorId, AgentsStorage, AGENTS_SCHEMA, TABLE_AGENTS, AGENT_VERSIONS_SCHEMA, TABLE_AGENT_VERSIONS, createStorageErrorId, normalizePerPage, calculatePagination, BackgroundTasksStorage, TABLE_SCHEMAS, TABLE_BACKGROUND_TASKS, BlobStore, TABLE_SKILL_BLOBS, SKILL_BLOBS_SCHEMA, DatasetsStorage, DATASETS_SCHEMA, TABLE_DATASETS, DATASET_ITEMS_SCHEMA, TABLE_DATASET_ITEMS, DATASET_VERSIONS_SCHEMA, TABLE_DATASET_VERSIONS, ensureDate, safelyParseJSON, TABLE_EXPERIMENT_RESULTS, TABLE_EXPERIMENTS, ExperimentsStorage, EXPERIMENTS_SCHEMA, EXPERIMENT_RESULTS_SCHEMA, MCPClientsStorage, MCP_CLIENTS_SCHEMA, TABLE_MCP_CLIENTS, MCP_CLIENT_VERSIONS_SCHEMA, TABLE_MCP_CLIENT_VERSIONS, MCPServersStorage, MCP_SERVERS_SCHEMA, TABLE_MCP_SERVERS, MCP_SERVER_VERSIONS_SCHEMA, TABLE_MCP_SERVER_VERSIONS, MemoryStorage, TABLE_THREADS, TABLE_MESSAGES, TABLE_RESOURCES, ObservabilityStorage, SPAN_SCHEMA, TABLE_SPANS, listTracesArgsSchema, toTraceSpans, PromptBlocksStorage, PROMPT_BLOCKS_SCHEMA, TABLE_PROMPT_BLOCKS, PROMPT_BLOCK_VERSIONS_SCHEMA, TABLE_PROMPT_BLOCK_VERSIONS, ScorerDefinitionsStorage, SCORER_DEFINITIONS_SCHEMA, TABLE_SCORER_DEFINITIONS, SCORER_DEFINITION_VERSIONS_SCHEMA, TABLE_SCORER_DEFINITION_VERSIONS, ScoresStorage, SCORERS_SCHEMA, TABLE_SCORERS, transformScoreRow, SkillsStorage, SKILLS_SCHEMA, TABLE_SKILLS, SKILL_VERSIONS_SCHEMA, TABLE_SKILL_VERSIONS, WorkflowsStorage, TABLE_WORKFLOW_SNAPSHOT, WorkspacesStorage, WORKSPACES_SCHEMA, TABLE_WORKSPACES, WORKSPACE_VERSIONS_SCHEMA, TABLE_WORKSPACE_VERSIONS, MastraCompositeStore, getSqlType, TraceStatus } from '@mastra/core/storage';
|
|
4
4
|
import { parseSqlIdentifier, parseFieldKey } from '@mastra/core/utils';
|
|
5
5
|
import { MastraVector, validateTopK, validateUpsertInput } from '@mastra/core/vector';
|
|
6
6
|
import { BaseFilterTranslator } from '@mastra/core/vector/filter';
|
|
@@ -2882,6 +2882,235 @@ var AgentsLibSQL = class extends AgentsStorage {
|
|
|
2882
2882
|
};
|
|
2883
2883
|
}
|
|
2884
2884
|
};
|
|
2885
|
+
function serializeJson(v) {
|
|
2886
|
+
if (typeof v === "object" && v != null) return JSON.stringify(v);
|
|
2887
|
+
return v ?? null;
|
|
2888
|
+
}
|
|
2889
|
+
function parseJson(val) {
|
|
2890
|
+
if (val == null) return void 0;
|
|
2891
|
+
if (typeof val === "string") {
|
|
2892
|
+
try {
|
|
2893
|
+
return JSON.parse(val);
|
|
2894
|
+
} catch {
|
|
2895
|
+
return val;
|
|
2896
|
+
}
|
|
2897
|
+
}
|
|
2898
|
+
return val;
|
|
2899
|
+
}
|
|
2900
|
+
function rowToTask(row) {
|
|
2901
|
+
return {
|
|
2902
|
+
id: String(row.id),
|
|
2903
|
+
status: String(row.status),
|
|
2904
|
+
toolName: String(row.tool_name),
|
|
2905
|
+
toolCallId: String(row.tool_call_id),
|
|
2906
|
+
args: parseJson(row.args) ?? {},
|
|
2907
|
+
agentId: String(row.agent_id),
|
|
2908
|
+
threadId: row.thread_id != null ? String(row.thread_id) : void 0,
|
|
2909
|
+
resourceId: row.resource_id != null ? String(row.resource_id) : void 0,
|
|
2910
|
+
runId: String(row.run_id),
|
|
2911
|
+
result: parseJson(row.result),
|
|
2912
|
+
error: parseJson(row.error),
|
|
2913
|
+
retryCount: Number(row.retry_count),
|
|
2914
|
+
maxRetries: Number(row.max_retries),
|
|
2915
|
+
timeoutMs: Number(row.timeout_ms),
|
|
2916
|
+
createdAt: new Date(String(row.createdAt)),
|
|
2917
|
+
startedAt: row.startedAt ? new Date(String(row.startedAt)) : void 0,
|
|
2918
|
+
completedAt: row.completedAt ? new Date(String(row.completedAt)) : void 0
|
|
2919
|
+
};
|
|
2920
|
+
}
|
|
2921
|
+
var BackgroundTasksLibSQL = class extends BackgroundTasksStorage {
|
|
2922
|
+
#db;
|
|
2923
|
+
#client;
|
|
2924
|
+
constructor(config) {
|
|
2925
|
+
super();
|
|
2926
|
+
const client = resolveClient(config);
|
|
2927
|
+
this.#client = client;
|
|
2928
|
+
this.#db = new LibSQLDB({ client, maxRetries: config.maxRetries, initialBackoffMs: config.initialBackoffMs });
|
|
2929
|
+
}
|
|
2930
|
+
async init() {
|
|
2931
|
+
await this.#db.createTable({
|
|
2932
|
+
tableName: TABLE_BACKGROUND_TASKS,
|
|
2933
|
+
schema: TABLE_SCHEMAS[TABLE_BACKGROUND_TASKS]
|
|
2934
|
+
});
|
|
2935
|
+
}
|
|
2936
|
+
async dangerouslyClearAll() {
|
|
2937
|
+
await this.#db.deleteData({ tableName: TABLE_BACKGROUND_TASKS });
|
|
2938
|
+
}
|
|
2939
|
+
async createTask(task) {
|
|
2940
|
+
await this.#db.insert({
|
|
2941
|
+
tableName: TABLE_BACKGROUND_TASKS,
|
|
2942
|
+
record: {
|
|
2943
|
+
id: task.id,
|
|
2944
|
+
tool_call_id: task.toolCallId,
|
|
2945
|
+
tool_name: task.toolName,
|
|
2946
|
+
agent_id: task.agentId,
|
|
2947
|
+
thread_id: task.threadId ?? null,
|
|
2948
|
+
resource_id: task.resourceId ?? null,
|
|
2949
|
+
run_id: task.runId,
|
|
2950
|
+
status: task.status,
|
|
2951
|
+
args: task.args,
|
|
2952
|
+
result: task.result ?? null,
|
|
2953
|
+
error: task.error ?? null,
|
|
2954
|
+
retry_count: task.retryCount,
|
|
2955
|
+
max_retries: task.maxRetries,
|
|
2956
|
+
timeout_ms: task.timeoutMs,
|
|
2957
|
+
createdAt: task.createdAt.toISOString(),
|
|
2958
|
+
startedAt: task.startedAt?.toISOString() ?? null,
|
|
2959
|
+
completedAt: task.completedAt?.toISOString() ?? null
|
|
2960
|
+
}
|
|
2961
|
+
});
|
|
2962
|
+
}
|
|
2963
|
+
async updateTask(taskId, update) {
|
|
2964
|
+
const setClauses = [];
|
|
2965
|
+
const params = [];
|
|
2966
|
+
if ("status" in update) {
|
|
2967
|
+
setClauses.push("status = ?");
|
|
2968
|
+
params.push(update.status);
|
|
2969
|
+
}
|
|
2970
|
+
if ("result" in update) {
|
|
2971
|
+
setClauses.push("result = jsonb(?)");
|
|
2972
|
+
params.push(serializeJson(update.result));
|
|
2973
|
+
}
|
|
2974
|
+
if ("error" in update) {
|
|
2975
|
+
setClauses.push("error = jsonb(?)");
|
|
2976
|
+
params.push(serializeJson(update.error));
|
|
2977
|
+
}
|
|
2978
|
+
if ("retryCount" in update) {
|
|
2979
|
+
setClauses.push("retry_count = ?");
|
|
2980
|
+
params.push(update.retryCount);
|
|
2981
|
+
}
|
|
2982
|
+
if ("startedAt" in update) {
|
|
2983
|
+
setClauses.push("startedAt = ?");
|
|
2984
|
+
params.push(update.startedAt?.toISOString() ?? null);
|
|
2985
|
+
}
|
|
2986
|
+
if ("completedAt" in update) {
|
|
2987
|
+
setClauses.push("completedAt = ?");
|
|
2988
|
+
params.push(update.completedAt?.toISOString() ?? null);
|
|
2989
|
+
}
|
|
2990
|
+
if (setClauses.length === 0) return;
|
|
2991
|
+
params.push(taskId);
|
|
2992
|
+
await this.#client.execute({
|
|
2993
|
+
sql: `UPDATE ${TABLE_BACKGROUND_TASKS} SET ${setClauses.join(", ")} WHERE id = ?`,
|
|
2994
|
+
args: params
|
|
2995
|
+
});
|
|
2996
|
+
}
|
|
2997
|
+
async getTask(taskId) {
|
|
2998
|
+
const result = await this.#client.execute({
|
|
2999
|
+
sql: `SELECT ${buildSelectColumns(TABLE_BACKGROUND_TASKS)} FROM ${TABLE_BACKGROUND_TASKS} WHERE id = ?`,
|
|
3000
|
+
args: [taskId]
|
|
3001
|
+
});
|
|
3002
|
+
const row = result.rows[0];
|
|
3003
|
+
return row ? rowToTask(row) : null;
|
|
3004
|
+
}
|
|
3005
|
+
async listTasks(filter) {
|
|
3006
|
+
const conditions = [];
|
|
3007
|
+
const params = [];
|
|
3008
|
+
if (filter.status) {
|
|
3009
|
+
const statuses = Array.isArray(filter.status) ? filter.status : [filter.status];
|
|
3010
|
+
conditions.push(`status IN (${statuses.map(() => "?").join(", ")})`);
|
|
3011
|
+
params.push(...statuses);
|
|
3012
|
+
}
|
|
3013
|
+
if (filter.agentId) {
|
|
3014
|
+
conditions.push("agent_id = ?");
|
|
3015
|
+
params.push(filter.agentId);
|
|
3016
|
+
}
|
|
3017
|
+
if (filter.threadId) {
|
|
3018
|
+
conditions.push("thread_id = ?");
|
|
3019
|
+
params.push(filter.threadId);
|
|
3020
|
+
}
|
|
3021
|
+
if (filter.runId) {
|
|
3022
|
+
conditions.push("run_id = ?");
|
|
3023
|
+
params.push(filter.runId);
|
|
3024
|
+
}
|
|
3025
|
+
if (filter.resourceId) {
|
|
3026
|
+
conditions.push("resource_id = ?");
|
|
3027
|
+
params.push(filter.resourceId);
|
|
3028
|
+
}
|
|
3029
|
+
if (filter.toolName) {
|
|
3030
|
+
conditions.push("tool_name = ?");
|
|
3031
|
+
params.push(filter.toolName);
|
|
3032
|
+
}
|
|
3033
|
+
const dateCol = filter.dateFilterBy === "startedAt" ? "startedAt" : filter.dateFilterBy === "completedAt" ? "completedAt" : "createdAt";
|
|
3034
|
+
if (filter.fromDate) {
|
|
3035
|
+
conditions.push(`${dateCol} >= ?`);
|
|
3036
|
+
params.push(filter.fromDate.toISOString());
|
|
3037
|
+
}
|
|
3038
|
+
if (filter.toDate) {
|
|
3039
|
+
conditions.push(`${dateCol} < ?`);
|
|
3040
|
+
params.push(filter.toDate.toISOString());
|
|
3041
|
+
}
|
|
3042
|
+
const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
3043
|
+
const countResult = await this.#client.execute({
|
|
3044
|
+
sql: `SELECT COUNT(*) as count FROM ${TABLE_BACKGROUND_TASKS} ${where}`,
|
|
3045
|
+
args: [...params]
|
|
3046
|
+
});
|
|
3047
|
+
const total = Number(countResult.rows[0]?.count ?? 0);
|
|
3048
|
+
const orderCol = filter.orderBy === "startedAt" ? "startedAt" : filter.orderBy === "completedAt" ? "completedAt" : "createdAt";
|
|
3049
|
+
const direction = filter.orderDirection === "desc" ? "DESC" : "ASC";
|
|
3050
|
+
let sql = `SELECT ${buildSelectColumns(TABLE_BACKGROUND_TASKS)} FROM ${TABLE_BACKGROUND_TASKS} ${where} ORDER BY ${orderCol} ${direction}`;
|
|
3051
|
+
if (filter.perPage != null) {
|
|
3052
|
+
sql += " LIMIT ?";
|
|
3053
|
+
params.push(filter.perPage);
|
|
3054
|
+
if (filter.page != null) {
|
|
3055
|
+
sql += " OFFSET ?";
|
|
3056
|
+
params.push(filter.page * filter.perPage);
|
|
3057
|
+
}
|
|
3058
|
+
}
|
|
3059
|
+
const result = await this.#client.execute({ sql, args: params });
|
|
3060
|
+
return { tasks: result.rows.map((row) => rowToTask(row)), total };
|
|
3061
|
+
}
|
|
3062
|
+
async deleteTask(taskId) {
|
|
3063
|
+
await this.#client.execute({
|
|
3064
|
+
sql: `DELETE FROM ${TABLE_BACKGROUND_TASKS} WHERE id = ?`,
|
|
3065
|
+
args: [taskId]
|
|
3066
|
+
});
|
|
3067
|
+
}
|
|
3068
|
+
async deleteTasks(filter) {
|
|
3069
|
+
const conditions = [];
|
|
3070
|
+
const params = [];
|
|
3071
|
+
if (filter.status) {
|
|
3072
|
+
const statuses = Array.isArray(filter.status) ? filter.status : [filter.status];
|
|
3073
|
+
conditions.push(`status IN (${statuses.map(() => "?").join(", ")})`);
|
|
3074
|
+
params.push(...statuses);
|
|
3075
|
+
}
|
|
3076
|
+
const dateCol = filter.dateFilterBy === "startedAt" ? "startedAt" : filter.dateFilterBy === "completedAt" ? "completedAt" : "createdAt";
|
|
3077
|
+
if (filter.fromDate) {
|
|
3078
|
+
conditions.push(`${dateCol} >= ?`);
|
|
3079
|
+
params.push(filter.fromDate.toISOString());
|
|
3080
|
+
}
|
|
3081
|
+
if (filter.toDate) {
|
|
3082
|
+
conditions.push(`${dateCol} < ?`);
|
|
3083
|
+
params.push(filter.toDate.toISOString());
|
|
3084
|
+
}
|
|
3085
|
+
if (filter.agentId) {
|
|
3086
|
+
conditions.push("agent_id = ?");
|
|
3087
|
+
params.push(filter.agentId);
|
|
3088
|
+
}
|
|
3089
|
+
if (filter.runId) {
|
|
3090
|
+
conditions.push("run_id = ?");
|
|
3091
|
+
params.push(filter.runId);
|
|
3092
|
+
}
|
|
3093
|
+
if (conditions.length === 0) return;
|
|
3094
|
+
await this.#client.execute({
|
|
3095
|
+
sql: `DELETE FROM ${TABLE_BACKGROUND_TASKS} WHERE ${conditions.join(" AND ")}`,
|
|
3096
|
+
args: params
|
|
3097
|
+
});
|
|
3098
|
+
}
|
|
3099
|
+
async getRunningCount() {
|
|
3100
|
+
const result = await this.#client.execute({
|
|
3101
|
+
sql: `SELECT COUNT(*) as count FROM ${TABLE_BACKGROUND_TASKS} WHERE status = 'running'`,
|
|
3102
|
+
args: []
|
|
3103
|
+
});
|
|
3104
|
+
return Number(result.rows[0]?.count ?? 0);
|
|
3105
|
+
}
|
|
3106
|
+
async getRunningCountByAgent(agentId) {
|
|
3107
|
+
const result = await this.#client.execute({
|
|
3108
|
+
sql: `SELECT COUNT(*) as count FROM ${TABLE_BACKGROUND_TASKS} WHERE status = 'running' AND agent_id = ?`,
|
|
3109
|
+
args: [agentId]
|
|
3110
|
+
});
|
|
3111
|
+
return Number(result.rows[0]?.count ?? 0);
|
|
3112
|
+
}
|
|
3113
|
+
};
|
|
2885
3114
|
var BlobsLibSQL = class extends BlobStore {
|
|
2886
3115
|
#db;
|
|
2887
3116
|
#client;
|
|
@@ -10637,6 +10866,7 @@ var LibSQLStore = class extends MastraCompositeStore {
|
|
|
10637
10866
|
const workspaces = new WorkspacesLibSQL(domainConfig);
|
|
10638
10867
|
const skills = new SkillsLibSQL(domainConfig);
|
|
10639
10868
|
const blobs = new BlobsLibSQL(domainConfig);
|
|
10869
|
+
const backgroundTasks = new BackgroundTasksLibSQL(domainConfig);
|
|
10640
10870
|
this.stores = {
|
|
10641
10871
|
scores,
|
|
10642
10872
|
workflows,
|
|
@@ -10651,7 +10881,8 @@ var LibSQLStore = class extends MastraCompositeStore {
|
|
|
10651
10881
|
mcpServers,
|
|
10652
10882
|
workspaces,
|
|
10653
10883
|
skills,
|
|
10654
|
-
blobs
|
|
10884
|
+
blobs,
|
|
10885
|
+
backgroundTasks
|
|
10655
10886
|
};
|
|
10656
10887
|
}
|
|
10657
10888
|
};
|
|
@@ -10755,6 +10986,6 @@ Example Complex Query:
|
|
|
10755
10986
|
]
|
|
10756
10987
|
}`;
|
|
10757
10988
|
|
|
10758
|
-
export { AgentsLibSQL, BlobsLibSQL, DatasetsLibSQL, LibSQLStore as DefaultStorage, ExperimentsLibSQL, LIBSQL_PROMPT, LibSQLStore, LibSQLVector, MCPClientsLibSQL, MCPServersLibSQL, MemoryLibSQL, ObservabilityLibSQL, PromptBlocksLibSQL, ScorerDefinitionsLibSQL, ScoresLibSQL, SkillsLibSQL, WorkflowsLibSQL, WorkspacesLibSQL };
|
|
10989
|
+
export { AgentsLibSQL, BackgroundTasksLibSQL, BlobsLibSQL, DatasetsLibSQL, LibSQLStore as DefaultStorage, ExperimentsLibSQL, LIBSQL_PROMPT, LibSQLStore, LibSQLVector, MCPClientsLibSQL, MCPServersLibSQL, MemoryLibSQL, ObservabilityLibSQL, PromptBlocksLibSQL, ScorerDefinitionsLibSQL, ScoresLibSQL, SkillsLibSQL, WorkflowsLibSQL, WorkspacesLibSQL };
|
|
10759
10990
|
//# sourceMappingURL=index.js.map
|
|
10760
10991
|
//# sourceMappingURL=index.js.map
|