@agimon-ai/po-remote 0.0.0-alpha.170

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.
@@ -0,0 +1,1464 @@
1
+ import { defineFill, defineSettingsPanel, defineWebLifecycle, defineWebPlugin, hostRevisionTopic, subscribeHubRevision } from "@agimon-ai/po-core/web";
2
+ import { AlertIcon, Button, CheckIcon, Dialog, DialogBody, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, Dot, Input, QrCode, RadioGroup, RadioGroupCard, SectionLabel, SettingsActions, SettingsCard, SettingsDescription, SettingsField, SettingsNote, SettingsRow, SettingsRowDescription, SettingsRowText, SettingsRowTitle, SettingsSection, SettingsSectionDescription, SettingsSectionHeader, SettingsSectionTitle, ShieldIcon, Skeleton, Spinner, Switch, Tabs, TabsList, TabsTrigger, Tooltip, TooltipContent, TooltipTrigger } from "@agimon-ai/po-web-components";
3
+ import { useStore } from "@tanstack/react-store";
4
+ import { browserTransport, fetchWithStepUp, passkeysAvailable, registerPasskey } from "@agimon-ai/po-web-security/browser";
5
+ import { Store } from "@tanstack/store";
6
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
7
+ import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
8
+ //#region src/types/remoteAccess.ts
9
+ /**
10
+ * Wire vocabulary for remote access, shared by the hub routes and the cockpit.
11
+ *
12
+ * Remote access binds a second loopback listener that a tunnel points at, and
13
+ * everything arriving there must prove it holds a paired session. The
14
+ * discriminator is the listening socket, not a header: a tunnel connects from
15
+ * 127.0.0.1 like every local client, and there is no header a remote caller
16
+ * cannot forge.
17
+ */
18
+ /** REST surface for the remote-access control plane; local callers only, except turn-off and revoke. */
19
+ const REMOTE_API_ROUTE = "/api/remote";
20
+ /** Device-bound, sealed routes for ephemeral live Web Push registration. */
21
+ /** Trusted native devices; `DELETE ${TRUSTED_DEVICES_ROUTE}/:id` revokes one. Mirrors po-core's constant. */
22
+ const TRUSTED_DEVICES_ROUTE = `${REMOTE_API_ROUTE}/trusted-devices`;
23
+ /**
24
+ * The phone app's form of the same QR: its `po` scheme wrapping the encoded HTTPS pairing URL, so a
25
+ * phone camera opens Po instead of the browser. The app unwraps it and checks the inner URL as usual.
26
+ */
27
+ const NATIVE_PAIRING_LINK_PREFIX = "po://pair?link=";
28
+ //#endregion
29
+ //#region src/extensions/(frontend)/_lib/remoteApi.ts
30
+ const UNREACHABLE$1 = "The cockpit hub is unreachable.";
31
+ const JSON_HEADERS$1 = { "Content-Type": "application/json" };
32
+ function isRecord$1(value) {
33
+ return typeof value === "object" && value !== null && !Array.isArray(value);
34
+ }
35
+ /**
36
+ * One shape for every remote-access call, mirroring `authApi.ts`: a network
37
+ * failure, a non-2xx answer, and a 2xx body missing what was asked for all come
38
+ * back as `{ error }`, so the dialog has one branch to render.
39
+ */
40
+ async function request(input, init, pick, send = (target, options) => browserTransport.fetch(target, options)) {
41
+ let response;
42
+ try {
43
+ response = await send(input, init);
44
+ } catch {
45
+ return { error: UNREACHABLE$1 };
46
+ }
47
+ let body;
48
+ try {
49
+ body = await response.json();
50
+ } catch {
51
+ body = void 0;
52
+ }
53
+ if (response.ok && isRecord$1(body)) {
54
+ const picked = pick(body);
55
+ if (picked !== void 0) return picked;
56
+ }
57
+ if (isRecord$1(body) && typeof body.error === "string") return { error: body.error };
58
+ return { error: `The hub answered ${String(response.status)}.` };
59
+ }
60
+ function pickState(body) {
61
+ return isRecord$1(body.state) ? { state: body.state } : void 0;
62
+ }
63
+ async function fetchRemoteState() {
64
+ return await request(REMOTE_API_ROUTE, void 0, pickState);
65
+ }
66
+ async function enableRemoteAccess() {
67
+ return await request(`${REMOTE_API_ROUTE}/enable`, { method: "POST" }, pickState);
68
+ }
69
+ async function disableRemoteAccess() {
70
+ return await request(`${REMOTE_API_ROUTE}/disable`, { method: "POST" }, pickState);
71
+ }
72
+ /** Mints the code the QR encodes. Each call retires the previous one. */
73
+ async function mintPairingCode() {
74
+ return await request(`${REMOTE_API_ROUTE}/codes`, { method: "POST" }, (body) => typeof body.pairUrl === "string" && typeof body.code === "string" && typeof body.manualCode === "string" && typeof body.expiresAt === "string" && typeof body.publicKey === "string" && typeof body.fingerprint === "string" && typeof body.revision === "number" ? {
75
+ code: body.code,
76
+ manualCode: body.manualCode,
77
+ pairUrl: body.pairUrl,
78
+ expiresAt: body.expiresAt,
79
+ publicKey: body.publicKey,
80
+ fingerprint: body.fingerprint,
81
+ revision: body.revision
82
+ } : void 0);
83
+ }
84
+ async function approvePairing(requestId) {
85
+ return await request(`${REMOTE_API_ROUTE}/pairing/${encodeURIComponent(requestId)}/approve`, { method: "POST" }, pickState);
86
+ }
87
+ async function denyPairing(requestId) {
88
+ return await request(`${REMOTE_API_ROUTE}/pairing/${encodeURIComponent(requestId)}/deny`, { method: "POST" }, pickState);
89
+ }
90
+ async function revokeDevice(id) {
91
+ return await request(`${REMOTE_API_ROUTE}/devices/${encodeURIComponent(id)}`, { method: "DELETE" }, pickState);
92
+ }
93
+ /**
94
+ * Removes a trusted native device and every live session it holds. A remote caller answers a step-up
95
+ * first; a quick-tunnel browser cannot, so the hub refuses it with a message this returns as `error`.
96
+ */
97
+ async function revokeTrustedDevice(id) {
98
+ return await request(`${TRUSTED_DEVICES_ROUTE}/${encodeURIComponent(id)}`, { method: "DELETE" }, pickState, (target, options) => fetchWithStepUp(target, options));
99
+ }
100
+ async function saveRemoteSettings(patch) {
101
+ return await request(`${REMOTE_API_ROUTE}/settings`, {
102
+ method: "PUT",
103
+ headers: JSON_HEADERS$1,
104
+ body: JSON.stringify(patch)
105
+ }, (body) => isRecord$1(body.settings) ? { settings: body.settings } : void 0);
106
+ }
107
+ //#endregion
108
+ //#region src/extensions/(frontend)/_lib/remoteAccessStore.ts
109
+ const remoteAccessStore = new Store({
110
+ step: "closed",
111
+ busy: false
112
+ });
113
+ const pendingSettings = /* @__PURE__ */ new Set();
114
+ function set$1(patch) {
115
+ const view = patch.view;
116
+ if (view !== void 0 && pendingSettings.size > 0) patch = {
117
+ ...patch,
118
+ view: {
119
+ ...view,
120
+ settings: [...pendingSettings].reduce((settings, draft) => ({
121
+ ...settings,
122
+ ...draft
123
+ }), view.settings)
124
+ }
125
+ };
126
+ remoteAccessStore.setState((state) => ({
127
+ ...state,
128
+ ...patch
129
+ }));
130
+ }
131
+ /** Clears the previous error before an action, so a stale one never outlives its cause. */
132
+ function begin() {
133
+ set$1({
134
+ busy: true,
135
+ error: void 0
136
+ });
137
+ }
138
+ function settle(outcome) {
139
+ if ("error" in outcome) {
140
+ set$1({
141
+ busy: false,
142
+ error: outcome.error
143
+ });
144
+ return false;
145
+ }
146
+ set$1({
147
+ busy: false,
148
+ view: outcome.state
149
+ });
150
+ return true;
151
+ }
152
+ function openRemoteDialog() {
153
+ set$1({
154
+ step: "options",
155
+ error: void 0
156
+ });
157
+ refreshRemoteState();
158
+ }
159
+ function closeRemoteDialog() {
160
+ set$1({
161
+ step: "closed",
162
+ error: void 0
163
+ });
164
+ }
165
+ function showRemoteOptions() {
166
+ set$1({
167
+ step: "options",
168
+ error: void 0
169
+ });
170
+ }
171
+ /** Whether this tunnel and this browser can carry a passkey at all. */
172
+ async function refreshPasskeys() {
173
+ try {
174
+ const response = await browserTransport.fetch("/api/remote/passkeys", { credentials: "same-origin" });
175
+ if (!response.ok) return;
176
+ const body = await response.json();
177
+ set$1({ passkeys: {
178
+ supported: body.support.supported && passkeysAvailable(),
179
+ ...body.support.reason === void 0 ? {} : { reason: body.support.reason },
180
+ count: body.credentials.length
181
+ } });
182
+ } catch (error) {
183
+ console.warn("Passkey support could not be read", error);
184
+ }
185
+ }
186
+ async function addPasskey() {
187
+ begin();
188
+ const outcome = await registerPasskey();
189
+ set$1({
190
+ busy: false,
191
+ ...outcome.ok ? {} : { error: outcome.error }
192
+ });
193
+ await refreshPasskeys();
194
+ }
195
+ async function refreshRemoteState() {
196
+ const outcome = await fetchRemoteState();
197
+ if ("error" in outcome) {
198
+ set$1({ error: outcome.error });
199
+ return;
200
+ }
201
+ if (pendingSettings.size === 0 && JSON.stringify(remoteAccessStore.state.view) === JSON.stringify(outcome.state)) return;
202
+ set$1({ view: outcome.state });
203
+ }
204
+ /** Turns the tunnel on and moves straight to the code, which is what the user came for. */
205
+ async function turnRemoteAccessOn() {
206
+ begin();
207
+ if (!settle(await enableRemoteAccess())) return;
208
+ await Promise.all([newPairingCode(), refreshPasskeys()]);
209
+ set$1({ step: "pairing" });
210
+ }
211
+ async function turnRemoteAccessOff() {
212
+ begin();
213
+ if (!settle(await disableRemoteAccess())) return;
214
+ set$1({
215
+ step: "options",
216
+ pairUrl: void 0,
217
+ pairCode: void 0,
218
+ pairFingerprint: void 0,
219
+ pairRevision: void 0,
220
+ pairExpiresAt: void 0
221
+ });
222
+ }
223
+ async function newPairingCode() {
224
+ const minted = await mintPairingCode();
225
+ if ("error" in minted) {
226
+ set$1({
227
+ error: minted.error,
228
+ pairUrl: void 0,
229
+ pairCode: void 0,
230
+ pairFingerprint: void 0,
231
+ pairRevision: void 0
232
+ });
233
+ return;
234
+ }
235
+ set$1({
236
+ step: "pairing",
237
+ pairUrl: minted.pairUrl,
238
+ pairCode: minted.manualCode,
239
+ pairFingerprint: minted.fingerprint,
240
+ pairRevision: minted.revision,
241
+ pairExpiresAt: minted.expiresAt
242
+ });
243
+ }
244
+ /**
245
+ * Switches the code between the browser link and the Po app link. Choosing the app asks the host
246
+ * for its native build, which it defers until a phone needs it, so it is ready by the time the
247
+ * app connects.
248
+ */
249
+ function choosePairTarget(target) {
250
+ set$1({ pairTarget: target });
251
+ if (target !== "native") return;
252
+ browserTransport.fetch("/api/compositions?client=native", { credentials: "same-origin" }).catch((error) => console.warn("The Po app build could not be requested", error));
253
+ }
254
+ async function approveDevice(requestId) {
255
+ settle(await approvePairing(requestId));
256
+ }
257
+ async function denyDevice(requestId) {
258
+ settle(await denyPairing(requestId));
259
+ }
260
+ async function revokePairedDevice(id) {
261
+ begin();
262
+ settle(await revokeDevice(id));
263
+ }
264
+ async function revokeTrustedNativeDevice(id) {
265
+ begin();
266
+ settle(await revokeTrustedDevice(id));
267
+ }
268
+ const settingsWrites = { last: Promise.resolve() };
269
+ async function updateRemoteSettings(patch) {
270
+ const draft = { ...patch };
271
+ pendingSettings.add(draft);
272
+ const view = remoteAccessStore.state.view;
273
+ if (view !== void 0) set$1({
274
+ view: {
275
+ ...view,
276
+ settings: {
277
+ ...view.settings,
278
+ ...draft
279
+ }
280
+ },
281
+ error: void 0
282
+ });
283
+ const write = () => saveRemoteSettings(draft);
284
+ const pending = settingsWrites.last.then(write, write);
285
+ settingsWrites.last = pending;
286
+ const outcome = await pending;
287
+ pendingSettings.delete(draft);
288
+ if ("error" in outcome) {
289
+ set$1({ error: outcome.error });
290
+ if (settingsWrites.last === pending) refreshRemoteState();
291
+ return false;
292
+ }
293
+ const current = remoteAccessStore.state.view;
294
+ if (current !== void 0 && settingsWrites.last === pending) set$1({
295
+ view: {
296
+ ...current,
297
+ settings: outcome.settings
298
+ },
299
+ error: void 0
300
+ });
301
+ return true;
302
+ }
303
+ //#endregion
304
+ //#region src/extensions/(frontend)/_components/PairingApprovalDialog.tsx
305
+ /**
306
+ * The second factor, and the reason a photographed QR is not enough.
307
+ *
308
+ * Only ever rendered on the host: the hub sends pairing frames to local pages
309
+ * alone, so a paired phone cannot approve the next device and make its own
310
+ * access permanent.
311
+ */
312
+ function PairingApprovalDialog() {
313
+ const request = useStore(remoteAccessStore).view?.pending?.[0];
314
+ if (request === void 0) return null;
315
+ return /* @__PURE__ */ jsx(Dialog, {
316
+ open: true,
317
+ children: /* @__PURE__ */ jsxs(DialogContent, {
318
+ "data-testid": "pairing-approval",
319
+ className: "max-w-md",
320
+ children: [
321
+ /* @__PURE__ */ jsxs(DialogHeader, {
322
+ className: "flex-col items-start",
323
+ children: [/* @__PURE__ */ jsx(DialogTitle, { children: "Pair this device?" }), /* @__PURE__ */ jsx(DialogDescription, { children: "Something scanned your code. Approve it only if it is the device in your hand." })]
324
+ }),
325
+ /* @__PURE__ */ jsxs(DialogBody, {
326
+ className: "flex flex-col gap-2",
327
+ children: [
328
+ /* @__PURE__ */ jsx("p", {
329
+ "data-testid": "pairing-approval-agent",
330
+ className: "break-words text-base text-po-text",
331
+ children: request.userAgent
332
+ }),
333
+ /* @__PURE__ */ jsxs("p", {
334
+ className: "text-sm text-po-dim",
335
+ children: ["Address reported by the edge: ", request.edgeIp]
336
+ }),
337
+ /* @__PURE__ */ jsx("p", {
338
+ className: "text-sm text-po-dim",
339
+ children: "Approving grants the same access you have here, including running shell commands."
340
+ })
341
+ ]
342
+ }),
343
+ /* @__PURE__ */ jsxs(DialogFooter, {
344
+ className: "px-3 pb-3 sm:px-4 sm:pb-4",
345
+ children: [/* @__PURE__ */ jsx(Button, {
346
+ variant: "outline",
347
+ "data-testid": "pairing-deny",
348
+ onClick: () => void denyDevice(request.id),
349
+ children: "Deny"
350
+ }), /* @__PURE__ */ jsx(Button, {
351
+ variant: "primary",
352
+ "data-testid": "pairing-approve",
353
+ onClick: () => void approveDevice(request.id),
354
+ children: "Approve"
355
+ })]
356
+ })
357
+ ]
358
+ })
359
+ });
360
+ }
361
+ //#endregion
362
+ //#region src/extensions/(frontend)/fill/PairingApproval.overlay.web.tsx
363
+ /** The host-side approval for a device that scanned the code; renders nothing while none waits. */
364
+ var PairingApproval_overlay_web_default = defineFill({ component: PairingApprovalDialog });
365
+ //#endregion
366
+ //#region src/extensions/(frontend)/fill/_components/RemoteRailStatus.tsx
367
+ /**
368
+ * Remote access at the foot of the cockpit rail: the button that opens the dialog, and the banner that says
369
+ * the tunnel is starting, on, or failed.
370
+ *
371
+ * A template places the rail-status slot once per spot, inside an element whose `data-rail-status` names the
372
+ * template and the spot (`elegant-action`, `advanced-banner`, ...). Each spot draws only its own markup, so a
373
+ * template that puts the button in its header and the banner in its footer keeps both where they were. The
374
+ * spot is read before paint; a spot this fill does not know draws nothing.
375
+ */
376
+ function RemoteRailStatus() {
377
+ const marker = useRef(null);
378
+ const [spot, setSpot] = useState();
379
+ useLayoutEffect(() => {
380
+ setSpot(marker.current?.closest("[data-rail-status]")?.getAttribute("data-rail-status") ?? null);
381
+ }, []);
382
+ const view = useStore(remoteAccessStore, (state) => state.view);
383
+ const status = view?.status ?? "off";
384
+ const deviceCount = view?.devices.length ?? 0;
385
+ const host = view?.publicUrl === void 0 ? void 0 : new URL(view.publicUrl).host;
386
+ const live = status === "on" || status === "starting";
387
+ const devices = `${String(deviceCount)} device${deviceCount === 1 ? "" : "s"}`;
388
+ const failure = `Remote access failed: ${view?.error ?? "the tunnel stopped"}`;
389
+ const banner = status === "off" ? null : status === "failed" ? "red" : "yellow";
390
+ const remoteDetail = status === "on" ? `Remote access on, ${devices} paired` : void 0;
391
+ if (spot === void 0) return /* @__PURE__ */ jsx("span", {
392
+ ref: marker,
393
+ hidden: true
394
+ });
395
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
396
+ banner === null || spot !== "elegant-banner" ? null : /* @__PURE__ */ jsxs("div", {
397
+ "data-testid": "remote-banner",
398
+ className: `flex items-center gap-2 border-t border-po-border-soft px-4 py-2 text-sm ${banner === "red" ? "bg-po-tint-red text-po-red" : "bg-po-tint-yellow text-po-yellow"}`,
399
+ children: [
400
+ /* @__PURE__ */ jsx(Dot, { tone: banner }),
401
+ /* @__PURE__ */ jsx("span", {
402
+ className: "min-w-0 flex-1 truncate",
403
+ children: status === "failed" ? failure : `Remote access ${status === "starting" ? "starting" : "on"}${host === void 0 ? "" : ` · ${host}`} · ${devices}`
404
+ }),
405
+ /* @__PURE__ */ jsx(Button, {
406
+ variant: "ghost",
407
+ size: "xs",
408
+ "data-testid": "remote-banner-open",
409
+ onClick: openRemoteDialog,
410
+ children: "Manage"
411
+ }),
412
+ /* @__PURE__ */ jsx(Button, {
413
+ variant: "ghost",
414
+ size: "xs",
415
+ "data-testid": "remote-banner-off",
416
+ onClick: () => void turnRemoteAccessOff(),
417
+ children: "Turn off"
418
+ })
419
+ ]
420
+ }),
421
+ banner === null || spot !== "advanced-banner" ? null : /* @__PURE__ */ jsxs("div", {
422
+ "data-testid": "remote-banner",
423
+ className: `flex flex-col gap-1.5 border-t border-po-border-soft px-4 py-2 text-sm ${banner === "red" ? "bg-po-tint-red text-po-red" : "bg-po-tint-yellow text-po-yellow"}`,
424
+ children: [/* @__PURE__ */ jsxs("output", {
425
+ className: "flex min-w-0 items-center gap-2",
426
+ children: [/* @__PURE__ */ jsx(Dot, { tone: banner }), /* @__PURE__ */ jsx("span", {
427
+ className: "truncate",
428
+ children: status === "failed" ? failure : `Remote access is ${status === "starting" ? "starting" : "on"}${host === void 0 ? "" : ` · ${host}`} · ${devices} paired`
429
+ })]
430
+ }), /* @__PURE__ */ jsxs("span", {
431
+ className: "flex items-center justify-end gap-1",
432
+ children: [/* @__PURE__ */ jsx(Button, {
433
+ variant: "ghost",
434
+ size: "sm",
435
+ "data-testid": "remote-banner-open",
436
+ onClick: openRemoteDialog,
437
+ children: "Manage"
438
+ }), /* @__PURE__ */ jsx(Button, {
439
+ variant: "ghost",
440
+ size: "sm",
441
+ "data-testid": "remote-banner-off",
442
+ onClick: () => void turnRemoteAccessOff(),
443
+ children: "Turn off"
444
+ })]
445
+ })]
446
+ }),
447
+ spot !== "elegant-action" ? null : /* @__PURE__ */ jsxs(Button, {
448
+ variant: "ghost",
449
+ size: "md",
450
+ "data-testid": "remote-access-open",
451
+ "aria-label": `Remote access is ${status}`,
452
+ onClick: openRemoteDialog,
453
+ className: `h-9 w-full justify-start gap-3 rounded-lg border-0 px-2.5 text-base font-medium outline-none hover:bg-po-panel/50 focus-visible:ring-2 focus-visible:ring-po-green/50 ${status === "failed" ? "text-po-red" : "text-po-text"}`,
454
+ children: [
455
+ status === "failed" ? /* @__PURE__ */ jsx(AlertIcon, {
456
+ "aria-hidden": true,
457
+ className: "size-4"
458
+ }) : /* @__PURE__ */ jsx(ShieldIcon, {
459
+ "aria-hidden": true,
460
+ className: "size-4 text-po-dim"
461
+ }),
462
+ /* @__PURE__ */ jsx("span", {
463
+ className: "flex-1 text-left",
464
+ children: "Remote access"
465
+ }),
466
+ live ? /* @__PURE__ */ jsxs("span", {
467
+ className: "flex items-center gap-1.5 text-sm font-normal text-po-dim",
468
+ children: [/* @__PURE__ */ jsx(Dot, {
469
+ tone: "yellow",
470
+ pulse: true,
471
+ "data-testid": "remote-access-live"
472
+ }), status === "starting" ? "Starting" : devices]
473
+ }) : /* @__PURE__ */ jsx("span", {
474
+ className: "text-sm font-normal text-po-faint",
475
+ children: status === "failed" ? "Failed" : "Off"
476
+ })
477
+ ]
478
+ }),
479
+ spot !== "advanced-action" ? null : /* @__PURE__ */ jsxs(Button, {
480
+ variant: status === "failed" ? "danger-outline" : "outline",
481
+ size: "md",
482
+ "data-testid": "remote-access-open",
483
+ title: remoteDetail ?? "Remote access",
484
+ "aria-label": remoteDetail ?? `Remote access is ${status}`,
485
+ onClick: openRemoteDialog,
486
+ className: `gap-1.5 rounded-md ${status === "failed" ? "" : "bg-po-panel"}`,
487
+ children: [live ? /* @__PURE__ */ jsx(Dot, {
488
+ tone: "yellow",
489
+ pulse: true,
490
+ "data-testid": "remote-access-live"
491
+ }) : /* @__PURE__ */ jsx(ShieldIcon, { className: "size-4" }), "Remote access"]
492
+ }),
493
+ spot !== "desktop-action" ? null : /* @__PURE__ */ jsxs(Tooltip, { children: [/* @__PURE__ */ jsx(TooltipTrigger, {
494
+ asChild: true,
495
+ children: /* @__PURE__ */ jsx("button", {
496
+ type: "button",
497
+ "aria-label": status === "on" ? "Remote access is on" : "Remote access",
498
+ "data-testid": "desktop-remote",
499
+ onClick: openRemoteDialog,
500
+ className: `relative grid size-10 shrink-0 place-items-center rounded-xl focus-visible:ring-2 focus-visible:ring-po-green focus-visible:outline-none ${status === "on" ? "bg-po-panel text-po-hi shadow-sm" : "text-po-dim hover:bg-po-panel/70"}`,
501
+ children: /* @__PURE__ */ jsx(ShieldIcon, {
502
+ "aria-hidden": true,
503
+ className: `size-4 ${status === "failed" ? "text-po-red" : live ? "text-po-yellow" : ""}`
504
+ })
505
+ })
506
+ }), /* @__PURE__ */ jsx(TooltipContent, {
507
+ side: "top",
508
+ sideOffset: 8,
509
+ children: status === "on" ? "Remote access is on" : "Remote access"
510
+ })] })
511
+ ] });
512
+ }
513
+ //#endregion
514
+ //#region src/extensions/(frontend)/fill/Remote.rail-status.web.tsx
515
+ var Remote_rail_status_web_default = defineFill({ component: RemoteRailStatus });
516
+ const DEV_PROXY_TARGETS_ROUTE = `/api/remote/dev-proxy/targets`;
517
+ /**
518
+ * The path every proxied request lives under.
519
+ *
520
+ * Both slashes matter. The leading one anchors it at the root so no other
521
+ * route can be shadowed, and the trailing one makes `startsWith` exact: a
522
+ * request for `/devproxyevil` must not match, and without the trailing slash
523
+ * it would.
524
+ */
525
+ const DEV_PROXY_PREFIX = "/devproxy/";
526
+ //#endregion
527
+ //#region src/extensions/(frontend)/_lib/devProxyApi.ts
528
+ /**
529
+ * The dev proxy control plane, seen from the browser.
530
+ *
531
+ * Every call goes through the sealed session for the same reason the rest of
532
+ * the cockpit does: on a tunnel, an unsealed `/api/` request is refused. The
533
+ * proxied dev site itself is the deliberate exception, and it never comes
534
+ * through here, because the browser fetches those bytes on its own.
535
+ */
536
+ const UNREACHABLE = "The cockpit hub is unreachable.";
537
+ const JSON_HEADERS = { "Content-Type": "application/json" };
538
+ const NO_CONTENT = 204;
539
+ function isRecord(value) {
540
+ return typeof value === "object" && value !== null && !Array.isArray(value);
541
+ }
542
+ async function readError(response) {
543
+ try {
544
+ const body = await response.json();
545
+ if (isRecord(body) && typeof body.error === "string") return body.error;
546
+ } catch {}
547
+ return `The hub answered ${String(response.status)}.`;
548
+ }
549
+ async function fetchDevProxyTargets() {
550
+ let response;
551
+ try {
552
+ response = await browserTransport.fetch(DEV_PROXY_TARGETS_ROUTE);
553
+ } catch {
554
+ return { error: UNREACHABLE };
555
+ }
556
+ if (!response.ok) return { error: await readError(response) };
557
+ const body = await response.json().catch(() => void 0);
558
+ if (!isRecord(body) || !Array.isArray(body.targets)) return { error: "The hub sent no dev proxy targets." };
559
+ return { state: {
560
+ targets: body.targets,
561
+ canRegister: body.canRegister === true
562
+ } };
563
+ }
564
+ async function addDevProxyTarget(name, port) {
565
+ let response;
566
+ try {
567
+ response = await browserTransport.fetch(DEV_PROXY_TARGETS_ROUTE, {
568
+ method: "POST",
569
+ headers: JSON_HEADERS,
570
+ body: JSON.stringify({
571
+ name,
572
+ port
573
+ })
574
+ });
575
+ } catch {
576
+ return { error: UNREACHABLE };
577
+ }
578
+ if (!response.ok) return { error: await readError(response) };
579
+ const body = await response.json().catch(() => void 0);
580
+ if (!isRecord(body) || !isRecord(body.target)) return { error: "The hub did not confirm the target." };
581
+ return { target: body.target };
582
+ }
583
+ async function removeDevProxyTarget(name) {
584
+ let response;
585
+ try {
586
+ response = await browserTransport.fetch(`${DEV_PROXY_TARGETS_ROUTE}/${encodeURIComponent(name)}`, { method: "DELETE" });
587
+ } catch {
588
+ return { error: UNREACHABLE };
589
+ }
590
+ if (response.status !== NO_CONTENT && !response.ok) return { error: await readError(response) };
591
+ return { ok: true };
592
+ }
593
+ //#endregion
594
+ //#region src/extensions/(frontend)/_lib/devProxyStore.ts
595
+ const devProxyStore = new Store({
596
+ targets: [],
597
+ canRegister: false,
598
+ busy: false
599
+ });
600
+ function set(patch) {
601
+ devProxyStore.setState((state) => ({
602
+ ...state,
603
+ ...patch
604
+ }));
605
+ }
606
+ async function refreshDevProxyTargets() {
607
+ const outcome = await fetchDevProxyTargets();
608
+ if ("error" in outcome) {
609
+ set({ error: outcome.error });
610
+ return;
611
+ }
612
+ set({
613
+ targets: outcome.state.targets,
614
+ canRegister: outcome.state.canRegister,
615
+ error: void 0
616
+ });
617
+ }
618
+ async function createDevProxyTarget(name, port) {
619
+ if (devProxyStore.state.busy) return false;
620
+ set({
621
+ busy: true,
622
+ error: void 0
623
+ });
624
+ const outcome = await addDevProxyTarget(name, port);
625
+ if ("error" in outcome) {
626
+ set({
627
+ busy: false,
628
+ error: outcome.error
629
+ });
630
+ return false;
631
+ }
632
+ await refreshDevProxyTargets();
633
+ set({ busy: false });
634
+ return true;
635
+ }
636
+ async function deleteDevProxyTarget(name) {
637
+ if (devProxyStore.state.busy) return;
638
+ set({
639
+ busy: true,
640
+ error: void 0
641
+ });
642
+ const outcome = await removeDevProxyTarget(name);
643
+ if ("error" in outcome) {
644
+ set({
645
+ busy: false,
646
+ error: outcome.error
647
+ });
648
+ return;
649
+ }
650
+ await refreshDevProxyTargets();
651
+ set({ busy: false });
652
+ }
653
+ //#endregion
654
+ //#region src/extensions/(frontend)/_lib/uiState.ts
655
+ /**
656
+ * Form drafts that outlive a remount, such as a template switch, the way the
657
+ * dashboard's own keyed state does. Web plugins may not import the dashboard.
658
+ */
659
+ const states = /* @__PURE__ */ new Map();
660
+ /** Memory only. Keys include the form and its resource, never the selected template. */
661
+ function uiStateFor(key, initial) {
662
+ let store = states.get(key);
663
+ if (store === void 0) {
664
+ store = new Store(typeof initial === "function" ? initial() : initial);
665
+ states.set(key, store);
666
+ }
667
+ return store;
668
+ }
669
+ /** The store is also exposed for synchronous admission checks in event handlers. */
670
+ function useUiState(key, initial) {
671
+ const store = uiStateFor(key, initial);
672
+ return [
673
+ useStore(store),
674
+ useCallback((next) => {
675
+ store.setState((previous) => typeof next === "function" ? next(previous) : next);
676
+ }, [store]),
677
+ store
678
+ ];
679
+ }
680
+ //#endregion
681
+ //#region src/extensions/(frontend)/_components/DevProxyTargets.tsx
682
+ /**
683
+ * Local dev servers reachable through the cockpit's own address.
684
+ *
685
+ * The `base` line is shown rather than described. A sub-path proxy needs the
686
+ * application to know its base path, exactly as it would behind nginx, and a
687
+ * developer who has to work that out from prose will conclude the feature is
688
+ * broken when their assets 404.
689
+ *
690
+ * Adding a target is host-only, so on a phone the form is replaced by the
691
+ * reason rather than rendered as a button that would be refused.
692
+ */
693
+ function DevProxyTargets() {
694
+ const state = useStore(devProxyStore);
695
+ const [name, setName] = useUiState("dev-proxy/name", "");
696
+ const [port, setPort] = useUiState("dev-proxy/port", "");
697
+ useEffect(() => {
698
+ refreshDevProxyTargets();
699
+ }, []);
700
+ const submit = async () => {
701
+ if (await createDevProxyTarget(name.trim(), Number(port))) {
702
+ setName((current) => current === name ? "" : current);
703
+ setPort((current) => current === port ? "" : current);
704
+ }
705
+ };
706
+ return /* @__PURE__ */ jsxs("div", {
707
+ className: "flex w-full flex-col gap-1.5",
708
+ children: [
709
+ /* @__PURE__ */ jsx(SectionLabel, { children: "dev sites" }),
710
+ /* @__PURE__ */ jsx("span", {
711
+ className: "text-sm text-po-dim",
712
+ children: "Reach a local dev server from a paired device, on this same address."
713
+ }),
714
+ state.targets.map((target) => /* @__PURE__ */ jsxs("div", {
715
+ "data-testid": `dev-proxy-target-${target.name}`,
716
+ className: "flex items-center justify-between gap-3 rounded border border-po-border px-2.5 py-1.5",
717
+ children: [/* @__PURE__ */ jsxs("span", {
718
+ className: "flex min-w-0 flex-col",
719
+ children: [/* @__PURE__ */ jsxs("a", {
720
+ href: state.canRegister ? `http://localhost:${String(target.port)}${DEV_PROXY_PREFIX}${target.name}/` : `${DEV_PROXY_PREFIX}${target.name}/`,
721
+ target: "_blank",
722
+ rel: "noreferrer",
723
+ className: "truncate text-sm text-po-hi underline",
724
+ "data-testid": `dev-proxy-open-${target.name}`,
725
+ children: [
726
+ DEV_PROXY_PREFIX,
727
+ target.name,
728
+ "/"
729
+ ]
730
+ }), /* @__PURE__ */ jsxs("span", {
731
+ className: "truncate text-sm text-po-dim",
732
+ children: [
733
+ "port ",
734
+ target.port,
735
+ " · set base: '",
736
+ DEV_PROXY_PREFIX,
737
+ target.name,
738
+ "/' in the dev server"
739
+ ]
740
+ })]
741
+ }), state.canRegister ? /* @__PURE__ */ jsx(Button, {
742
+ variant: "ghost",
743
+ size: "sm",
744
+ "data-testid": `dev-proxy-remove-${target.name}`,
745
+ onClick: () => void deleteDevProxyTarget(target.name),
746
+ children: "Remove"
747
+ }) : null]
748
+ }, target.name)),
749
+ state.canRegister ? /* @__PURE__ */ jsxs("div", {
750
+ className: "flex items-center gap-2",
751
+ children: [
752
+ /* @__PURE__ */ jsx(Input, {
753
+ "aria-label": "dev site name",
754
+ "data-testid": "dev-proxy-name",
755
+ placeholder: "storefront",
756
+ className: "min-w-0 flex-1",
757
+ value: name,
758
+ onChange: (event) => setName(event.target.value)
759
+ }),
760
+ /* @__PURE__ */ jsx(Input, {
761
+ "aria-label": "dev site port",
762
+ "data-testid": "dev-proxy-port",
763
+ type: "number",
764
+ min: 1,
765
+ max: 65535,
766
+ placeholder: "3000",
767
+ className: "w-24",
768
+ value: port,
769
+ onChange: (event) => setPort(event.target.value)
770
+ }),
771
+ /* @__PURE__ */ jsx(Button, {
772
+ variant: "outline",
773
+ size: "sm",
774
+ "data-testid": "dev-proxy-add",
775
+ disabled: state.busy || name.trim() === "" || port === "",
776
+ onClick: () => void submit(),
777
+ children: "Add"
778
+ })
779
+ ]
780
+ }) : /* @__PURE__ */ jsx("span", {
781
+ className: "text-sm text-po-dim",
782
+ children: "Add a dev site on the host. A paired device can open the ones already listed, but not name new ones."
783
+ }),
784
+ state.error === void 0 ? null : /* @__PURE__ */ jsx("span", {
785
+ "data-testid": "dev-proxy-error",
786
+ className: "text-sm text-po-yellow",
787
+ children: state.error
788
+ })
789
+ ]
790
+ });
791
+ }
792
+ //#endregion
793
+ //#region src/extensions/(frontend)/_components/PairedDeviceList.tsx
794
+ /** Every device currently holding a session, with the one way to take it back. */
795
+ function PairedDeviceList() {
796
+ const devices = useStore(remoteAccessStore).view?.devices ?? [];
797
+ if (devices.length === 0) return null;
798
+ return /* @__PURE__ */ jsxs("div", {
799
+ className: "flex w-full flex-col gap-1.5",
800
+ children: [/* @__PURE__ */ jsx(SectionLabel, { children: "paired devices" }), devices.map((device) => /* @__PURE__ */ jsxs("div", {
801
+ "data-testid": `remote-device-${device.id}`,
802
+ className: "flex items-center justify-between gap-3 rounded border border-po-border px-2.5 py-1.5",
803
+ children: [/* @__PURE__ */ jsxs("span", {
804
+ className: "flex min-w-0 flex-col",
805
+ children: [/* @__PURE__ */ jsxs("span", {
806
+ className: "truncate text-base font-semibold text-po-hi",
807
+ children: [device.label, device.self ? " · this device" : ""]
808
+ }), /* @__PURE__ */ jsx("span", {
809
+ className: "truncate text-sm text-po-dim",
810
+ children: device.userAgent
811
+ })]
812
+ }), /* @__PURE__ */ jsx(Button, {
813
+ variant: "ghost",
814
+ size: "sm",
815
+ "data-testid": `remote-revoke-${device.id}`,
816
+ onClick: () => void revokePairedDevice(device.id),
817
+ children: "Revoke"
818
+ })]
819
+ }, device.id))]
820
+ });
821
+ }
822
+ //#endregion
823
+ //#region src/extensions/(frontend)/_components/TrustedDeviceList.tsx
824
+ const PLATFORM_LABEL = {
825
+ ios: "iOS",
826
+ android: "Android"
827
+ };
828
+ /** Native devices that sign back in with their own key, each with the one way to take that back. */
829
+ function TrustedDeviceListView({ devices, busy = false, onRevoke }) {
830
+ if (devices.length === 0) return null;
831
+ return /* @__PURE__ */ jsxs("div", {
832
+ className: "flex w-full flex-col gap-1.5",
833
+ "data-testid": "remote-trusted-devices",
834
+ children: [
835
+ /* @__PURE__ */ jsx(SectionLabel, { children: "trusted phones" }),
836
+ /* @__PURE__ */ jsx("p", {
837
+ className: "text-sm text-po-dim",
838
+ children: "A trusted phone signs back in on its own. Revoking one signs it out now, and it pairs again by QR."
839
+ }),
840
+ devices.map((device) => /* @__PURE__ */ jsxs("div", {
841
+ "data-testid": `remote-trusted-device-${device.id}`,
842
+ className: "flex items-center justify-between gap-3 rounded border border-po-border px-2.5 py-1.5",
843
+ children: [/* @__PURE__ */ jsxs("span", {
844
+ className: "flex min-w-0 flex-col",
845
+ children: [/* @__PURE__ */ jsxs("span", {
846
+ className: "truncate text-base font-semibold text-po-hi",
847
+ children: [device.label, device.self ? " · this device" : ""]
848
+ }), /* @__PURE__ */ jsxs("span", {
849
+ className: "truncate text-sm text-po-dim",
850
+ children: [
851
+ PLATFORM_LABEL[device.platform],
852
+ " ",
853
+ "·",
854
+ " trusted since ",
855
+ device.createdAt.slice(0, 10)
856
+ ]
857
+ })]
858
+ }), /* @__PURE__ */ jsx(Button, {
859
+ variant: "ghost",
860
+ size: "sm",
861
+ disabled: busy,
862
+ "data-testid": `remote-trusted-revoke-${device.id}`,
863
+ onClick: () => onRevoke(device.id),
864
+ children: "Revoke"
865
+ })]
866
+ }, device.id))
867
+ ]
868
+ });
869
+ }
870
+ /** Reads the hub's trusted devices; revoking from a remote caller asks for a step-up first. */
871
+ function TrustedDeviceList() {
872
+ const state = useStore(remoteAccessStore);
873
+ return /* @__PURE__ */ jsx(TrustedDeviceListView, {
874
+ devices: state.view?.trustedDevices ?? [],
875
+ busy: state.busy,
876
+ onRevoke: (id) => void revokeTrustedNativeDevice(id)
877
+ });
878
+ }
879
+ //#endregion
880
+ //#region src/extensions/(frontend)/_components/RemoteAccessOptions.tsx
881
+ const MAX_MINUTES = 1440;
882
+ const MAX_HOURS = 720;
883
+ /**
884
+ * The bounds on remote access, asked before it is switched on.
885
+ *
886
+ * These sit in front of the decision rather than behind a gear elsewhere,
887
+ * because they are the difference between a tunnel that closes itself and one
888
+ * that is still open next week.
889
+ */
890
+ function RemoteAccessOptions() {
891
+ const settings = useStore(remoteAccessStore).view?.settings;
892
+ if (settings === void 0) return /* @__PURE__ */ jsx(Spinner, {});
893
+ return /* @__PURE__ */ jsxs("div", {
894
+ className: "flex flex-col gap-4",
895
+ children: [
896
+ /* @__PURE__ */ jsxs("label", {
897
+ htmlFor: "remote-autoclose-switch",
898
+ className: "flex items-start justify-between gap-4",
899
+ children: [/* @__PURE__ */ jsxs("span", {
900
+ className: "flex flex-col gap-0.5",
901
+ children: [/* @__PURE__ */ jsx("span", {
902
+ className: "text-base font-medium text-po-text",
903
+ children: "Close the tunnel automatically"
904
+ }), /* @__PURE__ */ jsx("span", {
905
+ className: "text-sm text-po-dim",
906
+ children: "So a tunnel you forgot about does not stay open for weeks."
907
+ })]
908
+ }), /* @__PURE__ */ jsx(Switch, {
909
+ id: "remote-autoclose-switch",
910
+ "data-testid": "remote-autoclose-switch",
911
+ checked: settings.autoCloseEnabled,
912
+ onCheckedChange: (checked) => void updateRemoteSettings({ autoCloseEnabled: checked })
913
+ })]
914
+ }),
915
+ settings.autoCloseEnabled ? /* @__PURE__ */ jsxs("label", {
916
+ htmlFor: "remote-autoclose-minutes",
917
+ className: "flex items-center justify-between gap-4 pl-4",
918
+ children: [/* @__PURE__ */ jsx("span", {
919
+ className: "text-base font-medium text-po-text",
920
+ children: "After this many minutes"
921
+ }), /* @__PURE__ */ jsx(Input, {
922
+ id: "remote-autoclose-minutes",
923
+ "data-testid": "remote-autoclose-minutes",
924
+ type: "number",
925
+ min: 1,
926
+ max: MAX_MINUTES,
927
+ className: "w-24",
928
+ value: settings.autoCloseMinutes,
929
+ onChange: (event) => void updateRemoteSettings({ autoCloseMinutes: Number(event.target.value) })
930
+ })]
931
+ }) : null,
932
+ /* @__PURE__ */ jsxs("label", {
933
+ htmlFor: "remote-expiry-switch",
934
+ className: "flex items-start justify-between gap-4",
935
+ children: [/* @__PURE__ */ jsxs("span", {
936
+ className: "flex flex-col gap-0.5",
937
+ children: [/* @__PURE__ */ jsx("span", {
938
+ className: "text-base font-medium text-po-text",
939
+ children: "Expire paired sessions"
940
+ }), /* @__PURE__ */ jsx("span", {
941
+ className: "text-sm text-po-dim",
942
+ children: "A device that goes quiet, or has simply been paired a long time, has to pair again."
943
+ })]
944
+ }), /* @__PURE__ */ jsx(Switch, {
945
+ id: "remote-expiry-switch",
946
+ "data-testid": "remote-expiry-switch",
947
+ checked: settings.sessionExpiryEnabled,
948
+ onCheckedChange: (checked) => void updateRemoteSettings({ sessionExpiryEnabled: checked })
949
+ })]
950
+ }),
951
+ settings.sessionExpiryEnabled ? /* @__PURE__ */ jsxs("div", {
952
+ className: "flex items-center justify-between gap-4 pl-4",
953
+ children: [/* @__PURE__ */ jsxs("label", {
954
+ htmlFor: "remote-idle-minutes",
955
+ className: "flex items-center gap-2 text-base font-medium text-po-text",
956
+ children: ["Idle minutes", /* @__PURE__ */ jsx(Input, {
957
+ id: "remote-idle-minutes",
958
+ "data-testid": "remote-idle-minutes",
959
+ type: "number",
960
+ min: 1,
961
+ max: MAX_MINUTES,
962
+ className: "w-20",
963
+ value: settings.idleMinutes,
964
+ onChange: (event) => void updateRemoteSettings({ idleMinutes: Number(event.target.value) })
965
+ })]
966
+ }), /* @__PURE__ */ jsxs("label", {
967
+ htmlFor: "remote-absolute-hours",
968
+ className: "flex items-center gap-2 text-base font-medium text-po-text",
969
+ children: ["Total hours", /* @__PURE__ */ jsx(Input, {
970
+ id: "remote-absolute-hours",
971
+ "data-testid": "remote-absolute-hours",
972
+ type: "number",
973
+ min: 1,
974
+ max: MAX_HOURS,
975
+ className: "w-20",
976
+ value: settings.absoluteHours,
977
+ onChange: (event) => void updateRemoteSettings({ absoluteHours: Number(event.target.value) })
978
+ })]
979
+ })]
980
+ }) : null,
981
+ /* @__PURE__ */ jsxs("p", {
982
+ className: "text-sm text-po-dim",
983
+ children: [
984
+ "Switching remote access off always revokes every paired device. Requires ",
985
+ /* @__PURE__ */ jsx("code", { children: "cloudflared" }),
986
+ " on PATH."
987
+ ]
988
+ }),
989
+ /* @__PURE__ */ jsx(PairedDeviceList, {}),
990
+ /* @__PURE__ */ jsx(TrustedDeviceList, {}),
991
+ /* @__PURE__ */ jsx(DevProxyTargets, {})
992
+ ]
993
+ });
994
+ }
995
+ //#endregion
996
+ //#region src/extensions/(frontend)/_components/RemoteAccessPairing.tsx
997
+ /** The QR credential, a short manual code, and the direct address. */
998
+ function RemoteAccessPairing() {
999
+ const state = useStore(remoteAccessStore);
1000
+ if (state.pairUrl === void 0 || state.pairCode === void 0 || state.pairFingerprint === void 0) return /* @__PURE__ */ jsx(Spinner, {});
1001
+ const target = state.pairTarget ?? "web";
1002
+ const qrValue = target === "native" ? `${NATIVE_PAIRING_LINK_PREFIX}${encodeURIComponent(state.pairUrl)}` : state.pairUrl;
1003
+ return /* @__PURE__ */ jsxs("div", {
1004
+ className: "flex flex-col items-center gap-4",
1005
+ children: [
1006
+ /* @__PURE__ */ jsx(Tabs, {
1007
+ value: target,
1008
+ onValueChange: (value) => choosePairTarget(value),
1009
+ children: /* @__PURE__ */ jsxs(TabsList, {
1010
+ "aria-label": "Pair with",
1011
+ children: [/* @__PURE__ */ jsx(TabsTrigger, {
1012
+ value: "web",
1013
+ "data-testid": "remote-pair-target-web",
1014
+ children: "Browser"
1015
+ }), /* @__PURE__ */ jsx(TabsTrigger, {
1016
+ value: "native",
1017
+ "data-testid": "remote-pair-target-native",
1018
+ children: "Po app"
1019
+ })]
1020
+ })
1021
+ }),
1022
+ /* @__PURE__ */ jsx("p", {
1023
+ className: "text-center text-sm text-po-dim",
1024
+ children: target === "native" ? "Scan with the phone camera to open the Po app. Scanning from inside Po? Use the Browser code, or paste the address below." : "Scan with the phone camera to open Po in the phone browser."
1025
+ }),
1026
+ /* @__PURE__ */ jsx("div", {
1027
+ className: "rounded-lg bg-po-hi p-3 text-po-deep",
1028
+ children: /* @__PURE__ */ jsx(QrCode, {
1029
+ value: qrValue,
1030
+ size: 288,
1031
+ label: "Scan to pair this device"
1032
+ })
1033
+ }),
1034
+ target === "web" ? /* @__PURE__ */ jsxs("div", {
1035
+ className: "flex w-full flex-col gap-1",
1036
+ children: [/* @__PURE__ */ jsx(SectionLabel, { children: "or enter this pairing code" }), /* @__PURE__ */ jsx("code", {
1037
+ "data-testid": "remote-pair-code",
1038
+ className: "rounded bg-po-deep p-2 text-center font-mono text-lg tracking-widest text-po-text",
1039
+ children: state.pairCode
1040
+ })]
1041
+ }) : null,
1042
+ /* @__PURE__ */ jsxs("div", {
1043
+ className: "flex w-full flex-col gap-1",
1044
+ children: [
1045
+ /* @__PURE__ */ jsx(SectionLabel, { children: "signing-key fingerprint" }),
1046
+ /* @__PURE__ */ jsx("code", {
1047
+ "data-testid": "remote-signing-fingerprint",
1048
+ className: "break-all rounded bg-po-deep p-2 text-center font-mono text-sm text-po-text",
1049
+ children: state.pairFingerprint.match(/.{1,8}/gu)?.join(" ") ?? state.pairFingerprint
1050
+ }),
1051
+ /* @__PURE__ */ jsxs("p", {
1052
+ className: "text-sm text-po-dim",
1053
+ children: [
1054
+ target === "web" ? "Compare this on the phone when entering the manual code. " : "",
1055
+ "Bundle revision ",
1056
+ String(state.pairRevision),
1057
+ "."
1058
+ ]
1059
+ })
1060
+ ]
1061
+ }),
1062
+ /* @__PURE__ */ jsxs("div", {
1063
+ className: "flex w-full flex-col gap-1",
1064
+ children: [/* @__PURE__ */ jsx(SectionLabel, { children: target === "native" ? "or paste this address in the app" : "or open this address" }), /* @__PURE__ */ jsx("code", {
1065
+ "data-testid": "remote-pair-url",
1066
+ className: "break-all rounded bg-po-deep p-2 text-sm text-po-dim",
1067
+ children: state.pairUrl
1068
+ })]
1069
+ }),
1070
+ /* @__PURE__ */ jsx(Button, {
1071
+ variant: "ghost",
1072
+ size: "sm",
1073
+ "data-testid": "remote-new-code",
1074
+ onClick: () => void newPairingCode(),
1075
+ children: "Show a new code"
1076
+ }),
1077
+ state.passkeys?.supported === true ? /* @__PURE__ */ jsxs("div", {
1078
+ className: "flex w-full flex-col gap-1.5 border-t border-po-border pt-3",
1079
+ children: [
1080
+ /* @__PURE__ */ jsx(SectionLabel, { children: "passkeys" }),
1081
+ /* @__PURE__ */ jsx("p", {
1082
+ className: "text-sm text-po-dim",
1083
+ children: state.passkeys.count === 0 ? "Add one on the device you just paired and it will not need the code again." : `${String(state.passkeys.count)} registered. A paired device signs in with a gesture instead of a code.`
1084
+ }),
1085
+ /* @__PURE__ */ jsx(Button, {
1086
+ variant: "outline",
1087
+ size: "sm",
1088
+ "data-testid": "remote-add-passkey",
1089
+ onClick: () => void addPasskey(),
1090
+ children: "Add a passkey for this device"
1091
+ })
1092
+ ]
1093
+ }) : state.passkeys?.reason === void 0 ? null : /* @__PURE__ */ jsx("p", {
1094
+ "data-testid": "remote-passkey-unavailable",
1095
+ className: "w-full text-sm text-po-dim",
1096
+ children: state.passkeys.reason
1097
+ }),
1098
+ /* @__PURE__ */ jsx(PairedDeviceList, {})
1099
+ ]
1100
+ });
1101
+ }
1102
+ //#endregion
1103
+ //#region src/extensions/(frontend)/_components/RemoteAccessDialog.tsx
1104
+ /**
1105
+ * Two panels rather than one.
1106
+ *
1107
+ * Turning this on puts a shell on this machine within reach of the internet, so
1108
+ * the settings that bound it come first and the code to scan comes second, once
1109
+ * those are answered.
1110
+ */
1111
+ function RemoteAccessDialog() {
1112
+ const state = useStore(remoteAccessStore);
1113
+ const view = state.view;
1114
+ const pairing = state.step === "pairing";
1115
+ const starting = state.busy || view?.status === "starting";
1116
+ if (view?.pending?.length) return null;
1117
+ return /* @__PURE__ */ jsx(Dialog, {
1118
+ open: state.step !== "closed",
1119
+ onOpenChange: (next) => next ? void 0 : closeRemoteDialog(),
1120
+ children: /* @__PURE__ */ jsxs(DialogContent, {
1121
+ width: "lg",
1122
+ "data-testid": "remote-access-dialog",
1123
+ "aria-describedby": void 0,
1124
+ children: [
1125
+ /* @__PURE__ */ jsxs(DialogHeader, { children: [/* @__PURE__ */ jsx(DialogTitle, { children: pairing ? "Pair a device" : "Remote access" }), /* @__PURE__ */ jsx(DialogDescription, { children: pairing ? "Scan this with the device you want to use. You will be asked to approve it here." : "Reach this cockpit from your phone over a public tunnel." })] }),
1126
+ /* @__PURE__ */ jsxs(DialogBody, {
1127
+ className: "flex flex-col gap-5",
1128
+ children: [
1129
+ /* @__PURE__ */ jsx("p", {
1130
+ className: "text-sm leading-relaxed text-po-dim",
1131
+ children: "A paired device can prompt the agent, approve its tool calls, and run shell commands as you. Pair only devices you hold, and only when you mean to."
1132
+ }),
1133
+ pairing ? /* @__PURE__ */ jsx(RemoteAccessPairing, {}) : /* @__PURE__ */ jsx(RemoteAccessOptions, {}),
1134
+ state.error === void 0 ? null : /* @__PURE__ */ jsx("p", {
1135
+ "data-testid": "remote-access-error",
1136
+ className: "text-sm text-po-red",
1137
+ children: state.error
1138
+ })
1139
+ ]
1140
+ }),
1141
+ /* @__PURE__ */ jsx(DialogFooter, {
1142
+ className: "px-3 pb-3 sm:px-4 sm:pb-4",
1143
+ children: view?.status === "on" ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Button, {
1144
+ variant: "danger-outline",
1145
+ "data-testid": "remote-access-off",
1146
+ disabled: state.busy,
1147
+ onClick: () => void turnRemoteAccessOff(),
1148
+ children: "Turn off"
1149
+ }), pairing ? /* @__PURE__ */ jsx(Button, {
1150
+ variant: "ghost",
1151
+ "data-testid": "remote-access-back",
1152
+ onClick: showRemoteOptions,
1153
+ children: "Options"
1154
+ }) : /* @__PURE__ */ jsx(Button, {
1155
+ variant: "primary",
1156
+ "data-testid": "remote-access-pair",
1157
+ disabled: state.busy,
1158
+ onClick: () => void newPairingCode(),
1159
+ children: "Pair a device"
1160
+ })] }) : /* @__PURE__ */ jsxs(Button, {
1161
+ variant: "primary",
1162
+ "data-testid": "remote-access-on",
1163
+ disabled: starting,
1164
+ onClick: () => void turnRemoteAccessOn(),
1165
+ children: [starting ? /* @__PURE__ */ jsx(Spinner, {}) : null, "Turn on and show the code"]
1166
+ })
1167
+ })
1168
+ ]
1169
+ })
1170
+ });
1171
+ }
1172
+ //#endregion
1173
+ //#region src/extensions/(frontend)/fill/RemoteAccess.overlay.web.tsx
1174
+ /** Opened from the rail's remote access button; renders nothing while closed. */
1175
+ var RemoteAccess_overlay_web_default = defineFill({ component: RemoteAccessDialog });
1176
+ //#endregion
1177
+ //#region src/extensions/(frontend)/lifecycle/start.web.ts
1178
+ /** Subscribe before the first read, so a pairing request or tunnel change between the two is not missed. */
1179
+ var start_web_default = defineWebLifecycle(() => {
1180
+ const stop = subscribeHubRevision(hostRevisionTopic("remote"), () => {
1181
+ refreshRemoteState();
1182
+ });
1183
+ refreshRemoteState();
1184
+ return stop;
1185
+ });
1186
+ //#endregion
1187
+ //#region src/extensions/(frontend)/_lib/remoteSummary.ts
1188
+ /** The one-line state a settings list shows beside Remote control, such as "On · po.example.com". */
1189
+ function remoteSummaryText(remote) {
1190
+ if (remote.status === "on") return remote.publicUrl ? `On · ${remote.publicUrl.replace(/^https?:\/\//u, "")}` : "On";
1191
+ if (remote.status === "starting") return "Starting";
1192
+ if (remote.status === "failed") return remote.error ? `Failed · ${remote.error}` : "Failed";
1193
+ return "Off";
1194
+ }
1195
+ /** Reads the state through the host's transport; any failure shows no summary rather than a wrong one. */
1196
+ async function readRemoteSummary(request) {
1197
+ const response = await request(REMOTE_API_ROUTE);
1198
+ if (!response.ok) return void 0;
1199
+ const body = await response.json();
1200
+ return body.state === void 0 ? void 0 : remoteSummaryText(body.state);
1201
+ }
1202
+ //#endregion
1203
+ //#region src/extensions/(frontend)/setting/_components/TunnelSettings.tsx
1204
+ const PUBLIC_HOSTNAME = /^(?=.{1,253}$)(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/iu;
1205
+ function namedTunnel(tunnel) {
1206
+ return tunnel.kind === "named" ? tunnel : {
1207
+ kind: "named",
1208
+ hostname: ""
1209
+ };
1210
+ }
1211
+ function optional(value) {
1212
+ const trimmed = value.trim();
1213
+ return trimmed === "" ? void 0 : trimmed;
1214
+ }
1215
+ const TUNNEL_KINDS = [{
1216
+ kind: "quick",
1217
+ label: "Quick tunnel",
1218
+ detail: "No account needed. The address changes each time."
1219
+ }, {
1220
+ kind: "named",
1221
+ label: "Named tunnel",
1222
+ detail: "Your own domain, and the address stays put."
1223
+ }];
1224
+ /** Selects a rotating quick tunnel or the stable named tunnel needed for a custom domain and passkeys. */
1225
+ function TunnelSettings({ tunnel }) {
1226
+ const [draft, setDraft] = useUiState("tunnel/draft", tunnel);
1227
+ const [lastTunnel, setLastTunnel] = useUiState("tunnel/source", tunnel);
1228
+ const [busy, setBusy, busyState] = useUiState("tunnel/saving", false);
1229
+ if (lastTunnel !== tunnel && JSON.stringify(draft) === JSON.stringify(lastTunnel)) {
1230
+ setLastTunnel(tunnel);
1231
+ setDraft(tunnel);
1232
+ }
1233
+ const hostname = draft.kind === "named" ? draft.hostname.trim() : "";
1234
+ const invalidHostname = draft.kind === "named" && !PUBLIC_HOSTNAME.test(hostname);
1235
+ const changed = JSON.stringify(draft) !== JSON.stringify(tunnel);
1236
+ function updateNamed(patch) {
1237
+ setDraft((current) => ({
1238
+ ...namedTunnel(current),
1239
+ ...patch
1240
+ }));
1241
+ }
1242
+ async function save() {
1243
+ if (busyState.state) return;
1244
+ setBusy(true);
1245
+ const named = namedTunnel(draft);
1246
+ const tokenFile = optional(named.tokenFile ?? "");
1247
+ const name = optional(named.name ?? "");
1248
+ const configFile = optional(named.configFile ?? "");
1249
+ const next = draft.kind === "quick" ? draft : {
1250
+ kind: "named",
1251
+ hostname,
1252
+ ...tokenFile === void 0 ? {} : { tokenFile },
1253
+ ...name === void 0 ? {} : { name },
1254
+ ...configFile === void 0 ? {} : { configFile }
1255
+ };
1256
+ try {
1257
+ if (await updateRemoteSettings({ tunnel: next })) {
1258
+ setLastTunnel(next);
1259
+ setDraft((current) => current === draft ? next : current);
1260
+ }
1261
+ } finally {
1262
+ setBusy(false);
1263
+ }
1264
+ }
1265
+ return /* @__PURE__ */ jsxs(SettingsSection, {
1266
+ "data-testid": "remote-tunnel-settings",
1267
+ children: [
1268
+ /* @__PURE__ */ jsxs(SettingsSectionHeader, { children: [/* @__PURE__ */ jsx(SettingsSectionTitle, { children: "Tunnel" }), /* @__PURE__ */ jsx(SettingsSectionDescription, { children: "How your other devices reach Po. A named tunnel gives you a stable address, which passkeys need." })] }),
1269
+ /* @__PURE__ */ jsx(RadioGroup, {
1270
+ value: draft.kind,
1271
+ onValueChange: (kind) => setDraft(kind === "named" ? namedTunnel(draft) : { kind: "quick" }),
1272
+ className: "grid grid-cols-1 gap-3 min-[480px]:grid-cols-2",
1273
+ "aria-label": "Tunnel type",
1274
+ children: TUNNEL_KINDS.map((option) => /* @__PURE__ */ jsxs(RadioGroupCard, {
1275
+ value: option.kind,
1276
+ "data-testid": `remote-tunnel-${option.kind}`,
1277
+ className: "flex items-start gap-2 rounded-lg p-4",
1278
+ children: [/* @__PURE__ */ jsxs("span", {
1279
+ className: "flex min-w-0 flex-1 flex-col gap-1",
1280
+ children: [/* @__PURE__ */ jsx("span", {
1281
+ className: "text-base font-semibold text-po-hi",
1282
+ children: option.label
1283
+ }), /* @__PURE__ */ jsx("span", {
1284
+ className: "text-sm leading-relaxed text-po-dim",
1285
+ children: option.detail
1286
+ })]
1287
+ }), draft.kind === option.kind ? /* @__PURE__ */ jsx(CheckIcon, { className: "size-4 shrink-0 text-po-green" }) : null]
1288
+ }, option.kind))
1289
+ }),
1290
+ draft.kind === "named" ? /* @__PURE__ */ jsxs(SettingsCard, { children: [
1291
+ /* @__PURE__ */ jsx(SettingsField, {
1292
+ id: "remote-tunnel-hostname",
1293
+ label: "Hostname",
1294
+ description: invalidHostname ? /* @__PURE__ */ jsx("span", {
1295
+ className: "text-po-red",
1296
+ children: "Enter the hostname only, without https://, a port or a path."
1297
+ }) : "The domain your devices will open.",
1298
+ children: /* @__PURE__ */ jsx(Input, {
1299
+ id: "remote-tunnel-hostname",
1300
+ "data-testid": "remote-tunnel-hostname",
1301
+ value: draft.hostname,
1302
+ placeholder: "po.example.com",
1303
+ "aria-invalid": invalidHostname,
1304
+ spellCheck: false,
1305
+ onChange: (event) => updateNamed({ hostname: event.target.value }),
1306
+ className: "font-mono text-sm"
1307
+ })
1308
+ }),
1309
+ /* @__PURE__ */ jsx(SettingsField, {
1310
+ id: "remote-tunnel-token-file",
1311
+ label: "Token file",
1312
+ description: "A local file holding your Cloudflare connector token. Po reads the file and never stores the token itself.",
1313
+ children: /* @__PURE__ */ jsx(Input, {
1314
+ id: "remote-tunnel-token-file",
1315
+ "data-testid": "remote-tunnel-token-file",
1316
+ value: draft.tokenFile ?? "",
1317
+ placeholder: "~/.cloudflared/po.token",
1318
+ spellCheck: false,
1319
+ onChange: (event) => updateNamed({ tokenFile: event.target.value }),
1320
+ className: "font-mono text-sm"
1321
+ })
1322
+ }),
1323
+ /* @__PURE__ */ jsxs("details", {
1324
+ className: "group",
1325
+ children: [/* @__PURE__ */ jsx("summary", {
1326
+ className: "cursor-pointer px-5 py-3 text-sm text-po-dim hover:text-po-hi",
1327
+ children: "Tunnel you manage with cloudflared"
1328
+ }), /* @__PURE__ */ jsxs("div", {
1329
+ className: "flex flex-col divide-y divide-po-border-soft border-t border-po-border-soft",
1330
+ children: [/* @__PURE__ */ jsx(SettingsField, {
1331
+ id: "remote-tunnel-name",
1332
+ label: "Tunnel name",
1333
+ children: /* @__PURE__ */ jsx(Input, {
1334
+ id: "remote-tunnel-name",
1335
+ "data-testid": "remote-tunnel-name",
1336
+ value: draft.name ?? "",
1337
+ placeholder: "po",
1338
+ spellCheck: false,
1339
+ onChange: (event) => updateNamed({ name: event.target.value }),
1340
+ className: "font-mono text-sm"
1341
+ })
1342
+ }), /* @__PURE__ */ jsx(SettingsField, {
1343
+ id: "remote-tunnel-config-file",
1344
+ label: "Config file",
1345
+ children: /* @__PURE__ */ jsx(Input, {
1346
+ id: "remote-tunnel-config-file",
1347
+ "data-testid": "remote-tunnel-config-file",
1348
+ value: draft.configFile ?? "",
1349
+ placeholder: "~/.cloudflared/config.yml",
1350
+ spellCheck: false,
1351
+ onChange: (event) => updateNamed({ configFile: event.target.value }),
1352
+ className: "font-mono text-sm"
1353
+ })
1354
+ })]
1355
+ })]
1356
+ })
1357
+ ] }) : null,
1358
+ /* @__PURE__ */ jsxs(SettingsActions, { children: [/* @__PURE__ */ jsx(Button, {
1359
+ variant: changed && !invalidHostname ? "primary" : "outline",
1360
+ size: "sm",
1361
+ "data-testid": "remote-tunnel-save",
1362
+ loading: busy,
1363
+ disabled: busy || !changed || invalidHostname,
1364
+ onClick: () => void save(),
1365
+ children: "Save tunnel"
1366
+ }), /* @__PURE__ */ jsxs(SettingsNote, { children: [
1367
+ "Takes effect the next time remote access starts. Install ",
1368
+ /* @__PURE__ */ jsx("code", {
1369
+ className: "font-mono",
1370
+ children: "cloudflared"
1371
+ }),
1372
+ " on this machine first."
1373
+ ] })] })
1374
+ ]
1375
+ });
1376
+ }
1377
+ //#endregion
1378
+ //#region src/extensions/(frontend)/setting/_components/RemoteControlSettings.tsx
1379
+ /**
1380
+ * Persistent tunnel configuration, separate from the dialog that starts and pairs a remote session. The host
1381
+ * frames the page with its label and detail, so this draws only the body.
1382
+ */
1383
+ function RemoteControlSettings() {
1384
+ const state = useStore(remoteAccessStore);
1385
+ useEffect(() => {
1386
+ refreshRemoteState();
1387
+ }, []);
1388
+ return /* @__PURE__ */ jsxs("div", {
1389
+ "data-testid": "remote-control-settings",
1390
+ className: "flex flex-col gap-8",
1391
+ children: [/* @__PURE__ */ jsx(SettingsDescription, { children: "You turn access on and pair devices from the remote access dialog; this page holds what stays the same between visits." }), state.view === void 0 && state.error ? /* @__PURE__ */ jsx(SettingsCard, { children: /* @__PURE__ */ jsxs(SettingsRow, {
1392
+ title: state.error,
1393
+ children: [/* @__PURE__ */ jsxs(SettingsRowText, {
1394
+ role: "alert",
1395
+ children: [/* @__PURE__ */ jsx(SettingsRowTitle, { children: "Po couldn't read your remote settings just now" }), /* @__PURE__ */ jsx(SettingsRowDescription, { children: "Nothing has changed. Remote access is as you left it." })]
1396
+ }), /* @__PURE__ */ jsx(Button, {
1397
+ variant: "outline",
1398
+ size: "sm",
1399
+ onClick: () => void refreshRemoteState(),
1400
+ children: "Try again"
1401
+ })]
1402
+ }) }) : state.view === void 0 ? /* @__PURE__ */ jsxs(SettingsCard, {
1403
+ role: "status",
1404
+ "aria-busy": true,
1405
+ className: "gap-4 p-5",
1406
+ children: [
1407
+ /* @__PURE__ */ jsx("span", {
1408
+ className: "sr-only",
1409
+ children: "Reading remote settings"
1410
+ }),
1411
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-48" }),
1412
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-72" })
1413
+ ]
1414
+ }) : /* @__PURE__ */ jsx(TunnelSettings, { tunnel: state.view.settings.tunnel })]
1415
+ });
1416
+ }
1417
+ //#endregion
1418
+ //#region src/extensions/(frontend)/setting/remote.panel.web.tsx
1419
+ /** Remote control configures Po itself, so it lists with the host's own pages. */
1420
+ var remote_panel_web_default = defineSettingsPanel({
1421
+ label: "Remote control",
1422
+ detail: "Reach this Po from your phone or another computer",
1423
+ menuGroup: "general",
1424
+ component: RemoteControlSettings,
1425
+ summary: readRemoteSummary
1426
+ });
1427
+ //#endregion
1428
+ //#region generated/web.ts
1429
+ const via = (identity, value) => value === void 0 ? void 0 : {
1430
+ ...identity,
1431
+ ...value
1432
+ };
1433
+ const webPlugin = defineWebPlugin({
1434
+ id: "remote",
1435
+ packageName: "@agimon-ai/po-remote",
1436
+ host: {
1437
+ get fills() {
1438
+ return [
1439
+ via({
1440
+ slot: "overlay",
1441
+ id: "pairing-approval"
1442
+ }, PairingApproval_overlay_web_default),
1443
+ via({
1444
+ slot: "rail-status",
1445
+ id: "remote"
1446
+ }, Remote_rail_status_web_default),
1447
+ via({
1448
+ slot: "overlay",
1449
+ id: "remote-access"
1450
+ }, RemoteAccess_overlay_web_default)
1451
+ ];
1452
+ },
1453
+ get settingsPanels() {
1454
+ return [via({ id: "remote" }, remote_panel_web_default)];
1455
+ },
1456
+ get start() {
1457
+ return start_web_default;
1458
+ }
1459
+ }
1460
+ });
1461
+ //#endregion
1462
+ export { webPlugin };
1463
+
1464
+ //# sourceMappingURL=web.mjs.map