@mastra/upstash 1.0.2 → 1.0.3

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,27 @@
1
1
  # @mastra/upstash
2
2
 
3
+ ## 1.0.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Added atomic `updateWorkflowResults` and `updateWorkflowState` to safely merge concurrent step results into workflow snapshots. ([#12575](https://github.com/mastra-ai/mastra/pull/12575))
8
+
9
+ - Added `insertObservationalMemoryRecord()` to PostgreSQL, LibSQL, MongoDB, and Upstash adapters for OM cloning support. ([#13569](https://github.com/mastra-ai/mastra/pull/13569))
10
+
11
+ - Updated dependencies [[`504fc8b`](https://github.com/mastra-ai/mastra/commit/504fc8b9d0ddab717577ad3bf9c95ea4bd5377bd), [`f9c150b`](https://github.com/mastra-ai/mastra/commit/f9c150b7595ad05ad9cc9a11098e2944361e8c22), [`88de7e8`](https://github.com/mastra-ai/mastra/commit/88de7e8dfe4b7e1951a9e441bb33136e705ce24e), [`edee4b3`](https://github.com/mastra-ai/mastra/commit/edee4b37dff0af515fc7cc0e8d71ee39e6a762f0), [`3790c75`](https://github.com/mastra-ai/mastra/commit/3790c7578cc6a47d854eb12d89e6b1912867fe29), [`e7a235b`](https://github.com/mastra-ai/mastra/commit/e7a235be6472e0c870ed6c791ddb17c492dc188b), [`d51d298`](https://github.com/mastra-ai/mastra/commit/d51d298953967aab1f58ec965b644d109214f085), [`6dbeeb9`](https://github.com/mastra-ai/mastra/commit/6dbeeb94a8b1eebb727300d1a98961f882180794), [`d5f0d8d`](https://github.com/mastra-ai/mastra/commit/d5f0d8d6a03e515ddaa9b5da19b7e44b8357b07b), [`09c3b18`](https://github.com/mastra-ai/mastra/commit/09c3b1802ff14e243a8a8baea327440bc8cc2e32), [`b896379`](https://github.com/mastra-ai/mastra/commit/b8963791c6afa79484645fcec596a201f936b9a2), [`85c84eb`](https://github.com/mastra-ai/mastra/commit/85c84ebb78aebfcba9d209c8e152b16d7a00cb71), [`a89272a`](https://github.com/mastra-ai/mastra/commit/a89272a5d71939b9fcd284e6a6dc1dd091a6bdcf), [`ee9c8df`](https://github.com/mastra-ai/mastra/commit/ee9c8df644f19d055af5f496bf4942705f5a47b7), [`77b4a25`](https://github.com/mastra-ai/mastra/commit/77b4a254e51907f8ff3a3ba95596a18e93ae4b35), [`276246e`](https://github.com/mastra-ai/mastra/commit/276246e0b9066a1ea48bbc70df84dbe528daaf99), [`08ecfdb`](https://github.com/mastra-ai/mastra/commit/08ecfdbdad6fb8285deef86a034bdf4a6047cfca), [`d5f628c`](https://github.com/mastra-ai/mastra/commit/d5f628ca86c6f6f3ff1035d52f635df32dd81cab), [`524c0f3`](https://github.com/mastra-ai/mastra/commit/524c0f3c434c3d9d18f66338dcef383d6161b59c), [`c18a0e9`](https://github.com/mastra-ai/mastra/commit/c18a0e9cef1e4ca004b2963d35e4cfc031971eac), [`4bd21ea`](https://github.com/mastra-ai/mastra/commit/4bd21ea43d44d0a0427414fc047577f9f0aa3bec), [`115a7a4`](https://github.com/mastra-ai/mastra/commit/115a7a47db5e9896fec12ae6507501adb9ec89bf), [`22a48ae`](https://github.com/mastra-ai/mastra/commit/22a48ae2513eb54d8d79dad361fddbca97a155e8), [`3c6ef79`](https://github.com/mastra-ai/mastra/commit/3c6ef798481e00d6d22563be2de98818fd4dd5e0), [`9311c17`](https://github.com/mastra-ai/mastra/commit/9311c17d7a0640d9c4da2e71b814dc67c57c6369), [`7edf78f`](https://github.com/mastra-ai/mastra/commit/7edf78f80422c43e84585f08ba11df0d4d0b73c5), [`1c4221c`](https://github.com/mastra-ai/mastra/commit/1c4221cf6032ec98d0e094d4ee11da3e48490d96), [`d25b9ea`](https://github.com/mastra-ai/mastra/commit/d25b9eabd400167255a97b690ffbc4ee4097ded5), [`fe1ce5c`](https://github.com/mastra-ai/mastra/commit/fe1ce5c9211c03d561606fda95cbfe7df1d9a9b5), [`b03c0e0`](https://github.com/mastra-ai/mastra/commit/b03c0e0389a799523929a458b0509c9e4244d562), [`0a8366b`](https://github.com/mastra-ai/mastra/commit/0a8366b0a692fcdde56c4d526e4cf03c502ae4ac), [`85664e9`](https://github.com/mastra-ai/mastra/commit/85664e9fd857320fbc245e301f764f45f66f32a3), [`bc79650`](https://github.com/mastra-ai/mastra/commit/bc796500c6e0334faa158a96077e3fb332274869), [`9257d01`](https://github.com/mastra-ai/mastra/commit/9257d01d1366d81f84c582fe02b5e200cf9621f4), [`3a3a59e`](https://github.com/mastra-ai/mastra/commit/3a3a59e8ffaa6a985fe3d9a126a3f5ade11a6724), [`3108d4e`](https://github.com/mastra-ai/mastra/commit/3108d4e649c9fddbf03253a6feeb388a5fa9fa5a), [`0c33b2c`](https://github.com/mastra-ai/mastra/commit/0c33b2c9db537f815e1c59e2c898ffce2e395a79), [`191e5bd`](https://github.com/mastra-ai/mastra/commit/191e5bd29b82f5bda35243945790da7bc7b695c2), [`f77cd94`](https://github.com/mastra-ai/mastra/commit/f77cd94c44eabed490384e7d19232a865e13214c), [`e8135c7`](https://github.com/mastra-ai/mastra/commit/e8135c7e300dac5040670eec7eab896ac6092e30), [`daca48f`](https://github.com/mastra-ai/mastra/commit/daca48f0fb17b7ae0b62a2ac40cf0e491b2fd0b7), [`257d14f`](https://github.com/mastra-ai/mastra/commit/257d14faca5931f2e4186fc165b6f0b1f915deee), [`352f25d`](https://github.com/mastra-ai/mastra/commit/352f25da316b24cdd5b410fd8dddf6a8b763da2a), [`93477d0`](https://github.com/mastra-ai/mastra/commit/93477d0769b8a13ea5ed73d508d967fb23eaeed9), [`31c78b3`](https://github.com/mastra-ai/mastra/commit/31c78b3eb28f58a8017f1dcc795c33214d87feac), [`0bc0720`](https://github.com/mastra-ai/mastra/commit/0bc07201095791858087cc56f353fcd65e87ab54), [`36516ac`](https://github.com/mastra-ai/mastra/commit/36516aca1021cbeb42e74751b46a2614101f37c8), [`e947652`](https://github.com/mastra-ai/mastra/commit/e9476527fdecb4449e54570e80dfaf8466901254), [`3c6ef79`](https://github.com/mastra-ai/mastra/commit/3c6ef798481e00d6d22563be2de98818fd4dd5e0), [`9257d01`](https://github.com/mastra-ai/mastra/commit/9257d01d1366d81f84c582fe02b5e200cf9621f4), [`ec248f6`](https://github.com/mastra-ai/mastra/commit/ec248f6b56e8a037c066c49b2178e2507471d988)]:
12
+ - @mastra/core@1.9.0
13
+
14
+ ## 1.0.3-alpha.0
15
+
16
+ ### Patch Changes
17
+
18
+ - Added atomic `updateWorkflowResults` and `updateWorkflowState` to safely merge concurrent step results into workflow snapshots. ([#12575](https://github.com/mastra-ai/mastra/pull/12575))
19
+
20
+ - Added `insertObservationalMemoryRecord()` to PostgreSQL, LibSQL, MongoDB, and Upstash adapters for OM cloning support. ([#13569](https://github.com/mastra-ai/mastra/pull/13569))
21
+
22
+ - Updated dependencies [[`504fc8b`](https://github.com/mastra-ai/mastra/commit/504fc8b9d0ddab717577ad3bf9c95ea4bd5377bd), [`f9c150b`](https://github.com/mastra-ai/mastra/commit/f9c150b7595ad05ad9cc9a11098e2944361e8c22), [`88de7e8`](https://github.com/mastra-ai/mastra/commit/88de7e8dfe4b7e1951a9e441bb33136e705ce24e), [`edee4b3`](https://github.com/mastra-ai/mastra/commit/edee4b37dff0af515fc7cc0e8d71ee39e6a762f0), [`3790c75`](https://github.com/mastra-ai/mastra/commit/3790c7578cc6a47d854eb12d89e6b1912867fe29), [`e7a235b`](https://github.com/mastra-ai/mastra/commit/e7a235be6472e0c870ed6c791ddb17c492dc188b), [`d51d298`](https://github.com/mastra-ai/mastra/commit/d51d298953967aab1f58ec965b644d109214f085), [`6dbeeb9`](https://github.com/mastra-ai/mastra/commit/6dbeeb94a8b1eebb727300d1a98961f882180794), [`d5f0d8d`](https://github.com/mastra-ai/mastra/commit/d5f0d8d6a03e515ddaa9b5da19b7e44b8357b07b), [`09c3b18`](https://github.com/mastra-ai/mastra/commit/09c3b1802ff14e243a8a8baea327440bc8cc2e32), [`b896379`](https://github.com/mastra-ai/mastra/commit/b8963791c6afa79484645fcec596a201f936b9a2), [`85c84eb`](https://github.com/mastra-ai/mastra/commit/85c84ebb78aebfcba9d209c8e152b16d7a00cb71), [`a89272a`](https://github.com/mastra-ai/mastra/commit/a89272a5d71939b9fcd284e6a6dc1dd091a6bdcf), [`ee9c8df`](https://github.com/mastra-ai/mastra/commit/ee9c8df644f19d055af5f496bf4942705f5a47b7), [`77b4a25`](https://github.com/mastra-ai/mastra/commit/77b4a254e51907f8ff3a3ba95596a18e93ae4b35), [`276246e`](https://github.com/mastra-ai/mastra/commit/276246e0b9066a1ea48bbc70df84dbe528daaf99), [`08ecfdb`](https://github.com/mastra-ai/mastra/commit/08ecfdbdad6fb8285deef86a034bdf4a6047cfca), [`d5f628c`](https://github.com/mastra-ai/mastra/commit/d5f628ca86c6f6f3ff1035d52f635df32dd81cab), [`524c0f3`](https://github.com/mastra-ai/mastra/commit/524c0f3c434c3d9d18f66338dcef383d6161b59c), [`c18a0e9`](https://github.com/mastra-ai/mastra/commit/c18a0e9cef1e4ca004b2963d35e4cfc031971eac), [`4bd21ea`](https://github.com/mastra-ai/mastra/commit/4bd21ea43d44d0a0427414fc047577f9f0aa3bec), [`115a7a4`](https://github.com/mastra-ai/mastra/commit/115a7a47db5e9896fec12ae6507501adb9ec89bf), [`22a48ae`](https://github.com/mastra-ai/mastra/commit/22a48ae2513eb54d8d79dad361fddbca97a155e8), [`3c6ef79`](https://github.com/mastra-ai/mastra/commit/3c6ef798481e00d6d22563be2de98818fd4dd5e0), [`9311c17`](https://github.com/mastra-ai/mastra/commit/9311c17d7a0640d9c4da2e71b814dc67c57c6369), [`7edf78f`](https://github.com/mastra-ai/mastra/commit/7edf78f80422c43e84585f08ba11df0d4d0b73c5), [`1c4221c`](https://github.com/mastra-ai/mastra/commit/1c4221cf6032ec98d0e094d4ee11da3e48490d96), [`d25b9ea`](https://github.com/mastra-ai/mastra/commit/d25b9eabd400167255a97b690ffbc4ee4097ded5), [`fe1ce5c`](https://github.com/mastra-ai/mastra/commit/fe1ce5c9211c03d561606fda95cbfe7df1d9a9b5), [`b03c0e0`](https://github.com/mastra-ai/mastra/commit/b03c0e0389a799523929a458b0509c9e4244d562), [`0a8366b`](https://github.com/mastra-ai/mastra/commit/0a8366b0a692fcdde56c4d526e4cf03c502ae4ac), [`85664e9`](https://github.com/mastra-ai/mastra/commit/85664e9fd857320fbc245e301f764f45f66f32a3), [`bc79650`](https://github.com/mastra-ai/mastra/commit/bc796500c6e0334faa158a96077e3fb332274869), [`9257d01`](https://github.com/mastra-ai/mastra/commit/9257d01d1366d81f84c582fe02b5e200cf9621f4), [`3a3a59e`](https://github.com/mastra-ai/mastra/commit/3a3a59e8ffaa6a985fe3d9a126a3f5ade11a6724), [`3108d4e`](https://github.com/mastra-ai/mastra/commit/3108d4e649c9fddbf03253a6feeb388a5fa9fa5a), [`0c33b2c`](https://github.com/mastra-ai/mastra/commit/0c33b2c9db537f815e1c59e2c898ffce2e395a79), [`191e5bd`](https://github.com/mastra-ai/mastra/commit/191e5bd29b82f5bda35243945790da7bc7b695c2), [`f77cd94`](https://github.com/mastra-ai/mastra/commit/f77cd94c44eabed490384e7d19232a865e13214c), [`e8135c7`](https://github.com/mastra-ai/mastra/commit/e8135c7e300dac5040670eec7eab896ac6092e30), [`daca48f`](https://github.com/mastra-ai/mastra/commit/daca48f0fb17b7ae0b62a2ac40cf0e491b2fd0b7), [`257d14f`](https://github.com/mastra-ai/mastra/commit/257d14faca5931f2e4186fc165b6f0b1f915deee), [`352f25d`](https://github.com/mastra-ai/mastra/commit/352f25da316b24cdd5b410fd8dddf6a8b763da2a), [`93477d0`](https://github.com/mastra-ai/mastra/commit/93477d0769b8a13ea5ed73d508d967fb23eaeed9), [`31c78b3`](https://github.com/mastra-ai/mastra/commit/31c78b3eb28f58a8017f1dcc795c33214d87feac), [`0bc0720`](https://github.com/mastra-ai/mastra/commit/0bc07201095791858087cc56f353fcd65e87ab54), [`36516ac`](https://github.com/mastra-ai/mastra/commit/36516aca1021cbeb42e74751b46a2614101f37c8), [`e947652`](https://github.com/mastra-ai/mastra/commit/e9476527fdecb4449e54570e80dfaf8466901254), [`3c6ef79`](https://github.com/mastra-ai/mastra/commit/3c6ef798481e00d6d22563be2de98818fd4dd5e0), [`9257d01`](https://github.com/mastra-ai/mastra/commit/9257d01d1366d81f84c582fe02b5e200cf9621f4), [`ec248f6`](https://github.com/mastra-ai/mastra/commit/ec248f6b56e8a037c066c49b2178e2507471d988)]:
23
+ - @mastra/core@1.9.0-alpha.0
24
+
3
25
  ## 1.0.2
4
26
 
5
27
  ### Patch Changes
package/LICENSE.md CHANGED
@@ -1,3 +1,18 @@
1
+ Portions of this software are licensed as follows:
2
+
3
+ - All content that resides under any directory named "ee/" within this
4
+ repository, including but not limited to:
5
+ - `packages/core/src/auth/ee/`
6
+ - `packages/server/src/server/auth/ee/`
7
+ is licensed under the license defined in `ee/LICENSE`.
8
+
9
+ - All third-party components incorporated into the Mastra Software are
10
+ licensed under the original license provided by the owner of the
11
+ applicable component.
12
+
13
+ - Content outside of the above-mentioned directories or restrictions is
14
+ available under the "Apache License 2.0" as defined below.
15
+
1
16
  # Apache License 2.0
2
17
 
3
18
  Copyright (c) 2025 Kepler Software, Inc.
@@ -3,7 +3,7 @@ name: mastra-upstash
3
3
  description: Documentation for @mastra/upstash. Use when working with @mastra/upstash APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/upstash"
6
- version: "1.0.2"
6
+ version: "1.0.3"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.2",
2
+ "version": "1.0.3",
3
3
  "package": "@mastra/upstash",
4
4
  "exports": {},
5
5
  "modules": {}
package/dist/index.cjs CHANGED
@@ -1092,11 +1092,13 @@ var StoreMemoryUpstash = class extends storage.MemoryStorage {
1092
1092
  const threadKey = getKey(storage.TABLE_THREADS, { id: newThreadId });
1093
1093
  writePipeline.set(threadKey, processRecord(storage.TABLE_THREADS, newThread).processedRecord);
1094
1094
  const clonedMessages = [];
1095
+ const messageIdMap = {};
1095
1096
  const targetResourceId = resourceId || sourceThread.resourceId;
1096
1097
  const newThreadMessagesKey = getThreadMessagesKey(newThreadId);
1097
1098
  for (let i = 0; i < sourceMessages.length; i++) {
1098
1099
  const sourceMsg = sourceMessages[i];
1099
1100
  const newMessageId = crypto.randomUUID();
1101
+ messageIdMap[sourceMsg.id] = newMessageId;
1100
1102
  const { _index, ...restMsg } = sourceMsg;
1101
1103
  const newMessage = {
1102
1104
  ...restMsg,
@@ -1116,7 +1118,8 @@ var StoreMemoryUpstash = class extends storage.MemoryStorage {
1116
1118
  await writePipeline.exec();
1117
1119
  return {
1118
1120
  thread: newThread,
1119
- clonedMessages
1121
+ clonedMessages,
1122
+ messageIdMap
1120
1123
  };
1121
1124
  } catch (error$1) {
1122
1125
  if (error$1 instanceof error.MastraError) {
@@ -1422,6 +1425,9 @@ var WorkflowsUpstash = class extends storage.WorkflowsStorage {
1422
1425
  this.client = client;
1423
1426
  this.#db = new UpstashDB({ client });
1424
1427
  }
1428
+ supportsConcurrentUpdates() {
1429
+ return true;
1430
+ }
1425
1431
  parseWorkflowRun(row) {
1426
1432
  let parsedSnapshot = row.snapshot;
1427
1433
  if (typeof parsedSnapshot === "string") {
@@ -1451,38 +1457,108 @@ var WorkflowsUpstash = class extends storage.WorkflowsStorage {
1451
1457
  requestContext
1452
1458
  }) {
1453
1459
  try {
1454
- const existingSnapshot = await this.loadWorkflowSnapshot({
1460
+ const key = getKey(storage.TABLE_WORKFLOW_SNAPSHOT, {
1455
1461
  namespace: "workflows",
1456
- workflowName,
1457
- runId
1462
+ workflow_name: workflowName,
1463
+ run_id: runId
1458
1464
  });
1459
- let snapshot;
1460
- if (!existingSnapshot) {
1461
- snapshot = {
1462
- context: {},
1463
- activePaths: [],
1464
- timestamp: Date.now(),
1465
- suspendedPaths: {},
1466
- activeStepsPath: {},
1467
- resumeLabels: {},
1468
- serializedStepGraph: [],
1469
- status: "pending",
1470
- value: {},
1471
- waitingPaths: {},
1465
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1466
+ const luaScript = `
1467
+ local key = KEYS[1]
1468
+ local stepId = ARGV[1]
1469
+ local resultJson = ARGV[2]
1470
+ local requestContextJson = ARGV[3]
1471
+ local now = ARGV[4]
1472
+ local namespace = ARGV[5]
1473
+ local workflowName = ARGV[6]
1474
+ local runId = ARGV[7]
1475
+ local timestamp = tonumber(ARGV[8])
1476
+
1477
+ -- Get existing data
1478
+ local existing = redis.call('GET', key)
1479
+ local data
1480
+ local snapshot
1481
+
1482
+ if existing then
1483
+ data = cjson.decode(existing)
1484
+ snapshot = data.snapshot
1485
+ if type(snapshot) == 'string' then
1486
+ snapshot = cjson.decode(snapshot)
1487
+ end
1488
+ else
1489
+ -- Create new record with default snapshot
1490
+ snapshot = {
1491
+ context = {},
1492
+ activePaths = {},
1493
+ timestamp = timestamp,
1494
+ suspendedPaths = {},
1495
+ activeStepsPath = {},
1496
+ resumeLabels = {},
1497
+ serializedStepGraph = {},
1498
+ status = 'pending',
1499
+ value = {},
1500
+ waitingPaths = {},
1501
+ runId = runId,
1502
+ requestContext = {}
1503
+ }
1504
+ data = {
1505
+ namespace = namespace,
1506
+ workflow_name = workflowName,
1507
+ run_id = runId,
1508
+ createdAt = now,
1509
+ updatedAt = now
1510
+ }
1511
+ end
1512
+
1513
+ -- Initialize context if nil
1514
+ if snapshot.context == nil then
1515
+ snapshot.context = {}
1516
+ end
1517
+
1518
+ -- Merge the new step result
1519
+ local stepResult = cjson.decode(resultJson)
1520
+ snapshot.context[stepId] = stepResult
1521
+
1522
+ -- Merge request context
1523
+ local newRequestContext = cjson.decode(requestContextJson)
1524
+ if snapshot.requestContext == nil then
1525
+ snapshot.requestContext = {}
1526
+ end
1527
+ for k, v in pairs(newRequestContext) do
1528
+ snapshot.requestContext[k] = v
1529
+ end
1530
+
1531
+ -- Update the record
1532
+ data.snapshot = snapshot
1533
+ data.updatedAt = now
1534
+
1535
+ -- Save back
1536
+ redis.call('SET', key, cjson.encode(data))
1537
+
1538
+ -- Return the full updated data
1539
+ return cjson.encode(data)
1540
+ `;
1541
+ const resultJson = await this.client.eval(
1542
+ luaScript,
1543
+ [key],
1544
+ [
1545
+ stepId,
1546
+ JSON.stringify(result),
1547
+ JSON.stringify(requestContext),
1548
+ now,
1549
+ "workflows",
1550
+ workflowName,
1472
1551
  runId,
1473
- requestContext: {}
1474
- };
1552
+ String(Date.now())
1553
+ ]
1554
+ );
1555
+ let data;
1556
+ if (typeof resultJson === "string") {
1557
+ data = JSON.parse(resultJson);
1475
1558
  } else {
1476
- snapshot = existingSnapshot;
1559
+ data = resultJson;
1477
1560
  }
1478
- snapshot.context[stepId] = result;
1479
- snapshot.requestContext = { ...snapshot.requestContext, ...requestContext };
1480
- await this.persistWorkflowSnapshot({
1481
- namespace: "workflows",
1482
- workflowName,
1483
- runId,
1484
- snapshot
1485
- });
1561
+ const snapshot = typeof data.snapshot === "string" ? JSON.parse(data.snapshot) : data.snapshot;
1486
1562
  return snapshot.context;
1487
1563
  } catch (error$1) {
1488
1564
  if (error$1 instanceof error.MastraError) throw error$1;
@@ -1503,22 +1579,63 @@ var WorkflowsUpstash = class extends storage.WorkflowsStorage {
1503
1579
  opts
1504
1580
  }) {
1505
1581
  try {
1506
- const existingSnapshot = await this.loadWorkflowSnapshot({
1582
+ const key = getKey(storage.TABLE_WORKFLOW_SNAPSHOT, {
1507
1583
  namespace: "workflows",
1508
- workflowName,
1509
- runId
1584
+ workflow_name: workflowName,
1585
+ run_id: runId
1510
1586
  });
1511
- if (!existingSnapshot || !existingSnapshot.context) {
1587
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1588
+ const luaScript = `
1589
+ local key = KEYS[1]
1590
+ local optsJson = ARGV[1]
1591
+ local now = ARGV[2]
1592
+
1593
+ -- Get existing data
1594
+ local existing = redis.call('GET', key)
1595
+
1596
+ if not existing then
1597
+ return nil
1598
+ end
1599
+
1600
+ local data = cjson.decode(existing)
1601
+ local snapshot = data.snapshot
1602
+
1603
+ if type(snapshot) == 'string' then
1604
+ snapshot = cjson.decode(snapshot)
1605
+ end
1606
+
1607
+ if not snapshot or not snapshot.context then
1608
+ return nil
1609
+ end
1610
+
1611
+ -- Merge the new options with the existing snapshot
1612
+ local opts = cjson.decode(optsJson)
1613
+ for k, v in pairs(opts) do
1614
+ snapshot[k] = v
1615
+ end
1616
+
1617
+ -- Update the record
1618
+ data.snapshot = snapshot
1619
+ data.updatedAt = now
1620
+
1621
+ -- Save back
1622
+ redis.call('SET', key, cjson.encode(data))
1623
+
1624
+ -- Return the full updated data
1625
+ return cjson.encode(data)
1626
+ `;
1627
+ const resultJson = await this.client.eval(luaScript, [key], [JSON.stringify(opts), now]);
1628
+ if (!resultJson) {
1512
1629
  return void 0;
1513
1630
  }
1514
- const updatedSnapshot = { ...existingSnapshot, ...opts };
1515
- await this.persistWorkflowSnapshot({
1516
- namespace: "workflows",
1517
- workflowName,
1518
- runId,
1519
- snapshot: updatedSnapshot
1520
- });
1521
- return updatedSnapshot;
1631
+ let data;
1632
+ if (typeof resultJson === "string") {
1633
+ data = JSON.parse(resultJson);
1634
+ } else {
1635
+ data = resultJson;
1636
+ }
1637
+ const snapshot = typeof data.snapshot === "string" ? JSON.parse(data.snapshot) : data.snapshot;
1638
+ return snapshot;
1522
1639
  } catch (error$1) {
1523
1640
  if (error$1 instanceof error.MastraError) throw error$1;
1524
1641
  throw new error.MastraError(