zeitlich 0.2.48 → 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.
- package/dist/{activities-BlQR5gX4.d.cts → activities-7OcT_vdR.d.cts} +3 -3
- package/dist/{activities-DCaIPQBT.d.ts → activities-zG_FBoY2.d.ts} +3 -3
- package/dist/adapters/thread/anthropic/index.d.cts +5 -5
- package/dist/adapters/thread/anthropic/index.d.ts +5 -5
- package/dist/adapters/thread/anthropic/workflow.d.cts +5 -5
- package/dist/adapters/thread/anthropic/workflow.d.ts +5 -5
- package/dist/adapters/thread/google-genai/index.d.cts +5 -5
- package/dist/adapters/thread/google-genai/index.d.ts +5 -5
- package/dist/adapters/thread/google-genai/workflow.d.cts +6 -6
- package/dist/adapters/thread/google-genai/workflow.d.ts +6 -6
- package/dist/adapters/thread/langchain/index.d.cts +5 -5
- package/dist/adapters/thread/langchain/index.d.ts +5 -5
- package/dist/adapters/thread/langchain/workflow.d.cts +5 -5
- package/dist/adapters/thread/langchain/workflow.d.ts +5 -5
- package/dist/{cold-store-UL13Sstw.d.cts → cold-store-CkWoNtMh.d.cts} +1 -1
- package/dist/{cold-store-aD4TSKlU.d.ts → cold-store-DKMAO1Dd.d.ts} +1 -1
- package/dist/index.cjs +33 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -8
- package/dist/index.d.ts +8 -8
- package/dist/index.js +33 -5
- package/dist/index.js.map +1 -1
- package/dist/{proxy-BAty3CWM.d.cts → proxy-B7CWEV-T.d.cts} +1 -1
- package/dist/{proxy-mbnwBhHw.d.ts → proxy-ByFHMVRX.d.ts} +1 -1
- package/dist/{thread-manager-DtEtbUkp.d.ts → thread-manager-7AW4rhfu.d.ts} +2 -2
- package/dist/{thread-manager-R6c3lnJy.d.cts → thread-manager-B9rtMEVn.d.cts} +2 -2
- package/dist/{thread-manager-DsXvJ5cJ.d.cts → thread-manager-Cibe0X5m.d.cts} +2 -2
- package/dist/{thread-manager-CICj68PI.d.ts → thread-manager-nK-WcFzM.d.ts} +2 -2
- package/dist/{types-DDLPnxBh.d.cts → types-BR-k7h0e.d.cts} +1 -1
- package/dist/{types-DF4wzWQG.d.ts → types-DO4Tkwxo.d.ts} +1 -1
- package/dist/{types-DwBYd0ij.d.ts → types-DeVNWqlb.d.ts} +23 -0
- package/dist/{types-DWeyCTYK.d.cts → types-XUUFvrJ9.d.cts} +23 -0
- package/dist/{workflow-DVNPR7eX.d.cts → workflow-KbGsxpfh.d.cts} +1 -1
- package/dist/{workflow-DdaU7_j4.d.ts → workflow-uhOIj9D-.d.ts} +1 -1
- package/dist/workflow.cjs +33 -5
- package/dist/workflow.cjs.map +1 -1
- package/dist/workflow.d.cts +2 -2
- package/dist/workflow.d.ts +2 -2
- package/dist/workflow.js +33 -5
- package/dist/workflow.js.map +1 -1
- package/package.json +1 -1
- package/src/lib/session/session.ts +11 -0
- package/src/lib/subagent/handler.ts +23 -0
- package/src/lib/subagent/subagent.integration.test.ts +198 -0
- package/src/lib/tool-router/router.ts +11 -3
- package/src/lib/tool-router/types.ts +23 -0
|
@@ -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-
|
|
4
|
-
import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-
|
|
3
|
+
import { J as JsonValue } from './types-DeVNWqlb.js';
|
|
4
|
+
import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-DO4Tkwxo.js';
|
|
5
5
|
|
|
6
6
|
/** SDK-native content type for Anthropic human messages */
|
|
7
7
|
type AnthropicContent = string | Anthropic.Messages.ContentBlockParam[];
|
|
@@ -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-
|
|
4
|
-
import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-
|
|
3
|
+
import { J as JsonValue } from './types-XUUFvrJ9.cjs';
|
|
4
|
+
import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-BR-k7h0e.cjs';
|
|
5
5
|
|
|
6
6
|
/** SDK-native content type for Anthropic human messages */
|
|
7
7
|
type AnthropicContent = string | Anthropic.Messages.ContentBlockParam[];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Redis from 'ioredis';
|
|
2
|
-
import { J as JsonValue } from './types-
|
|
2
|
+
import { J as JsonValue } from './types-XUUFvrJ9.cjs';
|
|
3
3
|
import { MessageContent, StoredMessage, BaseMessage } from '@langchain/core/messages';
|
|
4
|
-
import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-
|
|
4
|
+
import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-BR-k7h0e.cjs';
|
|
5
5
|
|
|
6
6
|
/** SDK-native content type for LangChain human messages */
|
|
7
7
|
type LangChainContent = string | MessageContent;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Redis from 'ioredis';
|
|
2
|
-
import { J as JsonValue } from './types-
|
|
2
|
+
import { J as JsonValue } from './types-DeVNWqlb.js';
|
|
3
3
|
import { MessageContent, StoredMessage, BaseMessage } from '@langchain/core/messages';
|
|
4
|
-
import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-
|
|
4
|
+
import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-DO4Tkwxo.js';
|
|
5
5
|
|
|
6
6
|
/** SDK-native content type for LangChain human messages */
|
|
7
7
|
type LangChainContent = string | MessageContent;
|
|
@@ -146,6 +146,20 @@ interface RouterContext {
|
|
|
146
146
|
* thread so the child's first model call sees a well-formed history.
|
|
147
147
|
*/
|
|
148
148
|
assistantMessageId?: string;
|
|
149
|
+
/**
|
|
150
|
+
* Persist the parent session's current `PersistedThreadState` slice
|
|
151
|
+
* (tasks + custom state) to the durable thread store. Wired up by
|
|
152
|
+
* the session — absent for manually-driven routers (tests, custom
|
|
153
|
+
* orchestrators).
|
|
154
|
+
*
|
|
155
|
+
* Subagent handlers invoke this before spawning a child that will
|
|
156
|
+
* read the parent's thread (`newThreadSource: "from-parent"` or an
|
|
157
|
+
* explicit parent threadId): the parent's slice otherwise only
|
|
158
|
+
* lands in storage at session-exit time, so the child would load a
|
|
159
|
+
* stale (or empty) snapshot. Best-effort — failures are logged by
|
|
160
|
+
* the session but never thrown.
|
|
161
|
+
*/
|
|
162
|
+
persistThreadState?: () => Promise<void>;
|
|
149
163
|
}
|
|
150
164
|
/**
|
|
151
165
|
* A handler function for a specific tool.
|
|
@@ -221,6 +235,15 @@ interface ProcessToolCallsContext {
|
|
|
221
235
|
* out of a parent-forked thread).
|
|
222
236
|
*/
|
|
223
237
|
assistantMessageId?: string;
|
|
238
|
+
/**
|
|
239
|
+
* Optional callback that flushes the session's in-memory
|
|
240
|
+
* `PersistedThreadState` slice to the durable thread store. The
|
|
241
|
+
* router forwards it into every handler's {@link RouterContext}
|
|
242
|
+
* verbatim. The session uses this to let mid-loop tool handlers
|
|
243
|
+
* (notably subagents that fork or continue the parent's thread)
|
|
244
|
+
* persist the parent's slice before the child reads it.
|
|
245
|
+
*/
|
|
246
|
+
persistThreadState?: () => Promise<void>;
|
|
224
247
|
}
|
|
225
248
|
/**
|
|
226
249
|
* Signal that a tool handler requested a rewind. Attached to the
|
|
@@ -146,6 +146,20 @@ interface RouterContext {
|
|
|
146
146
|
* thread so the child's first model call sees a well-formed history.
|
|
147
147
|
*/
|
|
148
148
|
assistantMessageId?: string;
|
|
149
|
+
/**
|
|
150
|
+
* Persist the parent session's current `PersistedThreadState` slice
|
|
151
|
+
* (tasks + custom state) to the durable thread store. Wired up by
|
|
152
|
+
* the session — absent for manually-driven routers (tests, custom
|
|
153
|
+
* orchestrators).
|
|
154
|
+
*
|
|
155
|
+
* Subagent handlers invoke this before spawning a child that will
|
|
156
|
+
* read the parent's thread (`newThreadSource: "from-parent"` or an
|
|
157
|
+
* explicit parent threadId): the parent's slice otherwise only
|
|
158
|
+
* lands in storage at session-exit time, so the child would load a
|
|
159
|
+
* stale (or empty) snapshot. Best-effort — failures are logged by
|
|
160
|
+
* the session but never thrown.
|
|
161
|
+
*/
|
|
162
|
+
persistThreadState?: () => Promise<void>;
|
|
149
163
|
}
|
|
150
164
|
/**
|
|
151
165
|
* A handler function for a specific tool.
|
|
@@ -221,6 +235,15 @@ interface ProcessToolCallsContext {
|
|
|
221
235
|
* out of a parent-forked thread).
|
|
222
236
|
*/
|
|
223
237
|
assistantMessageId?: string;
|
|
238
|
+
/**
|
|
239
|
+
* Optional callback that flushes the session's in-memory
|
|
240
|
+
* `PersistedThreadState` slice to the durable thread store. The
|
|
241
|
+
* router forwards it into every handler's {@link RouterContext}
|
|
242
|
+
* verbatim. The session uses this to let mid-loop tool handlers
|
|
243
|
+
* (notably subagents that fork or continue the parent's thread)
|
|
244
|
+
* persist the parent's slice before the child reads it.
|
|
245
|
+
*/
|
|
246
|
+
persistThreadState?: () => Promise<void>;
|
|
224
247
|
}
|
|
225
248
|
/**
|
|
226
249
|
* Signal that a tool handler requested a rewind. Attached to the
|
|
@@ -1,4 +1,4 @@
|
|
|
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-
|
|
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-XUUFvrJ9.cjs';
|
|
2
2
|
import z$1, { z } from 'zod';
|
|
3
3
|
import './types-CJ7tCdl6.cjs';
|
|
4
4
|
import { Duration } from '@temporalio/common';
|
|
@@ -1,4 +1,4 @@
|
|
|
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-
|
|
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-DeVNWqlb.js';
|
|
2
2
|
import z$1, { z } from 'zod';
|
|
3
3
|
import './types-CJ7tCdl6.js';
|
|
4
4
|
import { Duration } from '@temporalio/common';
|
package/dist/workflow.cjs
CHANGED
|
@@ -123,7 +123,7 @@ function createToolRouter(options) {
|
|
|
123
123
|
});
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
|
-
async function processToolCall(toolCall, turn, sandboxId, onRewindRequested, assistantMessageId) {
|
|
126
|
+
async function processToolCall(toolCall, turn, sandboxId, onRewindRequested, assistantMessageId, persistThreadState) {
|
|
127
127
|
const startTime = Date.now();
|
|
128
128
|
const tool = toolMap.get(toolCall.name);
|
|
129
129
|
const preResult = await runPreHooks(toolCall, tool, turn);
|
|
@@ -159,7 +159,8 @@ function createToolRouter(options) {
|
|
|
159
159
|
toolCallId: toolCall.id,
|
|
160
160
|
toolName: toolCall.name,
|
|
161
161
|
...sandboxId !== void 0 && { sandboxId },
|
|
162
|
-
...assistantMessageId !== void 0 && { assistantMessageId }
|
|
162
|
+
...assistantMessageId !== void 0 && { assistantMessageId },
|
|
163
|
+
...persistThreadState !== void 0 && { persistThreadState }
|
|
163
164
|
};
|
|
164
165
|
const response = await tool.handler(
|
|
165
166
|
effectiveArgs,
|
|
@@ -287,6 +288,7 @@ function createToolRouter(options) {
|
|
|
287
288
|
const turn = context?.turn ?? 0;
|
|
288
289
|
const sandboxId = context?.sandboxId;
|
|
289
290
|
const assistantMessageId = context?.assistantMessageId;
|
|
291
|
+
const persistThreadState = context?.persistThreadState;
|
|
290
292
|
let rewindSignal;
|
|
291
293
|
if (options.parallel) {
|
|
292
294
|
const scope = new workflow.CancellationScope({ cancellable: true });
|
|
@@ -304,7 +306,8 @@ function createToolRouter(options) {
|
|
|
304
306
|
turn,
|
|
305
307
|
sandboxId,
|
|
306
308
|
onRewindRequested,
|
|
307
|
-
assistantMessageId
|
|
309
|
+
assistantMessageId,
|
|
310
|
+
persistThreadState
|
|
308
311
|
)
|
|
309
312
|
)
|
|
310
313
|
)
|
|
@@ -330,7 +333,8 @@ function createToolRouter(options) {
|
|
|
330
333
|
turn,
|
|
331
334
|
sandboxId,
|
|
332
335
|
void 0,
|
|
333
|
-
assistantMessageId
|
|
336
|
+
assistantMessageId,
|
|
337
|
+
persistThreadState
|
|
334
338
|
);
|
|
335
339
|
if (outcome.kind === "rewind") {
|
|
336
340
|
rewindSignal = outcome.signal;
|
|
@@ -358,6 +362,9 @@ function createToolRouter(options) {
|
|
|
358
362
|
},
|
|
359
363
|
...context?.assistantMessageId !== void 0 && {
|
|
360
364
|
assistantMessageId: context.assistantMessageId
|
|
365
|
+
},
|
|
366
|
+
...context?.persistThreadState !== void 0 && {
|
|
367
|
+
persistThreadState: context.persistThreadState
|
|
361
368
|
}
|
|
362
369
|
};
|
|
363
370
|
const response = await handler(
|
|
@@ -715,6 +722,17 @@ function createSubagentHandler(subagents) {
|
|
|
715
722
|
if (isSnapshotBaseCreator) {
|
|
716
723
|
snapshotBaseCreatorAgent.set(childWorkflowId, config.agentName);
|
|
717
724
|
}
|
|
725
|
+
if (continuationThreadId && continuationThreadId === context.threadId && context.persistThreadState) {
|
|
726
|
+
try {
|
|
727
|
+
await context.persistThreadState();
|
|
728
|
+
} catch (err) {
|
|
729
|
+
workflow.log.warn("failed to persist parent thread state for subagent", {
|
|
730
|
+
subagent: config.agentName,
|
|
731
|
+
childWorkflowId,
|
|
732
|
+
error: err instanceof Error ? err.message : String(err)
|
|
733
|
+
});
|
|
734
|
+
}
|
|
735
|
+
}
|
|
718
736
|
workflow.log.info("subagent spawned", {
|
|
719
737
|
subagent: config.agentName,
|
|
720
738
|
childWorkflowId,
|
|
@@ -1350,7 +1368,17 @@ async function createSession(config) {
|
|
|
1350
1368
|
...sandboxId !== void 0 && { sandboxId },
|
|
1351
1369
|
...assistantId !== void 0 && {
|
|
1352
1370
|
assistantMessageId: assistantId
|
|
1353
|
-
}
|
|
1371
|
+
},
|
|
1372
|
+
// Hand handlers a way to persist the parent's slice
|
|
1373
|
+
// mid-loop (subagents that fork or continue the parent's
|
|
1374
|
+
// thread need this — otherwise the child loads a stale
|
|
1375
|
+
// snapshot from the prior session, since `saveThreadState`
|
|
1376
|
+
// would otherwise only run in the `finally` below).
|
|
1377
|
+
persistThreadState: () => saveThreadState(
|
|
1378
|
+
threadId,
|
|
1379
|
+
stateManager.getPersistedSlice(),
|
|
1380
|
+
threadKey
|
|
1381
|
+
)
|
|
1354
1382
|
}
|
|
1355
1383
|
);
|
|
1356
1384
|
for (const result of toolCallResults) {
|