@empiricalrun/test-gen 0.76.0 → 0.78.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 (237) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/dist/agent/base/index.d.ts +25 -21
  3. package/dist/agent/base/index.d.ts.map +1 -1
  4. package/dist/agent/base/index.js +50 -37
  5. package/dist/agent/browsing/run.d.ts +1 -2
  6. package/dist/agent/browsing/run.d.ts.map +1 -1
  7. package/dist/agent/browsing/run.js +3 -9
  8. package/dist/agent/browsing/utils.d.ts +2 -9
  9. package/dist/agent/browsing/utils.d.ts.map +1 -1
  10. package/dist/agent/browsing/utils.js +5 -109
  11. package/dist/agent/chat/agent-loop.d.ts +5 -5
  12. package/dist/agent/chat/agent-loop.d.ts.map +1 -1
  13. package/dist/agent/chat/agent-loop.js +3 -8
  14. package/dist/agent/chat/exports.d.ts +6 -5
  15. package/dist/agent/chat/exports.d.ts.map +1 -1
  16. package/dist/agent/chat/exports.js +4 -9
  17. package/dist/agent/chat/index.d.ts +2 -2
  18. package/dist/agent/chat/index.d.ts.map +1 -1
  19. package/dist/agent/chat/index.js +23 -35
  20. package/dist/agent/chat/models.d.ts +0 -2
  21. package/dist/agent/chat/models.d.ts.map +1 -1
  22. package/dist/agent/chat/models.js +12 -26
  23. package/dist/agent/chat/prompt/pw-utils-docs.d.ts +1 -1
  24. package/dist/agent/chat/prompt/pw-utils-docs.d.ts.map +1 -1
  25. package/dist/agent/chat/prompt/pw-utils-docs.js +52 -0
  26. package/dist/agent/chat/prompt/repo.d.ts.map +1 -1
  27. package/dist/agent/chat/prompt/repo.js +11 -22
  28. package/dist/agent/chat/prompt/test-case-def.d.ts +2 -0
  29. package/dist/agent/chat/prompt/test-case-def.d.ts.map +1 -0
  30. package/dist/agent/chat/prompt/test-case-def.js +44 -0
  31. package/dist/agent/chat/state.d.ts +8 -14
  32. package/dist/agent/chat/state.d.ts.map +1 -1
  33. package/dist/agent/chat/state.js +15 -60
  34. package/dist/agent/chat/utils.d.ts +2 -2
  35. package/dist/agent/chat/utils.d.ts.map +1 -1
  36. package/dist/agent/chat/utils.js +14 -7
  37. package/dist/agent/cli.d.ts.map +1 -1
  38. package/dist/agent/cli.js +49 -58
  39. package/dist/agent/code-review/executor/index.d.ts +5 -0
  40. package/dist/agent/code-review/executor/index.d.ts.map +1 -0
  41. package/dist/agent/code-review/executor/index.js +13 -0
  42. package/dist/agent/code-review/index.d.ts +8 -3
  43. package/dist/agent/code-review/index.d.ts.map +1 -1
  44. package/dist/agent/code-review/index.js +118 -21
  45. package/dist/agent/code-review/parser.d.ts +5 -0
  46. package/dist/agent/code-review/parser.d.ts.map +1 -0
  47. package/dist/agent/code-review/parser.js +70 -0
  48. package/dist/agent/code-review/types.d.ts +36 -0
  49. package/dist/agent/code-review/types.d.ts.map +1 -0
  50. package/dist/agent/code-review/types.js +13 -0
  51. package/dist/agent/cua/index.d.ts.map +1 -1
  52. package/dist/agent/cua/index.js +18 -2
  53. package/dist/agent/cua/model.d.ts.map +1 -1
  54. package/dist/agent/cua/model.js +4 -1
  55. package/dist/agent/cua/pw-codegen/pw-pause/index.d.ts.map +1 -1
  56. package/dist/agent/triage/index.d.ts +3 -3
  57. package/dist/agent/triage/index.d.ts.map +1 -1
  58. package/dist/agent/triage/index.js +16 -20
  59. package/dist/agent/video-analysis/executor/index.d.ts +5 -0
  60. package/dist/agent/video-analysis/executor/index.d.ts.map +1 -0
  61. package/dist/agent/video-analysis/executor/index.js +10 -0
  62. package/dist/agent/video-analysis/index.d.ts +2 -2
  63. package/dist/agent/video-analysis/index.d.ts.map +1 -1
  64. package/dist/agent/video-analysis/index.js +38 -13
  65. package/dist/artifacts/index.d.ts +1 -1
  66. package/dist/artifacts/index.d.ts.map +1 -1
  67. package/dist/artifacts/index.js +3 -1
  68. package/dist/artifacts/utils.d.ts.map +1 -1
  69. package/dist/bin/index.js +11 -21
  70. package/dist/constants/index.d.ts +14 -0
  71. package/dist/constants/index.d.ts.map +1 -1
  72. package/dist/constants/index.js +33 -1
  73. package/dist/file/server.d.ts +1 -3
  74. package/dist/file/server.d.ts.map +1 -1
  75. package/dist/file/server.js +0 -13
  76. package/dist/file-info/adapters/file-system/index.d.ts.map +1 -1
  77. package/dist/file-info/adapters/file-system/reader.d.ts.map +1 -1
  78. package/dist/file-info/adapters/file-system/reader.js +8 -1
  79. package/dist/file-info/adapters/github/index.d.ts.map +1 -1
  80. package/dist/file-info/adapters/github/reader.d.ts +1 -1
  81. package/dist/file-info/adapters/github/reader.d.ts.map +1 -1
  82. package/dist/file-info/adapters/github/reader.js +8 -5
  83. package/dist/index.d.ts.map +1 -1
  84. package/dist/tools/analyse-video/index.d.ts +5 -0
  85. package/dist/tools/analyse-video/index.d.ts.map +1 -0
  86. package/dist/tools/analyse-video/index.js +56 -0
  87. package/dist/tools/create-pull-request/index.js +4 -6
  88. package/dist/tools/create-pull-request/utils.d.ts +1 -1
  89. package/dist/tools/definitions/{fetch-video-analysis.d.ts → analyse-video.d.ts} +17 -12
  90. package/dist/tools/definitions/analyse-video.d.ts.map +1 -0
  91. package/dist/tools/definitions/analyse-video.js +60 -0
  92. package/dist/tools/definitions/review-pull-request.d.ts +3 -0
  93. package/dist/tools/definitions/review-pull-request.d.ts.map +1 -0
  94. package/dist/tools/definitions/review-pull-request.js +16 -0
  95. package/dist/tools/definitions/str_replace_editor.d.ts +1 -0
  96. package/dist/tools/definitions/str_replace_editor.d.ts.map +1 -1
  97. package/dist/tools/definitions/str_replace_editor.js +4 -1
  98. package/dist/tools/definitions/test-gen-browser.d.ts +0 -3
  99. package/dist/tools/definitions/test-gen-browser.d.ts.map +1 -1
  100. package/dist/tools/definitions/test-gen-browser.js +33 -8
  101. package/dist/tools/delete-file/index.d.ts.map +1 -1
  102. package/dist/tools/delete-file/index.js +1 -19
  103. package/dist/tools/executor/base.d.ts +32 -0
  104. package/dist/tools/executor/base.d.ts.map +1 -0
  105. package/dist/tools/executor/base.js +131 -0
  106. package/dist/tools/executor/index.d.ts +3 -22
  107. package/dist/tools/executor/index.d.ts.map +1 -1
  108. package/dist/tools/executor/index.js +7 -100
  109. package/dist/tools/executor/utils/checkpoint.d.ts +1 -1
  110. package/dist/tools/executor/utils/checkpoint.d.ts.map +1 -1
  111. package/dist/tools/executor/utils/checkpoint.js +6 -2
  112. package/dist/tools/executor/utils/git.d.ts +2 -2
  113. package/dist/tools/executor/utils/git.d.ts.map +1 -1
  114. package/dist/tools/executor/utils/git.js +7 -3
  115. package/dist/tools/executor/utils/index.d.ts +5 -3
  116. package/dist/tools/executor/utils/index.d.ts.map +1 -1
  117. package/dist/tools/executor/utils/index.js +23 -2
  118. package/dist/tools/fetch-session-diff/index.js +2 -2
  119. package/dist/tools/file-operations/create.d.ts.map +1 -1
  120. package/dist/tools/file-operations/create.js +1 -4
  121. package/dist/tools/file-operations/index.d.ts +2 -1
  122. package/dist/tools/file-operations/index.d.ts.map +1 -1
  123. package/dist/tools/file-operations/index.js +4 -1
  124. package/dist/tools/file-operations/insert.d.ts +1 -2
  125. package/dist/tools/file-operations/insert.d.ts.map +1 -1
  126. package/dist/tools/file-operations/insert.js +1 -4
  127. package/dist/tools/file-operations/replace.d.ts.map +1 -1
  128. package/dist/tools/file-operations/replace.js +21 -25
  129. package/dist/tools/file-operations/shared/helpers.d.ts +3 -5
  130. package/dist/tools/file-operations/shared/helpers.d.ts.map +1 -1
  131. package/dist/tools/file-operations/shared/helpers.js +1 -5
  132. package/dist/tools/grep/index.d.ts.map +1 -1
  133. package/dist/tools/grep/index.js +18 -11
  134. package/dist/tools/index.d.ts +5 -5
  135. package/dist/tools/index.d.ts.map +1 -1
  136. package/dist/tools/index.js +17 -16
  137. package/dist/tools/merge-conflicts/index.d.ts.map +1 -1
  138. package/dist/tools/merge-conflicts/index.js +1 -1
  139. package/dist/tools/rename-file/index.js +1 -1
  140. package/dist/tools/review-pull-request/index.d.ts.map +1 -1
  141. package/dist/tools/review-pull-request/index.js +44 -65
  142. package/dist/tools/run-test.d.ts.map +1 -1
  143. package/dist/tools/run-test.js +25 -3
  144. package/dist/tools/test-gen-browser.d.ts.map +1 -1
  145. package/dist/tools/test-gen-browser.js +51 -47
  146. package/dist/tools/upgrade-packages/index.d.ts.map +1 -1
  147. package/dist/tools/upgrade-packages/index.js +4 -0
  148. package/dist/tools/upgrade-packages/utils.d.ts +1 -0
  149. package/dist/tools/upgrade-packages/utils.d.ts.map +1 -1
  150. package/dist/tools/upgrade-packages/utils.js +1 -0
  151. package/dist/trace-utils/index.d.ts +1 -1
  152. package/dist/trace-utils/index.d.ts.map +1 -1
  153. package/dist/trace-utils/index.js +1 -1
  154. package/dist/utils/dedup/dedup-image.d.ts +22 -0
  155. package/dist/utils/dedup/dedup-image.d.ts.map +1 -0
  156. package/dist/utils/dedup/dedup-image.js +26 -0
  157. package/dist/utils/dedup/find-threshold.d.ts +2 -0
  158. package/dist/utils/dedup/find-threshold.d.ts.map +1 -0
  159. package/dist/utils/dedup/find-threshold.js +42 -0
  160. package/dist/utils/hash.d.ts +2 -0
  161. package/dist/utils/hash.d.ts.map +1 -0
  162. package/dist/utils/hash.js +24 -0
  163. package/dist/utils/model.d.ts +1 -1
  164. package/dist/utils/model.d.ts.map +1 -1
  165. package/dist/utils/model.js +7 -5
  166. package/dist/utils/repo-tree.d.ts +0 -1
  167. package/dist/utils/repo-tree.d.ts.map +1 -1
  168. package/dist/utils/repo-tree.js +2 -14
  169. package/dist/utils/slug.js +1 -1
  170. package/dist/video-core/agent-orchestrator.d.ts +13 -0
  171. package/dist/video-core/agent-orchestrator.d.ts.map +1 -0
  172. package/dist/video-core/agent-orchestrator.js +59 -0
  173. package/dist/video-core/index.d.ts +39 -0
  174. package/dist/video-core/index.d.ts.map +1 -0
  175. package/dist/video-core/index.js +134 -0
  176. package/dist/video-core/model-limits.d.ts +4 -0
  177. package/dist/video-core/model-limits.d.ts.map +1 -0
  178. package/dist/video-core/model-limits.js +73 -0
  179. package/dist/video-core/storage-manager.d.ts +5 -0
  180. package/dist/video-core/storage-manager.d.ts.map +1 -0
  181. package/dist/video-core/storage-manager.js +62 -0
  182. package/dist/video-core/types.d.ts +13 -0
  183. package/dist/video-core/types.d.ts.map +1 -0
  184. package/dist/video-core/types.js +2 -0
  185. package/dist/video-core/utils.d.ts +15 -0
  186. package/dist/video-core/utils.d.ts.map +1 -0
  187. package/dist/video-core/utils.js +194 -0
  188. package/dist/video-core/xml-parser.d.ts +3 -0
  189. package/dist/video-core/xml-parser.d.ts.map +1 -0
  190. package/dist/video-core/xml-parser.js +27 -0
  191. package/package.json +6 -6
  192. package/tsconfig.tsbuildinfo +1 -1
  193. package/dist/agent/chat/prompt/index.d.ts +0 -6
  194. package/dist/agent/chat/prompt/index.d.ts.map +0 -1
  195. package/dist/agent/chat/prompt/index.js +0 -200
  196. package/dist/agent/code-review/prompt.d.ts +0 -2
  197. package/dist/agent/code-review/prompt.d.ts.map +0 -1
  198. package/dist/agent/code-review/prompt.js +0 -55
  199. package/dist/agent/diagnosis-agent/index.d.ts +0 -11
  200. package/dist/agent/diagnosis-agent/index.d.ts.map +0 -1
  201. package/dist/agent/diagnosis-agent/index.js +0 -88
  202. package/dist/agent/diagnosis-agent/strict-mode-violation.d.ts +0 -10
  203. package/dist/agent/diagnosis-agent/strict-mode-violation.d.ts.map +0 -1
  204. package/dist/agent/diagnosis-agent/strict-mode-violation.js +0 -30
  205. package/dist/tools/definitions/extract-frames-from-video.d.ts +0 -39
  206. package/dist/tools/definitions/extract-frames-from-video.d.ts.map +0 -1
  207. package/dist/tools/definitions/extract-frames-from-video.js +0 -60
  208. package/dist/tools/definitions/fetch-video-analysis.d.ts.map +0 -1
  209. package/dist/tools/definitions/fetch-video-analysis.js +0 -61
  210. package/dist/tools/extract-frames-from-video/index.d.ts +0 -7
  211. package/dist/tools/extract-frames-from-video/index.d.ts.map +0 -1
  212. package/dist/tools/extract-frames-from-video/index.js +0 -145
  213. package/dist/tools/fetch-video-analysis/index.d.ts +0 -5
  214. package/dist/tools/fetch-video-analysis/index.d.ts.map +0 -1
  215. package/dist/tools/fetch-video-analysis/index.js +0 -149
  216. package/dist/tools/fetch-video-analysis/open-ai.d.ts +0 -6
  217. package/dist/tools/fetch-video-analysis/open-ai.d.ts.map +0 -1
  218. package/dist/tools/fetch-video-analysis/open-ai.js +0 -37
  219. package/dist/tools/fetch-video-analysis/utils.d.ts +0 -16
  220. package/dist/tools/fetch-video-analysis/utils.d.ts.map +0 -1
  221. package/dist/tools/fetch-video-analysis/utils.js +0 -121
  222. package/dist/tools/fetch-video-analysis/video-analysis.d.ts +0 -7
  223. package/dist/tools/fetch-video-analysis/video-analysis.d.ts.map +0 -1
  224. package/dist/tools/fetch-video-analysis/video-analysis.js +0 -70
  225. package/dist/tools/file-operations/shared/git-helper.d.ts +0 -4
  226. package/dist/tools/file-operations/shared/git-helper.d.ts.map +0 -1
  227. package/dist/tools/file-operations/shared/git-helper.js +0 -29
  228. package/dist/utils/dedup-image-fs.d.ts +0 -27
  229. package/dist/utils/dedup-image-fs.d.ts.map +0 -1
  230. package/dist/utils/dedup-image-fs.js +0 -88
  231. package/dist/utils/dedup-image.d.ts +0 -25
  232. package/dist/utils/dedup-image.d.ts.map +0 -1
  233. package/dist/utils/dedup-image.js +0 -80
  234. package/dist/utils/local-ffmpeg-client.d.ts +0 -27
  235. package/dist/utils/local-ffmpeg-client.d.ts.map +0 -1
  236. package/dist/utils/local-ffmpeg-client.js +0 -299
  237. package/eslint.config.mjs +0 -43
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SUPPORTED_CHAT_MODELS = exports.createChatModel = exports.extractAttachments = exports.migrateChatState = exports.LATEST_CHAT_STATE_VERSION = exports.getLatestDownloadBuildUrl = exports.fetchToolCallFromId = exports.createChatStateForMessages = exports.createChatState = exports.chatStateFromModel = exports.CHAT_STATE_VERSIONS_MIGRATIONS_MAP = exports.resolveChatModelBasedOnInput = exports.getDefaultChatModelId = exports.ChatAgent = exports.TriageAgent = exports.MODE_TO_AGENT_MAP = exports.BaseAgent = exports.allToolsDefinitions = exports.viewFileUsingGitHub = exports.getFileInfoFromGitHub = void 0;
3
+ exports.extractAttachments = exports.migrateChatState = exports.LATEST_CHAT_STATE_VERSION = exports.getLatestDownloadBuildUrl = exports.fetchToolCallFromId = exports.chatStateFromModel = exports.CHAT_STATE_VERSIONS_MIGRATIONS_MAP = exports.resolveChatModelBasedOnInput = exports.ChatAgent = exports.TriageAgent = exports.MODE_TO_AGENT_MAP = exports.BaseAgent = exports.viewFileUsingGitHub = exports.getFileInfoFromGitHub = exports.SUPPORTED_CHAT_MODELS = exports.createChatModel = void 0;
4
+ var chat_1 = require("@empiricalrun/llm/chat");
5
+ Object.defineProperty(exports, "createChatModel", { enumerable: true, get: function () { return chat_1.createChatModel; } });
6
+ Object.defineProperty(exports, "SUPPORTED_CHAT_MODELS", { enumerable: true, get: function () { return chat_1.SUPPORTED_CHAT_MODELS; } });
4
7
  var github_1 = require("../../file-info/adapters/github");
5
8
  Object.defineProperty(exports, "getFileInfoFromGitHub", { enumerable: true, get: function () { return github_1.getFileInfoFromGitHub; } });
6
9
  Object.defineProperty(exports, "viewFileUsingGitHub", { enumerable: true, get: function () { return github_1.viewFileUsingGitHub; } });
7
- var tools_1 = require("../../tools");
8
- Object.defineProperty(exports, "allToolsDefinitions", { enumerable: true, get: function () { return tools_1.allToolsDefinitions; } });
9
10
  var base_1 = require("../base");
10
11
  Object.defineProperty(exports, "BaseAgent", { enumerable: true, get: function () { return base_1.BaseAgent; } });
11
12
  var index_1 = require("../index");
@@ -15,19 +16,13 @@ Object.defineProperty(exports, "TriageAgent", { enumerable: true, get: function
15
16
  var index_2 = require("./index");
16
17
  Object.defineProperty(exports, "ChatAgent", { enumerable: true, get: function () { return index_2.ChatAgent; } });
17
18
  var models_1 = require("./models");
18
- Object.defineProperty(exports, "getDefaultChatModelId", { enumerable: true, get: function () { return models_1.getDefaultChatModelId; } });
19
19
  Object.defineProperty(exports, "resolveChatModelBasedOnInput", { enumerable: true, get: function () { return models_1.resolveChatModelBasedOnInput; } });
20
20
  var state_1 = require("./state");
21
21
  Object.defineProperty(exports, "CHAT_STATE_VERSIONS_MIGRATIONS_MAP", { enumerable: true, get: function () { return state_1.CHAT_STATE_VERSIONS_MIGRATIONS_MAP; } });
22
22
  Object.defineProperty(exports, "chatStateFromModel", { enumerable: true, get: function () { return state_1.chatStateFromModel; } });
23
- Object.defineProperty(exports, "createChatState", { enumerable: true, get: function () { return state_1.createChatState; } });
24
- Object.defineProperty(exports, "createChatStateForMessages", { enumerable: true, get: function () { return state_1.createChatStateForMessages; } });
25
23
  Object.defineProperty(exports, "fetchToolCallFromId", { enumerable: true, get: function () { return state_1.fetchToolCallFromId; } });
26
24
  Object.defineProperty(exports, "getLatestDownloadBuildUrl", { enumerable: true, get: function () { return state_1.getLatestDownloadBuildUrl; } });
27
25
  Object.defineProperty(exports, "LATEST_CHAT_STATE_VERSION", { enumerable: true, get: function () { return state_1.LATEST_CHAT_STATE_VERSION; } });
28
26
  Object.defineProperty(exports, "migrateChatState", { enumerable: true, get: function () { return state_1.migrateChatState; } });
29
27
  var utils_1 = require("./utils");
30
28
  Object.defineProperty(exports, "extractAttachments", { enumerable: true, get: function () { return utils_1.extractAttachments; } });
31
- var chat_1 = require("@empiricalrun/llm/chat");
32
- Object.defineProperty(exports, "createChatModel", { enumerable: true, get: function () { return chat_1.createChatModel; } });
33
- Object.defineProperty(exports, "SUPPORTED_CHAT_MODELS", { enumerable: true, get: function () { return chat_1.SUPPORTED_CHAT_MODELS; } });
@@ -1,7 +1,7 @@
1
- import type { ToolDefinition } from "@empiricalrun/shared-types";
1
+ import type { ToolsForLLM } from "@empiricalrun/shared-types";
2
2
  import { BaseAgent } from "../base";
3
3
  export declare class ChatAgent extends BaseAgent {
4
- protected getTools(): ToolDefinition[];
4
+ protected getTools(): ToolsForLLM;
5
5
  protected buildSystemPrompt(repoContext?: string): Promise<string>;
6
6
  }
7
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/agent/chat/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAQjE,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGpC,qBAAa,SAAU,SAAQ,SAAS;IACtC,SAAS,CAAC,QAAQ,IAAI,cAAc,EAAE;cAmBtB,iBAAiB,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAkHzE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/agent/chat/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAS9D,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAIpC,qBAAa,SAAU,SAAQ,SAAS;IACtC,SAAS,CAAC,QAAQ,IAAI,WAAW;cAajB,iBAAiB,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAuGzE"}
@@ -4,20 +4,19 @@ exports.ChatAgent = void 0;
4
4
  const tools_1 = require("../../tools");
5
5
  const base_1 = require("../base");
6
6
  const pw_utils_docs_1 = require("./prompt/pw-utils-docs");
7
+ const test_case_def_1 = require("./prompt/test-case-def");
7
8
  class ChatAgent extends base_1.BaseAgent {
8
9
  getTools() {
9
- const tools = [
10
+ const custom = [
10
11
  ...tools_1.commonTools,
11
12
  ...tools_1.testGenerationTools,
12
- // Model-specific tools
13
+ tools_1.analyseVideo,
13
14
  ...(0, tools_1.textEditorToolsForModel)(this.selectedModel),
14
15
  ];
15
- // Feature flag: video analysis (if not already included)
16
- if (this.featureFlags?.includes("useVideoAnalysis") &&
17
- !tools.some((tool) => tool.schema.name === "fetchVideoAnalysis")) {
18
- tools.push(tools_1.fetchVideoAnalysis);
19
- }
20
- return tools;
16
+ return {
17
+ custom,
18
+ builtInTextEditor: (0, tools_1.hasBuiltInTextEditor)(this.selectedModel),
19
+ };
21
20
  }
22
21
  async buildSystemPrompt(repoContext) {
23
22
  if (!repoContext) {
@@ -46,39 +45,26 @@ fixed with modifications to the test code, and it is your job to do that.
46
45
 
47
46
  # Tools
48
47
 
49
- You are given a set of tools to help you fulfill the user's request. Read their descriptions to
50
- understand what each tool does.
51
-
52
- For example, if the user asks you to run a test, you could use the runTest tool.
53
- Once the test is run, you will receive the results in the form of a JSON object.
54
- Summarize the results in a few sentences.
55
-
56
- If the user provides a diagnosis URL, you can use the fetchDiagnosisDetails tool
57
- to get more information about the test case and its results.
58
-
59
- If the user provides a test run URL, you can use the fetchTestRunDetails tool
60
- to get detailed information about a specific test run.
48
+ You are given a set of tools (= functions) to help you fulfill the user's request. Read their descriptions
49
+ to understand what each tool does. You are HIGHLY encouraged to use tools and generate a high quality output.
61
50
 
62
- Or if the user asks you to modify a test, you could use the generateTestWithBrowserAgent tool. If you suspect
63
- that a UI selector needs to be updated, using the browser agent is a good idea.
51
+ For example,
64
52
 
65
- Before using generateTestWithBrowserAgent, you need to prepare the test code for the browser agent.
66
- You can do this by using the strReplaceEditor or the text editor tool to add a TODO comment to the test
67
- code. This comment explains to the browser agent what it needs to do.
53
+ 1. If you are adding or modifying a test, run the test to ensure it works well.
54
+ 2. Every test run generates report artifacts, and you have tools to read markdown files, see screenshots and videos. Use them to understand the test results
55
+ and fix test issues.
56
+ 3. Use the grep and file view tools to read the codebase. While the codebase only has Playwright tests, there are often patterns that can be reused.
68
57
 
69
- For example, if the expected modification is to click on a login button, you could add the following comment.
70
-
71
- // TODO(agent): Click on the login button
58
+ # Proactiveness
72
59
 
73
- The position of the comment is important: the browser agent will look for this comment and replace it with
74
- the actual code to click on the login button. If you are fixing a failing test, your comment should be
75
- around the failing line of code, so that it can be replaced/modified.
60
+ You are encouraged to be proactive. Use the tools, explore the repo, and accomplish the task that the user has given to you. As long as your actions
61
+ are aligned with the user's objective, you should lean on being more proactive than not.
76
62
 
77
- # Proactiveness
63
+ If you are supposed to add or modify a test, understand the context, make changes, run the test, and go over this loop until you have achieved
64
+ the user's goal - OR, ask the user for clarifications if there's some confusion.
78
65
 
79
- 1. You are allowed to be proactive, but ONLY for read-only tool calls: like searching for content, reading files, fetching data from tools, and
80
- running Playwright tests.
81
- 2. For any read-write tool calls (e.g. modifying any file), you should share your plan and get the user's approval before proceeding.
66
+ If you are unsure about next steps, or have some evidence to modify the user's objective, ask for clarification with a brief summary of
67
+ your findings and 1-2 questions for the user to help you understand the user's objective better.
82
68
 
83
69
  # Rules to follow
84
70
 
@@ -123,6 +109,8 @@ if (await saveButton.isVisible()) {
123
109
  `;
124
110
  return `${preamble}
125
111
 
112
+ ${test_case_def_1.testCasesDefinitionPrompt}
113
+
126
114
  # Recipes
127
115
  ${pw_utils_docs_1.playwrightUtilsDocs}
128
116
 
@@ -1,5 +1,3 @@
1
1
  import { SupportedChatModels } from "@empiricalrun/shared-types";
2
- export declare function getDefaultChatModelId(): SupportedChatModels;
3
2
  export declare const resolveChatModelBasedOnInput: (requestedModel?: string) => SupportedChatModels;
4
- export declare const modelLabels: Record<SupportedChatModels, string>;
5
3
  //# sourceMappingURL=models.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../../src/agent/chat/models.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAIjE,wBAAgB,qBAAqB,IAAI,mBAAmB,CAM3D;AAED,eAAO,MAAM,4BAA4B,GACvC,iBAAiB,MAAM,KACtB,mBA6BF,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,mBAAmB,EAAE,MAAM,CAOzD,CAAC"}
1
+ {"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../../src/agent/chat/models.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAOjE,eAAO,MAAM,4BAA4B,GACvC,iBAAiB,MAAM,KACtB,mBAsBF,CAAC"}
@@ -1,38 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.modelLabels = exports.resolveChatModelBasedOnInput = void 0;
4
- exports.getDefaultChatModelId = getDefaultChatModelId;
3
+ exports.resolveChatModelBasedOnInput = void 0;
5
4
  const chat_1 = require("@empiricalrun/llm/chat");
6
5
  const model_1 = require("../../utils/model");
7
- function getDefaultChatModelId() {
8
- const DEFAULT_CHAT_MODEL_ID = "claude-sonnet-4-20250514";
9
- if (!chat_1.SUPPORTED_CHAT_MODELS.some((m) => m.id === DEFAULT_CHAT_MODEL_ID)) {
10
- throw new Error("Default chat model is not in SUPPORTED_CHAT_MODELS");
11
- }
12
- return DEFAULT_CHAT_MODEL_ID;
13
- }
6
+ const DEFAULT_AUTO_FALLBACK_MODEL = "claude-sonnet-4-5-20250929";
14
7
  const resolveChatModelBasedOnInput = (requestedModel) => {
15
8
  const sanitizedModelInput = requestedModel?.trim().toLowerCase();
16
9
  if (!sanitizedModelInput || sanitizedModelInput === "auto") {
17
- const autoSelectedModelId = getDefaultChatModelId();
18
- return autoSelectedModelId;
10
+ return DEFAULT_AUTO_FALLBACK_MODEL;
19
11
  }
20
- // requestedModel is already a valid SupportedChatModels string
21
- if (sanitizedModelInput &&
22
- Object.values(chat_1.SUPPORTED_CHAT_MODELS).some((model) => model.id.toLowerCase() === sanitizedModelInput)) {
23
- const matchedModel = chat_1.SUPPORTED_CHAT_MODELS.find((model) => model.id.toLowerCase() === sanitizedModelInput);
24
- if (matchedModel) {
25
- return matchedModel.id;
26
- }
12
+ // Check for exact match first
13
+ const matchedModel = chat_1.SUPPORTED_CHAT_MODELS.find((model) => model.id.toLowerCase() === sanitizedModelInput);
14
+ if (matchedModel) {
15
+ return matchedModel.id;
27
16
  }
28
- const resolvedModelId = model_1.ARGS_TO_MODEL_MAP[sanitizedModelInput];
29
- if (!resolvedModelId) {
30
- throw new Error(`Invalid chat model: ${requestedModel}`);
17
+ // Check for CLI args match (smaller aliases for full model names)
18
+ const resolvedModelId = model_1.CLI_ARGS_TO_MODEL_MAP[sanitizedModelInput];
19
+ if (resolvedModelId) {
20
+ return resolvedModelId;
31
21
  }
32
- return resolvedModelId;
22
+ throw new Error(`Invalid chat model: ${requestedModel}`);
33
23
  };
34
24
  exports.resolveChatModelBasedOnInput = resolveChatModelBasedOnInput;
35
- exports.modelLabels = chat_1.SUPPORTED_CHAT_MODELS.reduce((acc, model) => ({
36
- ...acc,
37
- [model.id]: model.label,
38
- }), {});
@@ -1,2 +1,2 @@
1
- export declare const playwrightUtilsDocs = "\nYou can refer to the following recipes to learn how to write tests for different scenarios.\n\n<email-automation>\n\n# Email automation\n\n## Example usage\n\n### Dynamic email\n\nThis dynamically generates a random email address that can \nbe used for the test (e.g. invite a new user).\n\n```ts\nimport { EmailClient } from \"@empiricalrun/playwright-utils\";\nimport { expect } from \"@playwright/test\";\n\nconst client = new EmailClient();\nconst address = client.getAddress();\n\n// Input the `address` in the application\n// that sends the email.\n\n// Get email received on the `address`\nconst email = await client.waitForEmail();\nexpect(\n email.links.find((l) => l.text === \"Join your team\")\n).toBeTruthy();\n```\n\n### Static email\n\nThis uses a known (static) email that can be used to login\ninto an application.\n\nThis needs an email id (e.g. `test-login-user`). The email id\nis appended with the domain (managed internally) to get the full\nemail address.\n\n```ts\nimport { EmailClient } from \"@empiricalrun/playwright-utils\";\n\nconst emailId = `test-login-user`;\n\nconst client = new EmailClient({ emailId });\nconst address = client.getAddress(); // Returns full address with domain\n\n// Get email received on the `address`\nconst email = await client.waitForEmail();\n\n// Get login OTP\nconst loginCode = email.codes[0];\n```\n\n</email-automation>\n\n";
1
+ export declare const playwrightUtilsDocs = "\nYou can refer to the following recipes to learn how to write tests for different scenarios.\n\n<email-automation>\n\n# Email automation\n\n## Example usage\n\n### Dynamic email\n\nThis dynamically generates a random email address that can \nbe used for the test (e.g. invite a new user).\n\n```ts\nimport { EmailClient } from \"@empiricalrun/playwright-utils\";\nimport { expect } from \"@playwright/test\";\n\nconst client = new EmailClient();\nconst address = client.getAddress();\n\n// Input the `address` in the application\n// that sends the email.\n\n// Get email received on the `address`\nconst email = await client.waitForEmail();\nexpect(\n email.links.find((l) => l.text === \"Join your team\")\n).toBeTruthy();\n```\n\n### Static email\n\nThis uses a known (static) email that can be used to login\ninto an application.\n\nThis needs an email id (e.g. `test-login-user`). The email id\nis appended with the domain (managed internally) to get the full\nemail address.\n\n```ts\nimport { EmailClient } from \"@empiricalrun/playwright-utils\";\n\nconst emailId = `test-login-user`;\n\nconst client = new EmailClient({ emailId });\nconst address = client.getAddress(); // Returns full address with domain\n\n// Get email received on the `address`\nconst email = await client.waitForEmail();\n\n// Get login OTP\nconst loginCode = email.codes[0];\n```\n\n</email-automation>\n\n<fixtures>\n\nThe playwright-utils package provides fixtures that wrap around Playwright's built-in\n`page`, `context` fixtures to provide a mouse highlighter (which makes it easier to\nsee actions taken in a video).\n\nTo use this, you can use the `baseTestFixture` and `extendExpect` imports\nin your fixtures file.\n\n```ts\nimport { test as base, expect as baseExpect } from \"@playwright/test\";\nimport { baseTestFixture, extendExpect } from \"@empiricalrun/playwright-utils/test\";\n\nexport const test = baseTestFixture(base);\nexport const expect = extendExpect(baseExpect);\n```\n\n### Get a new browser context\n\nThis package provides a fixture `customContextPageProvider` which is a good way to create\na fresh, new browser context, and a page inside it.\n\nThere are two benefits of using this to create contexts or pages:\n1. Videos get recorded and attached to the test report\n2. Mouse highlights are available\n\n```ts\nimport { test, expect } from \"./fixtures\";\n\ntest(\"Example test\", async ({ page: builtInPage, customContextPageProvider }) => {\n // builtInPage is from default browser context\n const { page: newPage, context } = await customContextPageProvider();\n // newPage is from this other browser context\n});\n```\n\ncustomContextPageProvider can accept options to customize the browser context.\n\n```\n customContextPageProvider: (\n options?: BrowserContextOptions,\n ) => Promise<{ context: BrowserContext; page: Page }>;\n```\n\nFor example, pass { storageState: undefined } to create a new browser context without\nthe auth state of the current browser context. This is useful for multi-user scenarios.\n\n</fixtures>\n\n";
2
2
  //# sourceMappingURL=pw-utils-docs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"pw-utils-docs.d.ts","sourceRoot":"","sources":["../../../../src/agent/chat/prompt/pw-utils-docs.ts"],"names":[],"mappings":"AAoDA,eAAO,MAAM,mBAAmB,i3CAO/B,CAAC"}
1
+ {"version":3,"file":"pw-utils-docs.d.ts","sourceRoot":"","sources":["../../../../src/agent/chat/prompt/pw-utils-docs.ts"],"names":[],"mappings":"AAqGA,eAAO,MAAM,mBAAmB,w/FAW/B,CAAC"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.playwrightUtilsDocs = void 0;
4
+ // Ref: packages/playwright-utils/docs/email.md
4
5
  const emailRecipe = `
5
6
  # Email automation
6
7
 
@@ -52,6 +53,53 @@ const email = await client.waitForEmail();
52
53
  const loginCode = email.codes[0];
53
54
  \`\`\`
54
55
  `;
56
+ // Ref: packages/playwright-utils/docs/fixtures.md
57
+ const fixturesRecipe = `
58
+ The playwright-utils package provides fixtures that wrap around Playwright's built-in
59
+ \`page\`, \`context\` fixtures to provide a mouse highlighter (which makes it easier to
60
+ see actions taken in a video).
61
+
62
+ To use this, you can use the \`baseTestFixture\` and \`extendExpect\` imports
63
+ in your fixtures file.
64
+
65
+ \`\`\`ts
66
+ import { test as base, expect as baseExpect } from "@playwright/test";
67
+ import { baseTestFixture, extendExpect } from "@empiricalrun/playwright-utils/test";
68
+
69
+ export const test = baseTestFixture(base);
70
+ export const expect = extendExpect(baseExpect);
71
+ \`\`\`
72
+
73
+ ### Get a new browser context
74
+
75
+ This package provides a fixture \`customContextPageProvider\` which is a good way to create
76
+ a fresh, new browser context, and a page inside it.
77
+
78
+ There are two benefits of using this to create contexts or pages:
79
+ 1. Videos get recorded and attached to the test report
80
+ 2. Mouse highlights are available
81
+
82
+ \`\`\`ts
83
+ import { test, expect } from "./fixtures";
84
+
85
+ test("Example test", async ({ page: builtInPage, customContextPageProvider }) => {
86
+ // builtInPage is from default browser context
87
+ const { page: newPage, context } = await customContextPageProvider();
88
+ // newPage is from this other browser context
89
+ });
90
+ \`\`\`
91
+
92
+ customContextPageProvider can accept options to customize the browser context.
93
+
94
+ \`\`\`
95
+ customContextPageProvider: (
96
+ options?: BrowserContextOptions,
97
+ ) => Promise<{ context: BrowserContext; page: Page }>;
98
+ \`\`\`
99
+
100
+ For example, pass { storageState: undefined } to create a new browser context without
101
+ the auth state of the current browser context. This is useful for multi-user scenarios.
102
+ `;
55
103
  exports.playwrightUtilsDocs = `
56
104
  You can refer to the following recipes to learn how to write tests for different scenarios.
57
105
 
@@ -59,4 +107,8 @@ You can refer to the following recipes to learn how to write tests for different
59
107
  ${emailRecipe}
60
108
  </email-automation>
61
109
 
110
+ <fixtures>
111
+ ${fixturesRecipe}
112
+ </fixtures>
113
+
62
114
  `;
@@ -1 +1 @@
1
- {"version":3,"file":"repo.d.ts","sourceRoot":"","sources":["../../../../src/agent/chat/prompt/repo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAsDtD,wBAAsB,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,mBA0CzD"}
1
+ {"version":3,"file":"repo.d.ts","sourceRoot":"","sources":["../../../../src/agent/chat/prompt/repo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAuDtD,wBAAsB,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,mBA2BzD"}
@@ -18,8 +18,8 @@ async function getAllMarkdownFiles(directory) {
18
18
  .filter((file) => file.type === "file" && file.path.endsWith(".md"))
19
19
  .map(async (file) => {
20
20
  return {
21
- // TODO: Give full path
22
21
  name: path_1.default.basename(file.path),
22
+ path: file.path,
23
23
  content: file.type === "file" ? await file.getContent() : "",
24
24
  };
25
25
  }));
@@ -35,13 +35,14 @@ async function knowledgeContext(repoInfo) {
35
35
  const mdFiles = await getAllMarkdownFiles(knowledgeDir);
36
36
  const knowledge = mdFiles.map((file) => {
37
37
  return `
38
- <knowledge_file>
39
- <file_name>${file.name}</file_name>
40
- <file_content>
41
- ${file.content}
42
- </file_content>
43
- </knowledge_file>
44
- `;
38
+ <knowledge_file>
39
+ <file_name>${file.name}</file_name>
40
+ <file_path>${file.path}</file_path>
41
+ <file_content>
42
+ ${file.content}
43
+ </file_content>
44
+ </knowledge_file>
45
+ `;
45
46
  });
46
47
  return knowledge.join("\n");
47
48
  }
@@ -59,25 +60,13 @@ While specifying paths to files, use relative paths from the current working dir
59
60
  - Correct path: "tests/lesson.spec.ts"
60
61
  - Incorrect path: "/repo/tests/lesson.spec.ts" or "${repoInfo.name}/tests/lesson.spec.ts"
61
62
  `;
62
- // try {
63
- // const playwrightConfig = await readPlaywrightConfig(process.cwd());
64
- // const validProjectNames = await getValidProjectNames(playwrightConfig);
65
- // if (validProjectNames.length > 0) {
66
- // REPO_CONTEXT_PROMPT += `
67
- // ## Playwright configuration
68
- // This repo is configured with these Playwright projects (in the playwright.config.ts file):
69
- // ${validProjectNames.map((name) => `- ${name}`).join("\n")}
70
- // `;
71
- // }
72
- // } catch (error) {
73
- // console.warn("Failed to read playwright config", error);
74
- // }
75
63
  const knowledge = await knowledgeContext(repoInfo);
76
64
  if (knowledge.length > 0) {
77
65
  REPO_CONTEXT_PROMPT += `
78
66
  ## Repo-specific knowledge
79
67
 
80
- You can use the following knowledge with your tasks.
68
+ This repo knowledge files that will help you understand the repo and application better.
69
+
81
70
  <knowledge>
82
71
  ${knowledge}
83
72
  </knowledge>
@@ -0,0 +1,2 @@
1
+ export declare const testCasesDefinitionPrompt = "\n# Specifying test cases for tools/functions\n\nMany tools and functions that you use require specifying a test case with the following properties: \n- Test case name: Name of the test (specified to the \"test(...)\" method)\n- Suites: Refers to describe blocks where this test is located, specified as an array of strings\n- File path: Path to the file - must be relative to the repo directory\n\n<example_1>\n// Contents of tests/example.spec.ts\nimport { test, expect } from \"./fixtures\";\n\ntest(\"has title\", async ({ page }) => {\n await page.goto(\"https://playwright.dev/\");\n await expect(page).toHaveTitle(/Playwright/);\n});\n\n// Specifying this test case\n- Test case name: \"has title\"\n- Suites: [] (since this test has no describe blocks)\n- File path: \"tests/example.spec.ts\"\n</example_1>\n\n<example_2>\n// Contents of tests/sidebar/nav.spec.ts\nimport { test, expect } from \"./fixtures\";\n\ntest.describe(\"Sidebar Navigation\", () => {\n test(\"collapse sidebar and expand it by clicking settings gear icon\", async ({ page }) => {\n await page.goto(\"/\");\n await page.getByRole('button', { name: 'Collapse sidebar' }).click();\n await page.getByRole('navigation').getByRole('button').click();\n });\n});\n\n// Specifying this test case\n- Test case name: \"collapse sidebar and expand it by clicking settings gear icon\"\n- Suites: [\"Sidebar Navigation\"]\n- File path: \"tests/sidebar/nav.spec.ts\"\n</example_2>\n";
2
+ //# sourceMappingURL=test-case-def.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-case-def.d.ts","sourceRoot":"","sources":["../../../../src/agent/chat/prompt/test-case-def.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,yBAAyB,47CAwCrC,CAAC"}
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.testCasesDefinitionPrompt = void 0;
4
+ exports.testCasesDefinitionPrompt = `
5
+ # Specifying test cases for tools/functions
6
+
7
+ Many tools and functions that you use require specifying a test case with the following properties:
8
+ - Test case name: Name of the test (specified to the "test(...)" method)
9
+ - Suites: Refers to describe blocks where this test is located, specified as an array of strings
10
+ - File path: Path to the file - must be relative to the repo directory
11
+
12
+ <example_1>
13
+ // Contents of tests/example.spec.ts
14
+ import { test, expect } from "./fixtures";
15
+
16
+ test("has title", async ({ page }) => {
17
+ await page.goto("https://playwright.dev/");
18
+ await expect(page).toHaveTitle(/Playwright/);
19
+ });
20
+
21
+ // Specifying this test case
22
+ - Test case name: "has title"
23
+ - Suites: [] (since this test has no describe blocks)
24
+ - File path: "tests/example.spec.ts"
25
+ </example_1>
26
+
27
+ <example_2>
28
+ // Contents of tests/sidebar/nav.spec.ts
29
+ import { test, expect } from "./fixtures";
30
+
31
+ test.describe("Sidebar Navigation", () => {
32
+ test("collapse sidebar and expand it by clicking settings gear icon", async ({ page }) => {
33
+ await page.goto("/");
34
+ await page.getByRole('button', { name: 'Collapse sidebar' }).click();
35
+ await page.getByRole('navigation').getByRole('button').click();
36
+ });
37
+ });
38
+
39
+ // Specifying this test case
40
+ - Test case name: "collapse sidebar and expand it by clicking settings gear icon"
41
+ - Suites: ["Sidebar Navigation"]
42
+ - File path: "tests/sidebar/nav.spec.ts"
43
+ </example_2>
44
+ `;
@@ -1,16 +1,8 @@
1
- import { IChatModel } from "@empiricalrun/llm/chat";
2
- import { Attachment, CanonicalMessage, ChatState, ChatStateError, PendingToolCall, SupportedChatModels, ToolResult } from "@empiricalrun/shared-types";
1
+ import { IChatCanonicalModel, IChatModel } from "@empiricalrun/llm/chat";
2
+ import { CanonicalMessage, ChatState, ChatStateError, PendingToolCall, SupportedChatModels, ToolResult } from "@empiricalrun/shared-types";
3
3
  export declare const CHAT_STATE_VERSIONS_MIGRATIONS_MAP: Record<string, (state: any) => any>;
4
4
  export declare const LATEST_CHAT_STATE_VERSION = "0.1";
5
5
  export declare const CHAT_STATE_PATH: string;
6
- export declare function clearChatState(): void;
7
- export declare function createChatState({ userPrompt, attachments, existingState, selectedModel, error, }: {
8
- userPrompt: string | undefined;
9
- attachments: Attachment[];
10
- existingState: ChatState | undefined;
11
- selectedModel: SupportedChatModels;
12
- error: ChatStateError | null;
13
- }): ChatState;
14
6
  export declare function createChatStateForMessages({ messages, selectedModel, askUserForInput, error, }: {
15
7
  messages: CanonicalMessage[];
16
8
  selectedModel: SupportedChatModels;
@@ -18,17 +10,19 @@ export declare function createChatStateForMessages({ messages, selectedModel, as
18
10
  error: ChatStateError | null;
19
11
  }): ChatState;
20
12
  export declare function chatStateFromModel<T>({ chatModel, error, }: {
21
- chatModel: IChatModel<T>;
13
+ chatModel: IChatModel<T> | IChatCanonicalModel;
22
14
  error: ChatStateError | null;
23
15
  }): ChatState;
24
- export declare function getUsageSummary(chatModel: IChatModel<CanonicalMessage>): string;
25
- export declare function loadChatState(): ChatState | undefined;
16
+ export declare function getUsageSummary(chatState: ChatState): string;
17
+ export declare function loadChatState({ resetChat, }: {
18
+ resetChat: boolean;
19
+ }): ChatState | undefined;
26
20
  /**
27
21
  * Migrates a chat state object from an old version to the latest version.
28
22
  * Add migration logic for each version as needed.
29
23
  */
30
24
  export declare function migrateChatState(oldState: any): ChatState;
31
- export declare function saveToDisk(messages: Array<CanonicalMessage>, selectedModel: SupportedChatModels, askUserForInput: boolean, error: ChatStateError | null): void;
25
+ export declare function saveToDisk(chatState: ChatState): void;
32
26
  export declare function getLatestDownloadBuildUrl(messages: CanonicalMessage[]): string | null;
33
27
  export declare function fetchToolCallFromId(toolCallId: String, messages: CanonicalMessage[]): {
34
28
  toolCallQueuedAt: Date | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../src/agent/chat/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,UAAU,EACX,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,UAAU,EACV,gBAAgB,EAChB,SAAS,EACT,cAAc,EACd,eAAe,EACf,mBAAmB,EAEnB,UAAU,EACX,MAAM,4BAA4B,CAAC;AA+BpC,eAAO,MAAM,kCAAkC,EAAE,MAAM,CACrD,MAAM,EACN,CAAC,KAAK,EAAE,GAAG,KAAK,GAAG,CAIpB,CAAC;AAEF,eAAO,MAAM,yBAAyB,QAAQ,CAAC;AAE/C,eAAO,MAAM,eAAe,QAI3B,CAAC;AAEF,wBAAgB,cAAc,SAQ7B;AAED,wBAAgB,eAAe,CAAC,EAC9B,UAAU,EACV,WAAW,EACX,aAAa,EACb,aAAa,EACb,KAAK,GACN,EAAE;IACD,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,aAAa,EAAE,SAAS,GAAG,SAAS,CAAC;IACrC,aAAa,EAAE,mBAAmB,CAAC;IACnC,KAAK,EAAE,cAAc,GAAG,IAAI,CAAC;CAC9B,aAYA;AAED,wBAAgB,0BAA0B,CAAC,EACzC,QAAQ,EACR,aAAa,EACb,eAAe,EACf,KAAK,GACN,EAAE;IACD,QAAQ,EAAE,gBAAgB,EAAE,CAAC;IAC7B,aAAa,EAAE,mBAAmB,CAAC;IACnC,eAAe,EAAE,OAAO,CAAC;IACzB,KAAK,EAAE,cAAc,GAAG,IAAI,CAAC;CAC9B,GAAG,SAAS,CASZ;AAED,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,EACpC,SAAS,EACT,KAAK,GACN,EAAE;IACD,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;IACzB,KAAK,EAAE,cAAc,GAAG,IAAI,CAAC;CAC9B,aAOA;AAED,wBAAgB,eAAe,CAC7B,SAAS,EAAE,UAAU,CAAC,gBAAgB,CAAC,GACtC,MAAM,CA0BR;AAED,wBAAgB,aAAa,IAAI,SAAS,GAAG,SAAS,CAarD;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,GAAG,GAAG,SAAS,CAqBzD;AAED,wBAAgB,UAAU,CACxB,QAAQ,EAAE,KAAK,CAAC,gBAAgB,CAAC,EACjC,aAAa,EAAE,mBAAmB,EAClC,eAAe,EAAE,OAAO,EACxB,KAAK,EAAE,cAAc,GAAG,IAAI,QAgB7B;AA2BD,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,gBAAgB,EAAE,GAC3B,MAAM,GAAG,IAAI,CAef;AAED,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,gBAAgB,EAAE,GAC3B;IACD,gBAAgB,EAAE,IAAI,GAAG,SAAS,CAAC;IACnC,QAAQ,EAAE,eAAe,GAAG,SAAS,CAAC;IACtC,UAAU,EAAE,UAAU,GAAG,SAAS,CAAC;CACpC,CA0BA"}
1
+ {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../src/agent/chat/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,EACL,gBAAgB,EAChB,SAAS,EACT,cAAc,EACd,eAAe,EACf,mBAAmB,EAEnB,UAAU,EACX,MAAM,4BAA4B,CAAC;AAMpC,eAAO,MAAM,kCAAkC,EAAE,MAAM,CACrD,MAAM,EACN,CAAC,KAAK,EAAE,GAAG,KAAK,GAAG,CAGpB,CAAC;AAEF,eAAO,MAAM,yBAAyB,QAAQ,CAAC;AAE/C,eAAO,MAAM,eAAe,QAI3B,CAAC;AAEF,wBAAgB,0BAA0B,CAAC,EACzC,QAAQ,EACR,aAAa,EACb,eAAe,EACf,KAAK,GACN,EAAE;IACD,QAAQ,EAAE,gBAAgB,EAAE,CAAC;IAC7B,aAAa,EAAE,mBAAmB,CAAC;IACnC,eAAe,EAAE,OAAO,CAAC;IACzB,KAAK,EAAE,cAAc,GAAG,IAAI,CAAC;CAC9B,GAAG,SAAS,CASZ;AAED,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,EACpC,SAAS,EACT,KAAK,GACN,EAAE;IACD,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,mBAAmB,CAAC;IAC/C,KAAK,EAAE,cAAc,GAAG,IAAI,CAAC;CAC9B,aAOA;AAED,wBAAgB,eAAe,CAAC,SAAS,EAAE,SAAS,GAAG,MAAM,CA0B5D;AAED,wBAAgB,aAAa,CAAC,EAC5B,SAAS,GACV,EAAE;IACD,SAAS,EAAE,OAAO,CAAC;CACpB,GAAG,SAAS,GAAG,SAAS,CAsBxB;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,GAAG,GAAG,SAAS,CAqBzD;AAED,wBAAgB,UAAU,CAAC,SAAS,EAAE,SAAS,QAQ9C;AA2BD,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,gBAAgB,EAAE,GAC3B,MAAM,GAAG,IAAI,CAef;AAED,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,gBAAgB,EAAE,GAC3B;IACD,gBAAgB,EAAE,IAAI,GAAG,SAAS,CAAC;IACnC,QAAQ,EAAE,eAAe,GAAG,SAAS,CAAC;IACtC,UAAU,EAAE,UAAU,GAAG,SAAS,CAAC;CACpC,CA0BA"}
@@ -4,8 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.CHAT_STATE_PATH = exports.LATEST_CHAT_STATE_VERSION = exports.CHAT_STATE_VERSIONS_MIGRATIONS_MAP = void 0;
7
- exports.clearChatState = clearChatState;
8
- exports.createChatState = createChatState;
9
7
  exports.createChatStateForMessages = createChatStateForMessages;
10
8
  exports.chatStateFromModel = chatStateFromModel;
11
9
  exports.getUsageSummary = getUsageSummary;
@@ -14,59 +12,13 @@ exports.migrateChatState = migrateChatState;
14
12
  exports.saveToDisk = saveToDisk;
15
13
  exports.getLatestDownloadBuildUrl = getLatestDownloadBuildUrl;
16
14
  exports.fetchToolCallFromId = fetchToolCallFromId;
17
- const chat_1 = require("@empiricalrun/llm/chat");
18
15
  const fs_1 = __importDefault(require("fs"));
19
16
  const path_1 = __importDefault(require("path"));
20
- // Migration wrapper for v20250327.1 -> v0.1 chat state versions
21
- // v20250327.1 was model-specific, but v0.1 is canonical
22
- function migrateToV01(oldState) {
23
- if (oldState.model &&
24
- typeof oldState.model === "string" &&
25
- Array.isArray(oldState.messages)) {
26
- const provider = (0, chat_1.getProviderForModel)(oldState.model);
27
- if (provider === "google") {
28
- return {
29
- ...oldState,
30
- version: "0.1",
31
- messages: oldState.messages.map(chat_1.geminiToCanonical),
32
- };
33
- }
34
- else {
35
- throw new Error(`Unsupported state for migration with model: ${oldState.model} and version: ${oldState.version}`);
36
- }
37
- }
38
- // If not Gemini or not matching, return the old state
39
- return oldState;
40
- }
41
17
  exports.CHAT_STATE_VERSIONS_MIGRATIONS_MAP = {
42
- "20250327.1": migrateToV01,
43
18
  "0.1": (state) => state,
44
19
  };
45
20
  exports.LATEST_CHAT_STATE_VERSION = "0.1";
46
21
  exports.CHAT_STATE_PATH = path_1.default.join(process.cwd(), ".empiricalrun", "last-chat.json");
47
- function clearChatState() {
48
- try {
49
- if (fs_1.default.existsSync(exports.CHAT_STATE_PATH)) {
50
- fs_1.default.unlinkSync(exports.CHAT_STATE_PATH);
51
- }
52
- }
53
- catch {
54
- // Swallow errors to avoid blocking the CLI; deletion is best-effort
55
- }
56
- }
57
- function createChatState({ userPrompt, attachments, existingState, selectedModel, error, }) {
58
- const messages = existingState?.messages || [];
59
- const chatModel = (0, chat_1.createChatModel)(messages, selectedModel);
60
- if (userPrompt) {
61
- chatModel.pushUserMessage(userPrompt, attachments);
62
- }
63
- return createChatStateForMessages({
64
- messages: chatModel.messages,
65
- selectedModel,
66
- askUserForInput: chatModel.askUserForInput,
67
- error,
68
- });
69
- }
70
22
  function createChatStateForMessages({ messages, selectedModel, askUserForInput, error, }) {
71
23
  // TODO: Add better types for messages
72
24
  return {
@@ -85,8 +37,8 @@ function chatStateFromModel({ chatModel, error, }) {
85
37
  error,
86
38
  });
87
39
  }
88
- function getUsageSummary(chatModel) {
89
- const messages = chatModel.messages;
40
+ function getUsageSummary(chatState) {
41
+ const messages = chatState.messages;
90
42
  const messageUsages = messages.map((msg) => msg.usage).filter(Boolean);
91
43
  const inputTokens = messageUsages.reduce((sum, usage) => sum + (usage?.tokens?.input || 0), 0);
92
44
  const outputTokens = messageUsages.reduce((sum, usage) => sum + (usage?.tokens?.output || 0), 0);
@@ -103,7 +55,17 @@ function getUsageSummary(chatModel) {
103
55
  Input: ${inputTokens.toLocaleString()} tokens / Output: ${outputTokens.toLocaleString()} tokens`;
104
56
  return msgsSummary;
105
57
  }
106
- function loadChatState() {
58
+ function loadChatState({ resetChat, }) {
59
+ if (resetChat) {
60
+ try {
61
+ if (fs_1.default.existsSync(exports.CHAT_STATE_PATH)) {
62
+ fs_1.default.unlinkSync(exports.CHAT_STATE_PATH);
63
+ }
64
+ }
65
+ catch {
66
+ // Swallow errors to avoid blocking the CLI; deletion is best-effort
67
+ }
68
+ }
107
69
  if (!fs_1.default.existsSync(exports.CHAT_STATE_PATH)) {
108
70
  return undefined;
109
71
  }
@@ -141,21 +103,14 @@ function migrateChatState(oldState) {
141
103
  ...migrated,
142
104
  };
143
105
  }
144
- function saveToDisk(messages, selectedModel, askUserForInput, error) {
106
+ function saveToDisk(chatState) {
145
107
  const statePath = exports.CHAT_STATE_PATH;
146
108
  // Ensure directory exists before trying to read/write
147
109
  const dirname = path_1.default.dirname(statePath);
148
110
  if (!fs_1.default.existsSync(dirname)) {
149
111
  fs_1.default.mkdirSync(dirname, { recursive: true });
150
112
  }
151
- // Use the helper to build the new state
152
- const newState = createChatStateForMessages({
153
- messages,
154
- selectedModel,
155
- askUserForInput,
156
- error,
157
- });
158
- fs_1.default.writeFileSync(statePath, JSON.stringify(newState, null, 2));
113
+ fs_1.default.writeFileSync(statePath, JSON.stringify(chatState, null, 2));
159
114
  }
160
115
  function findLatestToolCall(messages, toolName) {
161
116
  return messages
@@ -1,11 +1,11 @@
1
1
  import { TraceClient } from "@empiricalrun/llm";
2
- import { IChatModel } from "@empiricalrun/llm/chat";
2
+ import { IChatCanonicalModel, IChatModel } from "@empiricalrun/llm/chat";
3
3
  import { Attachment, ReporterFunction } from "@empiricalrun/shared-types";
4
4
  export declare const log: (...args: any[]) => void;
5
5
  export declare function getModelName(model: string): string;
6
6
  export declare function handleAgentError({ error, chatModel, reporter, trace, }: {
7
7
  error: unknown;
8
- chatModel: IChatModel<any>;
8
+ chatModel: IChatModel<any> | IChatCanonicalModel;
9
9
  reporter: ReporterFunction;
10
10
  trace?: TraceClient;
11
11
  }): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/agent/chat/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAuB,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,EACL,UAAU,EAEV,gBAAgB,EACjB,MAAM,4BAA4B,CAAC;AAKpC,eAAO,MAAM,GAAG,GAAI,GAAG,MAAM,GAAG,EAAE,SAEjC,CAAC;AAcF,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMlD;AAED,wBAAsB,gBAAgB,CAAC,EACrC,KAAK,EACL,SAAS,EACT,QAAQ,EACR,KAAK,GACN,EAAE;IACD,KAAK,EAAE,OAAO,CAAC;IACf,SAAS,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC;IAC3B,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,KAAK,CAAC,EAAE,WAAW,CAAC;CACrB,iBAeA;AAED,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG;IACtD,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,UAAU,EAAE,CAAC;CAC3B,CAsBA"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/agent/chat/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAGL,mBAAmB,EACnB,UAAU,EACX,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,UAAU,EAEV,gBAAgB,EACjB,MAAM,4BAA4B,CAAC;AAKpC,eAAO,MAAM,GAAG,GAAI,GAAG,MAAM,GAAG,EAAE,SAEjC,CAAC;AAcF,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMlD;AAED,wBAAsB,gBAAgB,CAAC,EACrC,KAAK,EACL,SAAS,EACT,QAAQ,EACR,KAAK,GACN,EAAE;IACD,KAAK,EAAE,OAAO,CAAC;IACf,SAAS,EAAE,UAAU,CAAC,GAAG,CAAC,GAAG,mBAAmB,CAAC;IACjD,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,KAAK,CAAC,EAAE,WAAW,CAAC;CACrB,iBAaA;AASD,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG;IACtD,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,UAAU,EAAE,CAAC;CAC3B,CA4BA"}