@mastra/redis 1.4.13 → 1.4.14-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.
@@ -3,7 +3,7 @@ name: mastra-redis
3
3
  description: Documentation for @mastra/redis. Use when working with @mastra/redis APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/redis"
6
- version: "1.4.13"
6
+ version: "1.4.14-alpha.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,46 +1,46 @@
1
1
  {
2
- "version": "1.4.13",
2
+ "version": "1.4.14-alpha.0",
3
3
  "package": "@mastra/redis",
4
4
  "exports": {
5
5
  "LIST_PUSH_INDEXED_SCRIPT": {
6
6
  "types": "dist/cache.d.ts",
7
7
  "implementation": "dist/index.js",
8
- "line": 1960
8
+ "line": 2018
9
9
  },
10
10
  "RedisServerCache": {
11
11
  "types": "dist/cache.d.ts",
12
12
  "implementation": "dist/index.js",
13
- "line": 1977
13
+ "line": 2035
14
14
  },
15
15
  "RedisStore": {
16
16
  "types": "dist/storage/store.d.ts",
17
17
  "implementation": "dist/index.js",
18
- "line": 1870
18
+ "line": 1928
19
19
  },
20
20
  "ScoresRedis": {
21
21
  "types": "dist/storage/domains/scores/index.d.ts",
22
22
  "implementation": "dist/index.js",
23
- "line": 1300
23
+ "line": 1320
24
24
  },
25
25
  "StoreMemoryRedis": {
26
26
  "types": "dist/storage/domains/memory/index.d.ts",
27
27
  "implementation": "dist/index.js",
28
- "line": 362
28
+ "line": 382
29
29
  },
30
30
  "WorkflowsRedis": {
31
31
  "types": "dist/storage/domains/workflows/index.d.ts",
32
32
  "implementation": "dist/index.js",
33
- "line": 1476
33
+ "line": 1517
34
34
  },
35
35
  "nodeRedisPreset": {
36
36
  "types": "dist/cache.d.ts",
37
37
  "implementation": "dist/index.js",
38
- "line": 2108
38
+ "line": 2166
39
39
  },
40
40
  "upstashPreset": {
41
41
  "types": "dist/cache.d.ts",
42
42
  "implementation": "dist/index.js",
43
- "line": 2100
43
+ "line": 2158
44
44
  }
45
45
  },
46
46
  "modules": {}
package/dist/index.cjs CHANGED
@@ -194,6 +194,8 @@ return 1
194
194
  const READ = `${LIB}
195
195
  return owner(1, now())
196
196
  `;
197
+ /** Single-key reads `getRunOwnerships` keeps in flight, bounding the client's pipeline. */
198
+ const READ_BATCH_SIZE = 500;
197
199
  const RAISE = `
198
200
  local r = redis.call('HMGET', KEYS[1], 'generation', 'ownerId')
199
201
  local current = tonumber(r[1])
@@ -293,6 +295,24 @@ async function releaseRunOwnership(client, fence) {
293
295
  async function getRunOwnership(client, runId) {
294
296
  return (await evalOwner(client, READ, runId, [])).record;
295
297
  }
298
+ /**
299
+ * The ownership records of `runIds`. Each run is its own single-key script call, so the reads stay
300
+ * valid on a clustered server where the keys live in different hash slots; the client pipelines
301
+ * the {@link READ_BATCH_SIZE} calls it sends at once into one round trip.
302
+ */
303
+ async function getRunOwnerships(client, runIds) {
304
+ const records = /* @__PURE__ */ new Map();
305
+ const ids = [...new Set(runIds)];
306
+ for (let start = 0; start < ids.length; start += READ_BATCH_SIZE) {
307
+ const chunk = ids.slice(start, start + READ_BATCH_SIZE);
308
+ const read = await Promise.all(chunk.map((runId) => evalOwner(client, READ, runId, [])));
309
+ chunk.forEach((runId, i) => {
310
+ const record = read[i].record;
311
+ if (record) records.set(runId, record);
312
+ });
313
+ }
314
+ return records;
315
+ }
296
316
  async function raiseRunFence(client, fence) {
297
317
  const raised = await evalScript(client, RAISE, [runClaimKey(_mastra_core_storage.TABLE_MEMORY_RUN_FENCES, fence.runId)], [String(fence.generation), fence.ownerId]);
298
318
  return Number(raised) === 1;
@@ -1458,6 +1478,27 @@ function parseWorkflowRun(row) {
1458
1478
  resourceId: row.resourceId
1459
1479
  };
1460
1480
  }
1481
+ /**
1482
+ * A run with its snapshot reduced to what `listWorkflowRuns({ summary: true })` returns: `status`
1483
+ * and `timestamp` when set, and `parentWorkflow` only when both of its IDs are non-empty strings.
1484
+ * A missing snapshot, or one that failed to parse and stayed a string, reduces to `{}`.
1485
+ */
1486
+ function summarizeWorkflowRun(run) {
1487
+ const { status, timestamp, parentWorkflow } = run.snapshot !== null && typeof run.snapshot === "object" ? run.snapshot : {};
1488
+ const snapshot = {};
1489
+ if (status !== void 0 && status !== null) snapshot.status = status;
1490
+ if (timestamp !== void 0 && timestamp !== null) snapshot.timestamp = timestamp;
1491
+ const workflowId = parentWorkflow?.workflowId;
1492
+ const runId = parentWorkflow?.runId;
1493
+ if (typeof workflowId === "string" && workflowId !== "" && typeof runId === "string" && runId !== "") snapshot.parentWorkflow = {
1494
+ workflowId,
1495
+ runId
1496
+ };
1497
+ return {
1498
+ ...run,
1499
+ snapshot
1500
+ };
1501
+ }
1461
1502
  function escapeGlob(value) {
1462
1503
  return value.replace(/[*?[\]\\]/g, "\\$&");
1463
1504
  }
@@ -1548,6 +1589,19 @@ var WorkflowsRedis = class extends _mastra_core_storage.WorkflowsStorage {
1548
1589
  throw this.#ownershipError("GET_RUN_OWNERSHIP", runId, error);
1549
1590
  }
1550
1591
  }
1592
+ /** Reads the records with single-key script calls the client pipelines, 500 at a time. */
1593
+ async getRunOwnerships({ runIds }) {
1594
+ try {
1595
+ return await getRunOwnerships(this.client, runIds);
1596
+ } catch (error) {
1597
+ throw new _mastra_core_error.MastraError({
1598
+ id: (0, _mastra_core_storage.createStorageErrorId)("REDIS", "GET_RUN_OWNERSHIPS", "FAILED"),
1599
+ domain: _mastra_core_error.ErrorDomain.STORAGE,
1600
+ category: _mastra_core_error.ErrorCategory.THIRD_PARTY,
1601
+ details: { runCount: runIds.length }
1602
+ }, error);
1603
+ }
1604
+ }
1551
1605
  async updateWorkflowResults({ workflowName, runId, stepId, result, requestContext, state, fence }) {
1552
1606
  const resolvedFence = (0, _mastra_core_storage.resolveRunFence)(this, fence, runId);
1553
1607
  try {
@@ -1736,7 +1790,11 @@ var WorkflowsRedis = class extends _mastra_core_storage.WorkflowsStorage {
1736
1790
  }, error);
1737
1791
  }
1738
1792
  }
1739
- async listWorkflowRuns({ workflowName, fromDate, toDate, perPage, page, resourceId, status } = {}) {
1793
+ /**
1794
+ * Lists runs newest first. With `summary`, each snapshot keeps only its status, timestamp and
1795
+ * parent run; the full snapshots are still read from Redis.
1796
+ */
1797
+ async listWorkflowRuns({ workflowName, fromDate, toDate, perPage, page, resourceId, status, summary } = {}) {
1740
1798
  try {
1741
1799
  if (page !== void 0 && page < 0) throw new _mastra_core_error.MastraError({
1742
1800
  id: (0, _mastra_core_storage.createStorageErrorId)("REDIS", "LIST_WORKFLOW_RUNS", "INVALID_PAGE"),
@@ -1791,7 +1849,7 @@ var WorkflowsRedis = class extends _mastra_core_storage.WorkflowsStorage {
1791
1849
  runs = runs.slice(offset, offset + normalizedPerPage);
1792
1850
  }
1793
1851
  return {
1794
- runs,
1852
+ runs: summary ? runs.map(summarizeWorkflowRun) : runs,
1795
1853
  total
1796
1854
  };
1797
1855
  } catch (error) {