@mastra/libsql 1.11.1-alpha.0 → 1.12.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/dist/index.cjs CHANGED
@@ -2275,7 +2275,15 @@ var AgentsLibSQL = class extends storage.AgentsStorage {
2275
2275
  await this.#db.alterTable({
2276
2276
  tableName: storage.TABLE_AGENT_VERSIONS,
2277
2277
  schema: storage.AGENT_VERSIONS_SCHEMA,
2278
- ifNotExists: ["mcpClients", "requestContextSchema", "workspace", "skills", "skillsFormat", "browser"]
2278
+ ifNotExists: [
2279
+ "mcpClients",
2280
+ "requestContextSchema",
2281
+ "workspace",
2282
+ "skills",
2283
+ "skillsFormat",
2284
+ "browser",
2285
+ "toolProviders"
2286
+ ]
2279
2287
  });
2280
2288
  await this.#migrateToolsToJsonbFormat();
2281
2289
  await this.#cleanupStaleDrafts();
@@ -2336,6 +2344,7 @@ var AgentsLibSQL = class extends storage.AgentsStorage {
2336
2344
  workflows: row.workflows ?? null,
2337
2345
  agents: row.agents ?? null,
2338
2346
  integrationTools: row.integrationTools ?? null,
2347
+ toolProviders: row.toolProviders ?? null,
2339
2348
  inputProcessors: row.inputProcessors ?? null,
2340
2349
  outputProcessors: row.outputProcessors ?? null,
2341
2350
  memory: row.memory ?? null,
@@ -2788,6 +2797,7 @@ var AgentsLibSQL = class extends storage.AgentsStorage {
2788
2797
  workflows: input.workflows ?? null,
2789
2798
  agents: input.agents ?? null,
2790
2799
  integrationTools: input.integrationTools ?? null,
2800
+ toolProviders: input.toolProviders ?? null,
2791
2801
  inputProcessors: input.inputProcessors ?? null,
2792
2802
  outputProcessors: input.outputProcessors ?? null,
2793
2803
  memory: input.memory ?? null,
@@ -3062,6 +3072,7 @@ var AgentsLibSQL = class extends storage.AgentsStorage {
3062
3072
  workflows: this.parseJson(row.workflows, "workflows"),
3063
3073
  agents: this.parseJson(row.agents, "agents"),
3064
3074
  integrationTools: this.parseJson(row.integrationTools, "integrationTools"),
3075
+ toolProviders: this.parseJson(row.toolProviders, "toolProviders"),
3065
3076
  inputProcessors: this.parseJson(row.inputProcessors, "inputProcessors"),
3066
3077
  outputProcessors: this.parseJson(row.outputProcessors, "outputProcessors"),
3067
3078
  memory: this.parseJson(row.memory, "memory"),
@@ -10980,6 +10991,197 @@ var SkillsLibSQL = class extends storage.SkillsStorage {
10980
10991
  };
10981
10992
  }
10982
10993
  };
10994
+ function normaliseScope(raw) {
10995
+ const value = raw == null ? "per-author" : String(raw);
10996
+ if (value === "shared") return "shared";
10997
+ if (value === "caller-supplied") return "caller-supplied";
10998
+ return "per-author";
10999
+ }
11000
+ function rowToToolProviderConnection(row) {
11001
+ return {
11002
+ authorId: String(row.authorId),
11003
+ providerId: String(row.providerId),
11004
+ toolkit: String(row.toolkit),
11005
+ connectionId: String(row.connectionId),
11006
+ label: row.label == null ? null : String(row.label),
11007
+ scope: normaliseScope(row.scope),
11008
+ createdAt: new Date(String(row.createdAt)),
11009
+ updatedAt: new Date(String(row.updatedAt))
11010
+ };
11011
+ }
11012
+ var ToolProviderConnectionsLibSQL = class extends storage.ToolProviderConnectionsStorage {
11013
+ #db;
11014
+ #client;
11015
+ constructor(config) {
11016
+ super();
11017
+ const client = resolveClient(config);
11018
+ this.#client = client;
11019
+ this.#db = new LibSQLDB({ client, maxRetries: config.maxRetries, initialBackoffMs: config.initialBackoffMs });
11020
+ }
11021
+ async init() {
11022
+ await this.#db.createTable({
11023
+ tableName: storage.TABLE_TOOL_PROVIDER_CONNECTIONS,
11024
+ schema: storage.TOOL_PROVIDER_CONNECTIONS_SCHEMA,
11025
+ compositePrimaryKey: ["authorId", "providerId", "connectionId"]
11026
+ });
11027
+ await this.#client.execute(
11028
+ `CREATE INDEX IF NOT EXISTS idx_tool_provider_connections_author ON "${storage.TABLE_TOOL_PROVIDER_CONNECTIONS}" ("authorId", "providerId", "toolkit")`
11029
+ );
11030
+ }
11031
+ async dangerouslyClearAll() {
11032
+ await this.#client.execute(`DELETE FROM "${storage.TABLE_TOOL_PROVIDER_CONNECTIONS}"`);
11033
+ }
11034
+ async getConnectionById({
11035
+ authorId,
11036
+ providerId,
11037
+ connectionId
11038
+ }) {
11039
+ try {
11040
+ const result = await this.#client.execute({
11041
+ sql: `SELECT * FROM "${storage.TABLE_TOOL_PROVIDER_CONNECTIONS}" WHERE "authorId" = ? AND "providerId" = ? AND "connectionId" = ? LIMIT 1`,
11042
+ args: [authorId, providerId, connectionId]
11043
+ });
11044
+ const row = result.rows?.[0];
11045
+ if (!row) return null;
11046
+ return rowToToolProviderConnection(row);
11047
+ } catch (error$1) {
11048
+ if (error$1 instanceof error.MastraError) throw error$1;
11049
+ throw new error.MastraError(
11050
+ {
11051
+ id: storage.createStorageErrorId("LIBSQL", "TOOL_PROVIDER_CONNECTION_GET", "FAILED"),
11052
+ domain: error.ErrorDomain.STORAGE,
11053
+ category: error.ErrorCategory.THIRD_PARTY,
11054
+ details: { authorId, providerId, connectionId }
11055
+ },
11056
+ error$1
11057
+ );
11058
+ }
11059
+ }
11060
+ async upsertConnection(input) {
11061
+ const { authorId, providerId, toolkit, connectionId, label } = input;
11062
+ const now = /* @__PURE__ */ new Date();
11063
+ const nowIso = now.toISOString();
11064
+ const labelValue = label == null ? null : label;
11065
+ try {
11066
+ const tx = await this.#client.transaction("write");
11067
+ try {
11068
+ const existing = await tx.execute({
11069
+ sql: `SELECT "createdAt", "scope" FROM "${storage.TABLE_TOOL_PROVIDER_CONNECTIONS}" WHERE "authorId" = ? AND "providerId" = ? AND "connectionId" = ? LIMIT 1`,
11070
+ args: [authorId, providerId, connectionId]
11071
+ });
11072
+ const existingRow = existing.rows?.[0];
11073
+ const createdAt = existingRow ? String(existingRow.createdAt) : nowIso;
11074
+ const existingScope = existingRow && existingRow.scope != null ? normaliseScope(existingRow.scope) : void 0;
11075
+ const scope = input.scope ?? existingScope ?? "per-author";
11076
+ if (existingRow) {
11077
+ await tx.execute({
11078
+ sql: `UPDATE "${storage.TABLE_TOOL_PROVIDER_CONNECTIONS}" SET "toolkit" = ?, "label" = ?, "scope" = ?, "updatedAt" = ? WHERE "authorId" = ? AND "providerId" = ? AND "connectionId" = ?`,
11079
+ args: [toolkit, labelValue, scope, nowIso, authorId, providerId, connectionId]
11080
+ });
11081
+ } else {
11082
+ await tx.execute({
11083
+ sql: `INSERT INTO "${storage.TABLE_TOOL_PROVIDER_CONNECTIONS}" ("authorId", "providerId", "toolkit", "connectionId", "label", "scope", "createdAt", "updatedAt") VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
11084
+ args: [authorId, providerId, toolkit, connectionId, labelValue, scope, createdAt, nowIso]
11085
+ });
11086
+ }
11087
+ await tx.commit();
11088
+ return {
11089
+ authorId,
11090
+ providerId,
11091
+ toolkit,
11092
+ connectionId,
11093
+ label: labelValue,
11094
+ scope,
11095
+ createdAt: new Date(createdAt),
11096
+ updatedAt: now
11097
+ };
11098
+ } catch (error) {
11099
+ if (!tx.closed) {
11100
+ await tx.rollback();
11101
+ }
11102
+ throw error;
11103
+ }
11104
+ } catch (error$1) {
11105
+ if (error$1 instanceof error.MastraError) throw error$1;
11106
+ throw new error.MastraError(
11107
+ {
11108
+ id: storage.createStorageErrorId("LIBSQL", "TOOL_PROVIDER_CONNECTION_UPSERT", "FAILED"),
11109
+ domain: error.ErrorDomain.STORAGE,
11110
+ category: error.ErrorCategory.THIRD_PARTY,
11111
+ details: { authorId, providerId, connectionId }
11112
+ },
11113
+ error$1
11114
+ );
11115
+ }
11116
+ }
11117
+ async listConnectionsByAuthor({
11118
+ authorId,
11119
+ providerId,
11120
+ toolkit,
11121
+ scope
11122
+ }) {
11123
+ try {
11124
+ const clauses = [];
11125
+ const args = [];
11126
+ if (authorId !== void 0) {
11127
+ clauses.push('"authorId" = ?');
11128
+ args.push(authorId);
11129
+ }
11130
+ if (providerId) {
11131
+ clauses.push('"providerId" = ?');
11132
+ args.push(providerId);
11133
+ }
11134
+ if (toolkit) {
11135
+ clauses.push('"toolkit" = ?');
11136
+ args.push(toolkit);
11137
+ }
11138
+ if (scope) {
11139
+ clauses.push('"scope" = ?');
11140
+ args.push(scope);
11141
+ }
11142
+ const whereClause = clauses.length > 0 ? ` WHERE ${clauses.join(" AND ")}` : "";
11143
+ const result = await this.#client.execute({
11144
+ sql: `SELECT * FROM "${storage.TABLE_TOOL_PROVIDER_CONNECTIONS}"${whereClause}`,
11145
+ args
11146
+ });
11147
+ return (result.rows ?? []).map((row) => rowToToolProviderConnection(row));
11148
+ } catch (error$1) {
11149
+ if (error$1 instanceof error.MastraError) throw error$1;
11150
+ throw new error.MastraError(
11151
+ {
11152
+ id: storage.createStorageErrorId("LIBSQL", "TOOL_PROVIDER_CONNECTION_LIST", "FAILED"),
11153
+ domain: error.ErrorDomain.STORAGE,
11154
+ category: error.ErrorCategory.THIRD_PARTY,
11155
+ details: { authorId: authorId ?? "", providerId: providerId ?? "", toolkit: toolkit ?? "" }
11156
+ },
11157
+ error$1
11158
+ );
11159
+ }
11160
+ }
11161
+ async deleteConnection({
11162
+ authorId,
11163
+ providerId,
11164
+ connectionId
11165
+ }) {
11166
+ try {
11167
+ await this.#client.execute({
11168
+ sql: `DELETE FROM "${storage.TABLE_TOOL_PROVIDER_CONNECTIONS}" WHERE "authorId" = ? AND "providerId" = ? AND "connectionId" = ?`,
11169
+ args: [authorId, providerId, connectionId]
11170
+ });
11171
+ } catch (error$1) {
11172
+ if (error$1 instanceof error.MastraError) throw error$1;
11173
+ throw new error.MastraError(
11174
+ {
11175
+ id: storage.createStorageErrorId("LIBSQL", "TOOL_PROVIDER_CONNECTION_DELETE", "FAILED"),
11176
+ domain: error.ErrorDomain.STORAGE,
11177
+ category: error.ErrorCategory.THIRD_PARTY,
11178
+ details: { authorId, providerId, connectionId }
11179
+ },
11180
+ error$1
11181
+ );
11182
+ }
11183
+ }
11184
+ };
10983
11185
  var WorkflowsLibSQL = class extends storage.WorkflowsStorage {
10984
11186
  #db;
10985
11187
  #client;
@@ -11916,6 +12118,7 @@ var LibSQLStore = class extends storage.MastraCompositeStore {
11916
12118
  const blobs = new BlobsLibSQL(domainConfig);
11917
12119
  const backgroundTasks = new BackgroundTasksLibSQL(domainConfig);
11918
12120
  const schedules = new SchedulesLibSQL(domainConfig);
12121
+ const toolProviderConnections = new ToolProviderConnectionsLibSQL(domainConfig);
11919
12122
  this.stores = {
11920
12123
  scores,
11921
12124
  workflows,
@@ -11934,7 +12137,8 @@ var LibSQLStore = class extends storage.MastraCompositeStore {
11934
12137
  favorites,
11935
12138
  blobs,
11936
12139
  backgroundTasks,
11937
- schedules
12140
+ schedules,
12141
+ toolProviderConnections
11938
12142
  };
11939
12143
  }
11940
12144
  async applyLocalPragmas() {
@@ -11994,6 +12198,34 @@ var LibSQLStore = class extends storage.MastraCompositeStore {
11994
12198
  }
11995
12199
  await this.initDomainsSequentially();
11996
12200
  }
12201
+ /**
12202
+ * Closes the underlying libsql client, releasing all OS file handles.
12203
+ *
12204
+ * For local file databases, first runs PRAGMA wal_checkpoint(TRUNCATE) and
12205
+ * switches back to journal_mode=DELETE so that Windows releases the -wal
12206
+ * and -shm sidecar files promptly. Without this, the handles stay open
12207
+ * until process exit, causing EBUSY errors when callers try to fs.rm the
12208
+ * storage directory after Mastra.shutdown().
12209
+ *
12210
+ * Remote (Turso) databases skip the WAL pragmas and just close the client.
12211
+ *
12212
+ * Safe to call more than once; subsequent calls are no-ops.
12213
+ */
12214
+ async close() {
12215
+ if (this.client.closed) {
12216
+ return;
12217
+ }
12218
+ const isLocalFileDb = this.isLocalDb || this.client.protocol === "file";
12219
+ if (isLocalFileDb) {
12220
+ try {
12221
+ await this.client.execute("PRAGMA wal_checkpoint(TRUNCATE);");
12222
+ await this.client.execute("PRAGMA journal_mode=DELETE;");
12223
+ } catch (err) {
12224
+ this.logger.warn("LibSQLStore: Failed to checkpoint WAL before close.", err);
12225
+ }
12226
+ }
12227
+ this.client.close();
12228
+ }
11997
12229
  };
11998
12230
 
11999
12231
  // src/vector/prompt.ts
@@ -12115,6 +12347,7 @@ exports.SchedulesLibSQL = SchedulesLibSQL;
12115
12347
  exports.ScorerDefinitionsLibSQL = ScorerDefinitionsLibSQL;
12116
12348
  exports.ScoresLibSQL = ScoresLibSQL;
12117
12349
  exports.SkillsLibSQL = SkillsLibSQL;
12350
+ exports.ToolProviderConnectionsLibSQL = ToolProviderConnectionsLibSQL;
12118
12351
  exports.WorkflowsLibSQL = WorkflowsLibSQL;
12119
12352
  exports.WorkspacesLibSQL = WorkspacesLibSQL;
12120
12353
  //# sourceMappingURL=index.cjs.map