@smoothdeploy/playwright 1.58.4 → 1.60.0-beta-1780662356000

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 (182) hide show
  1. package/ThirdPartyNotices.txt +8 -5036
  2. package/lib/agents/agentParser.js +2 -2
  3. package/lib/agents/generateAgents.js +21 -22
  4. package/lib/agents/playwright-test-healer.agent.md +1 -0
  5. package/lib/agents/playwright-test-planner.agent.md +2 -1
  6. package/lib/cli/reportActions.js +78 -0
  7. package/lib/cli/testActions.js +211 -0
  8. package/lib/common/index.js +2898 -0
  9. package/lib/common/index.js.txt +35 -0
  10. package/lib/errorContext.js +130 -0
  11. package/lib/index.js +258 -206
  12. package/lib/{isomorphic/testServerConnection.js → isomorphic.js} +70 -35
  13. package/lib/isomorphic.js.txt +9 -0
  14. package/lib/loader/loaderProcessEntry.js +34 -0
  15. package/lib/loader/loaderProcessEntry.js.txt +9 -0
  16. package/lib/matchers/expect.js +12988 -249
  17. package/lib/matchers/expect.js.LICENSE +693 -0
  18. package/lib/matchers/expect.js.txt +72 -0
  19. package/lib/mcp/test/browserBackend.js +49 -22
  20. package/lib/mcp/test/generatorTools.js +16 -16
  21. package/lib/mcp/test/plannerTools.js +25 -20
  22. package/lib/mcp/test/seed.js +7 -7
  23. package/lib/mcp/test/testBackend.js +30 -30
  24. package/lib/mcp/test/testContext.js +50 -33
  25. package/lib/mcp/test/testTools.js +15 -25
  26. package/lib/{internalsForTest.js → package.js} +13 -8
  27. package/lib/program.js +63 -263
  28. package/lib/runner/index.js +8339 -0
  29. package/lib/runner/index.js.txt +60 -0
  30. package/lib/transform/babelBundle.js +71002 -18
  31. package/lib/transform/babelBundle.js.LICENSE +2359 -0
  32. package/lib/transform/babelBundle.js.txt +325 -0
  33. package/lib/transform/esmLoader.js +5884 -30
  34. package/lib/transform/esmLoader.js.LICENSE +335 -0
  35. package/lib/transform/esmLoader.js.txt +55 -0
  36. package/lib/util.js +37 -34
  37. package/lib/worker/workerProcessEntry.js +3251 -0
  38. package/lib/worker/workerProcessEntry.js.txt +24 -0
  39. package/package.json +5 -16
  40. package/test.mjs +1 -0
  41. package/types/test.d.ts +172 -12
  42. package/types/testReporter.d.ts +7 -5
  43. package/lib/common/config.js +0 -282
  44. package/lib/common/configLoader.js +0 -344
  45. package/lib/common/esmLoaderHost.js +0 -104
  46. package/lib/common/expectBundle.js +0 -28
  47. package/lib/common/expectBundleImpl.js +0 -407
  48. package/lib/common/fixtures.js +0 -302
  49. package/lib/common/ipc.js +0 -60
  50. package/lib/common/poolBuilder.js +0 -85
  51. package/lib/common/process.js +0 -132
  52. package/lib/common/suiteUtils.js +0 -140
  53. package/lib/common/test.js +0 -321
  54. package/lib/common/testLoader.js +0 -101
  55. package/lib/common/testType.js +0 -298
  56. package/lib/common/validators.js +0 -68
  57. package/lib/fsWatcher.js +0 -67
  58. package/lib/isomorphic/events.js +0 -77
  59. package/lib/isomorphic/folders.js +0 -30
  60. package/lib/isomorphic/stringInternPool.js +0 -69
  61. package/lib/isomorphic/teleReceiver.js +0 -521
  62. package/lib/isomorphic/teleSuiteUpdater.js +0 -157
  63. package/lib/isomorphic/testServerInterface.js +0 -16
  64. package/lib/isomorphic/testTree.js +0 -329
  65. package/lib/isomorphic/types.d.js +0 -16
  66. package/lib/loader/loaderMain.js +0 -59
  67. package/lib/matchers/matcherHint.js +0 -44
  68. package/lib/matchers/matchers.js +0 -383
  69. package/lib/matchers/toBeTruthy.js +0 -75
  70. package/lib/matchers/toEqual.js +0 -100
  71. package/lib/matchers/toHaveURL.js +0 -101
  72. package/lib/matchers/toMatchAriaSnapshot.js +0 -159
  73. package/lib/matchers/toMatchSnapshot.js +0 -342
  74. package/lib/matchers/toMatchText.js +0 -99
  75. package/lib/mcp/browser/browserContextFactory.js +0 -329
  76. package/lib/mcp/browser/browserServerBackend.js +0 -84
  77. package/lib/mcp/browser/config.js +0 -421
  78. package/lib/mcp/browser/context.js +0 -244
  79. package/lib/mcp/browser/response.js +0 -278
  80. package/lib/mcp/browser/sessionLog.js +0 -75
  81. package/lib/mcp/browser/tab.js +0 -343
  82. package/lib/mcp/browser/tools/common.js +0 -65
  83. package/lib/mcp/browser/tools/console.js +0 -46
  84. package/lib/mcp/browser/tools/dialogs.js +0 -60
  85. package/lib/mcp/browser/tools/evaluate.js +0 -61
  86. package/lib/mcp/browser/tools/files.js +0 -58
  87. package/lib/mcp/browser/tools/form.js +0 -63
  88. package/lib/mcp/browser/tools/install.js +0 -72
  89. package/lib/mcp/browser/tools/keyboard.js +0 -107
  90. package/lib/mcp/browser/tools/mouse.js +0 -107
  91. package/lib/mcp/browser/tools/navigate.js +0 -71
  92. package/lib/mcp/browser/tools/network.js +0 -63
  93. package/lib/mcp/browser/tools/open.js +0 -57
  94. package/lib/mcp/browser/tools/pdf.js +0 -49
  95. package/lib/mcp/browser/tools/runCode.js +0 -78
  96. package/lib/mcp/browser/tools/screenshot.js +0 -93
  97. package/lib/mcp/browser/tools/snapshot.js +0 -173
  98. package/lib/mcp/browser/tools/tabs.js +0 -67
  99. package/lib/mcp/browser/tools/tool.js +0 -47
  100. package/lib/mcp/browser/tools/tracing.js +0 -74
  101. package/lib/mcp/browser/tools/utils.js +0 -94
  102. package/lib/mcp/browser/tools/verify.js +0 -143
  103. package/lib/mcp/browser/tools/wait.js +0 -63
  104. package/lib/mcp/browser/tools.js +0 -84
  105. package/lib/mcp/browser/watchdog.js +0 -44
  106. package/lib/mcp/config.d.js +0 -16
  107. package/lib/mcp/extension/cdpRelay.js +0 -351
  108. package/lib/mcp/extension/extensionContextFactory.js +0 -76
  109. package/lib/mcp/extension/protocol.js +0 -28
  110. package/lib/mcp/index.js +0 -61
  111. package/lib/mcp/log.js +0 -35
  112. package/lib/mcp/program.js +0 -111
  113. package/lib/mcp/sdk/exports.js +0 -28
  114. package/lib/mcp/sdk/http.js +0 -152
  115. package/lib/mcp/sdk/inProcessTransport.js +0 -71
  116. package/lib/mcp/sdk/server.js +0 -223
  117. package/lib/mcp/sdk/tool.js +0 -47
  118. package/lib/mcp/terminal/cli.js +0 -296
  119. package/lib/mcp/terminal/command.js +0 -56
  120. package/lib/mcp/terminal/commands.js +0 -333
  121. package/lib/mcp/terminal/daemon.js +0 -129
  122. package/lib/mcp/terminal/help.json +0 -32
  123. package/lib/mcp/terminal/helpGenerator.js +0 -88
  124. package/lib/mcp/terminal/socketConnection.js +0 -80
  125. package/lib/plugins/gitCommitInfoPlugin.js +0 -198
  126. package/lib/plugins/index.js +0 -28
  127. package/lib/plugins/webServerPlugin.js +0 -237
  128. package/lib/reporters/base.js +0 -634
  129. package/lib/reporters/blob.js +0 -138
  130. package/lib/reporters/dot.js +0 -99
  131. package/lib/reporters/empty.js +0 -32
  132. package/lib/reporters/github.js +0 -128
  133. package/lib/reporters/html.js +0 -633
  134. package/lib/reporters/internalReporter.js +0 -138
  135. package/lib/reporters/json.js +0 -254
  136. package/lib/reporters/junit.js +0 -232
  137. package/lib/reporters/line.js +0 -131
  138. package/lib/reporters/list.js +0 -253
  139. package/lib/reporters/listModeReporter.js +0 -69
  140. package/lib/reporters/markdown.js +0 -144
  141. package/lib/reporters/merge.js +0 -558
  142. package/lib/reporters/multiplexer.js +0 -112
  143. package/lib/reporters/reporterV2.js +0 -102
  144. package/lib/reporters/smoothdeploy.js +0 -333
  145. package/lib/reporters/teleEmitter.js +0 -317
  146. package/lib/reporters/versions/blobV1.js +0 -16
  147. package/lib/runner/dispatcher.js +0 -531
  148. package/lib/runner/failureTracker.js +0 -72
  149. package/lib/runner/lastRun.js +0 -77
  150. package/lib/runner/loadUtils.js +0 -334
  151. package/lib/runner/loaderHost.js +0 -89
  152. package/lib/runner/processHost.js +0 -180
  153. package/lib/runner/projectUtils.js +0 -241
  154. package/lib/runner/rebase.js +0 -189
  155. package/lib/runner/reporters.js +0 -140
  156. package/lib/runner/sigIntWatcher.js +0 -96
  157. package/lib/runner/storage.js +0 -91
  158. package/lib/runner/taskRunner.js +0 -127
  159. package/lib/runner/tasks.js +0 -410
  160. package/lib/runner/testGroups.js +0 -125
  161. package/lib/runner/testRunner.js +0 -398
  162. package/lib/runner/testServer.js +0 -269
  163. package/lib/runner/uiModeReporter.js +0 -30
  164. package/lib/runner/vcs.js +0 -72
  165. package/lib/runner/watchMode.js +0 -396
  166. package/lib/runner/workerHost.js +0 -104
  167. package/lib/third_party/pirates.js +0 -62
  168. package/lib/third_party/tsconfig-loader.js +0 -103
  169. package/lib/transform/babelBundleImpl.js +0 -461
  170. package/lib/transform/compilationCache.js +0 -274
  171. package/lib/transform/md.js +0 -221
  172. package/lib/transform/portTransport.js +0 -67
  173. package/lib/transform/transform.js +0 -303
  174. package/lib/utilsBundle.js +0 -50
  175. package/lib/utilsBundleImpl.js +0 -103
  176. package/lib/worker/fixtureRunner.js +0 -262
  177. package/lib/worker/testInfo.js +0 -536
  178. package/lib/worker/testTracing.js +0 -345
  179. package/lib/worker/timeoutManager.js +0 -174
  180. package/lib/worker/util.js +0 -31
  181. package/lib/worker/workerMain.js +0 -530
  182. /package/lib/{common/globals.js → globals.js} +0 -0
@@ -1,278 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var response_exports = {};
30
- __export(response_exports, {
31
- Response: () => Response,
32
- parseResponse: () => parseResponse,
33
- renderTabMarkdown: () => renderTabMarkdown,
34
- renderTabsMarkdown: () => renderTabsMarkdown,
35
- requestDebug: () => requestDebug
36
- });
37
- module.exports = __toCommonJS(response_exports);
38
- var import_fs = __toESM(require("fs"));
39
- var import_path = __toESM(require("path"));
40
- var import_utilsBundle = require("playwright-core/lib/utilsBundle");
41
- var import_tab = require("./tab");
42
- var import_utils = require("./tools/utils");
43
- const requestDebug = (0, import_utilsBundle.debug)("pw:mcp:request");
44
- class Response {
45
- constructor(ordinal, context, toolName, toolArgs) {
46
- this._results = [];
47
- this._errors = [];
48
- this._code = [];
49
- this._images = [];
50
- this._includeSnapshot = "none";
51
- this._ordinal = ordinal;
52
- this._context = context;
53
- this.toolName = toolName;
54
- this.toolArgs = toolArgs;
55
- }
56
- static {
57
- this._ordinal = 0;
58
- }
59
- static create(context, toolName, toolArgs) {
60
- return new Response(++Response._ordinal, context, toolName, toolArgs);
61
- }
62
- addTextResult(result) {
63
- this._results.push({ text: result });
64
- }
65
- async addResult(result) {
66
- if (result.data && !result.suggestedFilename)
67
- result.suggestedFilename = (0, import_utils.dateAsFileName)(result.ext ?? "bin");
68
- if (this._context.config.outputMode === "file") {
69
- if (!result.suggestedFilename)
70
- result.suggestedFilename = (0, import_utils.dateAsFileName)(result.ext ?? (result.text ? "txt" : "bin"));
71
- }
72
- const entry = { text: result.text, data: result.data, title: result.title };
73
- if (result.suggestedFilename)
74
- entry.filename = await this._context.outputFile(result.suggestedFilename, { origin: "llm", title: result.title ?? "Saved result" });
75
- this._results.push(entry);
76
- return { fileName: entry.filename };
77
- }
78
- addError(error) {
79
- this._errors.push(error);
80
- }
81
- addCode(code) {
82
- this._code.push(code);
83
- }
84
- addImage(image) {
85
- this._images.push(image);
86
- }
87
- setIncludeSnapshot() {
88
- this._includeSnapshot = this._context.config.snapshot.mode;
89
- }
90
- setIncludeFullSnapshot(includeSnapshotFileName) {
91
- this._includeSnapshot = "full";
92
- this._includeSnapshotFileName = includeSnapshotFileName;
93
- }
94
- async build() {
95
- const rootPath = this._context.firstRootPath();
96
- const sections = [];
97
- const addSection = (title) => {
98
- const section = { title, content: [] };
99
- sections.push(section);
100
- return section.content;
101
- };
102
- if (this._errors.length) {
103
- const text = addSection("Error");
104
- text.push("### Error");
105
- text.push(this._errors.join("\n"));
106
- }
107
- if (this._results.length) {
108
- const text = addSection("Result");
109
- for (const result of this._results) {
110
- if (result.filename) {
111
- text.push(`- [${result.title}](${rootPath ? import_path.default.relative(rootPath, result.filename) : result.filename})`);
112
- if (result.data)
113
- await import_fs.default.promises.writeFile(result.filename, result.data);
114
- else if (result.text)
115
- await import_fs.default.promises.writeFile(result.filename, this._redactText(result.text));
116
- } else if (result.text) {
117
- text.push(result.text);
118
- }
119
- }
120
- }
121
- if (this._context.config.codegen !== "none" && this._code.length) {
122
- const text = addSection("Ran Playwright code");
123
- text.push(...this._code);
124
- }
125
- const tabSnapshot = this._context.currentTab() ? await this._context.currentTabOrDie().captureSnapshot() : void 0;
126
- const tabHeaders = await Promise.all(this._context.tabs().map((tab) => tab.headerSnapshot()));
127
- if (tabHeaders.some((header) => header.changed)) {
128
- if (tabHeaders.length !== 1) {
129
- const text2 = addSection("Open tabs");
130
- text2.push(...renderTabsMarkdown(tabHeaders));
131
- }
132
- const text = addSection("Page");
133
- text.push(...renderTabMarkdown(tabHeaders[0]));
134
- }
135
- if (tabSnapshot?.modalStates.length) {
136
- const text = addSection("Modal state");
137
- text.push(...(0, import_tab.renderModalStates)(tabSnapshot.modalStates));
138
- }
139
- if (tabSnapshot && this._includeSnapshot === "full") {
140
- let fileName;
141
- if (this._includeSnapshotFileName)
142
- fileName = await this._context.outputFile(this._includeSnapshotFileName, { origin: "llm", title: "Saved snapshot" });
143
- else if (this._context.config.outputMode === "file")
144
- fileName = await this._context.outputFile(`snapshot-${this._ordinal}.yml`, { origin: "code", title: "Saved snapshot" });
145
- if (fileName) {
146
- await import_fs.default.promises.writeFile(fileName, tabSnapshot.ariaSnapshot);
147
- const text = addSection("Snapshot");
148
- text.push(`- File: ${rootPath ? import_path.default.relative(rootPath, fileName) : fileName}`);
149
- } else {
150
- const text = addSection("Snapshot");
151
- text.push("```yaml");
152
- text.push(tabSnapshot.ariaSnapshot);
153
- text.push("```");
154
- }
155
- }
156
- if (tabSnapshot && this._includeSnapshot === "incremental") {
157
- const text = addSection("Snapshot");
158
- text.push("```yaml");
159
- if (tabSnapshot.ariaSnapshotDiff !== void 0)
160
- text.push(tabSnapshot.ariaSnapshotDiff);
161
- else
162
- text.push(tabSnapshot.ariaSnapshot);
163
- text.push("```");
164
- }
165
- if (tabSnapshot?.events.filter((event) => event.type !== "request").length) {
166
- const text = addSection("Events");
167
- for (const event of tabSnapshot.events) {
168
- if (event.type === "console") {
169
- if ((0, import_tab.shouldIncludeMessage)(this._context.config.console.level, event.message.type))
170
- text.push(`- ${trimMiddle(event.message.toString(), 100)}`);
171
- } else if (event.type === "download-start") {
172
- text.push(`- Downloading file ${event.download.download.suggestedFilename()} ...`);
173
- } else if (event.type === "download-finish") {
174
- text.push(`- Downloaded file ${event.download.download.suggestedFilename()} to "${rootPath ? import_path.default.relative(rootPath, event.download.outputFile) : event.download.outputFile}"`);
175
- }
176
- }
177
- }
178
- const allText = sections.flatMap((section) => {
179
- const content2 = [];
180
- content2.push(`### ${section.title}`);
181
- content2.push(...section.content);
182
- content2.push("");
183
- return content2;
184
- }).join("\n");
185
- const content = [
186
- {
187
- type: "text",
188
- text: this._redactText(allText)
189
- }
190
- ];
191
- if (this._context.config.imageResponses !== "omit") {
192
- for (const image of this._images)
193
- content.push({ type: "image", data: image.data.toString("base64"), mimeType: image.contentType });
194
- }
195
- return {
196
- content,
197
- ...this._errors.length > 0 ? { isError: true } : {}
198
- };
199
- }
200
- _redactText(text) {
201
- for (const [secretName, secretValue] of Object.entries(this._context.config.secrets ?? {}))
202
- text = text.replaceAll(secretValue, `<secret>${secretName}</secret>`);
203
- return text;
204
- }
205
- }
206
- function renderTabMarkdown(tab) {
207
- const lines = [`- Page URL: ${tab.url}`];
208
- if (tab.title)
209
- lines.push(`- Page Title: ${tab.title}`);
210
- return lines;
211
- }
212
- function renderTabsMarkdown(tabs) {
213
- if (!tabs.length)
214
- return ['No open tabs. Use the "browser_navigate" tool to navigate to a page first.'];
215
- const lines = [];
216
- for (let i = 0; i < tabs.length; i++) {
217
- const tab = tabs[i];
218
- const current = tab.current ? " (current)" : "";
219
- lines.push(`- ${i}:${current} [${tab.title}](${tab.url})`);
220
- }
221
- return lines;
222
- }
223
- function trimMiddle(text, maxLength) {
224
- if (text.length <= maxLength)
225
- return text;
226
- return text.slice(0, Math.floor(maxLength / 2)) + "..." + text.slice(-3 - Math.floor(maxLength / 2));
227
- }
228
- function parseSections(text) {
229
- const sections = /* @__PURE__ */ new Map();
230
- const sectionHeaders = text.split(/^### /m).slice(1);
231
- for (const section of sectionHeaders) {
232
- const firstNewlineIndex = section.indexOf("\n");
233
- if (firstNewlineIndex === -1)
234
- continue;
235
- const sectionName = section.substring(0, firstNewlineIndex);
236
- const sectionContent = section.substring(firstNewlineIndex + 1).trim();
237
- sections.set(sectionName, sectionContent);
238
- }
239
- return sections;
240
- }
241
- function parseResponse(response) {
242
- if (response.content?.[0].type !== "text")
243
- return void 0;
244
- const text = response.content[0].text;
245
- const sections = parseSections(text);
246
- const error = sections.get("Error");
247
- const result = sections.get("Result");
248
- const code = sections.get("Ran Playwright code");
249
- const tabs = sections.get("Open tabs");
250
- const page = sections.get("Page");
251
- const snapshot = sections.get("Snapshot");
252
- const events = sections.get("Events");
253
- const modalState = sections.get("Modal state");
254
- const codeNoFrame = code?.replace(/^```js\n/, "").replace(/\n```$/, "");
255
- const isError = response.isError;
256
- const attachments = response.content.length > 1 ? response.content.slice(1) : void 0;
257
- return {
258
- result,
259
- error,
260
- code: codeNoFrame,
261
- tabs,
262
- page,
263
- snapshot,
264
- events,
265
- modalState,
266
- isError,
267
- attachments,
268
- text
269
- };
270
- }
271
- // Annotate the CommonJS export names for ESM import in node:
272
- 0 && (module.exports = {
273
- Response,
274
- parseResponse,
275
- renderTabMarkdown,
276
- renderTabsMarkdown,
277
- requestDebug
278
- });
@@ -1,75 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var sessionLog_exports = {};
30
- __export(sessionLog_exports, {
31
- SessionLog: () => SessionLog
32
- });
33
- module.exports = __toCommonJS(sessionLog_exports);
34
- var import_fs = __toESM(require("fs"));
35
- var import_path = __toESM(require("path"));
36
- var import_config = require("./config");
37
- var import_response = require("./response");
38
- class SessionLog {
39
- constructor(sessionFolder) {
40
- this._sessionFileQueue = Promise.resolve();
41
- this._folder = sessionFolder;
42
- this._file = import_path.default.join(this._folder, "session.md");
43
- }
44
- static async create(config, clientInfo) {
45
- const sessionFolder = await (0, import_config.outputFile)(config, clientInfo, `session-${Date.now()}`, { origin: "code", title: "Saving session" });
46
- await import_fs.default.promises.mkdir(sessionFolder, { recursive: true });
47
- console.error(`Session: ${sessionFolder}`);
48
- return new SessionLog(sessionFolder);
49
- }
50
- logResponse(toolName, toolArgs, responseObject) {
51
- const parsed = (0, import_response.parseResponse)(responseObject);
52
- if (parsed)
53
- delete parsed.text;
54
- const lines = [""];
55
- lines.push(
56
- `### Tool call: ${toolName}`,
57
- `- Args`,
58
- "```json",
59
- JSON.stringify(toolArgs, null, 2),
60
- "```"
61
- );
62
- if (parsed) {
63
- lines.push(`- Result`);
64
- lines.push("```json");
65
- lines.push(JSON.stringify(parsed, null, 2));
66
- lines.push("```");
67
- }
68
- lines.push("");
69
- this._sessionFileQueue = this._sessionFileQueue.then(() => import_fs.default.promises.appendFile(this._file, lines.join("\n")));
70
- }
71
- }
72
- // Annotate the CommonJS export names for ESM import in node:
73
- 0 && (module.exports = {
74
- SessionLog
75
- });
@@ -1,343 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var tab_exports = {};
20
- __export(tab_exports, {
21
- Tab: () => Tab,
22
- TabEvents: () => TabEvents,
23
- renderModalStates: () => renderModalStates,
24
- shouldIncludeMessage: () => shouldIncludeMessage
25
- });
26
- module.exports = __toCommonJS(tab_exports);
27
- var import_events = require("events");
28
- var import_utils = require("playwright-core/lib/utils");
29
- var import_utils2 = require("./tools/utils");
30
- var import_log = require("../log");
31
- var import_dialogs = require("./tools/dialogs");
32
- var import_files = require("./tools/files");
33
- var import_transform = require("../../transform/transform");
34
- const TabEvents = {
35
- modalState: "modalState"
36
- };
37
- class Tab extends import_events.EventEmitter {
38
- constructor(context, page, onPageClose) {
39
- super();
40
- this._lastHeader = { title: "about:blank", url: "about:blank", current: false };
41
- this._consoleMessages = [];
42
- this._downloads = [];
43
- this._requests = /* @__PURE__ */ new Set();
44
- this._modalStates = [];
45
- this._needsFullSnapshot = false;
46
- this._eventEntries = [];
47
- this._recentEventEntries = [];
48
- this.context = context;
49
- this.page = page;
50
- this._onPageClose = onPageClose;
51
- page.on("console", (event) => this._handleConsoleMessage(messageToConsoleMessage(event)));
52
- page.on("pageerror", (error) => this._handleConsoleMessage(pageErrorToConsoleMessage(error)));
53
- page.on("request", (request) => this._handleRequest(request));
54
- page.on("close", () => this._onClose());
55
- page.on("filechooser", (chooser) => {
56
- this.setModalState({
57
- type: "fileChooser",
58
- description: "File chooser",
59
- fileChooser: chooser,
60
- clearedBy: import_files.uploadFile.schema.name
61
- });
62
- });
63
- page.on("dialog", (dialog) => this._dialogShown(dialog));
64
- page.on("download", (download) => {
65
- void this._downloadStarted(download);
66
- });
67
- page.setDefaultNavigationTimeout(this.context.config.timeouts.navigation);
68
- page.setDefaultTimeout(this.context.config.timeouts.action);
69
- page[tabSymbol] = this;
70
- this._initializedPromise = this._initialize();
71
- }
72
- static forPage(page) {
73
- return page[tabSymbol];
74
- }
75
- static async collectConsoleMessages(page) {
76
- const result = [];
77
- const messages = await page.consoleMessages().catch(() => []);
78
- for (const message of messages)
79
- result.push(messageToConsoleMessage(message));
80
- const errors = await page.pageErrors().catch(() => []);
81
- for (const error of errors)
82
- result.push(pageErrorToConsoleMessage(error));
83
- return result;
84
- }
85
- async _initialize() {
86
- for (const message of await Tab.collectConsoleMessages(this.page))
87
- this._handleConsoleMessage(message);
88
- const requests = await this.page.requests().catch(() => []);
89
- for (const request of requests)
90
- this._requests.add(request);
91
- for (const initPage of this.context.config.browser.initPage || []) {
92
- try {
93
- const { default: func } = await (0, import_transform.requireOrImport)(initPage);
94
- await func({ page: this.page });
95
- } catch (e) {
96
- (0, import_log.logUnhandledError)(e);
97
- }
98
- }
99
- }
100
- modalStates() {
101
- return this._modalStates;
102
- }
103
- setModalState(modalState) {
104
- this._modalStates.push(modalState);
105
- this.emit(TabEvents.modalState, modalState);
106
- }
107
- clearModalState(modalState) {
108
- this._modalStates = this._modalStates.filter((state) => state !== modalState);
109
- }
110
- _dialogShown(dialog) {
111
- this.setModalState({
112
- type: "dialog",
113
- description: `"${dialog.type()}" dialog with message "${dialog.message()}"`,
114
- dialog,
115
- clearedBy: import_dialogs.handleDialog.schema.name
116
- });
117
- }
118
- async _downloadStarted(download) {
119
- const entry = {
120
- download,
121
- finished: false,
122
- outputFile: await this.context.outputFile(download.suggestedFilename(), { origin: "web", title: "Saving download" })
123
- };
124
- this._downloads.push(entry);
125
- this._addLogEntry({ type: "download-start", wallTime: Date.now(), download: entry });
126
- await download.saveAs(entry.outputFile);
127
- entry.finished = true;
128
- this._addLogEntry({ type: "download-finish", wallTime: Date.now(), download: entry });
129
- }
130
- _clearCollectedArtifacts() {
131
- this._consoleMessages.length = 0;
132
- this._downloads.length = 0;
133
- this._requests.clear();
134
- this._eventEntries.length = 0;
135
- this._recentEventEntries.length = 0;
136
- }
137
- _handleRequest(request) {
138
- this._requests.add(request);
139
- this._addLogEntry({ type: "request", wallTime: Date.now(), request });
140
- }
141
- _handleConsoleMessage(message) {
142
- this._consoleMessages.push(message);
143
- this._addLogEntry({ type: "console", wallTime: Date.now(), message });
144
- }
145
- _addLogEntry(entry) {
146
- this._eventEntries.push(entry);
147
- this._recentEventEntries.push(entry);
148
- }
149
- _onClose() {
150
- this._clearCollectedArtifacts();
151
- this._onPageClose(this);
152
- }
153
- async headerSnapshot() {
154
- let title;
155
- await this._raceAgainstModalStates(async () => {
156
- title = await (0, import_utils2.callOnPageNoTrace)(this.page, (page) => page.title());
157
- });
158
- if (this._lastHeader.title !== title || this._lastHeader.url !== this.page.url() || this._lastHeader.current !== this.isCurrentTab()) {
159
- this._lastHeader = { title: title ?? "", url: this.page.url(), current: this.isCurrentTab() };
160
- return { ...this._lastHeader, changed: true };
161
- }
162
- return { ...this._lastHeader, changed: false };
163
- }
164
- isCurrentTab() {
165
- return this === this.context.currentTab();
166
- }
167
- async waitForLoadState(state, options) {
168
- await this._initializedPromise;
169
- await (0, import_utils2.callOnPageNoTrace)(this.page, (page) => page.waitForLoadState(state, options).catch(import_log.logUnhandledError));
170
- }
171
- async navigate(url) {
172
- await this._initializedPromise;
173
- this._clearCollectedArtifacts();
174
- const { promise: downloadEvent, abort: abortDownloadEvent } = (0, import_utils2.eventWaiter)(this.page, "download", 3e3);
175
- try {
176
- await this.page.goto(url, { waitUntil: "domcontentloaded" });
177
- abortDownloadEvent();
178
- } catch (_e) {
179
- const e = _e;
180
- const mightBeDownload = e.message.includes("net::ERR_ABORTED") || e.message.includes("Download is starting");
181
- if (!mightBeDownload)
182
- throw e;
183
- const download = await downloadEvent;
184
- if (!download)
185
- throw e;
186
- await new Promise((resolve) => setTimeout(resolve, 500));
187
- return;
188
- }
189
- await this.waitForLoadState("load", { timeout: 5e3 });
190
- }
191
- async consoleMessages(level) {
192
- await this._initializedPromise;
193
- return this._consoleMessages.filter((message) => shouldIncludeMessage(level, message.type));
194
- }
195
- async requests() {
196
- await this._initializedPromise;
197
- return this._requests;
198
- }
199
- async captureSnapshot() {
200
- await this._initializedPromise;
201
- let tabSnapshot;
202
- const modalStates = await this._raceAgainstModalStates(async () => {
203
- const snapshot = await this.page._snapshotForAI({ track: "response" });
204
- tabSnapshot = {
205
- ariaSnapshot: snapshot.full,
206
- ariaSnapshotDiff: this._needsFullSnapshot ? void 0 : snapshot.incremental,
207
- modalStates: [],
208
- events: []
209
- };
210
- });
211
- if (tabSnapshot) {
212
- tabSnapshot.events = this._recentEventEntries;
213
- this._recentEventEntries = [];
214
- }
215
- this._needsFullSnapshot = !tabSnapshot;
216
- return tabSnapshot ?? {
217
- ariaSnapshot: "",
218
- ariaSnapshotDiff: "",
219
- modalStates,
220
- events: []
221
- };
222
- }
223
- _javaScriptBlocked() {
224
- return this._modalStates.some((state) => state.type === "dialog");
225
- }
226
- async _raceAgainstModalStates(action) {
227
- if (this.modalStates().length)
228
- return this.modalStates();
229
- const promise = new import_utils.ManualPromise();
230
- const listener = (modalState) => promise.resolve([modalState]);
231
- this.once(TabEvents.modalState, listener);
232
- return await Promise.race([
233
- action().then(() => {
234
- this.off(TabEvents.modalState, listener);
235
- return [];
236
- }),
237
- promise
238
- ]);
239
- }
240
- async waitForCompletion(callback) {
241
- await this._initializedPromise;
242
- await this._raceAgainstModalStates(() => (0, import_utils2.waitForCompletion)(this, callback));
243
- }
244
- async refLocator(params) {
245
- await this._initializedPromise;
246
- return (await this.refLocators([params]))[0];
247
- }
248
- async refLocators(params) {
249
- await this._initializedPromise;
250
- return Promise.all(params.map(async (param) => {
251
- try {
252
- let locator = this.page.locator(`aria-ref=${param.ref}`);
253
- if (param.element)
254
- locator = locator.describe(param.element);
255
- const { resolvedSelector } = await locator._resolveSelector();
256
- return { locator, resolved: (0, import_utils.asLocator)("javascript", resolvedSelector) };
257
- } catch (e) {
258
- throw new Error(`Ref ${param.ref} not found in the current page snapshot. Try capturing new snapshot.`);
259
- }
260
- }));
261
- }
262
- async waitForTimeout(time) {
263
- if (this._javaScriptBlocked()) {
264
- await new Promise((f) => setTimeout(f, time));
265
- return;
266
- }
267
- await (0, import_utils2.callOnPageNoTrace)(this.page, (page) => {
268
- return page.evaluate(() => new Promise((f) => setTimeout(f, 1e3))).catch(() => {
269
- });
270
- });
271
- }
272
- }
273
- function messageToConsoleMessage(message) {
274
- return {
275
- type: message.type(),
276
- text: message.text(),
277
- toString: () => `[${message.type().toUpperCase()}] ${message.text()} @ ${message.location().url}:${message.location().lineNumber}`
278
- };
279
- }
280
- function pageErrorToConsoleMessage(errorOrValue) {
281
- if (errorOrValue instanceof Error) {
282
- return {
283
- type: "error",
284
- text: errorOrValue.message,
285
- toString: () => errorOrValue.stack || errorOrValue.message
286
- };
287
- }
288
- return {
289
- type: "error",
290
- text: String(errorOrValue),
291
- toString: () => String(errorOrValue)
292
- };
293
- }
294
- function renderModalStates(modalStates) {
295
- const result = [];
296
- if (modalStates.length === 0)
297
- result.push("- There is no modal state present");
298
- for (const state of modalStates)
299
- result.push(`- [${state.description}]: can be handled by the "${state.clearedBy}" tool`);
300
- return result;
301
- }
302
- const consoleMessageLevels = ["error", "warning", "info", "debug"];
303
- function shouldIncludeMessage(thresholdLevel, type) {
304
- const messageLevel = consoleLevelForMessageType(type);
305
- return consoleMessageLevels.indexOf(messageLevel) <= consoleMessageLevels.indexOf(thresholdLevel);
306
- }
307
- function consoleLevelForMessageType(type) {
308
- switch (type) {
309
- case "assert":
310
- case "error":
311
- return "error";
312
- case "warning":
313
- return "warning";
314
- case "count":
315
- case "dir":
316
- case "dirxml":
317
- case "info":
318
- case "log":
319
- case "table":
320
- case "time":
321
- case "timeEnd":
322
- return "info";
323
- case "clear":
324
- case "debug":
325
- case "endGroup":
326
- case "profile":
327
- case "profileEnd":
328
- case "startGroup":
329
- case "startGroupCollapsed":
330
- case "trace":
331
- return "debug";
332
- default:
333
- return "info";
334
- }
335
- }
336
- const tabSymbol = Symbol("tabSymbol");
337
- // Annotate the CommonJS export names for ESM import in node:
338
- 0 && (module.exports = {
339
- Tab,
340
- TabEvents,
341
- renderModalStates,
342
- shouldIncludeMessage
343
- });