@empiricalrun/test-gen 0.57.2 → 0.59.0

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.
Files changed (147) hide show
  1. package/CHANGELOG.md +69 -0
  2. package/dist/actions/index.d.ts.map +1 -1
  3. package/dist/actions/skill.js +2 -2
  4. package/dist/actions/utils/index.js +2 -3
  5. package/dist/agent/browsing/index.js +1 -2
  6. package/dist/agent/browsing/run.d.ts +3 -1
  7. package/dist/agent/browsing/run.d.ts.map +1 -1
  8. package/dist/agent/browsing/run.js +24 -27
  9. package/dist/agent/browsing/utils.d.ts +1 -14
  10. package/dist/agent/browsing/utils.d.ts.map +1 -1
  11. package/dist/agent/browsing/utils.js +10 -67
  12. package/dist/agent/chat/agent-loop.d.ts +6 -3
  13. package/dist/agent/chat/agent-loop.d.ts.map +1 -1
  14. package/dist/agent/chat/agent-loop.js +43 -27
  15. package/dist/agent/chat/exports.d.ts +7 -8
  16. package/dist/agent/chat/exports.d.ts.map +1 -1
  17. package/dist/agent/chat/exports.js +14 -34
  18. package/dist/agent/chat/index.d.ts +1 -1
  19. package/dist/agent/chat/index.d.ts.map +1 -1
  20. package/dist/agent/chat/index.js +20 -10
  21. package/dist/agent/chat/models.d.ts +6 -0
  22. package/dist/agent/chat/models.d.ts.map +1 -0
  23. package/dist/agent/chat/models.js +37 -0
  24. package/dist/agent/chat/prompt.d.ts +2 -1
  25. package/dist/agent/chat/prompt.d.ts.map +1 -1
  26. package/dist/agent/chat/prompt.js +40 -12
  27. package/dist/agent/chat/repo.d.ts +2 -1
  28. package/dist/agent/chat/repo.d.ts.map +1 -1
  29. package/dist/agent/chat/repo.js +32 -36
  30. package/dist/agent/chat/state.d.ts +15 -7
  31. package/dist/agent/chat/state.d.ts.map +1 -1
  32. package/dist/agent/chat/state.js +95 -32
  33. package/dist/agent/chat/types.d.ts +0 -1
  34. package/dist/agent/chat/types.d.ts.map +1 -1
  35. package/dist/agent/codegen/create-test-block.js +1 -2
  36. package/dist/agent/codegen/fix-ts-errors.js +1 -2
  37. package/dist/agent/codegen/generate-code-apply-changes.js +2 -3
  38. package/dist/agent/codegen/lexical-scoped-vars.js +1 -2
  39. package/dist/agent/codegen/repo-edit.js +2 -3
  40. package/dist/agent/codegen/run.js +2 -3
  41. package/dist/agent/codegen/skills-retriever.d.ts +3 -3
  42. package/dist/agent/codegen/skills-retriever.d.ts.map +1 -1
  43. package/dist/agent/codegen/skills-retriever.js +2 -2
  44. package/dist/agent/codegen/test-update-feedback.js +1 -2
  45. package/dist/agent/codegen/update-flow.js +4 -5
  46. package/dist/agent/codegen/use-skill.js +1 -2
  47. package/dist/agent/codegen/utils.js +9 -10
  48. package/dist/agent/cua/computer.js +3 -4
  49. package/dist/agent/cua/index.js +2 -3
  50. package/dist/agent/cua/model.js +1 -2
  51. package/dist/agent/diagnosis-agent/index.js +2 -3
  52. package/dist/agent/diagnosis-agent/strict-mode-violation.js +1 -2
  53. package/dist/agent/enrich-prompt/index.d.ts +1 -1
  54. package/dist/agent/enrich-prompt/index.d.ts.map +1 -1
  55. package/dist/agent/enrich-prompt/utils.js +1 -2
  56. package/dist/agent/infer-agent/index.js +1 -2
  57. package/dist/agent/master/action-tool-calls.js +3 -3
  58. package/dist/agent/master/browser-tests/index.spec.js +6 -6
  59. package/dist/agent/master/element-annotation.js +2 -3
  60. package/dist/agent/master/execute-browser-action.d.ts +1 -1
  61. package/dist/agent/master/execute-browser-action.d.ts.map +1 -1
  62. package/dist/agent/master/execute-browser-action.js +1 -2
  63. package/dist/agent/master/execute-skill-action.js +1 -2
  64. package/dist/agent/master/icon-descriptor/index.js +6 -7
  65. package/dist/agent/master/icon-descriptor/normalize-svg.js +1 -2
  66. package/dist/agent/master/next-action.js +1 -2
  67. package/dist/agent/master/planner.d.ts.map +1 -1
  68. package/dist/agent/master/planner.js +1 -2
  69. package/dist/agent/master/run.js +3 -3
  70. package/dist/agent/master/scroller.js +1 -2
  71. package/dist/agent/master/with-hints.d.ts +1 -1
  72. package/dist/agent/master/with-hints.d.ts.map +1 -1
  73. package/dist/agent/planner/run-time-planner.d.ts.map +1 -1
  74. package/dist/agent/planner/run-time-planner.js +1 -2
  75. package/dist/agent/planner/run.js +1 -2
  76. package/dist/bin/index.js +4 -0
  77. package/dist/bin/logger/index.js +2 -2
  78. package/dist/bin/utils/context.js +5 -6
  79. package/dist/bin/utils/fs/index.d.ts.map +1 -1
  80. package/dist/bin/utils/fs/index.js +4 -5
  81. package/dist/bin/utils/index.d.ts +1 -0
  82. package/dist/bin/utils/index.d.ts.map +1 -1
  83. package/dist/bin/utils/index.js +2 -3
  84. package/dist/bin/utils/platform/web/index.d.ts.map +1 -1
  85. package/dist/bin/utils/platform/web/index.js +21 -21
  86. package/dist/bin/utils/scenarios/index.js +3 -4
  87. package/dist/constants/index.js +1 -1
  88. package/dist/file/server.js +2 -2
  89. package/dist/human-in-the-loop/cli.js +1 -2
  90. package/dist/human-in-the-loop/ipc.js +2 -3
  91. package/dist/index.d.ts +1 -0
  92. package/dist/index.d.ts.map +1 -1
  93. package/dist/index.js +4 -2
  94. package/dist/prompts/lib/ts-transformer.js +17 -7
  95. package/dist/reporter/index.js +3 -3
  96. package/dist/reporter/lib.js +1 -1
  97. package/dist/session/index.js +6 -7
  98. package/dist/test-build/index.js +3 -4
  99. package/dist/tool-call-service/index.d.ts +3 -3
  100. package/dist/tool-call-service/index.d.ts.map +1 -1
  101. package/dist/tool-call-service/index.js +51 -71
  102. package/dist/tool-call-service/utils.d.ts +10 -0
  103. package/dist/tool-call-service/utils.d.ts.map +1 -0
  104. package/dist/tool-call-service/utils.js +23 -0
  105. package/dist/tools/commit-and-create-pr.js +2 -2
  106. package/dist/tools/download-build.d.ts +9 -0
  107. package/dist/tools/download-build.d.ts.map +1 -1
  108. package/dist/tools/download-build.js +5 -4
  109. package/dist/tools/grep/ripgrep/index.js +2 -3
  110. package/dist/tools/grep/ripgrep/types.d.ts +0 -2
  111. package/dist/tools/grep/ripgrep/types.d.ts.map +1 -1
  112. package/dist/tools/str_replace_editor.js +3 -3
  113. package/dist/tools/test-gen-browser.d.ts.map +1 -1
  114. package/dist/tools/test-gen-browser.js +8 -13
  115. package/dist/tools/test-run-fetcher/index.js +2 -2
  116. package/dist/tools/test-run.d.ts.map +1 -1
  117. package/dist/tools/test-run.js +8 -13
  118. package/dist/tools/utils/index.js +2 -3
  119. package/dist/types/index.d.ts +8 -0
  120. package/dist/types/index.d.ts.map +1 -1
  121. package/dist/uploader/index.js +6 -6
  122. package/dist/uploader/utils.d.ts.map +1 -1
  123. package/dist/uploader/utils.js +2 -2
  124. package/dist/utils/checkpoint.d.ts.map +1 -1
  125. package/dist/utils/checkpoint.js +4 -3
  126. package/dist/utils/env.js +1 -2
  127. package/dist/utils/exec.d.ts +2 -2
  128. package/dist/utils/exec.d.ts.map +1 -1
  129. package/dist/utils/exec.js +7 -6
  130. package/dist/utils/file-tree.d.ts +3 -0
  131. package/dist/utils/file-tree.d.ts.map +1 -0
  132. package/dist/utils/file-tree.js +42 -0
  133. package/dist/utils/file.js +1 -2
  134. package/dist/utils/git.js +7 -8
  135. package/dist/utils/html.d.ts.map +1 -1
  136. package/dist/utils/pw-test.js +1 -2
  137. package/dist/utils/repo-tree.d.ts +2 -1
  138. package/dist/utils/repo-tree.d.ts.map +1 -1
  139. package/dist/utils/repo-tree.js +62 -53
  140. package/dist/utils/slug.d.ts.map +1 -1
  141. package/dist/utils/slug.js +1 -1
  142. package/dist/utils/string.js +1 -2
  143. package/package.json +5 -5
  144. package/tsconfig.tsbuildinfo +1 -0
  145. package/dist/agent/chat/model.d.ts +0 -4
  146. package/dist/agent/chat/model.d.ts.map +0 -1
  147. package/dist/agent/chat/model.js +0 -17
package/CHANGELOG.md CHANGED
@@ -1,5 +1,74 @@
1
1
  # @empiricalrun/test-gen
2
2
 
3
+ ## 0.59.0
4
+
5
+ ### Minor Changes
6
+
7
+ - e2b0318: feat: dashboard session migration from CLI working
8
+ - 894c5b5: fix: stricter types for tool call args in canonical message
9
+ - 919e7df: fix: session create, duplicate user message, add Model Options
10
+ - 045e370: feat: stateless build download for tool execution
11
+ - f2d5859: feat: canonical migration for claude and openai
12
+ - e2b0318: feat: migrate dashboard chat sessions to canonical chat state
13
+ - 4d3b46a: feat: migrate to new chat state version in cli run
14
+
15
+ ### Patch Changes
16
+
17
+ - 72f4577: feat: stop marking files as only and move to cmd builder approach
18
+ - 82b3373: test: remove irrelevant or flaky tests
19
+ - 3dbd4ff: fix: remove teardown skip since we interrupt agent with SIGINT
20
+ - 7c77600: refactor: move test-gen file changes to prepare for removal
21
+ - 562c25d: fix: update chat agent system prompt for using try/catch
22
+ - 43656bf: refactor: split tool call execute into 2 methods
23
+ - 51a9975: fix: unit tests for test-gen tool call
24
+ - 772b93c: feat: gemini message transformer into canonical message type
25
+ - 0c935ce: chore: chat model types are moved to shared-types pkg
26
+ - 050fbd3: fix: model selection is ignored while creating a new session
27
+ - ddfd009: fix: refactor chat agent and session list UI
28
+ - 28682e2: feat: use test-run cmd builder in test-gen, remove test.only marking
29
+ - 6b2ed6d: chore: use function args to tell if tool execution is remote
30
+ - 511dbb1: test: skip tests for the old master agent
31
+ - 7145e34: test: add new agent-loop test for openai canonical model
32
+ - 43fb70f: feat: add retry functionality for chat sessions and update ChatAgent …
33
+ - d1d1055: feat: integrate askUserForInput state into session handling
34
+ - ef491c0: fix: incorrect build url getter
35
+ - Updated dependencies [72f4577]
36
+ - Updated dependencies [97cef16]
37
+ - Updated dependencies [e2b0318]
38
+ - Updated dependencies [772b93c]
39
+ - Updated dependencies [894c5b5]
40
+ - Updated dependencies [0c935ce]
41
+ - Updated dependencies [919e7df]
42
+ - Updated dependencies [045e370]
43
+ - Updated dependencies [f2d5859]
44
+ - Updated dependencies [919e7df]
45
+ - Updated dependencies [ddfd009]
46
+ - Updated dependencies [e2b0318]
47
+ - Updated dependencies [28682e2]
48
+ - Updated dependencies [b415e29]
49
+ - Updated dependencies [09291a8]
50
+ - Updated dependencies [aab69ae]
51
+ - Updated dependencies [4d3b46a]
52
+ - Updated dependencies [bc5996d]
53
+ - @empiricalrun/test-run@0.9.0
54
+ - @empiricalrun/llm@0.16.0
55
+
56
+ ## 0.58.0
57
+
58
+ ### Minor Changes
59
+
60
+ - 8c71fd1: feat: pass file info to system prompt to construct repo context
61
+
62
+ ### Patch Changes
63
+
64
+ - 637c97f: chore: moved model creation logic from test-gen to llm
65
+ - Updated dependencies [0634233]
66
+ - Updated dependencies [637c97f]
67
+ - Updated dependencies [21b0768]
68
+ - @empiricalrun/test-run@0.8.5
69
+ - @empiricalrun/llm@0.15.4
70
+ - @empiricalrun/r2-uploader@0.3.9
71
+
3
72
  ## 0.57.2
4
73
 
5
74
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/actions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIhD,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,OAAO,EAEL,UAAU,EACV,YAAY,EAEb,MAAM,UAAU,CAAC;AAWlB,qBAAa,iBAAiB;IAQ1B,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,cAAc;IARxB,OAAO,CAAC,gBAAgB,CAAwC;IAChE,OAAO,CAAC,eAAe,CAInB;gBAEM,IAAI,EAAE,WAAW,EACjB,cAAc,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM;IAgB5C,aAAa,CACjB,IAAI,oBAAa,EACjB,IAAI,EAAE,UAAU,EAChB,KAAK,CAAC,EAAE,WAAW,GAClB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IA0D9B,wBAAwB,IAAI,YAAY,EAAE;IAoB1C,sBAAsB,IAAI,YAAY,EAAE;IAWxC,YAAY,IAAI;QACd,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,MAAM,EAAE,CAAC;KACvB;IAUD,gBAAgB,CAAC,KAAK,EAAE,MAAM;IAK9B;;;;;;OAMG;IACH,aAAa,IAAI,OAAO;IAQxB,UAAU;IAWV,iBAAiB;IAIjB,iBAAiB,CAAC,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;CAItD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/actions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIhD,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,OAAO,EAEL,UAAU,EACV,YAAY,EAEb,MAAM,UAAU,CAAC;AAWlB,qBAAa,iBAAiB;IAQ1B,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,cAAc;IARxB,OAAO,CAAC,gBAAgB,CAAwC;IAChE,OAAO,CAAC,eAAe,CAInB;gBAEM,IAAI,EAAE,WAAW,EACjB,cAAc,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM;IAgB5C,aAAa,CACjB,IAAI,EAAE,MAAM,YAAK,EACjB,IAAI,EAAE,UAAU,EAChB,KAAK,CAAC,EAAE,WAAW,GAClB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IA0D9B,wBAAwB,IAAI,YAAY,EAAE;IAoB1C,sBAAsB,IAAI,YAAY,EAAE;IAWxC,YAAY,IAAI;QACd,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,MAAM,EAAE,CAAC;KACvB;IAUD,gBAAgB,CAAC,KAAK,EAAE,MAAM;IAK9B;;;;;;OAMG;IACH,aAAa,IAAI,OAAO;IAQxB,UAAU;IAWV,iBAAiB;IAIjB,iBAAiB,CAAC,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;CAItD"}
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.skillActionGenerator = exports.extractSkillFromArgs = exports.testCaseSkills = exports.SKILL_USAGE = void 0;
6
+ exports.skillActionGenerator = exports.testCaseSkills = exports.SKILL_USAGE = void 0;
7
+ exports.extractSkillFromArgs = extractSkillFromArgs;
7
8
  const promises_1 = __importDefault(require("fs/promises"));
8
9
  const api_1 = __importDefault(require("tsx/cjs/api"));
9
10
  const use_skill_1 = require("../agent/codegen/use-skill");
@@ -28,7 +29,6 @@ function extractSkillFromArgs(args) {
28
29
  const [skillDetails] = availableSkills.filter((skillDetails) => skillDetails.testStep === skill);
29
30
  return { skillDetails };
30
31
  }
31
- exports.extractSkillFromArgs = extractSkillFromArgs;
32
32
  const skillActionGenerator = (page, options) => {
33
33
  const availableSkills = exports.testCaseSkills.getAvailableSkills();
34
34
  return {
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPageVarName = exports.getPlaywrightLocatorUsingCssSelector = void 0;
3
+ exports.getPlaywrightLocatorUsingCssSelector = getPlaywrightLocatorUsingCssSelector;
4
+ exports.getPageVarName = getPageVarName;
4
5
  async function getPlaywrightLocatorUsingCssSelector(cssSelector, xpath, page, elementAnnotation) {
5
6
  // TODO: analyse other solutions than just css. Also find other solutions to support :has-text -> prompting ?
6
7
  // jquery doesnt support :has-text. neither css. Only playwright locator supports this selector though.
@@ -101,9 +102,7 @@ async function getPlaywrightLocatorUsingCssSelector(cssSelector, xpath, page, el
101
102
  elementAnnotation,
102
103
  });
103
104
  }
104
- exports.getPlaywrightLocatorUsingCssSelector = getPlaywrightLocatorUsingCssSelector;
105
105
  function getPageVarName() {
106
106
  // eslint-disable-next-line turbo/no-undeclared-env-vars
107
107
  return process.env.PAGE_VAR_NAME || "page";
108
108
  }
109
- exports.getPageVarName = getPageVarName;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.executeTaskUsingBrowsingAgent = void 0;
3
+ exports.executeTaskUsingBrowsingAgent = executeTaskUsingBrowsingAgent;
4
4
  const llm_1 = require("@empiricalrun/llm");
5
5
  const constants_1 = require("../../constants");
6
6
  const promptTemplate_0 = "{{#section \"system\"}}\nYou are a browser automation agent who is given a task to generate code for navigation and assertion. This task is your\ngoal and you must achieve it.\n\nYou will be provided with already executed actions and basis that you need to pick the next step to achieve the task.\nRemember that the goal must be achieved.\n\nYou will be provided with the web page snapshot in the form of Document Object Model. Based on the goal and available\ntool calls you need to pick the appropriate tool call.\n\nInstructions:\n- Take actions one at a time. Do not try to take multiple actions\n- You can respond with multiple assertions in one shot\n- Do not repeat the same actions again otherwise your response will be marked INVALID\n- Avoid repeating errors which we got while executing the last action\n- Stick to the task provided to you and mark the task done once the task is complete\n- Do not execute any action which is not mentioned in the task\n- Do not repeat actions which are already executed more than twice otherwise your response will be marked INVALID\n- Always refer to \"Executed actions\" before deciding your next action for completion of the task.\n- End the task done if all actions required for task are executed\n{{/section}}\n\n{{#section \"user\"}}\nTask:\n{{task}}\n\nCurrent page snapshot:\n{{pageSnapshot}}\n{{/section}}";
@@ -64,4 +64,3 @@ async function executeTaskUsingBrowsingAgent({ action, page, actions, llm, trace
64
64
  toolCallsSpan?.end({ output: { toolCalls, generatedCodeSteps } });
65
65
  return generatedCodeSteps;
66
66
  }
67
- exports.executeTaskUsingBrowsingAgent = executeTaskUsingBrowsingAgent;
@@ -1,4 +1,6 @@
1
1
  type GenerateTestsType = {
2
+ testCaseName: string;
3
+ testCaseSuites: string[];
2
4
  testFilePath: string;
3
5
  filePathToUpdate: string;
4
6
  pwProjectsFilter: string[];
@@ -7,7 +9,7 @@ type GenerateTestsType = {
7
9
  traceId?: string;
8
10
  editFileWithGeneratedCode: boolean;
9
11
  };
10
- export declare function generateTestsUsingMasterAgent({ testFilePath, filePathToUpdate, pwProjectsFilter, testGenToken, repoDir, traceId, editFileWithGeneratedCode, }: GenerateTestsType): Promise<{
12
+ export declare function generateTestsUsingMasterAgent({ testCaseName, testCaseSuites, testFilePath, filePathToUpdate, pwProjectsFilter, testGenToken, repoDir, traceId, editFileWithGeneratedCode, }: GenerateTestsType): Promise<{
11
13
  isError: boolean;
12
14
  error: string;
13
15
  actionsSummary?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/agent/browsing/run.ts"],"names":[],"mappings":"AAiBA,KAAK,iBAAiB,GAAG;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,MAAM,CAAC;IACzB,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,yBAAyB,EAAE,OAAO,CAAC;CACpC,CAAC;AAEF,wBAAsB,6BAA6B,CAAC,EAClD,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,EACZ,OAAO,EACP,OAAO,EACP,yBAAyB,GAC1B,EAAE,iBAAiB,GAAG,OAAO,CAAC;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC,CAuFD"}
1
+ {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/agent/browsing/run.ts"],"names":[],"mappings":"AAcA,KAAK,iBAAiB,GAAG;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,MAAM,CAAC;IACzB,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,yBAAyB,EAAE,OAAO,CAAC;CACpC,CAAC;AAEF,wBAAsB,6BAA6B,CAAC,EAClD,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,EACZ,OAAO,EACP,OAAO,EACP,yBAAyB,GAC1B,EAAE,iBAAiB,GAAG,OAAO,CAAC;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC,CAsFD"}
@@ -3,14 +3,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.generateTestsUsingMasterAgent = void 0;
6
+ exports.generateTestsUsingMasterAgent = generateTestsUsingMasterAgent;
7
+ const test_run_1 = require("@empiricalrun/test-run");
7
8
  const detect_port_1 = __importDefault(require("detect-port"));
8
9
  const fs_1 = __importDefault(require("fs"));
9
10
  const web_1 = require("../../bin/utils/platform/web");
10
11
  const server_1 = require("../../file/server");
11
12
  const exec_1 = require("../../utils/exec");
12
13
  const utils_1 = require("./utils");
13
- async function generateTestsUsingMasterAgent({ testFilePath, filePathToUpdate, pwProjectsFilter, testGenToken, repoDir, traceId, editFileWithGeneratedCode, }) {
14
+ async function generateTestsUsingMasterAgent({ testCaseName, testCaseSuites, testFilePath, filePathToUpdate, pwProjectsFilter, testGenToken, repoDir, traceId, editFileWithGeneratedCode, }) {
14
15
  if (!fs_1.default.existsSync(testFilePath)) {
15
16
  throw new Error(`File for master agent to run not found: ${testFilePath}`);
16
17
  }
@@ -32,24 +33,27 @@ async function generateTestsUsingMasterAgent({ testFilePath, filePathToUpdate, p
32
33
  const project = await (0, utils_1.detectProjectName)(testFilePath, playwrightConfig, pwProjectsFilter);
33
34
  const pageVar = await (0, web_1.getPageVariableNameFromCreateTest)(filePathToUpdate);
34
35
  console.log(`Detected playwright project name: ${project}`);
35
- // run playwright test which will internally run the master agent
36
- const teardownFileRegex = /.*\.teardown\.ts/;
37
- const testsDirectory = `${repoDir}/tests`;
38
- const isTestRunTriggeredForTeardown = teardownFileRegex.test(testFilePath);
39
- const teardowns = new utils_1.TeardownManager(testsDirectory);
40
- let removeListeners;
41
- const command = `npx playwright test ${testFilePath} --retries 0 --project ${project} --timeout 0`;
42
- let isError = false;
43
- let error = "";
36
+ const testsDir = "tests";
37
+ const cmd = await (0, test_run_1.runSpecificTestsCmd)({
38
+ tests: [
39
+ {
40
+ name: testCaseName,
41
+ dir: testsDir,
42
+ filePath: testFilePath,
43
+ suites: testCaseSuites,
44
+ },
45
+ ],
46
+ projects: [project],
47
+ passthroughArgs: "--retries 0 --timeout 0",
48
+ //@ts-ignore
49
+ platform: "web",
50
+ });
51
+ let error = undefined;
44
52
  try {
45
- if (!isTestRunTriggeredForTeardown) {
46
- removeListeners = await teardowns.skipAll();
47
- }
48
- await pm.execute(command.split(" "), {
53
+ await pm.execute(cmd.command, cmd.args, {
49
54
  env: {
50
55
  IPC_FILE_SERVICE_PORT: availablePort.toString(),
51
56
  PW_TEST_HTML_REPORT_OPEN: "never",
52
- // pass the test gen token so that the agent has the same configuration as cli
53
57
  TEST_GEN_TOKEN: testGenToken,
54
58
  PAGE_VAR_NAME: pageVar || "page",
55
59
  DISPLAY: ":99",
@@ -60,15 +64,9 @@ async function generateTestsUsingMasterAgent({ testFilePath, filePathToUpdate, p
60
64
  catch (e) {
61
65
  error = `Failed to generate test using master agent ${e}`;
62
66
  console.error(error);
63
- isError = true;
64
- }
65
- finally {
66
- // Remove process listeners before unskipping files
67
- removeListeners?.();
68
- teardowns.unskipAll();
69
67
  }
70
- // clean up the file if there is any error
71
- if (isError) {
68
+ if (error) {
69
+ // clean up the file if there is any error
72
70
  try {
73
71
  const fileContent = fs_1.default.readFileSync(filePathToUpdate, "utf-8");
74
72
  const updatedContent = (0, web_1.replaceCreateTestWithNewCode)(filePathToUpdate, fileContent, "");
@@ -83,9 +81,8 @@ async function generateTestsUsingMasterAgent({ testFilePath, filePathToUpdate, p
83
81
  await (0, web_1.removeTestOnly)(testFilePath);
84
82
  await fileServer.stop();
85
83
  return {
86
- isError,
87
- error,
84
+ isError: !!error,
85
+ error: error || "",
88
86
  actionsSummary: fileServer.getActionsSummary(),
89
87
  };
90
88
  }
91
- exports.generateTestsUsingMasterAgent = generateTestsUsingMasterAgent;
@@ -4,11 +4,7 @@ import { Page } from "playwright";
4
4
  import { PlaywrightTestConfig } from "playwright/test";
5
5
  export declare function isRegExp(obj: any): obj is RegExp;
6
6
  export declare function prepareBrowsingAgentTask(steps: string[]): string;
7
- export declare function replaceTodoWithCreateTest({ testFilePath, testCaseName, testCaseSuites, }: {
8
- testFilePath: string;
9
- testCaseName: string;
10
- testCaseSuites: string[];
11
- }): Promise<void>;
7
+ export declare function replaceTodoWithCreateTest(testFilePath: string): Promise<void>;
12
8
  export declare function markTestAsOnly({ testCaseName, testCaseSuites, specPath, }: {
13
9
  testCaseName: string;
14
10
  testCaseSuites: string[];
@@ -33,13 +29,4 @@ export declare function getValidProjectNames(playwrightConfig: PlaywrightTestCon
33
29
  * @returns
34
30
  */
35
31
  export declare function detectProjectName(testFilePath: string, playwrightConfig: PlaywrightTestConfig, pwProjectsFilter?: string[]): Promise<string>;
36
- export declare class TeardownManager {
37
- private directory;
38
- constructor(directory: string);
39
- private teardownFiles;
40
- private getAllTeardownFiles;
41
- private skipTeardownFile;
42
- skipAll(): Promise<() => void>;
43
- unskipAll(): void;
44
- }
45
32
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/agent/browsing/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EAAe,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAIxE,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAwBvD,wBAAgB,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,MAAM,CAKhD;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,EAAE,UAIvD;AAiFD,wBAAsB,yBAAyB,CAAC,EAC9C,YAAY,EACZ,YAAY,EACZ,cAAc,GACf,EAAE;IACD,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,EAAE,CAAC;CAC1B,iBA2BA;AAED,wBAAsB,cAAc,CAAC,EACnC,YAAY,EACZ,cAAc,EACd,QAAQ,GACT,EAAE;IACD,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAC;CAClB,iBAoBA;AAED,wBAAsB,yBAAyB,CAAC,EAC9C,QAAQ,EACR,QAAQ,EACR,KAAK,GACN,EAAE;IACD,QAAQ,EAAE,QAAQ,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,WAAW,CAAC;CACrB,GAAG,OAAO,CAAC,MAAM,CAAC,CAyDlB;AAyBD,wBAAsB,wBAAwB,CAAC,IAAI,EAAE,IAAI,iBA2HxD;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,oBAAoB,CAAC,CA2B/B;AAWD,wBAAsB,oBAAoB,CACxC,gBAAgB,EAAE,oBAAoB,GACrC,OAAO,CAAC,MAAM,EAAE,CAAC,CAQnB;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACrC,YAAY,EAAE,MAAM,EACpB,gBAAgB,EAAE,oBAAoB,EACtC,gBAAgB,GAAE,MAAM,EAAU,GACjC,OAAO,CAAC,MAAM,CAAC,CA+CjB;AAED,qBAAa,eAAe;IACd,OAAO,CAAC,SAAS;gBAAT,SAAS,EAAE,MAAM;IACrC,OAAO,CAAC,aAAa,CAAqB;YAE5B,mBAAmB;YAUnB,gBAAgB;IAsBjB,OAAO;IAoBb,SAAS;CAKjB"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/agent/browsing/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAI3D,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAsBvD,wBAAgB,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,MAAM,CAKhD;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,EAAE,UAIvD;AAiFD,wBAAsB,yBAAyB,CAAC,YAAY,EAAE,MAAM,iBAsBnE;AAED,wBAAsB,cAAc,CAAC,EACnC,YAAY,EACZ,cAAc,EACd,QAAQ,GACT,EAAE;IACD,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAC;CAClB,iBAoBA;AAED,wBAAsB,yBAAyB,CAAC,EAC9C,QAAQ,EACR,QAAQ,EACR,KAAK,GACN,EAAE;IACD,QAAQ,EAAE,QAAQ,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,WAAW,CAAC;CACrB,GAAG,OAAO,CAAC,MAAM,CAAC,CAyDlB;AAyBD,wBAAsB,wBAAwB,CAAC,IAAI,EAAE,IAAI,iBA2HxD;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,oBAAoB,CAAC,CA2B/B;AAWD,wBAAsB,oBAAoB,CACxC,gBAAgB,EAAE,oBAAoB,GACrC,OAAO,CAAC,MAAM,EAAE,CAAC,CAQnB;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACrC,YAAY,EAAE,MAAM,EACpB,gBAAgB,EAAE,oBAAoB,EACtC,gBAAgB,GAAE,MAAM,EAAU,GACjC,OAAO,CAAC,MAAM,CAAC,CA+CjB"}
@@ -3,16 +3,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.TeardownManager = exports.detectProjectName = exports.getValidProjectNames = exports.readPlaywrightConfig = exports.injectPwLocatorGenerator = exports.prepareFileForMasterAgent = exports.markTestAsOnly = exports.replaceTodoWithCreateTest = exports.prepareBrowsingAgentTask = exports.isRegExp = void 0;
6
+ exports.isRegExp = isRegExp;
7
+ exports.prepareBrowsingAgentTask = prepareBrowsingAgentTask;
8
+ exports.replaceTodoWithCreateTest = replaceTodoWithCreateTest;
9
+ exports.markTestAsOnly = markTestAsOnly;
10
+ exports.prepareFileForMasterAgent = prepareFileForMasterAgent;
11
+ exports.injectPwLocatorGenerator = injectPwLocatorGenerator;
12
+ exports.readPlaywrightConfig = readPlaywrightConfig;
13
+ exports.getValidProjectNames = getValidProjectNames;
14
+ exports.detectProjectName = detectProjectName;
7
15
  const fs_1 = __importDefault(require("fs"));
8
16
  const minimatch_1 = require("minimatch");
9
17
  const path_1 = __importDefault(require("path"));
10
- const ts_morph_1 = require("ts-morph");
11
18
  // For TypeScript type safety
12
19
  let tsxImport = null;
13
20
  const logger_1 = require("../../bin/logger");
14
21
  const context_1 = require("../../bin/utils/context");
15
- const fs_2 = require("../../bin/utils/fs");
16
22
  const web_1 = require("../../bin/utils/platform/web");
17
23
  const create_test_block_1 = require("../codegen/create-test-block");
18
24
  const fix_ts_errors_1 = require("../codegen/fix-ts-errors");
@@ -22,13 +28,11 @@ function isRegExp(obj) {
22
28
  return (obj instanceof RegExp ||
23
29
  Object.prototype.toString.call(obj) === "[object RegExp]");
24
30
  }
25
- exports.isRegExp = isRegExp;
26
31
  function prepareBrowsingAgentTask(steps) {
27
32
  const sanitizedSteps = steps.map((step) => step.replace(/`/g, "\\`"));
28
33
  const task = `${sanitizedSteps.join("\n")}\n`;
29
34
  return task;
30
35
  }
31
- exports.prepareBrowsingAgentTask = prepareBrowsingAgentTask;
32
36
  async function addImportForCreateTest(testFilePath) {
33
37
  // Instead of using "@empiricalrun/test-gen", we use the local dist file
34
38
  // This is to avoid assuming that the test-gen package is installed in the project
@@ -89,7 +93,7 @@ async function prepareFileForUpdateScenario({ testCase, specPath, trace, }) {
89
93
  });
90
94
  return createTestFilePath;
91
95
  }
92
- async function replaceTodoWithCreateTest({ testFilePath, testCaseName, testCaseSuites, }) {
96
+ async function replaceTodoWithCreateTest(testFilePath) {
93
97
  // This method is an alternative to prepareFileForUpdateScenario
94
98
  // TODO: Does not support scoped variables and updates in POM files
95
99
  const fileContent = fs_1.default.readFileSync(testFilePath, "utf-8");
@@ -102,13 +106,7 @@ async function replaceTodoWithCreateTest({ testFilePath, testCaseName, testCaseS
102
106
  const pageVariable = pageVarName || "page"; // Default to "page" if not specified
103
107
  fs_1.default.writeFileSync(testFilePath, fileContent.replace(todoRegex, (_, __, todoText) => `await createTest("${todoText.replace(/"/g, '\\"')}", ${pageVariable});`));
104
108
  await addImportForCreateTest(testFilePath);
105
- await markTestAsOnly({
106
- testCaseName,
107
- testCaseSuites,
108
- specPath: testFilePath,
109
- });
110
109
  }
111
- exports.replaceTodoWithCreateTest = replaceTodoWithCreateTest;
112
110
  async function markTestAsOnly({ testCaseName, testCaseSuites, specPath, }) {
113
111
  const testFileContent = fs_1.default.readFileSync(specPath, "utf-8");
114
112
  const { testBlock, testNode } = (0, web_1.getTypescriptTestBlock)({
@@ -124,7 +122,6 @@ async function markTestAsOnly({ testCaseName, testCaseSuites, specPath, }) {
124
122
  fs_1.default.writeFileSync(specPath, updatedTestFileContent);
125
123
  }
126
124
  }
127
- exports.markTestAsOnly = markTestAsOnly;
128
125
  async function prepareFileForMasterAgent({ testCase, specPath, trace, }) {
129
126
  const prepareFileSpan = trace?.span({
130
127
  name: "prepare-file-for-master-agent",
@@ -170,7 +167,6 @@ async function prepareFileForMasterAgent({ testCase, specPath, trace, }) {
170
167
  });
171
168
  return updatePath;
172
169
  }
173
- exports.prepareFileForMasterAgent = prepareFileForMasterAgent;
174
170
  function newContentsWithTestOnly(existingContents, originalTestBlock, updatedTestBlock, parentDescribeBlock) {
175
171
  if (!parentDescribeBlock) {
176
172
  const testMarkedAsOnly = updatedTestBlock.replace("test(", "test.only(");
@@ -290,7 +286,6 @@ async function injectPwLocatorGenerator(page) {
290
286
  console.warn("Error injecting script in iframe.");
291
287
  }
292
288
  }
293
- exports.injectPwLocatorGenerator = injectPwLocatorGenerator;
294
289
  /**
295
290
  * function to read playwright config from the source repo
296
291
  * @return {*} {Promise<PlaywrightTestConfig>}
@@ -318,7 +313,6 @@ async function readPlaywrightConfig(repoDir) {
318
313
  const playwrightConfig = (await tsxImport.require("./playwright.config.ts", `${repoDir}/${lastDir}`)).default;
319
314
  return playwrightConfig;
320
315
  }
321
- exports.readPlaywrightConfig = readPlaywrightConfig;
322
316
  function matchAgainstPattern(pattern, filePathToTest) {
323
317
  if (isRegExp(pattern)) {
324
318
  const regExp = pattern;
@@ -337,7 +331,6 @@ async function getValidProjectNames(playwrightConfig) {
337
331
  .filter((p) => !!p);
338
332
  return filteredProjectNames;
339
333
  }
340
- exports.getValidProjectNames = getValidProjectNames;
341
334
  /**
342
335
  * detect the project name for the given file in playwright test repo
343
336
  * if project and test file path for running test don't match, then playwright throws error
@@ -387,53 +380,3 @@ async function detectProjectName(testFilePath, playwrightConfig, pwProjectsFilte
387
380
  }
388
381
  return filteredProjectNames[0];
389
382
  }
390
- exports.detectProjectName = detectProjectName;
391
- class TeardownManager {
392
- directory;
393
- constructor(directory) {
394
- this.directory = directory;
395
- }
396
- teardownFiles = [];
397
- async getAllTeardownFiles() {
398
- const teardownFileRegex = /.*\.teardown\.ts/;
399
- const teardownFiles = await (0, fs_2.readFilesInDirectory)(this.directory, (fileName) => teardownFileRegex.test(fileName));
400
- return teardownFiles;
401
- }
402
- async skipTeardownFile(filePath) {
403
- const project = new ts_morph_1.Project();
404
- const sourceFile = project.addSourceFileAtPath(filePath);
405
- sourceFile
406
- .getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression)
407
- .forEach((callExpression) => {
408
- const expression = callExpression.getExpression();
409
- if (expression.getText() === "teardown") {
410
- expression.replaceWithText("teardown.skip");
411
- }
412
- else if (expression.getText() === "test") {
413
- expression.replaceWithText("test.skip");
414
- }
415
- });
416
- // Save the modified file
417
- sourceFile.save().catch((error) => {
418
- console.error(`Error updating the file: ${filePath}`, error);
419
- });
420
- }
421
- async skipAll() {
422
- this.teardownFiles = await this.getAllTeardownFiles();
423
- await Promise.all(this.teardownFiles.map(async ({ filePath }) => await this.skipTeardownFile(filePath)));
424
- const setupProcessListeners = (cleanup) => {
425
- const events = ["beforeExit", "exit", "SIGINT", "SIGTERM"];
426
- events.forEach((event) => process.on(event, cleanup));
427
- return () => {
428
- events.forEach((event) => process.removeListener(event, cleanup));
429
- };
430
- };
431
- return setupProcessListeners(this.unskipAll.bind(this));
432
- }
433
- unskipAll() {
434
- this.teardownFiles.forEach(({ filePath, content }) => {
435
- fs_1.default.writeFileSync(filePath, content, "utf-8");
436
- });
437
- }
438
- }
439
- exports.TeardownManager = TeardownManager;
@@ -1,12 +1,15 @@
1
1
  import { TraceClient } from "@empiricalrun/llm";
2
- import { IChatModel } from "@empiricalrun/llm/chat";
2
+ import { IChatModel, SupportedChatModels } from "@empiricalrun/llm/chat";
3
3
  import { ToolCallService } from "../../tool-call-service";
4
- import { ReporterFunction, SupportedChatModels } from "./types";
5
- export declare function chatAgentLoop({ chatModel, selectedModel, reporter, trace, toolCallService, }: {
4
+ import { FileInfo } from "../../types";
5
+ import { ReporterFunction } from "./types";
6
+ export declare function chatAgentLoop({ chatModel, selectedModel, reporter, trace, toolCallService, fileInfo, isToolExecutionRemote, }: {
6
7
  chatModel: IChatModel<any>;
7
8
  selectedModel: SupportedChatModels;
8
9
  toolCallService: ToolCallService;
9
10
  reporter: ReporterFunction;
10
11
  trace?: TraceClient;
12
+ fileInfo: FileInfo;
13
+ isToolExecutionRemote: boolean;
11
14
  }): Promise<void>;
12
15
  //# sourceMappingURL=agent-loop.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"agent-loop.d.ts","sourceRoot":"","sources":["../../../src/agent/chat/agent-loop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAmB,MAAM,wBAAwB,CAAC;AAGrE,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAG1D,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAgBhE,wBAAsB,aAAa,CAAC,EAClC,SAAS,EACT,aAAa,EACb,QAAQ,EACR,KAAK,EACL,eAAe,GAChB,EAAE;IACD,SAAS,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC;IAC3B,aAAa,EAAE,mBAAmB,CAAC;IACnC,eAAe,EAAE,eAAe,CAAC;IACjC,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,KAAK,CAAC,EAAE,WAAW,CAAC;CACrB,iBAoCA"}
1
+ {"version":3,"file":"agent-loop.d.ts","sourceRoot":"","sources":["../../../src/agent/chat/agent-loop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAEL,UAAU,EACV,mBAAmB,EAEpB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAGvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AA0B3C,wBAAsB,aAAa,CAAC,EAClC,SAAS,EACT,aAAa,EACb,QAAQ,EACR,KAAK,EACL,eAAe,EACf,QAAQ,EACR,qBAAqB,GACtB,EAAE;IACD,SAAS,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC;IAC3B,aAAa,EAAE,mBAAmB,CAAC;IACnC,eAAe,EAAE,eAAe,CAAC;IACjC,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,QAAQ,CAAC;IACnB,qBAAqB,EAAE,OAAO,CAAC;CAChC,iBAuCA"}
@@ -1,50 +1,66 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.chatAgentLoop = void 0;
3
+ exports.chatAgentLoop = chatAgentLoop;
4
4
  const chat_1 = require("@empiricalrun/llm/chat");
5
5
  const picocolors_1 = require("picocolors");
6
6
  const prompt_1 = require("./prompt");
7
7
  const state_1 = require("./state");
8
8
  function getModelName(model) {
9
- if (model.startsWith("claude"))
9
+ const provider = (0, chat_1.getProviderForModel)(model);
10
+ if (provider === "claude")
10
11
  return "Claude";
11
- if (model.startsWith("gemini"))
12
+ if (provider === "google")
12
13
  return "Gemini";
13
- if (model.startsWith("o4"))
14
+ if (provider === "openai")
14
15
  return "o4";
15
16
  return "AI";
16
17
  }
17
18
  const log = (...args) => {
18
19
  console.log((0, picocolors_1.gray)(args.join(" ")));
19
20
  };
20
- const isRemote = process.env.TOOL_EXECUTION_IS_REMOTE === "true" || false;
21
- async function chatAgentLoop({ chatModel, selectedModel, reporter, trace, toolCallService, }) {
22
- const systemPrompt = await (0, prompt_1.buildSystemPrompt)();
21
+ function logError(context, error, trace) {
22
+ console.error((0, picocolors_1.gray)(`[Error in ${context}]:`), error instanceof Error ? error.stack || error.message : error);
23
+ trace?.update({
24
+ output: {
25
+ error: error instanceof Error ? error.message : String(error),
26
+ },
27
+ });
28
+ }
29
+ async function chatAgentLoop({ chatModel, selectedModel, reporter, trace, toolCallService, fileInfo, isToolExecutionRemote, }) {
30
+ const systemPrompt = await (0, prompt_1.buildSystemPrompt)(fileInfo);
23
31
  trace?.update({ input: { systemPrompt } });
24
32
  const { tools } = await toolCallService.getTools();
25
33
  while (!chatModel.askUserForInput) {
26
- const toolCalls = chatModel.getPendingToolCalls();
27
- if (toolCalls.length) {
28
- const toolResults = await toolCallService.execute(toolCalls, isRemote, trace);
29
- if (isRemote) {
30
- log(`Tool call remote execution in progress`);
31
- break;
34
+ try {
35
+ const toolCalls = chatModel.getPendingToolCalls();
36
+ if (toolCalls.length) {
37
+ if (isToolExecutionRemote) {
38
+ await toolCallService.sendToQueue(toolCalls);
39
+ log(`Tool call remote execution in progress`);
40
+ break;
41
+ }
42
+ else {
43
+ const toolResults = await toolCallService.execute(toolCalls, trace);
44
+ chatModel.pushToolResultsMessage(toolCalls, toolResults);
45
+ }
32
46
  }
33
- chatModel.pushToolResultsMessage(toolCalls, toolResults);
47
+ log(`${getModelName(selectedModel)} is working...`);
48
+ const response = await chatModel.getLLMResponse({
49
+ systemPrompt,
50
+ tools: tools.map((tool) => (0, chat_1.zodToOpenAITool)(tool.schema)),
51
+ selectedModel,
52
+ trace,
53
+ });
54
+ if (!response) {
55
+ throw new Error("No response from LLM");
56
+ }
57
+ chatModel.pushMessage(response);
58
+ const latest = chatModel.getHumanReadableLatestMessage();
59
+ await reporter((0, state_1.chatStateFromModel)(chatModel, selectedModel), latest);
34
60
  }
35
- log(`${getModelName(selectedModel)} is working...`);
36
- const response = await chatModel.getLLMResponse({
37
- systemPrompt,
38
- tools: tools.map((tool) => (0, chat_1.zodToOpenAITool)(tool.schema)),
39
- selectedModel,
40
- trace,
41
- });
42
- if (!response) {
43
- throw new Error("No response from LLM");
61
+ catch (error) {
62
+ logError("chatAgentLoop", error, trace);
63
+ throw error;
44
64
  }
45
- chatModel.pushMessage(response);
46
- const latest = chatModel.getHumanReadableLatestMessage();
47
- await reporter((0, state_1.chatStateFromModel)(chatModel, selectedModel), latest);
48
65
  }
49
66
  }
50
- exports.chatAgentLoop = chatAgentLoop;
@@ -1,10 +1,9 @@
1
- import { IChatModel } from "@empiricalrun/llm/chat";
1
+ import { createChatModel, IChatModel } from "@empiricalrun/llm/chat";
2
+ import { FileInfo } from "../../types";
2
3
  import { chatAgentLoop } from "./agent-loop";
3
- import { createChatModel } from "./model";
4
- import * as State from "./state";
5
- import { ChatStateOnDisk } from "./state";
6
- import { ReporterFunction, SupportedChatModels } from "./types";
7
- declare const createChatState: typeof State.createChatState, createChatStateForMessages: typeof State.createChatStateForMessages, chatStateFromModel: typeof State.chatStateFromModel, loadChatState: typeof State.loadChatState, saveToDisk: typeof State.saveToDisk, CURRENT_CHAT_STATE_VERSION: string;
8
- export { chatAgentLoop, chatStateFromModel, createChatModel, createChatState, createChatStateForMessages, CURRENT_CHAT_STATE_VERSION, loadChatState, saveToDisk, };
9
- export type { ChatStateOnDisk, IChatModel, ReporterFunction, SupportedChatModels, };
4
+ import { defaultModel, SUPPORTED_CHAT_MODELS, SupportedChatModels } from "./models";
5
+ import { CHAT_STATE_VERSIONS_MIGRATIONS_MAP, chatStateFromModel, ChatStateOnDisk, createChatState, createChatStateForMessages, getLatestDownloadBuildUrl, LATEST_CHAT_STATE_VERSION, migrateChatState } from "./state";
6
+ import { ReporterFunction } from "./types";
7
+ export { CHAT_STATE_VERSIONS_MIGRATIONS_MAP, chatAgentLoop, chatStateFromModel, createChatModel, createChatState, createChatStateForMessages, defaultModel, getLatestDownloadBuildUrl, LATEST_CHAT_STATE_VERSION, migrateChatState, SUPPORTED_CHAT_MODELS, };
8
+ export type { ChatStateOnDisk, FileInfo, IChatModel, ReporterFunction, SupportedChatModels, };
10
9
  //# sourceMappingURL=exports.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"exports.d.ts","sourceRoot":"","sources":["../../../src/agent/chat/exports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAEhE,QAAA,MACE,eAAe,gCACf,0BAA0B,2CAC1B,kBAAkB,mCAClB,aAAa,8BACb,UAAU,2BACV,0BAA0B,QACnB,CAAC;AAEV,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,0BAA0B,EAC1B,0BAA0B,EAC1B,aAAa,EACb,UAAU,GACX,CAAC;AAEF,YAAY,EACV,eAAe,EACf,UAAU,EACV,gBAAgB,EAChB,mBAAmB,GACpB,CAAC"}
1
+ {"version":3,"file":"exports.d.ts","sourceRoot":"","sources":["../../../src/agent/chat/exports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAErE,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EACL,YAAY,EACZ,qBAAqB,EACrB,mBAAmB,EACpB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,kCAAkC,EAClC,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,0BAA0B,EAC1B,yBAAyB,EACzB,yBAAyB,EACzB,gBAAgB,EACjB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE3C,OAAO,EACL,kCAAkC,EAClC,aAAa,EACb,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,0BAA0B,EAC1B,YAAY,EACZ,yBAAyB,EACzB,yBAAyB,EACzB,gBAAgB,EAChB,qBAAqB,GACtB,CAAC;AAEF,YAAY,EACV,eAAe,EACf,QAAQ,EACR,UAAU,EACV,gBAAgB,EAChB,mBAAmB,GACpB,CAAC"}