@mastra/libsql 0.14.3 → 0.15.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 CHANGED
@@ -1,5 +1,43 @@
1
1
  # @mastra/libsql
2
2
 
3
+ ## 0.15.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Added Postgres and updated libsql storage adapters for ai-traces ([#8027](https://github.com/mastra-ai/mastra/pull/8027))
8
+
9
+ ### Patch Changes
10
+
11
+ - Update peer deps ([#8154](https://github.com/mastra-ai/mastra/pull/8154))
12
+
13
+ - Fix incorrect title and import references in README.md ([#8288](https://github.com/mastra-ai/mastra/pull/8288))
14
+
15
+ Fixed the package title from '@mastra/pg' to '@mastra/libsql' and corrected the import statement in the Storage usage example.
16
+
17
+ - Libsql get scores by span ([#8154](https://github.com/mastra-ai/mastra/pull/8154))
18
+
19
+ - Updated dependencies [[`dc099b4`](https://github.com/mastra-ai/mastra/commit/dc099b40fb31147ba3f362f98d991892033c4c67), [`504438b`](https://github.com/mastra-ai/mastra/commit/504438b961bde211071186bba63a842c4e3db879), [`b342a68`](https://github.com/mastra-ai/mastra/commit/b342a68e1399cf1ece9ba11bda112db89d21118c), [`a7243e2`](https://github.com/mastra-ai/mastra/commit/a7243e2e58762667a6e3921e755e89d6bb0a3282), [`7fceb0a`](https://github.com/mastra-ai/mastra/commit/7fceb0a327d678e812f90f5387c5bc4f38bd039e), [`303a9c0`](https://github.com/mastra-ai/mastra/commit/303a9c0d7dd58795915979f06a0512359e4532fb), [`df64f9e`](https://github.com/mastra-ai/mastra/commit/df64f9ef814916fff9baedd861c988084e7c41de), [`370f8a6`](https://github.com/mastra-ai/mastra/commit/370f8a6480faec70fef18d72e5f7538f27004301), [`809eea0`](https://github.com/mastra-ai/mastra/commit/809eea092fa80c3f69b9eaf078d843b57fd2a88e), [`683e5a1`](https://github.com/mastra-ai/mastra/commit/683e5a1466e48b686825b2c11f84680f296138e4), [`3679378`](https://github.com/mastra-ai/mastra/commit/3679378673350aa314741dc826f837b1984149bc), [`7775bc2`](https://github.com/mastra-ai/mastra/commit/7775bc20bb1ad1ab24797fb420e4f96c65b0d8ec), [`623ffaf`](https://github.com/mastra-ai/mastra/commit/623ffaf2d969e11e99a0224633cf7b5a0815c857), [`9fc1613`](https://github.com/mastra-ai/mastra/commit/9fc16136400186648880fd990119ac15f7c02ee4), [`61f62aa`](https://github.com/mastra-ai/mastra/commit/61f62aa31bc88fe4ddf8da6240dbcfbeb07358bd), [`db1891a`](https://github.com/mastra-ai/mastra/commit/db1891a4707443720b7cd8a260dc7e1d49b3609c), [`e8f379d`](https://github.com/mastra-ai/mastra/commit/e8f379d390efa264c4e0874f9ac0cf8839b07777), [`652066b`](https://github.com/mastra-ai/mastra/commit/652066bd1efc6bb6813ba950ed1d7573e8b7d9d4), [`3e292ba`](https://github.com/mastra-ai/mastra/commit/3e292ba00837886d5d68a34cbc0d9b703c991883), [`418c136`](https://github.com/mastra-ai/mastra/commit/418c1366843d88e491bca3f87763899ce855ca29), [`ea8d386`](https://github.com/mastra-ai/mastra/commit/ea8d386cd8c5593664515fd5770c06bf2aa980ef), [`67b0f00`](https://github.com/mastra-ai/mastra/commit/67b0f005b520335c71fb85cbaa25df4ce8484a81), [`c2a4919`](https://github.com/mastra-ai/mastra/commit/c2a4919ba6797d8bdb1509e02287496eef69303e), [`c84b7d0`](https://github.com/mastra-ai/mastra/commit/c84b7d093c4657772140cbfd2b15ef72f3315ed5), [`0130986`](https://github.com/mastra-ai/mastra/commit/0130986fc62d0edcc626dd593282661dbb9af141)]:
20
+ - @mastra/core@0.19.0
21
+
22
+ ## 0.15.0-alpha.0
23
+
24
+ ### Minor Changes
25
+
26
+ - Added Postgres and updated libsql storage adapters for ai-traces ([#8027](https://github.com/mastra-ai/mastra/pull/8027))
27
+
28
+ ### Patch Changes
29
+
30
+ - Update peer deps ([#8154](https://github.com/mastra-ai/mastra/pull/8154))
31
+
32
+ - Fix incorrect title and import references in README.md ([#8288](https://github.com/mastra-ai/mastra/pull/8288))
33
+
34
+ Fixed the package title from '@mastra/pg' to '@mastra/libsql' and corrected the import statement in the Storage usage example.
35
+
36
+ - Libsql get scores by span ([#8154](https://github.com/mastra-ai/mastra/pull/8154))
37
+
38
+ - Updated dependencies [[`504438b`](https://github.com/mastra-ai/mastra/commit/504438b961bde211071186bba63a842c4e3db879), [`a7243e2`](https://github.com/mastra-ai/mastra/commit/a7243e2e58762667a6e3921e755e89d6bb0a3282), [`7fceb0a`](https://github.com/mastra-ai/mastra/commit/7fceb0a327d678e812f90f5387c5bc4f38bd039e), [`df64f9e`](https://github.com/mastra-ai/mastra/commit/df64f9ef814916fff9baedd861c988084e7c41de), [`809eea0`](https://github.com/mastra-ai/mastra/commit/809eea092fa80c3f69b9eaf078d843b57fd2a88e), [`683e5a1`](https://github.com/mastra-ai/mastra/commit/683e5a1466e48b686825b2c11f84680f296138e4), [`3679378`](https://github.com/mastra-ai/mastra/commit/3679378673350aa314741dc826f837b1984149bc), [`7775bc2`](https://github.com/mastra-ai/mastra/commit/7775bc20bb1ad1ab24797fb420e4f96c65b0d8ec), [`db1891a`](https://github.com/mastra-ai/mastra/commit/db1891a4707443720b7cd8a260dc7e1d49b3609c), [`e8f379d`](https://github.com/mastra-ai/mastra/commit/e8f379d390efa264c4e0874f9ac0cf8839b07777), [`652066b`](https://github.com/mastra-ai/mastra/commit/652066bd1efc6bb6813ba950ed1d7573e8b7d9d4), [`ea8d386`](https://github.com/mastra-ai/mastra/commit/ea8d386cd8c5593664515fd5770c06bf2aa980ef), [`c2a4919`](https://github.com/mastra-ai/mastra/commit/c2a4919ba6797d8bdb1509e02287496eef69303e), [`0130986`](https://github.com/mastra-ai/mastra/commit/0130986fc62d0edcc626dd593282661dbb9af141)]:
39
+ - @mastra/core@0.19.0-alpha.1
40
+
3
41
  ## 0.14.3
4
42
 
5
43
  ### Patch Changes
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # @mastra/pg
1
+ # @mastra/libsql
2
2
 
3
3
  SQLite implementation for Mastra, providing both vector similarity search and general storage capabilities with connection pooling and transaction support.
4
4
 
@@ -47,7 +47,7 @@ const results = await vectorStore.query({
47
47
  ### Storage
48
48
 
49
49
  ```typescript
50
- import { LibSQLStore } from '@mastra/pg';
50
+ import { LibSQLStore } from '@mastra/libsql';
51
51
 
52
52
  const store = new LibSQLStore({
53
53
  url: 'file:./my-db.db',
package/dist/index.cjs CHANGED
@@ -7,6 +7,7 @@ var vector = require('@mastra/core/vector');
7
7
  var filter = require('@mastra/core/vector/filter');
8
8
  var storage = require('@mastra/core/storage');
9
9
  var agent = require('@mastra/core/agent');
10
+ var scores = require('@mastra/core/scores');
10
11
 
11
12
  // src/vector/index.ts
12
13
  var LibSQLFilterTranslator = class extends filter.BaseFilterTranslator {
@@ -1951,7 +1952,13 @@ var ObservabilityLibSQL = class extends storage.ObservabilityStorage {
1951
1952
  }
1952
1953
  async createAISpan(span) {
1953
1954
  try {
1954
- return this.operations.insert({ tableName: storage.TABLE_AI_SPANS, record: span });
1955
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1956
+ const record = {
1957
+ ...span,
1958
+ createdAt: now,
1959
+ updatedAt: now
1960
+ };
1961
+ return this.operations.insert({ tableName: storage.TABLE_AI_SPANS, record });
1955
1962
  } catch (error$1) {
1956
1963
  throw new error.MastraError(
1957
1964
  {
@@ -2125,12 +2132,13 @@ var ObservabilityLibSQL = class extends storage.ObservabilityStorage {
2125
2132
  }
2126
2133
  async batchCreateAISpans(args) {
2127
2134
  try {
2135
+ const now = (/* @__PURE__ */ new Date()).toISOString();
2128
2136
  return this.operations.batchInsert({
2129
2137
  tableName: storage.TABLE_AI_SPANS,
2130
2138
  records: args.records.map((record) => ({
2131
2139
  ...record,
2132
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
2133
- updatedAt: (/* @__PURE__ */ new Date()).toISOString()
2140
+ createdAt: now,
2141
+ updatedAt: now
2134
2142
  }))
2135
2143
  });
2136
2144
  } catch (error$1) {
@@ -2671,6 +2679,7 @@ var ScoresLibSQL = class extends storage.ScoresStorage {
2671
2679
  return {
2672
2680
  id: row.id,
2673
2681
  traceId: row.traceId,
2682
+ spanId: row.spanId,
2674
2683
  runId: row.runId,
2675
2684
  scorer: scorerValue,
2676
2685
  score: row.score,
@@ -2705,6 +2714,26 @@ var ScoresLibSQL = class extends storage.ScoresStorage {
2705
2714
  return result.rows?.[0] ? this.transformScoreRow(result.rows[0]) : null;
2706
2715
  }
2707
2716
  async saveScore(score) {
2717
+ let parsedScore;
2718
+ try {
2719
+ parsedScore = scores.saveScorePayloadSchema.parse(score);
2720
+ } catch (error$1) {
2721
+ throw new error.MastraError(
2722
+ {
2723
+ id: "LIBSQL_STORE_SAVE_SCORE_FAILED_INVALID_SCORE_PAYLOAD",
2724
+ domain: error.ErrorDomain.STORAGE,
2725
+ category: error.ErrorCategory.USER,
2726
+ details: {
2727
+ scorer: score.scorer.name,
2728
+ entityId: score.entityId,
2729
+ entityType: score.entityType,
2730
+ traceId: score.traceId || "",
2731
+ spanId: score.spanId || ""
2732
+ }
2733
+ },
2734
+ error$1
2735
+ );
2736
+ }
2708
2737
  try {
2709
2738
  const id = crypto.randomUUID();
2710
2739
  await this.operations.insert({
@@ -2713,7 +2742,7 @@ var ScoresLibSQL = class extends storage.ScoresStorage {
2713
2742
  id,
2714
2743
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
2715
2744
  updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
2716
- ...score
2745
+ ...parsedScore
2717
2746
  }
2718
2747
  });
2719
2748
  const scoreFromDb = await this.getScoreById({ id });
@@ -2759,6 +2788,43 @@ var ScoresLibSQL = class extends storage.ScoresStorage {
2759
2788
  );
2760
2789
  }
2761
2790
  }
2791
+ async getScoresBySpan({
2792
+ traceId,
2793
+ spanId,
2794
+ pagination
2795
+ }) {
2796
+ try {
2797
+ const countSQLResult = await this.client.execute({
2798
+ sql: `SELECT COUNT(*) as count FROM ${storage.TABLE_SCORERS} WHERE traceId = ? AND spanId = ?`,
2799
+ args: [traceId, spanId]
2800
+ });
2801
+ const total = Number(countSQLResult.rows?.[0]?.count ?? 0);
2802
+ const result = await this.client.execute({
2803
+ sql: `SELECT * FROM ${storage.TABLE_SCORERS} WHERE traceId = ? AND spanId = ? ORDER BY createdAt DESC LIMIT ? OFFSET ?`,
2804
+ args: [traceId, spanId, pagination.perPage + 1, pagination.page * pagination.perPage]
2805
+ });
2806
+ const hasMore = result.rows?.length > pagination.perPage;
2807
+ const scores = result.rows?.slice(0, pagination.perPage).map((row) => this.transformScoreRow(row)) ?? [];
2808
+ return {
2809
+ scores,
2810
+ pagination: {
2811
+ total,
2812
+ page: pagination.page,
2813
+ perPage: pagination.perPage,
2814
+ hasMore
2815
+ }
2816
+ };
2817
+ } catch (error$1) {
2818
+ throw new error.MastraError(
2819
+ {
2820
+ id: "LIBSQL_STORE_GET_SCORES_BY_SPAN_FAILED",
2821
+ domain: error.ErrorDomain.STORAGE,
2822
+ category: error.ErrorCategory.THIRD_PARTY
2823
+ },
2824
+ error$1
2825
+ );
2826
+ }
2827
+ }
2762
2828
  };
2763
2829
  var TracesLibSQL = class extends storage.TracesStorage {
2764
2830
  client;
@@ -3248,7 +3314,8 @@ var LibSQLStore = class extends storage.MastraStorage {
3248
3314
  hasColumn: true,
3249
3315
  createTable: true,
3250
3316
  deleteMessages: true,
3251
- aiTracing: true
3317
+ aiTracing: true,
3318
+ getScoresBySpan: true
3252
3319
  };
3253
3320
  }
3254
3321
  async createTable({
@@ -3461,6 +3528,13 @@ var LibSQLStore = class extends storage.MastraStorage {
3461
3528
  async getAITracesPaginated(args) {
3462
3529
  return this.stores.observability.getAITracesPaginated(args);
3463
3530
  }
3531
+ async getScoresBySpan({
3532
+ traceId,
3533
+ spanId,
3534
+ pagination
3535
+ }) {
3536
+ return this.stores.scores.getScoresBySpan({ traceId, spanId, pagination });
3537
+ }
3464
3538
  async batchCreateAISpans(args) {
3465
3539
  return this.stores.observability.batchCreateAISpans(args);
3466
3540
  }