pi-web-ui 0.114.0 → 0.114.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.
Files changed (195) hide show
  1. package/CHANGELOG.md +28 -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 -4073
  9. package/deploy/nginx-subpath.conf +100 -100
  10. package/deploy/pi-web-ui.service +36 -36
  11. package/dist/server/agent-service.js +131 -55
  12. package/dist/server/attachments.js +51 -5
  13. package/dist/server/canvas/canvas-agent-tool.js +3 -3
  14. package/dist/server/canvas/canvas-cards.js +1 -1
  15. package/dist/server/canvas/canvas-orchestrator.js +3 -3
  16. package/dist/server/canvas/canvas-scheduled-task.js +45 -0
  17. package/dist/server/canvas/canvas-validation.js +1 -1
  18. package/dist/server/client-state.js +6 -2
  19. package/dist/server/compaction-instructions.js +8 -8
  20. package/dist/server/device-center/connector.js +33 -14
  21. package/dist/server/device-center/desktop-page.js +228 -228
  22. package/dist/server/device-center/hub-page.js +64 -64
  23. package/dist/server/device-center/hub.js +2 -1
  24. package/dist/server/device-center/local-hub.js +92 -0
  25. package/dist/server/device-center/local.js +60 -7
  26. package/dist/server/device-center/native-desktop/macos.js +190 -190
  27. package/dist/server/device-center/native-desktop/windows.js +116 -116
  28. package/dist/server/device-center/path-portal.js +1 -1
  29. package/dist/server/device-center/relay.js +45 -8
  30. package/dist/server/dispatch-domain-handlers.js +1 -0
  31. package/dist/server/dsh/dsh-agent-service.js +5 -1
  32. package/dist/server/dsh/runtime/cordis.yml +1 -1
  33. package/dist/server/dsh/runtime/custom-prompt.mjs +33 -33
  34. package/dist/server/dsh/runtime/goal-rpc.mjs +1309 -1309
  35. package/dist/server/dsh/runtime/launcher.mjs +235 -235
  36. package/dist/server/dsh/runtime/override.patch.yml +89 -89
  37. package/dist/server/dsh/runtime/runtime-root.mjs +405 -405
  38. package/dist/server/engine-probe.js +36 -6
  39. package/dist/server/eval-tool.js +135 -135
  40. package/dist/server/global-loader.js +40 -2
  41. package/dist/server/index.js +56 -32
  42. package/dist/server/patch-bash-process.js +125 -0
  43. package/dist/server/patch-tool.js +9 -9
  44. package/dist/server/patch-turn-end-boundary.js +3 -3
  45. package/dist/server/persona-chain.js +8 -8
  46. package/dist/server/plugins.js +26 -2
  47. package/dist/server/preset-fields.js +7 -0
  48. package/dist/server/preset-share.js +1 -0
  49. package/dist/server/prompt-templates.js +106 -0
  50. package/dist/server/protocol-version.js +1 -1
  51. package/dist/server/remote-ssh-service.js +39 -39
  52. package/dist/server/resolve-global-sdk.js +2 -0
  53. package/dist/server/schedule-agent-tool.js +39 -21
  54. package/dist/server/scheduler-tasks.js +45 -9
  55. package/dist/server/scm-commitmsg.js +10 -10
  56. package/dist/server/settings-service.js +6 -0
  57. package/dist/server/setup-page.js +620 -620
  58. package/dist/server/text-quote.js +9 -0
  59. package/dist/server/tool-manager.js +2 -1
  60. package/dist/server/universal/drivers/claude-code.js +5 -0
  61. package/dist/server/universal/drivers/codex.js +336 -0
  62. package/dist/server/universal/index.js +1 -0
  63. package/dist/server/universal/universal-attachments.js +24 -1
  64. package/dist/server/universal/universal-session.js +23 -0
  65. package/dist/server/vision-bridge.js +18 -18
  66. package/docs/device-center.md +148 -142
  67. package/docs/device-desktop.md +48 -48
  68. package/docs/dsh-engine.md +493 -493
  69. package/extensions/webui.ts +335 -335
  70. package/package.json +2 -2
  71. package/plugin-sdk/README.md +174 -174
  72. package/plugin-sdk/client-utils.mjs +279 -279
  73. package/plugin-sdk/import-check.mjs +210 -210
  74. package/plugin-sdk/index.d.ts +698 -698
  75. package/plugin-sdk/index.mjs +696 -696
  76. package/plugin-sdk/package.json +13 -13
  77. package/plugin-sdk/ssh-host-trust.mjs +225 -225
  78. package/plugins/catalog.json +10 -0
  79. package/themes/aetheris.css +501 -501
  80. package/themes/ayu-light.css +116 -116
  81. package/themes/bases/flow-base.css +1357 -1357
  82. package/themes/bases/obsidian-base.css +895 -895
  83. package/themes/bases/statusbar-flat-base.css +112 -112
  84. package/themes/bases/zhujian-base.css +688 -688
  85. package/themes/bases/zhupi-base.css +660 -660
  86. package/themes/catppuccin-latte.css +119 -119
  87. package/themes/catppuccin.css +116 -116
  88. package/themes/claude-code-dark.css +147 -147
  89. package/themes/codex.css +114 -114
  90. package/themes/cyberpunk.css +50 -50
  91. package/themes/dark-teal.css +264 -264
  92. package/themes/dazzle.css +38 -38
  93. package/themes/everforest-light.css +115 -115
  94. package/themes/flow-light.css +164 -164
  95. package/themes/flow.css +161 -161
  96. package/themes/geist.css +114 -114
  97. package/themes/gruvbox-light.css +115 -115
  98. package/themes/kanagawa-lotus.css +115 -115
  99. package/themes/md-preview.css +24 -24
  100. package/themes/mist.css +166 -166
  101. package/themes/nord.css +107 -107
  102. package/themes/one-dark.css +106 -106
  103. package/themes/paper.css +174 -174
  104. package/themes/rose-pine-dawn.css +114 -114
  105. package/themes/sakura.css +166 -166
  106. package/themes/solarized-light.css +114 -114
  107. package/themes/tokyo-night.css +115 -115
  108. package/themes/translucent.css +85 -85
  109. package/themes/transparent.css +116 -116
  110. package/themes/vs-code-dark.css +147 -147
  111. package/themes/wallpaper-flow.css +382 -382
  112. package/themes/wallpaper-obsidian.css +74 -74
  113. package/themes/white.css +164 -164
  114. package/themes/zhujian-dark.css +115 -115
  115. package/themes/zhujian.css +114 -114
  116. package/themes/zhupi-dark.css +115 -115
  117. package/themes/zhupi.css +114 -114
  118. package/web/dist/.build-assets.json +1 -1
  119. package/web/dist/assets/BgTasksModal-BcXJ20RO.js +1 -0
  120. package/web/dist/assets/BgTasksModal-DjQmiKnE.js +1 -0
  121. package/web/dist/assets/{CanvasStudio-BEJZE5BI.js → CanvasStudio-PI9pid0Y.js} +3 -3
  122. package/web/dist/assets/{CanvasStudio-CgUNHqos.js → CanvasStudio-nf5-HxLM.js} +3 -3
  123. package/web/dist/assets/DeviceCenter-CYttJw2a.js +3 -0
  124. package/web/dist/assets/DeviceCenter-DPe4sz74.js +3 -0
  125. package/web/dist/assets/DeviceGroups-D2rogxEN.js +1 -0
  126. package/web/dist/assets/Dropdown-ZLS04O8p.js +1 -0
  127. package/web/dist/assets/FilePreview-C9Ut4Lq6.js +2 -0
  128. package/web/dist/assets/FilePreview-CvK3ZzX5.js +2 -0
  129. package/web/dist/assets/GlobalSearchModal-C5e-OCw2.js +1 -0
  130. package/web/dist/assets/GlobalSearchModal-H7pFK2UC.js +1 -0
  131. package/web/dist/assets/GroupConversation-C2wNM0dQ.js +1 -0
  132. package/web/dist/assets/GroupConversation-ChN3TWQK.js +1 -0
  133. package/web/dist/assets/ModelConfigModal-DDZccDYt.js +2 -0
  134. package/web/dist/assets/PiSetupModal-DHbqfx8T.js +1 -0
  135. package/web/dist/assets/ProviderOAuthControls-C-MK36Dk.js +1 -0
  136. package/web/dist/assets/SCMPanel-buTGziDB.js +2 -0
  137. package/web/dist/assets/SCMPanel-kx-SCL2s.js +2 -0
  138. package/web/dist/assets/SettingsModal-BsUF8jqr.js +20 -0
  139. package/web/dist/assets/SettingsModal-D357Ky7P.js +20 -0
  140. package/web/dist/assets/{TerminalPanel-DL20uKgU.js → TerminalPanel-BBuM_Sez.js} +2 -2
  141. package/web/dist/assets/{TerminalPanel-D6cPRFei.js → TerminalPanel-D6x6xz8Q.js} +2 -2
  142. package/web/dist/assets/TuiOverlayModal-CdbGV3Za.js +1 -0
  143. package/web/dist/assets/TuiOverlayModal-d6x9u25n.js +1 -0
  144. package/web/dist/assets/app-globals-DcyO0UPi.js +1 -0
  145. package/web/dist/assets/{desktop-DPyTy4M3.js → desktop-YguLbrX1.js} +1 -1
  146. package/web/dist/assets/fi-DaSO0Q-m.js +325 -0
  147. package/web/dist/assets/index-BPvpea8t.js +85 -0
  148. package/web/dist/assets/index-D6u8xH0o.js +85 -0
  149. package/web/dist/assets/index-DDZMv6LO.css +1 -0
  150. package/web/dist/assets/{plugin-host-CqA4yW6w.js → plugin-host-BRBg6zmQ.js} +1 -1
  151. package/web/dist/assets/theme-DDl-Oy1b.js +1 -0
  152. package/web/dist/index.html +37 -36
  153. package/web/dist/sw.js +179 -179
  154. package/web/public/sw.js +179 -179
  155. package/dist/gh-comment-781.md +0 -5
  156. package/dist/server/device-center/local-page.js +0 -17
  157. package/dist/server/device-center/smoke-preview.js +0 -3
  158. package/dist/server/durable/durable-capabilities.js +0 -11
  159. package/dist/server/markers/builtins/services.js +0 -123
  160. package/dist/server/markers/builtins/todo.js +0 -189
  161. package/dist/server/markers-list-tool.js +0 -34
  162. package/dist/server/orchestrator.js +0 -109
  163. package/dist/server/system-prompt-soul.js +0 -41
  164. package/dist/server/univer-service.js +0 -448
  165. package/dist/server/universal/drivers/dsh-driver.js +0 -379
  166. package/dist/test-artifact.md +0 -9
  167. package/dist/test-preview-modal.md +0 -11
  168. package/dist/test-report.html +0 -20
  169. package/web/dist/assets/BgTasksModal-CS7UNzcw.js +0 -1
  170. package/web/dist/assets/BgTasksModal-Dk-tp78W.js +0 -1
  171. package/web/dist/assets/DeviceCenter-C8_CbxQ3.js +0 -3
  172. package/web/dist/assets/DeviceCenter-CVblvhNX.js +0 -3
  173. package/web/dist/assets/Dropdown-Oug0DDte.js +0 -1
  174. package/web/dist/assets/FilePreview-CvdX6nr6.js +0 -2
  175. package/web/dist/assets/FilePreview-kCZhfBAF.js +0 -2
  176. package/web/dist/assets/GlobalSearchModal-BLH63yYP.js +0 -1
  177. package/web/dist/assets/GlobalSearchModal-DAkvlvp6.js +0 -1
  178. package/web/dist/assets/GroupConversation-Cgo4xbpa.js +0 -1
  179. package/web/dist/assets/GroupConversation-DZ71jEi8.js +0 -1
  180. package/web/dist/assets/ModelConfigModal-BpWdFdQC.js +0 -2
  181. package/web/dist/assets/PiSetupModal-mkWPSxMj.js +0 -1
  182. package/web/dist/assets/ProviderOAuthControls-VK_jqXYS.js +0 -1
  183. package/web/dist/assets/SCMPanel-BP1TUT-V.js +0 -2
  184. package/web/dist/assets/SCMPanel-BscPm9kf.js +0 -2
  185. package/web/dist/assets/SettingsModal-C8UgMjVM.js +0 -20
  186. package/web/dist/assets/SettingsModal-VynB7jNb.js +0 -20
  187. package/web/dist/assets/TuiOverlayModal-Dst3BmT8.js +0 -1
  188. package/web/dist/assets/TuiOverlayModal-NCkpNtTp.js +0 -1
  189. package/web/dist/assets/UniversalPathPicker-CfQFc_c3.js +0 -1
  190. package/web/dist/assets/UniversalPathPicker-DwxwNcFw.js +0 -1
  191. package/web/dist/assets/app-globals-CnO6KlEM.js +0 -325
  192. package/web/dist/assets/index-CPgAH5q7.js +0 -83
  193. package/web/dist/assets/index-Cje8iugL.js +0 -83
  194. package/web/dist/assets/index-DnKeiDbj.css +0 -1
  195. package/web/dist/assets/theme-BqdAjEjF.js +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
+ });
@@ -1,5 +0,0 @@
1
- 已在 commit 9e04e099 中彻底修复并闭环:
2
-
3
- 1. **Markdown 链接与图片拦截转写**:在 `web/src/components/Markdown.tsx` 中拦截相对路径(如 `output/summary.md`)和绝对路径,自动转换为受鉴权保护的工作区直链(HTML 文件走 `/api/preview` 沙箱隔离预览,其他文件走 `/api/file` 原生打开/流式播放);
4
- 2. **服务端直开权限完善**:更新 `server/index.ts` 放行合法工作区文本/数据文件(配合 `nosniff` 与沙箱),不再返回 400 阻断;
5
- 3. **适配远程访问**:`present_files` 探测到远程访问时,自动将本地窗口唤醒按钮替换为新标签页打开。
@@ -1,17 +0,0 @@
1
- export function renderLocalDevicePage() {
2
- return `<!doctype html><html lang="zh-CN"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>设备中心 · Device Center</title><style>
3
- :root{color-scheme:dark;--bg:#15181f;--panel:#202632;--text:#edf1f8;--muted:#b9c4d5;--line:#526078;--accent:#83b5ff;--on-accent:#10223d}*{box-sizing:border-box}body{background:var(--bg);color:var(--text);font:15px/1.6 system-ui;margin:0;padding:24px}main{max-width:760px;margin:auto;min-width:0}section{background:var(--panel);padding:20px;border:1px solid var(--line);border-radius:12px;margin:16px 0;min-width:0;max-width:100%}label{display:block;margin:12px 0}input:not([type=checkbox]){width:100%;padding:10px;background:var(--bg);color:var(--text);border:1px solid var(--line);border-radius:6px}button,a{font:inherit}button{padding:9px 15px;border:0;border-radius:6px;background:var(--accent);color:var(--on-accent);cursor:pointer;margin:5px 6px 5px 0}a{color:var(--accent)}p,pre{white-space:pre-wrap;overflow-wrap:anywhere;word-break:break-word}small{color:var(--muted)}#error{color:#ffb6b6}button:disabled{opacity:.6;cursor:wait}</style></head><body><main>
4
- <h1>设备中心 <small>Device Center</small></h1><p>绑定到你的设备中心,在群聊中用 @设备 分派跨平台任务。 / Bind this computer to your hub for remote access and group tasks.</p>
5
- <section><h2>绑定本机 / Pair this computer</h2><form id="pair"><label>设备中心地址 / Hub URL<input id="hub" type="url" placeholder="https://console.example.com" required></label><label>本机名称 / Device name<input id="name" maxlength="80" required></label><button>获取配对码 / Get code</button></form><p id="pairing"></p><a id="approve" hidden target="_blank" rel="noopener noreferrer">打开设备中心确认绑定 / Approve in hub</a></section>
6
- <section><h2>当前连接 / Connection</h2><pre id="status">加载中 / Loading…</pre><label><input id="execution" type="checkbox"> 允许群任务执行与文件同步导入 / Allow agent tasks and file imports</label><small>开启后,你的设备中心账号可向本机派发文件修改、命令和文件导入请求。智能体任务沿用本机审批,文件导入校验预览版本与覆盖清单。 / Allows agent tasks and file imports. Tasks retain local approvals; imports require a matching preview and explicit conflict overrides.</small><p><button id="save">保存执行权限 / Save permission</button><button id="disconnect">解除本机连接 / Disconnect locally</button></p><a id="open" hidden target="_blank" rel="noopener noreferrer">进入群聊与设备列表 / Open hub</a><p><small>本机断开不会删除中心设备记录;请到中心撤销设备授权。 / Local disconnect does not revoke the hub device record; revoke it in the hub.</small></p></section><p id="error" role="alert"></p><p><a href="./">返回 / Back</a></p>
7
- <script type="module">
8
- const api=new URL('./api/device-center/',location.href);const el=id=>document.getElementById(id);let generation=0;let polling=false;
9
- async function request(path,body){const response=await fetch(new URL(path,api),{method:body===undefined?'GET':'POST',headers:body===undefined?{}:{'Content-Type':'application/json'},body:body===undefined?undefined:JSON.stringify(body)});const data=await response.json();if(!response.ok)throw new Error(data.error||String(response.status));return data}
10
- function error(e){el('error').textContent=e.message||String(e)}
11
- async function status(){const s=await request('status');el('status').textContent=s.deviceId? s.name+'\\n'+s.hubUrl+'\\n'+(s.connected?'已连接 / Connected':'正在连接 / Connecting'):'未绑定 / Not paired';el('execution').checked=s.allowExecution;el('open').hidden=!s.hubUrl;if(s.hubUrl)el('open').href=s.hubUrl;el('name').value ||= s.name;if(s.hubUrl)el('hub').value ||= s.hubUrl}
12
- el('pair').onsubmit=async event=>{event.preventDefault();el('error').textContent='';const mine=++generation;try{const p=await request('pair',{hubUrl:el('hub').value,name:el('name').value});if(mine!==generation)return;el('pairing').textContent='配对码 / Code: '+p.code;el('approve').href=p.hubUrl;el('approve').hidden=false;polling=true;const poll=async()=>{if(mine!==generation)return;try{const result=await request('poll',{});if(mine!==generation)return;if(result.pending){setTimeout(poll,2000);return}polling=false;el('pairing').textContent='绑定完成 / Paired';el('approve').hidden=true;await status()}catch(e){polling=false;error(e)}};setTimeout(poll,1000)}catch(e){error(e)}};
13
- el('save').onclick=async()=>{try{await request('execution',{allowExecution:el('execution').checked});await status()}catch(e){error(e)}};
14
- el('disconnect').onclick=async()=>{if(!confirm('断开本机与设备中心的连接? / Disconnect this device?'))return;generation++;polling=false;try{await request('disconnect',{});el('pairing').textContent='';el('approve').hidden=true;await status()}catch(e){error(e)}};
15
- status().catch(error);setInterval(()=>{if(!polling)status().catch(error)},5000);
16
- </script></main></body></html>`;
17
- }
@@ -1,3 +0,0 @@
1
- // Temporary local preview runner; removed after browser validation.
2
- import { startDeviceHub } from "./main.js";
3
- await startDeviceHub({ ...process.env, PI_DEVICE_HUB_PUBLIC_URL: "http://127.0.0.1:18970", PI_DEVICE_HUB_DEVICE_DOMAIN: "devices.localhost:18970", PI_DEVICE_HUB_PORT: "18970", PI_DEVICE_HUB_DATA_DIR: process.env.TEMP + "/pi-device-hub-browser-preview", PI_DEVICE_HUB_ALLOW_REGISTRATION: "1" });
@@ -1,11 +0,0 @@
1
- /**
2
- * durable-capabilities.ts — Pi Durable 引擎的能力事实源。
3
- */
4
- import { DEFAULT_DURABLE_CAPABILITIES } from "../engine-capabilities.js";
5
- export { DEFAULT_DURABLE_CAPABILITIES };
6
- export function resolveDurableCapabilities(caps) {
7
- return {
8
- ...DEFAULT_DURABLE_CAPABILITIES,
9
- ...caps,
10
- };
11
- }
@@ -1,123 +0,0 @@
1
- /**
2
- * builtins/services.ts — 后台服务登记(复刻 pi-marker-tools)。
3
- */
4
- export const SVC_NAMESPACE = "svc";
5
- export function initServiceState() {
6
- return { services: [], nextId: 1 };
7
- }
8
- function parseId(raw) {
9
- if (raw === undefined)
10
- return null;
11
- const n = Number(raw);
12
- return Number.isInteger(n) && n > 0 ? n : null;
13
- }
14
- function toInt(raw) {
15
- if (raw === undefined || raw === "")
16
- return undefined;
17
- const n = Number(raw);
18
- return Number.isInteger(n) && n >= 0 ? n : undefined;
19
- }
20
- function findService(state, id) {
21
- return state.services.find((s) => s.id === id);
22
- }
23
- function lineOf(s) {
24
- const meta = [s.pid !== undefined ? `pid ${s.pid}` : "", s.port !== undefined ? `:${s.port}` : ""]
25
- .filter(Boolean)
26
- .join(" ");
27
- return `${s.stopped ? "[x]" : "[ ]"} #${s.id}: ${s.name}${meta ? ` (${meta})` : ""}${s.command ? ` — ${s.command}` : ""}`;
28
- }
29
- export function describeServices(state) {
30
- if (!state || state.services.length === 0)
31
- return "[svc] (空)";
32
- return state.services.map(lineOf).join("\n");
33
- }
34
- export const servicesMarker = {
35
- name: "svc",
36
- guidance: [
37
- "- 后台服务登记(todo 风格):[[svc:add:名称,pid=,port=,cmd=]] 登记;[[svc:stop:<id>]] 标记停止;[[svc:resume:<id>]] 标记运行;[[svc:remove:<id>]] 删除;[[svc:clear:]] 清空。",
38
- "- 用 bash 启动后台服务(nohup ... &、pm2 start、docker run -d 等)后,立即写 [[svc:add:...]] 登记,尽量带 pid= 和 port=;服务退出或被关闭后写 [[svc:stop:<id>]] 保持清单准确。",
39
- ],
40
- async apply(token, _ctx, _state) {
41
- const state = _state;
42
- const op = token.op;
43
- switch (op) {
44
- case "add": {
45
- const name = token.args[0]?.trim();
46
- if (!name)
47
- return { applied: false, error: "svc:add 需要一个名称参数 [[svc:add:<名称>,pid=,port=,cmd=]]" };
48
- const svc = {
49
- id: state.nextId++,
50
- name,
51
- command: token.kwargs["cmd"],
52
- pid: toInt(token.kwargs["pid"]),
53
- port: toInt(token.kwargs["port"]),
54
- startedAt: Date.now(),
55
- stopped: false,
56
- };
57
- state.services.push(svc);
58
- const meta = [svc.pid !== undefined ? `pid ${svc.pid}` : "", svc.port !== undefined ? `:${svc.port}` : ""]
59
- .filter(Boolean)
60
- .join(" ");
61
- return { applied: true, feedback: `Registered #${svc.id}: ${name}${meta ? ` (${meta})` : ""}` };
62
- }
63
- case "stop": {
64
- const id = parseId(token.args[0]);
65
- if (id === null)
66
- return { applied: false, error: `svc:stop 的 id 无效: "${token.args[0] ?? ""}"` };
67
- const svc = findService(state, id);
68
- if (!svc)
69
- return { applied: false, error: `svc:stop 服务 #${id} 不存在` };
70
- svc.stopped = true;
71
- svc.stoppedAt = Date.now();
72
- return { applied: true, feedback: `#${id} ${svc.name} marked stopped` };
73
- }
74
- case "resume": {
75
- const id = parseId(token.args[0]);
76
- if (id === null)
77
- return { applied: false, error: `svc:resume 的 id 无效: "${token.args[0] ?? ""}"` };
78
- const svc = findService(state, id);
79
- if (!svc)
80
- return { applied: false, error: `svc:resume 服务 #${id} 不存在` };
81
- svc.stopped = false;
82
- svc.stoppedAt = undefined;
83
- return { applied: true, feedback: `#${id} ${svc.name} marked running` };
84
- }
85
- case "remove": {
86
- const id = parseId(token.args[0]);
87
- if (id === null)
88
- return { applied: false, error: `svc:remove 的 id 无效: "${token.args[0] ?? ""}"` };
89
- const before = state.services.length;
90
- state.services = state.services.filter((s) => s.id !== id);
91
- if (state.services.length === before)
92
- return { applied: false, error: `svc:remove 服务 #${id} 不存在` };
93
- return { applied: true, feedback: `Removed #${id}` };
94
- }
95
- case "clear": {
96
- const n = state.services.length;
97
- state.services = [];
98
- state.nextId = 1;
99
- return { applied: true, feedback: `Cleared ${n} service(s)` };
100
- }
101
- default:
102
- return { applied: false, error: `svc 未知操作: ${op}` };
103
- }
104
- },
105
- overlay(state) {
106
- if (!state || state.services.length === 0)
107
- return undefined;
108
- const running = state.services.filter((s) => !s.stopped).length;
109
- const lines = state.services.map((s) => {
110
- const mark = s.stopped ? "○" : "●";
111
- let line = ` ${mark} #${s.id} ${s.name}`;
112
- if (s.port !== undefined)
113
- line += ` :${s.port}`;
114
- if (s.pid !== undefined)
115
- line += ` (pid ${s.pid})`;
116
- if (s.stopped)
117
- line += " 已停止";
118
- return line;
119
- });
120
- return { tool: "svc", lines: [`${running}/${state.services.length} running`, ...lines] };
121
- },
122
- init: initServiceState,
123
- };