zeitlich 0.2.46 → 0.2.48
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/README.md +66 -6
- package/dist/{activities-CyeiqK_f.d.cts → activities-BlQR5gX4.d.cts} +3 -3
- package/dist/{activities-Bm4TLTid.d.ts → activities-DCaIPQBT.d.ts} +3 -3
- package/dist/adapters/thread/anthropic/index.cjs +105 -6
- package/dist/adapters/thread/anthropic/index.cjs.map +1 -1
- package/dist/adapters/thread/anthropic/index.d.cts +48 -9
- package/dist/adapters/thread/anthropic/index.d.ts +48 -9
- package/dist/adapters/thread/anthropic/index.js +104 -7
- package/dist/adapters/thread/anthropic/index.js.map +1 -1
- package/dist/adapters/thread/anthropic/workflow.cjs +38 -22
- package/dist/adapters/thread/anthropic/workflow.cjs.map +1 -1
- package/dist/adapters/thread/anthropic/workflow.d.cts +5 -4
- package/dist/adapters/thread/anthropic/workflow.d.ts +5 -4
- package/dist/adapters/thread/anthropic/workflow.js +38 -22
- package/dist/adapters/thread/anthropic/workflow.js.map +1 -1
- package/dist/adapters/thread/google-genai/index.d.cts +6 -5
- package/dist/adapters/thread/google-genai/index.d.ts +6 -5
- package/dist/adapters/thread/google-genai/workflow.cjs +38 -22
- package/dist/adapters/thread/google-genai/workflow.cjs.map +1 -1
- package/dist/adapters/thread/google-genai/workflow.d.cts +7 -5
- package/dist/adapters/thread/google-genai/workflow.d.ts +7 -5
- package/dist/adapters/thread/google-genai/workflow.js +38 -22
- package/dist/adapters/thread/google-genai/workflow.js.map +1 -1
- package/dist/adapters/thread/langchain/index.d.cts +6 -5
- package/dist/adapters/thread/langchain/index.d.ts +6 -5
- package/dist/adapters/thread/langchain/workflow.cjs +38 -22
- package/dist/adapters/thread/langchain/workflow.cjs.map +1 -1
- package/dist/adapters/thread/langchain/workflow.d.cts +5 -4
- package/dist/adapters/thread/langchain/workflow.d.ts +5 -4
- package/dist/adapters/thread/langchain/workflow.js +38 -22
- package/dist/adapters/thread/langchain/workflow.js.map +1 -1
- package/dist/{cold-store-BC5L5Z8A.d.cts → cold-store-UL13Sstw.d.cts} +8 -11
- package/dist/{cold-store-CFHwemBJ.d.ts → cold-store-aD4TSKlU.d.ts} +8 -11
- package/dist/index.cjs +311 -99
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -9
- package/dist/index.d.ts +21 -9
- package/dist/index.js +312 -102
- package/dist/index.js.map +1 -1
- package/dist/proxy-BAty3CWM.d.cts +40 -0
- package/dist/proxy-mbnwBhHw.d.ts +40 -0
- package/dist/{thread-manager-DduoSkvJ.d.ts → thread-manager-CICj68PI.d.ts} +2 -2
- package/dist/{thread-manager-D33SUmZa.d.cts → thread-manager-DsXvJ5cJ.d.cts} +2 -2
- package/dist/{thread-manager-B-zy3xrs.d.ts → thread-manager-DtEtbUkp.d.ts} +2 -2
- package/dist/{thread-manager-9tezUcLW.d.cts → thread-manager-R6c3lnJy.d.cts} +2 -2
- package/dist/{types-oxt8GN97.d.cts → types-DDLPnxBh.d.cts} +1 -1
- package/dist/{types-L5bvbF-n.d.ts → types-DF4wzWQG.d.ts} +1 -1
- package/dist/{types-CnuN9T6t.d.cts → types-DWeyCTYK.d.cts} +47 -0
- package/dist/{types-CwN6_tAL.d.ts → types-DwBYd0ij.d.ts} +47 -0
- package/dist/{workflow-DIaIV7L2.d.cts → workflow-DVNPR7eX.d.cts} +17 -2
- package/dist/{workflow-B1TOcHbt.d.ts → workflow-DdaU7_j4.d.ts} +17 -2
- package/dist/workflow.cjs +80 -12
- 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 +80 -13
- package/dist/workflow.js.map +1 -1
- package/package.json +14 -8
- package/src/adapters/thread/anthropic/activities.ts +18 -11
- package/src/adapters/thread/anthropic/index.ts +8 -0
- package/src/adapters/thread/anthropic/model-invoker.test.ts +110 -0
- package/src/adapters/thread/anthropic/model-invoker.ts +26 -5
- package/src/adapters/thread/anthropic/prompt-cache.test.ts +134 -0
- package/src/adapters/thread/anthropic/prompt-cache.ts +163 -0
- package/src/adapters/thread/anthropic/proxy.ts +1 -0
- package/src/adapters/thread/google-genai/proxy.ts +1 -0
- package/src/adapters/thread/langchain/proxy.ts +1 -0
- package/src/index.ts +1 -1
- package/src/lib/lifecycle.ts +13 -1
- package/src/lib/session/session-edge-cases.integration.test.ts +44 -0
- package/src/lib/session/session.ts +15 -0
- package/src/lib/subagent/define.ts +1 -0
- package/src/lib/subagent/handler.ts +41 -6
- package/src/lib/subagent/subagent.integration.test.ts +178 -0
- package/src/lib/subagent/types.ts +16 -0
- package/src/lib/thread/cold-store.test.ts +33 -5
- package/src/lib/thread/cold-store.ts +50 -31
- package/src/lib/thread/proxy.ts +79 -29
- package/src/lib/tool-router/router-edge-cases.integration.test.ts +36 -0
- package/src/lib/tool-router/router.ts +21 -3
- package/src/lib/tool-router/types.ts +20 -0
- package/src/tools/edit/handler.test.ts +177 -0
- package/src/tools/edit/handler.ts +249 -47
- package/src/tools/edit/tool.ts +40 -0
- package/src/tools/task-create/handler.ts +1 -1
- package/src/tools/task-update/handler.ts +1 -1
- package/src/workflow.ts +2 -2
- package/dist/proxy-BxFyd6cg.d.cts +0 -24
- package/dist/proxy-Cskmj4Yx.d.ts +0 -24
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ActivityOptions, ActivityInterfaceFor } from '@temporalio/workflow';
|
|
2
|
+
import { T as ThreadOps } from './types-DWeyCTYK.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Shared proxy helper for thread operations.
|
|
6
|
+
*
|
|
7
|
+
* Each adapter re-exports a thin wrapper that supplies its prefix and
|
|
8
|
+
* casts the return type to carry the adapter's native content type.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
type OpName = keyof ThreadOps;
|
|
12
|
+
/**
|
|
13
|
+
* `perOp[op]` layers shallow-rightmost over `defaults` and the
|
|
14
|
+
* built-in cold-tier overlay (`hydrateThread` / `flushThread`).
|
|
15
|
+
* A bare {@link ActivityOptions} is also accepted (treated as `{ defaults }`).
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* proxyAnthropicThreadOps(undefined, {
|
|
20
|
+
* defaults: { startToCloseTimeout: "5s" },
|
|
21
|
+
* perOp: {
|
|
22
|
+
* flushThread: { startToCloseTimeout: "180s" }, // heartbeatTimeout still inherited
|
|
23
|
+
* },
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
interface ThreadOpsProxyOptions {
|
|
28
|
+
defaults?: ActivityOptions;
|
|
29
|
+
perOp?: Partial<Record<OpName, ActivityOptions>>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Creates a workflow-safe Temporal activity proxy for {@link ThreadOps}.
|
|
33
|
+
*
|
|
34
|
+
* @param adapterPrefix - Adapter identifier (e.g. "anthropic", "googleGenAI", "langChain")
|
|
35
|
+
* @param scope - Workflow scope. Defaults to `workflowInfo().workflowType`.
|
|
36
|
+
* @param options - {@link ThreadOpsProxyOptions} or a bare {@link ActivityOptions}.
|
|
37
|
+
*/
|
|
38
|
+
declare function createThreadOpsProxy(adapterPrefix: string, scope?: string, options?: ActivityOptions | ThreadOpsProxyOptions): ActivityInterfaceFor<ThreadOps>;
|
|
39
|
+
|
|
40
|
+
export { type ThreadOpsProxyOptions as T, createThreadOpsProxy as c };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ActivityOptions, ActivityInterfaceFor } from '@temporalio/workflow';
|
|
2
|
+
import { T as ThreadOps } from './types-DwBYd0ij.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Shared proxy helper for thread operations.
|
|
6
|
+
*
|
|
7
|
+
* Each adapter re-exports a thin wrapper that supplies its prefix and
|
|
8
|
+
* casts the return type to carry the adapter's native content type.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
type OpName = keyof ThreadOps;
|
|
12
|
+
/**
|
|
13
|
+
* `perOp[op]` layers shallow-rightmost over `defaults` and the
|
|
14
|
+
* built-in cold-tier overlay (`hydrateThread` / `flushThread`).
|
|
15
|
+
* A bare {@link ActivityOptions} is also accepted (treated as `{ defaults }`).
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* proxyAnthropicThreadOps(undefined, {
|
|
20
|
+
* defaults: { startToCloseTimeout: "5s" },
|
|
21
|
+
* perOp: {
|
|
22
|
+
* flushThread: { startToCloseTimeout: "180s" }, // heartbeatTimeout still inherited
|
|
23
|
+
* },
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
interface ThreadOpsProxyOptions {
|
|
28
|
+
defaults?: ActivityOptions;
|
|
29
|
+
perOp?: Partial<Record<OpName, ActivityOptions>>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Creates a workflow-safe Temporal activity proxy for {@link ThreadOps}.
|
|
33
|
+
*
|
|
34
|
+
* @param adapterPrefix - Adapter identifier (e.g. "anthropic", "googleGenAI", "langChain")
|
|
35
|
+
* @param scope - Workflow scope. Defaults to `workflowInfo().workflowType`.
|
|
36
|
+
* @param options - {@link ThreadOpsProxyOptions} or a bare {@link ActivityOptions}.
|
|
37
|
+
*/
|
|
38
|
+
declare function createThreadOpsProxy(adapterPrefix: string, scope?: string, options?: ActivityOptions | ThreadOpsProxyOptions): ActivityInterfaceFor<ThreadOps>;
|
|
39
|
+
|
|
40
|
+
export { type ThreadOpsProxyOptions as T, createThreadOpsProxy as c };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Redis from 'ioredis';
|
|
2
|
-
import { J as JsonValue } from './types-
|
|
2
|
+
import { J as JsonValue } from './types-DwBYd0ij.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-DF4wzWQG.js';
|
|
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-DWeyCTYK.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-DDLPnxBh.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
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-DwBYd0ij.js';
|
|
4
|
+
import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-DF4wzWQG.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-DWeyCTYK.cjs';
|
|
4
|
+
import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-DDLPnxBh.cjs';
|
|
5
5
|
|
|
6
6
|
/** SDK-native content type for Anthropic human messages */
|
|
7
7
|
type AnthropicContent = string | Anthropic.Messages.ContentBlockParam[];
|
|
@@ -134,6 +134,18 @@ interface RouterContext {
|
|
|
134
134
|
toolCallId: string;
|
|
135
135
|
toolName: string;
|
|
136
136
|
sandboxId?: string;
|
|
137
|
+
/**
|
|
138
|
+
* Id of the assistant message that issued this tool call (the message
|
|
139
|
+
* the session passed as `assistantMessageId` into `runAgent`). Present
|
|
140
|
+
* for any tool call processed through `processToolCalls` from a
|
|
141
|
+
* session; may be absent when the router is driven manually (e.g.
|
|
142
|
+
* tests, custom orchestrators).
|
|
143
|
+
*
|
|
144
|
+
* Subagent handlers that fork the parent's thread mid-call use this
|
|
145
|
+
* to truncate the orphan trailing assistant message from the forked
|
|
146
|
+
* thread so the child's first model call sees a well-formed history.
|
|
147
|
+
*/
|
|
148
|
+
assistantMessageId?: string;
|
|
137
149
|
}
|
|
138
150
|
/**
|
|
139
151
|
* A handler function for a specific tool.
|
|
@@ -201,6 +213,14 @@ interface ProcessToolCallsContext {
|
|
|
201
213
|
turn?: number;
|
|
202
214
|
/** Active sandbox ID (when a sandbox is configured for this session) */
|
|
203
215
|
sandboxId?: string;
|
|
216
|
+
/**
|
|
217
|
+
* Id of the assistant message that produced these tool calls. The
|
|
218
|
+
* router forwards it into every handler's {@link RouterContext} so
|
|
219
|
+
* handlers can reference the message they were issued from (e.g.
|
|
220
|
+
* subagent forks that need to truncate the orphan assistant message
|
|
221
|
+
* out of a parent-forked thread).
|
|
222
|
+
*/
|
|
223
|
+
assistantMessageId?: string;
|
|
204
224
|
}
|
|
205
225
|
/**
|
|
206
226
|
* Signal that a tool handler requested a rewind. Attached to the
|
|
@@ -887,6 +907,14 @@ interface Hooks<T extends ToolMap, TResult = unknown, TContent = unknown> extend
|
|
|
887
907
|
* continue there. When the adapter has `onForkPrepareThread` and/or
|
|
888
908
|
* `onForkTransform` hooks configured, they are applied once to the forked
|
|
889
909
|
* thread before the session starts.
|
|
910
|
+
*
|
|
911
|
+
* The optional `truncateAfterFork.fromMessageId` directs the session to
|
|
912
|
+
* call `truncateThread` on the freshly forked thread immediately after
|
|
913
|
+
* the fork, dropping that message and everything after. Used by
|
|
914
|
+
* subagents that fork their parent's thread mid-tool-call to strip the
|
|
915
|
+
* orphan assistant `tool_use` block (the one whose `tool_result` will
|
|
916
|
+
* never arrive in the child's thread) so the first model call doesn't
|
|
917
|
+
* reject on an unmatched tool-use/tool-result pair.
|
|
890
918
|
*/
|
|
891
919
|
type ThreadInit = {
|
|
892
920
|
mode: "new";
|
|
@@ -897,6 +925,9 @@ type ThreadInit = {
|
|
|
897
925
|
} | {
|
|
898
926
|
mode: "fork";
|
|
899
927
|
threadId: string;
|
|
928
|
+
truncateAfterFork?: {
|
|
929
|
+
fromMessageId: string;
|
|
930
|
+
};
|
|
900
931
|
};
|
|
901
932
|
|
|
902
933
|
/**
|
|
@@ -1283,6 +1314,22 @@ interface SubagentConfig<TResult extends z.ZodType = z.ZodType> {
|
|
|
1283
1314
|
* directly to the existing thread in-place.
|
|
1284
1315
|
*/
|
|
1285
1316
|
thread?: "new" | "fork" | "continue";
|
|
1317
|
+
/**
|
|
1318
|
+
* Where the subagent's thread comes from when the parent's tool call
|
|
1319
|
+
* omits `threadId`. Only meaningful in combination with
|
|
1320
|
+
* `thread: "fork"` or `"continue"`.
|
|
1321
|
+
*
|
|
1322
|
+
* - `"new"` (default) — start a fresh thread (the prior behavior).
|
|
1323
|
+
* - `"from-parent"` — use the parent's own `threadId` (from
|
|
1324
|
+
* `RouterContext`). With `thread: "fork"` the parent's conversation
|
|
1325
|
+
* is copied into a new thread; with `thread: "continue"` the
|
|
1326
|
+
* subagent appends to the parent's thread in-place.
|
|
1327
|
+
*
|
|
1328
|
+
* Has no effect when `thread` is `"new"` (or omitted). A `threadId`
|
|
1329
|
+
* supplied by the parent agent always wins — `newThreadSource` only
|
|
1330
|
+
* applies when none is provided.
|
|
1331
|
+
*/
|
|
1332
|
+
newThreadSource?: "new" | "from-parent";
|
|
1286
1333
|
/**
|
|
1287
1334
|
* Sandbox strategy for this subagent.
|
|
1288
1335
|
*
|
|
@@ -134,6 +134,18 @@ interface RouterContext {
|
|
|
134
134
|
toolCallId: string;
|
|
135
135
|
toolName: string;
|
|
136
136
|
sandboxId?: string;
|
|
137
|
+
/**
|
|
138
|
+
* Id of the assistant message that issued this tool call (the message
|
|
139
|
+
* the session passed as `assistantMessageId` into `runAgent`). Present
|
|
140
|
+
* for any tool call processed through `processToolCalls` from a
|
|
141
|
+
* session; may be absent when the router is driven manually (e.g.
|
|
142
|
+
* tests, custom orchestrators).
|
|
143
|
+
*
|
|
144
|
+
* Subagent handlers that fork the parent's thread mid-call use this
|
|
145
|
+
* to truncate the orphan trailing assistant message from the forked
|
|
146
|
+
* thread so the child's first model call sees a well-formed history.
|
|
147
|
+
*/
|
|
148
|
+
assistantMessageId?: string;
|
|
137
149
|
}
|
|
138
150
|
/**
|
|
139
151
|
* A handler function for a specific tool.
|
|
@@ -201,6 +213,14 @@ interface ProcessToolCallsContext {
|
|
|
201
213
|
turn?: number;
|
|
202
214
|
/** Active sandbox ID (when a sandbox is configured for this session) */
|
|
203
215
|
sandboxId?: string;
|
|
216
|
+
/**
|
|
217
|
+
* Id of the assistant message that produced these tool calls. The
|
|
218
|
+
* router forwards it into every handler's {@link RouterContext} so
|
|
219
|
+
* handlers can reference the message they were issued from (e.g.
|
|
220
|
+
* subagent forks that need to truncate the orphan assistant message
|
|
221
|
+
* out of a parent-forked thread).
|
|
222
|
+
*/
|
|
223
|
+
assistantMessageId?: string;
|
|
204
224
|
}
|
|
205
225
|
/**
|
|
206
226
|
* Signal that a tool handler requested a rewind. Attached to the
|
|
@@ -887,6 +907,14 @@ interface Hooks<T extends ToolMap, TResult = unknown, TContent = unknown> extend
|
|
|
887
907
|
* continue there. When the adapter has `onForkPrepareThread` and/or
|
|
888
908
|
* `onForkTransform` hooks configured, they are applied once to the forked
|
|
889
909
|
* thread before the session starts.
|
|
910
|
+
*
|
|
911
|
+
* The optional `truncateAfterFork.fromMessageId` directs the session to
|
|
912
|
+
* call `truncateThread` on the freshly forked thread immediately after
|
|
913
|
+
* the fork, dropping that message and everything after. Used by
|
|
914
|
+
* subagents that fork their parent's thread mid-tool-call to strip the
|
|
915
|
+
* orphan assistant `tool_use` block (the one whose `tool_result` will
|
|
916
|
+
* never arrive in the child's thread) so the first model call doesn't
|
|
917
|
+
* reject on an unmatched tool-use/tool-result pair.
|
|
890
918
|
*/
|
|
891
919
|
type ThreadInit = {
|
|
892
920
|
mode: "new";
|
|
@@ -897,6 +925,9 @@ type ThreadInit = {
|
|
|
897
925
|
} | {
|
|
898
926
|
mode: "fork";
|
|
899
927
|
threadId: string;
|
|
928
|
+
truncateAfterFork?: {
|
|
929
|
+
fromMessageId: string;
|
|
930
|
+
};
|
|
900
931
|
};
|
|
901
932
|
|
|
902
933
|
/**
|
|
@@ -1283,6 +1314,22 @@ interface SubagentConfig<TResult extends z.ZodType = z.ZodType> {
|
|
|
1283
1314
|
* directly to the existing thread in-place.
|
|
1284
1315
|
*/
|
|
1285
1316
|
thread?: "new" | "fork" | "continue";
|
|
1317
|
+
/**
|
|
1318
|
+
* Where the subagent's thread comes from when the parent's tool call
|
|
1319
|
+
* omits `threadId`. Only meaningful in combination with
|
|
1320
|
+
* `thread: "fork"` or `"continue"`.
|
|
1321
|
+
*
|
|
1322
|
+
* - `"new"` (default) — start a fresh thread (the prior behavior).
|
|
1323
|
+
* - `"from-parent"` — use the parent's own `threadId` (from
|
|
1324
|
+
* `RouterContext`). With `thread: "fork"` the parent's conversation
|
|
1325
|
+
* is copied into a new thread; with `thread: "continue"` the
|
|
1326
|
+
* subagent appends to the parent's thread in-place.
|
|
1327
|
+
*
|
|
1328
|
+
* Has no effect when `thread` is `"new"` (or omitted). A `threadId`
|
|
1329
|
+
* supplied by the parent agent always wins — `newThreadSource` only
|
|
1330
|
+
* applies when none is provided.
|
|
1331
|
+
*/
|
|
1332
|
+
newThreadSource?: "new" | "from-parent";
|
|
1286
1333
|
/**
|
|
1287
1334
|
* Sandbox strategy for this subagent.
|
|
1288
1335
|
*
|
|
@@ -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-DWeyCTYK.cjs';
|
|
2
2
|
import z$1, { z } from 'zod';
|
|
3
3
|
import './types-CJ7tCdl6.cjs';
|
|
4
4
|
import { Duration } from '@temporalio/common';
|
|
@@ -335,6 +335,7 @@ declare function defineSubagent<TResult extends z.ZodType = z.ZodType, TContext
|
|
|
335
335
|
enabled?: boolean | (() => boolean);
|
|
336
336
|
taskQueue?: string;
|
|
337
337
|
thread?: "new" | "fork" | "continue";
|
|
338
|
+
newThreadSource?: "new" | "from-parent";
|
|
338
339
|
sandbox?: SubagentSandboxConfig;
|
|
339
340
|
}): SubagentConfig<TResult>;
|
|
340
341
|
|
|
@@ -740,6 +741,20 @@ declare const editTool: {
|
|
|
740
741
|
strict: true;
|
|
741
742
|
};
|
|
742
743
|
type FileEditArgs = z.infer<typeof editTool.schema>;
|
|
744
|
+
declare const multiEditTool: {
|
|
745
|
+
name: "FileMultiEdit";
|
|
746
|
+
description: string;
|
|
747
|
+
schema: z.ZodObject<{
|
|
748
|
+
file_path: z.ZodString;
|
|
749
|
+
edits: z.ZodArray<z.ZodObject<{
|
|
750
|
+
old_string: z.ZodString;
|
|
751
|
+
new_string: z.ZodString;
|
|
752
|
+
replace_all: z.ZodOptional<z.ZodBoolean>;
|
|
753
|
+
}, z.core.$strip>>;
|
|
754
|
+
}, z.core.$strip>;
|
|
755
|
+
strict: true;
|
|
756
|
+
};
|
|
757
|
+
type FileMultiEditArgs = z.infer<typeof multiEditTool.schema>;
|
|
743
758
|
|
|
744
759
|
declare const taskCreateTool: {
|
|
745
760
|
name: "TaskCreate";
|
|
@@ -887,4 +902,4 @@ declare const createAskUserQuestionHandler: () => ActivityToolHandler<AskUserQue
|
|
|
887
902
|
}[];
|
|
888
903
|
}>;
|
|
889
904
|
|
|
890
|
-
export {
|
|
905
|
+
export { getThreadStateKey as $, type AskUserQuestionArgs as A, type BashArgs as B, createTaskCreateHandler as C, DEFAULT_SUBAGENT_WORKFLOW_RUN_TIMEOUT as D, createTaskGetHandler as E, type FileEditArgs as F, type GlobArgs as G, createTaskListHandler as H, createTaskUpdateHandler as I, createToolRouter as J, defineSubagent as K, defineSubagentWorkflow as L, defineTool as M, defineWorkflow as N, type ObservabilityHooks as O, editTool as P, filesWithMimeType as Q, type ReadSkillArgs as R, type SessionEndedEvent as S, THREAD_TTL_SECONDS as T, formatVirtualFileTree as U, getShortId as V, type WorkflowConfig as W, getThreadDedupKey as X, getThreadListKey as Y, type ZeitlichObservabilitySinks as Z, getThreadMetaKey as _, type FileMultiEditArgs as a, globTool as a0, grepTool as a1, hasDirectory as a2, hasFileWithMimeType as a3, hasNoOtherToolCalls as a4, multiEditTool as a5, parseSkillFile as a6, proxyRunAgent as a7, proxyVirtualFsOps as a8, readFileTool as a9, taskCreateTool as aa, taskGetTool as ab, taskListTool as ac, taskUpdateTool as ad, writeFileTool as ae, type FileReadArgs as b, type FileWriteArgs as c, type FileTreeAccessor as d, type GrepArgs as e, type SessionStartedEvent as f, type SubagentArgs as g, type TaskCreateArgs as h, type TaskGetArgs as i, type TaskListArgs as j, type TaskUpdateArgs as k, type ToolExecutedEvent as l, type TurnCompletedEvent as m, type WorkflowInput as n, type WorkflowSessionInput as o, applyVirtualTreeMutations as p, askUserQuestionTool as q, bashTool as r, composeHooks as s, createAgentStateManager as t, createAskUserQuestionHandler as u, createBashToolDescription as v, createObservabilityHooks as w, createReadSkillHandler as x, createReadSkillTool as y, createSession as z };
|
|
@@ -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-DwBYd0ij.js';
|
|
2
2
|
import z$1, { z } from 'zod';
|
|
3
3
|
import './types-CJ7tCdl6.js';
|
|
4
4
|
import { Duration } from '@temporalio/common';
|
|
@@ -335,6 +335,7 @@ declare function defineSubagent<TResult extends z.ZodType = z.ZodType, TContext
|
|
|
335
335
|
enabled?: boolean | (() => boolean);
|
|
336
336
|
taskQueue?: string;
|
|
337
337
|
thread?: "new" | "fork" | "continue";
|
|
338
|
+
newThreadSource?: "new" | "from-parent";
|
|
338
339
|
sandbox?: SubagentSandboxConfig;
|
|
339
340
|
}): SubagentConfig<TResult>;
|
|
340
341
|
|
|
@@ -740,6 +741,20 @@ declare const editTool: {
|
|
|
740
741
|
strict: true;
|
|
741
742
|
};
|
|
742
743
|
type FileEditArgs = z.infer<typeof editTool.schema>;
|
|
744
|
+
declare const multiEditTool: {
|
|
745
|
+
name: "FileMultiEdit";
|
|
746
|
+
description: string;
|
|
747
|
+
schema: z.ZodObject<{
|
|
748
|
+
file_path: z.ZodString;
|
|
749
|
+
edits: z.ZodArray<z.ZodObject<{
|
|
750
|
+
old_string: z.ZodString;
|
|
751
|
+
new_string: z.ZodString;
|
|
752
|
+
replace_all: z.ZodOptional<z.ZodBoolean>;
|
|
753
|
+
}, z.core.$strip>>;
|
|
754
|
+
}, z.core.$strip>;
|
|
755
|
+
strict: true;
|
|
756
|
+
};
|
|
757
|
+
type FileMultiEditArgs = z.infer<typeof multiEditTool.schema>;
|
|
743
758
|
|
|
744
759
|
declare const taskCreateTool: {
|
|
745
760
|
name: "TaskCreate";
|
|
@@ -887,4 +902,4 @@ declare const createAskUserQuestionHandler: () => ActivityToolHandler<AskUserQue
|
|
|
887
902
|
}[];
|
|
888
903
|
}>;
|
|
889
904
|
|
|
890
|
-
export {
|
|
905
|
+
export { getThreadStateKey as $, type AskUserQuestionArgs as A, type BashArgs as B, createTaskCreateHandler as C, DEFAULT_SUBAGENT_WORKFLOW_RUN_TIMEOUT as D, createTaskGetHandler as E, type FileEditArgs as F, type GlobArgs as G, createTaskListHandler as H, createTaskUpdateHandler as I, createToolRouter as J, defineSubagent as K, defineSubagentWorkflow as L, defineTool as M, defineWorkflow as N, type ObservabilityHooks as O, editTool as P, filesWithMimeType as Q, type ReadSkillArgs as R, type SessionEndedEvent as S, THREAD_TTL_SECONDS as T, formatVirtualFileTree as U, getShortId as V, type WorkflowConfig as W, getThreadDedupKey as X, getThreadListKey as Y, type ZeitlichObservabilitySinks as Z, getThreadMetaKey as _, type FileMultiEditArgs as a, globTool as a0, grepTool as a1, hasDirectory as a2, hasFileWithMimeType as a3, hasNoOtherToolCalls as a4, multiEditTool as a5, parseSkillFile as a6, proxyRunAgent as a7, proxyVirtualFsOps as a8, readFileTool as a9, taskCreateTool as aa, taskGetTool as ab, taskListTool as ac, taskUpdateTool as ad, writeFileTool as ae, type FileReadArgs as b, type FileWriteArgs as c, type FileTreeAccessor as d, type GrepArgs as e, type SessionStartedEvent as f, type SubagentArgs as g, type TaskCreateArgs as h, type TaskGetArgs as i, type TaskListArgs as j, type TaskUpdateArgs as k, type ToolExecutedEvent as l, type TurnCompletedEvent as m, type WorkflowInput as n, type WorkflowSessionInput as o, applyVirtualTreeMutations as p, askUserQuestionTool as q, bashTool as r, composeHooks as s, createAgentStateManager as t, createAskUserQuestionHandler as u, createBashToolDescription as v, createObservabilityHooks as w, createReadSkillHandler as x, createReadSkillTool as y, createSession as z };
|
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) {
|
|
126
|
+
async function processToolCall(toolCall, turn, sandboxId, onRewindRequested, assistantMessageId) {
|
|
127
127
|
const startTime = Date.now();
|
|
128
128
|
const tool = toolMap.get(toolCall.name);
|
|
129
129
|
const preResult = await runPreHooks(toolCall, tool, turn);
|
|
@@ -158,7 +158,8 @@ function createToolRouter(options) {
|
|
|
158
158
|
...options.threadKey && { threadKey: options.threadKey },
|
|
159
159
|
toolCallId: toolCall.id,
|
|
160
160
|
toolName: toolCall.name,
|
|
161
|
-
...sandboxId !== void 0 && { sandboxId }
|
|
161
|
+
...sandboxId !== void 0 && { sandboxId },
|
|
162
|
+
...assistantMessageId !== void 0 && { assistantMessageId }
|
|
162
163
|
};
|
|
163
164
|
const response = await tool.handler(
|
|
164
165
|
effectiveArgs,
|
|
@@ -285,6 +286,7 @@ function createToolRouter(options) {
|
|
|
285
286
|
}
|
|
286
287
|
const turn = context?.turn ?? 0;
|
|
287
288
|
const sandboxId = context?.sandboxId;
|
|
289
|
+
const assistantMessageId = context?.assistantMessageId;
|
|
288
290
|
let rewindSignal;
|
|
289
291
|
if (options.parallel) {
|
|
290
292
|
const scope = new workflow.CancellationScope({ cancellable: true });
|
|
@@ -297,7 +299,13 @@ function createToolRouter(options) {
|
|
|
297
299
|
const outcomes = await scope.run(
|
|
298
300
|
async () => Promise.allSettled(
|
|
299
301
|
toolCalls.map(
|
|
300
|
-
(tc) => processToolCall(
|
|
302
|
+
(tc) => processToolCall(
|
|
303
|
+
tc,
|
|
304
|
+
turn,
|
|
305
|
+
sandboxId,
|
|
306
|
+
onRewindRequested,
|
|
307
|
+
assistantMessageId
|
|
308
|
+
)
|
|
301
309
|
)
|
|
302
310
|
)
|
|
303
311
|
);
|
|
@@ -317,7 +325,13 @@ function createToolRouter(options) {
|
|
|
317
325
|
}
|
|
318
326
|
const results = [];
|
|
319
327
|
for (const toolCall of toolCalls) {
|
|
320
|
-
const outcome = await processToolCall(
|
|
328
|
+
const outcome = await processToolCall(
|
|
329
|
+
toolCall,
|
|
330
|
+
turn,
|
|
331
|
+
sandboxId,
|
|
332
|
+
void 0,
|
|
333
|
+
assistantMessageId
|
|
334
|
+
);
|
|
321
335
|
if (outcome.kind === "rewind") {
|
|
322
336
|
rewindSignal = outcome.signal;
|
|
323
337
|
break;
|
|
@@ -341,6 +355,9 @@ function createToolRouter(options) {
|
|
|
341
355
|
toolName: toolCall.name,
|
|
342
356
|
...context?.sandboxId !== void 0 && {
|
|
343
357
|
sandboxId: context.sandboxId
|
|
358
|
+
},
|
|
359
|
+
...context?.assistantMessageId !== void 0 && {
|
|
360
|
+
assistantMessageId: context.assistantMessageId
|
|
344
361
|
}
|
|
345
362
|
};
|
|
346
363
|
const response = await handler(
|
|
@@ -566,13 +583,27 @@ function createSubagentHandler(subagents) {
|
|
|
566
583
|
}
|
|
567
584
|
const threadMode = config.thread ?? "new";
|
|
568
585
|
const allowsContinuation = threadMode !== "new";
|
|
569
|
-
const
|
|
586
|
+
const newThreadSource = config.newThreadSource ?? "new";
|
|
587
|
+
const usingParentFallback = allowsContinuation && !args.threadId && newThreadSource === "from-parent";
|
|
588
|
+
const continuationThreadId = !allowsContinuation ? void 0 : args.threadId ?? (usingParentFallback ? context.threadId : void 0);
|
|
570
589
|
let thread;
|
|
571
590
|
if (continuationThreadId) {
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
591
|
+
if (threadMode === "fork") {
|
|
592
|
+
thread = {
|
|
593
|
+
mode: "fork",
|
|
594
|
+
threadId: continuationThreadId,
|
|
595
|
+
...usingParentFallback && context.assistantMessageId ? {
|
|
596
|
+
truncateAfterFork: {
|
|
597
|
+
fromMessageId: context.assistantMessageId
|
|
598
|
+
}
|
|
599
|
+
} : {}
|
|
600
|
+
};
|
|
601
|
+
} else {
|
|
602
|
+
thread = {
|
|
603
|
+
mode: "continue",
|
|
604
|
+
threadId: continuationThreadId
|
|
605
|
+
};
|
|
606
|
+
}
|
|
576
607
|
}
|
|
577
608
|
let sandbox;
|
|
578
609
|
let sandboxShutdownOverride;
|
|
@@ -1033,6 +1064,7 @@ async function createSession(config) {
|
|
|
1033
1064
|
appendSystemMessage,
|
|
1034
1065
|
appendAgentMessage,
|
|
1035
1066
|
forkThread,
|
|
1067
|
+
truncateThread,
|
|
1036
1068
|
loadThreadState,
|
|
1037
1069
|
saveThreadState,
|
|
1038
1070
|
hydrateThread,
|
|
@@ -1182,6 +1214,10 @@ async function createSession(config) {
|
|
|
1182
1214
|
if (threadMode === "fork" && sourceThreadId) {
|
|
1183
1215
|
await hydrateThread(sourceThreadId, threadKey);
|
|
1184
1216
|
await forkThread(sourceThreadId, threadId, threadKey);
|
|
1217
|
+
const truncate = threadInit.truncateAfterFork;
|
|
1218
|
+
if (truncate?.fromMessageId) {
|
|
1219
|
+
await truncateThread(threadId, truncate.fromMessageId, threadKey);
|
|
1220
|
+
}
|
|
1185
1221
|
const forkedSlice = await loadThreadState(threadId, threadKey);
|
|
1186
1222
|
if (forkedSlice) rehydrateFromSlice(forkedSlice);
|
|
1187
1223
|
} else if (threadMode === "continue") {
|
|
@@ -1311,7 +1347,10 @@ async function createSession(config) {
|
|
|
1311
1347
|
parsedToolCalls,
|
|
1312
1348
|
{
|
|
1313
1349
|
turn: currentTurn,
|
|
1314
|
-
...sandboxId !== void 0 && { sandboxId }
|
|
1350
|
+
...sandboxId !== void 0 && { sandboxId },
|
|
1351
|
+
...assistantId !== void 0 && {
|
|
1352
|
+
assistantMessageId: assistantId
|
|
1353
|
+
}
|
|
1315
1354
|
}
|
|
1316
1355
|
);
|
|
1317
1356
|
for (const result of toolCallResults) {
|
|
@@ -2118,6 +2157,13 @@ IMPORTANT:
|
|
|
2118
2157
|
}),
|
|
2119
2158
|
strict: true
|
|
2120
2159
|
};
|
|
2160
|
+
var textEditSchema = z14.z.object({
|
|
2161
|
+
old_string: z14.z.string().describe("The exact text to replace"),
|
|
2162
|
+
new_string: z14.z.string().describe("The text to replace it with"),
|
|
2163
|
+
replace_all: z14.z.boolean().optional().describe(
|
|
2164
|
+
"If true, replace all occurrences of old_string for this edit (default: false)"
|
|
2165
|
+
)
|
|
2166
|
+
});
|
|
2121
2167
|
var editTool = {
|
|
2122
2168
|
name: "FileEdit",
|
|
2123
2169
|
description: `Edit specific sections of a file by replacing text.
|
|
@@ -2146,6 +2192,27 @@ IMPORTANT:
|
|
|
2146
2192
|
}),
|
|
2147
2193
|
strict: true
|
|
2148
2194
|
};
|
|
2195
|
+
var multiEditTool = {
|
|
2196
|
+
name: "FileMultiEdit",
|
|
2197
|
+
description: `Apply multiple exact text replacements to one file in order.
|
|
2198
|
+
|
|
2199
|
+
Usage:
|
|
2200
|
+
- Use this when a task needs several related edits in the same file
|
|
2201
|
+
- Each edit is applied to the file content produced by the prior edit
|
|
2202
|
+
- The operation is atomic: if any edit fails, the file is left unchanged
|
|
2203
|
+
|
|
2204
|
+
IMPORTANT:
|
|
2205
|
+
- You must read the file first (in this session) before editing it
|
|
2206
|
+
- Each old_string must match exactly (whitespace-sensitive)
|
|
2207
|
+
- Each old_string must be unique unless that edit uses replace_all: true
|
|
2208
|
+
- old_string and new_string must be different for every edit
|
|
2209
|
+
`,
|
|
2210
|
+
schema: z14.z.object({
|
|
2211
|
+
file_path: z14.z.string().describe("The absolute virtual path to the file to modify"),
|
|
2212
|
+
edits: z14.z.array(textEditSchema).min(1).describe("Exact replacements to apply sequentially to the file")
|
|
2213
|
+
}),
|
|
2214
|
+
strict: true
|
|
2215
|
+
};
|
|
2149
2216
|
var taskCreateTool = {
|
|
2150
2217
|
name: "TaskCreate",
|
|
2151
2218
|
description: `Use this tool to create a structured task list. This helps you track progress, organize complex tasks, and demonstrate thoroughness to the user.
|
|
@@ -2216,7 +2283,7 @@ function createTaskCreateHandler(stateManager) {
|
|
|
2216
2283
|
};
|
|
2217
2284
|
stateManager.setTask(task);
|
|
2218
2285
|
return {
|
|
2219
|
-
toolResponse:
|
|
2286
|
+
toolResponse: `Task ${task.id} created`,
|
|
2220
2287
|
data: task
|
|
2221
2288
|
};
|
|
2222
2289
|
};
|
|
@@ -2315,7 +2382,7 @@ function createTaskUpdateHandler(stateManager) {
|
|
|
2315
2382
|
}
|
|
2316
2383
|
stateManager.setTask(task);
|
|
2317
2384
|
return {
|
|
2318
|
-
toolResponse:
|
|
2385
|
+
toolResponse: `Task ${task.id} updated`,
|
|
2319
2386
|
data: task
|
|
2320
2387
|
};
|
|
2321
2388
|
};
|
|
@@ -2424,6 +2491,7 @@ exports.hasDirectory = hasDirectory;
|
|
|
2424
2491
|
exports.hasFileWithMimeType = hasFileWithMimeType;
|
|
2425
2492
|
exports.hasNoOtherToolCalls = hasNoOtherToolCalls;
|
|
2426
2493
|
exports.isTerminalStatus = isTerminalStatus;
|
|
2494
|
+
exports.multiEditTool = multiEditTool;
|
|
2427
2495
|
exports.parseSkillFile = parseSkillFile;
|
|
2428
2496
|
exports.proxyRunAgent = proxyRunAgent;
|
|
2429
2497
|
exports.proxyVirtualFsOps = proxyVirtualFsOps;
|