zeitlich 0.2.19 → 0.2.20
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/adapters/sandbox/daytona/index.cjs +25 -10
- package/dist/adapters/sandbox/daytona/index.cjs.map +1 -1
- package/dist/adapters/sandbox/daytona/index.d.cts +4 -1
- package/dist/adapters/sandbox/daytona/index.d.ts +4 -1
- package/dist/adapters/sandbox/daytona/index.js +25 -10
- package/dist/adapters/sandbox/daytona/index.js.map +1 -1
- package/dist/adapters/sandbox/virtual/index.d.cts +4 -3
- package/dist/adapters/sandbox/virtual/index.d.ts +4 -3
- package/dist/adapters/thread/google-genai/index.cjs +0 -2
- package/dist/adapters/thread/google-genai/index.cjs.map +1 -1
- package/dist/adapters/thread/google-genai/index.d.cts +2 -2
- package/dist/adapters/thread/google-genai/index.d.ts +2 -2
- package/dist/adapters/thread/google-genai/index.js +0 -2
- package/dist/adapters/thread/google-genai/index.js.map +1 -1
- package/dist/adapters/thread/langchain/index.cjs +3 -1
- package/dist/adapters/thread/langchain/index.cjs.map +1 -1
- package/dist/adapters/thread/langchain/index.d.cts +3 -3
- package/dist/adapters/thread/langchain/index.d.ts +3 -3
- package/dist/adapters/thread/langchain/index.js +3 -1
- package/dist/adapters/thread/langchain/index.js.map +1 -1
- package/dist/index.cjs +145 -110
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -13
- package/dist/index.d.ts +13 -13
- package/dist/index.js +145 -110
- package/dist/index.js.map +1 -1
- package/dist/{queries-D8T4pEeu.d.ts → queries-KHj5Otv7.d.ts} +1 -1
- package/dist/{queries-D22uWTOb.d.cts → queries-nIdzTCDS.d.cts} +1 -1
- package/dist/{types-CxWLeJTB.d.ts → types-By80IE1x.d.ts} +3 -3
- package/dist/{types-DjT78Sdp.d.cts → types-Ct2igz9y.d.cts} +4 -2
- package/dist/{types-DjT78Sdp.d.ts → types-Ct2igz9y.d.ts} +4 -2
- package/dist/{types-CCfJb5Jl.d.cts → types-DZ7BkA3-.d.cts} +3 -3
- package/dist/workflow.cjs +62 -27
- package/dist/workflow.cjs.map +1 -1
- package/dist/workflow.d.cts +16 -12
- package/dist/workflow.d.ts +16 -12
- package/dist/workflow.js +62 -27
- package/dist/workflow.js.map +1 -1
- package/package.json +1 -1
- package/src/adapters/sandbox/daytona/filesystem.ts +21 -12
- package/src/adapters/sandbox/daytona/index.ts +24 -23
- package/src/adapters/thread/langchain/thread-manager.ts +11 -7
- package/src/lib/session/session-edge-cases.integration.test.ts +20 -2
- package/src/lib/session/session.integration.test.ts +16 -2
- package/src/lib/session/session.ts +2 -1
- package/src/lib/session/types.ts +2 -1
- package/src/lib/subagent/handler.ts +1 -1
- package/src/lib/subagent/subagent.integration.test.ts +5 -4
- package/src/lib/subagent/tool.ts +1 -1
- package/src/lib/thread/index.ts +0 -1
- package/src/lib/tool-router/router-edge-cases.integration.test.ts +8 -3
- package/src/lib/tool-router/router.integration.test.ts +8 -3
- package/src/lib/tool-router/router.ts +55 -27
- package/src/lib/tool-router/types.ts +12 -7
- package/src/lib/workflow.test.ts +18 -6
- package/src/lib/workflow.ts +13 -3
- package/src/tools/task-create/handler.ts +3 -6
- package/src/workflow.ts +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,26 +1,20 @@
|
|
|
1
1
|
import { BashArgs, FileEditArgs, GlobArgs, FileReadArgs, FileWriteArgs } from './workflow.cjs';
|
|
2
|
-
export { AskUserQuestionArgs, GrepArgs, ReadSkillArgs, SubagentArgs, TaskCreateArgs, TaskGetArgs, TaskListArgs, TaskUpdateArgs, WorkflowInput, WorkflowSessionInput, applyVirtualTreeMutations, askUserQuestionTool, bashTool, createAgentStateManager, createAskUserQuestionHandler, createBashToolDescription, createReadSkillHandler, createReadSkillTool, createSession, createTaskCreateHandler, createTaskGetHandler, createTaskListHandler, createTaskUpdateHandler, createToolRouter, defineSubagent, defineSubagentWorkflow, defineTool, defineWorkflow, editTool, formatVirtualFileTree, getShortId, globTool, grepTool, hasNoOtherToolCalls, parseSkillFile, proxyDefaultThreadOps, proxySandboxOps, readFileTool, taskCreateTool, taskGetTool, taskListTool, taskUpdateTool, writeFileTool } from './workflow.cjs';
|
|
3
|
-
import { S as SkillProvider, b as SkillMetadata, c as Skill } from './types-
|
|
4
|
-
export { A as AgentResponse, d as AgentState, e as AgentStateManager, H as Hooks, J as JsonPrimitive, f as JsonSerializable, g as JsonValue, M as ModelInvoker, a as ModelInvokerConfig, P as PostHumanMessageAppendHook, h as PostHumanMessageAppendHookContext, i as PreHumanMessageAppendHook, j as PreHumanMessageAppendHookContext, R as RunAgentActivity, k as SessionConfig, l as SessionEndHook, m as SessionEndHookContext, n as SessionStartHook, o as SessionStartHookContext, p as SubagentConfig, q as SubagentDefinition, r as SubagentHandlerResponse, s as SubagentHooks, t as SubagentSessionInput, u as SubagentWorkflow, v as SubagentWorkflowInput, T as ThreadOps, Z as ZeitlichSession } from './types-
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
export { l as AgentConfig, m as AgentFile, h as AgentStatus, n as AppendToolResultFn, C as ContentPart, I as InferToolResults, M as MessageContent, o as ParsedToolCall, p as ParsedToolCallUnion, q as PostToolUseFailureHook, r as PostToolUseFailureHookContext, d as PostToolUseFailureHookResult, s as PostToolUseHook, t as PostToolUseHookContext, u as PreToolUseHook, v as PreToolUseHookContext, P as PreToolUseHookResult, w as ProcessToolCallsContext, e as RawToolCall, x as SerializableToolDefinition, S as SessionExitReason, y as TaskStatus, f as TokenUsage, z as ToolArgs, D as ToolCallResult, k as ToolCallResultUnion, i as ToolDefinition, E as ToolHandler, F as ToolHooks, a as ToolMap, T as ToolMessageContent, G as ToolNames, H as ToolResult, J as ToolRouter, b as ToolRouterHooks, K as ToolWithHandler, W as WorkflowTask, L as isTerminalStatus } from './types-DjT78Sdp.cjs';
|
|
2
|
+
export { AskUserQuestionArgs, GrepArgs, ReadSkillArgs, SubagentArgs, TaskCreateArgs, TaskGetArgs, TaskListArgs, TaskUpdateArgs, WorkflowConfig, WorkflowInput, WorkflowSessionInput, applyVirtualTreeMutations, askUserQuestionTool, bashTool, createAgentStateManager, createAskUserQuestionHandler, createBashToolDescription, createReadSkillHandler, createReadSkillTool, createSession, createTaskCreateHandler, createTaskGetHandler, createTaskListHandler, createTaskUpdateHandler, createToolRouter, defineSubagent, defineSubagentWorkflow, defineTool, defineWorkflow, editTool, formatVirtualFileTree, getShortId, globTool, grepTool, hasNoOtherToolCalls, parseSkillFile, proxyDefaultThreadOps, proxySandboxOps, readFileTool, taskCreateTool, taskGetTool, taskListTool, taskUpdateTool, writeFileTool } from './workflow.cjs';
|
|
3
|
+
import { S as SkillProvider, b as SkillMetadata, c as Skill } from './types-DZ7BkA3-.cjs';
|
|
4
|
+
export { A as AgentResponse, d as AgentState, e as AgentStateManager, H as Hooks, J as JsonPrimitive, f as JsonSerializable, g as JsonValue, M as ModelInvoker, a as ModelInvokerConfig, P as PostHumanMessageAppendHook, h as PostHumanMessageAppendHookContext, i as PreHumanMessageAppendHook, j as PreHumanMessageAppendHookContext, R as RunAgentActivity, k as SessionConfig, l as SessionEndHook, m as SessionEndHookContext, n as SessionStartHook, o as SessionStartHookContext, p as SubagentConfig, q as SubagentDefinition, r as SubagentHandlerResponse, s as SubagentHooks, t as SubagentSessionInput, u as SubagentWorkflow, v as SubagentWorkflowInput, T as ThreadOps, Z as ZeitlichSession } from './types-DZ7BkA3-.cjs';
|
|
5
|
+
import { R as RouterContext, j as ToolResultConfig, A as ActivityToolHandler, c as ToolHandlerResponse, B as BaseAgentState, g as RunAgentConfig } from './types-Ct2igz9y.cjs';
|
|
6
|
+
export { l as AgentConfig, m as AgentFile, h as AgentStatus, n as AppendToolResultFn, C as ContentPart, I as InferToolResults, M as MessageContent, o as ParsedToolCall, p as ParsedToolCallUnion, q as PostToolUseFailureHook, r as PostToolUseFailureHookContext, d as PostToolUseFailureHookResult, s as PostToolUseHook, t as PostToolUseHookContext, u as PreToolUseHook, v as PreToolUseHookContext, P as PreToolUseHookResult, w as ProcessToolCallsContext, e as RawToolCall, x as SerializableToolDefinition, S as SessionExitReason, y as TaskStatus, f as TokenUsage, z as ToolArgs, D as ToolCallResult, k as ToolCallResultUnion, i as ToolDefinition, E as ToolHandler, F as ToolHooks, a as ToolMap, T as ToolMessageContent, G as ToolNames, H as ToolResult, J as ToolRouter, b as ToolRouterHooks, K as ToolWithHandler, W as WorkflowTask, L as isTerminalStatus } from './types-Ct2igz9y.cjs';
|
|
8
7
|
import { S as Sandbox, a as SandboxFileSystem, d as SandboxCreateOptions, b as SandboxProvider, f as SandboxSnapshot, g as SandboxOps, E as ExecResult } from './types-BMRzfELQ.cjs';
|
|
9
8
|
export { h as ExecOptions, c as SandboxCapabilities, e as SandboxCreateResult, D as SandboxDirentEntry, F as SandboxFileStat, i as SandboxNotFoundError, j as SandboxNotSupportedError } from './types-BMRzfELQ.cjs';
|
|
10
9
|
import { WorkflowClient } from '@temporalio/client';
|
|
11
|
-
export { c as FileEntry, F as FileEntryMetadata, a as FileResolver, T as TreeMutation, f as VirtualFileTree, h as VirtualSandboxState, i as filesWithMimeType, j as hasDirectory, k as hasFileWithMimeType } from './queries-
|
|
10
|
+
export { c as FileEntry, F as FileEntryMetadata, a as FileResolver, T as TreeMutation, f as VirtualFileTree, h as VirtualSandboxState, i as filesWithMimeType, j as hasDirectory, k as hasFileWithMimeType } from './queries-nIdzTCDS.cjs';
|
|
11
|
+
import { T as ThreadManagerConfig, B as BaseThreadManager } from './types-35POpVfa.cjs';
|
|
12
12
|
import '@temporalio/workflow';
|
|
13
13
|
import 'zod';
|
|
14
14
|
import '@temporalio/common';
|
|
15
15
|
import '@temporalio/common/lib/interfaces';
|
|
16
16
|
import 'ioredis';
|
|
17
17
|
|
|
18
|
-
/**
|
|
19
|
-
* Creates a generic thread manager for handling conversation state in Redis.
|
|
20
|
-
* Framework-agnostic — works with any serializable message type.
|
|
21
|
-
*/
|
|
22
|
-
declare function createThreadManager<T>(config: ThreadManagerConfig<T>): BaseThreadManager<T>;
|
|
23
|
-
|
|
24
18
|
/**
|
|
25
19
|
* Wraps a tool handler to automatically append its result directly to the
|
|
26
20
|
* thread and sets `resultAppended: true` on the response.
|
|
@@ -183,6 +177,12 @@ declare class FileSystemSkillProvider implements SkillProvider {
|
|
|
183
177
|
private discoverSkillDirs;
|
|
184
178
|
}
|
|
185
179
|
|
|
180
|
+
/**
|
|
181
|
+
* Creates a generic thread manager for handling conversation state in Redis.
|
|
182
|
+
* Framework-agnostic — works with any serializable message type.
|
|
183
|
+
*/
|
|
184
|
+
declare function createThreadManager<T>(config: ThreadManagerConfig<T>): BaseThreadManager<T>;
|
|
185
|
+
|
|
186
186
|
/**
|
|
187
187
|
* Stateless facade over a {@link SandboxProvider}.
|
|
188
188
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -1,26 +1,20 @@
|
|
|
1
1
|
import { BashArgs, FileEditArgs, GlobArgs, FileReadArgs, FileWriteArgs } from './workflow.js';
|
|
2
|
-
export { AskUserQuestionArgs, GrepArgs, ReadSkillArgs, SubagentArgs, TaskCreateArgs, TaskGetArgs, TaskListArgs, TaskUpdateArgs, WorkflowInput, WorkflowSessionInput, applyVirtualTreeMutations, askUserQuestionTool, bashTool, createAgentStateManager, createAskUserQuestionHandler, createBashToolDescription, createReadSkillHandler, createReadSkillTool, createSession, createTaskCreateHandler, createTaskGetHandler, createTaskListHandler, createTaskUpdateHandler, createToolRouter, defineSubagent, defineSubagentWorkflow, defineTool, defineWorkflow, editTool, formatVirtualFileTree, getShortId, globTool, grepTool, hasNoOtherToolCalls, parseSkillFile, proxyDefaultThreadOps, proxySandboxOps, readFileTool, taskCreateTool, taskGetTool, taskListTool, taskUpdateTool, writeFileTool } from './workflow.js';
|
|
3
|
-
import { S as SkillProvider, b as SkillMetadata, c as Skill } from './types-
|
|
4
|
-
export { A as AgentResponse, d as AgentState, e as AgentStateManager, H as Hooks, J as JsonPrimitive, f as JsonSerializable, g as JsonValue, M as ModelInvoker, a as ModelInvokerConfig, P as PostHumanMessageAppendHook, h as PostHumanMessageAppendHookContext, i as PreHumanMessageAppendHook, j as PreHumanMessageAppendHookContext, R as RunAgentActivity, k as SessionConfig, l as SessionEndHook, m as SessionEndHookContext, n as SessionStartHook, o as SessionStartHookContext, p as SubagentConfig, q as SubagentDefinition, r as SubagentHandlerResponse, s as SubagentHooks, t as SubagentSessionInput, u as SubagentWorkflow, v as SubagentWorkflowInput, T as ThreadOps, Z as ZeitlichSession } from './types-
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
export { l as AgentConfig, m as AgentFile, h as AgentStatus, n as AppendToolResultFn, C as ContentPart, I as InferToolResults, M as MessageContent, o as ParsedToolCall, p as ParsedToolCallUnion, q as PostToolUseFailureHook, r as PostToolUseFailureHookContext, d as PostToolUseFailureHookResult, s as PostToolUseHook, t as PostToolUseHookContext, u as PreToolUseHook, v as PreToolUseHookContext, P as PreToolUseHookResult, w as ProcessToolCallsContext, e as RawToolCall, x as SerializableToolDefinition, S as SessionExitReason, y as TaskStatus, f as TokenUsage, z as ToolArgs, D as ToolCallResult, k as ToolCallResultUnion, i as ToolDefinition, E as ToolHandler, F as ToolHooks, a as ToolMap, T as ToolMessageContent, G as ToolNames, H as ToolResult, J as ToolRouter, b as ToolRouterHooks, K as ToolWithHandler, W as WorkflowTask, L as isTerminalStatus } from './types-DjT78Sdp.js';
|
|
2
|
+
export { AskUserQuestionArgs, GrepArgs, ReadSkillArgs, SubagentArgs, TaskCreateArgs, TaskGetArgs, TaskListArgs, TaskUpdateArgs, WorkflowConfig, WorkflowInput, WorkflowSessionInput, applyVirtualTreeMutations, askUserQuestionTool, bashTool, createAgentStateManager, createAskUserQuestionHandler, createBashToolDescription, createReadSkillHandler, createReadSkillTool, createSession, createTaskCreateHandler, createTaskGetHandler, createTaskListHandler, createTaskUpdateHandler, createToolRouter, defineSubagent, defineSubagentWorkflow, defineTool, defineWorkflow, editTool, formatVirtualFileTree, getShortId, globTool, grepTool, hasNoOtherToolCalls, parseSkillFile, proxyDefaultThreadOps, proxySandboxOps, readFileTool, taskCreateTool, taskGetTool, taskListTool, taskUpdateTool, writeFileTool } from './workflow.js';
|
|
3
|
+
import { S as SkillProvider, b as SkillMetadata, c as Skill } from './types-By80IE1x.js';
|
|
4
|
+
export { A as AgentResponse, d as AgentState, e as AgentStateManager, H as Hooks, J as JsonPrimitive, f as JsonSerializable, g as JsonValue, M as ModelInvoker, a as ModelInvokerConfig, P as PostHumanMessageAppendHook, h as PostHumanMessageAppendHookContext, i as PreHumanMessageAppendHook, j as PreHumanMessageAppendHookContext, R as RunAgentActivity, k as SessionConfig, l as SessionEndHook, m as SessionEndHookContext, n as SessionStartHook, o as SessionStartHookContext, p as SubagentConfig, q as SubagentDefinition, r as SubagentHandlerResponse, s as SubagentHooks, t as SubagentSessionInput, u as SubagentWorkflow, v as SubagentWorkflowInput, T as ThreadOps, Z as ZeitlichSession } from './types-By80IE1x.js';
|
|
5
|
+
import { R as RouterContext, j as ToolResultConfig, A as ActivityToolHandler, c as ToolHandlerResponse, B as BaseAgentState, g as RunAgentConfig } from './types-Ct2igz9y.js';
|
|
6
|
+
export { l as AgentConfig, m as AgentFile, h as AgentStatus, n as AppendToolResultFn, C as ContentPart, I as InferToolResults, M as MessageContent, o as ParsedToolCall, p as ParsedToolCallUnion, q as PostToolUseFailureHook, r as PostToolUseFailureHookContext, d as PostToolUseFailureHookResult, s as PostToolUseHook, t as PostToolUseHookContext, u as PreToolUseHook, v as PreToolUseHookContext, P as PreToolUseHookResult, w as ProcessToolCallsContext, e as RawToolCall, x as SerializableToolDefinition, S as SessionExitReason, y as TaskStatus, f as TokenUsage, z as ToolArgs, D as ToolCallResult, k as ToolCallResultUnion, i as ToolDefinition, E as ToolHandler, F as ToolHooks, a as ToolMap, T as ToolMessageContent, G as ToolNames, H as ToolResult, J as ToolRouter, b as ToolRouterHooks, K as ToolWithHandler, W as WorkflowTask, L as isTerminalStatus } from './types-Ct2igz9y.js';
|
|
8
7
|
import { S as Sandbox, a as SandboxFileSystem, d as SandboxCreateOptions, b as SandboxProvider, f as SandboxSnapshot, g as SandboxOps, E as ExecResult } from './types-BMRzfELQ.js';
|
|
9
8
|
export { h as ExecOptions, c as SandboxCapabilities, e as SandboxCreateResult, D as SandboxDirentEntry, F as SandboxFileStat, i as SandboxNotFoundError, j as SandboxNotSupportedError } from './types-BMRzfELQ.js';
|
|
10
9
|
import { WorkflowClient } from '@temporalio/client';
|
|
11
|
-
export { c as FileEntry, F as FileEntryMetadata, a as FileResolver, T as TreeMutation, f as VirtualFileTree, h as VirtualSandboxState, i as filesWithMimeType, j as hasDirectory, k as hasFileWithMimeType } from './queries-
|
|
10
|
+
export { c as FileEntry, F as FileEntryMetadata, a as FileResolver, T as TreeMutation, f as VirtualFileTree, h as VirtualSandboxState, i as filesWithMimeType, j as hasDirectory, k as hasFileWithMimeType } from './queries-KHj5Otv7.js';
|
|
11
|
+
import { T as ThreadManagerConfig, B as BaseThreadManager } from './types-35POpVfa.js';
|
|
12
12
|
import '@temporalio/workflow';
|
|
13
13
|
import 'zod';
|
|
14
14
|
import '@temporalio/common';
|
|
15
15
|
import '@temporalio/common/lib/interfaces';
|
|
16
16
|
import 'ioredis';
|
|
17
17
|
|
|
18
|
-
/**
|
|
19
|
-
* Creates a generic thread manager for handling conversation state in Redis.
|
|
20
|
-
* Framework-agnostic — works with any serializable message type.
|
|
21
|
-
*/
|
|
22
|
-
declare function createThreadManager<T>(config: ThreadManagerConfig<T>): BaseThreadManager<T>;
|
|
23
|
-
|
|
24
18
|
/**
|
|
25
19
|
* Wraps a tool handler to automatically append its result directly to the
|
|
26
20
|
* thread and sets `resultAppended: true` on the response.
|
|
@@ -183,6 +177,12 @@ declare class FileSystemSkillProvider implements SkillProvider {
|
|
|
183
177
|
private discoverSkillDirs;
|
|
184
178
|
}
|
|
185
179
|
|
|
180
|
+
/**
|
|
181
|
+
* Creates a generic thread manager for handling conversation state in Redis.
|
|
182
|
+
* Framework-agnostic — works with any serializable message type.
|
|
183
|
+
*/
|
|
184
|
+
declare function createThreadManager<T>(config: ThreadManagerConfig<T>): BaseThreadManager<T>;
|
|
185
|
+
|
|
186
186
|
/**
|
|
187
187
|
* Stateless facade over a {@link SandboxProvider}.
|
|
188
188
|
*
|
package/dist/index.js
CHANGED
|
@@ -53,7 +53,10 @@ function createToolRouter(options) {
|
|
|
53
53
|
turn
|
|
54
54
|
});
|
|
55
55
|
if (r?.fallbackContent !== void 0)
|
|
56
|
-
return {
|
|
56
|
+
return {
|
|
57
|
+
content: r.fallbackContent,
|
|
58
|
+
result: { error: errorStr, recovered: true }
|
|
59
|
+
};
|
|
57
60
|
if (r?.suppress)
|
|
58
61
|
return {
|
|
59
62
|
content: JSON.stringify({ error: errorStr, suppressed: true }),
|
|
@@ -68,7 +71,10 @@ function createToolRouter(options) {
|
|
|
68
71
|
turn
|
|
69
72
|
});
|
|
70
73
|
if (r?.fallbackContent !== void 0)
|
|
71
|
-
return {
|
|
74
|
+
return {
|
|
75
|
+
content: r.fallbackContent,
|
|
76
|
+
result: { error: errorStr, recovered: true }
|
|
77
|
+
};
|
|
72
78
|
if (r?.suppress)
|
|
73
79
|
return {
|
|
74
80
|
content: JSON.stringify({ error: errorStr, suppressed: true }),
|
|
@@ -106,7 +112,10 @@ function createToolRouter(options) {
|
|
|
106
112
|
threadId: options.threadId,
|
|
107
113
|
toolCallId: toolCall.id,
|
|
108
114
|
toolName: toolCall.name,
|
|
109
|
-
content: JSON.stringify({
|
|
115
|
+
content: JSON.stringify({
|
|
116
|
+
skipped: true,
|
|
117
|
+
reason: "Skipped by PreToolUse hook"
|
|
118
|
+
})
|
|
110
119
|
});
|
|
111
120
|
return null;
|
|
112
121
|
}
|
|
@@ -134,24 +143,43 @@ function createToolRouter(options) {
|
|
|
134
143
|
content = JSON.stringify(result, null, 2);
|
|
135
144
|
}
|
|
136
145
|
} catch (error) {
|
|
137
|
-
const recovery = await runFailureHooks(
|
|
146
|
+
const recovery = await runFailureHooks(
|
|
147
|
+
toolCall,
|
|
148
|
+
tool,
|
|
149
|
+
error,
|
|
150
|
+
effectiveArgs,
|
|
151
|
+
turn
|
|
152
|
+
);
|
|
138
153
|
result = recovery.result;
|
|
139
154
|
content = recovery.content;
|
|
140
155
|
}
|
|
141
156
|
if (!resultAppended) {
|
|
142
|
-
|
|
157
|
+
const config = {
|
|
143
158
|
threadId: options.threadId,
|
|
144
159
|
toolCallId: toolCall.id,
|
|
145
160
|
toolName: toolCall.name,
|
|
146
161
|
content
|
|
147
|
-
}
|
|
162
|
+
};
|
|
163
|
+
await appendToolResult.executeWithOptions(
|
|
164
|
+
{
|
|
165
|
+
summary: `Append ${toolCall.name} result`
|
|
166
|
+
},
|
|
167
|
+
[config]
|
|
168
|
+
);
|
|
148
169
|
}
|
|
149
170
|
const toolResult = {
|
|
150
171
|
toolCallId: toolCall.id,
|
|
151
172
|
name: toolCall.name,
|
|
152
173
|
data: result
|
|
153
174
|
};
|
|
154
|
-
await runPostHooks(
|
|
175
|
+
await runPostHooks(
|
|
176
|
+
toolCall,
|
|
177
|
+
tool,
|
|
178
|
+
toolResult,
|
|
179
|
+
effectiveArgs,
|
|
180
|
+
turn,
|
|
181
|
+
Date.now() - startTime
|
|
182
|
+
);
|
|
155
183
|
return toolResult;
|
|
156
184
|
}
|
|
157
185
|
return {
|
|
@@ -194,9 +222,7 @@ function createToolRouter(options) {
|
|
|
194
222
|
const sandboxId = context?.sandboxId;
|
|
195
223
|
if (options.parallel) {
|
|
196
224
|
const results2 = await Promise.all(
|
|
197
|
-
toolCalls.map(
|
|
198
|
-
(tc) => processToolCall(tc, turn, sandboxId)
|
|
199
|
-
)
|
|
225
|
+
toolCalls.map((tc) => processToolCall(tc, turn, sandboxId))
|
|
200
226
|
);
|
|
201
227
|
return results2.filter(
|
|
202
228
|
(r) => r !== null
|
|
@@ -204,11 +230,7 @@ function createToolRouter(options) {
|
|
|
204
230
|
}
|
|
205
231
|
const results = [];
|
|
206
232
|
for (const toolCall of toolCalls) {
|
|
207
|
-
const result = await processToolCall(
|
|
208
|
-
toolCall,
|
|
209
|
-
turn,
|
|
210
|
-
sandboxId
|
|
211
|
-
);
|
|
233
|
+
const result = await processToolCall(toolCall, turn, sandboxId);
|
|
212
234
|
if (result !== null) {
|
|
213
235
|
results.push(result);
|
|
214
236
|
}
|
|
@@ -225,19 +247,28 @@ function createToolRouter(options) {
|
|
|
225
247
|
threadId: options.threadId,
|
|
226
248
|
toolCallId: toolCall.id,
|
|
227
249
|
toolName: toolCall.name,
|
|
228
|
-
...context?.sandboxId !== void 0 && {
|
|
250
|
+
...context?.sandboxId !== void 0 && {
|
|
251
|
+
sandboxId: context.sandboxId
|
|
252
|
+
}
|
|
229
253
|
};
|
|
230
254
|
const response = await handler(
|
|
231
255
|
toolCall.args,
|
|
232
256
|
routerContext
|
|
233
257
|
);
|
|
234
258
|
if (!response.resultAppended) {
|
|
235
|
-
await appendToolResult(
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
259
|
+
await appendToolResult.executeWithOptions(
|
|
260
|
+
{
|
|
261
|
+
summary: `Append ${toolCall.name} result`
|
|
262
|
+
},
|
|
263
|
+
[
|
|
264
|
+
{
|
|
265
|
+
threadId: options.threadId,
|
|
266
|
+
toolCallId: toolCall.id,
|
|
267
|
+
toolName: toolCall.name,
|
|
268
|
+
content: response.toolResponse
|
|
269
|
+
}
|
|
270
|
+
]
|
|
271
|
+
);
|
|
241
272
|
}
|
|
242
273
|
return {
|
|
243
274
|
toolCallId: toolCall.id,
|
|
@@ -312,7 +343,7 @@ function createSubagentTool(subagents) {
|
|
|
312
343
|
const schema = hasThreadContinuation ? z14.object({
|
|
313
344
|
...baseFields,
|
|
314
345
|
threadId: z14.string().nullable().describe(
|
|
315
|
-
"Thread ID to continue an existing conversation, or null to start a new one"
|
|
346
|
+
"Thread ID to continue an existing conversation from the same subagent, or null to start a new one"
|
|
316
347
|
)
|
|
317
348
|
}) : z14.object(baseFields);
|
|
318
349
|
return {
|
|
@@ -369,7 +400,7 @@ function createSubagentHandler(subagents) {
|
|
|
369
400
|
if (config.allowThreadContinuation && childThreadId) {
|
|
370
401
|
finalToolResponse = typeof toolResponse === "string" ? `${toolResponse}
|
|
371
402
|
|
|
372
|
-
[Thread ID: ${childThreadId}]` : toolResponse;
|
|
403
|
+
[${config.agentName} Thread ID: ${childThreadId}]` : toolResponse;
|
|
373
404
|
}
|
|
374
405
|
return {
|
|
375
406
|
toolResponse: finalToolResponse,
|
|
@@ -692,8 +723,8 @@ function proxySandboxOps(options) {
|
|
|
692
723
|
}
|
|
693
724
|
|
|
694
725
|
// src/lib/workflow.ts
|
|
695
|
-
function defineWorkflow(fn) {
|
|
696
|
-
|
|
726
|
+
function defineWorkflow(config, fn) {
|
|
727
|
+
const workflow = async (input, workflowInput = {}) => {
|
|
697
728
|
const sessionInput = {
|
|
698
729
|
...workflowInput.previousThreadId && {
|
|
699
730
|
threadId: workflowInput.previousThreadId,
|
|
@@ -703,89 +734,8 @@ function defineWorkflow(fn) {
|
|
|
703
734
|
};
|
|
704
735
|
return fn(input, sessionInput);
|
|
705
736
|
};
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
// src/lib/thread/manager.ts
|
|
709
|
-
var THREAD_TTL_SECONDS = 60 * 60 * 24 * 90;
|
|
710
|
-
var APPEND_IDEMPOTENT_SCRIPT = `
|
|
711
|
-
if redis.call('EXISTS', KEYS[1]) == 1 then
|
|
712
|
-
return 0
|
|
713
|
-
end
|
|
714
|
-
for i = 2, #ARGV do
|
|
715
|
-
redis.call('RPUSH', KEYS[2], ARGV[i])
|
|
716
|
-
end
|
|
717
|
-
redis.call('EXPIRE', KEYS[2], tonumber(ARGV[1]))
|
|
718
|
-
redis.call('SET', KEYS[1], '1', 'EX', tonumber(ARGV[1]))
|
|
719
|
-
return 1
|
|
720
|
-
`;
|
|
721
|
-
function getThreadKey(threadId, key) {
|
|
722
|
-
return `thread:${threadId}:${key}`;
|
|
723
|
-
}
|
|
724
|
-
function createThreadManager(config) {
|
|
725
|
-
const {
|
|
726
|
-
redis,
|
|
727
|
-
threadId,
|
|
728
|
-
key = "messages",
|
|
729
|
-
serialize = (m) => JSON.stringify(m),
|
|
730
|
-
deserialize = (raw) => JSON.parse(raw),
|
|
731
|
-
idOf
|
|
732
|
-
} = config;
|
|
733
|
-
const redisKey = getThreadKey(threadId, key);
|
|
734
|
-
const metaKey = getThreadKey(threadId, `${key}:meta`);
|
|
735
|
-
async function assertThreadExists() {
|
|
736
|
-
const exists = await redis.exists(metaKey);
|
|
737
|
-
if (!exists) {
|
|
738
|
-
throw new Error(`Thread "${threadId}" (key: ${key}) does not exist`);
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
return {
|
|
742
|
-
async initialize() {
|
|
743
|
-
await redis.del(redisKey);
|
|
744
|
-
await redis.set(metaKey, "1", "EX", THREAD_TTL_SECONDS);
|
|
745
|
-
},
|
|
746
|
-
async load() {
|
|
747
|
-
await assertThreadExists();
|
|
748
|
-
const data = await redis.lrange(redisKey, 0, -1);
|
|
749
|
-
return data.map(deserialize);
|
|
750
|
-
},
|
|
751
|
-
async append(messages) {
|
|
752
|
-
if (messages.length === 0) return;
|
|
753
|
-
await assertThreadExists();
|
|
754
|
-
if (idOf) {
|
|
755
|
-
const dedupId = messages.map(idOf).join(":");
|
|
756
|
-
const dedupKey = getThreadKey(threadId, `dedup:${dedupId}`);
|
|
757
|
-
await redis.eval(
|
|
758
|
-
APPEND_IDEMPOTENT_SCRIPT,
|
|
759
|
-
2,
|
|
760
|
-
dedupKey,
|
|
761
|
-
redisKey,
|
|
762
|
-
String(THREAD_TTL_SECONDS),
|
|
763
|
-
...messages.map(serialize)
|
|
764
|
-
);
|
|
765
|
-
} else {
|
|
766
|
-
await redis.rpush(redisKey, ...messages.map(serialize));
|
|
767
|
-
await redis.expire(redisKey, THREAD_TTL_SECONDS);
|
|
768
|
-
}
|
|
769
|
-
},
|
|
770
|
-
async fork(newThreadId) {
|
|
771
|
-
await assertThreadExists();
|
|
772
|
-
const data = await redis.lrange(redisKey, 0, -1);
|
|
773
|
-
const forked = createThreadManager({
|
|
774
|
-
...config,
|
|
775
|
-
threadId: newThreadId
|
|
776
|
-
});
|
|
777
|
-
await forked.initialize();
|
|
778
|
-
if (data.length > 0) {
|
|
779
|
-
const newKey = getThreadKey(newThreadId, key);
|
|
780
|
-
await redis.rpush(newKey, ...data);
|
|
781
|
-
await redis.expire(newKey, THREAD_TTL_SECONDS);
|
|
782
|
-
}
|
|
783
|
-
return forked;
|
|
784
|
-
},
|
|
785
|
-
async delete() {
|
|
786
|
-
await redis.del(redisKey, metaKey);
|
|
787
|
-
}
|
|
788
|
-
};
|
|
737
|
+
Object.defineProperty(workflow, "name", { value: config.name });
|
|
738
|
+
return workflow;
|
|
789
739
|
}
|
|
790
740
|
|
|
791
741
|
// src/lib/types.ts
|
|
@@ -1384,10 +1334,12 @@ var taskCreateTool = {
|
|
|
1384
1334
|
metadata: z14.record(z14.string(), z14.string()).describe("Arbitrary key-value pairs for tracking")
|
|
1385
1335
|
})
|
|
1386
1336
|
};
|
|
1337
|
+
|
|
1338
|
+
// src/tools/task-create/handler.ts
|
|
1387
1339
|
function createTaskCreateHandler(stateManager) {
|
|
1388
1340
|
return (args) => {
|
|
1389
1341
|
const task = {
|
|
1390
|
-
id:
|
|
1342
|
+
id: getShortId(),
|
|
1391
1343
|
subject: args.subject,
|
|
1392
1344
|
description: args.description,
|
|
1393
1345
|
activeForm: args.activeForm,
|
|
@@ -1619,6 +1571,89 @@ var FileSystemSkillProvider = class {
|
|
|
1619
1571
|
return dirs;
|
|
1620
1572
|
}
|
|
1621
1573
|
};
|
|
1574
|
+
|
|
1575
|
+
// src/lib/thread/manager.ts
|
|
1576
|
+
var THREAD_TTL_SECONDS = 60 * 60 * 24 * 90;
|
|
1577
|
+
var APPEND_IDEMPOTENT_SCRIPT = `
|
|
1578
|
+
if redis.call('EXISTS', KEYS[1]) == 1 then
|
|
1579
|
+
return 0
|
|
1580
|
+
end
|
|
1581
|
+
for i = 2, #ARGV do
|
|
1582
|
+
redis.call('RPUSH', KEYS[2], ARGV[i])
|
|
1583
|
+
end
|
|
1584
|
+
redis.call('EXPIRE', KEYS[2], tonumber(ARGV[1]))
|
|
1585
|
+
redis.call('SET', KEYS[1], '1', 'EX', tonumber(ARGV[1]))
|
|
1586
|
+
return 1
|
|
1587
|
+
`;
|
|
1588
|
+
function getThreadKey(threadId, key) {
|
|
1589
|
+
return `thread:${threadId}:${key}`;
|
|
1590
|
+
}
|
|
1591
|
+
function createThreadManager(config) {
|
|
1592
|
+
const {
|
|
1593
|
+
redis,
|
|
1594
|
+
threadId,
|
|
1595
|
+
key = "messages",
|
|
1596
|
+
serialize = (m) => JSON.stringify(m),
|
|
1597
|
+
deserialize = (raw) => JSON.parse(raw),
|
|
1598
|
+
idOf
|
|
1599
|
+
} = config;
|
|
1600
|
+
const redisKey = getThreadKey(threadId, key);
|
|
1601
|
+
const metaKey = getThreadKey(threadId, `${key}:meta`);
|
|
1602
|
+
async function assertThreadExists() {
|
|
1603
|
+
const exists = await redis.exists(metaKey);
|
|
1604
|
+
if (!exists) {
|
|
1605
|
+
throw new Error(`Thread "${threadId}" (key: ${key}) does not exist`);
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
return {
|
|
1609
|
+
async initialize() {
|
|
1610
|
+
await redis.del(redisKey);
|
|
1611
|
+
await redis.set(metaKey, "1", "EX", THREAD_TTL_SECONDS);
|
|
1612
|
+
},
|
|
1613
|
+
async load() {
|
|
1614
|
+
await assertThreadExists();
|
|
1615
|
+
const data = await redis.lrange(redisKey, 0, -1);
|
|
1616
|
+
return data.map(deserialize);
|
|
1617
|
+
},
|
|
1618
|
+
async append(messages) {
|
|
1619
|
+
if (messages.length === 0) return;
|
|
1620
|
+
await assertThreadExists();
|
|
1621
|
+
if (idOf) {
|
|
1622
|
+
const dedupId = messages.map(idOf).join(":");
|
|
1623
|
+
const dedupKey = getThreadKey(threadId, `dedup:${dedupId}`);
|
|
1624
|
+
await redis.eval(
|
|
1625
|
+
APPEND_IDEMPOTENT_SCRIPT,
|
|
1626
|
+
2,
|
|
1627
|
+
dedupKey,
|
|
1628
|
+
redisKey,
|
|
1629
|
+
String(THREAD_TTL_SECONDS),
|
|
1630
|
+
...messages.map(serialize)
|
|
1631
|
+
);
|
|
1632
|
+
} else {
|
|
1633
|
+
await redis.rpush(redisKey, ...messages.map(serialize));
|
|
1634
|
+
await redis.expire(redisKey, THREAD_TTL_SECONDS);
|
|
1635
|
+
}
|
|
1636
|
+
},
|
|
1637
|
+
async fork(newThreadId) {
|
|
1638
|
+
await assertThreadExists();
|
|
1639
|
+
const data = await redis.lrange(redisKey, 0, -1);
|
|
1640
|
+
const forked = createThreadManager({
|
|
1641
|
+
...config,
|
|
1642
|
+
threadId: newThreadId
|
|
1643
|
+
});
|
|
1644
|
+
await forked.initialize();
|
|
1645
|
+
if (data.length > 0) {
|
|
1646
|
+
const newKey = getThreadKey(newThreadId, key);
|
|
1647
|
+
await redis.rpush(newKey, ...data);
|
|
1648
|
+
await redis.expire(newKey, THREAD_TTL_SECONDS);
|
|
1649
|
+
}
|
|
1650
|
+
return forked;
|
|
1651
|
+
},
|
|
1652
|
+
async delete() {
|
|
1653
|
+
await redis.del(redisKey, metaKey);
|
|
1654
|
+
}
|
|
1655
|
+
};
|
|
1656
|
+
}
|
|
1622
1657
|
async function queryParentWorkflowState(client) {
|
|
1623
1658
|
const { workflowExecution } = Context.current().info;
|
|
1624
1659
|
const handle = client.getHandle(
|