@mastra/cloudflare 0.11.5-alpha.0 → 0.11.6

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.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
2
- import { MastraStorage, TABLE_THREADS, TABLE_MESSAGES, TABLE_WORKFLOW_SNAPSHOT, TABLE_EVALS, TABLE_SCORERS, TABLE_TRACES, StoreOperations, serializeDate, ensureDate, LegacyEvalsStorage, WorkflowsStorage, TracesStorage, MemoryStorage, resolveMessageLimit, TABLE_RESOURCES, ScoresStorage } from '@mastra/core/storage';
2
+ import { MastraStorage, TABLE_THREADS, TABLE_MESSAGES, TABLE_WORKFLOW_SNAPSHOT, TABLE_EVALS, TABLE_SCORERS, TABLE_TRACES, StoreOperations, serializeDate, ensureDate, LegacyEvalsStorage, WorkflowsStorage, TracesStorage, MemoryStorage, resolveMessageLimit, TABLE_RESOURCES, ScoresStorage, safelyParseJSON } from '@mastra/core/storage';
3
3
  import Cloudflare from 'cloudflare';
4
4
  import { MessageList } from '@mastra/core/agent';
5
5
 
@@ -1529,18 +1529,17 @@ var StoreOperationsCloudflare = class extends StoreOperations {
1529
1529
  }
1530
1530
  };
1531
1531
  function transformScoreRow(row) {
1532
- let input = void 0;
1533
- if (row.input) {
1534
- try {
1535
- input = JSON.parse(row.input);
1536
- } catch {
1537
- input = row.input;
1538
- }
1539
- }
1540
- return {
1541
- ...row,
1542
- input
1543
- };
1532
+ const deserialized = { ...row };
1533
+ deserialized.input = safelyParseJSON(row.input);
1534
+ deserialized.output = safelyParseJSON(row.output);
1535
+ deserialized.scorer = safelyParseJSON(row.scorer);
1536
+ deserialized.preprocessStepResult = safelyParseJSON(row.preprocessStepResult);
1537
+ deserialized.analyzeStepResult = safelyParseJSON(row.analyzeStepResult);
1538
+ deserialized.metadata = safelyParseJSON(row.metadata);
1539
+ deserialized.additionalContext = safelyParseJSON(row.additionalContext);
1540
+ deserialized.runtimeContext = safelyParseJSON(row.runtimeContext);
1541
+ deserialized.entity = safelyParseJSON(row.entity);
1542
+ return deserialized;
1544
1543
  }
1545
1544
  var ScoresStorageCloudflare = class extends ScoresStorage {
1546
1545
  operations;
@@ -1572,6 +1571,7 @@ var ScoresStorageCloudflare = class extends ScoresStorage {
1572
1571
  }
1573
1572
  async saveScore(score) {
1574
1573
  try {
1574
+ const id = crypto.randomUUID();
1575
1575
  const { input, ...rest } = score;
1576
1576
  const serializedRecord = {};
1577
1577
  for (const [key, value] of Object.entries(rest)) {
@@ -1585,12 +1585,12 @@ var ScoresStorageCloudflare = class extends ScoresStorage {
1585
1585
  serializedRecord[key] = null;
1586
1586
  }
1587
1587
  }
1588
- serializedRecord.input = JSON.stringify(input);
1588
+ serializedRecord.id = id;
1589
1589
  serializedRecord.createdAt = (/* @__PURE__ */ new Date()).toISOString();
1590
1590
  serializedRecord.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
1591
1591
  await this.operations.putKV({
1592
1592
  tableName: TABLE_SCORERS,
1593
- key: score.id,
1593
+ key: id,
1594
1594
  value: serializedRecord
1595
1595
  });
1596
1596
  const scoreFromDb = await this.getScoreById({ id: score.id });
@@ -1612,6 +1612,9 @@ var ScoresStorageCloudflare = class extends ScoresStorage {
1612
1612
  }
1613
1613
  async getScoresByScorerId({
1614
1614
  scorerId,
1615
+ entityId,
1616
+ entityType,
1617
+ source,
1615
1618
  pagination
1616
1619
  }) {
1617
1620
  try {
@@ -1619,6 +1622,15 @@ var ScoresStorageCloudflare = class extends ScoresStorage {
1619
1622
  const scores = [];
1620
1623
  for (const { name: key } of keys) {
1621
1624
  const score = await this.operations.getKV(TABLE_SCORERS, key);
1625
+ if (entityId && score.entityId !== entityId) {
1626
+ continue;
1627
+ }
1628
+ if (entityType && score.entityType !== entityType) {
1629
+ continue;
1630
+ }
1631
+ if (source && score.source !== source) {
1632
+ continue;
1633
+ }
1622
1634
  if (score && score.scorerId === scorerId) {
1623
1635
  scores.push(transformScoreRow(score));
1624
1636
  }
@@ -2323,9 +2335,12 @@ var CloudflareStore = class extends MastraStorage {
2323
2335
  }
2324
2336
  async getScoresByScorerId({
2325
2337
  scorerId,
2338
+ entityId,
2339
+ entityType,
2340
+ source,
2326
2341
  pagination
2327
2342
  }) {
2328
- return this.stores.scores.getScoresByScorerId({ scorerId, pagination });
2343
+ return this.stores.scores.getScoresByScorerId({ scorerId, entityId, entityType, source, pagination });
2329
2344
  }
2330
2345
  async getResourceById({ resourceId }) {
2331
2346
  return this.stores.memory.getResourceById({ resourceId });