zeitlich 0.2.2 → 0.2.4

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.
Files changed (46) hide show
  1. package/README.md +34 -31
  2. package/dist/index.cjs +330 -399
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +24 -43
  5. package/dist/index.d.ts +24 -43
  6. package/dist/index.js +301 -373
  7. package/dist/index.js.map +1 -1
  8. package/dist/{workflow-BQf5EfNN.d.cts → workflow-PjeURKw4.d.cts} +265 -258
  9. package/dist/{workflow-BQf5EfNN.d.ts → workflow-PjeURKw4.d.ts} +265 -258
  10. package/dist/workflow.cjs +223 -281
  11. package/dist/workflow.cjs.map +1 -1
  12. package/dist/workflow.d.cts +2 -3
  13. package/dist/workflow.d.ts +2 -3
  14. package/dist/workflow.js +198 -258
  15. package/dist/workflow.js.map +1 -1
  16. package/package.json +3 -2
  17. package/src/activities.ts +0 -32
  18. package/src/index.ts +14 -11
  19. package/src/lib/model-invoker.ts +7 -1
  20. package/src/lib/session.ts +54 -109
  21. package/src/lib/thread-manager.ts +45 -37
  22. package/src/lib/tool-router.ts +148 -108
  23. package/src/lib/types.ts +35 -26
  24. package/src/tools/ask-user-question/handler.ts +5 -5
  25. package/src/tools/ask-user-question/tool.ts +3 -2
  26. package/src/tools/bash/bash.test.ts +12 -12
  27. package/src/tools/bash/handler.ts +5 -5
  28. package/src/tools/bash/tool.ts +3 -2
  29. package/src/tools/edit/handler.ts +78 -123
  30. package/src/tools/edit/tool.ts +3 -2
  31. package/src/tools/glob/handler.ts +17 -48
  32. package/src/tools/glob/tool.ts +3 -2
  33. package/src/tools/grep/tool.ts +3 -2
  34. package/src/tools/{read → read-file}/tool.ts +3 -2
  35. package/src/tools/{task → subagent}/handler.ts +18 -31
  36. package/src/tools/{task → subagent}/tool.ts +13 -20
  37. package/src/tools/task-create/handler.ts +5 -11
  38. package/src/tools/task-create/tool.ts +3 -2
  39. package/src/tools/task-get/handler.ts +5 -10
  40. package/src/tools/task-get/tool.ts +3 -2
  41. package/src/tools/task-list/handler.ts +5 -10
  42. package/src/tools/task-list/tool.ts +3 -2
  43. package/src/tools/task-update/handler.ts +5 -12
  44. package/src/tools/task-update/tool.ts +3 -2
  45. package/src/tools/{write → write-file}/tool.ts +5 -6
  46. package/src/workflow.ts +24 -21
@@ -1,31 +1,31 @@
1
1
  import z from "zod";
2
2
  import type { SubagentConfig } from "../../lib/types";
3
3
 
4
- const TASK_TOOL = "Task" as const;
4
+ const SUBAGENT_TOOL = "Subagent" as const;
5
5
 
6
6
  /**
7
7
  * Builds the tool description with available subagent information
8
8
  */
9
- function buildTaskDescription(subagents: SubagentConfig[]): string {
9
+ function buildSubagentDescription(subagents: SubagentConfig[]): string {
10
10
  const subagentList = subagents
11
11
  .map((s) => `- **${s.name}**: ${s.description}`)
12
12
  .join("\n");
13
13
 
14
- return `Launch a new agent to handle complex, multi-step tasks autonomously.
14
+ return `Launch a new agent to handle complex tasks autonomously.
15
15
 
16
- The ${TASK_TOOL} tool launches specialized agents (subprocesses) that autonomously handle complex tasks. Each agent type has specific capabilities and tools available to it.
16
+ The ${SUBAGENT_TOOL} tool launches specialized agents (subprocesses) that autonomously handle complex tasks. Each agent type has specific capabilities and tools available to it.
17
17
 
18
18
  Available agent types:
19
19
 
20
20
  ${subagentList}
21
21
 
22
- When using the ${TASK_TOOL} tool, you must specify a subagent parameter to select which agent type to use.
22
+ When using the ${SUBAGENT_TOOL} tool, you must specify a subagent parameter to select which agent type to use.
23
23
 
24
24
  Usage notes:
25
25
 
26
26
  - Always include a short description (3-5 words) summarizing what the agent will do
27
27
  - Launch multiple agents concurrently whenever possible, to maximize performance; to do that, use a single message with multiple tool uses
28
- - When the agent is done, it will return a single message back to you. The result returned by the agent is not visible to the user. To show the user the result, you should send a text message back to the user with a concise summary of the result.
28
+ - When the agent is done, it will return a single message back to you.
29
29
  - Each invocation starts fresh - provide a detailed task description with all necessary context.
30
30
  - Provide clear, detailed prompts so the agent can work autonomously and return exactly the information you need.
31
31
  - The agent's outputs should generally be trusted
@@ -34,13 +34,13 @@ Usage notes:
34
34
  }
35
35
 
36
36
  /**
37
- * Creates a Task tool configured with the available subagents.
37
+ * Creates a Subagent tool configured with the available subagents.
38
38
  *
39
39
  * @param subagents - Array of subagent configurations (must have at least one)
40
40
  * @returns A tool definition with dynamic schema based on available subagents
41
41
  *
42
42
  * @example
43
- * const taskTool = createTaskTool([
43
+ * const subagentTool = createSubagentTool([
44
44
  * {
45
45
  * name: "researcher",
46
46
  * description: "Researches topics and gathers information",
@@ -49,7 +49,7 @@ Usage notes:
49
49
  * },
50
50
  * ]);
51
51
  */
52
- export function createTaskTool<T extends SubagentConfig[]>(
52
+ export function createSubagentTool<T extends SubagentConfig[]>(
53
53
  subagents: T
54
54
  ): {
55
55
  name: string;
@@ -67,8 +67,8 @@ export function createTaskTool<T extends SubagentConfig[]>(
67
67
  const names = subagents.map((s) => s.name);
68
68
 
69
69
  return {
70
- name: TASK_TOOL,
71
- description: buildTaskDescription(subagents),
70
+ name: SUBAGENT_TOOL,
71
+ description: buildSubagentDescription(subagents),
72
72
  schema: z.object({
73
73
  subagent: z.enum(names).describe("The type of subagent to launch"),
74
74
  description: z
@@ -80,16 +80,9 @@ export function createTaskTool<T extends SubagentConfig[]>(
80
80
  }
81
81
 
82
82
  /**
83
- * Infer the schema type for a task tool created with specific subagents
83
+ * Subagent tool args type (when subagent names are not known at compile time)
84
84
  */
85
- export type TaskToolSchemaType<T extends SubagentConfig[]> = z.infer<
86
- ReturnType<typeof createTaskTool<T>>["schema"]
87
- >;
88
-
89
- /**
90
- * Generic task tool schema type (when subagent names are not known at compile time)
91
- */
92
- export type GenericTaskToolSchemaType = {
85
+ export type SubagentArgs = {
93
86
  subagent: string;
94
87
  description: string;
95
88
  prompt: string;
@@ -2,29 +2,23 @@ import type {
2
2
  AgentStateManager,
3
3
  JsonSerializable,
4
4
  } from "../../lib/state-manager";
5
- import type { ToolHandlerResponse } from "../../lib/tool-router";
5
+ import type { ToolHandler } from "../../lib/tool-router";
6
6
  import type { WorkflowTask } from "../../lib/types";
7
- import type { TaskCreateToolSchemaType } from "./tool";
7
+ import type { TaskCreateArgs } from "./tool";
8
8
  import { uuid4 } from "@temporalio/workflow";
9
9
 
10
10
  /**
11
11
  * Creates a TaskCreate handler that adds tasks to the workflow state.
12
12
  *
13
13
  * @param stateManager - State manager containing tasks state
14
- * @param idGenerator - Function to generate unique task IDs (e.g., uuid4 from Temporal)
15
- * @returns A tool handler function
16
- *
17
- * @example
18
- * const handler = createTaskCreateHandler(stateManager, uuid4);
14
+ * @returns A ToolHandler for TaskCreate tool calls
19
15
  */
20
16
  export function createTaskCreateHandler<
21
17
  TCustom extends JsonSerializable<TCustom>,
22
18
  >(
23
19
  stateManager: AgentStateManager<TCustom>
24
- ): (args: TaskCreateToolSchemaType) => ToolHandlerResponse<WorkflowTask> {
25
- return (
26
- args: TaskCreateToolSchemaType
27
- ): ToolHandlerResponse<WorkflowTask> => {
20
+ ): ToolHandler<TaskCreateArgs, WorkflowTask> {
21
+ return (args) => {
28
22
  const task: WorkflowTask = {
29
23
  id: uuid4(),
30
24
  subject: args.subject,
@@ -1,4 +1,5 @@
1
1
  import z from "zod";
2
+ import type { ToolDefinition } from "../../lib/tool-router";
2
3
 
3
4
  export const taskCreateTool = {
4
5
  name: "TaskCreate" as const,
@@ -61,6 +62,6 @@ export const taskCreateTool = {
61
62
  .record(z.string(), z.string())
62
63
  .describe("Arbitrary key-value pairs for tracking"),
63
64
  }),
64
- };
65
+ } satisfies ToolDefinition;
65
66
 
66
- export type TaskCreateToolSchemaType = z.infer<typeof taskCreateTool.schema>;
67
+ export type TaskCreateArgs = z.infer<typeof taskCreateTool.schema>;
@@ -2,25 +2,20 @@ import type {
2
2
  AgentStateManager,
3
3
  JsonSerializable,
4
4
  } from "../../lib/state-manager";
5
- import type { ToolHandlerResponse } from "../../lib/tool-router";
5
+ import type { ToolHandler } from "../../lib/tool-router";
6
6
  import type { WorkflowTask } from "../../lib/types";
7
- import type { TaskGetToolSchemaType } from "./tool";
7
+ import type { TaskGetArgs } from "./tool";
8
8
 
9
9
  /**
10
10
  * Creates a TaskGet handler that retrieves a task by ID.
11
11
  *
12
12
  * @param stateManager - State manager containing tasks state
13
- * @returns A tool handler function
14
- *
15
- * @example
16
- * const handler = createTaskGetHandler(stateManager);
13
+ * @returns A ToolHandler for TaskGet tool calls
17
14
  */
18
15
  export function createTaskGetHandler<TCustom extends JsonSerializable<TCustom>>(
19
16
  stateManager: AgentStateManager<TCustom>
20
- ): (args: TaskGetToolSchemaType) => ToolHandlerResponse<WorkflowTask | null> {
21
- return (
22
- args: TaskGetToolSchemaType
23
- ): ToolHandlerResponse<WorkflowTask | null> => {
17
+ ): ToolHandler<TaskGetArgs, WorkflowTask | null> {
18
+ return (args) => {
24
19
  const task = stateManager.getTask(args.taskId) ?? null;
25
20
 
26
21
  if (!task) {
@@ -1,4 +1,5 @@
1
1
  import z from "zod";
2
+ import type { ToolDefinition } from "../../lib/tool-router";
2
3
 
3
4
  export const taskGetTool = {
4
5
  name: "TaskGet" as const,
@@ -6,6 +7,6 @@ export const taskGetTool = {
6
7
  schema: z.object({
7
8
  taskId: z.string().describe("The ID of the task to get"),
8
9
  }),
9
- };
10
+ } satisfies ToolDefinition;
10
11
 
11
- export type TaskGetToolSchemaType = z.infer<typeof taskGetTool.schema>;
12
+ export type TaskGetArgs = z.infer<typeof taskGetTool.schema>;
@@ -2,27 +2,22 @@ import type {
2
2
  AgentStateManager,
3
3
  JsonSerializable,
4
4
  } from "../../lib/state-manager";
5
- import type { ToolHandlerResponse } from "../../lib/tool-router";
5
+ import type { ToolHandler } from "../../lib/tool-router";
6
6
  import type { WorkflowTask } from "../../lib/types";
7
- import type { TaskListToolSchemaType } from "./tool";
7
+ import type { TaskListArgs } from "./tool";
8
8
 
9
9
  /**
10
10
  * Creates a TaskList handler that returns all tasks.
11
11
  *
12
12
  * @param stateManager - State manager containing tasks state
13
- * @returns A tool handler function
14
- *
15
- * @example
16
- * const handler = createTaskListHandler(stateManager);
13
+ * @returns A ToolHandler for TaskList tool calls
17
14
  */
18
15
  export function createTaskListHandler<
19
16
  TCustom extends JsonSerializable<TCustom>,
20
17
  >(
21
18
  stateManager: AgentStateManager<TCustom>
22
- ): (args: TaskListToolSchemaType) => ToolHandlerResponse<WorkflowTask[]> {
23
- return (
24
- _args: TaskListToolSchemaType
25
- ): ToolHandlerResponse<WorkflowTask[]> => {
19
+ ): ToolHandler<TaskListArgs, WorkflowTask[]> {
20
+ return () => {
26
21
  const taskList = stateManager.getTasks();
27
22
 
28
23
  return {
@@ -1,9 +1,10 @@
1
1
  import z from "zod";
2
+ import type { ToolDefinition } from "../../lib/tool-router";
2
3
 
3
4
  export const taskListTool = {
4
5
  name: "TaskList" as const,
5
6
  description: `List all tasks with current state.`,
6
7
  schema: z.object({}),
7
- };
8
+ } satisfies ToolDefinition;
8
9
 
9
- export type TaskListToolSchemaType = z.infer<typeof taskListTool.schema>;
10
+ export type TaskListArgs = z.infer<typeof taskListTool.schema>;
@@ -2,29 +2,22 @@ import type {
2
2
  AgentStateManager,
3
3
  JsonSerializable,
4
4
  } from "../../lib/state-manager";
5
- import type { ToolHandlerResponse } from "../../lib/tool-router";
5
+ import type { ToolHandler } from "../../lib/tool-router";
6
6
  import type { WorkflowTask } from "../../lib/types";
7
- import type { TaskUpdateToolSchemaType } from "./tool";
7
+ import type { TaskUpdateArgs } from "./tool";
8
8
 
9
9
  /**
10
10
  * Creates a TaskUpdate handler that modifies task status and dependencies.
11
11
  *
12
12
  * @param stateManager - State manager containing tasks state
13
- * @returns A tool handler function
14
- *
15
- * @example
16
- * const handler = createTaskUpdateHandler(stateManager);
13
+ * @returns A ToolHandler for TaskUpdate tool calls
17
14
  */
18
15
  export function createTaskUpdateHandler<
19
16
  TCustom extends JsonSerializable<TCustom>,
20
17
  >(
21
18
  stateManager: AgentStateManager<TCustom>
22
- ): (
23
- args: TaskUpdateToolSchemaType
24
- ) => ToolHandlerResponse<WorkflowTask | null> {
25
- return (
26
- args: TaskUpdateToolSchemaType
27
- ): ToolHandlerResponse<WorkflowTask | null> => {
19
+ ): ToolHandler<TaskUpdateArgs, WorkflowTask | null> {
20
+ return (args) => {
28
21
  const task = stateManager.getTask(args.taskId);
29
22
 
30
23
  if (!task) {
@@ -1,4 +1,5 @@
1
1
  import z from "zod";
2
+ import type { ToolDefinition } from "../../lib/tool-router";
2
3
 
3
4
  export const taskUpdateTool = {
4
5
  name: "TaskUpdate" as const,
@@ -15,6 +16,6 @@ export const taskUpdateTool = {
15
16
  .array(z.string())
16
17
  .describe("The IDs of the tasks that this task is blocking"),
17
18
  }),
18
- };
19
+ } satisfies ToolDefinition;
19
20
 
20
- export type TaskUpdateToolSchemaType = z.infer<typeof taskUpdateTool.schema>;
21
+ export type TaskUpdateArgs = z.infer<typeof taskUpdateTool.schema>;
@@ -1,11 +1,12 @@
1
1
  import { z } from "zod";
2
+ import type { ToolDefinition } from "../../lib/tool-router";
2
3
 
3
4
  export const writeTool = {
4
5
  name: "FileWrite" as const,
5
6
  description: `Create or overwrite a file with new content.
6
7
 
7
8
  Usage:
8
- - Provide the absolute virtual path to the file
9
+ - Provide the absolute path to the file
9
10
  - The file will be created if it doesn't exist
10
11
  - If the file exists, it will be completely overwritten
11
12
 
@@ -15,12 +16,10 @@ IMPORTANT:
15
16
  - Path must be absolute (e.g., "/docs/readme.md", not "docs/readme.md")
16
17
  `,
17
18
  schema: z.object({
18
- file_path: z
19
- .string()
20
- .describe("The absolute virtual path to the file to write"),
19
+ file_path: z.string().describe("The absolute path to the file to write"),
21
20
  content: z.string().describe("The content to write to the file"),
22
21
  }),
23
22
  strict: true,
24
- };
23
+ } satisfies ToolDefinition;
25
24
 
26
- export type WriteToolSchemaType = z.infer<typeof writeTool.schema>;
25
+ export type FileWriteArgs = z.infer<typeof writeTool.schema>;
package/src/workflow.ts CHANGED
@@ -16,7 +16,7 @@
16
16
  */
17
17
 
18
18
  // Session
19
- export { createSession } from "./lib/session";
19
+ export { createSession, proxyDefaultThreadOps } from "./lib/session";
20
20
  export type { ZeitlichSession, SessionLifecycleHooks } from "./lib/session";
21
21
 
22
22
  // State management
@@ -33,7 +33,12 @@ export type {
33
33
  } from "./lib/state-manager";
34
34
 
35
35
  // Tool router (includes registry functionality)
36
- export { createToolRouter, hasNoOtherToolCalls, defineTool, defineSubagent } from "./lib/tool-router";
36
+ export {
37
+ createToolRouter,
38
+ hasNoOtherToolCalls,
39
+ defineTool,
40
+ defineSubagent,
41
+ } from "./lib/tool-router";
37
42
  export type {
38
43
  // Tool definition types
39
44
  ToolDefinition,
@@ -68,6 +73,7 @@ export type {
68
73
  BaseAgentState,
69
74
  AgentFile,
70
75
  AgentResponse,
76
+ ThreadOps,
71
77
  ZeitlichAgentConfig,
72
78
  RunAgentConfig,
73
79
  RunAgentActivity,
@@ -95,12 +101,8 @@ export type {
95
101
  export { isTerminalStatus } from "./lib/types";
96
102
 
97
103
  // Subagent support
98
- export { createTaskTool } from "./tools/task/tool";
99
- export type {
100
- TaskToolSchemaType,
101
- GenericTaskToolSchemaType,
102
- } from "./tools/task/tool";
103
- export type { TaskHandlerResult } from "./tools/task/handler";
104
+ export { createSubagentTool } from "./tools/subagent/tool";
105
+ export type { SubagentArgs } from "./tools/subagent/tool";
104
106
 
105
107
  // Activity type interfaces (types only, no runtime code)
106
108
  // These are safe to import in workflows for typing proxyActivities
@@ -108,33 +110,34 @@ export type { ZeitlichSharedActivities } from "./activities";
108
110
 
109
111
  // Tool definitions (schemas only - no handlers)
110
112
  export { askUserQuestionTool } from "./tools/ask-user-question/tool";
111
- export type { AskUserQuestionToolSchemaType } from "./tools/ask-user-question/tool";
113
+ export type { AskUserQuestionArgs } from "./tools/ask-user-question/tool";
112
114
  export { globTool } from "./tools/glob/tool";
113
- export type { GlobToolSchemaType } from "./tools/glob/tool";
115
+ export type { GlobArgs } from "./tools/glob/tool";
114
116
  export { grepTool } from "./tools/grep/tool";
115
- export type { GrepToolSchemaType } from "./tools/grep/tool";
116
- export { readTool } from "./tools/read/tool";
117
- export type { ReadToolSchemaType } from "./tools/read/tool";
118
- export { writeTool } from "./tools/write/tool";
119
- export type { WriteToolSchemaType } from "./tools/write/tool";
117
+ export type { GrepArgs } from "./tools/grep/tool";
118
+ export { readTool } from "./tools/read-file/tool";
119
+ export type { FileReadArgs } from "./tools/read-file/tool";
120
+ export { writeTool } from "./tools/write-file/tool";
121
+ export type { FileWriteArgs } from "./tools/write-file/tool";
120
122
  export { editTool } from "./tools/edit/tool";
121
- export type { EditToolSchemaType } from "./tools/edit/tool";
123
+ export type { FileEditArgs } from "./tools/edit/tool";
122
124
 
123
125
  // Workflow task tools (state-only, no activities needed)
124
126
  export { taskCreateTool } from "./tools/task-create/tool";
125
- export type { TaskCreateToolSchemaType } from "./tools/task-create/tool";
127
+ export type { TaskCreateArgs } from "./tools/task-create/tool";
126
128
  export { createTaskCreateHandler } from "./tools/task-create/handler";
127
129
 
128
130
  export { taskGetTool } from "./tools/task-get/tool";
129
- export type { TaskGetToolSchemaType } from "./tools/task-get/tool";
131
+ export type { TaskGetArgs } from "./tools/task-get/tool";
130
132
  export { createTaskGetHandler } from "./tools/task-get/handler";
131
133
 
132
134
  export { taskListTool } from "./tools/task-list/tool";
135
+ export type { TaskListArgs } from "./tools/task-list/tool";
133
136
  export { createTaskListHandler } from "./tools/task-list/handler";
134
137
 
135
138
  export { taskUpdateTool } from "./tools/task-update/tool";
136
- export type { TaskUpdateToolSchemaType } from "./tools/task-update/tool";
139
+ export type { TaskUpdateArgs } from "./tools/task-update/tool";
137
140
  export { createTaskUpdateHandler } from "./tools/task-update/handler";
138
141
 
139
- export { bashTool } from "./tools/bash/tool";
140
- export type { bashToolSchemaType } from "./tools/bash/tool";
142
+ export { bashTool, createBashToolDescription } from "./tools/bash/tool";
143
+ export type { BashArgs } from "./tools/bash/tool";