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 { proxyActivities, ActivityInterfaceFor } from '@temporalio/workflow';
2
- import { T as ThreadOps } from './types-4Wmk-wRq.cjs';
2
+ import { T as ThreadOps } from './types-CnuN9T6t.cjs';
3
3
 
4
4
  /**
5
5
  * Shared proxy helper for thread operations.
@@ -1,5 +1,5 @@
1
1
  import { proxyActivities, ActivityInterfaceFor } from '@temporalio/workflow';
2
- import { T as ThreadOps } from './types-DKsCdAtQ.js';
2
+ import { T as ThreadOps } from './types-CwN6_tAL.js';
3
3
 
4
4
  /**
5
5
  * Shared proxy helper for thread operations.
@@ -1,7 +1,7 @@
1
1
  import Redis from 'ioredis';
2
2
  import Anthropic from '@anthropic-ai/sdk';
3
- import { J as JsonValue } from './types-4Wmk-wRq.cjs';
4
- import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-DRJt1TMi.cjs';
3
+ import { J as JsonValue } from './types-CnuN9T6t.cjs';
4
+ import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-oxt8GN97.cjs';
5
5
 
6
6
  /** SDK-native content type for Anthropic human messages */
7
7
  type AnthropicContent = string | Anthropic.Messages.ContentBlockParam[];
@@ -21,6 +21,12 @@ interface AnthropicThreadManagerConfig {
21
21
  /** Thread key, defaults to 'messages' */
22
22
  key?: string;
23
23
  hooks?: AnthropicThreadManagerHooks;
24
+ /**
25
+ * Override the default thread TTL (90 days). When pairing the
26
+ * adapter with a durable cold tier, a shorter TTL (hours) is
27
+ * typically more appropriate.
28
+ */
29
+ ttlSeconds?: number;
24
30
  }
25
31
  /** Prepared payload ready to send to the Anthropic API */
26
32
  interface AnthropicInvocationPayload {
@@ -39,4 +45,4 @@ interface AnthropicThreadManager extends ProviderThreadManager<StoredMessage, An
39
45
  */
40
46
  declare function createAnthropicThreadManager(config: AnthropicThreadManagerConfig): AnthropicThreadManager;
41
47
 
42
- export { type AnthropicContent as A, type StoredMessage as S, type AnthropicThreadManagerHooks as a, type AnthropicThreadManager as b, createAnthropicThreadManager as c, type AnthropicThreadManagerConfig as d, type AnthropicInvocationPayload as e };
48
+ export { type AnthropicContent as A, type StoredMessage as S, type AnthropicThreadManagerHooks as a, type AnthropicInvocationPayload as b, type AnthropicThreadManager as c, type AnthropicThreadManagerConfig as d, createAnthropicThreadManager as e };
@@ -1,7 +1,7 @@
1
1
  import Redis from 'ioredis';
2
2
  import Anthropic from '@anthropic-ai/sdk';
3
- import { J as JsonValue } from './types-DKsCdAtQ.js';
4
- import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-Clhqautb.js';
3
+ import { J as JsonValue } from './types-CwN6_tAL.js';
4
+ import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-L5bvbF-n.js';
5
5
 
6
6
  /** SDK-native content type for Anthropic human messages */
7
7
  type AnthropicContent = string | Anthropic.Messages.ContentBlockParam[];
@@ -21,6 +21,12 @@ interface AnthropicThreadManagerConfig {
21
21
  /** Thread key, defaults to 'messages' */
22
22
  key?: string;
23
23
  hooks?: AnthropicThreadManagerHooks;
24
+ /**
25
+ * Override the default thread TTL (90 days). When pairing the
26
+ * adapter with a durable cold tier, a shorter TTL (hours) is
27
+ * typically more appropriate.
28
+ */
29
+ ttlSeconds?: number;
24
30
  }
25
31
  /** Prepared payload ready to send to the Anthropic API */
26
32
  interface AnthropicInvocationPayload {
@@ -39,4 +45,4 @@ interface AnthropicThreadManager extends ProviderThreadManager<StoredMessage, An
39
45
  */
40
46
  declare function createAnthropicThreadManager(config: AnthropicThreadManagerConfig): AnthropicThreadManager;
41
47
 
42
- export { type AnthropicContent as A, type StoredMessage as S, type AnthropicThreadManagerHooks as a, type AnthropicThreadManager as b, createAnthropicThreadManager as c, type AnthropicThreadManagerConfig as d, type AnthropicInvocationPayload as e };
48
+ export { type AnthropicContent as A, type StoredMessage as S, type AnthropicThreadManagerHooks as a, type AnthropicInvocationPayload as b, type AnthropicThreadManager as c, type AnthropicThreadManagerConfig as d, createAnthropicThreadManager as e };
@@ -1,7 +1,7 @@
1
1
  import Redis from 'ioredis';
2
- import { J as JsonValue } from './types-DKsCdAtQ.js';
3
- import { StoredMessage, BaseMessage, MessageContent } from '@langchain/core/messages';
4
- import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-Clhqautb.js';
2
+ import { J as JsonValue } from './types-CnuN9T6t.cjs';
3
+ import { MessageContent, StoredMessage, BaseMessage } from '@langchain/core/messages';
4
+ import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-oxt8GN97.cjs';
5
5
 
6
6
  /** SDK-native content type for LangChain human messages */
7
7
  type LangChainContent = string | MessageContent;
@@ -14,6 +14,12 @@ interface LangChainThreadManagerConfig {
14
14
  /** Thread key, defaults to 'messages' */
15
15
  key?: string;
16
16
  hooks?: LangChainThreadManagerHooks;
17
+ /**
18
+ * Override the default thread TTL (90 days). When pairing the
19
+ * adapter with a durable cold tier, a shorter TTL (hours) is
20
+ * typically more appropriate.
21
+ */
22
+ ttlSeconds?: number;
17
23
  }
18
24
  /** Prepared payload ready to send to a LangChain chat model */
19
25
  interface LangChainInvocationPayload {
@@ -31,4 +37,4 @@ interface LangChainThreadManager extends ProviderThreadManager<StoredMessage, La
31
37
  */
32
38
  declare function createLangChainThreadManager(config: LangChainThreadManagerConfig): LangChainThreadManager;
33
39
 
34
- export { type LangChainContent as L, type LangChainThreadManagerHooks as a, type LangChainThreadManager as b, createLangChainThreadManager as c, type LangChainThreadManagerConfig as d, type LangChainInvocationPayload as e };
40
+ export { type LangChainContent as L, type LangChainThreadManagerHooks as a, type LangChainInvocationPayload as b, type LangChainThreadManager as c, type LangChainThreadManagerConfig as d, createLangChainThreadManager as e };
@@ -1,7 +1,7 @@
1
1
  import Redis from 'ioredis';
2
- import { J as JsonValue } from './types-4Wmk-wRq.cjs';
3
- import { StoredMessage, BaseMessage, MessageContent } from '@langchain/core/messages';
4
- import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-DRJt1TMi.cjs';
2
+ import { J as JsonValue } from './types-CwN6_tAL.js';
3
+ import { MessageContent, StoredMessage, BaseMessage } from '@langchain/core/messages';
4
+ import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-L5bvbF-n.js';
5
5
 
6
6
  /** SDK-native content type for LangChain human messages */
7
7
  type LangChainContent = string | MessageContent;
@@ -14,6 +14,12 @@ interface LangChainThreadManagerConfig {
14
14
  /** Thread key, defaults to 'messages' */
15
15
  key?: string;
16
16
  hooks?: LangChainThreadManagerHooks;
17
+ /**
18
+ * Override the default thread TTL (90 days). When pairing the
19
+ * adapter with a durable cold tier, a shorter TTL (hours) is
20
+ * typically more appropriate.
21
+ */
22
+ ttlSeconds?: number;
17
23
  }
18
24
  /** Prepared payload ready to send to a LangChain chat model */
19
25
  interface LangChainInvocationPayload {
@@ -31,4 +37,4 @@ interface LangChainThreadManager extends ProviderThreadManager<StoredMessage, La
31
37
  */
32
38
  declare function createLangChainThreadManager(config: LangChainThreadManagerConfig): LangChainThreadManager;
33
39
 
34
- export { type LangChainContent as L, type LangChainThreadManagerHooks as a, type LangChainThreadManager as b, createLangChainThreadManager as c, type LangChainThreadManagerConfig as d, type LangChainInvocationPayload as e };
40
+ export { type LangChainContent as L, type LangChainThreadManagerHooks as a, type LangChainInvocationPayload as b, type LangChainThreadManager as c, type LangChainThreadManagerConfig as d, createLangChainThreadManager as e };
@@ -1,4 +1,4 @@
1
- import { c as SandboxFileSystem, F as FileStat, D as DirentEntry, a as SandboxCreateOptions, b as Sandbox$1 } from './types-CJ7tCdl6.cjs';
1
+ import { c as SandboxFileSystem, F as FileStat, D as DirentEntry, b as Sandbox$1, a as SandboxCreateOptions } from './types-CJ7tCdl6.cjs';
2
2
  import { Sandbox } from '@daytonaio/sdk';
3
3
 
4
4
  /**
@@ -1529,6 +1529,28 @@ interface ThreadOps<TContent = string> {
1529
1529
  * store, continue later" works regardless of exit reason.
1530
1530
  */
1531
1531
  saveThreadState(threadId: string, state: PersistedThreadState, threadKey?: string): Promise<void>;
1532
+ /**
1533
+ * Restore the thread's contents from the durable cold tier (if any)
1534
+ * into Redis. Called once on session entry for `mode: "continue"`
1535
+ * and `mode: "fork"` so the rest of the loop reads the freshest data.
1536
+ *
1537
+ * Adapters configured without a cold-store implementation treat this
1538
+ * as a no-op. Implementations must be **idempotent** — Temporal
1539
+ * retries the activity on transient failures, and a thread that is
1540
+ * already hot must not be wiped.
1541
+ */
1542
+ hydrateThread(threadId: string, threadKey?: string): Promise<void>;
1543
+ /**
1544
+ * Archive the thread's contents to the durable cold tier and
1545
+ * (optionally) drop the hot-tier Redis keys. Called once in the
1546
+ * session's `finally` block on every exit path, after
1547
+ * `saveThreadState`.
1548
+ *
1549
+ * Adapters configured without a cold-store implementation treat this
1550
+ * as a no-op. Implementations must be **idempotent** — the cold
1551
+ * tier is last-writer-wins and a retried flush must converge.
1552
+ */
1553
+ flushThread(threadId: string, threadKey?: string): Promise<void>;
1532
1554
  }
1533
1555
  /**
1534
1556
  * Composes an adapter prefix + workflow scope for activity naming.
@@ -1774,4 +1796,4 @@ interface ZeitlichSession<M = unknown, HasSandbox extends boolean = boolean> {
1774
1796
  }): Promise<SessionResult<M, T, HasSandbox>>;
1775
1797
  }
1776
1798
 
1777
- export { type PostToolUseHook as $, type AgentResponse as A, type BaseAgentState as B, type ToolMap as C, type ToolNames as D, type RawToolCall as E, type FileEntryMetadata as F, type ParsedToolCall as G, type ParsedToolCallUnion as H, type ToolRouter as I, type JsonValue as J, type ToolRouterHooks as K, type ToolHandler as L, type ModelInvokerConfig as M, type ToolArgs as N, type ToolResult as O, type PersistedThreadState as P, type ToolCallResult as Q, type RouterContext as R, type ScopedPrefix as S, type ThreadOps as T, type ToolCallResultUnion as U, type VirtualFsContext as V, type InferToolResults as W, type PreToolUseHook as X, type PreToolUseHookContext as Y, type ZeitlichSession as Z, type PreToolUseHookResult as _, type ModelInvoker as a, type PostToolUseHookContext as a0, type PostToolUseFailureHook as a1, type PostToolUseFailureHookContext as a2, type PostToolUseFailureHookResult as a3, type ToolHooks as a4, type AppendToolResultFn as a5, type ProcessToolCallsContext as a6, type ProcessToolCallsResult as a7, type RewindSignal as a8, type Hooks as a9, type SubagentWorkflow as aA, type SubagentWorkflowInput as aB, type SubagentSessionInput as aC, type FileEntry as aD, type VirtualFileTree as aE, type VirtualFsOps as aF, type VirtualFsState as aG, type ToolRouterOptions as aH, type SessionStartHook as aa, type SessionStartHookContext as ab, type SessionEndHook as ac, type SessionEndHookContext as ad, type PreHumanMessageAppendHook as ae, type PreHumanMessageAppendHookContext as af, type PostHumanMessageAppendHook as ag, type PostHumanMessageAppendHookContext as ah, type TokenUsage as ai, type AgentStatus as aj, type AgentFile as ak, type AgentConfig as al, type SessionExitReason as am, type SerializableToolDefinition as an, type TaskStatus as ao, type WorkflowTask as ap, isTerminalStatus as aq, type RunAgentActivity as ar, type SubagentConfig as as, type SubagentChildWorkflowOptions as at, type SubagentDefinition as au, type SubagentFnResult as av, type SubagentHooks as aw, type SubagentHandlerResponse as ax, type SubagentSandboxConfig as ay, type SubagentContinuationCaps as az, type PrefixedThreadOps as b, type ToolHandlerResponse as c, type ActivityToolHandler as d, type ToolResultConfig as e, type RunAgentConfig as f, type SkillProvider as g, type SkillMetadata as h, type Skill as i, type FileResolver as j, type TreeMutation as k, type PrefixedVirtualFsOps as l, VirtualFileSystem as m, type SessionResult as n, type SessionConfig as o, type SessionRequiredCaps as p, type ThreadInit as q, type SandboxInit as r, type SandboxShutdown as s, type SubagentSandboxShutdown as t, type AgentState as u, type AgentStateManager as v, type JsonSerializable as w, type JsonPrimitive as x, type ToolDefinition as y, type ToolWithHandler as z };
1799
+ export { type SandboxShutdown as $, type AgentResponse as A, type BaseAgentState as B, type PostToolUseFailureHookContext as C, type PostToolUseFailureHookResult as D, type PostToolUseHook as E, type FileEntryMetadata as F, type PostToolUseHookContext as G, type Hooks as H, type InferToolResults as I, type JsonValue as J, type PreHumanMessageAppendHook as K, type PreHumanMessageAppendHookContext as L, type ModelInvokerConfig as M, type PreToolUseHook as N, type PreToolUseHookContext as O, type PersistedThreadState as P, type PreToolUseHookResult as Q, type RouterContext as R, type ScopedPrefix as S, type ThreadOps as T, type ProcessToolCallsContext as U, type VirtualFsContext as V, type ProcessToolCallsResult as W, type RawToolCall as X, type RewindSignal as Y, type RunAgentActivity as Z, type SandboxInit as _, type ModelInvoker as a, type SerializableToolDefinition as a0, type SessionConfig as a1, type SessionEndHook as a2, type SessionEndHookContext as a3, type SessionExitReason as a4, type SessionRequiredCaps as a5, type SessionResult as a6, type SessionStartHook as a7, type SessionStartHookContext as a8, type SubagentChildWorkflowOptions as a9, VirtualFileSystem as aA, type VirtualFileTree as aB, type VirtualFsOps as aC, type VirtualFsState as aD, type WorkflowTask as aE, type ZeitlichSession as aF, isTerminalStatus as aG, type ToolRouterOptions as aH, type SubagentConfig as aa, type SubagentContinuationCaps as ab, type SubagentDefinition as ac, type SubagentFnResult as ad, type SubagentHandlerResponse as ae, type SubagentHooks as af, type SubagentSandboxConfig as ag, type SubagentSandboxShutdown as ah, type SubagentSessionInput as ai, type SubagentWorkflow as aj, type SubagentWorkflowInput as ak, type TaskStatus as al, type ThreadInit as am, type TokenUsage as an, type ToolArgs as ao, type ToolCallResult as ap, type ToolCallResultUnion as aq, type ToolDefinition as ar, type ToolHandler as as, type ToolHooks as at, type ToolMap as au, type ToolNames as av, type ToolResult as aw, type ToolRouter as ax, type ToolRouterHooks as ay, type ToolWithHandler as az, type PrefixedThreadOps as b, type ToolHandlerResponse as c, type ActivityToolHandler as d, type ToolResultConfig as e, type RunAgentConfig as f, type SkillProvider as g, type SkillMetadata as h, type Skill as i, type FileResolver as j, type TreeMutation as k, type PrefixedVirtualFsOps as l, type AgentConfig as m, type AgentFile as n, type AgentState as o, type AgentStateManager as p, type AgentStatus as q, type AppendToolResultFn as r, type FileEntry as s, type JsonPrimitive as t, type JsonSerializable as u, type ParsedToolCall as v, type ParsedToolCallUnion as w, type PostHumanMessageAppendHook as x, type PostHumanMessageAppendHookContext as y, type PostToolUseFailureHook as z };
@@ -1529,6 +1529,28 @@ interface ThreadOps<TContent = string> {
1529
1529
  * store, continue later" works regardless of exit reason.
1530
1530
  */
1531
1531
  saveThreadState(threadId: string, state: PersistedThreadState, threadKey?: string): Promise<void>;
1532
+ /**
1533
+ * Restore the thread's contents from the durable cold tier (if any)
1534
+ * into Redis. Called once on session entry for `mode: "continue"`
1535
+ * and `mode: "fork"` so the rest of the loop reads the freshest data.
1536
+ *
1537
+ * Adapters configured without a cold-store implementation treat this
1538
+ * as a no-op. Implementations must be **idempotent** — Temporal
1539
+ * retries the activity on transient failures, and a thread that is
1540
+ * already hot must not be wiped.
1541
+ */
1542
+ hydrateThread(threadId: string, threadKey?: string): Promise<void>;
1543
+ /**
1544
+ * Archive the thread's contents to the durable cold tier and
1545
+ * (optionally) drop the hot-tier Redis keys. Called once in the
1546
+ * session's `finally` block on every exit path, after
1547
+ * `saveThreadState`.
1548
+ *
1549
+ * Adapters configured without a cold-store implementation treat this
1550
+ * as a no-op. Implementations must be **idempotent** — the cold
1551
+ * tier is last-writer-wins and a retried flush must converge.
1552
+ */
1553
+ flushThread(threadId: string, threadKey?: string): Promise<void>;
1532
1554
  }
1533
1555
  /**
1534
1556
  * Composes an adapter prefix + workflow scope for activity naming.
@@ -1774,4 +1796,4 @@ interface ZeitlichSession<M = unknown, HasSandbox extends boolean = boolean> {
1774
1796
  }): Promise<SessionResult<M, T, HasSandbox>>;
1775
1797
  }
1776
1798
 
1777
- export { type PostToolUseHook as $, type AgentResponse as A, type BaseAgentState as B, type ToolMap as C, type ToolNames as D, type RawToolCall as E, type FileEntryMetadata as F, type ParsedToolCall as G, type ParsedToolCallUnion as H, type ToolRouter as I, type JsonValue as J, type ToolRouterHooks as K, type ToolHandler as L, type ModelInvokerConfig as M, type ToolArgs as N, type ToolResult as O, type PersistedThreadState as P, type ToolCallResult as Q, type RouterContext as R, type ScopedPrefix as S, type ThreadOps as T, type ToolCallResultUnion as U, type VirtualFsContext as V, type InferToolResults as W, type PreToolUseHook as X, type PreToolUseHookContext as Y, type ZeitlichSession as Z, type PreToolUseHookResult as _, type ModelInvoker as a, type PostToolUseHookContext as a0, type PostToolUseFailureHook as a1, type PostToolUseFailureHookContext as a2, type PostToolUseFailureHookResult as a3, type ToolHooks as a4, type AppendToolResultFn as a5, type ProcessToolCallsContext as a6, type ProcessToolCallsResult as a7, type RewindSignal as a8, type Hooks as a9, type SubagentWorkflow as aA, type SubagentWorkflowInput as aB, type SubagentSessionInput as aC, type FileEntry as aD, type VirtualFileTree as aE, type VirtualFsOps as aF, type VirtualFsState as aG, type ToolRouterOptions as aH, type SessionStartHook as aa, type SessionStartHookContext as ab, type SessionEndHook as ac, type SessionEndHookContext as ad, type PreHumanMessageAppendHook as ae, type PreHumanMessageAppendHookContext as af, type PostHumanMessageAppendHook as ag, type PostHumanMessageAppendHookContext as ah, type TokenUsage as ai, type AgentStatus as aj, type AgentFile as ak, type AgentConfig as al, type SessionExitReason as am, type SerializableToolDefinition as an, type TaskStatus as ao, type WorkflowTask as ap, isTerminalStatus as aq, type RunAgentActivity as ar, type SubagentConfig as as, type SubagentChildWorkflowOptions as at, type SubagentDefinition as au, type SubagentFnResult as av, type SubagentHooks as aw, type SubagentHandlerResponse as ax, type SubagentSandboxConfig as ay, type SubagentContinuationCaps as az, type PrefixedThreadOps as b, type ToolHandlerResponse as c, type ActivityToolHandler as d, type ToolResultConfig as e, type RunAgentConfig as f, type SkillProvider as g, type SkillMetadata as h, type Skill as i, type FileResolver as j, type TreeMutation as k, type PrefixedVirtualFsOps as l, VirtualFileSystem as m, type SessionResult as n, type SessionConfig as o, type SessionRequiredCaps as p, type ThreadInit as q, type SandboxInit as r, type SandboxShutdown as s, type SubagentSandboxShutdown as t, type AgentState as u, type AgentStateManager as v, type JsonSerializable as w, type JsonPrimitive as x, type ToolDefinition as y, type ToolWithHandler as z };
1799
+ export { type SandboxShutdown as $, type AgentResponse as A, type BaseAgentState as B, type PostToolUseFailureHookContext as C, type PostToolUseFailureHookResult as D, type PostToolUseHook as E, type FileEntryMetadata as F, type PostToolUseHookContext as G, type Hooks as H, type InferToolResults as I, type JsonValue as J, type PreHumanMessageAppendHook as K, type PreHumanMessageAppendHookContext as L, type ModelInvokerConfig as M, type PreToolUseHook as N, type PreToolUseHookContext as O, type PersistedThreadState as P, type PreToolUseHookResult as Q, type RouterContext as R, type ScopedPrefix as S, type ThreadOps as T, type ProcessToolCallsContext as U, type VirtualFsContext as V, type ProcessToolCallsResult as W, type RawToolCall as X, type RewindSignal as Y, type RunAgentActivity as Z, type SandboxInit as _, type ModelInvoker as a, type SerializableToolDefinition as a0, type SessionConfig as a1, type SessionEndHook as a2, type SessionEndHookContext as a3, type SessionExitReason as a4, type SessionRequiredCaps as a5, type SessionResult as a6, type SessionStartHook as a7, type SessionStartHookContext as a8, type SubagentChildWorkflowOptions as a9, VirtualFileSystem as aA, type VirtualFileTree as aB, type VirtualFsOps as aC, type VirtualFsState as aD, type WorkflowTask as aE, type ZeitlichSession as aF, isTerminalStatus as aG, type ToolRouterOptions as aH, type SubagentConfig as aa, type SubagentContinuationCaps as ab, type SubagentDefinition as ac, type SubagentFnResult as ad, type SubagentHandlerResponse as ae, type SubagentHooks as af, type SubagentSandboxConfig as ag, type SubagentSandboxShutdown as ah, type SubagentSessionInput as ai, type SubagentWorkflow as aj, type SubagentWorkflowInput as ak, type TaskStatus as al, type ThreadInit as am, type TokenUsage as an, type ToolArgs as ao, type ToolCallResult as ap, type ToolCallResultUnion as aq, type ToolDefinition as ar, type ToolHandler as as, type ToolHooks as at, type ToolMap as au, type ToolNames as av, type ToolResult as aw, type ToolRouter as ax, type ToolRouterHooks as ay, type ToolWithHandler as az, type PrefixedThreadOps as b, type ToolHandlerResponse as c, type ActivityToolHandler as d, type ToolResultConfig as e, type RunAgentConfig as f, type SkillProvider as g, type SkillMetadata as h, type Skill as i, type FileResolver as j, type TreeMutation as k, type PrefixedVirtualFsOps as l, type AgentConfig as m, type AgentFile as n, type AgentState as o, type AgentStateManager as p, type AgentStatus as q, type AppendToolResultFn as r, type FileEntry as s, type JsonPrimitive as t, type JsonSerializable as u, type ParsedToolCall as v, type ParsedToolCallUnion as w, type PostHumanMessageAppendHook as x, type PostHumanMessageAppendHookContext as y, type PostToolUseFailureHook as z };
@@ -1,5 +1,5 @@
1
1
  import Redis from 'ioredis';
2
- import { P as PersistedThreadState, J as JsonValue } from './types-DKsCdAtQ.js';
2
+ import { P as PersistedThreadState, J as JsonValue } from './types-CwN6_tAL.js';
3
3
 
4
4
  interface ThreadManagerConfig<T> {
5
5
  redis: Redis;
@@ -15,6 +15,17 @@ interface ThreadManagerConfig<T> {
15
15
  * When provided, `append` uses an atomic Lua script to skip duplicate writes.
16
16
  */
17
17
  idOf?: (message: T) => string;
18
+ /**
19
+ * TTL (in seconds) applied to every Redis key the manager writes
20
+ * (the list, the meta marker, the state slice, and dedup markers).
21
+ *
22
+ * Defaults to {@link THREAD_TTL_SECONDS} (90 days) for back-compat.
23
+ * When the consumer pairs the thread manager with a durable cold
24
+ * tier (see `createTieredThreadManager`), a much shorter TTL — e.g.
25
+ * a few hours — is usually more appropriate since the cold tier is
26
+ * the source of truth and Redis is just a hot cache.
27
+ */
28
+ ttlSeconds?: number;
18
29
  }
19
30
  /** Generic thread manager for any message type */
20
31
  interface BaseThreadManager<T> {
@@ -26,6 +37,11 @@ interface BaseThreadManager<T> {
26
37
  * Append messages to the thread.
27
38
  * When `idOf` is configured, appends are idempotent — retries with the
28
39
  * same message ids are atomically skipped via a Redis Lua script.
40
+ *
41
+ * Caveat with tiered storage: multi-message batches write one composite
42
+ * dedup key (`"m1:m2"`); snapshots only persist per-message keys, so a
43
+ * batch retried after `flush` → `hydrate` will not be deduped. Adapter
44
+ * helpers all single-append and are unaffected.
29
45
  */
30
46
  append(messages: T[]): Promise<void>;
31
47
  /**
@@ -1,4 +1,4 @@
1
- import { c as SandboxFileSystem, F as FileStat, D as DirentEntry, a as SandboxCreateOptions, b as Sandbox$1 } from './types-CJ7tCdl6.js';
1
+ import { c as SandboxFileSystem, F as FileStat, D as DirentEntry, b as Sandbox$1, a as SandboxCreateOptions } from './types-CJ7tCdl6.js';
2
2
  import { Sandbox } from '@daytonaio/sdk';
3
3
 
4
4
  /**
@@ -1,5 +1,5 @@
1
1
  import Redis from 'ioredis';
2
- import { P as PersistedThreadState, J as JsonValue } from './types-4Wmk-wRq.cjs';
2
+ import { P as PersistedThreadState, J as JsonValue } from './types-CnuN9T6t.cjs';
3
3
 
4
4
  interface ThreadManagerConfig<T> {
5
5
  redis: Redis;
@@ -15,6 +15,17 @@ interface ThreadManagerConfig<T> {
15
15
  * When provided, `append` uses an atomic Lua script to skip duplicate writes.
16
16
  */
17
17
  idOf?: (message: T) => string;
18
+ /**
19
+ * TTL (in seconds) applied to every Redis key the manager writes
20
+ * (the list, the meta marker, the state slice, and dedup markers).
21
+ *
22
+ * Defaults to {@link THREAD_TTL_SECONDS} (90 days) for back-compat.
23
+ * When the consumer pairs the thread manager with a durable cold
24
+ * tier (see `createTieredThreadManager`), a much shorter TTL — e.g.
25
+ * a few hours — is usually more appropriate since the cold tier is
26
+ * the source of truth and Redis is just a hot cache.
27
+ */
28
+ ttlSeconds?: number;
18
29
  }
19
30
  /** Generic thread manager for any message type */
20
31
  interface BaseThreadManager<T> {
@@ -26,6 +37,11 @@ interface BaseThreadManager<T> {
26
37
  * Append messages to the thread.
27
38
  * When `idOf` is configured, appends are idempotent — retries with the
28
39
  * same message ids are atomically skipped via a Redis Lua script.
40
+ *
41
+ * Caveat with tiered storage: multi-message batches write one composite
42
+ * dedup key (`"m1:m2"`); snapshots only persist per-message keys, so a
43
+ * batch retried after `flush` → `hydrate` will not be deduped. Adapter
44
+ * helpers all single-append and are unaffected.
29
45
  */
30
46
  append(messages: T[]): Promise<void>;
31
47
  /**
@@ -1,4 +1,4 @@
1
- import { C as ToolMap, r as SandboxInit, t as SubagentSandboxShutdown, o as SessionConfig, Z as ZeitlichSession, s as SandboxShutdown, q as ThreadInit, w as JsonSerializable, B as BaseAgentState, v as AgentStateManager, aH as ToolRouterOptions, I as ToolRouter, H as ParsedToolCallUnion, D as ToolNames, R as RouterContext, J as JsonValue, z as ToolWithHandler, au as SubagentDefinition, aw as SubagentHooks, ay as SubagentSandboxConfig, as as SubagentConfig, aC as SubagentSessionInput, av as SubagentFnResult, aa as SessionStartHook, ac as SessionEndHook, $ as PostToolUseHook, a1 as PostToolUseFailureHook, am as SessionExitReason, ai as TokenUsage, f as RunAgentConfig, A as AgentResponse, F as FileEntryMetadata, aE as VirtualFileTree, k as TreeMutation, aD as FileEntry, aF as VirtualFsOps, h as SkillMetadata, i as Skill, c as ToolHandlerResponse, L as ToolHandler, ap as WorkflowTask, d as ActivityToolHandler } from './types-DKsCdAtQ.js';
1
+ import { au as ToolMap, _ as SandboxInit, ah as SubagentSandboxShutdown, a1 as SessionConfig, aF as ZeitlichSession, $ as SandboxShutdown, am as ThreadInit, u as JsonSerializable, B as BaseAgentState, p as AgentStateManager, aH as ToolRouterOptions, ax as ToolRouter, R as RouterContext, J as JsonValue, az as ToolWithHandler, w as ParsedToolCallUnion, av as ToolNames, ac as SubagentDefinition, af as SubagentHooks, ag as SubagentSandboxConfig, aa as SubagentConfig, ai as SubagentSessionInput, ad as SubagentFnResult, a7 as SessionStartHook, a2 as SessionEndHook, E as PostToolUseHook, z as PostToolUseFailureHook, a4 as SessionExitReason, an as TokenUsage, f as RunAgentConfig, A as AgentResponse, F as FileEntryMetadata, aB as VirtualFileTree, k as TreeMutation, s as FileEntry, aC as VirtualFsOps, h as SkillMetadata, i as Skill, c as ToolHandlerResponse, as as ToolHandler, aE as WorkflowTask, d as ActivityToolHandler } from './types-CwN6_tAL.js';
2
2
  import z$1, { z } from 'zod';
3
3
  import './types-CJ7tCdl6.js';
4
4
  import { Duration } from '@temporalio/common';
@@ -159,6 +159,37 @@ declare function getThreadListKey(threadKey: string, threadId: string): string;
159
159
  * @param threadId - Thread id as provided to the thread manager.
160
160
  */
161
161
  declare function getThreadMetaKey(threadKey: string, threadId: string): string;
162
+ /**
163
+ * Build the Redis key that stores a thread's persisted state slice
164
+ * (tasks + custom state) written by zeitlich's session loop on every
165
+ * exit path.
166
+ *
167
+ * Consumers can read this key with `redis.get(getThreadStateKey(key, id))`
168
+ * and `JSON.parse` the result into a {@link PersistedThreadState}.
169
+ *
170
+ * @param threadKey - Thread key (defaults to `"messages"` inside the
171
+ * thread manager, but downstream adapters may pass
172
+ * their own value).
173
+ * @param threadId - Thread id as provided to the thread manager.
174
+ */
175
+ declare function getThreadStateKey(threadKey: string, threadId: string): string;
176
+ /**
177
+ * Build the Redis key that guards an idempotent append against a
178
+ * duplicate write of the message (or message batch) identified by
179
+ * `dedupId`. Zeitlich's thread manager writes one of these per
180
+ * single-message append (and one per batch for multi-message appends),
181
+ * keyed by the message id returned by the configured `idOf`.
182
+ *
183
+ * Note: the key layout intentionally does **not** include the
184
+ * `threadKey` prefix — the dedup namespace is shared across thread
185
+ * keys for a given `threadId`, mirroring the original internal
186
+ * implementation.
187
+ *
188
+ * @param threadId - Thread id as provided to the thread manager.
189
+ * @param dedupId - Joined message ids (single message id for the
190
+ * common single-append case).
191
+ */
192
+ declare function getThreadDedupKey(threadId: string, dedupId: string): string;
162
193
 
163
194
  /**
164
195
  * Creates an agent state manager for tracking workflow state.
@@ -856,4 +887,4 @@ declare const createAskUserQuestionHandler: () => ActivityToolHandler<AskUserQue
856
887
  }[];
857
888
  }>;
858
889
 
859
- export { createTaskGetHandler as $, hasDirectory as A, type BashArgs as B, proxyVirtualFsOps as C, DEFAULT_SUBAGENT_WORKFLOW_RUN_TIMEOUT as D, type SubagentArgs as E, type FileEditArgs as F, type GlobArgs as G, parseSkillFile as H, createReadSkillTool as I, createReadSkillHandler as J, globTool as K, grepTool as L, type GrepArgs as M, readFileTool as N, type ObservabilityHooks as O, writeFileTool as P, editTool as Q, type ReadSkillArgs as R, type SessionStartedEvent as S, THREAD_TTL_SECONDS as T, taskCreateTool as U, type TaskCreateArgs as V, type WorkflowConfig as W, createTaskCreateHandler as X, taskGetTool as Y, type ZeitlichObservabilitySinks as Z, type TaskGetArgs as _, type FileReadArgs as a, taskListTool as a0, type TaskListArgs as a1, createTaskListHandler as a2, taskUpdateTool as a3, type TaskUpdateArgs as a4, createTaskUpdateHandler as a5, bashTool as a6, createBashToolDescription as a7, askUserQuestionTool as a8, type AskUserQuestionArgs as a9, createAskUserQuestionHandler as aa, type FileWriteArgs as b, type FileTreeAccessor as c, createSession as d, defineWorkflow as e, type WorkflowInput as f, type WorkflowSessionInput as g, getShortId as h, getThreadListKey as i, getThreadMetaKey as j, createAgentStateManager as k, createToolRouter as l, hasNoOtherToolCalls as m, defineTool as n, defineSubagent as o, defineSubagentWorkflow as p, createObservabilityHooks as q, composeHooks as r, type SessionEndedEvent as s, type TurnCompletedEvent as t, type ToolExecutedEvent as u, proxyRunAgent as v, applyVirtualTreeMutations as w, formatVirtualFileTree as x, hasFileWithMimeType as y, filesWithMimeType as z };
890
+ export { globTool as $, type AskUserQuestionArgs as A, type BashArgs as B, createTaskGetHandler as C, DEFAULT_SUBAGENT_WORKFLOW_RUN_TIMEOUT as D, createTaskListHandler as E, type FileEditArgs as F, type GlobArgs as G, createTaskUpdateHandler as H, createToolRouter as I, defineSubagent as J, defineSubagentWorkflow as K, defineTool as L, defineWorkflow as M, editTool as N, type ObservabilityHooks as O, filesWithMimeType as P, formatVirtualFileTree as Q, type ReadSkillArgs as R, type SessionEndedEvent as S, THREAD_TTL_SECONDS as T, getShortId as U, getThreadDedupKey as V, type WorkflowConfig as W, getThreadListKey as X, getThreadMetaKey as Y, type ZeitlichObservabilitySinks as Z, getThreadStateKey as _, type FileReadArgs as a, grepTool as a0, hasDirectory as a1, hasFileWithMimeType as a2, hasNoOtherToolCalls as a3, parseSkillFile as a4, proxyRunAgent as a5, proxyVirtualFsOps as a6, readFileTool as a7, taskCreateTool as a8, taskGetTool as a9, taskListTool as aa, taskUpdateTool as ab, writeFileTool as ac, type FileWriteArgs as b, type FileTreeAccessor as c, type GrepArgs as d, type SessionStartedEvent as e, type SubagentArgs as f, type TaskCreateArgs as g, type TaskGetArgs as h, type TaskListArgs as i, type TaskUpdateArgs as j, type ToolExecutedEvent as k, type TurnCompletedEvent as l, type WorkflowInput as m, type WorkflowSessionInput as n, applyVirtualTreeMutations as o, askUserQuestionTool as p, bashTool as q, composeHooks as r, createAgentStateManager as s, createAskUserQuestionHandler as t, createBashToolDescription as u, createObservabilityHooks as v, createReadSkillHandler as w, createReadSkillTool as x, createSession as y, createTaskCreateHandler as z };
@@ -1,4 +1,4 @@
1
- import { C as ToolMap, r as SandboxInit, t as SubagentSandboxShutdown, o as SessionConfig, Z as ZeitlichSession, s as SandboxShutdown, q as ThreadInit, w as JsonSerializable, B as BaseAgentState, v as AgentStateManager, aH as ToolRouterOptions, I as ToolRouter, H as ParsedToolCallUnion, D as ToolNames, R as RouterContext, J as JsonValue, z as ToolWithHandler, au as SubagentDefinition, aw as SubagentHooks, ay as SubagentSandboxConfig, as as SubagentConfig, aC as SubagentSessionInput, av as SubagentFnResult, aa as SessionStartHook, ac as SessionEndHook, $ as PostToolUseHook, a1 as PostToolUseFailureHook, am as SessionExitReason, ai as TokenUsage, f as RunAgentConfig, A as AgentResponse, F as FileEntryMetadata, aE as VirtualFileTree, k as TreeMutation, aD as FileEntry, aF as VirtualFsOps, h as SkillMetadata, i as Skill, c as ToolHandlerResponse, L as ToolHandler, ap as WorkflowTask, d as ActivityToolHandler } from './types-4Wmk-wRq.cjs';
1
+ import { au as ToolMap, _ as SandboxInit, ah as SubagentSandboxShutdown, a1 as SessionConfig, aF as ZeitlichSession, $ as SandboxShutdown, am as ThreadInit, u as JsonSerializable, B as BaseAgentState, p as AgentStateManager, aH as ToolRouterOptions, ax as ToolRouter, R as RouterContext, J as JsonValue, az as ToolWithHandler, w as ParsedToolCallUnion, av as ToolNames, ac as SubagentDefinition, af as SubagentHooks, ag as SubagentSandboxConfig, aa as SubagentConfig, ai as SubagentSessionInput, ad as SubagentFnResult, a7 as SessionStartHook, a2 as SessionEndHook, E as PostToolUseHook, z as PostToolUseFailureHook, a4 as SessionExitReason, an as TokenUsage, f as RunAgentConfig, A as AgentResponse, F as FileEntryMetadata, aB as VirtualFileTree, k as TreeMutation, s as FileEntry, aC as VirtualFsOps, h as SkillMetadata, i as Skill, c as ToolHandlerResponse, as as ToolHandler, aE as WorkflowTask, d as ActivityToolHandler } from './types-CnuN9T6t.cjs';
2
2
  import z$1, { z } from 'zod';
3
3
  import './types-CJ7tCdl6.cjs';
4
4
  import { Duration } from '@temporalio/common';
@@ -159,6 +159,37 @@ declare function getThreadListKey(threadKey: string, threadId: string): string;
159
159
  * @param threadId - Thread id as provided to the thread manager.
160
160
  */
161
161
  declare function getThreadMetaKey(threadKey: string, threadId: string): string;
162
+ /**
163
+ * Build the Redis key that stores a thread's persisted state slice
164
+ * (tasks + custom state) written by zeitlich's session loop on every
165
+ * exit path.
166
+ *
167
+ * Consumers can read this key with `redis.get(getThreadStateKey(key, id))`
168
+ * and `JSON.parse` the result into a {@link PersistedThreadState}.
169
+ *
170
+ * @param threadKey - Thread key (defaults to `"messages"` inside the
171
+ * thread manager, but downstream adapters may pass
172
+ * their own value).
173
+ * @param threadId - Thread id as provided to the thread manager.
174
+ */
175
+ declare function getThreadStateKey(threadKey: string, threadId: string): string;
176
+ /**
177
+ * Build the Redis key that guards an idempotent append against a
178
+ * duplicate write of the message (or message batch) identified by
179
+ * `dedupId`. Zeitlich's thread manager writes one of these per
180
+ * single-message append (and one per batch for multi-message appends),
181
+ * keyed by the message id returned by the configured `idOf`.
182
+ *
183
+ * Note: the key layout intentionally does **not** include the
184
+ * `threadKey` prefix — the dedup namespace is shared across thread
185
+ * keys for a given `threadId`, mirroring the original internal
186
+ * implementation.
187
+ *
188
+ * @param threadId - Thread id as provided to the thread manager.
189
+ * @param dedupId - Joined message ids (single message id for the
190
+ * common single-append case).
191
+ */
192
+ declare function getThreadDedupKey(threadId: string, dedupId: string): string;
162
193
 
163
194
  /**
164
195
  * Creates an agent state manager for tracking workflow state.
@@ -856,4 +887,4 @@ declare const createAskUserQuestionHandler: () => ActivityToolHandler<AskUserQue
856
887
  }[];
857
888
  }>;
858
889
 
859
- export { createTaskGetHandler as $, hasDirectory as A, type BashArgs as B, proxyVirtualFsOps as C, DEFAULT_SUBAGENT_WORKFLOW_RUN_TIMEOUT as D, type SubagentArgs as E, type FileEditArgs as F, type GlobArgs as G, parseSkillFile as H, createReadSkillTool as I, createReadSkillHandler as J, globTool as K, grepTool as L, type GrepArgs as M, readFileTool as N, type ObservabilityHooks as O, writeFileTool as P, editTool as Q, type ReadSkillArgs as R, type SessionStartedEvent as S, THREAD_TTL_SECONDS as T, taskCreateTool as U, type TaskCreateArgs as V, type WorkflowConfig as W, createTaskCreateHandler as X, taskGetTool as Y, type ZeitlichObservabilitySinks as Z, type TaskGetArgs as _, type FileReadArgs as a, taskListTool as a0, type TaskListArgs as a1, createTaskListHandler as a2, taskUpdateTool as a3, type TaskUpdateArgs as a4, createTaskUpdateHandler as a5, bashTool as a6, createBashToolDescription as a7, askUserQuestionTool as a8, type AskUserQuestionArgs as a9, createAskUserQuestionHandler as aa, type FileWriteArgs as b, type FileTreeAccessor as c, createSession as d, defineWorkflow as e, type WorkflowInput as f, type WorkflowSessionInput as g, getShortId as h, getThreadListKey as i, getThreadMetaKey as j, createAgentStateManager as k, createToolRouter as l, hasNoOtherToolCalls as m, defineTool as n, defineSubagent as o, defineSubagentWorkflow as p, createObservabilityHooks as q, composeHooks as r, type SessionEndedEvent as s, type TurnCompletedEvent as t, type ToolExecutedEvent as u, proxyRunAgent as v, applyVirtualTreeMutations as w, formatVirtualFileTree as x, hasFileWithMimeType as y, filesWithMimeType as z };
890
+ export { globTool as $, type AskUserQuestionArgs as A, type BashArgs as B, createTaskGetHandler as C, DEFAULT_SUBAGENT_WORKFLOW_RUN_TIMEOUT as D, createTaskListHandler as E, type FileEditArgs as F, type GlobArgs as G, createTaskUpdateHandler as H, createToolRouter as I, defineSubagent as J, defineSubagentWorkflow as K, defineTool as L, defineWorkflow as M, editTool as N, type ObservabilityHooks as O, filesWithMimeType as P, formatVirtualFileTree as Q, type ReadSkillArgs as R, type SessionEndedEvent as S, THREAD_TTL_SECONDS as T, getShortId as U, getThreadDedupKey as V, type WorkflowConfig as W, getThreadListKey as X, getThreadMetaKey as Y, type ZeitlichObservabilitySinks as Z, getThreadStateKey as _, type FileReadArgs as a, grepTool as a0, hasDirectory as a1, hasFileWithMimeType as a2, hasNoOtherToolCalls as a3, parseSkillFile as a4, proxyRunAgent as a5, proxyVirtualFsOps as a6, readFileTool as a7, taskCreateTool as a8, taskGetTool as a9, taskListTool as aa, taskUpdateTool as ab, writeFileTool as ac, type FileWriteArgs as b, type FileTreeAccessor as c, type GrepArgs as d, type SessionStartedEvent as e, type SubagentArgs as f, type TaskCreateArgs as g, type TaskGetArgs as h, type TaskListArgs as i, type TaskUpdateArgs as j, type ToolExecutedEvent as k, type TurnCompletedEvent as l, type WorkflowInput as m, type WorkflowSessionInput as n, applyVirtualTreeMutations as o, askUserQuestionTool as p, bashTool as q, composeHooks as r, createAgentStateManager as s, createAskUserQuestionHandler as t, createBashToolDescription as u, createObservabilityHooks as v, createReadSkillHandler as w, createReadSkillTool as x, createSession as y, createTaskCreateHandler as z };
package/dist/workflow.cjs CHANGED
@@ -1034,7 +1034,9 @@ async function createSession(config) {
1034
1034
  appendAgentMessage,
1035
1035
  forkThread,
1036
1036
  loadThreadState,
1037
- saveThreadState
1037
+ saveThreadState,
1038
+ hydrateThread,
1039
+ flushThread
1038
1040
  } = threadOps;
1039
1041
  const plugins = [];
1040
1042
  let destroySubagentSandboxes;
@@ -1094,10 +1096,7 @@ async function createSession(config) {
1094
1096
  stateManager.run();
1095
1097
  }
1096
1098
  );
1097
- const lifecycle = resolveSessionLifecycle(
1098
- sandboxInit,
1099
- sandboxShutdown
1100
- );
1099
+ const lifecycle = resolveSessionLifecycle(sandboxInit, sandboxShutdown);
1101
1100
  const sandboxMode = lifecycle.mode;
1102
1101
  const resolvedShutdown = lifecycle.shutdown;
1103
1102
  let sandboxId;
@@ -1172,20 +1171,6 @@ async function createSession(config) {
1172
1171
  ...baseSnapshot && { baseSnapshot }
1173
1172
  });
1174
1173
  }
1175
- if (hooks.onSessionStart) {
1176
- await hooks.onSessionStart({
1177
- threadId,
1178
- agentName,
1179
- metadata
1180
- });
1181
- }
1182
- workflow.log.info("session started", {
1183
- agentName,
1184
- threadId,
1185
- threadMode,
1186
- maxTurns,
1187
- ...sandboxId && { sandboxId }
1188
- });
1189
1174
  const sessionStartMs = Date.now();
1190
1175
  const systemPrompt = stateManager.getSystemPrompt();
1191
1176
  const rehydrateFromSlice = (slice) => {
@@ -1195,10 +1180,12 @@ async function createSession(config) {
1195
1180
  });
1196
1181
  };
1197
1182
  if (threadMode === "fork" && sourceThreadId) {
1183
+ await hydrateThread(sourceThreadId, threadKey);
1198
1184
  await forkThread(sourceThreadId, threadId, threadKey);
1199
1185
  const forkedSlice = await loadThreadState(threadId, threadKey);
1200
1186
  if (forkedSlice) rehydrateFromSlice(forkedSlice);
1201
1187
  } else if (threadMode === "continue") {
1188
+ await hydrateThread(threadId, threadKey);
1202
1189
  const continuedSlice = await loadThreadState(threadId, threadKey);
1203
1190
  if (continuedSlice) rehydrateFromSlice(continuedSlice);
1204
1191
  } else {
@@ -1258,6 +1245,20 @@ async function createSession(config) {
1258
1245
  );
1259
1246
  let exitReason = "completed";
1260
1247
  let finalMessage = null;
1248
+ if (hooks.onSessionStart) {
1249
+ await hooks.onSessionStart({
1250
+ threadId,
1251
+ agentName,
1252
+ metadata
1253
+ });
1254
+ }
1255
+ workflow.log.info("session started", {
1256
+ agentName,
1257
+ threadId,
1258
+ threadMode,
1259
+ maxTurns,
1260
+ ...sandboxId && { sandboxId }
1261
+ });
1261
1262
  try {
1262
1263
  let assistantId;
1263
1264
  while (stateManager.isRunning() && !stateManager.isTerminal() && stateManager.getTurns() < maxTurns) {
@@ -1366,6 +1367,15 @@ async function createSession(config) {
1366
1367
  error: persistError instanceof Error ? persistError.message : String(persistError)
1367
1368
  });
1368
1369
  }
1370
+ try {
1371
+ await flushThread(threadId, threadKey);
1372
+ } catch (flushError) {
1373
+ workflow.log.warn("failed to flush thread to cold tier", {
1374
+ agentName,
1375
+ threadId,
1376
+ error: flushError instanceof Error ? flushError.message : String(flushError)
1377
+ });
1378
+ }
1369
1379
  await callSessionEnd(exitReason, stateManager.getTurns());
1370
1380
  if (sandboxOwned && sandboxId && sandboxOps) {
1371
1381
  switch (resolvedShutdown) {