@mastra/libsql 1.0.0 → 1.1.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.
Files changed (32) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/dist/docs/README.md +2 -2
  3. package/dist/docs/SKILL.md +2 -2
  4. package/dist/docs/SOURCE_MAP.json +1 -1
  5. package/dist/docs/agents/01-agent-memory.md +8 -8
  6. package/dist/docs/agents/02-networks.md +1 -1
  7. package/dist/docs/agents/03-agent-approval.md +2 -2
  8. package/dist/docs/agents/04-network-approval.md +2 -2
  9. package/dist/docs/core/01-reference.md +7 -7
  10. package/dist/docs/guides/01-ai-sdk.md +9 -30
  11. package/dist/docs/memory/01-overview.md +22 -53
  12. package/dist/docs/memory/02-storage.md +115 -87
  13. package/dist/docs/memory/03-message-history.md +249 -0
  14. package/dist/docs/memory/{03-working-memory.md → 04-working-memory.md} +22 -1
  15. package/dist/docs/memory/{04-semantic-recall.md → 05-semantic-recall.md} +45 -22
  16. package/dist/docs/memory/{05-memory-processors.md → 06-memory-processors.md} +4 -4
  17. package/dist/docs/memory/{06-reference.md → 07-reference.md} +11 -11
  18. package/dist/docs/observability/01-overview.md +13 -4
  19. package/dist/docs/observability/02-default.md +44 -7
  20. package/dist/docs/rag/01-retrieval.md +4 -4
  21. package/dist/docs/storage/01-reference.md +31 -17
  22. package/dist/docs/vectors/01-reference.md +4 -4
  23. package/dist/docs/workflows/01-snapshots.md +14 -14
  24. package/dist/index.cjs +271 -1
  25. package/dist/index.cjs.map +1 -1
  26. package/dist/index.js +272 -2
  27. package/dist/index.js.map +1 -1
  28. package/dist/storage/domains/agents/index.d.ts +10 -1
  29. package/dist/storage/domains/agents/index.d.ts.map +1 -1
  30. package/dist/storage/domains/observability/index.d.ts +2 -5
  31. package/dist/storage/domains/observability/index.d.ts.map +1 -1
  32. package/package.json +8 -8
package/dist/index.cjs CHANGED
@@ -2050,8 +2050,10 @@ var AgentsLibSQL = class extends storage.AgentsStorage {
2050
2050
  }
2051
2051
  async init() {
2052
2052
  await this.#db.createTable({ tableName: storage.TABLE_AGENTS, schema: storage.AGENTS_SCHEMA });
2053
+ await this.#db.createTable({ tableName: storage.TABLE_AGENT_VERSIONS, schema: storage.AGENT_VERSIONS_SCHEMA });
2053
2054
  }
2054
2055
  async dangerouslyClearAll() {
2056
+ await this.#db.deleteData({ tableName: storage.TABLE_AGENT_VERSIONS });
2055
2057
  await this.#db.deleteData({ tableName: storage.TABLE_AGENTS });
2056
2058
  }
2057
2059
  parseJson(value, fieldName) {
@@ -2093,6 +2095,9 @@ var AgentsLibSQL = class extends storage.AgentsStorage {
2093
2095
  outputProcessors: this.parseJson(row.outputProcessors, "outputProcessors"),
2094
2096
  memory: this.parseJson(row.memory, "memory"),
2095
2097
  scorers: this.parseJson(row.scorers, "scorers"),
2098
+ integrationTools: this.parseJson(row.integrationTools, "integrationTools"),
2099
+ ownerId: row.ownerId,
2100
+ activeVersionId: row.activeVersionId,
2096
2101
  metadata: this.parseJson(row.metadata, "metadata"),
2097
2102
  createdAt: new Date(row.createdAt),
2098
2103
  updatedAt: new Date(row.updatedAt)
@@ -2136,6 +2141,9 @@ var AgentsLibSQL = class extends storage.AgentsStorage {
2136
2141
  outputProcessors: agent.outputProcessors ?? null,
2137
2142
  memory: agent.memory ?? null,
2138
2143
  scorers: agent.scorers ?? null,
2144
+ integrationTools: agent.integrationTools ?? null,
2145
+ ownerId: agent.ownerId ?? null,
2146
+ activeVersionId: agent.activeVersionId ?? null,
2139
2147
  metadata: agent.metadata ?? null,
2140
2148
  createdAt: now,
2141
2149
  updatedAt: now
@@ -2185,6 +2193,9 @@ var AgentsLibSQL = class extends storage.AgentsStorage {
2185
2193
  if (updates.outputProcessors !== void 0) data.outputProcessors = updates.outputProcessors;
2186
2194
  if (updates.memory !== void 0) data.memory = updates.memory;
2187
2195
  if (updates.scorers !== void 0) data.scorers = updates.scorers;
2196
+ if (updates.integrationTools !== void 0) data.integrationTools = updates.integrationTools;
2197
+ if (updates.ownerId !== void 0) data.ownerId = updates.ownerId;
2198
+ if (updates.activeVersionId !== void 0) data.activeVersionId = updates.activeVersionId;
2188
2199
  if (updates.metadata !== void 0) {
2189
2200
  data.metadata = { ...existingAgent.metadata, ...updates.metadata };
2190
2201
  }
@@ -2223,6 +2234,7 @@ var AgentsLibSQL = class extends storage.AgentsStorage {
2223
2234
  }
2224
2235
  async deleteAgent({ id }) {
2225
2236
  try {
2237
+ await this.deleteVersionsByAgentId(id);
2226
2238
  await this.#db.delete({
2227
2239
  tableName: storage.TABLE_AGENTS,
2228
2240
  keys: { id }
@@ -2292,6 +2304,262 @@ var AgentsLibSQL = class extends storage.AgentsStorage {
2292
2304
  );
2293
2305
  }
2294
2306
  }
2307
+ // ==========================================================================
2308
+ // Agent Version Methods
2309
+ // ==========================================================================
2310
+ async createVersion(input) {
2311
+ try {
2312
+ const now = /* @__PURE__ */ new Date();
2313
+ await this.#db.insert({
2314
+ tableName: storage.TABLE_AGENT_VERSIONS,
2315
+ record: {
2316
+ id: input.id,
2317
+ agentId: input.agentId,
2318
+ versionNumber: input.versionNumber,
2319
+ name: input.name ?? null,
2320
+ snapshot: input.snapshot,
2321
+ changedFields: input.changedFields ?? null,
2322
+ changeMessage: input.changeMessage ?? null,
2323
+ createdAt: now
2324
+ }
2325
+ });
2326
+ return {
2327
+ ...input,
2328
+ createdAt: now
2329
+ };
2330
+ } catch (error$1) {
2331
+ throw new error.MastraError(
2332
+ {
2333
+ id: storage.createStorageErrorId("LIBSQL", "CREATE_VERSION", "FAILED"),
2334
+ domain: error.ErrorDomain.STORAGE,
2335
+ category: error.ErrorCategory.THIRD_PARTY,
2336
+ details: { versionId: input.id, agentId: input.agentId }
2337
+ },
2338
+ error$1
2339
+ );
2340
+ }
2341
+ }
2342
+ async getVersion(id) {
2343
+ try {
2344
+ const result = await this.#db.select({
2345
+ tableName: storage.TABLE_AGENT_VERSIONS,
2346
+ keys: { id }
2347
+ });
2348
+ if (!result) {
2349
+ return null;
2350
+ }
2351
+ return this.parseVersionRow(result);
2352
+ } catch (error$1) {
2353
+ throw new error.MastraError(
2354
+ {
2355
+ id: storage.createStorageErrorId("LIBSQL", "GET_VERSION", "FAILED"),
2356
+ domain: error.ErrorDomain.STORAGE,
2357
+ category: error.ErrorCategory.THIRD_PARTY,
2358
+ details: { versionId: id }
2359
+ },
2360
+ error$1
2361
+ );
2362
+ }
2363
+ }
2364
+ async getVersionByNumber(agentId, versionNumber) {
2365
+ try {
2366
+ const rows = await this.#db.selectMany({
2367
+ tableName: storage.TABLE_AGENT_VERSIONS,
2368
+ whereClause: {
2369
+ sql: "WHERE agentId = ? AND versionNumber = ?",
2370
+ args: [agentId, versionNumber]
2371
+ },
2372
+ limit: 1
2373
+ });
2374
+ if (!rows || rows.length === 0) {
2375
+ return null;
2376
+ }
2377
+ return this.parseVersionRow(rows[0]);
2378
+ } catch (error$1) {
2379
+ throw new error.MastraError(
2380
+ {
2381
+ id: storage.createStorageErrorId("LIBSQL", "GET_VERSION_BY_NUMBER", "FAILED"),
2382
+ domain: error.ErrorDomain.STORAGE,
2383
+ category: error.ErrorCategory.THIRD_PARTY,
2384
+ details: { agentId, versionNumber }
2385
+ },
2386
+ error$1
2387
+ );
2388
+ }
2389
+ }
2390
+ async getLatestVersion(agentId) {
2391
+ try {
2392
+ const rows = await this.#db.selectMany({
2393
+ tableName: storage.TABLE_AGENT_VERSIONS,
2394
+ whereClause: {
2395
+ sql: "WHERE agentId = ?",
2396
+ args: [agentId]
2397
+ },
2398
+ orderBy: "versionNumber DESC",
2399
+ limit: 1
2400
+ });
2401
+ if (!rows || rows.length === 0) {
2402
+ return null;
2403
+ }
2404
+ return this.parseVersionRow(rows[0]);
2405
+ } catch (error$1) {
2406
+ throw new error.MastraError(
2407
+ {
2408
+ id: storage.createStorageErrorId("LIBSQL", "GET_LATEST_VERSION", "FAILED"),
2409
+ domain: error.ErrorDomain.STORAGE,
2410
+ category: error.ErrorCategory.THIRD_PARTY,
2411
+ details: { agentId }
2412
+ },
2413
+ error$1
2414
+ );
2415
+ }
2416
+ }
2417
+ async listVersions(input) {
2418
+ const { agentId, page = 0, perPage: perPageInput, orderBy } = input;
2419
+ if (page < 0) {
2420
+ throw new error.MastraError(
2421
+ {
2422
+ id: storage.createStorageErrorId("LIBSQL", "LIST_VERSIONS", "INVALID_PAGE"),
2423
+ domain: error.ErrorDomain.STORAGE,
2424
+ category: error.ErrorCategory.USER,
2425
+ details: { page }
2426
+ },
2427
+ new Error("page must be >= 0")
2428
+ );
2429
+ }
2430
+ const perPage = storage.normalizePerPage(perPageInput, 20);
2431
+ const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
2432
+ try {
2433
+ const { field, direction } = this.parseVersionOrderBy(orderBy);
2434
+ const total = await this.#db.selectTotalCount({
2435
+ tableName: storage.TABLE_AGENT_VERSIONS,
2436
+ whereClause: {
2437
+ sql: "WHERE agentId = ?",
2438
+ args: [agentId]
2439
+ }
2440
+ });
2441
+ if (total === 0) {
2442
+ return {
2443
+ versions: [],
2444
+ total: 0,
2445
+ page,
2446
+ perPage: perPageForResponse,
2447
+ hasMore: false
2448
+ };
2449
+ }
2450
+ const limitValue = perPageInput === false ? total : perPage;
2451
+ const rows = await this.#db.selectMany({
2452
+ tableName: storage.TABLE_AGENT_VERSIONS,
2453
+ whereClause: {
2454
+ sql: "WHERE agentId = ?",
2455
+ args: [agentId]
2456
+ },
2457
+ orderBy: `"${field}" ${direction}`,
2458
+ limit: limitValue,
2459
+ offset
2460
+ });
2461
+ const versions = rows.map((row) => this.parseVersionRow(row));
2462
+ return {
2463
+ versions,
2464
+ total,
2465
+ page,
2466
+ perPage: perPageForResponse,
2467
+ hasMore: perPageInput === false ? false : offset + perPage < total
2468
+ };
2469
+ } catch (error$1) {
2470
+ throw new error.MastraError(
2471
+ {
2472
+ id: storage.createStorageErrorId("LIBSQL", "LIST_VERSIONS", "FAILED"),
2473
+ domain: error.ErrorDomain.STORAGE,
2474
+ category: error.ErrorCategory.THIRD_PARTY,
2475
+ details: { agentId }
2476
+ },
2477
+ error$1
2478
+ );
2479
+ }
2480
+ }
2481
+ async deleteVersion(id) {
2482
+ try {
2483
+ await this.#db.delete({
2484
+ tableName: storage.TABLE_AGENT_VERSIONS,
2485
+ keys: { id }
2486
+ });
2487
+ } catch (error$1) {
2488
+ throw new error.MastraError(
2489
+ {
2490
+ id: storage.createStorageErrorId("LIBSQL", "DELETE_VERSION", "FAILED"),
2491
+ domain: error.ErrorDomain.STORAGE,
2492
+ category: error.ErrorCategory.THIRD_PARTY,
2493
+ details: { versionId: id }
2494
+ },
2495
+ error$1
2496
+ );
2497
+ }
2498
+ }
2499
+ async deleteVersionsByAgentId(agentId) {
2500
+ try {
2501
+ const versions = await this.#db.selectMany({
2502
+ tableName: storage.TABLE_AGENT_VERSIONS,
2503
+ whereClause: {
2504
+ sql: "WHERE agentId = ?",
2505
+ args: [agentId]
2506
+ }
2507
+ });
2508
+ for (const version of versions) {
2509
+ await this.#db.delete({
2510
+ tableName: storage.TABLE_AGENT_VERSIONS,
2511
+ keys: { id: version.id }
2512
+ });
2513
+ }
2514
+ } catch (error$1) {
2515
+ throw new error.MastraError(
2516
+ {
2517
+ id: storage.createStorageErrorId("LIBSQL", "DELETE_VERSIONS_BY_AGENT_ID", "FAILED"),
2518
+ domain: error.ErrorDomain.STORAGE,
2519
+ category: error.ErrorCategory.THIRD_PARTY,
2520
+ details: { agentId }
2521
+ },
2522
+ error$1
2523
+ );
2524
+ }
2525
+ }
2526
+ async countVersions(agentId) {
2527
+ try {
2528
+ const count = await this.#db.selectTotalCount({
2529
+ tableName: storage.TABLE_AGENT_VERSIONS,
2530
+ whereClause: {
2531
+ sql: "WHERE agentId = ?",
2532
+ args: [agentId]
2533
+ }
2534
+ });
2535
+ return count;
2536
+ } catch (error$1) {
2537
+ throw new error.MastraError(
2538
+ {
2539
+ id: storage.createStorageErrorId("LIBSQL", "COUNT_VERSIONS", "FAILED"),
2540
+ domain: error.ErrorDomain.STORAGE,
2541
+ category: error.ErrorCategory.THIRD_PARTY,
2542
+ details: { agentId }
2543
+ },
2544
+ error$1
2545
+ );
2546
+ }
2547
+ }
2548
+ // ==========================================================================
2549
+ // Private Helper Methods
2550
+ // ==========================================================================
2551
+ parseVersionRow(row) {
2552
+ return {
2553
+ id: row.id,
2554
+ agentId: row.agentId,
2555
+ versionNumber: row.versionNumber,
2556
+ name: row.name,
2557
+ snapshot: this.parseJson(row.snapshot, "snapshot"),
2558
+ changedFields: this.parseJson(row.changedFields, "changedFields"),
2559
+ changeMessage: row.changeMessage,
2560
+ createdAt: new Date(row.createdAt)
2561
+ };
2562
+ }
2295
2563
  };
2296
2564
  var MemoryLibSQL = class extends storage.MemoryStorage {
2297
2565
  #client;
@@ -3558,7 +3826,9 @@ var ObservabilityLibSQL = class extends storage.ObservabilityStorage {
3558
3826
  perPage,
3559
3827
  hasMore: (page + 1) * perPage < count
3560
3828
  },
3561
- spans: spans.map((span) => transformFromSqlRow({ tableName: storage.TABLE_SPANS, sqlRow: span }))
3829
+ spans: storage.toTraceSpans(
3830
+ spans.map((span) => transformFromSqlRow({ tableName: storage.TABLE_SPANS, sqlRow: span }))
3831
+ )
3562
3832
  };
3563
3833
  } catch (error$1) {
3564
3834
  throw new error.MastraError(