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.
@@ -14,8 +14,8 @@ export interface EditResult {
14
14
  * Edit handler response
15
15
  */
16
16
  export interface EditHandlerResponse {
17
- content: string;
18
- result: EditResult;
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
- content: `Error: old_string and new_string must be different.`,
59
- result: {
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
- content: `Error: File "${file_path}" does not exist.`,
73
- result: {
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
- content: `Error: Could not find the specified text in "${file_path}". Make sure old_string matches exactly (whitespace-sensitive).`,
88
- result: {
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
- content: `Error: old_string appears ${occurrences} times in "${file_path}". Either provide more context to make it unique, or use replace_all: true.`,
105
- result: {
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
- content: `${summary} in ${file_path}`,
139
- result: {
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
- content: `Error editing file "${file_path}": ${message}`,
149
- result: {
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
- content: string;
17
- result: GlobResult;
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
- content: "Hello, world!",
35
- result: { files: [] },
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
- * workflowType: "researcherWorkflow",
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 childResult = await executeChild(config.workflowType, {
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: [{ prompt: args.prompt } satisfies SubagentInput],
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 content =
72
+ const toolResponse =
63
73
  typeof validated === "string"
64
74
  ? validated
65
75
  : JSON.stringify(validated, null, 2);
66
76
 
67
77
  return {
68
- content,
69
- result: {
78
+ toolResponse,
79
+ data: {
70
80
  result: validated,
71
81
  childWorkflowId,
72
82
  },
@@ -44,7 +44,7 @@ Usage notes:
44
44
  * {
45
45
  * name: "researcher",
46
46
  * description: "Researches topics and gathers information",
47
- * workflowType: "researcherWorkflow",
47
+ * workflow: "researcherWorkflow",
48
48
  * resultSchema: z.object({ findings: z.string() }),
49
49
  * },
50
50
  * ]);
@@ -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
- idGenerator,
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: idGenerator(),
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
- content: JSON.stringify(task, null, 2),
46
- result: task,
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
- content: JSON.stringify({ error: `Task not found: ${args.taskId}` }),
29
- result: null,
28
+ toolResponse: JSON.stringify({ error: `Task not found: ${args.taskId}` }),
29
+ data: null,
30
30
  };
31
31
  }
32
32
 
33
33
  return {
34
- content: JSON.stringify(task, null, 2),
35
- result: task,
34
+ toolResponse: JSON.stringify(task, null, 2),
35
+ data: task,
36
36
  };
37
37
  };
38
38
  }
@@ -26,8 +26,8 @@ export function createTaskListHandler<
26
26
  const taskList = stateManager.getTasks();
27
27
 
28
28
  return {
29
- content: JSON.stringify(taskList, null, 2),
30
- result: taskList,
29
+ toolResponse: JSON.stringify(taskList, null, 2),
30
+ data: taskList,
31
31
  };
32
32
  };
33
33
  }
@@ -29,8 +29,8 @@ export function createTaskUpdateHandler<
29
29
 
30
30
  if (!task) {
31
31
  return {
32
- content: JSON.stringify({ error: `Task not found: ${args.taskId}` }),
33
- result: null,
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
- content: JSON.stringify(task, null, 2),
76
- result: task,
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,