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.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { setHandler, defineUpdate, condition, proxyActivities, defineQuery, uuid4, workflowInfo, executeChild } from '@temporalio/workflow';
|
|
2
|
+
import z13, { z } from 'zod';
|
|
3
3
|
|
|
4
4
|
// src/lib/session.ts
|
|
5
5
|
var SUBAGENT_TOOL = "Subagent";
|
|
@@ -34,10 +34,10 @@ function createSubagentTool(subagents) {
|
|
|
34
34
|
return {
|
|
35
35
|
name: SUBAGENT_TOOL,
|
|
36
36
|
description: buildSubagentDescription(subagents),
|
|
37
|
-
schema:
|
|
38
|
-
subagent:
|
|
39
|
-
description:
|
|
40
|
-
prompt:
|
|
37
|
+
schema: z13.object({
|
|
38
|
+
subagent: z13.enum(names).describe("The type of subagent to launch"),
|
|
39
|
+
description: z13.string().describe("A short (3-5 word) description of the task"),
|
|
40
|
+
prompt: z13.string().describe("The task for the agent to perform")
|
|
41
41
|
})
|
|
42
42
|
};
|
|
43
43
|
}
|
|
@@ -390,7 +390,8 @@ var createSession = async ({
|
|
|
390
390
|
processToolsInParallel = true,
|
|
391
391
|
hooks = {},
|
|
392
392
|
appendSystemPrompt = true,
|
|
393
|
-
systemPrompt
|
|
393
|
+
systemPrompt,
|
|
394
|
+
waitForInputTimeout = "48h"
|
|
394
395
|
}) => {
|
|
395
396
|
const {
|
|
396
397
|
appendToolResult,
|
|
@@ -419,6 +420,25 @@ var createSession = async ({
|
|
|
419
420
|
};
|
|
420
421
|
return {
|
|
421
422
|
runSession: async ({ stateManager }) => {
|
|
423
|
+
setHandler(
|
|
424
|
+
defineUpdate(`add${agentName}Message`),
|
|
425
|
+
async (message) => {
|
|
426
|
+
if (hooks.onPreHumanMessageAppend) {
|
|
427
|
+
await hooks.onPreHumanMessageAppend({
|
|
428
|
+
message,
|
|
429
|
+
threadId
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
await appendHumanMessage(threadId, message);
|
|
433
|
+
if (hooks.onPostHumanMessageAppend) {
|
|
434
|
+
await hooks.onPostHumanMessageAppend({
|
|
435
|
+
message,
|
|
436
|
+
threadId
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
stateManager.run();
|
|
440
|
+
}
|
|
441
|
+
);
|
|
422
442
|
if (hooks.onSessionStart) {
|
|
423
443
|
await hooks.onSessionStart({
|
|
424
444
|
threadId,
|
|
@@ -466,8 +486,15 @@ var createSession = async ({
|
|
|
466
486
|
turn: currentTurn
|
|
467
487
|
});
|
|
468
488
|
if (stateManager.getStatus() === "WAITING_FOR_INPUT") {
|
|
469
|
-
|
|
470
|
-
|
|
489
|
+
const conditionMet = await condition(
|
|
490
|
+
() => stateManager.getStatus() === "RUNNING",
|
|
491
|
+
waitForInputTimeout
|
|
492
|
+
);
|
|
493
|
+
if (!conditionMet) {
|
|
494
|
+
stateManager.cancel();
|
|
495
|
+
await condition(() => false, "2s");
|
|
496
|
+
break;
|
|
497
|
+
}
|
|
471
498
|
}
|
|
472
499
|
}
|
|
473
500
|
if (stateManager.getTurns() >= maxTurns && stateManager.isRunning()) {
|
|
@@ -508,8 +535,10 @@ function proxyDefaultThreadOps(options) {
|
|
|
508
535
|
function isTerminalStatus(status) {
|
|
509
536
|
return status === "COMPLETED" || status === "FAILED" || status === "CANCELLED";
|
|
510
537
|
}
|
|
511
|
-
|
|
512
|
-
|
|
538
|
+
function createAgentStateManager({
|
|
539
|
+
initialState,
|
|
540
|
+
agentConfig
|
|
541
|
+
}) {
|
|
513
542
|
let status = initialState?.status ?? "RUNNING";
|
|
514
543
|
let version = initialState?.version ?? 0;
|
|
515
544
|
let turns = initialState?.turns ?? 0;
|
|
@@ -533,9 +562,21 @@ function createAgentStateManager(initialState) {
|
|
|
533
562
|
...customState
|
|
534
563
|
};
|
|
535
564
|
}
|
|
536
|
-
setHandler(
|
|
565
|
+
setHandler(defineQuery(`get${agentConfig.agentName}State`), () => {
|
|
537
566
|
return buildState();
|
|
538
567
|
});
|
|
568
|
+
setHandler(
|
|
569
|
+
defineUpdate(
|
|
570
|
+
`waitFor${agentConfig.agentName}StateChange`
|
|
571
|
+
),
|
|
572
|
+
async (lastKnownVersion) => {
|
|
573
|
+
await condition(
|
|
574
|
+
() => version > lastKnownVersion || isTerminalStatus(status),
|
|
575
|
+
"55s"
|
|
576
|
+
);
|
|
577
|
+
return buildState();
|
|
578
|
+
}
|
|
579
|
+
);
|
|
539
580
|
return {
|
|
540
581
|
getStatus() {
|
|
541
582
|
return status;
|
|
@@ -624,38 +665,6 @@ var AGENT_HANDLER_NAMES = {
|
|
|
624
665
|
waitForStateChange: "waitForStateChange",
|
|
625
666
|
addMessage: "addMessage"
|
|
626
667
|
};
|
|
627
|
-
var askUserQuestionTool = {
|
|
628
|
-
name: "AskUserQuestion",
|
|
629
|
-
description: `Use this tool when you need to ask the user questions during execution. This allows you to:
|
|
630
|
-
|
|
631
|
-
1. Gather user preferences or requirements
|
|
632
|
-
2. Clarify ambiguous instructions
|
|
633
|
-
3. Get decisions on implementation choices as you work
|
|
634
|
-
4. Offer choices to the user about what direction to take.
|
|
635
|
-
|
|
636
|
-
Usage notes:
|
|
637
|
-
|
|
638
|
-
* Users will always be able to select "Other" to provide custom text input
|
|
639
|
-
* Use multiSelect: true to allow multiple answers to be selected for a question
|
|
640
|
-
* If you recommend a specific option, make that the first option in the list and add "(Recommended)" at the end of the label
|
|
641
|
-
`,
|
|
642
|
-
schema: z3.object({
|
|
643
|
-
questions: z3.array(
|
|
644
|
-
z3.object({
|
|
645
|
-
question: z3.string().describe("The full question text to display"),
|
|
646
|
-
header: z3.string().describe("Short label for the question (max 12 characters)"),
|
|
647
|
-
options: z3.array(
|
|
648
|
-
z3.object({
|
|
649
|
-
label: z3.string(),
|
|
650
|
-
description: z3.string()
|
|
651
|
-
})
|
|
652
|
-
).min(0).max(4).describe("Array of 0-4 choices, each with label and description"),
|
|
653
|
-
multiSelect: z3.boolean().describe("If true, users can select multiple options")
|
|
654
|
-
})
|
|
655
|
-
)
|
|
656
|
-
}),
|
|
657
|
-
strict: true
|
|
658
|
-
};
|
|
659
668
|
var globTool = {
|
|
660
669
|
name: "Glob",
|
|
661
670
|
description: `Search for files matching a glob pattern within the available file system.
|
|
@@ -812,17 +821,17 @@ var taskCreateTool = {
|
|
|
812
821
|
- Include enough detail in the description for another agent to understand and complete the task
|
|
813
822
|
- After creating tasks, use TaskUpdate to set up dependencies (blocks/blockedBy) if needed
|
|
814
823
|
- Check TaskList first to avoid creating duplicate tasks`,
|
|
815
|
-
schema:
|
|
816
|
-
subject:
|
|
824
|
+
schema: z13.object({
|
|
825
|
+
subject: z13.string().describe(
|
|
817
826
|
'A brief, actionable title in imperative form (e.g., "Fix authentication bug in login flow")'
|
|
818
827
|
),
|
|
819
|
-
description:
|
|
828
|
+
description: z13.string().describe(
|
|
820
829
|
"Detailed description of what needs to be done, including context and acceptance criteria"
|
|
821
830
|
),
|
|
822
|
-
activeForm:
|
|
831
|
+
activeForm: z13.string().describe(
|
|
823
832
|
'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.'
|
|
824
833
|
),
|
|
825
|
-
metadata:
|
|
834
|
+
metadata: z13.record(z13.string(), z13.string()).describe("Arbitrary key-value pairs for tracking")
|
|
826
835
|
})
|
|
827
836
|
};
|
|
828
837
|
function createTaskCreateHandler(stateManager) {
|
|
@@ -847,8 +856,8 @@ function createTaskCreateHandler(stateManager) {
|
|
|
847
856
|
var taskGetTool = {
|
|
848
857
|
name: "TaskGet",
|
|
849
858
|
description: `Retrieve full task details including dependencies.`,
|
|
850
|
-
schema:
|
|
851
|
-
taskId:
|
|
859
|
+
schema: z13.object({
|
|
860
|
+
taskId: z13.string().describe("The ID of the task to get")
|
|
852
861
|
})
|
|
853
862
|
};
|
|
854
863
|
|
|
@@ -871,7 +880,7 @@ function createTaskGetHandler(stateManager) {
|
|
|
871
880
|
var taskListTool = {
|
|
872
881
|
name: "TaskList",
|
|
873
882
|
description: `List all tasks with current state.`,
|
|
874
|
-
schema:
|
|
883
|
+
schema: z13.object({})
|
|
875
884
|
};
|
|
876
885
|
|
|
877
886
|
// src/tools/task-list/handler.ts
|
|
@@ -887,11 +896,11 @@ function createTaskListHandler(stateManager) {
|
|
|
887
896
|
var taskUpdateTool = {
|
|
888
897
|
name: "TaskUpdate",
|
|
889
898
|
description: `Update status, add blockers, modify details.`,
|
|
890
|
-
schema:
|
|
891
|
-
taskId:
|
|
892
|
-
status:
|
|
893
|
-
addBlockedBy:
|
|
894
|
-
addBlocks:
|
|
899
|
+
schema: z13.object({
|
|
900
|
+
taskId: z13.string().describe("The ID of the task to get"),
|
|
901
|
+
status: z13.enum(["pending", "in_progress", "completed"]).describe("The status of the task"),
|
|
902
|
+
addBlockedBy: z13.array(z13.string()).describe("The IDs of the tasks that are blocking this task"),
|
|
903
|
+
addBlocks: z13.array(z13.string()).describe("The IDs of the tasks that this task is blocking")
|
|
895
904
|
})
|
|
896
905
|
};
|
|
897
906
|
|
|
@@ -959,14 +968,54 @@ Use this tool to:
|
|
|
959
968
|
- Execute scripts and chain commands with pipes (|) or logical operators (&&, ||)
|
|
960
969
|
- Inspect files and directories
|
|
961
970
|
`,
|
|
962
|
-
schema:
|
|
963
|
-
command:
|
|
971
|
+
schema: z13.object({
|
|
972
|
+
command: z13.string().describe(
|
|
964
973
|
"The bash command to execute. Can include pipes (|), redirects (>, >>), logical operators (&&, ||), and shell features like command substitution $(...)."
|
|
965
974
|
)
|
|
966
975
|
}),
|
|
967
976
|
strict: true
|
|
968
977
|
};
|
|
978
|
+
var askUserQuestionTool = {
|
|
979
|
+
name: "AskUserQuestion",
|
|
980
|
+
description: `Use this tool when you need to ask the user questions during execution. This allows you to:
|
|
981
|
+
|
|
982
|
+
1. Gather user preferences or requirements
|
|
983
|
+
2. Clarify ambiguous instructions
|
|
984
|
+
3. Get decisions on implementation choices as you work
|
|
985
|
+
4. Offer choices to the user about what direction to take.
|
|
986
|
+
|
|
987
|
+
Usage notes:
|
|
988
|
+
|
|
989
|
+
* Users will always be able to select "Other" to provide custom text input
|
|
990
|
+
* Use multiSelect: true to allow multiple answers to be selected for a question
|
|
991
|
+
* If you recommend a specific option, make that the first option in the list and add "(Recommended)" at the end of the label
|
|
992
|
+
`,
|
|
993
|
+
schema: z13.object({
|
|
994
|
+
questions: z13.array(
|
|
995
|
+
z13.object({
|
|
996
|
+
question: z13.string().describe("The full question text to display"),
|
|
997
|
+
header: z13.string().describe("Short label for the question (max 12 characters)"),
|
|
998
|
+
options: z13.array(
|
|
999
|
+
z13.object({
|
|
1000
|
+
label: z13.string(),
|
|
1001
|
+
description: z13.string()
|
|
1002
|
+
})
|
|
1003
|
+
).min(0).max(4).describe("Array of 0-4 choices, each with label and description"),
|
|
1004
|
+
multiSelect: z13.boolean().describe("If true, users can select multiple options")
|
|
1005
|
+
})
|
|
1006
|
+
)
|
|
1007
|
+
}),
|
|
1008
|
+
strict: true
|
|
1009
|
+
};
|
|
1010
|
+
|
|
1011
|
+
// src/tools/ask-user-question/handler.ts
|
|
1012
|
+
var createAskUserQuestionHandler = () => (args) => {
|
|
1013
|
+
return {
|
|
1014
|
+
toolResponse: "Question submitted",
|
|
1015
|
+
data: { questions: args.questions }
|
|
1016
|
+
};
|
|
1017
|
+
};
|
|
969
1018
|
|
|
970
|
-
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 };
|
|
1019
|
+
export { AGENT_HANDLER_NAMES, askUserQuestionTool, bashTool, createAgentStateManager, createAskUserQuestionHandler, createBashToolDescription, createSession, createSubagentTool, createTaskCreateHandler, createTaskGetHandler, createTaskListHandler, createTaskUpdateHandler, createToolRouter, defineSubagent, defineTool, editTool, globTool, grepTool, hasNoOtherToolCalls, isTerminalStatus, proxyDefaultThreadOps, readTool, taskCreateTool, taskGetTool, taskListTool, taskUpdateTool, writeTool };
|
|
971
1020
|
//# sourceMappingURL=workflow.js.map
|
|
972
1021
|
//# sourceMappingURL=workflow.js.map
|