pi-web-ui 0.113.1 → 0.114.0

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 (222) hide show
  1. package/CHANGELOG.md +43 -1
  2. package/README.md +117 -246
  3. package/README.zh-CN.md +145 -217
  4. package/README.zh-TW.md +145 -217
  5. package/bin/device-hub-cli.mjs +577 -0
  6. package/bin/pi-device-hub.mjs +9 -0
  7. package/bin/pi-web-ui.mjs +47 -15
  8. package/dist/server/agent-service-daemon.js +102 -24
  9. package/dist/server/agent-service.js +2289 -1120
  10. package/dist/server/approval-rules.js +29 -3
  11. package/dist/server/ask-user-question-tool.js +8 -8
  12. package/dist/server/atomic-file.js +35 -14
  13. package/dist/server/attachment-store.js +71 -35
  14. package/dist/server/attachments.js +18 -8
  15. package/dist/server/canvas/canvas-agent-tool.js +65 -15
  16. package/dist/server/canvas/canvas-dispatch.js +61 -20
  17. package/dist/server/canvas/canvas-orchestrator.js +516 -199
  18. package/dist/server/canvas/canvas-scheduler.js +99 -0
  19. package/dist/server/canvas/canvas-store.js +107 -54
  20. package/dist/server/canvas/canvas-validation.js +131 -0
  21. package/dist/server/canvas/canvas-workspace.js +284 -0
  22. package/dist/server/client-id-utils.js +8 -0
  23. package/dist/server/client-state.js +104 -22
  24. package/dist/server/communicate-tool.js +76 -0
  25. package/dist/server/compact-context-tool.js +2 -3
  26. package/dist/server/compaction-instructions.js +75 -0
  27. package/dist/server/compaction-markers.js +7 -2
  28. package/dist/server/compaction-state.js +84 -0
  29. package/dist/server/composer-drafts.js +43 -40
  30. package/dist/server/context-evidence.js +346 -0
  31. package/dist/server/conversation-communication.js +368 -0
  32. package/dist/server/conversation-read-tool.js +3 -4
  33. package/dist/server/conversation-tool-names.js +14 -0
  34. package/dist/server/conversation-tool.js +57 -0
  35. package/dist/server/delegate-mode.js +17 -4
  36. package/dist/server/device-center/bot-catalog.js +88 -0
  37. package/dist/server/device-center/bot-execution.js +106 -0
  38. package/dist/server/device-center/bots.js +170 -0
  39. package/dist/server/device-center/collab-service.js +153 -0
  40. package/dist/server/device-center/collab-tool.js +184 -0
  41. package/dist/server/device-center/connector.js +332 -0
  42. package/dist/server/device-center/desktop-linux.js +372 -0
  43. package/dist/server/device-center/desktop-native.js +413 -0
  44. package/dist/server/device-center/desktop-page.js +232 -0
  45. package/dist/server/device-center/desktop-setup.js +30 -0
  46. package/dist/server/device-center/desktop.js +387 -0
  47. package/dist/server/device-center/device-portals.js +241 -0
  48. package/dist/server/device-center/execution-failure.js +70 -0
  49. package/dist/server/device-center/executor.js +371 -0
  50. package/dist/server/device-center/file-sync.js +493 -0
  51. package/dist/server/device-center/hub-auth.js +69 -0
  52. package/dist/server/device-center/hub-page.js +68 -0
  53. package/dist/server/device-center/hub-setup.js +214 -0
  54. package/dist/server/device-center/hub.js +829 -0
  55. package/dist/server/device-center/local-page.js +17 -0
  56. package/dist/server/device-center/local.js +476 -0
  57. package/dist/server/device-center/main.js +118 -0
  58. package/dist/server/device-center/native-desktop/macos.js +192 -0
  59. package/dist/server/device-center/native-desktop/windows.js +118 -0
  60. package/dist/server/device-center/path-portal.js +120 -0
  61. package/dist/server/device-center/relay.js +959 -0
  62. package/dist/server/device-center/runtime.js +253 -0
  63. package/dist/server/device-center/smoke-preview.js +3 -0
  64. package/dist/server/device-center/store.js +122 -0
  65. package/dist/server/device-center/task-error.js +14 -0
  66. package/dist/server/device-center/transfers.js +293 -0
  67. package/dist/server/device-center/workspaces.js +45 -0
  68. package/dist/server/dispatch-domain-handlers.js +83 -27
  69. package/dist/server/dsh/dsh-agent-service.js +277 -158
  70. package/dist/server/dsh/dsh-client.js +12 -2
  71. package/dist/server/durable/durable-agent-service.js +1 -1
  72. package/dist/server/evidence-tool-hooks.js +49 -0
  73. package/dist/server/file-save.js +95 -0
  74. package/dist/server/file-transfer-routes.js +97 -47
  75. package/dist/server/files-service.js +38 -26
  76. package/dist/server/goal-review-gate.js +16 -6
  77. package/dist/server/goal-service.js +54 -30
  78. package/dist/server/http-proxy.js +120 -0
  79. package/dist/server/index.js +229 -223
  80. package/dist/server/load-timing.js +31 -0
  81. package/dist/server/mcp-bridge.js +219 -94
  82. package/dist/server/mcp-hot-reload.js +31 -5
  83. package/dist/server/mcp-manager.js +192 -93
  84. package/dist/server/mcp-oauth-login.js +169 -0
  85. package/dist/server/mcp-oauth-ui.js +137 -0
  86. package/dist/server/mcp-oauth.js +395 -0
  87. package/dist/server/mcp-project-runtime.js +207 -0
  88. package/dist/server/message-window.js +74 -21
  89. package/dist/server/net-guard.js +122 -20
  90. package/dist/server/payload-limits.js +17 -0
  91. package/dist/server/pending-question.js +82 -0
  92. package/dist/server/plan-mode.js +338 -137
  93. package/dist/server/plugin-assets.js +8 -4
  94. package/dist/server/plugin-chat-attachments.js +48 -0
  95. package/dist/server/plugin-facilities.js +67 -220
  96. package/dist/server/plugin-installer.js +2 -1
  97. package/dist/server/plugin-removal.js +49 -0
  98. package/dist/server/plugin-secrets.js +179 -0
  99. package/dist/server/plugins.js +262 -92
  100. package/dist/server/preset-fields.js +49 -0
  101. package/dist/server/preset-plugin-dependencies.js +57 -0
  102. package/dist/server/preset-share.js +112 -72
  103. package/dist/server/protocol-version.js +1 -1
  104. package/dist/server/queue-modes.js +10 -0
  105. package/dist/server/remote-ssh-service.js +160 -67
  106. package/dist/server/request-context.js +164 -0
  107. package/dist/server/sandbox-data.js +655 -0
  108. package/dist/server/sandbox-engines.js +7 -0
  109. package/dist/server/sandbox-runtime-gate.js +41 -0
  110. package/dist/server/sandbox-service.js +139 -698
  111. package/dist/server/sandbox-tool.js +21 -4
  112. package/dist/server/scheduler-tasks.js +63 -48
  113. package/dist/server/serialize.js +48 -19
  114. package/dist/server/session-branch.js +25 -3
  115. package/dist/server/session-parser.js +28 -18
  116. package/dist/server/session-scan.js +130 -0
  117. package/dist/server/session-search.js +51 -37
  118. package/dist/server/settings-service.js +267 -111
  119. package/dist/server/setup-config.js +58 -0
  120. package/dist/server/skill-maintenance.js +112 -24
  121. package/dist/server/subagent-helpers.js +4 -1
  122. package/dist/server/subagent-notify.js +4 -1
  123. package/dist/server/subagent-security-gate.js +52 -11
  124. package/dist/server/subagent-task.js +27 -0
  125. package/dist/server/subagents.js +217 -46
  126. package/dist/server/tabs.js +9 -1
  127. package/dist/server/terminals.js +467 -363
  128. package/dist/server/tool-guards.js +42 -6
  129. package/dist/server/tool-manager.js +47 -20
  130. package/dist/server/tool-overrides.js +13 -11
  131. package/dist/server/tool-prompt-overrides.js +32 -2
  132. package/dist/server/tool-prompts.js +1 -1
  133. package/dist/server/turn-timing.js +11 -0
  134. package/dist/server/universal/session-store.js +48 -6
  135. package/dist/server/universal/universal-service.js +1 -1
  136. package/dist/server/universal/universal-session.js +334 -231
  137. package/dist/server/uploads.js +64 -5
  138. package/dist/server/worktree-service.js +32 -24
  139. package/dist/server/ws-pending-queue.js +73 -27
  140. package/docs/device-center.md +142 -0
  141. package/docs/device-desktop.md +48 -0
  142. package/package.json +4 -1
  143. package/plugin-sdk/index.d.ts +28 -6
  144. package/plugin-sdk/ssh-host-trust.mjs +225 -0
  145. package/plugins/catalog.json +1 -1
  146. package/themes/aetheris.css +1 -107
  147. package/themes/ayu-light.css +5 -29
  148. package/themes/bases/flow-base.css +0 -6
  149. package/themes/bases/statusbar-flat-base.css +112 -0
  150. package/themes/bases/zhujian-base.css +1 -0
  151. package/themes/bases/zhupi-base.css +1 -0
  152. package/themes/catppuccin-latte.css +4 -27
  153. package/themes/catppuccin.css +4 -35
  154. package/themes/claude-code-dark.css +1 -0
  155. package/themes/codex.css +4 -28
  156. package/themes/cyberpunk.css +3 -61
  157. package/themes/dark-teal.css +0 -1
  158. package/themes/dazzle.css +3 -73
  159. package/themes/everforest-light.css +4 -27
  160. package/themes/geist.css +4 -28
  161. package/themes/gruvbox-light.css +4 -27
  162. package/themes/kanagawa-lotus.css +4 -27
  163. package/themes/md-preview.css +3 -213
  164. package/themes/mist.css +4 -24
  165. package/themes/nord.css +4 -35
  166. package/themes/one-dark.css +4 -37
  167. package/themes/paper.css +4 -16
  168. package/themes/rose-pine-dawn.css +4 -28
  169. package/themes/sakura.css +4 -24
  170. package/themes/solarized-light.css +4 -27
  171. package/themes/tokyo-night.css +3 -34
  172. package/themes/white.css +4 -26
  173. package/themes/zhujian-dark.css +1 -0
  174. package/themes/zhupi-dark.css +1 -0
  175. package/web/dist/.build-assets.json +1 -0
  176. package/web/dist/assets/BgTasksModal-CS7UNzcw.js +1 -0
  177. package/web/dist/assets/BgTasksModal-Dk-tp78W.js +1 -0
  178. package/web/dist/assets/CanvasStudio-BEJZE5BI.js +1579 -0
  179. package/web/dist/assets/CanvasStudio-CgUNHqos.js +1579 -0
  180. package/web/dist/assets/DeviceCenter-C8_CbxQ3.js +3 -0
  181. package/web/dist/assets/DeviceCenter-CVblvhNX.js +3 -0
  182. package/web/dist/assets/Dropdown-Oug0DDte.js +1 -0
  183. package/web/dist/assets/FilePreview-CvdX6nr6.js +2 -0
  184. package/web/dist/assets/FilePreview-kCZhfBAF.js +2 -0
  185. package/web/dist/assets/GlobalSearchModal-BLH63yYP.js +1 -0
  186. package/web/dist/assets/GlobalSearchModal-DAkvlvp6.js +1 -0
  187. package/web/dist/assets/GroupConversation-Cgo4xbpa.js +1 -0
  188. package/web/dist/assets/GroupConversation-DZ71jEi8.js +1 -0
  189. package/web/dist/assets/ModelConfigModal-BpWdFdQC.js +2 -0
  190. package/web/dist/assets/PiSetupModal-mkWPSxMj.js +1 -0
  191. package/web/dist/assets/ProviderOAuthControls-VK_jqXYS.js +1 -0
  192. package/web/dist/assets/SCMPanel-BP1TUT-V.js +2 -0
  193. package/web/dist/assets/SCMPanel-BscPm9kf.js +2 -0
  194. package/web/dist/assets/SettingsModal-C8UgMjVM.js +20 -0
  195. package/web/dist/assets/SettingsModal-VynB7jNb.js +20 -0
  196. package/web/dist/assets/TerminalPanel-D6cPRFei.js +3 -0
  197. package/web/dist/assets/TerminalPanel-DL20uKgU.js +3 -0
  198. package/web/dist/assets/TuiOverlayModal-Dst3BmT8.js +1 -0
  199. package/web/dist/assets/TuiOverlayModal-NCkpNtTp.js +1 -0
  200. package/web/dist/assets/UniversalPathPicker-CfQFc_c3.js +1 -0
  201. package/web/dist/assets/UniversalPathPicker-DwxwNcFw.js +1 -0
  202. package/web/dist/assets/app-globals-CnO6KlEM.js +325 -0
  203. package/web/dist/assets/desktop-DPyTy4M3.js +1 -0
  204. package/web/dist/assets/es-DWMIuDU2.js +2 -0
  205. package/web/dist/assets/index-CPgAH5q7.js +83 -0
  206. package/web/dist/assets/index-Cje8iugL.js +83 -0
  207. package/web/dist/assets/index-DnKeiDbj.css +1 -0
  208. package/web/dist/assets/markdown-BggnuQ4H.js +40 -0
  209. package/web/dist/assets/markdown-C8LL_u4z.css +1 -0
  210. package/web/dist/assets/math-1uRJCsA9.js +257 -0
  211. package/web/dist/assets/math-BorAY7qD.css +1 -0
  212. package/web/dist/assets/plugin-host-CqA4yW6w.js +1 -0
  213. package/web/dist/assets/shortcut-stack-hhrDyRBn.js +1 -0
  214. package/web/dist/assets/theme-BqdAjEjF.js +1 -0
  215. package/web/dist/assets/uuid-BzDIGCwP.js +1 -0
  216. package/web/dist/index.html +15 -9
  217. package/web/dist/sw.js +1 -1
  218. package/web/dist/assets/TerminalPanel-Ci55JtJL.js +0 -3
  219. package/web/dist/assets/index-ByiO9f-N.js +0 -2008
  220. package/web/dist/assets/index-ycGLh4a4.css +0 -1
  221. package/web/dist/assets/markdown-BJZlfvdP.js +0 -296
  222. package/web/dist/assets/markdown-DSNUiDzp.css +0 -1
@@ -0,0 +1,3 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Dt as t,Gt as n,L as r,Pt as i,Wt as a,Y as o,bt as s,en as c,g as l,h as u,m as d,ot as f,pn as p,x as m,xn as h,y as g,zt as _}from"./app-globals-CnO6KlEM.js";import{i as v,r as y,t as b}from"./react-CR5VJ85Q.js";import{L as x,T as S}from"./index-CPgAH5q7.js";import{t as C}from"./UniversalPathPicker-DwxwNcFw.js";var w=e(v(),1),T=b(),E={zh:{groups:`群聊`,manage:`管理成员`,save:`保存成员`,create:`建群`,name:`群名称`,devices:`选择 Bot(设备仅承载 Bot)`,empty:`还没有群聊,创建一个群开始协作。`,choose:`选择一个群聊`,open:`打开聊天`,online:`在线`,offline:`离线`,cancel:`取消`,loading:`加载中…`,rebind:`设备绑定已失效或已解除,请在设备设置中重新绑定。`,forbidden:`本机访问被拒绝,请检查本机登录状态与访问权限。`,failed:`请求失败`},en:{groups:`Groups`,manage:`Manage members`,save:`Save members`,create:`Create group`,name:`Group name`,devices:`Select Bots (devices host Bots)`,empty:`No groups yet. Create a group to collaborate.`,choose:`Select a group`,open:`Open chat`,online:`Online`,offline:`Offline`,cancel:`Cancel`,loading:`Loading…`,rebind:`The device binding has expired or was removed. Bind again in device settings.`,forbidden:`Local access denied. Check your local sign-in and access permissions.`,failed:`Request failed`}},D=class extends Error{status;code;constructor(e,t,n){super(n),this.status=e,this.code=t}};async function O(e,t,n){let r=await fetch(m(h(`/api/device-center/${e}`)),{method:n?`POST`:`GET`,credentials:`same-origin`,signal:t,...n?{headers:{"Content-Type":`application/json`},body:JSON.stringify(n)}:{}}),i=await r.json().catch(()=>({}));if(!r.ok)throw new D(r.status,i.code??``,typeof i.error==`string`?i.error:String(r.status));return i}function k(e){window.dispatchEvent(new CustomEvent(`pi-web-ui:device-group-open`,{detail:{roomId:e}}))}function A({active:e=!0,navigation:t}){let{locale:n}=d(),r=E[g(n)?`zh`:`en`],[o,s]=(0,w.useState)([]),[c,l]=(0,w.useState)([]),[u,f]=(0,w.useState)(``),[m,h]=(0,w.useState)(null),[v,y]=(0,w.useState)(!0),[b,x]=(0,w.useState)(``),[S,C]=(0,w.useState)(!1),[A,j]=(0,w.useState)(!1),[M,N]=(0,w.useState)(``),[P,F]=(0,w.useState)([]),[I,L]=(0,w.useState)(!1),[R,z]=(0,w.useState)(0),B=(0,w.useRef)(null),V=(0,w.useRef)(void 0),H=(0,w.useRef)(0),U=(0,w.useRef)(null),W=(0,w.useRef)(r);W.current=r;function G(e){let t=W.current;if(e instanceof D){if(e.status===409&&/^(REPAIR_REQUIRED|NOT_PAIRED|DEVICE_CHANGED)$/.test(e.code)||e.status===403&&/binding|credential|unpaired|revoked|not_bound|hub_forbidden/i.test(e.code))return t.rebind;if(e.status===403)return t.forbidden}return`${t.failed}: ${e instanceof Error?e.message:String(e)}`}function K(){U.current?.abort(),U.current=null,L(!1)}function ee(e,t=!1){++H.current,K(),f(e),h(null),C(!1),j(t),B.current=t?e:null,F([]),y(!0),x(``),z(e=>e+1)}function q(){++H.current,K(),C(!0),j(!1),B.current=null,h(null),F([]),N(``),x(``),z(e=>e+1)}(0,w.useEffect)(()=>{let t=++H.current,n=null,r=!1,i=()=>H.current===t;async function a(){if(!e||document.visibilityState===`hidden`||r)return;r=!0;let t=new AbortController;n=t;try{let[e,n,r]=await Promise.all([O(`bots`,t.signal),O(`rooms`,t.signal),A&&u?O(`rooms/${encodeURIComponent(u)}`,t.signal):Promise.resolve(null)]);if(!i()||t.signal.aborted)return;s(e.bots),l(n.rooms),h(r),r&&B.current===r.room.id&&(B.current=null,F(r.room.botIds)),x(``)}catch(e){i()&&!t.signal.aborted&&x(G(e))}finally{t.abort(),r=!1,i()&&y(!1)}}a();let o=window.setInterval(()=>void a(),3e3),c=()=>{document.visibilityState===`hidden`?n?.abort():a()};return document.addEventListener(`visibilitychange`,c),()=>{++H.current,n?.abort(),clearInterval(o),document.removeEventListener(`visibilitychange`,c)}},[e,u,A,R]),(0,w.useEffect)(()=>()=>U.current?.abort(),[]),(0,w.useEffect)(()=>{e||K()},[e]),(0,w.useEffect)(()=>{e&&t&&t.revision!==V.current&&(V.current=t.revision,t.create?q():t.roomId&&ee(t.roomId,t.manage))},[e,t?.revision]);async function J(){if(!e||U.current||(S?!M.trim():!m))return;let t=new AbortController;U.current=t,L(!0),x(``);let n=S,r=m?.room.id;try{let{room:e}=await O(n?`rooms`:`rooms/${encodeURIComponent(r)}/members`,t.signal,n?{name:M.trim(),botIds:P}:{botIds:P});if(t.signal.aborted||U.current!==t)return;l(t=>[...t.filter(t=>t.id!==e.id),e]),f(e.id),h({room:e}),C(!1),j(!1),N(``),F([]),z(e=>e+1),window.dispatchEvent(new CustomEvent(`pi-web-ui:device-groups-changed`)),n&&k(e.id)}catch(e){!t.signal.aborted&&U.current===t&&x(G(e))}finally{U.current===t&&(U.current=null,L(!1))}}let Y=c.find(e=>e.id===u);return(0,T.jsxs)(`section`,{className:`dg-root`,"aria-label":r.groups,children:[(0,T.jsxs)(`div`,{className:`dc-card dg-sidebar`,children:[(0,T.jsxs)(`div`,{className:`dg-heading`,children:[(0,T.jsxs)(`h2`,{children:[(0,T.jsx)(p,{}),` `,r.groups]}),(0,T.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:q,children:[(0,T.jsx)(a,{}),` `,r.create]})]}),(0,T.jsx)(`div`,{className:`dg-rooms`,children:c.map(t=>(0,T.jsxs)(`button`,{className:`dc-button dg-room`,type:`button`,"aria-current":t.id===u?`page`:void 0,disabled:!e,onClick:()=>{ee(t.id),k(t.id)},children:[(0,T.jsx)(i,{}),` `,t.name]},t.id))}),!v&&!c.length&&(0,T.jsx)(`p`,{className:`dg-empty`,children:r.empty})]}),(0,T.jsxs)(`div`,{className:`dc-card dg-chat`,children:[b&&(0,T.jsx)(`p`,{className:`dc-error`,role:`alert`,children:b}),v&&(0,T.jsx)(`p`,{role:`status`,children:r.loading}),S||A?(0,T.jsxs)(`form`,{className:`dg-create`,onSubmit:e=>{e.preventDefault(),J()},children:[(0,T.jsx)(`h2`,{children:S?r.create:r.manage}),S&&(0,T.jsxs)(`div`,{className:`dc-field`,children:[(0,T.jsx)(`label`,{htmlFor:`device-group-name`,children:r.name}),(0,T.jsx)(`input`,{id:`device-group-name`,value:M,onChange:e=>N(e.target.value),disabled:I||!e})]}),(0,T.jsxs)(`fieldset`,{disabled:I||!e||A&&!m,children:[(0,T.jsx)(`legend`,{children:r.devices}),o.map(e=>(0,T.jsxs)(`label`,{className:`dg-device`,children:[(0,T.jsx)(`input`,{type:`checkbox`,disabled:!e.enabled&&!P.includes(e.id),checked:P.includes(e.id),onChange:t=>F(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}),(0,T.jsx)(_,{}),(0,T.jsxs)(`span`,{children:[e.name,` · `,e.id,` · `,e.deviceId,` · `,e.online?r.online:r.offline]})]},e.id))]}),(0,T.jsxs)(`div`,{className:`dc-actions`,children:[(0,T.jsx)(`button`,{className:`dc-button`,type:`submit`,disabled:I||!e||(S?!M.trim():!m),children:S?r.create:r.save}),(0,T.jsx)(`button`,{className:`dc-button`,type:`button`,onClick:()=>{K(),B.current=null,C(!1),j(!1),x(``)},children:r.cancel})]})]}):Y?(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`div`,{className:`dg-title`,children:(0,T.jsxs)(`h2`,{children:[(0,T.jsx)(p,{}),` `,Y.name]})}),(0,T.jsxs)(`div`,{className:`dc-actions`,children:[(0,T.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:()=>k(Y.id),children:[(0,T.jsx)(i,{}),r.open]}),(0,T.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:()=>ee(Y.id,!0),children:[(0,T.jsx)(p,{}),r.manage]})]})]}):(0,T.jsx)(`p`,{className:`dg-empty`,children:r.choose})]})]})}var j=y();function M(e,t){let n=e.trim().replace(/\\/g,`/`);if(!n)return``;let r=/^(?:[a-z]:\/|\/)/i.test(n)?n:`${t.replace(/\\/g,`/`).replace(/\/$/,``)}/${n}`,i=r.match(/^(?:[a-z]:\/|\/\/[^/]+\/[^/]+\/?|\/)/i)?.[0];if(!i)return n;let a=[];for(let e of r.slice(i.length).split(`/`))e===`..`?a.pop():e&&e!==`.`&&a.push(e);return i.replace(/\/$/,``)+`/`+a.join(`/`)}function N({title:e,entries:t,selected:n,onChange:r,disabled:i,pending:a}){let o=l(),s=(0,w.useId)(),[c,u]=(0,w.useState)(``),d=new Set(t.map(e=>e.id)),f=n.filter(e=>!d.has(e)),p=[...t,...f.map(e=>({id:e,name:e}))],m=c.trim().toLowerCase(),h=p.filter(e=>[e.name,e.id,e.description,e.path].some(e=>e?.toLowerCase().includes(m))),g=h.filter(e=>d.has(e.id)&&e.status!==`disabled`);return(0,T.jsxs)(`fieldset`,{className:`dc-bot-catalog`,disabled:i,children:[(0,T.jsxs)(`legend`,{children:[e,` `,(0,T.jsxs)(`span`,{className:`dc-bot-count`,children:[n.length,` `,o(`localBotSelected`)]})]}),(0,T.jsxs)(`div`,{className:`dc-bot-catalog-actions`,children:[(0,T.jsx)(`input`,{type:`search`,"aria-label":`${o(`localBotSearch`)} ${e}`,placeholder:o(`localBotSearch`),value:c,onChange:e=>u(e.target.value)}),(0,T.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:a||!g.length,onClick:()=>r([...new Set([...n,...g.map(e=>e.id)])]),children:o(m?`localBotSelectVisible`:`localBotSelectAll`)}),(0,T.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:!n.length,onClick:()=>r([]),children:o(`localBotClear`)})]}),(0,T.jsxs)(`div`,{className:`dc-bot-catalog-list`,children:[h.map((e,t)=>(0,T.jsxs)(`label`,{className:`dc-bot-option`,htmlFor:`${s}-${t}`,children:[(0,T.jsx)(`input`,{id:`${s}-${t}`,type:`checkbox`,checked:n.includes(e.id),disabled:e.status===`disabled`&&!n.includes(e.id),onChange:t=>r(t.target.checked?[...new Set([...n,e.id])]:n.filter(t=>t!==e.id))}),(0,T.jsxs)(`span`,{children:[(0,T.jsx)(`strong`,{children:e.name}),!d.has(e.id)&&(0,T.jsx)(`small`,{children:o(a?`localBotUnverified`:`localBotUnavailable`)}),e.description&&(0,T.jsx)(`small`,{children:e.description}),e.status===`not_loaded`&&(0,T.jsx)(`small`,{children:o(`localBotMcpNotLoaded`)}),e.status===`disabled`&&(0,T.jsx)(`small`,{children:o(`localBotMcpDisabled`)}),e.source&&(0,T.jsx)(`small`,{children:e.source}),e.path&&(0,T.jsx)(`small`,{children:e.path})]})]},e.id)),!h.length&&(0,T.jsx)(`p`,{children:o(a?`localBotOptionsLoading`:`localBotNoOptions`)})]})]})}var P=e=>e.id.startsWith(`${e.provider}/`)?e.id.slice(e.provider.length+1):e.id,F=()=>({name:``,description:``,systemPrompt:``,cwd:``,tools:[],skills:[],mcpServers:[],enabled:!0});async function I(e,t,n){let r=await fetch(m(h(`/api/device-center/${e}`)),{method:n?`POST`:`GET`,credentials:`same-origin`,signal:t,...n?{headers:{"Content-Type":`application/json`},body:JSON.stringify(n)}:{}}),i=await r.json();if(!r.ok)throw Error(i.error||String(r.status));return i}function L({pathCompletions:e=[]}){let t=l(),[n,r]=(0,w.useState)([]),[i,a]=(0,w.useState)(null),[o,s]=(0,w.useState)(!1),[c,u]=(0,w.useState)(``),[d,f]=(0,w.useState)(``),[p,m]=(0,w.useState)(null),[h,g]=(0,w.useState)(``),[_,v]=(0,w.useState)(!1),[y,b]=(0,w.useState)(0),[S,E]=(0,w.useState)(!1),[D,O]=(0,w.useState)(`identity`),k=(0,w.useRef)(null),A=(0,w.useRef)(``),L=(0,w.useRef)(null),R=i!==null;(0,w.useEffect)(()=>{if(!R)return;let e=L.current,t=document.activeElement,n=document.body.style.overflow;return document.body.style.overflow=`hidden`,O(`identity`),e?.showModal?.(),()=>{e?.close?.(),document.body.style.overflow=n,t?.focus()}},[R]),(0,w.useEffect)(()=>{let e=new AbortController;return I(`local-bots`,e.signal).then(t=>{if(!e.signal.aborted){if(!Array.isArray(t.bots))throw Error(`Invalid Bot list`);r(t.bots)}}).catch(t=>{e.signal.aborted||u(String(t))}),()=>{e.abort(),k.current?.abort()}},[]);let z=i?.cwd;(0,w.useEffect)(()=>{if(z===void 0)return;let e=new AbortController;return v(!0),g(``),m(null),I(z?`local-bot-options?cwd=${encodeURIComponent(z)}`:`local-bot-options`,e.signal).then(n=>{if(!e.signal.aborted){if(![n.models,n.tools,n.skills,n.mcpServers,n.projects].every(Array.isArray)||!n.defaultCwd||!n.cwd)throw Error(t(`localBotOptionsInvalid`));A.current=n.defaultCwd,m(n),z||a(e=>e&&!e.cwd?{...e,cwd:n.cwd}:e)}}).catch(t=>{e.signal.aborted||g(String(t))}).finally(()=>{e.signal.aborted||v(!1)}),()=>e.abort()},[z,y]),(0,w.useEffect)(()=>{if(!S)return;let e=e=>{e.key===`Escape`&&E(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[S]);async function B(e=!1){if(!i||o)return;let n=new AbortController;k.current=n,s(!0),u(``),f(``);try{let o=await I(e?`local-bots/${encodeURIComponent(i.id)}/delete`:`local-bots`,n.signal,e?{revision:i.revision}:i);if(n.signal.aborted)return;r(t=>e?t.filter(e=>e.id!==i.id):[...t.filter(e=>e.id!==o.bot.id),o.bot]),a(null),E(!1),f(o.synced===!1?t(`localBotSyncFailed`):t(`localBotSaved`))}catch(e){n.signal.aborted||u(e instanceof Error?e.message:String(e))}finally{n.signal.aborted||s(!1)}}let V=p?.models.find(e=>e.provider===i?.model?.provider&&P(e)===i?.model?.modelId);return(0,T.jsxs)(`section`,{className:`dc-card dc-bots`,"aria-label":t(`localBotTitle`),children:[(0,T.jsxs)(`div`,{className:`dg-heading`,children:[(0,T.jsx)(`h2`,{children:t(`localBotTitle`)}),(0,T.jsx)(`button`,{className:`dc-button`,type:`button`,disabled:o,onClick:()=>{a(F()),u(``),E(!1)},children:t(`localBotCreate`)})]}),(0,T.jsx)(`p`,{children:t(`localBotHint`)}),c&&!i&&(0,T.jsx)(`p`,{role:`alert`,children:c}),d&&(0,T.jsx)(`p`,{role:`status`,children:d}),(0,T.jsxs)(`div`,{className:`dc-bot-workspace${i?` is-editing`:``}`,children:[(0,T.jsx)(`div`,{className:`dc-bot-list`,"aria-label":t(`localBotTitle`),children:n.map(e=>(0,T.jsxs)(`button`,{className:`dc-button dc-bot-item${i?.id===e.id?` is-selected`:``}`,"aria-pressed":i?.id===e.id,disabled:o,onClick:()=>{a(structuredClone(e)),u(``),E(!1)},children:[(0,T.jsx)(`span`,{className:`dc-bot-avatar`,"aria-hidden":`true`,children:e.name.slice(0,2).toUpperCase()}),(0,T.jsxs)(`span`,{className:`dc-bot-item-copy`,children:[(0,T.jsx)(`strong`,{children:e.name}),(0,T.jsxs)(`small`,{className:e.enabled?`is-enabled`:``,children:[e.enabled?t(`localBotEnabled`):t(`localBotDisabled`),` · r`,e.revision]})]})]},e.id))}),i&&(0,T.jsx)(`dialog`,{ref:L,className:`dc-bot-drawer`,"aria-label":t(`localBotTitle`),onCancel:e=>{e.preventDefault(),!o&&!S&&a(null)},onClick:e=>{if(e.target!==e.currentTarget||o)return;let t=e.currentTarget.getBoundingClientRect();(e.clientX<t.left||e.clientX>t.right||e.clientY<t.top||e.clientY>t.bottom)&&a(null)},children:(0,T.jsxs)(`form`,{className:`dc-bot-editor`,onSubmit:e=>{e.preventDefault(),B()},children:[(0,T.jsxs)(`header`,{className:`dc-bot-editor-head`,children:[(0,T.jsx)(`span`,{className:`dc-bot-avatar`,"aria-hidden":`true`,children:i.name.slice(0,2).toUpperCase()||`B`}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h3`,{children:i.name||t(`localBotCreate`)}),i.id&&(0,T.jsxs)(`small`,{children:[i.id,` · r`,i.revision]})]}),(0,T.jsxs)(`label`,{className:`dc-bot-enabled`,children:[(0,T.jsx)(`input`,{type:`checkbox`,role:`switch`,disabled:o,checked:i.enabled,onChange:e=>a({...i,enabled:e.target.checked})}),t(`localBotEnable`)]}),(0,T.jsx)(`button`,{className:`dc-button dc-bot-drawer-close`,type:`button`,"aria-label":t(`localBotCancel`),disabled:o,onClick:()=>a(null),children:`×`})]}),(0,T.jsx)(`div`,{className:`dc-bot-tabs`,role:`tablist`,"aria-label":t(`localBotTitle`),children:[[`identity`,t(`localBotIdentity`)],[`runtime`,t(`localBotRuntime`)],[`permissions`,t(`localBotPermissions`)]].map(([e,t],n,r)=>(0,T.jsx)(`button`,{type:`button`,role:`tab`,id:`bot-tab-${e}`,"aria-controls":`bot-panel-${e}`,"aria-selected":D===e,tabIndex:D===e?0:-1,onClick:()=>O(e),onKeyDown:e=>{let t=n;if(e.key===`ArrowRight`)t=(n+1)%r.length;else if(e.key===`ArrowLeft`)t=(n+r.length-1)%r.length;else if(e.key===`Home`)t=0;else if(e.key===`End`)t=r.length-1;else return;e.preventDefault(),O(r[t][0]),document.getElementById(`bot-tab-${r[t][0]}`)?.focus()},children:t},e))}),(0,T.jsxs)(`div`,{className:`dc-bot-editor-body`,children:[c&&(0,T.jsx)(`p`,{className:`dc-bot-error`,role:`alert`,children:c}),(0,T.jsxs)(`div`,{role:`tabpanel`,id:`bot-panel-identity`,"aria-labelledby":`bot-tab-identity`,hidden:D!==`identity`,children:[(0,T.jsx)(`p`,{className:`dc-bot-section-intro`,children:t(`localBotIdentityHint`)}),(0,T.jsxs)(`fieldset`,{className:`dc-bot-section`,disabled:o,children:[(0,T.jsx)(`legend`,{children:t(`localBotIdentity`)}),(0,T.jsxs)(`label`,{className:`dc-field`,children:[t(`localBotName`),(0,T.jsx)(`input`,{required:!0,value:i.name,onChange:e=>a({...i,name:e.target.value})})]}),(0,T.jsxs)(`label`,{className:`dc-field`,children:[t(`localBotDescription`),(0,T.jsx)(`textarea`,{rows:2,value:i.description,onChange:e=>a({...i,description:e.target.value})})]}),(0,T.jsxs)(`label`,{className:`dc-field`,children:[t(`localBotSystemPrompt`),(0,T.jsx)(`textarea`,{rows:9,className:`dc-bot-prompt`,spellCheck:!1,value:i.systemPrompt,onChange:e=>a({...i,systemPrompt:e.target.value})})]})]}),(0,T.jsx)(`p`,{className:`dc-bot-local-note`,children:t(`localBotPrivatePrompt`)})]}),(0,T.jsxs)(`div`,{role:`tabpanel`,id:`bot-panel-runtime`,"aria-labelledby":`bot-tab-runtime`,hidden:D!==`runtime`,children:[(0,T.jsx)(`p`,{className:`dc-bot-section-intro`,children:t(`localBotRuntimeHint`)}),(0,T.jsxs)(`fieldset`,{className:`dc-bot-section`,disabled:o,children:[(0,T.jsx)(`legend`,{children:t(`localBotRuntime`)}),(0,T.jsxs)(`div`,{className:`dc-field`,children:[(0,T.jsx)(`label`,{htmlFor:`local-bot-cwd`,children:t(`localBotCwd`)}),(0,T.jsx)(C,{inputId:`local-bot-cwd`,localOnly:!0,commitOnBlur:!0,pathCompletions:e,cwd:i.cwd,baseCwd:A.current||i.cwd,projects:p?.projects.map(e=>({...e,lastUsed:0}))??[],disabled:o,onSelectCwd:e=>a({...i,cwd:M(e,A.current||i.cwd)})})]}),(0,T.jsxs)(`div`,{className:`dc-field`,children:[(0,T.jsx)(`span`,{children:t(`localBotModel`)}),(0,T.jsxs)(`div`,{className:`dc-actions`,children:[(0,T.jsx)(`button`,{className:`dc-button`,type:`button`,"aria-haspopup":`dialog`,onClick:()=>E(!0),children:i.model?V?.name??`${i.model.provider}/${i.model.modelId}`:t(`localBotInheritModel`)}),i.model&&(0,T.jsx)(`button`,{className:`dc-button`,type:`button`,onClick:()=>a({...i,model:void 0}),children:t(`localBotInheritModel`)})]}),i.model&&!V&&(0,T.jsx)(`small`,{children:t(_?`localBotUnverified`:`localBotUnavailable`)})]})]})]}),(0,T.jsxs)(`div`,{role:`tabpanel`,id:`bot-panel-permissions`,"aria-labelledby":`bot-tab-permissions`,hidden:D!==`permissions`,children:[(0,T.jsx)(`p`,{className:`dc-bot-section-intro`,children:t(`localBotPermissionsHint`)}),(0,T.jsxs)(`div`,{className:`dc-bot-options-status`,"aria-live":`polite`,children:[_&&(0,T.jsx)(`span`,{children:t(`localBotOptionsLoading`)}),h&&(0,T.jsx)(`span`,{role:`alert`,children:h}),(0,T.jsx)(`button`,{className:`dc-button`,type:`button`,disabled:_||o,onClick:()=>b(e=>e+1),children:t(h?`deviceHubRetry`:`localBotReload`)})]}),(0,T.jsx)(`div`,{className:`dc-bot-permissions`,children:[[`tools`,t(`localBotTools`)],[`skills`,t(`localBotSkills`)],[`mcpServers`,t(`localBotMcpServers`)]].map(([e,t])=>(0,T.jsx)(N,{title:t,entries:p?.[e]??[],selected:i[e],disabled:o,pending:_||!!h,onChange:t=>a({...i,[e]:t})},e))})]})]}),(0,T.jsxs)(`footer`,{className:`dc-actions dc-bot-editor-footer`,children:[(0,T.jsx)(`button`,{className:`dc-button dc-bot-save`,disabled:o||!i.cwd||!i.name.trim(),children:t(`localBotSave`)}),(0,T.jsx)(`button`,{className:`dc-button`,type:`button`,disabled:o,onClick:()=>{a(null),E(!1)},children:t(`localBotCancel`)}),i.id&&(0,T.jsx)(`button`,{className:`dc-button is-danger`,type:`button`,disabled:o,onClick:()=>{window.confirm(t(`localBotDeleteConfirm`))&&B(!0)},children:t(`localBotDelete`)})]})]})})]}),i&&S&&(0,j.createPortal)((0,T.jsx)(`div`,{className:`modal-backdrop dc-bot-model-backdrop`,onClick:e=>{e.target===e.currentTarget&&E(!1)},children:(0,T.jsxs)(`div`,{className:`dc-bot-model-modal dd-menu-model`,role:`dialog`,"aria-modal":`true`,"aria-label":t(`localBotModel`),children:[(0,T.jsxs)(`div`,{className:`dg-heading`,children:[(0,T.jsx)(`h3`,{children:t(`localBotModel`)}),(0,T.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>E(!1),children:t(`localBotCancel`)})]}),(0,T.jsx)(x,{models:p?.models??[],modelsLoading:_,defaultModel:p?.defaultModel,currentModelId:i.model?`${i.model.provider}/${i.model.modelId}`:null,active:!0,onEnsureModels:()=>{},onRefresh:()=>b(e=>e+1),onPickModel:e=>{a({...i,model:{provider:e.provider,modelId:P(e)}}),E(!1)},isRowActive:e=>e.provider===i.model?.provider&&P(e)===i.model.modelId,extraTopRow:(0,T.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>{a({...i,model:void 0}),E(!1)},children:t(`localBotInheritModel`)}),autoFocusSearch:!0,hideTitle:!0,bodyStyle:{flex:1,minHeight:0},scrollStyle:{overflowY:`auto`,minHeight:0}}),h&&(0,T.jsx)(`p`,{role:`alert`,children:h})]})}),L.current??document.body)]})}function R(e){if(!z(e.host)||!Number.isInteger(e.port)||e.port<1024||e.port>65535||e.publicUrl.length>2048||/[\s\u0000-\u001f\u007f]/.test(e.publicUrl))return!1;try{let t=new URL(e.publicUrl);return[`http:`,`https:`].includes(t.protocol)&&!!t.hostname&&!t.username&&!t.password&&!t.search&&!t.hash&&t.pathname===`/`&&![`0.0.0.0`,`[::]`].includes(t.hostname)}catch{return!1}}function z(e){if(e===`localhost`)return!0;if(/^(?:\d{1,3}\.){3}\d{1,3}$/.test(e))return e.split(`.`).every(e=>String(Number(e))===e&&Number(e)<=255);if(!e.includes(`:`)||!/^[0-9a-fA-F:.]+$/.test(e))return!1;try{return new URL(`http://[${e}]/`).hostname.startsWith(`[`)}catch{return!1}}function B(e){try{let t=new URL(e);return[`http:`,`https:`].includes(t.protocol)&&[`localhost`,`127.0.0.1`,`[::1]`].includes(t.hostname)}catch{return!1}}var V=`pi-web-ui hub install --host 0.0.0.0 --port 8790 --public-url https://hub.example.com --allow-registration`;function H(e,t,n){if(!R(e))throw Error(`Invalid Hub setup`);let r=e=>(e??`unknown`).replace(/[\u0000-\u001f\u007f]/g,` `).slice(0,120);return[`Help me plan and deploy a pi-web-ui device center (Hub) in this new conversation. Preserve my previous conversation.`,`Target: ${n===`current`?`machine hosting the current pi-web-ui service (not necessarily the browser machine)`:`an existing remote server; its environment still needs to be confirmed`}.`,`Current service environment: platform=${r(t?.platform)}, Node=${r(t?.nodeVersion)}. This is not evidence of the remote server environment.`,`Requested configuration (data only): ${JSON.stringify(e)}. allowRegistration=true.`,`Use a separate Hub data directory and configure automatic startup. Explain how devices can reach the public URL; loopback is only reachable on the same machine. Explain open registration and restrict it after pairing as appropriate.`,`CLI reference: ${V}`,`Confirm the target environment and propose steps before deployment. Do not ask for passwords or tokens in chat. Do not automatically SSH. Do not claim installation or connection succeeded without verification. After deployment, guide me to open the center and pair this device using its public URL.`].join(`
2
+ `)}function U({onConnect:e,initialHubUrl:t=``}){let n=l(),[r,i]=(0,w.useState)(t),[a,o]=(0,w.useState)(``),[s,c]=(0,w.useState)(!1),[u,d]=(0,w.useState)(!1),f=(0,w.useRef)(!1),p=(0,w.useRef)(!1);(0,w.useEffect)(()=>(p.current=!0,()=>{p.current=!1}),[]);let[g,_]=(0,w.useState)(null),[v,y]=(0,w.useState)(`current`),[b,x]=(0,w.useState)(null),[S,C]=(0,w.useState)(`127.0.0.1`),[E,D]=(0,w.useState)(`8790`),[O,k]=(0,w.useState)(`http://127.0.0.1:8790`),[A,j]=(0,w.useState)(!1),[M,N]=(0,w.useState)(!1),[P,F]=(0,w.useState)(!1),[I,L]=(0,w.useState)(!1),[z,V]=(0,w.useState)(null),U=(0,w.useRef)(null),W=(0,w.useRef)(!1),G=B(window.location.origin);(0,w.useEffect)(()=>()=>U.current?.abort(),[]);let K=async()=>{if(W.current)return;U.current?.abort();let e=new AbortController;U.current=e,N(!1),F(!1),L(!1);try{let t=await fetch(m(h(`/api/device-center/setup`)),{credentials:`same-origin`,signal:e.signal});if(!t.ok)throw Error();let n=await t.json();if(!n||typeof n.platform!=`string`||typeof n.nodeVersion!=`string`||typeof n.dataDir!=`string`||typeof n.cliPath!=`string`||!R({host:`127.0.0.1`,port:n.defaultPort,publicUrl:n.defaultPublicUrl}))throw Error();if(e.signal.aborted)return;x(n),n.installation?.installed?(C(n.installation.host??`127.0.0.1`),D(String(n.installation.port)),k(n.installation.publicUrl??``),i(n.installation.publicUrl??``)):b||(D(String(n.defaultPort)),k(n.defaultPublicUrl))}catch{e.signal.aborted||(N(!0),L(!0))}finally{e.signal.aborted||F(!0)}},ee=async()=>{let e={host:S,port:Number(E),publicUrl:O};if(W.current||!G||!b||!P||I||b.busy||b.installation?.installed||!R(e))return;W.current=!0,U.current?.abort(),j(!0),N(!1),o(``);let t=new AbortController;U.current=t;try{let n=await fetch(m(h(`/api/device-center/setup`)),{credentials:`same-origin`,method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({...e,allowRegistration:!0}),signal:t.signal});if(n.status===409){x(e=>e&&{...e,busy:!0}),W.current=!1,j(!1),await K();return}if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(typeof e.error==`string`?e.error.slice(0,4096):`HTTP ${n.status}`)}let r=await n.json();if(!R({...e,publicUrl:r.publicUrl})||typeof r.output!=`string`)throw Error();t.signal.aborted||V(r)}catch(e){t.signal.aborted||(N(!0),o(e instanceof Error?e.message.slice(0,4096):``))}finally{W.current=!1,t.signal.aborted||j(!1)}},q=b?.installation,J=!!q?.installed,Y=J&&q.running&&q.owned,te={host:S,port:Number(E),publicUrl:O},X=R(te);return(0,T.jsxs)(`section`,{className:`dc-onboarding`,children:[(0,T.jsx)(`h3`,{children:n(`deviceSetupWelcome`)}),(0,T.jsx)(`p`,{children:n(`deviceSetupIntro`)}),(0,T.jsxs)(`div`,{className:`dc-actions`,children:[(0,T.jsx)(`button`,{className:`dc-button`,disabled:A,"aria-pressed":g===`connect`,onClick:()=>_(`connect`),children:n(`deviceSetupConnect`)}),(0,T.jsx)(`button`,{className:`dc-button`,disabled:A,"aria-pressed":g===`create`,onClick:()=>{_(`create`),!b&&G&&K()},children:n(`deviceSetupCreate`)})]}),g===`connect`&&(0,T.jsxs)(`form`,{onSubmit:t=>{t.preventDefault(),e(r.trim())},children:[(0,T.jsxs)(`label`,{className:`dc-field`,children:[(0,T.jsx)(`span`,{children:n(`deviceHubHubUrl`)}),(0,T.jsx)(`input`,{type:`url`,required:!0,maxLength:2048,value:r,onChange:e=>i(e.target.value),placeholder:`https://hub.example.com`})]}),(0,T.jsx)(`button`,{className:`dc-button is-primary`,disabled:!R({host:`localhost`,port:8790,publicUrl:r.trim()}),children:n(`deviceSetupPair`)})]}),g===`create`&&(0,T.jsxs)(T.Fragment,{children:[(0,T.jsxs)(`label`,{className:`dc-field`,children:[(0,T.jsx)(`span`,{children:n(`deviceSetupTarget`)}),(0,T.jsxs)(`select`,{disabled:A,value:v,onChange:e=>y(e.target.value),children:[(0,T.jsx)(`option`,{value:`current`,children:n(`deviceSetupCurrent`)}),(0,T.jsx)(`option`,{value:`remote`,children:n(`deviceSetupRemote`)}),(0,T.jsx)(`option`,{value:`none`,children:n(`deviceSetupNoServer`)})]})]}),v===`none`?(0,T.jsx)(`p`,{children:n(`deviceSetupNoServerHint`)}):(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`p`,{children:n(v===`current`?`deviceSetupCurrentHint`:`deviceSetupRemoteHint`)}),v===`current`&&(0,T.jsxs)(`div`,{className:`dc-setup-plan`,children:[(0,T.jsx)(`strong`,{children:n(`deviceSetupPlan`)}),(0,T.jsx)(`p`,{children:n(`deviceSetupPlanHint`)}),b&&(0,T.jsxs)(`dl`,{children:[(0,T.jsx)(`dt`,{children:n(`deviceSetupEnvironment`)}),(0,T.jsxs)(`dd`,{children:[b.platform,` · Node `,b.nodeVersion]}),(0,T.jsx)(`dt`,{children:n(`deviceSetupDataDir`)}),(0,T.jsx)(`dd`,{children:b.dataDir}),(0,T.jsx)(`dt`,{children:n(`deviceSetupCli`)}),(0,T.jsx)(`dd`,{children:b.cliPath})]}),!G&&(0,T.jsx)(`p`,{role:`status`,children:n(`deviceSetupLocalOnly`)}),(0,T.jsx)(`p`,{children:n(`deviceSetupBackground`)}),J&&(0,T.jsxs)(`div`,{role:`status`,children:[(0,T.jsx)(`h4`,{children:n(Y?`deviceSetupRestored`:`deviceSetupUnhealthy`)}),(0,T.jsx)(`p`,{children:q.publicUrl}),Y&&X&&q.publicUrl?(0,T.jsxs)(`div`,{className:`dc-actions`,children:[(0,T.jsx)(`a`,{className:`dc-button`,href:q.publicUrl,target:`_blank`,rel:`noopener noreferrer`,children:n(`deviceHubOpenHub`)}),(0,T.jsx)(`button`,{className:`dc-button`,onClick:()=>e(q.publicUrl),children:n(`deviceSetupPair`)})]}):(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`p`,{children:n(`deviceSetupRecovery`)}),(0,T.jsx)(`pre`,{className:`dc-setup-output`,children:`pi-web-ui hub status --json
3
+ pi-web-ui hub --help`})]})]}),b?.busy&&(0,T.jsx)(`p`,{role:`status`,children:n(`deviceSetupBusy`)}),G&&(0,T.jsx)(`button`,{className:`dc-button`,disabled:A||!P,onClick:()=>void K(),children:n(P?`deviceSetupRetry`:`deviceHubWorking`)})]}),(0,T.jsxs)(`div`,{className:`dc-setup-fields`,children:[(0,T.jsxs)(`label`,{className:`dc-field`,children:[(0,T.jsx)(`span`,{children:n(`deviceSetupHost`)}),(0,T.jsx)(`input`,{disabled:A||!!z,maxLength:253,value:S,onChange:e=>C(e.target.value)})]}),(0,T.jsxs)(`label`,{className:`dc-field`,children:[(0,T.jsx)(`span`,{children:n(`deviceSetupPort`)}),(0,T.jsx)(`input`,{disabled:A||!!z,type:`number`,min:1024,max:65535,value:E,onChange:e=>D(e.target.value)})]}),(0,T.jsxs)(`label`,{className:`dc-field`,children:[(0,T.jsx)(`span`,{children:n(`deviceHubHubUrl`)}),(0,T.jsx)(`input`,{disabled:A||!!z,maxLength:2048,value:O,onChange:e=>k(e.target.value)})]})]}),(0,T.jsx)(`p`,{className:`dc-setup-warning`,children:n(`deviceSetupReachable`)}),(0,T.jsx)(`p`,{children:n(`deviceSetupRegistration`)}),!X&&(0,T.jsx)(`p`,{role:`alert`,children:n(`deviceSetupInvalid`)}),v===`remote`&&(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`p`,{children:n(`deviceSetupCliHint`)}),(0,T.jsx)(`pre`,{className:`dc-setup-output`,children:`pi-web-ui hub install --host 0.0.0.0 --port 8790 --public-url https://hub.example.com --allow-registration`})]}),(0,T.jsxs)(`div`,{className:`dc-actions`,children:[v===`current`&&!z&&!J&&(0,T.jsx)(`button`,{className:`dc-button is-primary`,disabled:A||!G||!b||!P||I||!!b.busy||!X,onClick:()=>void ee(),children:n(A?`deviceSetupInstalling`:`deviceSetupInstall`)}),(0,T.jsx)(`button`,{className:`dc-button`,disabled:A||s||!X,onClick:()=>{if(!X||v===`none`||f.current)return;f.current=!0,c(!0),d(!1);let e=e=>{f.current=!1,p.current&&(c(!1),d(!e))},t=window.__piWebUiHost;try{t?.startChat({newChat:!0,prompt:H(te,b,v),onResult:e})||e(!1)}catch{e(!1)}},children:n(`deviceSetupAi`)})]}),(0,T.jsx)(`p`,{children:n(`deviceSetupAiHint`)}),s&&(0,T.jsx)(`p`,{role:`status`,children:n(`deviceSetupAiCreating`)}),u&&(0,T.jsx)(`p`,{role:`alert`,children:n(`deviceSetupAiFailed`)})]})]}),M&&(0,T.jsxs)(`div`,{role:`alert`,children:[(0,T.jsx)(`p`,{children:n(`deviceSetupFailed`)}),a&&(0,T.jsx)(`pre`,{className:`dc-setup-output`,children:a})]}),z&&(0,T.jsxs)(`div`,{role:`status`,children:[(0,T.jsx)(`h4`,{children:n(`deviceSetupSuccess`)}),(0,T.jsx)(`pre`,{className:`dc-setup-output`,children:z.output.slice(0,16e3)}),(0,T.jsxs)(`div`,{className:`dc-actions`,children:[(0,T.jsx)(`a`,{className:`dc-button`,href:z.publicUrl,target:`_blank`,rel:`noopener noreferrer`,children:n(`deviceHubOpenHub`)}),(0,T.jsx)(`button`,{className:`dc-button is-primary`,onClick:()=>e(z.publicUrl),children:n(`deviceSetupPair`)})]})]})]})}function W({hubUrl:e,currentDeviceId:t}){let{locale:r}=d(),i=g(r),[a,o]=(0,w.useState)([]),[s,c]=(0,w.useState)(``),[l,u]=(0,w.useState)(0);(0,w.useEffect)(()=>{let e=!1,t,n;async function r(){t=new AbortController;try{let n=await fetch(m(h(`/api/device-center/devices`)),{signal:AbortSignal.any([t.signal,AbortSignal.timeout(15e3)]),credentials:`same-origin`});if(!n.ok)throw Error(n.status===409?i?`请重新绑定本机以读取设备列表。`:`Pair this computer again to read the device list.`:i?`无法读取设备列表,请重试。`:`Could not load devices. Try again.`);let r=await n.json();if(!Array.isArray(r.devices))throw Error(i?`设备列表格式异常。`:`Invalid device list.`);e||(o(r.devices),c(``))}catch(t){e||(o([]),c(t instanceof Error?t.message:String(t)))}finally{e||(n=setTimeout(r,5e3))}}return r(),()=>{e=!0,t?.abort(),clearTimeout(n)}},[e,t,l,i]);function p(t){try{let n=new URL(e);return![`http:`,`https:`].includes(n.protocol)||n.username||n.password?void 0:new URL(`/device/${encodeURIComponent(t)}`,n).href}catch{return}}async function v(t,n,r=!1){t.preventDefault();let a=window.open(`about:blank`,`_blank`);if(!a){c(i?`请允许弹出窗口后重试。`:`Allow popups and try again.`);return}a.opener=null;try{let t=await fetch(m(h(`/api/device-center/devices/${encodeURIComponent(n)}/open`)),{method:`POST`,headers:{"Content-Type":`application/json`},body:`{}`,credentials:`same-origin`,signal:AbortSignal.timeout(15e3)});if(!t.ok)throw Error(i?`无法打开设备,请确认设备在线且本机绑定有效。`:`Could not open the device. Check connectivity and local pairing.`);let o=await t.json(),s=new URL(o.url);if(![`http:`,`https:`].includes(s.protocol)||s.hostname!==new URL(e).hostname||s.username||s.password||!(s.pathname===`/__device/open`||s.origin===new URL(e).origin&&s.pathname===`/device/${encodeURIComponent(n)}/__open`))throw Error(`Invalid device access URL`);s.searchParams.delete(`next`),r&&s.searchParams.set(`next`,`/desktop`),a.location.replace(s.href),c(``)}catch(e){a.close(),c(e instanceof Error?e.message:String(e))}}return(0,T.jsxs)(`section`,{className:`dc-card`,"aria-label":i?`所有设备`:`All devices`,children:[(0,T.jsxs)(`div`,{className:`dc-card-header`,children:[(0,T.jsx)(`span`,{className:`dc-icon`,children:(0,T.jsx)(_,{"aria-hidden":!0})}),(0,T.jsxs)(`div`,{children:[(0,T.jsxs)(`h2`,{children:[i?`所有设备`:`All devices`,` · `,a.length]}),(0,T.jsx)(`p`,{children:i?`同一账号下的设备,使用本机绑定授权直接访问。`:`Devices in your account. Access is authorized through this computer's pairing.`})]}),(0,T.jsx)(`button`,{type:`button`,className:`dc-icon-button`,"aria-label":i?`刷新设备`:`Refresh devices`,onClick:()=>u(e=>e+1),children:(0,T.jsx)(n,{})})]}),s&&(0,T.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:s}),(0,T.jsx)(`div`,{className:`dd-list`,children:a.map(e=>(0,T.jsxs)(`div`,{className:`dd-device`,children:[(0,T.jsx)(`span`,{className:`dc-device-icon`,children:(0,T.jsx)(_,{"aria-hidden":!0})}),(0,T.jsxs)(`div`,{className:`dd-identity`,children:[(0,T.jsx)(`strong`,{children:e.name}),(0,T.jsx)(`span`,{children:e.id===t?i?`本机`:`This device`:e.id})]}),(0,T.jsx)(`span`,{className:`dc-status ${e.online?`is-online`:`is-offline`}`,children:e.online?i?`在线`:`Online`:i?`离线`:`Offline`}),p(e.id)&&(0,T.jsxs)(`div`,{className:`dc-actions`,children:[(0,T.jsxs)(`a`,{className:`dc-button`,href:p(e.id),target:`_blank`,rel:`noopener noreferrer`,onClick:t=>void v(t,e.id),children:[(0,T.jsx)(f,{"aria-hidden":!0}),i?`打开设备`:`Open device`]}),(0,T.jsxs)(`a`,{className:`dc-button`,href:`${p(e.id)}/desktop`,target:`_blank`,rel:`noopener noreferrer`,onClick:t=>void v(t,e.id,!0),children:[(0,T.jsx)(_,{"aria-hidden":!0}),i?`远程桌面`:`Remote desktop`]})]})]},e.id))})]})}var G=class extends Error{status;constructor(e,t){super(t),this.status=e}};function K(e){try{let t=new URL(e);return[`http:`,`https:`].includes(t.protocol)&&!t.username&&!t.password?t.href:null}catch{return null}}function ee(){let e=l(),t=u().startsWith(`zh`),[r,i]=(0,w.useState)(null),[a,o]=(0,w.useState)(!1),[s,c]=(0,w.useState)(!1),[d,f]=(0,w.useState)(!1),[p,g]=(0,w.useState)(!1),v=(0,w.useRef)(0),y=(0,w.useRef)(null);async function b(e,t){if(y.current)return;let n=++v.current,r=new AbortController;y.current=r,o(!0),c(!1);try{let a=await fetch(m(h(`/api/device-desktop/local/${e}`)),{method:t?`POST`:`GET`,credentials:`same-origin`,signal:r.signal,...t?{headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}:{}});if(v.current!==n||r.signal.aborted)return;if(a.status===403){f(!0),i(null);return}if(!a.ok)throw Error(`Request failed`);let o=await a.json();if(v.current!==n||r.signal.aborted)return;if(e===`permissions`){if(typeof o?.screen!=`boolean`||typeof o?.accessibility!=`boolean`)throw Error(`Invalid permission status`);i(e=>e&&{...e,permissions:{supported:!0,screen:o.screen,accessibility:o.accessibility}}),g(!0)}else{if(typeof o?.os!=`string`||typeof o.enabled!=`boolean`||typeof o.environmentEnabled!=`boolean`||typeof o.supported!=`boolean`)throw Error(`Invalid desktop status`);i(o)}}catch{v.current===n&&!r.signal.aborted&&c(!0)}finally{v.current===n&&!r.signal.aborted&&(y.current=null,o(!1))}}return(0,w.useEffect)(()=>(b(`status`),()=>{v.current++,y.current?.abort(),y.current=null}),[]),(0,T.jsxs)(`section`,{className:`dc-card`,"aria-label":t?`本机远程桌面`:`Local remote desktop`,"aria-busy":a,children:[(0,T.jsxs)(`div`,{className:`dc-card-header`,children:[(0,T.jsx)(`span`,{className:`dc-icon`,children:(0,T.jsx)(_,{"aria-hidden":!0})}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h2`,{children:t?`本机远程桌面`:`Local remote desktop`}),(0,T.jsx)(`p`,{children:t?`管理这台设备的远程桌面与系统权限,无需连接设备中心。`:`Manage remote desktop and system permissions on this device, even while the device center is offline.`})]})]}),d?(0,T.jsx)(`p`,{role:`status`,children:t?`请在设备本机打开此页面以管理远程桌面权限。`:`Open this page on the device itself to manage remote desktop permissions.`}):(0,T.jsxs)(T.Fragment,{children:[r&&(0,T.jsxs)(T.Fragment,{children:[(0,T.jsxs)(`div`,{className:`dc-permission-row`,children:[(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h3`,{id:`dc-desktop-label`,children:t?`启用远程桌面`:`Enable remote desktop`}),(0,T.jsx)(`p`,{children:r.enabled?t?`已启用`:`Enabled`:t?`未启用`:`Disabled`})]}),(0,T.jsx)(`button`,{type:`button`,className:`dc-toggle${r.enabled?` is-on`:``}`,role:`switch`,"aria-checked":r.enabled,"aria-labelledby":`dc-desktop-label`,disabled:a||r.environmentEnabled||!r.supported&&!r.enabled,onClick:()=>void b(`enable`,{enabled:!r.enabled}),children:(0,T.jsx)(`span`,{className:`dc-toggle-thumb`})})]}),!r.supported&&(0,T.jsx)(`p`,{children:t?`这台设备暂不支持远程桌面。`:`Remote desktop is currently unavailable on this device.`}),r.environmentEnabled&&(0,T.jsx)(`p`,{children:t?`远程桌面由本机服务设置保持启用。`:`Remote desktop is kept enabled by the service settings on this device.`}),r.os===`darwin`&&(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`p`,{children:t?`点击下方按钮发起系统授权,请在这台 Mac 的系统设置中确认。授权后可能需要重启服务。`:`Use the buttons below to request system permission, then confirm in System Settings on this Mac. You may need to restart the service afterward.`}),(0,T.jsxs)(`div`,{className:`dc-actions`,children:[(0,T.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:a||r.permissions?.supported===!1,onClick:()=>void b(`permissions`,{kind:`screen`}),children:t?`授予屏幕录制权限`:`Grant screen recording permission`}),(0,T.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:a||r.permissions?.supported===!1,onClick:()=>void b(`permissions`,{kind:`control`}),children:t?`授予远程控制权限`:`Grant remote control permission`})]}),r.permissions?.screen===!0&&(0,T.jsx)(`p`,{children:t?`屏幕录制:已授权`:`Screen recording: granted`}),r.permissions?.accessibility===!0&&(0,T.jsx)(`p`,{children:t?`远程控制:已授权`:`Remote control: granted`}),p&&(0,T.jsx)(`p`,{role:`status`,children:t?`已发起授权请求,请确认系统设置后刷新状态。`:`Permission requested. Confirm in System Settings, then refresh the status.`})]})]}),s&&(0,T.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:t?`无法更新本机远程桌面设置,请重试。`:`Unable to update local remote desktop settings. Please retry.`}),(0,T.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:a,onClick:()=>void b(`status`),children:[(0,T.jsx)(n,{"aria-hidden":!0}),a?e(`deviceHubWorking`):t?`刷新远程桌面状态`:`Refresh remote desktop status`]})]})]})}function q({pathCompletions:e=[]}){let a=l(),u=S(),[d,p]=(0,w.useState)(u.revision?`groups`:`overview`);(0,w.useEffect)(()=>{u.revision&&p(`groups`)},[u.revision]);let[g,v]=(0,w.useState)(null),[y,b]=(0,w.useState)(``),[x,C]=(0,w.useState)(``),[E,D]=(0,w.useState)(null),[O,k]=(0,w.useState)(Date.now()),[j,M]=(0,w.useState)(null),[N,P]=(0,w.useState)(``),[F,I]=(0,w.useState)(``),[R,z]=(0,w.useState)(``),[B,V]=(0,w.useState)(!1),[H,q]=(0,w.useState)(!0),J=(0,w.useRef)(!1),Y=(0,w.useRef)(0),te=(0,w.useRef)(new Set),X=(0,w.useRef)(!1),Z=(0,w.useRef)(!1),ne=(0,w.useRef)(null),re=(0,w.useRef)(a);re.current=a;async function ie(e,t){let n=new AbortController;te.current.add(n);try{let r=await fetch(m(h(`/api/device-center/${e}`)),{method:t?`POST`:`GET`,credentials:`same-origin`,signal:n.signal,...t?{headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}:{}}),i=await r.json().catch(()=>({}));if(!r.ok)throw new G(r.status,typeof i.error==`string`?i.error:re.current(`deviceHubRequestFailed`,{status:r.status}));return i}finally{te.current.delete(n)}}function Q(e){return J.current&&Y.current===e}function ae(e){return e instanceof G&&e.status===403?(V(!0),re.current(`deviceHubLocalOnly`)):e instanceof Error?e.message:re.current(`deviceHubNetworkError`)}function oe(e){ne.current=e,v(e),Z.current||(C(e.name),b(e.hubUrl??``))}async function se(){let e=Y.current;try{let t=await ie(`status`);if(!Q(e)||X.current)return;oe(t),I(``),V(!1)}catch(t){Q(e)&&I(ae(t))}finally{Q(e)&&q(!1)}}(0,w.useEffect)(()=>{J.current=!0;let e=!1,t,n=async()=>{await se(),!e&&J.current&&(t=setTimeout(n,5e3))};return n(),()=>{e=!0,J.current=!1,Y.current++,clearTimeout(t);for(let e of te.current)e.abort()}},[]),(0,w.useEffect)(()=>{if(!E)return;let e=Y.current,t=!1,n,r=setInterval(()=>k(Date.now()),1e3),i=async()=>{if(!(t||!Q(e)||Date.now()>=E.expiresAt)){try{let n=await ie(`poll`,{});if(t||!Q(e))return;if(n.paired){let n=await ie(`status`);if(t||!Q(e))return;Z.current=!1,oe(n),D(null),P(``),z(``);return}P(``)}catch(n){!t&&Q(e)&&P(`${re.current(`deviceHubPollError`)} ${ae(n)}`)}!t&&Q(e)&&(n=setTimeout(i,2e3))}};return n=setTimeout(i,2e3),()=>{t=!0,clearTimeout(n),clearInterval(r)}},[E]);async function ce(){if(X.current)return;let e=K(y.trim());if(!e){P(a(`deviceHubInvalidUrl`));return}if(!x.trim()||x.trim().length>80){P(a(`deviceHubInvalidName`));return}let t=++Y.current;X.current=!0,M(`pair`),P(``),z(``),D(null);try{let n=await ie(`pair`,{hubUrl:e,name:x.trim()});if(!Q(t))return;if(!n.code||!Number.isFinite(n.expiresAt)||!K(n.hubUrl))throw Error(a(`deviceHubPairError`));k(Date.now()),D(n)}catch(e){Q(t)&&P(`${a(`deviceHubPairError`)} ${ae(e)}`)}finally{Q(t)&&(X.current=!1,M(null))}}async function le(){let e=ne.current;if(!e?.deviceId||X.current)return;let t=++Y.current;X.current=!0,M(`permission`),P(``),z(``),oe({...e,allowExecution:!e.allowExecution});try{await ie(`execution`,{allowExecution:!e.allowExecution}),Q(t)&&z(a(`deviceHubSaved`))}catch(n){Q(t)&&(oe(e),P(`${a(`deviceHubPermissionError`)} ${ae(n)}`))}finally{Q(t)&&(X.current=!1,M(null))}}async function ue(){let e=ne.current;if(!e?.deviceId||X.current||!window.confirm(a(`deviceHubDisconnectConfirm`,{name:e.name})))return;let t=++Y.current;X.current=!0,M(`disconnect`),P(``),z(``);try{if(await ie(`disconnect`,{}),!Q(t))return;Z.current=!1,oe({name:e.name,allowExecution:!1,connected:!1}),D(null)}catch(e){Q(t)&&P(`${a(`deviceHubDisconnectError`)} ${ae(e)}`)}finally{Q(t)&&(X.current=!1,M(null))}}async function de(){if(!E)return;let e=Y.current;try{await navigator.clipboard.writeText(E.code),Q(e)&&z(a(`deviceHubCopied`))}catch{Q(e)&&P(a(`deviceHubCopyFailed`))}}let $=!!g?.deviceId,fe=K($?g?.hubUrl??``:E?.hubUrl??``),pe=Math.max(0,Math.ceil(((E?.expiresAt??0)-O)/1e3)),me=`${Math.floor(pe/60)}:${String(pe%60).padStart(2,`0`)}`,he=fe?(0,T.jsxs)(`a`,{className:`dc-button`,href:fe,target:`_blank`,rel:`noopener noreferrer`,children:[(0,T.jsx)(f,{"aria-hidden":!0}),a(`deviceHubOpenHub`)]}):null;return(0,T.jsxs)(`section`,{className:`dc-page`,"aria-label":a(`deviceHubTitle`),children:[(0,T.jsxs)(`header`,{className:`dc-header`,children:[(0,T.jsxs)(`div`,{className:`dc-heading`,children:[(0,T.jsxs)(`span`,{className:`dc-eyebrow`,children:[(0,T.jsx)(_,{"aria-hidden":!0}),a(`deviceHubTitle`)]}),(0,T.jsx)(`h1`,{children:a(`deviceHubTitle`)}),(0,T.jsx)(`p`,{children:a(`deviceHubSubtitle`)})]}),(0,T.jsxs)(`div`,{className:`dc-actions`,children:[$&&he,(0,T.jsxs)(`span`,{className:`dc-status ${$?g?.connected?`is-online`:`is-offline`:`is-unpaired`}`,children:[(0,T.jsx)(`span`,{className:`dc-status-dot`}),a($?g?.connected?`deviceHubOnline`:`deviceHubOffline`:`deviceHubUnpaired`)]})]})]}),(0,T.jsxs)(`div`,{className:`dc-layout`,children:[(0,T.jsxs)(`nav`,{className:`dc-sidebar`,"aria-label":a(`deviceHubTitle`),children:[(0,T.jsxs)(`button`,{type:`button`,className:`dc-nav-item${d===`overview`?` is-active`:``}`,"aria-current":d===`overview`?`page`:void 0,onClick:()=>p(`overview`),children:[(0,T.jsx)(_,{"aria-hidden":!0}),a(`deviceHubOverview`)]}),(0,T.jsxs)(`button`,{type:`button`,className:`dc-nav-item${d===`groups`?` is-active`:``}`,"aria-current":d===`groups`?`page`:void 0,onClick:()=>p(`groups`),children:[(0,T.jsx)(i,{"aria-hidden":!0}),a(`deviceHubGroups`)]}),(0,T.jsxs)(`button`,{type:`button`,className:`dc-nav-item${d===`settings`?` is-active`:``}`,"aria-current":d===`settings`?`page`:void 0,onClick:()=>p(`settings`),children:[(0,T.jsx)(t,{"aria-hidden":!0}),a(`deviceHubSettings`)]})]}),(0,T.jsxs)(`main`,{className:`dc-content`,children:[H&&(0,T.jsxs)(`div`,{className:`dc-loading`,role:`status`,children:[(0,T.jsx)(n,{"aria-hidden":!0}),a(`deviceHubLoading`)]}),(B||F)&&(0,T.jsxs)(`div`,{className:`dc-notice is-error`,role:`alert`,children:[(0,T.jsx)(`span`,{children:B?a(`deviceHubLocalOnly`):`${a(`deviceHubStatusError`)} ${F}`}),(0,T.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>void se(),children:[(0,T.jsx)(n,{"aria-hidden":!0}),a(`deviceHubRetry`)]})]}),N&&!B&&(0,T.jsx)(`div`,{className:`dc-notice is-error`,role:`alert`,children:N}),R&&(0,T.jsxs)(`div`,{className:`dc-notice is-success`,role:`status`,children:[(0,T.jsx)(r,{"aria-hidden":!0}),R]}),!$&&(g||B)&&d===`overview`&&(0,T.jsx)(U,{initialHubUrl:y,onConnect:e=>{if(B){z(a(`deviceHubLocalOnly`));return}Z.current=!0,b(e),p(`settings`)}}),$&&d===`overview`&&(0,T.jsxs)(`section`,{className:`dc-card`,children:[(0,T.jsx)(`h3`,{children:a(`deviceSetupNext`)}),(0,T.jsx)(`p`,{children:a(`deviceSetupNextHint`)}),(0,T.jsx)(`button`,{className:`dc-button is-primary`,onClick:()=>p(`groups`),children:a(`deviceSetupManage`)})]}),d===`settings`&&(0,T.jsx)(ee,{}),g&&!B&&!$&&d===`settings`&&(0,T.jsxs)(`section`,{className:`dc-card`,children:[(0,T.jsxs)(`div`,{className:`dc-card-header`,children:[(0,T.jsx)(`span`,{className:`dc-icon`,children:(0,T.jsx)(t,{"aria-hidden":!0})}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h2`,{children:a(`deviceHubPairTitle`)}),(0,T.jsx)(`p`,{children:a(`deviceHubPairHint`)})]})]}),(0,T.jsx)(`ol`,{className:`dc-steps`,children:[`deviceHubStepDetails`,`deviceHubStepApprove`,`deviceHubStepWait`].map((e,t)=>(0,T.jsxs)(`li`,{className:E?t===0?`is-complete`:`is-active`:t===0?`is-active`:``,children:[(0,T.jsx)(`span`,{className:`dc-step-number`,children:E&&t===0?(0,T.jsx)(r,{"aria-hidden":!0}):t+1}),(0,T.jsx)(`span`,{children:a(e)})]},e))}),(0,T.jsxs)(`form`,{className:`dc-form`,onSubmit:e=>{e.preventDefault(),ce()},children:[(0,T.jsxs)(`div`,{className:`dc-field`,children:[(0,T.jsx)(`label`,{htmlFor:`dc-hub-url`,children:a(`deviceHubHubUrl`)}),(0,T.jsx)(`input`,{id:`dc-hub-url`,type:`url`,autoComplete:`url`,required:!0,placeholder:a(`deviceHubHubPlaceholder`),value:y,disabled:!!E||!!j,onChange:e=>{Z.current=!0,b(e.target.value)}})]}),(0,T.jsxs)(`div`,{className:`dc-field`,children:[(0,T.jsx)(`label`,{htmlFor:`dc-device-name`,children:a(`deviceHubName`)}),(0,T.jsx)(`input`,{id:`dc-device-name`,maxLength:80,required:!0,autoComplete:`off`,placeholder:a(`deviceHubNamePlaceholder`),value:x,disabled:!!E||!!j,onChange:e=>{Z.current=!0,C(e.target.value)}})]}),!E&&(0,T.jsx)(`div`,{className:`dc-actions`,children:(0,T.jsxs)(`button`,{className:`dc-button is-primary`,type:`submit`,disabled:!!j,children:[(0,T.jsx)(t,{"aria-hidden":!0}),a(j?`deviceHubWorking`:`deviceHubGetCode`)]})})]}),E&&(0,T.jsxs)(`div`,{className:`dc-pairing`,children:[(0,T.jsx)(`span`,{className:`dc-code-label`,children:a(`deviceHubCode`)}),(0,T.jsxs)(`div`,{className:`dc-code-row`,children:[(0,T.jsx)(`code`,{className:`dc-code`,children:E.code}),(0,T.jsx)(`button`,{className:`dc-icon-button`,type:`button`,"aria-label":a(`deviceHubCopy`),onClick:()=>void de(),children:(0,T.jsx)(o,{"aria-hidden":!0})})]}),(0,T.jsx)(`div`,{className:`dc-pair-meta`,children:a(pe?`deviceHubExpires`:`deviceHubExpired`,{time:me})}),(0,T.jsxs)(`div`,{className:`dc-actions`,children:[he,(0,T.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:!!j,onClick:()=>{++Y.current,D(null),P(``),z(``)},children:[(0,T.jsx)(n,{"aria-hidden":!0}),a(`deviceHubNewCode`)]})]}),pe>0&&(0,T.jsxs)(`p`,{className:`dc-progress`,role:`status`,children:[(0,T.jsx)(n,{"aria-hidden":!0}),a(`deviceHubWaiting`)]})]})]}),$&&g&&!B&&(0,T.jsxs)(T.Fragment,{children:[d===`overview`&&(0,T.jsxs)(`section`,{className:`dc-card`,children:[(0,T.jsxs)(`div`,{className:`dc-device-summary`,children:[(0,T.jsx)(`span`,{className:`dc-device-icon`,children:(0,T.jsx)(_,{"aria-hidden":!0})}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h2`,{children:g.name}),(0,T.jsx)(`p`,{children:a(`deviceHubDeviceTitle`)})]})]}),(0,T.jsxs)(`dl`,{className:`dc-details`,children:[(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`dt`,{children:a(`deviceHubDeviceId`)}),(0,T.jsx)(`dd`,{children:g.deviceId})]}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`dt`,{children:a(`deviceHubHubUrl`)}),(0,T.jsx)(`dd`,{children:g.hubUrl})]})]})]}),d===`settings`&&(0,T.jsxs)(`section`,{className:`dc-card`,children:[(0,T.jsxs)(`div`,{className:`dc-card-header`,children:[(0,T.jsx)(`span`,{className:`dc-icon`,children:(0,T.jsx)(c,{"aria-hidden":!0})}),(0,T.jsx)(`div`,{children:(0,T.jsx)(`h2`,{children:a(`deviceHubPermissions`)})})]}),(0,T.jsxs)(`div`,{className:`dc-permission-row`,children:[(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h3`,{id:`dc-permission-label`,children:a(`deviceHubPermissionLabel`)}),(0,T.jsx)(`p`,{id:`dc-permission-hint`,children:a(`deviceHubPermissionHint`)})]}),(0,T.jsx)(`button`,{type:`button`,className:`dc-toggle${g.allowExecution?` is-on`:``}`,role:`switch`,"aria-checked":g.allowExecution,"aria-labelledby":`dc-permission-label`,"aria-describedby":`dc-permission-hint`,disabled:!!j,onClick:()=>void le(),children:(0,T.jsx)(`span`,{className:`dc-toggle-thumb`})})]}),(0,T.jsx)(`p`,{className:`dc-permission-state`,role:`status`,children:a(j===`permission`?`deviceHubSaving`:g.allowExecution?`deviceHubEnabled`:`deviceHubReadOnly`)})]}),d===`settings`&&(0,T.jsxs)(`details`,{className:`dc-advanced`,children:[(0,T.jsx)(`summary`,{children:a(`deviceHubAdvanced`)}),(0,T.jsxs)(`div`,{className:`dc-danger-zone`,children:[(0,T.jsx)(`h3`,{children:a(`deviceHubDisconnect`)}),(0,T.jsx)(`p`,{children:a(`deviceHubDisconnectHint`)}),(0,T.jsx)(`button`,{type:`button`,className:`dc-button is-danger`,disabled:!!j,onClick:()=>void ue(),children:a(j===`disconnect`?`deviceHubWorking`:`deviceHubDisconnect`)})]})]})]}),$&&g?.hubUrl&&g.deviceId&&!B&&d!==`groups`&&(0,T.jsx)(W,{hubUrl:g.hubUrl,currentDeviceId:g.deviceId},`directory:${g.hubUrl}:${g.deviceId}`),!B&&(d===`settings`||d===`groups`)&&(0,T.jsx)(L,{pathCompletions:e},`bots:${g?.hubUrl??``}:${g?.deviceId??`unpaired`}`),d===`groups`&&(0,T.jsx)(A,{navigation:u}),(0,T.jsxs)(`aside`,{className:`dc-help`,children:[(0,T.jsx)(s,{className:`dc-help-icon`,"aria-hidden":!0}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h3`,{children:a(`deviceHubHelpTitle`)}),(0,T.jsx)(`p`,{children:a(`deviceHubHelpText`)})]})]})]})]})]})}export{q as DeviceCenter};
@@ -0,0 +1,3 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Dt as t,Gt as n,L as r,Pt as i,Wt as a,Y as o,bt as s,en as c,g as l,h as u,m as d,ot as f,pn as p,x as m,xn as h,y as g,zt as _}from"./app-globals-CnO6KlEM.js";import{i as v,r as y,t as b}from"./react-CR5VJ85Q.js";import{L as x,T as S}from"./index-Cje8iugL.js";import{t as C}from"./UniversalPathPicker-CfQFc_c3.js";var w=e(v(),1),T=b(),E={zh:{groups:`群聊`,manage:`管理成员`,save:`保存成员`,create:`建群`,name:`群名称`,devices:`选择 Bot(设备仅承载 Bot)`,empty:`还没有群聊,创建一个群开始协作。`,choose:`选择一个群聊`,open:`打开聊天`,online:`在线`,offline:`离线`,cancel:`取消`,loading:`加载中…`,rebind:`设备绑定已失效或已解除,请在设备设置中重新绑定。`,forbidden:`本机访问被拒绝,请检查本机登录状态与访问权限。`,failed:`请求失败`},en:{groups:`Groups`,manage:`Manage members`,save:`Save members`,create:`Create group`,name:`Group name`,devices:`Select Bots (devices host Bots)`,empty:`No groups yet. Create a group to collaborate.`,choose:`Select a group`,open:`Open chat`,online:`Online`,offline:`Offline`,cancel:`Cancel`,loading:`Loading…`,rebind:`The device binding has expired or was removed. Bind again in device settings.`,forbidden:`Local access denied. Check your local sign-in and access permissions.`,failed:`Request failed`}},D=class extends Error{status;code;constructor(e,t,n){super(n),this.status=e,this.code=t}};async function O(e,t,n){let r=await fetch(m(h(`/api/device-center/${e}`)),{method:n?`POST`:`GET`,credentials:`same-origin`,signal:t,...n?{headers:{"Content-Type":`application/json`},body:JSON.stringify(n)}:{}}),i=await r.json().catch(()=>({}));if(!r.ok)throw new D(r.status,i.code??``,typeof i.error==`string`?i.error:String(r.status));return i}function k(e){window.dispatchEvent(new CustomEvent(`pi-web-ui:device-group-open`,{detail:{roomId:e}}))}function A({active:e=!0,navigation:t}){let{locale:n}=d(),r=E[g(n)?`zh`:`en`],[o,s]=(0,w.useState)([]),[c,l]=(0,w.useState)([]),[u,f]=(0,w.useState)(``),[m,h]=(0,w.useState)(null),[v,y]=(0,w.useState)(!0),[b,x]=(0,w.useState)(``),[S,C]=(0,w.useState)(!1),[A,j]=(0,w.useState)(!1),[M,N]=(0,w.useState)(``),[P,F]=(0,w.useState)([]),[I,L]=(0,w.useState)(!1),[R,z]=(0,w.useState)(0),B=(0,w.useRef)(null),V=(0,w.useRef)(void 0),H=(0,w.useRef)(0),U=(0,w.useRef)(null),W=(0,w.useRef)(r);W.current=r;function G(e){let t=W.current;if(e instanceof D){if(e.status===409&&/^(REPAIR_REQUIRED|NOT_PAIRED|DEVICE_CHANGED)$/.test(e.code)||e.status===403&&/binding|credential|unpaired|revoked|not_bound|hub_forbidden/i.test(e.code))return t.rebind;if(e.status===403)return t.forbidden}return`${t.failed}: ${e instanceof Error?e.message:String(e)}`}function K(){U.current?.abort(),U.current=null,L(!1)}function ee(e,t=!1){++H.current,K(),f(e),h(null),C(!1),j(t),B.current=t?e:null,F([]),y(!0),x(``),z(e=>e+1)}function q(){++H.current,K(),C(!0),j(!1),B.current=null,h(null),F([]),N(``),x(``),z(e=>e+1)}(0,w.useEffect)(()=>{let t=++H.current,n=null,r=!1,i=()=>H.current===t;async function a(){if(!e||document.visibilityState===`hidden`||r)return;r=!0;let t=new AbortController;n=t;try{let[e,n,r]=await Promise.all([O(`bots`,t.signal),O(`rooms`,t.signal),A&&u?O(`rooms/${encodeURIComponent(u)}`,t.signal):Promise.resolve(null)]);if(!i()||t.signal.aborted)return;s(e.bots),l(n.rooms),h(r),r&&B.current===r.room.id&&(B.current=null,F(r.room.botIds)),x(``)}catch(e){i()&&!t.signal.aborted&&x(G(e))}finally{t.abort(),r=!1,i()&&y(!1)}}a();let o=window.setInterval(()=>void a(),3e3),c=()=>{document.visibilityState===`hidden`?n?.abort():a()};return document.addEventListener(`visibilitychange`,c),()=>{++H.current,n?.abort(),clearInterval(o),document.removeEventListener(`visibilitychange`,c)}},[e,u,A,R]),(0,w.useEffect)(()=>()=>U.current?.abort(),[]),(0,w.useEffect)(()=>{e||K()},[e]),(0,w.useEffect)(()=>{e&&t&&t.revision!==V.current&&(V.current=t.revision,t.create?q():t.roomId&&ee(t.roomId,t.manage))},[e,t?.revision]);async function J(){if(!e||U.current||(S?!M.trim():!m))return;let t=new AbortController;U.current=t,L(!0),x(``);let n=S,r=m?.room.id;try{let{room:e}=await O(n?`rooms`:`rooms/${encodeURIComponent(r)}/members`,t.signal,n?{name:M.trim(),botIds:P}:{botIds:P});if(t.signal.aborted||U.current!==t)return;l(t=>[...t.filter(t=>t.id!==e.id),e]),f(e.id),h({room:e}),C(!1),j(!1),N(``),F([]),z(e=>e+1),window.dispatchEvent(new CustomEvent(`pi-web-ui:device-groups-changed`)),n&&k(e.id)}catch(e){!t.signal.aborted&&U.current===t&&x(G(e))}finally{U.current===t&&(U.current=null,L(!1))}}let Y=c.find(e=>e.id===u);return(0,T.jsxs)(`section`,{className:`dg-root`,"aria-label":r.groups,children:[(0,T.jsxs)(`div`,{className:`dc-card dg-sidebar`,children:[(0,T.jsxs)(`div`,{className:`dg-heading`,children:[(0,T.jsxs)(`h2`,{children:[(0,T.jsx)(p,{}),` `,r.groups]}),(0,T.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:q,children:[(0,T.jsx)(a,{}),` `,r.create]})]}),(0,T.jsx)(`div`,{className:`dg-rooms`,children:c.map(t=>(0,T.jsxs)(`button`,{className:`dc-button dg-room`,type:`button`,"aria-current":t.id===u?`page`:void 0,disabled:!e,onClick:()=>{ee(t.id),k(t.id)},children:[(0,T.jsx)(i,{}),` `,t.name]},t.id))}),!v&&!c.length&&(0,T.jsx)(`p`,{className:`dg-empty`,children:r.empty})]}),(0,T.jsxs)(`div`,{className:`dc-card dg-chat`,children:[b&&(0,T.jsx)(`p`,{className:`dc-error`,role:`alert`,children:b}),v&&(0,T.jsx)(`p`,{role:`status`,children:r.loading}),S||A?(0,T.jsxs)(`form`,{className:`dg-create`,onSubmit:e=>{e.preventDefault(),J()},children:[(0,T.jsx)(`h2`,{children:S?r.create:r.manage}),S&&(0,T.jsxs)(`div`,{className:`dc-field`,children:[(0,T.jsx)(`label`,{htmlFor:`device-group-name`,children:r.name}),(0,T.jsx)(`input`,{id:`device-group-name`,value:M,onChange:e=>N(e.target.value),disabled:I||!e})]}),(0,T.jsxs)(`fieldset`,{disabled:I||!e||A&&!m,children:[(0,T.jsx)(`legend`,{children:r.devices}),o.map(e=>(0,T.jsxs)(`label`,{className:`dg-device`,children:[(0,T.jsx)(`input`,{type:`checkbox`,disabled:!e.enabled&&!P.includes(e.id),checked:P.includes(e.id),onChange:t=>F(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}),(0,T.jsx)(_,{}),(0,T.jsxs)(`span`,{children:[e.name,` · `,e.id,` · `,e.deviceId,` · `,e.online?r.online:r.offline]})]},e.id))]}),(0,T.jsxs)(`div`,{className:`dc-actions`,children:[(0,T.jsx)(`button`,{className:`dc-button`,type:`submit`,disabled:I||!e||(S?!M.trim():!m),children:S?r.create:r.save}),(0,T.jsx)(`button`,{className:`dc-button`,type:`button`,onClick:()=>{K(),B.current=null,C(!1),j(!1),x(``)},children:r.cancel})]})]}):Y?(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`div`,{className:`dg-title`,children:(0,T.jsxs)(`h2`,{children:[(0,T.jsx)(p,{}),` `,Y.name]})}),(0,T.jsxs)(`div`,{className:`dc-actions`,children:[(0,T.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:()=>k(Y.id),children:[(0,T.jsx)(i,{}),r.open]}),(0,T.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:()=>ee(Y.id,!0),children:[(0,T.jsx)(p,{}),r.manage]})]})]}):(0,T.jsx)(`p`,{className:`dg-empty`,children:r.choose})]})]})}var j=y();function M(e,t){let n=e.trim().replace(/\\/g,`/`);if(!n)return``;let r=/^(?:[a-z]:\/|\/)/i.test(n)?n:`${t.replace(/\\/g,`/`).replace(/\/$/,``)}/${n}`,i=r.match(/^(?:[a-z]:\/|\/\/[^/]+\/[^/]+\/?|\/)/i)?.[0];if(!i)return n;let a=[];for(let e of r.slice(i.length).split(`/`))e===`..`?a.pop():e&&e!==`.`&&a.push(e);return i.replace(/\/$/,``)+`/`+a.join(`/`)}function N({title:e,entries:t,selected:n,onChange:r,disabled:i,pending:a}){let o=l(),s=(0,w.useId)(),[c,u]=(0,w.useState)(``),d=new Set(t.map(e=>e.id)),f=n.filter(e=>!d.has(e)),p=[...t,...f.map(e=>({id:e,name:e}))],m=c.trim().toLowerCase(),h=p.filter(e=>[e.name,e.id,e.description,e.path].some(e=>e?.toLowerCase().includes(m))),g=h.filter(e=>d.has(e.id)&&e.status!==`disabled`);return(0,T.jsxs)(`fieldset`,{className:`dc-bot-catalog`,disabled:i,children:[(0,T.jsxs)(`legend`,{children:[e,` `,(0,T.jsxs)(`span`,{className:`dc-bot-count`,children:[n.length,` `,o(`localBotSelected`)]})]}),(0,T.jsxs)(`div`,{className:`dc-bot-catalog-actions`,children:[(0,T.jsx)(`input`,{type:`search`,"aria-label":`${o(`localBotSearch`)} ${e}`,placeholder:o(`localBotSearch`),value:c,onChange:e=>u(e.target.value)}),(0,T.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:a||!g.length,onClick:()=>r([...new Set([...n,...g.map(e=>e.id)])]),children:o(m?`localBotSelectVisible`:`localBotSelectAll`)}),(0,T.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:!n.length,onClick:()=>r([]),children:o(`localBotClear`)})]}),(0,T.jsxs)(`div`,{className:`dc-bot-catalog-list`,children:[h.map((e,t)=>(0,T.jsxs)(`label`,{className:`dc-bot-option`,htmlFor:`${s}-${t}`,children:[(0,T.jsx)(`input`,{id:`${s}-${t}`,type:`checkbox`,checked:n.includes(e.id),disabled:e.status===`disabled`&&!n.includes(e.id),onChange:t=>r(t.target.checked?[...new Set([...n,e.id])]:n.filter(t=>t!==e.id))}),(0,T.jsxs)(`span`,{children:[(0,T.jsx)(`strong`,{children:e.name}),!d.has(e.id)&&(0,T.jsx)(`small`,{children:o(a?`localBotUnverified`:`localBotUnavailable`)}),e.description&&(0,T.jsx)(`small`,{children:e.description}),e.status===`not_loaded`&&(0,T.jsx)(`small`,{children:o(`localBotMcpNotLoaded`)}),e.status===`disabled`&&(0,T.jsx)(`small`,{children:o(`localBotMcpDisabled`)}),e.source&&(0,T.jsx)(`small`,{children:e.source}),e.path&&(0,T.jsx)(`small`,{children:e.path})]})]},e.id)),!h.length&&(0,T.jsx)(`p`,{children:o(a?`localBotOptionsLoading`:`localBotNoOptions`)})]})]})}var P=e=>e.id.startsWith(`${e.provider}/`)?e.id.slice(e.provider.length+1):e.id,F=()=>({name:``,description:``,systemPrompt:``,cwd:``,tools:[],skills:[],mcpServers:[],enabled:!0});async function I(e,t,n){let r=await fetch(m(h(`/api/device-center/${e}`)),{method:n?`POST`:`GET`,credentials:`same-origin`,signal:t,...n?{headers:{"Content-Type":`application/json`},body:JSON.stringify(n)}:{}}),i=await r.json();if(!r.ok)throw Error(i.error||String(r.status));return i}function L({pathCompletions:e=[]}){let t=l(),[n,r]=(0,w.useState)([]),[i,a]=(0,w.useState)(null),[o,s]=(0,w.useState)(!1),[c,u]=(0,w.useState)(``),[d,f]=(0,w.useState)(``),[p,m]=(0,w.useState)(null),[h,g]=(0,w.useState)(``),[_,v]=(0,w.useState)(!1),[y,b]=(0,w.useState)(0),[S,E]=(0,w.useState)(!1),[D,O]=(0,w.useState)(`identity`),k=(0,w.useRef)(null),A=(0,w.useRef)(``),L=(0,w.useRef)(null),R=i!==null;(0,w.useEffect)(()=>{if(!R)return;let e=L.current,t=document.activeElement,n=document.body.style.overflow;return document.body.style.overflow=`hidden`,O(`identity`),e?.showModal?.(),()=>{e?.close?.(),document.body.style.overflow=n,t?.focus()}},[R]),(0,w.useEffect)(()=>{let e=new AbortController;return I(`local-bots`,e.signal).then(t=>{if(!e.signal.aborted){if(!Array.isArray(t.bots))throw Error(`Invalid Bot list`);r(t.bots)}}).catch(t=>{e.signal.aborted||u(String(t))}),()=>{e.abort(),k.current?.abort()}},[]);let z=i?.cwd;(0,w.useEffect)(()=>{if(z===void 0)return;let e=new AbortController;return v(!0),g(``),m(null),I(z?`local-bot-options?cwd=${encodeURIComponent(z)}`:`local-bot-options`,e.signal).then(n=>{if(!e.signal.aborted){if(![n.models,n.tools,n.skills,n.mcpServers,n.projects].every(Array.isArray)||!n.defaultCwd||!n.cwd)throw Error(t(`localBotOptionsInvalid`));A.current=n.defaultCwd,m(n),z||a(e=>e&&!e.cwd?{...e,cwd:n.cwd}:e)}}).catch(t=>{e.signal.aborted||g(String(t))}).finally(()=>{e.signal.aborted||v(!1)}),()=>e.abort()},[z,y]),(0,w.useEffect)(()=>{if(!S)return;let e=e=>{e.key===`Escape`&&E(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[S]);async function B(e=!1){if(!i||o)return;let n=new AbortController;k.current=n,s(!0),u(``),f(``);try{let o=await I(e?`local-bots/${encodeURIComponent(i.id)}/delete`:`local-bots`,n.signal,e?{revision:i.revision}:i);if(n.signal.aborted)return;r(t=>e?t.filter(e=>e.id!==i.id):[...t.filter(e=>e.id!==o.bot.id),o.bot]),a(null),E(!1),f(o.synced===!1?t(`localBotSyncFailed`):t(`localBotSaved`))}catch(e){n.signal.aborted||u(e instanceof Error?e.message:String(e))}finally{n.signal.aborted||s(!1)}}let V=p?.models.find(e=>e.provider===i?.model?.provider&&P(e)===i?.model?.modelId);return(0,T.jsxs)(`section`,{className:`dc-card dc-bots`,"aria-label":t(`localBotTitle`),children:[(0,T.jsxs)(`div`,{className:`dg-heading`,children:[(0,T.jsx)(`h2`,{children:t(`localBotTitle`)}),(0,T.jsx)(`button`,{className:`dc-button`,type:`button`,disabled:o,onClick:()=>{a(F()),u(``),E(!1)},children:t(`localBotCreate`)})]}),(0,T.jsx)(`p`,{children:t(`localBotHint`)}),c&&!i&&(0,T.jsx)(`p`,{role:`alert`,children:c}),d&&(0,T.jsx)(`p`,{role:`status`,children:d}),(0,T.jsxs)(`div`,{className:`dc-bot-workspace${i?` is-editing`:``}`,children:[(0,T.jsx)(`div`,{className:`dc-bot-list`,"aria-label":t(`localBotTitle`),children:n.map(e=>(0,T.jsxs)(`button`,{className:`dc-button dc-bot-item${i?.id===e.id?` is-selected`:``}`,"aria-pressed":i?.id===e.id,disabled:o,onClick:()=>{a(structuredClone(e)),u(``),E(!1)},children:[(0,T.jsx)(`span`,{className:`dc-bot-avatar`,"aria-hidden":`true`,children:e.name.slice(0,2).toUpperCase()}),(0,T.jsxs)(`span`,{className:`dc-bot-item-copy`,children:[(0,T.jsx)(`strong`,{children:e.name}),(0,T.jsxs)(`small`,{className:e.enabled?`is-enabled`:``,children:[e.enabled?t(`localBotEnabled`):t(`localBotDisabled`),` · r`,e.revision]})]})]},e.id))}),i&&(0,T.jsx)(`dialog`,{ref:L,className:`dc-bot-drawer`,"aria-label":t(`localBotTitle`),onCancel:e=>{e.preventDefault(),!o&&!S&&a(null)},onClick:e=>{if(e.target!==e.currentTarget||o)return;let t=e.currentTarget.getBoundingClientRect();(e.clientX<t.left||e.clientX>t.right||e.clientY<t.top||e.clientY>t.bottom)&&a(null)},children:(0,T.jsxs)(`form`,{className:`dc-bot-editor`,onSubmit:e=>{e.preventDefault(),B()},children:[(0,T.jsxs)(`header`,{className:`dc-bot-editor-head`,children:[(0,T.jsx)(`span`,{className:`dc-bot-avatar`,"aria-hidden":`true`,children:i.name.slice(0,2).toUpperCase()||`B`}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h3`,{children:i.name||t(`localBotCreate`)}),i.id&&(0,T.jsxs)(`small`,{children:[i.id,` · r`,i.revision]})]}),(0,T.jsxs)(`label`,{className:`dc-bot-enabled`,children:[(0,T.jsx)(`input`,{type:`checkbox`,role:`switch`,disabled:o,checked:i.enabled,onChange:e=>a({...i,enabled:e.target.checked})}),t(`localBotEnable`)]}),(0,T.jsx)(`button`,{className:`dc-button dc-bot-drawer-close`,type:`button`,"aria-label":t(`localBotCancel`),disabled:o,onClick:()=>a(null),children:`×`})]}),(0,T.jsx)(`div`,{className:`dc-bot-tabs`,role:`tablist`,"aria-label":t(`localBotTitle`),children:[[`identity`,t(`localBotIdentity`)],[`runtime`,t(`localBotRuntime`)],[`permissions`,t(`localBotPermissions`)]].map(([e,t],n,r)=>(0,T.jsx)(`button`,{type:`button`,role:`tab`,id:`bot-tab-${e}`,"aria-controls":`bot-panel-${e}`,"aria-selected":D===e,tabIndex:D===e?0:-1,onClick:()=>O(e),onKeyDown:e=>{let t=n;if(e.key===`ArrowRight`)t=(n+1)%r.length;else if(e.key===`ArrowLeft`)t=(n+r.length-1)%r.length;else if(e.key===`Home`)t=0;else if(e.key===`End`)t=r.length-1;else return;e.preventDefault(),O(r[t][0]),document.getElementById(`bot-tab-${r[t][0]}`)?.focus()},children:t},e))}),(0,T.jsxs)(`div`,{className:`dc-bot-editor-body`,children:[c&&(0,T.jsx)(`p`,{className:`dc-bot-error`,role:`alert`,children:c}),(0,T.jsxs)(`div`,{role:`tabpanel`,id:`bot-panel-identity`,"aria-labelledby":`bot-tab-identity`,hidden:D!==`identity`,children:[(0,T.jsx)(`p`,{className:`dc-bot-section-intro`,children:t(`localBotIdentityHint`)}),(0,T.jsxs)(`fieldset`,{className:`dc-bot-section`,disabled:o,children:[(0,T.jsx)(`legend`,{children:t(`localBotIdentity`)}),(0,T.jsxs)(`label`,{className:`dc-field`,children:[t(`localBotName`),(0,T.jsx)(`input`,{required:!0,value:i.name,onChange:e=>a({...i,name:e.target.value})})]}),(0,T.jsxs)(`label`,{className:`dc-field`,children:[t(`localBotDescription`),(0,T.jsx)(`textarea`,{rows:2,value:i.description,onChange:e=>a({...i,description:e.target.value})})]}),(0,T.jsxs)(`label`,{className:`dc-field`,children:[t(`localBotSystemPrompt`),(0,T.jsx)(`textarea`,{rows:9,className:`dc-bot-prompt`,spellCheck:!1,value:i.systemPrompt,onChange:e=>a({...i,systemPrompt:e.target.value})})]})]}),(0,T.jsx)(`p`,{className:`dc-bot-local-note`,children:t(`localBotPrivatePrompt`)})]}),(0,T.jsxs)(`div`,{role:`tabpanel`,id:`bot-panel-runtime`,"aria-labelledby":`bot-tab-runtime`,hidden:D!==`runtime`,children:[(0,T.jsx)(`p`,{className:`dc-bot-section-intro`,children:t(`localBotRuntimeHint`)}),(0,T.jsxs)(`fieldset`,{className:`dc-bot-section`,disabled:o,children:[(0,T.jsx)(`legend`,{children:t(`localBotRuntime`)}),(0,T.jsxs)(`div`,{className:`dc-field`,children:[(0,T.jsx)(`label`,{htmlFor:`local-bot-cwd`,children:t(`localBotCwd`)}),(0,T.jsx)(C,{inputId:`local-bot-cwd`,localOnly:!0,commitOnBlur:!0,pathCompletions:e,cwd:i.cwd,baseCwd:A.current||i.cwd,projects:p?.projects.map(e=>({...e,lastUsed:0}))??[],disabled:o,onSelectCwd:e=>a({...i,cwd:M(e,A.current||i.cwd)})})]}),(0,T.jsxs)(`div`,{className:`dc-field`,children:[(0,T.jsx)(`span`,{children:t(`localBotModel`)}),(0,T.jsxs)(`div`,{className:`dc-actions`,children:[(0,T.jsx)(`button`,{className:`dc-button`,type:`button`,"aria-haspopup":`dialog`,onClick:()=>E(!0),children:i.model?V?.name??`${i.model.provider}/${i.model.modelId}`:t(`localBotInheritModel`)}),i.model&&(0,T.jsx)(`button`,{className:`dc-button`,type:`button`,onClick:()=>a({...i,model:void 0}),children:t(`localBotInheritModel`)})]}),i.model&&!V&&(0,T.jsx)(`small`,{children:t(_?`localBotUnverified`:`localBotUnavailable`)})]})]})]}),(0,T.jsxs)(`div`,{role:`tabpanel`,id:`bot-panel-permissions`,"aria-labelledby":`bot-tab-permissions`,hidden:D!==`permissions`,children:[(0,T.jsx)(`p`,{className:`dc-bot-section-intro`,children:t(`localBotPermissionsHint`)}),(0,T.jsxs)(`div`,{className:`dc-bot-options-status`,"aria-live":`polite`,children:[_&&(0,T.jsx)(`span`,{children:t(`localBotOptionsLoading`)}),h&&(0,T.jsx)(`span`,{role:`alert`,children:h}),(0,T.jsx)(`button`,{className:`dc-button`,type:`button`,disabled:_||o,onClick:()=>b(e=>e+1),children:t(h?`deviceHubRetry`:`localBotReload`)})]}),(0,T.jsx)(`div`,{className:`dc-bot-permissions`,children:[[`tools`,t(`localBotTools`)],[`skills`,t(`localBotSkills`)],[`mcpServers`,t(`localBotMcpServers`)]].map(([e,t])=>(0,T.jsx)(N,{title:t,entries:p?.[e]??[],selected:i[e],disabled:o,pending:_||!!h,onChange:t=>a({...i,[e]:t})},e))})]})]}),(0,T.jsxs)(`footer`,{className:`dc-actions dc-bot-editor-footer`,children:[(0,T.jsx)(`button`,{className:`dc-button dc-bot-save`,disabled:o||!i.cwd||!i.name.trim(),children:t(`localBotSave`)}),(0,T.jsx)(`button`,{className:`dc-button`,type:`button`,disabled:o,onClick:()=>{a(null),E(!1)},children:t(`localBotCancel`)}),i.id&&(0,T.jsx)(`button`,{className:`dc-button is-danger`,type:`button`,disabled:o,onClick:()=>{window.confirm(t(`localBotDeleteConfirm`))&&B(!0)},children:t(`localBotDelete`)})]})]})})]}),i&&S&&(0,j.createPortal)((0,T.jsx)(`div`,{className:`modal-backdrop dc-bot-model-backdrop`,onClick:e=>{e.target===e.currentTarget&&E(!1)},children:(0,T.jsxs)(`div`,{className:`dc-bot-model-modal dd-menu-model`,role:`dialog`,"aria-modal":`true`,"aria-label":t(`localBotModel`),children:[(0,T.jsxs)(`div`,{className:`dg-heading`,children:[(0,T.jsx)(`h3`,{children:t(`localBotModel`)}),(0,T.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>E(!1),children:t(`localBotCancel`)})]}),(0,T.jsx)(x,{models:p?.models??[],modelsLoading:_,defaultModel:p?.defaultModel,currentModelId:i.model?`${i.model.provider}/${i.model.modelId}`:null,active:!0,onEnsureModels:()=>{},onRefresh:()=>b(e=>e+1),onPickModel:e=>{a({...i,model:{provider:e.provider,modelId:P(e)}}),E(!1)},isRowActive:e=>e.provider===i.model?.provider&&P(e)===i.model.modelId,extraTopRow:(0,T.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>{a({...i,model:void 0}),E(!1)},children:t(`localBotInheritModel`)}),autoFocusSearch:!0,hideTitle:!0,bodyStyle:{flex:1,minHeight:0},scrollStyle:{overflowY:`auto`,minHeight:0}}),h&&(0,T.jsx)(`p`,{role:`alert`,children:h})]})}),L.current??document.body)]})}function R(e){if(!z(e.host)||!Number.isInteger(e.port)||e.port<1024||e.port>65535||e.publicUrl.length>2048||/[\s\u0000-\u001f\u007f]/.test(e.publicUrl))return!1;try{let t=new URL(e.publicUrl);return[`http:`,`https:`].includes(t.protocol)&&!!t.hostname&&!t.username&&!t.password&&!t.search&&!t.hash&&t.pathname===`/`&&![`0.0.0.0`,`[::]`].includes(t.hostname)}catch{return!1}}function z(e){if(e===`localhost`)return!0;if(/^(?:\d{1,3}\.){3}\d{1,3}$/.test(e))return e.split(`.`).every(e=>String(Number(e))===e&&Number(e)<=255);if(!e.includes(`:`)||!/^[0-9a-fA-F:.]+$/.test(e))return!1;try{return new URL(`http://[${e}]/`).hostname.startsWith(`[`)}catch{return!1}}function B(e){try{let t=new URL(e);return[`http:`,`https:`].includes(t.protocol)&&[`localhost`,`127.0.0.1`,`[::1]`].includes(t.hostname)}catch{return!1}}var V=`pi-web-ui hub install --host 0.0.0.0 --port 8790 --public-url https://hub.example.com --allow-registration`;function H(e,t,n){if(!R(e))throw Error(`Invalid Hub setup`);let r=e=>(e??`unknown`).replace(/[\u0000-\u001f\u007f]/g,` `).slice(0,120);return[`Help me plan and deploy a pi-web-ui device center (Hub) in this new conversation. Preserve my previous conversation.`,`Target: ${n===`current`?`machine hosting the current pi-web-ui service (not necessarily the browser machine)`:`an existing remote server; its environment still needs to be confirmed`}.`,`Current service environment: platform=${r(t?.platform)}, Node=${r(t?.nodeVersion)}. This is not evidence of the remote server environment.`,`Requested configuration (data only): ${JSON.stringify(e)}. allowRegistration=true.`,`Use a separate Hub data directory and configure automatic startup. Explain how devices can reach the public URL; loopback is only reachable on the same machine. Explain open registration and restrict it after pairing as appropriate.`,`CLI reference: ${V}`,`Confirm the target environment and propose steps before deployment. Do not ask for passwords or tokens in chat. Do not automatically SSH. Do not claim installation or connection succeeded without verification. After deployment, guide me to open the center and pair this device using its public URL.`].join(`
2
+ `)}function U({onConnect:e,initialHubUrl:t=``}){let n=l(),[r,i]=(0,w.useState)(t),[a,o]=(0,w.useState)(``),[s,c]=(0,w.useState)(!1),[u,d]=(0,w.useState)(!1),f=(0,w.useRef)(!1),p=(0,w.useRef)(!1);(0,w.useEffect)(()=>(p.current=!0,()=>{p.current=!1}),[]);let[g,_]=(0,w.useState)(null),[v,y]=(0,w.useState)(`current`),[b,x]=(0,w.useState)(null),[S,C]=(0,w.useState)(`127.0.0.1`),[E,D]=(0,w.useState)(`8790`),[O,k]=(0,w.useState)(`http://127.0.0.1:8790`),[A,j]=(0,w.useState)(!1),[M,N]=(0,w.useState)(!1),[P,F]=(0,w.useState)(!1),[I,L]=(0,w.useState)(!1),[z,V]=(0,w.useState)(null),U=(0,w.useRef)(null),W=(0,w.useRef)(!1),G=B(window.location.origin);(0,w.useEffect)(()=>()=>U.current?.abort(),[]);let K=async()=>{if(W.current)return;U.current?.abort();let e=new AbortController;U.current=e,N(!1),F(!1),L(!1);try{let t=await fetch(m(h(`/api/device-center/setup`)),{credentials:`same-origin`,signal:e.signal});if(!t.ok)throw Error();let n=await t.json();if(!n||typeof n.platform!=`string`||typeof n.nodeVersion!=`string`||typeof n.dataDir!=`string`||typeof n.cliPath!=`string`||!R({host:`127.0.0.1`,port:n.defaultPort,publicUrl:n.defaultPublicUrl}))throw Error();if(e.signal.aborted)return;x(n),n.installation?.installed?(C(n.installation.host??`127.0.0.1`),D(String(n.installation.port)),k(n.installation.publicUrl??``),i(n.installation.publicUrl??``)):b||(D(String(n.defaultPort)),k(n.defaultPublicUrl))}catch{e.signal.aborted||(N(!0),L(!0))}finally{e.signal.aborted||F(!0)}},ee=async()=>{let e={host:S,port:Number(E),publicUrl:O};if(W.current||!G||!b||!P||I||b.busy||b.installation?.installed||!R(e))return;W.current=!0,U.current?.abort(),j(!0),N(!1),o(``);let t=new AbortController;U.current=t;try{let n=await fetch(m(h(`/api/device-center/setup`)),{credentials:`same-origin`,method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({...e,allowRegistration:!0}),signal:t.signal});if(n.status===409){x(e=>e&&{...e,busy:!0}),W.current=!1,j(!1),await K();return}if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(typeof e.error==`string`?e.error.slice(0,4096):`HTTP ${n.status}`)}let r=await n.json();if(!R({...e,publicUrl:r.publicUrl})||typeof r.output!=`string`)throw Error();t.signal.aborted||V(r)}catch(e){t.signal.aborted||(N(!0),o(e instanceof Error?e.message.slice(0,4096):``))}finally{W.current=!1,t.signal.aborted||j(!1)}},q=b?.installation,J=!!q?.installed,Y=J&&q.running&&q.owned,te={host:S,port:Number(E),publicUrl:O},X=R(te);return(0,T.jsxs)(`section`,{className:`dc-onboarding`,children:[(0,T.jsx)(`h3`,{children:n(`deviceSetupWelcome`)}),(0,T.jsx)(`p`,{children:n(`deviceSetupIntro`)}),(0,T.jsxs)(`div`,{className:`dc-actions`,children:[(0,T.jsx)(`button`,{className:`dc-button`,disabled:A,"aria-pressed":g===`connect`,onClick:()=>_(`connect`),children:n(`deviceSetupConnect`)}),(0,T.jsx)(`button`,{className:`dc-button`,disabled:A,"aria-pressed":g===`create`,onClick:()=>{_(`create`),!b&&G&&K()},children:n(`deviceSetupCreate`)})]}),g===`connect`&&(0,T.jsxs)(`form`,{onSubmit:t=>{t.preventDefault(),e(r.trim())},children:[(0,T.jsxs)(`label`,{className:`dc-field`,children:[(0,T.jsx)(`span`,{children:n(`deviceHubHubUrl`)}),(0,T.jsx)(`input`,{type:`url`,required:!0,maxLength:2048,value:r,onChange:e=>i(e.target.value),placeholder:`https://hub.example.com`})]}),(0,T.jsx)(`button`,{className:`dc-button is-primary`,disabled:!R({host:`localhost`,port:8790,publicUrl:r.trim()}),children:n(`deviceSetupPair`)})]}),g===`create`&&(0,T.jsxs)(T.Fragment,{children:[(0,T.jsxs)(`label`,{className:`dc-field`,children:[(0,T.jsx)(`span`,{children:n(`deviceSetupTarget`)}),(0,T.jsxs)(`select`,{disabled:A,value:v,onChange:e=>y(e.target.value),children:[(0,T.jsx)(`option`,{value:`current`,children:n(`deviceSetupCurrent`)}),(0,T.jsx)(`option`,{value:`remote`,children:n(`deviceSetupRemote`)}),(0,T.jsx)(`option`,{value:`none`,children:n(`deviceSetupNoServer`)})]})]}),v===`none`?(0,T.jsx)(`p`,{children:n(`deviceSetupNoServerHint`)}):(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`p`,{children:n(v===`current`?`deviceSetupCurrentHint`:`deviceSetupRemoteHint`)}),v===`current`&&(0,T.jsxs)(`div`,{className:`dc-setup-plan`,children:[(0,T.jsx)(`strong`,{children:n(`deviceSetupPlan`)}),(0,T.jsx)(`p`,{children:n(`deviceSetupPlanHint`)}),b&&(0,T.jsxs)(`dl`,{children:[(0,T.jsx)(`dt`,{children:n(`deviceSetupEnvironment`)}),(0,T.jsxs)(`dd`,{children:[b.platform,` · Node `,b.nodeVersion]}),(0,T.jsx)(`dt`,{children:n(`deviceSetupDataDir`)}),(0,T.jsx)(`dd`,{children:b.dataDir}),(0,T.jsx)(`dt`,{children:n(`deviceSetupCli`)}),(0,T.jsx)(`dd`,{children:b.cliPath})]}),!G&&(0,T.jsx)(`p`,{role:`status`,children:n(`deviceSetupLocalOnly`)}),(0,T.jsx)(`p`,{children:n(`deviceSetupBackground`)}),J&&(0,T.jsxs)(`div`,{role:`status`,children:[(0,T.jsx)(`h4`,{children:n(Y?`deviceSetupRestored`:`deviceSetupUnhealthy`)}),(0,T.jsx)(`p`,{children:q.publicUrl}),Y&&X&&q.publicUrl?(0,T.jsxs)(`div`,{className:`dc-actions`,children:[(0,T.jsx)(`a`,{className:`dc-button`,href:q.publicUrl,target:`_blank`,rel:`noopener noreferrer`,children:n(`deviceHubOpenHub`)}),(0,T.jsx)(`button`,{className:`dc-button`,onClick:()=>e(q.publicUrl),children:n(`deviceSetupPair`)})]}):(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`p`,{children:n(`deviceSetupRecovery`)}),(0,T.jsx)(`pre`,{className:`dc-setup-output`,children:`pi-web-ui hub status --json
3
+ pi-web-ui hub --help`})]})]}),b?.busy&&(0,T.jsx)(`p`,{role:`status`,children:n(`deviceSetupBusy`)}),G&&(0,T.jsx)(`button`,{className:`dc-button`,disabled:A||!P,onClick:()=>void K(),children:n(P?`deviceSetupRetry`:`deviceHubWorking`)})]}),(0,T.jsxs)(`div`,{className:`dc-setup-fields`,children:[(0,T.jsxs)(`label`,{className:`dc-field`,children:[(0,T.jsx)(`span`,{children:n(`deviceSetupHost`)}),(0,T.jsx)(`input`,{disabled:A||!!z,maxLength:253,value:S,onChange:e=>C(e.target.value)})]}),(0,T.jsxs)(`label`,{className:`dc-field`,children:[(0,T.jsx)(`span`,{children:n(`deviceSetupPort`)}),(0,T.jsx)(`input`,{disabled:A||!!z,type:`number`,min:1024,max:65535,value:E,onChange:e=>D(e.target.value)})]}),(0,T.jsxs)(`label`,{className:`dc-field`,children:[(0,T.jsx)(`span`,{children:n(`deviceHubHubUrl`)}),(0,T.jsx)(`input`,{disabled:A||!!z,maxLength:2048,value:O,onChange:e=>k(e.target.value)})]})]}),(0,T.jsx)(`p`,{className:`dc-setup-warning`,children:n(`deviceSetupReachable`)}),(0,T.jsx)(`p`,{children:n(`deviceSetupRegistration`)}),!X&&(0,T.jsx)(`p`,{role:`alert`,children:n(`deviceSetupInvalid`)}),v===`remote`&&(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`p`,{children:n(`deviceSetupCliHint`)}),(0,T.jsx)(`pre`,{className:`dc-setup-output`,children:`pi-web-ui hub install --host 0.0.0.0 --port 8790 --public-url https://hub.example.com --allow-registration`})]}),(0,T.jsxs)(`div`,{className:`dc-actions`,children:[v===`current`&&!z&&!J&&(0,T.jsx)(`button`,{className:`dc-button is-primary`,disabled:A||!G||!b||!P||I||!!b.busy||!X,onClick:()=>void ee(),children:n(A?`deviceSetupInstalling`:`deviceSetupInstall`)}),(0,T.jsx)(`button`,{className:`dc-button`,disabled:A||s||!X,onClick:()=>{if(!X||v===`none`||f.current)return;f.current=!0,c(!0),d(!1);let e=e=>{f.current=!1,p.current&&(c(!1),d(!e))},t=window.__piWebUiHost;try{t?.startChat({newChat:!0,prompt:H(te,b,v),onResult:e})||e(!1)}catch{e(!1)}},children:n(`deviceSetupAi`)})]}),(0,T.jsx)(`p`,{children:n(`deviceSetupAiHint`)}),s&&(0,T.jsx)(`p`,{role:`status`,children:n(`deviceSetupAiCreating`)}),u&&(0,T.jsx)(`p`,{role:`alert`,children:n(`deviceSetupAiFailed`)})]})]}),M&&(0,T.jsxs)(`div`,{role:`alert`,children:[(0,T.jsx)(`p`,{children:n(`deviceSetupFailed`)}),a&&(0,T.jsx)(`pre`,{className:`dc-setup-output`,children:a})]}),z&&(0,T.jsxs)(`div`,{role:`status`,children:[(0,T.jsx)(`h4`,{children:n(`deviceSetupSuccess`)}),(0,T.jsx)(`pre`,{className:`dc-setup-output`,children:z.output.slice(0,16e3)}),(0,T.jsxs)(`div`,{className:`dc-actions`,children:[(0,T.jsx)(`a`,{className:`dc-button`,href:z.publicUrl,target:`_blank`,rel:`noopener noreferrer`,children:n(`deviceHubOpenHub`)}),(0,T.jsx)(`button`,{className:`dc-button is-primary`,onClick:()=>e(z.publicUrl),children:n(`deviceSetupPair`)})]})]})]})}function W({hubUrl:e,currentDeviceId:t}){let{locale:r}=d(),i=g(r),[a,o]=(0,w.useState)([]),[s,c]=(0,w.useState)(``),[l,u]=(0,w.useState)(0);(0,w.useEffect)(()=>{let e=!1,t,n;async function r(){t=new AbortController;try{let n=await fetch(m(h(`/api/device-center/devices`)),{signal:AbortSignal.any([t.signal,AbortSignal.timeout(15e3)]),credentials:`same-origin`});if(!n.ok)throw Error(n.status===409?i?`请重新绑定本机以读取设备列表。`:`Pair this computer again to read the device list.`:i?`无法读取设备列表,请重试。`:`Could not load devices. Try again.`);let r=await n.json();if(!Array.isArray(r.devices))throw Error(i?`设备列表格式异常。`:`Invalid device list.`);e||(o(r.devices),c(``))}catch(t){e||(o([]),c(t instanceof Error?t.message:String(t)))}finally{e||(n=setTimeout(r,5e3))}}return r(),()=>{e=!0,t?.abort(),clearTimeout(n)}},[e,t,l,i]);function p(t){try{let n=new URL(e);return![`http:`,`https:`].includes(n.protocol)||n.username||n.password?void 0:new URL(`/device/${encodeURIComponent(t)}`,n).href}catch{return}}async function v(t,n,r=!1){t.preventDefault();let a=window.open(`about:blank`,`_blank`);if(!a){c(i?`请允许弹出窗口后重试。`:`Allow popups and try again.`);return}a.opener=null;try{let t=await fetch(m(h(`/api/device-center/devices/${encodeURIComponent(n)}/open`)),{method:`POST`,headers:{"Content-Type":`application/json`},body:`{}`,credentials:`same-origin`,signal:AbortSignal.timeout(15e3)});if(!t.ok)throw Error(i?`无法打开设备,请确认设备在线且本机绑定有效。`:`Could not open the device. Check connectivity and local pairing.`);let o=await t.json(),s=new URL(o.url);if(![`http:`,`https:`].includes(s.protocol)||s.hostname!==new URL(e).hostname||s.username||s.password||!(s.pathname===`/__device/open`||s.origin===new URL(e).origin&&s.pathname===`/device/${encodeURIComponent(n)}/__open`))throw Error(`Invalid device access URL`);s.searchParams.delete(`next`),r&&s.searchParams.set(`next`,`/desktop`),a.location.replace(s.href),c(``)}catch(e){a.close(),c(e instanceof Error?e.message:String(e))}}return(0,T.jsxs)(`section`,{className:`dc-card`,"aria-label":i?`所有设备`:`All devices`,children:[(0,T.jsxs)(`div`,{className:`dc-card-header`,children:[(0,T.jsx)(`span`,{className:`dc-icon`,children:(0,T.jsx)(_,{"aria-hidden":!0})}),(0,T.jsxs)(`div`,{children:[(0,T.jsxs)(`h2`,{children:[i?`所有设备`:`All devices`,` · `,a.length]}),(0,T.jsx)(`p`,{children:i?`同一账号下的设备,使用本机绑定授权直接访问。`:`Devices in your account. Access is authorized through this computer's pairing.`})]}),(0,T.jsx)(`button`,{type:`button`,className:`dc-icon-button`,"aria-label":i?`刷新设备`:`Refresh devices`,onClick:()=>u(e=>e+1),children:(0,T.jsx)(n,{})})]}),s&&(0,T.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:s}),(0,T.jsx)(`div`,{className:`dd-list`,children:a.map(e=>(0,T.jsxs)(`div`,{className:`dd-device`,children:[(0,T.jsx)(`span`,{className:`dc-device-icon`,children:(0,T.jsx)(_,{"aria-hidden":!0})}),(0,T.jsxs)(`div`,{className:`dd-identity`,children:[(0,T.jsx)(`strong`,{children:e.name}),(0,T.jsx)(`span`,{children:e.id===t?i?`本机`:`This device`:e.id})]}),(0,T.jsx)(`span`,{className:`dc-status ${e.online?`is-online`:`is-offline`}`,children:e.online?i?`在线`:`Online`:i?`离线`:`Offline`}),p(e.id)&&(0,T.jsxs)(`div`,{className:`dc-actions`,children:[(0,T.jsxs)(`a`,{className:`dc-button`,href:p(e.id),target:`_blank`,rel:`noopener noreferrer`,onClick:t=>void v(t,e.id),children:[(0,T.jsx)(f,{"aria-hidden":!0}),i?`打开设备`:`Open device`]}),(0,T.jsxs)(`a`,{className:`dc-button`,href:`${p(e.id)}/desktop`,target:`_blank`,rel:`noopener noreferrer`,onClick:t=>void v(t,e.id,!0),children:[(0,T.jsx)(_,{"aria-hidden":!0}),i?`远程桌面`:`Remote desktop`]})]})]},e.id))})]})}var G=class extends Error{status;constructor(e,t){super(t),this.status=e}};function K(e){try{let t=new URL(e);return[`http:`,`https:`].includes(t.protocol)&&!t.username&&!t.password?t.href:null}catch{return null}}function ee(){let e=l(),t=u().startsWith(`zh`),[r,i]=(0,w.useState)(null),[a,o]=(0,w.useState)(!1),[s,c]=(0,w.useState)(!1),[d,f]=(0,w.useState)(!1),[p,g]=(0,w.useState)(!1),v=(0,w.useRef)(0),y=(0,w.useRef)(null);async function b(e,t){if(y.current)return;let n=++v.current,r=new AbortController;y.current=r,o(!0),c(!1);try{let a=await fetch(m(h(`/api/device-desktop/local/${e}`)),{method:t?`POST`:`GET`,credentials:`same-origin`,signal:r.signal,...t?{headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}:{}});if(v.current!==n||r.signal.aborted)return;if(a.status===403){f(!0),i(null);return}if(!a.ok)throw Error(`Request failed`);let o=await a.json();if(v.current!==n||r.signal.aborted)return;if(e===`permissions`){if(typeof o?.screen!=`boolean`||typeof o?.accessibility!=`boolean`)throw Error(`Invalid permission status`);i(e=>e&&{...e,permissions:{supported:!0,screen:o.screen,accessibility:o.accessibility}}),g(!0)}else{if(typeof o?.os!=`string`||typeof o.enabled!=`boolean`||typeof o.environmentEnabled!=`boolean`||typeof o.supported!=`boolean`)throw Error(`Invalid desktop status`);i(o)}}catch{v.current===n&&!r.signal.aborted&&c(!0)}finally{v.current===n&&!r.signal.aborted&&(y.current=null,o(!1))}}return(0,w.useEffect)(()=>(b(`status`),()=>{v.current++,y.current?.abort(),y.current=null}),[]),(0,T.jsxs)(`section`,{className:`dc-card`,"aria-label":t?`本机远程桌面`:`Local remote desktop`,"aria-busy":a,children:[(0,T.jsxs)(`div`,{className:`dc-card-header`,children:[(0,T.jsx)(`span`,{className:`dc-icon`,children:(0,T.jsx)(_,{"aria-hidden":!0})}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h2`,{children:t?`本机远程桌面`:`Local remote desktop`}),(0,T.jsx)(`p`,{children:t?`管理这台设备的远程桌面与系统权限,无需连接设备中心。`:`Manage remote desktop and system permissions on this device, even while the device center is offline.`})]})]}),d?(0,T.jsx)(`p`,{role:`status`,children:t?`请在设备本机打开此页面以管理远程桌面权限。`:`Open this page on the device itself to manage remote desktop permissions.`}):(0,T.jsxs)(T.Fragment,{children:[r&&(0,T.jsxs)(T.Fragment,{children:[(0,T.jsxs)(`div`,{className:`dc-permission-row`,children:[(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h3`,{id:`dc-desktop-label`,children:t?`启用远程桌面`:`Enable remote desktop`}),(0,T.jsx)(`p`,{children:r.enabled?t?`已启用`:`Enabled`:t?`未启用`:`Disabled`})]}),(0,T.jsx)(`button`,{type:`button`,className:`dc-toggle${r.enabled?` is-on`:``}`,role:`switch`,"aria-checked":r.enabled,"aria-labelledby":`dc-desktop-label`,disabled:a||r.environmentEnabled||!r.supported&&!r.enabled,onClick:()=>void b(`enable`,{enabled:!r.enabled}),children:(0,T.jsx)(`span`,{className:`dc-toggle-thumb`})})]}),!r.supported&&(0,T.jsx)(`p`,{children:t?`这台设备暂不支持远程桌面。`:`Remote desktop is currently unavailable on this device.`}),r.environmentEnabled&&(0,T.jsx)(`p`,{children:t?`远程桌面由本机服务设置保持启用。`:`Remote desktop is kept enabled by the service settings on this device.`}),r.os===`darwin`&&(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`p`,{children:t?`点击下方按钮发起系统授权,请在这台 Mac 的系统设置中确认。授权后可能需要重启服务。`:`Use the buttons below to request system permission, then confirm in System Settings on this Mac. You may need to restart the service afterward.`}),(0,T.jsxs)(`div`,{className:`dc-actions`,children:[(0,T.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:a||r.permissions?.supported===!1,onClick:()=>void b(`permissions`,{kind:`screen`}),children:t?`授予屏幕录制权限`:`Grant screen recording permission`}),(0,T.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:a||r.permissions?.supported===!1,onClick:()=>void b(`permissions`,{kind:`control`}),children:t?`授予远程控制权限`:`Grant remote control permission`})]}),r.permissions?.screen===!0&&(0,T.jsx)(`p`,{children:t?`屏幕录制:已授权`:`Screen recording: granted`}),r.permissions?.accessibility===!0&&(0,T.jsx)(`p`,{children:t?`远程控制:已授权`:`Remote control: granted`}),p&&(0,T.jsx)(`p`,{role:`status`,children:t?`已发起授权请求,请确认系统设置后刷新状态。`:`Permission requested. Confirm in System Settings, then refresh the status.`})]})]}),s&&(0,T.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:t?`无法更新本机远程桌面设置,请重试。`:`Unable to update local remote desktop settings. Please retry.`}),(0,T.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:a,onClick:()=>void b(`status`),children:[(0,T.jsx)(n,{"aria-hidden":!0}),a?e(`deviceHubWorking`):t?`刷新远程桌面状态`:`Refresh remote desktop status`]})]})]})}function q({pathCompletions:e=[]}){let a=l(),u=S(),[d,p]=(0,w.useState)(u.revision?`groups`:`overview`);(0,w.useEffect)(()=>{u.revision&&p(`groups`)},[u.revision]);let[g,v]=(0,w.useState)(null),[y,b]=(0,w.useState)(``),[x,C]=(0,w.useState)(``),[E,D]=(0,w.useState)(null),[O,k]=(0,w.useState)(Date.now()),[j,M]=(0,w.useState)(null),[N,P]=(0,w.useState)(``),[F,I]=(0,w.useState)(``),[R,z]=(0,w.useState)(``),[B,V]=(0,w.useState)(!1),[H,q]=(0,w.useState)(!0),J=(0,w.useRef)(!1),Y=(0,w.useRef)(0),te=(0,w.useRef)(new Set),X=(0,w.useRef)(!1),Z=(0,w.useRef)(!1),ne=(0,w.useRef)(null),re=(0,w.useRef)(a);re.current=a;async function ie(e,t){let n=new AbortController;te.current.add(n);try{let r=await fetch(m(h(`/api/device-center/${e}`)),{method:t?`POST`:`GET`,credentials:`same-origin`,signal:n.signal,...t?{headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}:{}}),i=await r.json().catch(()=>({}));if(!r.ok)throw new G(r.status,typeof i.error==`string`?i.error:re.current(`deviceHubRequestFailed`,{status:r.status}));return i}finally{te.current.delete(n)}}function Q(e){return J.current&&Y.current===e}function ae(e){return e instanceof G&&e.status===403?(V(!0),re.current(`deviceHubLocalOnly`)):e instanceof Error?e.message:re.current(`deviceHubNetworkError`)}function oe(e){ne.current=e,v(e),Z.current||(C(e.name),b(e.hubUrl??``))}async function se(){let e=Y.current;try{let t=await ie(`status`);if(!Q(e)||X.current)return;oe(t),I(``),V(!1)}catch(t){Q(e)&&I(ae(t))}finally{Q(e)&&q(!1)}}(0,w.useEffect)(()=>{J.current=!0;let e=!1,t,n=async()=>{await se(),!e&&J.current&&(t=setTimeout(n,5e3))};return n(),()=>{e=!0,J.current=!1,Y.current++,clearTimeout(t);for(let e of te.current)e.abort()}},[]),(0,w.useEffect)(()=>{if(!E)return;let e=Y.current,t=!1,n,r=setInterval(()=>k(Date.now()),1e3),i=async()=>{if(!(t||!Q(e)||Date.now()>=E.expiresAt)){try{let n=await ie(`poll`,{});if(t||!Q(e))return;if(n.paired){let n=await ie(`status`);if(t||!Q(e))return;Z.current=!1,oe(n),D(null),P(``),z(``);return}P(``)}catch(n){!t&&Q(e)&&P(`${re.current(`deviceHubPollError`)} ${ae(n)}`)}!t&&Q(e)&&(n=setTimeout(i,2e3))}};return n=setTimeout(i,2e3),()=>{t=!0,clearTimeout(n),clearInterval(r)}},[E]);async function ce(){if(X.current)return;let e=K(y.trim());if(!e){P(a(`deviceHubInvalidUrl`));return}if(!x.trim()||x.trim().length>80){P(a(`deviceHubInvalidName`));return}let t=++Y.current;X.current=!0,M(`pair`),P(``),z(``),D(null);try{let n=await ie(`pair`,{hubUrl:e,name:x.trim()});if(!Q(t))return;if(!n.code||!Number.isFinite(n.expiresAt)||!K(n.hubUrl))throw Error(a(`deviceHubPairError`));k(Date.now()),D(n)}catch(e){Q(t)&&P(`${a(`deviceHubPairError`)} ${ae(e)}`)}finally{Q(t)&&(X.current=!1,M(null))}}async function le(){let e=ne.current;if(!e?.deviceId||X.current)return;let t=++Y.current;X.current=!0,M(`permission`),P(``),z(``),oe({...e,allowExecution:!e.allowExecution});try{await ie(`execution`,{allowExecution:!e.allowExecution}),Q(t)&&z(a(`deviceHubSaved`))}catch(n){Q(t)&&(oe(e),P(`${a(`deviceHubPermissionError`)} ${ae(n)}`))}finally{Q(t)&&(X.current=!1,M(null))}}async function ue(){let e=ne.current;if(!e?.deviceId||X.current||!window.confirm(a(`deviceHubDisconnectConfirm`,{name:e.name})))return;let t=++Y.current;X.current=!0,M(`disconnect`),P(``),z(``);try{if(await ie(`disconnect`,{}),!Q(t))return;Z.current=!1,oe({name:e.name,allowExecution:!1,connected:!1}),D(null)}catch(e){Q(t)&&P(`${a(`deviceHubDisconnectError`)} ${ae(e)}`)}finally{Q(t)&&(X.current=!1,M(null))}}async function de(){if(!E)return;let e=Y.current;try{await navigator.clipboard.writeText(E.code),Q(e)&&z(a(`deviceHubCopied`))}catch{Q(e)&&P(a(`deviceHubCopyFailed`))}}let $=!!g?.deviceId,fe=K($?g?.hubUrl??``:E?.hubUrl??``),pe=Math.max(0,Math.ceil(((E?.expiresAt??0)-O)/1e3)),me=`${Math.floor(pe/60)}:${String(pe%60).padStart(2,`0`)}`,he=fe?(0,T.jsxs)(`a`,{className:`dc-button`,href:fe,target:`_blank`,rel:`noopener noreferrer`,children:[(0,T.jsx)(f,{"aria-hidden":!0}),a(`deviceHubOpenHub`)]}):null;return(0,T.jsxs)(`section`,{className:`dc-page`,"aria-label":a(`deviceHubTitle`),children:[(0,T.jsxs)(`header`,{className:`dc-header`,children:[(0,T.jsxs)(`div`,{className:`dc-heading`,children:[(0,T.jsxs)(`span`,{className:`dc-eyebrow`,children:[(0,T.jsx)(_,{"aria-hidden":!0}),a(`deviceHubTitle`)]}),(0,T.jsx)(`h1`,{children:a(`deviceHubTitle`)}),(0,T.jsx)(`p`,{children:a(`deviceHubSubtitle`)})]}),(0,T.jsxs)(`div`,{className:`dc-actions`,children:[$&&he,(0,T.jsxs)(`span`,{className:`dc-status ${$?g?.connected?`is-online`:`is-offline`:`is-unpaired`}`,children:[(0,T.jsx)(`span`,{className:`dc-status-dot`}),a($?g?.connected?`deviceHubOnline`:`deviceHubOffline`:`deviceHubUnpaired`)]})]})]}),(0,T.jsxs)(`div`,{className:`dc-layout`,children:[(0,T.jsxs)(`nav`,{className:`dc-sidebar`,"aria-label":a(`deviceHubTitle`),children:[(0,T.jsxs)(`button`,{type:`button`,className:`dc-nav-item${d===`overview`?` is-active`:``}`,"aria-current":d===`overview`?`page`:void 0,onClick:()=>p(`overview`),children:[(0,T.jsx)(_,{"aria-hidden":!0}),a(`deviceHubOverview`)]}),(0,T.jsxs)(`button`,{type:`button`,className:`dc-nav-item${d===`groups`?` is-active`:``}`,"aria-current":d===`groups`?`page`:void 0,onClick:()=>p(`groups`),children:[(0,T.jsx)(i,{"aria-hidden":!0}),a(`deviceHubGroups`)]}),(0,T.jsxs)(`button`,{type:`button`,className:`dc-nav-item${d===`settings`?` is-active`:``}`,"aria-current":d===`settings`?`page`:void 0,onClick:()=>p(`settings`),children:[(0,T.jsx)(t,{"aria-hidden":!0}),a(`deviceHubSettings`)]})]}),(0,T.jsxs)(`main`,{className:`dc-content`,children:[H&&(0,T.jsxs)(`div`,{className:`dc-loading`,role:`status`,children:[(0,T.jsx)(n,{"aria-hidden":!0}),a(`deviceHubLoading`)]}),(B||F)&&(0,T.jsxs)(`div`,{className:`dc-notice is-error`,role:`alert`,children:[(0,T.jsx)(`span`,{children:B?a(`deviceHubLocalOnly`):`${a(`deviceHubStatusError`)} ${F}`}),(0,T.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>void se(),children:[(0,T.jsx)(n,{"aria-hidden":!0}),a(`deviceHubRetry`)]})]}),N&&!B&&(0,T.jsx)(`div`,{className:`dc-notice is-error`,role:`alert`,children:N}),R&&(0,T.jsxs)(`div`,{className:`dc-notice is-success`,role:`status`,children:[(0,T.jsx)(r,{"aria-hidden":!0}),R]}),!$&&(g||B)&&d===`overview`&&(0,T.jsx)(U,{initialHubUrl:y,onConnect:e=>{if(B){z(a(`deviceHubLocalOnly`));return}Z.current=!0,b(e),p(`settings`)}}),$&&d===`overview`&&(0,T.jsxs)(`section`,{className:`dc-card`,children:[(0,T.jsx)(`h3`,{children:a(`deviceSetupNext`)}),(0,T.jsx)(`p`,{children:a(`deviceSetupNextHint`)}),(0,T.jsx)(`button`,{className:`dc-button is-primary`,onClick:()=>p(`groups`),children:a(`deviceSetupManage`)})]}),d===`settings`&&(0,T.jsx)(ee,{}),g&&!B&&!$&&d===`settings`&&(0,T.jsxs)(`section`,{className:`dc-card`,children:[(0,T.jsxs)(`div`,{className:`dc-card-header`,children:[(0,T.jsx)(`span`,{className:`dc-icon`,children:(0,T.jsx)(t,{"aria-hidden":!0})}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h2`,{children:a(`deviceHubPairTitle`)}),(0,T.jsx)(`p`,{children:a(`deviceHubPairHint`)})]})]}),(0,T.jsx)(`ol`,{className:`dc-steps`,children:[`deviceHubStepDetails`,`deviceHubStepApprove`,`deviceHubStepWait`].map((e,t)=>(0,T.jsxs)(`li`,{className:E?t===0?`is-complete`:`is-active`:t===0?`is-active`:``,children:[(0,T.jsx)(`span`,{className:`dc-step-number`,children:E&&t===0?(0,T.jsx)(r,{"aria-hidden":!0}):t+1}),(0,T.jsx)(`span`,{children:a(e)})]},e))}),(0,T.jsxs)(`form`,{className:`dc-form`,onSubmit:e=>{e.preventDefault(),ce()},children:[(0,T.jsxs)(`div`,{className:`dc-field`,children:[(0,T.jsx)(`label`,{htmlFor:`dc-hub-url`,children:a(`deviceHubHubUrl`)}),(0,T.jsx)(`input`,{id:`dc-hub-url`,type:`url`,autoComplete:`url`,required:!0,placeholder:a(`deviceHubHubPlaceholder`),value:y,disabled:!!E||!!j,onChange:e=>{Z.current=!0,b(e.target.value)}})]}),(0,T.jsxs)(`div`,{className:`dc-field`,children:[(0,T.jsx)(`label`,{htmlFor:`dc-device-name`,children:a(`deviceHubName`)}),(0,T.jsx)(`input`,{id:`dc-device-name`,maxLength:80,required:!0,autoComplete:`off`,placeholder:a(`deviceHubNamePlaceholder`),value:x,disabled:!!E||!!j,onChange:e=>{Z.current=!0,C(e.target.value)}})]}),!E&&(0,T.jsx)(`div`,{className:`dc-actions`,children:(0,T.jsxs)(`button`,{className:`dc-button is-primary`,type:`submit`,disabled:!!j,children:[(0,T.jsx)(t,{"aria-hidden":!0}),a(j?`deviceHubWorking`:`deviceHubGetCode`)]})})]}),E&&(0,T.jsxs)(`div`,{className:`dc-pairing`,children:[(0,T.jsx)(`span`,{className:`dc-code-label`,children:a(`deviceHubCode`)}),(0,T.jsxs)(`div`,{className:`dc-code-row`,children:[(0,T.jsx)(`code`,{className:`dc-code`,children:E.code}),(0,T.jsx)(`button`,{className:`dc-icon-button`,type:`button`,"aria-label":a(`deviceHubCopy`),onClick:()=>void de(),children:(0,T.jsx)(o,{"aria-hidden":!0})})]}),(0,T.jsx)(`div`,{className:`dc-pair-meta`,children:a(pe?`deviceHubExpires`:`deviceHubExpired`,{time:me})}),(0,T.jsxs)(`div`,{className:`dc-actions`,children:[he,(0,T.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:!!j,onClick:()=>{++Y.current,D(null),P(``),z(``)},children:[(0,T.jsx)(n,{"aria-hidden":!0}),a(`deviceHubNewCode`)]})]}),pe>0&&(0,T.jsxs)(`p`,{className:`dc-progress`,role:`status`,children:[(0,T.jsx)(n,{"aria-hidden":!0}),a(`deviceHubWaiting`)]})]})]}),$&&g&&!B&&(0,T.jsxs)(T.Fragment,{children:[d===`overview`&&(0,T.jsxs)(`section`,{className:`dc-card`,children:[(0,T.jsxs)(`div`,{className:`dc-device-summary`,children:[(0,T.jsx)(`span`,{className:`dc-device-icon`,children:(0,T.jsx)(_,{"aria-hidden":!0})}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h2`,{children:g.name}),(0,T.jsx)(`p`,{children:a(`deviceHubDeviceTitle`)})]})]}),(0,T.jsxs)(`dl`,{className:`dc-details`,children:[(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`dt`,{children:a(`deviceHubDeviceId`)}),(0,T.jsx)(`dd`,{children:g.deviceId})]}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`dt`,{children:a(`deviceHubHubUrl`)}),(0,T.jsx)(`dd`,{children:g.hubUrl})]})]})]}),d===`settings`&&(0,T.jsxs)(`section`,{className:`dc-card`,children:[(0,T.jsxs)(`div`,{className:`dc-card-header`,children:[(0,T.jsx)(`span`,{className:`dc-icon`,children:(0,T.jsx)(c,{"aria-hidden":!0})}),(0,T.jsx)(`div`,{children:(0,T.jsx)(`h2`,{children:a(`deviceHubPermissions`)})})]}),(0,T.jsxs)(`div`,{className:`dc-permission-row`,children:[(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h3`,{id:`dc-permission-label`,children:a(`deviceHubPermissionLabel`)}),(0,T.jsx)(`p`,{id:`dc-permission-hint`,children:a(`deviceHubPermissionHint`)})]}),(0,T.jsx)(`button`,{type:`button`,className:`dc-toggle${g.allowExecution?` is-on`:``}`,role:`switch`,"aria-checked":g.allowExecution,"aria-labelledby":`dc-permission-label`,"aria-describedby":`dc-permission-hint`,disabled:!!j,onClick:()=>void le(),children:(0,T.jsx)(`span`,{className:`dc-toggle-thumb`})})]}),(0,T.jsx)(`p`,{className:`dc-permission-state`,role:`status`,children:a(j===`permission`?`deviceHubSaving`:g.allowExecution?`deviceHubEnabled`:`deviceHubReadOnly`)})]}),d===`settings`&&(0,T.jsxs)(`details`,{className:`dc-advanced`,children:[(0,T.jsx)(`summary`,{children:a(`deviceHubAdvanced`)}),(0,T.jsxs)(`div`,{className:`dc-danger-zone`,children:[(0,T.jsx)(`h3`,{children:a(`deviceHubDisconnect`)}),(0,T.jsx)(`p`,{children:a(`deviceHubDisconnectHint`)}),(0,T.jsx)(`button`,{type:`button`,className:`dc-button is-danger`,disabled:!!j,onClick:()=>void ue(),children:a(j===`disconnect`?`deviceHubWorking`:`deviceHubDisconnect`)})]})]})]}),$&&g?.hubUrl&&g.deviceId&&!B&&d!==`groups`&&(0,T.jsx)(W,{hubUrl:g.hubUrl,currentDeviceId:g.deviceId},`directory:${g.hubUrl}:${g.deviceId}`),!B&&(d===`settings`||d===`groups`)&&(0,T.jsx)(L,{pathCompletions:e},`bots:${g?.hubUrl??``}:${g?.deviceId??`unpaired`}`),d===`groups`&&(0,T.jsx)(A,{navigation:u}),(0,T.jsxs)(`aside`,{className:`dc-help`,children:[(0,T.jsx)(s,{className:`dc-help-icon`,"aria-hidden":!0}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h3`,{children:a(`deviceHubHelpTitle`)}),(0,T.jsx)(`p`,{children:a(`deviceHubHelpText`)})]})]})]})]})]})}export{q as DeviceCenter};
@@ -0,0 +1 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{B as t}from"./app-globals-CnO6KlEM.js";import{i as n,r,t as i}from"./react-CR5VJ85Q.js";import{t as a}from"./shortcut-stack-hhrDyRBn.js";var o=r(),s=e(n(),1);function c(e,t,n={}){let{enabled:r=!0,ignore:i}=n,a=(0,s.useRef)(t);(0,s.useLayoutEffect)(()=>{a.current=t}),(0,s.useEffect)(()=>{if(!r)return;let t=(e,t)=>{if(!t)return!1;let n=`current`in t?t.current:t;return n?n.contains(e):!1},n=n=>{let r=n.target;r instanceof Node&&(e.current?.contains(r)||i&&(Array.isArray(i)?i:[i]).some(e=>t(r,e))||a.current(n))};return document.addEventListener(`mousedown`,n),document.addEventListener(`touchstart`,n),()=>{document.removeEventListener(`mousedown`,n),document.removeEventListener(`touchstart`,n)}},[r,e,i])}var l=i();function u({align:e,triggerLeft:t,triggerRight:n,menuWidth:r,viewportWidth:i,margin:a=8}){if(r<=0||i<=0)return 0;let o=e===`left`?t:n-r,s=Math.max(a,i-a-r);return Math.round(Math.max(a,Math.min(o,s))-o)}function d({triggerRect:e,menuWidth:t,menuHeight:n,viewportWidth:r,viewportHeight:i,direction:a=`down`,align:o=`right`,gap:s=6,margin:c=8}){if(t<=0||r<=0||i<=0)return{left:Math.round(e.left),top:Math.round(e.bottom+s)};let l=Math.max(c,r-c-t),u=Math.max(c,i-c-n),d=c,f=c,p,m=Math.max(0,e.top-s-c),h=Math.max(0,i-e.bottom-s-c);if(a===`right`)d=e.right+s,d+t>r-c&&e.left-t-s>=c&&(d=e.left-t-s),d=Math.max(c,Math.min(d,l)),f=e.top,f+n>i-c&&(f=i-c-n),f=Math.max(c,Math.min(f,u)),p=Math.max(0,i-2*c);else if(a===`left`)d=e.left-t-s,d<c&&e.right+s+t<=r-c&&(d=e.right+s),d=Math.max(c,Math.min(d,l)),f=e.top,f+n>i-c&&(f=i-c-n),f=Math.max(c,Math.min(f,u)),p=Math.max(0,i-2*c);else if(a===`up`){m>=n?(f=e.top-n-s,p=m):h>=n||h>m?(f=e.bottom+s,p=h):(p=m,f=e.top-Math.min(n,m)-s);let r=Math.max(c,i-c-Math.min(n,p));f=Math.max(c,Math.min(f,r));let a=o===`left`?e.left:e.right-t;d=Math.max(c,Math.min(a,l))}else{h>=n?(f=e.bottom+s,p=h):m>=n?(f=e.top-n-s,p=m):m>h?(f=e.top-Math.min(n,m)-s,p=m):(f=e.bottom+s,p=h);let r=Math.max(c,i-c-Math.min(n,p));f=Math.max(c,Math.min(f,r));let a=o===`left`?e.left:e.right-t;d=Math.max(c,Math.min(a,l))}return{left:Math.round(d),top:Math.round(f),...p===void 0?{}:{maxHeight:Math.round(p)}}}function f({trigger:e,open:n,onOpenChange:r,children:i,align:f=`right`,fit:p=!1,direction:m=`down`,portal:h=!1,tip:g,caret:_=!0,menuClassName:v,triggerClassName:y,onContextMenu:b,dataBarItem:x,menuRef:S,menuStyle:C,className:w}){let T=(0,s.useRef)(null),E=(0,s.useRef)(null),[D,O]=(0,s.useState)(0),[k,A]=(0,s.useState)(null),j=e=>{E.current=e,typeof S==`function`?S(e):S&&`current`in S&&(S.current=e)},M=()=>{let e=T.current,t=E.current;if(!e||!t)return;if(window.innerWidth<=768){D!==0&&O(0);return}let n=t.getBoundingClientRect(),r=e.getBoundingClientRect();if(r.width===0&&r.height===0||n.width===0){D!==0&&O(0);return}if(h){let e=d({triggerRect:r,menuWidth:n.width,menuHeight:n.height,viewportWidth:window.innerWidth,viewportHeight:window.innerHeight,direction:m,align:f,gap:6,margin:8});A(t=>t?.left===e.left&&t?.top===e.top&&t?.maxHeight===e.maxHeight?t:e)}else{let e=n.width,t=u({align:f,triggerLeft:r.left,triggerRight:r.right,menuWidth:e,viewportWidth:window.innerWidth,margin:8});t!==D&&O(t)}};(0,s.useLayoutEffect)(()=>{n?M():(D!==0&&O(0),k!==null&&A(null))}),(0,s.useEffect)(()=>{if(n)return window.addEventListener(`resize`,M),h&&window.addEventListener(`scroll`,M,!0),()=>{window.removeEventListener(`resize`,M),h&&window.removeEventListener(`scroll`,M,!0)}},[n,D,h,m,f]),c(T,()=>r(!1),{enabled:n,ignore:E}),a(()=>r(!1),n);let N=typeof window<`u`&&window.innerWidth<=768?{...C,pointerEvents:`auto`}:{...C,position:`fixed`,left:k?`${k.left}px`:`-9999px`,top:k?`${k.top}px`:`-9999px`,maxHeight:k?.maxHeight==null?C?.maxHeight:C?.maxHeight==null?`${k.maxHeight}px`:`min(${k.maxHeight}px, ${C.maxHeight})`,right:`auto`,bottom:`auto`,pointerEvents:`auto`,visibility:k?`visible`:`hidden`},P=k!=null&&T.current?k.top<T.current.getBoundingClientRect().top:m===`up`;return(0,l.jsxs)(`div`,{className:`dropdown ${f} ${p?`fit`:``} ${m===`up`?`dd-up`:``} ${w??``}`.trim(),ref:T,children:[(0,l.jsxs)(`button`,{type:`button`,className:y??`chip`,onClick:()=>r(!n),onContextMenu:b,"aria-expanded":n,"data-tip":g,"data-bar-item":x,children:[e,_&&(0,l.jsx)(t,{className:`dd-caret ${n?`up`:``}`})]}),n&&(h?(0,o.createPortal)((0,l.jsx)(`div`,{className:`dd-portal-wrapper dropdown ${f} ${p?`fit`:``} ${P?`dd-up`:``}`,style:{position:`fixed`,left:0,top:0,width:`100%`,height:`100%`,pointerEvents:`none`,zIndex:9999},children:(0,l.jsx)(`div`,{className:`dd-menu ${v??``}`,ref:j,style:N,onPointerDown:e=>e.stopPropagation(),onMouseDown:e=>e.stopPropagation(),onWheel:e=>e.stopPropagation(),children:i})}),document.body):(0,l.jsx)(`div`,{className:`dd-menu ${v??``}`,ref:j,onPointerDown:e=>e.stopPropagation(),onMouseDown:e=>e.stopPropagation(),onWheel:e=>e.stopPropagation(),style:D===0?C:{...C,transform:C?.transform?`${C.transform} translateX(${D}px)`:`translateX(${D}px)`},children:i}))]})}function p({active:e,disabled:t=!1,title:n,onClick:r,children:i}){return(0,l.jsx)(`button`,{type:`button`,className:`dd-item ${e?`active`:``}`,disabled:t,title:n,onClick:r,children:i})}export{p as n,f as t};
@@ -0,0 +1,2 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Dt as t,It as n,L as r,Ot as i,X as a,_n as ee,at as te,g as ne,hn as re,jt as ie,ot as ae,q as oe,qt as se,rt as ce,st as le,t as o,vn as ue,x as de,xn as fe}from"./app-globals-CnO6KlEM.js";import{i as s,t as pe}from"./react-CR5VJ85Q.js";import{K as me,Y as he,dt as ge,gt as _e,mt as ve}from"./index-CPgAH5q7.js";var c=e(s(),1),l=`未命名章节`;function u(e){return String(e??``).trim().replace(/[\s\u3000]+/g,`-`).replace(/[^\p{L}\p{N}_-]+/gu,`-`).replace(/-{2,}/g,`-`).replace(/^-+|-+$/g,``).slice(0,80)||`section`}function ye(e){let t=new Map;return e.map(({level:e,label:n})=>{let r=String(n??``).replace(/\s+/g,` `).trim(),i=u(r||l),a=(t.get(i)??0)+1;return t.set(i,a),{level:e,id:a===1?i:`${i}-${a}`,label:r||l}})}function d(e){return e.length>=2}var f=pe(),p=5e3,be=`pi-web-ui:preview-toc`;function m({file:e,content:s,onAddLines:pe,onAttach:l,onClose:u,uiFilePreviewToolbar:m,onUiAction:xe}){let v=ne(),[y,Se]=(0,c.useState)(null),[b,Ce]=(0,c.useState)(!1),[x,S]=(0,c.useState)(null),[we,Te]=(0,c.useState)(!1),[Ee,De]=(0,c.useState)(!1),[C,w]=(0,c.useState)(!1),[T,E]=(0,c.useState)(``),[D,O]=(0,c.useState)(!0),[k,A]=(0,c.useState)(!0),[j,Oe]=(0,c.useState)(!1),M=(0,c.useRef)(!1),[N,ke]=(0,c.useState)(!0),[P,Ae]=(0,c.useState)(!1),[F,je]=(0,c.useState)(100),I=(0,c.useRef)(0),L=(0,c.useRef)(!1),R=(0,c.useRef)(null),[Me,z]=(0,c.useState)(!1),[Ne,B]=(0,c.useState)(!1),V=(0,c.useRef)(!1),H=(0,c.useRef)(null);(0,c.useEffect)(()=>()=>{R.current&&clearTimeout(R.current),H.current&&clearTimeout(H.current)},[]),(0,c.useEffect)(()=>{Ce(!0),Se(null),S(null),w(!1),E(``),O(!0),A(!0),Oe(!1),M.current=!1,V.current=!1,z(!1),B(!1),H.current&&clearTimeout(H.current),o({type:`read_file`,path:e.path})},[e.path]),(0,c.useEffect)(()=>{s&&s.path===e.path&&(Se(s),C||E(s.text),Ce(!1),V.current&&(V.current=!1,H.current&&clearTimeout(H.current),z(!1),B(!1),w(!1),E(s.text),M.current&&(h(e.name)&&O(!0),_(e.name)&&A(!0)),S(null)))},[s,C,e.path]),(0,c.useEffect)(()=>{let e=e=>{if(e.key===`Escape`){G();return}if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`s`&&C){e.preventDefault(),Ve();return}let t=e.target,n=t&&(t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.isContentEditable);(e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`a`&&!n&&(e.preventDefault(),Le())};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[u,y,C,T]),(0,c.useEffect)(()=>{let e=()=>{L.current=!1,Te(!1)};return window.addEventListener(`mouseup`,e),()=>window.removeEventListener(`mouseup`,e)},[]);let U=(0,c.useMemo)(()=>{if(!y)return[];let e=y.text.split(`
2
+ `);return e.length>0&&e[e.length-1]===``&&e.pop(),e.slice(0,p)},[y]),Pe=y?.lines??0,Fe=Pe>p,Ie=(e,t)=>{if(t){let t=I.current>0?I.current:e;S({start:Math.min(t,e),end:Math.max(t,e)})}else I.current=e,S({start:e,end:e})},Le=()=>{U.length!==0&&(I.current=1,S({start:1,end:U.length}))},Re=()=>{x&&(pe(e.path,e.name,x.start,x.end),De(!0),R.current&&clearTimeout(R.current),R.current=setTimeout(()=>De(!1),1400))},W=y!==null&&y.kind===`text`&&!y.binary&&!y.truncated&&!g(e.name),ze=()=>{V.current=!1,H.current&&clearTimeout(H.current),z(!1),B(!1),E(y?.text??``),w(!1),M.current&&(h(e.name)&&O(!0),_(e.name)&&A(!0))},Be=()=>{if(C){if(T!==(y?.text??``)&&!window.confirm(v(`discardFileChanges`)))return;ze();return}W&&y&&(M.current=h(e.name)&&D||_(e.name)&&k,h(e.name)&&O(!1),_(e.name)&&A(!1),S(null),E(y.text),w(!0))},Ve=()=>{C&&y&&W&&o({type:`write_file`,path:e.path,text:T})&&(V.current=!0,B(!1),z(!0),H.current&&clearTimeout(H.current),H.current=setTimeout(()=>{V.current=!1,z(!1),B(!0)},5e3))},G=()=>{(!C||T===(y?.text??``)||window.confirm(v(`discardFileChanges`)))&&u()},He=e=>{je(Math.min(200,Math.max(50,e)))},Ue=x?x.end-x.start+1:0,K=y?.binary??!1,We=y?.truncated??!1,q=y?.kind??`text`,Ge=h(e.name)||g(e.name),Ke=_(e.name),qe=g(e.name),J=Ge&&D&&!C&&q===`text`&&!K,Y=Ke&&k&&!C&&q===`text`&&!K,[X,Je]=(0,c.useState)(()=>{try{return localStorage.getItem(be)===`1`}catch{return!1}});(0,c.useEffect)(()=>{try{localStorage.setItem(be,X?`1`:`0`)}catch{}},[X]);let[Z,Ye]=(0,c.useState)([]),[Xe,Ze]=(0,c.useState)(``),Q=(0,c.useRef)(null);(0,c.useEffect)(()=>{let e=Q.current;if(!e||!J){Ye([]);return}let t=[...e.querySelectorAll(`h1, h2, h3, h4, h5, h6`)],n=ye(t.map(e=>({level:Number(e.tagName.slice(1)),label:e.textContent??``})));t.forEach((e,t)=>{e.id||=n[t].id}),Ye(n)},[J,y?.text,e.path]),(0,c.useEffect)(()=>{let e=Q.current;if(!e||!X||!d(Z))return;let t=Z.map(t=>e.querySelector(`#${CSS.escape(t.id)}`)).filter(e=>e!==null);if(t.length===0)return;let n=new IntersectionObserver(e=>{let t=e.filter(e=>e.isIntersecting).sort((e,t)=>e.boundingClientRect.top-t.boundingClientRect.top)[0];t?.target.id&&Ze(t.target.id)},{rootMargin:`0px 0px -70% 0px`});for(let e of t)n.observe(e);return()=>n.disconnect()},[Z,X]);let Qe={"host:fp-md":Ge&&q===`text`&&!K&&y?(0,f.jsx)(`button`,{type:`button`,className:`fp-attach markdown ${D?`on`:``}`,"data-tip":v(D?`showMarkdownSource`:`showMarkdownPreview`),disabled:C,onClick:()=>O(e=>!e),children:D?(0,f.jsx)(le,{}):(0,f.jsx)(oe,{})}):null,"host:fp-toc":J&&d(Z)?(0,f.jsx)(`button`,{type:`button`,className:`fp-attach toc ${X?`on`:``}`,"data-tip":v(X?`previewTocHide`:`previewTocShow`),onClick:()=>Je(e=>!e),children:(0,f.jsx)(i,{})}):null,"host:fp-html":Ke&&q===`text`&&!K&&y?(0,f.jsx)(`button`,{type:`button`,className:`fp-attach html ${k?`on`:``}`,"data-tip":v(k?`showHtmlSource`:`showHtmlPreview`),disabled:C,onClick:()=>A(e=>!e),children:k?(0,f.jsx)(oe,{}):(0,f.jsx)(le,{})}):null,"host:fp-edit":q===`text`&&!K&&y?(0,f.jsx)(`button`,{type:`button`,className:`fp-attach edit ${C?`on`:``}`,"data-tip":v(We?`fileEditTruncated`:C?`exitEditFile`:`editFile`),disabled:!W&&!C,onClick:Be,children:(0,f.jsx)(te,{})}):null,"host:fp-wrap":q===`text`&&!K&&!J&&!Y?(0,f.jsx)(`button`,{type:`button`,className:`fp-attach wrap ${N?`on`:``}`,"data-tip":v(N?`disableWrap`:`enableWrap`),onClick:()=>ke(e=>!e),children:(0,f.jsx)(a,{})}):null,"host:fp-zoom":q===`text`&&y?(0,f.jsxs)(`span`,{className:`fp-zoom`,children:[(0,f.jsx)(`button`,{type:`button`,className:`fp-attach zoom-out`,"data-tip":v(`zoomOut`),disabled:F<=50,onClick:()=>He(F-10),children:(0,f.jsx)(ue,{})}),(0,f.jsxs)(`button`,{type:`button`,className:`fp-zoom-val`,title:v(`resetZoom`),onClick:()=>je(100),children:[F,`%`]}),(0,f.jsx)(`button`,{type:`button`,className:`fp-attach zoom-in`,"data-tip":v(`zoomIn`),disabled:F>=200,onClick:()=>He(F+10),children:(0,f.jsx)(ee,{})})]}):null,"host:fp-download":(0,f.jsx)(`button`,{type:`button`,className:`fp-attach download`,"data-tip":v(`downloadFile`),onClick:()=>void ve(e.path,e.name),children:(0,f.jsx)(ce,{})}),"host:fp-ref":(0,f.jsx)(`button`,{type:`button`,className:`fp-attach ref`,"data-tip":v(`referenceTip`),onClick:()=>l(e.path,e.name,`reference`),children:(0,f.jsx)(t,{})}),"host:fp-full":(0,f.jsx)(`button`,{type:`button`,className:`fp-attach full ${P?`on`:``}`,"data-tip":v(P?`exitFullscreen`:`fullscreen`),onClick:()=>Ae(e=>!e),children:P?(0,f.jsx)(n,{}):(0,f.jsx)(ie,{})}),"host:fp-close":null},$e=m===void 0?[`host:fp-md`,`host:fp-toc`,`host:fp-html`,`host:fp-edit`,`host:fp-wrap`,`host:fp-zoom`,`host:fp-download`,`host:fp-ref`,`host:fp-full`].map(e=>({id:e,source:`host`})):m.filter(e=>!e.hidden&&e.id!==`host:fp-close`),$=e=>de(fe(`/api/file?clientId=${encodeURIComponent(he())}&path=${encodeURIComponent(e)}`)),et=e=>{let t=e.split(`/`).map(e=>encodeURIComponent(e)).join(`/`),n=/^[A-Za-z]:([\\/]|$)/.test(e)||e.startsWith(`/`)?`/api/preview/__abs__/${t}`:`/api/preview/${t}`;return de(fe(`${n}?clientId=${encodeURIComponent(he())}${j?`&allowJs=1`:``}`))};return(0,f.jsx)(`div`,{className:`fp-overlay ${P?`fullscreen`:``}`,onMouseDown:e=>{e.target===e.currentTarget&&G()},children:(0,f.jsxs)(`div`,{className:`fp ${P?`fullscreen`:``} ${qe?`is-ppt`:``}`,style:{"--fp-zoom":F/100},children:[(0,f.jsxs)(`div`,{className:`fp-head`,onDoubleClick:e=>{let t=e.target;t&&!t.closest(`button, a, input`)&&Ae(e=>!e)},children:[(0,f.jsx)(`span`,{className:`fp-name`,title:e.path,children:e.name}),(0,f.jsx)(`span`,{className:`fp-path`,children:e.path}),(0,f.jsxs)(`span`,{className:`fp-meta`,children:[y&&q===`text`&&!K&&v(`fileLines`,{n:Pe}),y&&` · ${ge(y.size)}`]}),(0,f.jsx)(`span`,{className:`fp-head-actions`,children:me($e,Qe,xe)}),(0,f.jsx)(`button`,{type:`button`,className:`fp-close`,title:v(`close`),"aria-label":v(`close`),onClick:G,children:(0,f.jsx)(re,{})})]}),We&&q===`text`&&!K&&(0,f.jsx)(`div`,{className:`fp-notice`,children:g(e.name)?v(`previewLinesTruncated`,{n:U.length}):v(`previewTruncated`)}),b&&!y&&(0,f.jsx)(`div`,{className:`fp-empty`,children:v(`loading`)}),!b&&q===`none`&&!K&&(0,f.jsx)(`div`,{className:`fp-empty`,children:v(`previewNotSupported`)}),!b&&q===`image`&&(0,f.jsx)(`div`,{className:`fp-media-wrap clickable`,onClick:G,title:v(`clickToCloseImage`),children:(0,f.jsx)(`img`,{className:`fp-media fp-media-clickable`,src:$(e.path),alt:e.name,onClick:G,title:v(`clickToCloseImage`)})}),!b&&q===`video`&&(0,f.jsx)(`div`,{className:`fp-media-wrap`,children:(0,f.jsx)(`video`,{className:`fp-media`,src:$(e.path),controls:!0,preload:`metadata`})}),!b&&q===`audio`&&(0,f.jsx)(`div`,{className:`fp-media-wrap fp-audio-wrap`,children:(0,f.jsxs)(`div`,{className:`fp-audio-card`,children:[(0,f.jsx)(`div`,{className:`fp-audio-icon`,"aria-hidden":`true`,children:`🎵`}),(0,f.jsxs)(`div`,{className:`fp-audio-info`,children:[(0,f.jsx)(`div`,{className:`fp-audio-name`,title:e.name,children:e.name}),y?.size?(0,f.jsx)(`div`,{className:`fp-audio-size`,children:ge(y.size)}):null]}),(0,f.jsx)(`audio`,{className:`fp-audio-element`,src:$(e.path),controls:!0,autoPlay:!0,preload:`metadata`})]})}),!b&&Y&&y&&(0,f.jsxs)(`div`,{className:`fp-html`,children:[(0,f.jsxs)(`div`,{className:`fp-html-bar`,children:[(0,f.jsx)(`span`,{className:`fp-html-hint`,title:v(j?`htmlJsOnTip`:`htmlJsOffTip`),children:v(j?`htmlJsOn`:`htmlJsOff`)}),(0,f.jsx)(`button`,{type:`button`,className:`fp-html-js ${j?`on`:``}`,"data-tip":v(j?`htmlDisableJs`:`htmlEnableJs`),onClick:()=>Oe(e=>!e),children:v(j?`htmlDisableJs`:`htmlEnableJs`)}),(0,f.jsxs)(`a`,{className:`fp-html-btn fp-html-external`,href:et(e.path),target:`_blank`,rel:`noopener noreferrer`,title:v(`openInNewTab`),children:[(0,f.jsx)(ae,{}),(0,f.jsx)(`span`,{children:v(`openInNewTab`)})]})]}),(0,f.jsx)(`iframe`,{className:`fp-html-frame`,src:et(e.path),title:e.name,sandbox:j?`allow-scripts`:``,referrerPolicy:`no-referrer`},j?`js`:`nojs`)]}),!b&&J&&y&&(0,f.jsx)(`div`,{className:g(e.name)?`fp-markdown msg-text fp-office`:`fp-markdown msg-text`,children:(0,f.jsxs)(`div`,{className:X&&d(Z)?`fp-toc-layout`:void 0,children:[X&&d(Z)&&(0,f.jsx)(`nav`,{className:`fp-toc`,"aria-label":v(`previewTocLabel`),children:Z.map(e=>(0,f.jsx)(`a`,{className:`l${Math.min(e.level,6)}${e.id===Xe?` on`:``}`,href:`#${e.id}`,title:e.label,onClick:t=>{t.preventDefault(),Q.current?.querySelector(`#${CSS.escape(e.id)}`)?.scrollIntoView({behavior:`smooth`,block:`start`})},children:e.label},e.id))}),(0,f.jsx)(`div`,{className:`fp-markdown-zoom`,ref:Q,children:(0,f.jsx)(_e,{text:y.text})})]})}),!b&&K&&q!==`image`&&q!==`video`&&y&&(0,f.jsxs)(`div`,{className:`fp-hex-wrap`,children:[(0,f.jsxs)(`div`,{className:`fp-notice`,children:[v(`binaryFile`),y.truncated&&v(`binaryHexTruncated`)]}),(0,f.jsx)(`pre`,{className:`fp-hex`,children:y.text})]}),!b&&C&&q===`text`&&!K&&y&&(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`textarea`,{className:`fp-editor ${N?``:`no-wrap`}`,value:T,onChange:e=>E(e.target.value),wrap:N?`soft`:`off`,spellCheck:!1,autoFocus:!0}),Ne&&(0,f.jsx)(`div`,{className:`fp-notice`,role:`alert`,children:v(`saveResultUnknown`)})]}),!b&&!J&&!Y&&!C&&q===`text`&&!K&&y&&U.length===0&&(0,f.jsx)(`div`,{className:`fp-empty`,children:v(`emptyFile`)}),!b&&!J&&!Y&&!C&&q===`text`&&!K&&U.length>0&&(0,f.jsxs)(`div`,{className:`fp-code ${we?`dragging`:``} ${N?``:`no-wrap`}`,onMouseDown:e=>{e.button===0&&e.preventDefault()},children:[U.map((e,t)=>{let n=t+1,r=x!==null&&n>=x.start&&n<=x.end;return(0,f.jsxs)(`div`,{className:`fp-line ${r?`sel`:``}`,onMouseDown:e=>{e.button===0&&(Ie(n,e.shiftKey),L.current=!0,Te(!0))},onMouseEnter:()=>{L.current&&Ie(n,!0)},children:[(0,f.jsx)(`span`,{className:`fp-num`,children:n}),(0,f.jsx)(`span`,{className:`fp-code-text`,children:e})]},n)}),Fe&&(0,f.jsx)(`div`,{className:`fp-lines-note`,children:v(`previewLinesTruncated`,{n:p})})]}),(C||!J&&!Y&&q===`text`)&&(0,f.jsx)(`div`,{className:`fp-foot`,children:C?(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`span`,{className:`fp-hint`,children:v(`editFile`)}),(0,f.jsxs)(`div`,{className:`fp-actions`,children:[(0,f.jsx)(`button`,{type:`button`,className:`btn`,onClick:Be,children:v(`cancel`)}),(0,f.jsxs)(`button`,{type:`button`,className:`btn primary`,disabled:Me||T===(y?.text??``),onClick:Ve,children:[(0,f.jsx)(se,{}),` `,v(`saveFile`)]})]})]}):(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`span`,{className:`fp-hint`,children:x?v(`selectedRange`,{n:Ue,start:x.start,end:x.end}):v(`selectLinesHint`)}),(0,f.jsxs)(`div`,{className:`fp-actions`,children:[(0,f.jsx)(`button`,{type:`button`,className:`btn`,disabled:U.length===0,onClick:Le,children:v(`selectAll`)}),(0,f.jsx)(`button`,{type:`button`,className:`btn`,disabled:!x,onClick:()=>S(null),children:v(`clearSelection`)}),(0,f.jsxs)(`button`,{type:`button`,className:`btn primary`,disabled:!x||K,onClick:Re,children:[Ee?(0,f.jsx)(r,{}):null,v(Ee?`addedToChat`:`addToChat`)]})]})]})})]})})}function h(e){let t=e.toLowerCase();return t.endsWith(`.md`)||t.endsWith(`.markdown`)}function g(e){let t=e.toLowerCase();return t.endsWith(`.docx`)||t.endsWith(`.xlsx`)||t.endsWith(`.xlsm`)||t.endsWith(`.pptx`)||t.endsWith(`.pptm`)||t.endsWith(`.ppsx`)||t.endsWith(`.potx`)}function _(e){let t=e.toLowerCase();return t.endsWith(`.html`)||t.endsWith(`.htm`)||t.endsWith(`.xhtml`)}export{m as FilePreview};
@@ -0,0 +1,2 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Dt as t,It as n,L as r,Ot as i,X as a,_n as ee,at as te,g as ne,hn as re,jt as ie,ot as ae,q as oe,qt as se,rt as ce,st as le,t as o,vn as ue,x as de,xn as fe}from"./app-globals-CnO6KlEM.js";import{i as s,t as pe}from"./react-CR5VJ85Q.js";import{K as me,Y as he,dt as ge,gt as _e,mt as ve}from"./index-Cje8iugL.js";var c=e(s(),1),l=`未命名章节`;function u(e){return String(e??``).trim().replace(/[\s\u3000]+/g,`-`).replace(/[^\p{L}\p{N}_-]+/gu,`-`).replace(/-{2,}/g,`-`).replace(/^-+|-+$/g,``).slice(0,80)||`section`}function ye(e){let t=new Map;return e.map(({level:e,label:n})=>{let r=String(n??``).replace(/\s+/g,` `).trim(),i=u(r||l),a=(t.get(i)??0)+1;return t.set(i,a),{level:e,id:a===1?i:`${i}-${a}`,label:r||l}})}function d(e){return e.length>=2}var f=pe(),p=5e3,be=`pi-web-ui:preview-toc`;function m({file:e,content:s,onAddLines:pe,onAttach:l,onClose:u,uiFilePreviewToolbar:m,onUiAction:xe}){let v=ne(),[y,Se]=(0,c.useState)(null),[b,Ce]=(0,c.useState)(!1),[x,S]=(0,c.useState)(null),[we,Te]=(0,c.useState)(!1),[Ee,De]=(0,c.useState)(!1),[C,w]=(0,c.useState)(!1),[T,E]=(0,c.useState)(``),[D,O]=(0,c.useState)(!0),[k,A]=(0,c.useState)(!0),[j,Oe]=(0,c.useState)(!1),M=(0,c.useRef)(!1),[N,ke]=(0,c.useState)(!0),[P,Ae]=(0,c.useState)(!1),[F,je]=(0,c.useState)(100),I=(0,c.useRef)(0),L=(0,c.useRef)(!1),R=(0,c.useRef)(null),[Me,z]=(0,c.useState)(!1),[Ne,B]=(0,c.useState)(!1),V=(0,c.useRef)(!1),H=(0,c.useRef)(null);(0,c.useEffect)(()=>()=>{R.current&&clearTimeout(R.current),H.current&&clearTimeout(H.current)},[]),(0,c.useEffect)(()=>{Ce(!0),Se(null),S(null),w(!1),E(``),O(!0),A(!0),Oe(!1),M.current=!1,V.current=!1,z(!1),B(!1),H.current&&clearTimeout(H.current),o({type:`read_file`,path:e.path})},[e.path]),(0,c.useEffect)(()=>{s&&s.path===e.path&&(Se(s),C||E(s.text),Ce(!1),V.current&&(V.current=!1,H.current&&clearTimeout(H.current),z(!1),B(!1),w(!1),E(s.text),M.current&&(h(e.name)&&O(!0),_(e.name)&&A(!0)),S(null)))},[s,C,e.path]),(0,c.useEffect)(()=>{let e=e=>{if(e.key===`Escape`){G();return}if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`s`&&C){e.preventDefault(),Ve();return}let t=e.target,n=t&&(t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.isContentEditable);(e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`a`&&!n&&(e.preventDefault(),Le())};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[u,y,C,T]),(0,c.useEffect)(()=>{let e=()=>{L.current=!1,Te(!1)};return window.addEventListener(`mouseup`,e),()=>window.removeEventListener(`mouseup`,e)},[]);let U=(0,c.useMemo)(()=>{if(!y)return[];let e=y.text.split(`
2
+ `);return e.length>0&&e[e.length-1]===``&&e.pop(),e.slice(0,p)},[y]),Pe=y?.lines??0,Fe=Pe>p,Ie=(e,t)=>{if(t){let t=I.current>0?I.current:e;S({start:Math.min(t,e),end:Math.max(t,e)})}else I.current=e,S({start:e,end:e})},Le=()=>{U.length!==0&&(I.current=1,S({start:1,end:U.length}))},Re=()=>{x&&(pe(e.path,e.name,x.start,x.end),De(!0),R.current&&clearTimeout(R.current),R.current=setTimeout(()=>De(!1),1400))},W=y!==null&&y.kind===`text`&&!y.binary&&!y.truncated&&!g(e.name),ze=()=>{V.current=!1,H.current&&clearTimeout(H.current),z(!1),B(!1),E(y?.text??``),w(!1),M.current&&(h(e.name)&&O(!0),_(e.name)&&A(!0))},Be=()=>{if(C){if(T!==(y?.text??``)&&!window.confirm(v(`discardFileChanges`)))return;ze();return}W&&y&&(M.current=h(e.name)&&D||_(e.name)&&k,h(e.name)&&O(!1),_(e.name)&&A(!1),S(null),E(y.text),w(!0))},Ve=()=>{C&&y&&W&&o({type:`write_file`,path:e.path,text:T})&&(V.current=!0,B(!1),z(!0),H.current&&clearTimeout(H.current),H.current=setTimeout(()=>{V.current=!1,z(!1),B(!0)},5e3))},G=()=>{(!C||T===(y?.text??``)||window.confirm(v(`discardFileChanges`)))&&u()},He=e=>{je(Math.min(200,Math.max(50,e)))},Ue=x?x.end-x.start+1:0,K=y?.binary??!1,We=y?.truncated??!1,q=y?.kind??`text`,Ge=h(e.name)||g(e.name),Ke=_(e.name),qe=g(e.name),J=Ge&&D&&!C&&q===`text`&&!K,Y=Ke&&k&&!C&&q===`text`&&!K,[X,Je]=(0,c.useState)(()=>{try{return localStorage.getItem(be)===`1`}catch{return!1}});(0,c.useEffect)(()=>{try{localStorage.setItem(be,X?`1`:`0`)}catch{}},[X]);let[Z,Ye]=(0,c.useState)([]),[Xe,Ze]=(0,c.useState)(``),Q=(0,c.useRef)(null);(0,c.useEffect)(()=>{let e=Q.current;if(!e||!J){Ye([]);return}let t=[...e.querySelectorAll(`h1, h2, h3, h4, h5, h6`)],n=ye(t.map(e=>({level:Number(e.tagName.slice(1)),label:e.textContent??``})));t.forEach((e,t)=>{e.id||=n[t].id}),Ye(n)},[J,y?.text,e.path]),(0,c.useEffect)(()=>{let e=Q.current;if(!e||!X||!d(Z))return;let t=Z.map(t=>e.querySelector(`#${CSS.escape(t.id)}`)).filter(e=>e!==null);if(t.length===0)return;let n=new IntersectionObserver(e=>{let t=e.filter(e=>e.isIntersecting).sort((e,t)=>e.boundingClientRect.top-t.boundingClientRect.top)[0];t?.target.id&&Ze(t.target.id)},{rootMargin:`0px 0px -70% 0px`});for(let e of t)n.observe(e);return()=>n.disconnect()},[Z,X]);let Qe={"host:fp-md":Ge&&q===`text`&&!K&&y?(0,f.jsx)(`button`,{type:`button`,className:`fp-attach markdown ${D?`on`:``}`,"data-tip":v(D?`showMarkdownSource`:`showMarkdownPreview`),disabled:C,onClick:()=>O(e=>!e),children:D?(0,f.jsx)(le,{}):(0,f.jsx)(oe,{})}):null,"host:fp-toc":J&&d(Z)?(0,f.jsx)(`button`,{type:`button`,className:`fp-attach toc ${X?`on`:``}`,"data-tip":v(X?`previewTocHide`:`previewTocShow`),onClick:()=>Je(e=>!e),children:(0,f.jsx)(i,{})}):null,"host:fp-html":Ke&&q===`text`&&!K&&y?(0,f.jsx)(`button`,{type:`button`,className:`fp-attach html ${k?`on`:``}`,"data-tip":v(k?`showHtmlSource`:`showHtmlPreview`),disabled:C,onClick:()=>A(e=>!e),children:k?(0,f.jsx)(oe,{}):(0,f.jsx)(le,{})}):null,"host:fp-edit":q===`text`&&!K&&y?(0,f.jsx)(`button`,{type:`button`,className:`fp-attach edit ${C?`on`:``}`,"data-tip":v(We?`fileEditTruncated`:C?`exitEditFile`:`editFile`),disabled:!W&&!C,onClick:Be,children:(0,f.jsx)(te,{})}):null,"host:fp-wrap":q===`text`&&!K&&!J&&!Y?(0,f.jsx)(`button`,{type:`button`,className:`fp-attach wrap ${N?`on`:``}`,"data-tip":v(N?`disableWrap`:`enableWrap`),onClick:()=>ke(e=>!e),children:(0,f.jsx)(a,{})}):null,"host:fp-zoom":q===`text`&&y?(0,f.jsxs)(`span`,{className:`fp-zoom`,children:[(0,f.jsx)(`button`,{type:`button`,className:`fp-attach zoom-out`,"data-tip":v(`zoomOut`),disabled:F<=50,onClick:()=>He(F-10),children:(0,f.jsx)(ue,{})}),(0,f.jsxs)(`button`,{type:`button`,className:`fp-zoom-val`,title:v(`resetZoom`),onClick:()=>je(100),children:[F,`%`]}),(0,f.jsx)(`button`,{type:`button`,className:`fp-attach zoom-in`,"data-tip":v(`zoomIn`),disabled:F>=200,onClick:()=>He(F+10),children:(0,f.jsx)(ee,{})})]}):null,"host:fp-download":(0,f.jsx)(`button`,{type:`button`,className:`fp-attach download`,"data-tip":v(`downloadFile`),onClick:()=>void ve(e.path,e.name),children:(0,f.jsx)(ce,{})}),"host:fp-ref":(0,f.jsx)(`button`,{type:`button`,className:`fp-attach ref`,"data-tip":v(`referenceTip`),onClick:()=>l(e.path,e.name,`reference`),children:(0,f.jsx)(t,{})}),"host:fp-full":(0,f.jsx)(`button`,{type:`button`,className:`fp-attach full ${P?`on`:``}`,"data-tip":v(P?`exitFullscreen`:`fullscreen`),onClick:()=>Ae(e=>!e),children:P?(0,f.jsx)(n,{}):(0,f.jsx)(ie,{})}),"host:fp-close":null},$e=m===void 0?[`host:fp-md`,`host:fp-toc`,`host:fp-html`,`host:fp-edit`,`host:fp-wrap`,`host:fp-zoom`,`host:fp-download`,`host:fp-ref`,`host:fp-full`].map(e=>({id:e,source:`host`})):m.filter(e=>!e.hidden&&e.id!==`host:fp-close`),$=e=>de(fe(`/api/file?clientId=${encodeURIComponent(he())}&path=${encodeURIComponent(e)}`)),et=e=>{let t=e.split(`/`).map(e=>encodeURIComponent(e)).join(`/`),n=/^[A-Za-z]:([\\/]|$)/.test(e)||e.startsWith(`/`)?`/api/preview/__abs__/${t}`:`/api/preview/${t}`;return de(fe(`${n}?clientId=${encodeURIComponent(he())}${j?`&allowJs=1`:``}`))};return(0,f.jsx)(`div`,{className:`fp-overlay ${P?`fullscreen`:``}`,onMouseDown:e=>{e.target===e.currentTarget&&G()},children:(0,f.jsxs)(`div`,{className:`fp ${P?`fullscreen`:``} ${qe?`is-ppt`:``}`,style:{"--fp-zoom":F/100},children:[(0,f.jsxs)(`div`,{className:`fp-head`,onDoubleClick:e=>{let t=e.target;t&&!t.closest(`button, a, input`)&&Ae(e=>!e)},children:[(0,f.jsx)(`span`,{className:`fp-name`,title:e.path,children:e.name}),(0,f.jsx)(`span`,{className:`fp-path`,children:e.path}),(0,f.jsxs)(`span`,{className:`fp-meta`,children:[y&&q===`text`&&!K&&v(`fileLines`,{n:Pe}),y&&` · ${ge(y.size)}`]}),(0,f.jsx)(`span`,{className:`fp-head-actions`,children:me($e,Qe,xe)}),(0,f.jsx)(`button`,{type:`button`,className:`fp-close`,title:v(`close`),"aria-label":v(`close`),onClick:G,children:(0,f.jsx)(re,{})})]}),We&&q===`text`&&!K&&(0,f.jsx)(`div`,{className:`fp-notice`,children:g(e.name)?v(`previewLinesTruncated`,{n:U.length}):v(`previewTruncated`)}),b&&!y&&(0,f.jsx)(`div`,{className:`fp-empty`,children:v(`loading`)}),!b&&q===`none`&&!K&&(0,f.jsx)(`div`,{className:`fp-empty`,children:v(`previewNotSupported`)}),!b&&q===`image`&&(0,f.jsx)(`div`,{className:`fp-media-wrap clickable`,onClick:G,title:v(`clickToCloseImage`),children:(0,f.jsx)(`img`,{className:`fp-media fp-media-clickable`,src:$(e.path),alt:e.name,onClick:G,title:v(`clickToCloseImage`)})}),!b&&q===`video`&&(0,f.jsx)(`div`,{className:`fp-media-wrap`,children:(0,f.jsx)(`video`,{className:`fp-media`,src:$(e.path),controls:!0,preload:`metadata`})}),!b&&q===`audio`&&(0,f.jsx)(`div`,{className:`fp-media-wrap fp-audio-wrap`,children:(0,f.jsxs)(`div`,{className:`fp-audio-card`,children:[(0,f.jsx)(`div`,{className:`fp-audio-icon`,"aria-hidden":`true`,children:`🎵`}),(0,f.jsxs)(`div`,{className:`fp-audio-info`,children:[(0,f.jsx)(`div`,{className:`fp-audio-name`,title:e.name,children:e.name}),y?.size?(0,f.jsx)(`div`,{className:`fp-audio-size`,children:ge(y.size)}):null]}),(0,f.jsx)(`audio`,{className:`fp-audio-element`,src:$(e.path),controls:!0,autoPlay:!0,preload:`metadata`})]})}),!b&&Y&&y&&(0,f.jsxs)(`div`,{className:`fp-html`,children:[(0,f.jsxs)(`div`,{className:`fp-html-bar`,children:[(0,f.jsx)(`span`,{className:`fp-html-hint`,title:v(j?`htmlJsOnTip`:`htmlJsOffTip`),children:v(j?`htmlJsOn`:`htmlJsOff`)}),(0,f.jsx)(`button`,{type:`button`,className:`fp-html-js ${j?`on`:``}`,"data-tip":v(j?`htmlDisableJs`:`htmlEnableJs`),onClick:()=>Oe(e=>!e),children:v(j?`htmlDisableJs`:`htmlEnableJs`)}),(0,f.jsxs)(`a`,{className:`fp-html-btn fp-html-external`,href:et(e.path),target:`_blank`,rel:`noopener noreferrer`,title:v(`openInNewTab`),children:[(0,f.jsx)(ae,{}),(0,f.jsx)(`span`,{children:v(`openInNewTab`)})]})]}),(0,f.jsx)(`iframe`,{className:`fp-html-frame`,src:et(e.path),title:e.name,sandbox:j?`allow-scripts`:``,referrerPolicy:`no-referrer`},j?`js`:`nojs`)]}),!b&&J&&y&&(0,f.jsx)(`div`,{className:g(e.name)?`fp-markdown msg-text fp-office`:`fp-markdown msg-text`,children:(0,f.jsxs)(`div`,{className:X&&d(Z)?`fp-toc-layout`:void 0,children:[X&&d(Z)&&(0,f.jsx)(`nav`,{className:`fp-toc`,"aria-label":v(`previewTocLabel`),children:Z.map(e=>(0,f.jsx)(`a`,{className:`l${Math.min(e.level,6)}${e.id===Xe?` on`:``}`,href:`#${e.id}`,title:e.label,onClick:t=>{t.preventDefault(),Q.current?.querySelector(`#${CSS.escape(e.id)}`)?.scrollIntoView({behavior:`smooth`,block:`start`})},children:e.label},e.id))}),(0,f.jsx)(`div`,{className:`fp-markdown-zoom`,ref:Q,children:(0,f.jsx)(_e,{text:y.text})})]})}),!b&&K&&q!==`image`&&q!==`video`&&y&&(0,f.jsxs)(`div`,{className:`fp-hex-wrap`,children:[(0,f.jsxs)(`div`,{className:`fp-notice`,children:[v(`binaryFile`),y.truncated&&v(`binaryHexTruncated`)]}),(0,f.jsx)(`pre`,{className:`fp-hex`,children:y.text})]}),!b&&C&&q===`text`&&!K&&y&&(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`textarea`,{className:`fp-editor ${N?``:`no-wrap`}`,value:T,onChange:e=>E(e.target.value),wrap:N?`soft`:`off`,spellCheck:!1,autoFocus:!0}),Ne&&(0,f.jsx)(`div`,{className:`fp-notice`,role:`alert`,children:v(`saveResultUnknown`)})]}),!b&&!J&&!Y&&!C&&q===`text`&&!K&&y&&U.length===0&&(0,f.jsx)(`div`,{className:`fp-empty`,children:v(`emptyFile`)}),!b&&!J&&!Y&&!C&&q===`text`&&!K&&U.length>0&&(0,f.jsxs)(`div`,{className:`fp-code ${we?`dragging`:``} ${N?``:`no-wrap`}`,onMouseDown:e=>{e.button===0&&e.preventDefault()},children:[U.map((e,t)=>{let n=t+1,r=x!==null&&n>=x.start&&n<=x.end;return(0,f.jsxs)(`div`,{className:`fp-line ${r?`sel`:``}`,onMouseDown:e=>{e.button===0&&(Ie(n,e.shiftKey),L.current=!0,Te(!0))},onMouseEnter:()=>{L.current&&Ie(n,!0)},children:[(0,f.jsx)(`span`,{className:`fp-num`,children:n}),(0,f.jsx)(`span`,{className:`fp-code-text`,children:e})]},n)}),Fe&&(0,f.jsx)(`div`,{className:`fp-lines-note`,children:v(`previewLinesTruncated`,{n:p})})]}),(C||!J&&!Y&&q===`text`)&&(0,f.jsx)(`div`,{className:`fp-foot`,children:C?(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`span`,{className:`fp-hint`,children:v(`editFile`)}),(0,f.jsxs)(`div`,{className:`fp-actions`,children:[(0,f.jsx)(`button`,{type:`button`,className:`btn`,onClick:Be,children:v(`cancel`)}),(0,f.jsxs)(`button`,{type:`button`,className:`btn primary`,disabled:Me||T===(y?.text??``),onClick:Ve,children:[(0,f.jsx)(se,{}),` `,v(`saveFile`)]})]})]}):(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`span`,{className:`fp-hint`,children:x?v(`selectedRange`,{n:Ue,start:x.start,end:x.end}):v(`selectLinesHint`)}),(0,f.jsxs)(`div`,{className:`fp-actions`,children:[(0,f.jsx)(`button`,{type:`button`,className:`btn`,disabled:U.length===0,onClick:Le,children:v(`selectAll`)}),(0,f.jsx)(`button`,{type:`button`,className:`btn`,disabled:!x,onClick:()=>S(null),children:v(`clearSelection`)}),(0,f.jsxs)(`button`,{type:`button`,className:`btn primary`,disabled:!x||K,onClick:Re,children:[Ee?(0,f.jsx)(r,{}):null,v(Ee?`addedToChat`:`addToChat`)]})]})]})})]})})}function h(e){let t=e.toLowerCase();return t.endsWith(`.md`)||t.endsWith(`.markdown`)}function g(e){let t=e.toLowerCase();return t.endsWith(`.docx`)||t.endsWith(`.xlsx`)||t.endsWith(`.xlsm`)||t.endsWith(`.pptx`)||t.endsWith(`.pptm`)||t.endsWith(`.ppsx`)||t.endsWith(`.potx`)}function _(e){let t=e.toLowerCase();return t.endsWith(`.html`)||t.endsWith(`.htm`)||t.endsWith(`.xhtml`)}export{m as FilePreview};
@@ -0,0 +1 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Pt as t,Vt as n,Yt as r,ft as i,g as a,hn as o,i as s,o as c,pt as l,t as u}from"./app-globals-CnO6KlEM.js";import{i as d,t as f}from"./react-CR5VJ85Q.js";import{b as p,d as m,h,s as g}from"./plugin-host-CqA4yW6w.js";import{R as _}from"./index-CPgAH5q7.js";var v=e(d(),1),y=f();function b(e,t){return e.toLowerCase().includes(t)}function x({open:e,projects:d,fileSearch:f,sessionSearch:x,onClose:S,onSwitchSession:C,onSwitchProject:w,onPreviewFile:T}){let E=a(),D=c(),O=E(`pluginMenuTitle`),k=s(`cwd`),A=(0,v.useRef)(null),[j,M]=(0,v.useState)(``),N=(0,v.useDeferredValue)(j),[P,F]=(0,v.useState)(0),I=(0,v.useRef)(0),L=(0,v.useRef)(null),[R,z]=(0,v.useState)(null);(0,v.useEffect)(()=>{if(!e)return;u({type:`list_sessions`}),u({type:`list_projects`});let t=j.trim();if(t){let e=_();I.current=e,V(!0),u({type:`search_files`,reqId:e,query:t}),u({type:`search_sessions`,reqId:e,query:t})}requestAnimationFrame(()=>A.current?.select())},[e]);let[B,V]=(0,v.useState)(!1);(0,v.useEffect)(()=>{L.current&&clearTimeout(L.current);let e=N.trim();if(!e){V(!1),z(null);return}return L.current=setTimeout(()=>{let t=_();I.current=t,V(!0),u({type:`search_files`,reqId:t,query:e}),u({type:`search_sessions`,reqId:t,query:e})},300),()=>{L.current&&clearTimeout(L.current)}},[N]),(0,v.useEffect)(()=>{f&&f.reqId===I.current&&z(f)},[f]);let H=N.trim().toLowerCase(),U=(0,v.useMemo)(()=>!H||!x||x.reqId!==I.current||!x.ok?[]:x.results,[x,H]),W=(0,v.useMemo)(()=>H?d.filter(e=>b(e.path,H)).slice(0,10):[],[d,H]),G=(0,v.useMemo)(()=>!H||!R||!R.ok?[]:R.results,[R,H]);(0,v.useEffect)(()=>{R&&R.reqId===I.current&&x&&x.reqId===I.current&&I.current!==0&&V(!1)},[R,x]);let K=!!R&&R.ok&&R.truncated,[q,J]=(0,v.useState)([]);(0,v.useEffect)(()=>{if(!e)return;let t=N.trim();if(!t){J([]);return}let n=!1,r=[];try{let e=window,t=e.__piWebUiHost?.searchProviders?.list;if(typeof t==`function`){let n=t.call(e.__piWebUiHost);Array.isArray(n)&&(r=n)}else typeof m==`function`&&(r=m())}catch{r=[]}let i=r.filter(e=>e&&typeof e.id==`string`).map(e=>{if(typeof e.search==`function`)return e;try{let t=g(e.id);return t&&typeof t.search==`function`?{...e,search:t.search}:null}catch{return null}}).filter(e=>!!e);if(i.length===0){J([]);return}return Promise.allSettled(i.map(e=>Promise.race([e.search(t),new Promise((e,t)=>setTimeout(()=>t(Error(`timeout`)),3e3))]).then(t=>({provider:e,items:Array.isArray(t)?t:[]}),()=>({provider:e,items:[]})))).then(e=>{if(n)return;let t=[];for(let n of e)if(n.status===`fulfilled`)for(let e of n.value.items){if(!e||typeof e!=`object`)continue;let r=e;typeof r.title==`string`&&typeof r.action==`string`&&t.push({providerId:n.value.provider.id,providerLabel:n.value.provider.label,title:r.title,...typeof r.hint==`string`?{hint:r.hint}:{},action:r.action})}J(t.slice(0,20))}),()=>{n=!0}},[e,N]);let Y=(0,v.useMemo)(()=>[...U.map(e=>({kind:`session`,path:e.path,anchors:e.anchors})),...W.map(e=>({kind:`project`,path:e.path})),...G.filter(e=>e.type===`file`).map(e=>({kind:`file`,path:e.path,name:e.name})),...q.map(e=>({kind:`plugin`,providerId:e.providerId,providerLabel:e.providerLabel,title:e.title,action:e.action}))],[U,W,G,q]);(0,v.useEffect)(()=>{F(0)},[N]);let X=(0,v.useCallback)(e=>{if(e){if(e.kind===`session`)C(e.path,e.anchors),S();else if(e.kind===`project`){w(e.path),u({type:`list_sessions`}),u({type:`list_projects`});let t=N.trim();if(t){let e=_();I.current=e,V(!0),u({type:`search_files`,reqId:e,query:t}),u({type:`search_sessions`,reqId:e,query:t})}}else e.kind===`plugin`?h(e.providerId,e.action,e.action).catch(()=>{}):T(e.path,e.name)}},[C,w,T,N]);(0,v.useEffect)(()=>{if(!e)return;let t=e=>{e.key===`Escape`?(e.preventDefault(),e.stopPropagation(),S()):e.key===`ArrowDown`?(e.preventDefault(),F(e=>Math.max(0,Math.min(e+1,Y.length-1)))):e.key===`ArrowUp`?(e.preventDefault(),F(e=>Math.max(e-1,0))):e.key===`Enter`&&(e.preventDefault(),X(Y[P]))};return window.addEventListener(`keydown`,t,!0),()=>window.removeEventListener(`keydown`,t,!0)},[Y,P,X,S,e]);let Z=U.length+W.length+G.length+q.length,Q=(e,t,n)=>(0,y.jsxs)(`div`,{className:`gs-section-head`,children:[n,(0,y.jsx)(`span`,{children:e}),(0,y.jsx)(`em`,{children:t})]}),$=-1;return e?(0,y.jsx)(`div`,{className:`modal-backdrop gs-backdrop`,onClick:S,children:(0,y.jsxs)(`div`,{className:`gs-modal`,onClick:e=>e.stopPropagation(),children:[(0,y.jsxs)(`div`,{className:`gs-input-row`,children:[(0,y.jsx)(r,{}),(0,y.jsx)(`input`,{ref:A,type:`text`,value:j,placeholder:E(`gsPlaceholder`),onChange:e=>M(e.target.value)}),(0,y.jsx)(`button`,{type:`button`,className:`gs-close`,title:E(`close`),onClick:S,children:(0,y.jsx)(o,{})})]}),(0,y.jsxs)(`div`,{className:`gs-results`,children:[!H&&(0,y.jsx)(`div`,{className:`gs-empty`,children:E(`gsHint`)}),H&&Z===0&&!K&&(0,y.jsx)(`div`,{className:`gs-empty`,children:E(B?`gsSearching`:`gsNoResults`)}),U.length>0&&(0,y.jsxs)(`div`,{className:`gs-section`,children:[Q(E(`gsSessions`),U.length,(0,y.jsx)(t,{})),U.map(e=>{$++;let t=$,n=e.displayName||e.name||e.firstMessage?.trim()||(e.path.split(/[\\/]/).pop()||e.path).replace(/\.jsonl$/i,``);return(0,y.jsxs)(`div`,{className:`gs-item-wrap`,children:[(0,y.jsxs)(`button`,{type:`button`,className:t===P?`gs-item active`:`gs-item`,onMouseEnter:()=>F(t),onClick:()=>X({kind:`session`,path:e.path,anchors:e.anchors}),children:[(0,y.jsxs)(`span`,{className:`gs-item-title`,children:[n,(0,y.jsx)(`em`,{className:`gs-item-meta`,children:e.messageCount})]}),(0,y.jsx)(`span`,{className:`gs-item-sub`,children:e.firstMessage})]}),D.conversationRef&&(0,y.jsxs)(`button`,{type:`button`,className:`gs-quote`,title:E(`quoteConversation`),onClick:t=>{t.stopPropagation(),p({attachments:[{path:``,key:`conv||${e.path}`,name:n,mode:`conversation`,sessionPath:e.path}]})},children:[`💬 `,E(`quoteConversationShort`)]})]},e.path)})]}),W.length>0&&(0,y.jsxs)(`div`,{className:`gs-section`,children:[Q(E(`gsProjects`),W.length,(0,y.jsx)(l,{})),W.map(e=>{$++;let t=$,n=k&&e.path===k;return(0,y.jsxs)(`button`,{type:`button`,className:t===P?`gs-item active`:`gs-item`,onMouseEnter:()=>F(t),onClick:()=>X({kind:`project`,path:e.path}),children:[(0,y.jsxs)(`span`,{className:`gs-item-title`,children:[e.path.split(/[\\/]/).pop(),n&&(0,y.jsx)(`em`,{className:`gs-item-meta`,children:E(`gsCurrentProject`)})]}),(0,y.jsx)(`span`,{className:`gs-item-sub`,children:e.path})]},e.path)})]}),(G.length>0||H&&K)&&(0,y.jsxs)(`div`,{className:`gs-section`,children:[Q(E(`gsFiles`),G.length,(0,y.jsx)(i,{})),G.map(e=>{$++;let t=$;return(0,y.jsxs)(`button`,{type:`button`,className:t===P?`gs-item active`:`gs-item`,disabled:e.type===`dir`,title:e.type===`dir`?void 0:E(`gsOpenPreview`),onMouseEnter:()=>F(t),onClick:()=>{e.type===`file`&&X({kind:`file`,path:e.path,name:e.name})},children:[(0,y.jsx)(`span`,{className:`gs-item-title`,children:e.name}),(0,y.jsx)(`span`,{className:`gs-item-sub`,children:e.path})]},`${e.type}:${e.path}`)}),K&&(0,y.jsx)(`div`,{className:`gs-truncated`,children:E(`gsTruncated`)})]}),q.length>0&&(0,y.jsxs)(`div`,{className:`gs-section`,children:[Q(O,q.length,(0,y.jsx)(n,{})),q.map((e,t)=>{$++;let n=$;return(0,y.jsxs)(`button`,{type:`button`,className:n===P?`gs-item active`:`gs-item`,title:e.providerLabel,onMouseEnter:()=>F(n),onClick:()=>X({kind:`plugin`,providerId:e.providerId,providerLabel:e.providerLabel,title:e.title,action:e.action}),children:[(0,y.jsx)(`span`,{className:`gs-item-title`,children:e.title}),(0,y.jsx)(`span`,{className:`gs-item-sub`,children:e.hint??e.providerLabel})]},`${e.providerId}:${e.action}:${t}`)})]})]}),(0,y.jsxs)(`div`,{className:`gs-foot`,children:[(0,y.jsxs)(`span`,{children:[`↑↓ `,E(`gsNavigate`)]}),(0,y.jsxs)(`span`,{children:[`Enter `,E(`gsOpen`)]}),(0,y.jsxs)(`span`,{children:[`Esc `,E(`gsCloseHint`)]})]})]})}):null}export{x as GlobalSearchModal};
@@ -0,0 +1 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Pt as t,Vt as n,Yt as r,ft as i,g as a,hn as o,i as s,o as c,pt as l,t as u}from"./app-globals-CnO6KlEM.js";import{i as d,t as f}from"./react-CR5VJ85Q.js";import{b as p,d as m,h,s as g}from"./plugin-host-CqA4yW6w.js";import{R as _}from"./index-Cje8iugL.js";var v=e(d(),1),y=f();function b(e,t){return e.toLowerCase().includes(t)}function x({open:e,projects:d,fileSearch:f,sessionSearch:x,onClose:S,onSwitchSession:C,onSwitchProject:w,onPreviewFile:T}){let E=a(),D=c(),O=E(`pluginMenuTitle`),k=s(`cwd`),A=(0,v.useRef)(null),[j,M]=(0,v.useState)(``),N=(0,v.useDeferredValue)(j),[P,F]=(0,v.useState)(0),I=(0,v.useRef)(0),L=(0,v.useRef)(null),[R,z]=(0,v.useState)(null);(0,v.useEffect)(()=>{if(!e)return;u({type:`list_sessions`}),u({type:`list_projects`});let t=j.trim();if(t){let e=_();I.current=e,V(!0),u({type:`search_files`,reqId:e,query:t}),u({type:`search_sessions`,reqId:e,query:t})}requestAnimationFrame(()=>A.current?.select())},[e]);let[B,V]=(0,v.useState)(!1);(0,v.useEffect)(()=>{L.current&&clearTimeout(L.current);let e=N.trim();if(!e){V(!1),z(null);return}return L.current=setTimeout(()=>{let t=_();I.current=t,V(!0),u({type:`search_files`,reqId:t,query:e}),u({type:`search_sessions`,reqId:t,query:e})},300),()=>{L.current&&clearTimeout(L.current)}},[N]),(0,v.useEffect)(()=>{f&&f.reqId===I.current&&z(f)},[f]);let H=N.trim().toLowerCase(),U=(0,v.useMemo)(()=>!H||!x||x.reqId!==I.current||!x.ok?[]:x.results,[x,H]),W=(0,v.useMemo)(()=>H?d.filter(e=>b(e.path,H)).slice(0,10):[],[d,H]),G=(0,v.useMemo)(()=>!H||!R||!R.ok?[]:R.results,[R,H]);(0,v.useEffect)(()=>{R&&R.reqId===I.current&&x&&x.reqId===I.current&&I.current!==0&&V(!1)},[R,x]);let K=!!R&&R.ok&&R.truncated,[q,J]=(0,v.useState)([]);(0,v.useEffect)(()=>{if(!e)return;let t=N.trim();if(!t){J([]);return}let n=!1,r=[];try{let e=window,t=e.__piWebUiHost?.searchProviders?.list;if(typeof t==`function`){let n=t.call(e.__piWebUiHost);Array.isArray(n)&&(r=n)}else typeof m==`function`&&(r=m())}catch{r=[]}let i=r.filter(e=>e&&typeof e.id==`string`).map(e=>{if(typeof e.search==`function`)return e;try{let t=g(e.id);return t&&typeof t.search==`function`?{...e,search:t.search}:null}catch{return null}}).filter(e=>!!e);if(i.length===0){J([]);return}return Promise.allSettled(i.map(e=>Promise.race([e.search(t),new Promise((e,t)=>setTimeout(()=>t(Error(`timeout`)),3e3))]).then(t=>({provider:e,items:Array.isArray(t)?t:[]}),()=>({provider:e,items:[]})))).then(e=>{if(n)return;let t=[];for(let n of e)if(n.status===`fulfilled`)for(let e of n.value.items){if(!e||typeof e!=`object`)continue;let r=e;typeof r.title==`string`&&typeof r.action==`string`&&t.push({providerId:n.value.provider.id,providerLabel:n.value.provider.label,title:r.title,...typeof r.hint==`string`?{hint:r.hint}:{},action:r.action})}J(t.slice(0,20))}),()=>{n=!0}},[e,N]);let Y=(0,v.useMemo)(()=>[...U.map(e=>({kind:`session`,path:e.path,anchors:e.anchors})),...W.map(e=>({kind:`project`,path:e.path})),...G.filter(e=>e.type===`file`).map(e=>({kind:`file`,path:e.path,name:e.name})),...q.map(e=>({kind:`plugin`,providerId:e.providerId,providerLabel:e.providerLabel,title:e.title,action:e.action}))],[U,W,G,q]);(0,v.useEffect)(()=>{F(0)},[N]);let X=(0,v.useCallback)(e=>{if(e){if(e.kind===`session`)C(e.path,e.anchors),S();else if(e.kind===`project`){w(e.path),u({type:`list_sessions`}),u({type:`list_projects`});let t=N.trim();if(t){let e=_();I.current=e,V(!0),u({type:`search_files`,reqId:e,query:t}),u({type:`search_sessions`,reqId:e,query:t})}}else e.kind===`plugin`?h(e.providerId,e.action,e.action).catch(()=>{}):T(e.path,e.name)}},[C,w,T,N]);(0,v.useEffect)(()=>{if(!e)return;let t=e=>{e.key===`Escape`?(e.preventDefault(),e.stopPropagation(),S()):e.key===`ArrowDown`?(e.preventDefault(),F(e=>Math.max(0,Math.min(e+1,Y.length-1)))):e.key===`ArrowUp`?(e.preventDefault(),F(e=>Math.max(e-1,0))):e.key===`Enter`&&(e.preventDefault(),X(Y[P]))};return window.addEventListener(`keydown`,t,!0),()=>window.removeEventListener(`keydown`,t,!0)},[Y,P,X,S,e]);let Z=U.length+W.length+G.length+q.length,Q=(e,t,n)=>(0,y.jsxs)(`div`,{className:`gs-section-head`,children:[n,(0,y.jsx)(`span`,{children:e}),(0,y.jsx)(`em`,{children:t})]}),$=-1;return e?(0,y.jsx)(`div`,{className:`modal-backdrop gs-backdrop`,onClick:S,children:(0,y.jsxs)(`div`,{className:`gs-modal`,onClick:e=>e.stopPropagation(),children:[(0,y.jsxs)(`div`,{className:`gs-input-row`,children:[(0,y.jsx)(r,{}),(0,y.jsx)(`input`,{ref:A,type:`text`,value:j,placeholder:E(`gsPlaceholder`),onChange:e=>M(e.target.value)}),(0,y.jsx)(`button`,{type:`button`,className:`gs-close`,title:E(`close`),onClick:S,children:(0,y.jsx)(o,{})})]}),(0,y.jsxs)(`div`,{className:`gs-results`,children:[!H&&(0,y.jsx)(`div`,{className:`gs-empty`,children:E(`gsHint`)}),H&&Z===0&&!K&&(0,y.jsx)(`div`,{className:`gs-empty`,children:E(B?`gsSearching`:`gsNoResults`)}),U.length>0&&(0,y.jsxs)(`div`,{className:`gs-section`,children:[Q(E(`gsSessions`),U.length,(0,y.jsx)(t,{})),U.map(e=>{$++;let t=$,n=e.displayName||e.name||e.firstMessage?.trim()||(e.path.split(/[\\/]/).pop()||e.path).replace(/\.jsonl$/i,``);return(0,y.jsxs)(`div`,{className:`gs-item-wrap`,children:[(0,y.jsxs)(`button`,{type:`button`,className:t===P?`gs-item active`:`gs-item`,onMouseEnter:()=>F(t),onClick:()=>X({kind:`session`,path:e.path,anchors:e.anchors}),children:[(0,y.jsxs)(`span`,{className:`gs-item-title`,children:[n,(0,y.jsx)(`em`,{className:`gs-item-meta`,children:e.messageCount})]}),(0,y.jsx)(`span`,{className:`gs-item-sub`,children:e.firstMessage})]}),D.conversationRef&&(0,y.jsxs)(`button`,{type:`button`,className:`gs-quote`,title:E(`quoteConversation`),onClick:t=>{t.stopPropagation(),p({attachments:[{path:``,key:`conv||${e.path}`,name:n,mode:`conversation`,sessionPath:e.path}]})},children:[`💬 `,E(`quoteConversationShort`)]})]},e.path)})]}),W.length>0&&(0,y.jsxs)(`div`,{className:`gs-section`,children:[Q(E(`gsProjects`),W.length,(0,y.jsx)(l,{})),W.map(e=>{$++;let t=$,n=k&&e.path===k;return(0,y.jsxs)(`button`,{type:`button`,className:t===P?`gs-item active`:`gs-item`,onMouseEnter:()=>F(t),onClick:()=>X({kind:`project`,path:e.path}),children:[(0,y.jsxs)(`span`,{className:`gs-item-title`,children:[e.path.split(/[\\/]/).pop(),n&&(0,y.jsx)(`em`,{className:`gs-item-meta`,children:E(`gsCurrentProject`)})]}),(0,y.jsx)(`span`,{className:`gs-item-sub`,children:e.path})]},e.path)})]}),(G.length>0||H&&K)&&(0,y.jsxs)(`div`,{className:`gs-section`,children:[Q(E(`gsFiles`),G.length,(0,y.jsx)(i,{})),G.map(e=>{$++;let t=$;return(0,y.jsxs)(`button`,{type:`button`,className:t===P?`gs-item active`:`gs-item`,disabled:e.type===`dir`,title:e.type===`dir`?void 0:E(`gsOpenPreview`),onMouseEnter:()=>F(t),onClick:()=>{e.type===`file`&&X({kind:`file`,path:e.path,name:e.name})},children:[(0,y.jsx)(`span`,{className:`gs-item-title`,children:e.name}),(0,y.jsx)(`span`,{className:`gs-item-sub`,children:e.path})]},`${e.type}:${e.path}`)}),K&&(0,y.jsx)(`div`,{className:`gs-truncated`,children:E(`gsTruncated`)})]}),q.length>0&&(0,y.jsxs)(`div`,{className:`gs-section`,children:[Q(O,q.length,(0,y.jsx)(n,{})),q.map((e,t)=>{$++;let n=$;return(0,y.jsxs)(`button`,{type:`button`,className:n===P?`gs-item active`:`gs-item`,title:e.providerLabel,onMouseEnter:()=>F(n),onClick:()=>X({kind:`plugin`,providerId:e.providerId,providerLabel:e.providerLabel,title:e.title,action:e.action}),children:[(0,y.jsx)(`span`,{className:`gs-item-title`,children:e.title}),(0,y.jsx)(`span`,{className:`gs-item-sub`,children:e.hint??e.providerLabel})]},`${e.providerId}:${e.action}:${t}`)})]})]}),(0,y.jsxs)(`div`,{className:`gs-foot`,children:[(0,y.jsxs)(`span`,{children:[`↑↓ `,E(`gsNavigate`)]}),(0,y.jsxs)(`span`,{children:[`Enter `,E(`gsOpen`)]}),(0,y.jsxs)(`span`,{children:[`Esc `,E(`gsCloseHint`)]})]})]})}):null}export{x as GlobalSearchModal};
@@ -0,0 +1 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{m as t,x as n,xn as r,y as i}from"./app-globals-CnO6KlEM.js";import{i as a,t as o}from"./react-CR5VJ85Q.js";import{t as s}from"./uuid-BzDIGCwP.js";import{F as c,G as l,O as u,P as d}from"./index-Cje8iugL.js";var f=e(a(),1),p=o(),m=class extends Error{status;code;constructor(e,t,n=``){super(t),this.status=e,this.code=n}};async function h(e,t,i){let a=await fetch(n(r(`/api/device-center/${e}`)),{method:i?`POST`:`GET`,credentials:`same-origin`,signal:t,...i?{headers:{"Content-Type":`application/json`},body:JSON.stringify(i)}:{}}),o=await a.json().catch(()=>({}));if(!a.ok)throw new m(a.status,o.error||String(a.status),o.code??``);return o}var g=new Map,_=()=>{};function v({roomId:e,active:t=!0,onBack:n}){return(0,p.jsx)(y,{roomId:e,active:t,onBack:n},e)}function y({roomId:e,active:n,onBack:r}){let{locale:a}=t(),o=i(a),[v,y]=(0,f.useState)(null),b=v?.bots??[],[x,S]=(0,f.useState)(``),[C,w]=(0,f.useState)(!1),[T,E]=(0,f.useState)(0);function D(e){return e instanceof m&&(e.status===404||e.status===403||e.status===409&&e.code===`REPAIR_REQUIRED`)}function O(e){return e instanceof m&&e.status===409&&e.code===`REPAIR_REQUIRED`?o?`设备绑定已失效,请返回设备设置重新绑定。`:`Device binding expired. Return to device settings and bind again.`:e instanceof Error?e.message:String(e)}let k=(0,f.useRef)(0),A=(0,f.useRef)(null),j=(0,f.useRef)(null),M=(0,f.useRef)(!1);(0,f.useEffect)(()=>{let t=++k.current,r=null,i=!1;async function a(){if(!n||i||document.visibilityState===`hidden`)return;i=!0,r=new AbortController;let a=r.signal;try{let n=await h(`rooms/${encodeURIComponent(e)}`,a);if(k.current!==t||a.aborted)return;y(n),w(!1),S(``)}catch(e){if(k.current!==t||a.aborted)return;D(e)&&(y(null),w(!0)),S(O(e))}finally{i=!1}}a();let o=window.setInterval(()=>void a(),2e3),s=()=>{document.visibilityState===`hidden`?r?.abort():a()};return document.addEventListener(`visibilitychange`,s),()=>{++k.current,r?.abort(),A.current?.abort(),clearInterval(o),document.removeEventListener(`visibilitychange`,s)}},[e,n,T]);let{state:N,labels:P}=(0,f.useMemo)(()=>d(e,v,b,o),[e,v,b,o]),F=b.filter(e=>e.enabled!==!1&&v?.room.botIds.includes(e.id));async function I(t,r){if(!n||C||!v||M.current||r.some(e=>!v.room.botIds.includes(e)))return!1;j.current=c(j.current,e,t,r,s);let i=new AbortController;A.current=i;let a=k.current;M.current=!0;try{return await h(`rooms/${encodeURIComponent(e)}/messages`,i.signal,{text:t,targetBotIds:r,idempotencyKey:j.current.key}),i.signal.aborted||k.current!==a?!1:(j.current=null,S(``),E(e=>e+1),!0)}catch(e){return!i.signal.aborted&&k.current===a&&(D(e)&&(y(null),w(!0)),S(O(e))),!1}finally{A.current===i&&(M.current=!1,A.current=null)}}return(0,p.jsxs)(p.Fragment,{children:[(0,p.jsxs)(`div`,{className:`dg-head`,children:[(0,p.jsx)(`strong`,{children:v?.room.name??(o?`群聊`:`Group`)}),r&&(0,p.jsx)(`button`,{type:`button`,className:`btn`,onClick:r,children:o?`返回对话`:`Back to chat`})]}),x&&(0,p.jsxs)(`div`,{role:`alert`,children:[x,C?o?`此群聊已删除或你已不在群中,请返回。`:`This group is unavailable or you are no longer a member. Return to chat.`:x]}),(0,p.jsx)(l,{state:N,liveOutputs:g,toolStatuses:g,messageLabels:P,readOnly:!0}),(0,p.jsx)(u,{groupDevices:F,onGroupSend:I,streaming:!1,messages:N.messages,slashCommands:[],modelState:null,models:[],modelsLoading:!1,attachments:[],onRemoveAttachment:_,onAddImageFiles:_,onAddLocalFiles:_,onNotice:(e,t)=>S(t),onSent:_,onManageModels:_,providerKeys:{},quickPhrases:[],quickPhrasesEnabled:!1,groupReady:n&&!!v&&!C,sessionId:`device-group:${e}`,conversationId:`device-group:${e}`})]})}export{v as GroupConversation};
@@ -0,0 +1 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{m as t,x as n,xn as r,y as i}from"./app-globals-CnO6KlEM.js";import{i as a,t as o}from"./react-CR5VJ85Q.js";import{t as s}from"./uuid-BzDIGCwP.js";import{F as c,G as l,O as u,P as d}from"./index-CPgAH5q7.js";var f=e(a(),1),p=o(),m=class extends Error{status;code;constructor(e,t,n=``){super(t),this.status=e,this.code=n}};async function h(e,t,i){let a=await fetch(n(r(`/api/device-center/${e}`)),{method:i?`POST`:`GET`,credentials:`same-origin`,signal:t,...i?{headers:{"Content-Type":`application/json`},body:JSON.stringify(i)}:{}}),o=await a.json().catch(()=>({}));if(!a.ok)throw new m(a.status,o.error||String(a.status),o.code??``);return o}var g=new Map,_=()=>{};function v({roomId:e,active:t=!0,onBack:n}){return(0,p.jsx)(y,{roomId:e,active:t,onBack:n},e)}function y({roomId:e,active:n,onBack:r}){let{locale:a}=t(),o=i(a),[v,y]=(0,f.useState)(null),b=v?.bots??[],[x,S]=(0,f.useState)(``),[C,w]=(0,f.useState)(!1),[T,E]=(0,f.useState)(0);function D(e){return e instanceof m&&(e.status===404||e.status===403||e.status===409&&e.code===`REPAIR_REQUIRED`)}function O(e){return e instanceof m&&e.status===409&&e.code===`REPAIR_REQUIRED`?o?`设备绑定已失效,请返回设备设置重新绑定。`:`Device binding expired. Return to device settings and bind again.`:e instanceof Error?e.message:String(e)}let k=(0,f.useRef)(0),A=(0,f.useRef)(null),j=(0,f.useRef)(null),M=(0,f.useRef)(!1);(0,f.useEffect)(()=>{let t=++k.current,r=null,i=!1;async function a(){if(!n||i||document.visibilityState===`hidden`)return;i=!0,r=new AbortController;let a=r.signal;try{let n=await h(`rooms/${encodeURIComponent(e)}`,a);if(k.current!==t||a.aborted)return;y(n),w(!1),S(``)}catch(e){if(k.current!==t||a.aborted)return;D(e)&&(y(null),w(!0)),S(O(e))}finally{i=!1}}a();let o=window.setInterval(()=>void a(),2e3),s=()=>{document.visibilityState===`hidden`?r?.abort():a()};return document.addEventListener(`visibilitychange`,s),()=>{++k.current,r?.abort(),A.current?.abort(),clearInterval(o),document.removeEventListener(`visibilitychange`,s)}},[e,n,T]);let{state:N,labels:P}=(0,f.useMemo)(()=>d(e,v,b,o),[e,v,b,o]),F=b.filter(e=>e.enabled!==!1&&v?.room.botIds.includes(e.id));async function I(t,r){if(!n||C||!v||M.current||r.some(e=>!v.room.botIds.includes(e)))return!1;j.current=c(j.current,e,t,r,s);let i=new AbortController;A.current=i;let a=k.current;M.current=!0;try{return await h(`rooms/${encodeURIComponent(e)}/messages`,i.signal,{text:t,targetBotIds:r,idempotencyKey:j.current.key}),i.signal.aborted||k.current!==a?!1:(j.current=null,S(``),E(e=>e+1),!0)}catch(e){return!i.signal.aborted&&k.current===a&&(D(e)&&(y(null),w(!0)),S(O(e))),!1}finally{A.current===i&&(M.current=!1,A.current=null)}}return(0,p.jsxs)(p.Fragment,{children:[(0,p.jsxs)(`div`,{className:`dg-head`,children:[(0,p.jsx)(`strong`,{children:v?.room.name??(o?`群聊`:`Group`)}),r&&(0,p.jsx)(`button`,{type:`button`,className:`btn`,onClick:r,children:o?`返回对话`:`Back to chat`})]}),x&&(0,p.jsxs)(`div`,{role:`alert`,children:[x,C?o?`此群聊已删除或你已不在群中,请返回。`:`This group is unavailable or you are no longer a member. Return to chat.`:x]}),(0,p.jsx)(l,{state:N,liveOutputs:g,toolStatuses:g,messageLabels:P,readOnly:!0}),(0,p.jsx)(u,{groupDevices:F,onGroupSend:I,streaming:!1,messages:N.messages,slashCommands:[],modelState:null,models:[],modelsLoading:!1,attachments:[],onRemoveAttachment:_,onAddImageFiles:_,onAddLocalFiles:_,onNotice:(e,t)=>S(t),onSent:_,onManageModels:_,providerKeys:{},quickPhrases:[],quickPhrasesEnabled:!1,groupReady:n&&!!v&&!C,sessionId:`device-group:${e}`,conversationId:`device-group:${e}`})]})}export{v as GroupConversation};
@@ -0,0 +1,2 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$ as t,Gt as n,L as r,S as i,Wt as a,Y as o,Yt as s,cn as c,g as ee,gn as l,hn as u,rt as d,t as f}from"./app-globals-CnO6KlEM.js";import{i as p,t as te}from"./react-CR5VJ85Q.js";import{t as ne}from"./ProviderOAuthControls-VK_jqXYS.js";var m=e(p(),1);function re(e,t,n){if(JSON.stringify(e)===JSON.stringify(t))return n;let r=new Map(t.map(e=>[e.id,e])),i=new Map(n.map(e=>[e.id,e])),a=new Set(e.map(e=>e.id)),o=e.flatMap(e=>{let t=r.get(e.id);if(!t||JSON.stringify(t)!==JSON.stringify(e))return[e];let n=i.get(e.id);return n?[n]:[]});for(let e of n)!r.has(e.id)&&!a.has(e.id)&&o.push(e);return o}var h=te(),ie=[`openai-completions`,`openai-responses`,`anthropic-messages`,`google-generative-ai`],ae=[{id:`magpie`,name:`Magpie`,api:`openai-completions`,baseUrl:`http://127.0.0.1:3425/v1`,authHeader:!0,apiKey:`magpie`},{id:`deepseek`,name:`DeepSeek`,api:`openai-completions`,baseUrl:`https://api.deepseek.com/v1`,authHeader:!0,tag:`官方`},{id:`openrouter`,name:`OpenRouter`,api:`openai-completions`,baseUrl:`https://openrouter.ai/api/v1`,authHeader:!0,tag:`聚合`},{id:`moonshot`,name:`Moonshot (Kimi)`,api:`openai-completions`,baseUrl:`https://api.moonshot.cn/v1`,authHeader:!0,tag:`官方`},{id:`zhipu`,name:`智谱 GLM`,api:`openai-completions`,baseUrl:`https://open.bigmodel.cn/api/paas/v4`,authHeader:!0,tag:`官方`},{id:`siliconflow`,name:`硅基流动`,api:`openai-completions`,baseUrl:`https://api.siliconflow.cn/v1`,authHeader:!0,tag:`云端`},{id:`ollama`,name:`Ollama`,api:`openai-completions`,baseUrl:`http://127.0.0.1:11434/v1`,authHeader:!0,tag:`本地`},{id:`vllm`,name:`vLLM / LM Studio`,api:`openai-completions`,baseUrl:`http://127.0.0.1:8000/v1`,authHeader:!0,tag:`本地`},{id:`antigravity`,name:`Antigravity (OpenAI)`,api:`openai-completions`,baseUrl:`http://127.0.0.1:8045/v1`,authHeader:!0,tag:`反代`},{id:`antigravity-anthropic`,name:`Antigravity (Anthropic)`,api:`anthropic-messages`,baseUrl:`http://127.0.0.1:8045`,authHeader:!0,tag:`反代`}],g=[{label:`8K`,value:`8192`},{label:`16K`,value:`16384`},{label:`32K`,value:`32768`},{label:`64K`,value:`65536`},{label:`128K`,value:`131072`},{label:`200K`,value:`200000`},{label:`1M`,value:`1000000`}],_=[{label:`2K`,value:`2048`},{label:`4K`,value:`4096`},{label:`8K`,value:`8192`},{label:`16K`,value:`16384`},{label:`32K`,value:`32768`},{label:`64K`,value:`65536`}];function oe(e,t){switch(e){case`官方`:return t(`presetTagOfficial`);case`聚合`:return t(`presetTagAggregator`);case`云端`:return t(`presetTagCloud`);case`本地`:return t(`presetTagLocal`);case`反代`:return t(`presetTagProxy`);default:return e}}var v=()=>({id:``,name:``,reasoning:!1,input:`text`,contextWindow:``,maxTokens:``}),y=()=>({providerId:``,name:``,api:`openai-completions`,baseUrl:``,apiKey:``,hasApiKey:!1,authHeader:!0,models:[v()]});function b(e){return{providerId:e.providerId,name:e.name??``,api:e.api??`openai-completions`,baseUrl:e.baseUrl??``,apiKey:``,hasApiKey:e.hasApiKey??!1,authHeader:e.authHeader??!1,models:(e.models.length?e.models:[v()]).map(e=>({id:e.id,name:e.name??``,reasoning:e.reasoning??!1,input:e.input?.includes(`image`)?`text-image`:`text`,contextWindow:e.contextWindow?String(e.contextWindow):``,maxTokens:e.maxTokens?String(e.maxTokens):``,...e.thinkingLevelMap?{thinkingLevelMap:e.thinkingLevelMap}:{}}))}}function se(e){let t={};for(let n of e.split(`
2
+ `)){let e=n.indexOf(`=`);if(e<=0)continue;let r=n.slice(0,e).trim(),i=n.slice(e+1).trim();r&&i&&(t[r]=i)}return t}function ce({candidates:e,preselectedIds:t,onAdopt:n,onClose:r}){let i=ee(),[a,o]=(0,m.useState)(``),[c,d]=(0,m.useState)(()=>{let n=new Set(e.map(e=>e.id)),r=(t??[]).map(e=>e.trim()).filter(e=>n.has(e));if(r.length>0)return new Set(r);let i=new Set;for(let t of e){let e=t.id.toLowerCase();!e.includes(`embed`)&&!e.includes(`audio`)&&!e.includes(`tts`)&&!e.includes(`whisper`)&&i.add(t.id)}if(i.size===0)for(let t of e)i.add(t.id);return i}),f=(0,m.useMemo)(()=>{let t=a.trim().toLowerCase();return t?e.filter(e=>e.id.toLowerCase().includes(t)||e.name&&e.name.toLowerCase().includes(t)):e},[e,a]),p=e=>{d(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,h.jsx)(`div`,{className:`candidate-picker-backdrop`,onClick:r,children:(0,h.jsxs)(`div`,{className:`candidate-picker-modal`,onClick:e=>e.stopPropagation(),children:[(0,h.jsxs)(`div`,{className:`candidate-header`,children:[(0,h.jsxs)(`div`,{className:`candidate-title-group`,children:[(0,h.jsx)(`span`,{className:`candidate-title`,children:i(`candidatePickerTitle`)}),(0,h.jsx)(`span`,{className:`candidate-subtitle`,children:i(`candidatePickerSubtitle`,{n:e.length})})]}),(0,h.jsx)(`button`,{type:`button`,className:`iconbtn`,onClick:r,"aria-label":i(`close`),children:(0,h.jsx)(u,{})})]}),(0,h.jsxs)(`div`,{className:`candidate-filter-bar`,children:[(0,h.jsx)(s,{style:{color:`var(--text-faint)`,flexShrink:0}}),(0,h.jsx)(`input`,{type:`text`,className:`candidate-search-input`,placeholder:i(`searchCandidatePlaceholder`),value:a,onChange:e=>o(e.target.value),autoFocus:!0}),(0,h.jsxs)(`div`,{style:{display:`flex`,gap:6,flexShrink:0},children:[(0,h.jsx)(`button`,{type:`button`,className:`btn sm`,onClick:()=>{d(new Set(f.map(e=>e.id)))},children:i(`selectAll`)}),(0,h.jsx)(`button`,{type:`button`,className:`btn sm`,onClick:()=>{d(new Set)},children:i(`deselectAll`)})]})]}),(0,h.jsxs)(`div`,{className:`candidate-list-scroll`,children:[f.length===0&&(0,h.jsx)(`div`,{style:{padding:`32px 0`,textAlign:`center`,color:`var(--text-faint)`,fontSize:13},children:i(`noCandidateMatches`)}),f.map(e=>{let t=c.has(e.id);return(0,h.jsxs)(`div`,{className:`candidate-item-card ${t?`selected`:``}`,onClick:()=>p(e.id),children:[(0,h.jsxs)(`div`,{className:`candidate-item-left`,children:[(0,h.jsx)(`input`,{type:`checkbox`,className:`candidate-checkbox`,checked:t,onChange:()=>{},onClick:e=>e.stopPropagation()}),(0,h.jsxs)(`div`,{className:`candidate-id-info`,children:[(0,h.jsx)(`span`,{className:`candidate-id-name`,children:e.id}),e.name&&e.name!==e.id&&(0,h.jsx)(`span`,{style:{fontSize:11.5,color:`var(--text-dim)`},children:e.name})]})]}),(0,h.jsxs)(`div`,{className:`candidate-item-meta`,children:[e.contextWindow&&(0,h.jsx)(`span`,{className:`spec-badge ctx`,title:i(`contextWindowTooltip`),children:e.contextWindow>=1e6?`${Math.round(e.contextWindow/1e6)}M`:`${Math.round(e.contextWindow/1024)}K`}),e.reasoning&&(0,h.jsxs)(`span`,{className:`spec-badge reasoning`,title:i(`reasoningTooltip`),children:[(0,h.jsx)(l,{}),` `,i(`reasoning`)]}),e.input?.includes(`image`)&&(0,h.jsx)(`span`,{className:`spec-badge vision`,title:i(`visionTooltip`),children:i(`vision`)})]})]},e.id)})]}),(0,h.jsxs)(`div`,{className:`candidate-actions-footer`,children:[(0,h.jsx)(`span`,{className:`candidate-select-summary`,children:i(`selectedCandidatesCount`,{count:c.size,total:e.length})}),(0,h.jsxs)(`div`,{style:{display:`flex`,gap:8},children:[(0,h.jsx)(`button`,{type:`button`,className:`btn`,onClick:r,children:i(`cancel`)}),(0,h.jsx)(`button`,{type:`button`,className:`btn primary`,disabled:c.size===0,onClick:()=>{n(e.filter(e=>c.has(e.id)))},children:i(`adoptSelectedModels`,{count:c.size})})]})]})]})})}function x({providers:e,providerStatus:s,providerKeys:l,providerOAuthFlows:p,providerOAuthResults:te,fetchModelsResult:x,testModelConnectionResult:S,enrichModelsResult:C,enrichModelsProgress:le,cloneProviderResult:w,refreshBuiltinResult:T,refreshProviderResult:E,appendBuiltinResult:D,defaultModel:O,onClose:k}){let A=ee(),[j,M]=(0,m.useState)(()=>e.length>0?{type:`custom`,id:e[0].providerId}:s.length>0?{type:`builtin`,id:s[0].id}:{type:`custom`,id:``}),[N,P]=(0,m.useState)(()=>e.length>0?b(e[0]):s.length>0?null:y()),ue=(0,m.useRef)(e);(0,m.useEffect)(()=>{let t=ue.current;ue.current=e,P(n=>{if(!n)return n;let r=e.find(e=>e.providerId===n.providerId),i=t.find(e=>e.providerId===n.providerId);return!r||r===i?n:{...n,hasApiKey:r.hasApiKey??!1,models:re(n.models,i?b(i).models:[],b(r).models)}})},[e]);let[de,fe]=(0,m.useState)(null),[pe,me]=(0,m.useState)(!1),[he,ge]=(0,m.useState)(0),[F,I]=(0,m.useState)(null),_e=(0,m.useRef)(0),[L,ve]=(0,m.useState)({}),[ye,be]=(0,m.useState)({}),[R,z]=(0,m.useState)(null),xe=(0,m.useRef)(l),B=(0,m.useRef)(null);(0,m.useEffect)(()=>{let e=R;e&&l[e]!==xe.current[e]&&(z(null),ve(t=>({...t,[e]:``})),be(t=>({...t,[e]:``})),B.current&&clearTimeout(B.current)),xe.current=l},[l,R]),(0,m.useEffect)(()=>()=>{B.current&&clearTimeout(B.current)},[]);let[V,Se]=(0,m.useState)(!1),[Ce,we]=(0,m.useState)(0),[H,U]=(0,m.useState)(null),Te=(0,m.useRef)(0),[W,Ee]=(0,m.useState)(!1),[G,K]=(0,m.useState)(!1),[De,Oe]=(0,m.useState)(0),[q,J]=(0,m.useState)(null),[ke,Ae]=(0,m.useState)([]),[je]=(0,m.useState)(``),Me=(0,m.useRef)(0),[Y,Ne]=(0,m.useState)(!1),[Pe,Fe]=(0,m.useState)(0),[X,Ie]=(0,m.useState)(null),Le=(0,m.useRef)(0),[Re,ze]=(0,m.useState)(null),[Be,Ve]=(0,m.useState)(``),[He,Ue]=(0,m.useState)(``),[We,Ge]=(0,m.useState)(``),[Ke,qe]=(0,m.useState)(``),[Je,Ye]=(0,m.useState)(!1),[Xe,Ze]=(0,m.useState)(0),[Qe,Z]=(0,m.useState)(null),$e=(0,m.useRef)(0),[et,tt]=(0,m.useState)(null),[nt,rt]=(0,m.useState)(``),[it,at]=(0,m.useState)(null),[ot,st]=(0,m.useState)({}),ct=(0,m.useRef)(0),lt=(0,m.useRef)(0),[ut,Q]=(0,m.useState)(null),dt=(0,m.useRef)(0),ft=(0,m.useRef)(0),pt=e=>{if(ot[e])return;let t=++ct.current+Date.now();st(t=>({...t,[e]:!0})),f({type:`refresh_provider_models`,providerId:e,reqId:t})};(0,m.useEffect)(()=>{E&&E.reqId!==lt.current&&(lt.current=E.reqId,st({}))},[E]);let mt=e=>{if(ut)return;Q(e.id);let t=++dt.current+Date.now();f({type:`clone_provider`,provider:e.id,reqId:t})||Q(null)};(0,m.useEffect)(()=>{f({type:`list_models_config`}),f({type:`list_providers`}),f({type:`list_provider_keys`}),f({type:`list_provider_oauth_flows`})},[]),(0,m.useEffect)(()=>{S&&S.reqId!==_e.current&&(_e.current=S.reqId,me(!1),I({ok:S.ok,latencyMs:S.latencyMs,error:S.error}))},[S]),(0,m.useEffect)(()=>{x&&x.reqId!==Te.current&&(Te.current=x.reqId,Se(!1),x.ok&&x.models?.length?(fe(x.models),U({ok:!0,text:A(`fetchModelsOk`,{n:x.models.length})})):U({ok:!1,text:x.error||A(`fetchModelsEmpty`)}))},[x,A]),(0,m.useEffect)(()=>{if(C&&C.reqId!==Me.current){if(Me.current=C.reqId,Ee(!1),K(!1),C.ok&&C.results?.length){let e=C.results,t=new Map(e.map(e=>[e.id.trim(),e]));P(e=>e&&{...e,models:e.models.map(e=>{let n=t.get(e.id.trim());return!n||n.status!==`matched`?e:{...e,name:e.name||n.name||``,contextWindow:e.contextWindow||(n.contextWindow?String(n.contextWindow):``),maxTokens:e.maxTokens||(n.maxTokens?String(n.maxTokens):``),input:e.input===`text`&&n.input?.includes(`image`)?`text-image`:e.input,reasoning:e.reasoning||(n.reasoning??!1),src:n.source}})});let n=e.filter(e=>e.status===`matched`).length,r=e.length-n;J({ok:!0,text:A(`enrichModelsOk`,{n,m:r})});let i=e.filter(e=>e.status!==`matched`&&(e.suggestions?.length||e.note)).map(e=>({id:e.id,suggestions:e.suggestions??[],note:e.note}));Ae(i)}else J({ok:!1,text:C.error||A(`enrichModelsErr`,{msg:``})})}},[C,A]),(0,m.useEffect)(()=>{T&&T.reqId!==Le.current&&(Le.current=T.reqId,Ne(!1),T.ok?Ie({ok:!0,text:A(`refreshBuiltinOk`)}):Ie({ok:!1,text:T.error||A(`refreshBuiltinFail`)}))},[T,A]),(0,m.useEffect)(()=>{D&&D.reqId!==$e.current&&($e.current=D.reqId,Ye(!1),D.ok?(Z({ok:!0,text:A(`appendModelOk`)}),Ve(``),Ue(``),Ge(``),qe(``),ze(null),f({type:`list_models_config`})):Z({ok:!1,text:D.error||A(`appendModelFail`)}))},[D,A]),(0,m.useEffect)(()=>{if(w&&w.reqId!==ft.current&&(ft.current=w.reqId,Q(null),w.ok)){let e=w.configs;if(e&&e.length>1){tt(e.map(e=>b(e))),rt(``);return}w.config&&at(b(w.config))}},[w]);let ht=()=>{if(!N)return;let e=N.baseUrl.trim();if(!e){I({ok:!1,error:A(`fetchModelsNeedBaseUrl`)});return}me(!0),I(null);let t=he+1;ge(t),f({type:`test_model_connection`,reqId:t,baseUrl:e,apiKey:N.apiKey.trim()||void 0,...N.apiKey.trim()?{}:N.hasApiKey?{providerId:N.providerId.trim()}:{},authHeader:N.authHeader,api:N.api})},gt=()=>{if(!N)return;let e=N.baseUrl.trim();if(!e){U({ok:!1,text:A(`fetchModelsNeedBaseUrl`)});return}if(V)return;Se(!0),U(null);let t=Ce+1;we(t),f({type:`fetch_models`,reqId:t,baseUrl:e,apiKey:N.apiKey.trim()||void 0,...N.apiKey.trim()?{}:N.hasApiKey?{providerId:N.providerId.trim()}:{},authHeader:N.authHeader,api:N.api})},_t=e=>{N&&(P(t=>{if(!t)return t;let n=t.models.filter(e=>e.id.trim()),r=new Set(n.map(e=>e.id.trim())),i=e.filter(e=>!r.has(e.id)).map(e=>({id:e.id,name:e.name??``,reasoning:e.reasoning??!1,input:e.input?.includes(`image`)?`text-image`:`text`,contextWindow:e.contextWindow?String(e.contextWindow):``,maxTokens:e.maxTokens?String(e.maxTokens):``,...e.thinkingLevelMap?{thinkingLevelMap:e.thinkingLevelMap}:{}}));return{...t,models:n.length===0?i:[...n,...i]}}),fe(null))},vt=()=>{if(!N||W)return;let e=N.models.map(e=>e.id.trim()).filter(Boolean);if(e.length===0){J({ok:!1,text:A(`enrichModelsNeedIds`)});return}Ee(!0),K(!1),J(null),Ae([]);let t=De+1;Oe(t),f({type:`enrich_models`,reqId:t,ids:e,hints:se(je)})},yt=()=>{W&&!G&&(K(!0),f({type:`abort_enrich_models`,reqId:De}))},bt=e=>{P(t=>({providerId:t?.providerId.trim()||e.id,name:t?.name.trim()||e.name,api:e.api,baseUrl:e.baseUrl,apiKey:t?.apiKey||(t?.hasApiKey?``:e.apiKey)||``,hasApiKey:t?.hasApiKey??!1,authHeader:e.authHeader,models:t?.models.length?t.models:[v()]})),I(null),U(null)},xt=()=>{if(!N)return;let e=N.providerId.trim();if(!e)return;let t=N.models.filter(e=>e.id.trim()).map(e=>({id:e.id.trim(),name:e.name.trim()||void 0,reasoning:e.reasoning||void 0,input:e.input===`text-image`?[`text`,`image`]:void 0,contextWindow:e.contextWindow?Number(e.contextWindow):void 0,maxTokens:e.maxTokens?Number(e.maxTokens):void 0,...e.thinkingLevelMap?{thinkingLevelMap:e.thinkingLevelMap}:{}})),n={providerId:e,name:N.name.trim()||void 0,api:N.api.trim()||void 0,baseUrl:N.baseUrl.trim()||void 0,...N.apiKey.trim()?{apiKey:N.apiKey.trim()}:{},authHeader:N.authHeader||void 0,models:t};f({type:`save_model_config`,providerId:e,config:n}),k()},$=(e,t)=>{N&&P({...N,models:N.models.map((n,r)=>r===e?{...n,...t}:n)})},St=()=>{N&&P({...N,models:[...N.models,v()]})},Ct=e=>{N&&P({...N,models:N.models.filter((t,n)=>n!==e)})},wt=e=>{let t=(L[e.id]??``).trim();t&&!R&&(z(e.id),f({type:`add_provider_key`,provider:e.id,apiKey:t,name:(ye[e.id]??``).trim()||void 0}),B.current&&clearTimeout(B.current),B.current=setTimeout(()=>{z(t=>t===e.id?null:t)},1e4))},Tt=(e,t)=>{f({type:`activate_provider_key`,provider:e,keyName:t}),f({type:`list_provider_keys`})},Et=(e,t)=>{window.confirm(A(`removeKeyConfirm`))&&(f({type:`remove_provider_key`,provider:e,keyName:t}),f({type:`list_provider_keys`}))},Dt=e=>{window.confirm(A(`clearKeyConfirm`,{id:e}))&&f({type:`clear_provider_api_key`,provider:e})},Ot=t=>{if(window.confirm(A(`deleteProviderConfirm`,{id:t.providerId,n:t.models.length}))&&(f({type:`delete_model_config`,providerId:t.providerId}),j.type===`custom`&&j.id===t.providerId)){let n=e.filter(e=>e.providerId!==t.providerId);n.length>0?(M({type:`custom`,id:n[0].providerId}),P(b(n[0]))):(M({type:`custom`,id:``}),P(y()))}},kt=e=>{let t=Be.trim();if(!t||Je)return;Ye(!0),Z(null);let n=Xe+1;Ze(n),f({type:`append_builtin_model`,providerId:e,model:{id:t,...He.trim()?{name:He.trim()}:{},...We?{api:We}:{},...Ke.trim()?{baseUrl:Ke.trim()}:{}},reqId:n})};return(0,h.jsx)(`div`,{className:`modal-backdrop`,onClick:k,children:(0,h.jsxs)(`div`,{className:`modal model-studio-modal`,onClick:e=>e.stopPropagation(),children:[(0,h.jsxs)(`div`,{className:`studio-header`,children:[(0,h.jsxs)(`div`,{className:`studio-header-left`,children:[(0,h.jsx)(`div`,{className:`studio-header-icon-box`,children:(0,h.jsx)(t,{})}),(0,h.jsxs)(`div`,{className:`studio-header-title-wrap`,children:[(0,h.jsx)(`h2`,{className:`studio-header-title`,children:A(`modelManagementTitle`)}),(0,h.jsx)(`span`,{className:`studio-header-badge`,children:`Studio`})]})]}),(0,h.jsxs)(`div`,{className:`studio-header-actions`,children:[O!==void 0&&O&&(0,h.jsxs)(`div`,{style:{display:`inline-flex`,alignItems:`center`,gap:5,padding:`3px 8px`,borderRadius:6,background:`rgba(251, 191, 36, 0.08)`,border:`1px solid rgba(251, 191, 36, 0.3)`,fontSize:11.5,color:`var(--amber)`},title:A(`defaultModelLabel`,{model:O}),children:[(0,h.jsx)(`span`,{children:`★`}),(0,h.jsx)(`span`,{style:{maxWidth:120,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,fontFamily:`var(--mono)`},children:O.split(`/`).slice(1).join(`/`)}),(0,h.jsx)(`button`,{type:`button`,style:{background:`transparent`,border:`none`,color:`var(--amber)`,cursor:`pointer`,fontSize:10,padding:`0 2px`,opacity:.7},title:A(`clearDefaultModel`),onClick:()=>f({type:`clear_default_model`}),children:`✕`})]}),(0,h.jsxs)(`button`,{type:`button`,className:`studio-header-btn`,title:A(`refreshBuiltinHint`),disabled:Y,onClick:()=>{if(Y)return;Ne(!0),Ie(null);let e=Pe+1;Fe(e),f({type:`refresh_builtin_models`,reqId:e})},children:[(0,h.jsx)(d,{}),(0,h.jsx)(`span`,{children:A(Y?`refreshBuiltinBusy`:`refreshBuiltinCatalog`)})]}),(0,h.jsx)(`button`,{type:`button`,className:`studio-header-iconbtn`,title:A(`reloadModelsHint`),onClick:()=>f({type:`reload_models_config`}),children:(0,h.jsx)(n,{})}),(0,h.jsx)(`button`,{type:`button`,className:`studio-header-iconbtn close-btn`,"aria-label":A(`close`),onClick:k,children:(0,h.jsx)(u,{})})]})]}),X&&(0,h.jsx)(`div`,{style:{padding:`6px 20px`,background:`var(--bg-elev2)`,fontSize:12,borderBottom:`1px solid var(--border-soft)`},children:(0,h.jsx)(`span`,{className:`fetch-msg ${X.ok?`ok`:`err`}`,children:X.text})}),(0,h.jsxs)(`div`,{className:`model-studio-body`,children:[(0,h.jsxs)(`div`,{className:`model-studio-sidebar`,children:[(0,h.jsx)(`div`,{style:{padding:`12px 10px 6px`},children:(0,h.jsxs)(`button`,{type:`button`,className:`btn primary sm`,style:{width:`100%`,justifyContent:`center`},onClick:()=>{M({type:`custom`,id:``}),P(y()),I(null),U(null)},children:[(0,h.jsx)(a,{}),` `,A(`addCustomProvider`)]})}),(0,h.jsxs)(`div`,{className:`studio-sidebar-section`,children:[(0,h.jsx)(`span`,{className:`studio-sidebar-title`,children:A(`customProvidersCount`,{n:e.length})}),e.length===0&&(0,h.jsx)(`div`,{style:{fontSize:11.5,color:`var(--text-faint)`,padding:`6px 8px`},children:A(`noCustomProviders`)}),e.map(e=>{let t=j.type===`custom`&&j.id===e.providerId;return(0,h.jsxs)(`div`,{className:`studio-nav-item ${t?`active`:``}`,onClick:()=>{M({type:`custom`,id:e.providerId}),P(b(e)),I(null),U(null)},children:[(0,h.jsxs)(`span`,{className:`studio-nav-label`,children:[(0,h.jsx)(`span`,{className:`studio-nav-dot configured`}),(0,h.jsx)(`span`,{children:e.name||e.providerId})]}),(0,h.jsxs)(`span`,{style:{fontSize:10.5,color:`var(--text-faint)`,fontFamily:`var(--mono)`},children:[e.models.length,`m`]})]},e.providerId)})]}),(0,h.jsxs)(`div`,{className:`studio-sidebar-section`,children:[(0,h.jsx)(`span`,{className:`studio-sidebar-title`,children:A(`builtinProvidersCount`,{n:s.length})}),s.map(e=>{let t=j.type===`builtin`&&j.id===e.id,n=l[e.id]??[];return(0,h.jsxs)(`div`,{className:`studio-nav-item ${t?`active`:``}`,onClick:()=>{M({type:`builtin`,id:e.id}),P(null)},children:[(0,h.jsxs)(`span`,{className:`studio-nav-label`,children:[(0,h.jsx)(`span`,{className:`studio-nav-dot ${e.configured?`configured`:``}`}),(0,h.jsx)(`span`,{children:e.name})]}),n.length>0&&(0,h.jsxs)(`span`,{style:{fontSize:10.5,color:`var(--text-faint)`,fontFamily:`var(--mono)`},children:[n.length,`k`]})]},e.id)})]})]}),(0,h.jsxs)(`div`,{className:`model-studio-main`,children:[N&&(0,h.jsxs)(`div`,{className:`studio-card`,children:[(0,h.jsxs)(`div`,{className:`studio-card-head`,children:[(0,h.jsxs)(`div`,{className:`studio-card-title`,children:[(0,h.jsx)(`span`,{children:N.providerId?A(`editProviderTitle`,{id:N.providerId}):A(`newCustomProviderTitle`)}),N.providerId&&e.some(e=>e.providerId===N.providerId)&&(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`button`,{type:`button`,className:`iconbtn sm`,title:A(`refreshModels`),disabled:ot[N.providerId],onClick:()=>pt(N.providerId),children:(0,h.jsx)(n,{className:ot[N.providerId]?`spin`:``})}),(0,h.jsx)(`button`,{type:`button`,className:`iconbtn danger sm`,title:A(`deleteProviderTooltip`),onClick:()=>{let t=e.find(e=>e.providerId===N.providerId);t&&Ot(t)},children:(0,h.jsx)(c,{})})]})]}),(0,h.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8},children:[(0,h.jsxs)(`div`,{className:`conn-test-box`,children:[(0,h.jsxs)(`button`,{type:`button`,className:`conn-test-btn`,disabled:pe||!N.baseUrl.trim(),onClick:ht,children:[(0,h.jsx)(i,{}),` `,A(pe?`testingConnection`:`testConnection`)]}),F&&(0,h.jsxs)(`span`,{className:`ping-indicator ${F.ok?`ok`:`err`}`,children:[(0,h.jsx)(`span`,{className:`ping-dot`}),(0,h.jsx)(`span`,{children:F.ok?A(`connSuccess`,{latency:F.latencyMs??0}):A(`connFailed`)})]})]}),(0,h.jsx)(`button`,{type:`button`,className:`btn primary sm`,onClick:xt,children:A(`save`)})]})]}),(0,h.jsxs)(`div`,{className:`quick-chips-wrapper`,children:[(0,h.jsx)(`span`,{className:`quick-chips-label`,children:A(`quickPresetsLabel`)}),(0,h.jsx)(`div`,{className:`quick-chips-grid`,children:ae.map(e=>(0,h.jsxs)(`button`,{type:`button`,className:`quick-chip`,onClick:()=>bt(e),children:[(0,h.jsx)(`span`,{className:`quick-chip-name`,children:e.name}),e.tag&&(0,h.jsx)(`span`,{className:`quick-chip-tag`,children:oe(e.tag,A)})]},e.id))})]}),(0,h.jsxs)(`div`,{className:`form-grid`,children:[(0,h.jsxs)(`label`,{className:`field`,children:[(0,h.jsxs)(`span`,{className:`field-label`,children:[A(`providerId`),` `,(0,h.jsx)(`em`,{children:A(`providerIdHint`)})]}),(0,h.jsx)(`input`,{type:`text`,value:N.providerId,disabled:e.some(e=>e.providerId===N.providerId),onChange:e=>P({...N,providerId:e.target.value}),placeholder:A(`providerIdPlaceholder`)})]}),(0,h.jsxs)(`label`,{className:`field`,children:[(0,h.jsx)(`span`,{className:`field-label`,children:A(`displayName`)}),(0,h.jsx)(`input`,{type:`text`,value:N.name,onChange:e=>P({...N,name:e.target.value}),placeholder:A(`displayNamePh`)})]}),(0,h.jsxs)(`label`,{className:`field`,children:[(0,h.jsx)(`span`,{className:`field-label`,children:A(`apiType`)}),(0,h.jsx)(`select`,{value:N.api,onChange:e=>P({...N,api:e.target.value}),children:ie.map(e=>(0,h.jsx)(`option`,{value:e,children:e},e))})]}),(0,h.jsxs)(`label`,{className:`field`,children:[(0,h.jsxs)(`span`,{className:`field-label`,children:[`baseUrl `,(0,h.jsx)(`em`,{children:A(`baseUrlHint`)})]}),(0,h.jsx)(`input`,{type:`text`,value:N.baseUrl,onChange:e=>P({...N,baseUrl:e.target.value}),placeholder:`https://api.deepseek.com/v1`})]}),(0,h.jsxs)(`label`,{className:`field`,children:[(0,h.jsx)(`span`,{className:`field-label`,children:A(`apiKey`)}),(0,h.jsx)(`input`,{type:`password`,value:N.apiKey,onChange:e=>P({...N,apiKey:e.target.value}),placeholder:N.hasApiKey?A(`apiKeySavedHint`):A(`apiKeyHint`)})]}),(0,h.jsxs)(`label`,{className:`field check`,style:{alignSelf:`center`,paddingTop:16},children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:N.authHeader,onChange:e=>P({...N,authHeader:e.target.checked})}),(0,h.jsx)(`span`,{children:A(`authHeader`)})]})]}),(0,h.jsxs)(`div`,{style:{marginTop:8},children:[(0,h.jsxs)(`div`,{className:`model-section-head`,children:[(0,h.jsx)(`span`,{className:`form-section-title`,style:{fontSize:13,fontWeight:600},children:A(`modelMatrixCount`,{n:N.models.filter(e=>e.id.trim()).length})}),(0,h.jsxs)(`div`,{className:`model-section-actions`,children:[H&&(0,h.jsx)(`span`,{className:`fetch-msg ${H.ok?`ok`:`err`}`,title:H.text,children:H.text}),q&&(0,h.jsx)(`span`,{className:`fetch-msg ${q.ok?`ok`:`err`}`,title:q.text,children:q.text}),(0,h.jsxs)(`button`,{type:`button`,className:`btn sm`,disabled:V||!N.baseUrl.trim(),title:A(`fetchModelsHint`),onClick:gt,children:[(0,h.jsx)(d,{}),` `,A(V?`fetchingModels`:`autoFetchAndAdopt`)]}),(0,h.jsxs)(`button`,{type:`button`,className:`btn sm`,disabled:W,title:A(`enrichModelsHint`),onClick:vt,children:[(0,h.jsx)(d,{}),` `,A(W?`enrichingModels`:`enrichModels`)]}),W&&(0,h.jsxs)(`button`,{type:`button`,className:`btn sm`,disabled:G,title:A(`enrichModelsAbort`),onClick:yt,style:{color:`var(--red)`},children:[(0,h.jsx)(u,{}),` `,A(G?`enrichCancelling`:`enrichModelsCancel`)]})]})]}),(0,h.jsxs)(`div`,{className:`model-matrix-list`,children:[N.models.map((e,n)=>(0,h.jsxs)(`div`,{className:`model-matrix-card`,children:[(0,h.jsxs)(`div`,{className:`matrix-main-row`,children:[(0,h.jsxs)(`div`,{className:`matrix-input-group id-group`,children:[(0,h.jsxs)(`span`,{className:`matrix-input-prefix`,children:[(0,h.jsx)(t,{}),` ID`]}),(0,h.jsx)(`input`,{type:`text`,className:`matrix-input-field mono`,value:e.id,onChange:e=>$(n,{id:e.target.value}),placeholder:A(`modelIdPlaceholder`)})]}),(0,h.jsxs)(`div`,{className:`matrix-input-group name-group`,children:[(0,h.jsx)(`span`,{className:`matrix-input-prefix`,children:A(`modelAliasPrefix`)}),(0,h.jsx)(`input`,{type:`text`,className:`matrix-input-field`,value:e.name,onChange:e=>$(n,{name:e.target.value}),placeholder:A(`modelAliasPlaceholder`)})]}),(0,h.jsxs)(`div`,{className:`matrix-toggles`,children:[(0,h.jsx)(`button`,{type:`button`,className:`matrix-toggle-tag ${e.input===`text-image`?`active vision`:``}`,onClick:()=>$(n,{input:e.input===`text-image`?`text`:`text-image`}),title:A(`visionCheckboxTitle`),children:A(`visionCheckboxLabel`)}),(0,h.jsx)(`button`,{type:`button`,className:`matrix-toggle-tag ${e.reasoning?`active reasoning`:``}`,onClick:()=>$(n,{reasoning:!e.reasoning}),title:A(`reasoningCheckboxTitle`),children:A(`reasoningCheckboxLabel`)}),O!==void 0&&e.id.trim()&&(()=>{let t=`${N.providerId}/${e.id.trim()}`,n=O===t||O===e.id.trim();return(0,h.jsxs)(`button`,{type:`button`,className:`matrix-star-btn ${n?`active`:``}`,title:A(n?`cancelDefaultTooltip`:`setDefaultTooltip`),onClick:()=>{f(n?{type:`clear_default_model`}:{type:`set_default_model`,modelId:t})},children:[(0,h.jsx)(`span`,{className:`matrix-star-icon`,children:n?`★`:`☆`}),(0,h.jsx)(`span`,{children:A(n?`defaultModelBadge`:`setDefaultModelBtn`)})]})})(),(0,h.jsx)(`button`,{type:`button`,className:`matrix-delete-btn`,title:A(`delete`),onClick:()=>Ct(n),children:(0,h.jsx)(c,{})})]})]}),(0,h.jsxs)(`div`,{className:`matrix-spec-bar`,children:[(0,h.jsxs)(`div`,{className:`spec-combobox`,children:[(0,h.jsx)(`span`,{className:`spec-combobox-label`,children:A(`contextWindowLabel`)}),(0,h.jsxs)(`select`,{className:`spec-combobox-select`,value:g.some(t=>t.value===e.contextWindow)?e.contextWindow:`custom`,onChange:e=>{e.target.value!==`custom`&&$(n,{contextWindow:e.target.value})},children:[g.map(e=>(0,h.jsxs)(`option`,{value:e.value,children:[e.label,` (`,Math.round(Number(e.value)/1024),`K)`]},e.value)),(0,h.jsx)(`option`,{value:`custom`,children:A(`customOption`)})]}),(!g.some(t=>t.value===e.contextWindow)||e.contextWindow===``)&&(0,h.jsx)(`input`,{type:`text`,className:`spec-combobox-custom-input`,value:e.contextWindow,onChange:e=>$(n,{contextWindow:e.target.value}),placeholder:A(`contextPlaceholder`)})]}),(0,h.jsxs)(`div`,{className:`spec-combobox`,children:[(0,h.jsx)(`span`,{className:`spec-combobox-label`,children:A(`maxOutputLabel`)}),(0,h.jsxs)(`select`,{className:`spec-combobox-select`,value:_.some(t=>t.value===e.maxTokens)?e.maxTokens:`custom`,onChange:e=>{e.target.value!==`custom`&&$(n,{maxTokens:e.target.value})},children:[_.map(e=>(0,h.jsxs)(`option`,{value:e.value,children:[e.label,` (`,Math.round(Number(e.value)/1024),`K)`]},e.value)),(0,h.jsx)(`option`,{value:`custom`,children:A(`customOption`)})]}),(!_.some(t=>t.value===e.maxTokens)||e.maxTokens===``)&&(0,h.jsx)(`input`,{type:`text`,className:`spec-combobox-custom-input`,value:e.maxTokens,onChange:e=>$(n,{maxTokens:e.target.value}),placeholder:A(`maxOutputPlaceholder`)})]}),(0,h.jsx)(`div`,{className:`matrix-spec-quick-pills`,children:[`32K`,`128K`,`200K`].map(t=>{let r=g.find(e=>e.label===t);return r?(0,h.jsx)(`button`,{type:`button`,className:`param-pill ${e.contextWindow===r.value?`active`:``}`,onClick:()=>$(n,{contextWindow:r.value}),title:A(`contextPresetTooltip`,{label:t}),children:t},t):null})})]})]},n)),(0,h.jsxs)(`button`,{type:`button`,className:`btn sm`,style:{alignSelf:`flex-start`,marginTop:4},onClick:St,children:[(0,h.jsx)(a,{}),` `,A(`addModelRow`)]})]})]})]}),j.type===`builtin`&&(()=>{let e=s.find(e=>e.id===j.id);if(!e)return null;let t=l[e.id]??[];return(0,h.jsxs)(`div`,{className:`studio-card`,children:[(0,h.jsxs)(`div`,{className:`studio-card-head`,children:[(0,h.jsxs)(`div`,{className:`studio-card-title`,children:[(0,h.jsx)(`span`,{children:A(`builtinProviderTitle`,{name:e.name})}),e.configured&&(0,h.jsx)(`span`,{className:`auth-badge`,children:A(`configuredBadge`)}),e.source&&!e.configured&&(0,h.jsx)(`span`,{className:`auth-badge dim`,children:e.source})]}),(0,h.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:6},children:[(0,h.jsxs)(`button`,{type:`button`,className:`btn sm`,title:A(`cloneProvider`),disabled:ut===e.id,onClick:()=>mt(e),children:[(0,h.jsx)(o,{}),` `,A(`cloneProvider`)]}),(0,h.jsxs)(`button`,{type:`button`,className:`btn sm`,onClick:()=>{ze(Re===e.id?null:e.id),Z(null)},children:[(0,h.jsx)(a,{}),` `,A(`appendModel`)]}),e.supportsApiKey&&e.source===`stored`&&!e.usingOAuth&&(0,h.jsxs)(`button`,{type:`button`,className:`btn sm danger`,title:A(`clearKeyTitle`),onClick:()=>Dt(e.id),children:[(0,h.jsx)(c,{}),` `,A(`clearKey`)]})]})]}),e.supportsOAuth&&(0,h.jsx)(ne,{provider:e,flow:p.find(t=>t.provider===e.id),result:te[e.id]}),e.supportsApiKey&&(0,h.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:10},children:[(0,h.jsx)(`span`,{style:{fontSize:12.5,fontWeight:600},children:A(`apiKeyManagement`)}),(0,h.jsxs)(`div`,{className:`provider-keys`,children:[t.length===0&&(0,h.jsx)(`div`,{className:`provider-key-empty`,children:A(`noKeyYet`)}),t.map(t=>(0,h.jsxs)(`div`,{className:`provider-key-item ${t.active?`active`:``}`,children:[(0,h.jsx)(`span`,{className:`provider-key-dot`,children:t.active?`●`:`○`}),(0,h.jsx)(`span`,{className:`provider-key-label`,children:t.name}),!t.active&&(0,h.jsx)(`button`,{type:`button`,className:`iconbtn`,title:A(`activateKey`),onClick:()=>Tt(e.id,t.name),children:(0,h.jsx)(r,{})}),(0,h.jsx)(`button`,{type:`button`,className:`iconbtn danger`,title:A(`removeKey`),onClick:()=>Et(e.id,t.name),children:(0,h.jsx)(c,{})})]},t.name))]}),(0,h.jsxs)(`div`,{className:`provider-add-key`,style:{marginTop:6},children:[(0,h.jsx)(`input`,{type:`text`,className:`key-input key-input-name`,placeholder:A(`keyNamePh`),value:ye[e.id]??``,onChange:t=>be(n=>({...n,[e.id]:t.target.value}))}),(0,h.jsx)(`input`,{type:`password`,className:`key-input key-input-value`,placeholder:A(`addKeyPlaceholder`),value:L[e.id]??``,onChange:t=>ve(n=>({...n,[e.id]:t.target.value}))}),(0,h.jsxs)(`button`,{type:`button`,className:`btn primary sm`,disabled:!(L[e.id]??``).trim()||R===e.id,onClick:()=>wt(e),children:[(0,h.jsx)(a,{}),` `,R===e.id?A(`savingKey`):A(`addKey`)]})]})]}),Re===e.id&&(0,h.jsxs)(`div`,{style:{marginTop:12,padding:12,background:`var(--bg)`,borderRadius:8,border:`1px dashed var(--border-soft)`},children:[(0,h.jsx)(`span`,{style:{fontSize:12,fontWeight:600,display:`block`,marginBottom:8},children:A(`addBuiltinOverlay`)}),(0,h.jsxs)(`div`,{style:{display:`flex`,gap:8,flexWrap:`wrap`},children:[(0,h.jsx)(`input`,{type:`text`,className:`key-input`,placeholder:A(`overlayModelIdPlaceholder`),value:Be,onChange:e=>Ve(e.target.value)}),(0,h.jsx)(`input`,{type:`text`,className:`key-input`,placeholder:A(`overlayModelNamePlaceholder`),value:He,onChange:e=>Ue(e.target.value)}),(0,h.jsxs)(`button`,{type:`button`,className:`btn primary sm`,disabled:!Be.trim()||Je,onClick:()=>kt(e.id),children:[(0,h.jsx)(a,{}),` `,A(`submitOverlayBtn`)]})]}),Qe&&(0,h.jsx)(`span`,{style:{fontSize:12,color:Qe.ok?`var(--green)`:`var(--red)`,marginTop:6},children:Qe.text})]})]})})()]})]}),de&&(0,h.jsx)(ce,{candidates:de,preselectedIds:N?.models.map(e=>e.id.trim()).filter(Boolean)??[],onAdopt:_t,onClose:()=>fe(null)})]})})}export{x as ModelConfigModal};
@@ -0,0 +1 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$ as t,Gt as n,g as r,hn as i,l as a,t as o}from"./app-globals-CnO6KlEM.js";import{i as s,t as c}from"./react-CR5VJ85Q.js";import{r as l}from"./desktop-DPyTy4M3.js";import{t as u}from"./ProviderOAuthControls-VK_jqXYS.js";var d=e(s(),1),f=c();function p({piConfigured:e,piAgentInstalled:s,providers:c,providerOAuthFlows:p,providerOAuthResults:m,installResult:h,onClose:g}){let _=r(),v=l(),y=a(),[b,x]=(0,d.useState)(!1),[S,C]=(0,d.useState)(``),[w,T]=(0,d.useState)(``),[E,D]=(0,d.useState)(!1);(0,d.useEffect)(()=>{o({type:`list_providers`}),o({type:`list_provider_oauth_flows`})},[]),(0,d.useEffect)(()=>{e&&g()},[e,g]),(0,d.useEffect)(()=>{h&&x(!1)},[h]),(0,d.useEffect)(()=>{!S&&c.length>0&&C(c.find(e=>!e.configured)?.id??c[0].id)},[c,S]);let O=()=>{b||(x(!0),o({type:`install_pi_agent`}))},k=()=>{w.trim()&&!E&&(D(!0),o({type:`set_provider_api_key`,provider:S.trim(),apiKey:w.trim()}),setTimeout(()=>D(!1),3e3))},A=()=>{o({type:`get_state`}),o({type:`list_providers`})},j=c.find(e=>e.id===S),M=h!==null&&!h.ok;return(0,f.jsx)(`div`,{className:`modal-backdrop`,children:(0,f.jsxs)(`div`,{className:`modal setup-modal`,children:[(0,f.jsx)(`button`,{type:`button`,className:`modal-close`,"aria-label":_(`close`),onClick:g,children:(0,f.jsx)(i,{})}),(0,f.jsxs)(`div`,{className:`modal-head`,children:[(0,f.jsx)(t,{className:`modal-head-icon`}),(0,f.jsx)(`h2`,{children:_(`setupTitle`)})]}),(0,f.jsx)(`p`,{className:`modal-desc`,children:_(`setupDesc`)}),M?(0,f.jsxs)(`div`,{className:`setup-failed`,children:[(0,f.jsx)(`div`,{className:`setup-done`,children:_(`installFailed`)}),(0,f.jsx)(`pre`,{className:`setup-detail`,children:h.detail}),(0,f.jsxs)(`div`,{className:`setup-actions`,children:[(0,f.jsx)(`button`,{type:`button`,className:`btn primary`,disabled:b,onClick:O,children:_(`retryInstall`)}),(0,f.jsx)(`button`,{type:`button`,className:`btn`,onClick:g,children:_(`skip`)})]})]}):s||h?.ok||v?(0,f.jsxs)(`div`,{className:`setup-key-form`,children:[(0,f.jsx)(`div`,{className:`setup-done`,children:h?.ok?_(`installDone`):_(`cliReadyHint`)}),(0,f.jsxs)(`label`,{className:`field`,children:[(0,f.jsx)(`span`,{className:`field-label`,children:_(`provider`)}),(0,f.jsxs)(`select`,{value:S,onChange:e=>C(e.target.value),children:[c.length===0&&(0,f.jsx)(`option`,{value:``,children:_(`loading`)}),c.map(e=>(0,f.jsxs)(`option`,{value:e.id,children:[e.name,`(`,e.id,`)`,e.configured?` · ${_(`configured`)}`:``]},e.id))]}),j?.configured&&(0,f.jsx)(`div`,{className:`field-hint`,children:_(`providerKeyReady`)})]}),j?.supportsOAuth&&(0,f.jsx)(u,{provider:j,flow:p.find(e=>e.provider===j.id),result:m[j.id]}),j?.supportsApiKey&&(0,f.jsxs)(`label`,{className:`field`,children:[(0,f.jsx)(`span`,{className:`field-label`,children:_(`apiKey`)}),(0,f.jsx)(`input`,{type:`password`,value:w,onChange:e=>T(e.target.value),placeholder:`sk-…`})]}),(0,f.jsxs)(`div`,{className:`setup-actions`,children:[j?.supportsApiKey&&(0,f.jsx)(`button`,{type:`button`,className:`btn primary`,disabled:!w.trim()||E||!S,onClick:k,children:_(E?`saving`:`saveAndStart`)}),(0,f.jsxs)(`button`,{type:`button`,className:`btn`,onClick:A,children:[(0,f.jsx)(n,{}),` `,_(`recheck`)]})]})]}):y?(0,f.jsxs)(`div`,{className:`setup-actions`,children:[(0,f.jsx)(`div`,{className:`setup-done`,children:_(`updatesManaged`)}),(0,f.jsx)(`button`,{type:`button`,className:`btn`,onClick:g,children:_(`skip`)})]}):(0,f.jsxs)(`div`,{className:`setup-actions`,children:[(0,f.jsx)(`button`,{type:`button`,className:`btn primary`,disabled:b,onClick:O,children:_(b?`installing`:`autoInstall`)}),(0,f.jsx)(`button`,{type:`button`,className:`btn`,onClick:g,children:_(`skip`)})]})]})})}export{p as PiSetupModal};
@@ -0,0 +1 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{g as t,t as n}from"./app-globals-CnO6KlEM.js";import{i as r,t as i}from"./react-CR5VJ85Q.js";var a=e(r(),1),o=i();function s({provider:e,flow:r,result:i}){let s=t(),c=r?.event,l=e.oauthName??e.name,[u,d]=(0,a.useState)(``);return(0,a.useEffect)(()=>d(``),[r?.promptId]),e.usingOAuth?(0,o.jsxs)(`div`,{className:`provider-oauth`,children:[(0,o.jsx)(`span`,{className:`provider-oauth-status`,children:s(`oauthConnected`,{name:l})}),(0,o.jsx)(`button`,{type:`button`,className:`btn sm danger`,"data-provider-oauth-logout":e.id,onClick:()=>n({type:`provider_oauth_logout`,provider:e.id}),children:s(`oauthLogout`)}),i?.error&&(0,o.jsx)(`div`,{className:`provider-oauth-error`,children:i.error})]}):(0,o.jsxs)(`div`,{className:`provider-oauth`,children:[r?(0,o.jsxs)(o.Fragment,{children:[c?.type===`device_code`&&(0,o.jsxs)(`div`,{className:`provider-oauth-device`,children:[(0,o.jsx)(`div`,{children:s(`oauthDeviceCode`)}),(0,o.jsx)(`code`,{"data-oauth-device-code":!0,children:c.userCode}),(0,o.jsx)(`a`,{"data-oauth-verification-url":!0,href:c.verificationUri,target:`_blank`,rel:`noreferrer`,children:s(`oauthOpenVerification`)})]}),c?.type===`auth_url`&&(0,o.jsxs)(`div`,{className:`provider-oauth-event`,children:[c.instructions&&(0,o.jsx)(`div`,{children:c.instructions}),(0,o.jsx)(`a`,{href:c.url,target:`_blank`,rel:`noreferrer`,children:s(`oauthOpenVerification`)})]}),c?.type===`progress`&&(0,o.jsx)(`div`,{className:`provider-oauth-message`,children:c.message}),c?.type===`info`&&(0,o.jsxs)(`div`,{className:`provider-oauth-event`,children:[(0,o.jsx)(`div`,{children:c.message}),c.links?.map(e=>(0,o.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noreferrer`,children:e.label??e.url},e.url))]}),r.prompt&&(0,o.jsx)(`div`,{className:`provider-oauth-message`,children:r.prompt.message}),r.prompt?.type===`select`&&r.promptId&&(0,o.jsx)(`div`,{className:`provider-oauth-options`,children:r.prompt.options.map(e=>(0,o.jsx)(`button`,{type:`button`,className:`btn sm`,"data-oauth-option":e.id,onClick:()=>n({type:`provider_oauth_reply`,flowId:r.flowId,promptId:r.promptId,value:e.id}),children:e.label},e.id))}),r.prompt&&r.prompt.type!==`select`&&r.promptId&&(0,o.jsxs)(`form`,{className:`provider-oauth-prompt`,onSubmit:e=>{e.preventDefault(),u.trim()&&n({type:`provider_oauth_reply`,flowId:r.flowId,promptId:r.promptId,value:u.trim()})},children:[(0,o.jsx)(`input`,{"data-oauth-prompt-input":!0,type:r.prompt.type===`secret`?`password`:`text`,className:`key-input`,placeholder:r.prompt.placeholder,value:u,onChange:e=>d(e.target.value)}),(0,o.jsx)(`button`,{type:`submit`,className:`btn primary sm`,"data-oauth-prompt-submit":!0,disabled:!u.trim(),children:s(`oauthContinue`)})]}),(0,o.jsx)(`button`,{type:`button`,className:`btn sm danger`,"data-oauth-cancel":r.flowId,onClick:()=>n({type:`provider_oauth_cancel`,flowId:r.flowId}),children:s(`cancel`)})]}):(0,o.jsx)(`button`,{type:`button`,className:`btn primary sm`,"data-provider-oauth-login":e.id,onClick:()=>n({type:`provider_oauth_start`,provider:e.id}),children:s(`oauthLogin`,{name:l})}),i?.error&&(0,o.jsx)(`div`,{className:`provider-oauth-error`,children:i.error})]})}export{s as t};
@@ -0,0 +1,2 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$ as t,A as n,Gt as r,L as i,O as a,g as o,ht as s,on as ee,t as te}from"./app-globals-CnO6KlEM.js";import{i as c,t as l}from"./react-CR5VJ85Q.js";import{t as ne}from"./uuid-BzDIGCwP.js";import{K as u}from"./index-CPgAH5q7.js";var d=e(c(),1),re=e=>`'${e.replace(/'/g,`'\\''`)}'`,ie=`pi-web-ui:scm-sidebar-width`;function ae(e,t=0){if(!Number.isFinite(e))return 300;let n=Math.max(200,Math.min(720,t>0?t-220:720));return Math.min(n,Math.max(200,Math.round(e)))}function oe(e){return e===null||e.trim()===``?300:ae(Number(e))}function f(e,t){let n=t.toLowerCase();return e.subject.toLowerCase().includes(n)||e.author.toLowerCase().includes(n)||e.shortHash.toLowerCase().includes(n)||e.hash.toLowerCase().includes(n)||e.decorations!==void 0&&e.decorations.toLowerCase().includes(n)}function se(e,t){let n=t.trim().toLowerCase().split(/\s+/).filter(Boolean);return n.length===0?e:e.filter(e=>n.every(t=>f(e,t)))}var p=`scm-commit-history`;function m(e=localStorage){try{let t=e.getItem(p);if(!t)return[];let n=JSON.parse(t);return Array.isArray(n)?n.filter(e=>typeof e==`string`&&e.length>0):[]}catch{return[]}}function ce(e,t=localStorage){let n=e.trim();if(!n)return m(t);let r=[n,...m(t).filter(e=>e!==n)].slice(0,20);try{t.setItem(p,JSON.stringify(r))}catch{}return r}var h={idx:-1,draft:``};function le(e,t,n,r){return e.length===0?null:r===`up`?t.idx>=e.length-1?null:t.idx===-1?{state:{idx:0,draft:n},text:e[0]}:{state:{idx:t.idx+1,draft:t.draft},text:e[t.idx+1]}:t.idx===-1?null:t.idx===0?{state:h,text:t.draft}:{state:{idx:t.idx-1,draft:t.draft},text:e[t.idx-1]}}var g=l();function ue(e){if(e.x===`?`&&e.y===`?`)return`untracked`;let t=e.x!==` `&&e.x!==`?`,n=e.y!==` `&&e.y!==`?`;return t&&n?`both`:t?`staged`:`unstaged`}function _({chat:e,terminal:c,active:l,onSwitchToTerminal:f,uiScmToolbar:p,onUiAction:_}){let v=o(),[y,b]=(0,d.useState)(null),[x,S]=(0,d.useState)([]),[C,de]=(0,d.useState)(``),[fe,pe]=(0,d.useState)(new Map),[w,me]=(0,d.useState)(`changes`),[T,he]=(0,d.useState)([]),[E,D]=(0,d.useState)(null),[ge,O]=(0,d.useState)(``),[k,_e]=(0,d.useState)(!1),[A,j]=(0,d.useState)(null),[M,N]=(0,d.useState)(null),[ve,P]=(0,d.useState)(!1),[ye,be]=(0,d.useState)(!1),[xe,Se]=(0,d.useState)(!1),[F,I]=(0,d.useState)(null),[L,Ce]=(0,d.useState)(!1),[R,z]=(0,d.useState)(!1),[we,B]=(0,d.useState)(null),[V,Te]=(0,d.useState)(()=>oe(localStorage.getItem(ie))),[H,U]=(0,d.useState)(``),[Ee,De]=(0,d.useState)(``),[Oe,ke]=(0,d.useState)(()=>m()),W=(0,d.useRef)(h),Ae=(0,d.useRef)(0),je=(0,d.useRef)(-1),Me=(0,d.useRef)(-1),Ne=(0,d.useRef)(-1),G=(0,d.useRef)(-1),K=(0,d.useRef)(-1),Pe=(0,d.useRef)(void 0),Fe=(0,d.useRef)(null),Ie=(0,d.useRef)([]),Le=(0,d.useRef)(V);Le.current=V;let Re=(0,d.useRef)(null),q=(0,d.useCallback)(e=>{try{localStorage.setItem(ie,String(e))}catch{}},[]),ze=(0,d.useCallback)(e=>{e.preventDefault();let t=e.clientX,n=Le.current,r=Re.current?.getBoundingClientRect().width??0,i=n,a=e=>{i=ae(n+(e.clientX-t),r),Te(i)},o=()=>{window.removeEventListener(`pointermove`,a),window.removeEventListener(`pointerup`,o),document.body.classList.remove(`panel-resizing`),q(i)};window.addEventListener(`pointermove`,a),window.addEventListener(`pointerup`,o),document.body.classList.add(`panel-resizing`)},[q]),Be=(0,d.useCallback)(()=>{Te(300),q(300)},[q]),Ve=(0,d.useCallback)(e=>{if(e.reqId===je.current){if(je.current=-1,be(!1),I(null),!e.ok){I(e.error??v(`scmQueryFailedShort`));return}if(e.notRepo){Ce(!0),b(null),S([]),pe(new Map),he([]),D(null),O(``),N(null);return}Ce(!1);let t={branch:e.branch??``,detached:!!e.detached,upstream:e.upstream??null,ahead:e.ahead??0,behind:e.behind??0,upstreamGone:!!e.upstreamGone,files:(e.files??[]).map(e=>({...e}))},n=(e.branches??[]).map(e=>({...e})),r=new Map;for(let[t,n]of Object.entries(e.stats??{}))r.set(t,{add:n[0],del:n[1]});b(t),S(n),pe(r),de(e=>t.detached?e||``:t.branch&&n.some(e=>e.name===t.branch)?t.branch:e&&n.some(t=>t.name===e)?e:n[0]?.name??``),N(e=>e&&!t.files.some(t=>t.path===e.file.path)?null:e)}else if(e.reqId===Me.current){if(Me.current=-1,P(!1),!e.ok){I(e.error??v(`scmQueryFailedShort`));return}let t=Fe.current;if(!t)return;N({file:t,staged:e.stagedText??``,worktree:e.worktreeText??``,untracked:!1})}else if(e.reqId===G.current){if(G.current=-1,Se(!1),!e.ok){I(e.error??v(`scmQueryFailedShort`));return}he((e.history??[]).map(e=>({...e})))}else if(e.reqId===Ne.current){if(Ne.current=-1,_e(!1),!e.ok){I(e.error??v(`scmQueryFailedShort`));return}O(e.text??``)}else if(e.reqId===K.current){if(K.current=-1,z(!1),!e.ok){B(e.error??v(`scmGenMsgFail`));return}B(null),U(e.text??``)}},[]);(0,d.useEffect)(()=>{let t=e.scmData;t&&t.type===`scm_data`&&Ve(t)},[e.scmData,Ve]);let J=(0,d.useCallback)((t,n)=>{if(!e.ready||e.status!==`open`)return!1;let r=++Ae.current;return te({...t,reqId:r})?(n.current=r,!0):(--Ae.current,!1)},[e.ready,e.status]),Y=(0,d.useCallback)((t=!1,n=!1)=>{e.ready&&e.status===`open`&&e.state?.cwd&&(Pe.current!==void 0&&Pe.current!==e.state.cwd&&(b(null),S([]),pe(new Map),he([]),De(``),Se(!1),G.current=-1,D(null),O(``),N(null),j(null),B(null),z(!1),K.current=-1),Pe.current=e.state.cwd,I(null),J({type:`scm_status`},je)&&(n||be(!0)))},[e.ready,e.state?.cwd,e.status,J]),He=(0,d.useCallback)(e=>{if(j(e),D(null),Fe.current=e,e.x===`?`&&e.y===`?`){N({file:e,staged:``,worktree:``,untracked:!0});return}P(!0),I(null),J({type:`scm_filediff`,path:e.path},Me)||P(!1)},[J]),Ue=(0,d.useCallback)(e=>{D(e),j(null),N(null),O(``),_e(!0),I(null),J({type:`scm_commit`,hash:e.hash},Ne)||_e(!1)},[J]),X=(0,d.useCallback)((t,n)=>{if(!e.ready)return;let r={name:t,command:n,cwd:"${pwd}"},i,a=e.terminals.find(e=>e.title===t);a?(c.restart(a.id),te({type:`run_command`,terminalId:a.id,conversationId:a.conversationId,command:r,cols:80,rows:24}),i=a.id):(i=ne(),c.create({id:i,conversationId:e.activeConversationId||e.state?.conversationId||``,title:t,cwd:e.state?.cwd??``,cols:80,rows:24,running:!0,exitCode:null,command:r})),c.select(i),f()},[e.ready,e.state?.cwd,e.terminals,f,c]),We=(0,d.useCallback)(()=>{let e=H.trim();if(!e||L)return;let t=e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/`/g,"\\`").replace(/\$/g,`\\$`);X(`git commit`,`git commit -m "${t}"`),ke(ce(e)),U(``),W.current=h},[H,L,X]),Ge=(0,d.useCallback)(()=>{let e=H.trim();if(!e||L)return;let t=e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/`/g,"\\`").replace(/\$/g,`\\$`);X(`git commit`,`git add -A && git commit -m "${t}"`),ke(ce(e)),U(``),W.current=h},[H,L,X]),Ke=(0,d.useCallback)(e=>{L||X(`git add`,`git add -- ${re(e.path)}`)},[L,X]),qe=(0,d.useCallback)(e=>{L||X(`git reset`,`git reset HEAD -- ${re(e.path)}`)},[L,X]),Je=(0,d.useCallback)(()=>{if(!C||L)return;let e=x.find(e=>e.name===C);if(e?.remote&&typeof e.remote==`string`){let t=C.slice(e.remote.length+1);X(`git checkout`,`git checkout -b ${t} ${C} || git checkout ${C}`)}else X(`git checkout`,`git checkout ${C}`)},[C,x,L,X]),Ye=(0,d.useCallback)(()=>X(`git push`,`git push`),[X]),Xe=(0,d.useCallback)(()=>X(`git pull`,`git pull`),[X]),Ze=(0,d.useCallback)(()=>{R||L||!e.ready||e.status!==`open`||(B(null),J({type:`scm_commitmsg`},K)?z(!0):B(v(`scmGenMsgFail`)))},[R,L,e.ready,e.status,J,v]),Z=(0,d.useCallback)(()=>{J({type:`scm_history`},G)||(G.current=-1)},[J]);(0,d.useEffect)(()=>{l&&Y()},[l,Y]),(0,d.useEffect)(()=>{w===`history`&&y&&Z()},[w,y,Z]),(0,d.useEffect)(()=>{e.scmDirty>0&&l&&Y(!1,!0)},[e.scmDirty]),(0,d.useEffect)(()=>{if(!l||!e.ready||e.status!==`open`)return;let t=setInterval(()=>{document.visibilityState!==`hidden`&&Y(!1,!0)},3e4);return()=>clearInterval(t)},[l,e.ready,e.status,Y]),(0,d.useEffect)(()=>{let t=Ie.current;Ie.current=e.terminals,l&&e.terminals.some(e=>e.running===!1&&t.find(t=>t.id===e.id)?.running===!0&&e.title.startsWith(`git `))&&e.ready&&e.status===`open`&&(Y(!1,!0),w===`history`&&y&&Z())},[e.terminals,l,e.ready,e.status,Y,w,y,Z]);let Qe={staged:v(`scmStaged`),unstaged:v(`scmUnstaged`),untracked:v(`scmUntracked`),both:v(`scmStagedUnstaged`)},$e=se(T,Ee),et=e=>{let t=e.split(`
2
+ `);return(0,g.jsx)(`pre`,{className:`scm-diff-pre`,children:t.map((e,t)=>{let n=``;return e.startsWith(`diff --git`)||e.startsWith(`index `)||e.startsWith(`new file`)||e.startsWith(`deleted file`)||e.startsWith(`old mode`)||e.startsWith(`new mode`)||e.startsWith(`similarity index`)||e.startsWith(`rename `)||e.startsWith(`copy `)||e.startsWith(`Binary files`)||e.startsWith(`---`)||e.startsWith(`+++`)?n=`hdr`:e.startsWith(`@@`)?n=`hunk`:e.startsWith(`+`)?n=`add`:e.startsWith(`-`)&&(n=`del`),(0,g.jsx)(`div`,{className:`scm-diff-line ${n}`,children:e||` `},t)})})},tt=p===void 0?[`host:scm-changes`,`host:scm-history`,`host:scm-refresh`,`host:scm-branch`,`host:scm-switch`,`host:scm-push`,`host:scm-pull`,`host:scm-input`,`host:scm-genmsg`,`host:scm-commit`,`host:scm-commit-all`,`host:scm-term`].map(e=>({id:e,source:`host`})):p.filter(e=>!e.hidden),nt=[`host:scm-branch`,`host:scm-switch`,`host:scm-push`,`host:scm-pull`,`host:scm-input`,`host:scm-genmsg`,`host:scm-commit`,`host:scm-commit-all`],rt=(e,t)=>{let n=new Set(e);return tt.filter(e=>n.has(e.id)||t&&e.source!==`host`)},it=e=>p===void 0||!p.some(t=>t.id===e&&t.hidden),Q=(e,t)=>{let n=tt.find(t=>t.id===e);return n?.labelExplicit?n.label:t},$={"host:scm-changes":(0,g.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":w===`changes`,className:w===`changes`?`active`:``,onClick:()=>{me(`changes`),I(null)},children:Q(`host:scm-changes`,v(`scmChanges`))}),"host:scm-history":(0,g.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":w===`history`,className:w===`history`?`active`:``,onClick:()=>{me(`history`),I(null)},children:Q(`host:scm-history`,v(`scmHistory`))}),"host:scm-refresh":(0,g.jsx)(`button`,{type:`button`,className:`panel-refresh`,title:v(`scmRefreshTip`),disabled:ye,onClick:()=>Y(!0),children:(0,g.jsx)(r,{className:ye?`scm-spin`:``})}),"host:scm-branch":(0,g.jsxs)(`select`,{className:`scm-select`,value:C,disabled:L||x.length===0,title:Q(`host:scm-branch`,v(`scmSwitchBranch`)),onChange:e=>de(e.target.value),children:[(0,g.jsx)(`option`,{value:``,disabled:!0,children:v(`scmSelectBranch`)}),x.filter(e=>!e.remote).map(e=>(0,g.jsx)(`option`,{value:e.name,children:e.current?`* ${e.name}`:e.name},e.name)),x.some(e=>e.remote)&&(0,g.jsx)(`optgroup`,{label:v(`scmRemoteBranches`),children:x.filter(e=>e.remote).map(e=>(0,g.jsx)(`option`,{value:e.name,children:e.name},e.name))})]}),"host:scm-switch":(0,g.jsxs)(`button`,{type:`button`,className:`btn`,disabled:!C||C===y?.branch||L,title:v(`scmSwitchBranchTip`,{branch:C}),onClick:Je,children:[(0,g.jsx)(s,{}),Q(`host:scm-switch`,v(`scmSwitch`))]}),"host:scm-push":(0,g.jsxs)(`button`,{type:`button`,className:`btn`,disabled:!y||y.detached||L,title:v(`scmPushTip`),onClick:Ye,children:[(0,g.jsx)(n,{}),Q(`host:scm-push`,v(`scmPush`))]}),"host:scm-pull":(0,g.jsxs)(`button`,{type:`button`,className:`btn`,disabled:!y||y.detached||L,title:v(`scmPullTip`),onClick:Xe,children:[(0,g.jsx)(a,{}),Q(`host:scm-pull`,v(`scmPull`))]}),"host:scm-input":(0,g.jsx)(`input`,{className:`scm-commit-input`,value:H,placeholder:v(`scmCommitPlaceholder`),disabled:L,title:Oe.length>0?v(`scmCommitHistoryTip`):void 0,onChange:e=>{U(e.target.value),W.current=h},onKeyDown:e=>{if(!e.nativeEvent.isComposing){if(e.key===`Enter`){We();return}if(e.key===`ArrowUp`||e.key===`ArrowDown`){let t=le(Oe,W.current,H,e.key===`ArrowUp`?`up`:`down`);t&&(e.preventDefault(),W.current=t.state,U(t.text))}}}}),"host:scm-genmsg":(0,g.jsxs)(`button`,{type:`button`,className:`btn`,disabled:R||L||!y||y.files.length===0,title:v(`scmGenMsgTip`),onClick:Ze,children:[(0,g.jsx)(t,{className:R?`scm-spin`:``}),R?v(`scmGenMsgRunning`):Q(`host:scm-genmsg`,v(`scmGenMsg`))]}),"host:scm-commit":(0,g.jsxs)(`button`,{type:`button`,className:`btn primary`,disabled:!H.trim()||L,title:v(`scmCommitTip`),onClick:We,children:[(0,g.jsx)(i,{}),Q(`host:scm-commit`,v(`scmCommit`))]}),"host:scm-commit-all":(0,g.jsx)(`button`,{type:`button`,className:`btn`,disabled:!H.trim()||L,title:v(`scmCommitAllTip`),onClick:Ge,children:Q(`host:scm-commit-all`,v(`scmCommitAll`))})};return(0,g.jsxs)(`div`,{className:`scm-view`,children:[(0,g.jsxs)(`div`,{className:`scm-header`,children:[(0,g.jsxs)(`div`,{className:`scm-title-row`,children:[(0,g.jsxs)(`span`,{className:`scm-title`,children:[(0,g.jsx)(s,{}),v(`scmTitle`)]}),(0,g.jsx)(`div`,{className:`scm-view-tabs`,role:`tablist`,children:u(rt([`host:scm-changes`,`host:scm-history`],!1),$,_)}),u(rt([`host:scm-refresh`],!0),$,_)]}),(0,g.jsxs)(`div`,{className:`scm-row`,children:[(0,g.jsxs)(`span`,{className:`scm-branch-current`,title:v(`scmCurrentBranch`),children:[(0,g.jsx)(s,{}),y?y.detached?v(`scmDetached`):y.branch:`…`,y?.upstream&&(0,g.jsx)(`span`,{className:`scm-upstream`,children:y.upstreamGone?v(`scmUpstreamGone`):y.ahead>0||y.behind>0?v(`scmAheadBehind`,{ahead:y.ahead,behind:y.behind}):y.upstream})]}),u(rt(nt,!1),$,_)]}),we&&(0,g.jsx)(`div`,{className:`scm-gen-error`,role:`alert`,title:v(`close`),onClick:()=>B(null),children:we})]}),(0,g.jsxs)(`div`,{className:`scm-body`,ref:Re,style:{"--scm-sidebar-w":`${V}px`},children:[w===`history`?(0,g.jsxs)(`div`,{className:`scm-history`,children:[(0,g.jsxs)(`div`,{className:`scm-files-header`,children:[(0,g.jsx)(`span`,{children:v(`scmHistory`)}),T.length>0&&(0,g.jsx)(`span`,{className:`scm-files-count`,children:Ee.trim()?`${$e.length}/${T.length}`:T.length})]}),T.length>0&&!L&&(0,g.jsx)(`input`,{className:`scm-history-filter`,value:Ee,placeholder:v(`scmHistoryFilterPlaceholder`),title:v(`scmHistoryFilterTip`),onChange:e=>De(e.target.value)}),(0,g.jsx)(`div`,{className:`scm-history-list`,children:L?(0,g.jsx)(`div`,{className:`scm-empty`,children:v(`scmNotGitRepo`)}):!y||xe?(0,g.jsx)(`div`,{className:`scm-empty`,children:e.status===`open`?v(`scmLoading`):v(`scmConnecting`)}):T.length===0?(0,g.jsx)(`div`,{className:`scm-empty`,children:v(`scmNoHistory`)}):$e.length===0?(0,g.jsx)(`div`,{className:`scm-empty`,children:v(`scmHistoryFilterEmpty`)}):$e.map(e=>(0,g.jsxs)(`button`,{type:`button`,className:`scm-commit ${E?.hash===e.hash?`active`:``}`,onClick:()=>Ue(e),title:e.hash,children:[(0,g.jsx)(`span`,{className:`scm-commit-graph`,"aria-hidden":`true`,children:e.graph||`* `}),(0,g.jsxs)(`span`,{className:`scm-commit-info`,children:[(0,g.jsx)(`span`,{className:`scm-commit-subject`,children:e.subject}),(0,g.jsxs)(`span`,{className:`scm-commit-meta`,children:[e.shortHash,` · `,e.author,` · `,e.date]}),e.decorations&&(0,g.jsx)(`span`,{className:`scm-commit-refs`,children:e.decorations})]})]},e.hash))})]}):(0,g.jsxs)(`div`,{className:`scm-files`,children:[(0,g.jsxs)(`div`,{className:`scm-files-header`,children:[(0,g.jsx)(`span`,{children:v(`scmChanges`)}),y&&y.files.length>0&&(0,g.jsx)(`span`,{className:`scm-files-count`,children:y.files.length})]}),(0,g.jsx)(`div`,{className:`scm-files-list`,children:L?(0,g.jsx)(`div`,{className:`scm-empty`,children:v(`scmNotGitRepo`)}):y?y.files.length===0?(0,g.jsx)(`div`,{className:`scm-empty`,children:v(`scmNoChanges`)}):y.files.map(e=>{let t=ue(e),n=fe.get(e.path);return(0,g.jsxs)(`div`,{className:`scm-file ${A?.path===e.path?`active`:``}`,title:Qe[t],onClick:()=>He(e),children:[(0,g.jsx)(`span`,{className:`scm-file-xy ${t===`untracked`?`q`:`x`}`,children:e.x===` `?`\xA0`:e.x}),(0,g.jsx)(`span`,{className:`scm-file-xy ${t===`untracked`?`q`:`y`}`,children:e.y===` `?`\xA0`:e.y}),(0,g.jsx)(`span`,{className:`scm-file-path`,children:e.path}),n&&(n.add>0||n.del>0)&&(0,g.jsxs)(`span`,{className:`scm-file-stat`,children:[n.add>0&&(0,g.jsxs)(`span`,{className:`add`,children:[`+`,n.add]}),n.del>0&&(0,g.jsxs)(`span`,{className:`del`,children:[`-`,n.del]})]}),(0,g.jsxs)(`span`,{className:`scm-file-actions`,children:[(e.y!==` `||t===`untracked`)&&(0,g.jsx)(`button`,{type:`button`,className:`scm-act`,title:v(`scmStageTip`,{path:e.path}),onClick:t=>{t.stopPropagation(),Ke(e)},children:`+`}),t===`staged`||t===`both`?(0,g.jsx)(`button`,{type:`button`,className:`scm-act`,title:v(`scmUnstageTip`,{path:e.path}),onClick:t=>{t.stopPropagation(),qe(e)},children:`−`}):null]})]},e.path)}):(0,g.jsx)(`div`,{className:`scm-empty`,children:e.status===`open`?v(`scmLoading`):v(`scmConnecting`)})})]}),(0,g.jsx)(`div`,{className:`scm-divider`,role:`separator`,"aria-orientation":`vertical`,title:v(`dragToResize`),onPointerDown:ze,onDoubleClick:Be}),(0,g.jsxs)(`div`,{className:`scm-diff`,children:[(0,g.jsxs)(`div`,{className:`scm-diff-header`,children:[(0,g.jsx)(`span`,{children:w===`history`?E?`${E.shortHash} ${E.subject}`:v(`scmCommitDetail`):A?A.path:v(`scmDiff`)}),(w===`history`?k:ve)&&(0,g.jsx)(`span`,{className:`scm-diff-loading`,children:v(`scmLoading`)})]}),(0,g.jsx)(`div`,{className:`scm-diff-body`,children:w===`history`?(0,g.jsxs)(g.Fragment,{children:[F&&(0,g.jsx)(`div`,{className:`scm-error`,children:F}),!E&&!F&&(0,g.jsx)(`div`,{className:`scm-empty`,children:v(`scmSelectCommitHint`)}),E&&k&&!F&&(0,g.jsx)(`div`,{className:`scm-empty`,children:v(`scmLoading`)}),E&&!k&&!F&&ge?et(ge):null]}):(0,g.jsxs)(g.Fragment,{children:[F&&(0,g.jsx)(`div`,{className:`scm-error`,children:F}),!A&&!F&&(0,g.jsx)(`div`,{className:`scm-empty`,children:v(`scmSelectFileHint`)}),A&&!M&&!F&&(0,g.jsx)(`div`,{className:`scm-empty`,children:v(`scmLoading`)}),A&&M&&M.untracked&&(0,g.jsx)(`div`,{className:`scm-empty`,children:v(`scmUntrackedNote`)}),A&&M&&!M.untracked&&(0,g.jsxs)(g.Fragment,{children:[M.staged&&(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`div`,{className:`scm-diff-section`,children:v(`scmStaged`)}),et(M.staged)]}),M.worktree&&(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`div`,{className:`scm-diff-section`,children:v(`scmUnstaged`)}),et(M.worktree)]}),!M.staged&&!M.worktree&&(0,g.jsx)(`div`,{className:`scm-empty`,children:v(`scmNoDiff`)})]})]})})]})]}),(0,g.jsxs)(`div`,{className:`scm-hint`,children:[(0,g.jsx)(ee,{}),(0,g.jsx)(`span`,{children:v(`scmRunsInTerminal`)}),it(`host:scm-term`)&&(0,g.jsx)(`button`,{type:`button`,className:`scm-goto-term`,onClick:f,children:Q(`host:scm-term`,v(`scmViewTerminal`))})]})]})}export{_ as ScmPanel};