@capybara-hq/plugin-browser 0.1.0-rc.1 → 0.1.0-rc.11

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/dist/index.mjs CHANGED
@@ -18,9 +18,12 @@ 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).";
26
+ var FAVICON_MAX_BYTES = 8 * 1024;
24
27
 
25
28
  // src/browser.ts
26
29
  import {
@@ -29,12 +32,39 @@ import {
29
32
 
30
33
  // src/messages.ts
31
34
  var NOT_OWNER_MESSAGE = "Browser tools only run for the conversation's owner on their own device.";
32
- var TAKEN_OVER_MESSAGE = "The user is controlling the browser; call browser_wait or browser_handoff.";
33
35
 
34
36
  // src/browser.ts
37
+ var TAKEN_OVER_MESSAGE = "The user is controlling the browser; call browser_wait or browser_handoff.";
35
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.";
36
39
  var SERVICE = "browser";
40
+ var RESTARTING_MESSAGE = "The browser was just installed in the device and its service is restarting; call the tool again.";
41
+ var RESTART_ATTEMPTS = 3;
42
+ var RESTART_WAIT_MS = 3e4;
43
+ var RESTART_PAUSE_FIRST_MS = 100;
44
+ var RESTART_PAUSE_MAX_MS = 1e3;
45
+ var pause = (ms, signal) => new Promise((resolve) => {
46
+ if (signal.aborted) return resolve();
47
+ const timer = AbortSignal.timeout(ms);
48
+ const done = () => {
49
+ signal.removeEventListener("abort", done);
50
+ timer.removeEventListener("abort", done);
51
+ resolve();
52
+ };
53
+ signal.addEventListener("abort", done, { once: true });
54
+ timer.addEventListener("abort", done, { once: true });
55
+ });
37
56
  var REQUEST_TIMEOUT_MS = 9e4;
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
+ }
38
68
  function assertOwner(call) {
39
69
  if (call.ownerAccountId === void 0 || call.accountId !== call.ownerAccountId)
40
70
  throw new ToolError(NOT_OWNER_MESSAGE);
@@ -68,26 +98,34 @@ function deviceAccessToolError(e) {
68
98
  return e;
69
99
  }
70
100
  }
71
- function daemonToolError(code, message) {
101
+ function daemonToolError(code, message, tail) {
72
102
  switch (code) {
73
103
  case "taken_over":
74
- return new ToolError(TAKEN_OVER_MESSAGE);
104
+ return new ToolError(TAKEN_OVER_MESSAGE + tail);
75
105
  case "no_such_ref":
76
- 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}`);
77
107
  case "timeout":
78
108
  return new ToolError(
79
- `${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}`
110
+ );
111
+ case "network_unavailable":
112
+ return new ToolError(
113
+ `${message} Retry after a while; if it keeps failing, ask the user to check the device's network.`
80
114
  );
115
+ case "unreachable":
116
+ return new ToolError(`${message} Check the address before retrying.${tail}`);
81
117
  case "blocked":
82
118
  if (message.startsWith(DOWNLOAD_BLOCKED_PREFIX))
83
119
  return new ToolError(
84
- `${message} Ask the user to allow these hosts so the browser can be installed, then retry.`
120
+ `${message} Ask the user to allow these hosts so the browser can be installed, then retry.${tail}`
85
121
  );
86
122
  return new ToolError(
87
- `${message} The user is asked to allow the host; if they decline, use another site.`
123
+ `${message} The network note says whether the host can be allowed from this conversation; if it is not allowed, use another site.${tail}`
88
124
  );
89
125
  default:
90
- return new ToolError(`${message} Check the page with browser_snapshot before retrying.`);
126
+ return new ToolError(
127
+ `${message} Check the page with browser_snapshot before retrying.${tail}`
128
+ );
91
129
  }
92
130
  }
93
131
  function parseReply(bytes) {
@@ -120,23 +158,72 @@ function failure(deps, call, e, starting) {
120
158
  async function runRequest(deps, call, req, timeoutMs = REQUEST_TIMEOUT_MS) {
121
159
  assertOwner(call);
122
160
  let reply;
123
- try {
124
- await deps.deviceAccess.ensureService(call, await deps.serviceSpec());
125
- } catch (e) {
126
- throw failure(deps, call, e, true);
161
+ let exiting;
162
+ let waitUntil = 0;
163
+ let pauseMs = RESTART_PAUSE_FIRST_MS;
164
+ const waitMore = async () => {
165
+ if (call.signal.aborted || Date.now() + pauseMs > waitUntil) return false;
166
+ await pause(pauseMs, call.signal);
167
+ pauseMs = Math.min(pauseMs * 2, RESTART_PAUSE_MAX_MS);
168
+ return !call.signal.aborted;
169
+ };
170
+ for (let restarts = 0; ; ) {
171
+ let startedAt;
172
+ try {
173
+ ({ startedAt } = await deps.deviceAccess.ensureService(call, await deps.serviceSpec()));
174
+ } catch (e) {
175
+ throw failure(deps, call, e, true);
176
+ }
177
+ if (exiting !== void 0 && startedAt !== null && startedAt === exiting.startedAt) {
178
+ if (await waitMore()) continue;
179
+ if (call.signal.aborted) throw failure(deps, call, call.signal.reason, true);
180
+ throw new ToolError(RESTARTING_MESSAGE);
181
+ }
182
+ try {
183
+ const sent = {
184
+ ...req,
185
+ conversationId: call.conversationId,
186
+ rootConversationId: call.rootConversationId
187
+ };
188
+ const body = new TextEncoder().encode(JSON.stringify(sent));
189
+ reply = parseReply(
190
+ await deps.deviceAccess.request(call, { service: SERVICE, body, timeoutMs })
191
+ );
192
+ } catch (e) {
193
+ if (exiting !== void 0 && !call.signal.aborted) {
194
+ if (await waitMore()) continue;
195
+ if (!call.signal.aborted) throw new ToolError(RESTARTING_MESSAGE);
196
+ }
197
+ throw failure(deps, call, e, false);
198
+ }
199
+ if (reply.ok || reply.error !== "restart") break;
200
+ if (restarts >= RESTART_ATTEMPTS) throw new ToolError(RESTARTING_MESSAGE);
201
+ restarts++;
202
+ exiting = { startedAt };
203
+ waitUntil = Date.now() + RESTART_WAIT_MS;
204
+ pauseMs = RESTART_PAUSE_FIRST_MS;
127
205
  }
128
- try {
129
- const body = new TextEncoder().encode(JSON.stringify(req));
130
- reply = parseReply(
131
- await deps.deviceAccess.request(call, { service: SERVICE, body, timeoutMs })
206
+ const hosts = Array.isArray(reply.blockedHosts) ? reply.blockedHosts.flatMap((h) => {
207
+ const b = h;
208
+ if (typeof b !== "object" || b === null || typeof b.host !== "string" || b.host === "")
209
+ return [];
210
+ return [{ host: b.host, layer: b.layer === "address" ? "address" : "device" }];
211
+ }) : [];
212
+ if (hosts.length > 0)
213
+ deps.deviceAccess.reportBlockedHosts(
214
+ call,
215
+ hosts,
216
+ reply.ok && reply.page !== void 0 ? { url: reply.page.url } : {}
217
+ );
218
+ if (!reply.ok) {
219
+ const tabs = tabCountOf(reply);
220
+ throw daemonToolError(
221
+ reply.error,
222
+ reply.message,
223
+ tabs === void 0 ? "" : `
224
+ ${tabsLine(tabs)}`
132
225
  );
133
- } catch (e) {
134
- throw failure(deps, call, e, false);
135
226
  }
136
- const hosts = Array.isArray(reply.blockedHosts) ? reply.blockedHosts.filter((h) => typeof h === "string" && h !== "") : [];
137
- if (hosts.length > 0)
138
- deps.deviceAccess.reportBlockedHosts(call, hosts, reply.ok ? { url: reply.page.url } : {});
139
- if (!reply.ok) throw daemonToolError(reply.error, reply.message);
140
227
  return reply;
141
228
  }
142
229
  function pageLine(page) {
@@ -146,10 +233,12 @@ function toResult(reply) {
146
233
  const lines = [];
147
234
  if (reply.userControlledSince !== void 0)
148
235
  lines.push(
149
- `The user controlled the browser from ${reply.userControlledSince}; now at ${reply.page.url} (${reply.page.title}).`
236
+ 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}).`
150
237
  );
151
- lines.push(pageLine(reply.page));
238
+ lines.push(reply.page === void 0 ? NO_TAB_MESSAGE : pageLine(reply.page));
152
239
  if (reply.text !== void 0 && reply.text !== "") lines.push(reply.text);
240
+ const tabs = tabCountOf(reply);
241
+ if (tabs !== void 0) lines.push(tabsLine(tabs));
153
242
  return {
154
243
  content: [
155
244
  { type: "text", text: lines.join("\n") },
@@ -160,15 +249,22 @@ function toResult(reply) {
160
249
 
161
250
  // src/i18n.ts
162
251
  var HANDOFF_FORM = {
252
+ titlePrefix: { zh: "请在浏览器中完成:", en: "Finish in the browser: " },
163
253
  label: { zh: "完成", en: "Done" },
164
- description: {
165
- zh: "完成后打开开关并提交,浏览器交还智能体;关闭开关提交或关闭此问题即为取消。",
166
- en: "Turn on and submit when you are done to hand the browser back; submit with it off, or dismiss the question, to cancel."
167
- }
254
+ done: { zh: "完成", en: "Done" },
255
+ cancel: { zh: "取消", en: "Cancel" }
168
256
  };
169
257
 
170
258
  // src/handoff.ts
259
+ var PANEL = "browser";
171
260
  var MESSAGE_MAX = Math.min(2e3, HANDOFF_MAX_CHARS);
261
+ var SHORT_MAX = 40;
262
+ function shortReason(message) {
263
+ const first = message.trim().split(/(?<=[。!?.!?])\s*|\n/u)[0]?.trim() ?? "";
264
+ const chars = Array.from(first);
265
+ if (chars.length <= SHORT_MAX) return first.replace(/[。.]$/u, "");
266
+ return `${chars.slice(0, SHORT_MAX - 1).join("")}…`;
267
+ }
172
268
  var HANDOFF = {
173
269
  name: "browser_handoff",
174
270
  title: "Hand the browser to the user",
@@ -186,7 +282,8 @@ var HANDOFF = {
186
282
  additionalProperties: false
187
283
  },
188
284
  keyArgs: ["message"],
189
- defaultPolicy: "allow"
285
+ defaultPolicy: "allow",
286
+ timeoutMs: TOOL_TIMEOUT_MS
190
287
  };
191
288
  function handoffHandler(deps) {
192
289
  return async (input, call) => {
@@ -199,35 +296,49 @@ function handoffHandler(deps) {
199
296
  const asked = {
200
297
  kind: "input_required",
201
298
  form: {
202
- title: message,
299
+ title: {
300
+ zh: `${HANDOFF_FORM.titlePrefix.zh}${shortReason(message)}`,
301
+ en: `${HANDOFF_FORM.titlePrefix.en}${shortReason(message)}`
302
+ },
303
+ body: message,
203
304
  fields: [
204
305
  {
205
306
  key: "done",
206
307
  label: HANDOFF_FORM.label,
207
- description: HANDOFF_FORM.description,
208
308
  schema: { type: "boolean" },
209
- required: true
309
+ required: true,
310
+ // two buttons (完成 primary, 取消), the same answer the panel's banner sends
311
+ choices: [
312
+ { value: true, label: HANDOFF_FORM.done },
313
+ { value: false, label: HANDOFF_FORM.cancel }
314
+ ]
210
315
  }
211
316
  ]
212
317
  },
213
- state: { handoff: 1 }
318
+ state: { handoff: 1 },
319
+ // the person's conversation page opens the panel, where they do it
320
+ open: { contribution: PANEL }
214
321
  };
215
322
  return asked;
216
323
  }
217
324
  assertOwner(call);
218
325
  const answer = call.resume.answer;
219
326
  const done = answer !== null && answer.done === true;
220
- await runRequest(deps, call, {
327
+ const cleared = await runRequest(deps, call, {
221
328
  op: "handoff_clear",
222
329
  callId: call.callId,
223
330
  ...done ? { handback: true } : {}
224
331
  }).catch((e) => {
225
332
  if (!(e instanceof ToolError2)) throw e;
333
+ return void 0;
226
334
  });
227
- if (!done)
335
+ if (!done) {
336
+ const tabs = cleared === void 0 ? void 0 : tabCountOf(cleared);
228
337
  throw new ToolError2(
229
- "The user cancelled the handoff; ask the user how to continue, or try another approach."
338
+ `The user cancelled the handoff; ask the user how to continue, or try another approach.${tabs === void 0 ? "" : `
339
+ ${tabsLine(tabs)}`}`
230
340
  );
341
+ }
231
342
  return toResult(await runRequest(deps, call, { op: "snapshot" }));
232
343
  };
233
344
  }
@@ -236,6 +347,21 @@ function registerHandoffTool(ctx, deps) {
236
347
  }
237
348
 
238
349
  // ui-src/panel/page.ts
350
+ var ICONS = {
351
+ back: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m15 18-6-6 6-6"/></svg>',
352
+ forward: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m9 18 6-6-6-6"/></svg>',
353
+ reload: '<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 12a9 9 0 1 1-3-6.7L21 8"/><path d="M21 3v5h-5"/></svg>',
354
+ close: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M18 6 6 18M6 6l12 12"/></svg>',
355
+ plus: '<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M12 5v14M5 12h14"/></svg>',
356
+ lock: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><rect x="5" y="11" width="14" height="10" rx="2"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg>',
357
+ globe: '<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="9"/><path d="M3 12h18M12 3a14 14 0 0 1 0 18M12 3a14 14 0 0 0 0 18"/></svg>',
358
+ more: '<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><circle cx="5" cy="12" r="1.6"/><circle cx="12" cy="12" r="1.6"/><circle cx="19" cy="12" r="1.6"/></svg>',
359
+ spin: '<svg class="spin" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" aria-hidden="true"><path d="M21 12a9 9 0 1 1-9-9"/></svg>',
360
+ dot: '<svg width="12" height="12" viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="12" r="4" fill="currentColor"/></svg>',
361
+ hand: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9 11V5a2 2 0 0 1 4 0v6"/><path d="M13 10V8a2 2 0 0 1 4 0v5a7 7 0 0 1-7 7h-.5A6.5 6.5 0 0 1 5 17.5L4 15a2 2 0 0 1 3.4-2L9 15"/></svg>',
362
+ pause: '<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><rect x="6" y="5" width="4" height="14" rx="1"/><rect x="14" y="5" width="4" height="14" rx="1"/></svg>'
363
+ };
364
+ var bone = (style) => `<span class="bone" style="${style}"></span>`;
239
365
  var PANEL_HTML = `<!doctype html>
240
366
  <html lang="en">
241
367
  <head>
@@ -243,68 +369,194 @@ var PANEL_HTML = `<!doctype html>
243
369
  <meta name="viewport" content="width=device-width, initial-scale=1">
244
370
  <title>Browser</title>
245
371
  <style>
246
- :root { color-scheme: dark light; }
372
+ :root {
373
+ color-scheme: light;
374
+ --ground: color-mix(in srgb, var(--cb-ink, #1A1A18) 5%, var(--cb-bg, #FAF9F6));
375
+ --frame-shadow: 0 1px 2px rgba(26,26,24,.06), 0 4px 16px rgba(26,26,24,.06);
376
+ --bone: color-mix(in srgb, var(--cb-ink, #1A1A18) 7%, transparent);
377
+ --radius: 6px;
378
+ }
379
+ :root[data-theme="dark"] {
380
+ color-scheme: dark;
381
+ --ground: var(--cb-bg, #0A0A0A);
382
+ --frame-shadow: 0 0 0 1px rgba(255,255,255,.08);
383
+ }
247
384
  * { box-sizing: border-box; }
248
385
  html, body { height: 100%; }
249
386
  body {
250
- margin: 0; display: flex; flex-direction: column; overflow: hidden;
251
- background: var(--cb-bg, Canvas); color: var(--cb-ink, CanvasText);
252
- font: 12px/1.4 var(--cb-font, ui-monospace, monospace);
387
+ margin: 0; position: relative; overflow: hidden;
388
+ background: var(--cb-panel-2, Canvas); color: var(--cb-ink, CanvasText);
389
+ font-family: var(--cb-font, ui-monospace, "SF Mono", Menlo, monospace);
390
+ font-size: var(--cb-type-body-size, 13px); line-height: var(--cb-type-body-line, 20px);
253
391
  }
392
+ /* nothing before the host's tokens and language (init) */
393
+ body:not([data-ready]) { visibility: hidden; }
254
394
  [hidden] { display: none !important; }
255
- button, input {
256
- font: inherit; color: inherit; background: transparent;
257
- border: 1px solid var(--cb-line-strong, GrayText); padding: 2px 8px; min-height: 26px;
395
+ button, input { font: inherit; color: inherit; margin: 0; }
396
+ button {
397
+ display: inline-grid; place-items: center; flex: none; height: 28px; min-width: 28px;
398
+ padding: 0; border: 0; border-radius: var(--radius); background: transparent; cursor: pointer;
399
+ white-space: nowrap;
400
+ }
401
+ button:hover:not(:disabled) { background: var(--cb-hover, rgba(26,26,24,.04)); }
402
+ button:disabled { color: var(--cb-disabled, GrayText); cursor: default; }
403
+ button:focus-visible, input:focus-visible { outline: 2px solid var(--cb-focus-ring, Highlight); outline-offset: 1px; }
404
+ .primary, .secondary, .outline { padding: 0 14px; font-weight: 600; }
405
+ .primary { background: var(--cb-accent, #CC4609); color: var(--cb-on-accent, #fff); }
406
+ .primary:hover:not(:disabled) { background: var(--cb-accent-hover, var(--cb-accent, #CC4609)); }
407
+ .secondary { font-weight: 400; box-shadow: inset 0 0 0 1px var(--cb-line, #D9D8D2); }
408
+ .outline { padding: 0 12px; color: var(--cb-accent, #CC4609); box-shadow: inset 0 0 0 1px var(--cb-accent, #CC4609); }
409
+
410
+ .layer { position: absolute; inset: 0; display: flex; flex-direction: column; }
411
+ /* laid out underneath while the skeleton or the idle state shows, so the switch never reflows */
412
+ #app[data-loading], #app[data-idle] { visibility: hidden; }
413
+ .row { flex: none; display: flex; align-items: center; padding: 0 12px; }
414
+
415
+ /* tab strip */
416
+ #tabs { height: 32px; align-items: stretch; gap: 4px; }
417
+ #tablist { flex: 1 1 auto; min-width: 0; display: flex; align-items: stretch; gap: 2px; overflow-x: auto; scrollbar-width: none; }
418
+ /* a group of the tree's other conversations: a quiet label before its tabs, set apart by space */
419
+ #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; }
420
+ #others { align-self: center; height: 24px; padding: 0 8px; font-size: var(--cb-type-micro-size, 11px); color: var(--cb-muted, #5E5E5A); }
421
+ #others[aria-expanded="true"] { background: var(--cb-hover, rgba(26,26,24,.04)); }
422
+ .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); }
423
+ .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; }
424
+ /* the icon slot: always a deliberate 14 px glyph (spinner while loading, globe without an icon)
425
+ or the site's icon, the same box in every state so nothing shifts when the icon arrives */
426
+ .fav { display: inline-grid; place-items: center; width: 14px; height: 14px; flex: none; color: var(--cb-muted, #5E5E5A); }
427
+ .fav svg { width: 14px; height: 14px; }
428
+ img.fav { object-fit: contain; border-radius: 2px; }
429
+ .fav[data-glyph="loading"] { color: var(--cb-accent, #CC4609); }
430
+ .tab .label { flex: 1; min-width: 0; display: block; height: auto; text-align: left; overflow: hidden; text-overflow: ellipsis; font-weight: inherit; }
431
+ .tab .label:hover:not(:disabled) { background: transparent; }
432
+ .tab .label:disabled { color: inherit; }
433
+ .tab .x { width: 20px; min-width: 20px; height: 20px; border-radius: 4px; color: var(--cb-muted, #5E5E5A); }
434
+ #tablist .add { align-self: center; color: var(--cb-muted, #5E5E5A); }
435
+
436
+ /* toolbar */
437
+ #bar { height: 44px; gap: 4px; }
438
+ #field { flex: 1 1 0; min-width: 0; height: 28px; margin-left: 4px; position: relative; display: flex; align-items: center; border-radius: var(--radius); background: var(--cb-hover, rgba(26,26,24,.05)); }
439
+ #field[data-edit] { background: var(--cb-panel, #fff); box-shadow: inset 0 0 0 1px var(--cb-line, #D9D8D2); }
440
+ #lock { display: inline-flex; flex: none; margin-left: 10px; color: var(--cb-muted, #5E5E5A); }
441
+ #url { flex: 1; min-width: 0; height: 100%; padding: 0 10px 0 6px; border: 0; outline: 0; background: transparent; color: transparent; caret-color: var(--cb-ink, #1A1A18); text-overflow: ellipsis; }
442
+ #lock[hidden] + #url, #lock[hidden] ~ #urltext { padding-left: 10px; }
443
+ #url:focus { color: var(--cb-ink, #1A1A18); }
444
+ #urltext { position: absolute; inset: 0 10px 0 26px; display: flex; align-items: center; pointer-events: none; white-space: nowrap; overflow: hidden; }
445
+ #lock[hidden] ~ #urltext { left: 10px; padding-left: 0; }
446
+ #urltext span:first-child { flex: none; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
447
+ #urltext span:last-child { color: var(--cb-muted, #5E5E5A); overflow: hidden; text-overflow: ellipsis; }
448
+ #url:focus ~ #urltext { visibility: hidden; }
449
+ #takeover, #handback { margin-left: 4px; }
450
+ /* the takeover slot is always reserved: gone only when hand back takes its place */
451
+ #takeover[hidden]:not([data-gone]) { display: inline-grid !important; visibility: hidden; }
452
+ #tabsbtn { flex: 1 1 0; min-width: 0; display: flex; align-items: center; gap: 6px; padding: 0 8px; background: var(--cb-hover, rgba(26,26,24,.05)); text-align: left; }
453
+ #tabsbtn .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
454
+ #tabsbtn .count { min-width: 18px; height: 18px; padding: 0 4px; border-radius: 4px; box-shadow: inset 0 0 0 1px var(--cb-line-strong, #B5B5AE); font-size: 11px; line-height: 18px; text-align: center; color: var(--cb-muted, #5E5E5A); }
455
+ #tabsbtn, #more { display: none; }
456
+ @media (max-width: 440px) {
457
+ #tabs, #forward, #reload, #field { display: none; }
458
+ #tabsbtn { display: flex; }
459
+ #more { display: inline-grid; color: var(--cb-muted, #5E5E5A); }
460
+ }
461
+
462
+ /* status line: one fixed-height line */
463
+ #status { height: 24px; gap: 6px; margin: 0; padding: 0 16px; font-size: var(--cb-type-micro-size, 11px); line-height: var(--cb-type-micro-line, 14px); color: var(--cb-muted, #5E5E5A); white-space: nowrap; overflow: hidden; }
464
+ #status .ico { display: inline-flex; flex: none; }
465
+ #status .lead { flex: none; }
466
+ #status .detail { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
467
+ #status[data-tone="agent"] .ico, #status[data-tone="agent"] .lead { color: var(--cb-accent, #CC4609); }
468
+ #status[data-tone="user"] .ico, #status[data-tone="user"] .lead { color: var(--cb-ink, #1A1A18); }
469
+ .spin { animation: spin 1s linear infinite; }
470
+ @keyframes spin { to { transform: rotate(360deg); } }
471
+
472
+ /* needs the person: a warn strip in the status line's place */
473
+ .warn { flex: none; display: flex; align-items: center; gap: 10px; padding: 8px 12px 8px 16px; background: color-mix(in srgb, var(--cb-warn, #8F6500) 8%, transparent); }
474
+ .warn > .ico { display: inline-flex; flex: none; color: var(--cb-warn, #8F6500); }
475
+ .warn .text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
476
+ .warn .title { color: var(--cb-warn, #8F6500); font-weight: 500; overflow-wrap: anywhere; }
477
+ .warn .body { font-family: var(--cb-font-prose, system-ui, sans-serif); color: var(--cb-muted, #5E5E5A); overflow-wrap: anywhere; }
478
+ .warn .actions { display: flex; gap: 6px; flex: none; }
479
+
480
+ /* the picture, contained and centred on a neutral ground */
481
+ #stage { flex: 1; min-height: 0; position: relative; display: flex; align-items: center; justify-content: center; padding: 12px; overflow: hidden; background: var(--ground); }
482
+ #view { display: block; flex: none; border-radius: var(--radius); background: #fff; box-shadow: var(--frame-shadow); outline: none; }
483
+ #stage[data-control="user"] #view { box-shadow: 0 0 0 2px var(--cb-accent, #CC4609), 0 4px 16px rgba(26,26,24,.08); }
484
+ #view:focus-visible { box-shadow: 0 0 0 2px var(--cb-focus-ring, Highlight), var(--frame-shadow); }
485
+ #flash { position: absolute; width: 24px; height: 24px; margin: -12px 0 0 -12px; border: 2px solid var(--cb-accent, #CC4609); border-radius: 50%; pointer-events: none; }
486
+ .center { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 6px; align-items: center; justify-content: center; padding: 16px; text-align: center; background: var(--ground); }
487
+ .center h2 { margin: 0; font-size: inherit; font-weight: 600; }
488
+ .center p { margin: 0; font-family: var(--cb-font-prose, system-ui, sans-serif); color: var(--cb-muted, #5E5E5A); }
489
+ .center button { margin-top: 6px; }
490
+ /* short-lived notices float over the picture's bottom edge: they never move it */
491
+ #strips { position: absolute; left: 12px; right: 12px; bottom: 12px; display: flex; flex-direction: column; gap: 6px; pointer-events: none; }
492
+ .strip { display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 12px; pointer-events: auto; 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); }
493
+ .strip p { flex: 1; min-width: 0; margin: 0; overflow-wrap: anywhere; }
494
+ .strip .label { color: var(--cb-muted, #5E5E5A); }
495
+ .strip:not(:has(button)) { padding-right: 12px; }
496
+
497
+ /* menus (narrow: tabs, more) */
498
+ .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); }
499
+ .menu button { display: flex; width: 100%; justify-content: flex-start; gap: 8px; padding: 0 8px; text-align: left; overflow: hidden; text-overflow: ellipsis; }
500
+ .menu button[aria-current="true"] { font-weight: 600; }
501
+ .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); }
502
+ .menu .heading:not(:first-child) { margin-top: 4px; }
503
+ .menu button .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
504
+ .menu button .hint { flex: none; margin-left: 8px; color: var(--cb-accent, #CC4609); }
505
+
506
+ /* the skeleton: the panel's own shape, quietly pulsing */
507
+ .bone { display: block; flex: none; border-radius: 2px; background: var(--bone); animation: pulse 1.6s ease-in-out infinite; }
508
+ @keyframes pulse { 50% { opacity: .5; } }
509
+ #skeleton .shot { width: 100%; max-height: 100%; aspect-ratio: 16 / 10; display: flex; flex-direction: column; gap: 12px; padding: 20px; border-radius: var(--radius); background: var(--cb-panel, #fff); box-shadow: 0 1px 2px rgba(26,26,24,.06); }
510
+ :root[data-theme="dark"] #skeleton .shot { background: var(--cb-raised, #141413); box-shadow: var(--frame-shadow); }
511
+ #skeleton .narrow { display: none; }
512
+ @media (max-width: 440px) {
513
+ #skeleton .wide { display: none; }
514
+ #skeleton .narrow { display: block; }
258
515
  }
259
- button:hover:not(:disabled) { background: var(--cb-hover, transparent); }
260
- button:disabled { opacity: .5; }
261
- button.primary { background: var(--cb-accent, Highlight); color: var(--cb-on-accent, HighlightText); border-color: transparent; }
262
- #tabs { display: flex; gap: 2px; overflow-x: auto; padding: 4px 4px 0; border-bottom: 1px solid var(--cb-line, GrayText); }
263
- .tab { display: flex; align-items: center; max-width: 160px; border: 1px solid var(--cb-line, GrayText); border-bottom: 0; padding: 0 4px 0 8px; gap: 4px; min-height: 26px; }
264
- .tab[data-active="true"] { background: var(--cb-panel, Canvas); font-weight: 600; }
265
- .tab button { border: 0; padding: 0 4px; min-height: 22px; }
266
- .tab .label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border: 0; text-align: left; padding: 0; }
267
- #bar { display: flex; gap: 4px; padding: 4px; align-items: center; }
268
- #url { flex: 1; min-width: 0; }
269
- #lock { display: inline-flex; color: var(--cb-muted, GrayText); }
270
- #status { color: var(--cb-muted, GrayText); padding: 0 8px 4px; min-height: 18px; }
271
- #status[data-control="user"] { color: var(--cb-accent, Highlight); }
272
- #stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; background: var(--cb-panel, Canvas); position: relative; overflow: hidden; }
273
- #view { background: #fff; outline: none; display: block; }
274
- #view:focus-visible { outline: 2px solid var(--cb-accent, Highlight); }
275
- #flash { position: absolute; width: 24px; height: 24px; margin: -12px 0 0 -12px; border: 2px solid var(--cb-accent, Highlight); border-radius: 50%; pointer-events: none; }
276
- .strip { display: flex; gap: 8px; align-items: center; padding: 4px 8px; border-top: 1px solid var(--cb-line, GrayText); background: var(--cb-panel, Canvas); }
277
- .strip span { flex: 1; min-width: 0; overflow-wrap: anywhere; }
278
- .center { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 6px; align-items: center; justify-content: center; text-align: center; padding: 16px; background: var(--cb-bg, Canvas); }
279
- .center h2 { margin: 0; font-size: 13px; }
280
- .center p { margin: 0; color: var(--cb-muted, GrayText); }
516
+ @media (prefers-reduced-motion: reduce) { .bone, .spin { animation: none; } }
281
517
  </style>
282
518
  </head>
283
519
  <body>
284
- <div id="tabs" role="tablist"></div>
285
- <div id="bar">
286
- <button type="button" id="back"></button>
287
- <button type="button" id="forward"></button>
288
- <button type="button" id="reload"></button>
289
- <span id="lock" role="img" hidden><svg width="12" height="12" viewBox="0 0 12 12" aria-hidden="true"><rect x="2" y="5" width="8" height="6" fill="currentColor"/><path d="M4 5V3.5a2 2 0 0 1 4 0V5" fill="none" stroke="currentColor" stroke-width="1.2"/></svg></span>
290
- <input id="url" type="text" spellcheck="false" autocomplete="off">
291
- <button type="button" id="takeover" class="primary"></button>
292
- <button type="button" id="handback" class="primary" hidden></button>
520
+ <div id="skeleton" class="layer" aria-busy="true">
521
+ <div class="row wide" style="height:32px;gap:8px;padding:0 22px;display:flex">${bone("width:14px;height:14px;border-radius:3px")}${bone("width:96px;height:10px")}</div>
522
+ <div class="row" style="height:44px;gap:4px">${bone("width:28px;height:28px;border-radius:6px")}<span class="wide" style="display:contents">${bone("width:28px;height:28px;border-radius:6px")}${bone("width:28px;height:28px;border-radius:6px")}</span>${bone("flex:1;height:28px;margin-left:4px;border-radius:6px")}${bone("width:56px;height:28px;margin-left:4px;border-radius:6px")}</div>
523
+ <p id="skeleton-status" class="row" role="status" style="height:24px;margin:0;padding:0 16px;font-size:11px;line-height:14px;color:var(--cb-muted,#5E5E5A)"></p>
524
+ <div style="flex:1;min-height:0;display:flex;align-items:center;justify-content:center;padding:12px;background:var(--ground)">
525
+ <div class="shot">${bone("width:40%;height:12px")}${bone("width:75%;height:10px")}${bone("width:60%;height:10px")}${bone("flex:1;border-radius:4px")}</div>
526
+ </div>
293
527
  </div>
294
- <div id="handoff" class="strip" hidden><p><span id="handoff-label"></span> <span id="handoff-message"></span></p><button type="button" id="handoff-done" class="primary"></button><button type="button" id="handoff-cancel"></button></div>
295
- <p id="status" role="status"></p>
296
- <div id="stage">
297
- <canvas id="view" tabindex="0"></canvas>
298
- <div id="flash" hidden></div>
299
- <div id="empty" class="center" hidden>
300
- <h2 id="empty-title"></h2>
301
- <p id="empty-body"></p>
302
- <button type="button" id="reconnect"></button>
528
+ <div id="app" class="layer" data-loading>
529
+ <div id="tabs" class="row"><div id="tablist" role="tablist"></div><button type="button" id="others" aria-haspopup="menu" hidden></button></div>
530
+ <div id="bar" class="row">
531
+ <button type="button" id="back">${ICONS.back}</button>
532
+ <button type="button" id="forward">${ICONS.forward}</button>
533
+ <button type="button" id="reload">${ICONS.reload}</button>
534
+ <button type="button" id="tabsbtn" aria-haspopup="menu"><span class="fav" data-glyph="site">${ICONS.globe}</span><span class="name" id="tabsbtn-name"></span><span class="count" id="tabsbtn-count"></span></button>
535
+ <label id="field"><span id="lock" role="img" hidden>${ICONS.lock}</span><input id="url" type="text" spellcheck="false" autocomplete="off"><span id="urltext"><span id="urltext-host"></span><span id="urltext-path"></span></span></label>
536
+ <button type="button" id="more" aria-haspopup="menu">${ICONS.more}</button>
537
+ <button type="button" id="takeover" class="primary" hidden></button>
538
+ <button type="button" id="handback" class="outline" hidden></button>
539
+ </div>
540
+ <p id="status" class="row" role="status"><span class="ico" id="status-icon"></span><span class="lead" id="status-lead"></span><span class="detail" id="status-detail"></span></p>
541
+ <div id="verify" class="warn" hidden><span class="ico">${ICONS.pause}</span><div class="text"><span class="title" id="verify-title"></span><span class="body" id="verify-body"></span></div><div class="actions"><button type="button" id="verify-go" class="primary"></button></div></div>
542
+ <div id="handoff" class="warn" hidden><span class="ico">${ICONS.pause}</span><div class="text"><span class="title" id="handoff-label"></span><span class="body" id="handoff-message"></span></div><div class="actions"><button type="button" id="handoff-done" class="primary"></button><button type="button" id="handoff-cancel" class="secondary"></button></div></div>
543
+ <div id="stage">
544
+ <canvas id="view" tabindex="0"></canvas>
545
+ <div id="flash" hidden></div>
546
+ <div id="strips">
547
+ <div id="blocked" class="strip" hidden><p><span id="blocked-label" class="label"></span> <span id="blocked-host"></span></p><button type="button" id="allow" class="primary"></button></div>
548
+ <div id="dialog" class="strip" hidden><p><span id="dialog-label" class="label"></span> <span id="dialog-text"></span></p></div>
549
+ <div id="notice" class="strip" role="alert" hidden><p><span id="notice-text"></span></p></div>
550
+ </div>
303
551
  </div>
304
552
  </div>
305
- <div id="blocked" class="strip" hidden><p><span id="blocked-label"></span> <span id="blocked-host"></span></p><button type="button" id="allow" class="primary"></button></div>
306
- <div id="dialog" class="strip" hidden><p><span id="dialog-label"></span> <span id="dialog-text"></span></p></div>
307
- <div id="notice" class="strip" role="alert" hidden><p><span id="notice-text"></span></p></div>
553
+ <div id="empty" class="layer center" hidden>
554
+ <h2 id="empty-title"></h2>
555
+ <p id="empty-body"></p>
556
+ <button type="button" id="reconnect" class="secondary"></button>
557
+ <button type="button" id="empty-others" class="secondary" aria-haspopup="menu" hidden></button>
558
+ </div>
559
+ <div id="menu" class="menu" role="menu" hidden></div>
308
560
  <script src="panel.js"></script>
309
561
  </body>
310
562
  </html>
@@ -402,9 +654,19 @@ function registerRoutes(ctx, deps) {
402
654
  const body = await readJson(req);
403
655
  const callId = body?.callId;
404
656
  const done = body?.done;
405
- if (typeof callId !== "string" || callId === "" || callId.length > CALL_ID_MAX || typeof done !== "boolean")
406
- return error(400, "invalid_body", "the body must be { callId: string, done: boolean }");
407
- await deps.deviceAccess.answerHandoff({ ...scope, callId, done });
657
+ const raised = body?.handoffConversationId;
658
+ if (typeof callId !== "string" || callId === "" || callId.length > CALL_ID_MAX || typeof done !== "boolean" || typeof raised !== "string" || raised === "" || raised.length > CALL_ID_MAX)
659
+ return error(
660
+ 400,
661
+ "invalid_body",
662
+ "the body must be { callId: string, handoffConversationId: string, done: boolean }"
663
+ );
664
+ await deps.deviceAccess.answerHandoff({
665
+ ...scope,
666
+ callId,
667
+ handoffConversationId: raised,
668
+ done
669
+ });
408
670
  return json(200, { ok: true });
409
671
  })
410
672
  );
@@ -480,35 +742,41 @@ var NAVIGATE = {
480
742
  additionalProperties: false
481
743
  },
482
744
  keyArgs: ["url", "action"],
483
- defaultPolicy: "allow"
745
+ defaultPolicy: "allow",
746
+ // any tool may start the device first (see TOOL_TIMEOUT_MS)
747
+ timeoutMs: TOOL_TIMEOUT_MS
484
748
  };
485
749
  var TABS = {
486
750
  name: "browser_tabs",
487
751
  title: "Browser tabs",
488
- description: "List, open, switch or close tabs of the browser in the user's device (at most 10 tabs). Use list to see the tab ids, open to load a url in a new tab, switch to make a tab active (the other tools act on the active tab) and close to close one.",
752
+ 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.",
489
753
  inputSchema: {
490
754
  type: "object",
491
755
  properties: {
492
756
  action: {
493
757
  type: "string",
494
- enum: ["list", "open", "switch", "close"],
758
+ enum: ["list", "open", "switch", "close", "adopt"],
495
759
  description: "What to do."
496
760
  },
497
- tabId: { type: "string", description: "The tab for switch and close, from list." },
761
+ tabId: { type: "string", description: "The tab for switch, close and adopt, from list." },
498
762
  url: { type: "string", description: "The address for open (optional: a blank tab)." }
499
763
  },
500
764
  required: ["action"],
501
765
  additionalProperties: false
502
766
  },
503
- keyArgs: ["action", "url"],
504
- defaultPolicy: "allow"
767
+ keyArgs: ["action", "tabId", "url"],
768
+ defaultPolicy: "allow",
769
+ // any tool may start the device first (see TOOL_TIMEOUT_MS)
770
+ timeoutMs: TOOL_TIMEOUT_MS
505
771
  };
506
772
  var SNAPSHOT = {
507
773
  name: "browser_snapshot",
508
774
  title: "Read the page",
509
775
  description: "Read the active page as an accessibility tree in text, with a ref (e.g. e12) on every element you can act on. Call it after opening a page and after any action that changes the page: refs from older snapshots may no longer exist. Prefer it to browser_screenshot unless the layout or an image matters.",
510
776
  inputSchema: { type: "object", properties: {}, additionalProperties: false },
511
- defaultPolicy: "allow"
777
+ defaultPolicy: "allow",
778
+ // any tool may start the device first (see TOOL_TIMEOUT_MS)
779
+ timeoutMs: TOOL_TIMEOUT_MS
512
780
  };
513
781
  var SCREENSHOT = {
514
782
  name: "browser_screenshot",
@@ -521,7 +789,9 @@ var SCREENSHOT = {
521
789
  },
522
790
  additionalProperties: false
523
791
  },
524
- defaultPolicy: "allow"
792
+ defaultPolicy: "allow",
793
+ // any tool may start the device first (see TOOL_TIMEOUT_MS)
794
+ timeoutMs: TOOL_TIMEOUT_MS
525
795
  };
526
796
  var CLICK = {
527
797
  name: "browser_click",
@@ -534,7 +804,9 @@ var CLICK = {
534
804
  additionalProperties: false
535
805
  },
536
806
  keyArgs: ["ref"],
537
- defaultPolicy: "ask"
807
+ defaultPolicy: "ask",
808
+ // any tool may start the device first (see TOOL_TIMEOUT_MS)
809
+ timeoutMs: TOOL_TIMEOUT_MS
538
810
  };
539
811
  var TYPE = {
540
812
  name: "browser_type",
@@ -551,7 +823,9 @@ var TYPE = {
551
823
  additionalProperties: false
552
824
  },
553
825
  keyArgs: ["ref", "text"],
554
- defaultPolicy: "ask"
826
+ defaultPolicy: "ask",
827
+ // any tool may start the device first (see TOOL_TIMEOUT_MS)
828
+ timeoutMs: TOOL_TIMEOUT_MS
555
829
  };
556
830
  var SELECT = {
557
831
  name: "browser_select",
@@ -572,7 +846,9 @@ var SELECT = {
572
846
  additionalProperties: false
573
847
  },
574
848
  keyArgs: ["ref", "values"],
575
- defaultPolicy: "ask"
849
+ defaultPolicy: "ask",
850
+ // any tool may start the device first (see TOOL_TIMEOUT_MS)
851
+ timeoutMs: TOOL_TIMEOUT_MS
576
852
  };
577
853
  var PRESS = {
578
854
  name: "browser_press",
@@ -590,7 +866,9 @@ var PRESS = {
590
866
  additionalProperties: false
591
867
  },
592
868
  keyArgs: ["key"],
593
- defaultPolicy: "ask"
869
+ defaultPolicy: "ask",
870
+ // any tool may start the device first (see TOOL_TIMEOUT_MS)
871
+ timeoutMs: TOOL_TIMEOUT_MS
594
872
  };
595
873
  var SCROLL = {
596
874
  name: "browser_scroll",
@@ -606,7 +884,9 @@ var SCROLL = {
606
884
  additionalProperties: false
607
885
  },
608
886
  keyArgs: ["ref", "dy"],
609
- defaultPolicy: "ask"
887
+ defaultPolicy: "ask",
888
+ // any tool may start the device first (see TOOL_TIMEOUT_MS)
889
+ timeoutMs: TOOL_TIMEOUT_MS
610
890
  };
611
891
  var HOVER = {
612
892
  name: "browser_hover",
@@ -619,7 +899,9 @@ var HOVER = {
619
899
  additionalProperties: false
620
900
  },
621
901
  keyArgs: ["ref"],
622
- defaultPolicy: "ask"
902
+ defaultPolicy: "ask",
903
+ // any tool may start the device first (see TOOL_TIMEOUT_MS)
904
+ timeoutMs: TOOL_TIMEOUT_MS
623
905
  };
624
906
  var UPLOAD = {
625
907
  name: "browser_upload",
@@ -635,7 +917,9 @@ var UPLOAD = {
635
917
  additionalProperties: false
636
918
  },
637
919
  keyArgs: ["ref", "path"],
638
- defaultPolicy: "ask"
920
+ defaultPolicy: "ask",
921
+ // any tool may start the device first (see TOOL_TIMEOUT_MS)
922
+ timeoutMs: TOOL_TIMEOUT_MS
639
923
  };
640
924
  var POINT = {
641
925
  x: {
@@ -662,7 +946,9 @@ var CLICK_AT = {
662
946
  additionalProperties: false
663
947
  },
664
948
  keyArgs: ["x", "y"],
665
- defaultPolicy: "ask"
949
+ defaultPolicy: "ask",
950
+ // any tool may start the device first (see TOOL_TIMEOUT_MS)
951
+ timeoutMs: TOOL_TIMEOUT_MS
666
952
  };
667
953
  var TYPE_AT = {
668
954
  name: "browser_type_at",
@@ -675,7 +961,9 @@ var TYPE_AT = {
675
961
  additionalProperties: false
676
962
  },
677
963
  keyArgs: ["x", "y", "text"],
678
- defaultPolicy: "ask"
964
+ defaultPolicy: "ask",
965
+ // any tool may start the device first (see TOOL_TIMEOUT_MS)
966
+ timeoutMs: TOOL_TIMEOUT_MS
679
967
  };
680
968
  var WAIT = {
681
969
  name: "browser_wait",
@@ -697,7 +985,9 @@ var WAIT = {
697
985
  additionalProperties: false
698
986
  },
699
987
  keyArgs: ["text", "timeoutMs"],
700
- defaultPolicy: "allow"
988
+ defaultPolicy: "allow",
989
+ // any tool may start the device first (see TOOL_TIMEOUT_MS)
990
+ timeoutMs: TOOL_TIMEOUT_MS
701
991
  };
702
992
  var obj = (input) => typeof input === "object" && input !== null ? input : {};
703
993
  var str = (v) => typeof v === "string" ? v : void 0;
@@ -709,6 +999,7 @@ function need(v, field, tool) {
709
999
  if (v === void 0) throw new ToolError3(`${tool} needs ${field}; pass it and retry.`);
710
1000
  return v;
711
1001
  }
1002
+ var namesTab = (a) => a === "switch" || a === "close" || a === "adopt";
712
1003
  function handler(deps, toRequest, timeoutOf = () => REQUEST_TIMEOUT_MS) {
713
1004
  return async (input, call) => {
714
1005
  const req = toRequest(obj(input));
@@ -728,15 +1019,15 @@ function registerBrowserTools(ctx, deps) {
728
1019
  );
729
1020
  ctx.tools.register(
730
1021
  TABS,
731
- handler(
732
- deps,
733
- (i) => defined({
734
- op: "tabs",
735
- action: need(str(i.action), "an action", "browser_tabs"),
736
- tabId: str(i.tabId),
737
- url: str(i.url)
738
- })
739
- )
1022
+ handler(deps, (i) => {
1023
+ const action = need(str(i.action), "an action", "browser_tabs");
1024
+ const tabId = str(i.tabId);
1025
+ if (namesTab(action) && (tabId === void 0 || tabId === ""))
1026
+ throw new ToolError3(
1027
+ `browser_tabs needs a tabId for ${action}; call browser_tabs with action list for the tab ids, then retry.`
1028
+ );
1029
+ return defined({ op: "tabs", action, tabId, url: str(i.url) });
1030
+ })
740
1031
  );
741
1032
  ctx.tools.register(
742
1033
  SNAPSHOT,
@@ -859,8 +1150,8 @@ function registerBrowserTools(ctx, deps) {
859
1150
  // src/index.ts
860
1151
  var index_default = defineExtension({
861
1152
  name: "browser",
862
- version: "0.1.0-rc.1",
863
- sdk: "^0.1.0-rc.69",
1153
+ version: "0.1.0-rc.11",
1154
+ sdk: "^0.1.0-rc.75",
864
1155
  provides: [],
865
1156
  ui: [
866
1157
  {