@capybara-hq/plugin-browser 0.1.0-rc.7 → 0.1.0-rc.9
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/.capybara-plugin/plugin.json +3 -3
- package/README.md +60 -10
- package/dist/index.mjs +86 -38
- package/package.json +2 -2
- package/ui/panel.js +149 -41
- package/ui/service/daemon.mjs +1267 -307
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
3
|
"name": "browser",
|
|
4
|
-
"version": "0.1.0-rc.
|
|
4
|
+
"version": "0.1.0-rc.9",
|
|
5
5
|
"publisher": "Capybara",
|
|
6
6
|
"description": {
|
|
7
7
|
"en": "A real browser in the conversation owner's device for agents: navigate, read and act on pages through tools, with a live view in the conversation panel and takeover by the person",
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
"entry": "./dist/index.mjs",
|
|
18
18
|
"manifest": {
|
|
19
19
|
"name": "browser",
|
|
20
|
-
"version": "0.1.0-rc.
|
|
21
|
-
"sdk": "^0.1.0-rc.
|
|
20
|
+
"version": "0.1.0-rc.9",
|
|
21
|
+
"sdk": "^0.1.0-rc.75",
|
|
22
22
|
"provides": [],
|
|
23
23
|
"requires": [],
|
|
24
24
|
"optional": [],
|
package/README.md
CHANGED
|
@@ -26,6 +26,10 @@ A real browser in the person's device for agents (browser use spec,
|
|
|
26
26
|
`ctx.deviceAccess.ensureService` (files: every file under `ui/service/`, read once per
|
|
27
27
|
extension instance), sends one `ToolRequest` and reports the hosts the device refused with
|
|
28
28
|
`reportBlockedHosts` (the kernel raises the network ask and reruns the call once allowed).
|
|
29
|
+
Every request carries the call's `conversationId` and `rootConversationId` from the kernel's
|
|
30
|
+
tool call context (written after the operation, never from tool input). A result names the
|
|
31
|
+
conversation's active tab, or says "This conversation has no browser tab yet.", and every result
|
|
32
|
+
the daemon answered, ok or error, ends with "Tabs open in this conversation: N of 6.".
|
|
29
33
|
- `browser_handoff` sends the daemon a handoff notice (the panels show a banner with 完成 / 取消),
|
|
30
34
|
then raises an `InputRequired` question `{ done: boolean }` in the conversation, with `open`
|
|
31
35
|
naming the `browser` panel so the person's conversation page opens it. The question's title is
|
|
@@ -41,8 +45,11 @@ A real browser in the person's device for agents (browser use spec,
|
|
|
41
45
|
- Panel routes: `GET /ui/browser` (the page) and `GET /ui/panel.js` are public; `POST
|
|
42
46
|
/ui/stream-ticket`, `/ui/network-hosts` and `/ui/handoff-answer` are `embed` routes that take
|
|
43
47
|
the org, account and conversation from the caller only (a platform-scope token or one without a
|
|
44
|
-
conversation gets 403).
|
|
45
|
-
|
|
48
|
+
conversation gets 403). `/ui/handoff-answer` takes `{ callId, handoffConversationId, done }`:
|
|
49
|
+
the panel echoes the handoff's conversation from the daemon's `state.handoffs` (a sub-agent's,
|
|
50
|
+
in the root's panel), and the kernel answers only for the scope conversation or a descendant.
|
|
51
|
+
The panel never starts the service: a ticket is minted either way, and a stopped service closes
|
|
52
|
+
the viewer with 4404 (the panel's "not running" state).
|
|
46
53
|
|
|
47
54
|
## The daemon (`daemon/`)
|
|
48
55
|
|
|
@@ -104,7 +111,8 @@ A real browser in the person's device for agents (browser use spec,
|
|
|
104
111
|
running for up to 24 hours after its notice (the person may take a while to sign in); the
|
|
105
112
|
device's own idle suspension can still stop it sooner, and then the question stays open in the
|
|
106
113
|
conversation without its banner until the browser runs again.
|
|
107
|
-
- `<state>/session.json` keeps the open tabs' URLs
|
|
114
|
+
- `<state>/session.json` keeps the open tabs' URLs with their owners and, per conversation, the
|
|
115
|
+
active tab, the pending handoff and park (an older file is not restored). A daemon started within
|
|
108
116
|
10 minutes of the last write (a provider that restarts the service for a network change, see
|
|
109
117
|
device-local) reopens them; an idle stop removes the file. The profile keeps cookies and storage
|
|
110
118
|
on its own.
|
|
@@ -117,11 +125,12 @@ A real browser in the person's device for agents (browser use spec,
|
|
|
117
125
|
either: the daemon runs Chromium with `--use-mock-keychain`, so its values are only obfuscated
|
|
118
126
|
with a key every Chromium shares (observed: `encrypted_value` of 51 bytes, readable by anyone
|
|
119
127
|
who can read the directory). The JSON therefore adds no exposure.
|
|
120
|
-
- A `handoff_clear` with `handback` (the person answered Done) also ends a takeover.
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
128
|
+
- A `handoff_clear` with `handback` (the person answered Done) also ends a takeover. A handoff is
|
|
129
|
+
kept per conversation (at most one each) and dropped only by that conversation's next request.
|
|
130
|
+
- Viewer input (mouse, keys, text, address bar, tab open / switch / close) is applied only while
|
|
131
|
+
the person holds control: in the watch state a viewer may only choose its shown tab (`show`, a
|
|
132
|
+
tab of its tree) and move another conversation's tab here (`tab` `adopt`); any other input is
|
|
133
|
+
dropped on arrival, and input
|
|
125
134
|
still queued when control returns to the agent is dropped too (input already running, a navigation
|
|
126
135
|
or a long paste, finishes). Keys and buttons the person still holds are released when control
|
|
127
136
|
returns to the agent or the viewer ends, each on the tab where it was pressed (a held button after
|
|
@@ -145,14 +154,55 @@ A real browser in the person's device for agents (browser use spec,
|
|
|
145
154
|
(a stale one is replaced), and Chromium encodes the next frame at most every 500 ms while one
|
|
146
155
|
waits. JSON messages (state, cursor, pings, dialogs) never wait behind a held frame.
|
|
147
156
|
|
|
157
|
+
## Tabs
|
|
158
|
+
|
|
159
|
+
Tab ownership spec, `docs/superpowers/specs/2026-11-25-browser-tab-ownership-design.md` in
|
|
160
|
+
capybara-hq/core. One daemon, one Chromium and one profile per device stay: logins and cookies are
|
|
161
|
+
shared by every conversation, the tabs are not.
|
|
162
|
+
|
|
163
|
+
- **Owned per conversation.** Every tab belongs to one conversation, which alone acts on it, and
|
|
164
|
+
each conversation has its own active tab and its own action queue. A conversation's first acting
|
|
165
|
+
call takes the browser's blank start tab if it is free, else opens a new tab (never another
|
|
166
|
+
unowned page); `tabs list`, `adopt`, `wait` and the handoff bookkeeping never open one. When a
|
|
167
|
+
conversation loses its active tab, the tab it gained last becomes active. A popup belongs to the
|
|
168
|
+
owner of the page that opened it. `switch` and `close` take only the conversation's own tabs.
|
|
169
|
+
- **Seen per task tree.** A conversation and its sub-agent conversations form a tree whose root is
|
|
170
|
+
the conversation the person looks at. `tabs list` shows the conversation's own tabs, then the
|
|
171
|
+
tree's other tabs, then other trees' tabs (titles cut to 120 characters, URLs without query or
|
|
172
|
+
fragment). A panel shows its tree's tabs, grouped per sub-task, and the newest pending handoff of
|
|
173
|
+
the tree; a sub-agent's handoff is answered with Done from the root's panel.
|
|
174
|
+
- **Adopt / Move here.** `browser_tabs` action `adopt` (with `tabId`) moves another conversation's
|
|
175
|
+
tab (or an unowned one) to the calling conversation and makes it its active tab; the previous
|
|
176
|
+
owner's next result says so. The panel's 其他对话 / Other conversations menu does the same with
|
|
177
|
+
移到此对话 / Move here, also while only watching. Refused while the owner is in use (a request in
|
|
178
|
+
flight or a pending handoff, long wait or held dialog).
|
|
179
|
+
- **Caps and eviction.** At most 10 tabs in the browser and 6 per conversation. At the device cap
|
|
180
|
+
the daemon first closes the least recently used tab of a conversation that is not in use and has
|
|
181
|
+
made no request for 5 minutes (its non-active tabs before its active one) and tells that
|
|
182
|
+
conversation; it refuses only when no tab qualifies.
|
|
183
|
+
- **Idle close.** A conversation's tabs close after 15 minutes without a request, without an open
|
|
184
|
+
panel showing it and without a pending park; its per-conversation state goes with them. The
|
|
185
|
+
profile is never touched.
|
|
186
|
+
- **Takeover per device.** While the person controls the browser from any conversation's panel,
|
|
187
|
+
every conversation's agent requests are refused. Afterwards only the conversations whose tabs the
|
|
188
|
+
takeover concerned are told that the user had control.
|
|
189
|
+
|
|
148
190
|
## The panel (`ui-src/panel/`)
|
|
149
191
|
|
|
150
192
|
- Every viewer is the owner's: any non-compact panel is interactive (keys, pointer, Esc) while the
|
|
151
193
|
person holds control, whichever panel took it, and may ask for frames up to the full viewport
|
|
152
|
-
then. In the watch state the panel
|
|
153
|
-
navigation; the cursor is the arrow)
|
|
194
|
+
then. In the watch state the panel takes no page input (no pointer, keys, address bar,
|
|
195
|
+
navigation or tab open / close; the cursor is the arrow), but a click on a tab of the strip shows
|
|
196
|
+
that tab, and 其他对话 / Other conversations › 移到此对话 / Move here moves another conversation's
|
|
197
|
+
tab here. Nothing is kept in storage (the sandboxed iframe has none);
|
|
154
198
|
a remount rebuilds from the daemon's first state. Take over is offered only in the live view;
|
|
155
199
|
handing back with a pending handoff answers it Done.
|
|
200
|
+
- The strip shows the conversation tree's tabs: this conversation's first, then one 子任务 /
|
|
201
|
+
Sub-task group per sub-agent conversation. With no tab in the tree while the browser runs, the
|
|
202
|
+
panel shows 智能体尚未在此对话中打开网页 / "The agent has not opened a page in this conversation
|
|
203
|
+
yet" (never another conversation's page). A refused Move here shows a short line (the tab is in
|
|
204
|
+
use, or this conversation has its most tabs). The banner shows the tree's newest pending handoff;
|
|
205
|
+
its Done / Cancel answer that handoff's conversation.
|
|
156
206
|
- Takeover input (`ui-src/panel/input.ts`): button and wheel events at once, moves coalesced to the
|
|
157
207
|
newest position at most every 33 ms (hover effects, menus and tooltips render in the stream), a
|
|
158
208
|
drag reported until the button is released wherever that happens; the page's cursor from the
|
package/dist/index.mjs
CHANGED
|
@@ -18,6 +18,8 @@ var VIEWPORT = { width: 1280, height: 800 };
|
|
|
18
18
|
var IDLE_STOP_MS = 15 * 6e4;
|
|
19
19
|
var DEFAULT_FRAME_MAX_BYTES = 256 * 1024;
|
|
20
20
|
var HANDOFF_MAX_CHARS = 4096;
|
|
21
|
+
var CONVERSATION_IDLE_MS = 15 * 6e4;
|
|
22
|
+
var EVICT_MIN_IDLE_MS = 5 * 6e4;
|
|
21
23
|
var HANDOFF_KEEPALIVE_MS = 24 * 60 * 6e4;
|
|
22
24
|
var DOWNLOAD_BLOCKED_PREFIX = "The browser could not be downloaded into the device: its network settings block ";
|
|
23
25
|
var REPLY_TOO_LARGE_MESSAGE = "The reply was too large to send; ask for less (a smaller maxBytes).";
|
|
@@ -30,9 +32,9 @@ import {
|
|
|
30
32
|
|
|
31
33
|
// src/messages.ts
|
|
32
34
|
var NOT_OWNER_MESSAGE = "Browser tools only run for the conversation's owner on their own device.";
|
|
33
|
-
var TAKEN_OVER_MESSAGE = "The user is controlling the browser; call browser_wait or browser_handoff.";
|
|
34
35
|
|
|
35
36
|
// src/browser.ts
|
|
37
|
+
var TAKEN_OVER_MESSAGE = "The user is controlling the browser; call browser_wait or browser_handoff.";
|
|
36
38
|
var START_FAILED_MESSAGE = "The browser could not start in the device; retry, and ask the user to check the device if it keeps failing.";
|
|
37
39
|
var SERVICE = "browser";
|
|
38
40
|
var RESTARTING_MESSAGE = "The browser was just installed in the device and its service is restarting; call the tool again.";
|
|
@@ -53,6 +55,16 @@ var pause = (ms, signal) => new Promise((resolve) => {
|
|
|
53
55
|
});
|
|
54
56
|
var REQUEST_TIMEOUT_MS = 9e4;
|
|
55
57
|
var TOOL_TIMEOUT_MS = 3e5;
|
|
58
|
+
var NO_TAB_MESSAGE = "This conversation has no browser tab yet.";
|
|
59
|
+
function tabsLine(tabs) {
|
|
60
|
+
return `Tabs open in this conversation: ${tabs.open} of ${tabs.max}.`;
|
|
61
|
+
}
|
|
62
|
+
function tabCountOf(reply) {
|
|
63
|
+
const t = reply.tabs;
|
|
64
|
+
if (typeof t !== "object" || t === null) return void 0;
|
|
65
|
+
const ok = (n) => typeof n === "number" && Number.isInteger(n) && n >= 0;
|
|
66
|
+
return ok(t.open) && ok(t.max) ? { open: t.open, max: t.max } : void 0;
|
|
67
|
+
}
|
|
56
68
|
function assertOwner(call) {
|
|
57
69
|
if (call.ownerAccountId === void 0 || call.accountId !== call.ownerAccountId)
|
|
58
70
|
throw new ToolError(NOT_OWNER_MESSAGE);
|
|
@@ -86,28 +98,30 @@ function deviceAccessToolError(e) {
|
|
|
86
98
|
return e;
|
|
87
99
|
}
|
|
88
100
|
}
|
|
89
|
-
function daemonToolError(code, message) {
|
|
101
|
+
function daemonToolError(code, message, tail) {
|
|
90
102
|
switch (code) {
|
|
91
103
|
case "taken_over":
|
|
92
|
-
return new ToolError(TAKEN_OVER_MESSAGE);
|
|
104
|
+
return new ToolError(TAKEN_OVER_MESSAGE + tail);
|
|
93
105
|
case "no_such_ref":
|
|
94
|
-
return new ToolError(`${message} Call browser_snapshot for the current element refs
|
|
106
|
+
return new ToolError(`${message} Call browser_snapshot for the current element refs.${tail}`);
|
|
95
107
|
case "timeout":
|
|
96
108
|
return new ToolError(
|
|
97
|
-
`${message} Check the page with browser_snapshot, then retry or call browser_wait
|
|
109
|
+
`${message} Check the page with browser_snapshot, then retry or call browser_wait.${tail}`
|
|
98
110
|
);
|
|
99
111
|
case "unreachable":
|
|
100
|
-
return new ToolError(`${message} Check the address before retrying
|
|
112
|
+
return new ToolError(`${message} Check the address before retrying.${tail}`);
|
|
101
113
|
case "blocked":
|
|
102
114
|
if (message.startsWith(DOWNLOAD_BLOCKED_PREFIX))
|
|
103
115
|
return new ToolError(
|
|
104
|
-
`${message} Ask the user to allow these hosts so the browser can be installed, then retry
|
|
116
|
+
`${message} Ask the user to allow these hosts so the browser can be installed, then retry.${tail}`
|
|
105
117
|
);
|
|
106
118
|
return new ToolError(
|
|
107
|
-
`${message} The network note says whether the host can be allowed from this conversation; if it is not allowed, use another site
|
|
119
|
+
`${message} The network note says whether the host can be allowed from this conversation; if it is not allowed, use another site.${tail}`
|
|
108
120
|
);
|
|
109
121
|
default:
|
|
110
|
-
return new ToolError(
|
|
122
|
+
return new ToolError(
|
|
123
|
+
`${message} Check the page with browser_snapshot before retrying.${tail}`
|
|
124
|
+
);
|
|
111
125
|
}
|
|
112
126
|
}
|
|
113
127
|
function parseReply(bytes) {
|
|
@@ -162,7 +176,12 @@ async function runRequest(deps, call, req, timeoutMs = REQUEST_TIMEOUT_MS) {
|
|
|
162
176
|
throw new ToolError(RESTARTING_MESSAGE);
|
|
163
177
|
}
|
|
164
178
|
try {
|
|
165
|
-
const
|
|
179
|
+
const sent = {
|
|
180
|
+
...req,
|
|
181
|
+
conversationId: call.conversationId,
|
|
182
|
+
rootConversationId: call.rootConversationId
|
|
183
|
+
};
|
|
184
|
+
const body = new TextEncoder().encode(JSON.stringify(sent));
|
|
166
185
|
reply = parseReply(
|
|
167
186
|
await deps.deviceAccess.request(call, { service: SERVICE, body, timeoutMs })
|
|
168
187
|
);
|
|
@@ -182,8 +201,20 @@ async function runRequest(deps, call, req, timeoutMs = REQUEST_TIMEOUT_MS) {
|
|
|
182
201
|
}
|
|
183
202
|
const hosts = Array.isArray(reply.blockedHosts) ? reply.blockedHosts.filter((h) => typeof h === "string" && h !== "") : [];
|
|
184
203
|
if (hosts.length > 0)
|
|
185
|
-
deps.deviceAccess.reportBlockedHosts(
|
|
186
|
-
|
|
204
|
+
deps.deviceAccess.reportBlockedHosts(
|
|
205
|
+
call,
|
|
206
|
+
hosts,
|
|
207
|
+
reply.ok && reply.page !== void 0 ? { url: reply.page.url } : {}
|
|
208
|
+
);
|
|
209
|
+
if (!reply.ok) {
|
|
210
|
+
const tabs = tabCountOf(reply);
|
|
211
|
+
throw daemonToolError(
|
|
212
|
+
reply.error,
|
|
213
|
+
reply.message,
|
|
214
|
+
tabs === void 0 ? "" : `
|
|
215
|
+
${tabsLine(tabs)}`
|
|
216
|
+
);
|
|
217
|
+
}
|
|
187
218
|
return reply;
|
|
188
219
|
}
|
|
189
220
|
function pageLine(page) {
|
|
@@ -193,10 +224,12 @@ function toResult(reply) {
|
|
|
193
224
|
const lines = [];
|
|
194
225
|
if (reply.userControlledSince !== void 0)
|
|
195
226
|
lines.push(
|
|
196
|
-
`The user controlled the browser from ${reply.userControlledSince}; now at ${reply.page.url} (${reply.page.title}).`
|
|
227
|
+
reply.page === void 0 ? `The user controlled the browser from ${reply.userControlledSince}.` : `The user controlled the browser from ${reply.userControlledSince}; now at ${reply.page.url} (${reply.page.title}).`
|
|
197
228
|
);
|
|
198
|
-
lines.push(pageLine(reply.page));
|
|
229
|
+
lines.push(reply.page === void 0 ? NO_TAB_MESSAGE : pageLine(reply.page));
|
|
199
230
|
if (reply.text !== void 0 && reply.text !== "") lines.push(reply.text);
|
|
231
|
+
const tabs = tabCountOf(reply);
|
|
232
|
+
if (tabs !== void 0) lines.push(tabsLine(tabs));
|
|
200
233
|
return {
|
|
201
234
|
content: [
|
|
202
235
|
{ type: "text", text: lines.join("\n") },
|
|
@@ -282,17 +315,21 @@ function handoffHandler(deps) {
|
|
|
282
315
|
assertOwner(call);
|
|
283
316
|
const answer = call.resume.answer;
|
|
284
317
|
const done = answer !== null && answer.done === true;
|
|
285
|
-
await runRequest(deps, call, {
|
|
318
|
+
const cleared = await runRequest(deps, call, {
|
|
286
319
|
op: "handoff_clear",
|
|
287
320
|
callId: call.callId,
|
|
288
321
|
...done ? { handback: true } : {}
|
|
289
322
|
}).catch((e) => {
|
|
290
323
|
if (!(e instanceof ToolError2)) throw e;
|
|
324
|
+
return void 0;
|
|
291
325
|
});
|
|
292
|
-
if (!done)
|
|
326
|
+
if (!done) {
|
|
327
|
+
const tabs = cleared === void 0 ? void 0 : tabCountOf(cleared);
|
|
293
328
|
throw new ToolError2(
|
|
294
|
-
|
|
329
|
+
`The user cancelled the handoff; ask the user how to continue, or try another approach.${tabs === void 0 ? "" : `
|
|
330
|
+
${tabsLine(tabs)}`}`
|
|
295
331
|
);
|
|
332
|
+
}
|
|
296
333
|
return toResult(await runRequest(deps, call, { op: "snapshot" }));
|
|
297
334
|
};
|
|
298
335
|
}
|
|
@@ -366,7 +403,12 @@ var PANEL_HTML = `<!doctype html>
|
|
|
366
403
|
.row { flex: none; display: flex; align-items: center; padding: 0 12px; }
|
|
367
404
|
|
|
368
405
|
/* tab strip */
|
|
369
|
-
#tabs { height: 32px; align-items: stretch; gap:
|
|
406
|
+
#tabs { height: 32px; align-items: stretch; gap: 4px; }
|
|
407
|
+
#tablist { flex: 1 1 auto; min-width: 0; display: flex; align-items: stretch; gap: 2px; overflow-x: auto; scrollbar-width: none; }
|
|
408
|
+
/* a group of the tree's other conversations: a quiet label before its tabs, set apart by space */
|
|
409
|
+
#tablist .group { flex: none; align-self: center; margin-left: 12px; padding: 0 2px; font-size: var(--cb-type-micro-size, 11px); line-height: var(--cb-type-micro-line, 14px); color: var(--cb-muted, #5E5E5A); white-space: nowrap; }
|
|
410
|
+
#others { align-self: center; height: 24px; padding: 0 8px; font-size: var(--cb-type-micro-size, 11px); color: var(--cb-muted, #5E5E5A); }
|
|
411
|
+
#others[aria-expanded="true"] { background: var(--cb-hover, rgba(26,26,24,.04)); }
|
|
370
412
|
.tab { display: flex; align-items: center; gap: 6px; flex: 0 1 auto; min-width: 64px; max-width: 200px; padding: 0 10px; color: var(--cb-muted, #5E5E5A); }
|
|
371
413
|
.tab[data-active="true"] { color: var(--cb-ink, #1A1A18); font-weight: 500; box-shadow: inset 0 -2px 0 var(--cb-accent, #CC4609); padding-right: 6px; }
|
|
372
414
|
.fav { width: 14px; height: 14px; border-radius: 3px; flex: none; background: var(--cb-line-soft, #E8E7E2); }
|
|
@@ -376,7 +418,7 @@ var PANEL_HTML = `<!doctype html>
|
|
|
376
418
|
.tab .label:hover:not(:disabled) { background: transparent; }
|
|
377
419
|
.tab .label:disabled { color: inherit; }
|
|
378
420
|
.tab .x { width: 20px; min-width: 20px; height: 20px; border-radius: 4px; color: var(--cb-muted, #5E5E5A); }
|
|
379
|
-
#
|
|
421
|
+
#tablist .add { align-self: center; color: var(--cb-muted, #5E5E5A); }
|
|
380
422
|
|
|
381
423
|
/* toolbar */
|
|
382
424
|
#bar { height: 44px; gap: 4px; }
|
|
@@ -443,6 +485,10 @@ var PANEL_HTML = `<!doctype html>
|
|
|
443
485
|
.menu { position: absolute; z-index: 2; min-width: 180px; max-width: calc(100% - 24px); max-height: 60%; overflow: auto; padding: 4px; border-radius: var(--cb-radius-md, 8px); background: var(--cb-raised, #fff); box-shadow: var(--cb-shadow-float, 0 8px 24px rgba(26,26,24,.08)), 0 0 0 1px var(--cb-line-soft, #E8E7E2); }
|
|
444
486
|
.menu button { display: flex; width: 100%; justify-content: flex-start; gap: 8px; padding: 0 8px; text-align: left; overflow: hidden; text-overflow: ellipsis; }
|
|
445
487
|
.menu button[aria-current="true"] { font-weight: 600; }
|
|
488
|
+
.menu .heading { margin: 0; padding: 6px 8px 2px; font-size: var(--cb-type-micro-size, 11px); line-height: var(--cb-type-micro-line, 14px); color: var(--cb-muted, #5E5E5A); }
|
|
489
|
+
.menu .heading:not(:first-child) { margin-top: 4px; }
|
|
490
|
+
.menu button .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
|
|
491
|
+
.menu button .hint { flex: none; margin-left: 8px; color: var(--cb-accent, #CC4609); }
|
|
446
492
|
|
|
447
493
|
/* the skeleton: the panel's own shape, quietly pulsing */
|
|
448
494
|
.bone { display: block; flex: none; border-radius: 2px; background: var(--bone); animation: pulse 1.6s ease-in-out infinite; }
|
|
@@ -467,7 +513,7 @@ var PANEL_HTML = `<!doctype html>
|
|
|
467
513
|
</div>
|
|
468
514
|
</div>
|
|
469
515
|
<div id="app" class="layer" data-loading>
|
|
470
|
-
<div id="tabs" class="row" role="tablist"></div>
|
|
516
|
+
<div id="tabs" class="row"><div id="tablist" role="tablist"></div><button type="button" id="others" aria-haspopup="menu" hidden></button></div>
|
|
471
517
|
<div id="bar" class="row">
|
|
472
518
|
<button type="button" id="back">${ICONS.back}</button>
|
|
473
519
|
<button type="button" id="forward">${ICONS.forward}</button>
|
|
@@ -495,6 +541,7 @@ var PANEL_HTML = `<!doctype html>
|
|
|
495
541
|
<h2 id="empty-title"></h2>
|
|
496
542
|
<p id="empty-body"></p>
|
|
497
543
|
<button type="button" id="reconnect" class="secondary"></button>
|
|
544
|
+
<button type="button" id="empty-others" class="secondary" aria-haspopup="menu" hidden></button>
|
|
498
545
|
</div>
|
|
499
546
|
<div id="menu" class="menu" role="menu" hidden></div>
|
|
500
547
|
<script src="panel.js"></script>
|
|
@@ -595,16 +642,16 @@ function registerRoutes(ctx, deps) {
|
|
|
595
642
|
const callId = body?.callId;
|
|
596
643
|
const done = body?.done;
|
|
597
644
|
const raised = body?.handoffConversationId;
|
|
598
|
-
if (typeof callId !== "string" || callId === "" || callId.length > CALL_ID_MAX || typeof done !== "boolean" ||
|
|
645
|
+
if (typeof callId !== "string" || callId === "" || callId.length > CALL_ID_MAX || typeof done !== "boolean" || typeof raised !== "string" || raised === "" || raised.length > CALL_ID_MAX)
|
|
599
646
|
return error(
|
|
600
647
|
400,
|
|
601
648
|
"invalid_body",
|
|
602
|
-
"the body must be { callId: string,
|
|
649
|
+
"the body must be { callId: string, handoffConversationId: string, done: boolean }"
|
|
603
650
|
);
|
|
604
651
|
await deps.deviceAccess.answerHandoff({
|
|
605
652
|
...scope,
|
|
606
653
|
callId,
|
|
607
|
-
handoffConversationId:
|
|
654
|
+
handoffConversationId: raised,
|
|
608
655
|
done
|
|
609
656
|
});
|
|
610
657
|
return json(200, { ok: true });
|
|
@@ -689,22 +736,22 @@ var NAVIGATE = {
|
|
|
689
736
|
var TABS = {
|
|
690
737
|
name: "browser_tabs",
|
|
691
738
|
title: "Browser tabs",
|
|
692
|
-
description: "List, open, switch or
|
|
739
|
+
description: "List, open, switch, close or adopt tabs of the browser in the user's device. Each conversation has its own tabs (at most 6, and 10 in the browser) and its own active tab, which the other tools act on. Use list to see the tab ids, open to load a url in a new tab, switch to make one of this conversation's tabs active and close to close one. list also shows tabs of other conversations; adopt moves one of them (tabId) to this conversation and makes it active, for when the user points you to a page they opened elsewhere.",
|
|
693
740
|
inputSchema: {
|
|
694
741
|
type: "object",
|
|
695
742
|
properties: {
|
|
696
743
|
action: {
|
|
697
744
|
type: "string",
|
|
698
|
-
enum: ["list", "open", "switch", "close"],
|
|
745
|
+
enum: ["list", "open", "switch", "close", "adopt"],
|
|
699
746
|
description: "What to do."
|
|
700
747
|
},
|
|
701
|
-
tabId: { type: "string", description: "The tab for switch and
|
|
748
|
+
tabId: { type: "string", description: "The tab for switch, close and adopt, from list." },
|
|
702
749
|
url: { type: "string", description: "The address for open (optional: a blank tab)." }
|
|
703
750
|
},
|
|
704
751
|
required: ["action"],
|
|
705
752
|
additionalProperties: false
|
|
706
753
|
},
|
|
707
|
-
keyArgs: ["action", "url"],
|
|
754
|
+
keyArgs: ["action", "tabId", "url"],
|
|
708
755
|
defaultPolicy: "allow",
|
|
709
756
|
// any tool may start the device first (see TOOL_TIMEOUT_MS)
|
|
710
757
|
timeoutMs: TOOL_TIMEOUT_MS
|
|
@@ -939,6 +986,7 @@ function need(v, field, tool) {
|
|
|
939
986
|
if (v === void 0) throw new ToolError3(`${tool} needs ${field}; pass it and retry.`);
|
|
940
987
|
return v;
|
|
941
988
|
}
|
|
989
|
+
var namesTab = (a) => a === "switch" || a === "close" || a === "adopt";
|
|
942
990
|
function handler(deps, toRequest, timeoutOf = () => REQUEST_TIMEOUT_MS) {
|
|
943
991
|
return async (input, call) => {
|
|
944
992
|
const req = toRequest(obj(input));
|
|
@@ -958,15 +1006,15 @@ function registerBrowserTools(ctx, deps) {
|
|
|
958
1006
|
);
|
|
959
1007
|
ctx.tools.register(
|
|
960
1008
|
TABS,
|
|
961
|
-
handler(
|
|
962
|
-
|
|
963
|
-
(i)
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
})
|
|
969
|
-
)
|
|
1009
|
+
handler(deps, (i) => {
|
|
1010
|
+
const action = need(str(i.action), "an action", "browser_tabs");
|
|
1011
|
+
const tabId = str(i.tabId);
|
|
1012
|
+
if (namesTab(action) && (tabId === void 0 || tabId === ""))
|
|
1013
|
+
throw new ToolError3(
|
|
1014
|
+
`browser_tabs needs a tabId for ${action}; call browser_tabs with action list for the tab ids, then retry.`
|
|
1015
|
+
);
|
|
1016
|
+
return defined({ op: "tabs", action, tabId, url: str(i.url) });
|
|
1017
|
+
})
|
|
970
1018
|
);
|
|
971
1019
|
ctx.tools.register(
|
|
972
1020
|
SNAPSHOT,
|
|
@@ -1089,8 +1137,8 @@ function registerBrowserTools(ctx, deps) {
|
|
|
1089
1137
|
// src/index.ts
|
|
1090
1138
|
var index_default = defineExtension({
|
|
1091
1139
|
name: "browser",
|
|
1092
|
-
version: "0.1.0-rc.
|
|
1093
|
-
sdk: "^0.1.0-rc.
|
|
1140
|
+
version: "0.1.0-rc.9",
|
|
1141
|
+
sdk: "^0.1.0-rc.75",
|
|
1094
1142
|
provides: [],
|
|
1095
1143
|
ui: [
|
|
1096
1144
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capybara-hq/plugin-browser",
|
|
3
|
-
"version": "0.1.0-rc.
|
|
3
|
+
"version": "0.1.0-rc.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"description": "A real browser in the person's device for agents: navigate, read and act on pages through tools, with a live view in the conversation and takeover by the person",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
".": "./dist/index.mjs"
|
|
16
16
|
},
|
|
17
17
|
"peerDependencies": {
|
|
18
|
-
"@capybara-hq/plugin-sdk": "^0.1.0-rc.
|
|
18
|
+
"@capybara-hq/plugin-sdk": "^0.1.0-rc.75",
|
|
19
19
|
"zod": "^4.0.0"
|
|
20
20
|
}
|
|
21
21
|
}
|