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 CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var workflow = require('@temporalio/workflow');
4
- var z3 = require('zod');
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 z3__default = /*#__PURE__*/_interopDefault(z3);
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: z3__default.default.object({
50
- subagent: z3__default.default.enum(names).describe("The type of subagent to launch"),
51
- description: z3__default.default.string().describe("A short (3-5 word) description of the task"),
52
- prompt: z3__default.default.string().describe("The task for the agent to perform")
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
  }
@@ -421,7 +421,8 @@ var createSession = async ({
421
421
  processToolsInParallel = true,
422
422
  hooks = {},
423
423
  appendSystemPrompt = true,
424
- systemPrompt
424
+ systemPrompt,
425
+ waitForInputTimeout = "48h"
425
426
  }) => {
426
427
  const {
427
428
  appendToolResult,
@@ -450,6 +451,25 @@ var createSession = async ({
450
451
  };
451
452
  return {
452
453
  runSession: async ({ stateManager }) => {
454
+ workflow.setHandler(
455
+ workflow.defineUpdate(`add${agentName}Message`),
456
+ async (message) => {
457
+ if (hooks.onPreHumanMessageAppend) {
458
+ await hooks.onPreHumanMessageAppend({
459
+ message,
460
+ threadId
461
+ });
462
+ }
463
+ await appendHumanMessage(threadId, message);
464
+ if (hooks.onPostHumanMessageAppend) {
465
+ await hooks.onPostHumanMessageAppend({
466
+ message,
467
+ threadId
468
+ });
469
+ }
470
+ stateManager.run();
471
+ }
472
+ );
453
473
  if (hooks.onSessionStart) {
454
474
  await hooks.onSessionStart({
455
475
  threadId,
@@ -497,8 +517,15 @@ var createSession = async ({
497
517
  turn: currentTurn
498
518
  });
499
519
  if (stateManager.getStatus() === "WAITING_FOR_INPUT") {
500
- exitReason = "waiting_for_input";
501
- break;
520
+ const conditionMet = await workflow.condition(
521
+ () => stateManager.getStatus() === "RUNNING",
522
+ waitForInputTimeout
523
+ );
524
+ if (!conditionMet) {
525
+ stateManager.cancel();
526
+ await workflow.condition(() => false, "2s");
527
+ break;
528
+ }
502
529
  }
503
530
  }
504
531
  if (stateManager.getTurns() >= maxTurns && stateManager.isRunning()) {
@@ -539,8 +566,10 @@ function proxyDefaultThreadOps(options) {
539
566
  function isTerminalStatus(status) {
540
567
  return status === "COMPLETED" || status === "FAILED" || status === "CANCELLED";
541
568
  }
542
- var getStateQuery = workflow.defineQuery("getState");
543
- function createAgentStateManager(initialState) {
569
+ function createAgentStateManager({
570
+ initialState,
571
+ agentConfig
572
+ }) {
544
573
  let status = initialState?.status ?? "RUNNING";
545
574
  let version = initialState?.version ?? 0;
546
575
  let turns = initialState?.turns ?? 0;
@@ -564,9 +593,21 @@ function createAgentStateManager(initialState) {
564
593
  ...customState
565
594
  };
566
595
  }
567
- workflow.setHandler(getStateQuery, () => {
596
+ workflow.setHandler(workflow.defineQuery(`get${agentConfig.agentName}State`), () => {
568
597
  return buildState();
569
598
  });
599
+ workflow.setHandler(
600
+ workflow.defineUpdate(
601
+ `waitFor${agentConfig.agentName}StateChange`
602
+ ),
603
+ async (lastKnownVersion) => {
604
+ await workflow.condition(
605
+ () => version > lastKnownVersion || isTerminalStatus(status),
606
+ "55s"
607
+ );
608
+ return buildState();
609
+ }
610
+ );
570
611
  return {
571
612
  getStatus() {
572
613
  return status;
@@ -636,7 +677,7 @@ function createAgentStateManager(initialState) {
636
677
  tools = newTools.map((tool) => ({
637
678
  name: tool.name,
638
679
  description: tool.description,
639
- schema: z3.z.toJSONSchema(tool.schema),
680
+ schema: z13.z.toJSONSchema(tool.schema),
640
681
  strict: tool.strict,
641
682
  max_uses: tool.max_uses
642
683
  }));
@@ -655,38 +696,6 @@ var AGENT_HANDLER_NAMES = {
655
696
  waitForStateChange: "waitForStateChange",
656
697
  addMessage: "addMessage"
657
698
  };
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
699
  var globTool = {
691
700
  name: "Glob",
692
701
  description: `Search for files matching a glob pattern within the available file system.
@@ -701,9 +710,9 @@ Examples:
701
710
  - "**/*.test.ts" - Find all test files recursively
702
711
  - "src/**/*.ts" - Find all TypeScript files in src directory
703
712
  `,
704
- schema: z3.z.object({
705
- pattern: z3.z.string().describe("Glob pattern to match files against"),
706
- root: z3.z.string().optional().describe("Optional root directory to search from")
713
+ schema: z13.z.object({
714
+ pattern: z13.z.string().describe("Glob pattern to match files against"),
715
+ root: z13.z.string().optional().describe("Optional root directory to search from")
707
716
  }),
708
717
  strict: true
709
718
  };
@@ -721,13 +730,13 @@ Examples:
721
730
  - Search for function definitions with "function.*handleClick"
722
731
  - Search case-insensitively with ignoreCase: true
723
732
  `,
724
- schema: z3.z.object({
725
- pattern: z3.z.string().describe("Regex pattern to search for in file contents"),
726
- ignoreCase: z3.z.boolean().optional().describe("Case-insensitive search (default: false)"),
727
- maxMatches: z3.z.number().optional().describe("Maximum number of matches to return (default: 50)"),
728
- includePatterns: z3.z.array(z3.z.string()).optional().describe("Glob patterns to include (e.g., ['*.ts', '*.js'])"),
729
- excludePatterns: z3.z.array(z3.z.string()).optional().describe("Glob patterns to exclude (e.g., ['*.test.ts'])"),
730
- contextLines: z3.z.number().optional().describe("Number of context lines to show around matches")
733
+ schema: z13.z.object({
734
+ pattern: z13.z.string().describe("Regex pattern to search for in file contents"),
735
+ ignoreCase: z13.z.boolean().optional().describe("Case-insensitive search (default: false)"),
736
+ maxMatches: z13.z.number().optional().describe("Maximum number of matches to return (default: 50)"),
737
+ includePatterns: z13.z.array(z13.z.string()).optional().describe("Glob patterns to include (e.g., ['*.ts', '*.js'])"),
738
+ excludePatterns: z13.z.array(z13.z.string()).optional().describe("Glob patterns to exclude (e.g., ['*.test.ts'])"),
739
+ contextLines: z13.z.number().optional().describe("Number of context lines to show around matches")
731
740
  }),
732
741
  strict: true
733
742
  };
@@ -745,12 +754,12 @@ The tool returns the file content in an appropriate format:
745
754
  - Images: Base64-encoded image data
746
755
  - PDFs: Extracted text content
747
756
  `,
748
- schema: z3.z.object({
749
- path: z3.z.string().describe("Virtual path to the file to read"),
750
- offset: z3.z.number().optional().describe(
757
+ schema: z13.z.object({
758
+ path: z13.z.string().describe("Virtual path to the file to read"),
759
+ offset: z13.z.number().optional().describe(
751
760
  "Line number to start reading from (1-indexed, for text files)"
752
761
  ),
753
- limit: z3.z.number().optional().describe("Maximum number of lines to read (for text files)")
762
+ limit: z13.z.number().optional().describe("Maximum number of lines to read (for text files)")
754
763
  }),
755
764
  strict: true
756
765
  };
@@ -768,9 +777,9 @@ IMPORTANT:
768
777
  - This is an atomic write operation - the entire file is replaced
769
778
  - Path must be absolute (e.g., "/docs/readme.md", not "docs/readme.md")
770
779
  `,
771
- schema: z3.z.object({
772
- file_path: z3.z.string().describe("The absolute path to the file to write"),
773
- content: z3.z.string().describe("The content to write to the file")
780
+ schema: z13.z.object({
781
+ file_path: z13.z.string().describe("The absolute path to the file to write"),
782
+ content: z13.z.string().describe("The content to write to the file")
774
783
  }),
775
784
  strict: true
776
785
  };
@@ -790,13 +799,13 @@ IMPORTANT:
790
799
  - The operation fails if old_string is not found
791
800
  - old_string and new_string must be different
792
801
  `,
793
- schema: z3.z.object({
794
- file_path: z3.z.string().describe("The absolute virtual path to the file to modify"),
795
- old_string: z3.z.string().describe("The exact text to replace"),
796
- new_string: z3.z.string().describe(
802
+ schema: z13.z.object({
803
+ file_path: z13.z.string().describe("The absolute virtual path to the file to modify"),
804
+ old_string: z13.z.string().describe("The exact text to replace"),
805
+ new_string: z13.z.string().describe(
797
806
  "The text to replace it with (must be different from old_string)"
798
807
  ),
799
- replace_all: z3.z.boolean().optional().describe(
808
+ replace_all: z13.z.boolean().optional().describe(
800
809
  "If true, replace all occurrences of old_string (default: false)"
801
810
  )
802
811
  }),
@@ -843,17 +852,17 @@ var taskCreateTool = {
843
852
  - Include enough detail in the description for another agent to understand and complete the task
844
853
  - After creating tasks, use TaskUpdate to set up dependencies (blocks/blockedBy) if needed
845
854
  - Check TaskList first to avoid creating duplicate tasks`,
846
- schema: z3__default.default.object({
847
- subject: z3__default.default.string().describe(
855
+ schema: z13__default.default.object({
856
+ subject: z13__default.default.string().describe(
848
857
  'A brief, actionable title in imperative form (e.g., "Fix authentication bug in login flow")'
849
858
  ),
850
- description: z3__default.default.string().describe(
859
+ description: z13__default.default.string().describe(
851
860
  "Detailed description of what needs to be done, including context and acceptance criteria"
852
861
  ),
853
- activeForm: z3__default.default.string().describe(
862
+ activeForm: z13__default.default.string().describe(
854
863
  '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
864
  ),
856
- metadata: z3__default.default.record(z3__default.default.string(), z3__default.default.string()).describe("Arbitrary key-value pairs for tracking")
865
+ metadata: z13__default.default.record(z13__default.default.string(), z13__default.default.string()).describe("Arbitrary key-value pairs for tracking")
857
866
  })
858
867
  };
859
868
  function createTaskCreateHandler(stateManager) {
@@ -878,8 +887,8 @@ function createTaskCreateHandler(stateManager) {
878
887
  var taskGetTool = {
879
888
  name: "TaskGet",
880
889
  description: `Retrieve full task details including dependencies.`,
881
- schema: z3__default.default.object({
882
- taskId: z3__default.default.string().describe("The ID of the task to get")
890
+ schema: z13__default.default.object({
891
+ taskId: z13__default.default.string().describe("The ID of the task to get")
883
892
  })
884
893
  };
885
894
 
@@ -902,7 +911,7 @@ function createTaskGetHandler(stateManager) {
902
911
  var taskListTool = {
903
912
  name: "TaskList",
904
913
  description: `List all tasks with current state.`,
905
- schema: z3__default.default.object({})
914
+ schema: z13__default.default.object({})
906
915
  };
907
916
 
908
917
  // src/tools/task-list/handler.ts
@@ -918,11 +927,11 @@ function createTaskListHandler(stateManager) {
918
927
  var taskUpdateTool = {
919
928
  name: "TaskUpdate",
920
929
  description: `Update status, add blockers, modify details.`,
921
- schema: z3__default.default.object({
922
- taskId: z3__default.default.string().describe("The ID of the task to get"),
923
- status: z3__default.default.enum(["pending", "in_progress", "completed"]).describe("The status of the task"),
924
- addBlockedBy: z3__default.default.array(z3__default.default.string()).describe("The IDs of the tasks that are blocking this task"),
925
- addBlocks: z3__default.default.array(z3__default.default.string()).describe("The IDs of the tasks that this task is blocking")
930
+ schema: z13__default.default.object({
931
+ taskId: z13__default.default.string().describe("The ID of the task to get"),
932
+ status: z13__default.default.enum(["pending", "in_progress", "completed"]).describe("The status of the task"),
933
+ addBlockedBy: z13__default.default.array(z13__default.default.string()).describe("The IDs of the tasks that are blocking this task"),
934
+ addBlocks: z13__default.default.array(z13__default.default.string()).describe("The IDs of the tasks that this task is blocking")
926
935
  })
927
936
  };
928
937
 
@@ -990,13 +999,53 @@ Use this tool to:
990
999
  - Execute scripts and chain commands with pipes (|) or logical operators (&&, ||)
991
1000
  - Inspect files and directories
992
1001
  `,
993
- schema: z3__default.default.object({
994
- command: z3__default.default.string().describe(
1002
+ schema: z13__default.default.object({
1003
+ command: z13__default.default.string().describe(
995
1004
  "The bash command to execute. Can include pipes (|), redirects (>, >>), logical operators (&&, ||), and shell features like command substitution $(...)."
996
1005
  )
997
1006
  }),
998
1007
  strict: true
999
1008
  };
1009
+ var askUserQuestionTool = {
1010
+ name: "AskUserQuestion",
1011
+ description: `Use this tool when you need to ask the user questions during execution. This allows you to:
1012
+
1013
+ 1. Gather user preferences or requirements
1014
+ 2. Clarify ambiguous instructions
1015
+ 3. Get decisions on implementation choices as you work
1016
+ 4. Offer choices to the user about what direction to take.
1017
+
1018
+ Usage notes:
1019
+
1020
+ * Users will always be able to select "Other" to provide custom text input
1021
+ * Use multiSelect: true to allow multiple answers to be selected for a question
1022
+ * If you recommend a specific option, make that the first option in the list and add "(Recommended)" at the end of the label
1023
+ `,
1024
+ schema: z13__default.default.object({
1025
+ questions: z13__default.default.array(
1026
+ z13__default.default.object({
1027
+ question: z13__default.default.string().describe("The full question text to display"),
1028
+ header: z13__default.default.string().describe("Short label for the question (max 12 characters)"),
1029
+ options: z13__default.default.array(
1030
+ z13__default.default.object({
1031
+ label: z13__default.default.string(),
1032
+ description: z13__default.default.string()
1033
+ })
1034
+ ).min(0).max(4).describe("Array of 0-4 choices, each with label and description"),
1035
+ multiSelect: z13__default.default.boolean().describe("If true, users can select multiple options")
1036
+ })
1037
+ )
1038
+ }),
1039
+ strict: true
1040
+ };
1041
+
1042
+ // src/tools/ask-user-question/handler.ts
1043
+ var createAskUserQuestionHandler = () => (args) => {
1044
+ return {
1045
+ toolResponse: "Question submitted",
1046
+ data: { questions: args.questions }
1047
+ };
1048
+ };
1000
1049
 
1001
1050
  // node_modules/uuid/dist/esm-node/stringify.js
1002
1051
  var byteToHex = [];
@@ -1169,7 +1218,7 @@ async function invokeModel({
1169
1218
  const parentWorkflowId = info.workflowExecution.workflowId;
1170
1219
  const parentRunId = info.workflowExecution.runId;
1171
1220
  const handle = client.getHandle(parentWorkflowId, parentRunId);
1172
- const { tools } = await handle.query(getStateQuery);
1221
+ const { tools } = await handle.query(`get${agentName}State`);
1173
1222
  const messages$1 = await thread.load();
1174
1223
  const response = await model.invoke(
1175
1224
  [...messages.mapStoredMessagesToChatMessages(messages$1)],
@@ -1196,19 +1245,6 @@ async function invokeModel({
1196
1245
  }
1197
1246
  };
1198
1247
  }
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
1248
  function createGlobHandler(fs) {
1213
1249
  return async (_args) => {
1214
1250
  new justBash.Bash({ fs });
@@ -1400,7 +1436,6 @@ exports.createToolRouter = createToolRouter;
1400
1436
  exports.defineSubagent = defineSubagent;
1401
1437
  exports.defineTool = defineTool;
1402
1438
  exports.editTool = editTool;
1403
- exports.getStateQuery = getStateQuery;
1404
1439
  exports.globTool = globTool;
1405
1440
  exports.grepTool = grepTool;
1406
1441
  exports.hasNoOtherToolCalls = hasNoOtherToolCalls;