zeitlich 0.2.6 → 0.2.7
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 +132 -97
- 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 +111 -75
- package/dist/index.js.map +1 -1
- package/dist/{workflow-Dg5JMeOC.d.cts → workflow-CyYHDbrr.d.cts} +86 -26
- package/dist/{workflow-Dg5JMeOC.d.ts → workflow-CyYHDbrr.d.ts} +86 -26
- package/dist/workflow.cjs +132 -82
- 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 +109 -60
- package/dist/workflow.js.map +1 -1
- package/package.json +4 -4
- package/src/index.ts +0 -2
- package/src/lib/model-invoker.ts +2 -3
- package/src/lib/session.ts +42 -5
- package/src/lib/state-manager.ts +28 -7
- package/src/lib/types.ts +56 -3
- package/src/tools/ask-user-question/handler.ts +19 -20
- package/src/workflow.ts +5 -3
package/dist/workflow.cjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var workflow = require('@temporalio/workflow');
|
|
4
|
-
var
|
|
4
|
+
var z13 = require('zod');
|
|
5
5
|
|
|
6
6
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var z13__default = /*#__PURE__*/_interopDefault(z13);
|
|
9
9
|
|
|
10
10
|
// src/lib/session.ts
|
|
11
11
|
var SUBAGENT_TOOL = "Subagent";
|
|
@@ -40,10 +40,10 @@ function createSubagentTool(subagents) {
|
|
|
40
40
|
return {
|
|
41
41
|
name: SUBAGENT_TOOL,
|
|
42
42
|
description: buildSubagentDescription(subagents),
|
|
43
|
-
schema:
|
|
44
|
-
subagent:
|
|
45
|
-
description:
|
|
46
|
-
prompt:
|
|
43
|
+
schema: z13__default.default.object({
|
|
44
|
+
subagent: z13__default.default.enum(names).describe("The type of subagent to launch"),
|
|
45
|
+
description: z13__default.default.string().describe("A short (3-5 word) description of the task"),
|
|
46
|
+
prompt: z13__default.default.string().describe("The task for the agent to perform")
|
|
47
47
|
})
|
|
48
48
|
};
|
|
49
49
|
}
|
|
@@ -396,7 +396,8 @@ var createSession = async ({
|
|
|
396
396
|
processToolsInParallel = true,
|
|
397
397
|
hooks = {},
|
|
398
398
|
appendSystemPrompt = true,
|
|
399
|
-
systemPrompt
|
|
399
|
+
systemPrompt,
|
|
400
|
+
waitForInputTimeout = "48h"
|
|
400
401
|
}) => {
|
|
401
402
|
const {
|
|
402
403
|
appendToolResult,
|
|
@@ -425,6 +426,25 @@ var createSession = async ({
|
|
|
425
426
|
};
|
|
426
427
|
return {
|
|
427
428
|
runSession: async ({ stateManager }) => {
|
|
429
|
+
workflow.setHandler(
|
|
430
|
+
workflow.defineUpdate(`add${agentName}Message`),
|
|
431
|
+
async (message) => {
|
|
432
|
+
if (hooks.onPreHumanMessageAppend) {
|
|
433
|
+
await hooks.onPreHumanMessageAppend({
|
|
434
|
+
message,
|
|
435
|
+
threadId
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
await appendHumanMessage(threadId, message);
|
|
439
|
+
if (hooks.onPostHumanMessageAppend) {
|
|
440
|
+
await hooks.onPostHumanMessageAppend({
|
|
441
|
+
message,
|
|
442
|
+
threadId
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
stateManager.run();
|
|
446
|
+
}
|
|
447
|
+
);
|
|
428
448
|
if (hooks.onSessionStart) {
|
|
429
449
|
await hooks.onSessionStart({
|
|
430
450
|
threadId,
|
|
@@ -472,8 +492,15 @@ var createSession = async ({
|
|
|
472
492
|
turn: currentTurn
|
|
473
493
|
});
|
|
474
494
|
if (stateManager.getStatus() === "WAITING_FOR_INPUT") {
|
|
475
|
-
|
|
476
|
-
|
|
495
|
+
const conditionMet = await workflow.condition(
|
|
496
|
+
() => stateManager.getStatus() === "RUNNING",
|
|
497
|
+
waitForInputTimeout
|
|
498
|
+
);
|
|
499
|
+
if (!conditionMet) {
|
|
500
|
+
stateManager.cancel();
|
|
501
|
+
await workflow.condition(() => false, "2s");
|
|
502
|
+
break;
|
|
503
|
+
}
|
|
477
504
|
}
|
|
478
505
|
}
|
|
479
506
|
if (stateManager.getTurns() >= maxTurns && stateManager.isRunning()) {
|
|
@@ -514,8 +541,10 @@ function proxyDefaultThreadOps(options) {
|
|
|
514
541
|
function isTerminalStatus(status) {
|
|
515
542
|
return status === "COMPLETED" || status === "FAILED" || status === "CANCELLED";
|
|
516
543
|
}
|
|
517
|
-
|
|
518
|
-
|
|
544
|
+
function createAgentStateManager({
|
|
545
|
+
initialState,
|
|
546
|
+
agentConfig
|
|
547
|
+
}) {
|
|
519
548
|
let status = initialState?.status ?? "RUNNING";
|
|
520
549
|
let version = initialState?.version ?? 0;
|
|
521
550
|
let turns = initialState?.turns ?? 0;
|
|
@@ -539,9 +568,21 @@ function createAgentStateManager(initialState) {
|
|
|
539
568
|
...customState
|
|
540
569
|
};
|
|
541
570
|
}
|
|
542
|
-
workflow.setHandler(
|
|
571
|
+
workflow.setHandler(workflow.defineQuery(`get${agentConfig.agentName}State`), () => {
|
|
543
572
|
return buildState();
|
|
544
573
|
});
|
|
574
|
+
workflow.setHandler(
|
|
575
|
+
workflow.defineUpdate(
|
|
576
|
+
`waitFor${agentConfig.agentName}StateChange`
|
|
577
|
+
),
|
|
578
|
+
async (lastKnownVersion) => {
|
|
579
|
+
await workflow.condition(
|
|
580
|
+
() => version > lastKnownVersion || isTerminalStatus(status),
|
|
581
|
+
"55s"
|
|
582
|
+
);
|
|
583
|
+
return buildState();
|
|
584
|
+
}
|
|
585
|
+
);
|
|
545
586
|
return {
|
|
546
587
|
getStatus() {
|
|
547
588
|
return status;
|
|
@@ -611,7 +652,7 @@ function createAgentStateManager(initialState) {
|
|
|
611
652
|
tools = newTools.map((tool) => ({
|
|
612
653
|
name: tool.name,
|
|
613
654
|
description: tool.description,
|
|
614
|
-
schema:
|
|
655
|
+
schema: z13.z.toJSONSchema(tool.schema),
|
|
615
656
|
strict: tool.strict,
|
|
616
657
|
max_uses: tool.max_uses
|
|
617
658
|
}));
|
|
@@ -630,38 +671,6 @@ var AGENT_HANDLER_NAMES = {
|
|
|
630
671
|
waitForStateChange: "waitForStateChange",
|
|
631
672
|
addMessage: "addMessage"
|
|
632
673
|
};
|
|
633
|
-
var askUserQuestionTool = {
|
|
634
|
-
name: "AskUserQuestion",
|
|
635
|
-
description: `Use this tool when you need to ask the user questions during execution. This allows you to:
|
|
636
|
-
|
|
637
|
-
1. Gather user preferences or requirements
|
|
638
|
-
2. Clarify ambiguous instructions
|
|
639
|
-
3. Get decisions on implementation choices as you work
|
|
640
|
-
4. Offer choices to the user about what direction to take.
|
|
641
|
-
|
|
642
|
-
Usage notes:
|
|
643
|
-
|
|
644
|
-
* Users will always be able to select "Other" to provide custom text input
|
|
645
|
-
* Use multiSelect: true to allow multiple answers to be selected for a question
|
|
646
|
-
* If you recommend a specific option, make that the first option in the list and add "(Recommended)" at the end of the label
|
|
647
|
-
`,
|
|
648
|
-
schema: z3__default.default.object({
|
|
649
|
-
questions: z3__default.default.array(
|
|
650
|
-
z3__default.default.object({
|
|
651
|
-
question: z3__default.default.string().describe("The full question text to display"),
|
|
652
|
-
header: z3__default.default.string().describe("Short label for the question (max 12 characters)"),
|
|
653
|
-
options: z3__default.default.array(
|
|
654
|
-
z3__default.default.object({
|
|
655
|
-
label: z3__default.default.string(),
|
|
656
|
-
description: z3__default.default.string()
|
|
657
|
-
})
|
|
658
|
-
).min(0).max(4).describe("Array of 0-4 choices, each with label and description"),
|
|
659
|
-
multiSelect: z3__default.default.boolean().describe("If true, users can select multiple options")
|
|
660
|
-
})
|
|
661
|
-
)
|
|
662
|
-
}),
|
|
663
|
-
strict: true
|
|
664
|
-
};
|
|
665
674
|
var globTool = {
|
|
666
675
|
name: "Glob",
|
|
667
676
|
description: `Search for files matching a glob pattern within the available file system.
|
|
@@ -676,9 +685,9 @@ Examples:
|
|
|
676
685
|
- "**/*.test.ts" - Find all test files recursively
|
|
677
686
|
- "src/**/*.ts" - Find all TypeScript files in src directory
|
|
678
687
|
`,
|
|
679
|
-
schema:
|
|
680
|
-
pattern:
|
|
681
|
-
root:
|
|
688
|
+
schema: z13.z.object({
|
|
689
|
+
pattern: z13.z.string().describe("Glob pattern to match files against"),
|
|
690
|
+
root: z13.z.string().optional().describe("Optional root directory to search from")
|
|
682
691
|
}),
|
|
683
692
|
strict: true
|
|
684
693
|
};
|
|
@@ -696,13 +705,13 @@ Examples:
|
|
|
696
705
|
- Search for function definitions with "function.*handleClick"
|
|
697
706
|
- Search case-insensitively with ignoreCase: true
|
|
698
707
|
`,
|
|
699
|
-
schema:
|
|
700
|
-
pattern:
|
|
701
|
-
ignoreCase:
|
|
702
|
-
maxMatches:
|
|
703
|
-
includePatterns:
|
|
704
|
-
excludePatterns:
|
|
705
|
-
contextLines:
|
|
708
|
+
schema: z13.z.object({
|
|
709
|
+
pattern: z13.z.string().describe("Regex pattern to search for in file contents"),
|
|
710
|
+
ignoreCase: z13.z.boolean().optional().describe("Case-insensitive search (default: false)"),
|
|
711
|
+
maxMatches: z13.z.number().optional().describe("Maximum number of matches to return (default: 50)"),
|
|
712
|
+
includePatterns: z13.z.array(z13.z.string()).optional().describe("Glob patterns to include (e.g., ['*.ts', '*.js'])"),
|
|
713
|
+
excludePatterns: z13.z.array(z13.z.string()).optional().describe("Glob patterns to exclude (e.g., ['*.test.ts'])"),
|
|
714
|
+
contextLines: z13.z.number().optional().describe("Number of context lines to show around matches")
|
|
706
715
|
}),
|
|
707
716
|
strict: true
|
|
708
717
|
};
|
|
@@ -720,12 +729,12 @@ The tool returns the file content in an appropriate format:
|
|
|
720
729
|
- Images: Base64-encoded image data
|
|
721
730
|
- PDFs: Extracted text content
|
|
722
731
|
`,
|
|
723
|
-
schema:
|
|
724
|
-
path:
|
|
725
|
-
offset:
|
|
732
|
+
schema: z13.z.object({
|
|
733
|
+
path: z13.z.string().describe("Virtual path to the file to read"),
|
|
734
|
+
offset: z13.z.number().optional().describe(
|
|
726
735
|
"Line number to start reading from (1-indexed, for text files)"
|
|
727
736
|
),
|
|
728
|
-
limit:
|
|
737
|
+
limit: z13.z.number().optional().describe("Maximum number of lines to read (for text files)")
|
|
729
738
|
}),
|
|
730
739
|
strict: true
|
|
731
740
|
};
|
|
@@ -743,9 +752,9 @@ IMPORTANT:
|
|
|
743
752
|
- This is an atomic write operation - the entire file is replaced
|
|
744
753
|
- Path must be absolute (e.g., "/docs/readme.md", not "docs/readme.md")
|
|
745
754
|
`,
|
|
746
|
-
schema:
|
|
747
|
-
file_path:
|
|
748
|
-
content:
|
|
755
|
+
schema: z13.z.object({
|
|
756
|
+
file_path: z13.z.string().describe("The absolute path to the file to write"),
|
|
757
|
+
content: z13.z.string().describe("The content to write to the file")
|
|
749
758
|
}),
|
|
750
759
|
strict: true
|
|
751
760
|
};
|
|
@@ -765,13 +774,13 @@ IMPORTANT:
|
|
|
765
774
|
- The operation fails if old_string is not found
|
|
766
775
|
- old_string and new_string must be different
|
|
767
776
|
`,
|
|
768
|
-
schema:
|
|
769
|
-
file_path:
|
|
770
|
-
old_string:
|
|
771
|
-
new_string:
|
|
777
|
+
schema: z13.z.object({
|
|
778
|
+
file_path: z13.z.string().describe("The absolute virtual path to the file to modify"),
|
|
779
|
+
old_string: z13.z.string().describe("The exact text to replace"),
|
|
780
|
+
new_string: z13.z.string().describe(
|
|
772
781
|
"The text to replace it with (must be different from old_string)"
|
|
773
782
|
),
|
|
774
|
-
replace_all:
|
|
783
|
+
replace_all: z13.z.boolean().optional().describe(
|
|
775
784
|
"If true, replace all occurrences of old_string (default: false)"
|
|
776
785
|
)
|
|
777
786
|
}),
|
|
@@ -818,17 +827,17 @@ var taskCreateTool = {
|
|
|
818
827
|
- Include enough detail in the description for another agent to understand and complete the task
|
|
819
828
|
- After creating tasks, use TaskUpdate to set up dependencies (blocks/blockedBy) if needed
|
|
820
829
|
- Check TaskList first to avoid creating duplicate tasks`,
|
|
821
|
-
schema:
|
|
822
|
-
subject:
|
|
830
|
+
schema: z13__default.default.object({
|
|
831
|
+
subject: z13__default.default.string().describe(
|
|
823
832
|
'A brief, actionable title in imperative form (e.g., "Fix authentication bug in login flow")'
|
|
824
833
|
),
|
|
825
|
-
description:
|
|
834
|
+
description: z13__default.default.string().describe(
|
|
826
835
|
"Detailed description of what needs to be done, including context and acceptance criteria"
|
|
827
836
|
),
|
|
828
|
-
activeForm:
|
|
837
|
+
activeForm: z13__default.default.string().describe(
|
|
829
838
|
'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.'
|
|
830
839
|
),
|
|
831
|
-
metadata:
|
|
840
|
+
metadata: z13__default.default.record(z13__default.default.string(), z13__default.default.string()).describe("Arbitrary key-value pairs for tracking")
|
|
832
841
|
})
|
|
833
842
|
};
|
|
834
843
|
function createTaskCreateHandler(stateManager) {
|
|
@@ -853,8 +862,8 @@ function createTaskCreateHandler(stateManager) {
|
|
|
853
862
|
var taskGetTool = {
|
|
854
863
|
name: "TaskGet",
|
|
855
864
|
description: `Retrieve full task details including dependencies.`,
|
|
856
|
-
schema:
|
|
857
|
-
taskId:
|
|
865
|
+
schema: z13__default.default.object({
|
|
866
|
+
taskId: z13__default.default.string().describe("The ID of the task to get")
|
|
858
867
|
})
|
|
859
868
|
};
|
|
860
869
|
|
|
@@ -877,7 +886,7 @@ function createTaskGetHandler(stateManager) {
|
|
|
877
886
|
var taskListTool = {
|
|
878
887
|
name: "TaskList",
|
|
879
888
|
description: `List all tasks with current state.`,
|
|
880
|
-
schema:
|
|
889
|
+
schema: z13__default.default.object({})
|
|
881
890
|
};
|
|
882
891
|
|
|
883
892
|
// src/tools/task-list/handler.ts
|
|
@@ -893,11 +902,11 @@ function createTaskListHandler(stateManager) {
|
|
|
893
902
|
var taskUpdateTool = {
|
|
894
903
|
name: "TaskUpdate",
|
|
895
904
|
description: `Update status, add blockers, modify details.`,
|
|
896
|
-
schema:
|
|
897
|
-
taskId:
|
|
898
|
-
status:
|
|
899
|
-
addBlockedBy:
|
|
900
|
-
addBlocks:
|
|
905
|
+
schema: z13__default.default.object({
|
|
906
|
+
taskId: z13__default.default.string().describe("The ID of the task to get"),
|
|
907
|
+
status: z13__default.default.enum(["pending", "in_progress", "completed"]).describe("The status of the task"),
|
|
908
|
+
addBlockedBy: z13__default.default.array(z13__default.default.string()).describe("The IDs of the tasks that are blocking this task"),
|
|
909
|
+
addBlocks: z13__default.default.array(z13__default.default.string()).describe("The IDs of the tasks that this task is blocking")
|
|
901
910
|
})
|
|
902
911
|
};
|
|
903
912
|
|
|
@@ -965,18 +974,59 @@ Use this tool to:
|
|
|
965
974
|
- Execute scripts and chain commands with pipes (|) or logical operators (&&, ||)
|
|
966
975
|
- Inspect files and directories
|
|
967
976
|
`,
|
|
968
|
-
schema:
|
|
969
|
-
command:
|
|
977
|
+
schema: z13__default.default.object({
|
|
978
|
+
command: z13__default.default.string().describe(
|
|
970
979
|
"The bash command to execute. Can include pipes (|), redirects (>, >>), logical operators (&&, ||), and shell features like command substitution $(...)."
|
|
971
980
|
)
|
|
972
981
|
}),
|
|
973
982
|
strict: true
|
|
974
983
|
};
|
|
984
|
+
var askUserQuestionTool = {
|
|
985
|
+
name: "AskUserQuestion",
|
|
986
|
+
description: `Use this tool when you need to ask the user questions during execution. This allows you to:
|
|
987
|
+
|
|
988
|
+
1. Gather user preferences or requirements
|
|
989
|
+
2. Clarify ambiguous instructions
|
|
990
|
+
3. Get decisions on implementation choices as you work
|
|
991
|
+
4. Offer choices to the user about what direction to take.
|
|
992
|
+
|
|
993
|
+
Usage notes:
|
|
994
|
+
|
|
995
|
+
* Users will always be able to select "Other" to provide custom text input
|
|
996
|
+
* Use multiSelect: true to allow multiple answers to be selected for a question
|
|
997
|
+
* If you recommend a specific option, make that the first option in the list and add "(Recommended)" at the end of the label
|
|
998
|
+
`,
|
|
999
|
+
schema: z13__default.default.object({
|
|
1000
|
+
questions: z13__default.default.array(
|
|
1001
|
+
z13__default.default.object({
|
|
1002
|
+
question: z13__default.default.string().describe("The full question text to display"),
|
|
1003
|
+
header: z13__default.default.string().describe("Short label for the question (max 12 characters)"),
|
|
1004
|
+
options: z13__default.default.array(
|
|
1005
|
+
z13__default.default.object({
|
|
1006
|
+
label: z13__default.default.string(),
|
|
1007
|
+
description: z13__default.default.string()
|
|
1008
|
+
})
|
|
1009
|
+
).min(0).max(4).describe("Array of 0-4 choices, each with label and description"),
|
|
1010
|
+
multiSelect: z13__default.default.boolean().describe("If true, users can select multiple options")
|
|
1011
|
+
})
|
|
1012
|
+
)
|
|
1013
|
+
}),
|
|
1014
|
+
strict: true
|
|
1015
|
+
};
|
|
1016
|
+
|
|
1017
|
+
// src/tools/ask-user-question/handler.ts
|
|
1018
|
+
var createAskUserQuestionHandler = () => (args) => {
|
|
1019
|
+
return {
|
|
1020
|
+
toolResponse: "Question submitted",
|
|
1021
|
+
data: { questions: args.questions }
|
|
1022
|
+
};
|
|
1023
|
+
};
|
|
975
1024
|
|
|
976
1025
|
exports.AGENT_HANDLER_NAMES = AGENT_HANDLER_NAMES;
|
|
977
1026
|
exports.askUserQuestionTool = askUserQuestionTool;
|
|
978
1027
|
exports.bashTool = bashTool;
|
|
979
1028
|
exports.createAgentStateManager = createAgentStateManager;
|
|
1029
|
+
exports.createAskUserQuestionHandler = createAskUserQuestionHandler;
|
|
980
1030
|
exports.createBashToolDescription = createBashToolDescription;
|
|
981
1031
|
exports.createSession = createSession;
|
|
982
1032
|
exports.createSubagentTool = createSubagentTool;
|