|
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 testBackend_exports = {}; |
|
30
|
__export(testBackend_exports, { |
|
31
|
TestServerBackend: () => TestServerBackend |
|
32
|
}); |
|
33
|
module.exports = __toCommonJS(testBackend_exports); |
|
34
|
var import_mcpBundle = require("playwright-core/lib/mcpBundle"); |
|
35
|
var mcp = __toESM(require("../sdk/exports")); |
|
36
|
var import_testContext = require("./testContext"); |
|
37
|
var testTools = __toESM(require("./testTools.js")); |
|
38
|
var generatorTools = __toESM(require("./generatorTools.js")); |
|
39
|
var plannerTools = __toESM(require("./plannerTools.js")); |
|
40
|
var import_tools = require("../browser/tools"); |
|
41
|
class TestServerBackend { |
|
42
|
constructor(configPath, options) { |
|
43
|
this.name = "Playwright"; |
|
44
|
this.version = "0.0.1"; |
|
45
|
this._tools = [ |
|
46
|
plannerTools.saveTestPlan, |
|
47
|
plannerTools.setupPage, |
|
48
|
plannerTools.submitTestPlan, |
|
49
|
generatorTools.setupPage, |
|
50
|
generatorTools.generatorReadLog, |
|
51
|
generatorTools.generatorWriteTest, |
|
52
|
testTools.listTests, |
|
53
|
testTools.runTests, |
|
54
|
testTools.debugTest, |
|
55
|
...import_tools.browserTools.map((tool) => wrapBrowserTool(tool)) |
|
56
|
]; |
|
57
|
this._options = options || {}; |
|
58
|
this._configPath = configPath; |
|
59
|
} |
|
60
|
async initialize(clientInfo) { |
|
61
|
this._context = new import_testContext.TestContext(clientInfo, this._configPath, this._options); |
|
62
|
} |
|
63
|
async listTools() { |
|
64
|
return this._tools.map((tool) => mcp.toMcpTool(tool.schema)); |
|
65
|
} |
|
66
|
async callTool(name, args) { |
|
67
|
const tool = this._tools.find((tool2) => tool2.schema.name === name); |
|
68
|
if (!tool) |
|
69
|
throw new Error(`Tool not found: ${name}. Available tools: ${this._tools.map((tool2) => tool2.schema.name).join(", ")}`); |
|
70
|
try { |
|
71
|
return await tool.handle(this._context, tool.schema.inputSchema.parse(args || {})); |
|
72
|
} catch (e) { |
|
73
|
return { content: [{ type: "text", text: String(e) }], isError: true }; |
|
74
|
} |
|
75
|
} |
|
76
|
serverClosed() { |
|
77
|
void this._context?.close(); |
|
78
|
} |
|
79
|
} |
|
80
|
const typesWithIntent = ["action", "assertion", "input"]; |
|
81
|
function wrapBrowserTool(tool) { |
|
82
|
const inputSchema = typesWithIntent.includes(tool.schema.type) ? tool.schema.inputSchema.extend({ |
|
83
|
intent: import_mcpBundle.z.string().describe("The intent of the call, for example the test step description plan idea") |
|
84
|
}) : tool.schema.inputSchema; |
|
85
|
return { |
|
86
|
schema: { |
|
87
|
...tool.schema, |
|
88
|
inputSchema |
|
89
|
}, |
|
90
|
handle: async (context, params) => { |
|
91
|
const response = await context.sendMessageToPausedTest({ callTool: { name: tool.schema.name, arguments: params } }); |
|
92
|
return response.callTool; |
|
93
|
} |
|
94
|
}; |
|
95
|
} |
|
96
|
// Annotate the CommonJS export names for ESM import in node: |
|
97
|
0 && (module.exports = { |
|
98
|
TestServerBackend |
|
99
|
}); |
|
100
|
|