|
1 | 1 | import z from 'zod/v4' |
2 | 2 |
|
3 | 3 | import { BrowserResponseSchema } from '../../../browser-actions' |
| 4 | +import { $getToolCallString, jsonToolResultSchema } from '../utils' |
4 | 5 |
|
5 | 6 | import type { $ToolParams } from '../../constants' |
6 | 7 |
|
7 | 8 | const toolName = 'browser_logs' |
8 | 9 | const endsAgentStep = true |
| 10 | +const inputSchema = z.object({ |
| 11 | + type: z |
| 12 | + .string() |
| 13 | + .min(1, 'Type cannot be empty') |
| 14 | + .describe('The type of browser action to perform (e.g., "navigate").'), |
| 15 | + url: z |
| 16 | + .string() |
| 17 | + .min(1, 'URL cannot be empty') |
| 18 | + .describe('The URL to navigate to.'), |
| 19 | + waitUntil: z |
| 20 | + .enum(['load', 'domcontentloaded', 'networkidle0']) |
| 21 | + .optional() |
| 22 | + .describe("When to consider navigation successful. Defaults to 'load'."), |
| 23 | +}) |
| 24 | +const description = ` |
| 25 | +Purpose: Use this tool to check the output of console.log or errors in order to debug issues, test functionality, or verify expected behavior. |
| 26 | +
|
| 27 | +IMPORTANT: Assume the user's development server is ALREADY running and active, unless you see logs indicating otherwise. Never start the user's development server for them, unless they ask you to do so. |
| 28 | +Never offer to interact with the website aside from reading them (see available actions below). The user will manipulate the website themselves and bring you to the UI they want you to interact with. |
| 29 | +
|
| 30 | +### Response Analysis |
| 31 | +
|
| 32 | +After each action, you'll receive: |
| 33 | +1. Success/failure status |
| 34 | +2. New console logs since last action |
| 35 | +3. Network requests and responses |
| 36 | +4. JavaScript errors with stack traces |
| 37 | +
|
| 38 | +Use this data to: |
| 39 | +- Verify expected behavior |
| 40 | +- Debug issues |
| 41 | +- Guide next actions |
| 42 | +- Make informed decisions about fixes |
| 43 | +
|
| 44 | +### Best Practices |
| 45 | +
|
| 46 | +**Workflow** |
| 47 | +- Navigate to the user's website, probably on localhost, but you can compare with the production site if you want. |
| 48 | +- Scroll to the relevant section |
| 49 | +- Take screenshots and analyze confirm changes |
| 50 | +- Check network requests for anomalies |
| 51 | +
|
| 52 | +**Debugging Flow** |
| 53 | +- Start with minimal reproduction steps |
| 54 | +- Collect data at each step |
| 55 | +- Analyze results before next action |
| 56 | +- Take screenshots to track your changes after each UI change you make |
| 57 | +
|
| 58 | +There is currently only one type of browser action available: |
| 59 | +Navigate: |
| 60 | + - Load a new URL in the current browser window and get the logs after page load. |
| 61 | + Params: |
| 62 | + - \`type\`: (required) Must be equal to 'navigate' |
| 63 | + - \`url\`: (required) The URL to navigate to. |
| 64 | + - \`waitUntil\`: (required) One of 'load', 'domcontentloaded', 'networkidle0' |
| 65 | +
|
| 66 | +Example: |
| 67 | +${$getToolCallString({ |
| 68 | + toolName, |
| 69 | + inputSchema, |
| 70 | + input: { |
| 71 | + type: 'navigate', |
| 72 | + url: 'localhost:3000', |
| 73 | + waitUntil: 'domcontentloaded', |
| 74 | + }, |
| 75 | + endsAgentStep, |
| 76 | +})} |
| 77 | + `.trim() |
| 78 | + |
9 | 79 | export const browserLogsParams = { |
10 | 80 | toolName, |
11 | 81 | endsAgentStep, |
12 | | - inputSchema: z.object({ |
13 | | - type: z |
14 | | - .string() |
15 | | - .min(1, 'Type cannot be empty') |
16 | | - .describe('The type of browser action to perform (e.g., "navigate").'), |
17 | | - url: z |
18 | | - .string() |
19 | | - .min(1, 'URL cannot be empty') |
20 | | - .describe('The URL to navigate to.'), |
21 | | - waitUntil: z |
22 | | - .enum(['load', 'domcontentloaded', 'networkidle0']) |
23 | | - .optional() |
24 | | - .describe("When to consider navigation successful. Defaults to 'load'."), |
25 | | - }), |
26 | | - outputSchema: z.tuple([ |
27 | | - z.object({ |
28 | | - type: z.literal('json'), |
29 | | - value: BrowserResponseSchema, |
30 | | - }), |
31 | | - ]), |
| 82 | + description, |
| 83 | + inputSchema, |
| 84 | + outputSchema: jsonToolResultSchema(BrowserResponseSchema), |
32 | 85 | } satisfies $ToolParams |
0 commit comments