@mastra/cloudflare 0.12.2 → 0.12.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,16 @@
1
1
  # @mastra/cloudflare
2
2
 
3
+ ## 0.12.3-alpha.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Update peer deps ([#8154](https://github.com/mastra-ai/mastra/pull/8154))
8
+
9
+ - Cloudflare support to fetch scores by traceId and spanId ([#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
+
3
14
  ## 0.12.2
4
15
 
5
16
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -4,6 +4,7 @@ var error = require('@mastra/core/error');
4
4
  var storage = require('@mastra/core/storage');
5
5
  var Cloudflare = require('cloudflare');
6
6
  var agent = require('@mastra/core/agent');
7
+ var scores = require('@mastra/core/scores');
7
8
 
8
9
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
10
 
@@ -1620,11 +1621,24 @@ var ScoresStorageCloudflare = class extends storage.ScoresStorage {
1620
1621
  }
1621
1622
  }
1622
1623
  async saveScore(score) {
1624
+ let parsedScore;
1625
+ try {
1626
+ parsedScore = scores.saveScorePayloadSchema.parse(score);
1627
+ } catch (error$1) {
1628
+ throw new error.MastraError(
1629
+ {
1630
+ id: "CLOUDFLARE_STORAGE_SAVE_SCORE_FAILED_INVALID_SCORE_PAYLOAD",
1631
+ domain: error.ErrorDomain.STORAGE,
1632
+ category: error.ErrorCategory.USER,
1633
+ details: { scoreId: score.id }
1634
+ },
1635
+ error$1
1636
+ );
1637
+ }
1623
1638
  try {
1624
1639
  const id = crypto.randomUUID();
1625
- const { input, ...rest } = score;
1626
1640
  const serializedRecord = {};
1627
- for (const [key, value] of Object.entries(rest)) {
1641
+ for (const [key, value] of Object.entries(parsedScore)) {
1628
1642
  if (value !== null && value !== void 0) {
1629
1643
  if (typeof value === "object") {
1630
1644
  serializedRecord[key] = JSON.stringify(value);
@@ -1811,6 +1825,50 @@ var ScoresStorageCloudflare = class extends storage.ScoresStorage {
1811
1825
  return { pagination: { total: 0, page: 0, perPage: 100, hasMore: false }, scores: [] };
1812
1826
  }
1813
1827
  }
1828
+ async getScoresBySpan({
1829
+ traceId,
1830
+ spanId,
1831
+ pagination
1832
+ }) {
1833
+ try {
1834
+ const keys = await this.operations.listKV(storage.TABLE_SCORERS);
1835
+ const scores = [];
1836
+ for (const { name: key } of keys) {
1837
+ const score = await this.operations.getKV(storage.TABLE_SCORERS, key);
1838
+ if (score && score.traceId === traceId && score.spanId === spanId) {
1839
+ scores.push(transformScoreRow(score));
1840
+ }
1841
+ }
1842
+ scores.sort((a, b) => {
1843
+ const dateA = new Date(a.createdAt || 0).getTime();
1844
+ const dateB = new Date(b.createdAt || 0).getTime();
1845
+ return dateB - dateA;
1846
+ });
1847
+ const total = scores.length;
1848
+ const start = pagination.page * pagination.perPage;
1849
+ const end = start + pagination.perPage;
1850
+ const pagedScores = scores.slice(start, end);
1851
+ return {
1852
+ pagination: {
1853
+ total,
1854
+ page: pagination.page,
1855
+ perPage: pagination.perPage,
1856
+ hasMore: end < total
1857
+ },
1858
+ scores: pagedScores
1859
+ };
1860
+ } catch (error$1) {
1861
+ throw new error.MastraError(
1862
+ {
1863
+ id: "CLOUDFLARE_STORAGE_SCORES_GET_SCORES_BY_SPAN_FAILED",
1864
+ domain: error.ErrorDomain.STORAGE,
1865
+ category: error.ErrorCategory.THIRD_PARTY,
1866
+ text: `Failed to get scores by span: traceId=${traceId}, spanId=${spanId}`
1867
+ },
1868
+ error$1
1869
+ );
1870
+ }
1871
+ }
1814
1872
  };
1815
1873
  var TracesStorageCloudflare = class extends storage.TracesStorage {
1816
1874
  operations;
@@ -2201,6 +2259,11 @@ var CloudflareStore = class extends storage.MastraStorage {
2201
2259
  throw new Error("apiToken is required for REST API");
2202
2260
  }
2203
2261
  }
2262
+ get supports() {
2263
+ const supports = super.supports;
2264
+ supports.getScoresBySpan = true;
2265
+ return supports;
2266
+ }
2204
2267
  constructor(config) {
2205
2268
  super({ name: "Cloudflare" });
2206
2269
  try {
@@ -2431,6 +2494,13 @@ var CloudflareStore = class extends storage.MastraStorage {
2431
2494
  }) {
2432
2495
  return this.stores.scores.getScoresByScorerId({ scorerId, entityId, entityType, source, pagination });
2433
2496
  }
2497
+ async getScoresBySpan({
2498
+ traceId,
2499
+ spanId,
2500
+ pagination
2501
+ }) {
2502
+ return this.stores.scores.getScoresBySpan({ traceId, spanId, pagination });
2503
+ }
2434
2504
  async getResourceById({ resourceId }) {
2435
2505
  return this.stores.memory.getResourceById({ resourceId });
2436
2506
  }