aboutsummaryrefslogtreecommitdiff
path: root/src/registry.ts
blob: d09f1cc93128b310eb612a7a1cd0e9ba88c5799c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
import type { BrowserClient } from "./client";
import { type AnyBrowserToolDefinition, registerBrowserTool } from "./util/tool";
import { clickTool } from "./domains/click";
import { typeTool, pressKeyTool, dispatchKeyTool } from "./domains/keyboard";
import { fillTool, selectOptionTool, focusTool } from "./domains/form";
import { pageInfoTool, waitTool, waitForLoadTool } from "./domains/page";
import { scrollTool } from "./domains/scroll";
import { handleDialogTool } from "./domains/dialog";
import { screenshotTool } from "./domains/screenshot";
import { navigateTool, openUrlsTool } from "./domains/navigate";
import { goBackTool, goForwardTool, reloadTool } from "./domains/history";
import { listTabsTool, currentTabTool, switchTabTool, newTabTool, closeTabTool } from "./domains/tabs";
import { uploadFileTool, downloadTool, printToPdfTool } from "./domains/files";
import { viewportResizeTool } from "./domains/viewport";
import { dragAndDropTool } from "./domains/drag";
import { httpGetTool, networkRequestsTool } from "./domains/network";
import { consoleTool } from "./domains/console";
import { snapshotTool } from "./domains/snapshot";
import { executeJsTool, runScriptTool } from "./domains/js";
import { setupTool } from "./domains/setup";

// Mutation tools that modify page / browser state are marked `serialized: true`
// so they run through a shared async mutex.  Observation / read-only tools are
// left unmarked and can execute in parallel.
const TOOLS: ReadonlyArray<AnyBrowserToolDefinition> = [
  // setup comes first — the agent calls this to self-recover from not-initialized
  setupTool,
  { ...clickTool, serialized: true },
  { ...typeTool, serialized: true },
  { ...fillTool, serialized: true },
  { ...selectOptionTool, serialized: true },
  { ...focusTool, serialized: true },
  { ...pressKeyTool, serialized: true },
  { ...dispatchKeyTool, serialized: true },
  { ...scrollTool, serialized: true },
  pageInfoTool,
  waitTool,
  { ...waitForLoadTool, serialized: true },
  { ...handleDialogTool, serialized: true },
  screenshotTool,
  { ...navigateTool, serialized: true },
  { ...openUrlsTool, serialized: true },
  { ...goBackTool, serialized: true },
  { ...goForwardTool, serialized: true },
  { ...reloadTool, serialized: true },
  listTabsTool,
  currentTabTool,
  { ...switchTabTool, serialized: true },
  { ...newTabTool, serialized: true },
  { ...closeTabTool, serialized: true },
  { ...uploadFileTool, serialized: true },
  { ...downloadTool, serialized: true },
  { ...printToPdfTool, serialized: true },
  { ...viewportResizeTool, serialized: true },
  { ...dragAndDropTool, serialized: true },
  httpGetTool,
  networkRequestsTool,
  consoleTool,
  snapshotTool,
  executeJsTool,
  runScriptTool,
];

export const registerAllTools = (pi: ExtensionAPI, client: BrowserClient): void => {
  for (const t of TOOLS) registerBrowserTool(pi, client, t);
};