@mastra/cloudflare-d1 0.13.2-alpha.0 → 0.13.3-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 CHANGED
@@ -1,5 +1,25 @@
1
1
  # @mastra/cloudflare-d1
2
2
 
3
+ ## 0.13.3-alpha.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Update peer deps ([#8154](https://github.com/mastra-ai/mastra/pull/8154))
8
+
9
+ - Cloudflare D1 support fetch scores by trace and span id ([#8154](https://github.com/mastra-ai/mastra/pull/8154))
10
+
11
+ - 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)]:
12
+ - @mastra/core@0.19.0-alpha.1
13
+
14
+ ## 0.13.2
15
+
16
+ ### Patch Changes
17
+
18
+ - Update Peerdeps for packages based on core minor bump ([#8025](https://github.com/mastra-ai/mastra/pull/8025))
19
+
20
+ - Updated dependencies [[`cf34503`](https://github.com/mastra-ai/mastra/commit/cf345031de4e157f29087946449e60b965e9c8a9), [`6b4b1e4`](https://github.com/mastra-ai/mastra/commit/6b4b1e4235428d39e51cbda9832704c0ba70ab32), [`3469fca`](https://github.com/mastra-ai/mastra/commit/3469fca7bb7e5e19369ff9f7044716a5e4b02585), [`a61f23f`](https://github.com/mastra-ai/mastra/commit/a61f23fbbca4b88b763d94f1d784c47895ed72d7), [`4b339b8`](https://github.com/mastra-ai/mastra/commit/4b339b8141c20d6a6d80583c7e8c5c05d8c19492), [`d1dc606`](https://github.com/mastra-ai/mastra/commit/d1dc6067b0557a71190b68d56ee15b48c26d2411), [`c45298a`](https://github.com/mastra-ai/mastra/commit/c45298a0a0791db35cf79f1199d77004da0704cb), [`c4a8204`](https://github.com/mastra-ai/mastra/commit/c4a82046bfd241d6044e234bc5917d5a01fe6b55), [`d3bd4d4`](https://github.com/mastra-ai/mastra/commit/d3bd4d482a685bbb67bfa89be91c90dca3fa71ad), [`c591dfc`](https://github.com/mastra-ai/mastra/commit/c591dfc1e600fae1dedffe239357d250e146378f), [`1920c5c`](https://github.com/mastra-ai/mastra/commit/1920c5c6d666f687785c73021196aa551e579e0d), [`b6a3b65`](https://github.com/mastra-ai/mastra/commit/b6a3b65d830fa0ca7754ad6481661d1f2c878f21), [`af3abb6`](https://github.com/mastra-ai/mastra/commit/af3abb6f7c7585d856e22d27f4e7d2ece2186b9a)]:
21
+ - @mastra/core@0.18.0
22
+
3
23
  ## 0.13.2-alpha.0
4
24
 
5
25
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -5,6 +5,7 @@ var storage = require('@mastra/core/storage');
5
5
  var Cloudflare = require('cloudflare');
6
6
  var utils = require('@mastra/core/utils');
7
7
  var agent = require('@mastra/core/agent');
8
+ var scores = require('@mastra/core/scores');
8
9
 
9
10
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
10
11
 
@@ -1615,12 +1616,25 @@ var ScoresStorageD1 = class extends storage.ScoresStorage {
1615
1616
  }
1616
1617
  }
1617
1618
  async saveScore(score) {
1619
+ let parsedScore;
1620
+ try {
1621
+ parsedScore = scores.saveScorePayloadSchema.parse(score);
1622
+ } catch (error$1) {
1623
+ throw new error.MastraError(
1624
+ {
1625
+ id: "CLOUDFLARE_D1_STORE_SCORES_SAVE_SCORE_FAILED_INVALID_SCORE_PAYLOAD",
1626
+ domain: error.ErrorDomain.STORAGE,
1627
+ category: error.ErrorCategory.USER,
1628
+ details: { scoreId: score.id }
1629
+ },
1630
+ error$1
1631
+ );
1632
+ }
1618
1633
  try {
1619
1634
  const id = crypto.randomUUID();
1620
1635
  const fullTableName = this.operations.getTableName(storage.TABLE_SCORERS);
1621
- const { input, ...rest } = score;
1622
1636
  const serializedRecord = {};
1623
- for (const [key, value] of Object.entries(rest)) {
1637
+ for (const [key, value] of Object.entries(parsedScore)) {
1624
1638
  if (value !== null && value !== void 0) {
1625
1639
  if (typeof value === "object") {
1626
1640
  serializedRecord[key] = JSON.stringify(value);
@@ -1632,7 +1646,6 @@ var ScoresStorageD1 = class extends storage.ScoresStorage {
1632
1646
  }
1633
1647
  }
1634
1648
  serializedRecord.id = id;
1635
- serializedRecord.input = JSON.stringify(input);
1636
1649
  serializedRecord.createdAt = (/* @__PURE__ */ new Date()).toISOString();
1637
1650
  serializedRecord.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
1638
1651
  const columns = Object.keys(serializedRecord);
@@ -1808,6 +1821,53 @@ var ScoresStorageD1 = class extends storage.ScoresStorage {
1808
1821
  );
1809
1822
  }
1810
1823
  }
1824
+ async getScoresBySpan({
1825
+ traceId,
1826
+ spanId,
1827
+ pagination
1828
+ }) {
1829
+ try {
1830
+ const fullTableName = this.operations.getTableName(storage.TABLE_SCORERS);
1831
+ const countQuery = createSqlBuilder().count().from(fullTableName).where("traceId = ?", traceId).andWhere("spanId = ?", spanId);
1832
+ const countResult = await this.operations.executeQuery(countQuery.build());
1833
+ const total = Array.isArray(countResult) ? Number(countResult?.[0]?.count ?? 0) : Number(countResult?.count ?? 0);
1834
+ if (total === 0) {
1835
+ return {
1836
+ pagination: {
1837
+ total: 0,
1838
+ page: pagination.page,
1839
+ perPage: pagination.perPage,
1840
+ hasMore: false
1841
+ },
1842
+ scores: []
1843
+ };
1844
+ }
1845
+ const limit = pagination.perPage + 1;
1846
+ const selectQuery = createSqlBuilder().select("*").from(fullTableName).where("traceId = ?", traceId).andWhere("spanId = ?", spanId).orderBy("createdAt", "DESC").limit(limit).offset(pagination.page * pagination.perPage);
1847
+ const { sql, params } = selectQuery.build();
1848
+ const results = await this.operations.executeQuery({ sql, params });
1849
+ const rows = Array.isArray(results) ? results : [];
1850
+ const scores = rows.slice(0, pagination.perPage).map(transformScoreRow);
1851
+ return {
1852
+ pagination: {
1853
+ total,
1854
+ page: pagination.page,
1855
+ perPage: pagination.perPage,
1856
+ hasMore: rows.length > pagination.perPage
1857
+ },
1858
+ scores
1859
+ };
1860
+ } catch (error$1) {
1861
+ throw new error.MastraError(
1862
+ {
1863
+ id: "CLOUDFLARE_D1_STORE_SCORES_GET_SCORES_BY_SPAN_FAILED",
1864
+ domain: error.ErrorDomain.STORAGE,
1865
+ category: error.ErrorCategory.THIRD_PARTY
1866
+ },
1867
+ error$1
1868
+ );
1869
+ }
1870
+ }
1811
1871
  };
1812
1872
  function isArrayOfRecords2(value) {
1813
1873
  return value && Array.isArray(value) && value.length > 0;
@@ -2239,7 +2299,8 @@ var D1Store = class extends storage.MastraStorage {
2239
2299
  resourceWorkingMemory: true,
2240
2300
  hasColumn: true,
2241
2301
  createTable: true,
2242
- deleteMessages: false
2302
+ deleteMessages: false,
2303
+ getScoresBySpan: true
2243
2304
  };
2244
2305
  }
2245
2306
  async createTable({
@@ -2441,6 +2502,13 @@ var D1Store = class extends storage.MastraStorage {
2441
2502
  }) {
2442
2503
  return this.stores.scores.getScoresByScorerId({ scorerId, pagination, entityId, entityType, source });
2443
2504
  }
2505
+ async getScoresBySpan({
2506
+ traceId,
2507
+ spanId,
2508
+ pagination
2509
+ }) {
2510
+ return this.stores.scores.getScoresBySpan({ traceId, spanId, pagination });
2511
+ }
2444
2512
  /**
2445
2513
  * Close the database connection
2446
2514
  * No explicit cleanup needed for D1 in either REST or Workers Binding mode