@mastra/libsql 1.9.1-alpha.0 → 1.10.0-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 +231 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +232 -3
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/schedules/index.d.ts +19 -0
- package/dist/storage/domains/schedules/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, BackgroundTasksStorage, TABLE_SCHEMAS, TABLE_BACKGROUND_TASKS, BlobStore, TABLE_SKILL_BLOBS, SKILL_BLOBS_SCHEMA, ChannelsStorage, TABLE_CHANNEL_INSTALLATIONS, TABLE_CHANNEL_CONFIG, 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';
|
|
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, ChannelsStorage, TABLE_CHANNEL_INSTALLATIONS, TABLE_CHANNEL_CONFIG, 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, SchedulesStorage, TABLE_SCHEDULES, TABLE_SCHEDULE_TRIGGERS, 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';
|
|
@@ -8894,6 +8894,233 @@ var PromptBlocksLibSQL = class extends PromptBlocksStorage {
|
|
|
8894
8894
|
};
|
|
8895
8895
|
}
|
|
8896
8896
|
};
|
|
8897
|
+
function parseJson2(val) {
|
|
8898
|
+
if (val == null) return void 0;
|
|
8899
|
+
if (typeof val === "string") {
|
|
8900
|
+
try {
|
|
8901
|
+
return JSON.parse(val);
|
|
8902
|
+
} catch {
|
|
8903
|
+
return val;
|
|
8904
|
+
}
|
|
8905
|
+
}
|
|
8906
|
+
return val;
|
|
8907
|
+
}
|
|
8908
|
+
function toNumber(val) {
|
|
8909
|
+
if (typeof val === "bigint") return Number(val);
|
|
8910
|
+
return Number(val);
|
|
8911
|
+
}
|
|
8912
|
+
function rowToSchedule(row) {
|
|
8913
|
+
const target = parseJson2(row.target);
|
|
8914
|
+
if (!target) {
|
|
8915
|
+
throw new Error(`Schedule row ${row.id} has invalid target`);
|
|
8916
|
+
}
|
|
8917
|
+
const schedule = {
|
|
8918
|
+
id: String(row.id),
|
|
8919
|
+
target,
|
|
8920
|
+
cron: String(row.cron),
|
|
8921
|
+
status: String(row.status),
|
|
8922
|
+
nextFireAt: toNumber(row.next_fire_at),
|
|
8923
|
+
createdAt: toNumber(row.created_at),
|
|
8924
|
+
updatedAt: toNumber(row.updated_at)
|
|
8925
|
+
};
|
|
8926
|
+
if (row.timezone != null) schedule.timezone = String(row.timezone);
|
|
8927
|
+
if (row.last_fire_at != null) schedule.lastFireAt = toNumber(row.last_fire_at);
|
|
8928
|
+
if (row.last_run_id != null) schedule.lastRunId = String(row.last_run_id);
|
|
8929
|
+
const metadata = parseJson2(row.metadata);
|
|
8930
|
+
if (metadata !== void 0) schedule.metadata = metadata;
|
|
8931
|
+
return schedule;
|
|
8932
|
+
}
|
|
8933
|
+
function rowToTrigger(row) {
|
|
8934
|
+
const trigger = {
|
|
8935
|
+
scheduleId: String(row.schedule_id),
|
|
8936
|
+
runId: String(row.run_id),
|
|
8937
|
+
scheduledFireAt: toNumber(row.scheduled_fire_at),
|
|
8938
|
+
actualFireAt: toNumber(row.actual_fire_at),
|
|
8939
|
+
status: String(row.status)
|
|
8940
|
+
};
|
|
8941
|
+
if (row.error != null) trigger.error = String(row.error);
|
|
8942
|
+
return trigger;
|
|
8943
|
+
}
|
|
8944
|
+
var SchedulesLibSQL = class extends SchedulesStorage {
|
|
8945
|
+
#db;
|
|
8946
|
+
#client;
|
|
8947
|
+
constructor(config) {
|
|
8948
|
+
super();
|
|
8949
|
+
const client = resolveClient(config);
|
|
8950
|
+
this.#client = client;
|
|
8951
|
+
this.#db = new LibSQLDB({ client, maxRetries: config.maxRetries, initialBackoffMs: config.initialBackoffMs });
|
|
8952
|
+
}
|
|
8953
|
+
async init() {
|
|
8954
|
+
await this.#db.createTable({
|
|
8955
|
+
tableName: TABLE_SCHEDULES,
|
|
8956
|
+
schema: TABLE_SCHEMAS[TABLE_SCHEDULES]
|
|
8957
|
+
});
|
|
8958
|
+
await this.#db.createTable({
|
|
8959
|
+
tableName: TABLE_SCHEDULE_TRIGGERS,
|
|
8960
|
+
schema: TABLE_SCHEMAS[TABLE_SCHEDULE_TRIGGERS]
|
|
8961
|
+
});
|
|
8962
|
+
}
|
|
8963
|
+
async dangerouslyClearAll() {
|
|
8964
|
+
await this.#db.deleteData({ tableName: TABLE_SCHEDULE_TRIGGERS });
|
|
8965
|
+
await this.#db.deleteData({ tableName: TABLE_SCHEDULES });
|
|
8966
|
+
}
|
|
8967
|
+
async createSchedule(schedule) {
|
|
8968
|
+
const existing = await this.getSchedule(schedule.id);
|
|
8969
|
+
if (existing) {
|
|
8970
|
+
throw new Error(`Schedule with id "${schedule.id}" already exists`);
|
|
8971
|
+
}
|
|
8972
|
+
await this.#db.insert({
|
|
8973
|
+
tableName: TABLE_SCHEDULES,
|
|
8974
|
+
record: {
|
|
8975
|
+
id: schedule.id,
|
|
8976
|
+
target: schedule.target,
|
|
8977
|
+
cron: schedule.cron,
|
|
8978
|
+
timezone: schedule.timezone ?? null,
|
|
8979
|
+
status: schedule.status,
|
|
8980
|
+
next_fire_at: schedule.nextFireAt,
|
|
8981
|
+
last_fire_at: schedule.lastFireAt ?? null,
|
|
8982
|
+
last_run_id: schedule.lastRunId ?? null,
|
|
8983
|
+
created_at: schedule.createdAt,
|
|
8984
|
+
updated_at: schedule.updatedAt,
|
|
8985
|
+
metadata: schedule.metadata ?? null
|
|
8986
|
+
}
|
|
8987
|
+
});
|
|
8988
|
+
return schedule;
|
|
8989
|
+
}
|
|
8990
|
+
async getSchedule(id) {
|
|
8991
|
+
const result = await this.#client.execute({
|
|
8992
|
+
sql: `SELECT ${buildSelectColumns(TABLE_SCHEDULES)} FROM ${TABLE_SCHEDULES} WHERE id = ?`,
|
|
8993
|
+
args: [id]
|
|
8994
|
+
});
|
|
8995
|
+
const row = result.rows[0];
|
|
8996
|
+
return row ? rowToSchedule(row) : null;
|
|
8997
|
+
}
|
|
8998
|
+
async listSchedules(filter) {
|
|
8999
|
+
const conditions = [];
|
|
9000
|
+
const params = [];
|
|
9001
|
+
if (filter?.status) {
|
|
9002
|
+
conditions.push("status = ?");
|
|
9003
|
+
params.push(filter.status);
|
|
9004
|
+
}
|
|
9005
|
+
if (filter?.workflowId) {
|
|
9006
|
+
conditions.push("json_extract(target, '$.workflowId') = ?");
|
|
9007
|
+
params.push(filter.workflowId);
|
|
9008
|
+
}
|
|
9009
|
+
const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
9010
|
+
const result = await this.#client.execute({
|
|
9011
|
+
sql: `SELECT ${buildSelectColumns(TABLE_SCHEDULES)} FROM ${TABLE_SCHEDULES} ${where} ORDER BY created_at ASC`,
|
|
9012
|
+
args: params
|
|
9013
|
+
});
|
|
9014
|
+
return result.rows.map((r) => rowToSchedule(r));
|
|
9015
|
+
}
|
|
9016
|
+
async listDueSchedules(now, limit) {
|
|
9017
|
+
const cap = limit ?? 100;
|
|
9018
|
+
const result = await this.#client.execute({
|
|
9019
|
+
sql: `SELECT ${buildSelectColumns(TABLE_SCHEDULES)} FROM ${TABLE_SCHEDULES}
|
|
9020
|
+
WHERE status = ? AND next_fire_at <= ?
|
|
9021
|
+
ORDER BY next_fire_at ASC
|
|
9022
|
+
LIMIT ?`,
|
|
9023
|
+
args: ["active", now, cap]
|
|
9024
|
+
});
|
|
9025
|
+
return result.rows.map((r) => rowToSchedule(r));
|
|
9026
|
+
}
|
|
9027
|
+
async updateSchedule(id, patch) {
|
|
9028
|
+
const setClauses = [];
|
|
9029
|
+
const params = [];
|
|
9030
|
+
if ("cron" in patch && patch.cron !== void 0) {
|
|
9031
|
+
setClauses.push("cron = ?");
|
|
9032
|
+
params.push(patch.cron);
|
|
9033
|
+
}
|
|
9034
|
+
if ("timezone" in patch) {
|
|
9035
|
+
setClauses.push("timezone = ?");
|
|
9036
|
+
params.push(patch.timezone ?? null);
|
|
9037
|
+
}
|
|
9038
|
+
if ("status" in patch && patch.status !== void 0) {
|
|
9039
|
+
setClauses.push("status = ?");
|
|
9040
|
+
params.push(patch.status);
|
|
9041
|
+
}
|
|
9042
|
+
if ("nextFireAt" in patch && patch.nextFireAt !== void 0) {
|
|
9043
|
+
setClauses.push("next_fire_at = ?");
|
|
9044
|
+
params.push(patch.nextFireAt);
|
|
9045
|
+
}
|
|
9046
|
+
if ("target" in patch && patch.target !== void 0) {
|
|
9047
|
+
setClauses.push("target = jsonb(?)");
|
|
9048
|
+
params.push(JSON.stringify(patch.target));
|
|
9049
|
+
}
|
|
9050
|
+
if ("metadata" in patch) {
|
|
9051
|
+
setClauses.push("metadata = jsonb(?)");
|
|
9052
|
+
params.push(patch.metadata != null ? JSON.stringify(patch.metadata) : null);
|
|
9053
|
+
}
|
|
9054
|
+
setClauses.push("updated_at = ?");
|
|
9055
|
+
params.push(Date.now());
|
|
9056
|
+
params.push(id);
|
|
9057
|
+
if (setClauses.length === 1) {
|
|
9058
|
+
const existing = await this.getSchedule(id);
|
|
9059
|
+
if (!existing) throw new Error(`Schedule ${id} not found`);
|
|
9060
|
+
return existing;
|
|
9061
|
+
}
|
|
9062
|
+
await this.#client.execute({
|
|
9063
|
+
sql: `UPDATE ${TABLE_SCHEDULES} SET ${setClauses.join(", ")} WHERE id = ?`,
|
|
9064
|
+
args: params
|
|
9065
|
+
});
|
|
9066
|
+
const updated = await this.getSchedule(id);
|
|
9067
|
+
if (!updated) throw new Error(`Schedule ${id} not found`);
|
|
9068
|
+
return updated;
|
|
9069
|
+
}
|
|
9070
|
+
async updateScheduleNextFire(id, expectedNextFireAt, newNextFireAt, lastFireAt, lastRunId) {
|
|
9071
|
+
const result = await this.#client.execute({
|
|
9072
|
+
sql: `UPDATE ${TABLE_SCHEDULES}
|
|
9073
|
+
SET next_fire_at = ?, last_fire_at = ?, last_run_id = ?, updated_at = ?
|
|
9074
|
+
WHERE id = ? AND next_fire_at = ? AND status = ?`,
|
|
9075
|
+
args: [newNextFireAt, lastFireAt, lastRunId, Date.now(), id, expectedNextFireAt, "active"]
|
|
9076
|
+
});
|
|
9077
|
+
return (result.rowsAffected ?? 0) > 0;
|
|
9078
|
+
}
|
|
9079
|
+
async deleteSchedule(id) {
|
|
9080
|
+
await this.#client.execute({
|
|
9081
|
+
sql: `DELETE FROM ${TABLE_SCHEDULE_TRIGGERS} WHERE schedule_id = ?`,
|
|
9082
|
+
args: [id]
|
|
9083
|
+
});
|
|
9084
|
+
await this.#client.execute({
|
|
9085
|
+
sql: `DELETE FROM ${TABLE_SCHEDULES} WHERE id = ?`,
|
|
9086
|
+
args: [id]
|
|
9087
|
+
});
|
|
9088
|
+
}
|
|
9089
|
+
async recordTrigger(trigger) {
|
|
9090
|
+
await this.#db.insert({
|
|
9091
|
+
tableName: TABLE_SCHEDULE_TRIGGERS,
|
|
9092
|
+
record: {
|
|
9093
|
+
schedule_id: trigger.scheduleId,
|
|
9094
|
+
run_id: trigger.runId,
|
|
9095
|
+
scheduled_fire_at: trigger.scheduledFireAt,
|
|
9096
|
+
actual_fire_at: trigger.actualFireAt,
|
|
9097
|
+
status: trigger.status,
|
|
9098
|
+
error: trigger.error ?? null
|
|
9099
|
+
}
|
|
9100
|
+
});
|
|
9101
|
+
}
|
|
9102
|
+
async listTriggers(scheduleId, opts) {
|
|
9103
|
+
const conditions = ["schedule_id = ?"];
|
|
9104
|
+
const params = [scheduleId];
|
|
9105
|
+
if (opts?.fromActualFireAt != null) {
|
|
9106
|
+
conditions.push("actual_fire_at >= ?");
|
|
9107
|
+
params.push(opts.fromActualFireAt);
|
|
9108
|
+
}
|
|
9109
|
+
if (opts?.toActualFireAt != null) {
|
|
9110
|
+
conditions.push("actual_fire_at < ?");
|
|
9111
|
+
params.push(opts.toActualFireAt);
|
|
9112
|
+
}
|
|
9113
|
+
const limitClause = opts?.limit != null ? `LIMIT ${Math.floor(opts.limit)}` : "";
|
|
9114
|
+
const result = await this.#client.execute({
|
|
9115
|
+
sql: `SELECT ${buildSelectColumns(TABLE_SCHEDULE_TRIGGERS)} FROM ${TABLE_SCHEDULE_TRIGGERS}
|
|
9116
|
+
WHERE ${conditions.join(" AND ")}
|
|
9117
|
+
ORDER BY actual_fire_at DESC
|
|
9118
|
+
${limitClause}`,
|
|
9119
|
+
args: params
|
|
9120
|
+
});
|
|
9121
|
+
return result.rows.map((r) => rowToTrigger(r));
|
|
9122
|
+
}
|
|
9123
|
+
};
|
|
8897
9124
|
var ScorerDefinitionsLibSQL = class extends ScorerDefinitionsStorage {
|
|
8898
9125
|
#db;
|
|
8899
9126
|
#client;
|
|
@@ -11125,6 +11352,7 @@ var LibSQLStore = class extends MastraCompositeStore {
|
|
|
11125
11352
|
const skills = new SkillsLibSQL(domainConfig);
|
|
11126
11353
|
const blobs = new BlobsLibSQL(domainConfig);
|
|
11127
11354
|
const backgroundTasks = new BackgroundTasksLibSQL(domainConfig);
|
|
11355
|
+
const schedules = new SchedulesLibSQL(domainConfig);
|
|
11128
11356
|
this.stores = {
|
|
11129
11357
|
scores,
|
|
11130
11358
|
workflows,
|
|
@@ -11141,7 +11369,8 @@ var LibSQLStore = class extends MastraCompositeStore {
|
|
|
11141
11369
|
workspaces,
|
|
11142
11370
|
skills,
|
|
11143
11371
|
blobs,
|
|
11144
|
-
backgroundTasks
|
|
11372
|
+
backgroundTasks,
|
|
11373
|
+
schedules
|
|
11145
11374
|
};
|
|
11146
11375
|
}
|
|
11147
11376
|
};
|
|
@@ -11245,6 +11474,6 @@ Example Complex Query:
|
|
|
11245
11474
|
]
|
|
11246
11475
|
}`;
|
|
11247
11476
|
|
|
11248
|
-
export { AgentsLibSQL, BackgroundTasksLibSQL, BlobsLibSQL, ChannelsLibSQL, DatasetsLibSQL, LibSQLStore as DefaultStorage, ExperimentsLibSQL, LIBSQL_PROMPT, LibSQLStore, LibSQLVector, MCPClientsLibSQL, MCPServersLibSQL, MemoryLibSQL, ObservabilityLibSQL, PromptBlocksLibSQL, ScorerDefinitionsLibSQL, ScoresLibSQL, SkillsLibSQL, WorkflowsLibSQL, WorkspacesLibSQL };
|
|
11477
|
+
export { AgentsLibSQL, BackgroundTasksLibSQL, BlobsLibSQL, ChannelsLibSQL, DatasetsLibSQL, LibSQLStore as DefaultStorage, ExperimentsLibSQL, LIBSQL_PROMPT, LibSQLStore, LibSQLVector, MCPClientsLibSQL, MCPServersLibSQL, MemoryLibSQL, ObservabilityLibSQL, PromptBlocksLibSQL, SchedulesLibSQL, ScorerDefinitionsLibSQL, ScoresLibSQL, SkillsLibSQL, WorkflowsLibSQL, WorkspacesLibSQL };
|
|
11249
11478
|
//# sourceMappingURL=index.js.map
|
|
11250
11479
|
//# sourceMappingURL=index.js.map
|