@scoutqa/playwright 1.58.0-fork.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.
- package/ThirdPartyNotices.txt +3919 -0
- package/cli.js +19 -0
- package/index.d.ts +17 -0
- package/index.js +17 -0
- package/index.mjs +18 -0
- package/jsx-runtime.js +42 -0
- package/jsx-runtime.mjs +21 -0
- package/lib/agents/agentParser.js +89 -0
- package/lib/agents/copilot-setup-steps.yml +34 -0
- package/lib/agents/generateAgents.js +348 -0
- package/lib/agents/playwright-test-coverage.prompt.md +31 -0
- package/lib/agents/playwright-test-generate.prompt.md +8 -0
- package/lib/agents/playwright-test-generator.agent.md +88 -0
- package/lib/agents/playwright-test-heal.prompt.md +6 -0
- package/lib/agents/playwright-test-healer.agent.md +55 -0
- package/lib/agents/playwright-test-plan.prompt.md +9 -0
- package/lib/agents/playwright-test-planner.agent.md +73 -0
- package/lib/common/config.js +281 -0
- package/lib/common/configLoader.js +344 -0
- package/lib/common/esmLoaderHost.js +104 -0
- package/lib/common/expectBundle.js +43 -0
- package/lib/common/expectBundleImpl.js +407 -0
- package/lib/common/fixtures.js +302 -0
- package/lib/common/globals.js +58 -0
- package/lib/common/ipc.js +60 -0
- package/lib/common/poolBuilder.js +85 -0
- package/lib/common/process.js +132 -0
- package/lib/common/suiteUtils.js +140 -0
- package/lib/common/test.js +322 -0
- package/lib/common/testLoader.js +101 -0
- package/lib/common/testType.js +298 -0
- package/lib/common/validators.js +68 -0
- package/lib/fsWatcher.js +67 -0
- package/lib/index.js +721 -0
- package/lib/internalsForTest.js +42 -0
- package/lib/isomorphic/events.js +77 -0
- package/lib/isomorphic/folders.js +30 -0
- package/lib/isomorphic/stringInternPool.js +69 -0
- package/lib/isomorphic/teleReceiver.js +523 -0
- package/lib/isomorphic/teleSuiteUpdater.js +157 -0
- package/lib/isomorphic/testServerConnection.js +225 -0
- package/lib/isomorphic/testServerInterface.js +16 -0
- package/lib/isomorphic/testTree.js +329 -0
- package/lib/isomorphic/types.d.js +16 -0
- package/lib/loader/loaderMain.js +59 -0
- package/lib/matchers/expect.js +324 -0
- package/lib/matchers/matcherHint.js +87 -0
- package/lib/matchers/matchers.js +382 -0
- package/lib/matchers/toBeTruthy.js +73 -0
- package/lib/matchers/toEqual.js +99 -0
- package/lib/matchers/toHaveURL.js +102 -0
- package/lib/matchers/toMatchAriaSnapshot.js +159 -0
- package/lib/matchers/toMatchSnapshot.js +341 -0
- package/lib/matchers/toMatchText.js +99 -0
- package/lib/mcp/browser/actions.d.js +16 -0
- package/lib/mcp/browser/browserContextFactory.js +321 -0
- package/lib/mcp/browser/browserServerBackend.js +77 -0
- package/lib/mcp/browser/config.js +418 -0
- package/lib/mcp/browser/context.js +285 -0
- package/lib/mcp/browser/response.js +352 -0
- package/lib/mcp/browser/sessionLog.js +160 -0
- package/lib/mcp/browser/tab.js +328 -0
- package/lib/mcp/browser/tools/common.js +63 -0
- package/lib/mcp/browser/tools/console.js +44 -0
- package/lib/mcp/browser/tools/dialogs.js +60 -0
- package/lib/mcp/browser/tools/evaluate.js +59 -0
- package/lib/mcp/browser/tools/files.js +58 -0
- package/lib/mcp/browser/tools/form.js +63 -0
- package/lib/mcp/browser/tools/install.js +69 -0
- package/lib/mcp/browser/tools/keyboard.js +84 -0
- package/lib/mcp/browser/tools/mouse.js +107 -0
- package/lib/mcp/browser/tools/navigate.js +62 -0
- package/lib/mcp/browser/tools/network.js +60 -0
- package/lib/mcp/browser/tools/pdf.js +48 -0
- package/lib/mcp/browser/tools/runCode.js +77 -0
- package/lib/mcp/browser/tools/screenshot.js +105 -0
- package/lib/mcp/browser/tools/snapshot.js +191 -0
- package/lib/mcp/browser/tools/tabs.js +67 -0
- package/lib/mcp/browser/tools/tool.js +50 -0
- package/lib/mcp/browser/tools/tracing.js +74 -0
- package/lib/mcp/browser/tools/utils.js +94 -0
- package/lib/mcp/browser/tools/verify.js +143 -0
- package/lib/mcp/browser/tools/wait.js +63 -0
- package/lib/mcp/browser/tools.js +82 -0
- package/lib/mcp/browser/watchdog.js +44 -0
- package/lib/mcp/config.d.js +16 -0
- package/lib/mcp/extension/cdpRelay.js +351 -0
- package/lib/mcp/extension/extensionContextFactory.js +76 -0
- package/lib/mcp/extension/protocol.js +28 -0
- package/lib/mcp/index.js +61 -0
- package/lib/mcp/log.js +35 -0
- package/lib/mcp/program.js +93 -0
- package/lib/mcp/sdk/exports.js +28 -0
- package/lib/mcp/sdk/http.js +152 -0
- package/lib/mcp/sdk/inProcessTransport.js +71 -0
- package/lib/mcp/sdk/server.js +207 -0
- package/lib/mcp/sdk/tool.js +47 -0
- package/lib/mcp/test/browserBackend.js +98 -0
- package/lib/mcp/test/generatorTools.js +122 -0
- package/lib/mcp/test/plannerTools.js +144 -0
- package/lib/mcp/test/seed.js +82 -0
- package/lib/mcp/test/streams.js +44 -0
- package/lib/mcp/test/testBackend.js +99 -0
- package/lib/mcp/test/testContext.js +279 -0
- package/lib/mcp/test/testTool.js +30 -0
- package/lib/mcp/test/testTools.js +108 -0
- package/lib/plugins/gitCommitInfoPlugin.js +198 -0
- package/lib/plugins/index.js +28 -0
- package/lib/plugins/webServerPlugin.js +237 -0
- package/lib/program.js +417 -0
- package/lib/reporters/base.js +609 -0
- package/lib/reporters/blob.js +139 -0
- package/lib/reporters/dot.js +82 -0
- package/lib/reporters/empty.js +32 -0
- package/lib/reporters/github.js +128 -0
- package/lib/reporters/html.js +623 -0
- package/lib/reporters/internalReporter.js +140 -0
- package/lib/reporters/json.js +255 -0
- package/lib/reporters/junit.js +232 -0
- package/lib/reporters/line.js +113 -0
- package/lib/reporters/list.js +231 -0
- package/lib/reporters/listModeReporter.js +69 -0
- package/lib/reporters/markdown.js +144 -0
- package/lib/reporters/merge.js +546 -0
- package/lib/reporters/multiplexer.js +112 -0
- package/lib/reporters/reporterV2.js +102 -0
- package/lib/reporters/teleEmitter.js +319 -0
- package/lib/reporters/versions/blobV1.js +16 -0
- package/lib/runner/dispatcher.js +533 -0
- package/lib/runner/failureTracker.js +72 -0
- package/lib/runner/lastRun.js +77 -0
- package/lib/runner/loadUtils.js +334 -0
- package/lib/runner/loaderHost.js +89 -0
- package/lib/runner/processHost.js +180 -0
- package/lib/runner/projectUtils.js +241 -0
- package/lib/runner/rebase.js +189 -0
- package/lib/runner/reporters.js +138 -0
- package/lib/runner/sigIntWatcher.js +96 -0
- package/lib/runner/storage.js +91 -0
- package/lib/runner/taskRunner.js +127 -0
- package/lib/runner/tasks.js +410 -0
- package/lib/runner/testGroups.js +125 -0
- package/lib/runner/testRunner.js +398 -0
- package/lib/runner/testServer.js +269 -0
- package/lib/runner/uiModeReporter.js +30 -0
- package/lib/runner/vcs.js +72 -0
- package/lib/runner/watchMode.js +396 -0
- package/lib/runner/workerHost.js +104 -0
- package/lib/third_party/pirates.js +62 -0
- package/lib/third_party/tsconfig-loader.js +103 -0
- package/lib/transform/babelBundle.js +43 -0
- package/lib/transform/babelBundleImpl.js +461 -0
- package/lib/transform/babelHighlightUtils.js +63 -0
- package/lib/transform/compilationCache.js +272 -0
- package/lib/transform/esmLoader.js +103 -0
- package/lib/transform/portTransport.js +67 -0
- package/lib/transform/transform.js +296 -0
- package/lib/util.js +403 -0
- package/lib/utilsBundle.js +43 -0
- package/lib/utilsBundleImpl.js +100 -0
- package/lib/worker/fixtureRunner.js +258 -0
- package/lib/worker/testInfo.js +557 -0
- package/lib/worker/testTracing.js +345 -0
- package/lib/worker/timeoutManager.js +174 -0
- package/lib/worker/util.js +31 -0
- package/lib/worker/workerMain.js +529 -0
- package/package.json +72 -0
- package/test.d.ts +18 -0
- package/test.js +24 -0
- package/test.mjs +34 -0
- package/types/test.d.ts +10277 -0
- package/types/testReporter.d.ts +827 -0
|
@@ -0,0 +1,352 @@
|
|
|
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 response_exports = {};
|
|
20
|
+
__export(response_exports, {
|
|
21
|
+
RenderedResponse: () => RenderedResponse,
|
|
22
|
+
Response: () => Response,
|
|
23
|
+
parseResponse: () => parseResponse,
|
|
24
|
+
requestDebug: () => requestDebug
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(response_exports);
|
|
27
|
+
var import_utilsBundle = require("playwright-core/lib/utilsBundle");
|
|
28
|
+
var import_tab = require("./tab");
|
|
29
|
+
const requestDebug = (0, import_utilsBundle.debug)("pw:mcp:request");
|
|
30
|
+
class Response {
|
|
31
|
+
constructor(context, toolName, toolArgs) {
|
|
32
|
+
this._result = [];
|
|
33
|
+
this._code = [];
|
|
34
|
+
this._images = [];
|
|
35
|
+
this._files = [];
|
|
36
|
+
this._includeSnapshot = "none";
|
|
37
|
+
this._includeTabs = false;
|
|
38
|
+
this._includeMetaOnly = false;
|
|
39
|
+
this._context = context;
|
|
40
|
+
this.toolName = toolName;
|
|
41
|
+
this.toolArgs = toolArgs;
|
|
42
|
+
}
|
|
43
|
+
addResult(result) {
|
|
44
|
+
this._result.push(result);
|
|
45
|
+
}
|
|
46
|
+
addError(error) {
|
|
47
|
+
this._result.push(error);
|
|
48
|
+
this._isError = true;
|
|
49
|
+
}
|
|
50
|
+
isError() {
|
|
51
|
+
return this._isError;
|
|
52
|
+
}
|
|
53
|
+
result() {
|
|
54
|
+
return this._result.join("\n");
|
|
55
|
+
}
|
|
56
|
+
addCode(code) {
|
|
57
|
+
this._code.push(code);
|
|
58
|
+
}
|
|
59
|
+
code() {
|
|
60
|
+
return this._code.join("\n");
|
|
61
|
+
}
|
|
62
|
+
addImage(image) {
|
|
63
|
+
this._images.push(image);
|
|
64
|
+
}
|
|
65
|
+
images() {
|
|
66
|
+
return this._images;
|
|
67
|
+
}
|
|
68
|
+
async addFile(fileName, options) {
|
|
69
|
+
const resolvedFile = await this._context.outputFile(fileName, options);
|
|
70
|
+
this._files.push({ fileName: resolvedFile, title: options.reason });
|
|
71
|
+
return resolvedFile;
|
|
72
|
+
}
|
|
73
|
+
setIncludeSnapshot() {
|
|
74
|
+
this._includeSnapshot = this._context.config.snapshot.mode;
|
|
75
|
+
}
|
|
76
|
+
setIncludeFullSnapshot() {
|
|
77
|
+
this._includeSnapshot = "full";
|
|
78
|
+
}
|
|
79
|
+
setIncludeTabs() {
|
|
80
|
+
this._includeTabs = true;
|
|
81
|
+
}
|
|
82
|
+
setIncludeModalStates(modalStates) {
|
|
83
|
+
this._includeModalStates = modalStates;
|
|
84
|
+
}
|
|
85
|
+
setIncludeMetaOnly() {
|
|
86
|
+
this._includeMetaOnly = true;
|
|
87
|
+
}
|
|
88
|
+
async finish() {
|
|
89
|
+
if (this._tabSnapshot)
|
|
90
|
+
return;
|
|
91
|
+
if (this._includeSnapshot !== "none" && this._context.currentTab())
|
|
92
|
+
this._tabSnapshot = await this._context.currentTabOrDie().captureSnapshot();
|
|
93
|
+
for (const tab of this._context.tabs())
|
|
94
|
+
await tab.updateTitle();
|
|
95
|
+
}
|
|
96
|
+
tabSnapshot() {
|
|
97
|
+
return this._tabSnapshot;
|
|
98
|
+
}
|
|
99
|
+
logBegin() {
|
|
100
|
+
if (requestDebug.enabled)
|
|
101
|
+
requestDebug(this.toolName, this.toolArgs);
|
|
102
|
+
}
|
|
103
|
+
logEnd() {
|
|
104
|
+
if (requestDebug.enabled)
|
|
105
|
+
requestDebug(this.serialize());
|
|
106
|
+
}
|
|
107
|
+
render() {
|
|
108
|
+
const renderedResponse = new RenderedResponse();
|
|
109
|
+
if (this._result.length)
|
|
110
|
+
renderedResponse.results.push(...this._result);
|
|
111
|
+
if (this._code.length)
|
|
112
|
+
renderedResponse.code.push(...this._code);
|
|
113
|
+
if (this._includeSnapshot !== "none" || this._includeTabs) {
|
|
114
|
+
const tabsMarkdown = renderTabsMarkdown(this._context.tabs(), this._includeTabs);
|
|
115
|
+
if (tabsMarkdown.length)
|
|
116
|
+
renderedResponse.states.tabs = tabsMarkdown.join("\n");
|
|
117
|
+
}
|
|
118
|
+
if (this._tabSnapshot?.modalStates.length) {
|
|
119
|
+
const modalStatesMarkdown = (0, import_tab.renderModalStates)(this._tabSnapshot.modalStates);
|
|
120
|
+
renderedResponse.states.modal = modalStatesMarkdown.join("\n");
|
|
121
|
+
} else if (this._tabSnapshot) {
|
|
122
|
+
renderTabSnapshot(this._tabSnapshot, this._includeSnapshot, renderedResponse);
|
|
123
|
+
} else if (this._includeModalStates) {
|
|
124
|
+
const modalStatesMarkdown = (0, import_tab.renderModalStates)(this._includeModalStates);
|
|
125
|
+
renderedResponse.states.modal = modalStatesMarkdown.join("\n");
|
|
126
|
+
}
|
|
127
|
+
if (this._files.length) {
|
|
128
|
+
const lines = [];
|
|
129
|
+
for (const file of this._files)
|
|
130
|
+
lines.push(`- [${file.title}](${file.fileName})`);
|
|
131
|
+
renderedResponse.updates.push({ category: "files", content: lines.join("\n") });
|
|
132
|
+
}
|
|
133
|
+
return this._context.config.secrets ? renderedResponse.redact(this._context.config.secrets) : renderedResponse;
|
|
134
|
+
}
|
|
135
|
+
serialize(options = {}) {
|
|
136
|
+
const renderedResponse = this.render();
|
|
137
|
+
const includeMeta = options._meta && "dev.lowire/history" in options._meta && "dev.lowire/state" in options._meta;
|
|
138
|
+
const _meta = includeMeta ? renderedResponse.asMeta() : void 0;
|
|
139
|
+
const content = [
|
|
140
|
+
{
|
|
141
|
+
type: "text",
|
|
142
|
+
text: renderedResponse.asText(this._includeMetaOnly ? { categories: ["files"] } : void 0)
|
|
143
|
+
}
|
|
144
|
+
];
|
|
145
|
+
if (this._includeMetaOnly)
|
|
146
|
+
return { _meta, content, isError: this._isError };
|
|
147
|
+
if (this._context.config.imageResponses !== "omit") {
|
|
148
|
+
for (const image of this._images)
|
|
149
|
+
content.push({ type: "image", data: image.data.toString("base64"), mimeType: image.contentType });
|
|
150
|
+
}
|
|
151
|
+
return {
|
|
152
|
+
_meta,
|
|
153
|
+
content,
|
|
154
|
+
isError: this._isError
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
function renderTabSnapshot(tabSnapshot, includeSnapshot, response) {
|
|
159
|
+
if (tabSnapshot.consoleMessages.length) {
|
|
160
|
+
const lines2 = [];
|
|
161
|
+
for (const message of tabSnapshot.consoleMessages)
|
|
162
|
+
lines2.push(`- ${trim(message.toString(), 100)}`);
|
|
163
|
+
response.updates.push({ category: "console", content: lines2.join("\n") });
|
|
164
|
+
}
|
|
165
|
+
if (tabSnapshot.downloads.length) {
|
|
166
|
+
const lines2 = [];
|
|
167
|
+
for (const entry of tabSnapshot.downloads) {
|
|
168
|
+
if (entry.finished)
|
|
169
|
+
lines2.push(`- Downloaded file ${entry.download.suggestedFilename()} to ${entry.outputFile}`);
|
|
170
|
+
else
|
|
171
|
+
lines2.push(`- Downloading file ${entry.download.suggestedFilename()} ...`);
|
|
172
|
+
}
|
|
173
|
+
response.updates.push({ category: "downloads", content: lines2.join("\n") });
|
|
174
|
+
}
|
|
175
|
+
if (includeSnapshot === "incremental" && tabSnapshot.ariaSnapshotDiff === "") {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
const lines = [];
|
|
179
|
+
lines.push(`- Page URL: ${tabSnapshot.url}`);
|
|
180
|
+
lines.push(`- Page Title: ${tabSnapshot.title}`);
|
|
181
|
+
if (includeSnapshot !== "none") {
|
|
182
|
+
lines.push(`- Page Snapshot:`);
|
|
183
|
+
lines.push("```yaml");
|
|
184
|
+
if (includeSnapshot === "incremental" && tabSnapshot.ariaSnapshotDiff !== void 0)
|
|
185
|
+
lines.push(tabSnapshot.ariaSnapshotDiff);
|
|
186
|
+
else
|
|
187
|
+
lines.push(tabSnapshot.ariaSnapshot);
|
|
188
|
+
lines.push("```");
|
|
189
|
+
}
|
|
190
|
+
response.states.page = lines.join("\n");
|
|
191
|
+
}
|
|
192
|
+
function renderTabsMarkdown(tabs, force = false) {
|
|
193
|
+
if (tabs.length === 1 && !force)
|
|
194
|
+
return [];
|
|
195
|
+
if (!tabs.length)
|
|
196
|
+
return ['No open tabs. Use the "browser_navigate" tool to navigate to a page first.'];
|
|
197
|
+
const lines = [];
|
|
198
|
+
for (let i = 0; i < tabs.length; i++) {
|
|
199
|
+
const tab = tabs[i];
|
|
200
|
+
const current = tab.isCurrentTab() ? " (current)" : "";
|
|
201
|
+
lines.push(`- ${i}:${current} [${tab.lastTitle()}] (${tab.page.url()})`);
|
|
202
|
+
}
|
|
203
|
+
return lines;
|
|
204
|
+
}
|
|
205
|
+
function trim(text, maxLength) {
|
|
206
|
+
if (text.length <= maxLength)
|
|
207
|
+
return text;
|
|
208
|
+
return text.slice(0, maxLength) + "...";
|
|
209
|
+
}
|
|
210
|
+
class RenderedResponse {
|
|
211
|
+
constructor(copy) {
|
|
212
|
+
this.states = {};
|
|
213
|
+
this.updates = [];
|
|
214
|
+
this.results = [];
|
|
215
|
+
this.code = [];
|
|
216
|
+
if (copy) {
|
|
217
|
+
this.states = copy.states;
|
|
218
|
+
this.updates = copy.updates;
|
|
219
|
+
this.results = copy.results;
|
|
220
|
+
this.code = copy.code;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
asText(filter) {
|
|
224
|
+
const text = [];
|
|
225
|
+
if (this.results.length)
|
|
226
|
+
text.push(`### Result
|
|
227
|
+
${this.results.join("\n")}
|
|
228
|
+
`);
|
|
229
|
+
if (this.code.length)
|
|
230
|
+
text.push(`### Ran Playwright code
|
|
231
|
+
${this.code.join("\n")}
|
|
232
|
+
`);
|
|
233
|
+
for (const { category, content } of this.updates) {
|
|
234
|
+
if (filter && !filter.categories.includes(category))
|
|
235
|
+
continue;
|
|
236
|
+
if (!content.trim())
|
|
237
|
+
continue;
|
|
238
|
+
switch (category) {
|
|
239
|
+
case "console":
|
|
240
|
+
text.push(`### New console messages
|
|
241
|
+
${content}
|
|
242
|
+
`);
|
|
243
|
+
break;
|
|
244
|
+
case "downloads":
|
|
245
|
+
text.push(`### Downloads
|
|
246
|
+
${content}
|
|
247
|
+
`);
|
|
248
|
+
break;
|
|
249
|
+
case "files":
|
|
250
|
+
text.push(`### Files
|
|
251
|
+
${content}
|
|
252
|
+
`);
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
for (const [category, value] of Object.entries(this.states)) {
|
|
257
|
+
if (filter && !filter.categories.includes(category))
|
|
258
|
+
continue;
|
|
259
|
+
if (!value.trim())
|
|
260
|
+
continue;
|
|
261
|
+
switch (category) {
|
|
262
|
+
case "page":
|
|
263
|
+
text.push(`### Page state
|
|
264
|
+
${value}
|
|
265
|
+
`);
|
|
266
|
+
break;
|
|
267
|
+
case "tabs":
|
|
268
|
+
text.push(`### Open tabs
|
|
269
|
+
${value}
|
|
270
|
+
`);
|
|
271
|
+
break;
|
|
272
|
+
case "modal":
|
|
273
|
+
text.push(`### Modal state
|
|
274
|
+
${value}
|
|
275
|
+
`);
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return text.join("\n");
|
|
280
|
+
}
|
|
281
|
+
asMeta() {
|
|
282
|
+
const codeUpdate = this.code.length ? { category: "code", content: this.code.join("\n") } : void 0;
|
|
283
|
+
const resultUpdate = this.results.length ? { category: "result", content: this.results.join("\n") } : void 0;
|
|
284
|
+
const updates = [resultUpdate, codeUpdate, ...this.updates].filter(Boolean);
|
|
285
|
+
return {
|
|
286
|
+
"dev.lowire/history": updates,
|
|
287
|
+
"dev.lowire/state": { ...this.states }
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
redact(secrets) {
|
|
291
|
+
const redactText = (text) => {
|
|
292
|
+
for (const [secretName, secretValue] of Object.entries(secrets))
|
|
293
|
+
text = text.replaceAll(secretValue, `<secret>${secretName}</secret>`);
|
|
294
|
+
return text;
|
|
295
|
+
};
|
|
296
|
+
const updates = this.updates.map((update) => ({ ...update, content: redactText(update.content) }));
|
|
297
|
+
const results = this.results.map((result) => redactText(result));
|
|
298
|
+
const code = this.code.map((code2) => redactText(code2));
|
|
299
|
+
const states = Object.fromEntries(Object.entries(this.states).map(([key, value]) => [key, redactText(value)]));
|
|
300
|
+
return new RenderedResponse({ states, updates, results, code });
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
function parseSections(text) {
|
|
304
|
+
const sections = /* @__PURE__ */ new Map();
|
|
305
|
+
const sectionHeaders = text.split(/^### /m).slice(1);
|
|
306
|
+
for (const section of sectionHeaders) {
|
|
307
|
+
const firstNewlineIndex = section.indexOf("\n");
|
|
308
|
+
if (firstNewlineIndex === -1)
|
|
309
|
+
continue;
|
|
310
|
+
const sectionName = section.substring(0, firstNewlineIndex);
|
|
311
|
+
const sectionContent = section.substring(firstNewlineIndex + 1).trim();
|
|
312
|
+
sections.set(sectionName, sectionContent);
|
|
313
|
+
}
|
|
314
|
+
return sections;
|
|
315
|
+
}
|
|
316
|
+
function parseResponse(response) {
|
|
317
|
+
if (response.content?.[0].type !== "text")
|
|
318
|
+
return void 0;
|
|
319
|
+
const text = response.content[0].text;
|
|
320
|
+
const sections = parseSections(text);
|
|
321
|
+
const result = sections.get("Result");
|
|
322
|
+
const code = sections.get("Ran Playwright code");
|
|
323
|
+
const tabs = sections.get("Open tabs");
|
|
324
|
+
const pageState = sections.get("Page state");
|
|
325
|
+
const consoleMessages = sections.get("New console messages");
|
|
326
|
+
const modalState = sections.get("Modal state");
|
|
327
|
+
const downloads = sections.get("Downloads");
|
|
328
|
+
const files = sections.get("Files");
|
|
329
|
+
const codeNoFrame = code?.replace(/^```js\n/, "").replace(/\n```$/, "");
|
|
330
|
+
const isError = response.isError;
|
|
331
|
+
const attachments = response.content.slice(1);
|
|
332
|
+
return {
|
|
333
|
+
result,
|
|
334
|
+
code: codeNoFrame,
|
|
335
|
+
tabs,
|
|
336
|
+
pageState,
|
|
337
|
+
consoleMessages,
|
|
338
|
+
modalState,
|
|
339
|
+
downloads,
|
|
340
|
+
files,
|
|
341
|
+
isError,
|
|
342
|
+
attachments,
|
|
343
|
+
_meta: response._meta
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
347
|
+
0 && (module.exports = {
|
|
348
|
+
RenderedResponse,
|
|
349
|
+
Response,
|
|
350
|
+
parseResponse,
|
|
351
|
+
requestDebug
|
|
352
|
+
});
|
|
@@ -0,0 +1,160 @@
|
|
|
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_log = require("../log");
|
|
37
|
+
var import_config = require("./config");
|
|
38
|
+
class SessionLog {
|
|
39
|
+
constructor(sessionFolder) {
|
|
40
|
+
this._ordinal = 0;
|
|
41
|
+
this._pendingEntries = [];
|
|
42
|
+
this._sessionFileQueue = Promise.resolve();
|
|
43
|
+
this._folder = sessionFolder;
|
|
44
|
+
this._file = import_path.default.join(this._folder, "session.md");
|
|
45
|
+
}
|
|
46
|
+
static async create(config, clientInfo) {
|
|
47
|
+
const sessionFolder = await (0, import_config.outputFile)(config, clientInfo, `session-${Date.now()}`, { origin: "code", reason: "Saving session" });
|
|
48
|
+
await import_fs.default.promises.mkdir(sessionFolder, { recursive: true });
|
|
49
|
+
console.error(`Session: ${sessionFolder}`);
|
|
50
|
+
return new SessionLog(sessionFolder);
|
|
51
|
+
}
|
|
52
|
+
logResponse(response) {
|
|
53
|
+
const entry = {
|
|
54
|
+
timestamp: performance.now(),
|
|
55
|
+
toolCall: {
|
|
56
|
+
toolName: response.toolName,
|
|
57
|
+
toolArgs: response.toolArgs,
|
|
58
|
+
result: response.result(),
|
|
59
|
+
isError: response.isError()
|
|
60
|
+
},
|
|
61
|
+
code: response.code(),
|
|
62
|
+
tabSnapshot: response.tabSnapshot()
|
|
63
|
+
};
|
|
64
|
+
this._appendEntry(entry);
|
|
65
|
+
}
|
|
66
|
+
logUserAction(action, tab, code, isUpdate) {
|
|
67
|
+
code = code.trim();
|
|
68
|
+
if (isUpdate) {
|
|
69
|
+
const lastEntry = this._pendingEntries[this._pendingEntries.length - 1];
|
|
70
|
+
if (lastEntry?.userAction?.name === action.name) {
|
|
71
|
+
lastEntry.userAction = action;
|
|
72
|
+
lastEntry.code = code;
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (action.name === "navigate") {
|
|
77
|
+
const lastEntry = this._pendingEntries[this._pendingEntries.length - 1];
|
|
78
|
+
if (lastEntry?.tabSnapshot?.url === action.url)
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const entry = {
|
|
82
|
+
timestamp: performance.now(),
|
|
83
|
+
userAction: action,
|
|
84
|
+
code,
|
|
85
|
+
tabSnapshot: {
|
|
86
|
+
url: tab.page.url(),
|
|
87
|
+
title: "",
|
|
88
|
+
ariaSnapshot: action.ariaSnapshot || "",
|
|
89
|
+
modalStates: [],
|
|
90
|
+
consoleMessages: [],
|
|
91
|
+
downloads: []
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
this._appendEntry(entry);
|
|
95
|
+
}
|
|
96
|
+
_appendEntry(entry) {
|
|
97
|
+
this._pendingEntries.push(entry);
|
|
98
|
+
if (this._flushEntriesTimeout)
|
|
99
|
+
clearTimeout(this._flushEntriesTimeout);
|
|
100
|
+
this._flushEntriesTimeout = setTimeout(() => this._flushEntries(), 1e3);
|
|
101
|
+
}
|
|
102
|
+
async _flushEntries() {
|
|
103
|
+
clearTimeout(this._flushEntriesTimeout);
|
|
104
|
+
const entries = this._pendingEntries;
|
|
105
|
+
this._pendingEntries = [];
|
|
106
|
+
const lines = [""];
|
|
107
|
+
for (const entry of entries) {
|
|
108
|
+
const ordinal = (++this._ordinal).toString().padStart(3, "0");
|
|
109
|
+
if (entry.toolCall) {
|
|
110
|
+
lines.push(
|
|
111
|
+
`### Tool call: ${entry.toolCall.toolName}`,
|
|
112
|
+
`- Args`,
|
|
113
|
+
"```json",
|
|
114
|
+
JSON.stringify(entry.toolCall.toolArgs, null, 2),
|
|
115
|
+
"```"
|
|
116
|
+
);
|
|
117
|
+
if (entry.toolCall.result) {
|
|
118
|
+
lines.push(
|
|
119
|
+
entry.toolCall.isError ? `- Error` : `- Result`,
|
|
120
|
+
"```",
|
|
121
|
+
entry.toolCall.result,
|
|
122
|
+
"```"
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (entry.userAction) {
|
|
127
|
+
const actionData = { ...entry.userAction };
|
|
128
|
+
delete actionData.ariaSnapshot;
|
|
129
|
+
delete actionData.selector;
|
|
130
|
+
delete actionData.signals;
|
|
131
|
+
lines.push(
|
|
132
|
+
`### User action: ${entry.userAction.name}`,
|
|
133
|
+
`- Args`,
|
|
134
|
+
"```json",
|
|
135
|
+
JSON.stringify(actionData, null, 2),
|
|
136
|
+
"```"
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
if (entry.code) {
|
|
140
|
+
lines.push(
|
|
141
|
+
`- Code`,
|
|
142
|
+
"```js",
|
|
143
|
+
entry.code,
|
|
144
|
+
"```"
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
if (entry.tabSnapshot) {
|
|
148
|
+
const fileName = `${ordinal}.snapshot.yml`;
|
|
149
|
+
import_fs.default.promises.writeFile(import_path.default.join(this._folder, fileName), entry.tabSnapshot.ariaSnapshot).catch(import_log.logUnhandledError);
|
|
150
|
+
lines.push(`- Snapshot: ${fileName}`);
|
|
151
|
+
}
|
|
152
|
+
lines.push("", "");
|
|
153
|
+
}
|
|
154
|
+
this._sessionFileQueue = this._sessionFileQueue.then(() => import_fs.default.promises.appendFile(this._file, lines.join("\n")));
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
158
|
+
0 && (module.exports = {
|
|
159
|
+
SessionLog
|
|
160
|
+
});
|