@pedropaulovc/playwright 1.59.0-alpha-1769214875000
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/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +170 -0
- package/ThirdPartyNotices.txt +5042 -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 +28 -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 +321 -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 +726 -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 +520 -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 +311 -0
- package/lib/matchers/matcherHint.js +44 -0
- package/lib/matchers/matchers.js +383 -0
- package/lib/matchers/toBeTruthy.js +75 -0
- package/lib/matchers/toEqual.js +100 -0
- package/lib/matchers/toHaveURL.js +101 -0
- package/lib/matchers/toMatchAriaSnapshot.js +159 -0
- package/lib/matchers/toMatchSnapshot.js +342 -0
- package/lib/matchers/toMatchText.js +99 -0
- package/lib/mcp/browser/browserContextFactory.js +329 -0
- package/lib/mcp/browser/browserServerBackend.js +89 -0
- package/lib/mcp/browser/config.js +421 -0
- package/lib/mcp/browser/context.js +244 -0
- package/lib/mcp/browser/response.js +284 -0
- package/lib/mcp/browser/sessionLog.js +75 -0
- package/lib/mcp/browser/tab.js +351 -0
- package/lib/mcp/browser/tools/common.js +63 -0
- package/lib/mcp/browser/tools/console.js +61 -0
- package/lib/mcp/browser/tools/dialogs.js +59 -0
- package/lib/mcp/browser/tools/evaluate.js +61 -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 +72 -0
- package/lib/mcp/browser/tools/keyboard.js +151 -0
- package/lib/mcp/browser/tools/mouse.js +159 -0
- package/lib/mcp/browser/tools/navigate.js +136 -0
- package/lib/mcp/browser/tools/network.js +78 -0
- package/lib/mcp/browser/tools/pdf.js +49 -0
- package/lib/mcp/browser/tools/runCode.js +76 -0
- package/lib/mcp/browser/tools/screenshot.js +87 -0
- package/lib/mcp/browser/tools/snapshot.js +207 -0
- package/lib/mcp/browser/tools/tabs.js +67 -0
- package/lib/mcp/browser/tools/tool.js +47 -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 +109 -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 +223 -0
- package/lib/mcp/sdk/tool.js +47 -0
- package/lib/mcp/terminal/SKILL.md +158 -0
- package/lib/mcp/terminal/cli.js +7 -0
- package/lib/mcp/terminal/command.js +56 -0
- package/lib/mcp/terminal/commands.js +519 -0
- package/lib/mcp/terminal/daemon.js +131 -0
- package/lib/mcp/terminal/help.json +47 -0
- package/lib/mcp/terminal/helpGenerator.js +115 -0
- package/lib/mcp/terminal/program.js +365 -0
- package/lib/mcp/terminal/socketConnection.js +80 -0
- package/lib/mcp/test/browserBackend.js +98 -0
- package/lib/mcp/test/generatorTools.js +122 -0
- package/lib/mcp/test/plannerTools.js +145 -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 +285 -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 +418 -0
- package/lib/reporters/base.js +638 -0
- package/lib/reporters/blob.js +138 -0
- package/lib/reporters/dot.js +99 -0
- package/lib/reporters/empty.js +32 -0
- package/lib/reporters/github.js +128 -0
- package/lib/reporters/html.js +633 -0
- package/lib/reporters/internalReporter.js +138 -0
- package/lib/reporters/json.js +254 -0
- package/lib/reporters/junit.js +232 -0
- package/lib/reporters/line.js +131 -0
- package/lib/reporters/list.js +253 -0
- package/lib/reporters/listModeReporter.js +69 -0
- package/lib/reporters/markdown.js +144 -0
- package/lib/reporters/merge.js +558 -0
- package/lib/reporters/multiplexer.js +112 -0
- package/lib/reporters/reporterV2.js +102 -0
- package/lib/reporters/teleEmitter.js +317 -0
- package/lib/reporters/versions/blobV1.js +16 -0
- package/lib/runner/dispatcher.js +530 -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 +46 -0
- package/lib/transform/babelBundleImpl.js +461 -0
- package/lib/transform/compilationCache.js +274 -0
- package/lib/transform/esmLoader.js +103 -0
- package/lib/transform/md.js +221 -0
- package/lib/transform/portTransport.js +67 -0
- package/lib/transform/transform.js +303 -0
- package/lib/util.js +400 -0
- package/lib/utilsBundle.js +50 -0
- package/lib/utilsBundleImpl.js +103 -0
- package/lib/worker/fixtureRunner.js +262 -0
- package/lib/worker/testInfo.js +536 -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 +530 -0
- package/package.json +73 -0
- package/test.d.ts +18 -0
- package/test.js +24 -0
- package/test.mjs +34 -0
- package/types/test.d.ts +10287 -0
- package/types/testReporter.d.ts +822 -0
|
@@ -0,0 +1,284 @@
|
|
|
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
|
+
serializeResponse: () => serializeResponse,
|
|
37
|
+
serializeStructuredResponse: () => serializeStructuredResponse
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(response_exports);
|
|
40
|
+
var import_fs = __toESM(require("fs"));
|
|
41
|
+
var import_path = __toESM(require("path"));
|
|
42
|
+
var import_utilsBundle = require("playwright-core/lib/utilsBundle");
|
|
43
|
+
var import_tab = require("./tab");
|
|
44
|
+
var import_utils = require("./tools/utils");
|
|
45
|
+
var import_screenshot = require("./tools/screenshot");
|
|
46
|
+
const requestDebug = (0, import_utilsBundle.debug)("pw:mcp:request");
|
|
47
|
+
class Response {
|
|
48
|
+
constructor(ordinal, context, toolName, toolArgs) {
|
|
49
|
+
this._results = [];
|
|
50
|
+
this._errors = [];
|
|
51
|
+
this._code = [];
|
|
52
|
+
this._includeSnapshot = "none";
|
|
53
|
+
this._context = context;
|
|
54
|
+
this.toolName = toolName;
|
|
55
|
+
this.toolArgs = toolArgs;
|
|
56
|
+
}
|
|
57
|
+
static {
|
|
58
|
+
this._ordinal = 0;
|
|
59
|
+
}
|
|
60
|
+
static create(context, toolName, toolArgs) {
|
|
61
|
+
return new Response(++Response._ordinal, context, toolName, toolArgs);
|
|
62
|
+
}
|
|
63
|
+
addTextResult(text) {
|
|
64
|
+
this._results.push({ title: "", text });
|
|
65
|
+
}
|
|
66
|
+
async addResult(title, data, file) {
|
|
67
|
+
this._results.push({
|
|
68
|
+
text: typeof data === "string" ? data : void 0,
|
|
69
|
+
data: typeof data === "string" ? void 0 : data,
|
|
70
|
+
title,
|
|
71
|
+
file
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
addError(error) {
|
|
75
|
+
this._errors.push(error);
|
|
76
|
+
}
|
|
77
|
+
addCode(code) {
|
|
78
|
+
this._code.push(code);
|
|
79
|
+
}
|
|
80
|
+
setIncludeSnapshot() {
|
|
81
|
+
this._includeSnapshot = this._context.config.snapshot.mode;
|
|
82
|
+
}
|
|
83
|
+
setIncludeFullSnapshot(includeSnapshotFileName) {
|
|
84
|
+
this._includeSnapshot = "full";
|
|
85
|
+
this._includeSnapshotFileName = includeSnapshotFileName;
|
|
86
|
+
}
|
|
87
|
+
async build() {
|
|
88
|
+
const rootPath = this._context.firstRootPath();
|
|
89
|
+
const sections = [];
|
|
90
|
+
const addSection = (title) => {
|
|
91
|
+
const section = { title, content: [], isError: title === "Error" };
|
|
92
|
+
sections.push(section);
|
|
93
|
+
return section.content;
|
|
94
|
+
};
|
|
95
|
+
if (this._errors.length) {
|
|
96
|
+
const content = addSection("Error");
|
|
97
|
+
content.push({ text: this._errors.join("\n"), title: "error" });
|
|
98
|
+
}
|
|
99
|
+
if (this._results.length) {
|
|
100
|
+
const content = addSection("Result");
|
|
101
|
+
content.push(...this._results);
|
|
102
|
+
}
|
|
103
|
+
if (this._context.config.codegen !== "none" && this._code.length) {
|
|
104
|
+
const content = addSection("Ran Playwright code");
|
|
105
|
+
for (const code of this._code)
|
|
106
|
+
content.push({ text: code, title: "code" });
|
|
107
|
+
}
|
|
108
|
+
const tabSnapshot = this._context.currentTab() ? await this._context.currentTabOrDie().captureSnapshot() : void 0;
|
|
109
|
+
const tabHeaders = await Promise.all(this._context.tabs().map((tab) => tab.headerSnapshot()));
|
|
110
|
+
if (this._includeSnapshot !== "none" || tabHeaders.some((header) => header.changed)) {
|
|
111
|
+
if (tabHeaders.length !== 1) {
|
|
112
|
+
const content2 = addSection("Open tabs");
|
|
113
|
+
content2.push({ text: renderTabsMarkdown(tabHeaders).join("\n"), title: "Open tabs" });
|
|
114
|
+
}
|
|
115
|
+
const content = addSection("Page");
|
|
116
|
+
content.push({ text: renderTabMarkdown(tabHeaders[0]).join("\n"), title: "Page" });
|
|
117
|
+
}
|
|
118
|
+
if (tabSnapshot?.modalStates.length) {
|
|
119
|
+
const content = addSection("Modal state");
|
|
120
|
+
content.push({ text: (0, import_tab.renderModalStates)(this._context.config, tabSnapshot.modalStates).join("\n"), title: "Modal state" });
|
|
121
|
+
}
|
|
122
|
+
if (tabSnapshot && this._includeSnapshot !== "none") {
|
|
123
|
+
const content = addSection("Snapshot");
|
|
124
|
+
const snapshot = this._includeSnapshot === "full" ? tabSnapshot.ariaSnapshot : tabSnapshot.ariaSnapshotDiff ?? tabSnapshot.ariaSnapshot;
|
|
125
|
+
content.push({ text: snapshot, title: "snapshot", file: { prefix: "page", ext: "yml", suggestedFilename: this._includeSnapshotFileName } });
|
|
126
|
+
}
|
|
127
|
+
if (tabSnapshot?.events.filter((event) => event.type !== "request").length) {
|
|
128
|
+
const content = addSection("Events");
|
|
129
|
+
const text = [];
|
|
130
|
+
for (const event of tabSnapshot.events) {
|
|
131
|
+
if (event.type === "console") {
|
|
132
|
+
if ((0, import_tab.shouldIncludeMessage)(this._context.config.console.level, event.message.type))
|
|
133
|
+
text.push(`- ${trimMiddle(event.message.toString(), 100)}`);
|
|
134
|
+
} else if (event.type === "download-start") {
|
|
135
|
+
text.push(`- Downloading file ${event.download.download.suggestedFilename()} ...`);
|
|
136
|
+
} else if (event.type === "download-finish") {
|
|
137
|
+
text.push(`- Downloaded file ${event.download.download.suggestedFilename()} to "${rootPath ? import_path.default.relative(rootPath, event.download.outputFile) : event.download.outputFile}"`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
content.push({ text: text.join("\n"), title: "events" });
|
|
141
|
+
}
|
|
142
|
+
return sections;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
function renderTabMarkdown(tab) {
|
|
146
|
+
const lines = [`- Page URL: ${tab.url}`];
|
|
147
|
+
if (tab.title)
|
|
148
|
+
lines.push(`- Page Title: ${tab.title}`);
|
|
149
|
+
return lines;
|
|
150
|
+
}
|
|
151
|
+
function renderTabsMarkdown(tabs) {
|
|
152
|
+
if (!tabs.length)
|
|
153
|
+
return ["No open tabs. Navigate to a URL to create one."];
|
|
154
|
+
const lines = [];
|
|
155
|
+
for (let i = 0; i < tabs.length; i++) {
|
|
156
|
+
const tab = tabs[i];
|
|
157
|
+
const current = tab.current ? " (current)" : "";
|
|
158
|
+
lines.push(`- ${i}:${current} [${tab.title}](${tab.url})`);
|
|
159
|
+
}
|
|
160
|
+
return lines;
|
|
161
|
+
}
|
|
162
|
+
function trimMiddle(text, maxLength) {
|
|
163
|
+
if (text.length <= maxLength)
|
|
164
|
+
return text;
|
|
165
|
+
return text.slice(0, Math.floor(maxLength / 2)) + "..." + text.slice(-3 - Math.floor(maxLength / 2));
|
|
166
|
+
}
|
|
167
|
+
function parseSections(text) {
|
|
168
|
+
const sections = /* @__PURE__ */ new Map();
|
|
169
|
+
const sectionHeaders = text.split(/^### /m).slice(1);
|
|
170
|
+
for (const section of sectionHeaders) {
|
|
171
|
+
const firstNewlineIndex = section.indexOf("\n");
|
|
172
|
+
if (firstNewlineIndex === -1)
|
|
173
|
+
continue;
|
|
174
|
+
const sectionName = section.substring(0, firstNewlineIndex);
|
|
175
|
+
const sectionContent = section.substring(firstNewlineIndex + 1).trim();
|
|
176
|
+
sections.set(sectionName, sectionContent);
|
|
177
|
+
}
|
|
178
|
+
return sections;
|
|
179
|
+
}
|
|
180
|
+
async function serializeResponse(context, sections, rootPath) {
|
|
181
|
+
const redactText = (text2) => {
|
|
182
|
+
for (const [secretName, secretValue] of Object.entries(context.config.secrets ?? {}))
|
|
183
|
+
text2 = text2.replaceAll(secretValue, `<secret>${secretName}</secret>`);
|
|
184
|
+
return text2;
|
|
185
|
+
};
|
|
186
|
+
const text = [];
|
|
187
|
+
for (const section of sections) {
|
|
188
|
+
text.push(`### ${section.title}`);
|
|
189
|
+
for (const result of section.content) {
|
|
190
|
+
if (!result.file) {
|
|
191
|
+
if (result.text !== void 0)
|
|
192
|
+
text.push(result.text);
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
if (result.file.suggestedFilename || context.config.outputMode === "file" || result.data) {
|
|
196
|
+
const generatedFileName = await context.outputFile((0, import_utils.dateAsFileName)(result.file.prefix, result.file.ext), { origin: "code", title: section.title });
|
|
197
|
+
const fileName = result.file.suggestedFilename ? await context.outputFile(result.file.suggestedFilename, { origin: "llm", title: section.title }) : generatedFileName;
|
|
198
|
+
text.push(`- [${result.title}](${rootPath ? import_path.default.relative(rootPath, fileName) : fileName})`);
|
|
199
|
+
if (result.data)
|
|
200
|
+
await import_fs.default.promises.writeFile(fileName, result.data, "utf-8");
|
|
201
|
+
else
|
|
202
|
+
await import_fs.default.promises.writeFile(fileName, result.text);
|
|
203
|
+
} else {
|
|
204
|
+
if (result.file.ext === "yml")
|
|
205
|
+
text.push(`\`\`\`yaml
|
|
206
|
+
${result.text}
|
|
207
|
+
\`\`\``);
|
|
208
|
+
else
|
|
209
|
+
text.push(result.text);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
const content = [
|
|
214
|
+
{
|
|
215
|
+
type: "text",
|
|
216
|
+
text: redactText(text.join("\n"))
|
|
217
|
+
}
|
|
218
|
+
];
|
|
219
|
+
if (context.config.imageResponses !== "omit") {
|
|
220
|
+
for (const result of sections.flatMap((section) => section.content).filter((result2) => result2.file?.contentType)) {
|
|
221
|
+
const scaledData = (0, import_screenshot.scaleImageToFitMessage)(result.data, result.file.contentType === "image/png" ? "png" : "jpeg");
|
|
222
|
+
content.push({ type: "image", data: scaledData.toString("base64"), mimeType: result.file.contentType });
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return {
|
|
226
|
+
content,
|
|
227
|
+
...sections.some((section) => section.isError) ? { isError: true } : {}
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
async function serializeStructuredResponse(sections) {
|
|
231
|
+
for (const section of sections) {
|
|
232
|
+
for (const result of section.content) {
|
|
233
|
+
if (!result.data)
|
|
234
|
+
continue;
|
|
235
|
+
result.isBase64 = true;
|
|
236
|
+
result.text = result.data.toString("base64");
|
|
237
|
+
result.data = void 0;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return {
|
|
241
|
+
content: [{ type: "text", text: "", _meta: { sections } }],
|
|
242
|
+
isError: sections.some((section) => section.isError)
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
function parseResponse(response) {
|
|
246
|
+
if (response.content?.[0].type !== "text")
|
|
247
|
+
return void 0;
|
|
248
|
+
const text = response.content[0].text;
|
|
249
|
+
const sections = parseSections(text);
|
|
250
|
+
const error = sections.get("Error");
|
|
251
|
+
const result = sections.get("Result");
|
|
252
|
+
const code = sections.get("Ran Playwright code");
|
|
253
|
+
const tabs = sections.get("Open tabs");
|
|
254
|
+
const page = sections.get("Page");
|
|
255
|
+
const snapshot = sections.get("Snapshot");
|
|
256
|
+
const events = sections.get("Events");
|
|
257
|
+
const modalState = sections.get("Modal state");
|
|
258
|
+
const codeNoFrame = code?.replace(/^```js\n/, "").replace(/\n```$/, "");
|
|
259
|
+
const isError = response.isError;
|
|
260
|
+
const attachments = response.content.length > 1 ? response.content.slice(1) : void 0;
|
|
261
|
+
return {
|
|
262
|
+
result,
|
|
263
|
+
error,
|
|
264
|
+
code: codeNoFrame,
|
|
265
|
+
tabs,
|
|
266
|
+
page,
|
|
267
|
+
snapshot,
|
|
268
|
+
events,
|
|
269
|
+
modalState,
|
|
270
|
+
isError,
|
|
271
|
+
attachments,
|
|
272
|
+
text
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
276
|
+
0 && (module.exports = {
|
|
277
|
+
Response,
|
|
278
|
+
parseResponse,
|
|
279
|
+
renderTabMarkdown,
|
|
280
|
+
renderTabsMarkdown,
|
|
281
|
+
requestDebug,
|
|
282
|
+
serializeResponse,
|
|
283
|
+
serializeStructuredResponse
|
|
284
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
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
|
+
});
|