zeitlich 0.2.6 → 0.2.8
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/index.cjs +200 -119
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -11
- package/dist/index.d.ts +4 -11
- package/dist/index.js +179 -97
- package/dist/index.js.map +1 -1
- package/dist/{workflow-Dg5JMeOC.d.cts → workflow-BdAuMMjY.d.cts} +129 -37
- package/dist/{workflow-Dg5JMeOC.d.ts → workflow-BdAuMMjY.d.ts} +129 -37
- package/dist/workflow.cjs +195 -101
- package/dist/workflow.cjs.map +1 -1
- package/dist/workflow.d.cts +1 -1
- package/dist/workflow.d.ts +1 -1
- package/dist/workflow.js +172 -79
- package/dist/workflow.js.map +1 -1
- package/package.json +4 -4
- package/src/index.ts +0 -2
- package/src/lib/model-invoker.ts +9 -6
- package/src/lib/session.ts +86 -15
- package/src/lib/state-manager.ts +84 -7
- package/src/lib/tool-router.ts +12 -10
- package/src/lib/types.ts +74 -11
- package/src/tools/ask-user-question/handler.ts +19 -20
- package/src/tools/subagent/handler.ts +2 -1
- package/src/workflow.ts +5 -3
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var workflow = require('@temporalio/workflow');
|
|
4
|
-
var
|
|
4
|
+
var z13 = require('zod');
|
|
5
5
|
var plugin = require('@temporalio/plugin');
|
|
6
6
|
var messages = require('@langchain/core/messages');
|
|
7
7
|
var crypto = require('crypto');
|
|
@@ -10,7 +10,7 @@ var justBash = require('just-bash');
|
|
|
10
10
|
|
|
11
11
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
12
|
|
|
13
|
-
var
|
|
13
|
+
var z13__default = /*#__PURE__*/_interopDefault(z13);
|
|
14
14
|
var crypto__default = /*#__PURE__*/_interopDefault(crypto);
|
|
15
15
|
|
|
16
16
|
// src/lib/session.ts
|
|
@@ -46,10 +46,10 @@ function createSubagentTool(subagents) {
|
|
|
46
46
|
return {
|
|
47
47
|
name: SUBAGENT_TOOL,
|
|
48
48
|
description: buildSubagentDescription(subagents),
|
|
49
|
-
schema:
|
|
50
|
-
subagent:
|
|
51
|
-
description:
|
|
52
|
-
prompt:
|
|
49
|
+
schema: z13__default.default.object({
|
|
50
|
+
subagent: z13__default.default.enum(names).describe("The type of subagent to launch"),
|
|
51
|
+
description: z13__default.default.string().describe("A short (3-5 word) description of the task"),
|
|
52
|
+
prompt: z13__default.default.string().describe("The task for the agent to perform")
|
|
53
53
|
})
|
|
54
54
|
};
|
|
55
55
|
}
|
|
@@ -72,11 +72,12 @@ function createSubagentHandler(subagents) {
|
|
|
72
72
|
args: [input],
|
|
73
73
|
taskQueue: config.taskQueue ?? parentTaskQueue
|
|
74
74
|
};
|
|
75
|
-
const { toolResponse, data } = typeof config.workflow === "string" ? await workflow.executeChild(config.workflow, childOpts) : await workflow.executeChild(config.workflow, childOpts);
|
|
75
|
+
const { toolResponse, data, usage } = typeof config.workflow === "string" ? await workflow.executeChild(config.workflow, childOpts) : await workflow.executeChild(config.workflow, childOpts);
|
|
76
76
|
const validated = config.resultSchema ? config.resultSchema.parse(data) : null;
|
|
77
77
|
return {
|
|
78
78
|
toolResponse,
|
|
79
|
-
data: validated
|
|
79
|
+
data: validated,
|
|
80
|
+
...usage && { usage }
|
|
80
81
|
};
|
|
81
82
|
};
|
|
82
83
|
}
|
|
@@ -88,20 +89,17 @@ function createToolRouter(options) {
|
|
|
88
89
|
for (const [_key, tool] of Object.entries(options.tools)) {
|
|
89
90
|
toolMap.set(tool.name, tool);
|
|
90
91
|
}
|
|
91
|
-
const isEnabled = (tool) => tool.enabled
|
|
92
|
+
const isEnabled = (tool) => tool.enabled?.() ?? true;
|
|
92
93
|
if (options.subagents) {
|
|
93
|
-
|
|
94
|
-
(s) => s.enabled !== false
|
|
95
|
-
);
|
|
96
|
-
if (enabledSubagents.length > 0) {
|
|
94
|
+
if (options.subagents.length > 0) {
|
|
97
95
|
const subagentHooksMap = /* @__PURE__ */ new Map();
|
|
98
|
-
for (const s of
|
|
96
|
+
for (const s of options.subagents) {
|
|
99
97
|
if (s.hooks) subagentHooksMap.set(s.agentName, s.hooks);
|
|
100
98
|
}
|
|
101
99
|
const resolveSubagentName = (args) => args.subagent;
|
|
102
100
|
toolMap.set("Subagent", {
|
|
103
|
-
...createSubagentTool(
|
|
104
|
-
handler: createSubagentHandler(
|
|
101
|
+
...createSubagentTool(options.subagents),
|
|
102
|
+
handler: createSubagentHandler(options.subagents),
|
|
105
103
|
...subagentHooksMap.size > 0 && {
|
|
106
104
|
hooks: {
|
|
107
105
|
onPreToolUse: async (ctx) => {
|
|
@@ -411,6 +409,7 @@ function hasNoOtherToolCalls(toolCalls, excludeName) {
|
|
|
411
409
|
var createSession = async ({
|
|
412
410
|
threadId,
|
|
413
411
|
agentName,
|
|
412
|
+
description,
|
|
414
413
|
maxTurns = 50,
|
|
415
414
|
metadata = {},
|
|
416
415
|
runAgent,
|
|
@@ -421,7 +420,8 @@ var createSession = async ({
|
|
|
421
420
|
processToolsInParallel = true,
|
|
422
421
|
hooks = {},
|
|
423
422
|
appendSystemPrompt = true,
|
|
424
|
-
systemPrompt
|
|
423
|
+
systemPrompt,
|
|
424
|
+
waitForInputTimeout = "48h"
|
|
425
425
|
}) => {
|
|
426
426
|
const {
|
|
427
427
|
appendToolResult,
|
|
@@ -449,7 +449,28 @@ var createSession = async ({
|
|
|
449
449
|
}
|
|
450
450
|
};
|
|
451
451
|
return {
|
|
452
|
-
runSession: async ({
|
|
452
|
+
runSession: async ({
|
|
453
|
+
stateManager
|
|
454
|
+
}) => {
|
|
455
|
+
workflow.setHandler(
|
|
456
|
+
workflow.defineUpdate(`add${agentName}Message`),
|
|
457
|
+
async (message) => {
|
|
458
|
+
if (hooks.onPreHumanMessageAppend) {
|
|
459
|
+
await hooks.onPreHumanMessageAppend({
|
|
460
|
+
message,
|
|
461
|
+
threadId
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
await appendHumanMessage(threadId, message);
|
|
465
|
+
if (hooks.onPostHumanMessageAppend) {
|
|
466
|
+
await hooks.onPostHumanMessageAppend({
|
|
467
|
+
message,
|
|
468
|
+
threadId
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
stateManager.run();
|
|
472
|
+
}
|
|
473
|
+
);
|
|
453
474
|
if (hooks.onSessionStart) {
|
|
454
475
|
await hooks.onSessionStart({
|
|
455
476
|
threadId,
|
|
@@ -457,7 +478,6 @@ var createSession = async ({
|
|
|
457
478
|
metadata
|
|
458
479
|
});
|
|
459
480
|
}
|
|
460
|
-
stateManager.setTools(toolRouter.getToolDefinitions());
|
|
461
481
|
await initializeThread(threadId);
|
|
462
482
|
if (appendSystemPrompt && systemPrompt && systemPrompt.trim() !== "") {
|
|
463
483
|
await appendSystemMessage(threadId, systemPrompt);
|
|
@@ -468,15 +488,25 @@ var createSession = async ({
|
|
|
468
488
|
while (stateManager.isRunning() && !stateManager.isTerminal() && stateManager.getTurns() < maxTurns) {
|
|
469
489
|
stateManager.incrementTurns();
|
|
470
490
|
const currentTurn = stateManager.getTurns();
|
|
471
|
-
|
|
491
|
+
stateManager.setTools(toolRouter.getToolDefinitions());
|
|
492
|
+
const { message, rawToolCalls, usage } = await runAgent({
|
|
472
493
|
threadId,
|
|
473
494
|
agentName,
|
|
474
|
-
metadata
|
|
495
|
+
metadata,
|
|
496
|
+
systemPrompt,
|
|
497
|
+
description
|
|
475
498
|
});
|
|
499
|
+
if (usage) {
|
|
500
|
+
stateManager.updateUsage(usage);
|
|
501
|
+
}
|
|
476
502
|
if (!toolRouter.hasTools() || rawToolCalls.length === 0) {
|
|
477
503
|
stateManager.complete();
|
|
478
504
|
exitReason = "completed";
|
|
479
|
-
return
|
|
505
|
+
return {
|
|
506
|
+
finalMessage: message,
|
|
507
|
+
exitReason,
|
|
508
|
+
usage: stateManager.getTotalUsage()
|
|
509
|
+
};
|
|
480
510
|
}
|
|
481
511
|
const parsedToolCalls = [];
|
|
482
512
|
for (const tc of rawToolCalls) {
|
|
@@ -493,12 +523,27 @@ var createSession = async ({
|
|
|
493
523
|
});
|
|
494
524
|
}
|
|
495
525
|
}
|
|
496
|
-
await toolRouter.processToolCalls(
|
|
497
|
-
|
|
498
|
-
|
|
526
|
+
const toolCallResults = await toolRouter.processToolCalls(
|
|
527
|
+
parsedToolCalls,
|
|
528
|
+
{
|
|
529
|
+
turn: currentTurn
|
|
530
|
+
}
|
|
531
|
+
);
|
|
532
|
+
for (const result of toolCallResults) {
|
|
533
|
+
if (result.usage) {
|
|
534
|
+
stateManager.updateUsage(result.usage);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
499
537
|
if (stateManager.getStatus() === "WAITING_FOR_INPUT") {
|
|
500
|
-
|
|
501
|
-
|
|
538
|
+
const conditionMet = await workflow.condition(
|
|
539
|
+
() => stateManager.getStatus() === "RUNNING",
|
|
540
|
+
waitForInputTimeout
|
|
541
|
+
);
|
|
542
|
+
if (!conditionMet) {
|
|
543
|
+
stateManager.cancel();
|
|
544
|
+
await workflow.condition(() => false, "2s");
|
|
545
|
+
break;
|
|
546
|
+
}
|
|
502
547
|
}
|
|
503
548
|
}
|
|
504
549
|
if (stateManager.getTurns() >= maxTurns && stateManager.isRunning()) {
|
|
@@ -510,7 +555,11 @@ var createSession = async ({
|
|
|
510
555
|
} finally {
|
|
511
556
|
await callSessionEnd(exitReason, stateManager.getTurns());
|
|
512
557
|
}
|
|
513
|
-
return
|
|
558
|
+
return {
|
|
559
|
+
finalMessage: null,
|
|
560
|
+
exitReason,
|
|
561
|
+
usage: stateManager.getTotalUsage()
|
|
562
|
+
};
|
|
514
563
|
}
|
|
515
564
|
};
|
|
516
565
|
};
|
|
@@ -539,12 +588,19 @@ function proxyDefaultThreadOps(options) {
|
|
|
539
588
|
function isTerminalStatus(status) {
|
|
540
589
|
return status === "COMPLETED" || status === "FAILED" || status === "CANCELLED";
|
|
541
590
|
}
|
|
542
|
-
|
|
543
|
-
|
|
591
|
+
function createAgentStateManager({
|
|
592
|
+
initialState,
|
|
593
|
+
agentConfig
|
|
594
|
+
}) {
|
|
544
595
|
let status = initialState?.status ?? "RUNNING";
|
|
545
596
|
let version = initialState?.version ?? 0;
|
|
546
597
|
let turns = initialState?.turns ?? 0;
|
|
547
598
|
let tools = initialState?.tools ?? [];
|
|
599
|
+
let totalInputTokens = 0;
|
|
600
|
+
let totalOutputTokens = 0;
|
|
601
|
+
let totalCachedWriteTokens = 0;
|
|
602
|
+
let totalCachedReadTokens = 0;
|
|
603
|
+
let totalReasonTokens = 0;
|
|
548
604
|
const tasks = new Map(initialState?.tasks);
|
|
549
605
|
const {
|
|
550
606
|
status: _,
|
|
@@ -564,9 +620,21 @@ function createAgentStateManager(initialState) {
|
|
|
564
620
|
...customState
|
|
565
621
|
};
|
|
566
622
|
}
|
|
567
|
-
workflow.setHandler(
|
|
623
|
+
workflow.setHandler(workflow.defineQuery(`get${agentConfig.agentName}State`), () => {
|
|
568
624
|
return buildState();
|
|
569
625
|
});
|
|
626
|
+
workflow.setHandler(
|
|
627
|
+
workflow.defineUpdate(
|
|
628
|
+
`waitFor${agentConfig.agentName}StateChange`
|
|
629
|
+
),
|
|
630
|
+
async (lastKnownVersion) => {
|
|
631
|
+
await workflow.condition(
|
|
632
|
+
() => version > lastKnownVersion || isTerminalStatus(status),
|
|
633
|
+
"55s"
|
|
634
|
+
);
|
|
635
|
+
return buildState();
|
|
636
|
+
}
|
|
637
|
+
);
|
|
570
638
|
return {
|
|
571
639
|
getStatus() {
|
|
572
640
|
return status;
|
|
@@ -636,7 +704,7 @@ function createAgentStateManager(initialState) {
|
|
|
636
704
|
tools = newTools.map((tool) => ({
|
|
637
705
|
name: tool.name,
|
|
638
706
|
description: tool.description,
|
|
639
|
-
schema:
|
|
707
|
+
schema: z13.z.toJSONSchema(tool.schema),
|
|
640
708
|
strict: tool.strict,
|
|
641
709
|
max_uses: tool.max_uses
|
|
642
710
|
}));
|
|
@@ -647,6 +715,23 @@ function createAgentStateManager(initialState) {
|
|
|
647
715
|
version++;
|
|
648
716
|
}
|
|
649
717
|
return deleted;
|
|
718
|
+
},
|
|
719
|
+
updateUsage(usage) {
|
|
720
|
+
totalInputTokens += usage.inputTokens ?? 0;
|
|
721
|
+
totalOutputTokens += usage.outputTokens ?? 0;
|
|
722
|
+
totalCachedWriteTokens += usage.cachedWriteTokens ?? 0;
|
|
723
|
+
totalCachedReadTokens += usage.cachedReadTokens ?? 0;
|
|
724
|
+
totalReasonTokens += usage.reasonTokens ?? 0;
|
|
725
|
+
},
|
|
726
|
+
getTotalUsage() {
|
|
727
|
+
return {
|
|
728
|
+
totalInputTokens,
|
|
729
|
+
totalOutputTokens,
|
|
730
|
+
totalCachedWriteTokens,
|
|
731
|
+
totalCachedReadTokens,
|
|
732
|
+
totalReasonTokens,
|
|
733
|
+
turns
|
|
734
|
+
};
|
|
650
735
|
}
|
|
651
736
|
};
|
|
652
737
|
}
|
|
@@ -655,38 +740,6 @@ var AGENT_HANDLER_NAMES = {
|
|
|
655
740
|
waitForStateChange: "waitForStateChange",
|
|
656
741
|
addMessage: "addMessage"
|
|
657
742
|
};
|
|
658
|
-
var askUserQuestionTool = {
|
|
659
|
-
name: "AskUserQuestion",
|
|
660
|
-
description: `Use this tool when you need to ask the user questions during execution. This allows you to:
|
|
661
|
-
|
|
662
|
-
1. Gather user preferences or requirements
|
|
663
|
-
2. Clarify ambiguous instructions
|
|
664
|
-
3. Get decisions on implementation choices as you work
|
|
665
|
-
4. Offer choices to the user about what direction to take.
|
|
666
|
-
|
|
667
|
-
Usage notes:
|
|
668
|
-
|
|
669
|
-
* Users will always be able to select "Other" to provide custom text input
|
|
670
|
-
* Use multiSelect: true to allow multiple answers to be selected for a question
|
|
671
|
-
* If you recommend a specific option, make that the first option in the list and add "(Recommended)" at the end of the label
|
|
672
|
-
`,
|
|
673
|
-
schema: z3__default.default.object({
|
|
674
|
-
questions: z3__default.default.array(
|
|
675
|
-
z3__default.default.object({
|
|
676
|
-
question: z3__default.default.string().describe("The full question text to display"),
|
|
677
|
-
header: z3__default.default.string().describe("Short label for the question (max 12 characters)"),
|
|
678
|
-
options: z3__default.default.array(
|
|
679
|
-
z3__default.default.object({
|
|
680
|
-
label: z3__default.default.string(),
|
|
681
|
-
description: z3__default.default.string()
|
|
682
|
-
})
|
|
683
|
-
).min(0).max(4).describe("Array of 0-4 choices, each with label and description"),
|
|
684
|
-
multiSelect: z3__default.default.boolean().describe("If true, users can select multiple options")
|
|
685
|
-
})
|
|
686
|
-
)
|
|
687
|
-
}),
|
|
688
|
-
strict: true
|
|
689
|
-
};
|
|
690
743
|
var globTool = {
|
|
691
744
|
name: "Glob",
|
|
692
745
|
description: `Search for files matching a glob pattern within the available file system.
|
|
@@ -701,9 +754,9 @@ Examples:
|
|
|
701
754
|
- "**/*.test.ts" - Find all test files recursively
|
|
702
755
|
- "src/**/*.ts" - Find all TypeScript files in src directory
|
|
703
756
|
`,
|
|
704
|
-
schema:
|
|
705
|
-
pattern:
|
|
706
|
-
root:
|
|
757
|
+
schema: z13.z.object({
|
|
758
|
+
pattern: z13.z.string().describe("Glob pattern to match files against"),
|
|
759
|
+
root: z13.z.string().optional().describe("Optional root directory to search from")
|
|
707
760
|
}),
|
|
708
761
|
strict: true
|
|
709
762
|
};
|
|
@@ -721,13 +774,13 @@ Examples:
|
|
|
721
774
|
- Search for function definitions with "function.*handleClick"
|
|
722
775
|
- Search case-insensitively with ignoreCase: true
|
|
723
776
|
`,
|
|
724
|
-
schema:
|
|
725
|
-
pattern:
|
|
726
|
-
ignoreCase:
|
|
727
|
-
maxMatches:
|
|
728
|
-
includePatterns:
|
|
729
|
-
excludePatterns:
|
|
730
|
-
contextLines:
|
|
777
|
+
schema: z13.z.object({
|
|
778
|
+
pattern: z13.z.string().describe("Regex pattern to search for in file contents"),
|
|
779
|
+
ignoreCase: z13.z.boolean().optional().describe("Case-insensitive search (default: false)"),
|
|
780
|
+
maxMatches: z13.z.number().optional().describe("Maximum number of matches to return (default: 50)"),
|
|
781
|
+
includePatterns: z13.z.array(z13.z.string()).optional().describe("Glob patterns to include (e.g., ['*.ts', '*.js'])"),
|
|
782
|
+
excludePatterns: z13.z.array(z13.z.string()).optional().describe("Glob patterns to exclude (e.g., ['*.test.ts'])"),
|
|
783
|
+
contextLines: z13.z.number().optional().describe("Number of context lines to show around matches")
|
|
731
784
|
}),
|
|
732
785
|
strict: true
|
|
733
786
|
};
|
|
@@ -745,12 +798,12 @@ The tool returns the file content in an appropriate format:
|
|
|
745
798
|
- Images: Base64-encoded image data
|
|
746
799
|
- PDFs: Extracted text content
|
|
747
800
|
`,
|
|
748
|
-
schema:
|
|
749
|
-
path:
|
|
750
|
-
offset:
|
|
801
|
+
schema: z13.z.object({
|
|
802
|
+
path: z13.z.string().describe("Virtual path to the file to read"),
|
|
803
|
+
offset: z13.z.number().optional().describe(
|
|
751
804
|
"Line number to start reading from (1-indexed, for text files)"
|
|
752
805
|
),
|
|
753
|
-
limit:
|
|
806
|
+
limit: z13.z.number().optional().describe("Maximum number of lines to read (for text files)")
|
|
754
807
|
}),
|
|
755
808
|
strict: true
|
|
756
809
|
};
|
|
@@ -768,9 +821,9 @@ IMPORTANT:
|
|
|
768
821
|
- This is an atomic write operation - the entire file is replaced
|
|
769
822
|
- Path must be absolute (e.g., "/docs/readme.md", not "docs/readme.md")
|
|
770
823
|
`,
|
|
771
|
-
schema:
|
|
772
|
-
file_path:
|
|
773
|
-
content:
|
|
824
|
+
schema: z13.z.object({
|
|
825
|
+
file_path: z13.z.string().describe("The absolute path to the file to write"),
|
|
826
|
+
content: z13.z.string().describe("The content to write to the file")
|
|
774
827
|
}),
|
|
775
828
|
strict: true
|
|
776
829
|
};
|
|
@@ -790,13 +843,13 @@ IMPORTANT:
|
|
|
790
843
|
- The operation fails if old_string is not found
|
|
791
844
|
- old_string and new_string must be different
|
|
792
845
|
`,
|
|
793
|
-
schema:
|
|
794
|
-
file_path:
|
|
795
|
-
old_string:
|
|
796
|
-
new_string:
|
|
846
|
+
schema: z13.z.object({
|
|
847
|
+
file_path: z13.z.string().describe("The absolute virtual path to the file to modify"),
|
|
848
|
+
old_string: z13.z.string().describe("The exact text to replace"),
|
|
849
|
+
new_string: z13.z.string().describe(
|
|
797
850
|
"The text to replace it with (must be different from old_string)"
|
|
798
851
|
),
|
|
799
|
-
replace_all:
|
|
852
|
+
replace_all: z13.z.boolean().optional().describe(
|
|
800
853
|
"If true, replace all occurrences of old_string (default: false)"
|
|
801
854
|
)
|
|
802
855
|
}),
|
|
@@ -843,17 +896,17 @@ var taskCreateTool = {
|
|
|
843
896
|
- Include enough detail in the description for another agent to understand and complete the task
|
|
844
897
|
- After creating tasks, use TaskUpdate to set up dependencies (blocks/blockedBy) if needed
|
|
845
898
|
- Check TaskList first to avoid creating duplicate tasks`,
|
|
846
|
-
schema:
|
|
847
|
-
subject:
|
|
899
|
+
schema: z13__default.default.object({
|
|
900
|
+
subject: z13__default.default.string().describe(
|
|
848
901
|
'A brief, actionable title in imperative form (e.g., "Fix authentication bug in login flow")'
|
|
849
902
|
),
|
|
850
|
-
description:
|
|
903
|
+
description: z13__default.default.string().describe(
|
|
851
904
|
"Detailed description of what needs to be done, including context and acceptance criteria"
|
|
852
905
|
),
|
|
853
|
-
activeForm:
|
|
906
|
+
activeForm: z13__default.default.string().describe(
|
|
854
907
|
'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.'
|
|
855
908
|
),
|
|
856
|
-
metadata:
|
|
909
|
+
metadata: z13__default.default.record(z13__default.default.string(), z13__default.default.string()).describe("Arbitrary key-value pairs for tracking")
|
|
857
910
|
})
|
|
858
911
|
};
|
|
859
912
|
function createTaskCreateHandler(stateManager) {
|
|
@@ -878,8 +931,8 @@ function createTaskCreateHandler(stateManager) {
|
|
|
878
931
|
var taskGetTool = {
|
|
879
932
|
name: "TaskGet",
|
|
880
933
|
description: `Retrieve full task details including dependencies.`,
|
|
881
|
-
schema:
|
|
882
|
-
taskId:
|
|
934
|
+
schema: z13__default.default.object({
|
|
935
|
+
taskId: z13__default.default.string().describe("The ID of the task to get")
|
|
883
936
|
})
|
|
884
937
|
};
|
|
885
938
|
|
|
@@ -902,7 +955,7 @@ function createTaskGetHandler(stateManager) {
|
|
|
902
955
|
var taskListTool = {
|
|
903
956
|
name: "TaskList",
|
|
904
957
|
description: `List all tasks with current state.`,
|
|
905
|
-
schema:
|
|
958
|
+
schema: z13__default.default.object({})
|
|
906
959
|
};
|
|
907
960
|
|
|
908
961
|
// src/tools/task-list/handler.ts
|
|
@@ -918,11 +971,11 @@ function createTaskListHandler(stateManager) {
|
|
|
918
971
|
var taskUpdateTool = {
|
|
919
972
|
name: "TaskUpdate",
|
|
920
973
|
description: `Update status, add blockers, modify details.`,
|
|
921
|
-
schema:
|
|
922
|
-
taskId:
|
|
923
|
-
status:
|
|
924
|
-
addBlockedBy:
|
|
925
|
-
addBlocks:
|
|
974
|
+
schema: z13__default.default.object({
|
|
975
|
+
taskId: z13__default.default.string().describe("The ID of the task to get"),
|
|
976
|
+
status: z13__default.default.enum(["pending", "in_progress", "completed"]).describe("The status of the task"),
|
|
977
|
+
addBlockedBy: z13__default.default.array(z13__default.default.string()).describe("The IDs of the tasks that are blocking this task"),
|
|
978
|
+
addBlocks: z13__default.default.array(z13__default.default.string()).describe("The IDs of the tasks that this task is blocking")
|
|
926
979
|
})
|
|
927
980
|
};
|
|
928
981
|
|
|
@@ -990,13 +1043,53 @@ Use this tool to:
|
|
|
990
1043
|
- Execute scripts and chain commands with pipes (|) or logical operators (&&, ||)
|
|
991
1044
|
- Inspect files and directories
|
|
992
1045
|
`,
|
|
993
|
-
schema:
|
|
994
|
-
command:
|
|
1046
|
+
schema: z13__default.default.object({
|
|
1047
|
+
command: z13__default.default.string().describe(
|
|
995
1048
|
"The bash command to execute. Can include pipes (|), redirects (>, >>), logical operators (&&, ||), and shell features like command substitution $(...)."
|
|
996
1049
|
)
|
|
997
1050
|
}),
|
|
998
1051
|
strict: true
|
|
999
1052
|
};
|
|
1053
|
+
var askUserQuestionTool = {
|
|
1054
|
+
name: "AskUserQuestion",
|
|
1055
|
+
description: `Use this tool when you need to ask the user questions during execution. This allows you to:
|
|
1056
|
+
|
|
1057
|
+
1. Gather user preferences or requirements
|
|
1058
|
+
2. Clarify ambiguous instructions
|
|
1059
|
+
3. Get decisions on implementation choices as you work
|
|
1060
|
+
4. Offer choices to the user about what direction to take.
|
|
1061
|
+
|
|
1062
|
+
Usage notes:
|
|
1063
|
+
|
|
1064
|
+
* Users will always be able to select "Other" to provide custom text input
|
|
1065
|
+
* Use multiSelect: true to allow multiple answers to be selected for a question
|
|
1066
|
+
* If you recommend a specific option, make that the first option in the list and add "(Recommended)" at the end of the label
|
|
1067
|
+
`,
|
|
1068
|
+
schema: z13__default.default.object({
|
|
1069
|
+
questions: z13__default.default.array(
|
|
1070
|
+
z13__default.default.object({
|
|
1071
|
+
question: z13__default.default.string().describe("The full question text to display"),
|
|
1072
|
+
header: z13__default.default.string().describe("Short label for the question (max 12 characters)"),
|
|
1073
|
+
options: z13__default.default.array(
|
|
1074
|
+
z13__default.default.object({
|
|
1075
|
+
label: z13__default.default.string(),
|
|
1076
|
+
description: z13__default.default.string()
|
|
1077
|
+
})
|
|
1078
|
+
).min(0).max(4).describe("Array of 0-4 choices, each with label and description"),
|
|
1079
|
+
multiSelect: z13__default.default.boolean().describe("If true, users can select multiple options")
|
|
1080
|
+
})
|
|
1081
|
+
)
|
|
1082
|
+
}),
|
|
1083
|
+
strict: true
|
|
1084
|
+
};
|
|
1085
|
+
|
|
1086
|
+
// src/tools/ask-user-question/handler.ts
|
|
1087
|
+
var createAskUserQuestionHandler = () => (args) => {
|
|
1088
|
+
return {
|
|
1089
|
+
toolResponse: "Question submitted",
|
|
1090
|
+
data: { questions: args.questions }
|
|
1091
|
+
};
|
|
1092
|
+
};
|
|
1000
1093
|
|
|
1001
1094
|
// node_modules/uuid/dist/esm-node/stringify.js
|
|
1002
1095
|
var byteToHex = [];
|
|
@@ -1169,7 +1262,7 @@ async function invokeModel({
|
|
|
1169
1262
|
const parentWorkflowId = info.workflowExecution.workflowId;
|
|
1170
1263
|
const parentRunId = info.workflowExecution.runId;
|
|
1171
1264
|
const handle = client.getHandle(parentWorkflowId, parentRunId);
|
|
1172
|
-
const { tools } = await handle.query(
|
|
1265
|
+
const { tools } = await handle.query(`get${agentName}State`);
|
|
1173
1266
|
const messages$1 = await thread.load();
|
|
1174
1267
|
const response = await model.invoke(
|
|
1175
1268
|
[...messages.mapStoredMessagesToChatMessages(messages$1)],
|
|
@@ -1190,25 +1283,14 @@ async function invokeModel({
|
|
|
1190
1283
|
args: tc.args
|
|
1191
1284
|
})),
|
|
1192
1285
|
usage: {
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1286
|
+
inputTokens: response.usage_metadata?.input_tokens,
|
|
1287
|
+
outputTokens: response.usage_metadata?.output_tokens,
|
|
1288
|
+
reasonTokens: response.usage_metadata?.output_token_details?.reasoning,
|
|
1289
|
+
cachedWriteTokens: response.usage_metadata?.input_token_details?.cache_creation,
|
|
1290
|
+
cachedReadTokens: response.usage_metadata?.input_token_details?.cache_read
|
|
1196
1291
|
}
|
|
1197
1292
|
};
|
|
1198
1293
|
}
|
|
1199
|
-
var createAskUserQuestionHandler = () => async (args) => {
|
|
1200
|
-
const messages$1 = args.questions.map(
|
|
1201
|
-
({ question, header, options, multiSelect }) => new messages.AIMessage({
|
|
1202
|
-
content: question,
|
|
1203
|
-
additional_kwargs: {
|
|
1204
|
-
header,
|
|
1205
|
-
options,
|
|
1206
|
-
multiSelect
|
|
1207
|
-
}
|
|
1208
|
-
}).toDict()
|
|
1209
|
-
);
|
|
1210
|
-
return { toolResponse: "Question submitted", data: { chatMessages: messages$1 } };
|
|
1211
|
-
};
|
|
1212
1294
|
function createGlobHandler(fs) {
|
|
1213
1295
|
return async (_args) => {
|
|
1214
1296
|
new justBash.Bash({ fs });
|
|
@@ -1400,7 +1482,6 @@ exports.createToolRouter = createToolRouter;
|
|
|
1400
1482
|
exports.defineSubagent = defineSubagent;
|
|
1401
1483
|
exports.defineTool = defineTool;
|
|
1402
1484
|
exports.editTool = editTool;
|
|
1403
|
-
exports.getStateQuery = getStateQuery;
|
|
1404
1485
|
exports.globTool = globTool;
|
|
1405
1486
|
exports.grepTool = grepTool;
|
|
1406
1487
|
exports.hasNoOtherToolCalls = hasNoOtherToolCalls;
|