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
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { defineQuery, proxyActivities, setHandler,
|
|
2
|
-
import
|
|
1
|
+
import { defineQuery, proxyActivities, setHandler, uuid4, workflowInfo, executeChild } from '@temporalio/workflow';
|
|
2
|
+
import z5, { z } from 'zod';
|
|
3
3
|
import { SimplePlugin } from '@temporalio/plugin';
|
|
4
|
-
import {
|
|
4
|
+
import { SystemMessage, ToolMessage, AIMessage, HumanMessage, mapStoredMessageToChatMessage, mapStoredMessagesToChatMessages } from '@langchain/core/messages';
|
|
5
5
|
import crypto from 'crypto';
|
|
6
6
|
import { Context } from '@temporalio/activity';
|
|
7
7
|
import { Bash } from 'just-bash';
|
|
@@ -39,10 +39,10 @@ function createTaskTool(subagents) {
|
|
|
39
39
|
return {
|
|
40
40
|
name: TASK_TOOL,
|
|
41
41
|
description: buildTaskDescription(subagents),
|
|
42
|
-
schema:
|
|
43
|
-
subagent:
|
|
44
|
-
description:
|
|
45
|
-
prompt:
|
|
42
|
+
schema: z5.object({
|
|
43
|
+
subagent: z5.enum(names).describe("The type of subagent to launch"),
|
|
44
|
+
description: z5.string().describe("A short (3-5 word) description of the task"),
|
|
45
|
+
prompt: z5.string().describe("The task for the agent to perform")
|
|
46
46
|
})
|
|
47
47
|
};
|
|
48
48
|
}
|
|
@@ -56,16 +56,21 @@ function createTaskHandler(subagents) {
|
|
|
56
56
|
);
|
|
57
57
|
}
|
|
58
58
|
const childWorkflowId = `${parentWorkflowId}-${args.subagent}-${uuid4()}`;
|
|
59
|
-
const
|
|
59
|
+
const input = {
|
|
60
|
+
prompt: args.prompt,
|
|
61
|
+
...config.context && { context: config.context }
|
|
62
|
+
};
|
|
63
|
+
const childOpts = {
|
|
60
64
|
workflowId: childWorkflowId,
|
|
61
|
-
args: [
|
|
65
|
+
args: [input],
|
|
62
66
|
taskQueue: config.taskQueue ?? parentTaskQueue
|
|
63
|
-
}
|
|
67
|
+
};
|
|
68
|
+
const childResult = typeof config.workflow === "string" ? await executeChild(config.workflow, childOpts) : await executeChild(config.workflow, childOpts);
|
|
64
69
|
const validated = config.resultSchema ? config.resultSchema.parse(childResult) : childResult;
|
|
65
|
-
const
|
|
70
|
+
const toolResponse = typeof validated === "string" ? validated : JSON.stringify(validated, null, 2);
|
|
66
71
|
return {
|
|
67
|
-
|
|
68
|
-
|
|
72
|
+
toolResponse,
|
|
73
|
+
data: {
|
|
69
74
|
result: validated,
|
|
70
75
|
childWorkflowId
|
|
71
76
|
}
|
|
@@ -92,8 +97,8 @@ Use this tool to:
|
|
|
92
97
|
- Execute scripts and chain commands with pipes (|) or logical operators (&&, ||)
|
|
93
98
|
- Inspect files and directories
|
|
94
99
|
`,
|
|
95
|
-
schema:
|
|
96
|
-
command:
|
|
100
|
+
schema: z5.object({
|
|
101
|
+
command: z5.string().describe(
|
|
97
102
|
"The bash command to execute. Can include pipes (|), redirects (>, >>), logical operators (&&, ||), and shell features like command substitution $(...)."
|
|
98
103
|
)
|
|
99
104
|
}),
|
|
@@ -140,17 +145,17 @@ var taskCreateTool = {
|
|
|
140
145
|
- Include enough detail in the description for another agent to understand and complete the task
|
|
141
146
|
- After creating tasks, use TaskUpdate to set up dependencies (blocks/blockedBy) if needed
|
|
142
147
|
- Check TaskList first to avoid creating duplicate tasks`,
|
|
143
|
-
schema:
|
|
144
|
-
subject:
|
|
148
|
+
schema: z5.object({
|
|
149
|
+
subject: z5.string().describe(
|
|
145
150
|
'A brief, actionable title in imperative form (e.g., "Fix authentication bug in login flow")'
|
|
146
151
|
),
|
|
147
|
-
description:
|
|
152
|
+
description: z5.string().describe(
|
|
148
153
|
"Detailed description of what needs to be done, including context and acceptance criteria"
|
|
149
154
|
),
|
|
150
|
-
activeForm:
|
|
155
|
+
activeForm: z5.string().describe(
|
|
151
156
|
'Present continuous form shown in spinner when task is in_progress (e.g., "Fixing authentication bug"). This is displayed to the user while you work on the task.'
|
|
152
157
|
),
|
|
153
|
-
metadata:
|
|
158
|
+
metadata: z5.record(z5.string(), z5.string()).describe("Arbitrary key-value pairs for tracking")
|
|
154
159
|
})
|
|
155
160
|
};
|
|
156
161
|
|
|
@@ -174,9 +179,30 @@ function createToolRouter(options) {
|
|
|
174
179
|
toolMap.set(tool.name, tool);
|
|
175
180
|
}
|
|
176
181
|
if (options.subagents) {
|
|
182
|
+
const subagentHooksMap = /* @__PURE__ */ new Map();
|
|
183
|
+
for (const s of options.subagents) {
|
|
184
|
+
if (s.hooks) subagentHooksMap.set(s.name, s.hooks);
|
|
185
|
+
}
|
|
186
|
+
const resolveSubagentName = (args) => args.subagent;
|
|
177
187
|
toolMap.set("Task", {
|
|
178
188
|
...createTaskTool(options.subagents),
|
|
179
|
-
handler: createTaskHandler(options.subagents)
|
|
189
|
+
handler: createTaskHandler(options.subagents),
|
|
190
|
+
...subagentHooksMap.size > 0 && {
|
|
191
|
+
hooks: {
|
|
192
|
+
onPreToolUse: async (ctx) => {
|
|
193
|
+
const hooks = subagentHooksMap.get(resolveSubagentName(ctx.args));
|
|
194
|
+
return hooks?.onPreExecution?.(ctx) ?? {};
|
|
195
|
+
},
|
|
196
|
+
onPostToolUse: async (ctx) => {
|
|
197
|
+
const hooks = subagentHooksMap.get(resolveSubagentName(ctx.args));
|
|
198
|
+
await hooks?.onPostExecution?.(ctx);
|
|
199
|
+
},
|
|
200
|
+
onPostToolUseFailure: async (ctx) => {
|
|
201
|
+
const hooks = subagentHooksMap.get(resolveSubagentName(ctx.args));
|
|
202
|
+
return hooks?.onExecutionFailure?.(ctx) ?? {};
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
180
206
|
});
|
|
181
207
|
}
|
|
182
208
|
if (options.buildInTools) {
|
|
@@ -199,6 +225,8 @@ function createToolRouter(options) {
|
|
|
199
225
|
}
|
|
200
226
|
async function processToolCall(toolCall, turn, handlerContext) {
|
|
201
227
|
const startTime = Date.now();
|
|
228
|
+
const tool = toolMap.get(toolCall.name);
|
|
229
|
+
const toolHooks = tool?.hooks;
|
|
202
230
|
let effectiveArgs = toolCall.args;
|
|
203
231
|
if (options.hooks?.onPreToolUse) {
|
|
204
232
|
const preResult = await options.hooks.onPreToolUse({
|
|
@@ -221,7 +249,27 @@ function createToolRouter(options) {
|
|
|
221
249
|
effectiveArgs = preResult.modifiedArgs;
|
|
222
250
|
}
|
|
223
251
|
}
|
|
224
|
-
|
|
252
|
+
if (toolHooks?.onPreToolUse) {
|
|
253
|
+
const preResult = await toolHooks.onPreToolUse({
|
|
254
|
+
args: effectiveArgs,
|
|
255
|
+
threadId: options.threadId,
|
|
256
|
+
turn
|
|
257
|
+
});
|
|
258
|
+
if (preResult?.skip) {
|
|
259
|
+
await appendToolResult({
|
|
260
|
+
threadId: options.threadId,
|
|
261
|
+
toolCallId: toolCall.id,
|
|
262
|
+
content: JSON.stringify({
|
|
263
|
+
skipped: true,
|
|
264
|
+
reason: "Skipped by tool PreToolUse hook"
|
|
265
|
+
})
|
|
266
|
+
});
|
|
267
|
+
return null;
|
|
268
|
+
}
|
|
269
|
+
if (preResult?.modifiedArgs !== void 0) {
|
|
270
|
+
effectiveArgs = preResult.modifiedArgs;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
225
273
|
let result;
|
|
226
274
|
let content;
|
|
227
275
|
try {
|
|
@@ -230,30 +278,50 @@ function createToolRouter(options) {
|
|
|
230
278
|
effectiveArgs,
|
|
231
279
|
handlerContext ?? {}
|
|
232
280
|
);
|
|
233
|
-
result = response.
|
|
234
|
-
content = response.
|
|
281
|
+
result = response.data;
|
|
282
|
+
content = response.toolResponse;
|
|
235
283
|
} else {
|
|
236
284
|
result = { error: `Unknown tool: ${toolCall.name}` };
|
|
237
285
|
content = JSON.stringify(result, null, 2);
|
|
238
286
|
}
|
|
239
287
|
} catch (error) {
|
|
240
|
-
|
|
288
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
289
|
+
let recovered = false;
|
|
290
|
+
if (toolHooks?.onPostToolUseFailure) {
|
|
291
|
+
const failureResult = await toolHooks.onPostToolUseFailure({
|
|
292
|
+
args: effectiveArgs,
|
|
293
|
+
error: err,
|
|
294
|
+
threadId: options.threadId,
|
|
295
|
+
turn
|
|
296
|
+
});
|
|
297
|
+
if (failureResult?.fallbackContent !== void 0) {
|
|
298
|
+
content = failureResult.fallbackContent;
|
|
299
|
+
result = { error: String(error), recovered: true };
|
|
300
|
+
recovered = true;
|
|
301
|
+
} else if (failureResult?.suppress) {
|
|
302
|
+
content = JSON.stringify({ error: String(error), suppressed: true });
|
|
303
|
+
result = { error: String(error), suppressed: true };
|
|
304
|
+
recovered = true;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
if (!recovered && options.hooks?.onPostToolUseFailure) {
|
|
241
308
|
const failureResult = await options.hooks.onPostToolUseFailure({
|
|
242
309
|
toolCall,
|
|
243
|
-
error:
|
|
310
|
+
error: err,
|
|
244
311
|
threadId: options.threadId,
|
|
245
312
|
turn
|
|
246
313
|
});
|
|
247
314
|
if (failureResult?.fallbackContent !== void 0) {
|
|
248
315
|
content = failureResult.fallbackContent;
|
|
249
316
|
result = { error: String(error), recovered: true };
|
|
317
|
+
recovered = true;
|
|
250
318
|
} else if (failureResult?.suppress) {
|
|
251
319
|
content = JSON.stringify({ error: String(error), suppressed: true });
|
|
252
320
|
result = { error: String(error), suppressed: true };
|
|
253
|
-
|
|
254
|
-
throw error;
|
|
321
|
+
recovered = true;
|
|
255
322
|
}
|
|
256
|
-
}
|
|
323
|
+
}
|
|
324
|
+
if (!recovered) {
|
|
257
325
|
throw error;
|
|
258
326
|
}
|
|
259
327
|
}
|
|
@@ -265,10 +333,19 @@ function createToolRouter(options) {
|
|
|
265
333
|
const toolResult = {
|
|
266
334
|
toolCallId: toolCall.id,
|
|
267
335
|
name: toolCall.name,
|
|
268
|
-
result
|
|
336
|
+
data: result
|
|
269
337
|
};
|
|
338
|
+
const durationMs = Date.now() - startTime;
|
|
339
|
+
if (toolHooks?.onPostToolUse) {
|
|
340
|
+
await toolHooks.onPostToolUse({
|
|
341
|
+
args: effectiveArgs,
|
|
342
|
+
result,
|
|
343
|
+
threadId: options.threadId,
|
|
344
|
+
turn,
|
|
345
|
+
durationMs
|
|
346
|
+
});
|
|
347
|
+
}
|
|
270
348
|
if (options.hooks?.onPostToolUse) {
|
|
271
|
-
const durationMs = Date.now() - startTime;
|
|
272
349
|
await options.hooks.onPostToolUse({
|
|
273
350
|
toolCall,
|
|
274
351
|
result: toolResult,
|
|
@@ -349,12 +426,12 @@ function createToolRouter(options) {
|
|
|
349
426
|
await appendToolResult({
|
|
350
427
|
threadId: options.threadId,
|
|
351
428
|
toolCallId: toolCall.id,
|
|
352
|
-
content: response.
|
|
429
|
+
content: response.toolResponse
|
|
353
430
|
});
|
|
354
431
|
return {
|
|
355
432
|
toolCallId: toolCall.id,
|
|
356
433
|
name: toolCall.name,
|
|
357
|
-
|
|
434
|
+
data: response.data ?? null
|
|
358
435
|
};
|
|
359
436
|
};
|
|
360
437
|
if (options.parallel) {
|
|
@@ -380,6 +457,12 @@ function createToolRouter(options) {
|
|
|
380
457
|
}
|
|
381
458
|
};
|
|
382
459
|
}
|
|
460
|
+
function defineTool(tool) {
|
|
461
|
+
return tool;
|
|
462
|
+
}
|
|
463
|
+
function defineSubagent(config) {
|
|
464
|
+
return config;
|
|
465
|
+
}
|
|
383
466
|
function hasNoOtherToolCalls(toolCalls, excludeName) {
|
|
384
467
|
return toolCalls.filter((tc) => tc.name !== excludeName).length === 0;
|
|
385
468
|
}
|
|
@@ -484,17 +567,47 @@ var createSession = async ({
|
|
|
484
567
|
return message;
|
|
485
568
|
}
|
|
486
569
|
const rawToolCalls = await parseToolCalls(message);
|
|
487
|
-
const parsedToolCalls =
|
|
488
|
-
const
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
570
|
+
const parsedToolCalls = [];
|
|
571
|
+
for (const tc of rawToolCalls.filter(
|
|
572
|
+
(tc2) => tc2.name !== "Task"
|
|
573
|
+
)) {
|
|
574
|
+
try {
|
|
575
|
+
parsedToolCalls.push(toolRouter.parseToolCall(tc));
|
|
576
|
+
} catch (error) {
|
|
577
|
+
await appendToolResult({
|
|
578
|
+
threadId,
|
|
579
|
+
toolCallId: tc.id ?? "",
|
|
580
|
+
content: JSON.stringify({
|
|
581
|
+
error: `Invalid tool call for "${tc.name}": ${error instanceof Error ? error.message : String(error)}`
|
|
582
|
+
})
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
const taskToolCalls = [];
|
|
587
|
+
if (subagents && subagents.length > 0) {
|
|
588
|
+
for (const tc of rawToolCalls.filter(
|
|
589
|
+
(tc2) => tc2.name === "Task"
|
|
590
|
+
)) {
|
|
591
|
+
try {
|
|
592
|
+
const parsedArgs = createTaskTool(subagents).schema.parse(
|
|
593
|
+
tc.args
|
|
594
|
+
);
|
|
595
|
+
taskToolCalls.push({
|
|
596
|
+
id: tc.id ?? "",
|
|
597
|
+
name: tc.name,
|
|
598
|
+
args: parsedArgs
|
|
599
|
+
});
|
|
600
|
+
} catch (error) {
|
|
601
|
+
await appendToolResult({
|
|
602
|
+
threadId,
|
|
603
|
+
toolCallId: tc.id ?? "",
|
|
604
|
+
content: JSON.stringify({
|
|
605
|
+
error: `Invalid tool call for "Task": ${error instanceof Error ? error.message : String(error)}`
|
|
606
|
+
})
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
}
|
|
498
611
|
await toolRouter.processToolCalls(
|
|
499
612
|
[...parsedToolCalls, ...taskToolCalls],
|
|
500
613
|
{
|
|
@@ -524,8 +637,6 @@ var createSession = async ({
|
|
|
524
637
|
function isTerminalStatus(status) {
|
|
525
638
|
return status === "COMPLETED" || status === "FAILED" || status === "CANCELLED";
|
|
526
639
|
}
|
|
527
|
-
|
|
528
|
-
// src/lib/state-manager.ts
|
|
529
640
|
var getStateQuery = defineQuery("getState");
|
|
530
641
|
function createAgentStateManager(initialState) {
|
|
531
642
|
let status = initialState?.status ?? "RUNNING";
|
|
@@ -620,7 +731,13 @@ function createAgentStateManager(initialState) {
|
|
|
620
731
|
version++;
|
|
621
732
|
},
|
|
622
733
|
setTools(newTools) {
|
|
623
|
-
tools = newTools
|
|
734
|
+
tools = newTools.map((tool) => ({
|
|
735
|
+
name: tool.name,
|
|
736
|
+
description: tool.description,
|
|
737
|
+
schema: z.toJSONSchema(tool.schema),
|
|
738
|
+
strict: tool.strict,
|
|
739
|
+
max_uses: tool.max_uses
|
|
740
|
+
}));
|
|
624
741
|
},
|
|
625
742
|
deleteTask(id) {
|
|
626
743
|
const deleted = tasks.delete(id);
|
|
@@ -651,18 +768,18 @@ Usage notes:
|
|
|
651
768
|
* Use multiSelect: true to allow multiple answers to be selected for a question
|
|
652
769
|
* If you recommend a specific option, make that the first option in the list and add "(Recommended)" at the end of the label
|
|
653
770
|
`,
|
|
654
|
-
schema:
|
|
655
|
-
questions:
|
|
656
|
-
|
|
657
|
-
question:
|
|
658
|
-
header:
|
|
659
|
-
options:
|
|
660
|
-
|
|
661
|
-
label:
|
|
662
|
-
description:
|
|
771
|
+
schema: z5.object({
|
|
772
|
+
questions: z5.array(
|
|
773
|
+
z5.object({
|
|
774
|
+
question: z5.string().describe("The full question text to display"),
|
|
775
|
+
header: z5.string().describe("Short label for the question (max 12 characters)"),
|
|
776
|
+
options: z5.array(
|
|
777
|
+
z5.object({
|
|
778
|
+
label: z5.string(),
|
|
779
|
+
description: z5.string()
|
|
663
780
|
})
|
|
664
781
|
).min(0).max(4).describe("Array of 0-4 choices, each with label and description"),
|
|
665
|
-
multiSelect:
|
|
782
|
+
multiSelect: z5.boolean().describe("If true, users can select multiple options")
|
|
666
783
|
})
|
|
667
784
|
)
|
|
668
785
|
}),
|
|
@@ -783,15 +900,10 @@ IMPORTANT:
|
|
|
783
900
|
}),
|
|
784
901
|
strict: true
|
|
785
902
|
};
|
|
786
|
-
|
|
787
|
-
// src/tools/task-create/handler.ts
|
|
788
|
-
function createTaskCreateHandler({
|
|
789
|
-
stateManager,
|
|
790
|
-
idGenerator
|
|
791
|
-
}) {
|
|
903
|
+
function createTaskCreateHandler(stateManager) {
|
|
792
904
|
return (args) => {
|
|
793
905
|
const task = {
|
|
794
|
-
id:
|
|
906
|
+
id: uuid4(),
|
|
795
907
|
subject: args.subject,
|
|
796
908
|
description: args.description,
|
|
797
909
|
activeForm: args.activeForm,
|
|
@@ -802,16 +914,16 @@ function createTaskCreateHandler({
|
|
|
802
914
|
};
|
|
803
915
|
stateManager.setTask(task);
|
|
804
916
|
return {
|
|
805
|
-
|
|
806
|
-
|
|
917
|
+
toolResponse: JSON.stringify(task, null, 2),
|
|
918
|
+
data: task
|
|
807
919
|
};
|
|
808
920
|
};
|
|
809
921
|
}
|
|
810
922
|
var taskGetTool = {
|
|
811
923
|
name: "TaskGet",
|
|
812
924
|
description: `Retrieve full task details including dependencies.`,
|
|
813
|
-
schema:
|
|
814
|
-
taskId:
|
|
925
|
+
schema: z5.object({
|
|
926
|
+
taskId: z5.string().describe("The ID of the task to get")
|
|
815
927
|
})
|
|
816
928
|
};
|
|
817
929
|
|
|
@@ -821,20 +933,20 @@ function createTaskGetHandler(stateManager) {
|
|
|
821
933
|
const task = stateManager.getTask(args.taskId) ?? null;
|
|
822
934
|
if (!task) {
|
|
823
935
|
return {
|
|
824
|
-
|
|
825
|
-
|
|
936
|
+
toolResponse: JSON.stringify({ error: `Task not found: ${args.taskId}` }),
|
|
937
|
+
data: null
|
|
826
938
|
};
|
|
827
939
|
}
|
|
828
940
|
return {
|
|
829
|
-
|
|
830
|
-
|
|
941
|
+
toolResponse: JSON.stringify(task, null, 2),
|
|
942
|
+
data: task
|
|
831
943
|
};
|
|
832
944
|
};
|
|
833
945
|
}
|
|
834
946
|
var taskListTool = {
|
|
835
947
|
name: "TaskList",
|
|
836
948
|
description: `List all tasks with current state.`,
|
|
837
|
-
schema:
|
|
949
|
+
schema: z5.object({})
|
|
838
950
|
};
|
|
839
951
|
|
|
840
952
|
// src/tools/task-list/handler.ts
|
|
@@ -842,19 +954,19 @@ function createTaskListHandler(stateManager) {
|
|
|
842
954
|
return (_args) => {
|
|
843
955
|
const taskList = stateManager.getTasks();
|
|
844
956
|
return {
|
|
845
|
-
|
|
846
|
-
|
|
957
|
+
toolResponse: JSON.stringify(taskList, null, 2),
|
|
958
|
+
data: taskList
|
|
847
959
|
};
|
|
848
960
|
};
|
|
849
961
|
}
|
|
850
962
|
var taskUpdateTool = {
|
|
851
963
|
name: "TaskUpdate",
|
|
852
964
|
description: `Update status, add blockers, modify details.`,
|
|
853
|
-
schema:
|
|
854
|
-
taskId:
|
|
855
|
-
status:
|
|
856
|
-
addBlockedBy:
|
|
857
|
-
addBlocks:
|
|
965
|
+
schema: z5.object({
|
|
966
|
+
taskId: z5.string().describe("The ID of the task to get"),
|
|
967
|
+
status: z5.enum(["pending", "in_progress", "completed"]).describe("The status of the task"),
|
|
968
|
+
addBlockedBy: z5.array(z5.string()).describe("The IDs of the tasks that are blocking this task"),
|
|
969
|
+
addBlocks: z5.array(z5.string()).describe("The IDs of the tasks that this task is blocking")
|
|
858
970
|
})
|
|
859
971
|
};
|
|
860
972
|
|
|
@@ -864,8 +976,8 @@ function createTaskUpdateHandler(stateManager) {
|
|
|
864
976
|
const task = stateManager.getTask(args.taskId);
|
|
865
977
|
if (!task) {
|
|
866
978
|
return {
|
|
867
|
-
|
|
868
|
-
|
|
979
|
+
toolResponse: JSON.stringify({ error: `Task not found: ${args.taskId}` }),
|
|
980
|
+
data: null
|
|
869
981
|
};
|
|
870
982
|
}
|
|
871
983
|
if (args.status) {
|
|
@@ -897,8 +1009,8 @@ function createTaskUpdateHandler(stateManager) {
|
|
|
897
1009
|
}
|
|
898
1010
|
stateManager.setTask(task);
|
|
899
1011
|
return {
|
|
900
|
-
|
|
901
|
-
|
|
1012
|
+
toolResponse: JSON.stringify(task, null, 2),
|
|
1013
|
+
data: task
|
|
902
1014
|
};
|
|
903
1015
|
};
|
|
904
1016
|
}
|
|
@@ -1105,13 +1217,13 @@ var handleAskUserQuestionToolResult = async (args) => {
|
|
|
1105
1217
|
}
|
|
1106
1218
|
}).toDict()
|
|
1107
1219
|
);
|
|
1108
|
-
return {
|
|
1220
|
+
return { toolResponse: "Question submitted", data: { chatMessages: messages } };
|
|
1109
1221
|
};
|
|
1110
1222
|
async function globHandler(_args, fs) {
|
|
1111
1223
|
new Bash({ fs });
|
|
1112
1224
|
return Promise.resolve({
|
|
1113
|
-
|
|
1114
|
-
|
|
1225
|
+
toolResponse: "Hello, world!",
|
|
1226
|
+
data: { files: [] }
|
|
1115
1227
|
});
|
|
1116
1228
|
}
|
|
1117
1229
|
|
|
@@ -1123,8 +1235,8 @@ async function editHandler(args, fs) {
|
|
|
1123
1235
|
const { file_path, old_string, new_string, replace_all = false } = args;
|
|
1124
1236
|
if (old_string === new_string) {
|
|
1125
1237
|
return {
|
|
1126
|
-
|
|
1127
|
-
|
|
1238
|
+
toolResponse: `Error: old_string and new_string must be different.`,
|
|
1239
|
+
data: {
|
|
1128
1240
|
path: file_path,
|
|
1129
1241
|
success: false,
|
|
1130
1242
|
replacements: 0
|
|
@@ -1135,8 +1247,8 @@ async function editHandler(args, fs) {
|
|
|
1135
1247
|
const exists = await fs.exists(file_path);
|
|
1136
1248
|
if (!exists) {
|
|
1137
1249
|
return {
|
|
1138
|
-
|
|
1139
|
-
|
|
1250
|
+
toolResponse: `Error: File "${file_path}" does not exist.`,
|
|
1251
|
+
data: {
|
|
1140
1252
|
path: file_path,
|
|
1141
1253
|
success: false,
|
|
1142
1254
|
replacements: 0
|
|
@@ -1146,8 +1258,8 @@ async function editHandler(args, fs) {
|
|
|
1146
1258
|
const content = await fs.readFile(file_path);
|
|
1147
1259
|
if (!content.includes(old_string)) {
|
|
1148
1260
|
return {
|
|
1149
|
-
|
|
1150
|
-
|
|
1261
|
+
toolResponse: `Error: Could not find the specified text in "${file_path}". Make sure old_string matches exactly (whitespace-sensitive).`,
|
|
1262
|
+
data: {
|
|
1151
1263
|
path: file_path,
|
|
1152
1264
|
success: false,
|
|
1153
1265
|
replacements: 0
|
|
@@ -1159,8 +1271,8 @@ async function editHandler(args, fs) {
|
|
|
1159
1271
|
const occurrences = (content.match(globalRegex) || []).length;
|
|
1160
1272
|
if (!replace_all && occurrences > 1) {
|
|
1161
1273
|
return {
|
|
1162
|
-
|
|
1163
|
-
|
|
1274
|
+
toolResponse: `Error: old_string appears ${occurrences} times in "${file_path}". Either provide more context to make it unique, or use replace_all: true.`,
|
|
1275
|
+
data: {
|
|
1164
1276
|
path: file_path,
|
|
1165
1277
|
success: false,
|
|
1166
1278
|
replacements: 0
|
|
@@ -1180,8 +1292,8 @@ async function editHandler(args, fs) {
|
|
|
1180
1292
|
await fs.writeFile(file_path, newContent);
|
|
1181
1293
|
const summary = replace_all ? `Replaced ${replacements} occurrence(s)` : `Replaced 1 occurrence`;
|
|
1182
1294
|
return {
|
|
1183
|
-
|
|
1184
|
-
|
|
1295
|
+
toolResponse: `${summary} in ${file_path}`,
|
|
1296
|
+
data: {
|
|
1185
1297
|
path: file_path,
|
|
1186
1298
|
success: true,
|
|
1187
1299
|
replacements
|
|
@@ -1190,8 +1302,8 @@ async function editHandler(args, fs) {
|
|
|
1190
1302
|
} catch (error) {
|
|
1191
1303
|
const message = error instanceof Error ? error.message : "Unknown error";
|
|
1192
1304
|
return {
|
|
1193
|
-
|
|
1194
|
-
|
|
1305
|
+
toolResponse: `Error editing file "${file_path}": ${message}`,
|
|
1306
|
+
data: {
|
|
1195
1307
|
path: file_path,
|
|
1196
1308
|
success: false,
|
|
1197
1309
|
replacements: 0
|
|
@@ -1214,20 +1326,20 @@ var handleBashTool = (bashOptions) => async (args, _context) => {
|
|
|
1214
1326
|
const { exitCode, stderr, stdout } = await bash.exec(command);
|
|
1215
1327
|
const bashExecOut = { exitCode, stderr, stdout };
|
|
1216
1328
|
return {
|
|
1217
|
-
|
|
1329
|
+
toolResponse: `Exit code: ${exitCode}
|
|
1218
1330
|
|
|
1219
1331
|
stdout:
|
|
1220
1332
|
${stdout}
|
|
1221
1333
|
|
|
1222
1334
|
stderr:
|
|
1223
1335
|
${stderr}`,
|
|
1224
|
-
|
|
1336
|
+
data: bashExecOut
|
|
1225
1337
|
};
|
|
1226
1338
|
} catch (error) {
|
|
1227
1339
|
const err = error instanceof Error ? error : new Error("Unknown error");
|
|
1228
1340
|
return {
|
|
1229
|
-
|
|
1230
|
-
|
|
1341
|
+
toolResponse: `Error executing bash command: ${err.message}`,
|
|
1342
|
+
data: null
|
|
1231
1343
|
};
|
|
1232
1344
|
}
|
|
1233
1345
|
};
|
|
@@ -1296,6 +1408,6 @@ var toTree = async (fs, opts = {}) => {
|
|
|
1296
1408
|
return base + subtree;
|
|
1297
1409
|
};
|
|
1298
1410
|
|
|
1299
|
-
export { AGENT_HANDLER_NAMES, ZeitlichPlugin, askUserQuestionTool, bashTool, createAgentStateManager, createSession, createSharedActivities, createTaskCreateHandler, createTaskGetHandler, createTaskListHandler, createTaskTool, createTaskUpdateHandler, createToolRouter, editHandler, editTool, globHandler, globTool, grepTool, handleAskUserQuestionToolResult, handleBashTool, hasNoOtherToolCalls, invokeModel, isTerminalStatus, readTool, taskCreateTool, taskGetTool, taskListTool, taskUpdateTool, toTree, writeTool };
|
|
1411
|
+
export { AGENT_HANDLER_NAMES, ZeitlichPlugin, askUserQuestionTool, bashTool, createAgentStateManager, createSession, createSharedActivities, createTaskCreateHandler, createTaskGetHandler, createTaskListHandler, createTaskTool, createTaskUpdateHandler, createThreadManager, createToolRouter, defineSubagent, defineTool, editHandler, editTool, getStateQuery, globHandler, globTool, grepTool, handleAskUserQuestionToolResult, handleBashTool, hasNoOtherToolCalls, invokeModel, isTerminalStatus, readTool, taskCreateTool, taskGetTool, taskListTool, taskUpdateTool, toTree, writeTool };
|
|
1300
1412
|
//# sourceMappingURL=index.js.map
|
|
1301
1413
|
//# sourceMappingURL=index.js.map
|