@empiricalrun/test-gen 0.80.3 → 0.81.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/dist/agent/chat/index.d.ts.map +1 -1
  3. package/dist/agent/chat/index.js +1 -9
  4. package/dist/agent/chat/prompt/pw-utils-docs.d.ts +1 -1
  5. package/dist/agent/chat/prompt/pw-utils-docs.d.ts.map +1 -1
  6. package/dist/agent/chat/prompt/pw-utils-docs.js +0 -56
  7. package/dist/agent/chat/prompt/skills.d.ts +1 -2
  8. package/dist/agent/chat/prompt/skills.d.ts.map +1 -1
  9. package/dist/agent/chat/prompt/skills.js +34 -20
  10. package/dist/recorder/index.d.ts.map +1 -1
  11. package/dist/recorder/index.js +5 -3
  12. package/dist/tools/diagnosis-fetcher.d.ts +6 -2
  13. package/dist/tools/diagnosis-fetcher.d.ts.map +1 -1
  14. package/dist/tools/diagnosis-fetcher.js +1 -1
  15. package/dist/tools/executor/index.d.ts.map +1 -1
  16. package/dist/tools/executor/index.js +0 -2
  17. package/dist/tools/index.d.ts.map +1 -1
  18. package/dist/tools/index.js +3 -1
  19. package/dist/tools/run-test.js +2 -2
  20. package/dist/tools/test-run-fetcher/index.d.ts.map +1 -1
  21. package/package.json +11 -11
  22. package/tsconfig.tsbuildinfo +1 -1
  23. package/dist/agent/browsing/index.d.ts +0 -15
  24. package/dist/agent/browsing/index.d.ts.map +0 -1
  25. package/dist/agent/browsing/index.js +0 -60
  26. package/dist/agent/master/action-tool-calls.d.ts +0 -42
  27. package/dist/agent/master/action-tool-calls.d.ts.map +0 -1
  28. package/dist/agent/master/action-tool-calls.js +0 -87
  29. package/dist/agent/master/element-annotation.d.ts +0 -30
  30. package/dist/agent/master/element-annotation.d.ts.map +0 -1
  31. package/dist/agent/master/element-annotation.js +0 -175
  32. package/dist/agent/master/execute-browser-action.d.ts +0 -24
  33. package/dist/agent/master/execute-browser-action.d.ts.map +0 -1
  34. package/dist/agent/master/execute-browser-action.js +0 -121
  35. package/dist/agent/master/next-action.d.ts +0 -22
  36. package/dist/agent/master/next-action.d.ts.map +0 -1
  37. package/dist/agent/master/next-action.js +0 -97
  38. package/dist/agent/master/planner.d.ts +0 -15
  39. package/dist/agent/master/planner.d.ts.map +0 -1
  40. package/dist/agent/master/planner.js +0 -142
  41. package/dist/agent/master/run.d.ts +0 -17
  42. package/dist/agent/master/run.d.ts.map +0 -1
  43. package/dist/agent/master/run.js +0 -156
  44. package/dist/agent/master/scroller.d.ts +0 -15
  45. package/dist/agent/master/scroller.d.ts.map +0 -1
  46. package/dist/agent/master/scroller.js +0 -369
  47. package/dist/agent/master/with-hints.d.ts +0 -17
  48. package/dist/agent/master/with-hints.d.ts.map +0 -1
  49. package/dist/agent/master/with-hints.js +0 -103
  50. package/dist/agent/planner/run-time-planner.d.ts +0 -15
  51. package/dist/agent/planner/run-time-planner.d.ts.map +0 -1
  52. package/dist/agent/planner/run-time-planner.js +0 -98
  53. package/dist/agent/planner/run.d.ts +0 -7
  54. package/dist/agent/planner/run.d.ts.map +0 -1
  55. package/dist/agent/planner/run.js +0 -128
  56. package/dist/browser-injected-scripts/annotate-elements.js +0 -612
  57. package/dist/browser-injected-scripts/annotate-elements.spec.d.ts +0 -2
  58. package/dist/browser-injected-scripts/annotate-elements.spec.d.ts.map +0 -1
  59. package/dist/browser-injected-scripts/annotate-elements.spec.js +0 -202
  60. package/dist/browser-injected-scripts/annotate-elements.spec.ts +0 -327
  61. package/dist/generate-summary/frame-sampling.d.ts +0 -12
  62. package/dist/generate-summary/frame-sampling.d.ts.map +0 -1
  63. package/dist/generate-summary/frame-sampling.js +0 -72
  64. package/dist/generate-summary/generate-error-stack-summary.d.ts +0 -11
  65. package/dist/generate-summary/generate-error-stack-summary.d.ts.map +0 -1
  66. package/dist/generate-summary/generate-error-stack-summary.js +0 -41
  67. package/dist/generate-summary/generate-failed-step-screenshot-diff-summary.d.ts +0 -58
  68. package/dist/generate-summary/generate-failed-step-screenshot-diff-summary.d.ts.map +0 -1
  69. package/dist/generate-summary/generate-failed-step-screenshot-diff-summary.js +0 -460
  70. package/dist/generate-summary/generate-grouped-summary.d.ts +0 -18
  71. package/dist/generate-summary/generate-grouped-summary.d.ts.map +0 -1
  72. package/dist/generate-summary/generate-grouped-summary.js +0 -88
  73. package/dist/generate-summary/merge-summary.d.ts +0 -16
  74. package/dist/generate-summary/merge-summary.d.ts.map +0 -1
  75. package/dist/generate-summary/merge-summary.js +0 -43
  76. package/dist/generate-summary/pick-videos-for-comparison.d.ts +0 -9
  77. package/dist/generate-summary/pick-videos-for-comparison.d.ts.map +0 -1
  78. package/dist/generate-summary/pick-videos-for-comparison.js +0 -54
  79. package/dist/tools/slack-message/index.d.ts +0 -3
  80. package/dist/tools/slack-message/index.d.ts.map +0 -1
  81. package/dist/tools/slack-message/index.js +0 -69
  82. package/dist/tools/test-run-fetcher/types.d.ts +0 -79
  83. package/dist/tools/test-run-fetcher/types.d.ts.map +0 -1
  84. package/dist/tools/test-run-fetcher/types.js +0 -2
  85. package/dist/utils/env.d.ts +0 -2
  86. package/dist/utils/env.d.ts.map +0 -1
  87. package/dist/utils/env.js +0 -7
@@ -1 +0,0 @@
1
- {"version":3,"file":"action-tool-calls.d.ts","sourceRoot":"","sources":["../../../src/agent/master/action-tool-calls.ts"],"names":[],"mappings":"AAAA,oBAAY,UAAU;IACpB,IAAI,SAAS;IACb,SAAS,cAAc;IACvB,KAAK,UAAU;IACf,YAAY,8BAA8B;IAC1C,WAAW,gBAAgB;IAC3B,KAAK,kBAAkB;IACvB,MAAM,WAAW;IACjB,WAAW,gBAAgB;IAC3B,OAAO,YAAY;CACpB;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,UAAU,CAEpE;AAqDD,wBAAgB,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA8CjC"}
@@ -1,87 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ActionType = void 0;
4
- exports.isValidActionType = isValidActionType;
5
- exports.getActionToolCalls = getActionToolCalls;
6
- var ActionType;
7
- (function (ActionType) {
8
- ActionType["FILL"] = "fill";
9
- ActionType["PAGE_GOTO"] = "page_goto";
10
- ActionType["CLICK"] = "click";
11
- ActionType["PRESS_ACTION"] = "keyboard_press_on_element";
12
- ActionType["ASSERT_TEXT"] = "assert_text";
13
- ActionType["HOVER"] = "hover_element";
14
- ActionType["SCROLL"] = "scroll";
15
- ActionType["OBSERVATION"] = "observation";
16
- ActionType["UNKNOWN"] = "unknown";
17
- })(ActionType || (exports.ActionType = ActionType = {}));
18
- function isValidActionType(value) {
19
- return Object.values(ActionType).includes(value);
20
- }
21
- const createActionCall = (name, description, additionalProperties = {}) => ({
22
- type: "function",
23
- function: {
24
- name,
25
- description,
26
- parameters: {
27
- type: "object",
28
- properties: {
29
- reason: {
30
- type: "string",
31
- description: "explain how this action will help to complete the task. the reason should align with the task provided",
32
- },
33
- action: {
34
- type: "string",
35
- description: `explain the next action in natural language.
36
- The next action should be as atomic as possible, precise and should contain enough details about the action to be performed.
37
- E.g. each click, key press, input, assert, observation should be a separate action.
38
- Each action should take the task to completion, if not the action is invalid.
39
- If the element is not visible then action should be scroll.`,
40
- },
41
- element_description: {
42
- type: "string",
43
- description: "The description of the element on which action needs to be taken, including its position, appearance, etc.",
44
- },
45
- is_element_visible: {
46
- type: "boolean",
47
- description: "A boolean to indicate whether the concerned element is visible in the screenshot.",
48
- },
49
- ...additionalProperties,
50
- },
51
- required: [
52
- "reason",
53
- "action",
54
- "element_description",
55
- "is_element_visible",
56
- ...Object.keys(additionalProperties),
57
- ],
58
- },
59
- },
60
- });
61
- function getActionToolCalls() {
62
- return [
63
- createActionCall(ActionType.ASSERT_TEXT, "assert whether the given element on the page is visible", {
64
- assertion_text: {
65
- type: "string",
66
- description: "The text for which the visibility needs to be asserted.",
67
- },
68
- }),
69
- createActionCall(ActionType.FILL, "fill the input element with a particular text"),
70
- createActionCall(ActionType.CLICK, "click an element on the page"),
71
- createActionCall(ActionType.PAGE_GOTO, "navigate the page to a new URL"),
72
- createActionCall(ActionType.PRESS_ACTION, "Focuses the matching element and presses a combination of the keys"),
73
- createActionCall(ActionType.HOVER, "hover over an element on the page"),
74
- createActionCall(ActionType.SCROLL, "Scroll the page since element is not visible in the screenshot", {
75
- element: {
76
- type: "string",
77
- description: "Element to look for after scrolling to complete the task.",
78
- },
79
- }),
80
- createActionCall(ActionType.OBSERVATION, "Observation based on the task provided. If the task doesn't explicitly mention any browser interaction, and instead, asks questions to be answered — use this tool call", {
81
- observation: {
82
- type: "string",
83
- description: "Observation based on the task provided.",
84
- },
85
- }),
86
- ];
87
- }
@@ -1,30 +0,0 @@
1
- import { LLM, TraceClient } from "@empiricalrun/llm";
2
- import { TestGenConfigOptions } from "@empiricalrun/shared-types/agent-workflow";
3
- import { Page } from "playwright";
4
- import { ActionType } from "./action-tool-calls";
5
- export declare function getElementAnnotation({ elementDescription, annotations, annotatedScreenshot, trace, llm, options, preference, }: {
6
- elementDescription: string;
7
- annotations: string;
8
- annotatedScreenshot: string;
9
- trace?: TraceClient;
10
- llm?: LLM;
11
- options?: TestGenConfigOptions;
12
- preference: AnnotationPreference;
13
- }): Promise<string | undefined>;
14
- export type AnnotationPreference = {
15
- actionType: "all" | ActionType.FILL | ActionType.ASSERT_TEXT | ActionType.SCROLL;
16
- assertionText?: string | undefined;
17
- };
18
- export declare function getAnnotationKeys({ page, preference, trace, }: {
19
- page: Page;
20
- preference: AnnotationPreference;
21
- trace?: TraceClient;
22
- }): Promise<{
23
- annotationKeys: {
24
- elementID: string;
25
- text: string;
26
- }[];
27
- annotationBuffer: Buffer;
28
- annotatedPageScreenshot: string;
29
- }>;
30
- //# sourceMappingURL=element-annotation.d.ts.map
@@ -1 +0,0 @@
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,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAQlC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AA0DjD,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,KAAK,GACN,EAAE;IACD,IAAI,EAAE,IAAI,CAAC;IACX,UAAU,EAAE,oBAAoB,CAAC;IACjC,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,CAmFD"}
@@ -1,175 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getElementAnnotation = getElementAnnotation;
4
- exports.getAnnotationKeys = getAnnotationKeys;
5
- const llm_1 = require("@empiricalrun/llm");
6
- const constants_1 = require("../../constants");
7
- 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}}";
8
- const annotationToolAction = {
9
- name: "element_annotation",
10
- schema: {
11
- type: "function",
12
- function: {
13
- name: "element_annotation",
14
- description: "Handles annotations for elements and enriched annotations.",
15
- parameters: {
16
- type: "object",
17
- properties: {
18
- enriched_annotations: {
19
- type: "array",
20
- description: "List of enriched annotations for elements.",
21
- items: {
22
- type: "object",
23
- properties: {
24
- element_id: {
25
- type: "string",
26
- description: "Unique element ID for the element.",
27
- },
28
- description: {
29
- type: "string",
30
- description: "Detailed description for the element. Must not be NA",
31
- },
32
- },
33
- required: ["element_id", "description"],
34
- },
35
- },
36
- reason: {
37
- type: "string",
38
- description: "Explain why this element is selected. The reason should be clear and align with the task or purpose.",
39
- },
40
- element: {
41
- type: "string",
42
- description: "Detailed description of the DOM element's visual characteristics and position.",
43
- },
44
- element_annotation: {
45
- type: "string",
46
- description: "Return the unique element ID for the element on which the action needs to be performed.",
47
- },
48
- },
49
- required: [
50
- "enriched_annotations",
51
- "reason",
52
- "element",
53
- "element_annotation",
54
- ],
55
- },
56
- },
57
- },
58
- };
59
- async function getElementAnnotation({ elementDescription, annotations, annotatedScreenshot, trace, llm, options, preference, }) {
60
- const annotationsSpan = trace?.span({
61
- name: "get-element-annotation",
62
- input: {
63
- elementDescription,
64
- annotations,
65
- annotatedScreenshot,
66
- preference,
67
- },
68
- });
69
- const messages = (0, llm_1.compilePrompt)(promptTemplate_0, {
70
- elementDescription,
71
- annotations,
72
- annotatedScreenshot,
73
- }, options);
74
- llm =
75
- llm ||
76
- new llm_1.LLM({
77
- provider: options?.modelProvider || constants_1.DEFAULT_MODEL_PROVIDER,
78
- defaultModel: options?.model || constants_1.DEFAULT_MODEL,
79
- });
80
- const completion = await llm.createChatCompletion({
81
- messages,
82
- modelParameters: {
83
- ...constants_1.DEFAULT_MODEL_PARAMETERS,
84
- ...options?.modelParameters,
85
- tool_choice: "required",
86
- temperature: 0.5,
87
- },
88
- trace: annotationsSpan,
89
- traceName: "get-element-from-action",
90
- //@ts-ignore
91
- tools: [annotationToolAction.schema],
92
- });
93
- const toolCall = completion?.tool_calls?.[0];
94
- annotationsSpan?.end({ output: toolCall });
95
- if (toolCall && "function" in toolCall) {
96
- const args = JSON.parse(toolCall.function.arguments);
97
- return args.element_annotation;
98
- }
99
- return;
100
- }
101
- async function getAnnotationKeys({ page, preference, trace, }) {
102
- const annotatedElements = await page.evaluate(({ preference, options }) => {
103
- // @ts-ignore
104
- window.annotationInstance = annotateElementsWithPreference({
105
- options: options,
106
- preference: preference,
107
- });
108
- const annotations = Object.entries(
109
- // @ts-ignore
110
- window.annotationInstance.annotations).map(([key, value]) => {
111
- // Helper function to safely get text content
112
- const getTextContent = (node) => {
113
- try {
114
- return node?.innerText?.trim() || null;
115
- }
116
- catch {
117
- return null;
118
- }
119
- };
120
- // Helper function to safely get placeholder
121
- const getPlaceholder = (node) => {
122
- try {
123
- return node?.placeholder?.trim() || null;
124
- }
125
- catch {
126
- return null;
127
- }
128
- };
129
- return {
130
- elementID: key,
131
- innerText: getTextContent(value.node),
132
- innerHTML: value.node.innerHTML,
133
- outerHTML: value.node.outerHTML,
134
- placeholder: getPlaceholder(value.node),
135
- };
136
- });
137
- const fullPageHTML = document.documentElement.outerHTML;
138
- return { annotations, fullPageHTML };
139
- }, { preference, options: {} });
140
- const annotationKeys = await enrichAnnotations(annotatedElements.annotations, annotatedElements.fullPageHTML, trace);
141
- const annotationBuffer = await page.screenshot({
142
- // path: `screenshots/screenshot-${screenshotIndex++}.png`,
143
- });
144
- const annotatedPageScreenshot = annotationBuffer.toString("base64");
145
- await page.evaluate(() => {
146
- console.log({
147
- // @ts-ignore
148
- disable: window?.annotationInstance?.disable,
149
- });
150
- if (
151
- // @ts-ignore
152
- window?.annotationInstance &&
153
- // @ts-ignore
154
- window?.annotationInstance?.destroy) {
155
- // @ts-ignore
156
- window?.annotationInstance?.destroy();
157
- }
158
- });
159
- return {
160
- annotationKeys,
161
- annotationBuffer,
162
- annotatedPageScreenshot,
163
- };
164
- }
165
- async function enrichAnnotations(annotatedElements, _pageHtml, _trace) {
166
- const results = [];
167
- for (const element of annotatedElements) {
168
- const text = element.innerText?.trim() || element.placeholder?.trim();
169
- results.push({
170
- elementID: element.elementID,
171
- text: text || "NA",
172
- });
173
- }
174
- return results;
175
- }
@@ -1,24 +0,0 @@
1
- import { LLM, TraceClient } from "@empiricalrun/llm";
2
- import type { Page } from "@playwright/test";
3
- import { PlaywrightActions } from "../../actions";
4
- export declare function executeBrowserAction({ page, nextAction, flags, actions, llm, trace, }: {
5
- page: Page;
6
- nextAction: {
7
- actionType: string;
8
- toolCallArgs: string;
9
- };
10
- flags: {
11
- useActionSpecificAnnotations: boolean;
12
- };
13
- actions: PlaywrightActions;
14
- trace?: TraceClient | undefined;
15
- llm: LLM;
16
- }): Promise<{
17
- generatedCodeSteps: string[];
18
- output: {
19
- action: string;
20
- reason: string;
21
- elementAnnotation?: string;
22
- };
23
- }>;
24
- //# sourceMappingURL=execute-browser-action.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"execute-browser-action.d.ts","sourceRoot":"","sources":["../../../src/agent/master/execute-browser-action.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAE7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAUlD,wBAAsB,oBAAoB,CAAC,EACzC,IAAI,EACJ,UAAU,EACV,KAAK,EACL,OAAO,EACP,GAAG,EACH,KAAK,GACN,EAAE;IACD,IAAI,EAAE,IAAI,CAAC;IACX,UAAU,EAAE;QACV,UAAU,EAAE,MAAM,CAAC;QACnB,YAAY,EAAE,MAAM,CAAC;KACtB,CAAC;IACF,KAAK,EAAE;QACL,4BAA4B,EAAE,OAAO,CAAC;KACvC,CAAC;IACF,OAAO,EAAE,iBAAiB,CAAC;IAC3B,KAAK,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;IAChC,GAAG,EAAE,GAAG,CAAC;CACV;;;gBAIW,MAAM;gBACN,MAAM;4BACM,MAAM;;GA+H7B"}
@@ -1,121 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.executeBrowserAction = executeBrowserAction;
4
- const browsing_1 = require("../browsing");
5
- const action_tool_calls_1 = require("./action-tool-calls");
6
- const element_annotation_1 = require("./element-annotation");
7
- const with_hints_1 = require("./with-hints");
8
- async function executeBrowserAction({ page, nextAction, flags, actions, llm, trace, }) {
9
- const args = JSON.parse(nextAction.toolCallArgs);
10
- let generatedCodeSteps = [];
11
- let output = {
12
- action: args.action,
13
- reason: args.reason,
14
- };
15
- let shouldTriggerHintsFlow;
16
- let hintsExecutionCompletion;
17
- let elementAnnotation;
18
- const actionType = nextAction.actionType;
19
- let preference = {
20
- actionType: "all",
21
- };
22
- if (flags.useActionSpecificAnnotations && (0, action_tool_calls_1.isValidActionType)(actionType)) {
23
- switch (actionType) {
24
- case action_tool_calls_1.ActionType.FILL:
25
- preference = {
26
- actionType: action_tool_calls_1.ActionType.FILL,
27
- };
28
- break;
29
- case action_tool_calls_1.ActionType.ASSERT_TEXT:
30
- preference = {
31
- actionType: action_tool_calls_1.ActionType.ASSERT_TEXT,
32
- assertionText: args.assertion_text,
33
- };
34
- break;
35
- default:
36
- preference = {
37
- actionType: "all",
38
- };
39
- }
40
- }
41
- let { annotationKeys, annotatedPageScreenshot } = await (0, element_annotation_1.getAnnotationKeys)({
42
- page,
43
- preference,
44
- trace,
45
- });
46
- if (annotationKeys.length > 0) {
47
- // TODO: this string has newline characters that makes it harder to read
48
- const annotationMapString = annotationKeys
49
- ?.map((a) => `${a.elementID}: ${a.text}`)
50
- .join("\n");
51
- // Provides the annotations for all the element present on screen
52
- // Also provides the annotation of element on which the action needs to be taken
53
- elementAnnotation = await (0, element_annotation_1.getElementAnnotation)({
54
- elementDescription: args.element_description,
55
- annotations: annotationMapString,
56
- annotatedScreenshot: annotatedPageScreenshot,
57
- trace,
58
- llm,
59
- preference,
60
- });
61
- output.elementAnnotation = elementAnnotation;
62
- console.log("Output: ", output);
63
- const triggerHintsFlowSpan = trace?.span({
64
- name: "trigger-hints-flow",
65
- input: {
66
- outputFromGetNextAction: output,
67
- generatedAnnotations: annotationKeys,
68
- },
69
- });
70
- // Provides the action whether its a click, fill etc.
71
- const result = await (0, with_hints_1.triggerHintsFlow)({
72
- outputFromGetNextAction: output,
73
- generatedAnnotations: annotationKeys,
74
- actions,
75
- llm,
76
- trace: triggerHintsFlowSpan,
77
- });
78
- shouldTriggerHintsFlow = result.shouldTriggerHintsFlow;
79
- hintsExecutionCompletion = result.hintsExecutionCompletion;
80
- triggerHintsFlowSpan?.end({
81
- output: result,
82
- });
83
- }
84
- if (shouldTriggerHintsFlow && hintsExecutionCompletion) {
85
- const toolCalls = hintsExecutionCompletion?.tool_calls || [];
86
- for (const i in toolCalls) {
87
- const currentToolCall = toolCalls[i];
88
- if (currentToolCall && "function" in currentToolCall) {
89
- const code = await actions.executeAction(currentToolCall.function.name, {
90
- ...JSON.parse(currentToolCall.function.arguments),
91
- elementAnnotation,
92
- }, trace);
93
- if (code) {
94
- generatedCodeSteps.push(code);
95
- }
96
- }
97
- }
98
- if (actions.isStuckInLoop()) {
99
- throw new Error("Agent is not able to figure out next action when using hints");
100
- }
101
- }
102
- else {
103
- const browserAction = await (0, browsing_1.executeTaskUsingBrowsingAgent)({
104
- trace,
105
- action: output.action,
106
- page,
107
- llm,
108
- actions,
109
- });
110
- if (browserAction) {
111
- output.action = browserAction.action;
112
- if (browserAction.code) {
113
- generatedCodeSteps.push(browserAction.code);
114
- }
115
- }
116
- }
117
- return {
118
- generatedCodeSteps,
119
- output,
120
- };
121
- }
@@ -1,22 +0,0 @@
1
- import { LLM, TraceClient } from "@empiricalrun/llm";
2
- import { TestGenConfigOptions } from "@empiricalrun/shared-types/agent-workflow";
3
- import { Page } from "playwright";
4
- import { PlaywrightActions } from "../../actions";
5
- import { CustomLogger } from "../../bin/logger";
6
- export declare function getNextAction({ page, pageScreenshot, task, executedActions, failedActions, trace, llm, options, actions, disableSkills, logger, }: {
7
- page: Page;
8
- pageScreenshot: string[];
9
- task: string;
10
- executedActions: string[];
11
- failedActions: any[];
12
- trace?: TraceClient;
13
- llm?: LLM;
14
- options?: Partial<TestGenConfigOptions>;
15
- actions: PlaywrightActions;
16
- disableSkills: boolean;
17
- logger?: CustomLogger;
18
- }): Promise<{
19
- actionType: string;
20
- toolCallArgs: string;
21
- } | undefined>;
22
- //# sourceMappingURL=next-action.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"next-action.d.ts","sourceRoot":"","sources":["../../../src/agent/master/next-action.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,GAAG,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAUhD,wBAAsB,aAAa,CAAC,EAClC,IAAI,EACJ,cAAc,EACd,IAAI,EACJ,eAAe,EACf,aAAa,EACb,KAAK,EACL,GAAG,EACH,OAAO,EACP,OAAO,EACP,aAAa,EACb,MAAM,GACP,EAAE;IACD,IAAI,EAAE,IAAI,CAAC;IACX,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,aAAa,EAAE,GAAG,EAAE,CAAC;IACrB,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,OAAO,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACxC,OAAO,EAAE,iBAAiB,CAAC;IAC3B,aAAa,EAAE,OAAO,CAAC;IACvB,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB,GAAG,OAAO,CACP;IACE,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;CACtB,GACD,SAAS,CACZ,CAwFA"}
@@ -1,97 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getNextAction = getNextAction;
4
- const llm_1 = require("@empiricalrun/llm");
5
- const constants_1 = require("../../constants");
6
- const promptTemplate_0 = "{{#section \"system\"}}\nYou are a web automation tool which is given a task to complete. You need to execute the\ntask provided to you with the help of web page screenshot, a browser automation tool or skills\nwhich are learnt while writing previous tests. \n \nBrowser automation tool is a tool which uses Playwright and browser to execute action using\nnext_action tool call.\nSkill usage is a tool which helps to execute previously known pieces of code to achieve a task.\n\nYou will be provided with a screenshot of the webpage which you will use to extract the action\nthat needs to be taken.\n\nYou will be provided with previously executed actions by the browser automation tool and based\non the current screenshot and previously executed actions, you need to predict the next action\nto be taken.\n\nYou will also be provided with failed next action predicted by you, so that you can avoid\nsuggesting the same action again - which failed.\n\nThe next action should be as atomic as possible. e.g: scroll, click on an element, fill an input\nelement, assert, extract text from an element are valid next action as they are atomic in nature.\n\nYou also need to provide the action type using the list below, action type which is not present in\nthe list is invalid: {{validActionTypes}}\n\nYou will also be provided with skill usage tool which you can use to execute action. These skills\nare compound functions which helps you to complete your action.\n\nYou need to respond with either:\n- Next action to be taken by a browser automation tool \n- Use previously learnt skills in the form of tool call.\n \nYou need to make a decision whether the given skill can be reused if \"YES\" respond with the\nskill else respond with the next action.\n{{/section}}\n\n{{#section \"user\"}}\nTask:\n{{task}}\n\n-----\n\nPrevious executed actions:\n{{executedActions}}\n\n-----\n\nPrevious failed actions:\n{{failedActions}}\n\n-----\n\nYou are also provided with a page screenshot for you to decide the next action.\n\nCurrent page URL: {{pageUrl}}\n\nFollow the instructions before responding:\n- Divide the task into sub tasks\n- Using previously executed actions, identify tasks are complete and which tasks needs to be executed next.\n- You will be provided a skill usage action, if the testStep matches the next action then respond with the skill usage.\n- If responding with next action, ensure next action to be detailed and explicit about what action needs to be done. Provide all the information which can be extracted from the screenshot as a part of next action.\n- Mark task as complete only when executed actions provided to you indicates that the task is done.\n- Refer to the text and references available in the screenshot to create the next action.\n- Do not take any extra actions which are not required for the execution of the task\n- If there are no further actions required based on the task, then respond with task as done.\n- Do not recommend actions which are not available in the screenshot\n\nScreenshots:\n{{images pageScreenshots}}\n\n{{/section}}\n";
7
- const action_tool_calls_1 = require("./action-tool-calls");
8
- const scroller_1 = require("./scroller");
9
- async function getNextAction({ page, pageScreenshot, task, executedActions, failedActions, trace, llm, options, actions, disableSkills, logger, }) {
10
- const pageUrl = page.url();
11
- const nextActionSpan = trace?.span({
12
- name: "master-agent-next-action",
13
- input: {
14
- task,
15
- executedActions,
16
- failedActions,
17
- pageUrl,
18
- options,
19
- pageScreenshot,
20
- disableSkills,
21
- },
22
- });
23
- const messages = (0, llm_1.compilePrompt)(promptTemplate_0, {
24
- validActionTypes: Object.values(action_tool_calls_1.ActionType).join(", "),
25
- task,
26
- executedActions: executedActions.map((a) => a).join("\n"),
27
- failedActions: failedActions.map((a) => a).join("\n"),
28
- pageUrl,
29
- pageScreenshots: pageScreenshot,
30
- });
31
- const tools = [...(0, action_tool_calls_1.getActionToolCalls)()];
32
- llm =
33
- llm ||
34
- new llm_1.LLM({
35
- provider: options?.modelProvider || constants_1.DEFAULT_MODEL_PROVIDER,
36
- defaultModel: options?.model || constants_1.DEFAULT_MODEL,
37
- });
38
- const completion = await llm.createChatCompletion({
39
- messages,
40
- modelParameters: {
41
- ...constants_1.DEFAULT_MODEL_PARAMETERS,
42
- ...options?.modelParameters,
43
- tool_choice: "required",
44
- temperature: 1,
45
- },
46
- trace: nextActionSpan,
47
- traceName: "master-agent-llm",
48
- // @ts-ignore
49
- tools,
50
- });
51
- const toolCall = completion?.tool_calls?.[0];
52
- nextActionSpan?.end({ output: toolCall });
53
- if (toolCall && "function" in toolCall) {
54
- const toolCallArgs = JSON.parse(toolCall.function.arguments);
55
- const actionType = toolCall.function.name;
56
- // If the action type is scroll, we need to scroll the page and get the reference to the frame in which the element is visible
57
- // else we return the next action
58
- // For scroll we have at max 2 retries
59
- // If the element is not visible after 2 retries, we throw an error
60
- if (actionType === "scroll" && toolCallArgs) {
61
- let maxScrollRetries = 2;
62
- while (maxScrollRetries--) {
63
- const frames = await (0, scroller_1.scroller)({
64
- elementDescription: toolCallArgs.element,
65
- page,
66
- trace: nextActionSpan,
67
- logger,
68
- });
69
- if (frames.length > 0) {
70
- return getNextAction({
71
- task,
72
- executedActions,
73
- failedActions,
74
- trace,
75
- llm,
76
- options,
77
- pageScreenshot: frames.map((frame) => frame.frameScreenshot),
78
- actions,
79
- disableSkills,
80
- page,
81
- logger,
82
- });
83
- }
84
- }
85
- if (maxScrollRetries === -1) {
86
- return {
87
- actionType: action_tool_calls_1.ActionType.UNKNOWN,
88
- toolCallArgs: "",
89
- };
90
- }
91
- }
92
- return {
93
- actionType,
94
- toolCallArgs: toolCall?.function.arguments,
95
- };
96
- }
97
- }
@@ -1,15 +0,0 @@
1
- import { TraceClient } from "@empiricalrun/llm";
2
- import { Page } from "playwright/test";
3
- export declare function runtimePlannerWithScreenshot({ trace, task, conversation, pages, page, currentPage, }: {
4
- trace?: TraceClient;
5
- conversation: string[];
6
- task: string;
7
- pages?: Record<string, any>;
8
- page: Page;
9
- currentPage?: string;
10
- }): Promise<{
11
- pageName: string;
12
- isDone: boolean;
13
- reason: string;
14
- }>;
15
- //# sourceMappingURL=planner.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"planner.d.ts","sourceRoot":"","sources":["../../../src/agent/master/planner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAIvC,wBAAsB,4BAA4B,CAAC,EACjD,KAAK,EACL,IAAI,EACJ,YAAY,EACZ,KAAK,EACL,IAAI,EACJ,WAAW,GACZ,EAAE;IACD,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,IAAI,EAAE,IAAI,CAAC;IACX,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;cAsHoC,MAAM;YACV,OAAO;YACP,MAAM;GAgBtC"}