zeitlich 0.2.47 → 0.2.49

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 (50) hide show
  1. package/README.md +2 -0
  2. package/dist/{activities-CPwKoUlD.d.cts → activities-7OcT_vdR.d.cts} +3 -3
  3. package/dist/{activities-DlaBxNID.d.ts → activities-zG_FBoY2.d.ts} +3 -3
  4. package/dist/adapters/thread/anthropic/index.d.cts +5 -5
  5. package/dist/adapters/thread/anthropic/index.d.ts +5 -5
  6. package/dist/adapters/thread/anthropic/workflow.d.cts +5 -5
  7. package/dist/adapters/thread/anthropic/workflow.d.ts +5 -5
  8. package/dist/adapters/thread/google-genai/index.d.cts +5 -5
  9. package/dist/adapters/thread/google-genai/index.d.ts +5 -5
  10. package/dist/adapters/thread/google-genai/workflow.d.cts +6 -6
  11. package/dist/adapters/thread/google-genai/workflow.d.ts +6 -6
  12. package/dist/adapters/thread/langchain/index.d.cts +5 -5
  13. package/dist/adapters/thread/langchain/index.d.ts +5 -5
  14. package/dist/adapters/thread/langchain/workflow.d.cts +5 -5
  15. package/dist/adapters/thread/langchain/workflow.d.ts +5 -5
  16. package/dist/{cold-store-Z2wvK2cV.d.cts → cold-store-CkWoNtMh.d.cts} +1 -1
  17. package/dist/{cold-store-BDgJpwLI.d.ts → cold-store-DKMAO1Dd.d.ts} +1 -1
  18. package/dist/index.cjs +76 -10
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.cts +8 -8
  21. package/dist/index.d.ts +8 -8
  22. package/dist/index.js +76 -10
  23. package/dist/index.js.map +1 -1
  24. package/dist/{proxy-CDh3Rsa7.d.cts → proxy-B7CWEV-T.d.cts} +1 -1
  25. package/dist/{proxy-Du8ggERu.d.ts → proxy-ByFHMVRX.d.ts} +1 -1
  26. package/dist/{thread-manager-DtHYws2F.d.ts → thread-manager-7AW4rhfu.d.ts} +2 -2
  27. package/dist/{thread-manager-D8zKNFZ9.d.cts → thread-manager-B9rtMEVn.d.cts} +2 -2
  28. package/dist/{thread-manager-BjoYYXgd.d.cts → thread-manager-Cibe0X5m.d.cts} +2 -2
  29. package/dist/{thread-manager-Dw96FKH1.d.ts → thread-manager-nK-WcFzM.d.ts} +2 -2
  30. package/dist/{types-BMJrsHo0.d.cts → types-BR-k7h0e.d.cts} +1 -1
  31. package/dist/{types-CtdOquo3.d.ts → types-DO4Tkwxo.d.ts} +1 -1
  32. package/dist/{types-qQVZfhoT.d.ts → types-DeVNWqlb.d.ts} +54 -0
  33. package/dist/{types-DNEl5uxQ.d.cts → types-XUUFvrJ9.d.cts} +54 -0
  34. package/dist/{workflow-BH9ImDGq.d.cts → workflow-KbGsxpfh.d.cts} +1 -1
  35. package/dist/{workflow-Cdw3-RNB.d.ts → workflow-uhOIj9D-.d.ts} +1 -1
  36. package/dist/workflow.cjs +76 -10
  37. package/dist/workflow.cjs.map +1 -1
  38. package/dist/workflow.d.cts +2 -2
  39. package/dist/workflow.d.ts +2 -2
  40. package/dist/workflow.js +76 -10
  41. package/dist/workflow.js.map +1 -1
  42. package/package.json +6 -6
  43. package/src/lib/lifecycle.ts +13 -1
  44. package/src/lib/session/session-edge-cases.integration.test.ts +44 -0
  45. package/src/lib/session/session.ts +26 -0
  46. package/src/lib/subagent/handler.ts +55 -6
  47. package/src/lib/subagent/subagent.integration.test.ts +239 -2
  48. package/src/lib/tool-router/router-edge-cases.integration.test.ts +36 -0
  49. package/src/lib/tool-router/router.ts +29 -3
  50. package/src/lib/tool-router/types.ts +43 -0
package/README.md CHANGED
@@ -890,6 +890,8 @@ export const researcherSubagent = defineSubagent(researcherWorkflow, {
890
890
 
891
891
  An explicit `threadId` from the parent's tool call always wins; `newThreadSource` only applies when none is provided. The field has no effect with `thread: "new"`.
892
892
 
893
+ When `newThreadSource: "from-parent"` triggers a fork, the parent is mid-tool-call: its assistant message containing the `Subagent` tool_use has been persisted, but the matching `tool_result` hasn't (the subagent is what will produce it). A verbatim fork would leave that orphan `tool_use` at the tail of the child thread — which most model APIs reject on the next call with "unmatched tool_use". The framework handles this automatically: the child session truncates the parent's last assistant message from the forked thread before the first model invocation, so the child sees a well-formed history. No user action is required.
894
+
893
895
  The `sandbox` field accepts `"none"` (default) or an object with `source`, `continuation`, and optional `init`/`shutdown` fields:
894
896
 
895
897
  - `source: "inherit"` — use the parent's sandbox. `continuation: "continue"` shares it directly; `"fork"` forks from it on every call.
@@ -1,8 +1,8 @@
1
1
  import Redis from 'ioredis';
2
2
  import { Part, Content, GoogleGenAI } from '@google/genai';
3
- import { a as ModelInvoker, b as PrefixedThreadOps, S as ScopedPrefix, R as RouterContext, c as ToolHandlerResponse, d as ActivityToolHandler } from './types-DNEl5uxQ.cjs';
4
- import { C as ColdThreadStore } from './cold-store-Z2wvK2cV.cjs';
5
- import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-BMJrsHo0.cjs';
3
+ import { a as ModelInvoker, b as PrefixedThreadOps, S as ScopedPrefix, R as RouterContext, c as ToolHandlerResponse, d as ActivityToolHandler } from './types-XUUFvrJ9.cjs';
4
+ import { C as ColdThreadStore } from './cold-store-CkWoNtMh.cjs';
5
+ import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-BR-k7h0e.cjs';
6
6
  import { A as ADAPTER_ID } from './adapter-id-BB-mmrts.cjs';
7
7
 
8
8
  /** SDK-native content type for Google GenAI human messages */
@@ -1,8 +1,8 @@
1
1
  import Redis from 'ioredis';
2
2
  import { Part, Content, GoogleGenAI } from '@google/genai';
3
- import { a as ModelInvoker, b as PrefixedThreadOps, S as ScopedPrefix, R as RouterContext, c as ToolHandlerResponse, d as ActivityToolHandler } from './types-qQVZfhoT.js';
4
- import { C as ColdThreadStore } from './cold-store-BDgJpwLI.js';
5
- import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-CtdOquo3.js';
3
+ import { a as ModelInvoker, b as PrefixedThreadOps, S as ScopedPrefix, R as RouterContext, c as ToolHandlerResponse, d as ActivityToolHandler } from './types-DeVNWqlb.js';
4
+ import { C as ColdThreadStore } from './cold-store-DKMAO1Dd.js';
5
+ import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-DO4Tkwxo.js';
6
6
  import { A as ADAPTER_ID } from './adapter-id-BB-mmrts.js';
7
7
 
8
8
  /** SDK-native content type for Google GenAI human messages */
@@ -2,17 +2,17 @@ import { A as ADAPTER_ID } from '../../../adapter-id-CMwVrVqv.cjs';
2
2
  export { a as AdapterId } from '../../../adapter-id-CMwVrVqv.cjs';
3
3
  import Redis from 'ioredis';
4
4
  import Anthropic from '@anthropic-ai/sdk';
5
- import { a as ModelInvoker, b as PrefixedThreadOps, S as ScopedPrefix, R as RouterContext, c as ToolHandlerResponse, d as ActivityToolHandler, M as ModelInvokerConfig, A as AgentResponse } from '../../../types-DNEl5uxQ.cjs';
6
- import { C as ColdThreadStore } from '../../../cold-store-Z2wvK2cV.cjs';
7
- import { A as AnthropicContent, a as AnthropicThreadManagerHooks } from '../../../thread-manager-D8zKNFZ9.cjs';
8
- export { b as AnthropicInvocationPayload, c as AnthropicThreadManager, d as AnthropicThreadManagerConfig, S as StoredMessage, e as createAnthropicThreadManager } from '../../../thread-manager-D8zKNFZ9.cjs';
5
+ import { a as ModelInvoker, b as PrefixedThreadOps, S as ScopedPrefix, R as RouterContext, c as ToolHandlerResponse, d as ActivityToolHandler, M as ModelInvokerConfig, A as AgentResponse } from '../../../types-XUUFvrJ9.cjs';
6
+ import { C as ColdThreadStore } from '../../../cold-store-CkWoNtMh.cjs';
7
+ import { A as AnthropicContent, a as AnthropicThreadManagerHooks } from '../../../thread-manager-B9rtMEVn.cjs';
8
+ export { b as AnthropicInvocationPayload, c as AnthropicThreadManager, d as AnthropicThreadManagerConfig, S as StoredMessage, e as createAnthropicThreadManager } from '../../../thread-manager-B9rtMEVn.cjs';
9
9
  import '@temporalio/workflow';
10
10
  import '@temporalio/common/lib/interfaces';
11
11
  import 'zod';
12
12
  import '../../../types-CJ7tCdl6.cjs';
13
13
  import '@temporalio/common';
14
14
  import '@aws-sdk/client-s3';
15
- import '../../../types-BMJrsHo0.cjs';
15
+ import '../../../types-BR-k7h0e.cjs';
16
16
 
17
17
  interface AnthropicPromptCacheOptions {
18
18
  /** TTL for the cache checkpoint. Defaults to 5m. */
@@ -2,17 +2,17 @@ import { A as ADAPTER_ID } from '../../../adapter-id-CMwVrVqv.js';
2
2
  export { a as AdapterId } from '../../../adapter-id-CMwVrVqv.js';
3
3
  import Redis from 'ioredis';
4
4
  import Anthropic from '@anthropic-ai/sdk';
5
- import { a as ModelInvoker, b as PrefixedThreadOps, S as ScopedPrefix, R as RouterContext, c as ToolHandlerResponse, d as ActivityToolHandler, M as ModelInvokerConfig, A as AgentResponse } from '../../../types-qQVZfhoT.js';
6
- import { C as ColdThreadStore } from '../../../cold-store-BDgJpwLI.js';
7
- import { A as AnthropicContent, a as AnthropicThreadManagerHooks } from '../../../thread-manager-DtHYws2F.js';
8
- export { b as AnthropicInvocationPayload, c as AnthropicThreadManager, d as AnthropicThreadManagerConfig, S as StoredMessage, e as createAnthropicThreadManager } from '../../../thread-manager-DtHYws2F.js';
5
+ import { a as ModelInvoker, b as PrefixedThreadOps, S as ScopedPrefix, R as RouterContext, c as ToolHandlerResponse, d as ActivityToolHandler, M as ModelInvokerConfig, A as AgentResponse } from '../../../types-DeVNWqlb.js';
6
+ import { C as ColdThreadStore } from '../../../cold-store-DKMAO1Dd.js';
7
+ import { A as AnthropicContent, a as AnthropicThreadManagerHooks } from '../../../thread-manager-7AW4rhfu.js';
8
+ export { b as AnthropicInvocationPayload, c as AnthropicThreadManager, d as AnthropicThreadManagerConfig, S as StoredMessage, e as createAnthropicThreadManager } from '../../../thread-manager-7AW4rhfu.js';
9
9
  import '@temporalio/workflow';
10
10
  import '@temporalio/common/lib/interfaces';
11
11
  import 'zod';
12
12
  import '../../../types-CJ7tCdl6.js';
13
13
  import '@temporalio/common';
14
14
  import '@aws-sdk/client-s3';
15
- import '../../../types-CtdOquo3.js';
15
+ import '../../../types-DO4Tkwxo.js';
16
16
 
17
17
  interface AnthropicPromptCacheOptions {
18
18
  /** TTL for the cache checkpoint. Defaults to 5m. */
@@ -1,8 +1,8 @@
1
1
  import { ActivityInterfaceFor } from '@temporalio/workflow';
2
- import { T as ThreadOps } from '../../../types-DNEl5uxQ.cjs';
3
- import { A as AnthropicContent } from '../../../thread-manager-D8zKNFZ9.cjs';
4
- import { c as createThreadOpsProxy } from '../../../proxy-CDh3Rsa7.cjs';
5
- export { T as ThreadOpsProxyOptions } from '../../../proxy-CDh3Rsa7.cjs';
2
+ import { T as ThreadOps } from '../../../types-XUUFvrJ9.cjs';
3
+ import { A as AnthropicContent } from '../../../thread-manager-B9rtMEVn.cjs';
4
+ import { c as createThreadOpsProxy } from '../../../proxy-B7CWEV-T.cjs';
5
+ export { T as ThreadOpsProxyOptions } from '../../../proxy-B7CWEV-T.cjs';
6
6
  export { A as ADAPTER_ID, a as AdapterId } from '../../../adapter-id-CMwVrVqv.cjs';
7
7
  import '@temporalio/common/lib/interfaces';
8
8
  import 'zod';
@@ -10,7 +10,7 @@ import '../../../types-CJ7tCdl6.cjs';
10
10
  import '@temporalio/common';
11
11
  import 'ioredis';
12
12
  import '@anthropic-ai/sdk';
13
- import '../../../types-BMJrsHo0.cjs';
13
+ import '../../../types-BR-k7h0e.cjs';
14
14
 
15
15
  /**
16
16
  * Workflow-safe proxy for Anthropic thread operations.
@@ -1,8 +1,8 @@
1
1
  import { ActivityInterfaceFor } from '@temporalio/workflow';
2
- import { T as ThreadOps } from '../../../types-qQVZfhoT.js';
3
- import { A as AnthropicContent } from '../../../thread-manager-DtHYws2F.js';
4
- import { c as createThreadOpsProxy } from '../../../proxy-Du8ggERu.js';
5
- export { T as ThreadOpsProxyOptions } from '../../../proxy-Du8ggERu.js';
2
+ import { T as ThreadOps } from '../../../types-DeVNWqlb.js';
3
+ import { A as AnthropicContent } from '../../../thread-manager-7AW4rhfu.js';
4
+ import { c as createThreadOpsProxy } from '../../../proxy-ByFHMVRX.js';
5
+ export { T as ThreadOpsProxyOptions } from '../../../proxy-ByFHMVRX.js';
6
6
  export { A as ADAPTER_ID, a as AdapterId } from '../../../adapter-id-CMwVrVqv.js';
7
7
  import '@temporalio/common/lib/interfaces';
8
8
  import 'zod';
@@ -10,7 +10,7 @@ import '../../../types-CJ7tCdl6.js';
10
10
  import '@temporalio/common';
11
11
  import 'ioredis';
12
12
  import '@anthropic-ai/sdk';
13
- import '../../../types-CtdOquo3.js';
13
+ import '../../../types-DO4Tkwxo.js';
14
14
 
15
15
  /**
16
16
  * Workflow-safe proxy for Anthropic thread operations.
@@ -1,12 +1,12 @@
1
1
  export { A as ADAPTER_ID, a as AdapterId } from '../../../adapter-id-BB-mmrts.cjs';
2
- import { G as GoogleGenAIThreadManagerHooks } from '../../../activities-CPwKoUlD.cjs';
3
- export { a as GoogleGenAIAdapter, b as GoogleGenAIAdapterConfig, c as GoogleGenAIContent, d as GoogleGenAIInvocationPayload, e as GoogleGenAIThreadManager, f as GoogleGenAIThreadManagerConfig, g as GoogleGenAIThreadOps, h as GoogleGenAIToolResponse, S as StoredContent, i as createGoogleGenAIAdapter, j as createGoogleGenAIThreadManager } from '../../../activities-CPwKoUlD.cjs';
2
+ import { G as GoogleGenAIThreadManagerHooks } from '../../../activities-7OcT_vdR.cjs';
3
+ export { a as GoogleGenAIAdapter, b as GoogleGenAIAdapterConfig, c as GoogleGenAIContent, d as GoogleGenAIInvocationPayload, e as GoogleGenAIThreadManager, f as GoogleGenAIThreadManagerConfig, g as GoogleGenAIThreadOps, h as GoogleGenAIToolResponse, S as StoredContent, i as createGoogleGenAIAdapter, j as createGoogleGenAIThreadManager } from '../../../activities-7OcT_vdR.cjs';
4
4
  import Redis from 'ioredis';
5
5
  import { GoogleGenAI, Content } from '@google/genai';
6
- import { M as ModelInvokerConfig, A as AgentResponse } from '../../../types-DNEl5uxQ.cjs';
7
- import '../../../cold-store-Z2wvK2cV.cjs';
6
+ import { M as ModelInvokerConfig, A as AgentResponse } from '../../../types-XUUFvrJ9.cjs';
7
+ import '../../../cold-store-CkWoNtMh.cjs';
8
8
  import '@aws-sdk/client-s3';
9
- import '../../../types-BMJrsHo0.cjs';
9
+ import '../../../types-BR-k7h0e.cjs';
10
10
  import '@temporalio/workflow';
11
11
  import '@temporalio/common/lib/interfaces';
12
12
  import 'zod';
@@ -1,12 +1,12 @@
1
1
  export { A as ADAPTER_ID, a as AdapterId } from '../../../adapter-id-BB-mmrts.js';
2
- import { G as GoogleGenAIThreadManagerHooks } from '../../../activities-DlaBxNID.js';
3
- export { a as GoogleGenAIAdapter, b as GoogleGenAIAdapterConfig, c as GoogleGenAIContent, d as GoogleGenAIInvocationPayload, e as GoogleGenAIThreadManager, f as GoogleGenAIThreadManagerConfig, g as GoogleGenAIThreadOps, h as GoogleGenAIToolResponse, S as StoredContent, i as createGoogleGenAIAdapter, j as createGoogleGenAIThreadManager } from '../../../activities-DlaBxNID.js';
2
+ import { G as GoogleGenAIThreadManagerHooks } from '../../../activities-zG_FBoY2.js';
3
+ export { a as GoogleGenAIAdapter, b as GoogleGenAIAdapterConfig, c as GoogleGenAIContent, d as GoogleGenAIInvocationPayload, e as GoogleGenAIThreadManager, f as GoogleGenAIThreadManagerConfig, g as GoogleGenAIThreadOps, h as GoogleGenAIToolResponse, S as StoredContent, i as createGoogleGenAIAdapter, j as createGoogleGenAIThreadManager } from '../../../activities-zG_FBoY2.js';
4
4
  import Redis from 'ioredis';
5
5
  import { GoogleGenAI, Content } from '@google/genai';
6
- import { M as ModelInvokerConfig, A as AgentResponse } from '../../../types-qQVZfhoT.js';
7
- import '../../../cold-store-BDgJpwLI.js';
6
+ import { M as ModelInvokerConfig, A as AgentResponse } from '../../../types-DeVNWqlb.js';
7
+ import '../../../cold-store-DKMAO1Dd.js';
8
8
  import '@aws-sdk/client-s3';
9
- import '../../../types-CtdOquo3.js';
9
+ import '../../../types-DO4Tkwxo.js';
10
10
  import '@temporalio/workflow';
11
11
  import '@temporalio/common/lib/interfaces';
12
12
  import 'zod';
@@ -1,8 +1,8 @@
1
1
  import { ActivityInterfaceFor } from '@temporalio/workflow';
2
- import { T as ThreadOps } from '../../../types-DNEl5uxQ.cjs';
3
- import { c as GoogleGenAIContent } from '../../../activities-CPwKoUlD.cjs';
4
- import { c as createThreadOpsProxy } from '../../../proxy-CDh3Rsa7.cjs';
5
- export { T as ThreadOpsProxyOptions } from '../../../proxy-CDh3Rsa7.cjs';
2
+ import { T as ThreadOps } from '../../../types-XUUFvrJ9.cjs';
3
+ import { c as GoogleGenAIContent } from '../../../activities-7OcT_vdR.cjs';
4
+ import { c as createThreadOpsProxy } from '../../../proxy-B7CWEV-T.cjs';
5
+ export { T as ThreadOpsProxyOptions } from '../../../proxy-B7CWEV-T.cjs';
6
6
  export { A as ADAPTER_ID, a as AdapterId } from '../../../adapter-id-BB-mmrts.cjs';
7
7
  import '@temporalio/common/lib/interfaces';
8
8
  import 'zod';
@@ -10,9 +10,9 @@ import '../../../types-CJ7tCdl6.cjs';
10
10
  import '@temporalio/common';
11
11
  import 'ioredis';
12
12
  import '@google/genai';
13
- import '../../../cold-store-Z2wvK2cV.cjs';
13
+ import '../../../cold-store-CkWoNtMh.cjs';
14
14
  import '@aws-sdk/client-s3';
15
- import '../../../types-BMJrsHo0.cjs';
15
+ import '../../../types-BR-k7h0e.cjs';
16
16
 
17
17
  /**
18
18
  * Workflow-safe proxy for Google GenAI thread operations.
@@ -1,8 +1,8 @@
1
1
  import { ActivityInterfaceFor } from '@temporalio/workflow';
2
- import { T as ThreadOps } from '../../../types-qQVZfhoT.js';
3
- import { c as GoogleGenAIContent } from '../../../activities-DlaBxNID.js';
4
- import { c as createThreadOpsProxy } from '../../../proxy-Du8ggERu.js';
5
- export { T as ThreadOpsProxyOptions } from '../../../proxy-Du8ggERu.js';
2
+ import { T as ThreadOps } from '../../../types-DeVNWqlb.js';
3
+ import { c as GoogleGenAIContent } from '../../../activities-zG_FBoY2.js';
4
+ import { c as createThreadOpsProxy } from '../../../proxy-ByFHMVRX.js';
5
+ export { T as ThreadOpsProxyOptions } from '../../../proxy-ByFHMVRX.js';
6
6
  export { A as ADAPTER_ID, a as AdapterId } from '../../../adapter-id-BB-mmrts.js';
7
7
  import '@temporalio/common/lib/interfaces';
8
8
  import 'zod';
@@ -10,9 +10,9 @@ import '../../../types-CJ7tCdl6.js';
10
10
  import '@temporalio/common';
11
11
  import 'ioredis';
12
12
  import '@google/genai';
13
- import '../../../cold-store-BDgJpwLI.js';
13
+ import '../../../cold-store-DKMAO1Dd.js';
14
14
  import '@aws-sdk/client-s3';
15
- import '../../../types-CtdOquo3.js';
15
+ import '../../../types-DO4Tkwxo.js';
16
16
 
17
17
  /**
18
18
  * Workflow-safe proxy for Google GenAI thread operations.
@@ -2,18 +2,18 @@ import { A as ADAPTER_ID } from '../../../adapter-id-CbY2zeSt.cjs';
2
2
  export { a as AdapterId } from '../../../adapter-id-CbY2zeSt.cjs';
3
3
  import Redis from 'ioredis';
4
4
  import { StoredMessage, MessageContent, BaseMessage } from '@langchain/core/messages';
5
- import { a as ModelInvoker, b as PrefixedThreadOps, S as ScopedPrefix, R as RouterContext, c as ToolHandlerResponse, d as ActivityToolHandler, M as ModelInvokerConfig, A as AgentResponse } from '../../../types-DNEl5uxQ.cjs';
6
- import { C as ColdThreadStore } from '../../../cold-store-Z2wvK2cV.cjs';
5
+ import { a as ModelInvoker, b as PrefixedThreadOps, S as ScopedPrefix, R as RouterContext, c as ToolHandlerResponse, d as ActivityToolHandler, M as ModelInvokerConfig, A as AgentResponse } from '../../../types-XUUFvrJ9.cjs';
6
+ import { C as ColdThreadStore } from '../../../cold-store-CkWoNtMh.cjs';
7
7
  import { BaseChatModel } from '@langchain/core/language_models/chat_models';
8
- import { L as LangChainContent, a as LangChainThreadManagerHooks } from '../../../thread-manager-BjoYYXgd.cjs';
9
- export { b as LangChainInvocationPayload, c as LangChainThreadManager, d as LangChainThreadManagerConfig, e as createLangChainThreadManager } from '../../../thread-manager-BjoYYXgd.cjs';
8
+ import { L as LangChainContent, a as LangChainThreadManagerHooks } from '../../../thread-manager-Cibe0X5m.cjs';
9
+ export { b as LangChainInvocationPayload, c as LangChainThreadManager, d as LangChainThreadManagerConfig, e as createLangChainThreadManager } from '../../../thread-manager-Cibe0X5m.cjs';
10
10
  import '@temporalio/workflow';
11
11
  import '@temporalio/common/lib/interfaces';
12
12
  import 'zod';
13
13
  import '../../../types-CJ7tCdl6.cjs';
14
14
  import '@temporalio/common';
15
15
  import '@aws-sdk/client-s3';
16
- import '../../../types-BMJrsHo0.cjs';
16
+ import '../../../types-BR-k7h0e.cjs';
17
17
 
18
18
  type LangChainThreadOps<TScope extends string = ""> = PrefixedThreadOps<ScopedPrefix<TScope, typeof ADAPTER_ID>, LangChainContent>;
19
19
  interface LangChainAdapterConfig {
@@ -2,18 +2,18 @@ import { A as ADAPTER_ID } from '../../../adapter-id-CbY2zeSt.js';
2
2
  export { a as AdapterId } from '../../../adapter-id-CbY2zeSt.js';
3
3
  import Redis from 'ioredis';
4
4
  import { StoredMessage, MessageContent, BaseMessage } from '@langchain/core/messages';
5
- import { a as ModelInvoker, b as PrefixedThreadOps, S as ScopedPrefix, R as RouterContext, c as ToolHandlerResponse, d as ActivityToolHandler, M as ModelInvokerConfig, A as AgentResponse } from '../../../types-qQVZfhoT.js';
6
- import { C as ColdThreadStore } from '../../../cold-store-BDgJpwLI.js';
5
+ import { a as ModelInvoker, b as PrefixedThreadOps, S as ScopedPrefix, R as RouterContext, c as ToolHandlerResponse, d as ActivityToolHandler, M as ModelInvokerConfig, A as AgentResponse } from '../../../types-DeVNWqlb.js';
6
+ import { C as ColdThreadStore } from '../../../cold-store-DKMAO1Dd.js';
7
7
  import { BaseChatModel } from '@langchain/core/language_models/chat_models';
8
- import { L as LangChainContent, a as LangChainThreadManagerHooks } from '../../../thread-manager-Dw96FKH1.js';
9
- export { b as LangChainInvocationPayload, c as LangChainThreadManager, d as LangChainThreadManagerConfig, e as createLangChainThreadManager } from '../../../thread-manager-Dw96FKH1.js';
8
+ import { L as LangChainContent, a as LangChainThreadManagerHooks } from '../../../thread-manager-nK-WcFzM.js';
9
+ export { b as LangChainInvocationPayload, c as LangChainThreadManager, d as LangChainThreadManagerConfig, e as createLangChainThreadManager } from '../../../thread-manager-nK-WcFzM.js';
10
10
  import '@temporalio/workflow';
11
11
  import '@temporalio/common/lib/interfaces';
12
12
  import 'zod';
13
13
  import '../../../types-CJ7tCdl6.js';
14
14
  import '@temporalio/common';
15
15
  import '@aws-sdk/client-s3';
16
- import '../../../types-CtdOquo3.js';
16
+ import '../../../types-DO4Tkwxo.js';
17
17
 
18
18
  type LangChainThreadOps<TScope extends string = ""> = PrefixedThreadOps<ScopedPrefix<TScope, typeof ADAPTER_ID>, LangChainContent>;
19
19
  interface LangChainAdapterConfig {
@@ -1,8 +1,8 @@
1
1
  import { ActivityInterfaceFor } from '@temporalio/workflow';
2
- import { T as ThreadOps } from '../../../types-DNEl5uxQ.cjs';
3
- import { L as LangChainContent } from '../../../thread-manager-BjoYYXgd.cjs';
4
- import { c as createThreadOpsProxy } from '../../../proxy-CDh3Rsa7.cjs';
5
- export { T as ThreadOpsProxyOptions } from '../../../proxy-CDh3Rsa7.cjs';
2
+ import { T as ThreadOps } from '../../../types-XUUFvrJ9.cjs';
3
+ import { L as LangChainContent } from '../../../thread-manager-Cibe0X5m.cjs';
4
+ import { c as createThreadOpsProxy } from '../../../proxy-B7CWEV-T.cjs';
5
+ export { T as ThreadOpsProxyOptions } from '../../../proxy-B7CWEV-T.cjs';
6
6
  export { A as ADAPTER_ID, a as AdapterId } from '../../../adapter-id-CbY2zeSt.cjs';
7
7
  import '@temporalio/common/lib/interfaces';
8
8
  import 'zod';
@@ -10,7 +10,7 @@ import '../../../types-CJ7tCdl6.cjs';
10
10
  import '@temporalio/common';
11
11
  import 'ioredis';
12
12
  import '@langchain/core/messages';
13
- import '../../../types-BMJrsHo0.cjs';
13
+ import '../../../types-BR-k7h0e.cjs';
14
14
 
15
15
  /**
16
16
  * Workflow-safe proxy for LangChain thread operations.
@@ -1,8 +1,8 @@
1
1
  import { ActivityInterfaceFor } from '@temporalio/workflow';
2
- import { T as ThreadOps } from '../../../types-qQVZfhoT.js';
3
- import { L as LangChainContent } from '../../../thread-manager-Dw96FKH1.js';
4
- import { c as createThreadOpsProxy } from '../../../proxy-Du8ggERu.js';
5
- export { T as ThreadOpsProxyOptions } from '../../../proxy-Du8ggERu.js';
2
+ import { T as ThreadOps } from '../../../types-DeVNWqlb.js';
3
+ import { L as LangChainContent } from '../../../thread-manager-nK-WcFzM.js';
4
+ import { c as createThreadOpsProxy } from '../../../proxy-ByFHMVRX.js';
5
+ export { T as ThreadOpsProxyOptions } from '../../../proxy-ByFHMVRX.js';
6
6
  export { A as ADAPTER_ID, a as AdapterId } from '../../../adapter-id-CbY2zeSt.js';
7
7
  import '@temporalio/common/lib/interfaces';
8
8
  import 'zod';
@@ -10,7 +10,7 @@ import '../../../types-CJ7tCdl6.js';
10
10
  import '@temporalio/common';
11
11
  import 'ioredis';
12
12
  import '@langchain/core/messages';
13
- import '../../../types-CtdOquo3.js';
13
+ import '../../../types-DO4Tkwxo.js';
14
14
 
15
15
  /**
16
16
  * Workflow-safe proxy for LangChain thread operations.
@@ -1,4 +1,4 @@
1
- import { P as PersistedThreadState } from './types-DNEl5uxQ.cjs';
1
+ import { P as PersistedThreadState } from './types-XUUFvrJ9.cjs';
2
2
  import { S3Client } from '@aws-sdk/client-s3';
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { P as PersistedThreadState } from './types-qQVZfhoT.js';
1
+ import { P as PersistedThreadState } from './types-DeVNWqlb.js';
2
2
  import { S3Client } from '@aws-sdk/client-s3';
3
3
 
4
4
  /**
package/dist/index.cjs CHANGED
@@ -131,7 +131,7 @@ function createToolRouter(options) {
131
131
  });
132
132
  }
133
133
  }
134
- async function processToolCall(toolCall, turn, sandboxId, onRewindRequested) {
134
+ async function processToolCall(toolCall, turn, sandboxId, onRewindRequested, assistantMessageId, persistThreadState) {
135
135
  const startTime = Date.now();
136
136
  const tool = toolMap.get(toolCall.name);
137
137
  const preResult = await runPreHooks(toolCall, tool, turn);
@@ -166,7 +166,9 @@ function createToolRouter(options) {
166
166
  ...options.threadKey && { threadKey: options.threadKey },
167
167
  toolCallId: toolCall.id,
168
168
  toolName: toolCall.name,
169
- ...sandboxId !== void 0 && { sandboxId }
169
+ ...sandboxId !== void 0 && { sandboxId },
170
+ ...assistantMessageId !== void 0 && { assistantMessageId },
171
+ ...persistThreadState !== void 0 && { persistThreadState }
170
172
  };
171
173
  const response = await tool.handler(
172
174
  effectiveArgs,
@@ -293,6 +295,8 @@ function createToolRouter(options) {
293
295
  }
294
296
  const turn = context?.turn ?? 0;
295
297
  const sandboxId = context?.sandboxId;
298
+ const assistantMessageId = context?.assistantMessageId;
299
+ const persistThreadState = context?.persistThreadState;
296
300
  let rewindSignal;
297
301
  if (options.parallel) {
298
302
  const scope = new workflow.CancellationScope({ cancellable: true });
@@ -305,7 +309,14 @@ function createToolRouter(options) {
305
309
  const outcomes = await scope.run(
306
310
  async () => Promise.allSettled(
307
311
  toolCalls.map(
308
- (tc) => processToolCall(tc, turn, sandboxId, onRewindRequested)
312
+ (tc) => processToolCall(
313
+ tc,
314
+ turn,
315
+ sandboxId,
316
+ onRewindRequested,
317
+ assistantMessageId,
318
+ persistThreadState
319
+ )
309
320
  )
310
321
  )
311
322
  );
@@ -325,7 +336,14 @@ function createToolRouter(options) {
325
336
  }
326
337
  const results = [];
327
338
  for (const toolCall of toolCalls) {
328
- const outcome = await processToolCall(toolCall, turn, sandboxId);
339
+ const outcome = await processToolCall(
340
+ toolCall,
341
+ turn,
342
+ sandboxId,
343
+ void 0,
344
+ assistantMessageId,
345
+ persistThreadState
346
+ );
329
347
  if (outcome.kind === "rewind") {
330
348
  rewindSignal = outcome.signal;
331
349
  break;
@@ -349,6 +367,12 @@ function createToolRouter(options) {
349
367
  toolName: toolCall.name,
350
368
  ...context?.sandboxId !== void 0 && {
351
369
  sandboxId: context.sandboxId
370
+ },
371
+ ...context?.assistantMessageId !== void 0 && {
372
+ assistantMessageId: context.assistantMessageId
373
+ },
374
+ ...context?.persistThreadState !== void 0 && {
375
+ persistThreadState: context.persistThreadState
352
376
  }
353
377
  };
354
378
  const response = await handler(
@@ -575,13 +599,26 @@ function createSubagentHandler(subagents) {
575
599
  const threadMode = config.thread ?? "new";
576
600
  const allowsContinuation = threadMode !== "new";
577
601
  const newThreadSource = config.newThreadSource ?? "new";
578
- const continuationThreadId = !allowsContinuation ? void 0 : args.threadId ?? (newThreadSource === "from-parent" ? context.threadId : void 0);
602
+ const usingParentFallback = allowsContinuation && !args.threadId && newThreadSource === "from-parent";
603
+ const continuationThreadId = !allowsContinuation ? void 0 : args.threadId ?? (usingParentFallback ? context.threadId : void 0);
579
604
  let thread;
580
605
  if (continuationThreadId) {
581
- thread = {
582
- mode: threadMode,
583
- threadId: continuationThreadId
584
- };
606
+ if (threadMode === "fork") {
607
+ thread = {
608
+ mode: "fork",
609
+ threadId: continuationThreadId,
610
+ ...usingParentFallback && context.assistantMessageId ? {
611
+ truncateAfterFork: {
612
+ fromMessageId: context.assistantMessageId
613
+ }
614
+ } : {}
615
+ };
616
+ } else {
617
+ thread = {
618
+ mode: "continue",
619
+ threadId: continuationThreadId
620
+ };
621
+ }
585
622
  }
586
623
  let sandbox;
587
624
  let sandboxShutdownOverride;
@@ -693,6 +730,17 @@ function createSubagentHandler(subagents) {
693
730
  if (isSnapshotBaseCreator) {
694
731
  snapshotBaseCreatorAgent.set(childWorkflowId, config.agentName);
695
732
  }
733
+ if (continuationThreadId && continuationThreadId === context.threadId && context.persistThreadState) {
734
+ try {
735
+ await context.persistThreadState();
736
+ } catch (err) {
737
+ workflow.log.warn("failed to persist parent thread state for subagent", {
738
+ subagent: config.agentName,
739
+ childWorkflowId,
740
+ error: err instanceof Error ? err.message : String(err)
741
+ });
742
+ }
743
+ }
696
744
  workflow.log.info("subagent spawned", {
697
745
  subagent: config.agentName,
698
746
  childWorkflowId,
@@ -1042,6 +1090,7 @@ async function createSession(config) {
1042
1090
  appendSystemMessage,
1043
1091
  appendAgentMessage,
1044
1092
  forkThread,
1093
+ truncateThread,
1045
1094
  loadThreadState,
1046
1095
  saveThreadState,
1047
1096
  hydrateThread,
@@ -1191,6 +1240,10 @@ async function createSession(config) {
1191
1240
  if (threadMode === "fork" && sourceThreadId) {
1192
1241
  await hydrateThread(sourceThreadId, threadKey);
1193
1242
  await forkThread(sourceThreadId, threadId, threadKey);
1243
+ const truncate = threadInit.truncateAfterFork;
1244
+ if (truncate?.fromMessageId) {
1245
+ await truncateThread(threadId, truncate.fromMessageId, threadKey);
1246
+ }
1194
1247
  const forkedSlice = await loadThreadState(threadId, threadKey);
1195
1248
  if (forkedSlice) rehydrateFromSlice(forkedSlice);
1196
1249
  } else if (threadMode === "continue") {
@@ -1320,7 +1373,20 @@ async function createSession(config) {
1320
1373
  parsedToolCalls,
1321
1374
  {
1322
1375
  turn: currentTurn,
1323
- ...sandboxId !== void 0 && { sandboxId }
1376
+ ...sandboxId !== void 0 && { sandboxId },
1377
+ ...assistantId !== void 0 && {
1378
+ assistantMessageId: assistantId
1379
+ },
1380
+ // Hand handlers a way to persist the parent's slice
1381
+ // mid-loop (subagents that fork or continue the parent's
1382
+ // thread need this — otherwise the child loads a stale
1383
+ // snapshot from the prior session, since `saveThreadState`
1384
+ // would otherwise only run in the `finally` below).
1385
+ persistThreadState: () => saveThreadState(
1386
+ threadId,
1387
+ stateManager.getPersistedSlice(),
1388
+ threadKey
1389
+ )
1324
1390
  }
1325
1391
  );
1326
1392
  for (const result of toolCallResults) {