@empiricalrun/test-gen 0.76.0 → 0.77.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.
- package/CHANGELOG.md +33 -0
- package/dist/agent/base/index.d.ts +25 -21
- package/dist/agent/base/index.d.ts.map +1 -1
- package/dist/agent/base/index.js +48 -37
- package/dist/agent/browsing/run.d.ts +1 -2
- package/dist/agent/browsing/run.d.ts.map +1 -1
- package/dist/agent/browsing/run.js +3 -9
- package/dist/agent/browsing/utils.d.ts +2 -9
- package/dist/agent/browsing/utils.d.ts.map +1 -1
- package/dist/agent/browsing/utils.js +5 -109
- package/dist/agent/chat/agent-loop.d.ts +5 -5
- package/dist/agent/chat/agent-loop.d.ts.map +1 -1
- package/dist/agent/chat/agent-loop.js +3 -8
- package/dist/agent/chat/exports.d.ts +5 -4
- package/dist/agent/chat/exports.d.ts.map +1 -1
- package/dist/agent/chat/exports.js +4 -7
- package/dist/agent/chat/index.d.ts +2 -2
- package/dist/agent/chat/index.d.ts.map +1 -1
- package/dist/agent/chat/index.js +23 -35
- package/dist/agent/chat/models.d.ts +0 -2
- package/dist/agent/chat/models.d.ts.map +1 -1
- package/dist/agent/chat/models.js +12 -26
- package/dist/agent/chat/prompt/pw-utils-docs.d.ts +1 -1
- package/dist/agent/chat/prompt/pw-utils-docs.d.ts.map +1 -1
- package/dist/agent/chat/prompt/pw-utils-docs.js +52 -0
- package/dist/agent/chat/prompt/repo.d.ts.map +1 -1
- package/dist/agent/chat/prompt/repo.js +11 -22
- package/dist/agent/chat/prompt/test-case-def.d.ts +2 -0
- package/dist/agent/chat/prompt/test-case-def.d.ts.map +1 -0
- package/dist/agent/chat/prompt/test-case-def.js +44 -0
- package/dist/agent/chat/state.d.ts +7 -6
- package/dist/agent/chat/state.d.ts.map +1 -1
- package/dist/agent/chat/state.js +15 -45
- package/dist/agent/chat/utils.d.ts +2 -2
- package/dist/agent/chat/utils.d.ts.map +1 -1
- package/dist/agent/chat/utils.js +14 -7
- package/dist/agent/cli.d.ts.map +1 -1
- package/dist/agent/cli.js +62 -58
- package/dist/agent/code-review/executor/index.d.ts +5 -0
- package/dist/agent/code-review/executor/index.d.ts.map +1 -0
- package/dist/agent/code-review/executor/index.js +13 -0
- package/dist/agent/code-review/index.d.ts +8 -3
- package/dist/agent/code-review/index.d.ts.map +1 -1
- package/dist/agent/code-review/index.js +115 -21
- package/dist/agent/code-review/parser.d.ts +5 -0
- package/dist/agent/code-review/parser.d.ts.map +1 -0
- package/dist/agent/code-review/parser.js +70 -0
- package/dist/agent/code-review/types.d.ts +36 -0
- package/dist/agent/code-review/types.d.ts.map +1 -0
- package/dist/agent/code-review/types.js +13 -0
- package/dist/agent/cua/index.d.ts.map +1 -1
- package/dist/agent/cua/index.js +18 -2
- package/dist/agent/cua/model.d.ts.map +1 -1
- package/dist/agent/cua/model.js +4 -1
- package/dist/agent/cua/pw-codegen/pw-pause/index.d.ts.map +1 -1
- package/dist/agent/triage/index.d.ts +2 -2
- package/dist/agent/triage/index.d.ts.map +1 -1
- package/dist/agent/triage/index.js +8 -7
- package/dist/agent/video-analysis/executor/index.d.ts +5 -0
- package/dist/agent/video-analysis/executor/index.d.ts.map +1 -0
- package/dist/agent/video-analysis/executor/index.js +10 -0
- package/dist/agent/video-analysis/index.d.ts +2 -2
- package/dist/agent/video-analysis/index.d.ts.map +1 -1
- package/dist/agent/video-analysis/index.js +38 -13
- package/dist/artifacts/index.d.ts +1 -1
- package/dist/artifacts/index.d.ts.map +1 -1
- package/dist/artifacts/index.js +3 -1
- package/dist/artifacts/utils.d.ts.map +1 -1
- package/dist/bin/index.js +66 -21
- package/dist/constants/index.d.ts +14 -0
- package/dist/constants/index.d.ts.map +1 -1
- package/dist/constants/index.js +33 -1
- package/dist/file/server.d.ts +1 -3
- package/dist/file/server.d.ts.map +1 -1
- package/dist/file/server.js +0 -13
- package/dist/file-info/adapters/file-system/index.d.ts.map +1 -1
- package/dist/file-info/adapters/file-system/reader.d.ts.map +1 -1
- package/dist/file-info/adapters/file-system/reader.js +8 -1
- package/dist/file-info/adapters/github/index.d.ts.map +1 -1
- package/dist/file-info/adapters/github/reader.d.ts +1 -1
- package/dist/file-info/adapters/github/reader.d.ts.map +1 -1
- package/dist/file-info/adapters/github/reader.js +8 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/tools/analyse-video/index.d.ts +5 -0
- package/dist/tools/analyse-video/index.d.ts.map +1 -0
- package/dist/tools/analyse-video/index.js +50 -0
- package/dist/tools/create-pull-request/index.js +4 -6
- package/dist/tools/create-pull-request/utils.d.ts +1 -1
- package/dist/tools/definitions/{fetch-video-analysis.d.ts → analyse-video.d.ts} +13 -8
- package/dist/tools/definitions/analyse-video.d.ts.map +1 -0
- package/dist/tools/definitions/analyse-video.js +60 -0
- package/dist/tools/definitions/review-pull-request.d.ts +3 -0
- package/dist/tools/definitions/review-pull-request.d.ts.map +1 -0
- package/dist/tools/definitions/review-pull-request.js +16 -0
- package/dist/tools/definitions/str_replace_editor.d.ts +1 -0
- package/dist/tools/definitions/str_replace_editor.d.ts.map +1 -1
- package/dist/tools/definitions/str_replace_editor.js +4 -1
- package/dist/tools/definitions/test-gen-browser.d.ts +0 -3
- package/dist/tools/definitions/test-gen-browser.d.ts.map +1 -1
- package/dist/tools/definitions/test-gen-browser.js +33 -8
- package/dist/tools/delete-file/index.d.ts.map +1 -1
- package/dist/tools/delete-file/index.js +1 -19
- package/dist/tools/executor/base.d.ts +32 -0
- package/dist/tools/executor/base.d.ts.map +1 -0
- package/dist/tools/executor/base.js +114 -0
- package/dist/tools/executor/index.d.ts +3 -22
- package/dist/tools/executor/index.d.ts.map +1 -1
- package/dist/tools/executor/index.js +7 -100
- package/dist/tools/executor/utils/checkpoint.d.ts +1 -1
- package/dist/tools/executor/utils/checkpoint.d.ts.map +1 -1
- package/dist/tools/executor/utils/checkpoint.js +6 -2
- package/dist/tools/executor/utils/git.d.ts +2 -2
- package/dist/tools/executor/utils/git.d.ts.map +1 -1
- package/dist/tools/executor/utils/git.js +7 -3
- package/dist/tools/executor/utils/index.d.ts.map +1 -1
- package/dist/tools/executor/utils/index.js +1 -1
- package/dist/tools/fetch-session-diff/index.js +2 -2
- package/dist/tools/file-operations/create.d.ts.map +1 -1
- package/dist/tools/file-operations/create.js +1 -4
- package/dist/tools/file-operations/index.d.ts +2 -1
- package/dist/tools/file-operations/index.d.ts.map +1 -1
- package/dist/tools/file-operations/index.js +4 -1
- package/dist/tools/file-operations/insert.d.ts +1 -2
- package/dist/tools/file-operations/insert.d.ts.map +1 -1
- package/dist/tools/file-operations/insert.js +1 -4
- package/dist/tools/file-operations/replace.d.ts.map +1 -1
- package/dist/tools/file-operations/replace.js +1 -4
- package/dist/tools/grep/index.d.ts.map +1 -1
- package/dist/tools/grep/index.js +18 -11
- package/dist/tools/index.d.ts +5 -5
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +17 -16
- package/dist/tools/merge-conflicts/index.d.ts.map +1 -1
- package/dist/tools/merge-conflicts/index.js +1 -1
- package/dist/tools/rename-file/index.js +1 -1
- package/dist/tools/review-pull-request/index.d.ts.map +1 -1
- package/dist/tools/review-pull-request/index.js +45 -59
- package/dist/tools/run-test.d.ts.map +1 -1
- package/dist/tools/run-test.js +25 -3
- package/dist/tools/test-gen-browser.d.ts.map +1 -1
- package/dist/tools/test-gen-browser.js +51 -47
- package/dist/utils/artifact-paths.d.ts +20 -0
- package/dist/utils/artifact-paths.d.ts.map +1 -0
- package/dist/utils/artifact-paths.js +16 -0
- package/dist/utils/dedup-image-fs.d.ts +2 -16
- package/dist/utils/dedup-image-fs.d.ts.map +1 -1
- package/dist/utils/dedup-image-fs.js +12 -16
- package/dist/utils/dedup-image.d.ts +1 -14
- package/dist/utils/dedup-image.d.ts.map +1 -1
- package/dist/utils/dedup-image.js +7 -62
- package/dist/utils/{local-ffmpeg-client.d.ts → ffmpeg/index.d.ts} +6 -7
- package/dist/utils/ffmpeg/index.d.ts.map +1 -0
- package/dist/utils/{local-ffmpeg-client.js → ffmpeg/index.js} +169 -53
- package/dist/utils/find-threshold.d.ts +8 -0
- package/dist/utils/find-threshold.d.ts.map +1 -0
- package/dist/utils/find-threshold.js +55 -0
- package/dist/utils/hash.d.ts +2 -0
- package/dist/utils/hash.d.ts.map +1 -0
- package/dist/utils/hash.js +24 -0
- package/dist/utils/model.d.ts +1 -1
- package/dist/utils/model.d.ts.map +1 -1
- package/dist/utils/model.js +7 -5
- package/dist/utils/repo-tree.d.ts +0 -1
- package/dist/utils/repo-tree.d.ts.map +1 -1
- package/dist/utils/repo-tree.js +2 -14
- package/dist/utils/slug.js +1 -1
- package/dist/video-core/agent-orchestrator.d.ts +14 -0
- package/dist/video-core/agent-orchestrator.d.ts.map +1 -0
- package/dist/video-core/agent-orchestrator.js +78 -0
- package/dist/video-core/analysis-server.d.ts +24 -0
- package/dist/video-core/analysis-server.d.ts.map +1 -0
- package/dist/video-core/analysis-server.js +398 -0
- package/dist/video-core/analysis-viewer.html +1374 -0
- package/dist/video-core/index.d.ts +44 -0
- package/dist/video-core/index.d.ts.map +1 -0
- package/dist/video-core/index.js +204 -0
- package/dist/video-core/model-limits.d.ts +4 -0
- package/dist/video-core/model-limits.d.ts.map +1 -0
- package/dist/video-core/model-limits.js +67 -0
- package/dist/video-core/storage-manager.d.ts +5 -0
- package/dist/video-core/storage-manager.d.ts.map +1 -0
- package/dist/video-core/storage-manager.js +55 -0
- package/dist/video-core/types.d.ts +13 -0
- package/dist/video-core/types.d.ts.map +1 -0
- package/dist/video-core/types.js +2 -0
- package/dist/video-core/utils.d.ts +25 -0
- package/dist/video-core/utils.d.ts.map +1 -0
- package/dist/video-core/utils.js +211 -0
- package/dist/video-core/xml-parser.d.ts +3 -0
- package/dist/video-core/xml-parser.d.ts.map +1 -0
- package/dist/video-core/xml-parser.js +27 -0
- package/package.json +5 -6
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/agent/chat/prompt/index.d.ts +0 -6
- package/dist/agent/chat/prompt/index.d.ts.map +0 -1
- package/dist/agent/chat/prompt/index.js +0 -200
- package/dist/agent/code-review/prompt.d.ts +0 -2
- package/dist/agent/code-review/prompt.d.ts.map +0 -1
- package/dist/agent/code-review/prompt.js +0 -55
- package/dist/agent/diagnosis-agent/index.d.ts +0 -11
- package/dist/agent/diagnosis-agent/index.d.ts.map +0 -1
- package/dist/agent/diagnosis-agent/index.js +0 -88
- package/dist/agent/diagnosis-agent/strict-mode-violation.d.ts +0 -10
- package/dist/agent/diagnosis-agent/strict-mode-violation.d.ts.map +0 -1
- package/dist/agent/diagnosis-agent/strict-mode-violation.js +0 -30
- package/dist/tools/definitions/extract-frames-from-video.d.ts +0 -39
- package/dist/tools/definitions/extract-frames-from-video.d.ts.map +0 -1
- package/dist/tools/definitions/extract-frames-from-video.js +0 -60
- package/dist/tools/definitions/fetch-video-analysis.d.ts.map +0 -1
- package/dist/tools/definitions/fetch-video-analysis.js +0 -61
- package/dist/tools/extract-frames-from-video/index.d.ts +0 -7
- package/dist/tools/extract-frames-from-video/index.d.ts.map +0 -1
- package/dist/tools/extract-frames-from-video/index.js +0 -145
- package/dist/tools/fetch-video-analysis/index.d.ts +0 -5
- package/dist/tools/fetch-video-analysis/index.d.ts.map +0 -1
- package/dist/tools/fetch-video-analysis/index.js +0 -149
- package/dist/tools/fetch-video-analysis/open-ai.d.ts +0 -6
- package/dist/tools/fetch-video-analysis/open-ai.d.ts.map +0 -1
- package/dist/tools/fetch-video-analysis/open-ai.js +0 -37
- package/dist/tools/fetch-video-analysis/utils.d.ts +0 -16
- package/dist/tools/fetch-video-analysis/utils.d.ts.map +0 -1
- package/dist/tools/fetch-video-analysis/utils.js +0 -121
- package/dist/tools/fetch-video-analysis/video-analysis.d.ts +0 -7
- package/dist/tools/fetch-video-analysis/video-analysis.d.ts.map +0 -1
- package/dist/tools/fetch-video-analysis/video-analysis.js +0 -70
- package/dist/tools/file-operations/shared/git-helper.d.ts +0 -4
- package/dist/tools/file-operations/shared/git-helper.d.ts.map +0 -1
- package/dist/tools/file-operations/shared/git-helper.js +0 -29
- package/dist/utils/local-ffmpeg-client.d.ts.map +0 -1
- package/eslint.config.mjs +0 -43
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
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.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,7 +16,6 @@ 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; } });
|
|
@@ -28,6 +28,3 @@ Object.defineProperty(exports, "LATEST_CHAT_STATE_VERSION", { enumerable: true,
|
|
|
28
28
|
Object.defineProperty(exports, "migrateChatState", { enumerable: true, get: function () { return state_1.migrateChatState; } });
|
|
29
29
|
var utils_1 = require("./utils");
|
|
30
30
|
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 {
|
|
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():
|
|
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,
|
|
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"}
|
package/dist/agent/chat/index.js
CHANGED
|
@@ -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
|
|
10
|
+
const custom = [
|
|
10
11
|
...tools_1.commonTools,
|
|
11
12
|
...tools_1.testGenerationTools,
|
|
12
|
-
|
|
13
|
+
tools_1.analyseVideo,
|
|
13
14
|
...(0, tools_1.textEditorToolsForModel)(this.selectedModel),
|
|
14
15
|
];
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
|
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
|
-
|
|
63
|
-
that a UI selector needs to be updated, using the browser agent is a good idea.
|
|
51
|
+
For example,
|
|
64
52
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
70
|
-
|
|
71
|
-
// TODO(agent): Click on the login button
|
|
58
|
+
# Proactiveness
|
|
72
59
|
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
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
|
-
|
|
80
|
-
|
|
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;
|
|
1
|
+
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../../src/agent/chat/models.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAMjE,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.
|
|
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
|
-
|
|
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 = "gpt-5-codex";
|
|
14
7
|
const resolveChatModelBasedOnInput = (requestedModel) => {
|
|
15
8
|
const sanitizedModelInput = requestedModel?.trim().toLowerCase();
|
|
16
9
|
if (!sanitizedModelInput || sanitizedModelInput === "auto") {
|
|
17
|
-
|
|
18
|
-
return autoSelectedModelId;
|
|
10
|
+
return DEFAULT_AUTO_FALLBACK_MODEL;
|
|
19
11
|
}
|
|
20
|
-
//
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
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":"
|
|
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;
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
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,9 +1,8 @@
|
|
|
1
|
-
import { IChatModel } from "@empiricalrun/llm/chat";
|
|
1
|
+
import { IChatCanonicalModel, IChatModel } from "@empiricalrun/llm/chat";
|
|
2
2
|
import { Attachment, 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
6
|
export declare function createChatState({ userPrompt, attachments, existingState, selectedModel, error, }: {
|
|
8
7
|
userPrompt: string | undefined;
|
|
9
8
|
attachments: Attachment[];
|
|
@@ -18,17 +17,19 @@ export declare function createChatStateForMessages({ messages, selectedModel, as
|
|
|
18
17
|
error: ChatStateError | null;
|
|
19
18
|
}): ChatState;
|
|
20
19
|
export declare function chatStateFromModel<T>({ chatModel, error, }: {
|
|
21
|
-
chatModel: IChatModel<T
|
|
20
|
+
chatModel: IChatModel<T> | IChatCanonicalModel;
|
|
22
21
|
error: ChatStateError | null;
|
|
23
22
|
}): ChatState;
|
|
24
|
-
export declare function getUsageSummary(
|
|
25
|
-
export declare function loadChatState(
|
|
23
|
+
export declare function getUsageSummary(chatState: ChatState): string;
|
|
24
|
+
export declare function loadChatState({ resetChat, }: {
|
|
25
|
+
resetChat: boolean;
|
|
26
|
+
}): ChatState | undefined;
|
|
26
27
|
/**
|
|
27
28
|
* Migrates a chat state object from an old version to the latest version.
|
|
28
29
|
* Add migration logic for each version as needed.
|
|
29
30
|
*/
|
|
30
31
|
export declare function migrateChatState(oldState: any): ChatState;
|
|
31
|
-
export declare function saveToDisk(
|
|
32
|
+
export declare function saveToDisk(chatState: ChatState): void;
|
|
32
33
|
export declare function getLatestDownloadBuildUrl(messages: CanonicalMessage[]): string | null;
|
|
33
34
|
export declare function fetchToolCallFromId(toolCallId: String, messages: CanonicalMessage[]): {
|
|
34
35
|
toolCallQueuedAt: Date | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../src/agent/chat/state.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../src/agent/chat/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,mBAAmB,EACnB,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;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,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,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"}
|
package/dist/agent/chat/state.js
CHANGED
|
@@ -4,7 +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
7
|
exports.createChatState = createChatState;
|
|
9
8
|
exports.createChatStateForMessages = createChatStateForMessages;
|
|
10
9
|
exports.chatStateFromModel = chatStateFromModel;
|
|
@@ -17,43 +16,11 @@ exports.fetchToolCallFromId = fetchToolCallFromId;
|
|
|
17
16
|
const chat_1 = require("@empiricalrun/llm/chat");
|
|
18
17
|
const fs_1 = __importDefault(require("fs"));
|
|
19
18
|
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
19
|
exports.CHAT_STATE_VERSIONS_MIGRATIONS_MAP = {
|
|
42
|
-
"20250327.1": migrateToV01,
|
|
43
20
|
"0.1": (state) => state,
|
|
44
21
|
};
|
|
45
22
|
exports.LATEST_CHAT_STATE_VERSION = "0.1";
|
|
46
23
|
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
24
|
function createChatState({ userPrompt, attachments, existingState, selectedModel, error, }) {
|
|
58
25
|
const messages = existingState?.messages || [];
|
|
59
26
|
const chatModel = (0, chat_1.createChatModel)(messages, selectedModel);
|
|
@@ -85,8 +52,8 @@ function chatStateFromModel({ chatModel, error, }) {
|
|
|
85
52
|
error,
|
|
86
53
|
});
|
|
87
54
|
}
|
|
88
|
-
function getUsageSummary(
|
|
89
|
-
const messages =
|
|
55
|
+
function getUsageSummary(chatState) {
|
|
56
|
+
const messages = chatState.messages;
|
|
90
57
|
const messageUsages = messages.map((msg) => msg.usage).filter(Boolean);
|
|
91
58
|
const inputTokens = messageUsages.reduce((sum, usage) => sum + (usage?.tokens?.input || 0), 0);
|
|
92
59
|
const outputTokens = messageUsages.reduce((sum, usage) => sum + (usage?.tokens?.output || 0), 0);
|
|
@@ -103,7 +70,17 @@ function getUsageSummary(chatModel) {
|
|
|
103
70
|
Input: ${inputTokens.toLocaleString()} tokens / Output: ${outputTokens.toLocaleString()} tokens`;
|
|
104
71
|
return msgsSummary;
|
|
105
72
|
}
|
|
106
|
-
function loadChatState() {
|
|
73
|
+
function loadChatState({ resetChat, }) {
|
|
74
|
+
if (resetChat) {
|
|
75
|
+
try {
|
|
76
|
+
if (fs_1.default.existsSync(exports.CHAT_STATE_PATH)) {
|
|
77
|
+
fs_1.default.unlinkSync(exports.CHAT_STATE_PATH);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
// Swallow errors to avoid blocking the CLI; deletion is best-effort
|
|
82
|
+
}
|
|
83
|
+
}
|
|
107
84
|
if (!fs_1.default.existsSync(exports.CHAT_STATE_PATH)) {
|
|
108
85
|
return undefined;
|
|
109
86
|
}
|
|
@@ -141,21 +118,14 @@ function migrateChatState(oldState) {
|
|
|
141
118
|
...migrated,
|
|
142
119
|
};
|
|
143
120
|
}
|
|
144
|
-
function saveToDisk(
|
|
121
|
+
function saveToDisk(chatState) {
|
|
145
122
|
const statePath = exports.CHAT_STATE_PATH;
|
|
146
123
|
// Ensure directory exists before trying to read/write
|
|
147
124
|
const dirname = path_1.default.dirname(statePath);
|
|
148
125
|
if (!fs_1.default.existsSync(dirname)) {
|
|
149
126
|
fs_1.default.mkdirSync(dirname, { recursive: true });
|
|
150
127
|
}
|
|
151
|
-
|
|
152
|
-
const newState = createChatStateForMessages({
|
|
153
|
-
messages,
|
|
154
|
-
selectedModel,
|
|
155
|
-
askUserForInput,
|
|
156
|
-
error,
|
|
157
|
-
});
|
|
158
|
-
fs_1.default.writeFileSync(statePath, JSON.stringify(newState, null, 2));
|
|
128
|
+
fs_1.default.writeFileSync(statePath, JSON.stringify(chatState, null, 2));
|
|
159
129
|
}
|
|
160
130
|
function findLatestToolCall(messages, toolName) {
|
|
161
131
|
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,
|
|
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"}
|
package/dist/agent/chat/utils.js
CHANGED
|
@@ -34,25 +34,32 @@ async function handleAgentError({ error, chatModel, reporter, trace, }) {
|
|
|
34
34
|
message: error.message,
|
|
35
35
|
stack: error.stack || "Stack trace not available",
|
|
36
36
|
timestamp: new Date().toISOString(),
|
|
37
|
+
type: error instanceof chat_1.CanonicalError ? error.type : null,
|
|
37
38
|
};
|
|
38
|
-
await reporter((0, state_1.chatStateFromModel)({
|
|
39
|
-
chatModel,
|
|
40
|
-
error: errorObject,
|
|
41
|
-
}), chatModel.getHumanReadableLatestMessage());
|
|
39
|
+
await reporter((0, state_1.chatStateFromModel)({ chatModel, error: errorObject }), chatModel.getHumanReadableLatestMessage());
|
|
42
40
|
trace?.update({ output: { error: errorObject } });
|
|
43
41
|
logError(error, trace);
|
|
44
42
|
}
|
|
43
|
+
const VALID_ATTACHMENTS = [".webm", ".png"];
|
|
44
|
+
const MIME_MAP = {
|
|
45
|
+
".webm": "video/webm",
|
|
46
|
+
".png": "image/png",
|
|
47
|
+
};
|
|
45
48
|
function extractAttachments(userPrompt) {
|
|
46
49
|
const attachments = [];
|
|
47
50
|
const urlPattern = /\[\[(https?:\/\/[^\]]+)\]\]/g;
|
|
48
51
|
let match;
|
|
49
52
|
while ((match = urlPattern.exec(userPrompt)) !== null) {
|
|
50
53
|
const name = match[1].split("/").pop();
|
|
51
|
-
|
|
52
|
-
|
|
54
|
+
const ext = name ? name.substring(name.lastIndexOf(".")) : null;
|
|
55
|
+
if (!ext) {
|
|
56
|
+
throw new Error(`Attachment URL does not have a valid file extension: ${match[1]}`);
|
|
57
|
+
}
|
|
58
|
+
if (!name || !VALID_ATTACHMENTS.some((validExt) => ext === validExt)) {
|
|
59
|
+
throw new Error(`Invalid attachment name: ${name}. Only ${VALID_ATTACHMENTS.join(", ")} files are supported.`);
|
|
53
60
|
}
|
|
54
61
|
attachments.push({
|
|
55
|
-
contentType:
|
|
62
|
+
contentType: MIME_MAP[ext],
|
|
56
63
|
name,
|
|
57
64
|
url: match[1],
|
|
58
65
|
});
|