zeitlich 0.2.45 → 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 (89) hide show
  1. package/README.md +78 -10
  2. package/dist/{activities-CrN-ghLo.d.ts → activities-Bm4TLTid.d.ts} +22 -2
  3. package/dist/{activities-Coafq5zr.d.cts → activities-CyeiqK_f.d.cts} +22 -2
  4. package/dist/adapters/thread/anthropic/index.cjs +171 -65
  5. package/dist/adapters/thread/anthropic/index.cjs.map +1 -1
  6. package/dist/adapters/thread/anthropic/index.d.cts +19 -4
  7. package/dist/adapters/thread/anthropic/index.d.ts +19 -4
  8. package/dist/adapters/thread/anthropic/index.js +171 -65
  9. package/dist/adapters/thread/anthropic/index.js.map +1 -1
  10. package/dist/adapters/thread/anthropic/workflow.cjs +3 -1
  11. package/dist/adapters/thread/anthropic/workflow.cjs.map +1 -1
  12. package/dist/adapters/thread/anthropic/workflow.d.cts +4 -4
  13. package/dist/adapters/thread/anthropic/workflow.d.ts +4 -4
  14. package/dist/adapters/thread/anthropic/workflow.js +3 -1
  15. package/dist/adapters/thread/anthropic/workflow.js.map +1 -1
  16. package/dist/adapters/thread/google-genai/index.cjs +171 -69
  17. package/dist/adapters/thread/google-genai/index.cjs.map +1 -1
  18. package/dist/adapters/thread/google-genai/index.d.cts +5 -4
  19. package/dist/adapters/thread/google-genai/index.d.ts +5 -4
  20. package/dist/adapters/thread/google-genai/index.js +171 -69
  21. package/dist/adapters/thread/google-genai/index.js.map +1 -1
  22. package/dist/adapters/thread/google-genai/workflow.cjs +3 -1
  23. package/dist/adapters/thread/google-genai/workflow.cjs.map +1 -1
  24. package/dist/adapters/thread/google-genai/workflow.d.cts +5 -4
  25. package/dist/adapters/thread/google-genai/workflow.d.ts +5 -4
  26. package/dist/adapters/thread/google-genai/workflow.js +3 -1
  27. package/dist/adapters/thread/google-genai/workflow.js.map +1 -1
  28. package/dist/adapters/thread/langchain/index.cjs +170 -66
  29. package/dist/adapters/thread/langchain/index.cjs.map +1 -1
  30. package/dist/adapters/thread/langchain/index.d.cts +18 -4
  31. package/dist/adapters/thread/langchain/index.d.ts +18 -4
  32. package/dist/adapters/thread/langchain/index.js +170 -66
  33. package/dist/adapters/thread/langchain/index.js.map +1 -1
  34. package/dist/adapters/thread/langchain/workflow.cjs +3 -1
  35. package/dist/adapters/thread/langchain/workflow.cjs.map +1 -1
  36. package/dist/adapters/thread/langchain/workflow.d.cts +4 -4
  37. package/dist/adapters/thread/langchain/workflow.d.ts +4 -4
  38. package/dist/adapters/thread/langchain/workflow.js +3 -1
  39. package/dist/adapters/thread/langchain/workflow.js.map +1 -1
  40. package/dist/cold-store-BC5L5Z8A.d.cts +117 -0
  41. package/dist/cold-store-CFHwemBJ.d.ts +117 -0
  42. package/dist/index.cjs +226 -27
  43. package/dist/index.cjs.map +1 -1
  44. package/dist/index.d.cts +138 -8
  45. package/dist/index.d.ts +138 -8
  46. package/dist/index.js +220 -28
  47. package/dist/index.js.map +1 -1
  48. package/dist/{proxy-Bf7uI-Hw.d.cts → proxy-BxFyd6cg.d.cts} +1 -1
  49. package/dist/{proxy-COqA95FW.d.ts → proxy-Cskmj4Yx.d.ts} +1 -1
  50. package/dist/{thread-manager-BsLO3Fgc.d.cts → thread-manager-9tezUcLW.d.cts} +8 -2
  51. package/dist/{thread-manager-Bi1XlbpJ.d.ts → thread-manager-B-zy3xrs.d.ts} +8 -2
  52. package/dist/{thread-manager-wRVVBFgj.d.cts → thread-manager-D33SUmZa.d.cts} +8 -2
  53. package/dist/{thread-manager-BhkOyQ1I.d.ts → thread-manager-DduoSkvJ.d.ts} +8 -2
  54. package/dist/{types-CdALEF3z.d.cts → types-CnuN9T6t.d.cts} +22 -0
  55. package/dist/{types-ChAy_jSP.d.ts → types-CwN6_tAL.d.ts} +22 -0
  56. package/dist/{types-BkX4HLzi.d.ts → types-L5bvbF-n.d.ts} +17 -1
  57. package/dist/{types-C66-BVBr.d.cts → types-oxt8GN97.d.cts} +17 -1
  58. package/dist/{workflow-BwT5EybR.d.ts → workflow-B1TOcHbt.d.ts} +33 -2
  59. package/dist/{workflow-DMmiaw6w.d.cts → workflow-DIaIV7L2.d.cts} +33 -2
  60. package/dist/workflow.cjs +14 -1
  61. package/dist/workflow.cjs.map +1 -1
  62. package/dist/workflow.d.cts +2 -2
  63. package/dist/workflow.d.ts +2 -2
  64. package/dist/workflow.js +14 -1
  65. package/dist/workflow.js.map +1 -1
  66. package/package.json +6 -1
  67. package/src/adapters/thread/anthropic/activities.ts +72 -36
  68. package/src/adapters/thread/anthropic/thread-manager.ts +9 -1
  69. package/src/adapters/thread/google-genai/activities.ts +64 -40
  70. package/src/adapters/thread/google-genai/thread-manager.ts +9 -1
  71. package/src/adapters/thread/langchain/activities.ts +63 -36
  72. package/src/adapters/thread/langchain/thread-manager.ts +9 -1
  73. package/src/index.ts +20 -1
  74. package/src/lib/session/session-edge-cases.integration.test.ts +12 -0
  75. package/src/lib/session/session.integration.test.ts +138 -0
  76. package/src/lib/session/session.ts +29 -0
  77. package/src/lib/session/types.ts +22 -0
  78. package/src/lib/thread/cold-store.test.ts +193 -0
  79. package/src/lib/thread/cold-store.ts +250 -0
  80. package/src/lib/thread/index.ts +32 -0
  81. package/src/lib/thread/keys.ts +20 -0
  82. package/src/lib/thread/manager.ts +16 -27
  83. package/src/lib/thread/proxy.ts +2 -0
  84. package/src/lib/thread/snapshot.test.ts +443 -0
  85. package/src/lib/thread/snapshot.ts +163 -0
  86. package/src/lib/thread/test-utils.ts +228 -0
  87. package/src/lib/thread/tiered.test.ts +281 -0
  88. package/src/lib/thread/tiered.ts +135 -0
  89. package/src/lib/thread/types.ts +16 -0
package/dist/index.d.cts CHANGED
@@ -1,17 +1,19 @@
1
- import { B as BashArgs, F as FileEditArgs, G as GlobArgs, a as FileReadArgs, b as FileWriteArgs } from './workflow-DMmiaw6w.cjs';
2
- export { A as AskUserQuestionArgs, D as DEFAULT_SUBAGENT_WORKFLOW_RUN_TIMEOUT, c as FileTreeAccessor, d as GrepArgs, O as ObservabilityHooks, R as ReadSkillArgs, S as SessionEndedEvent, e as SessionStartedEvent, f as SubagentArgs, T as THREAD_TTL_SECONDS, g as TaskCreateArgs, h as TaskGetArgs, i as TaskListArgs, j as TaskUpdateArgs, k as ToolExecutedEvent, l as TurnCompletedEvent, W as WorkflowConfig, m as WorkflowInput, n as WorkflowSessionInput, Z as ZeitlichObservabilitySinks, o as applyVirtualTreeMutations, p as askUserQuestionTool, q as bashTool, r as composeHooks, s as createAgentStateManager, t as createAskUserQuestionHandler, u as createBashToolDescription, v as createObservabilityHooks, w as createReadSkillHandler, x as createReadSkillTool, y as createSession, z as createTaskCreateHandler, C as createTaskGetHandler, E as createTaskListHandler, H as createTaskUpdateHandler, I as createToolRouter, J as defineSubagent, K as defineSubagentWorkflow, L as defineTool, M as defineWorkflow, N as editTool, P as filesWithMimeType, Q as formatVirtualFileTree, U as getShortId, V as getThreadListKey, X as getThreadMetaKey, Y as globTool, _ as grepTool, $ as hasDirectory, a0 as hasFileWithMimeType, a1 as hasNoOtherToolCalls, a2 as parseSkillFile, a3 as proxyRunAgent, a4 as proxyVirtualFsOps, a5 as readFileTool, a6 as taskCreateTool, a7 as taskGetTool, a8 as taskListTool, a9 as taskUpdateTool, aa as writeFileTool } from './workflow-DMmiaw6w.cjs';
3
- import { R as RouterContext, e as ToolResultConfig, d as ActivityToolHandler, J as JsonValue, c as ToolHandlerResponse, B as BaseAgentState, f as RunAgentConfig, g as SkillProvider, h as SkillMetadata, i as Skill, F as FileEntryMetadata, j as FileResolver, V as VirtualFsContext, k as TreeMutation, l as PrefixedVirtualFsOps } from './types-CdALEF3z.cjs';
4
- export { m as AgentConfig, n as AgentFile, A as AgentResponse, o as AgentState, p as AgentStateManager, q as AgentStatus, r as AppendToolResultFn, s as FileEntry, H as Hooks, I as InferToolResults, t as JsonPrimitive, u as JsonSerializable, a as ModelInvoker, M as ModelInvokerConfig, v as ParsedToolCall, w as ParsedToolCallUnion, P as PersistedThreadState, x as PostHumanMessageAppendHook, y as PostHumanMessageAppendHookContext, z as PostToolUseFailureHook, C as PostToolUseFailureHookContext, D as PostToolUseFailureHookResult, E as PostToolUseHook, G as PostToolUseHookContext, K as PreHumanMessageAppendHook, L as PreHumanMessageAppendHookContext, N as PreToolUseHook, O as PreToolUseHookContext, Q as PreToolUseHookResult, b as PrefixedThreadOps, U as ProcessToolCallsContext, W as ProcessToolCallsResult, X as RawToolCall, Y as RewindSignal, Z as RunAgentActivity, _ as SandboxInit, $ as SandboxShutdown, S as ScopedPrefix, a0 as SerializableToolDefinition, a1 as SessionConfig, a2 as SessionEndHook, a3 as SessionEndHookContext, a4 as SessionExitReason, a5 as SessionRequiredCaps, a6 as SessionResult, a7 as SessionStartHook, a8 as SessionStartHookContext, a9 as SubagentChildWorkflowOptions, aa as SubagentConfig, ab as SubagentContinuationCaps, ac as SubagentDefinition, ad as SubagentFnResult, ae as SubagentHandlerResponse, af as SubagentHooks, ag as SubagentSandboxConfig, ah as SubagentSandboxShutdown, ai as SubagentSessionInput, aj as SubagentWorkflow, ak as SubagentWorkflowInput, al as TaskStatus, am as ThreadInit, T as ThreadOps, an as TokenUsage, ao as ToolArgs, ap as ToolCallResult, aq as ToolCallResultUnion, ar as ToolDefinition, as as ToolHandler, at as ToolHooks, au as ToolMap, av as ToolNames, aw as ToolResult, ax as ToolRouter, ay as ToolRouterHooks, az as ToolWithHandler, aA as VirtualFileSystem, aB as VirtualFileTree, aC as VirtualFsOps, aD as VirtualFsState, aE as WorkflowTask, aF as ZeitlichSession, aG as isTerminalStatus } from './types-CdALEF3z.cjs';
1
+ import { B as BashArgs, F as FileEditArgs, G as GlobArgs, a as FileReadArgs, b as FileWriteArgs } from './workflow-DIaIV7L2.cjs';
2
+ export { A as AskUserQuestionArgs, D as DEFAULT_SUBAGENT_WORKFLOW_RUN_TIMEOUT, c as FileTreeAccessor, d as GrepArgs, O as ObservabilityHooks, R as ReadSkillArgs, S as SessionEndedEvent, e as SessionStartedEvent, f as SubagentArgs, T as THREAD_TTL_SECONDS, g as TaskCreateArgs, h as TaskGetArgs, i as TaskListArgs, j as TaskUpdateArgs, k as ToolExecutedEvent, l as TurnCompletedEvent, W as WorkflowConfig, m as WorkflowInput, n as WorkflowSessionInput, Z as ZeitlichObservabilitySinks, o as applyVirtualTreeMutations, p as askUserQuestionTool, q as bashTool, r as composeHooks, s as createAgentStateManager, t as createAskUserQuestionHandler, u as createBashToolDescription, v as createObservabilityHooks, w as createReadSkillHandler, x as createReadSkillTool, y as createSession, z as createTaskCreateHandler, C as createTaskGetHandler, E as createTaskListHandler, H as createTaskUpdateHandler, I as createToolRouter, J as defineSubagent, K as defineSubagentWorkflow, L as defineTool, M as defineWorkflow, N as editTool, P as filesWithMimeType, Q as formatVirtualFileTree, U as getShortId, V as getThreadDedupKey, X as getThreadListKey, Y as getThreadMetaKey, _ as getThreadStateKey, $ as globTool, a0 as grepTool, a1 as hasDirectory, a2 as hasFileWithMimeType, a3 as hasNoOtherToolCalls, a4 as parseSkillFile, a5 as proxyRunAgent, a6 as proxyVirtualFsOps, a7 as readFileTool, a8 as taskCreateTool, a9 as taskGetTool, aa as taskListTool, ab as taskUpdateTool, ac as writeFileTool } from './workflow-DIaIV7L2.cjs';
3
+ import { R as RouterContext, e as ToolResultConfig, d as ActivityToolHandler, J as JsonValue, c as ToolHandlerResponse, B as BaseAgentState, f as RunAgentConfig, g as SkillProvider, h as SkillMetadata, i as Skill, F as FileEntryMetadata, j as FileResolver, V as VirtualFsContext, k as TreeMutation, l as PrefixedVirtualFsOps } from './types-CnuN9T6t.cjs';
4
+ export { m as AgentConfig, n as AgentFile, A as AgentResponse, o as AgentState, p as AgentStateManager, q as AgentStatus, r as AppendToolResultFn, s as FileEntry, H as Hooks, I as InferToolResults, t as JsonPrimitive, u as JsonSerializable, a as ModelInvoker, M as ModelInvokerConfig, v as ParsedToolCall, w as ParsedToolCallUnion, P as PersistedThreadState, x as PostHumanMessageAppendHook, y as PostHumanMessageAppendHookContext, z as PostToolUseFailureHook, C as PostToolUseFailureHookContext, D as PostToolUseFailureHookResult, E as PostToolUseHook, G as PostToolUseHookContext, K as PreHumanMessageAppendHook, L as PreHumanMessageAppendHookContext, N as PreToolUseHook, O as PreToolUseHookContext, Q as PreToolUseHookResult, b as PrefixedThreadOps, U as ProcessToolCallsContext, W as ProcessToolCallsResult, X as RawToolCall, Y as RewindSignal, Z as RunAgentActivity, _ as SandboxInit, $ as SandboxShutdown, S as ScopedPrefix, a0 as SerializableToolDefinition, a1 as SessionConfig, a2 as SessionEndHook, a3 as SessionEndHookContext, a4 as SessionExitReason, a5 as SessionRequiredCaps, a6 as SessionResult, a7 as SessionStartHook, a8 as SessionStartHookContext, a9 as SubagentChildWorkflowOptions, aa as SubagentConfig, ab as SubagentContinuationCaps, ac as SubagentDefinition, ad as SubagentFnResult, ae as SubagentHandlerResponse, af as SubagentHooks, ag as SubagentSandboxConfig, ah as SubagentSandboxShutdown, ai as SubagentSessionInput, aj as SubagentWorkflow, ak as SubagentWorkflowInput, al as TaskStatus, am as ThreadInit, T as ThreadOps, an as TokenUsage, ao as ToolArgs, ap as ToolCallResult, aq as ToolCallResultUnion, ar as ToolDefinition, as as ToolHandler, at as ToolHooks, au as ToolMap, av as ToolNames, aw as ToolResult, ax as ToolRouter, ay as ToolRouterHooks, az as ToolWithHandler, aA as VirtualFileSystem, aB as VirtualFileTree, aC as VirtualFsOps, aD as VirtualFsState, aE as WorkflowTask, aF as ZeitlichSession, aG as isTerminalStatus } from './types-CnuN9T6t.cjs';
5
5
  import { b as Sandbox, c as SandboxFileSystem, a as SandboxCreateOptions, h as SandboxCapability, d as SandboxProvider, g as SandboxSnapshot, P as PrefixedSandboxOps, F as FileStat, D as DirentEntry, E as ExecResult } from './types-CJ7tCdl6.cjs';
6
6
  export { i as ExecOptions, e as SandboxCapabilities, f as SandboxCreateResult, j as SandboxNotFoundError, k as SandboxNotSupportedError, S as SandboxOps } from './types-CJ7tCdl6.cjs';
7
7
  import { WorkflowClient } from '@temporalio/client';
8
- import { a as ThreadManagerConfig, B as BaseThreadManager } from './types-C66-BVBr.cjs';
9
- export { P as ProviderThreadManager } from './types-C66-BVBr.cjs';
8
+ import { a as ThreadManagerConfig, B as BaseThreadManager } from './types-oxt8GN97.cjs';
9
+ export { P as ProviderThreadManager } from './types-oxt8GN97.cjs';
10
+ import { C as ColdThreadStore, T as ThreadSnapshot } from './cold-store-BC5L5Z8A.cjs';
11
+ export { S as S3ColdStoreConfig, a as S3LikeClient, c as createS3ColdStore } from './cold-store-BC5L5Z8A.cjs';
12
+ import Redis from 'ioredis';
10
13
  import 'zod';
11
14
  import '@temporalio/common';
12
15
  import '@temporalio/workflow';
13
16
  import '@temporalio/common/lib/interfaces';
14
- import 'ioredis';
15
17
 
16
18
  /**
17
19
  * Wraps a tool handler to automatically append its result directly to the
@@ -232,6 +234,134 @@ declare class FileSystemSkillProvider implements SkillProvider {
232
234
  */
233
235
  declare function createThreadManager<T>(config: ThreadManagerConfig<T>): BaseThreadManager<T>;
234
236
 
237
+ /**
238
+ * Tiered thread manager: Redis hot tier + pluggable cold tier.
239
+ *
240
+ * Wraps {@link createThreadManager} (Redis-only) and adds two
241
+ * session-boundary operations:
242
+ *
243
+ * - `hydrate()` — when the thread is cold (no meta key in Redis),
244
+ * restore the latest {@link ThreadSnapshot} from the cold store.
245
+ * Idempotent; no-op when the thread is already hot or when no
246
+ * snapshot exists.
247
+ * - `flush({ deleteHot })` — write the current Redis state out to the
248
+ * cold store as one snapshot, then (by default) `DEL` the hot-tier
249
+ * keys so idle threads don't sit in Redis memory.
250
+ *
251
+ * All other operations (`append`, `load`, `fork`, `replaceAll`,
252
+ * `truncateFromId`, state I/O) delegate unchanged to the underlying
253
+ * Redis manager, so adapters and tests that use the
254
+ * `BaseThreadManager<T>` interface keep working with zero changes.
255
+ */
256
+
257
+ /** Configuration for {@link createTieredThreadManager}. */
258
+ interface TieredThreadManagerConfig<T> extends ThreadManagerConfig<T> {
259
+ /**
260
+ * Cold-tier archive. When omitted, `hydrate()` and `flush()` are
261
+ * no-ops and the manager behaves identically to
262
+ * {@link createThreadManager}.
263
+ */
264
+ coldStore?: ColdThreadStore;
265
+ }
266
+ /** Options for {@link TieredThreadManager.flush}. */
267
+ interface FlushOptions {
268
+ /**
269
+ * Delete the hot-tier Redis keys after a successful cold-tier
270
+ * write. Defaults to `true` when a cold store is configured —
271
+ * Redis is just a cache and a future continue/fork will
272
+ * re-hydrate in a single round-trip.
273
+ *
274
+ * Set to `false` to keep the hot tier warm (useful for tests or
275
+ * for "hot-after-flush" use cases where another session is expected
276
+ * to pick the thread up immediately).
277
+ */
278
+ deleteHot?: boolean;
279
+ }
280
+ /**
281
+ * Extension of {@link BaseThreadManager} with the two cold-tier
282
+ * lifecycle methods.
283
+ */
284
+ interface TieredThreadManager<T> extends BaseThreadManager<T> {
285
+ /**
286
+ * Restore the latest cold-tier snapshot into Redis when the thread
287
+ * is cold. Idempotent — safe to call from a retried activity.
288
+ */
289
+ hydrate(): Promise<void>;
290
+ /**
291
+ * Write the current Redis state to the cold tier and (optionally)
292
+ * drop the hot-tier keys. Idempotent — last-writer-wins on the
293
+ * cold side.
294
+ */
295
+ flush(opts?: FlushOptions): Promise<void>;
296
+ }
297
+ /**
298
+ * Build a thread manager backed by Redis (hot) and an optional
299
+ * pluggable cold store. See module docstring for the lifecycle
300
+ * semantics.
301
+ */
302
+ declare function createTieredThreadManager<T>(config: TieredThreadManagerConfig<T>): TieredThreadManager<T>;
303
+
304
+ /**
305
+ * Pure Redis I/O helpers for moving a thread between the hot tier
306
+ * (Redis lists + meta + state + dedup markers) and the cold tier
307
+ * (a single {@link ThreadSnapshot} blob in a {@link ColdThreadStore}).
308
+ *
309
+ * These helpers know nothing about S3 or the adapter-specific message
310
+ * envelope — they operate on the raw Redis representation. The
311
+ * tiered thread manager in `tiered.ts` is the only consumer.
312
+ */
313
+
314
+ /** Inputs shared by every snapshot operation. */
315
+ interface SnapshotCommon {
316
+ redis: Redis;
317
+ threadKey: string;
318
+ threadId: string;
319
+ }
320
+ /** Configuration for {@link encodeSnapshot}. */
321
+ interface EncodeSnapshotConfig extends SnapshotCommon {
322
+ /**
323
+ * Extract a dedup id from each raw-serialized message currently in
324
+ * the thread's Redis list. When omitted, the resulting snapshot has
325
+ * an empty `dedupIds` array — idempotency guarantees are best-effort
326
+ * once a thread crosses the hot/cold boundary.
327
+ */
328
+ idOf?: (raw: string) => string;
329
+ }
330
+ /**
331
+ * Build a {@link ThreadSnapshot} from the current hot-tier state.
332
+ *
333
+ * Returns `null` when no thread exists in the hot tier (the meta key
334
+ * is absent) — callers should treat that as "nothing to flush".
335
+ */
336
+ declare function encodeSnapshot(config: EncodeSnapshotConfig): Promise<ThreadSnapshot | null>;
337
+ /** Configuration for {@link applySnapshot}. */
338
+ interface ApplySnapshotConfig extends SnapshotCommon {
339
+ snapshot: ThreadSnapshot;
340
+ /** TTL applied to every Redis key. Defaults to {@link THREAD_TTL_SECONDS}. */
341
+ ttlSeconds?: number;
342
+ }
343
+ /**
344
+ * Restore a {@link ThreadSnapshot} into the hot tier.
345
+ *
346
+ * Idempotent — if the meta key already exists the thread is already
347
+ * hot and this is a no-op. The meta key is written **last** so a
348
+ * crash mid-restore leaves the thread cold (`load` / `append` will
349
+ * see "thread does not exist") and the next session's hydrate retries
350
+ * cleanly.
351
+ */
352
+ declare function applySnapshot(config: ApplySnapshotConfig): Promise<void>;
353
+ /** Configuration for {@link clearHotTier}. */
354
+ interface ClearHotTierConfig extends SnapshotCommon {
355
+ /** Dedup ids to delete alongside the list / meta / state keys. */
356
+ dedupIds?: string[];
357
+ }
358
+ /**
359
+ * Delete every Redis key the thread manager wrote for `(threadKey,
360
+ * threadId)`. Used by the tiered manager's `flush({ deleteHot: true })`
361
+ * to drop hot-tier memory after a successful archive write.
362
+ */
363
+ declare function clearHotTier(config: ClearHotTierConfig): Promise<void>;
364
+
235
365
  /**
236
366
  * Result returned by {@link SandboxManagerHooks.onPreCreate}.
237
367
  *
@@ -594,4 +724,4 @@ declare const toTree: (fs: SandboxFileSystem, opts?: {
594
724
  sort?: boolean;
595
725
  }) => Promise<string>;
596
726
 
597
- export { ActivityToolHandler, type AgentStateContext, BaseAgentState, BaseThreadManager, BashArgs, ExecResult, FileEditArgs, FileEntryMetadata, FileReadArgs, FileResolver, FileSystemSkillProvider, FileWriteArgs, GlobArgs, JsonValue, NodeFsSandboxFileSystem, type PreCreateHookResult, PrefixedSandboxOps, PrefixedVirtualFsOps, RouterContext, RunAgentConfig, Sandbox, SandboxCapability, type SandboxContext, SandboxCreateOptions, DirentEntry as SandboxDirentEntry, FileStat as SandboxFileStat, SandboxFileSystem, SandboxManager, type SandboxManagerHooks, SandboxProvider, SandboxSnapshot, Skill, SkillMetadata, SkillProvider, ThreadManagerConfig, ToolHandlerResponse, ToolResultConfig, TreeMutation, VirtualFsContext, type WithSandboxOptions, bashHandler, createRunAgentActivity, createThreadManager, createVirtualFsActivities, editHandler, getActivityContext, globHandler, queryParentWorkflowState, readFileHandler, toTree, withAutoAppend, withParentWorkflowState, withSandbox, withVirtualFs, writeFileHandler };
727
+ export { ActivityToolHandler, type AgentStateContext, type ApplySnapshotConfig, BaseAgentState, BaseThreadManager, BashArgs, type ClearHotTierConfig, ColdThreadStore, type EncodeSnapshotConfig, ExecResult, FileEditArgs, FileEntryMetadata, FileReadArgs, FileResolver, FileSystemSkillProvider, FileWriteArgs, type FlushOptions, GlobArgs, JsonValue, NodeFsSandboxFileSystem, type PreCreateHookResult, PrefixedSandboxOps, PrefixedVirtualFsOps, RouterContext, RunAgentConfig, Sandbox, SandboxCapability, type SandboxContext, SandboxCreateOptions, DirentEntry as SandboxDirentEntry, FileStat as SandboxFileStat, SandboxFileSystem, SandboxManager, type SandboxManagerHooks, SandboxProvider, SandboxSnapshot, Skill, SkillMetadata, SkillProvider, ThreadManagerConfig, ThreadSnapshot, type TieredThreadManager, type TieredThreadManagerConfig, ToolHandlerResponse, ToolResultConfig, TreeMutation, VirtualFsContext, type WithSandboxOptions, applySnapshot, bashHandler, clearHotTier, createRunAgentActivity, createThreadManager, createTieredThreadManager, createVirtualFsActivities, editHandler, encodeSnapshot, getActivityContext, globHandler, queryParentWorkflowState, readFileHandler, toTree, withAutoAppend, withParentWorkflowState, withSandbox, withVirtualFs, writeFileHandler };
package/dist/index.d.ts CHANGED
@@ -1,17 +1,19 @@
1
- import { B as BashArgs, F as FileEditArgs, G as GlobArgs, a as FileReadArgs, b as FileWriteArgs } from './workflow-BwT5EybR.js';
2
- export { A as AskUserQuestionArgs, D as DEFAULT_SUBAGENT_WORKFLOW_RUN_TIMEOUT, c as FileTreeAccessor, d as GrepArgs, O as ObservabilityHooks, R as ReadSkillArgs, S as SessionEndedEvent, e as SessionStartedEvent, f as SubagentArgs, T as THREAD_TTL_SECONDS, g as TaskCreateArgs, h as TaskGetArgs, i as TaskListArgs, j as TaskUpdateArgs, k as ToolExecutedEvent, l as TurnCompletedEvent, W as WorkflowConfig, m as WorkflowInput, n as WorkflowSessionInput, Z as ZeitlichObservabilitySinks, o as applyVirtualTreeMutations, p as askUserQuestionTool, q as bashTool, r as composeHooks, s as createAgentStateManager, t as createAskUserQuestionHandler, u as createBashToolDescription, v as createObservabilityHooks, w as createReadSkillHandler, x as createReadSkillTool, y as createSession, z as createTaskCreateHandler, C as createTaskGetHandler, E as createTaskListHandler, H as createTaskUpdateHandler, I as createToolRouter, J as defineSubagent, K as defineSubagentWorkflow, L as defineTool, M as defineWorkflow, N as editTool, P as filesWithMimeType, Q as formatVirtualFileTree, U as getShortId, V as getThreadListKey, X as getThreadMetaKey, Y as globTool, _ as grepTool, $ as hasDirectory, a0 as hasFileWithMimeType, a1 as hasNoOtherToolCalls, a2 as parseSkillFile, a3 as proxyRunAgent, a4 as proxyVirtualFsOps, a5 as readFileTool, a6 as taskCreateTool, a7 as taskGetTool, a8 as taskListTool, a9 as taskUpdateTool, aa as writeFileTool } from './workflow-BwT5EybR.js';
3
- import { R as RouterContext, e as ToolResultConfig, d as ActivityToolHandler, J as JsonValue, c as ToolHandlerResponse, B as BaseAgentState, f as RunAgentConfig, g as SkillProvider, h as SkillMetadata, i as Skill, F as FileEntryMetadata, j as FileResolver, V as VirtualFsContext, k as TreeMutation, l as PrefixedVirtualFsOps } from './types-ChAy_jSP.js';
4
- export { m as AgentConfig, n as AgentFile, A as AgentResponse, o as AgentState, p as AgentStateManager, q as AgentStatus, r as AppendToolResultFn, s as FileEntry, H as Hooks, I as InferToolResults, t as JsonPrimitive, u as JsonSerializable, a as ModelInvoker, M as ModelInvokerConfig, v as ParsedToolCall, w as ParsedToolCallUnion, P as PersistedThreadState, x as PostHumanMessageAppendHook, y as PostHumanMessageAppendHookContext, z as PostToolUseFailureHook, C as PostToolUseFailureHookContext, D as PostToolUseFailureHookResult, E as PostToolUseHook, G as PostToolUseHookContext, K as PreHumanMessageAppendHook, L as PreHumanMessageAppendHookContext, N as PreToolUseHook, O as PreToolUseHookContext, Q as PreToolUseHookResult, b as PrefixedThreadOps, U as ProcessToolCallsContext, W as ProcessToolCallsResult, X as RawToolCall, Y as RewindSignal, Z as RunAgentActivity, _ as SandboxInit, $ as SandboxShutdown, S as ScopedPrefix, a0 as SerializableToolDefinition, a1 as SessionConfig, a2 as SessionEndHook, a3 as SessionEndHookContext, a4 as SessionExitReason, a5 as SessionRequiredCaps, a6 as SessionResult, a7 as SessionStartHook, a8 as SessionStartHookContext, a9 as SubagentChildWorkflowOptions, aa as SubagentConfig, ab as SubagentContinuationCaps, ac as SubagentDefinition, ad as SubagentFnResult, ae as SubagentHandlerResponse, af as SubagentHooks, ag as SubagentSandboxConfig, ah as SubagentSandboxShutdown, ai as SubagentSessionInput, aj as SubagentWorkflow, ak as SubagentWorkflowInput, al as TaskStatus, am as ThreadInit, T as ThreadOps, an as TokenUsage, ao as ToolArgs, ap as ToolCallResult, aq as ToolCallResultUnion, ar as ToolDefinition, as as ToolHandler, at as ToolHooks, au as ToolMap, av as ToolNames, aw as ToolResult, ax as ToolRouter, ay as ToolRouterHooks, az as ToolWithHandler, aA as VirtualFileSystem, aB as VirtualFileTree, aC as VirtualFsOps, aD as VirtualFsState, aE as WorkflowTask, aF as ZeitlichSession, aG as isTerminalStatus } from './types-ChAy_jSP.js';
1
+ import { B as BashArgs, F as FileEditArgs, G as GlobArgs, a as FileReadArgs, b as FileWriteArgs } from './workflow-B1TOcHbt.js';
2
+ export { A as AskUserQuestionArgs, D as DEFAULT_SUBAGENT_WORKFLOW_RUN_TIMEOUT, c as FileTreeAccessor, d as GrepArgs, O as ObservabilityHooks, R as ReadSkillArgs, S as SessionEndedEvent, e as SessionStartedEvent, f as SubagentArgs, T as THREAD_TTL_SECONDS, g as TaskCreateArgs, h as TaskGetArgs, i as TaskListArgs, j as TaskUpdateArgs, k as ToolExecutedEvent, l as TurnCompletedEvent, W as WorkflowConfig, m as WorkflowInput, n as WorkflowSessionInput, Z as ZeitlichObservabilitySinks, o as applyVirtualTreeMutations, p as askUserQuestionTool, q as bashTool, r as composeHooks, s as createAgentStateManager, t as createAskUserQuestionHandler, u as createBashToolDescription, v as createObservabilityHooks, w as createReadSkillHandler, x as createReadSkillTool, y as createSession, z as createTaskCreateHandler, C as createTaskGetHandler, E as createTaskListHandler, H as createTaskUpdateHandler, I as createToolRouter, J as defineSubagent, K as defineSubagentWorkflow, L as defineTool, M as defineWorkflow, N as editTool, P as filesWithMimeType, Q as formatVirtualFileTree, U as getShortId, V as getThreadDedupKey, X as getThreadListKey, Y as getThreadMetaKey, _ as getThreadStateKey, $ as globTool, a0 as grepTool, a1 as hasDirectory, a2 as hasFileWithMimeType, a3 as hasNoOtherToolCalls, a4 as parseSkillFile, a5 as proxyRunAgent, a6 as proxyVirtualFsOps, a7 as readFileTool, a8 as taskCreateTool, a9 as taskGetTool, aa as taskListTool, ab as taskUpdateTool, ac as writeFileTool } from './workflow-B1TOcHbt.js';
3
+ import { R as RouterContext, e as ToolResultConfig, d as ActivityToolHandler, J as JsonValue, c as ToolHandlerResponse, B as BaseAgentState, f as RunAgentConfig, g as SkillProvider, h as SkillMetadata, i as Skill, F as FileEntryMetadata, j as FileResolver, V as VirtualFsContext, k as TreeMutation, l as PrefixedVirtualFsOps } from './types-CwN6_tAL.js';
4
+ export { m as AgentConfig, n as AgentFile, A as AgentResponse, o as AgentState, p as AgentStateManager, q as AgentStatus, r as AppendToolResultFn, s as FileEntry, H as Hooks, I as InferToolResults, t as JsonPrimitive, u as JsonSerializable, a as ModelInvoker, M as ModelInvokerConfig, v as ParsedToolCall, w as ParsedToolCallUnion, P as PersistedThreadState, x as PostHumanMessageAppendHook, y as PostHumanMessageAppendHookContext, z as PostToolUseFailureHook, C as PostToolUseFailureHookContext, D as PostToolUseFailureHookResult, E as PostToolUseHook, G as PostToolUseHookContext, K as PreHumanMessageAppendHook, L as PreHumanMessageAppendHookContext, N as PreToolUseHook, O as PreToolUseHookContext, Q as PreToolUseHookResult, b as PrefixedThreadOps, U as ProcessToolCallsContext, W as ProcessToolCallsResult, X as RawToolCall, Y as RewindSignal, Z as RunAgentActivity, _ as SandboxInit, $ as SandboxShutdown, S as ScopedPrefix, a0 as SerializableToolDefinition, a1 as SessionConfig, a2 as SessionEndHook, a3 as SessionEndHookContext, a4 as SessionExitReason, a5 as SessionRequiredCaps, a6 as SessionResult, a7 as SessionStartHook, a8 as SessionStartHookContext, a9 as SubagentChildWorkflowOptions, aa as SubagentConfig, ab as SubagentContinuationCaps, ac as SubagentDefinition, ad as SubagentFnResult, ae as SubagentHandlerResponse, af as SubagentHooks, ag as SubagentSandboxConfig, ah as SubagentSandboxShutdown, ai as SubagentSessionInput, aj as SubagentWorkflow, ak as SubagentWorkflowInput, al as TaskStatus, am as ThreadInit, T as ThreadOps, an as TokenUsage, ao as ToolArgs, ap as ToolCallResult, aq as ToolCallResultUnion, ar as ToolDefinition, as as ToolHandler, at as ToolHooks, au as ToolMap, av as ToolNames, aw as ToolResult, ax as ToolRouter, ay as ToolRouterHooks, az as ToolWithHandler, aA as VirtualFileSystem, aB as VirtualFileTree, aC as VirtualFsOps, aD as VirtualFsState, aE as WorkflowTask, aF as ZeitlichSession, aG as isTerminalStatus } from './types-CwN6_tAL.js';
5
5
  import { b as Sandbox, c as SandboxFileSystem, a as SandboxCreateOptions, h as SandboxCapability, d as SandboxProvider, g as SandboxSnapshot, P as PrefixedSandboxOps, F as FileStat, D as DirentEntry, E as ExecResult } from './types-CJ7tCdl6.js';
6
6
  export { i as ExecOptions, e as SandboxCapabilities, f as SandboxCreateResult, j as SandboxNotFoundError, k as SandboxNotSupportedError, S as SandboxOps } from './types-CJ7tCdl6.js';
7
7
  import { WorkflowClient } from '@temporalio/client';
8
- import { a as ThreadManagerConfig, B as BaseThreadManager } from './types-BkX4HLzi.js';
9
- export { P as ProviderThreadManager } from './types-BkX4HLzi.js';
8
+ import { a as ThreadManagerConfig, B as BaseThreadManager } from './types-L5bvbF-n.js';
9
+ export { P as ProviderThreadManager } from './types-L5bvbF-n.js';
10
+ import { C as ColdThreadStore, T as ThreadSnapshot } from './cold-store-CFHwemBJ.js';
11
+ export { S as S3ColdStoreConfig, a as S3LikeClient, c as createS3ColdStore } from './cold-store-CFHwemBJ.js';
12
+ import Redis from 'ioredis';
10
13
  import 'zod';
11
14
  import '@temporalio/common';
12
15
  import '@temporalio/workflow';
13
16
  import '@temporalio/common/lib/interfaces';
14
- import 'ioredis';
15
17
 
16
18
  /**
17
19
  * Wraps a tool handler to automatically append its result directly to the
@@ -232,6 +234,134 @@ declare class FileSystemSkillProvider implements SkillProvider {
232
234
  */
233
235
  declare function createThreadManager<T>(config: ThreadManagerConfig<T>): BaseThreadManager<T>;
234
236
 
237
+ /**
238
+ * Tiered thread manager: Redis hot tier + pluggable cold tier.
239
+ *
240
+ * Wraps {@link createThreadManager} (Redis-only) and adds two
241
+ * session-boundary operations:
242
+ *
243
+ * - `hydrate()` — when the thread is cold (no meta key in Redis),
244
+ * restore the latest {@link ThreadSnapshot} from the cold store.
245
+ * Idempotent; no-op when the thread is already hot or when no
246
+ * snapshot exists.
247
+ * - `flush({ deleteHot })` — write the current Redis state out to the
248
+ * cold store as one snapshot, then (by default) `DEL` the hot-tier
249
+ * keys so idle threads don't sit in Redis memory.
250
+ *
251
+ * All other operations (`append`, `load`, `fork`, `replaceAll`,
252
+ * `truncateFromId`, state I/O) delegate unchanged to the underlying
253
+ * Redis manager, so adapters and tests that use the
254
+ * `BaseThreadManager<T>` interface keep working with zero changes.
255
+ */
256
+
257
+ /** Configuration for {@link createTieredThreadManager}. */
258
+ interface TieredThreadManagerConfig<T> extends ThreadManagerConfig<T> {
259
+ /**
260
+ * Cold-tier archive. When omitted, `hydrate()` and `flush()` are
261
+ * no-ops and the manager behaves identically to
262
+ * {@link createThreadManager}.
263
+ */
264
+ coldStore?: ColdThreadStore;
265
+ }
266
+ /** Options for {@link TieredThreadManager.flush}. */
267
+ interface FlushOptions {
268
+ /**
269
+ * Delete the hot-tier Redis keys after a successful cold-tier
270
+ * write. Defaults to `true` when a cold store is configured —
271
+ * Redis is just a cache and a future continue/fork will
272
+ * re-hydrate in a single round-trip.
273
+ *
274
+ * Set to `false` to keep the hot tier warm (useful for tests or
275
+ * for "hot-after-flush" use cases where another session is expected
276
+ * to pick the thread up immediately).
277
+ */
278
+ deleteHot?: boolean;
279
+ }
280
+ /**
281
+ * Extension of {@link BaseThreadManager} with the two cold-tier
282
+ * lifecycle methods.
283
+ */
284
+ interface TieredThreadManager<T> extends BaseThreadManager<T> {
285
+ /**
286
+ * Restore the latest cold-tier snapshot into Redis when the thread
287
+ * is cold. Idempotent — safe to call from a retried activity.
288
+ */
289
+ hydrate(): Promise<void>;
290
+ /**
291
+ * Write the current Redis state to the cold tier and (optionally)
292
+ * drop the hot-tier keys. Idempotent — last-writer-wins on the
293
+ * cold side.
294
+ */
295
+ flush(opts?: FlushOptions): Promise<void>;
296
+ }
297
+ /**
298
+ * Build a thread manager backed by Redis (hot) and an optional
299
+ * pluggable cold store. See module docstring for the lifecycle
300
+ * semantics.
301
+ */
302
+ declare function createTieredThreadManager<T>(config: TieredThreadManagerConfig<T>): TieredThreadManager<T>;
303
+
304
+ /**
305
+ * Pure Redis I/O helpers for moving a thread between the hot tier
306
+ * (Redis lists + meta + state + dedup markers) and the cold tier
307
+ * (a single {@link ThreadSnapshot} blob in a {@link ColdThreadStore}).
308
+ *
309
+ * These helpers know nothing about S3 or the adapter-specific message
310
+ * envelope — they operate on the raw Redis representation. The
311
+ * tiered thread manager in `tiered.ts` is the only consumer.
312
+ */
313
+
314
+ /** Inputs shared by every snapshot operation. */
315
+ interface SnapshotCommon {
316
+ redis: Redis;
317
+ threadKey: string;
318
+ threadId: string;
319
+ }
320
+ /** Configuration for {@link encodeSnapshot}. */
321
+ interface EncodeSnapshotConfig extends SnapshotCommon {
322
+ /**
323
+ * Extract a dedup id from each raw-serialized message currently in
324
+ * the thread's Redis list. When omitted, the resulting snapshot has
325
+ * an empty `dedupIds` array — idempotency guarantees are best-effort
326
+ * once a thread crosses the hot/cold boundary.
327
+ */
328
+ idOf?: (raw: string) => string;
329
+ }
330
+ /**
331
+ * Build a {@link ThreadSnapshot} from the current hot-tier state.
332
+ *
333
+ * Returns `null` when no thread exists in the hot tier (the meta key
334
+ * is absent) — callers should treat that as "nothing to flush".
335
+ */
336
+ declare function encodeSnapshot(config: EncodeSnapshotConfig): Promise<ThreadSnapshot | null>;
337
+ /** Configuration for {@link applySnapshot}. */
338
+ interface ApplySnapshotConfig extends SnapshotCommon {
339
+ snapshot: ThreadSnapshot;
340
+ /** TTL applied to every Redis key. Defaults to {@link THREAD_TTL_SECONDS}. */
341
+ ttlSeconds?: number;
342
+ }
343
+ /**
344
+ * Restore a {@link ThreadSnapshot} into the hot tier.
345
+ *
346
+ * Idempotent — if the meta key already exists the thread is already
347
+ * hot and this is a no-op. The meta key is written **last** so a
348
+ * crash mid-restore leaves the thread cold (`load` / `append` will
349
+ * see "thread does not exist") and the next session's hydrate retries
350
+ * cleanly.
351
+ */
352
+ declare function applySnapshot(config: ApplySnapshotConfig): Promise<void>;
353
+ /** Configuration for {@link clearHotTier}. */
354
+ interface ClearHotTierConfig extends SnapshotCommon {
355
+ /** Dedup ids to delete alongside the list / meta / state keys. */
356
+ dedupIds?: string[];
357
+ }
358
+ /**
359
+ * Delete every Redis key the thread manager wrote for `(threadKey,
360
+ * threadId)`. Used by the tiered manager's `flush({ deleteHot: true })`
361
+ * to drop hot-tier memory after a successful archive write.
362
+ */
363
+ declare function clearHotTier(config: ClearHotTierConfig): Promise<void>;
364
+
235
365
  /**
236
366
  * Result returned by {@link SandboxManagerHooks.onPreCreate}.
237
367
  *
@@ -594,4 +724,4 @@ declare const toTree: (fs: SandboxFileSystem, opts?: {
594
724
  sort?: boolean;
595
725
  }) => Promise<string>;
596
726
 
597
- export { ActivityToolHandler, type AgentStateContext, BaseAgentState, BaseThreadManager, BashArgs, ExecResult, FileEditArgs, FileEntryMetadata, FileReadArgs, FileResolver, FileSystemSkillProvider, FileWriteArgs, GlobArgs, JsonValue, NodeFsSandboxFileSystem, type PreCreateHookResult, PrefixedSandboxOps, PrefixedVirtualFsOps, RouterContext, RunAgentConfig, Sandbox, SandboxCapability, type SandboxContext, SandboxCreateOptions, DirentEntry as SandboxDirentEntry, FileStat as SandboxFileStat, SandboxFileSystem, SandboxManager, type SandboxManagerHooks, SandboxProvider, SandboxSnapshot, Skill, SkillMetadata, SkillProvider, ThreadManagerConfig, ToolHandlerResponse, ToolResultConfig, TreeMutation, VirtualFsContext, type WithSandboxOptions, bashHandler, createRunAgentActivity, createThreadManager, createVirtualFsActivities, editHandler, getActivityContext, globHandler, queryParentWorkflowState, readFileHandler, toTree, withAutoAppend, withParentWorkflowState, withSandbox, withVirtualFs, writeFileHandler };
727
+ export { ActivityToolHandler, type AgentStateContext, type ApplySnapshotConfig, BaseAgentState, BaseThreadManager, BashArgs, type ClearHotTierConfig, ColdThreadStore, type EncodeSnapshotConfig, ExecResult, FileEditArgs, FileEntryMetadata, FileReadArgs, FileResolver, FileSystemSkillProvider, FileWriteArgs, type FlushOptions, GlobArgs, JsonValue, NodeFsSandboxFileSystem, type PreCreateHookResult, PrefixedSandboxOps, PrefixedVirtualFsOps, RouterContext, RunAgentConfig, Sandbox, SandboxCapability, type SandboxContext, SandboxCreateOptions, DirentEntry as SandboxDirentEntry, FileStat as SandboxFileStat, SandboxFileSystem, SandboxManager, type SandboxManagerHooks, SandboxProvider, SandboxSnapshot, Skill, SkillMetadata, SkillProvider, ThreadManagerConfig, ThreadSnapshot, type TieredThreadManager, type TieredThreadManagerConfig, ToolHandlerResponse, ToolResultConfig, TreeMutation, VirtualFsContext, type WithSandboxOptions, applySnapshot, bashHandler, clearHotTier, createRunAgentActivity, createThreadManager, createTieredThreadManager, createVirtualFsActivities, editHandler, encodeSnapshot, getActivityContext, globHandler, queryParentWorkflowState, readFileHandler, toTree, withAutoAppend, withParentWorkflowState, withSandbox, withVirtualFs, writeFileHandler };