@mastra/libsql 1.8.1 → 1.9.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 +22 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +308 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +309 -4
- 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/dist/vector/index.d.ts +14 -1
- package/dist/vector/index.d.ts.map +1 -1
- package/package.json +3 -3
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';
|
|
@@ -509,6 +509,9 @@ var LibSQLVector = class extends MastraVector {
|
|
|
509
509
|
turso;
|
|
510
510
|
maxRetries;
|
|
511
511
|
initialBackoffMs;
|
|
512
|
+
overFetchMultiplier;
|
|
513
|
+
isMemoryDb;
|
|
514
|
+
vectorIndexes;
|
|
512
515
|
constructor({
|
|
513
516
|
url,
|
|
514
517
|
authToken,
|
|
@@ -516,6 +519,7 @@ var LibSQLVector = class extends MastraVector {
|
|
|
516
519
|
syncInterval,
|
|
517
520
|
maxRetries = 5,
|
|
518
521
|
initialBackoffMs = 100,
|
|
522
|
+
vectorTopKOverFetchMultiplier = 10,
|
|
519
523
|
id
|
|
520
524
|
}) {
|
|
521
525
|
super({ id });
|
|
@@ -527,10 +531,27 @@ var LibSQLVector = class extends MastraVector {
|
|
|
527
531
|
});
|
|
528
532
|
this.maxRetries = maxRetries;
|
|
529
533
|
this.initialBackoffMs = initialBackoffMs;
|
|
530
|
-
if (
|
|
534
|
+
if (!Number.isInteger(vectorTopKOverFetchMultiplier) || vectorTopKOverFetchMultiplier < 1) {
|
|
535
|
+
throw new Error("vectorTopKOverFetchMultiplier must be a positive integer");
|
|
536
|
+
}
|
|
537
|
+
this.overFetchMultiplier = vectorTopKOverFetchMultiplier;
|
|
538
|
+
this.isMemoryDb = url.includes(":memory:");
|
|
539
|
+
if (url.includes(`file:`) || this.isMemoryDb) {
|
|
531
540
|
this.turso.execute("PRAGMA journal_mode=WAL;").then(() => this.logger.debug("LibSQLStore: PRAGMA journal_mode=WAL set.")).catch((err) => this.logger.warn("LibSQLStore: Failed to set PRAGMA journal_mode=WAL.", err));
|
|
532
541
|
this.turso.execute("PRAGMA busy_timeout = 5000;").then(() => this.logger.debug("LibSQLStore: PRAGMA busy_timeout=5000 set.")).catch((err) => this.logger.warn("LibSQLStore: Failed to set PRAGMA busy_timeout=5000.", err));
|
|
533
542
|
}
|
|
543
|
+
this.vectorIndexes = this.isMemoryDb ? Promise.resolve(/* @__PURE__ */ new Set()) : this.discoverVectorIndexes();
|
|
544
|
+
}
|
|
545
|
+
async discoverVectorIndexes() {
|
|
546
|
+
try {
|
|
547
|
+
const result = await this.turso.execute({
|
|
548
|
+
sql: `SELECT name FROM sqlite_master WHERE type='index' AND name LIKE '%_vector_idx'`,
|
|
549
|
+
args: []
|
|
550
|
+
});
|
|
551
|
+
return new Set(result.rows.map((row) => row.name));
|
|
552
|
+
} catch {
|
|
553
|
+
return /* @__PURE__ */ new Set();
|
|
554
|
+
}
|
|
534
555
|
}
|
|
535
556
|
async executeWriteOperationWithRetry(operation, isTransaction = false) {
|
|
536
557
|
let attempts = 0;
|
|
@@ -564,6 +585,40 @@ var LibSQLVector = class extends MastraVector {
|
|
|
564
585
|
const translator = new LibSQLFilterTranslator();
|
|
565
586
|
return translator.translate(filter);
|
|
566
587
|
}
|
|
588
|
+
async hasVectorIndex(parsedIndexName) {
|
|
589
|
+
const indexes = await this.vectorIndexes;
|
|
590
|
+
return indexes.has(`${parsedIndexName}_vector_idx`);
|
|
591
|
+
}
|
|
592
|
+
async queryWithIndex(parsedIndexName, vectorStr, topK, filter, includeVector, minScore) {
|
|
593
|
+
const translatedFilter = this.transformFilter(filter);
|
|
594
|
+
const { sql: filterQuery, values: filterValues } = buildFilterQuery(translatedFilter);
|
|
595
|
+
const hasFilter = filterQuery.length > 0;
|
|
596
|
+
const fetchCount = hasFilter ? topK * this.overFetchMultiplier : topK * 2;
|
|
597
|
+
const embeddingSelect = includeVector ? ", vector_extract(t.embedding) as embedding" : "";
|
|
598
|
+
const filterCondition = hasFilter ? filterQuery.replace(/^\s*WHERE\s+/i, "") : "";
|
|
599
|
+
const whereClause = hasFilter ? `WHERE ${filterCondition} AND score > ?` : "WHERE score > ?";
|
|
600
|
+
const query = `
|
|
601
|
+
WITH candidates AS (
|
|
602
|
+
SELECT t.vector_id AS id,
|
|
603
|
+
(1 - vector_distance_cos(t.embedding, vector32(?))) AS score,
|
|
604
|
+
t.metadata
|
|
605
|
+
${embeddingSelect}
|
|
606
|
+
FROM vector_top_k('${parsedIndexName}_vector_idx', vector32(?), ?) AS v
|
|
607
|
+
JOIN "${parsedIndexName}" AS t ON t.rowid = v.id
|
|
608
|
+
)
|
|
609
|
+
SELECT * FROM candidates
|
|
610
|
+
${whereClause}
|
|
611
|
+
ORDER BY score DESC
|
|
612
|
+
LIMIT ?`;
|
|
613
|
+
const args = [vectorStr, vectorStr, fetchCount, ...filterValues, minScore, topK];
|
|
614
|
+
const result = await this.turso.execute({ sql: query, args });
|
|
615
|
+
return result.rows.map(({ id, score, metadata, embedding }) => ({
|
|
616
|
+
id,
|
|
617
|
+
score,
|
|
618
|
+
metadata: JSON.parse(metadata ?? "{}"),
|
|
619
|
+
...includeVector && embedding && { vector: JSON.parse(embedding) }
|
|
620
|
+
}));
|
|
621
|
+
}
|
|
567
622
|
async query({
|
|
568
623
|
indexName,
|
|
569
624
|
queryVector,
|
|
@@ -594,6 +649,23 @@ var LibSQLVector = class extends MastraVector {
|
|
|
594
649
|
try {
|
|
595
650
|
const parsedIndexName = parseSqlIdentifier(indexName, "index name");
|
|
596
651
|
const vectorStr = `[${queryVector.join(",")}]`;
|
|
652
|
+
if (!this.isMemoryDb && await this.hasVectorIndex(parsedIndexName)) {
|
|
653
|
+
try {
|
|
654
|
+
const indexedResults = await this.queryWithIndex(
|
|
655
|
+
parsedIndexName,
|
|
656
|
+
vectorStr,
|
|
657
|
+
topK,
|
|
658
|
+
filter,
|
|
659
|
+
includeVector,
|
|
660
|
+
minScore
|
|
661
|
+
);
|
|
662
|
+
if (!filter || indexedResults.length >= topK) {
|
|
663
|
+
return indexedResults;
|
|
664
|
+
}
|
|
665
|
+
} catch (err) {
|
|
666
|
+
this.logger.warn("LibSQLVector: indexed query failed, falling back to brute-force", err);
|
|
667
|
+
}
|
|
668
|
+
}
|
|
597
669
|
const translatedFilter = this.transformFilter(filter);
|
|
598
670
|
const { sql: filterQuery, values: filterValues } = buildFilterQuery(translatedFilter);
|
|
599
671
|
filterValues.push(minScore);
|
|
@@ -727,6 +799,7 @@ var LibSQLVector = class extends MastraVector {
|
|
|
727
799
|
`,
|
|
728
800
|
args: []
|
|
729
801
|
});
|
|
802
|
+
void this.vectorIndexes.then((indexes) => indexes.add(`${parsedIndexName}_vector_idx`));
|
|
730
803
|
}
|
|
731
804
|
deleteIndex(args) {
|
|
732
805
|
try {
|
|
@@ -749,6 +822,7 @@ var LibSQLVector = class extends MastraVector {
|
|
|
749
822
|
sql: `DROP TABLE IF EXISTS ${parsedIndexName}`,
|
|
750
823
|
args: []
|
|
751
824
|
});
|
|
825
|
+
void this.vectorIndexes.then((indexes) => indexes.delete(`${parsedIndexName}_vector_idx`));
|
|
752
826
|
}
|
|
753
827
|
async listIndexes() {
|
|
754
828
|
try {
|
|
@@ -2882,6 +2956,235 @@ var AgentsLibSQL = class extends AgentsStorage {
|
|
|
2882
2956
|
};
|
|
2883
2957
|
}
|
|
2884
2958
|
};
|
|
2959
|
+
function serializeJson(v) {
|
|
2960
|
+
if (typeof v === "object" && v != null) return JSON.stringify(v);
|
|
2961
|
+
return v ?? null;
|
|
2962
|
+
}
|
|
2963
|
+
function parseJson(val) {
|
|
2964
|
+
if (val == null) return void 0;
|
|
2965
|
+
if (typeof val === "string") {
|
|
2966
|
+
try {
|
|
2967
|
+
return JSON.parse(val);
|
|
2968
|
+
} catch {
|
|
2969
|
+
return val;
|
|
2970
|
+
}
|
|
2971
|
+
}
|
|
2972
|
+
return val;
|
|
2973
|
+
}
|
|
2974
|
+
function rowToTask(row) {
|
|
2975
|
+
return {
|
|
2976
|
+
id: String(row.id),
|
|
2977
|
+
status: String(row.status),
|
|
2978
|
+
toolName: String(row.tool_name),
|
|
2979
|
+
toolCallId: String(row.tool_call_id),
|
|
2980
|
+
args: parseJson(row.args) ?? {},
|
|
2981
|
+
agentId: String(row.agent_id),
|
|
2982
|
+
threadId: row.thread_id != null ? String(row.thread_id) : void 0,
|
|
2983
|
+
resourceId: row.resource_id != null ? String(row.resource_id) : void 0,
|
|
2984
|
+
runId: String(row.run_id),
|
|
2985
|
+
result: parseJson(row.result),
|
|
2986
|
+
error: parseJson(row.error),
|
|
2987
|
+
retryCount: Number(row.retry_count),
|
|
2988
|
+
maxRetries: Number(row.max_retries),
|
|
2989
|
+
timeoutMs: Number(row.timeout_ms),
|
|
2990
|
+
createdAt: new Date(String(row.createdAt)),
|
|
2991
|
+
startedAt: row.startedAt ? new Date(String(row.startedAt)) : void 0,
|
|
2992
|
+
completedAt: row.completedAt ? new Date(String(row.completedAt)) : void 0
|
|
2993
|
+
};
|
|
2994
|
+
}
|
|
2995
|
+
var BackgroundTasksLibSQL = class extends BackgroundTasksStorage {
|
|
2996
|
+
#db;
|
|
2997
|
+
#client;
|
|
2998
|
+
constructor(config) {
|
|
2999
|
+
super();
|
|
3000
|
+
const client = resolveClient(config);
|
|
3001
|
+
this.#client = client;
|
|
3002
|
+
this.#db = new LibSQLDB({ client, maxRetries: config.maxRetries, initialBackoffMs: config.initialBackoffMs });
|
|
3003
|
+
}
|
|
3004
|
+
async init() {
|
|
3005
|
+
await this.#db.createTable({
|
|
3006
|
+
tableName: TABLE_BACKGROUND_TASKS,
|
|
3007
|
+
schema: TABLE_SCHEMAS[TABLE_BACKGROUND_TASKS]
|
|
3008
|
+
});
|
|
3009
|
+
}
|
|
3010
|
+
async dangerouslyClearAll() {
|
|
3011
|
+
await this.#db.deleteData({ tableName: TABLE_BACKGROUND_TASKS });
|
|
3012
|
+
}
|
|
3013
|
+
async createTask(task) {
|
|
3014
|
+
await this.#db.insert({
|
|
3015
|
+
tableName: TABLE_BACKGROUND_TASKS,
|
|
3016
|
+
record: {
|
|
3017
|
+
id: task.id,
|
|
3018
|
+
tool_call_id: task.toolCallId,
|
|
3019
|
+
tool_name: task.toolName,
|
|
3020
|
+
agent_id: task.agentId,
|
|
3021
|
+
thread_id: task.threadId ?? null,
|
|
3022
|
+
resource_id: task.resourceId ?? null,
|
|
3023
|
+
run_id: task.runId,
|
|
3024
|
+
status: task.status,
|
|
3025
|
+
args: task.args,
|
|
3026
|
+
result: task.result ?? null,
|
|
3027
|
+
error: task.error ?? null,
|
|
3028
|
+
retry_count: task.retryCount,
|
|
3029
|
+
max_retries: task.maxRetries,
|
|
3030
|
+
timeout_ms: task.timeoutMs,
|
|
3031
|
+
createdAt: task.createdAt.toISOString(),
|
|
3032
|
+
startedAt: task.startedAt?.toISOString() ?? null,
|
|
3033
|
+
completedAt: task.completedAt?.toISOString() ?? null
|
|
3034
|
+
}
|
|
3035
|
+
});
|
|
3036
|
+
}
|
|
3037
|
+
async updateTask(taskId, update) {
|
|
3038
|
+
const setClauses = [];
|
|
3039
|
+
const params = [];
|
|
3040
|
+
if ("status" in update) {
|
|
3041
|
+
setClauses.push("status = ?");
|
|
3042
|
+
params.push(update.status);
|
|
3043
|
+
}
|
|
3044
|
+
if ("result" in update) {
|
|
3045
|
+
setClauses.push("result = jsonb(?)");
|
|
3046
|
+
params.push(serializeJson(update.result));
|
|
3047
|
+
}
|
|
3048
|
+
if ("error" in update) {
|
|
3049
|
+
setClauses.push("error = jsonb(?)");
|
|
3050
|
+
params.push(serializeJson(update.error));
|
|
3051
|
+
}
|
|
3052
|
+
if ("retryCount" in update) {
|
|
3053
|
+
setClauses.push("retry_count = ?");
|
|
3054
|
+
params.push(update.retryCount);
|
|
3055
|
+
}
|
|
3056
|
+
if ("startedAt" in update) {
|
|
3057
|
+
setClauses.push("startedAt = ?");
|
|
3058
|
+
params.push(update.startedAt?.toISOString() ?? null);
|
|
3059
|
+
}
|
|
3060
|
+
if ("completedAt" in update) {
|
|
3061
|
+
setClauses.push("completedAt = ?");
|
|
3062
|
+
params.push(update.completedAt?.toISOString() ?? null);
|
|
3063
|
+
}
|
|
3064
|
+
if (setClauses.length === 0) return;
|
|
3065
|
+
params.push(taskId);
|
|
3066
|
+
await this.#client.execute({
|
|
3067
|
+
sql: `UPDATE ${TABLE_BACKGROUND_TASKS} SET ${setClauses.join(", ")} WHERE id = ?`,
|
|
3068
|
+
args: params
|
|
3069
|
+
});
|
|
3070
|
+
}
|
|
3071
|
+
async getTask(taskId) {
|
|
3072
|
+
const result = await this.#client.execute({
|
|
3073
|
+
sql: `SELECT ${buildSelectColumns(TABLE_BACKGROUND_TASKS)} FROM ${TABLE_BACKGROUND_TASKS} WHERE id = ?`,
|
|
3074
|
+
args: [taskId]
|
|
3075
|
+
});
|
|
3076
|
+
const row = result.rows[0];
|
|
3077
|
+
return row ? rowToTask(row) : null;
|
|
3078
|
+
}
|
|
3079
|
+
async listTasks(filter) {
|
|
3080
|
+
const conditions = [];
|
|
3081
|
+
const params = [];
|
|
3082
|
+
if (filter.status) {
|
|
3083
|
+
const statuses = Array.isArray(filter.status) ? filter.status : [filter.status];
|
|
3084
|
+
conditions.push(`status IN (${statuses.map(() => "?").join(", ")})`);
|
|
3085
|
+
params.push(...statuses);
|
|
3086
|
+
}
|
|
3087
|
+
if (filter.agentId) {
|
|
3088
|
+
conditions.push("agent_id = ?");
|
|
3089
|
+
params.push(filter.agentId);
|
|
3090
|
+
}
|
|
3091
|
+
if (filter.threadId) {
|
|
3092
|
+
conditions.push("thread_id = ?");
|
|
3093
|
+
params.push(filter.threadId);
|
|
3094
|
+
}
|
|
3095
|
+
if (filter.runId) {
|
|
3096
|
+
conditions.push("run_id = ?");
|
|
3097
|
+
params.push(filter.runId);
|
|
3098
|
+
}
|
|
3099
|
+
if (filter.resourceId) {
|
|
3100
|
+
conditions.push("resource_id = ?");
|
|
3101
|
+
params.push(filter.resourceId);
|
|
3102
|
+
}
|
|
3103
|
+
if (filter.toolName) {
|
|
3104
|
+
conditions.push("tool_name = ?");
|
|
3105
|
+
params.push(filter.toolName);
|
|
3106
|
+
}
|
|
3107
|
+
const dateCol = filter.dateFilterBy === "startedAt" ? "startedAt" : filter.dateFilterBy === "completedAt" ? "completedAt" : "createdAt";
|
|
3108
|
+
if (filter.fromDate) {
|
|
3109
|
+
conditions.push(`${dateCol} >= ?`);
|
|
3110
|
+
params.push(filter.fromDate.toISOString());
|
|
3111
|
+
}
|
|
3112
|
+
if (filter.toDate) {
|
|
3113
|
+
conditions.push(`${dateCol} < ?`);
|
|
3114
|
+
params.push(filter.toDate.toISOString());
|
|
3115
|
+
}
|
|
3116
|
+
const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
3117
|
+
const countResult = await this.#client.execute({
|
|
3118
|
+
sql: `SELECT COUNT(*) as count FROM ${TABLE_BACKGROUND_TASKS} ${where}`,
|
|
3119
|
+
args: [...params]
|
|
3120
|
+
});
|
|
3121
|
+
const total = Number(countResult.rows[0]?.count ?? 0);
|
|
3122
|
+
const orderCol = filter.orderBy === "startedAt" ? "startedAt" : filter.orderBy === "completedAt" ? "completedAt" : "createdAt";
|
|
3123
|
+
const direction = filter.orderDirection === "desc" ? "DESC" : "ASC";
|
|
3124
|
+
let sql = `SELECT ${buildSelectColumns(TABLE_BACKGROUND_TASKS)} FROM ${TABLE_BACKGROUND_TASKS} ${where} ORDER BY ${orderCol} ${direction}`;
|
|
3125
|
+
if (filter.perPage != null) {
|
|
3126
|
+
sql += " LIMIT ?";
|
|
3127
|
+
params.push(filter.perPage);
|
|
3128
|
+
if (filter.page != null) {
|
|
3129
|
+
sql += " OFFSET ?";
|
|
3130
|
+
params.push(filter.page * filter.perPage);
|
|
3131
|
+
}
|
|
3132
|
+
}
|
|
3133
|
+
const result = await this.#client.execute({ sql, args: params });
|
|
3134
|
+
return { tasks: result.rows.map((row) => rowToTask(row)), total };
|
|
3135
|
+
}
|
|
3136
|
+
async deleteTask(taskId) {
|
|
3137
|
+
await this.#client.execute({
|
|
3138
|
+
sql: `DELETE FROM ${TABLE_BACKGROUND_TASKS} WHERE id = ?`,
|
|
3139
|
+
args: [taskId]
|
|
3140
|
+
});
|
|
3141
|
+
}
|
|
3142
|
+
async deleteTasks(filter) {
|
|
3143
|
+
const conditions = [];
|
|
3144
|
+
const params = [];
|
|
3145
|
+
if (filter.status) {
|
|
3146
|
+
const statuses = Array.isArray(filter.status) ? filter.status : [filter.status];
|
|
3147
|
+
conditions.push(`status IN (${statuses.map(() => "?").join(", ")})`);
|
|
3148
|
+
params.push(...statuses);
|
|
3149
|
+
}
|
|
3150
|
+
const dateCol = filter.dateFilterBy === "startedAt" ? "startedAt" : filter.dateFilterBy === "completedAt" ? "completedAt" : "createdAt";
|
|
3151
|
+
if (filter.fromDate) {
|
|
3152
|
+
conditions.push(`${dateCol} >= ?`);
|
|
3153
|
+
params.push(filter.fromDate.toISOString());
|
|
3154
|
+
}
|
|
3155
|
+
if (filter.toDate) {
|
|
3156
|
+
conditions.push(`${dateCol} < ?`);
|
|
3157
|
+
params.push(filter.toDate.toISOString());
|
|
3158
|
+
}
|
|
3159
|
+
if (filter.agentId) {
|
|
3160
|
+
conditions.push("agent_id = ?");
|
|
3161
|
+
params.push(filter.agentId);
|
|
3162
|
+
}
|
|
3163
|
+
if (filter.runId) {
|
|
3164
|
+
conditions.push("run_id = ?");
|
|
3165
|
+
params.push(filter.runId);
|
|
3166
|
+
}
|
|
3167
|
+
if (conditions.length === 0) return;
|
|
3168
|
+
await this.#client.execute({
|
|
3169
|
+
sql: `DELETE FROM ${TABLE_BACKGROUND_TASKS} WHERE ${conditions.join(" AND ")}`,
|
|
3170
|
+
args: params
|
|
3171
|
+
});
|
|
3172
|
+
}
|
|
3173
|
+
async getRunningCount() {
|
|
3174
|
+
const result = await this.#client.execute({
|
|
3175
|
+
sql: `SELECT COUNT(*) as count FROM ${TABLE_BACKGROUND_TASKS} WHERE status = 'running'`,
|
|
3176
|
+
args: []
|
|
3177
|
+
});
|
|
3178
|
+
return Number(result.rows[0]?.count ?? 0);
|
|
3179
|
+
}
|
|
3180
|
+
async getRunningCountByAgent(agentId) {
|
|
3181
|
+
const result = await this.#client.execute({
|
|
3182
|
+
sql: `SELECT COUNT(*) as count FROM ${TABLE_BACKGROUND_TASKS} WHERE status = 'running' AND agent_id = ?`,
|
|
3183
|
+
args: [agentId]
|
|
3184
|
+
});
|
|
3185
|
+
return Number(result.rows[0]?.count ?? 0);
|
|
3186
|
+
}
|
|
3187
|
+
};
|
|
2885
3188
|
var BlobsLibSQL = class extends BlobStore {
|
|
2886
3189
|
#db;
|
|
2887
3190
|
#client;
|
|
@@ -10637,6 +10940,7 @@ var LibSQLStore = class extends MastraCompositeStore {
|
|
|
10637
10940
|
const workspaces = new WorkspacesLibSQL(domainConfig);
|
|
10638
10941
|
const skills = new SkillsLibSQL(domainConfig);
|
|
10639
10942
|
const blobs = new BlobsLibSQL(domainConfig);
|
|
10943
|
+
const backgroundTasks = new BackgroundTasksLibSQL(domainConfig);
|
|
10640
10944
|
this.stores = {
|
|
10641
10945
|
scores,
|
|
10642
10946
|
workflows,
|
|
@@ -10651,7 +10955,8 @@ var LibSQLStore = class extends MastraCompositeStore {
|
|
|
10651
10955
|
mcpServers,
|
|
10652
10956
|
workspaces,
|
|
10653
10957
|
skills,
|
|
10654
|
-
blobs
|
|
10958
|
+
blobs,
|
|
10959
|
+
backgroundTasks
|
|
10655
10960
|
};
|
|
10656
10961
|
}
|
|
10657
10962
|
};
|
|
@@ -10755,6 +11060,6 @@ Example Complex Query:
|
|
|
10755
11060
|
]
|
|
10756
11061
|
}`;
|
|
10757
11062
|
|
|
10758
|
-
export { AgentsLibSQL, BlobsLibSQL, DatasetsLibSQL, LibSQLStore as DefaultStorage, ExperimentsLibSQL, LIBSQL_PROMPT, LibSQLStore, LibSQLVector, MCPClientsLibSQL, MCPServersLibSQL, MemoryLibSQL, ObservabilityLibSQL, PromptBlocksLibSQL, ScorerDefinitionsLibSQL, ScoresLibSQL, SkillsLibSQL, WorkflowsLibSQL, WorkspacesLibSQL };
|
|
11063
|
+
export { AgentsLibSQL, BackgroundTasksLibSQL, BlobsLibSQL, DatasetsLibSQL, LibSQLStore as DefaultStorage, ExperimentsLibSQL, LIBSQL_PROMPT, LibSQLStore, LibSQLVector, MCPClientsLibSQL, MCPServersLibSQL, MemoryLibSQL, ObservabilityLibSQL, PromptBlocksLibSQL, ScorerDefinitionsLibSQL, ScoresLibSQL, SkillsLibSQL, WorkflowsLibSQL, WorkspacesLibSQL };
|
|
10759
11064
|
//# sourceMappingURL=index.js.map
|
|
10760
11065
|
//# sourceMappingURL=index.js.map
|