@empiricalrun/playwright-utils 0.23.0 → 0.23.2
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 +13 -0
- package/package.json +3 -3
- package/bundled/test-gen/actions/assert.d.ts +0 -4
- package/bundled/test-gen/actions/assert.d.ts.map +0 -1
- package/bundled/test-gen/actions/assert.js +0 -50
- package/bundled/test-gen/actions/click.d.ts +0 -4
- package/bundled/test-gen/actions/click.d.ts.map +0 -1
- package/bundled/test-gen/actions/click.js +0 -51
- package/bundled/test-gen/actions/constants/index.d.ts +0 -2
- package/bundled/test-gen/actions/constants/index.d.ts.map +0 -1
- package/bundled/test-gen/actions/constants/index.js +0 -4
- package/bundled/test-gen/actions/done.d.ts +0 -4
- package/bundled/test-gen/actions/done.d.ts.map +0 -1
- package/bundled/test-gen/actions/done.js +0 -30
- package/bundled/test-gen/actions/fill.d.ts +0 -4
- package/bundled/test-gen/actions/fill.d.ts.map +0 -1
- package/bundled/test-gen/actions/fill.js +0 -82
- package/bundled/test-gen/actions/goto.d.ts +0 -4
- package/bundled/test-gen/actions/goto.d.ts.map +0 -1
- package/bundled/test-gen/actions/goto.js +0 -47
- package/bundled/test-gen/actions/hover.d.ts +0 -4
- package/bundled/test-gen/actions/hover.d.ts.map +0 -1
- package/bundled/test-gen/actions/hover.js +0 -51
- package/bundled/test-gen/actions/index.d.ts +0 -30
- package/bundled/test-gen/actions/index.d.ts.map +0 -1
- package/bundled/test-gen/actions/index.js +0 -159
- package/bundled/test-gen/actions/next-task.d.ts +0 -53
- package/bundled/test-gen/actions/next-task.d.ts.map +0 -1
- package/bundled/test-gen/actions/next-task.js +0 -58
- package/bundled/test-gen/actions/press.d.ts +0 -4
- package/bundled/test-gen/actions/press.d.ts.map +0 -1
- package/bundled/test-gen/actions/press.js +0 -56
- package/bundled/test-gen/actions/skill.d.ts +0 -21
- package/bundled/test-gen/actions/skill.d.ts.map +0 -1
- package/bundled/test-gen/actions/skill.js +0 -127
- package/bundled/test-gen/actions/text-content.d.ts +0 -4
- package/bundled/test-gen/actions/text-content.d.ts.map +0 -1
- package/bundled/test-gen/actions/text-content.js +0 -58
- package/bundled/test-gen/actions/utils/index.d.ts +0 -10
- package/bundled/test-gen/actions/utils/index.d.ts.map +0 -1
- package/bundled/test-gen/actions/utils/index.js +0 -109
- package/bundled/test-gen/agent/browsing/index.d.ts +0 -15
- package/bundled/test-gen/agent/browsing/index.d.ts.map +0 -1
- package/bundled/test-gen/agent/browsing/index.js +0 -68
- package/bundled/test-gen/agent/browsing/run.d.ts +0 -19
- package/bundled/test-gen/agent/browsing/run.d.ts.map +0 -1
- package/bundled/test-gen/agent/browsing/run.js +0 -88
- package/bundled/test-gen/agent/browsing/utils.d.ts +0 -41
- package/bundled/test-gen/agent/browsing/utils.d.ts.map +0 -1
- package/bundled/test-gen/agent/browsing/utils.js +0 -406
- package/bundled/test-gen/agent/codegen/create-test-block.d.ts +0 -9
- package/bundled/test-gen/agent/codegen/create-test-block.d.ts.map +0 -1
- package/bundled/test-gen/agent/codegen/create-test-block.js +0 -63
- package/bundled/test-gen/agent/codegen/fix-ts-errors.d.ts +0 -13
- package/bundled/test-gen/agent/codegen/fix-ts-errors.d.ts.map +0 -1
- package/bundled/test-gen/agent/codegen/fix-ts-errors.js +0 -80
- package/bundled/test-gen/agent/codegen/generate-code-apply-changes.d.ts +0 -13
- package/bundled/test-gen/agent/codegen/generate-code-apply-changes.d.ts.map +0 -1
- package/bundled/test-gen/agent/codegen/generate-code-apply-changes.js +0 -381
- package/bundled/test-gen/agent/codegen/lexical-scoped-vars.d.ts +0 -9
- package/bundled/test-gen/agent/codegen/lexical-scoped-vars.d.ts.map +0 -1
- package/bundled/test-gen/agent/codegen/lexical-scoped-vars.js +0 -56
- package/bundled/test-gen/agent/codegen/repo-edit.d.ts +0 -23
- package/bundled/test-gen/agent/codegen/repo-edit.d.ts.map +0 -1
- package/bundled/test-gen/agent/codegen/repo-edit.js +0 -86
- package/bundled/test-gen/agent/codegen/run.d.ts +0 -16
- package/bundled/test-gen/agent/codegen/run.d.ts.map +0 -1
- package/bundled/test-gen/agent/codegen/run.js +0 -119
- package/bundled/test-gen/agent/codegen/skills-retriever.d.ts +0 -26
- package/bundled/test-gen/agent/codegen/skills-retriever.d.ts.map +0 -1
- package/bundled/test-gen/agent/codegen/skills-retriever.js +0 -93
- package/bundled/test-gen/agent/codegen/test-update-feedback.d.ts +0 -12
- package/bundled/test-gen/agent/codegen/test-update-feedback.d.ts.map +0 -1
- package/bundled/test-gen/agent/codegen/test-update-feedback.js +0 -50
- package/bundled/test-gen/agent/codegen/types.d.ts +0 -25
- package/bundled/test-gen/agent/codegen/types.d.ts.map +0 -1
- package/bundled/test-gen/agent/codegen/types.js +0 -8
- package/bundled/test-gen/agent/codegen/update-flow.d.ts +0 -34
- package/bundled/test-gen/agent/codegen/update-flow.d.ts.map +0 -1
- package/bundled/test-gen/agent/codegen/update-flow.js +0 -300
- package/bundled/test-gen/agent/codegen/use-skill.d.ts +0 -11
- package/bundled/test-gen/agent/codegen/use-skill.d.ts.map +0 -1
- package/bundled/test-gen/agent/codegen/use-skill.js +0 -54
- package/bundled/test-gen/agent/codegen/utils.d.ts +0 -126
- package/bundled/test-gen/agent/codegen/utils.d.ts.map +0 -1
- package/bundled/test-gen/agent/codegen/utils.js +0 -416
- package/bundled/test-gen/agent/diagnosis-agent/index.d.ts +0 -18
- package/bundled/test-gen/agent/diagnosis-agent/index.d.ts.map +0 -1
- package/bundled/test-gen/agent/diagnosis-agent/index.js +0 -105
- package/bundled/test-gen/agent/diagnosis-agent/strict-mode-violation.d.ts +0 -9
- package/bundled/test-gen/agent/diagnosis-agent/strict-mode-violation.d.ts.map +0 -1
- package/bundled/test-gen/agent/diagnosis-agent/strict-mode-violation.js +0 -31
- package/bundled/test-gen/agent/enrich-prompt/index.d.ts +0 -12
- package/bundled/test-gen/agent/enrich-prompt/index.d.ts.map +0 -1
- package/bundled/test-gen/agent/enrich-prompt/index.js +0 -81
- package/bundled/test-gen/agent/enrich-prompt/utils.d.ts +0 -6
- package/bundled/test-gen/agent/enrich-prompt/utils.d.ts.map +0 -1
- package/bundled/test-gen/agent/enrich-prompt/utils.js +0 -12
- package/bundled/test-gen/agent/infer-agent/index.d.ts +0 -10
- package/bundled/test-gen/agent/infer-agent/index.d.ts.map +0 -1
- package/bundled/test-gen/agent/infer-agent/index.js +0 -70
- package/bundled/test-gen/agent/master/action-tool-calls.d.ts +0 -42
- package/bundled/test-gen/agent/master/action-tool-calls.d.ts.map +0 -1
- package/bundled/test-gen/agent/master/action-tool-calls.js +0 -87
- package/bundled/test-gen/agent/master/browser-tests/fixtures.d.ts +0 -9
- package/bundled/test-gen/agent/master/browser-tests/fixtures.d.ts.map +0 -1
- package/bundled/test-gen/agent/master/browser-tests/fixtures.js +0 -33
- package/bundled/test-gen/agent/master/browser-tests/index.spec.d.ts +0 -2
- package/bundled/test-gen/agent/master/browser-tests/index.spec.d.ts.map +0 -1
- package/bundled/test-gen/agent/master/browser-tests/index.spec.js +0 -113
- package/bundled/test-gen/agent/master/browser-tests/skills.spec.d.ts +0 -2
- package/bundled/test-gen/agent/master/browser-tests/skills.spec.d.ts.map +0 -1
- package/bundled/test-gen/agent/master/browser-tests/skills.spec.js +0 -109
- package/bundled/test-gen/agent/master/element-annotation.d.ts +0 -30
- package/bundled/test-gen/agent/master/element-annotation.d.ts.map +0 -1
- package/bundled/test-gen/agent/master/element-annotation.js +0 -195
- package/bundled/test-gen/agent/master/execute-browser-action.d.ts +0 -24
- package/bundled/test-gen/agent/master/execute-browser-action.d.ts.map +0 -1
- package/bundled/test-gen/agent/master/execute-browser-action.js +0 -124
- package/bundled/test-gen/agent/master/execute-skill-action.d.ts +0 -11
- package/bundled/test-gen/agent/master/execute-skill-action.d.ts.map +0 -1
- package/bundled/test-gen/agent/master/execute-skill-action.js +0 -25
- package/bundled/test-gen/agent/master/icon-descriptor/index.d.ts +0 -22
- package/bundled/test-gen/agent/master/icon-descriptor/index.d.ts.map +0 -1
- package/bundled/test-gen/agent/master/icon-descriptor/index.js +0 -250
- package/bundled/test-gen/agent/master/icon-descriptor/normalize-svg.d.ts +0 -2
- package/bundled/test-gen/agent/master/icon-descriptor/normalize-svg.d.ts.map +0 -1
- package/bundled/test-gen/agent/master/icon-descriptor/normalize-svg.js +0 -248
- package/bundled/test-gen/agent/master/next-action.d.ts +0 -22
- package/bundled/test-gen/agent/master/next-action.d.ts.map +0 -1
- package/bundled/test-gen/agent/master/next-action.js +0 -104
- package/bundled/test-gen/agent/master/planner.d.ts +0 -15
- package/bundled/test-gen/agent/master/planner.d.ts.map +0 -1
- package/bundled/test-gen/agent/master/planner.js +0 -144
- package/bundled/test-gen/agent/master/run.d.ts +0 -15
- package/bundled/test-gen/agent/master/run.d.ts.map +0 -1
- package/bundled/test-gen/agent/master/run.js +0 -274
- package/bundled/test-gen/agent/master/scroller.d.ts +0 -15
- package/bundled/test-gen/agent/master/scroller.d.ts.map +0 -1
- package/bundled/test-gen/agent/master/scroller.js +0 -375
- package/bundled/test-gen/agent/master/with-hints.d.ts +0 -17
- package/bundled/test-gen/agent/master/with-hints.d.ts.map +0 -1
- package/bundled/test-gen/agent/master/with-hints.js +0 -102
- package/bundled/test-gen/agent/planner/run-time-planner.d.ts +0 -15
- package/bundled/test-gen/agent/planner/run-time-planner.d.ts.map +0 -1
- package/bundled/test-gen/agent/planner/run-time-planner.js +0 -100
- package/bundled/test-gen/agent/planner/run.d.ts +0 -7
- package/bundled/test-gen/agent/planner/run.d.ts.map +0 -1
- package/bundled/test-gen/agent/planner/run.js +0 -127
- package/bundled/test-gen/agent/utils.d.ts +0 -2
- package/bundled/test-gen/agent/utils.d.ts.map +0 -1
- package/bundled/test-gen/agent/utils.js +0 -12
- package/bundled/test-gen/bin/index.d.ts +0 -3
- package/bundled/test-gen/bin/index.d.ts.map +0 -1
- package/bundled/test-gen/bin/index.js +0 -212
- package/bundled/test-gen/bin/logger/index.d.ts +0 -14
- package/bundled/test-gen/bin/logger/index.d.ts.map +0 -1
- package/bundled/test-gen/bin/logger/index.js +0 -57
- package/bundled/test-gen/bin/utils/context.d.ts +0 -13
- package/bundled/test-gen/bin/utils/context.d.ts.map +0 -1
- package/bundled/test-gen/bin/utils/context.js +0 -67
- package/bundled/test-gen/bin/utils/fs/index.d.ts +0 -6
- package/bundled/test-gen/bin/utils/fs/index.d.ts.map +0 -1
- package/bundled/test-gen/bin/utils/fs/index.js +0 -63
- package/bundled/test-gen/bin/utils/index.d.ts +0 -9
- package/bundled/test-gen/bin/utils/index.d.ts.map +0 -1
- package/bundled/test-gen/bin/utils/index.js +0 -64
- package/bundled/test-gen/bin/utils/platform/web/index.d.ts +0 -78
- package/bundled/test-gen/bin/utils/platform/web/index.d.ts.map +0 -1
- package/bundled/test-gen/bin/utils/platform/web/index.js +0 -544
- package/bundled/test-gen/bin/utils/platform/web/test-files/ts-path-import-validate.d.ts +0 -2
- package/bundled/test-gen/bin/utils/platform/web/test-files/ts-path-import-validate.d.ts.map +0 -1
- package/bundled/test-gen/bin/utils/platform/web/test-files/ts-path-import-validate.js +0 -7
- package/bundled/test-gen/bin/utils/scenarios/index.d.ts +0 -6
- package/bundled/test-gen/bin/utils/scenarios/index.d.ts.map +0 -1
- package/bundled/test-gen/bin/utils/scenarios/index.js +0 -57
- package/bundled/test-gen/browser-injected-scripts/annotate-elements.js +0 -615
- package/bundled/test-gen/browser-injected-scripts/annotate-elements.spec.d.ts +0 -2
- package/bundled/test-gen/browser-injected-scripts/annotate-elements.spec.d.ts.map +0 -1
- package/bundled/test-gen/browser-injected-scripts/annotate-elements.spec.js +0 -207
- package/bundled/test-gen/browser-injected-scripts/annotate-elements.spec.ts +0 -332
- package/bundled/test-gen/constants/index.d.ts +0 -7
- package/bundled/test-gen/constants/index.d.ts.map +0 -1
- package/bundled/test-gen/constants/index.js +0 -18
- package/bundled/test-gen/errors/index.d.ts +0 -5
- package/bundled/test-gen/errors/index.d.ts.map +0 -1
- package/bundled/test-gen/errors/index.js +0 -9
- package/bundled/test-gen/evals/add-scenario-agent.evals.d.ts +0 -4
- package/bundled/test-gen/evals/add-scenario-agent.evals.d.ts.map +0 -1
- package/bundled/test-gen/evals/add-scenario-agent.evals.js +0 -44
- package/bundled/test-gen/evals/append-create-test-agent.evals.d.ts +0 -4
- package/bundled/test-gen/evals/append-create-test-agent.evals.d.ts.map +0 -1
- package/bundled/test-gen/evals/append-create-test-agent.evals.js +0 -117
- package/bundled/test-gen/evals/fetch-pom-skills-agent.evals.d.ts +0 -4
- package/bundled/test-gen/evals/fetch-pom-skills-agent.evals.d.ts.map +0 -1
- package/bundled/test-gen/evals/fetch-pom-skills-agent.evals.js +0 -36
- package/bundled/test-gen/evals/infer-master-or-code-agent.evals.d.ts +0 -4
- package/bundled/test-gen/evals/infer-master-or-code-agent.evals.d.ts.map +0 -1
- package/bundled/test-gen/evals/infer-master-or-code-agent.evals.js +0 -22
- package/bundled/test-gen/evals/master-agent.evals.d.ts +0 -4
- package/bundled/test-gen/evals/master-agent.evals.d.ts.map +0 -1
- package/bundled/test-gen/evals/master-agent.evals.js +0 -35
- package/bundled/test-gen/evals/type.d.ts +0 -12
- package/bundled/test-gen/evals/type.d.ts.map +0 -1
- package/bundled/test-gen/evals/type.js +0 -2
- package/bundled/test-gen/evals/update-scenario-agent.evals.d.ts +0 -4
- package/bundled/test-gen/evals/update-scenario-agent.evals.d.ts.map +0 -1
- package/bundled/test-gen/evals/update-scenario-agent.evals.js +0 -47
- package/bundled/test-gen/file/client.d.ts +0 -14
- package/bundled/test-gen/file/client.d.ts.map +0 -1
- package/bundled/test-gen/file/client.js +0 -48
- package/bundled/test-gen/file/server.d.ts +0 -13
- package/bundled/test-gen/file/server.d.ts.map +0 -1
- package/bundled/test-gen/file/server.js +0 -52
- package/bundled/test-gen/human-in-the-loop/cli.d.ts +0 -2
- package/bundled/test-gen/human-in-the-loop/cli.d.ts.map +0 -1
- package/bundled/test-gen/human-in-the-loop/cli.js +0 -24
- package/bundled/test-gen/human-in-the-loop/index.d.ts +0 -12
- package/bundled/test-gen/human-in-the-loop/index.d.ts.map +0 -1
- package/bundled/test-gen/human-in-the-loop/index.js +0 -30
- package/bundled/test-gen/human-in-the-loop/ipc.d.ts +0 -4
- package/bundled/test-gen/human-in-the-loop/ipc.d.ts.map +0 -1
- package/bundled/test-gen/human-in-the-loop/ipc.js +0 -47
- package/bundled/test-gen/index.d.ts +0 -4
- package/bundled/test-gen/index.d.ts.map +0 -1
- package/bundled/test-gen/index.js +0 -55
- package/bundled/test-gen/package.json +0 -106
- package/bundled/test-gen/page/index.d.ts +0 -11
- package/bundled/test-gen/page/index.d.ts.map +0 -1
- package/bundled/test-gen/page/index.js +0 -16
- package/bundled/test-gen/prompts/lib/ts-transformer.d.ts +0 -4
- package/bundled/test-gen/prompts/lib/ts-transformer.d.ts.map +0 -1
- package/bundled/test-gen/prompts/lib/ts-transformer.js +0 -92
- package/bundled/test-gen/reporter/index.d.ts +0 -33
- package/bundled/test-gen/reporter/index.d.ts.map +0 -1
- package/bundled/test-gen/reporter/index.js +0 -161
- package/bundled/test-gen/session/index.d.ts +0 -20
- package/bundled/test-gen/session/index.d.ts.map +0 -1
- package/bundled/test-gen/session/index.js +0 -105
- package/bundled/test-gen/test-build/index.d.ts +0 -10
- package/bundled/test-gen/test-build/index.d.ts.map +0 -1
- package/bundled/test-gen/test-build/index.js +0 -30
- package/bundled/test-gen/types/index.d.ts +0 -69
- package/bundled/test-gen/types/index.d.ts.map +0 -1
- package/bundled/test-gen/types/index.js +0 -2
- package/bundled/test-gen/uploader/index.d.ts +0 -26
- package/bundled/test-gen/uploader/index.d.ts.map +0 -1
- package/bundled/test-gen/uploader/index.js +0 -102
- package/bundled/test-gen/utils/env.d.ts +0 -2
- package/bundled/test-gen/utils/env.d.ts.map +0 -1
- package/bundled/test-gen/utils/env.js +0 -9
- package/bundled/test-gen/utils/exec.d.ts +0 -4
- package/bundled/test-gen/utils/exec.d.ts.map +0 -1
- package/bundled/test-gen/utils/exec.js +0 -45
- package/bundled/test-gen/utils/file.d.ts +0 -2
- package/bundled/test-gen/utils/file.d.ts.map +0 -1
- package/bundled/test-gen/utils/file.js +0 -25
- package/bundled/test-gen/utils/html.d.ts +0 -4
- package/bundled/test-gen/utils/html.d.ts.map +0 -1
- package/bundled/test-gen/utils/html.js +0 -46
- package/bundled/test-gen/utils/index.d.ts +0 -2
- package/bundled/test-gen/utils/index.d.ts.map +0 -1
- package/bundled/test-gen/utils/index.js +0 -5
- package/bundled/test-gen/utils/pw-test.d.ts +0 -3
- package/bundled/test-gen/utils/pw-test.d.ts.map +0 -1
- package/bundled/test-gen/utils/pw-test.js +0 -26
- package/bundled/test-gen/utils/slug.d.ts +0 -2
- package/bundled/test-gen/utils/slug.d.ts.map +0 -1
- package/bundled/test-gen/utils/slug.js +0 -18
- package/bundled/test-gen/utils/string.d.ts +0 -2
- package/bundled/test-gen/utils/string.d.ts.map +0 -1
- package/bundled/test-gen/utils/string.js +0 -9
- package/scripts/prepare-publish.js +0 -42
|
@@ -1,274 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createTestUsingMasterAgent = void 0;
|
|
4
|
-
const llm_1 = require("@empiricalrun/llm");
|
|
5
|
-
const actions_1 = require("../../actions");
|
|
6
|
-
const skill_1 = require("../../actions/skill");
|
|
7
|
-
const utils_1 = require("../../actions/utils");
|
|
8
|
-
const logger_1 = require("../../bin/logger");
|
|
9
|
-
const constants_1 = require("../../constants");
|
|
10
|
-
const errors_1 = require("../../errors");
|
|
11
|
-
const page_1 = require("../../page");
|
|
12
|
-
const reporter_1 = require("../../reporter");
|
|
13
|
-
const session_1 = require("../../session");
|
|
14
|
-
const utils_2 = require("../browsing/utils");
|
|
15
|
-
const skills_retriever_1 = require("../codegen/skills-retriever");
|
|
16
|
-
const run_1 = require("../planner/run");
|
|
17
|
-
const run_time_planner_1 = require("../planner/run-time-planner");
|
|
18
|
-
const utils_3 = require("../utils");
|
|
19
|
-
const action_tool_calls_1 = require("./action-tool-calls");
|
|
20
|
-
const execute_browser_action_1 = require("./execute-browser-action");
|
|
21
|
-
const execute_skill_action_1 = require("./execute-skill-action");
|
|
22
|
-
const next_action_1 = require("./next-action");
|
|
23
|
-
const MAX_ERROR_COUNT = 2;
|
|
24
|
-
function getPageVariables(stateVariables) {
|
|
25
|
-
const keys = Object.keys(stateVariables);
|
|
26
|
-
// This checks for whether page.url() exists, which is true for all pages
|
|
27
|
-
// created by playwright actions.
|
|
28
|
-
const pageVariables = keys.filter((key) => typeof stateVariables[key] === "object" &&
|
|
29
|
-
typeof stateVariables[key]?.url === "function");
|
|
30
|
-
const pages = pageVariables.reduce((acc, key) => {
|
|
31
|
-
acc[key] = stateVariables[key];
|
|
32
|
-
return acc;
|
|
33
|
-
}, {});
|
|
34
|
-
return pages;
|
|
35
|
-
}
|
|
36
|
-
async function createTestUsingMasterAgent({ task, page, testCase, specPath, options, scopeVars, }) {
|
|
37
|
-
const useActionSpecificAnnotations = options?.useActionSpecificAnnotations || false;
|
|
38
|
-
const usePlannerInMaster = options?.usePlannerInMaster || false;
|
|
39
|
-
const logger = new logger_1.CustomLogger({ useReporter: false });
|
|
40
|
-
const testgenUpdatesReporter = new reporter_1.TestGenUpdatesReporter();
|
|
41
|
-
const session = (0, session_1.getSessionDetails)();
|
|
42
|
-
const testGenPage = new page_1.TestGenPage(page, (0, utils_1.getPageVarName)());
|
|
43
|
-
const trace = llm_1.langfuseInstance?.trace({
|
|
44
|
-
name: "test-generator",
|
|
45
|
-
id: crypto.randomUUID(),
|
|
46
|
-
version: session.version,
|
|
47
|
-
metadata: {
|
|
48
|
-
generationId: session.generationId,
|
|
49
|
-
sessionId: session.sessionId,
|
|
50
|
-
testUrl: session.testUrl,
|
|
51
|
-
},
|
|
52
|
-
tags: [
|
|
53
|
-
options.metadata?.projectName,
|
|
54
|
-
options.metadata?.environment,
|
|
55
|
-
].filter((s) => !!s),
|
|
56
|
-
});
|
|
57
|
-
if (trace) {
|
|
58
|
-
void testgenUpdatesReporter.sendMessage(`Starting master agent. [view trace](${trace?.getTraceUrl()})`);
|
|
59
|
-
logger.log(`Starting master agent: ${trace?.getTraceUrl()}`);
|
|
60
|
-
void testgenUpdatesReporter.sendAgentTraceUrl(trace.getTraceUrl());
|
|
61
|
-
}
|
|
62
|
-
const llm = new llm_1.LLM({
|
|
63
|
-
trace,
|
|
64
|
-
provider: options.modelProvider || constants_1.DEFAULT_MODEL_PROVIDER,
|
|
65
|
-
defaultModel: options.model || constants_1.DEFAULT_MODEL,
|
|
66
|
-
providerApiKey: constants_1.MODEL_API_KEYS[options.modelProvider || constants_1.DEFAULT_MODEL_PROVIDER],
|
|
67
|
-
// we will be using google model for larger context window, in such cases 1 million tokens is not enough
|
|
68
|
-
maxTokens: options.modelProvider === "google" ? 3000000 : 1000000,
|
|
69
|
-
});
|
|
70
|
-
let skills = [];
|
|
71
|
-
if (testCase) {
|
|
72
|
-
skills = await (0, skills_retriever_1.getAppropriateSkills)({
|
|
73
|
-
testCase,
|
|
74
|
-
trace,
|
|
75
|
-
//@ts-ignore
|
|
76
|
-
options,
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
skill_1.testCaseSkills.updateSkills(skills);
|
|
80
|
-
if (usePlannerInMaster && testCase && specPath) {
|
|
81
|
-
void testgenUpdatesReporter.sendMessage(`Planner is working on task: ${task}`);
|
|
82
|
-
logger.log(`Planner is working on task: ${task}`);
|
|
83
|
-
const plan = await (0, run_1.planTask)({
|
|
84
|
-
task,
|
|
85
|
-
specPath,
|
|
86
|
-
trace,
|
|
87
|
-
});
|
|
88
|
-
void testgenUpdatesReporter.sendMessage(`Here is the plan:\n${plan}`);
|
|
89
|
-
logger.log(`Here is the plan:\n${plan}`);
|
|
90
|
-
// Will assume this is the task hereon
|
|
91
|
-
task = plan;
|
|
92
|
-
}
|
|
93
|
-
const actions = new actions_1.PlaywrightActions(testGenPage, scopeVars);
|
|
94
|
-
await (0, utils_2.injectPwLocatorGenerator)(page);
|
|
95
|
-
trace?.update({ input: { task } });
|
|
96
|
-
let isGivenTaskDone = false;
|
|
97
|
-
const masterAgentActions = [];
|
|
98
|
-
let failedActions = [];
|
|
99
|
-
let disableSkills = false;
|
|
100
|
-
// Run the loop until task is done or we have reached max retry limit
|
|
101
|
-
while (!isGivenTaskDone) {
|
|
102
|
-
if (await (0, session_1.shouldStopSession)()) {
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
const masterAgentSpan = trace?.span({
|
|
106
|
-
name: "master-agent",
|
|
107
|
-
input: {
|
|
108
|
-
task,
|
|
109
|
-
executedActions: masterAgentActions,
|
|
110
|
-
failedActions,
|
|
111
|
-
},
|
|
112
|
-
});
|
|
113
|
-
const plannerResp = await (0, run_time_planner_1.runtimePlanner)({
|
|
114
|
-
trace: masterAgentSpan,
|
|
115
|
-
task,
|
|
116
|
-
successfulActions: [...masterAgentActions],
|
|
117
|
-
pages: getPageVariables(actions.getStateVariables()),
|
|
118
|
-
currentPage: testGenPage,
|
|
119
|
-
});
|
|
120
|
-
isGivenTaskDone = plannerResp.isDone;
|
|
121
|
-
if (isGivenTaskDone) {
|
|
122
|
-
await testgenUpdatesReporter.sendMessage(`${plannerResp.reason} Marking the task as done.`);
|
|
123
|
-
break;
|
|
124
|
-
}
|
|
125
|
-
if (actions.getStateVariables()[plannerResp.pageName]) {
|
|
126
|
-
// update page for the master agent
|
|
127
|
-
page = actions.getStateVariables()[plannerResp.pageName];
|
|
128
|
-
// update page in actions
|
|
129
|
-
testGenPage.updatePage({ page, name: plannerResp.pageName });
|
|
130
|
-
}
|
|
131
|
-
// inject scripts in the page
|
|
132
|
-
await (0, utils_2.injectPwLocatorGenerator)(testGenPage.pwPageInstance);
|
|
133
|
-
const buffer = await page.screenshot();
|
|
134
|
-
const testGenReporter = new reporter_1.TestGenUpdatesReporter();
|
|
135
|
-
await testGenReporter.sendCurrentView(buffer);
|
|
136
|
-
const pageScreenshot = buffer.toString("base64");
|
|
137
|
-
let output;
|
|
138
|
-
let generatedCodeSteps = [];
|
|
139
|
-
if (await (0, session_1.shouldStopSession)()) {
|
|
140
|
-
break;
|
|
141
|
-
}
|
|
142
|
-
// Provides next action that needs to be taken
|
|
143
|
-
const nextAction = await (0, next_action_1.getNextAction)({
|
|
144
|
-
page,
|
|
145
|
-
pageScreenshot: [pageScreenshot],
|
|
146
|
-
task,
|
|
147
|
-
executedActions: masterAgentActions,
|
|
148
|
-
failedActions,
|
|
149
|
-
trace: masterAgentSpan,
|
|
150
|
-
llm,
|
|
151
|
-
options,
|
|
152
|
-
actions,
|
|
153
|
-
disableSkills,
|
|
154
|
-
logger,
|
|
155
|
-
});
|
|
156
|
-
if (await (0, session_1.shouldStopSession)()) {
|
|
157
|
-
break;
|
|
158
|
-
}
|
|
159
|
-
if (nextAction) {
|
|
160
|
-
if (nextAction.actionType === action_tool_calls_1.ActionType.UNKNOWN) {
|
|
161
|
-
logger.error("Agent is not able to figure out next action since element is not visible on screen.");
|
|
162
|
-
await testgenUpdatesReporter.sendMessage("Agent is not able to figure out next action since element is not visible on screen.");
|
|
163
|
-
break;
|
|
164
|
-
}
|
|
165
|
-
const args = (0, utils_3.parseJson)(nextAction.toolCallArgs);
|
|
166
|
-
const masterAgentActionSpan = masterAgentSpan?.span({
|
|
167
|
-
name: "master-agent-execute-action",
|
|
168
|
-
});
|
|
169
|
-
output = {
|
|
170
|
-
action: args.action || args.skill,
|
|
171
|
-
reason: args.reason,
|
|
172
|
-
};
|
|
173
|
-
try {
|
|
174
|
-
void testGenReporter.sendMessage(output.reason);
|
|
175
|
-
logger.log(`Next Action: ${output.action}`);
|
|
176
|
-
switch (nextAction.actionType) {
|
|
177
|
-
case skill_1.SKILL_USAGE: {
|
|
178
|
-
const code = await (0, execute_skill_action_1.executeSkillAction)({
|
|
179
|
-
actions,
|
|
180
|
-
nextAction,
|
|
181
|
-
trace: masterAgentActionSpan,
|
|
182
|
-
});
|
|
183
|
-
if (code) {
|
|
184
|
-
generatedCodeSteps.push(code);
|
|
185
|
-
}
|
|
186
|
-
break;
|
|
187
|
-
}
|
|
188
|
-
case action_tool_calls_1.ActionType.OBSERVATION: {
|
|
189
|
-
output.action = args.observation;
|
|
190
|
-
logger.log("Observation: ", output.action);
|
|
191
|
-
break;
|
|
192
|
-
}
|
|
193
|
-
default: {
|
|
194
|
-
const result = await (0, execute_browser_action_1.executeBrowserAction)({
|
|
195
|
-
page,
|
|
196
|
-
nextAction,
|
|
197
|
-
flags: {
|
|
198
|
-
useActionSpecificAnnotations,
|
|
199
|
-
},
|
|
200
|
-
actions,
|
|
201
|
-
llm,
|
|
202
|
-
trace: masterAgentActionSpan,
|
|
203
|
-
});
|
|
204
|
-
const { generatedCodeSteps: codeFromExecuteAction, output: outputFromExecuteAction, } = result;
|
|
205
|
-
generatedCodeSteps.push(...codeFromExecuteAction);
|
|
206
|
-
output = outputFromExecuteAction;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
// resetting error count as there is a successful action
|
|
210
|
-
failedActions = [];
|
|
211
|
-
masterAgentActions.push(output.action);
|
|
212
|
-
masterAgentActionSpan?.end({
|
|
213
|
-
input: {
|
|
214
|
-
action: output.action,
|
|
215
|
-
reason: output.reason,
|
|
216
|
-
type: nextAction.actionType,
|
|
217
|
-
},
|
|
218
|
-
output: {
|
|
219
|
-
success: true,
|
|
220
|
-
},
|
|
221
|
-
});
|
|
222
|
-
// enable skills after success
|
|
223
|
-
disableSkills = false;
|
|
224
|
-
}
|
|
225
|
-
catch (e) {
|
|
226
|
-
if (nextAction.actionType === skill_1.SKILL_USAGE) {
|
|
227
|
-
logger.log("Disabling skill usage for next retry");
|
|
228
|
-
disableSkills = true;
|
|
229
|
-
}
|
|
230
|
-
masterAgentActionSpan?.end({
|
|
231
|
-
input: {
|
|
232
|
-
action: output.action,
|
|
233
|
-
reason: output.reason,
|
|
234
|
-
type: nextAction.actionType,
|
|
235
|
-
},
|
|
236
|
-
output: {
|
|
237
|
-
error: true,
|
|
238
|
-
errorSummary: e.message,
|
|
239
|
-
},
|
|
240
|
-
});
|
|
241
|
-
if (!(e instanceof errors_1.HumanApprovalDenied)) {
|
|
242
|
-
logger.error("Failed to run master agent's next task", JSON.stringify(nextAction, null, 2), e);
|
|
243
|
-
failedActions.push(output.action);
|
|
244
|
-
if (failedActions.length >= MAX_ERROR_COUNT) {
|
|
245
|
-
const error = "Agent is not able to figure out next action, marking task as done";
|
|
246
|
-
logger.error(error);
|
|
247
|
-
await testgenUpdatesReporter.sendMessage(error);
|
|
248
|
-
break;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
trace?.update({ input: { task }, output: { output } });
|
|
254
|
-
masterAgentSpan?.end({
|
|
255
|
-
output: {
|
|
256
|
-
action: output?.action,
|
|
257
|
-
reason: output?.reason,
|
|
258
|
-
code: generatedCodeSteps,
|
|
259
|
-
},
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
const { code, importPaths } = actions.generateCode();
|
|
263
|
-
trace?.update({ input: { task }, output: { code } });
|
|
264
|
-
await new reporter_1.TestGenUpdatesReporter().sendCurrentView(await page.screenshot());
|
|
265
|
-
logger.success("Successfully generated code for the given task");
|
|
266
|
-
if (trace) {
|
|
267
|
-
await testgenUpdatesReporter.sendMessage(`Successfully generated code for the given task. \n View [trace](${trace.getTraceUrl()})`);
|
|
268
|
-
}
|
|
269
|
-
return {
|
|
270
|
-
code,
|
|
271
|
-
importPaths,
|
|
272
|
-
};
|
|
273
|
-
}
|
|
274
|
-
exports.createTestUsingMasterAgent = createTestUsingMasterAgent;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { TraceClient } from "@empiricalrun/llm";
|
|
2
|
-
import type { Page } from "@playwright/test";
|
|
3
|
-
import { CustomLogger } from "../../bin/logger";
|
|
4
|
-
export type FrameReference = {
|
|
5
|
-
scrollPosition: number;
|
|
6
|
-
frameScreenshot: string;
|
|
7
|
-
};
|
|
8
|
-
export declare function scroller({ elementDescription, page, trace, frameReference, logger, }: {
|
|
9
|
-
elementDescription: string;
|
|
10
|
-
page: Page;
|
|
11
|
-
trace?: TraceClient;
|
|
12
|
-
frameReference?: FrameReference;
|
|
13
|
-
logger?: CustomLogger;
|
|
14
|
-
}): Promise<FrameReference[]>;
|
|
15
|
-
//# sourceMappingURL=scroller.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"scroller.d.ts","sourceRoot":"","sources":["../../../src/agent/master/scroller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAG7C,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAchD,MAAM,MAAM,cAAc,GAAG;IAC3B,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AA2ZF,wBAAsB,QAAQ,CAAC,EAC7B,kBAAkB,EAClB,IAAI,EACJ,KAAK,EACL,cAAc,EACd,MAAM,GACP,EAAE;IACD,kBAAkB,EAAE,MAAM,CAAC;IAC3B,IAAI,EAAE,IAAI,CAAC;IACX,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CA6D5B"}
|
|
@@ -1,375 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.scroller = void 0;
|
|
4
|
-
const llm_1 = require("@empiricalrun/llm");
|
|
5
|
-
const vision_1 = require("@empiricalrun/llm/vision");
|
|
6
|
-
const constants_1 = require("../../constants");
|
|
7
|
-
const reporter_1 = require("../../reporter");
|
|
8
|
-
const utils_1 = require("../utils");
|
|
9
|
-
const action_tool_calls_1 = require("./action-tool-calls");
|
|
10
|
-
const element_annotation_1 = require("./element-annotation");
|
|
11
|
-
let usedAnnotations = [];
|
|
12
|
-
// This checks whether scroll is possible or not
|
|
13
|
-
// If the div annotation is undefined, we check the scrollability of the page
|
|
14
|
-
// else we check for the element
|
|
15
|
-
async function isScrollable({ scrollDirection, page, divAnnotation, }) {
|
|
16
|
-
if (divAnnotation) {
|
|
17
|
-
return await page.evaluate(({ scrollDirection, divAnnotation }) => {
|
|
18
|
-
if (
|
|
19
|
-
// @ts-ignore
|
|
20
|
-
window?.annotationInstance?.annotations?.[divAnnotation]) {
|
|
21
|
-
let element = // @ts-ignore
|
|
22
|
-
window?.annotationInstance?.annotations?.[divAnnotation]?.node;
|
|
23
|
-
if (scrollDirection === "up") {
|
|
24
|
-
return element.scrollTop > 0;
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
return (element.scrollHeight > element.clientHeight + element.scrollTop);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return false;
|
|
31
|
-
}, { scrollDirection, divAnnotation });
|
|
32
|
-
}
|
|
33
|
-
return await page.evaluate(({ scrollDirection }) => {
|
|
34
|
-
if (scrollDirection === "up") {
|
|
35
|
-
return window.scrollY > 0;
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
return (document.documentElement.scrollHeight >
|
|
39
|
-
window.innerHeight + window.scrollY);
|
|
40
|
-
}
|
|
41
|
-
}, { scrollDirection });
|
|
42
|
-
}
|
|
43
|
-
// Performs scroll on page or the element
|
|
44
|
-
// If the div annotation is undefined, we scroll the page
|
|
45
|
-
// else we scroll the element
|
|
46
|
-
async function scroll({ scrollBy, page, direction, divAnnotation, logger, }) {
|
|
47
|
-
const testGenUpdatesReporter = new reporter_1.TestGenUpdatesReporter();
|
|
48
|
-
if (divAnnotation) {
|
|
49
|
-
await testGenUpdatesReporter.sendMessage("Scrolling the div since element is not in view");
|
|
50
|
-
logger?.log("Scrolling the div since element is not in view");
|
|
51
|
-
return await page.evaluate(({ scrollBy, direction, divAnnotation }) => {
|
|
52
|
-
if (
|
|
53
|
-
// @ts-ignore
|
|
54
|
-
window?.annotationInstance?.annotations?.[divAnnotation]) {
|
|
55
|
-
let element = // @ts-ignore
|
|
56
|
-
window?.annotationInstance?.annotations?.[divAnnotation]?.node;
|
|
57
|
-
let scrollHeight = scrollBy || element.clientHeight;
|
|
58
|
-
element.scrollBy(0, scrollHeight * (direction === "up" ? -1 : 1));
|
|
59
|
-
return scrollHeight;
|
|
60
|
-
}
|
|
61
|
-
return 0;
|
|
62
|
-
}, { scrollBy, direction, divAnnotation });
|
|
63
|
-
}
|
|
64
|
-
await testGenUpdatesReporter.sendMessage("Scrolling the page since element is not in view");
|
|
65
|
-
logger?.log("Scrolling the page since element is not in view");
|
|
66
|
-
return await page.evaluate(({ scrollBy, direction }) => {
|
|
67
|
-
let scrollHeight = scrollBy || window.innerHeight;
|
|
68
|
-
window.scrollBy(0, scrollHeight * (direction === "up" ? -1 : 1));
|
|
69
|
-
return scrollHeight;
|
|
70
|
-
}, { scrollBy, direction });
|
|
71
|
-
}
|
|
72
|
-
// Scrolls the page to top
|
|
73
|
-
async function scrollToTop(page) {
|
|
74
|
-
await page.evaluate(() => {
|
|
75
|
-
window.scrollTo({ top: 0 });
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
// Checks if the element is visible in the current frame
|
|
79
|
-
async function isElementVisibleInFrame({ elementDescription, page, trace, logger, }) {
|
|
80
|
-
const buffer = await page.screenshot();
|
|
81
|
-
const frameScreenshot = buffer.toString("base64");
|
|
82
|
-
const systemMessage = {
|
|
83
|
-
role: "system",
|
|
84
|
-
content: `
|
|
85
|
-
You are a web automation tool having extraordinary capabilities of going through the webpage screenshots. You are given a task to identify whether the element with given element description is present on the screen.
|
|
86
|
-
You need to make a decision whether the element is visible or not. Only consider an element to be visible if it's completely visible, otherwise respond false.`,
|
|
87
|
-
};
|
|
88
|
-
const userMessage = {
|
|
89
|
-
role: "user",
|
|
90
|
-
content: [
|
|
91
|
-
{
|
|
92
|
-
type: "text",
|
|
93
|
-
text: `
|
|
94
|
-
Element description:
|
|
95
|
-
${elementDescription}
|
|
96
|
-
|
|
97
|
-
----
|
|
98
|
-
|
|
99
|
-
Follow the instructions before responding:
|
|
100
|
-
- Scan through the content in the screenshot
|
|
101
|
-
- While scanning check whether there is any element for which the given element description matches.
|
|
102
|
-
- If it matches set is_visible as true
|
|
103
|
-
- else set is_visible as false
|
|
104
|
-
`,
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
type: "text",
|
|
108
|
-
text: "Screenshot",
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
type: "image_url",
|
|
112
|
-
image_url: {
|
|
113
|
-
url: (0, vision_1.imageFormatForProvider)(constants_1.DEFAULT_MODEL_PROVIDER, frameScreenshot),
|
|
114
|
-
},
|
|
115
|
-
},
|
|
116
|
-
],
|
|
117
|
-
};
|
|
118
|
-
const tool = {
|
|
119
|
-
type: "function",
|
|
120
|
-
function: {
|
|
121
|
-
name: "is-element-visible",
|
|
122
|
-
description: "Is the element with given element description present in the screenshot",
|
|
123
|
-
parameters: {
|
|
124
|
-
type: "object",
|
|
125
|
-
properties: {
|
|
126
|
-
reason: {
|
|
127
|
-
type: "string",
|
|
128
|
-
description: "Explain why the element is marked as visible and its location. The reason should be clear and concise.",
|
|
129
|
-
},
|
|
130
|
-
is_visible: {
|
|
131
|
-
type: "boolean",
|
|
132
|
-
description: "Boolean value for whether the element is completely visible in the screenshot.",
|
|
133
|
-
},
|
|
134
|
-
},
|
|
135
|
-
required: ["reason", "is_visible"],
|
|
136
|
-
},
|
|
137
|
-
},
|
|
138
|
-
};
|
|
139
|
-
const messages = [
|
|
140
|
-
systemMessage,
|
|
141
|
-
userMessage,
|
|
142
|
-
];
|
|
143
|
-
const scrollSpan = trace?.span({
|
|
144
|
-
name: "is-element-visible-after-scroll",
|
|
145
|
-
input: {
|
|
146
|
-
elementDescription,
|
|
147
|
-
messages,
|
|
148
|
-
},
|
|
149
|
-
});
|
|
150
|
-
const llm = new llm_1.LLM({
|
|
151
|
-
provider: constants_1.DEFAULT_MODEL_PROVIDER,
|
|
152
|
-
defaultModel: constants_1.DEFAULT_MODEL,
|
|
153
|
-
});
|
|
154
|
-
const completion = await llm.createChatCompletion({
|
|
155
|
-
messages,
|
|
156
|
-
modelParameters: {
|
|
157
|
-
...constants_1.DEFAULT_MODEL_PARAMETERS,
|
|
158
|
-
tool_choice: "required",
|
|
159
|
-
temperature: 1,
|
|
160
|
-
},
|
|
161
|
-
trace: scrollSpan,
|
|
162
|
-
tools: [tool],
|
|
163
|
-
});
|
|
164
|
-
let isVisible = false;
|
|
165
|
-
const toolCall = completion?.tool_calls?.[0];
|
|
166
|
-
scrollSpan?.end({ output: toolCall });
|
|
167
|
-
if (toolCall) {
|
|
168
|
-
const args = (0, utils_1.parseJson)(toolCall.function.arguments);
|
|
169
|
-
isVisible = args.is_visible || false;
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
172
|
-
logger?.error(`No tool call found in completion. [Trace](${trace?.getTraceUrl()})`);
|
|
173
|
-
}
|
|
174
|
-
return {
|
|
175
|
-
isVisible,
|
|
176
|
-
frameScreenshot,
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
// Returns the element annotation to scroll on
|
|
180
|
-
// if there is no element matching the description we return "NA"
|
|
181
|
-
async function getDivAnnotationToScrollOn({ elementDescription, page, trace, logger, }) {
|
|
182
|
-
const preference = {
|
|
183
|
-
actionType: action_tool_calls_1.ActionType.SCROLL,
|
|
184
|
-
};
|
|
185
|
-
let { annotationKeys, annotatedPageScreenshot } = await (0, element_annotation_1.getAnnotationKeys)({
|
|
186
|
-
page,
|
|
187
|
-
preference: {
|
|
188
|
-
actionType: action_tool_calls_1.ActionType.SCROLL,
|
|
189
|
-
},
|
|
190
|
-
trace,
|
|
191
|
-
});
|
|
192
|
-
// Remove the used annotations from the list
|
|
193
|
-
annotationKeys = annotationKeys.filter((key) => !usedAnnotations.includes(key.elementID));
|
|
194
|
-
if (annotationKeys.length === 0) {
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
const annotationKeysString = annotationKeys
|
|
198
|
-
?.map((a) => `${a.elementID}:${a.text}`)
|
|
199
|
-
.join("\n");
|
|
200
|
-
const annotationsSpan = trace?.span({
|
|
201
|
-
name: "get-div-annotation",
|
|
202
|
-
input: {
|
|
203
|
-
elementDescription,
|
|
204
|
-
annotationKeys,
|
|
205
|
-
annotatedPageScreenshot,
|
|
206
|
-
preference,
|
|
207
|
-
},
|
|
208
|
-
});
|
|
209
|
-
const systemMessage = {
|
|
210
|
-
role: "system",
|
|
211
|
-
content: `
|
|
212
|
-
You are an expert in describing the images and it's content. You will be provided with an annotated screenshot where scrollable divs are annotated.
|
|
213
|
-
|
|
214
|
-
The annotation is done by drawing a red box around the element and a small yellow box on it which contains unique element id.
|
|
215
|
-
|
|
216
|
-
You are given a "Annotations" which contains list of unique element Id and description of the element separated by ":".
|
|
217
|
-
|
|
218
|
-
You are also given the description of the element which can be present inside the annotated element. The description includes information about how the element looks, it's position etc.
|
|
219
|
-
|
|
220
|
-
Your task is to provide the annotation of the div on which the scroll action needs to be performed based on whether the provided element is inside the div. You can use the description of the annotated element as well. E.g. text in the div contains the text as described in the element description.
|
|
221
|
-
|
|
222
|
-
You also need to extract the relevant information like the element text or position from the provided element description, this can be used to match the div content with the element.
|
|
223
|
-
|
|
224
|
-
If there is a match provide the annotation for the div else respond with "NA".
|
|
225
|
-
|
|
226
|
-
Follow steps to fulfil your task:
|
|
227
|
-
- If the provided "Annotations" is empty, respond with "NA"
|
|
228
|
-
- For each element Id, read the description for the div element
|
|
229
|
-
- If the description contains the element description or anything on similar lines
|
|
230
|
-
- Respond with the element Id
|
|
231
|
-
- If none of the description contains the element description respond with "NA"
|
|
232
|
-
- If the specified element Id is not found in the "Annotations" section, the response is invalid.
|
|
233
|
-
`,
|
|
234
|
-
};
|
|
235
|
-
const userMessage = {
|
|
236
|
-
role: "user",
|
|
237
|
-
content: [
|
|
238
|
-
{
|
|
239
|
-
type: "text",
|
|
240
|
-
text: `
|
|
241
|
-
Element description:
|
|
242
|
-
${elementDescription}
|
|
243
|
-
|
|
244
|
-
Annotations:
|
|
245
|
-
${annotationKeysString}`,
|
|
246
|
-
},
|
|
247
|
-
{
|
|
248
|
-
type: "image_url",
|
|
249
|
-
image_url: {
|
|
250
|
-
url: (0, vision_1.imageFormatForProvider)(constants_1.DEFAULT_MODEL_PROVIDER, annotatedPageScreenshot),
|
|
251
|
-
},
|
|
252
|
-
},
|
|
253
|
-
],
|
|
254
|
-
};
|
|
255
|
-
const messages = [
|
|
256
|
-
systemMessage,
|
|
257
|
-
userMessage,
|
|
258
|
-
];
|
|
259
|
-
const annotationToolAction = {
|
|
260
|
-
name: "element_annotation",
|
|
261
|
-
schema: {
|
|
262
|
-
type: "function",
|
|
263
|
-
function: {
|
|
264
|
-
name: "element_annotation",
|
|
265
|
-
description: "Handles annotations for elements",
|
|
266
|
-
parameters: {
|
|
267
|
-
type: "object",
|
|
268
|
-
properties: {
|
|
269
|
-
element: {
|
|
270
|
-
type: "string",
|
|
271
|
-
description: "Relevant information from the provided element description.",
|
|
272
|
-
},
|
|
273
|
-
reason: {
|
|
274
|
-
type: "string",
|
|
275
|
-
description: "Explain why this element is selected. The reason should be clear and align with the task or purpose.",
|
|
276
|
-
},
|
|
277
|
-
element_annotation: {
|
|
278
|
-
type: "string",
|
|
279
|
-
description: "Return the unique element ID for the element on which the action needs to be performed.",
|
|
280
|
-
},
|
|
281
|
-
},
|
|
282
|
-
required: ["element", "reason", "element_annotation"],
|
|
283
|
-
},
|
|
284
|
-
},
|
|
285
|
-
},
|
|
286
|
-
};
|
|
287
|
-
const llm = new llm_1.LLM({
|
|
288
|
-
provider: constants_1.DEFAULT_MODEL_PROVIDER,
|
|
289
|
-
defaultModel: constants_1.DEFAULT_MODEL,
|
|
290
|
-
});
|
|
291
|
-
const completion = await llm.createChatCompletion({
|
|
292
|
-
messages,
|
|
293
|
-
modelParameters: {
|
|
294
|
-
...constants_1.DEFAULT_MODEL_PARAMETERS,
|
|
295
|
-
tool_choice: "required",
|
|
296
|
-
temperature: 1,
|
|
297
|
-
},
|
|
298
|
-
trace: annotationsSpan,
|
|
299
|
-
traceName: "get-element-from-action",
|
|
300
|
-
//@ts-ignore
|
|
301
|
-
tools: [annotationToolAction.schema],
|
|
302
|
-
});
|
|
303
|
-
const toolCall = completion?.tool_calls?.[0];
|
|
304
|
-
annotationsSpan?.end({ output: toolCall });
|
|
305
|
-
if (toolCall) {
|
|
306
|
-
const args = (0, utils_1.parseJson)(toolCall.function.arguments);
|
|
307
|
-
const isAnnotationPresentInKeys = annotationKeys.some((annotation) => annotation.elementID === args.element_annotation);
|
|
308
|
-
if (args.element_annotation !== "NA" && isAnnotationPresentInKeys) {
|
|
309
|
-
usedAnnotations.push(args.element_annotation);
|
|
310
|
-
return args.element_annotation;
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
else {
|
|
314
|
-
logger?.error(`No tool call found in completion. [Trace](${trace?.getTraceUrl()})`);
|
|
315
|
-
}
|
|
316
|
-
return;
|
|
317
|
-
}
|
|
318
|
-
// Scrolls the page and returns the reference to the frame in which the element is visible
|
|
319
|
-
async function scroller({ elementDescription, page, trace, frameReference, logger, }) {
|
|
320
|
-
await scrollToTop(page);
|
|
321
|
-
if (frameReference) {
|
|
322
|
-
await scroll({
|
|
323
|
-
scrollBy: frameReference.scrollPosition,
|
|
324
|
-
page,
|
|
325
|
-
direction: "down",
|
|
326
|
-
});
|
|
327
|
-
return [frameReference];
|
|
328
|
-
}
|
|
329
|
-
let referenceImages = [];
|
|
330
|
-
let scrolledHeight = 0;
|
|
331
|
-
let isScrollAvailable = true;
|
|
332
|
-
const divAnnotation = await getDivAnnotationToScrollOn({
|
|
333
|
-
elementDescription,
|
|
334
|
-
page,
|
|
335
|
-
trace,
|
|
336
|
-
logger,
|
|
337
|
-
});
|
|
338
|
-
while (isScrollAvailable) {
|
|
339
|
-
// Perform action to check for visibility
|
|
340
|
-
const { isVisible, frameScreenshot } = await isElementVisibleInFrame({
|
|
341
|
-
elementDescription,
|
|
342
|
-
page,
|
|
343
|
-
trace,
|
|
344
|
-
logger,
|
|
345
|
-
});
|
|
346
|
-
if (isVisible) {
|
|
347
|
-
usedAnnotations = [];
|
|
348
|
-
referenceImages.push({
|
|
349
|
-
scrollPosition: scrolledHeight,
|
|
350
|
-
frameScreenshot,
|
|
351
|
-
});
|
|
352
|
-
// TODO: remove this to support multiple images
|
|
353
|
-
break;
|
|
354
|
-
}
|
|
355
|
-
isScrollAvailable = await isScrollable({
|
|
356
|
-
scrollDirection: "down",
|
|
357
|
-
page,
|
|
358
|
-
divAnnotation,
|
|
359
|
-
});
|
|
360
|
-
if (isScrollAvailable) {
|
|
361
|
-
scrolledHeight += await scroll({
|
|
362
|
-
page,
|
|
363
|
-
divAnnotation,
|
|
364
|
-
direction: "down",
|
|
365
|
-
logger,
|
|
366
|
-
});
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
if (referenceImages.length === 0) {
|
|
370
|
-
logger?.log("Element not found in the current scroll");
|
|
371
|
-
}
|
|
372
|
-
await (0, llm_1.flushAllTraces)();
|
|
373
|
-
return referenceImages;
|
|
374
|
-
}
|
|
375
|
-
exports.scroller = scroller;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { LLM, TraceClient } from "@empiricalrun/llm";
|
|
2
|
-
import OpenAI from "openai";
|
|
3
|
-
import { PlaywrightActions } from "../../actions";
|
|
4
|
-
export declare const triggerHintsFlow: ({ outputFromGetNextAction, generatedAnnotations, actions, llm, trace, }: {
|
|
5
|
-
outputFromGetNextAction: {
|
|
6
|
-
action: string;
|
|
7
|
-
elementAnnotation?: string;
|
|
8
|
-
};
|
|
9
|
-
generatedAnnotations: Record<string, any>;
|
|
10
|
-
actions: PlaywrightActions;
|
|
11
|
-
llm: LLM;
|
|
12
|
-
trace?: TraceClient | undefined;
|
|
13
|
-
}) => Promise<{
|
|
14
|
-
shouldTriggerHintsFlow: boolean;
|
|
15
|
-
hintsExecutionCompletion: OpenAI.ChatCompletionMessage | undefined;
|
|
16
|
-
}>;
|
|
17
|
-
//# sourceMappingURL=with-hints.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"with-hints.d.ts","sourceRoot":"","sources":["../../../src/agent/master/with-hints.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAOlD,eAAO,MAAM,gBAAgB;6BAOF;QACvB,MAAM,EAAE,MAAM,CAAC;QACf,iBAAiB,CAAC,EAAE,MAAM,CAAC;KAC5B;0BACqB,OAAO,MAAM,EAAE,GAAG,CAAC;aAChC,iBAAiB;SACrB,GAAG;;MAEN,QAAQ;IACV,sBAAsB,EAAE,OAAO,CAAC;IAChC,wBAAwB,EAAE,OAAO,qBAAqB,GAAG,SAAS,CAAC;CACpE,CAyGA,CAAC"}
|