Skip to content

Commit 2b74c50

Browse files
committed
fix tests, lint
1 parent c31477c commit 2b74c50

19 files changed

+749
-264
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,12 @@
5151
"dependencies": {
5252
"@anthropic-ai/sdk": "^0.36",
5353
"@playwright/test": "^1.50.1",
54+
"@vitest/browser": "^3.0.5",
5455
"chalk": "^5",
5556
"dotenv": "^16",
5657
"eslint-plugin-promise": "^7.2.1",
57-
"semver": "^7.7.1",
5858
"playwright": "^1.50.1",
59+
"semver": "^7.7.1",
5960
"source-map-support": "^0.5",
6061
"uuid": "^11",
6162
"yargs": "^17",

pnpm-lock.yaml

Lines changed: 469 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/toolAgent.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe('toolAgent', () => {
6464
type: 'string',
6565
description: 'The processed result',
6666
},
67-
execute: ({ input }) => Promise.resolve( `Processed: ${input}`),
67+
execute: ({ input }) => Promise.resolve(`Processed: ${input}`),
6868
};
6969

7070
const sequenceCompleteTool: Tool = {
@@ -84,7 +84,7 @@ describe('toolAgent', () => {
8484
type: 'string',
8585
description: 'The final result',
8686
},
87-
execute: ({ result }) => Promise.resolve( result),
87+
execute: ({ result }) => Promise.resolve(result),
8888
};
8989

9090
it('should execute tool calls', async () => {

src/core/toolAgent.ts

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -59,26 +59,26 @@ const CONFIG = {
5959
'For coding tasks:',
6060
'0. Try to break large tasks into smaller sub-tasks that can be completed and verified sequentially.',
6161
" - trying to make lots of changes in one go can make it really hard to identify when something doesn't work",
62-
" - use sub-agents for each sub-task, leaving the main agent in a supervisory role",
63-
" - when possible ensure the project compiles/builds and the tests pass after each sub-task",
64-
" - give the sub-agents the guidance and context necessary be successful",
65-
"1. First understand the context by:",
66-
" - Reading README.md, CONTRIBUTING.md, and similar documentation",
67-
" - Checking project configuration files (e.g., package.json)",
68-
" - Understanding coding standards",
69-
"2. Ensure changes:",
70-
" - Follow project conventions",
71-
" - Build successfully",
72-
" - Pass all tests",
73-
"3. Update documentation as needed",
74-
"4. Consider adding documentation if you encountered setup/understanding challenges",
75-
"",
76-
"Feel free to use Google and Bing via the browser tools to search for information or for ideas when you get stuck.",
77-
"",
78-
"When you run into issues or unexpected results, take a step back and read the project documentation and configuration files and look at other source files in the project for examples of what works.",
79-
"",
80-
"Use sub-agents for parallel tasks, providing them with specific context they need rather than having them rediscover it.",
81-
].join("\\n");
62+
' - use sub-agents for each sub-task, leaving the main agent in a supervisory role',
63+
' - when possible ensure the project compiles/builds and the tests pass after each sub-task',
64+
' - give the sub-agents the guidance and context necessary be successful',
65+
'1. First understand the context by:',
66+
' - Reading README.md, CONTRIBUTING.md, and similar documentation',
67+
' - Checking project configuration files (e.g., package.json)',
68+
' - Understanding coding standards',
69+
'2. Ensure changes:',
70+
' - Follow project conventions',
71+
' - Build successfully',
72+
' - Pass all tests',
73+
'3. Update documentation as needed',
74+
'4. Consider adding documentation if you encountered setup/understanding challenges',
75+
'',
76+
'Feel free to use Google and Bing via the browser tools to search for information or for ideas when you get stuck.',
77+
'',
78+
'When you run into issues or unexpected results, take a step back and read the project documentation and configuration files and look at other source files in the project for examples of what works.',
79+
'',
80+
'Use sub-agents for parallel tasks, providing them with specific context they need rather than having them rediscover it.',
81+
].join('\\n');
8282
},
8383
};
8484

@@ -114,7 +114,7 @@ async function executeTools(
114114
toolCalls: ToolUseContent[],
115115
tools: Tool[],
116116
messages: Message[],
117-
logger: Logger
117+
logger: Logger,
118118
): Promise<ToolCallResult> {
119119
if (toolCalls.length === 0) {
120120
return { sequenceCompleted: false, toolResults: [] };
@@ -136,7 +136,7 @@ async function executeTools(
136136
content: toolResult,
137137
isComplete: call.name === 'sequenceComplete',
138138
};
139-
})
139+
}),
140140
);
141141

142142
const toolResults = results.map(({ type, tool_use_id, content }) => ({
@@ -161,7 +161,7 @@ export const toolAgent = async (
161161
initialPrompt: string,
162162
tools: Tool[],
163163
logger: Logger,
164-
config = CONFIG
164+
config = CONFIG,
165165
): Promise<ToolAgentResult> => {
166166
logger.verbose('Starting agent execution');
167167
logger.verbose('Initial prompt:', initialPrompt);
@@ -190,7 +190,7 @@ export const toolAgent = async (
190190
logger.verbose(
191191
`Requesting completion ${i + 1} with ${messages.length} messages with ${
192192
JSON.stringify(messages).length
193-
} bytes`
193+
} bytes`,
194194
);
195195

196196
interactions++;
@@ -219,15 +219,15 @@ export const toolAgent = async (
219219
interactions,
220220
};
221221
logger.verbose(
222-
`Agent completed with ${result.tokens.input} input tokens, ${result.tokens.output} output tokens in ${result.interactions} interactions`
222+
`Agent completed with ${result.tokens.input} input tokens, ${result.tokens.output} output tokens in ${result.interactions} interactions`,
223223
);
224224
return result;
225225
}
226226

227227
totalInputTokens += response.usage.input_tokens;
228228
totalOutputTokens += response.usage.output_tokens;
229229
logger.verbose(
230-
` Token usage: ${response.usage.input_tokens} input, ${response.usage.output_tokens} output`
230+
` Token usage: ${response.usage.input_tokens} input, ${response.usage.output_tokens} output`,
231231
);
232232

233233
const { content, toolCalls } = processResponse(response);
@@ -246,7 +246,7 @@ export const toolAgent = async (
246246
toolCalls,
247247
tools,
248248
messages,
249-
logger
249+
logger,
250250
);
251251

252252
if (sequenceCompleted) {
@@ -261,7 +261,7 @@ export const toolAgent = async (
261261
interactions,
262262
};
263263
logger.verbose(
264-
`Agent completed with ${result.tokens.input} input tokens, ${result.tokens.output} output tokens in ${result.interactions} interactions`
264+
`Agent completed with ${result.tokens.input} input tokens, ${result.tokens.output} output tokens in ${result.interactions} interactions`,
265265
);
266266
return result;
267267
}
@@ -277,7 +277,7 @@ export const toolAgent = async (
277277
interactions,
278278
};
279279
logger.verbose(
280-
`Agent completed with ${result.tokens.input} input tokens, ${result.tokens.output} output tokens in ${result.interactions} interactions`
280+
`Agent completed with ${result.tokens.input} input tokens, ${result.tokens.output} output tokens in ${result.interactions} interactions`,
281281
);
282282
return result;
283283
};

src/tools/browser/BrowserAutomation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { BrowserManager } from "./BrowserManager.js";
2-
import { PageController } from "./PageController.js";
1+
import { BrowserManager } from './BrowserManager.js';
2+
import { PageController } from './PageController.js';
33

44
export class BrowserAutomation {
55
private static instance: BrowserAutomation;

src/tools/browser/BrowserManager.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ export class BrowserManager {
2424
// Create a new context (equivalent to Puppeteer's incognito context)
2525
const context = await browser.newContext({
2626
viewport: null,
27-
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
27+
userAgent:
28+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
2829
});
2930

3031
const page = await context.newPage();
@@ -44,7 +45,7 @@ export class BrowserManager {
4445
throw new BrowserError(
4546
'Failed to create browser session',
4647
BrowserErrorCode.LAUNCH_FAILED,
47-
error
48+
error,
4849
);
4950
}
5051
}
@@ -54,7 +55,7 @@ export class BrowserManager {
5455
if (!session) {
5556
throw new BrowserError(
5657
'Session not found',
57-
BrowserErrorCode.SESSION_ERROR
58+
BrowserErrorCode.SESSION_ERROR,
5859
);
5960
}
6061

@@ -67,7 +68,7 @@ export class BrowserManager {
6768
throw new BrowserError(
6869
'Failed to close session',
6970
BrowserErrorCode.SESSION_ERROR,
70-
error
71+
error,
7172
);
7273
}
7374
}
@@ -91,7 +92,7 @@ export class BrowserManager {
9192

9293
async closeAllSessions(): Promise<void> {
9394
const closePromises = Array.from(this.sessions.keys()).map((sessionId) =>
94-
this.closeSession(sessionId).catch(() => {})
95+
this.closeSession(sessionId).catch(() => {}),
9596
);
9697
await Promise.all(closePromises);
9798
}
@@ -101,9 +102,9 @@ export class BrowserManager {
101102
if (!session) {
102103
throw new BrowserError(
103104
'Session not found',
104-
BrowserErrorCode.SESSION_ERROR
105+
BrowserErrorCode.SESSION_ERROR,
105106
);
106107
}
107108
return session;
108109
}
109-
}
110+
}

src/tools/browser/PageController.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import { Page } from "@playwright/test";
1+
import { Page } from '@playwright/test';
22
import {
33
SelectorType,
44
SelectorOptions,
55
BrowserError,
66
BrowserErrorCode,
7-
} from "./types.js";
7+
} from './types.js';
88

99
export class PageController {
1010
constructor(private page: Page) {}
1111

1212
private getSelector(
1313
selector: string,
14-
type: SelectorType = SelectorType.CSS
14+
type: SelectorType = SelectorType.CSS,
1515
): string {
1616
switch (type) {
1717
case SelectorType.XPATH:
@@ -30,30 +30,30 @@ export class PageController {
3030
private validateSelector(selector: string, type: SelectorType): void {
3131
if (!selector) {
3232
throw new BrowserError(
33-
"Invalid selector: empty string",
34-
BrowserErrorCode.SELECTOR_INVALID
33+
'Invalid selector: empty string',
34+
BrowserErrorCode.SELECTOR_INVALID,
3535
);
3636
}
3737
}
3838

3939
async waitForSelector(
4040
selector: string,
41-
options: SelectorOptions = {}
41+
options: SelectorOptions = {},
4242
): Promise<void> {
4343
this.validateSelector(selector, options.type || SelectorType.CSS);
4444
try {
4545
const locator = this.page.locator(
46-
this.getSelector(selector, options.type)
46+
this.getSelector(selector, options.type),
4747
);
4848
await locator.waitFor({
49-
state: options.visible ? "visible" : "attached",
49+
state: options.visible ? 'visible' : 'attached',
5050
timeout: options.timeout,
5151
});
5252
} catch (error) {
5353
throw new BrowserError(
5454
`Failed to find element: ${error}`,
5555
BrowserErrorCode.ELEMENT_NOT_FOUND,
56-
error
56+
error,
5757
);
5858
}
5959
}
@@ -62,53 +62,53 @@ export class PageController {
6262
this.validateSelector(selector, options.type || SelectorType.CSS);
6363
try {
6464
const locator = this.page.locator(
65-
this.getSelector(selector, options.type)
65+
this.getSelector(selector, options.type),
6666
);
6767
await locator.click({ timeout: options.timeout });
6868
} catch (error) {
6969
throw new BrowserError(
7070
`Failed to click element: ${error}`,
7171
BrowserErrorCode.SELECTOR_ERROR,
72-
error
72+
error,
7373
);
7474
}
7575
}
7676

7777
async type(
7878
selector: string,
7979
text: string,
80-
options: SelectorOptions = {}
80+
options: SelectorOptions = {},
8181
): Promise<void> {
8282
this.validateSelector(selector, options.type || SelectorType.CSS);
8383
try {
8484
const locator = this.page.locator(
85-
this.getSelector(selector, options.type)
85+
this.getSelector(selector, options.type),
8686
);
8787
await locator.fill(text, { timeout: options.timeout });
8888
} catch (error) {
8989
throw new BrowserError(
9090
`Failed to type text: ${error}`,
9191
BrowserErrorCode.SELECTOR_ERROR,
92-
error
92+
error,
9393
);
9494
}
9595
}
9696

9797
async getText(
9898
selector: string,
99-
options: SelectorOptions = {}
99+
options: SelectorOptions = {},
100100
): Promise<string> {
101101
this.validateSelector(selector, options.type || SelectorType.CSS);
102102
try {
103103
const locator = this.page.locator(
104-
this.getSelector(selector, options.type)
104+
this.getSelector(selector, options.type),
105105
);
106-
return (await locator.textContent()) || "";
106+
return (await locator.textContent()) || '';
107107
} catch (error) {
108108
throw new BrowserError(
109109
`Failed to get text: ${error}`,
110110
BrowserErrorCode.SELECTOR_ERROR,
111-
error
111+
error,
112112
);
113113
}
114114
}

0 commit comments

Comments
 (0)