@empiricalrun/test-gen 0.45.0 → 0.46.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 +18 -0
- package/dist/actions/assert.d.ts +2 -2
- package/dist/actions/assert.d.ts.map +1 -1
- package/dist/actions/assert.js +1 -2
- package/dist/actions/click.d.ts +2 -2
- package/dist/actions/click.d.ts.map +1 -1
- package/dist/actions/click.js +1 -2
- package/dist/actions/done.d.ts +2 -2
- package/dist/actions/done.d.ts.map +1 -1
- package/dist/actions/fill.d.ts +2 -2
- package/dist/actions/fill.d.ts.map +1 -1
- package/dist/actions/fill.js +1 -2
- package/dist/actions/goto.d.ts +2 -2
- package/dist/actions/goto.d.ts.map +1 -1
- package/dist/actions/hover.d.ts +2 -2
- package/dist/actions/hover.d.ts.map +1 -1
- package/dist/actions/hover.js +3 -3
- package/dist/actions/index.d.ts +2 -2
- package/dist/actions/index.d.ts.map +1 -1
- package/dist/actions/press.d.ts +2 -2
- package/dist/actions/press.d.ts.map +1 -1
- package/dist/actions/skill.d.ts +2 -2
- package/dist/actions/skill.d.ts.map +1 -1
- package/dist/actions/skill.js +2 -3
- package/dist/actions/text-content.d.ts +3 -3
- package/dist/actions/text-content.d.ts.map +1 -1
- package/dist/actions/text-content.js +12 -13
- package/dist/agent/master/browser-tests/index.spec.js +8 -1
- package/dist/agent/master/element-annotation.d.ts +2 -1
- package/dist/agent/master/element-annotation.d.ts.map +1 -1
- package/dist/agent/master/element-annotation.js +45 -12
- package/dist/agent/master/icon-descriptor/index.d.ts +22 -0
- package/dist/agent/master/icon-descriptor/index.d.ts.map +1 -0
- package/dist/agent/master/icon-descriptor/index.js +211 -0
- package/dist/agent/master/icon-descriptor/normalize-svg.d.ts +2 -0
- package/dist/agent/master/icon-descriptor/normalize-svg.d.ts.map +1 -0
- package/dist/agent/master/icon-descriptor/normalize-svg.js +248 -0
- package/dist/agent/master/run.d.ts.map +1 -1
- package/dist/agent/master/run.js +2 -1
- package/dist/agent/master/scroller.d.ts.map +1 -1
- package/dist/agent/master/scroller.js +1 -0
- package/dist/agent/planner/run-time-planner.d.ts +2 -9
- package/dist/agent/planner/run-time-planner.d.ts.map +1 -1
- package/dist/agent/planner/run-time-planner.js +9 -46
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -26
- package/dist/types/index.d.ts +46 -5
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @empiricalrun/test-gen
|
|
2
2
|
|
|
3
|
+
## 0.46.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- b6dfc91: feat: create icon registry for test repositories
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- b6dfc91: feat: cache icon description generated through LLM
|
|
12
|
+
|
|
13
|
+
## 0.45.1
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- 04db1a6: chore: better types for playwright action generators
|
|
18
|
+
- 1b1815d: chore: move runtime planner to handlebars
|
|
19
|
+
- 62800d7: fix: prevent sending test run events to sentry
|
|
20
|
+
|
|
3
21
|
## 0.45.0
|
|
4
22
|
|
|
5
23
|
### Minor Changes
|
package/dist/actions/assert.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PlaywrightActionGenerator } from "../types";
|
|
1
|
+
import { AssertTextVisibilityActionArgs, PlaywrightActionGenerator } from "../types";
|
|
2
2
|
export declare const PLAYWRIGHT_ASSERT_TEXT_VISIBILITY_ACTION_NAME = "assert_text_visibility";
|
|
3
|
-
export declare const assertTextVisibilityActionGenerator: PlaywrightActionGenerator
|
|
3
|
+
export declare const assertTextVisibilityActionGenerator: PlaywrightActionGenerator<AssertTextVisibilityActionArgs>;
|
|
4
4
|
//# sourceMappingURL=assert.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../src/actions/assert.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../src/actions/assert.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,8BAA8B,EAC9B,yBAAyB,EAC1B,MAAM,UAAU,CAAC;AAIlB,eAAO,MAAM,6CAA6C,2BAChC,CAAC;AAE3B,eAAO,MAAM,mCAAmC,EAAE,yBAAyB,CACzE,8BAA8B,CAqD/B,CAAC"}
|
package/dist/actions/assert.js
CHANGED
|
@@ -14,8 +14,7 @@ const assertTextVisibilityActionGenerator = (page) => {
|
|
|
14
14
|
locator,
|
|
15
15
|
};
|
|
16
16
|
},
|
|
17
|
-
|
|
18
|
-
template: (_, options) => {
|
|
17
|
+
template: (args, options) => {
|
|
19
18
|
return {
|
|
20
19
|
code: `await expect(${page.name}.${options.locator}).toBeVisible();`,
|
|
21
20
|
};
|
package/dist/actions/click.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PlaywrightActionGenerator } from "../types";
|
|
1
|
+
import { ClickActionArgs, PlaywrightActionGenerator } from "../types";
|
|
2
2
|
export declare const PLAYWRIGHT_CLICK_ACTION_NAME = "click_element";
|
|
3
|
-
export declare const clickActionGenerator: PlaywrightActionGenerator
|
|
3
|
+
export declare const clickActionGenerator: PlaywrightActionGenerator<ClickActionArgs>;
|
|
4
4
|
//# sourceMappingURL=click.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"click.d.ts","sourceRoot":"","sources":["../../src/actions/click.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"click.d.ts","sourceRoot":"","sources":["../../src/actions/click.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAItE,eAAO,MAAM,4BAA4B,kBAAkB,CAAC;AAE5D,eAAO,MAAM,oBAAoB,EAAE,yBAAyB,CAC1D,eAAe,CAsDhB,CAAC"}
|
package/dist/actions/click.js
CHANGED
|
@@ -15,8 +15,7 @@ const clickActionGenerator = (page) => {
|
|
|
15
15
|
locator,
|
|
16
16
|
};
|
|
17
17
|
},
|
|
18
|
-
|
|
19
|
-
template: (_, options) => {
|
|
18
|
+
template: (args, options) => {
|
|
20
19
|
return {
|
|
21
20
|
code: `await ${page.name}.${options.locator}.click();`,
|
|
22
21
|
};
|
package/dist/actions/done.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PlaywrightActionGenerator } from "../types";
|
|
1
|
+
import { BaseActionArgs, PlaywrightActionGenerator } from "../types";
|
|
2
2
|
export declare const PLAYWRIGHT_DONE_ACTION_NAME = "task_done";
|
|
3
|
-
export declare const doneActionGenerator: PlaywrightActionGenerator
|
|
3
|
+
export declare const doneActionGenerator: PlaywrightActionGenerator<BaseActionArgs>;
|
|
4
4
|
//# sourceMappingURL=done.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"done.d.ts","sourceRoot":"","sources":["../../src/actions/done.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"done.d.ts","sourceRoot":"","sources":["../../src/actions/done.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAGrE,eAAO,MAAM,2BAA2B,cAAc,CAAC;AAEvD,eAAO,MAAM,mBAAmB,EAAE,yBAAyB,CACzD,cAAc,CAwBf,CAAC"}
|
package/dist/actions/fill.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PlaywrightActionGenerator } from "../types";
|
|
1
|
+
import { FillActionArgs, PlaywrightActionGenerator } from "../types";
|
|
2
2
|
export declare const PLAYWRIGHT_FILL_ACTION_NAME = "fill_input_element";
|
|
3
|
-
export declare const fillActionGenerator: PlaywrightActionGenerator
|
|
3
|
+
export declare const fillActionGenerator: PlaywrightActionGenerator<FillActionArgs>;
|
|
4
4
|
//# sourceMappingURL=fill.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fill.d.ts","sourceRoot":"","sources":["../../src/actions/fill.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"fill.d.ts","sourceRoot":"","sources":["../../src/actions/fill.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAIrE,eAAO,MAAM,2BAA2B,uBAAuB,CAAC;AAGhE,eAAO,MAAM,mBAAmB,EAAE,yBAAyB,CAAC,cAAc,CA+FzE,CAAC"}
|
package/dist/actions/fill.js
CHANGED
|
@@ -25,8 +25,7 @@ const fillActionGenerator = (page, options) => {
|
|
|
25
25
|
testCaseLine,
|
|
26
26
|
};
|
|
27
27
|
},
|
|
28
|
-
|
|
29
|
-
template: (_, options) => {
|
|
28
|
+
template: (args, options) => {
|
|
30
29
|
return {
|
|
31
30
|
code: `await ${page.name}.${options.testCaseLine}`,
|
|
32
31
|
};
|
package/dist/actions/goto.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PlaywrightActionGenerator } from "../types";
|
|
1
|
+
import { GotoActionArgs, PlaywrightActionGenerator } from "../types";
|
|
2
2
|
export declare const PLAYWRIGHT_GOTO_ACTION_NAME = "page_goto";
|
|
3
|
-
export declare const gotoActionGenerator: PlaywrightActionGenerator
|
|
3
|
+
export declare const gotoActionGenerator: PlaywrightActionGenerator<GotoActionArgs>;
|
|
4
4
|
//# sourceMappingURL=goto.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"goto.d.ts","sourceRoot":"","sources":["../../src/actions/goto.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"goto.d.ts","sourceRoot":"","sources":["../../src/actions/goto.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAGrE,eAAO,MAAM,2BAA2B,cAAc,CAAC;AAEvD,eAAO,MAAM,mBAAmB,EAAE,yBAAyB,CAAC,cAAc,CAyCzE,CAAC"}
|
package/dist/actions/hover.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PlaywrightActionGenerator } from "../types";
|
|
1
|
+
import { HoverActionArgs, PlaywrightActionGenerator } from "../types";
|
|
2
2
|
export declare const PLAYWRIGHT_HOVER_ACTION_NAME = "hover_element";
|
|
3
|
-
export declare const hoverActionGenerator: PlaywrightActionGenerator
|
|
3
|
+
export declare const hoverActionGenerator: PlaywrightActionGenerator<HoverActionArgs>;
|
|
4
4
|
//# sourceMappingURL=hover.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hover.d.ts","sourceRoot":"","sources":["../../src/actions/hover.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"hover.d.ts","sourceRoot":"","sources":["../../src/actions/hover.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAItE,eAAO,MAAM,4BAA4B,kBAAkB,CAAC;AAE5D,eAAO,MAAM,oBAAoB,EAAE,yBAAyB,CAC1D,eAAe,CAsDhB,CAAC"}
|
package/dist/actions/hover.js
CHANGED
|
@@ -11,14 +11,14 @@ const hoverActionGenerator = (page) => {
|
|
|
11
11
|
const locator = await (0, utils_1.getPlaywrightLocatorUsingCssSelector)(selector, args.xpath, page.pwPageInstance, args?.elementAnnotation);
|
|
12
12
|
const exec = new Function("page", `return page.${locator}.hover({ timeout: 3000 })`);
|
|
13
13
|
await exec(page.pwPageInstance);
|
|
14
|
-
await page.pwPageInstance.waitForTimeout(3000);
|
|
15
14
|
return {
|
|
16
15
|
locator,
|
|
17
16
|
};
|
|
18
17
|
},
|
|
19
|
-
// TODO: args transformer to be kept at a single place
|
|
20
18
|
template: (args, options) => {
|
|
21
|
-
return {
|
|
19
|
+
return {
|
|
20
|
+
code: `await ${page.name}.${options.locator}.hover();`,
|
|
21
|
+
};
|
|
22
22
|
},
|
|
23
23
|
name: exports.PLAYWRIGHT_HOVER_ACTION_NAME,
|
|
24
24
|
schema: {
|
package/dist/actions/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { TraceClient } from "@empiricalrun/llm";
|
|
2
2
|
import { TestGenPage } from "../page";
|
|
3
|
-
import { ActionSchema } from "../types";
|
|
3
|
+
import { ActionArgs, ActionSchema } from "../types";
|
|
4
4
|
export declare class PlaywrightActions {
|
|
5
5
|
private page;
|
|
6
6
|
private stateVariables;
|
|
7
7
|
private actionGenerators;
|
|
8
8
|
private recordedActions;
|
|
9
9
|
constructor(page: TestGenPage, stateVariables?: Record<string, any>);
|
|
10
|
-
executeAction(name: string | undefined, args:
|
|
10
|
+
executeAction(name: string | undefined, args: ActionArgs, trace?: TraceClient): Promise<string | undefined>;
|
|
11
11
|
getBrowsingActionSchemas(): ActionSchema[];
|
|
12
12
|
getMasterActionSchemas(): ActionSchema[];
|
|
13
13
|
generateCode(): {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/actions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIhD,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/actions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIhD,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,OAAO,EAEL,UAAU,EACV,YAAY,EAEb,MAAM,UAAU,CAAC;AAWlB,qBAAa,iBAAiB;IAQ1B,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,cAAc;IARxB,OAAO,CAAC,gBAAgB,CAAwC;IAChE,OAAO,CAAC,eAAe,CAInB;gBAEM,IAAI,EAAE,WAAW,EACjB,cAAc,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM;IAgB5C,aAAa,CACjB,IAAI,oBAAa,EACjB,IAAI,EAAE,UAAU,EAChB,KAAK,CAAC,EAAE,WAAW,GAClB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IA0D9B,wBAAwB,IAAI,YAAY,EAAE;IAoB1C,sBAAsB,IAAI,YAAY,EAAE;IAWxC,YAAY,IAAI;QACd,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,MAAM,EAAE,CAAC;KACvB;IAUD,gBAAgB,CAAC,KAAK,EAAE,MAAM;IAK9B;;;;;;OAMG;IACH,aAAa,IAAI,OAAO;IAQxB,UAAU;IAWV,iBAAiB;IAIjB,iBAAiB,CAAC,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;CAItD"}
|
package/dist/actions/press.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PlaywrightActionGenerator } from "../types";
|
|
1
|
+
import { PlaywrightActionGenerator, PressActionArgs } from "../types";
|
|
2
2
|
export declare const PLAYWRIGHT_PRESS_ACTION_NAME = "keyboard_press_on_element";
|
|
3
|
-
export declare const pressActionGenerator: PlaywrightActionGenerator
|
|
3
|
+
export declare const pressActionGenerator: PlaywrightActionGenerator<PressActionArgs>;
|
|
4
4
|
//# sourceMappingURL=press.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"press.d.ts","sourceRoot":"","sources":["../../src/actions/press.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"press.d.ts","sourceRoot":"","sources":["../../src/actions/press.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAItE,eAAO,MAAM,4BAA4B,8BAA8B,CAAC;AAExE,eAAO,MAAM,oBAAoB,EAAE,yBAAyB,CAC1D,eAAe,CA6DhB,CAAC"}
|
package/dist/actions/skill.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PlaywrightActionGenerator } from "../types";
|
|
1
|
+
import { PlaywrightActionGenerator, SkillActionArgs } from "../types";
|
|
2
2
|
export declare const SKILL_USAGE = "skill_usage";
|
|
3
3
|
export type Skill = {
|
|
4
4
|
testStep: string;
|
|
@@ -16,6 +16,6 @@ export declare const testCaseSkills: TestCaseSkills;
|
|
|
16
16
|
export declare function extractSkillFromArgs(args: Record<string, any>): {
|
|
17
17
|
skillDetails: Skill | undefined;
|
|
18
18
|
};
|
|
19
|
-
export declare const skillActionGenerator: PlaywrightActionGenerator
|
|
19
|
+
export declare const skillActionGenerator: PlaywrightActionGenerator<SkillActionArgs>;
|
|
20
20
|
export {};
|
|
21
21
|
//# sourceMappingURL=skill.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"skill.d.ts","sourceRoot":"","sources":["../../src/actions/skill.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"skill.d.ts","sourceRoot":"","sources":["../../src/actions/skill.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,yBAAyB,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAGtE,eAAO,MAAM,WAAW,gBAAgB,CAAC;AAEzC,MAAM,MAAM,KAAK,GAAG;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,cAAM,cAAc;IACN,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,KAAK,EAAE;IAEnC,kBAAkB;IAIlB,YAAY,CAAC,MAAM,EAAE,KAAK,EAAE;CAG7B;AAED,eAAO,MAAM,cAAc,gBAAyB,CAAC;AAErD,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;;EAO7D;AAED,eAAO,MAAM,oBAAoB,EAAE,yBAAyB,CAC1D,eAAe,CAkHhB,CAAC"}
|
package/dist/actions/skill.js
CHANGED
|
@@ -35,9 +35,9 @@ const skillActionGenerator = (page, options) => {
|
|
|
35
35
|
return {
|
|
36
36
|
execute: async ({ args, trace }) => {
|
|
37
37
|
const { skill, action } = args;
|
|
38
|
-
const
|
|
38
|
+
const [skillDetails] = availableSkills.filter((skillDetails) => skillDetails.testStep === skill);
|
|
39
39
|
if (!skillDetails) {
|
|
40
|
-
throw new Error(`No skill found for
|
|
40
|
+
throw new Error(`No skill found for ${skill}`);
|
|
41
41
|
}
|
|
42
42
|
const skillFilePath = skillDetails.filePath;
|
|
43
43
|
// This assumes repoDir is process.cwd()
|
|
@@ -86,7 +86,6 @@ const skillActionGenerator = (page, options) => {
|
|
|
86
86
|
};
|
|
87
87
|
},
|
|
88
88
|
template: (args, options) => {
|
|
89
|
-
// TODO: support for import statement
|
|
90
89
|
const code = `${options.locator}`;
|
|
91
90
|
const skill = args.skill;
|
|
92
91
|
const [skillDetails] = availableSkills.filter((skillDetails) => skillDetails.testStep === skill);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PlaywrightActionGenerator } from "../types";
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const textContentActionGenerator: PlaywrightActionGenerator
|
|
1
|
+
import { PlaywrightActionGenerator, TextContentActionArgs } from "../types";
|
|
2
|
+
export declare const PLAYWRIGHT_TEXT_CONTENT_ACTION_NAME = "text_content";
|
|
3
|
+
export declare const textContentActionGenerator: PlaywrightActionGenerator<TextContentActionArgs>;
|
|
4
4
|
//# sourceMappingURL=text-content.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text-content.d.ts","sourceRoot":"","sources":["../../src/actions/text-content.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"text-content.d.ts","sourceRoot":"","sources":["../../src/actions/text-content.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAI5E,eAAO,MAAM,mCAAmC,iBAAiB,CAAC;AAElE,eAAO,MAAM,0BAA0B,EAAE,yBAAyB,CAChE,qBAAqB,CA2DtB,CAAC"}
|
|
@@ -1,34 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.textContentActionGenerator = exports.
|
|
3
|
+
exports.textContentActionGenerator = exports.PLAYWRIGHT_TEXT_CONTENT_ACTION_NAME = void 0;
|
|
4
4
|
const constants_1 = require("./constants");
|
|
5
5
|
const utils_1 = require("./utils");
|
|
6
|
-
exports.
|
|
6
|
+
exports.PLAYWRIGHT_TEXT_CONTENT_ACTION_NAME = "text_content";
|
|
7
7
|
const textContentActionGenerator = (page, options) => {
|
|
8
8
|
return {
|
|
9
|
-
execute: async (args) => {
|
|
10
|
-
const
|
|
11
|
-
const locator = await (0, utils_1.getPlaywrightLocatorUsingCssSelector)(css, args.xpath, page.pwPageInstance, args?.elementAnnotation);
|
|
9
|
+
execute: async ({ args }) => {
|
|
10
|
+
const locator = await (0, utils_1.getPlaywrightLocatorUsingCssSelector)(args.css_selector, args.xpath, page.pwPageInstance, args?.elementAnnotation);
|
|
12
11
|
const exec = new Function("page", `return page.${locator}.textContent()`);
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
options.stateVariables
|
|
16
|
-
|
|
12
|
+
const textContent = await exec(page.pwPageInstance);
|
|
13
|
+
options.setStateVariables({
|
|
14
|
+
...options.stateVariables,
|
|
15
|
+
[args.variable_name]: textContent,
|
|
16
|
+
});
|
|
17
17
|
return {
|
|
18
18
|
locator,
|
|
19
19
|
};
|
|
20
20
|
},
|
|
21
21
|
template: (args, options) => {
|
|
22
|
-
const code = `const ${args.variable_name} = await ${page.name}.${options.locator}.textContent();`;
|
|
23
22
|
return {
|
|
24
|
-
code
|
|
23
|
+
code: `const ${args.variable_name} = await ${page.name}.${options.locator}.textContent();`,
|
|
25
24
|
};
|
|
26
25
|
},
|
|
27
|
-
name: exports.
|
|
26
|
+
name: exports.PLAYWRIGHT_TEXT_CONTENT_ACTION_NAME,
|
|
28
27
|
schema: {
|
|
29
28
|
type: "function",
|
|
30
29
|
function: {
|
|
31
|
-
name: exports.
|
|
30
|
+
name: exports.PLAYWRIGHT_TEXT_CONTENT_ACTION_NAME,
|
|
32
31
|
description: "extract text content of the element",
|
|
33
32
|
parameters: {
|
|
34
33
|
type: "object",
|
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const test_1 = require("@playwright/test");
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
7
8
|
const http_server_1 = __importDefault(require("http-server"));
|
|
8
9
|
const path_1 = __importDefault(require("path"));
|
|
9
10
|
const run_1 = require("../run");
|
|
@@ -57,9 +58,15 @@ test_1.test.afterAll(() => {
|
|
|
57
58
|
page,
|
|
58
59
|
options: {},
|
|
59
60
|
});
|
|
61
|
+
// Validate code generated and action performed
|
|
60
62
|
await (0, test_1.expect)(page.getByText("you clicked Gear")).toBeVisible();
|
|
61
63
|
console.log(response);
|
|
62
64
|
(0, test_1.expect)(response.importPaths.length).toBe(0);
|
|
63
|
-
(0, test_1.expect)(response.code).toContain("page.
|
|
65
|
+
(0, test_1.expect)(response.code).toContain("page.locator");
|
|
64
66
|
(0, test_1.expect)(response.code).toContain("click()");
|
|
67
|
+
// Validate icons registry
|
|
68
|
+
const iconsRegistryFile = path_1.default.join(process.cwd(), "icons.json");
|
|
69
|
+
const icons = JSON.parse(fs_1.default.readFileSync(iconsRegistryFile, "utf-8"));
|
|
70
|
+
(0, test_1.expect)(icons.length).toBe(4); // 1 for each unique icon
|
|
71
|
+
fs_1.default.unlinkSync(iconsRegistryFile);
|
|
65
72
|
});
|
|
@@ -15,10 +15,11 @@ export type AnnotationPreference = {
|
|
|
15
15
|
actionType: "all" | ActionType.FILL | ActionType.ASSERT_TEXT | ActionType.SCROLL;
|
|
16
16
|
assertionText?: string | undefined;
|
|
17
17
|
};
|
|
18
|
-
export declare function getAnnotationKeys({ page, preference, options, }: {
|
|
18
|
+
export declare function getAnnotationKeys({ page, preference, options, trace, }: {
|
|
19
19
|
page: Page;
|
|
20
20
|
preference: AnnotationPreference;
|
|
21
21
|
options: BrowsingAgentOptions;
|
|
22
|
+
trace?: TraceClient;
|
|
22
23
|
}): Promise<{
|
|
23
24
|
annotationKeys: {
|
|
24
25
|
elementID: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"element-annotation.d.ts","sourceRoot":"","sources":["../../../src/agent/master/element-annotation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,GAAG,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAQlC,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"element-annotation.d.ts","sourceRoot":"","sources":["../../../src/agent/master/element-annotation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,GAAG,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAQlC,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AA2DjD,wBAAsB,oBAAoB,CAAC,EACzC,kBAAkB,EAClB,WAAW,EACX,mBAAmB,EACnB,KAAK,EACL,GAAG,EACH,OAAO,EACP,UAAU,GACX,EAAE;IACD,kBAAkB,EAAE,MAAM,CAAC;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,OAAO,CAAC,EAAE,oBAAoB,CAAC;IAC/B,UAAU,EAAE,oBAAoB,CAAC;CAClC,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CA8C9B;AAED,MAAM,MAAM,oBAAoB,GAAG;IACjC,UAAU,EACN,KAAK,GACL,UAAU,CAAC,IAAI,GACf,UAAU,CAAC,WAAW,GACtB,UAAU,CAAC,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACpC,CAAC;AAgBF,wBAAsB,iBAAiB,CAAC,EACtC,IAAI,EACJ,UAAU,EACV,OAAO,EACP,KAAK,GACN,EAAE;IACD,IAAI,EAAE,IAAI,CAAC;IACX,UAAU,EAAE,oBAAoB,CAAC;IACjC,OAAO,EAAE,oBAAoB,CAAC;IAC9B,KAAK,CAAC,EAAE,WAAW,CAAC;CACrB,GAAG,OAAO,CAAC;IACV,cAAc,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACtD,gBAAgB,EAAE,MAAM,CAAC;IACzB,uBAAuB,EAAE,MAAM,CAAC;CACjC,CAAC,CAuED"}
|
|
@@ -5,6 +5,7 @@ const llm_1 = require("@empiricalrun/llm");
|
|
|
5
5
|
const constants_1 = require("../../constants");
|
|
6
6
|
const promptTemplate_0 = "{{#section \"system\"}}\nYou are an expert in describing the images and it's content. You need to provide the descriptions of annotated elements\npresent in the image.\n\nYou will be provided with an annotated screenshot where interact-able / clickable elements are annotated. The annotation\nis done by drawing a red box around the element and a small yellow box on it which contains unique element id.\n\nYou are given a Annotations which contains list of unique element id and description of the element separated by \":\".\n\nYou are also given the description of the element on which the action needs to be taken. The description includes\ninformation about how the element looks, it's position etc.\n\nYour task is to provide the annotation of the element on which the action needs to be performed based on the element\ndescription.\n\nFollow steps to fulfil your task:\n- Using the list of all element Ids provided to you, map all the element Ids on the annotated screen and describe each\nelement.\n- For describing each element Id\n-- iterate over each element Id in annotation list\n-- check if the description is already present for the element Id in the Annotation provided to you. If present skip\ndescribing it and use it as is.\n-- if the description is NA, then identify the element in the annotated screenshot and describe it using the image or\nicon enclosed in the element.\n- Respond with the mapped element Ids as \"enriched_annotations\"\n- Based on the description provided to you and the enriched annotations, first identify the element Id whose description\nmatches the task provided\n\nNote:\n- Ensure providing the description of all the elements in the list.\n- Don't update the description if its already present in the given annotations\n- Replace all the \"NA\" with description of the element. Its position, how does it look like etc.\n- There should be no \"NA\" present in any of the element description\n{{/section}}\n\n{{#section \"user\"}}\nElement description:\n{{elementDescription}}\n\nAnnotations:\n{{annotations}}\n\n{{image annotatedScreenshot}}\n{{/section}}";
|
|
7
7
|
const utils_1 = require("../utils");
|
|
8
|
+
const icon_descriptor_1 = require("./icon-descriptor");
|
|
8
9
|
const annotationToolAction = {
|
|
9
10
|
name: "element_annotation",
|
|
10
11
|
schema: {
|
|
@@ -99,8 +100,8 @@ async function getElementAnnotation({ elementDescription, annotations, annotated
|
|
|
99
100
|
return;
|
|
100
101
|
}
|
|
101
102
|
exports.getElementAnnotation = getElementAnnotation;
|
|
102
|
-
async function getAnnotationKeys({ page, preference, options, }) {
|
|
103
|
-
const
|
|
103
|
+
async function getAnnotationKeys({ page, preference, options, trace, }) {
|
|
104
|
+
const annotatedElements = await page.evaluate(({ preference, options }) => {
|
|
104
105
|
// @ts-ignore
|
|
105
106
|
// eslint-disable-next-line no-undef
|
|
106
107
|
window.annotationInstance = annotateElementsWithPreference({
|
|
@@ -109,17 +110,22 @@ async function getAnnotationKeys({ page, preference, options, }) {
|
|
|
109
110
|
});
|
|
110
111
|
const annotations = Object.entries(
|
|
111
112
|
// @ts-ignore
|
|
112
|
-
window.annotationInstance.annotations).map(([key, value]) =>
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
value.node
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
113
|
+
window.annotationInstance.annotations).map(([key, value]) => {
|
|
114
|
+
return {
|
|
115
|
+
elementID: key,
|
|
116
|
+
innerText: value.node instanceof HTMLElement ? value.node.innerText : null,
|
|
117
|
+
innerHTML: value.node.innerHTML,
|
|
118
|
+
outerHTML: value.node.outerHTML,
|
|
119
|
+
placeholder: value.node instanceof HTMLInputElement ||
|
|
120
|
+
value.node instanceof HTMLTextAreaElement
|
|
121
|
+
? value.node.placeholder
|
|
122
|
+
: null,
|
|
123
|
+
};
|
|
124
|
+
});
|
|
125
|
+
const fullPageHTML = document.documentElement.outerHTML;
|
|
126
|
+
return { annotations, fullPageHTML };
|
|
122
127
|
}, { preference, options });
|
|
128
|
+
const annotationKeys = await enrichAnnotations(annotatedElements.annotations, annotatedElements.fullPageHTML, trace);
|
|
123
129
|
const annotationBuffer = await page.screenshot({
|
|
124
130
|
// path: `screenshots/screenshot-${screenshotIndex++}.png`,
|
|
125
131
|
});
|
|
@@ -145,3 +151,30 @@ async function getAnnotationKeys({ page, preference, options, }) {
|
|
|
145
151
|
};
|
|
146
152
|
}
|
|
147
153
|
exports.getAnnotationKeys = getAnnotationKeys;
|
|
154
|
+
async function enrichAnnotations(annotatedElements, pageHtml, trace) {
|
|
155
|
+
// create icon descriptor span
|
|
156
|
+
const iconDescriptionSpan = trace?.span({
|
|
157
|
+
name: "describe-icons",
|
|
158
|
+
});
|
|
159
|
+
const results = [];
|
|
160
|
+
for (const element of annotatedElements) {
|
|
161
|
+
const text = element.innerText?.trim() || element.placeholder?.trim();
|
|
162
|
+
if (text) {
|
|
163
|
+
results.push({
|
|
164
|
+
elementID: element.elementID,
|
|
165
|
+
text,
|
|
166
|
+
});
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
const description = await (0, icon_descriptor_1.getIconDescription)({
|
|
170
|
+
htmlString: element.outerHTML,
|
|
171
|
+
pageHtml: pageHtml,
|
|
172
|
+
trace: iconDescriptionSpan,
|
|
173
|
+
});
|
|
174
|
+
results.push({
|
|
175
|
+
elementID: element.elementID,
|
|
176
|
+
text: description || "NA",
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
return results;
|
|
180
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { TraceClient } from "@empiricalrun/llm";
|
|
2
|
+
type IconKnowledge = {
|
|
3
|
+
description: string;
|
|
4
|
+
key: string;
|
|
5
|
+
normalized: string;
|
|
6
|
+
createdAt: Date;
|
|
7
|
+
};
|
|
8
|
+
export declare function loadIconsKnowledge(): Array<IconKnowledge>;
|
|
9
|
+
export declare function saveIconsKnowledge(iconsData: Array<IconKnowledge>): Promise<void>;
|
|
10
|
+
export declare function generateKey(htmlString: string): string;
|
|
11
|
+
export declare function reverseKey(hash: string): string;
|
|
12
|
+
export declare function createNodeFromHTML(htmlString: string): {
|
|
13
|
+
node: Element | null;
|
|
14
|
+
children: Element[];
|
|
15
|
+
};
|
|
16
|
+
export declare function getIconDescription({ htmlString, pageHtml, trace, }: {
|
|
17
|
+
htmlString: string;
|
|
18
|
+
trace?: TraceClient;
|
|
19
|
+
pageHtml: string;
|
|
20
|
+
}): Promise<string | undefined>;
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/agent/master/icon-descriptor/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAWrD,KAAK,aAAa,GAAG;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,IAAI,CAAC;CACjB,CAAC;AAEF,wBAAgB,kBAAkB,IAAI,KAAK,CAAC,aAAa,CAAC,CAczD;AAED,wBAAsB,kBAAkB,CACtC,SAAS,EAAE,KAAK,CAAC,aAAa,CAAC,GAC9B,OAAO,CAAC,IAAI,CAAC,CAGf;AAED,wBAAgB,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAKtD;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAG/C;AAED,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM;;;EAUpD;AAqKD,wBAAsB,kBAAkB,CAAC,EACvC,UAAU,EACV,QAAQ,EACR,KAAK,GACN,EAAE;IACD,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;CAClB,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAkC9B"}
|