diff options
| author | amankumarsingh77 <amankumarsingh7702@gmal.com> | 2026-05-02 16:26:01 +0530 |
|---|---|---|
| committer | amankumarsingh77 <amankumarsingh7702@gmal.com> | 2026-05-02 16:26:01 +0530 |
| commit | 1d0873c75e36d7bd1f1a12b6cae46ee10a53ee3b (patch) | |
| tree | be7316e826db158be3c8aee9b7cb2545bd4e0471 /src/tools.ts | |
| parent | 3dfc4f1150b80bb9a5e332999f7440b6255c4ec0 (diff) | |
feat(domains): migrate go_back, go_forward, reload
Diffstat (limited to 'src/tools.ts')
| -rw-r--r-- | src/tools.ts | 103 |
1 files changed, 1 insertions, 102 deletions
diff --git a/src/tools.ts b/src/tools.ts index 3b5d639..77023cd 100644 --- a/src/tools.ts +++ b/src/tools.ts @@ -96,108 +96,7 @@ async function applyTruncation( // ── Registration ───────────────────────────────────────────────────────────── export function registerTools(pi: ExtensionAPI, daemon: BrowserDaemon): void { - // ═══════════════════════════════════════════════════════════════════════════ - // browser_go_back - // ═══════════════════════════════════════════════════════════════════════════ - pi.registerTool({ - name: "browser_go_back", - label: "Browser Go Back", - description: "Navigate back one page in history.", - promptSnippet: "Go back one page in browser history", - promptGuidelines: [ - "Use browser_go_back to return to the previous page after navigating.", - ], - parameters: Type.Object({}), - async execute() { - try { - await daemon.ensureAlive(); - const history = (await daemon.cdp("Page.getNavigationHistory")) as { - entries: Array<{ id: number; url: string; title: string }>; - currentIndex: number; - }; - if (history.currentIndex <= 0) { - return { content: [{ type: "text" as const, text: "Already at the beginning of history." }], details: undefined }; - } - const targetEntry = history.entries[history.currentIndex - 1]; - await daemon.cdp("Page.navigateToHistoryEntry", { entryId: targetEntry.id }); - return { content: [{ type: "text" as const, text: `Navigated back to: ${targetEntry.url}` }], details: undefined }; - } catch (err) { - return { - isError: true, - content: [{ type: "text" as const, text: `Failed: ${err instanceof Error ? err.message : String(err)}` }], - details: undefined, - }; - } - }, - }); - - // ═══════════════════════════════════════════════════════════════════════════ - // browser_go_forward - // ═══════════════════════════════════════════════════════════════════════════ - pi.registerTool({ - name: "browser_go_forward", - label: "Browser Go Forward", - description: "Navigate forward one page in history.", - promptSnippet: "Go forward one page in browser history", - promptGuidelines: [ - "Use browser_go_forward to go forward after navigating back.", - ], - parameters: Type.Object({}), - async execute() { - try { - await daemon.ensureAlive(); - const history = (await daemon.cdp("Page.getNavigationHistory")) as { - entries: Array<{ id: number; url: string; title: string }>; - currentIndex: number; - }; - if (history.currentIndex >= history.entries.length - 1) { - return { content: [{ type: "text" as const, text: "Already at the end of history." }], details: undefined }; - } - const targetEntry = history.entries[history.currentIndex + 1]; - await daemon.cdp("Page.navigateToHistoryEntry", { entryId: targetEntry.id }); - return { content: [{ type: "text" as const, text: `Navigated forward to: ${targetEntry.url}` }], details: undefined }; - } catch (err) { - return { - isError: true, - content: [{ type: "text" as const, text: `Failed: ${err instanceof Error ? err.message : String(err)}` }], - details: undefined, - }; - } - }, - }); - - // ═══════════════════════════════════════════════════════════════════════════ - // browser_reload - // ═══════════════════════════════════════════════════════════════════════════ - pi.registerTool({ - name: "browser_reload", - label: "Browser Reload", - description: "Reload the current page.", - promptSnippet: "Reload the current page", - promptGuidelines: [ - "Use browser_reload to refresh the current page, e.g. after making changes that should be reflected.", - ], - parameters: Type.Object({}), - async execute() { - try { - await daemon.ensureAlive(); - await daemon.cdp("Page.reload"); - const info = await daemon.getPageInfo(); - if ("dialog" in info) { - return { content: [{ type: "text" as const, text: `Reloaded. ⚠️ Dialog open: ${info.dialog.type}` }], details: undefined }; - } - return { content: [{ type: "text" as const, text: `Reloaded: ${info.title} (${info.url})` }], details: undefined }; - } catch (err) { - return { - isError: true, - content: [{ type: "text" as const, text: `Failed: ${err instanceof Error ? err.message : String(err)}` }], - details: undefined, - }; - } - }, - }); - - // ═══════════════════════════════════════════════════════════════════════════ +// ═══════════════════════════════════════════════════════════════════════════ // browser_upload_file // ═══════════════════════════════════════════════════════════════════════════ pi.registerTool({ |
