@cotestdev/ai-runner 0.0.3 → 0.0.5

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 (115) hide show
  1. package/dist/ai-runner/src/runner.d.ts +1 -0
  2. package/dist/ai-runner/src/runner.d.ts.map +1 -1
  3. package/dist/ai-runner/src/runner.js +9 -1
  4. package/dist/ai-runner/src/runner.js.map +1 -1
  5. package/package.json +6 -1
  6. package/dist/agents/heal-agent.d.ts +0 -30
  7. package/dist/agents/heal-agent.d.ts.map +0 -1
  8. package/dist/agents/heal-agent.js +0 -76
  9. package/dist/agents/heal-agent.js.map +0 -1
  10. package/dist/agents/healer.d.ts +0 -73
  11. package/dist/agents/healer.d.ts.map +0 -1
  12. package/dist/agents/healer.js +0 -538
  13. package/dist/agents/healer.js.map +0 -1
  14. package/dist/agents/tools/form.d.ts +0 -22
  15. package/dist/agents/tools/form.d.ts.map +0 -1
  16. package/dist/agents/tools/form.js +0 -134
  17. package/dist/agents/tools/form.js.map +0 -1
  18. package/dist/agents/tools/index.d.ts +0 -13
  19. package/dist/agents/tools/index.d.ts.map +0 -1
  20. package/dist/agents/tools/index.js +0 -33
  21. package/dist/agents/tools/index.js.map +0 -1
  22. package/dist/agents/tools/navigate.d.ts +0 -22
  23. package/dist/agents/tools/navigate.d.ts.map +0 -1
  24. package/dist/agents/tools/navigate.js +0 -74
  25. package/dist/agents/tools/navigate.js.map +0 -1
  26. package/dist/agents/tools/snapshot.d.ts +0 -22
  27. package/dist/agents/tools/snapshot.d.ts.map +0 -1
  28. package/dist/agents/tools/snapshot.js +0 -110
  29. package/dist/agents/tools/snapshot.js.map +0 -1
  30. package/dist/agents/tools/verify.d.ts +0 -34
  31. package/dist/agents/tools/verify.d.ts.map +0 -1
  32. package/dist/agents/tools/verify.js +0 -169
  33. package/dist/agents/tools/verify.js.map +0 -1
  34. package/dist/agents/tools/wait.d.ts +0 -22
  35. package/dist/agents/tools/wait.d.ts.map +0 -1
  36. package/dist/agents/tools/wait.js +0 -104
  37. package/dist/agents/tools/wait.js.map +0 -1
  38. package/dist/agents/types.d.ts +0 -51
  39. package/dist/agents/types.d.ts.map +0 -1
  40. package/dist/agents/types.js +0 -6
  41. package/dist/agents/types.js.map +0 -1
  42. package/dist/ai-runner/src/examples/test-final.d.ts +0 -6
  43. package/dist/ai-runner/src/examples/test-final.d.ts.map +0 -1
  44. package/dist/ai-runner/src/examples/test-final.js +0 -73
  45. package/dist/ai-runner/src/examples/test-final.js.map +0 -1
  46. package/dist/ai-runner/src/examples/test-simple-tools.d.ts +0 -6
  47. package/dist/ai-runner/src/examples/test-simple-tools.d.ts.map +0 -1
  48. package/dist/ai-runner/src/examples/test-simple-tools.js +0 -149
  49. package/dist/ai-runner/src/examples/test-simple-tools.js.map +0 -1
  50. package/dist/ai-runner/src/examples/test-working.d.ts +0 -5
  51. package/dist/ai-runner/src/examples/test-working.d.ts.map +0 -1
  52. package/dist/ai-runner/src/examples/test-working.js +0 -43
  53. package/dist/ai-runner/src/examples/test-working.js.map +0 -1
  54. package/dist/ai-runner/src/examples/v-test-backend-adapter.d.ts +0 -15
  55. package/dist/ai-runner/src/examples/v-test-backend-adapter.d.ts.map +0 -1
  56. package/dist/ai-runner/src/examples/v-test-backend-adapter.js +0 -240
  57. package/dist/ai-runner/src/examples/v-test-backend-adapter.js.map +0 -1
  58. package/dist/core/runner.d.ts +0 -194
  59. package/dist/core/runner.d.ts.map +0 -1
  60. package/dist/core/runner.js +0 -650
  61. package/dist/core/runner.js.map +0 -1
  62. package/dist/index.d.ts +0 -8
  63. package/dist/index.d.ts.map +0 -1
  64. package/dist/index.js +0 -11
  65. package/dist/index.js.map +0 -1
  66. package/dist/types/external.d.ts +0 -6
  67. package/dist/types/external.d.ts.map +0 -1
  68. package/dist/types/external.js +0 -7
  69. package/dist/types/external.js.map +0 -1
  70. package/dist/types/index.d.ts +0 -153
  71. package/dist/types/index.d.ts.map +0 -1
  72. package/dist/types/index.js +0 -26
  73. package/dist/types/index.js.map +0 -1
  74. package/docs/PLAYWRIGHT_MCP_ADAPTER.md +0 -132
  75. package/docs/SCHEMA_EXTRACTION.md +0 -224
  76. package/playwright-report/data/26c3117906b682c9086892b9834f119fdef0ca60.webm +0 -0
  77. package/playwright-report/data/534e0d700217810c792ffbaf34b2d4160992d0ec.md +0 -210
  78. package/playwright-report/data/56a09464231ba6c36c441f95019b40b9238c9da5.zip +0 -0
  79. package/playwright-report/data/9c6ffeb3926521c8a7b610e82e1b29d49e859932.png +0 -0
  80. package/playwright-report/index.html +0 -85
  81. package/playwright-report/trace/assets/codeMirrorModule-Bucv2d7q.js +0 -25
  82. package/playwright-report/trace/assets/defaultSettingsView-BEpdCv1S.js +0 -266
  83. package/playwright-report/trace/codeMirrorModule.C3UTv-Ge.css +0 -1
  84. package/playwright-report/trace/codicon.DCmgc-ay.ttf +0 -0
  85. package/playwright-report/trace/defaultSettingsView.ConWv5KN.css +0 -1
  86. package/playwright-report/trace/index.BxQ34UMZ.js +0 -2
  87. package/playwright-report/trace/index.C4Y3Aw8n.css +0 -1
  88. package/playwright-report/trace/index.html +0 -43
  89. package/playwright-report/trace/manifest.webmanifest +0 -16
  90. package/playwright-report/trace/playwright-logo.svg +0 -9
  91. package/playwright-report/trace/snapshot.html +0 -21
  92. package/playwright-report/trace/sw.bundle.js +0 -3
  93. package/playwright-report/trace/uiMode.BWTwXl41.js +0 -5
  94. package/playwright-report/trace/uiMode.Btcz36p_.css +0 -1
  95. package/playwright-report/trace/uiMode.html +0 -17
  96. package/playwright-report/trace/xtermModule.DYP7pi_n.css +0 -32
  97. package/playwright.config.ts +0 -38
  98. package/src/agents/logger.ts +0 -20
  99. package/src/agents/playwright-executor.ts +0 -252
  100. package/src/agents/tools/playwright-backend-adapter.ts +0 -134
  101. package/src/agents/tools/playwright-mcp-types.d.ts +0 -71
  102. package/src/agents/types.ts +0 -80
  103. package/src/index.ts +0 -27
  104. package/src/runner.ts +0 -214
  105. package/src/tools/index.ts +0 -48
  106. package/src/tools/playwright-groups.ts +0 -54
  107. package/src/types/external.ts +0 -7
  108. package/src/types/index.ts +0 -118
  109. package/test-results/.last-run.json +0 -6
  110. package/test-results/tests-agent-test-heal-agent-Register-user-1-chromium/error-context.md +0 -210
  111. package/test-results/tests-agent-test-heal-agent-Register-user-1-chromium/test-failed-1.png +0 -0
  112. package/test-results/tests-agent-test-heal-agent-Register-user-1-chromium/trace.zip +0 -0
  113. package/test-results/tests-agent-test-heal-agent-Register-user-1-chromium/video.webm +0 -0
  114. package/tests/agent/test-heal-agent.spec.ts +0 -54
  115. package/tsconfig.json +0 -26
@@ -1,20 +0,0 @@
1
-
2
- export class Logger {
3
-
4
- private prefix = '[Agent]';
5
-
6
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
7
- log(message: string, ...optionalParams: any[]) {
8
- console.log(`${this.prefix} ${message}`, ...optionalParams);
9
- }
10
-
11
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
- warn(message: string, ...optionalParams: any[]) {
13
- console.warn(`${this.prefix} ${message}`, ...optionalParams);
14
- }
15
-
16
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
- error(message: string, ...optionalParams: any[]) {
18
- console.error(`${this.prefix} ${message}`, ...optionalParams);
19
- }
20
- }
@@ -1,252 +0,0 @@
1
- /**
2
- * Playwright Executor - Uses LangChain's createAgent API to implement ReAct loop
3
- */
4
- /* eslint-disable @typescript-eslint/no-explicit-any */
5
-
6
- import { createAgent } from 'langchain';
7
- import { DynamicStructuredTool } from '@langchain/core/tools';
8
- import type { HealContext } from '../types';
9
- import z from 'zod';
10
- import { PlaywrightAgentState } from './types';
11
-
12
- export class PlaywrightExecutor {
13
- private state: PlaywrightAgentState;
14
-
15
- constructor(state: PlaywrightAgentState) {
16
- this.state = state;
17
- }
18
-
19
- private async createPlaywrightTools(healContext: HealContext): Promise<DynamicStructuredTool[]> {
20
- const standardTools = this.state.playwrightGroup.getDefaultTools();
21
- const playwrightToolGroups = this.state.playwrightGroup.getNonDefaultGroupInfo();
22
-
23
- const getToolGroupsTool = {
24
- name: "get_tools",
25
- description: "Get available tools in a group.",
26
- schema: z.object({
27
- group_name: z.string().describe("The name of the tool group."),
28
- }),
29
- func: async (param: any) => {
30
- if (!param.group_name) throw new Error('Missing group_name parameter');
31
- return JSON.stringify(playwrightToolGroups[param.group_name]);
32
- },
33
- };
34
-
35
- const callToolTool = {
36
- name: "call_tool",
37
- description: "Call a tool in a group by name.",
38
- schema: z.object({
39
- group_name: z.string().describe("Tool group name."),
40
- tool_name: z.string().describe("Tool name."),
41
- args: z.object().describe("Tool parameters."),
42
- }),
43
- func: async (param: any) => {
44
- const { group_name, tool_name, args } = param;
45
- if (!group_name || !tool_name) throw new Error('Missing group_name or tool_name parameter');
46
- return await this.state.playwrightGroup.callTool(tool_name, args);
47
- },
48
- };
49
-
50
- const finishTool = {
51
- name: "finish_test",
52
- description: "Call this tool ONLY when the step goal has been fully achieved or failed. After calling this, no more tools should be called.",
53
- schema: z.object({
54
- isSuccess: z.boolean().describe("Whether the step goal was successfully achieved."),
55
- error: z.string().optional().describe("Reason if the step goal fails to fully achieve, otherwise leave empty."),
56
- variables: z.record(z.string(), z.any()).describe(`
57
- Key-value variables to assign in the test context to use in subsequent steps.
58
- - The variable names should be consistent with those in the original test script
59
- - Avoid conflicts with existing variable names
60
- - Only include variables that have been changed or newly assigned in the fix
61
- - The value should be NON-OBJECT types (string, number, boolean, etc.)
62
- - If subsequent steps get a variable using 'runner.get', make sure to extract and provide the ACTUAL VALUE from test or page context
63
- `),
64
- repairedScript: z.string().optional().describe(`
65
- The complete fixed test script, leave empty if the step fails:
66
- - Keep original runner.set, runner.get, runner.reuseTest calls for the steps fixed if possible and ensure no semantic changes
67
- - MUST return The COMPLETE fixed test script
68
- - ONLY apply fixes relevant to the current step and any necessary previous steps
69
- - Do NOT wrap in closures or test body - write direct code using runner API
70
- - Add a 'FIXED' comment for the step code being fixed
71
- - Example:
72
- \`\`\`typescript
73
- // FIXED
74
- await runner.runStep('Click button', async () => {
75
- await page.click('#button');
76
- });
77
- \`\`\`
78
- `),
79
- }),
80
- func: async (params: any) => {
81
- healContext.success = params.isSuccess;
82
- healContext.healError = params.error;
83
- if (healContext.success) {
84
- if (params.variables) {
85
- for (const [key, value] of Object.entries(params.variables)) {
86
- this.state.variables.set(key, value);
87
- }
88
- }
89
-
90
- this.state.originalScript = params.repairedScript;
91
- this.updateOriginalScript(params.repairedScript);
92
- }
93
-
94
- return 'Test step finished.';
95
- },
96
- };
97
-
98
- return [
99
- ...standardTools,
100
- new DynamicStructuredTool(getToolGroupsTool),
101
- new DynamicStructuredTool(callToolTool),
102
- new DynamicStructuredTool(finishTool)
103
- ];
104
- }
105
-
106
- /**
107
- * Update original script and save to database (heal mode)
108
- */
109
- private updateOriginalScript(script: string): void {
110
- this.state.storageService.saveTestScript(this.state.testCaseId, script);
111
- this.state.logger.log('Script fixed');
112
- }
113
-
114
- async execute(context: HealContext) {
115
- const page = this.state.page;
116
- if (!page) throw new Error('Missing page object');
117
-
118
- const tools = await this.createPlaywrightTools(context);
119
- const agent = createAgent({
120
- model: this.state.model!,
121
- tools: tools,
122
- systemPrompt: this.buildSystemPrompt()
123
- } as any);
124
-
125
- const inputStream = {
126
- messages: [{
127
- role: 'user' as const,
128
- content: await this.buildUserMessage(context)
129
- }]
130
- };
131
-
132
- const stream = await agent.stream(inputStream, {
133
- recursionLimit: 25,
134
- streamMode: 'updates',
135
- });
136
-
137
- for await (const event of stream) {
138
- // Process AI messages (thoughts and tool calls)
139
- const messages = event.model_request?.messages || event.messages;
140
- if (messages?.[0]?.type === 'ai') {
141
- const aiMsg = messages[0] as any;
142
-
143
- const content = this.extractContent(aiMsg.content);
144
- // Record thought
145
- if (content) {
146
- this.state.logger.log(`${content}`);
147
- }
148
- }
149
-
150
- // Process tool results
151
- const toolMsg = event.tools?.messages?.[0];
152
- if (toolMsg?.type === 'tool') {
153
- const output = this.extractContent(toolMsg.content) as string;
154
- this.state.logger.log(`✅ Result [${toolMsg.name}]:`, output.length > 300 ? output.substring(0, 100) + '...' : output);
155
- }
156
- }
157
- }
158
-
159
- private buildSystemPrompt(): string {
160
- return `
161
- You are a Playwright test expert, skilled at analyzing and fixing errors in browser automation tests.
162
-
163
- ## ** Critial Rules **
164
- - You MUST run the step using tools first before fixing the script
165
- - When you step finishes or fails, you MUST call 'finish_test' tool and set the 'isSuccess' parameter correctly.
166
- - Use tools squentially
167
- - Analyze the current step code, errors and page context and what variables are being set
168
- - Make sure the fixed code is concise and consistent with the original code in logic and style
169
- - CRITICAL: When calling 'finish_test', analyze the full test script to identify variables defined in the current step that are used in subsequent steps
170
- - IMPORTANT: Extract the ACTUAL VALUES of those variables from your tool execution results (browser_snapshot output, element text, attributes, etc.)
171
- - Include the extracted variable values in the 'variables' parameter of finish_test
172
-
173
- ## ** Constraints **
174
- - NEVER set 'isSuccess' to true if the step goal is not fully achieved
175
- - Fail the step fast and DON'T do unnecessary or unreansonable retries
176
- - Always check if variables assigned in the current step are referenced in later steps - if so, extract their actual values and include in 'variables'
177
- `.trim();
178
- }
179
-
180
- private async buildUserMessage(context: HealContext): Promise<string> {
181
- const variableList = Object.keys(this.state.variables).length > 0
182
- ? Object.keys(this.state.variables).map(v => ` - ${v}: ${JSON.stringify(this.state.variables.get(v))}`).join('\n')
183
- : undefined;
184
- const snapshot = await this.state.adapter.callTool('browser_snapshot', {});
185
- const pageState = snapshot.isError ? '' : this.extractContent(snapshot);
186
-
187
- return `
188
- ## Step Description: ${context.stepDescription}
189
-
190
- ${variableList ? `## Variables in Context\n${variableList}` : ''}
191
-
192
- ## Stacktrace
193
- ${context.stackTrace}
194
-
195
- ## Full Test Script
196
- \`\`\`typescript
197
- ${this.state.originalScript}
198
- \`\`\`
199
-
200
- ${pageState}
201
- }
202
- `.trim();
203
- }
204
-
205
- /**
206
- * Extract and normalize content from model response
207
- * Handles string, array (ContentBlock[]), and other types
208
- * Following LangChain.js best practices
209
- */
210
- private extractContent(content: unknown): string | Record<string, unknown> {
211
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
212
- const asAny = content as any;
213
- if (asAny.content) {
214
- content = asAny.content;
215
- }
216
- // If string, return as-is
217
- if (typeof content === 'string') {
218
- return content;
219
- }
220
-
221
- // If array (ContentBlock[]), extract text content
222
- if (Array.isArray(content)) {
223
- const content0 = content[0];
224
- if (typeof content0 === 'string') {
225
- return content0;
226
- }
227
- if (typeof content0 === 'object' && content0 !== null) {
228
- // Handle text blocks
229
- if ('text' in content0) {
230
- return content0.text as Record<string, unknown>;
231
- }
232
- // Handle other block types by converting to string
233
- return JSON.stringify(content0);
234
- }
235
- return String(content0);
236
- }
237
-
238
- // If object, try to extract text field or convert to string
239
- if (typeof content === 'object' && content !== null) {
240
- ``
241
- if ('text' in content) {
242
- return content as Record<string, unknown>;
243
- }
244
- return content as Record<string, unknown>;
245
- }
246
-
247
- // Fallback: convert to string
248
- return String(content);
249
- }
250
- }
251
-
252
-
@@ -1,134 +0,0 @@
1
- /**
2
- * Playwright Backend 工具适配器 - 新方案
3
- *
4
- * 基于 BrowserServerBackend 的伪实例实现
5
- * 参考:playwright/lib/mcp/test/browserBackend.js
6
- *
7
- * 这个方案的优势:
8
- * 1. 直接使用 Playwright 官方的 BrowserServerBackend 类
9
- * 2. 直接导入官方的 identityFactory,完全复用
10
- * 3. 获得完整的官方工具功能,包括 Response、Context 等
11
- * 4. 无需手动适配 Context 和 Response
12
- * 5. 自动跟随 Playwright 更新
13
- */
14
-
15
- import { DynamicStructuredTool } from '@langchain/core/tools';
16
- import type { BrowserContext } from 'playwright';
17
- import * as path from 'path';
18
-
19
- // 导入 Playwright MCP 模块的类型定义
20
- import type { PlaywrightMCPModules, BrowserServerBackendInstance } from './playwright-mcp-types';
21
-
22
- export class PlaywrightBackendAdapter {
23
-
24
- private backend: BrowserServerBackendInstance | undefined;
25
- private tools: DynamicStructuredTool[] = [];
26
-
27
- static async create(browserContext: BrowserContext): Promise<PlaywrightBackendAdapter> {
28
- const adapter = new PlaywrightBackendAdapter();
29
- adapter.backend = await adapter.getBackend(browserContext);
30
- adapter.tools = await adapter.getPlaywrightBackendToolsFromContext();
31
- return adapter;
32
- }
33
-
34
- getTools(): DynamicStructuredTool[] {
35
- return this.tools;
36
- }
37
-
38
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
39
- async callTool(name: string, params: any) {
40
- return await this.backend!.callTool(name, params);
41
- }
42
-
43
- // ============================================================================
44
- // 动态加载 Playwright 官方模块
45
- // ============================================================================
46
-
47
- /**
48
- * 官方的 identityFactory 函数
49
- * 参考:playwright/lib/mcp/test/browserBackend.js 第 94-104 行
50
- *
51
- * 注意:官方文件中定义了这个函数但没有导出,所以我们在这里复制一份
52
- */
53
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
54
- private identityFactory(browserContext: BrowserContext): any {
55
- return {
56
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
57
- createContext: async (clientInfo: any, abortSignal: any) => {
58
- void clientInfo;
59
- void abortSignal;
60
- return {
61
- browserContext,
62
- close: async () => {
63
- // 不关闭 context,因为它是外部的
64
- }
65
- };
66
- }
67
- };
68
- }
69
-
70
- private loadPlaywrightMCPModules(): PlaywrightMCPModules {
71
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
72
- const playwrightRoot = path.dirname((require as any).resolve('playwright'));
73
-
74
- return {
75
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
76
- BrowserServerBackend: (require as any)(path.join(playwrightRoot, 'lib', 'mcp', 'browser', 'browserServerBackend.js')).BrowserServerBackend,
77
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
78
- defaultConfig: (require as any)(path.join(playwrightRoot, 'lib', 'mcp', 'browser', 'config.js')).defaultConfig,
79
- // 使用本地定义的 identityFactory(因为官方没有导出)
80
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
81
- identityFactory: this.identityFactory as any,
82
- };
83
- }
84
-
85
- private async getBackend(browserContext: BrowserContext): Promise<BrowserServerBackendInstance> {
86
- // 加载 Playwright 模块(包括官方的 identityFactory)
87
- const { BrowserServerBackend, defaultConfig, identityFactory } = this.loadPlaywrightMCPModules();
88
-
89
- // 使用官方的 identityFactory(参考 browserBackend.js 第 34 行)
90
- const factory = identityFactory(browserContext);
91
-
92
- // 创建 Backend 实例
93
- const backend = new BrowserServerBackend(
94
- { ...defaultConfig, capabilities: ['core', 'core-tabs',] },
95
- factory
96
- );
97
-
98
- // 初始化 Backend
99
- await backend.initialize({
100
- name: 'ai-runner',
101
- version: '1.0.0'
102
- });
103
-
104
- return backend;
105
- }
106
- // ============================================================================
107
- // 工具转换函数
108
- // ============================================================================
109
-
110
- // export type ToolCapability = 'core' | 'core-tabs' | 'core-install' | 'vision' | 'pdf' | 'testing' | 'tracing';
111
-
112
- private async getPlaywrightBackendToolsFromContext(): Promise<DynamicStructuredTool[]> {
113
- // 列出所有工具
114
- const toolList = await this.backend!.listTools();
115
-
116
- // 转换为 LangChain 工具
117
- const tools: DynamicStructuredTool[] = [];
118
-
119
- for (const mcpTool of toolList) {
120
- const tool = new DynamicStructuredTool({
121
- name: mcpTool.name,
122
- description: mcpTool.description,
123
- schema: mcpTool.inputSchema,
124
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
125
- func: async (input: any) => {
126
- return await this.backend!.callTool(mcpTool.name, input);
127
- }
128
- });
129
- tools.push(tool);
130
- }
131
-
132
- return tools;
133
- }
134
- }
@@ -1,71 +0,0 @@
1
- /**
2
- * Playwright MCP 模块类型定义
3
- *
4
- * 为动态加载的 Playwright 内部模块提供 TypeScript 类型支持
5
- */
6
-
7
- import type { BrowserContext } from 'playwright';
8
-
9
- export interface BrowserContextFactory {
10
- createContext: (
11
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
- clientInfo: any,
13
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
- abortSignal: any,
15
- toolName: string
16
- ) => Promise<{
17
- browserContext: BrowserContext;
18
- close: () => Promise<void>;
19
- }>;
20
- }
21
-
22
- export interface BackendConfig {
23
- capabilities?: string[];
24
- saveSession?: boolean;
25
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
26
- [key: string]: any;
27
- }
28
-
29
- export interface BrowserServerBackendInstance {
30
- initialize(clientInfo: { name: string; version: string }): Promise<void>;
31
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
32
- listTools(): Promise<Array<{ name: string; description: string; inputSchema: any }>>;
33
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
34
- callTool(name: string, params: any): Promise<any>;
35
- serverClosed(): void;
36
- }
37
-
38
- export interface BrowserServerBackend {
39
- new (config: BackendConfig, factory: BrowserContextFactory): BrowserServerBackendInstance;
40
- }
41
-
42
- export interface DefaultConfig {
43
- capabilities?: string[];
44
- saveSession?: boolean;
45
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
46
- [key: string]: any;
47
- }
48
-
49
- /**
50
- * 官方的 identityFactory 函数类型
51
- * 参考:playwright/lib/mcp/test/browserBackend.js 第 94-104 行
52
- */
53
- export type IdentityFactory = (browserContext: BrowserContext) => BrowserContextFactory;
54
-
55
- export interface MCPTool {
56
- schema: {
57
- name: string;
58
- description: string;
59
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
60
- inputSchema: any;
61
- };
62
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
63
- handle: (context: any, params: any, response: any) => Promise<void>;
64
- }
65
-
66
- // 动态加载的模块类型
67
- export interface PlaywrightMCPModules {
68
- BrowserServerBackend: BrowserServerBackend;
69
- defaultConfig: DefaultConfig;
70
- identityFactory: IdentityFactory;
71
- }
@@ -1,80 +0,0 @@
1
- /**
2
- * Playwright Agent Type Definitions
3
- */
4
-
5
- import type { ModelConfig } from '../types/external';
6
- import type { ReActStep } from '../types';
7
- import { BrowserContext, Page } from '@playwright/test';
8
- import { Logger } from './logger';
9
- import { PlaywrightGroup } from '../tools/playwright-groups';
10
- import { PlaywrightBackendAdapter } from './tools/playwright-backend-adapter';
11
- import { StorageService } from '@cotestdev/core-infra';
12
- import { BaseLanguageModel } from '@langchain/core/language_models/base';
13
-
14
- // ============================================================================
15
- // Agent Execution Mode
16
- // ============================================================================
17
-
18
- /**
19
- * Agent execution mode
20
- */
21
- export type AgentMode = 'heal' | 'execute';
22
-
23
- // ============================================================================
24
- // Agent State
25
- // ============================================================================
26
-
27
- /**
28
- * Playwright Agent State
29
- */
30
- export interface PlaywrightAgentState {
31
- logger: Logger;
32
- /** Playwright Page object */
33
- page: Page;
34
- /** Playwright BrowserContext object */
35
- context: BrowserContext;
36
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
37
- variables: Map<string, any>;
38
- model?: BaseLanguageModel;
39
- originalScript: string;
40
- playwrightGroup: PlaywrightGroup;
41
- adapter: PlaywrightBackendAdapter;
42
- storageService: StorageService;
43
- testCaseId: string;
44
- }
45
-
46
- // ============================================================================
47
- // Agent Configuration
48
- // ============================================================================
49
-
50
- /**
51
- * Playwright Agent Configuration
52
- */
53
- export interface PlaywrightAgentConfig {
54
- /** Model configuration (for LLM Agent) */
55
- model: ModelConfig;
56
- }
57
-
58
- // ============================================================================
59
- // Agent Result
60
- // ============================================================================
61
-
62
- /**
63
- * Playwright Agent Execution Result
64
- */
65
- export interface PlaywrightAgentResult {
66
- /** Whether the goal was successfully completed */
67
- success: boolean;
68
-
69
- /** Agent's reasoning process */
70
- reasoning?: string;
71
-
72
- /** If failed, the error reason */
73
- errorMessage?: string;
74
-
75
- /** How many steps were executed */
76
- steps?: number;
77
-
78
- /** Detailed step records of ReAct loop */
79
- reactSteps?: ReActStep[];
80
- }
package/src/index.ts DELETED
@@ -1,27 +0,0 @@
1
- /**
2
- * ai-runner SDK Main Entry Point
3
- * Provides AI-driven test execution capabilities
4
- */
5
-
6
- // Types
7
- export type {
8
- RunnerConfig,
9
- ExecutionResult,
10
- HealContext,
11
- HealSummary,
12
- HealingDetail,
13
- RunStepOptions,
14
- } from './types';
15
-
16
-
17
- // Core Classes
18
- export { Runner } from './runner';
19
-
20
-
21
- // Agent
22
- export type {
23
- PlaywrightAgentState,
24
- PlaywrightAgentResult,
25
- PlaywrightAgentConfig,
26
- } from './agents/types';
27
-