zeitlich 0.2.1 → 0.2.2
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 +2 -2
- package/dist/index.cjs +240 -124
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -6
- package/dist/index.d.ts +8 -6
- package/dist/index.js +216 -104
- package/dist/index.js.map +1 -1
- package/dist/{workflow-CCoHnc3B.d.cts → workflow-BQf5EfNN.d.cts} +232 -53
- package/dist/{workflow-CCoHnc3B.d.ts → workflow-BQf5EfNN.d.ts} +232 -53
- package/dist/workflow.cjs +219 -105
- package/dist/workflow.cjs.map +1 -1
- package/dist/workflow.d.cts +4 -2
- package/dist/workflow.d.ts +4 -2
- package/dist/workflow.js +196 -84
- package/dist/workflow.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +3 -0
- package/src/lib/session.ts +50 -24
- package/src/lib/state-manager.ts +9 -2
- package/src/lib/tool-router.ts +205 -23
- package/src/lib/types.ts +79 -4
- package/src/tools/ask-user-question/handler.ts +1 -1
- package/src/tools/bash/bash.test.ts +31 -31
- package/src/tools/bash/handler.ts +4 -4
- package/src/tools/edit/handler.ts +14 -14
- package/src/tools/glob/handler.ts +4 -4
- package/src/tools/task/handler.ts +17 -7
- package/src/tools/task/tool.ts +1 -1
- package/src/tools/task-create/handler.ts +7 -10
- package/src/tools/task-get/handler.ts +4 -4
- package/src/tools/task-list/handler.ts +2 -2
- package/src/tools/task-update/handler.ts +4 -4
- package/src/workflow.ts +3 -1
|
@@ -14,8 +14,8 @@ export interface EditResult {
|
|
|
14
14
|
* Edit handler response
|
|
15
15
|
*/
|
|
16
16
|
export interface EditHandlerResponse {
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
toolResponse: string;
|
|
18
|
+
data: EditResult;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/**
|
|
@@ -55,8 +55,8 @@ export async function editHandler(
|
|
|
55
55
|
// Validate old_string !== new_string
|
|
56
56
|
if (old_string === new_string) {
|
|
57
57
|
return {
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
toolResponse: `Error: old_string and new_string must be different.`,
|
|
59
|
+
data: {
|
|
60
60
|
path: file_path,
|
|
61
61
|
success: false,
|
|
62
62
|
replacements: 0,
|
|
@@ -69,8 +69,8 @@ export async function editHandler(
|
|
|
69
69
|
const exists = await fs.exists(file_path);
|
|
70
70
|
if (!exists) {
|
|
71
71
|
return {
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
toolResponse: `Error: File "${file_path}" does not exist.`,
|
|
73
|
+
data: {
|
|
74
74
|
path: file_path,
|
|
75
75
|
success: false,
|
|
76
76
|
replacements: 0,
|
|
@@ -84,8 +84,8 @@ export async function editHandler(
|
|
|
84
84
|
// Check if old_string exists in the file
|
|
85
85
|
if (!content.includes(old_string)) {
|
|
86
86
|
return {
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
toolResponse: `Error: Could not find the specified text in "${file_path}". Make sure old_string matches exactly (whitespace-sensitive).`,
|
|
88
|
+
data: {
|
|
89
89
|
path: file_path,
|
|
90
90
|
success: false,
|
|
91
91
|
replacements: 0,
|
|
@@ -101,8 +101,8 @@ export async function editHandler(
|
|
|
101
101
|
// Check uniqueness if not replace_all
|
|
102
102
|
if (!replace_all && occurrences > 1) {
|
|
103
103
|
return {
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
toolResponse: `Error: old_string appears ${occurrences} times in "${file_path}". Either provide more context to make it unique, or use replace_all: true.`,
|
|
105
|
+
data: {
|
|
106
106
|
path: file_path,
|
|
107
107
|
success: false,
|
|
108
108
|
replacements: 0,
|
|
@@ -135,8 +135,8 @@ export async function editHandler(
|
|
|
135
135
|
: `Replaced 1 occurrence`;
|
|
136
136
|
|
|
137
137
|
return {
|
|
138
|
-
|
|
139
|
-
|
|
138
|
+
toolResponse: `${summary} in ${file_path}`,
|
|
139
|
+
data: {
|
|
140
140
|
path: file_path,
|
|
141
141
|
success: true,
|
|
142
142
|
replacements,
|
|
@@ -145,8 +145,8 @@ export async function editHandler(
|
|
|
145
145
|
} catch (error) {
|
|
146
146
|
const message = error instanceof Error ? error.message : "Unknown error";
|
|
147
147
|
return {
|
|
148
|
-
|
|
149
|
-
|
|
148
|
+
toolResponse: `Error editing file "${file_path}": ${message}`,
|
|
149
|
+
data: {
|
|
150
150
|
path: file_path,
|
|
151
151
|
success: false,
|
|
152
152
|
replacements: 0,
|
|
@@ -13,8 +13,8 @@ export interface GlobResult {
|
|
|
13
13
|
* Glob handler response
|
|
14
14
|
*/
|
|
15
15
|
export interface GlobHandlerResponse {
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
toolResponse: string;
|
|
17
|
+
data: GlobResult;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
/**
|
|
@@ -31,8 +31,8 @@ export async function globHandler(
|
|
|
31
31
|
const _bash = new Bash({ fs });
|
|
32
32
|
|
|
33
33
|
return Promise.resolve({
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
toolResponse: "Hello, world!",
|
|
35
|
+
data: { files: [] },
|
|
36
36
|
});
|
|
37
37
|
|
|
38
38
|
// try {
|
|
@@ -24,7 +24,7 @@ export interface TaskHandlerResult<TResult = unknown> {
|
|
|
24
24
|
* {
|
|
25
25
|
* name: "researcher",
|
|
26
26
|
* description: "Researches topics",
|
|
27
|
-
*
|
|
27
|
+
* workflow: "researcherWorkflow",
|
|
28
28
|
* resultSchema: z.object({ findings: z.string() }),
|
|
29
29
|
* },
|
|
30
30
|
* ]);
|
|
@@ -47,11 +47,21 @@ export function createTaskHandler(subagents: SubagentConfig[]) {
|
|
|
47
47
|
const childWorkflowId = `${parentWorkflowId}-${args.subagent}-${uuid4()}`;
|
|
48
48
|
|
|
49
49
|
// Execute the child workflow
|
|
50
|
-
const
|
|
50
|
+
const input: SubagentInput = {
|
|
51
|
+
prompt: args.prompt,
|
|
52
|
+
...(config.context && { context: config.context }),
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const childOpts = {
|
|
51
56
|
workflowId: childWorkflowId,
|
|
52
|
-
args: [
|
|
57
|
+
args: [input],
|
|
53
58
|
taskQueue: config.taskQueue ?? parentTaskQueue,
|
|
54
|
-
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const childResult =
|
|
62
|
+
typeof config.workflow === "string"
|
|
63
|
+
? await executeChild(config.workflow, childOpts)
|
|
64
|
+
: await executeChild(config.workflow, childOpts);
|
|
55
65
|
|
|
56
66
|
// Validate result if schema provided, otherwise pass through as-is
|
|
57
67
|
const validated = config.resultSchema
|
|
@@ -59,14 +69,14 @@ export function createTaskHandler(subagents: SubagentConfig[]) {
|
|
|
59
69
|
: childResult;
|
|
60
70
|
|
|
61
71
|
// Format content - stringify objects, pass strings through
|
|
62
|
-
const
|
|
72
|
+
const toolResponse =
|
|
63
73
|
typeof validated === "string"
|
|
64
74
|
? validated
|
|
65
75
|
: JSON.stringify(validated, null, 2);
|
|
66
76
|
|
|
67
77
|
return {
|
|
68
|
-
|
|
69
|
-
|
|
78
|
+
toolResponse,
|
|
79
|
+
data: {
|
|
70
80
|
result: validated,
|
|
71
81
|
childWorkflowId,
|
|
72
82
|
},
|
package/src/tools/task/tool.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type {
|
|
|
5
5
|
import type { ToolHandlerResponse } from "../../lib/tool-router";
|
|
6
6
|
import type { WorkflowTask } from "../../lib/types";
|
|
7
7
|
import type { TaskCreateToolSchemaType } from "./tool";
|
|
8
|
+
import { uuid4 } from "@temporalio/workflow";
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Creates a TaskCreate handler that adds tasks to the workflow state.
|
|
@@ -18,18 +19,14 @@ import type { TaskCreateToolSchemaType } from "./tool";
|
|
|
18
19
|
*/
|
|
19
20
|
export function createTaskCreateHandler<
|
|
20
21
|
TCustom extends JsonSerializable<TCustom>,
|
|
21
|
-
>(
|
|
22
|
-
stateManager
|
|
23
|
-
|
|
24
|
-
}: {
|
|
25
|
-
stateManager: AgentStateManager<TCustom>;
|
|
26
|
-
idGenerator: () => string;
|
|
27
|
-
}): (args: TaskCreateToolSchemaType) => ToolHandlerResponse<WorkflowTask> {
|
|
22
|
+
>(
|
|
23
|
+
stateManager: AgentStateManager<TCustom>
|
|
24
|
+
): (args: TaskCreateToolSchemaType) => ToolHandlerResponse<WorkflowTask> {
|
|
28
25
|
return (
|
|
29
26
|
args: TaskCreateToolSchemaType
|
|
30
27
|
): ToolHandlerResponse<WorkflowTask> => {
|
|
31
28
|
const task: WorkflowTask = {
|
|
32
|
-
id:
|
|
29
|
+
id: uuid4(),
|
|
33
30
|
subject: args.subject,
|
|
34
31
|
description: args.description,
|
|
35
32
|
activeForm: args.activeForm,
|
|
@@ -42,8 +39,8 @@ export function createTaskCreateHandler<
|
|
|
42
39
|
stateManager.setTask(task);
|
|
43
40
|
|
|
44
41
|
return {
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
toolResponse: JSON.stringify(task, null, 2),
|
|
43
|
+
data: task,
|
|
47
44
|
};
|
|
48
45
|
};
|
|
49
46
|
}
|
|
@@ -25,14 +25,14 @@ export function createTaskGetHandler<TCustom extends JsonSerializable<TCustom>>(
|
|
|
25
25
|
|
|
26
26
|
if (!task) {
|
|
27
27
|
return {
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
toolResponse: JSON.stringify({ error: `Task not found: ${args.taskId}` }),
|
|
29
|
+
data: null,
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
return {
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
toolResponse: JSON.stringify(task, null, 2),
|
|
35
|
+
data: task,
|
|
36
36
|
};
|
|
37
37
|
};
|
|
38
38
|
}
|
|
@@ -29,8 +29,8 @@ export function createTaskUpdateHandler<
|
|
|
29
29
|
|
|
30
30
|
if (!task) {
|
|
31
31
|
return {
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
toolResponse: JSON.stringify({ error: `Task not found: ${args.taskId}` }),
|
|
33
|
+
data: null,
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
36
|
|
|
@@ -72,8 +72,8 @@ export function createTaskUpdateHandler<
|
|
|
72
72
|
stateManager.setTask(task);
|
|
73
73
|
|
|
74
74
|
return {
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
toolResponse: JSON.stringify(task, null, 2),
|
|
76
|
+
data: task,
|
|
77
77
|
};
|
|
78
78
|
};
|
|
79
79
|
}
|
package/src/workflow.ts
CHANGED
|
@@ -33,7 +33,7 @@ export type {
|
|
|
33
33
|
} from "./lib/state-manager";
|
|
34
34
|
|
|
35
35
|
// Tool router (includes registry functionality)
|
|
36
|
-
export { createToolRouter, hasNoOtherToolCalls } from "./lib/tool-router";
|
|
36
|
+
export { createToolRouter, hasNoOtherToolCalls, defineTool, defineSubagent } from "./lib/tool-router";
|
|
37
37
|
export type {
|
|
38
38
|
// Tool definition types
|
|
39
39
|
ToolDefinition,
|
|
@@ -81,11 +81,13 @@ export type {
|
|
|
81
81
|
PostToolUseFailureHook,
|
|
82
82
|
PostToolUseFailureHookContext,
|
|
83
83
|
PostToolUseFailureHookResult,
|
|
84
|
+
ToolHooks,
|
|
84
85
|
SessionStartHook,
|
|
85
86
|
SessionStartHookContext,
|
|
86
87
|
SessionEndHook,
|
|
87
88
|
SessionEndHookContext,
|
|
88
89
|
SubagentConfig,
|
|
90
|
+
SubagentHooks,
|
|
89
91
|
SubagentInput,
|
|
90
92
|
TaskStatus,
|
|
91
93
|
WorkflowTask,
|