@capybara-hq/plugin-browser 0.1.0-rc.6 → 0.1.0-rc.8
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 +63 -12
- package/dist/index.mjs +117 -45
- package/package.json +2 -2
- package/ui/panel.js +150 -42
- package/ui/service/daemon.mjs +1232 -291
|
@@ -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.8",
|
|
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.8",
|
|
21
|
+
"sdk": "^0.1.0-rc.75",
|
|
22
22
|
"provides": [],
|
|
23
23
|
"requires": [],
|
|
24
24
|
"optional": [],
|
package/README.md
CHANGED
|
@@ -26,10 +26,16 @@ 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
|
-
naming the `browser` panel so the person's conversation page opens it
|
|
32
|
-
|
|
35
|
+
naming the `browser` panel so the person's conversation page opens it. The question's title is
|
|
36
|
+
请在浏览器中完成:<the reason's first sentence> / Finish in the browser: …, the body is the full
|
|
37
|
+
reason, and `choices` draw 完成 (true, primary) and 取消 (false) as buttons. It stays a boolean
|
|
38
|
+
because the kernel's `answerHandoff`, which the banner uses, answers `{ done }`. On
|
|
33
39
|
resume it clears the notice (with Done also handing the browser back, so a takeover the person
|
|
34
40
|
still holds ends) and returns the page snapshot, or fails with "The user cancelled the handoff;
|
|
35
41
|
ask the user how to continue, or try another approach.".
|
|
@@ -39,8 +45,11 @@ A real browser in the person's device for agents (browser use spec,
|
|
|
39
45
|
- Panel routes: `GET /ui/browser` (the page) and `GET /ui/panel.js` are public; `POST
|
|
40
46
|
/ui/stream-ticket`, `/ui/network-hosts` and `/ui/handoff-answer` are `embed` routes that take
|
|
41
47
|
the org, account and conversation from the caller only (a platform-scope token or one without a
|
|
42
|
-
conversation gets 403).
|
|
43
|
-
|
|
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).
|
|
44
53
|
|
|
45
54
|
## The daemon (`daemon/`)
|
|
46
55
|
|
|
@@ -102,7 +111,8 @@ A real browser in the person's device for agents (browser use spec,
|
|
|
102
111
|
running for up to 24 hours after its notice (the person may take a while to sign in); the
|
|
103
112
|
device's own idle suspension can still stop it sooner, and then the question stays open in the
|
|
104
113
|
conversation without its banner until the browser runs again.
|
|
105
|
-
- `<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
|
|
106
116
|
10 minutes of the last write (a provider that restarts the service for a network change, see
|
|
107
117
|
device-local) reopens them; an idle stop removes the file. The profile keeps cookies and storage
|
|
108
118
|
on its own.
|
|
@@ -115,11 +125,12 @@ A real browser in the person's device for agents (browser use spec,
|
|
|
115
125
|
either: the daemon runs Chromium with `--use-mock-keychain`, so its values are only obfuscated
|
|
116
126
|
with a key every Chromium shares (observed: `encrypted_value` of 51 bytes, readable by anyone
|
|
117
127
|
who can read the directory). The JSON therefore adds no exposure.
|
|
118
|
-
- A `handoff_clear` with `handback` (the person answered Done) also ends a takeover.
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
|
123
134
|
still queued when control returns to the agent is dropped too (input already running, a navigation
|
|
124
135
|
or a long paste, finishes). Keys and buttons the person still holds are released when control
|
|
125
136
|
returns to the agent or the viewer ends, each on the tab where it was pressed (a held button after
|
|
@@ -143,14 +154,54 @@ A real browser in the person's device for agents (browser use spec,
|
|
|
143
154
|
(a stale one is replaced), and Chromium encodes the next frame at most every 500 ms while one
|
|
144
155
|
waits. JSON messages (state, cursor, pings, dialogs) never wait behind a held frame.
|
|
145
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 unowned blank tab if there is one, else opens a new tab; `tabs list`, `adopt` and
|
|
166
|
+
the handoff bookkeeping never open one. A popup belongs to the owner of the page that opened it.
|
|
167
|
+
`switch` and `close` take only the conversation's own tabs.
|
|
168
|
+
- **Seen per task tree.** A conversation and its sub-agent conversations form a tree whose root is
|
|
169
|
+
the conversation the person looks at. `tabs list` shows the conversation's own tabs, then the
|
|
170
|
+
tree's other tabs, then other trees' tabs (titles cut to 120 characters, URLs without query or
|
|
171
|
+
fragment). A panel shows its tree's tabs, grouped per sub-task, and the newest pending handoff of
|
|
172
|
+
the tree; a sub-agent's handoff is answered with Done from the root's panel.
|
|
173
|
+
- **Adopt / Move here.** `browser_tabs` action `adopt` (with `tabId`) moves another conversation's
|
|
174
|
+
tab (or an unowned one) to the calling conversation and makes it its active tab; the previous
|
|
175
|
+
owner's next result says so. The panel's 其他对话 / Other conversations menu does the same with
|
|
176
|
+
移到此对话 / Move here, also while only watching. Refused while the owner is in use (a request in
|
|
177
|
+
flight or a pending handoff, long wait or held dialog).
|
|
178
|
+
- **Caps and eviction.** At most 10 tabs in the browser and 6 per conversation. At the device cap
|
|
179
|
+
the daemon first closes the least recently used tab of a conversation that is not in use and has
|
|
180
|
+
made no request for 5 minutes (its non-active tabs before its active one) and tells that
|
|
181
|
+
conversation; it refuses only when no tab qualifies.
|
|
182
|
+
- **Idle close.** A conversation's tabs close after 15 minutes without a request, without an open
|
|
183
|
+
panel showing it and without a pending park; its per-conversation state goes with them. The
|
|
184
|
+
profile is never touched.
|
|
185
|
+
- **Takeover per device.** While the person controls the browser from any conversation's panel,
|
|
186
|
+
every conversation's agent requests are refused. Afterwards only the conversations whose tabs the
|
|
187
|
+
takeover concerned are told that the user had control.
|
|
188
|
+
|
|
146
189
|
## The panel (`ui-src/panel/`)
|
|
147
190
|
|
|
148
191
|
- Every viewer is the owner's: any non-compact panel is interactive (keys, pointer, Esc) while the
|
|
149
192
|
person holds control, whichever panel took it, and may ask for frames up to the full viewport
|
|
150
|
-
then. In the watch state the panel
|
|
151
|
-
navigation; the cursor is the arrow)
|
|
193
|
+
then. In the watch state the panel takes no page input (no pointer, keys, address bar,
|
|
194
|
+
navigation or tab open / close; the cursor is the arrow), but a click on a tab of the strip shows
|
|
195
|
+
that tab, and 其他对话 / Other conversations › 移到此对话 / Move here moves another conversation's
|
|
196
|
+
tab here. Nothing is kept in storage (the sandboxed iframe has none);
|
|
152
197
|
a remount rebuilds from the daemon's first state. Take over is offered only in the live view;
|
|
153
198
|
handing back with a pending handoff answers it Done.
|
|
199
|
+
- The strip shows the conversation tree's tabs: this conversation's first, then one 子任务 /
|
|
200
|
+
Sub-task group per sub-agent conversation. With no tab in the tree while the browser runs, the
|
|
201
|
+
panel shows 智能体尚未在此对话中打开网页 / "The agent has not opened a page in this conversation
|
|
202
|
+
yet" (never another conversation's page). A refused Move here shows a short line (the tab is in
|
|
203
|
+
use, or this conversation has its most tabs). The banner shows the tree's newest pending handoff;
|
|
204
|
+
its Done / Cancel answer that handoff's conversation.
|
|
154
205
|
- Takeover input (`ui-src/panel/input.ts`): button and wheel events at once, moves coalesced to the
|
|
155
206
|
newest position at most every 33 ms (hover effects, menus and tooltips render in the stream), a
|
|
156
207
|
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") },
|
|
@@ -207,16 +240,22 @@ function toResult(reply) {
|
|
|
207
240
|
|
|
208
241
|
// src/i18n.ts
|
|
209
242
|
var HANDOFF_FORM = {
|
|
243
|
+
titlePrefix: { zh: "请在浏览器中完成:", en: "Finish in the browser: " },
|
|
210
244
|
label: { zh: "完成", en: "Done" },
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
en: "Turn on and submit when you are done to hand the browser back; submit with it off, or dismiss the question, to cancel."
|
|
214
|
-
}
|
|
245
|
+
done: { zh: "完成", en: "Done" },
|
|
246
|
+
cancel: { zh: "取消", en: "Cancel" }
|
|
215
247
|
};
|
|
216
248
|
|
|
217
249
|
// src/handoff.ts
|
|
218
250
|
var PANEL = "browser";
|
|
219
251
|
var MESSAGE_MAX = Math.min(2e3, HANDOFF_MAX_CHARS);
|
|
252
|
+
var SHORT_MAX = 40;
|
|
253
|
+
function shortReason(message) {
|
|
254
|
+
const first = message.trim().split(/(?<=[。!?.!?])\s*|\n/u)[0]?.trim() ?? "";
|
|
255
|
+
const chars = Array.from(first);
|
|
256
|
+
if (chars.length <= SHORT_MAX) return first.replace(/[。.]$/u, "");
|
|
257
|
+
return `${chars.slice(0, SHORT_MAX - 1).join("")}…`;
|
|
258
|
+
}
|
|
220
259
|
var HANDOFF = {
|
|
221
260
|
name: "browser_handoff",
|
|
222
261
|
title: "Hand the browser to the user",
|
|
@@ -248,14 +287,22 @@ function handoffHandler(deps) {
|
|
|
248
287
|
const asked = {
|
|
249
288
|
kind: "input_required",
|
|
250
289
|
form: {
|
|
251
|
-
title:
|
|
290
|
+
title: {
|
|
291
|
+
zh: `${HANDOFF_FORM.titlePrefix.zh}${shortReason(message)}`,
|
|
292
|
+
en: `${HANDOFF_FORM.titlePrefix.en}${shortReason(message)}`
|
|
293
|
+
},
|
|
294
|
+
body: message,
|
|
252
295
|
fields: [
|
|
253
296
|
{
|
|
254
297
|
key: "done",
|
|
255
298
|
label: HANDOFF_FORM.label,
|
|
256
|
-
description: HANDOFF_FORM.description,
|
|
257
299
|
schema: { type: "boolean" },
|
|
258
|
-
required: true
|
|
300
|
+
required: true,
|
|
301
|
+
// two buttons (完成 primary, 取消), the same answer the panel's banner sends
|
|
302
|
+
choices: [
|
|
303
|
+
{ value: true, label: HANDOFF_FORM.done },
|
|
304
|
+
{ value: false, label: HANDOFF_FORM.cancel }
|
|
305
|
+
]
|
|
259
306
|
}
|
|
260
307
|
]
|
|
261
308
|
},
|
|
@@ -268,17 +315,21 @@ function handoffHandler(deps) {
|
|
|
268
315
|
assertOwner(call);
|
|
269
316
|
const answer = call.resume.answer;
|
|
270
317
|
const done = answer !== null && answer.done === true;
|
|
271
|
-
await runRequest(deps, call, {
|
|
318
|
+
const cleared = await runRequest(deps, call, {
|
|
272
319
|
op: "handoff_clear",
|
|
273
320
|
callId: call.callId,
|
|
274
321
|
...done ? { handback: true } : {}
|
|
275
322
|
}).catch((e) => {
|
|
276
323
|
if (!(e instanceof ToolError2)) throw e;
|
|
324
|
+
return void 0;
|
|
277
325
|
});
|
|
278
|
-
if (!done)
|
|
326
|
+
if (!done) {
|
|
327
|
+
const tabs = cleared === void 0 ? void 0 : tabCountOf(cleared);
|
|
279
328
|
throw new ToolError2(
|
|
280
|
-
|
|
329
|
+
`The user cancelled the handoff; ask the user how to continue, or try another approach.${tabs === void 0 ? "" : `
|
|
330
|
+
${tabsLine(tabs)}`}`
|
|
281
331
|
);
|
|
332
|
+
}
|
|
282
333
|
return toResult(await runRequest(deps, call, { op: "snapshot" }));
|
|
283
334
|
};
|
|
284
335
|
}
|
|
@@ -352,7 +403,12 @@ var PANEL_HTML = `<!doctype html>
|
|
|
352
403
|
.row { flex: none; display: flex; align-items: center; padding: 0 12px; }
|
|
353
404
|
|
|
354
405
|
/* tab strip */
|
|
355
|
-
#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)); }
|
|
356
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); }
|
|
357
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; }
|
|
358
414
|
.fav { width: 14px; height: 14px; border-radius: 3px; flex: none; background: var(--cb-line-soft, #E8E7E2); }
|
|
@@ -362,7 +418,7 @@ var PANEL_HTML = `<!doctype html>
|
|
|
362
418
|
.tab .label:hover:not(:disabled) { background: transparent; }
|
|
363
419
|
.tab .label:disabled { color: inherit; }
|
|
364
420
|
.tab .x { width: 20px; min-width: 20px; height: 20px; border-radius: 4px; color: var(--cb-muted, #5E5E5A); }
|
|
365
|
-
#
|
|
421
|
+
#tablist .add { align-self: center; color: var(--cb-muted, #5E5E5A); }
|
|
366
422
|
|
|
367
423
|
/* toolbar */
|
|
368
424
|
#bar { height: 44px; gap: 4px; }
|
|
@@ -429,6 +485,10 @@ var PANEL_HTML = `<!doctype html>
|
|
|
429
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); }
|
|
430
486
|
.menu button { display: flex; width: 100%; justify-content: flex-start; gap: 8px; padding: 0 8px; text-align: left; overflow: hidden; text-overflow: ellipsis; }
|
|
431
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); }
|
|
432
492
|
|
|
433
493
|
/* the skeleton: the panel's own shape, quietly pulsing */
|
|
434
494
|
.bone { display: block; flex: none; border-radius: 2px; background: var(--bone); animation: pulse 1.6s ease-in-out infinite; }
|
|
@@ -453,7 +513,7 @@ var PANEL_HTML = `<!doctype html>
|
|
|
453
513
|
</div>
|
|
454
514
|
</div>
|
|
455
515
|
<div id="app" class="layer" data-loading>
|
|
456
|
-
<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>
|
|
457
517
|
<div id="bar" class="row">
|
|
458
518
|
<button type="button" id="back">${ICONS.back}</button>
|
|
459
519
|
<button type="button" id="forward">${ICONS.forward}</button>
|
|
@@ -481,6 +541,7 @@ var PANEL_HTML = `<!doctype html>
|
|
|
481
541
|
<h2 id="empty-title"></h2>
|
|
482
542
|
<p id="empty-body"></p>
|
|
483
543
|
<button type="button" id="reconnect" class="secondary"></button>
|
|
544
|
+
<button type="button" id="empty-others" class="secondary" aria-haspopup="menu" hidden></button>
|
|
484
545
|
</div>
|
|
485
546
|
<div id="menu" class="menu" role="menu" hidden></div>
|
|
486
547
|
<script src="panel.js"></script>
|
|
@@ -580,9 +641,19 @@ function registerRoutes(ctx, deps) {
|
|
|
580
641
|
const body = await readJson(req);
|
|
581
642
|
const callId = body?.callId;
|
|
582
643
|
const done = body?.done;
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
644
|
+
const raised = body?.handoffConversationId;
|
|
645
|
+
if (typeof callId !== "string" || callId === "" || callId.length > CALL_ID_MAX || typeof done !== "boolean" || typeof raised !== "string" || raised === "" || raised.length > CALL_ID_MAX)
|
|
646
|
+
return error(
|
|
647
|
+
400,
|
|
648
|
+
"invalid_body",
|
|
649
|
+
"the body must be { callId: string, handoffConversationId: string, done: boolean }"
|
|
650
|
+
);
|
|
651
|
+
await deps.deviceAccess.answerHandoff({
|
|
652
|
+
...scope,
|
|
653
|
+
callId,
|
|
654
|
+
handoffConversationId: raised,
|
|
655
|
+
done
|
|
656
|
+
});
|
|
586
657
|
return json(200, { ok: true });
|
|
587
658
|
})
|
|
588
659
|
);
|
|
@@ -665,22 +736,22 @@ var NAVIGATE = {
|
|
|
665
736
|
var TABS = {
|
|
666
737
|
name: "browser_tabs",
|
|
667
738
|
title: "Browser tabs",
|
|
668
|
-
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.",
|
|
669
740
|
inputSchema: {
|
|
670
741
|
type: "object",
|
|
671
742
|
properties: {
|
|
672
743
|
action: {
|
|
673
744
|
type: "string",
|
|
674
|
-
enum: ["list", "open", "switch", "close"],
|
|
745
|
+
enum: ["list", "open", "switch", "close", "adopt"],
|
|
675
746
|
description: "What to do."
|
|
676
747
|
},
|
|
677
|
-
tabId: { type: "string", description: "The tab for switch and
|
|
748
|
+
tabId: { type: "string", description: "The tab for switch, close and adopt, from list." },
|
|
678
749
|
url: { type: "string", description: "The address for open (optional: a blank tab)." }
|
|
679
750
|
},
|
|
680
751
|
required: ["action"],
|
|
681
752
|
additionalProperties: false
|
|
682
753
|
},
|
|
683
|
-
keyArgs: ["action", "url"],
|
|
754
|
+
keyArgs: ["action", "tabId", "url"],
|
|
684
755
|
defaultPolicy: "allow",
|
|
685
756
|
// any tool may start the device first (see TOOL_TIMEOUT_MS)
|
|
686
757
|
timeoutMs: TOOL_TIMEOUT_MS
|
|
@@ -915,6 +986,7 @@ function need(v, field, tool) {
|
|
|
915
986
|
if (v === void 0) throw new ToolError3(`${tool} needs ${field}; pass it and retry.`);
|
|
916
987
|
return v;
|
|
917
988
|
}
|
|
989
|
+
var namesTab = (a) => a === "switch" || a === "close" || a === "adopt";
|
|
918
990
|
function handler(deps, toRequest, timeoutOf = () => REQUEST_TIMEOUT_MS) {
|
|
919
991
|
return async (input, call) => {
|
|
920
992
|
const req = toRequest(obj(input));
|
|
@@ -934,15 +1006,15 @@ function registerBrowserTools(ctx, deps) {
|
|
|
934
1006
|
);
|
|
935
1007
|
ctx.tools.register(
|
|
936
1008
|
TABS,
|
|
937
|
-
handler(
|
|
938
|
-
|
|
939
|
-
(i)
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
})
|
|
945
|
-
)
|
|
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
|
+
})
|
|
946
1018
|
);
|
|
947
1019
|
ctx.tools.register(
|
|
948
1020
|
SNAPSHOT,
|
|
@@ -1065,8 +1137,8 @@ function registerBrowserTools(ctx, deps) {
|
|
|
1065
1137
|
// src/index.ts
|
|
1066
1138
|
var index_default = defineExtension({
|
|
1067
1139
|
name: "browser",
|
|
1068
|
-
version: "0.1.0-rc.
|
|
1069
|
-
sdk: "^0.1.0-rc.
|
|
1140
|
+
version: "0.1.0-rc.8",
|
|
1141
|
+
sdk: "^0.1.0-rc.75",
|
|
1070
1142
|
provides: [],
|
|
1071
1143
|
ui: [
|
|
1072
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.8",
|
|
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
|
}
|