zeitlich 0.2.44 → 0.2.46

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.
Files changed (99) hide show
  1. package/README.md +78 -10
  2. package/dist/{activities-CPIB2v2C.d.ts → activities-Bm4TLTid.d.ts} +24 -4
  3. package/dist/{activities-DnmNOnq4.d.cts → activities-CyeiqK_f.d.cts} +24 -4
  4. package/dist/adapters/sandbox/daytona/index.d.cts +2 -2
  5. package/dist/adapters/sandbox/daytona/index.d.ts +2 -2
  6. package/dist/adapters/sandbox/daytona/workflow.d.cts +1 -1
  7. package/dist/adapters/sandbox/daytona/workflow.d.ts +1 -1
  8. package/dist/adapters/sandbox/e2b/index.d.cts +1 -1
  9. package/dist/adapters/sandbox/e2b/index.d.ts +1 -1
  10. package/dist/adapters/thread/anthropic/index.cjs +171 -65
  11. package/dist/adapters/thread/anthropic/index.cjs.map +1 -1
  12. package/dist/adapters/thread/anthropic/index.d.cts +19 -4
  13. package/dist/adapters/thread/anthropic/index.d.ts +19 -4
  14. package/dist/adapters/thread/anthropic/index.js +171 -65
  15. package/dist/adapters/thread/anthropic/index.js.map +1 -1
  16. package/dist/adapters/thread/anthropic/workflow.cjs +3 -1
  17. package/dist/adapters/thread/anthropic/workflow.cjs.map +1 -1
  18. package/dist/adapters/thread/anthropic/workflow.d.cts +4 -4
  19. package/dist/adapters/thread/anthropic/workflow.d.ts +4 -4
  20. package/dist/adapters/thread/anthropic/workflow.js +3 -1
  21. package/dist/adapters/thread/anthropic/workflow.js.map +1 -1
  22. package/dist/adapters/thread/google-genai/index.cjs +171 -69
  23. package/dist/adapters/thread/google-genai/index.cjs.map +1 -1
  24. package/dist/adapters/thread/google-genai/index.d.cts +5 -4
  25. package/dist/adapters/thread/google-genai/index.d.ts +5 -4
  26. package/dist/adapters/thread/google-genai/index.js +171 -69
  27. package/dist/adapters/thread/google-genai/index.js.map +1 -1
  28. package/dist/adapters/thread/google-genai/workflow.cjs +3 -1
  29. package/dist/adapters/thread/google-genai/workflow.cjs.map +1 -1
  30. package/dist/adapters/thread/google-genai/workflow.d.cts +5 -4
  31. package/dist/adapters/thread/google-genai/workflow.d.ts +5 -4
  32. package/dist/adapters/thread/google-genai/workflow.js +3 -1
  33. package/dist/adapters/thread/google-genai/workflow.js.map +1 -1
  34. package/dist/adapters/thread/langchain/index.cjs +181 -77
  35. package/dist/adapters/thread/langchain/index.cjs.map +1 -1
  36. package/dist/adapters/thread/langchain/index.d.cts +18 -4
  37. package/dist/adapters/thread/langchain/index.d.ts +18 -4
  38. package/dist/adapters/thread/langchain/index.js +182 -74
  39. package/dist/adapters/thread/langchain/index.js.map +1 -1
  40. package/dist/adapters/thread/langchain/workflow.cjs +3 -1
  41. package/dist/adapters/thread/langchain/workflow.cjs.map +1 -1
  42. package/dist/adapters/thread/langchain/workflow.d.cts +4 -4
  43. package/dist/adapters/thread/langchain/workflow.d.ts +4 -4
  44. package/dist/adapters/thread/langchain/workflow.js +3 -1
  45. package/dist/adapters/thread/langchain/workflow.js.map +1 -1
  46. package/dist/cold-store-BC5L5Z8A.d.cts +117 -0
  47. package/dist/cold-store-CFHwemBJ.d.ts +117 -0
  48. package/dist/index.cjs +252 -53
  49. package/dist/index.cjs.map +1 -1
  50. package/dist/index.d.cts +138 -8
  51. package/dist/index.d.ts +138 -8
  52. package/dist/index.js +247 -54
  53. package/dist/index.js.map +1 -1
  54. package/dist/{proxy-DTnc5rqT.d.cts → proxy-BxFyd6cg.d.cts} +1 -1
  55. package/dist/{proxy-B7Xi1znZ.d.ts → proxy-Cskmj4Yx.d.ts} +1 -1
  56. package/dist/{thread-manager-BlX2TwRN.d.cts → thread-manager-9tezUcLW.d.cts} +9 -3
  57. package/dist/{thread-manager-BAv340mi.d.ts → thread-manager-B-zy3xrs.d.ts} +9 -3
  58. package/dist/{thread-manager-D2xorI-J.d.ts → thread-manager-D33SUmZa.d.cts} +10 -4
  59. package/dist/{thread-manager-BWv6ZXI3.d.cts → thread-manager-DduoSkvJ.d.ts} +10 -4
  60. package/dist/{types-C90VoEpt.d.cts → types-CjY93AWZ.d.cts} +1 -1
  61. package/dist/{types-4Wmk-wRq.d.cts → types-CnuN9T6t.d.cts} +23 -1
  62. package/dist/{types-DKsCdAtQ.d.ts → types-CwN6_tAL.d.ts} +23 -1
  63. package/dist/{types-Clhqautb.d.ts → types-L5bvbF-n.d.ts} +17 -1
  64. package/dist/{types-DpFD8ofR.d.ts → types-gVa5XCWD.d.ts} +1 -1
  65. package/dist/{types-DRJt1TMi.d.cts → types-oxt8GN97.d.cts} +17 -1
  66. package/dist/{workflow-D32TRMr-.d.ts → workflow-B1TOcHbt.d.ts} +33 -2
  67. package/dist/{workflow-XVt0ww8K.d.cts → workflow-DIaIV7L2.d.cts} +33 -2
  68. package/dist/workflow.cjs +29 -19
  69. package/dist/workflow.cjs.map +1 -1
  70. package/dist/workflow.d.cts +2 -2
  71. package/dist/workflow.d.ts +2 -2
  72. package/dist/workflow.js +29 -19
  73. package/dist/workflow.js.map +1 -1
  74. package/package.json +6 -1
  75. package/src/adapters/thread/anthropic/activities.ts +72 -36
  76. package/src/adapters/thread/anthropic/thread-manager.ts +9 -1
  77. package/src/adapters/thread/google-genai/activities.ts +64 -40
  78. package/src/adapters/thread/google-genai/thread-manager.ts +9 -1
  79. package/src/adapters/thread/langchain/activities.ts +63 -36
  80. package/src/adapters/thread/langchain/thread-manager.ts +9 -1
  81. package/src/index.ts +20 -1
  82. package/src/lib/session/session-edge-cases.integration.test.ts +12 -0
  83. package/src/lib/session/session.integration.test.ts +138 -0
  84. package/src/lib/session/session.ts +47 -22
  85. package/src/lib/session/types.ts +22 -0
  86. package/src/lib/thread/cold-store.test.ts +193 -0
  87. package/src/lib/thread/cold-store.ts +250 -0
  88. package/src/lib/thread/index.ts +32 -0
  89. package/src/lib/thread/keys.ts +20 -0
  90. package/src/lib/thread/manager.ts +16 -27
  91. package/src/lib/thread/proxy.ts +2 -0
  92. package/src/lib/thread/snapshot.test.ts +443 -0
  93. package/src/lib/thread/snapshot.ts +163 -0
  94. package/src/lib/thread/test-utils.ts +228 -0
  95. package/src/lib/thread/tiered.test.ts +281 -0
  96. package/src/lib/thread/tiered.ts +135 -0
  97. package/src/lib/thread/types.ts +16 -0
  98. package/src/lib/.env +0 -1
  99. package/src/tools/bash/.env +0 -1
@@ -1,5 +1,5 @@
1
1
  import { mapStoredMessagesToChatMessages, ToolMessage, AIMessage, SystemMessage, HumanMessage } from '@langchain/core/messages';
2
- import crypto from 'crypto';
2
+ import { randomUUID, randomFillSync } from 'crypto';
3
3
  import { Context } from '@temporalio/activity';
4
4
 
5
5
  // src/adapters/thread/langchain/adapter-id.ts
@@ -16,6 +16,9 @@ function getThreadMetaKey(threadKey, threadId) {
16
16
  function getThreadStateKey(threadKey, threadId) {
17
17
  return `${threadKey}:state:thread:${threadId}`;
18
18
  }
19
+ function getThreadDedupKey(threadId, dedupId) {
20
+ return `dedup:${dedupId}:thread:${threadId}`;
21
+ }
19
22
 
20
23
  // src/lib/thread/manager.ts
21
24
  var APPEND_IDEMPOTENT_SCRIPT = `
@@ -29,9 +32,6 @@ redis.call('EXPIRE', KEYS[2], tonumber(ARGV[1]))
29
32
  redis.call('SET', KEYS[1], '1', 'EX', tonumber(ARGV[1]))
30
33
  return 1
31
34
  `;
32
- function getDedupKey(threadId, id) {
33
- return `dedup:${id}:thread:${threadId}`;
34
- }
35
35
  function createThreadManager(config) {
36
36
  const {
37
37
  redis,
@@ -39,11 +39,13 @@ function createThreadManager(config) {
39
39
  key = "messages",
40
40
  serialize = (m) => JSON.stringify(m),
41
41
  deserialize = (raw) => JSON.parse(raw),
42
- idOf
42
+ idOf,
43
+ ttlSeconds = THREAD_TTL_SECONDS
43
44
  } = config;
44
45
  const redisKey = getThreadListKey(key, threadId);
45
46
  const metaKey = getThreadMetaKey(key, threadId);
46
47
  const stateKey = getThreadStateKey(key, threadId);
48
+ const dedupKey = (id) => getThreadDedupKey(threadId, id);
47
49
  async function assertThreadExists() {
48
50
  const exists = await redis.exists(metaKey);
49
51
  if (!exists) {
@@ -53,7 +55,7 @@ function createThreadManager(config) {
53
55
  return {
54
56
  async initialize() {
55
57
  await redis.del(redisKey);
56
- await redis.set(metaKey, "1", "EX", THREAD_TTL_SECONDS);
58
+ await redis.set(metaKey, "1", "EX", ttlSeconds);
57
59
  },
58
60
  async load() {
59
61
  await assertThreadExists();
@@ -65,18 +67,17 @@ function createThreadManager(config) {
65
67
  await assertThreadExists();
66
68
  if (idOf) {
67
69
  const dedupId = messages.map(idOf).join(":");
68
- const dedupKey = getDedupKey(threadId, dedupId);
69
70
  await redis.eval(
70
71
  APPEND_IDEMPOTENT_SCRIPT,
71
72
  2,
72
- dedupKey,
73
+ dedupKey(dedupId),
73
74
  redisKey,
74
- String(THREAD_TTL_SECONDS),
75
+ String(ttlSeconds),
75
76
  ...messages.map(serialize)
76
77
  );
77
78
  } else {
78
79
  await redis.rpush(redisKey, ...messages.map(serialize));
79
- await redis.expire(redisKey, THREAD_TTL_SECONDS);
80
+ await redis.expire(redisKey, ttlSeconds);
80
81
  }
81
82
  },
82
83
  async fork(newThreadId) {
@@ -91,11 +92,11 @@ function createThreadManager(config) {
91
92
  if (data.length > 0) {
92
93
  const newKey = getThreadListKey(key, newThreadId);
93
94
  await redis.rpush(newKey, ...data);
94
- await redis.expire(newKey, THREAD_TTL_SECONDS);
95
+ await redis.expire(newKey, ttlSeconds);
95
96
  }
96
97
  if (stateRaw != null) {
97
98
  const newStateKey = getThreadStateKey(key, newThreadId);
98
- await redis.set(newStateKey, stateRaw, "EX", THREAD_TTL_SECONDS);
99
+ await redis.set(newStateKey, stateRaw, "EX", ttlSeconds);
99
100
  }
100
101
  return forked;
101
102
  },
@@ -110,15 +111,13 @@ function createThreadManager(config) {
110
111
  const existingIds = existing.map((raw) => idOf(deserialize(raw))).filter((id) => typeof id === "string");
111
112
  await redis.del(redisKey);
112
113
  if (existingIds.length > 0) {
113
- await redis.del(
114
- ...existingIds.map((id) => getDedupKey(threadId, id))
115
- );
114
+ await redis.del(...existingIds.map(dedupKey));
116
115
  }
117
116
  if (messages.length > 0) {
118
117
  await redis.rpush(redisKey, ...messages.map(serialize));
119
- await redis.expire(redisKey, THREAD_TTL_SECONDS);
118
+ await redis.expire(redisKey, ttlSeconds);
120
119
  }
121
- await redis.expire(metaKey, THREAD_TTL_SECONDS);
120
+ await redis.expire(metaKey, ttlSeconds);
122
121
  },
123
122
  async delete() {
124
123
  await redis.del(redisKey, metaKey, stateKey);
@@ -130,12 +129,7 @@ function createThreadManager(config) {
130
129
  },
131
130
  async saveState(state) {
132
131
  await assertThreadExists();
133
- await redis.set(
134
- stateKey,
135
- JSON.stringify(state),
136
- "EX",
137
- THREAD_TTL_SECONDS
138
- );
132
+ await redis.set(stateKey, JSON.stringify(state), "EX", ttlSeconds);
139
133
  },
140
134
  async deleteState() {
141
135
  await redis.del(stateKey);
@@ -164,21 +158,132 @@ function createThreadManager(config) {
164
158
  if (idx === -1) return;
165
159
  if (idx === 0) {
166
160
  await redis.del(redisKey);
167
- await redis.expire(metaKey, THREAD_TTL_SECONDS);
161
+ await redis.expire(metaKey, ttlSeconds);
168
162
  } else {
169
163
  await redis.ltrim(redisKey, 0, idx - 1);
170
- await redis.expire(redisKey, THREAD_TTL_SECONDS);
164
+ await redis.expire(redisKey, ttlSeconds);
171
165
  }
172
166
  if (removedIds.length > 0) {
173
- await redis.del(
174
- ...removedIds.map((id) => getDedupKey(threadId, id))
175
- );
167
+ await redis.del(...removedIds.map(dedupKey));
176
168
  }
177
169
  }
178
170
  };
179
171
  }
180
172
 
181
- // src/adapters/thread/langchain/thread-manager.ts
173
+ // src/lib/thread/snapshot.ts
174
+ async function encodeSnapshot(config) {
175
+ const { redis, threadKey, threadId, idOf } = config;
176
+ const metaKey = getThreadMetaKey(threadKey, threadId);
177
+ if (await redis.exists(metaKey) === 0) {
178
+ return null;
179
+ }
180
+ const listKey = getThreadListKey(threadKey, threadId);
181
+ const stateKey = getThreadStateKey(threadKey, threadId);
182
+ const messages = await redis.lrange(listKey, 0, -1);
183
+ const stateRaw = await redis.get(stateKey);
184
+ const state = stateRaw == null ? null : JSON.parse(stateRaw);
185
+ const dedupIds = idOf ? messages.map(idOf) : [];
186
+ return { v: 1, messages, state, dedupIds };
187
+ }
188
+ async function applySnapshot(config) {
189
+ const {
190
+ redis,
191
+ threadKey,
192
+ threadId,
193
+ snapshot,
194
+ ttlSeconds = THREAD_TTL_SECONDS
195
+ } = config;
196
+ const metaKey = getThreadMetaKey(threadKey, threadId);
197
+ if (await redis.exists(metaKey) === 1) {
198
+ return;
199
+ }
200
+ const listKey = getThreadListKey(threadKey, threadId);
201
+ const stateKey = getThreadStateKey(threadKey, threadId);
202
+ await redis.del(listKey, stateKey);
203
+ const pipeline = redis.pipeline();
204
+ if (snapshot.messages.length > 0) {
205
+ pipeline.rpush(listKey, ...snapshot.messages);
206
+ pipeline.expire(listKey, ttlSeconds);
207
+ }
208
+ if (snapshot.state != null) {
209
+ pipeline.set(stateKey, JSON.stringify(snapshot.state), "EX", ttlSeconds);
210
+ }
211
+ for (const id of snapshot.dedupIds) {
212
+ pipeline.set(getThreadDedupKey(threadId, id), "1", "EX", ttlSeconds);
213
+ }
214
+ const results = await pipeline.exec();
215
+ if (results) {
216
+ const firstErr = results.find(([err]) => err)?.[0] ?? null;
217
+ if (firstErr) {
218
+ await redis.del(
219
+ listKey,
220
+ stateKey,
221
+ ...snapshot.dedupIds.map((id) => getThreadDedupKey(threadId, id))
222
+ ).catch(() => void 0);
223
+ throw firstErr;
224
+ }
225
+ }
226
+ await redis.set(metaKey, "1", "EX", ttlSeconds);
227
+ }
228
+ async function clearHotTier(config) {
229
+ const { redis, threadKey, threadId, dedupIds = [] } = config;
230
+ const keys = [
231
+ getThreadListKey(threadKey, threadId),
232
+ getThreadMetaKey(threadKey, threadId),
233
+ getThreadStateKey(threadKey, threadId),
234
+ ...dedupIds.map((id) => getThreadDedupKey(threadId, id))
235
+ ];
236
+ await redis.del(...keys);
237
+ }
238
+
239
+ // src/lib/thread/tiered.ts
240
+ function createTieredThreadManager(config) {
241
+ const {
242
+ redis,
243
+ threadId,
244
+ key = "messages",
245
+ coldStore,
246
+ idOf,
247
+ deserialize = (raw) => JSON.parse(raw),
248
+ ttlSeconds = THREAD_TTL_SECONDS
249
+ } = config;
250
+ const base = createThreadManager(config);
251
+ const rawIdOf = idOf ? (raw) => idOf(deserialize(raw)) : void 0;
252
+ return Object.assign(base, {
253
+ async hydrate() {
254
+ if (!coldStore) return;
255
+ const snapshot = await coldStore.read(key, threadId);
256
+ if (!snapshot) return;
257
+ await applySnapshot({
258
+ redis,
259
+ threadKey: key,
260
+ threadId,
261
+ snapshot,
262
+ ttlSeconds
263
+ });
264
+ },
265
+ async flush(opts) {
266
+ if (!coldStore) return;
267
+ const snapshot = await encodeSnapshot({
268
+ redis,
269
+ threadKey: key,
270
+ threadId,
271
+ ...rawIdOf ? { idOf: rawIdOf } : {}
272
+ });
273
+ if (!snapshot) return;
274
+ await coldStore.write(key, threadId, snapshot);
275
+ const deleteHot = opts?.deleteHot ?? true;
276
+ if (deleteHot) {
277
+ await clearHotTier({
278
+ redis,
279
+ threadKey: key,
280
+ threadId,
281
+ dedupIds: snapshot.dedupIds
282
+ });
283
+ }
284
+ }
285
+ });
286
+ }
182
287
  function storedMessageId(msg) {
183
288
  if (msg.type === "tool" && msg.data.tool_call_id) {
184
289
  return msg.data.tool_call_id;
@@ -193,7 +298,8 @@ function createLangChainThreadManager(config) {
193
298
  redis: config.redis,
194
299
  threadId: config.threadId,
195
300
  key: config.key,
196
- idOf: storedMessageId
301
+ idOf: storedMessageId,
302
+ ...config.ttlSeconds !== void 0 && { ttlSeconds: config.ttlSeconds }
197
303
  };
198
304
  const base = createThreadManager(baseConfig);
199
305
  const helpers = {
@@ -260,7 +366,7 @@ function createLangChainThreadManager(config) {
260
366
  return manager;
261
367
  }
262
368
 
263
- // ../2_monorepo/node_modules/.pnpm/uuid@10.0.0/node_modules/uuid/dist/esm-node/stringify.js
369
+ // node_modules/uuid/dist/esm/stringify.js
264
370
  var byteToHex = [];
265
371
  for (let i = 0; i < 256; ++i) {
266
372
  byteToHex.push((i + 256).toString(16).slice(1));
@@ -272,26 +378,30 @@ var rnds8Pool = new Uint8Array(256);
272
378
  var poolPtr = rnds8Pool.length;
273
379
  function rng() {
274
380
  if (poolPtr > rnds8Pool.length - 16) {
275
- crypto.randomFillSync(rnds8Pool);
381
+ randomFillSync(rnds8Pool);
276
382
  poolPtr = 0;
277
383
  }
278
384
  return rnds8Pool.slice(poolPtr, poolPtr += 16);
279
385
  }
280
- var native_default = {
281
- randomUUID: crypto.randomUUID
282
- };
386
+ var native_default = { randomUUID };
283
387
 
284
- // ../2_monorepo/node_modules/.pnpm/uuid@10.0.0/node_modules/uuid/dist/esm-node/v4.js
388
+ // node_modules/uuid/dist/esm/v4.js
285
389
  function v4(options, buf, offset) {
286
390
  if (native_default.randomUUID && !buf && !options) {
287
391
  return native_default.randomUUID();
288
392
  }
289
393
  options = options || {};
290
- const rnds = options.random || (options.rng || rng)();
394
+ const rnds = options.random ?? options.rng?.() ?? rng();
395
+ if (rnds.length < 16) {
396
+ throw new Error("Random bytes length must be >= 16");
397
+ }
291
398
  rnds[6] = rnds[6] & 15 | 64;
292
399
  rnds[8] = rnds[8] & 63 | 128;
293
400
  if (buf) {
294
401
  offset = offset || 0;
402
+ if (offset < 0 || offset + 16 > buf.length) {
403
+ throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
404
+ }
295
405
  for (let i = 0; i < 16; ++i) {
296
406
  buf[offset + i] = rnds[i];
297
407
  }
@@ -367,46 +477,43 @@ async function invokeLangChainModel({
367
477
  // src/adapters/thread/langchain/activities.ts
368
478
  function createLangChainAdapter(config) {
369
479
  const { redis } = config;
480
+ const baseExtras = {
481
+ ...config.ttlSeconds !== void 0 && { ttlSeconds: config.ttlSeconds }
482
+ };
483
+ const makeProviderThread = (threadId, threadKey) => createLangChainThreadManager({
484
+ redis,
485
+ threadId,
486
+ key: threadKey,
487
+ ...baseExtras
488
+ });
489
+ const makeTieredBase = (threadId, threadKey) => createTieredThreadManager({
490
+ redis,
491
+ threadId,
492
+ key: threadKey,
493
+ idOf: storedMessageId,
494
+ ...baseExtras,
495
+ ...config.coldStore && { coldStore: config.coldStore }
496
+ });
370
497
  const threadOps = {
371
498
  async initializeThread(threadId, threadKey) {
372
- const thread = createLangChainThreadManager({
373
- redis,
374
- threadId,
375
- key: threadKey
376
- });
499
+ const thread = makeProviderThread(threadId, threadKey);
377
500
  await thread.initialize();
378
501
  },
379
502
  async appendHumanMessage(threadId, id, content, threadKey) {
380
- const thread = createLangChainThreadManager({
381
- redis,
382
- threadId,
383
- key: threadKey
384
- });
503
+ const thread = makeProviderThread(threadId, threadKey);
385
504
  await thread.appendUserMessage(id, content);
386
505
  },
387
506
  async appendSystemMessage(threadId, id, content, threadKey) {
388
- const thread = createLangChainThreadManager({
389
- redis,
390
- threadId,
391
- key: threadKey
392
- });
507
+ const thread = makeProviderThread(threadId, threadKey);
393
508
  await thread.appendSystemMessage(id, content);
394
509
  },
395
510
  async appendToolResult(id, cfg) {
396
511
  const { threadId, threadKey, toolCallId, content } = cfg;
397
- const thread = createLangChainThreadManager({
398
- redis,
399
- threadId,
400
- key: threadKey
401
- });
512
+ const thread = makeProviderThread(threadId, threadKey);
402
513
  await thread.appendToolResult(id, toolCallId, "", content);
403
514
  },
404
515
  async appendAgentMessage(threadId, id, message, threadKey) {
405
- const thread = createLangChainThreadManager({
406
- redis,
407
- threadId,
408
- key: threadKey
409
- });
516
+ const thread = makeProviderThread(threadId, threadKey);
410
517
  const patched = { ...message, data: { ...message.data, id } };
411
518
  await thread.append([patched]);
412
519
  },
@@ -415,29 +522,30 @@ function createLangChainAdapter(config) {
415
522
  redis,
416
523
  threadId: sourceThreadId,
417
524
  key: threadKey,
418
- hooks: config.hooks
525
+ hooks: config.hooks,
526
+ ...baseExtras
419
527
  });
420
528
  await thread.fork(targetThreadId);
421
529
  },
422
530
  async truncateThread(threadId, messageId, threadKey) {
423
- const thread = createLangChainThreadManager({ redis, threadId, key: threadKey });
531
+ const thread = makeProviderThread(threadId, threadKey);
424
532
  await thread.truncateFromId(messageId);
425
533
  },
426
534
  async loadThreadState(threadId, threadKey) {
427
- const thread = createLangChainThreadManager({
428
- redis,
429
- threadId,
430
- key: threadKey
431
- });
535
+ const thread = makeProviderThread(threadId, threadKey);
432
536
  return thread.loadState();
433
537
  },
434
538
  async saveThreadState(threadId, state, threadKey) {
435
- const thread = createLangChainThreadManager({
436
- redis,
437
- threadId,
438
- key: threadKey
439
- });
539
+ const thread = makeProviderThread(threadId, threadKey);
440
540
  await thread.saveState(state);
541
+ },
542
+ async hydrateThread(threadId, threadKey) {
543
+ if (!config.coldStore) return;
544
+ await makeTieredBase(threadId, threadKey).hydrate();
545
+ },
546
+ async flushThread(threadId, threadKey) {
547
+ if (!config.coldStore) return;
548
+ await makeTieredBase(threadId, threadKey).flush();
441
549
  }
442
550
  };
443
551
  function createActivities(scope) {