@empiricalrun/playwright-utils 0.65.0 → 0.65.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 (37) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/generated/api-worker-openapi.d.ts +1979 -1272
  3. package/dist/generated/api-worker-openapi.d.ts.map +1 -1
  4. package/dist/overlay-tests/typesafe.spec.js +5 -3
  5. package/dist/overlay-tests/visual.spec.js +1 -1
  6. package/dist/reporter/attachment-cleanup-test-reporter.d.ts +3 -1
  7. package/dist/reporter/attachment-cleanup-test-reporter.d.ts.map +1 -1
  8. package/dist/reporter/attachment-cleanup-test-reporter.js +5 -1
  9. package/dist/reporter/attachment-cleanup.d.ts +1 -1
  10. package/dist/reporter/attachment-cleanup.d.ts.map +1 -1
  11. package/dist/reporter/attachment-cleanup.js +14 -7
  12. package/dist/reporter/attachment-key.d.ts +3 -0
  13. package/dist/reporter/attachment-key.d.ts.map +1 -0
  14. package/dist/reporter/attachment-key.js +31 -0
  15. package/dist/reporter/empirical-reporter.d.ts +1 -1
  16. package/dist/reporter/empirical-reporter.d.ts.map +1 -1
  17. package/dist/reporter/empirical-reporter.js +7 -6
  18. package/dist/reporter/harness.d.ts +6 -1
  19. package/dist/reporter/harness.d.ts.map +1 -1
  20. package/dist/reporter/harness.js +22 -13
  21. package/dist/reporter/incremental-blob-reporter.d.ts +1 -0
  22. package/dist/reporter/incremental-blob-reporter.d.ts.map +1 -1
  23. package/dist/reporter/incremental-blob-reporter.js +8 -4
  24. package/dist/reporter/util.d.ts +3 -3
  25. package/dist/reporter/util.d.ts.map +1 -1
  26. package/dist/reporter/util.js +10 -8
  27. package/dist/test/expect/visual.d.ts.map +1 -1
  28. package/dist/test/expect/visual.js +6 -2
  29. package/dist/test/scripts/pw-locator-patch/dismiss-overlays/index.d.ts.map +1 -1
  30. package/dist/test/scripts/pw-locator-patch/dismiss-overlays/index.js +0 -2
  31. package/dist/test/scripts/pw-locator-patch/dismiss-overlays/utils.d.ts +0 -1
  32. package/dist/test/scripts/pw-locator-patch/dismiss-overlays/utils.d.ts.map +1 -1
  33. package/dist/test/scripts/pw-locator-patch/dismiss-overlays/utils.js +0 -20
  34. package/dist/test/scripts/pw-locator-patch/vision/query.d.ts.map +1 -1
  35. package/dist/test/scripts/pw-locator-patch/vision/query.js +57 -5
  36. package/package.json +3 -4
  37. package/tsconfig.tsbuildinfo +1 -1
@@ -1,15 +1,67 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.patchQuery = patchQuery;
4
- const vision_1 = require("@empiricalrun/llm/vision");
7
+ const openai_1 = __importDefault(require("openai"));
5
8
  const api_worker_client_1 = require("../../../../api-worker-client");
9
+ const telemetry_1 = require("../../../../telemetry");
10
+ const QUERY_MODEL = "gpt-4o-mini";
11
+ const SYSTEM_PROMPT = `
12
+ You are given an image and an instruction. Use the "explanation" to
13
+ think it through, and then respond with the "answer".`;
14
+ async function queryScreenshot(base64Image, instruction) {
15
+ const openai = new openai_1.default({ maxRetries: 5, ...(0, api_worker_client_1.llmProxyOpenAIConfig)() });
16
+ const completion = await openai.chat.completions.create({
17
+ model: QUERY_MODEL,
18
+ messages: [
19
+ { role: "system", content: SYSTEM_PROMPT },
20
+ {
21
+ role: "user",
22
+ content: [
23
+ {
24
+ type: "image_url",
25
+ image_url: { url: `data:image/png;base64,${base64Image}` },
26
+ },
27
+ { type: "text", text: `Instruction: ${instruction}` },
28
+ ],
29
+ },
30
+ ],
31
+ temperature: 0.5,
32
+ response_format: {
33
+ type: "json_schema",
34
+ json_schema: {
35
+ name: "your_response",
36
+ strict: true,
37
+ schema: {
38
+ type: "object",
39
+ properties: {
40
+ explanation: { type: "string" },
41
+ answer: { type: "string" },
42
+ },
43
+ required: ["explanation", "answer"],
44
+ additionalProperties: false,
45
+ },
46
+ },
47
+ },
48
+ });
49
+ await (0, telemetry_1.trackLLMResponseGenerated)({
50
+ modelName: QUERY_MODEL,
51
+ tokensInput: completion.usage?.prompt_tokens ?? 0,
52
+ tokensOutput: completion.usage?.completion_tokens ?? 0,
53
+ chatSessionSource: "vision_query",
54
+ });
55
+ const content = completion.choices[0]?.message?.content;
56
+ if (!content) {
57
+ throw new Error("Query failed: no response content from LLM.");
58
+ }
59
+ return JSON.parse(content).answer;
60
+ }
6
61
  function patchQuery(LocatorClass) {
7
62
  LocatorClass.prototype.query = async function (instruction) {
8
63
  await this.waitFor({ state: "visible" });
9
64
  const screenshot = await this.screenshot();
10
- const answer = await (0, vision_1.query)(screenshot.toString("base64"), instruction, {
11
- clientConfig: (0, api_worker_client_1.llmProxyOpenAIConfig)(),
12
- });
13
- return answer;
65
+ return queryScreenshot(screenshot.toString("base64"), instruction);
14
66
  };
15
67
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@empiricalrun/playwright-utils",
3
- "version": "0.65.0",
3
+ "version": "0.65.1",
4
4
  "engines": {
5
5
  "node": ">=22"
6
6
  },
@@ -45,7 +45,7 @@
45
45
  "playwright-core": "1.63.0",
46
46
  "serve-handler": "^6.1.6",
47
47
  "typescript": "7.0.2",
48
- "@empiricalrun/shared-types": "0.23.0"
48
+ "@empiricalrun/shared-types": "0.23.2"
49
49
  },
50
50
  "dependencies": {
51
51
  "async-retry": "^1.3.3",
@@ -56,8 +56,7 @@
56
56
  "openapi-fetch": "0.14.1",
57
57
  "puppeteer-extra-plugin-recaptcha": "^3.6.8",
58
58
  "ts-morph": "^28.0.0",
59
- "@empiricalrun/cua": "^0.5.4",
60
- "@empiricalrun/llm": "^0.28.3",
59
+ "@empiricalrun/cua": "^0.6.0",
61
60
  "@empiricalrun/r2-uploader": "^0.11.5",
62
61
  "@empiricalrun/reporter": "^0.30.3"
63
62
  },