pi-web-ui 0.114.1 → 0.114.3

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.
Files changed (130) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/README.md +187 -187
  3. package/README.zh-CN.md +227 -227
  4. package/README.zh-TW.md +227 -227
  5. package/bin/device-hub-cli.mjs +577 -577
  6. package/bin/frp-manager.mjs +1573 -1573
  7. package/bin/pi-device-hub.mjs +9 -9
  8. package/bin/pi-web-ui.mjs +4081 -4081
  9. package/deploy/nginx-subpath.conf +100 -100
  10. package/deploy/pi-web-ui.service +36 -36
  11. package/dist/server/agent-service.js +88 -15
  12. package/dist/server/attachments.js +6 -6
  13. package/dist/server/canvas/canvas-orchestrator.js +3 -3
  14. package/dist/server/communicate-tool.js +37 -11
  15. package/dist/server/compaction-instructions.js +8 -8
  16. package/dist/server/context-usage.js +105 -0
  17. package/dist/server/device-center/desktop-page.js +228 -228
  18. package/dist/server/device-center/hub-page.js +64 -64
  19. package/dist/server/device-center/native-desktop/macos.js +190 -190
  20. package/dist/server/device-center/native-desktop/windows.js +116 -116
  21. package/dist/server/dsh/runtime/cordis.yml +1 -1
  22. package/dist/server/dsh/runtime/custom-prompt.mjs +33 -33
  23. package/dist/server/dsh/runtime/goal-rpc.mjs +1309 -1309
  24. package/dist/server/dsh/runtime/launcher.mjs +235 -235
  25. package/dist/server/dsh/runtime/override.patch.yml +89 -89
  26. package/dist/server/dsh/runtime/runtime-root.mjs +405 -405
  27. package/dist/server/durable/durable-event-projector.js +19 -3
  28. package/dist/server/durable/durable-models.js +134 -65
  29. package/dist/server/eval-tool.js +135 -135
  30. package/dist/server/model-resolver.js +4 -1
  31. package/dist/server/patch-bash-process.js +89 -89
  32. package/dist/server/patch-tool.js +9 -9
  33. package/dist/server/patch-turn-end-boundary.js +3 -3
  34. package/dist/server/persona-chain.js +8 -8
  35. package/dist/server/protocol-version.js +1 -1
  36. package/dist/server/remote-ssh-service.js +39 -39
  37. package/dist/server/schedule-agent-tool.js +11 -6
  38. package/dist/server/scheduler-tasks.js +84 -2
  39. package/dist/server/scm-commitmsg.js +10 -10
  40. package/dist/server/setup-page.js +620 -620
  41. package/dist/server/universal/universal-session.js +19 -18
  42. package/dist/server/vision-bridge.js +18 -18
  43. package/docs/device-center.md +148 -148
  44. package/docs/device-desktop.md +48 -48
  45. package/docs/dsh-engine.md +493 -493
  46. package/extensions/webui.ts +335 -335
  47. package/package.json +1 -1
  48. package/plugin-sdk/README.md +174 -174
  49. package/plugin-sdk/client-utils.mjs +279 -279
  50. package/plugin-sdk/import-check.mjs +210 -210
  51. package/plugin-sdk/index.d.ts +698 -698
  52. package/plugin-sdk/index.mjs +696 -696
  53. package/plugin-sdk/package.json +13 -13
  54. package/plugin-sdk/ssh-host-trust.mjs +225 -225
  55. package/themes/aetheris.css +501 -501
  56. package/themes/ayu-light.css +116 -116
  57. package/themes/bases/flow-base.css +1357 -1357
  58. package/themes/bases/obsidian-base.css +895 -895
  59. package/themes/bases/statusbar-flat-base.css +112 -112
  60. package/themes/bases/zhujian-base.css +688 -688
  61. package/themes/bases/zhupi-base.css +660 -660
  62. package/themes/catppuccin-latte.css +119 -119
  63. package/themes/catppuccin.css +116 -116
  64. package/themes/claude-code-dark.css +147 -147
  65. package/themes/codex.css +114 -114
  66. package/themes/cyberpunk.css +50 -50
  67. package/themes/dark-teal.css +264 -264
  68. package/themes/dazzle.css +38 -38
  69. package/themes/everforest-light.css +115 -115
  70. package/themes/flow-light.css +164 -164
  71. package/themes/flow.css +161 -161
  72. package/themes/geist.css +114 -114
  73. package/themes/gruvbox-light.css +115 -115
  74. package/themes/kanagawa-lotus.css +115 -115
  75. package/themes/md-preview.css +24 -24
  76. package/themes/mist.css +166 -166
  77. package/themes/nord.css +107 -107
  78. package/themes/one-dark.css +106 -106
  79. package/themes/paper.css +174 -174
  80. package/themes/rose-pine-dawn.css +114 -114
  81. package/themes/sakura.css +166 -166
  82. package/themes/solarized-light.css +114 -114
  83. package/themes/tokyo-night.css +115 -115
  84. package/themes/translucent.css +85 -85
  85. package/themes/transparent.css +116 -116
  86. package/themes/vs-code-dark.css +147 -147
  87. package/themes/wallpaper-flow.css +382 -382
  88. package/themes/wallpaper-obsidian.css +74 -74
  89. package/themes/white.css +164 -164
  90. package/themes/zhujian-dark.css +115 -115
  91. package/themes/zhujian.css +114 -114
  92. package/themes/zhupi-dark.css +115 -115
  93. package/themes/zhupi.css +114 -114
  94. package/web/dist/.build-assets.json +1 -1
  95. package/web/dist/assets/{BgTasksModal-BcXJ20RO.js → BgTasksModal-BvnUHjFe.js} +1 -1
  96. package/web/dist/assets/{BgTasksModal-DjQmiKnE.js → BgTasksModal-DSC8ncW3.js} +1 -1
  97. package/web/dist/assets/{CanvasStudio-PI9pid0Y.js → CanvasStudio-BSg9ghPV.js} +2 -2
  98. package/web/dist/assets/{CanvasStudio-nf5-HxLM.js → CanvasStudio-DxW7C3Sz.js} +2 -2
  99. package/web/dist/assets/{DeviceCenter-CYttJw2a.js → DeviceCenter-Bmgr-Bwm.js} +1 -1
  100. package/web/dist/assets/{DeviceCenter-DPe4sz74.js → DeviceCenter-Cl9MBXaH.js} +1 -1
  101. package/web/dist/assets/{DeviceGroups-D2rogxEN.js → DeviceGroups-aeLD2msl.js} +1 -1
  102. package/web/dist/assets/{Dropdown-ZLS04O8p.js → Dropdown-D1Jl35dw.js} +1 -1
  103. package/web/dist/assets/{FilePreview-C9Ut4Lq6.js → FilePreview-6CqoDF_P.js} +1 -1
  104. package/web/dist/assets/{FilePreview-CvK3ZzX5.js → FilePreview-CJa27G_Q.js} +1 -1
  105. package/web/dist/assets/{GlobalSearchModal-C5e-OCw2.js → GlobalSearchModal-CJX35rZL.js} +1 -1
  106. package/web/dist/assets/{GlobalSearchModal-H7pFK2UC.js → GlobalSearchModal-CMW0xz0P.js} +1 -1
  107. package/web/dist/assets/{GroupConversation-C2wNM0dQ.js → GroupConversation-Cq4daBFb.js} +1 -1
  108. package/web/dist/assets/{GroupConversation-ChN3TWQK.js → GroupConversation-DoELa83U.js} +1 -1
  109. package/web/dist/assets/{ModelConfigModal-DDZccDYt.js → ModelConfigModal-Bp7tfKYh.js} +1 -1
  110. package/web/dist/assets/{PiSetupModal-DHbqfx8T.js → PiSetupModal-DD8srwBJ.js} +1 -1
  111. package/web/dist/assets/{ProviderOAuthControls-C-MK36Dk.js → ProviderOAuthControls-C6tfXb88.js} +1 -1
  112. package/web/dist/assets/{SCMPanel-kx-SCL2s.js → SCMPanel-CghgsyBN.js} +1 -1
  113. package/web/dist/assets/{SCMPanel-buTGziDB.js → SCMPanel-D8-8aqwC.js} +1 -1
  114. package/web/dist/assets/{SettingsModal-BsUF8jqr.js → SettingsModal-BbBe2rYo.js} +1 -1
  115. package/web/dist/assets/{SettingsModal-D357Ky7P.js → SettingsModal-qETiVPKj.js} +1 -1
  116. package/web/dist/assets/{TerminalPanel-BBuM_Sez.js → TerminalPanel-Da-Xs4Wk.js} +1 -1
  117. package/web/dist/assets/{TerminalPanel-D6x6xz8Q.js → TerminalPanel-DnS4tFQO.js} +1 -1
  118. package/web/dist/assets/{TuiOverlayModal-CdbGV3Za.js → TuiOverlayModal-CGyGkKYl.js} +1 -1
  119. package/web/dist/assets/{TuiOverlayModal-d6x9u25n.js → TuiOverlayModal-CpBKjG6x.js} +1 -1
  120. package/web/dist/assets/{desktop-YguLbrX1.js → desktop-7EvUHhKQ.js} +1 -1
  121. package/web/dist/assets/{fi-DaSO0Q-m.js → fi-NyN-ZrgD.js} +2 -2
  122. package/web/dist/assets/{index-D6u8xH0o.js → index-DK3F5ZJo.js} +50 -50
  123. package/web/dist/assets/{index-BPvpea8t.js → index-DQMii2he.js} +50 -50
  124. package/web/dist/assets/index-vwBnwzkr.css +1 -0
  125. package/web/dist/assets/{plugin-host-BRBg6zmQ.js → plugin-host-BCnX3P8U.js} +1 -1
  126. package/web/dist/assets/{theme-DDl-Oy1b.js → theme-D2DMH6tH.js} +1 -1
  127. package/web/dist/index.html +35 -35
  128. package/web/dist/sw.js +179 -179
  129. package/web/public/sw.js +179 -179
  130. package/web/dist/assets/index-DDZMv6LO.css +0 -1
package/web/public/sw.js CHANGED
@@ -1,179 +1,179 @@
1
- /**
2
- * pi-web-ui — Progressive Web App service worker.
3
- *
4
- * Strategy overview
5
- * -----------------
6
- * pi-web-ui is a WebSocket-first app that needs a live backend, so we do NOT
7
- * try to make it fully offline. Instead the SW focuses on what makes it a
8
- * reliable *installable* PWA on mobile/desktop:
9
- *
10
- * - network-first for navigation requests (falls back to the cached app
11
- * shell when the network flaps), and
12
- * - cache-first for hashed static assets, which Vite fingerprints so a cache
13
- * hit is always the right version until a new deploy publishes new hashes.
14
- *
15
- * It also owns notification clicks (`notificationclick`): the desktop / OS
16
- * notifications posted from the page carry the page URL in `data.url`, and a
17
- * click must bring the app back — on Windows (and Linux) the click handler is
18
- * the only thing that can do that, otherwise the toast just disappears.
19
- *
20
- * Real-time / dynamic / credential-bearing routes (/ws, /api, /themes,
21
- * /plugins) are always fetched from the network and never cached, so we never
22
- * risk serving stale theme/plugin code or caching anything sensitive.
23
- */
24
-
25
- const BUILD_ID = "__BUILD_ID__";
26
- const STATIC_CACHE = BUILD_ID.startsWith("__") ? "pi-web-ui-static-dev" : `pi-web-ui-static-${BUILD_ID}`;
27
- const SHELL_CACHE = "pi-web-ui-shell-v1";
28
-
29
- // App root within this origin — "/" for root deployments, "/pi/" behind an
30
- // nginx sub-path reverse proxy. All path checks below are relative to it, so
31
- // the worker behaves identically under either deployment layout.
32
- const SCOPE = new URL("./", self.registration.scope).pathname;
33
-
34
- /** Map a request pathname to an app-relative path ("/pi/ws" → "/ws"), or null
35
- * when the request lies outside the registration scope (shouldn't happen). */
36
- function appPath(pathname) {
37
- if (SCOPE === "/") return pathname;
38
- if (pathname.startsWith(SCOPE)) return "/" + pathname.slice(SCOPE.length);
39
- return null;
40
- }
41
-
42
- self.addEventListener("install", (event) => {
43
- // Take control as soon as this version activates so the current page is
44
- // served by the new worker without requiring a second reload.
45
- self.skipWaiting();
46
- event.waitUntil(caches.open(SHELL_CACHE));
47
- });
48
-
49
- self.addEventListener("activate", (event) => {
50
- event.waitUntil(
51
- caches
52
- .keys()
53
- .then((keys) =>
54
- Promise.all(keys.filter((k) => k !== STATIC_CACHE && k !== SHELL_CACHE).map((k) => caches.delete(k))),
55
- )
56
- // Apply to already-open pages immediately.
57
- .then(() => self.clients.claim()),
58
- );
59
- });
60
-
61
- // Only cache simple, safe GET requests. Everything else goes straight through.
62
- function isCachable(request) {
63
- const method = request.method;
64
- if (method !== "GET") return false;
65
-
66
- const url = new URL(request.url);
67
- if (url.origin !== self.location.origin) return false;
68
-
69
- // Never cache real-time, dynamic or credential/data endpoints.
70
- const path = appPath(url.pathname);
71
- if (
72
- path === null ||
73
- path.startsWith("/ws") ||
74
- path.startsWith("/api") ||
75
- path.startsWith("/themes") ||
76
- path.startsWith("/plugins")
77
- ) {
78
- return false;
79
- }
80
- return true;
81
- }
82
-
83
- function assetContentOk(requestUrl, response) {
84
- const ct = (response.headers.get("content-type") || "").toLowerCase();
85
- const path = requestUrl.pathname.toLowerCase();
86
- if (path.endsWith(".js")) return ct.includes("javascript");
87
- if (path.endsWith(".css")) return ct.includes("css");
88
- if (path.endsWith(".svg")) return ct.includes("svg");
89
- if (path.endsWith(".webmanifest")) return ct.includes("json");
90
- return true;
91
- }
92
-
93
- self.addEventListener("fetch", (event) => {
94
- const { request } = event;
95
- if (!isCachable(request)) {
96
- // Let the browser/backend handle WebSockets, API calls and cross-origin
97
- // requests normally.
98
- return;
99
- }
100
-
101
- const requestUrl = new URL(request.url);
102
-
103
- // Navigation → app shell. Network-first with cached fallback: users get the
104
- // latest build when online but can still reopen the app while flaky.
105
- if (request.mode === "navigate") {
106
- event.respondWith(
107
- fetch(request)
108
- .then((response) => {
109
- const copy = response.clone();
110
- caches.open(SHELL_CACHE).then((cache) => cache.put(request, copy));
111
- return response;
112
- })
113
- .catch(() => caches.match(request).then((cached) => cached || caches.match(SCOPE) || Response.error())),
114
- );
115
- return;
116
- }
117
-
118
- // Static assets (hashed by Vite) → cache-first.
119
- const path = appPath(requestUrl.pathname);
120
- const isStatic =
121
- path !== null &&
122
- (path.startsWith("/assets/") ||
123
- path.startsWith("/icons/") ||
124
- path === "/favicon.svg" ||
125
- path === "/icon.ico" ||
126
- path === "/manifest.webmanifest");
127
-
128
- if (isStatic) {
129
- event.respondWith(
130
- caches.match(request).then((cached) => {
131
- if (cached) return cached;
132
- return fetch(request)
133
- .then((response) => {
134
- // Only cache bytes matching the extension: a missing file falls
135
- // through to the SPA catch-all (index.html, 200) and must never be
136
- // stored under an asset URL, or the page stays black until purged.
137
- if (response && response.ok && assetContentOk(requestUrl, response)) {
138
- const copy = response.clone();
139
- caches.open(STATIC_CACHE).then((cache) => cache.put(request, copy));
140
- }
141
- return response;
142
- })
143
- .catch(() => caches.match(request).then((fallback) => fallback || Response.error()));
144
- }),
145
- );
146
- }
147
- });
148
-
149
- // ---------------------------------------------------------------------------
150
- // Notification clicks.
151
- //
152
- // The page posts desktop / OS notifications (see web/src/notify.ts) with
153
- // `data.url` = the URL that raised them. A click must bring the app back:
154
- // on Windows (and Linux) this handler is the only thing that can do that —
155
- // the toast would otherwise just disappear, which is why "nothing happens when
156
- // I click the reminder" is a platform-level dead end rather than a UI bug.
157
- // Focus the window that is already open (a tab or the installed PWA — a
158
- // minimised window still counts as open) and only open a new one when none
159
- // exists. Windows never restores a window for us, so we match on URL first so
160
- // the session that raised the notification is the one that comes forward.
161
- self.addEventListener("notificationclick", (event) => {
162
- event.notification.close();
163
- const target = (event.notification.data && event.notification.data.url) || new URL(SCOPE, self.location.origin).href;
164
-
165
- event.waitUntil(
166
- self.clients
167
- .matchAll({ type: "window", includeUncontrolled: true })
168
- .then((clients) => {
169
- const inScope = clients.filter((client) => appPath(new URL(client.url).pathname) !== null);
170
- const match = inScope.find((client) => client.url === target) || inScope[0];
171
- // focus() rejects when the browser refuses to raise the window
172
- // (rare); fall back to just returning the client so the click
173
- // never logs an unhandled rejection.
174
- if (match) return match.focus ? match.focus().catch(() => match) : match;
175
- return self.clients.openWindow(target);
176
- })
177
- .catch(() => undefined),
178
- );
179
- });
1
+ /**
2
+ * pi-web-ui — Progressive Web App service worker.
3
+ *
4
+ * Strategy overview
5
+ * -----------------
6
+ * pi-web-ui is a WebSocket-first app that needs a live backend, so we do NOT
7
+ * try to make it fully offline. Instead the SW focuses on what makes it a
8
+ * reliable *installable* PWA on mobile/desktop:
9
+ *
10
+ * - network-first for navigation requests (falls back to the cached app
11
+ * shell when the network flaps), and
12
+ * - cache-first for hashed static assets, which Vite fingerprints so a cache
13
+ * hit is always the right version until a new deploy publishes new hashes.
14
+ *
15
+ * It also owns notification clicks (`notificationclick`): the desktop / OS
16
+ * notifications posted from the page carry the page URL in `data.url`, and a
17
+ * click must bring the app back — on Windows (and Linux) the click handler is
18
+ * the only thing that can do that, otherwise the toast just disappears.
19
+ *
20
+ * Real-time / dynamic / credential-bearing routes (/ws, /api, /themes,
21
+ * /plugins) are always fetched from the network and never cached, so we never
22
+ * risk serving stale theme/plugin code or caching anything sensitive.
23
+ */
24
+
25
+ const BUILD_ID = "__BUILD_ID__";
26
+ const STATIC_CACHE = BUILD_ID.startsWith("__") ? "pi-web-ui-static-dev" : `pi-web-ui-static-${BUILD_ID}`;
27
+ const SHELL_CACHE = "pi-web-ui-shell-v1";
28
+
29
+ // App root within this origin — "/" for root deployments, "/pi/" behind an
30
+ // nginx sub-path reverse proxy. All path checks below are relative to it, so
31
+ // the worker behaves identically under either deployment layout.
32
+ const SCOPE = new URL("./", self.registration.scope).pathname;
33
+
34
+ /** Map a request pathname to an app-relative path ("/pi/ws" → "/ws"), or null
35
+ * when the request lies outside the registration scope (shouldn't happen). */
36
+ function appPath(pathname) {
37
+ if (SCOPE === "/") return pathname;
38
+ if (pathname.startsWith(SCOPE)) return "/" + pathname.slice(SCOPE.length);
39
+ return null;
40
+ }
41
+
42
+ self.addEventListener("install", (event) => {
43
+ // Take control as soon as this version activates so the current page is
44
+ // served by the new worker without requiring a second reload.
45
+ self.skipWaiting();
46
+ event.waitUntil(caches.open(SHELL_CACHE));
47
+ });
48
+
49
+ self.addEventListener("activate", (event) => {
50
+ event.waitUntil(
51
+ caches
52
+ .keys()
53
+ .then((keys) =>
54
+ Promise.all(keys.filter((k) => k !== STATIC_CACHE && k !== SHELL_CACHE).map((k) => caches.delete(k))),
55
+ )
56
+ // Apply to already-open pages immediately.
57
+ .then(() => self.clients.claim()),
58
+ );
59
+ });
60
+
61
+ // Only cache simple, safe GET requests. Everything else goes straight through.
62
+ function isCachable(request) {
63
+ const method = request.method;
64
+ if (method !== "GET") return false;
65
+
66
+ const url = new URL(request.url);
67
+ if (url.origin !== self.location.origin) return false;
68
+
69
+ // Never cache real-time, dynamic or credential/data endpoints.
70
+ const path = appPath(url.pathname);
71
+ if (
72
+ path === null ||
73
+ path.startsWith("/ws") ||
74
+ path.startsWith("/api") ||
75
+ path.startsWith("/themes") ||
76
+ path.startsWith("/plugins")
77
+ ) {
78
+ return false;
79
+ }
80
+ return true;
81
+ }
82
+
83
+ function assetContentOk(requestUrl, response) {
84
+ const ct = (response.headers.get("content-type") || "").toLowerCase();
85
+ const path = requestUrl.pathname.toLowerCase();
86
+ if (path.endsWith(".js")) return ct.includes("javascript");
87
+ if (path.endsWith(".css")) return ct.includes("css");
88
+ if (path.endsWith(".svg")) return ct.includes("svg");
89
+ if (path.endsWith(".webmanifest")) return ct.includes("json");
90
+ return true;
91
+ }
92
+
93
+ self.addEventListener("fetch", (event) => {
94
+ const { request } = event;
95
+ if (!isCachable(request)) {
96
+ // Let the browser/backend handle WebSockets, API calls and cross-origin
97
+ // requests normally.
98
+ return;
99
+ }
100
+
101
+ const requestUrl = new URL(request.url);
102
+
103
+ // Navigation → app shell. Network-first with cached fallback: users get the
104
+ // latest build when online but can still reopen the app while flaky.
105
+ if (request.mode === "navigate") {
106
+ event.respondWith(
107
+ fetch(request)
108
+ .then((response) => {
109
+ const copy = response.clone();
110
+ caches.open(SHELL_CACHE).then((cache) => cache.put(request, copy));
111
+ return response;
112
+ })
113
+ .catch(() => caches.match(request).then((cached) => cached || caches.match(SCOPE) || Response.error())),
114
+ );
115
+ return;
116
+ }
117
+
118
+ // Static assets (hashed by Vite) → cache-first.
119
+ const path = appPath(requestUrl.pathname);
120
+ const isStatic =
121
+ path !== null &&
122
+ (path.startsWith("/assets/") ||
123
+ path.startsWith("/icons/") ||
124
+ path === "/favicon.svg" ||
125
+ path === "/icon.ico" ||
126
+ path === "/manifest.webmanifest");
127
+
128
+ if (isStatic) {
129
+ event.respondWith(
130
+ caches.match(request).then((cached) => {
131
+ if (cached) return cached;
132
+ return fetch(request)
133
+ .then((response) => {
134
+ // Only cache bytes matching the extension: a missing file falls
135
+ // through to the SPA catch-all (index.html, 200) and must never be
136
+ // stored under an asset URL, or the page stays black until purged.
137
+ if (response && response.ok && assetContentOk(requestUrl, response)) {
138
+ const copy = response.clone();
139
+ caches.open(STATIC_CACHE).then((cache) => cache.put(request, copy));
140
+ }
141
+ return response;
142
+ })
143
+ .catch(() => caches.match(request).then((fallback) => fallback || Response.error()));
144
+ }),
145
+ );
146
+ }
147
+ });
148
+
149
+ // ---------------------------------------------------------------------------
150
+ // Notification clicks.
151
+ //
152
+ // The page posts desktop / OS notifications (see web/src/notify.ts) with
153
+ // `data.url` = the URL that raised them. A click must bring the app back:
154
+ // on Windows (and Linux) this handler is the only thing that can do that —
155
+ // the toast would otherwise just disappear, which is why "nothing happens when
156
+ // I click the reminder" is a platform-level dead end rather than a UI bug.
157
+ // Focus the window that is already open (a tab or the installed PWA — a
158
+ // minimised window still counts as open) and only open a new one when none
159
+ // exists. Windows never restores a window for us, so we match on URL first so
160
+ // the session that raised the notification is the one that comes forward.
161
+ self.addEventListener("notificationclick", (event) => {
162
+ event.notification.close();
163
+ const target = (event.notification.data && event.notification.data.url) || new URL(SCOPE, self.location.origin).href;
164
+
165
+ event.waitUntil(
166
+ self.clients
167
+ .matchAll({ type: "window", includeUncontrolled: true })
168
+ .then((clients) => {
169
+ const inScope = clients.filter((client) => appPath(new URL(client.url).pathname) !== null);
170
+ const match = inScope.find((client) => client.url === target) || inScope[0];
171
+ // focus() rejects when the browser refuses to raise the window
172
+ // (rare); fall back to just returning the client so the click
173
+ // never logs an unhandled rejection.
174
+ if (match) return match.focus ? match.focus().catch(() => match) : match;
175
+ return self.clients.openWindow(target);
176
+ })
177
+ .catch(() => undefined),
178
+ );
179
+ });