testchimp-runner-core 0.0.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/dist/auth-config.d.ts +33 -0
- package/dist/auth-config.d.ts.map +1 -0
- package/dist/auth-config.js +69 -0
- package/dist/auth-config.js.map +1 -0
- package/dist/env-loader.d.ts +20 -0
- package/dist/env-loader.d.ts.map +1 -0
- package/dist/env-loader.js +83 -0
- package/dist/env-loader.js.map +1 -0
- package/dist/execution-service.d.ts +61 -0
- package/dist/execution-service.d.ts.map +1 -0
- package/dist/execution-service.js +822 -0
- package/dist/execution-service.js.map +1 -0
- package/dist/file-handler.d.ts +59 -0
- package/dist/file-handler.d.ts.map +1 -0
- package/dist/file-handler.js +75 -0
- package/dist/file-handler.js.map +1 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +196 -0
- package/dist/index.js.map +1 -0
- package/dist/llm-facade.d.ts +101 -0
- package/dist/llm-facade.d.ts.map +1 -0
- package/dist/llm-facade.js +289 -0
- package/dist/llm-facade.js.map +1 -0
- package/dist/playwright-mcp-service.d.ts +42 -0
- package/dist/playwright-mcp-service.d.ts.map +1 -0
- package/dist/playwright-mcp-service.js +167 -0
- package/dist/playwright-mcp-service.js.map +1 -0
- package/dist/prompts.d.ts +34 -0
- package/dist/prompts.d.ts.map +1 -0
- package/dist/prompts.js +237 -0
- package/dist/prompts.js.map +1 -0
- package/dist/scenario-service.d.ts +25 -0
- package/dist/scenario-service.d.ts.map +1 -0
- package/dist/scenario-service.js +119 -0
- package/dist/scenario-service.js.map +1 -0
- package/dist/scenario-worker-class.d.ts +30 -0
- package/dist/scenario-worker-class.d.ts.map +1 -0
- package/dist/scenario-worker-class.js +263 -0
- package/dist/scenario-worker-class.js.map +1 -0
- package/dist/script-utils.d.ts +44 -0
- package/dist/script-utils.d.ts.map +1 -0
- package/dist/script-utils.js +100 -0
- package/dist/script-utils.js.map +1 -0
- package/dist/types.d.ts +171 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +28 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/browser-utils.d.ts +13 -0
- package/dist/utils/browser-utils.d.ts.map +1 -0
- package/dist/utils/browser-utils.js +269 -0
- package/dist/utils/browser-utils.js.map +1 -0
- package/dist/utils/page-info-utils.d.ts +16 -0
- package/dist/utils/page-info-utils.d.ts.map +1 -0
- package/dist/utils/page-info-utils.js +77 -0
- package/dist/utils/page-info-utils.js.map +1 -0
- package/env.prod +1 -0
- package/env.staging +1 -0
- package/package.json +38 -0
- package/src/auth-config.ts +84 -0
- package/src/env-loader.ts +91 -0
- package/src/execution-service.ts +999 -0
- package/src/file-handler.ts +104 -0
- package/src/index.ts +205 -0
- package/src/llm-facade.ts +413 -0
- package/src/playwright-mcp-service.ts +203 -0
- package/src/prompts.ts +247 -0
- package/src/scenario-service.ts +138 -0
- package/src/scenario-worker-class.ts +330 -0
- package/src/script-utils.ts +109 -0
- package/src/types.ts +202 -0
- package/src/utils/browser-utils.ts +272 -0
- package/src/utils/page-info-utils.ts +93 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.LLMFacade = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const prompts_1 = require("./prompts");
|
|
9
|
+
const types_1 = require("./types");
|
|
10
|
+
const auth_config_1 = require("./auth-config");
|
|
11
|
+
const env_loader_1 = require("./env-loader");
|
|
12
|
+
class LLMFacade {
|
|
13
|
+
constructor(authConfig, backendUrl) {
|
|
14
|
+
// Use provided backend URL or fall back to environment configuration
|
|
15
|
+
if (backendUrl) {
|
|
16
|
+
this.backendUrl = backendUrl;
|
|
17
|
+
console.log(`LLMFacade initialized with provided backend URL: ${this.backendUrl}`);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
// Fall back to environment configuration for backward compatibility
|
|
21
|
+
const envConfig = (0, env_loader_1.loadEnvConfig)();
|
|
22
|
+
this.backendUrl = envConfig.TESTCHIMP_BACKEND_URL;
|
|
23
|
+
console.log(`LLMFacade initialized with environment backend URL: ${this.backendUrl}`);
|
|
24
|
+
}
|
|
25
|
+
// Use provided auth config or try to create from environment
|
|
26
|
+
this.authConfig = authConfig || (0, auth_config_1.createAuthConfigFromEnv)();
|
|
27
|
+
if (!this.authConfig) {
|
|
28
|
+
console.warn('TestChimp authentication not configured. LLM calls may fail.');
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Update authentication configuration
|
|
33
|
+
*/
|
|
34
|
+
setAuthConfig(authConfig) {
|
|
35
|
+
this.authConfig = authConfig;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Get current authentication configuration
|
|
39
|
+
*/
|
|
40
|
+
getAuthConfig() {
|
|
41
|
+
return this.authConfig;
|
|
42
|
+
}
|
|
43
|
+
async callLLM(request) {
|
|
44
|
+
if (!this.authConfig) {
|
|
45
|
+
throw new Error('Authentication not configured. Please set authentication credentials.');
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
const authHeaders = (0, auth_config_1.getAuthHeaders)(this.authConfig);
|
|
49
|
+
const url = `${this.backendUrl}/localagent/call_llm`;
|
|
50
|
+
console.log(`repairing step`);
|
|
51
|
+
const response = await axios_1.default.post(url, request, {
|
|
52
|
+
headers: {
|
|
53
|
+
...authHeaders,
|
|
54
|
+
'Content-Type': 'application/json'
|
|
55
|
+
},
|
|
56
|
+
timeout: 30000 // 30 second timeout for LLM calls
|
|
57
|
+
});
|
|
58
|
+
if (response.data && response.data.answer) {
|
|
59
|
+
return response.data.answer;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
throw new Error('Invalid response from LLM backend');
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
console.error('LLM call failed:', error);
|
|
67
|
+
throw new Error(`LLM call failed: ${error.message}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Generate a test name from scenario description
|
|
72
|
+
*/
|
|
73
|
+
async generateTestName(scenario, model = 'gpt-4.1-mini') {
|
|
74
|
+
console.log('Generating test name with LLM...');
|
|
75
|
+
const request = {
|
|
76
|
+
model,
|
|
77
|
+
system_prompt: prompts_1.PROMPTS.TEST_NAME_GENERATION.SYSTEM,
|
|
78
|
+
user_prompt: prompts_1.PROMPTS.TEST_NAME_GENERATION.USER(scenario)
|
|
79
|
+
};
|
|
80
|
+
try {
|
|
81
|
+
const response = await this.callLLM(request);
|
|
82
|
+
const testNameResponse = JSON.parse(response);
|
|
83
|
+
return testNameResponse.testName;
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
console.error('Failed to generate test name:', error);
|
|
87
|
+
// Fallback to a simple generated name
|
|
88
|
+
return `Test: ${scenario.substring(0, 50)}...`;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Break down scenario into steps
|
|
93
|
+
*/
|
|
94
|
+
async breakdownScenario(scenario, model = 'gpt-4.1-mini') {
|
|
95
|
+
console.log('Breaking down scenario with LLM...');
|
|
96
|
+
const request = {
|
|
97
|
+
model,
|
|
98
|
+
system_prompt: prompts_1.PROMPTS.SCENARIO_BREAKDOWN.SYSTEM,
|
|
99
|
+
user_prompt: prompts_1.PROMPTS.SCENARIO_BREAKDOWN.USER(scenario)
|
|
100
|
+
};
|
|
101
|
+
try {
|
|
102
|
+
const response = await this.callLLM(request);
|
|
103
|
+
const breakdownResponse = JSON.parse(response);
|
|
104
|
+
// Validate and clean up steps
|
|
105
|
+
const cleanedSteps = breakdownResponse.steps
|
|
106
|
+
.map(step => step.trim())
|
|
107
|
+
.filter(step => step.length > 0)
|
|
108
|
+
.slice(0, 10); // Limit to 10 steps max
|
|
109
|
+
return cleanedSteps.map((desc, index) => ({
|
|
110
|
+
stepNumber: index + 1,
|
|
111
|
+
description: desc,
|
|
112
|
+
}));
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
console.error('Failed to breakdown scenario:', error);
|
|
116
|
+
// Fallback to simple breakdown
|
|
117
|
+
const stepDescriptions = scenario.split('.').map(s => s.trim()).filter(s => s.length > 0);
|
|
118
|
+
return stepDescriptions.map((desc, index) => ({
|
|
119
|
+
stepNumber: index + 1,
|
|
120
|
+
description: desc,
|
|
121
|
+
}));
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Generate Playwright command for a step
|
|
126
|
+
*/
|
|
127
|
+
async generatePlaywrightCommand(stepDescription, pageInfo, previousSteps, lastError, currentStep, model = 'gpt-4.1-mini') {
|
|
128
|
+
console.log('Generating Playwright command with LLM...');
|
|
129
|
+
const previousCommands = previousSteps
|
|
130
|
+
.filter(s => s.playwrightCommand && s.success)
|
|
131
|
+
.map(s => `// Step ${s.stepNumber}: ${s.description}\n${s.playwrightCommand}`)
|
|
132
|
+
.join('\n');
|
|
133
|
+
// Build comprehensive attempt history for current step
|
|
134
|
+
const attemptHistory = this.buildAttemptHistory(currentStep);
|
|
135
|
+
// Provide raw error context for LLM analysis
|
|
136
|
+
const errorContext = this.buildErrorContext(lastError, currentStep);
|
|
137
|
+
const prompt = prompts_1.PROMPTS.PLAYWRIGHT_COMMAND.USER(stepDescription, pageInfo, previousCommands, attemptHistory, errorContext);
|
|
138
|
+
const request = {
|
|
139
|
+
model,
|
|
140
|
+
system_prompt: prompts_1.PROMPTS.PLAYWRIGHT_COMMAND.SYSTEM,
|
|
141
|
+
user_prompt: prompt
|
|
142
|
+
};
|
|
143
|
+
try {
|
|
144
|
+
const response = await this.callLLM(request);
|
|
145
|
+
const commandResponse = JSON.parse(response);
|
|
146
|
+
return commandResponse.command;
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
console.error('Failed to generate Playwright command:', error);
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Parse script into steps for AI repair
|
|
155
|
+
*/
|
|
156
|
+
async parseScriptIntoSteps(script, model = 'gpt-4o-mini') {
|
|
157
|
+
const request = {
|
|
158
|
+
model,
|
|
159
|
+
system_prompt: prompts_1.PROMPTS.SCRIPT_PARSING.SYSTEM,
|
|
160
|
+
user_prompt: prompts_1.PROMPTS.SCRIPT_PARSING.USER(script)
|
|
161
|
+
};
|
|
162
|
+
try {
|
|
163
|
+
const response = await this.callLLM(request);
|
|
164
|
+
const parsed = JSON.parse(response);
|
|
165
|
+
// Expect JSON object with steps array
|
|
166
|
+
if (parsed.steps && Array.isArray(parsed.steps)) {
|
|
167
|
+
return parsed.steps;
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
console.error('Unexpected LLM response format - expected {steps: [...]}:', parsed);
|
|
171
|
+
return [];
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
console.error('Failed to parse LLM response as JSON:', error);
|
|
176
|
+
return [];
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Get repair suggestion for a failing step
|
|
181
|
+
*/
|
|
182
|
+
async getRepairSuggestion(stepDescription, stepCode, errorMessage, pageInfo, failureHistory, recentRepairs, model = 'gpt-4.1-mini') {
|
|
183
|
+
const request = {
|
|
184
|
+
model,
|
|
185
|
+
system_prompt: prompts_1.PROMPTS.REPAIR_SUGGESTION.SYSTEM,
|
|
186
|
+
user_prompt: prompts_1.PROMPTS.REPAIR_SUGGESTION.USER(stepDescription, stepCode, errorMessage, pageInfo, failureHistory, recentRepairs)
|
|
187
|
+
};
|
|
188
|
+
const response = await this.callLLM(request);
|
|
189
|
+
console.log(`🤖 LLM Repair Response:`, response);
|
|
190
|
+
const parsed = JSON.parse(response);
|
|
191
|
+
console.log(`🤖 Parsed Repair Action:`, parsed);
|
|
192
|
+
// Convert string operation to enum
|
|
193
|
+
if (parsed.action && parsed.action.operation) {
|
|
194
|
+
switch (parsed.action.operation) {
|
|
195
|
+
case 'MODIFY':
|
|
196
|
+
parsed.action.operation = types_1.StepOperation.MODIFY;
|
|
197
|
+
break;
|
|
198
|
+
case 'INSERT':
|
|
199
|
+
parsed.action.operation = types_1.StepOperation.INSERT;
|
|
200
|
+
break;
|
|
201
|
+
case 'REMOVE':
|
|
202
|
+
parsed.action.operation = types_1.StepOperation.REMOVE;
|
|
203
|
+
break;
|
|
204
|
+
default:
|
|
205
|
+
parsed.action.operation = types_1.StepOperation.MODIFY;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return parsed;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Assess repair confidence and generate advice
|
|
212
|
+
*/
|
|
213
|
+
async assessRepairConfidence(originalScript, updatedScript, model = 'gpt-4.1-mini') {
|
|
214
|
+
const request = {
|
|
215
|
+
model,
|
|
216
|
+
system_prompt: prompts_1.PROMPTS.REPAIR_CONFIDENCE.SYSTEM,
|
|
217
|
+
user_prompt: prompts_1.PROMPTS.REPAIR_CONFIDENCE.USER(originalScript, updatedScript)
|
|
218
|
+
};
|
|
219
|
+
const response = await this.callLLM(request);
|
|
220
|
+
return JSON.parse(response);
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Generate final script with repair advice
|
|
224
|
+
*/
|
|
225
|
+
async generateFinalScript(originalScript, updatedScript, newRepairAdvice, model = 'gpt-4o-mini') {
|
|
226
|
+
const request = {
|
|
227
|
+
model,
|
|
228
|
+
system_prompt: prompts_1.PROMPTS.FINAL_SCRIPT.SYSTEM,
|
|
229
|
+
user_prompt: prompts_1.PROMPTS.FINAL_SCRIPT.USER(originalScript, updatedScript, newRepairAdvice)
|
|
230
|
+
};
|
|
231
|
+
const response = await this.callLLM(request);
|
|
232
|
+
try {
|
|
233
|
+
const parsed = JSON.parse(response);
|
|
234
|
+
return parsed.script || updatedScript;
|
|
235
|
+
}
|
|
236
|
+
catch (error) {
|
|
237
|
+
console.error('Failed to parse final script response:', error);
|
|
238
|
+
return updatedScript;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Build attempt history for current step
|
|
243
|
+
*/
|
|
244
|
+
buildAttemptHistory(currentStep) {
|
|
245
|
+
if (!currentStep || !currentStep.attempts || currentStep.attempts.length === 0) {
|
|
246
|
+
return 'This is the first attempt for this step.';
|
|
247
|
+
}
|
|
248
|
+
const attempts = currentStep.attempts.map((attempt, index) => {
|
|
249
|
+
const status = attempt.success ? '✅ SUCCESS' : '❌ FAILED';
|
|
250
|
+
return `Attempt ${attempt.attemptNumber} (${status}):
|
|
251
|
+
Command: ${attempt.command || 'No command generated'}
|
|
252
|
+
${attempt.error ? `Error: ${attempt.error}` : 'No error'}
|
|
253
|
+
Timestamp: ${new Date(attempt.timestamp).toISOString()}`;
|
|
254
|
+
}).join('\n\n');
|
|
255
|
+
return `Current step attempt history:
|
|
256
|
+
${attempts}
|
|
257
|
+
|
|
258
|
+
LEARNING FROM FAILURES:
|
|
259
|
+
- Analyze what went wrong in each attempt
|
|
260
|
+
- Try completely different approaches for failed attempts
|
|
261
|
+
- If a selector failed, try alternative selectors
|
|
262
|
+
- If timing failed, add proper waits
|
|
263
|
+
- If element not found, try different strategies`;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Build error context for LLM analysis
|
|
267
|
+
*/
|
|
268
|
+
buildErrorContext(lastError, currentStep) {
|
|
269
|
+
if (!lastError && (!currentStep || !currentStep.error)) {
|
|
270
|
+
return '';
|
|
271
|
+
}
|
|
272
|
+
const errors = [];
|
|
273
|
+
if (lastError)
|
|
274
|
+
errors.push(lastError);
|
|
275
|
+
if (currentStep?.error)
|
|
276
|
+
errors.push(currentStep.error);
|
|
277
|
+
const errorText = errors.join(' | ');
|
|
278
|
+
return `ERROR CONTEXT:
|
|
279
|
+
Last Error: ${errorText}
|
|
280
|
+
|
|
281
|
+
ANALYZE THE ERROR AND ADAPT:
|
|
282
|
+
- Study the error message to understand what went wrong
|
|
283
|
+
- Try a completely different approach than what failed
|
|
284
|
+
- Consider alternative selectors, timing, or interaction methods
|
|
285
|
+
- Never repeat the exact same command that failed`;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
exports.LLMFacade = LLMFacade;
|
|
289
|
+
//# sourceMappingURL=llm-facade.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llm-facade.js","sourceRoot":"","sources":["../src/llm-facade.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,uCAAoC;AAEpC,mCAAwC;AACxC,+CAAoF;AACpF,6CAA6C;AA8D7C,MAAa,SAAS;IAIpB,YAAY,UAAuB,EAAE,UAAmB;QACtD,qEAAqE;QACrE,IAAI,UAAU,EAAE,CAAC;YACf,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;YAC7B,OAAO,CAAC,GAAG,CAAC,oDAAoD,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;QACrF,CAAC;aAAM,CAAC;YACN,oEAAoE;YACpE,MAAM,SAAS,GAAG,IAAA,0BAAa,GAAE,CAAC;YAClC,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC,qBAAqB,CAAC;YAClD,OAAO,CAAC,GAAG,CAAC,uDAAuD,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;QACxF,CAAC;QAED,6DAA6D;QAC7D,IAAI,CAAC,UAAU,GAAG,UAAU,IAAI,IAAA,qCAAuB,GAAE,CAAC;QAE1D,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACrB,OAAO,CAAC,IAAI,CAAC,8DAA8D,CAAC,CAAC;QAC/E,CAAC;IACH,CAAC;IAED;;OAEG;IACH,aAAa,CAAC,UAAsB;QAClC,IAAI,CAAC,UAAU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AC,IAAI,CAAC,SAAS,CAAC,CAAC;QACtC,IAAI,WAAW,EAAE,KAAK;YAAE,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QAEvD,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAErC,OAAO;cACG,SAAS;;;;;;kDAM2B,CAAC;IACjD,CAAC;CACF;AAzVD,8BAyVC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ScriptResult, PlaywrightConfig } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Service for executing Playwright scripts using worker pool
|
|
4
|
+
*/
|
|
5
|
+
export declare class PlaywrightMCPService {
|
|
6
|
+
private isConnected;
|
|
7
|
+
constructor();
|
|
8
|
+
/**
|
|
9
|
+
* Initialize the service
|
|
10
|
+
*/
|
|
11
|
+
initialize(): Promise<void>;
|
|
12
|
+
/**
|
|
13
|
+
* Execute a complete job (prescript + script + postscript) using worker pool
|
|
14
|
+
*/
|
|
15
|
+
executeJob(prescript: string | undefined, script: string, postscript: string | undefined, config?: PlaywrightConfig): Promise<{
|
|
16
|
+
success: boolean;
|
|
17
|
+
results: {
|
|
18
|
+
prescript?: ScriptResult;
|
|
19
|
+
script: ScriptResult;
|
|
20
|
+
postscript?: ScriptResult;
|
|
21
|
+
};
|
|
22
|
+
executionTime: number;
|
|
23
|
+
error?: string;
|
|
24
|
+
}>;
|
|
25
|
+
/**
|
|
26
|
+
* Prepare the script content for execution
|
|
27
|
+
*/
|
|
28
|
+
private prepareScript;
|
|
29
|
+
/**
|
|
30
|
+
* Close the service
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* Execute script directly using Playwright
|
|
34
|
+
*/
|
|
35
|
+
private executeScriptDirectly;
|
|
36
|
+
close(): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Check if the service is ready
|
|
39
|
+
*/
|
|
40
|
+
isReady(): boolean;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=playwright-mcp-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"playwright-mcp-service.d.ts","sourceRoot":"","sources":["../src/playwright-mcp-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAIzD;;GAEG;AACH,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,WAAW,CAAS;;IAM5B;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAYjC;;OAEG;IACG,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,SAAS,EAAE,MAAM,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC;QAClI,OAAO,EAAE,OAAO,CAAC;QACjB,OAAO,EAAE;YACP,SAAS,CAAC,EAAE,YAAY,CAAC;YACzB,MAAM,EAAE,YAAY,CAAC;YACrB,UAAU,CAAC,EAAE,YAAY,CAAC;SAC3B,CAAC;QACF,aAAa,EAAE,MAAM,CAAC;QACtB,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;IAsBF;;OAEG;IACH,OAAO,CAAC,aAAa;IAcrB;;OAEG;IACH;;OAEG;YACW,qBAAqB;IAoG7B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAU5B;;OAEG;IACH,OAAO,IAAI,OAAO;CAGnB"}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PlaywrightMCPService = void 0;
|
|
4
|
+
const browser_utils_1 = require("./utils/browser-utils");
|
|
5
|
+
/**
|
|
6
|
+
* Service for executing Playwright scripts using worker pool
|
|
7
|
+
*/
|
|
8
|
+
class PlaywrightMCPService {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.isConnected = false;
|
|
11
|
+
// No initialization needed for direct Playwright execution
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Initialize the service
|
|
15
|
+
*/
|
|
16
|
+
async initialize() {
|
|
17
|
+
try {
|
|
18
|
+
console.log('Initializing Playwright service...');
|
|
19
|
+
// No specific initialization needed for direct Playwright execution
|
|
20
|
+
this.isConnected = true;
|
|
21
|
+
console.log('Playwright service initialized successfully');
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
throw new Error(`Failed to initialize Playwright service: ${error}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Execute a complete job (prescript + script + postscript) using worker pool
|
|
29
|
+
*/
|
|
30
|
+
async executeJob(prescript, script, postscript, config) {
|
|
31
|
+
if (!this.isConnected) {
|
|
32
|
+
throw new Error('Service not initialized');
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
// Execute the job directly using Playwright
|
|
36
|
+
return await this.executeScriptDirectly(prescript, script, postscript, config);
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
return {
|
|
40
|
+
success: false,
|
|
41
|
+
results: {
|
|
42
|
+
script: { success: false, output: '', error: '', executionTime: 0 }
|
|
43
|
+
},
|
|
44
|
+
executionTime: 0,
|
|
45
|
+
error: error instanceof Error ? error.message : 'Unknown error occurred'
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Prepare the script content for execution
|
|
51
|
+
*/
|
|
52
|
+
prepareScript(script, config) {
|
|
53
|
+
// If the script looks like a test file, return as-is
|
|
54
|
+
if (script.includes('test(') || script.includes('describe(')) {
|
|
55
|
+
return script;
|
|
56
|
+
}
|
|
57
|
+
// If it's a list of Playwright commands, wrap in a test
|
|
58
|
+
return `
|
|
59
|
+
test('executed script', async ({ page }) => {
|
|
60
|
+
${script}
|
|
61
|
+
});
|
|
62
|
+
`;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Close the service
|
|
66
|
+
*/
|
|
67
|
+
/**
|
|
68
|
+
* Execute script directly using Playwright
|
|
69
|
+
*/
|
|
70
|
+
async executeScriptDirectly(prescript, script, postscript, config) {
|
|
71
|
+
const startTime = Date.now();
|
|
72
|
+
let browser;
|
|
73
|
+
let context;
|
|
74
|
+
let page;
|
|
75
|
+
try {
|
|
76
|
+
// Use the centralized browser initialization utility
|
|
77
|
+
const browserInstance = await (0, browser_utils_1.initializeBrowser)(config);
|
|
78
|
+
browser = browserInstance.browser;
|
|
79
|
+
context = browserInstance.context;
|
|
80
|
+
page = browserInstance.page;
|
|
81
|
+
const results = {
|
|
82
|
+
script: { success: false, output: '', error: '', executionTime: 0 }
|
|
83
|
+
};
|
|
84
|
+
// Execute prescript
|
|
85
|
+
if (prescript) {
|
|
86
|
+
try {
|
|
87
|
+
const scriptFunction = new Function('page', 'browser', 'context', `
|
|
88
|
+
return (async () => {
|
|
89
|
+
${prescript}
|
|
90
|
+
})();
|
|
91
|
+
`);
|
|
92
|
+
await scriptFunction(page, browser, context);
|
|
93
|
+
results.prescript = { success: true, output: 'Prescript executed successfully', error: '', executionTime: 0 };
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
results.prescript = { success: false, output: '', error: error.message, executionTime: 0 };
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// Execute main script
|
|
100
|
+
try {
|
|
101
|
+
const scriptFunction = new Function('page', 'browser', 'context', `
|
|
102
|
+
return (async () => {
|
|
103
|
+
${script}
|
|
104
|
+
})();
|
|
105
|
+
`);
|
|
106
|
+
await scriptFunction(page, browser, context);
|
|
107
|
+
results.script = { success: true, output: 'Script executed successfully', error: '', executionTime: 0 };
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
results.script = { success: false, output: '', error: error.message, executionTime: 0 };
|
|
111
|
+
}
|
|
112
|
+
// Execute postscript
|
|
113
|
+
if (postscript) {
|
|
114
|
+
try {
|
|
115
|
+
const scriptFunction = new Function('page', 'browser', 'context', `
|
|
116
|
+
return (async () => {
|
|
117
|
+
${postscript}
|
|
118
|
+
})();
|
|
119
|
+
`);
|
|
120
|
+
await scriptFunction(page, browser, context);
|
|
121
|
+
results.postscript = { success: true, output: 'Postscript executed successfully', error: '', executionTime: 0 };
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
results.postscript = { success: false, output: '', error: error.message, executionTime: 0 };
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
success: results.script.success,
|
|
129
|
+
results,
|
|
130
|
+
executionTime: Date.now() - startTime
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
return {
|
|
135
|
+
success: false,
|
|
136
|
+
results: {
|
|
137
|
+
script: { success: false, output: '', error: error.message, executionTime: 0 }
|
|
138
|
+
},
|
|
139
|
+
executionTime: Date.now() - startTime,
|
|
140
|
+
error: error.message
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
finally {
|
|
144
|
+
if (browser) {
|
|
145
|
+
await browser.close();
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
async close() {
|
|
150
|
+
try {
|
|
151
|
+
// No cleanup needed for direct Playwright execution
|
|
152
|
+
this.isConnected = false;
|
|
153
|
+
console.log('Playwright service closed');
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
console.error('Error during shutdown:', error);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Check if the service is ready
|
|
161
|
+
*/
|
|
162
|
+
isReady() {
|
|
163
|
+
return this.isConnected;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
exports.PlaywrightMCPService = PlaywrightMCPService;
|
|
167
|
+
//# sourceMappingURL=playwright-mcp-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"playwright-mcp-service.js","sourceRoot":"","sources":["../src/playwright-mcp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+
export declare const PROMPTS: {
|
|
5
|
+
TEST_NAME_GENERATION: {
|
|
6
|
+
SYSTEM: string;
|
|
7
|
+
USER: (scenario: string) => string;
|
|
8
|
+
};
|
|
9
|
+
SCENARIO_BREAKDOWN: {
|
|
10
|
+
SYSTEM: string;
|
|
11
|
+
USER: (scenario: string) => string;
|
|
12
|
+
};
|
|
13
|
+
PLAYWRIGHT_COMMAND: {
|
|
14
|
+
SYSTEM: string;
|
|
15
|
+
USER: (stepDescription: string, pageInfo: any, previousCommands: string, attemptHistory: string, errorContext: string) => string;
|
|
16
|
+
};
|
|
17
|
+
SCRIPT_PARSING: {
|
|
18
|
+
SYSTEM: string;
|
|
19
|
+
USER: (script: string) => string;
|
|
20
|
+
};
|
|
21
|
+
REPAIR_SUGGESTION: {
|
|
22
|
+
SYSTEM: string;
|
|
23
|
+
USER: (stepDescription: string, stepCode: string, errorMessage: string, pageInfo: any, failureHistory: string, recentRepairs: string) => string;
|
|
24
|
+
};
|
|
25
|
+
REPAIR_CONFIDENCE: {
|
|
26
|
+
SYSTEM: string;
|
|
27
|
+
USER: (originalScript: string, updatedScript: string) => string;
|
|
28
|
+
};
|
|
29
|
+
FINAL_SCRIPT: {
|
|
30
|
+
SYSTEM: string;
|
|
31
|
+
USER: (originalScript: string, updatedScript: string, newRepairAdvice: string) => string;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=prompts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../src/prompts.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,eAAO,MAAM,OAAO;;;yBAKC,MAAM;;;;yBAuBN,MAAM;;;;gCAOC,MAAM,YAAY,GAAG,oBAAoB,MAAM,kBAAkB,MAAM,gBAAgB,MAAM;;;;uBA2EtG,MAAM;;;;gCA6BG,MAAM,YAAY,MAAM,gBAAgB,MAAM,YAAY,GAAG,kBAAkB,MAAM,iBAAiB,MAAM;;;;+BAwC7G,MAAM,iBAAiB,MAAM;;;;+BAqC7B,MAAM,iBAAiB,MAAM,mBAAmB,MAAM;;CA0BhF,CAAC"}
|