@omercnet/paseo-shared-browser 4.1.12 → 4.2.0-next.528.1

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/OVERVIEW.md CHANGED
@@ -13,7 +13,7 @@ New agents whose provider accepts external MCP servers receive a local MCP serve
13
13
 
14
14
  ## Setup
15
15
 
16
- - Paseo ^0.13.0 || ^0.14.0 || ^0.15.0 || ^0.16.0, and Node.js 24 or newer on the daemon host.
16
+ - Paseo ^0.13.0 || ^0.14.0 || ^0.15.0 || ^0.16.0 || ^0.17.0, and Node.js 24 or newer on the daemon host.
17
17
  - Chromium is downloaded when the plugin is installed and stored in the Paseo data directory. On Linux ARM64 nothing is downloaded, and you install a non-Snap Chromium at `/usr/bin/chromium` first. `PASEO_SHARED_BROWSER_CHROMIUM_EXECUTABLE` points the plugin at a different Chromium.
18
18
 
19
19
  ## Limits
package/README.md CHANGED
@@ -135,7 +135,8 @@ jumps to the chosen workspace's browser panel.
135
135
 
136
136
  The plugin automatically injects its stdio MCP adapter only when a new, non-internal agent is
137
137
  created with a provider that accepts external MCP servers. Agents that already exist, resumed
138
- sessions, imported sessions, and Paseo's internal agents are not modified. Paseo's built-in OMP
138
+ sessions, imported sessions, and Paseo's internal agents are not modified (the one exception is the labels list under
139
+ "listed" mode, which is applied at every interactive session open, resumed sessions included). Paseo's built-in OMP
139
140
  provider accepts session MCP servers, so new OMP agents receive the adapter.
140
141
  Pi agents also receive the adapter, but require Pi's optional MCP support to
141
142
  launch it.
@@ -157,6 +158,43 @@ The provider launches the stdio adapter on the Paseo daemon host, beside the dae
157
158
  runtime. Web, desktop, and mobile clients never own or host the adapter or Chromium, and a client
158
159
  disconnect does not close or reset either process.
159
160
 
161
+ ### Choosing which agents get the tool
162
+
163
+ By default every new agent gets the adapter. Settings, under Shared Browser, can restrict that:
164
+
165
+ - **Every new agent** (the default) injects the adapter into every new agent, as above.
166
+ - **Only the agents listed** injects it only into a new agent whose provider id is listed, or whose
167
+ workspace id or project id is listed, and into any agent that carries a listed label (below).
168
+ Separate entries with commas or new lines. An empty configuration means no agent.
169
+
170
+ **Labels.** An entry is a label key (`team`: any agent with that label) or `key=value` (`team=blue`:
171
+ that label with exactly that value). Matching is exact and case-sensitive. Labels are not on the
172
+ `agent.create` request, only on the session-open request, so this is decided there, and it works
173
+ differently from the other lists: a server returned from that hook lasts for that session only, while one
174
+ added in `agent.create` is stored on the agent. So an agent with a matching label gets the adapter in
175
+ every interactive session it opens (a new agent, a resume, a refresh, an import), each time with a fresh
176
+ ticket bound to that agent and its workspace; the tickets are revoked together when the agent is
177
+ archived, and an agent keeps at most eight bound tickets (the oldest is dropped first, its viewer is detached, and the log gets one line). A bind for a ticket that was issued before the agent was revoked is refused, however late it arrives; a ticket issued after the revocation, for example by a restored agent, binds normally. Helper (background) agents, history sessions and sessions without a workspace are skipped. If
178
+ the ticket cannot be issued or bound the session opens without the tool and the log gets one line. In
179
+ "Every new agent" mode this does nothing, because every new agent already has the tool; an agent that
180
+ the create hook already gave a ticket is not given a second one.
181
+
182
+ Labels are a convenience for choosing agents, not a lock. Any connected client with write access, and any agent
183
+ that has Paseo tools, can set or delete labels on any agent, itself included, so a label does not keep an
184
+ untrusted agent away from the browser.
185
+
186
+ `agent.create` carries the provider and the working directory but no labels and no workspace id, so a
187
+ workspace or project is matched by directory: the workspace whose directory is the agent's directory or
188
+ the deepest one containing it. Both directories are normalized first (separators, `.` and `..` segments),
189
+ so a path that climbs out of a workspace does not match it. The lookup includes background workspaces. If
190
+ the list is longer than 20 pages of 200, or the lookup fails, those lists match nothing. Workspaces that
191
+ share a directory cannot be told apart, so listing any of them matches them all. Matching is lexical: nothing on disk is consulted, so symlinks are not resolved and letter case is not folded. A path is only compared when it starts at a root (`/` or a drive such as `C:`); a relative workspace or agent directory never matches. Backslashes are read as separators and only drive paths are modelled, so a UNC path is not recognized (`\\server\share` reads as `/server/share`, and a bare `C:` reads as `C:/`) and a literal backslash in a POSIX file name counts as a separator. The settings read has a 2 second deadline, and a read that is too slow is treated like an unreadable setting, so every new agent gets the tool. The workspace lookup has its own 2 second deadline, and a timeout there counts as no match. Either timeout logs one line, and a slow lookup never holds up agent creation. The check runs before the adapter, its credential or the supervisor are set up, so
192
+ an agent that is not allowed costs nothing. It applies to agents created after the setting is saved. A
193
+ setting that cannot be read or is invalid falls back to every new agent, and the plugin log gets one line
194
+ saying so. The settings screen reports an entry over 256 characters or a list over 200 entries instead of
195
+ cutting it off. Changing the mode in the settings screen also saves the list text as typed, and shows
196
+ the error instead of saving when a list does not parse.
197
+
160
198
  ## Runtime environment overrides
161
199
 
162
200
  The plugin recognizes only these deployment overrides:
@@ -442,7 +480,7 @@ runs the actual Paseo compiler on both plugin entries.
442
480
  Release Please maintains the version, changelog, component tag, and GitHub release from
443
481
  Conventional Commits in the monorepo.
444
482
 
445
- Both the Paseo daemon and app must satisfy `^0.13.0 || ^0.14.0 || ^0.15.0 || ^0.16.0`. Encoded video is opt-in on the daemon and
483
+ Both the Paseo daemon and app must satisfy `^0.13.0 || ^0.14.0 || ^0.15.0 || ^0.16.0 || ^0.17.0`. Encoded video is opt-in on the daemon and
446
484
  requires WebCodecs in a web client; JPEG is always available. The client surface uses React
447
485
  Native primitives and works in desktop, web, iOS, and Android Paseo clients.
448
486
 
@@ -0,0 +1,157 @@
1
+ import { type PluginSurfaceProps, useSettings } from "@getpaseo/plugin/client";
2
+ import {
3
+ SettingsAction,
4
+ SettingsCard,
5
+ SettingsInput,
6
+ type SettingsInputHandle,
7
+ SettingsSection,
8
+ SettingsSelect,
9
+ } from "@getpaseo/plugin/client/ui";
10
+ import { useRef, useState } from "react";
11
+ import { Text } from "react-native";
12
+ import { type AgentAccessMode, agentAccessSettings, parseEntries } from "../shared/agent-access";
13
+
14
+ const MODE_OPTIONS: readonly { label: string; value: AgentAccessMode }[] = [
15
+ { label: "Every new agent", value: "all" },
16
+ { label: "Only the agents listed below", value: "listed" },
17
+ ];
18
+
19
+ type ListName = "providers" | "workspaces" | "projects" | "labels";
20
+ const NO_ERRORS: Record<ListName, string | null> = {
21
+ providers: null,
22
+ workspaces: null,
23
+ projects: null,
24
+ labels: null,
25
+ };
26
+
27
+ /** Settings screen: which new agents get the browser tool. */
28
+ export function AgentAccessSettings({ theme }: PluginSurfaceProps) {
29
+ const settings = useSettings(agentAccessSettings);
30
+ const providers = useRef<SettingsInputHandle>(null);
31
+ const workspaces = useRef<SettingsInputHandle>(null);
32
+ const projects = useRef<SettingsInputHandle>(null);
33
+ const labels = useRef<SettingsInputHandle>(null);
34
+ // Errors belong to the revision they were found on; a newer revision (another client saved) clears them.
35
+ const [found, setFound] = useState<{
36
+ revision: string | null;
37
+ errors: Record<ListName, string | null>;
38
+ }>({ revision: null, errors: NO_ERRORS });
39
+ const muted = { color: theme.colors.foregroundMuted, fontSize: 13, lineHeight: 19 };
40
+
41
+ if (settings.status === "loading") {
42
+ return (
43
+ <SettingsSection title="Shared Browser: agent access">
44
+ <Text style={muted}>Loading</Text>
45
+ </SettingsSection>
46
+ );
47
+ }
48
+ if (settings.status !== "ready") {
49
+ return (
50
+ <SettingsSection title="Shared Browser: agent access">
51
+ <Text style={muted}>{settings.error}</Text>
52
+ <SettingsCard>
53
+ <SettingsAction label="Try again" actionLabel="Reload" onPress={settings.reload} />
54
+ {settings.status === "invalid" ? (
55
+ <SettingsAction
56
+ label="Back to the default"
57
+ actionLabel="Reset"
58
+ onPress={settings.reset}
59
+ />
60
+ ) : null}
61
+ </SettingsCard>
62
+ </SettingsSection>
63
+ );
64
+ }
65
+
66
+ const { values } = settings;
67
+ const listErrors = found.revision === settings.revision ? found.errors : NO_ERRORS;
68
+ const save = (next: typeof values) => void settings.save(next, settings.revision);
69
+ // The lists as typed, parsed the same way for Save and for a mode change, so unsaved text is never
70
+ // lost to the revision remount. A list that does not parse shows its error and nothing is saved.
71
+ const typedLists = () => {
72
+ const parsed = {
73
+ providers: parseEntries(providers.current?.getText() ?? ""),
74
+ workspaces: parseEntries(workspaces.current?.getText() ?? ""),
75
+ projects: parseEntries(projects.current?.getText() ?? ""),
76
+ labels: parseEntries(labels.current?.getText() ?? ""),
77
+ };
78
+ const errors = {
79
+ providers: parsed.providers.error,
80
+ workspaces: parsed.workspaces.error,
81
+ projects: parsed.projects.error,
82
+ labels: parsed.labels.error,
83
+ };
84
+ setFound({ revision: settings.revision, errors });
85
+ if (errors.providers || errors.workspaces || errors.projects || errors.labels) return null;
86
+ return {
87
+ providers: parsed.providers.entries,
88
+ workspaces: parsed.workspaces.entries,
89
+ projects: parsed.projects.entries,
90
+ labels: parsed.labels.entries,
91
+ };
92
+ };
93
+ return (
94
+ <SettingsSection title="Shared Browser: agent access">
95
+ {/* Keyed on the revision, so the text inputs start over from the saved lists when another client changes them. */}
96
+ <SettingsCard key={settings.revision}>
97
+ <SettingsSelect
98
+ label="Browser tool for"
99
+ hint="Providers, workspaces and projects apply to agents created from now on; labels apply to every session of a labelled agent. With the lists empty, no agent gets the tool."
100
+ error={settings.saveError}
101
+ value={values.mode}
102
+ options={MODE_OPTIONS}
103
+ disabled={settings.saving}
104
+ onValueChange={(mode) => {
105
+ const lists = typedLists();
106
+ if (lists) save({ ...values, ...lists, mode });
107
+ }}
108
+ />
109
+ <SettingsInput
110
+ ref={providers}
111
+ label="Provider ids"
112
+ hint="Separated by commas or new lines. An agent whose provider is listed gets the tool."
113
+ initialValue={values.providers.join(", ")}
114
+ error={listErrors.providers}
115
+ onChangeText={() => {}}
116
+ disabled={settings.saving}
117
+ />
118
+ <SettingsInput
119
+ ref={workspaces}
120
+ label="Workspace ids"
121
+ hint="Every new agent in a listed workspace gets the tool."
122
+ initialValue={values.workspaces.join(", ")}
123
+ error={listErrors.workspaces}
124
+ onChangeText={() => {}}
125
+ disabled={settings.saving}
126
+ />
127
+ <SettingsInput
128
+ ref={projects}
129
+ label="Project ids"
130
+ hint="Every new agent in a workspace of a listed project gets the tool."
131
+ initialValue={values.projects.join(", ")}
132
+ error={listErrors.projects}
133
+ onChangeText={() => {}}
134
+ disabled={settings.saving}
135
+ />
136
+ <SettingsInput
137
+ ref={labels}
138
+ label="Labels"
139
+ hint="A label key (team) or key=value (team=blue). An agent with a matching label gets the tool in every session, including after a resume. Labels pick agents for convenience; they do not keep an untrusted agent away from the browser, because any agent with Paseo tools can set its own labels."
140
+ initialValue={values.labels.join(", ")}
141
+ error={listErrors.labels}
142
+ onChangeText={() => {}}
143
+ disabled={settings.saving}
144
+ />
145
+ <SettingsAction
146
+ label="Save the lists"
147
+ actionLabel="Save"
148
+ disabled={settings.saving}
149
+ onPress={() => {
150
+ const lists = typedLists();
151
+ if (lists) save({ ...values, ...lists });
152
+ }}
153
+ />
154
+ </SettingsCard>
155
+ </SettingsSection>
156
+ );
157
+ }
@@ -48,15 +48,20 @@ function fakeDom() {
48
48
  removeEventListener: nodeTarget.remove,
49
49
  } as unknown as KeyboardCanvasNode;
50
50
  sink.focus();
51
+ /** Dispatches to the adapter's listeners; returns whether one cancelled the default. */
51
52
  const fire = (name: string, type: string, event: object = {}) => {
53
+ let cancelled = false;
52
54
  for (const listener of registry.get(`${name}:${type}`) ?? [])
53
55
  (listener as (event: object) => void)({
54
- preventDefault() {},
56
+ preventDefault() {
57
+ cancelled = true;
58
+ },
55
59
  stopPropagation() {},
56
60
  ...event,
57
61
  });
62
+ return cancelled;
58
63
  };
59
- return { node, document, fire };
64
+ return { node, document, sink, fire };
60
65
  }
61
66
 
62
67
  const key = {
@@ -225,3 +230,181 @@ describe("web canvas keyboard adapter Android IME sequences", () => {
225
230
  expect(texts(dom)).toEqual(["x"]);
226
231
  });
227
232
  });
233
+
234
+ type Bound = ReturnType<typeof bind>;
235
+ /** Remote key edges, such as "down:Backspace". */
236
+ const presses = (dom: Bound) =>
237
+ dom.events.flatMap((event) => (event.kind === "key" ? [`${event.type}:${event.key}`] : []));
238
+ const BACKSPACE = ["down:Backspace", "up:Backspace"];
239
+
240
+ /** keydown 229, one beforeinput edit, keyup 229, regardless of what the sink holds. */
241
+ function imeEdit(dom: Bound, inputType: string) {
242
+ dom.fire("sink", "keydown", ime);
243
+ dom.fire("sink", "beforeinput", { inputType, data: null });
244
+ dom.fire("doc", "keyup", ime);
245
+ }
246
+
247
+ /**
248
+ * Chrome Android applying a soft-keyboard Backspace (ImeAdapterImpl
249
+ * deleteSurroundingText): keydown 229; only when the sink has text before the
250
+ * caret, beforeinput deleteContentBackward, the deletion and input; keyup 229.
251
+ * Blink applies this deletion even when beforeinput is cancelled
252
+ * (InputMethodController::DeleteSelectionWithoutAdjustment ignores the result);
253
+ * cancelHonored covers an engine that does honor it.
254
+ */
255
+ function softBackspace(dom: Bound, cancelHonored = false) {
256
+ dom.fire("sink", "keydown", ime);
257
+ if (dom.sink.value.length > 0) {
258
+ const cancelled = dom.fire("sink", "beforeinput", {
259
+ inputType: "deleteContentBackward",
260
+ data: null,
261
+ });
262
+ if (!cancelled || !cancelHonored) {
263
+ dom.sink.value = dom.sink.value.slice(0, -1);
264
+ dom.fire("sink", "input", { inputType: "deleteContentBackward", data: null });
265
+ }
266
+ }
267
+ dom.fire("doc", "keyup", ime);
268
+ }
269
+
270
+ /** Hangul composition steps; Backspace inside it rewrites the composition. */
271
+ function compose(dom: Bound, steps: Array<{ inputType: string; data: string | null }>) {
272
+ dom.fire("sink", "keydown", ime);
273
+ dom.fire("sink", "compositionstart", { data: "" });
274
+ for (const [index, step] of steps.entries()) {
275
+ if (index > 0) dom.fire("sink", "keydown", { ...ime, isComposing: true });
276
+ dom.fire("sink", "beforeinput", step);
277
+ }
278
+ }
279
+
280
+ describe("web canvas keyboard adapter Android soft-keyboard deletion", () => {
281
+ it.each<[string, (dom: Bound) => void, { texts: string[]; presses: string[] }]>([
282
+ [
283
+ "keydown 229 + beforeinput deleteContentBackward presses Backspace",
284
+ (dom) => imeEdit(dom, "deleteContentBackward"),
285
+ { texts: [], presses: BACKSPACE },
286
+ ],
287
+ [
288
+ "keydown 229 + beforeinput deleteContentForward presses Delete",
289
+ (dom) => imeEdit(dom, "deleteContentForward"),
290
+ { texts: [], presses: ["down:Delete", "up:Delete"] },
291
+ ],
292
+ // Word deletion has no host-independent shortcut (Ctrl or Option+Backspace).
293
+ [
294
+ "keydown 229 + beforeinput deleteWordBackward stays unmapped",
295
+ (dom) => imeEdit(dom, "deleteWordBackward"),
296
+ { texts: [], presses: [] },
297
+ ],
298
+ [
299
+ "keydown 229 + beforeinput deleteWordForward stays unmapped",
300
+ (dom) => imeEdit(dom, "deleteWordForward"),
301
+ { texts: [], presses: [] },
302
+ ],
303
+ [
304
+ "Backspace before any typing (empty field, keydown carries no key)",
305
+ (dom) => softBackspace(dom),
306
+ { texts: [], presses: BACKSPACE },
307
+ ],
308
+ [
309
+ "three Backspaces after a committed word",
310
+ (dom) => {
311
+ composeWord(dom, "hi");
312
+ for (let count = 0; count < 3; count += 1) softBackspace(dom);
313
+ },
314
+ { texts: ["hi"], presses: [...BACKSPACE, ...BACKSPACE, ...BACKSPACE] },
315
+ ],
316
+ [
317
+ "three Backspaces when the engine honors the cancelled beforeinput",
318
+ (dom) => {
319
+ composeWord(dom, "hi");
320
+ for (let count = 0; count < 3; count += 1) softBackspace(dom, true);
321
+ },
322
+ { texts: ["hi"], presses: [...BACKSPACE, ...BACKSPACE, ...BACKSPACE] },
323
+ ],
324
+ [
325
+ "Backspace after a non-composing insertText",
326
+ (dom) => {
327
+ dom.fire("sink", "keydown", ime);
328
+ dom.fire("sink", "beforeinput", { inputType: "insertText", data: "a" });
329
+ softBackspace(dom);
330
+ },
331
+ { texts: ["a"], presses: BACKSPACE },
332
+ ],
333
+ [
334
+ "Backspace after a paste",
335
+ (dom) => {
336
+ dom.fire("sink", "paste", { clipboardData: { getData: () => "pasted" } });
337
+ softBackspace(dom);
338
+ },
339
+ { texts: ["pasted"], presses: BACKSPACE },
340
+ ],
341
+ [
342
+ "Backspace after a control reset",
343
+ (dom) => {
344
+ dom.binding.reset();
345
+ softBackspace(dom);
346
+ },
347
+ { texts: [], presses: BACKSPACE },
348
+ ],
349
+ [
350
+ "Backspace inside a composing word edits it locally (Gboard predictive)",
351
+ (dom) => {
352
+ compose(dom, [
353
+ { inputType: "insertCompositionText", data: "hel" },
354
+ { inputType: "insertCompositionText", data: "he" },
355
+ ]);
356
+ dom.fire("sink", "compositionend", { data: "he" });
357
+ },
358
+ { texts: ["he"], presses: [] },
359
+ ],
360
+ [
361
+ "Hangul: Backspace removes a jamo inside the composition",
362
+ (dom) => {
363
+ compose(dom, [
364
+ { inputType: "insertCompositionText", data: "ㅎ" },
365
+ { inputType: "insertCompositionText", data: "하" },
366
+ { inputType: "insertCompositionText", data: "한" },
367
+ { inputType: "insertCompositionText", data: "하" },
368
+ ]);
369
+ dom.fire("sink", "compositionend", { data: "하" });
370
+ },
371
+ { texts: ["하"], presses: [] },
372
+ ],
373
+ [
374
+ "Hangul: Backspace empties the composition, then deletes the committed syllable",
375
+ (dom) => {
376
+ composeWord(dom, "한");
377
+ compose(dom, [
378
+ { inputType: "insertCompositionText", data: "ㄱ" },
379
+ { inputType: "deleteCompositionText", data: null },
380
+ ]);
381
+ dom.fire("sink", "compositionend", { data: "" });
382
+ softBackspace(dom);
383
+ },
384
+ { texts: ["한"], presses: BACKSPACE },
385
+ ],
386
+ [
387
+ "a real Backspace keydown (keyCode 8) presses once even if beforeinput follows",
388
+ (dom) => {
389
+ const backspace = { ...key, key: "Backspace", code: "Backspace", keyCode: 8 };
390
+ dom.fire("sink", "keydown", backspace);
391
+ dom.fire("sink", "beforeinput", { inputType: "deleteContentBackward", data: null });
392
+ dom.fire("doc", "keyup", backspace);
393
+ },
394
+ { texts: [], presses: BACKSPACE },
395
+ ],
396
+ [
397
+ "an IME deletion after a control reset is dropped",
398
+ (dom) => {
399
+ dom.fire("sink", "keydown", ime);
400
+ dom.binding.reset();
401
+ dom.fire("sink", "beforeinput", { inputType: "deleteContentBackward", data: null });
402
+ },
403
+ { texts: [], presses: [] },
404
+ ],
405
+ ])("%s", (_name, replay, expected) => {
406
+ const dom = bind();
407
+ replay(dom);
408
+ expect({ texts: texts(dom), presses: presses(dom) }).toEqual(expected);
409
+ });
410
+ });
@@ -57,6 +57,18 @@ interface BindingOptions {
57
57
  onError(error: Error): void;
58
58
  }
59
59
 
60
+ // Android soft keyboards delete through InputConnection.deleteSurroundingText.
61
+ // Chrome reports keydown 229/"Unidentified", then beforeinput delete* only when
62
+ // the sink has text next to the caret. With an empty sink the keydown and keyup
63
+ // are all that arrive, so the sink always keeps one invisible character to delete.
64
+ const SINK_TEXT = "\u200B";
65
+ // Character deletions map to the key a hardware keyboard sends. Word deletions
66
+ // stay unmapped: the remote shortcut depends on the host OS (Ctrl or Option).
67
+ const IME_EDIT_KEYS: Record<string, string> = {
68
+ deleteContentBackward: "Backspace",
69
+ deleteContentForward: "Delete",
70
+ };
71
+
60
72
  /** DOM-only binding; callers must dispose it and reset on route/control changes. */
61
73
  export function bindBrowserCanvasKeyboard(node: KeyboardCanvasNode, options: BindingOptions) {
62
74
  const document = node.ownerDocument;
@@ -80,13 +92,14 @@ export function bindBrowserCanvasKeyboard(node: KeyboardCanvasNode, options: Bin
80
92
  });
81
93
  node.tabIndex = 0;
82
94
  node.appendChild(sink);
95
+ sink.value = SINK_TEXT;
83
96
  let composing = false;
84
97
  let compositionAdmitted = false;
85
98
  let altTextPending: string | null = null;
86
- // Soft keyboards (Android Chrome) report committed text outside a composition,
87
- // such as a space after a word or every key on non-predictive keyboards, as
88
- // keydown 229/"Unidentified" followed by beforeinput insertText. That keydown
89
- // carries no key to forward, so the insertion itself is the only text source.
99
+ // Soft keyboards (Android Chrome) report edits outside a composition, such as
100
+ // a space after a word, every key on non-predictive keyboards, or Backspace,
101
+ // as keydown 229/"Unidentified" followed by beforeinput insertText or delete*.
102
+ // That keydown carries no key to forward, so the edit itself is the only source.
90
103
  let imeTextPending = false;
91
104
  const focused = () => document.activeElement === sink || document.activeElement === node;
92
105
  const keyboard = createBrowserCanvasKeyboard({
@@ -103,7 +116,7 @@ export function bindBrowserCanvasKeyboard(node: KeyboardCanvasNode, options: Bin
103
116
  composing = false;
104
117
  altTextPending = null;
105
118
  imeTextPending = false;
106
- sink.value = "";
119
+ sink.value = SINK_TEXT;
107
120
  };
108
121
  const cancel = () => {
109
122
  reset();
@@ -177,12 +190,31 @@ export function bindBrowserCanvasKeyboard(node: KeyboardCanvasNode, options: Bin
177
190
  if (accepted) {
178
191
  commitText(event.data ?? "");
179
192
  }
180
- sink.value = "";
193
+ sink.value = SINK_TEXT;
194
+ };
195
+ // One full press, as the matching hardware key would send it.
196
+ const pressKey = (key: string) => {
197
+ const press = {
198
+ key,
199
+ code: key,
200
+ altKey: false,
201
+ ctrlKey: false,
202
+ metaKey: false,
203
+ shiftKey: false,
204
+ repeat: false,
205
+ };
206
+ if (keyboard.key("down", press)) {
207
+ keyboard.key("up", press);
208
+ }
181
209
  };
182
210
  const beforeInput = (event: KeyboardDomEvent) => {
183
211
  if (!composing && options.enabled() && focused()) {
184
212
  consume(event);
185
- if (
213
+ const editKey =
214
+ imeTextPending && event.inputType ? IME_EDIT_KEYS[event.inputType] : undefined;
215
+ if (editKey) {
216
+ pressKey(editKey);
217
+ } else if (
186
218
  event.inputType === "insertText" &&
187
219
  event.data &&
188
220
  (imeTextPending || event.data === altTextPending)
@@ -192,6 +224,13 @@ export function bindBrowserCanvasKeyboard(node: KeyboardCanvasNode, options: Bin
192
224
  altTextPending = null;
193
225
  }
194
226
  };
227
+ // Blink applies a deleteSurroundingText deletion even when its beforeinput was
228
+ // cancelled. Put the sink text back so the next Backspace still has a target.
229
+ const input = () => {
230
+ if (!composing && sink.value !== SINK_TEXT) {
231
+ sink.value = SINK_TEXT;
232
+ }
233
+ };
195
234
  const paste = (event: KeyboardDomEvent) => {
196
235
  if (!options.enabled() || !focused()) {
197
236
  return;
@@ -199,7 +238,7 @@ export function bindBrowserCanvasKeyboard(node: KeyboardCanvasNode, options: Bin
199
238
  consume(event);
200
239
  altTextPending = null;
201
240
  commitText(event.clipboardData?.getData("text/plain") ?? "");
202
- sink.value = "";
241
+ sink.value = SINK_TEXT;
203
242
  };
204
243
  const visibility = () => {
205
244
  if (document.hidden) {
@@ -216,6 +255,7 @@ export function bindBrowserCanvasKeyboard(node: KeyboardCanvasNode, options: Bin
216
255
  [sink, "compositionstart", compositionStart],
217
256
  [sink, "compositionend", compositionEnd],
218
257
  [sink, "beforeinput", beforeInput],
258
+ [sink, "input", input],
219
259
  [sink, "paste", paste],
220
260
  [sink, "blur", cancel],
221
261
  ];
@@ -396,6 +396,38 @@ describe("bounded browser input queue", () => {
396
396
  expect(f.errors).toEqual([]);
397
397
  });
398
398
 
399
+ it("sends soft-keyboard text queued behind an in-flight call as one insertion, never across keys", async () => {
400
+ const f = fixture();
401
+ const backspace = (type: "down" | "up"): BrowserGestureEvent => ({
402
+ kind: "key",
403
+ type,
404
+ key: "Backspace",
405
+ code: "Backspace",
406
+ modifiers: 0,
407
+ repeat: false,
408
+ });
409
+ for (const text of ["h", "e", "l", "l", "o"]) f.queue.enqueue({ kind: "text", text });
410
+ f.queue.enqueue(backspace("down"));
411
+ f.queue.enqueue(backspace("up"));
412
+ for (const text of [" ", "w"]) f.queue.enqueue({ kind: "text", text });
413
+ // Merging stops at the per-event text limit the server enforces.
414
+ f.queue.enqueue({ kind: "text", text: "x".repeat(15_999) });
415
+ f.queue.finish();
416
+ f.beginGate.resolve({ state, gestureId: "owned", nextSequence: 1 });
417
+ await flush();
418
+ expect(f.sent.map(({ event }) => (event.kind === "text" ? event.text : event.kind))).toEqual([
419
+ "h",
420
+ "ello",
421
+ "key",
422
+ "key",
423
+ " w",
424
+ "x".repeat(15_999),
425
+ ]);
426
+ expect(f.sent.map((input) => input.sequence)).toEqual([1, 2, 3, 4, 5, 6]);
427
+ expect(f.ended[0]).toMatchObject({ sequence: 7, cancel: false });
428
+ expect(f.errors).toEqual([]);
429
+ });
430
+
399
431
  it("keeps touch-ID edges through 60Hz motion and partial release", async () => {
400
432
  const f = fixture();
401
433
  const touch = (
@@ -84,6 +84,8 @@ export const BROWSER_INPUT_IDLE_MS = 4_000;
84
84
  export const BROWSER_INPUT_KEEPALIVE_MS = 2_000;
85
85
  const MAX_QUEUED_COMMANDS = 64;
86
86
  const MAX_WHEEL_DELTA = 4_000;
87
+ /** Per-event text limit the gesture schema and runtime owner enforce. */
88
+ const MAX_TEXT_LENGTH = 16_000;
87
89
  const MAX_FRAME_ADMISSION_ATTEMPTS = 3;
88
90
  const FRAME_ADMISSION_WAIT_MS = 4_000;
89
91
 
@@ -551,6 +553,16 @@ export function createBrowserInputQueue(options: QueueOptions) {
551
553
  return true;
552
554
  }
553
555
  }
556
+ // Soft keyboards commit text in small pieces, one update each. Text still
557
+ // queued behind the in-flight call is one insertion; never merge across keys.
558
+ if (
559
+ event.kind === "text" &&
560
+ previous.event.kind === "text" &&
561
+ previous.event.text.length + event.text.length <= MAX_TEXT_LENGTH
562
+ ) {
563
+ previous.event = { kind: "text", text: previous.event.text + event.text };
564
+ return true;
565
+ }
554
566
  }
555
567
  if (commands.length >= MAX_QUEUED_COMMANDS) {
556
568
  cancel();
package/index.client.tsx CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { PluginClientContext } from "@getpaseo/plugin/client";
2
+ import { AgentAccessSettings } from "./client/agent-access-settings";
2
3
  import { contributeSharedBrowserClient, SharedBrowserPanel } from "./client/browser";
3
4
  import { contributeSharedBrowserSidebar } from "./client/sidebar";
4
5
 
@@ -21,9 +22,16 @@ export default function contribute(client: PluginClientContext) {
21
22
  },
22
23
  });
23
24
 
25
+ const removeSettings = client.addSettingsScreen({
26
+ id: "agent-access",
27
+ title: "Shared Browser",
28
+ icon: "PanelsTopLeft",
29
+ Component: AgentAccessSettings,
30
+ });
24
31
  const removeSidebar = contributeSharedBrowserSidebar(client);
25
32
  const cleanup = contributeSharedBrowserClient(client);
26
33
  return () => {
34
+ removeSettings();
27
35
  removeSidebar();
28
36
  return cleanup();
29
37
  };