@akshayram1/omnibrowser-agent 0.2.29 → 0.3.0
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.
- package/.env +1 -0
- package/README.github.md +330 -0
- package/README.md +94 -167
- package/README.npm.md +220 -0
- package/demo1.gif +0 -0
- package/dist/background.js +1 -1
- package/dist/background.js.map +1 -1
- package/dist/content.js +63 -15
- package/dist/content.js.map +3 -3
- package/dist/lib.js +103 -19
- package/dist/lib.js.map +3 -3
- package/dist/manifest.json +1 -1
- package/dist/types/lib/index.d.ts +1 -0
- package/dist/types/shared/contracts.d.ts +2 -0
- package/dist/types/shared/parse-action.d.ts +1 -0
- package/dist/types/shared/safety.d.ts +2 -2
- package/icons/big.png +0 -0
- package/icons/logo.png +0 -0
- package/icons/logo_horizontal.png +0 -0
- package/notebook/.env +1 -0
- package/notebook/README.md +39 -0
- package/notebook/custom_quantized_llm_colab copy.ipynb +7084 -0
- package/notebook/data/omnibrowser_planner_train.jsonl +500 -0
- package/package.json +4 -2
- package/.github/workflows/ci.yml +0 -41
- package/docs/ARCHITECTURE.md +0 -64
- package/docs/DEPLOYMENT.md +0 -67
- package/docs/EMBEDDING.md +0 -74
- package/docs/ROADMAP.md +0 -29
- package/docs/arch.md +0 -220
- package/index.html +0 -1448
- package/plan.md +0 -114
- package/styles.css +0 -845
- package/vercel.json +0 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akshayram1/omnibrowser-agent",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/lib.js",
|
|
@@ -20,7 +20,9 @@
|
|
|
20
20
|
"build:types": "tsc -p tsconfig.lib.json",
|
|
21
21
|
"watch": "node scripts/build.mjs --watch",
|
|
22
22
|
"typecheck": "tsc --noEmit && tsc -p tsconfig.test.json --noEmit",
|
|
23
|
-
"test": "node --experimental-strip-types --test src/shared/safety.test.ts src/core/planner.test.ts"
|
|
23
|
+
"test": "node --experimental-strip-types --test src/shared/safety.test.ts src/core/planner.test.ts",
|
|
24
|
+
"prepack": "cp README.md README.github.md && cp README.npm.md README.md",
|
|
25
|
+
"postpack": "mv README.github.md README.md"
|
|
24
26
|
},
|
|
25
27
|
"devDependencies": {
|
|
26
28
|
"@types/chrome": "^0.0.322",
|
package/.github/workflows/ci.yml
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
name: CI
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches: [main]
|
|
6
|
-
|
|
7
|
-
permissions:
|
|
8
|
-
contents: write
|
|
9
|
-
|
|
10
|
-
jobs:
|
|
11
|
-
ci:
|
|
12
|
-
runs-on: ubuntu-latest
|
|
13
|
-
steps:
|
|
14
|
-
- uses: actions/checkout@v4
|
|
15
|
-
with:
|
|
16
|
-
token: ${{ secrets.GITHUB_TOKEN }}
|
|
17
|
-
|
|
18
|
-
- uses: actions/setup-node@v4
|
|
19
|
-
with:
|
|
20
|
-
node-version: '22'
|
|
21
|
-
registry-url: 'https://registry.npmjs.org'
|
|
22
|
-
|
|
23
|
-
- name: Install dependencies
|
|
24
|
-
run: npm install
|
|
25
|
-
|
|
26
|
-
- name: Run tests
|
|
27
|
-
run: npm test
|
|
28
|
-
|
|
29
|
-
- name: Bump patch version
|
|
30
|
-
id: bump
|
|
31
|
-
run: |
|
|
32
|
-
NEW_VERSION=$(npm version patch --no-git-tag-version)
|
|
33
|
-
echo "version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
|
|
34
|
-
|
|
35
|
-
- name: Commit version bump
|
|
36
|
-
run: |
|
|
37
|
-
git config user.name "github-actions[bot]"
|
|
38
|
-
git config user.email "github-actions[bot]@users.noreply.github.com"
|
|
39
|
-
git add package.json
|
|
40
|
-
git commit -m "chore: bump version to ${{ steps.bump.outputs.version }} [skip ci]"
|
|
41
|
-
git push
|
package/docs/ARCHITECTURE.md
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
# OmniBrowser Agent Architecture (v0.2)
|
|
2
|
-
|
|
3
|
-
## Goals
|
|
4
|
-
|
|
5
|
-
- Local-first runtime in browser
|
|
6
|
-
- Privacy-first defaults
|
|
7
|
-
- Open-source composable planner/executor contracts
|
|
8
|
-
- Human-approved mode for risky actions
|
|
9
|
-
|
|
10
|
-
## Runtime Components
|
|
11
|
-
|
|
12
|
-
1. Popup UI (`src/popup`)
|
|
13
|
-
- Starts/stops sessions
|
|
14
|
-
- Picks mode (`autonomous`, `human-approved`)
|
|
15
|
-
- Picks planner (`heuristic`, `webllm`)
|
|
16
|
-
|
|
17
|
-
2. Background Service Worker (`src/background`)
|
|
18
|
-
- Session state machine per tab
|
|
19
|
-
- Tick loop orchestration
|
|
20
|
-
- Approval handling
|
|
21
|
-
|
|
22
|
-
3. Content Agent (`src/content`)
|
|
23
|
-
- `observer`: page snapshot extraction
|
|
24
|
-
- `planner`: next-action decision (heuristic / WebLLM)
|
|
25
|
-
- `safety`: risk gating (`safe`, `review`, `blocked`)
|
|
26
|
-
- `executor`: DOM action execution
|
|
27
|
-
|
|
28
|
-
## Contracts
|
|
29
|
-
|
|
30
|
-
- Shared in `src/shared/contracts.ts`
|
|
31
|
-
- Action protocol:
|
|
32
|
-
- click
|
|
33
|
-
- type
|
|
34
|
-
- navigate
|
|
35
|
-
- extract
|
|
36
|
-
- scroll
|
|
37
|
-
- focus
|
|
38
|
-
- wait
|
|
39
|
-
- done
|
|
40
|
-
|
|
41
|
-
## Safety Model
|
|
42
|
-
|
|
43
|
-
- Block invalid URL protocols
|
|
44
|
-
- Review risky actions (submit/delete/pay-like selectors)
|
|
45
|
-
- In `human-approved` mode, review-level actions require manual approval
|
|
46
|
-
|
|
47
|
-
## Planner Bridges
|
|
48
|
-
|
|
49
|
-
All planner bridges follow the same pattern: an object attached to `window` that implements a `plan()` method returning an `AgentAction`. The core library has zero runtime dependencies — bridge implementations are provided by the consumer.
|
|
50
|
-
|
|
51
|
-
### WebLLM bridge
|
|
52
|
-
|
|
53
|
-
```ts
|
|
54
|
-
window.__browserAgentWebLLM = {
|
|
55
|
-
async plan(input, modelId) { /* call local WebLLM engine, return AgentAction */ }
|
|
56
|
-
};
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
## Limitations (v0.2)
|
|
60
|
-
|
|
61
|
-
- No persistent long-term memory yet
|
|
62
|
-
- No task DSL/skills registry yet
|
|
63
|
-
- Risk scoring is simple keyword heuristic
|
|
64
|
-
- Selector healing is basic (attribute fallback + single-element shortcut)
|
package/docs/DEPLOYMENT.md
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
# Deployment Guide
|
|
2
|
-
|
|
3
|
-
## npm Package
|
|
4
|
-
|
|
5
|
-
### Publish a new version manually
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm run build
|
|
9
|
-
npm publish --access public
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
The CI pipeline auto-bumps the patch version on every push to `main`, so manual version bumps are only needed for minor/major releases:
|
|
13
|
-
|
|
14
|
-
```bash
|
|
15
|
-
npm version minor # 0.2.x → 0.3.0
|
|
16
|
-
npm version major # 0.x.y → 1.0.0
|
|
17
|
-
npm run build
|
|
18
|
-
npm publish --access public
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
### Required secret
|
|
22
|
-
|
|
23
|
-
Add `NPM_TOKEN` to your GitHub repository secrets if you want the pipeline to publish automatically (not enabled by default).
|
|
24
|
-
|
|
25
|
-
---
|
|
26
|
-
|
|
27
|
-
## Vercel (Static Site / Chatbot Demo)
|
|
28
|
-
|
|
29
|
-
The homepage and chatbot demo are static files served from the repo root.
|
|
30
|
-
|
|
31
|
-
1. Import the repository at [vercel.com/new](https://vercel.com/new).
|
|
32
|
-
2. Vercel picks up `vercel.json` automatically — no extra configuration needed.
|
|
33
|
-
3. Every push to `main` triggers a new deployment.
|
|
34
|
-
|
|
35
|
-
`vercel.json` key settings:
|
|
36
|
-
```json
|
|
37
|
-
{
|
|
38
|
-
"buildCommand": null,
|
|
39
|
-
"outputDirectory": "."
|
|
40
|
-
}
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
---
|
|
44
|
-
|
|
45
|
-
## Chrome Extension (local / sideload)
|
|
46
|
-
|
|
47
|
-
1. Build the extension bundle:
|
|
48
|
-
```bash
|
|
49
|
-
npm run build
|
|
50
|
-
```
|
|
51
|
-
2. Open `chrome://extensions` and enable **Developer mode**.
|
|
52
|
-
3. Click **Load unpacked** and select the `public/` folder.
|
|
53
|
-
|
|
54
|
-
To update after code changes, rebuild and click the refresh icon on the extension card.
|
|
55
|
-
|
|
56
|
-
---
|
|
57
|
-
|
|
58
|
-
## CI Pipeline
|
|
59
|
-
|
|
60
|
-
The GitHub Actions workflow (`.github/workflows/ci.yml`) runs on every push to `main`:
|
|
61
|
-
|
|
62
|
-
1. Installs dependencies.
|
|
63
|
-
2. Runs `npm test` (Node built-in test runner, no extra deps).
|
|
64
|
-
3. Bumps the patch version in `package.json` via `npm version patch`.
|
|
65
|
-
4. Commits and pushes the version bump with `[skip ci]` to avoid a second run.
|
|
66
|
-
|
|
67
|
-
The commit is made by `github-actions[bot]` using the built-in `GITHUB_TOKEN` — no extra secrets required.
|
package/docs/EMBEDDING.md
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
# Embedding OmniBrowser Agent in Your Website
|
|
2
|
-
|
|
3
|
-
You can keep the extension flow and also embed OmniBrowser Agent as a library in your own web app.
|
|
4
|
-
|
|
5
|
-
## Install
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install @akshayram1/omnibrowser-agent
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Basic usage
|
|
12
|
-
|
|
13
|
-
```ts
|
|
14
|
-
import { createBrowserAgent } from "@akshayram1/omnibrowser-agent";
|
|
15
|
-
|
|
16
|
-
const agent = createBrowserAgent(
|
|
17
|
-
{
|
|
18
|
-
goal: "Search contact Jane Doe and open profile",
|
|
19
|
-
mode: "human-approved",
|
|
20
|
-
planner: { kind: "heuristic" },
|
|
21
|
-
maxSteps: 15,
|
|
22
|
-
stepDelayMs: 400
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
onStep: (result) => console.log("step", result),
|
|
26
|
-
onApprovalRequired: (action) => {
|
|
27
|
-
console.log("approval required", action);
|
|
28
|
-
// Show your own modal/button then call approvePendingAction()
|
|
29
|
-
},
|
|
30
|
-
onDone: (result) => console.log("done", result),
|
|
31
|
-
onError: (error) => console.error(error)
|
|
32
|
-
}
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
await agent.start();
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
## Approve a pending action
|
|
39
|
-
|
|
40
|
-
```ts
|
|
41
|
-
await agent.approvePendingAction();
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
## Stop running session
|
|
45
|
-
|
|
46
|
-
```ts
|
|
47
|
-
agent.stop();
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
## WebLLM mode in embedded app
|
|
51
|
-
|
|
52
|
-
To use planner mode `webllm`, load the WebLLM engine and wire the bridge before starting the agent:
|
|
53
|
-
|
|
54
|
-
```ts
|
|
55
|
-
import * as webllm from "@mlc-ai/web-llm";
|
|
56
|
-
import { createBrowserAgent, createWebLLMBridge } from "@akshayram1/omnibrowser-agent";
|
|
57
|
-
|
|
58
|
-
const engine = await webllm.CreateMLCEngine("Llama-3.2-1B-Instruct-q4f16_1-MLC");
|
|
59
|
-
|
|
60
|
-
window.__browserAgentWebLLM = createWebLLMBridge(engine);
|
|
61
|
-
|
|
62
|
-
const agent = createBrowserAgent({
|
|
63
|
-
goal: "Fill the contact form",
|
|
64
|
-
planner: { kind: "webllm", modelId: "Llama-3.2-1B-Instruct-q4f16_1-MLC" }
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
await agent.start();
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
## Notes
|
|
71
|
-
|
|
72
|
-
- For production, mount this inside an authenticated app shell and add your own permission checks.
|
|
73
|
-
- `human-approved` mode is recommended for CRM/finance/admin actions.
|
|
74
|
-
- Bring your own WebLLM engine instance, then wire `createWebLLMBridge(engine)` to `window.__browserAgentWebLLM`.
|
package/docs/ROADMAP.md
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
# Roadmap
|
|
2
|
-
|
|
3
|
-
## v0.1
|
|
4
|
-
|
|
5
|
-
- Extension runtime loop
|
|
6
|
-
- Shared action contracts
|
|
7
|
-
- Heuristic + WebLLM planner switch
|
|
8
|
-
- Human-approved mode
|
|
9
|
-
|
|
10
|
-
## v0.2 (current)
|
|
11
|
-
|
|
12
|
-
- New actions: `scroll`, `focus`
|
|
13
|
-
- Improved heuristic planner with regex goal patterns
|
|
14
|
-
- Better page observation (visibility filtering, placeholder capture)
|
|
15
|
-
- Library API: `resume()`, `isRunning`, `hasPendingAction`, `AbortSignal`, `onMaxStepsReached`
|
|
16
|
-
|
|
17
|
-
## v0.3
|
|
18
|
-
|
|
19
|
-
- Expanded WebLLM model catalog (new 7B/8B options + compatibility matrix)
|
|
20
|
-
- Improved model loading UX (recommended presets by speed/quality and device memory)
|
|
21
|
-
- Enhanced default system prompts for safer, clearer multi-step planning
|
|
22
|
-
- Prompt presets for common workflows (docs navigation, CRM form fill, task automation)
|
|
23
|
-
|
|
24
|
-
## v1.0
|
|
25
|
-
|
|
26
|
-
- Advanced prompt orchestration (goal-aware system prompt routing and contextual guardrails)
|
|
27
|
-
- Functionality expansion: richer action toolkit and stronger extraction/navigation reliability
|
|
28
|
-
- Adaptive planner behaviour (model-aware retries, fallback strategies, and recovery flows)
|
|
29
|
-
- Evaluation suite for prompt and model quality across benchmark browser tasks
|
package/docs/arch.md
DELETED
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
# omnibrowser-agent — Architecture
|
|
2
|
-
|
|
3
|
-
> Local-first browser AI operator. Runs entirely in the browser — no API keys, no cloud costs, no data leaving your machine.
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
## Architecture Diagram
|
|
8
|
-
|
|
9
|
-
```mermaid
|
|
10
|
-
flowchart TB
|
|
11
|
-
subgraph DELIVERY["Delivery Layer"]
|
|
12
|
-
EXT["🧩 Chrome Extension\npopup + background worker"]
|
|
13
|
-
LIB["📦 npm Library\ncreateBrowserAgent()"]
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
subgraph ORCHESTRATION["Orchestration"]
|
|
17
|
-
BG["background/index.ts\nSession & tick loop"]
|
|
18
|
-
BA["BrowserAgent class\nrunLoop() / resume() / stop()"]
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
subgraph CORE["Core (src/core/)"]
|
|
22
|
-
PL["planner.ts\nheuristicPlan() / webllm bridge\nplanNextAction()"]
|
|
23
|
-
OB["observer.ts\ncollectSnapshot()\nDOM candidates + visibility filter"]
|
|
24
|
-
EX["executor.ts\nexecuteAction()\nclick / type / navigate\nscroll / focus / wait"]
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
subgraph SHARED["Shared (src/shared/)"]
|
|
28
|
-
CT["contracts.ts\nAgentAction · PageSnapshot\nAgentSession · PlannerResult"]
|
|
29
|
-
SF["safety.ts\nassessRisk()\nsafe / review / blocked"]
|
|
30
|
-
PA["parse-action.ts\nparseAction()\nparsePlannerResult()"]
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
subgraph OUTCOMES["Action Outcomes"]
|
|
34
|
-
direction LR
|
|
35
|
-
OK["✅ safe → execute"]
|
|
36
|
-
RV["⚠️ review → needs approval"]
|
|
37
|
-
BL["🚫 blocked → stop"]
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
subgraph PLANNERS["Planner Modes"]
|
|
41
|
-
direction LR
|
|
42
|
-
HP["Heuristic\nzero deps · offline\nregex patterns"]
|
|
43
|
-
WL["WebLLM\non-device · WebGPU\nwindow.__browserAgentWebLLM"]
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
EXT --> BG
|
|
47
|
-
LIB --> BA
|
|
48
|
-
BG -. "chrome.tabs.sendMessage" .-> CORE
|
|
49
|
-
BA --> CORE
|
|
50
|
-
|
|
51
|
-
PL --> OB
|
|
52
|
-
PL --> SHARED
|
|
53
|
-
OB --> SHARED
|
|
54
|
-
EX --> SHARED
|
|
55
|
-
|
|
56
|
-
SF --> OUTCOMES
|
|
57
|
-
PL --> PLANNERS
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
---
|
|
61
|
-
|
|
62
|
-
## Layer-by-layer explanation
|
|
63
|
-
|
|
64
|
-
### Delivery layer
|
|
65
|
-
|
|
66
|
-
There are two ways to use omnibrowser-agent, and they share the same underlying engine.
|
|
67
|
-
|
|
68
|
-
**Chrome extension** — Install by loading the `dist/` folder as an unpacked extension in Chrome. A popup UI lets you enter a goal, pick a mode, and click Start. The background service worker manages session state and orchestrates the tick loop across tabs.
|
|
69
|
-
|
|
70
|
-
**npm library** — Embed agent logic directly into any web app. Import `createBrowserAgent()` from `@akshayram1/omnibrowser-agent`, pass a goal and config, and wire up event callbacks. No extension required.
|
|
71
|
-
|
|
72
|
-
---
|
|
73
|
-
|
|
74
|
-
### Orchestration
|
|
75
|
-
|
|
76
|
-
**`background/index.ts`** (extension path) maintains a `Map<tabId, AgentSession>` and drives each session forward by sending `AGENT_TICK` messages to the active tab's content script. It handles `START_AGENT`, `APPROVE_ACTION`, `STOP_AGENT`, and `GET_STATUS` messages from the popup.
|
|
77
|
-
|
|
78
|
-
**`BrowserAgent` class** (library path) runs the same tick loop in-process. It exposes `start()`, `resume()`, `stop()`, `isRunning`, and `hasPendingAction`, along with a full event callback API (`onStep`, `onApprovalRequired`, `onDone`, `onError`, `onMaxStepsReached`). Supports `AbortSignal` for external cancellation.
|
|
79
|
-
|
|
80
|
-
---
|
|
81
|
-
|
|
82
|
-
### Core (`src/core/`)
|
|
83
|
-
|
|
84
|
-
These three modules are **shared** between the extension content script and the library. Neither delivery path duplicates them.
|
|
85
|
-
|
|
86
|
-
| Module | Responsibility |
|
|
87
|
-
|---|---|
|
|
88
|
-
| `planner.ts` | Decides the next action given a goal, page snapshot, and history |
|
|
89
|
-
| `observer.ts` | Reads the live DOM and returns a structured `PageSnapshot` |
|
|
90
|
-
| `executor.ts` | Performs DOM actions and returns a result string |
|
|
91
|
-
|
|
92
|
-
**`observer.ts` — `collectSnapshot()`**
|
|
93
|
-
Queries all interactive elements (`a`, `button`, `input`, `textarea`, `select`, `[role=button]`, `[contenteditable]`), filters out invisible ones (hidden, `display:none`, zero dimensions), and prioritises in-viewport elements. Resolves accessible labels via `aria-labelledby`, `aria-label`, `for/id`, and wrapping `<label>`. Generates stable CSS selectors preferring `name`, `placeholder`, and `aria-label` attributes over fragile `:nth-of-type()` indices. Caps at 60 candidates. Returns `url`, `title`, `textPreview`, and `candidates[]`.
|
|
94
|
-
|
|
95
|
-
**`planner.ts` — `planNextAction()`**
|
|
96
|
-
Two modes:
|
|
97
|
-
- *Heuristic* — pure regex. Matches `go to <url>`, `search for <x>`, `fill "<text>" in <field>`, `click <target>` patterns against the goal string, then falls back to filling the first visible input or clicking the first visible button.
|
|
98
|
-
- *WebLLM* — delegates to `window.__browserAgentWebLLM.plan()`. The bridge is external — you wire it in. Accepts both legacy `AgentAction` returns and the new `PlannerResult` (with `evaluation`, `memory`, `nextGoal` reflection fields).
|
|
99
|
-
|
|
100
|
-
**`executor.ts` — `executeAction()`**
|
|
101
|
-
Performs the action. Uses `InputEvent` with `bubbles: true` so React/Vue controlled inputs receive proper framework events. Verifies: element exists, is not disabled (for clicks), value updated (for type), extracted text is non-empty. Includes selector fallback: when a selector fails, tries to recover via tag+attribute matching or single-element shortcut before throwing. Throws on failure so the retry loop can feed `lastError` back to the planner.
|
|
102
|
-
|
|
103
|
-
---
|
|
104
|
-
|
|
105
|
-
### Shared (`src/shared/`)
|
|
106
|
-
|
|
107
|
-
**`contracts.ts`** — All TypeScript interfaces and union types. The single source of truth for `AgentAction`, `PageSnapshot`, `AgentSession`, `PlannerResult`, `ContentResult`, and the library config/event types.
|
|
108
|
-
|
|
109
|
-
**`safety.ts` — `assessRisk()`**
|
|
110
|
-
Returns one of three risk levels for any action:
|
|
111
|
-
|
|
112
|
-
| Level | Meaning | Examples |
|
|
113
|
-
|---|---|---|
|
|
114
|
-
| `safe` | Execute immediately | `navigate` to http/https, `click` neutral label, `scroll`, `wait`, `focus` |
|
|
115
|
-
| `review` | Pause for human approval in `human-approved` mode | `extract`, `click`/`type` on labels matching delete/pay/submit/confirm/transfer |
|
|
116
|
-
| `blocked` | Never execute | `navigate` to `javascript:`, `file:`, or malformed URLs |
|
|
117
|
-
|
|
118
|
-
**`parse-action.ts`** — Handles LLM output that may be wrapped in markdown fences, embedded in prose, or using the full reflection format `{ evaluation, memory, next_goal, action }`. Gracefully returns a `done` action on any parse failure so the loop never crashes.
|
|
119
|
-
|
|
120
|
-
---
|
|
121
|
-
|
|
122
|
-
### Planner modes
|
|
123
|
-
|
|
124
|
-
| Mode | Description | When to use |
|
|
125
|
-
|---|---|---|
|
|
126
|
-
| `heuristic` | Zero-dependency regex-based planner. Works fully offline. | Simple, predictable goals — navigate, search, fill a field, click a button |
|
|
127
|
-
| `webllm` | Delegates to a `window.__browserAgentWebLLM` bridge. Fully private, runs on-device via WebGPU. | Open-ended, multi-step, or language-heavy goals |
|
|
128
|
-
|
|
129
|
-
---
|
|
130
|
-
|
|
131
|
-
### Agent modes
|
|
132
|
-
|
|
133
|
-
| Mode | Behaviour |
|
|
134
|
-
|---|---|
|
|
135
|
-
| `autonomous` | All `safe` and `review` actions execute without pause |
|
|
136
|
-
| `human-approved` | `review`-rated actions pause and emit `onApprovalRequired` — user must call `resume()` or click **Approve** in the popup |
|
|
137
|
-
|
|
138
|
-
---
|
|
139
|
-
|
|
140
|
-
### Data flow (one tick)
|
|
141
|
-
|
|
142
|
-
```
|
|
143
|
-
goal + history
|
|
144
|
-
│
|
|
145
|
-
▼
|
|
146
|
-
observer.collectSnapshot() ──→ PageSnapshot (url, title, candidates[])
|
|
147
|
-
│
|
|
148
|
-
▼
|
|
149
|
-
planner.planNextAction() ──→ PlannerResult { action, evaluation?, memory?, nextGoal? }
|
|
150
|
-
│
|
|
151
|
-
▼
|
|
152
|
-
safety.assessRisk(action) ──→ safe | review | blocked
|
|
153
|
-
│
|
|
154
|
-
┌──┴──────────────────────┐
|
|
155
|
-
blocked review (human-approved mode)
|
|
156
|
-
│ │
|
|
157
|
-
stop pause → user approves → resume
|
|
158
|
-
│
|
|
159
|
-
safe / approved
|
|
160
|
-
│
|
|
161
|
-
▼
|
|
162
|
-
executor.executeAction(action) ──→ result string
|
|
163
|
-
│
|
|
164
|
-
▼
|
|
165
|
-
session.history.push(result)
|
|
166
|
-
→ next tick
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
---
|
|
170
|
-
|
|
171
|
-
## Project structure
|
|
172
|
-
|
|
173
|
-
```
|
|
174
|
-
src/
|
|
175
|
-
├── background/ Extension service worker — session management
|
|
176
|
-
├── content/ Extension content script — runs in page context
|
|
177
|
-
├── core/ Shared engine (planner, observer, executor)
|
|
178
|
-
│ ├── planner.ts
|
|
179
|
-
│ ├── observer.ts
|
|
180
|
-
│ └── executor.ts
|
|
181
|
-
├── lib/ npm library entry — BrowserAgent class
|
|
182
|
-
│ └── index.ts
|
|
183
|
-
├── popup/ Extension popup UI
|
|
184
|
-
│ ├── index.html
|
|
185
|
-
│ └── index.ts
|
|
186
|
-
└── shared/ Types, safety, and parse utilities
|
|
187
|
-
├── contracts.ts
|
|
188
|
-
├── safety.ts
|
|
189
|
-
└── parse-action.ts
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
---
|
|
193
|
-
|
|
194
|
-
## Quick reference
|
|
195
|
-
|
|
196
|
-
```ts
|
|
197
|
-
import { createBrowserAgent } from "@akshayram1/omnibrowser-agent";
|
|
198
|
-
|
|
199
|
-
const agent = createBrowserAgent({
|
|
200
|
-
goal: "Search for contact John Smith in CRM",
|
|
201
|
-
mode: "human-approved", // or "autonomous"
|
|
202
|
-
planner: { kind: "heuristic" } // or "webllm"
|
|
203
|
-
}, {
|
|
204
|
-
onStep: (result, session) => console.log(result.message),
|
|
205
|
-
onApprovalRequired:(action, session) => console.log("Review:", action),
|
|
206
|
-
onDone: (result, session) => console.log("Done:", result.message),
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
await agent.start();
|
|
210
|
-
|
|
211
|
-
// After onApprovalRequired fires:
|
|
212
|
-
await agent.resume();
|
|
213
|
-
|
|
214
|
-
// Cancel at any time:
|
|
215
|
-
agent.stop();
|
|
216
|
-
```
|
|
217
|
-
|
|
218
|
-
---
|
|
219
|
-
|
|
220
|
-
*MIT © Akshay Chame — [github.com/akshayram1/omnibrowser-agent](https://github.com/akshayram1/omnibrowser-agent)*
|