zeitlich 0.2.3 → 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.
package/dist/workflow.js CHANGED
@@ -2,38 +2,38 @@ import { defineQuery, proxyActivities, setHandler, uuid4, workflowInfo, executeC
2
2
  import z3, { z } from 'zod';
3
3
 
4
4
  // src/lib/session.ts
5
- var TASK_TOOL = "Task";
6
- function buildTaskDescription(subagents) {
5
+ var SUBAGENT_TOOL = "Subagent";
6
+ function buildSubagentDescription(subagents) {
7
7
  const subagentList = subagents.map((s) => `- **${s.name}**: ${s.description}`).join("\n");
8
- return `Launch a new agent to handle complex, multi-step tasks autonomously.
8
+ return `Launch a new agent to handle complex tasks autonomously.
9
9
 
10
- The ${TASK_TOOL} tool launches specialized agents (subprocesses) that autonomously handle complex tasks. Each agent type has specific capabilities and tools available to it.
10
+ The ${SUBAGENT_TOOL} tool launches specialized agents (subprocesses) that autonomously handle complex tasks. Each agent type has specific capabilities and tools available to it.
11
11
 
12
12
  Available agent types:
13
13
 
14
14
  ${subagentList}
15
15
 
16
- When using the ${TASK_TOOL} tool, you must specify a subagent parameter to select which agent type to use.
16
+ When using the ${SUBAGENT_TOOL} tool, you must specify a subagent parameter to select which agent type to use.
17
17
 
18
18
  Usage notes:
19
19
 
20
20
  - Always include a short description (3-5 words) summarizing what the agent will do
21
21
  - Launch multiple agents concurrently whenever possible, to maximize performance; to do that, use a single message with multiple tool uses
22
- - 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.
22
+ - When the agent is done, it will return a single message back to you.
23
23
  - Each invocation starts fresh - provide a detailed task description with all necessary context.
24
24
  - Provide clear, detailed prompts so the agent can work autonomously and return exactly the information you need.
25
25
  - The agent's outputs should generally be trusted
26
26
  - Clearly tell the agent what type of work you expect since it is not aware of the user's intent
27
27
  - If the agent description mentions that it should be used proactively, then you should try your best to use it without the user having to ask for it first. Use your judgement.`;
28
28
  }
29
- function createTaskTool(subagents) {
29
+ function createSubagentTool(subagents) {
30
30
  if (subagents.length === 0) {
31
31
  throw new Error("createTaskTool requires at least one subagent");
32
32
  }
33
33
  const names = subagents.map((s) => s.name);
34
34
  return {
35
- name: TASK_TOOL,
36
- description: buildTaskDescription(subagents),
35
+ name: SUBAGENT_TOOL,
36
+ description: buildSubagentDescription(subagents),
37
37
  schema: z3.object({
38
38
  subagent: z3.enum(names).describe("The type of subagent to launch"),
39
39
  description: z3.string().describe("A short (3-5 word) description of the task"),
@@ -41,7 +41,7 @@ function createTaskTool(subagents) {
41
41
  })
42
42
  };
43
43
  }
44
- function createTaskHandler(subagents) {
44
+ function createSubagentHandler(subagents) {
45
45
  const { workflowId: parentWorkflowId, taskQueue: parentTaskQueue } = workflowInfo();
46
46
  return async (args) => {
47
47
  const config = subagents.find((s) => s.name === args.subagent);
@@ -60,15 +60,11 @@ function createTaskHandler(subagents) {
60
60
  args: [input],
61
61
  taskQueue: config.taskQueue ?? parentTaskQueue
62
62
  };
63
- const childResult = typeof config.workflow === "string" ? await executeChild(config.workflow, childOpts) : await executeChild(config.workflow, childOpts);
64
- const validated = config.resultSchema ? config.resultSchema.parse(childResult) : childResult;
65
- const toolResponse = typeof validated === "string" ? validated : JSON.stringify(validated, null, 2);
63
+ const { toolResponse, data } = typeof config.workflow === "string" ? await executeChild(config.workflow, childOpts) : await executeChild(config.workflow, childOpts);
64
+ const validated = config.resultSchema ? config.resultSchema.parse(data) : null;
66
65
  return {
67
66
  toolResponse,
68
- data: {
69
- result: validated,
70
- childWorkflowId
71
- }
67
+ data: validated
72
68
  };
73
69
  };
74
70
  }
@@ -87,9 +83,9 @@ function createToolRouter(options) {
87
83
  if (s.hooks) subagentHooksMap.set(s.name, s.hooks);
88
84
  }
89
85
  const resolveSubagentName = (args) => args.subagent;
90
- toolMap.set("Task", {
91
- ...createTaskTool(options.subagents),
92
- handler: createTaskHandler(options.subagents),
86
+ toolMap.set("Subagent", {
87
+ ...createSubagentTool(options.subagents),
88
+ handler: createSubagentHandler(options.subagents),
93
89
  ...subagentHooksMap.size > 0 && {
94
90
  hooks: {
95
91
  onPreToolUse: async (ctx) => {
@@ -425,22 +421,16 @@ var createSession = async ({
425
421
  while (stateManager.isRunning() && !stateManager.isTerminal() && stateManager.getTurns() < maxTurns) {
426
422
  stateManager.incrementTurns();
427
423
  const currentTurn = stateManager.getTurns();
428
- const { message, stopReason } = await runAgent({
424
+ const { message, rawToolCalls } = await runAgent({
429
425
  threadId,
430
426
  agentName,
431
427
  metadata
432
428
  });
433
- if (stopReason === "end_turn") {
434
- stateManager.complete();
435
- exitReason = "completed";
436
- return message;
437
- }
438
- if (!toolRouter.hasTools()) {
429
+ if (!toolRouter.hasTools() || rawToolCalls.length === 0) {
439
430
  stateManager.complete();
440
431
  exitReason = "completed";
441
432
  return message;
442
433
  }
443
- const rawToolCalls = await threadOps.parseToolCalls(message);
444
434
  const parsedToolCalls = [];
445
435
  for (const tc of rawToolCalls) {
446
436
  try {
@@ -493,8 +483,7 @@ function proxyDefaultThreadOps(options) {
493
483
  return {
494
484
  initializeThread: activities.initializeThread,
495
485
  appendHumanMessage: activities.appendHumanMessage,
496
- appendToolResult: activities.appendToolResult,
497
- parseToolCalls: activities.parseToolCalls
486
+ appendToolResult: activities.appendToolResult
498
487
  };
499
488
  }
500
489
 
@@ -961,6 +950,6 @@ Use this tool to:
961
950
  strict: true
962
951
  };
963
952
 
964
- export { AGENT_HANDLER_NAMES, askUserQuestionTool, bashTool, createAgentStateManager, createBashToolDescription, createSession, createTaskCreateHandler, createTaskGetHandler, createTaskListHandler, createTaskTool, createTaskUpdateHandler, createToolRouter, defineSubagent, defineTool, editTool, globTool, grepTool, hasNoOtherToolCalls, isTerminalStatus, proxyDefaultThreadOps, readTool, taskCreateTool, taskGetTool, taskListTool, taskUpdateTool, writeTool };
953
+ export { AGENT_HANDLER_NAMES, askUserQuestionTool, bashTool, createAgentStateManager, createBashToolDescription, createSession, createSubagentTool, createTaskCreateHandler, createTaskGetHandler, createTaskListHandler, createTaskUpdateHandler, createToolRouter, defineSubagent, defineTool, editTool, globTool, grepTool, hasNoOtherToolCalls, isTerminalStatus, proxyDefaultThreadOps, readTool, taskCreateTool, taskGetTool, taskListTool, taskUpdateTool, writeTool };
965
954
  //# sourceMappingURL=workflow.js.map
966
955
  //# sourceMappingURL=workflow.js.map