pi-web-ui 0.115.0 โ†’ 0.117.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 (161) hide show
  1. package/CHANGELOG.md +65 -2
  2. package/bin/device-hub-cli.mjs +26 -3
  3. package/bin/pi-web-ui.mjs +159 -71
  4. package/dist/server/agent-service-daemon.js +136 -8
  5. package/dist/server/agent-service.js +594 -159
  6. package/dist/server/canvas/canvas-workspace.js +18 -86
  7. package/dist/server/client-state.js +52 -8
  8. package/dist/server/compaction-markers.js +43 -24
  9. package/dist/server/dangling-tools.js +172 -16
  10. package/dist/server/device-center/bot-execution.js +77 -2
  11. package/dist/server/device-center/collab-service.js +61 -12
  12. package/dist/server/device-center/collab-tool.js +482 -21
  13. package/dist/server/device-center/connector.js +107 -37
  14. package/dist/server/device-center/delivery-authority.js +98 -0
  15. package/dist/server/device-center/delivery-subject.js +30 -0
  16. package/dist/server/device-center/device-integration.js +453 -183
  17. package/dist/server/device-center/execution-guides.js +17 -7
  18. package/dist/server/device-center/execution-instructions.js +2 -1
  19. package/dist/server/device-center/execution-settings.js +138 -25
  20. package/dist/server/device-center/executor.js +51 -6
  21. package/dist/server/device-center/file-sync.js +14 -13
  22. package/dist/server/device-center/group-context-message.js +3 -1
  23. package/dist/server/device-center/group-context.js +73 -3
  24. package/dist/server/device-center/hub-conversations.js +71 -6
  25. package/dist/server/device-center/hub-deliveries.js +120 -15
  26. package/dist/server/device-center/hub-integration.js +655 -334
  27. package/dist/server/device-center/hub-locks.js +320 -0
  28. package/dist/server/device-center/hub-page.js +16 -35
  29. package/dist/server/device-center/hub-setup.js +23 -1
  30. package/dist/server/device-center/hub-transaction-log.js +197 -0
  31. package/dist/server/device-center/hub-webhooks.js +165 -0
  32. package/dist/server/device-center/hub.js +1531 -305
  33. package/dist/server/device-center/integration-verification.js +113 -0
  34. package/dist/server/device-center/local-hub.js +8 -3
  35. package/dist/server/device-center/local-publication.js +423 -0
  36. package/dist/server/device-center/local-verification-job.js +97 -0
  37. package/dist/server/device-center/local-verification.js +274 -0
  38. package/dist/server/device-center/local.js +181 -13
  39. package/dist/server/device-center/main.js +4 -1
  40. package/dist/server/device-center/partition-log.js +330 -0
  41. package/dist/server/device-center/publication-journal.js +312 -0
  42. package/dist/server/device-center/publish-intent.js +379 -0
  43. package/dist/server/device-center/relay.js +134 -24
  44. package/dist/server/device-center/runtime.js +475 -42
  45. package/dist/server/device-center/store.js +366 -89
  46. package/dist/server/device-center/task-outcome.js +81 -0
  47. package/dist/server/device-center/task-recovery.js +603 -178
  48. package/dist/server/device-center/task-scheduler.js +48 -3
  49. package/dist/server/device-center/task-settlement.js +353 -0
  50. package/dist/server/device-center/task-workspace.js +443 -0
  51. package/dist/server/device-center/transfers.js +41 -15
  52. package/dist/server/device-center/verification-limits.js +10 -0
  53. package/dist/server/device-center/work-contract.js +995 -0
  54. package/dist/server/dispatch-domain-handlers.js +29 -3
  55. package/dist/server/dsh/dsh-agent-service.js +9 -2
  56. package/dist/server/engine-probe.js +112 -1
  57. package/dist/server/global-loader.js +119 -19
  58. package/dist/server/index.js +159 -17
  59. package/dist/server/managed.js +2 -0
  60. package/dist/server/model-admin.js +48 -6
  61. package/dist/server/model-enrich.js +10 -1
  62. package/dist/server/patch-node-pty.js +3 -2
  63. package/dist/server/patch-remote-catalog.js +3 -2
  64. package/dist/server/plugins.js +64 -7
  65. package/dist/server/preset-fields.js +17 -1
  66. package/dist/server/preset-share.js +1 -0
  67. package/dist/server/prompt-composer.js +39 -0
  68. package/dist/server/protocol-version.js +1 -1
  69. package/dist/server/quick-ask-settings.js +28 -0
  70. package/dist/server/quick-ask.js +164 -0
  71. package/dist/server/reasoning-registry.js +207 -0
  72. package/dist/server/resolve-global-sdk.js +61 -11
  73. package/dist/server/scheduler-tasks.js +35 -8
  74. package/dist/server/session-list-scan.js +223 -0
  75. package/dist/server/session-open.js +93 -0
  76. package/dist/server/session-parser.js +4 -0
  77. package/dist/server/session-scan.js +90 -38
  78. package/dist/server/settings-service.js +9 -1
  79. package/dist/server/soft-cap.js +5 -0
  80. package/dist/server/startup-banner.js +35 -0
  81. package/dist/server/subagents.js +2 -1
  82. package/dist/server/tool-manager.js +17 -9
  83. package/dist/server/transcript-prepare.js +73 -0
  84. package/dist/server/unauthorized-page.js +319 -0
  85. package/dist/server/universal/drivers/claude-code.js +98 -34
  86. package/dist/server/universal/universal-session.js +4 -0
  87. package/dist/server/workspace-handle.js +428 -0
  88. package/docs/architecture-plugins.md +959 -0
  89. package/docs/device-center.md +34 -20
  90. package/package.json +4 -4
  91. package/plugin-sdk/README.md +16 -8
  92. package/plugin-sdk/client.d.ts +27 -0
  93. package/plugin-sdk/client.mjs +82 -0
  94. package/plugin-sdk/index.d.ts +10 -0
  95. package/plugin-sdk/index.mjs +4 -683
  96. package/plugin-sdk/package.json +15 -4
  97. package/plugin-sdk/testing.d.ts +10 -0
  98. package/plugin-sdk/testing.mjs +566 -0
  99. package/themes/flow-cristallo.css +168 -0
  100. package/themes/flow-ink.css +169 -0
  101. package/themes/flow-obsidian.css +169 -0
  102. package/themes/flow-zurich.css +169 -0
  103. package/web/dist/.build-assets.json +1 -1
  104. package/web/dist/assets/{BgTasksModal-BYzPgmoq.js โ†’ BgTasksModal-BjNRIUIc.js} +1 -1
  105. package/web/dist/assets/{BgTasksModal-ni0VTmAQ.js โ†’ BgTasksModal-C0zuU8FE.js} +1 -1
  106. package/web/dist/assets/{CanvasStudio-DNmDNBod.js โ†’ CanvasStudio-BWvdmJ0M.js} +3 -3
  107. package/web/dist/assets/{CanvasStudio-BCUeEf25.js โ†’ CanvasStudio-VQFjmTGq.js} +3 -3
  108. package/web/dist/assets/DeviceCenter-DI9_0aBB.js +3 -0
  109. package/web/dist/assets/DeviceCenter-DsNtXqzY.js +3 -0
  110. package/web/dist/assets/DeviceExecutionSettings-BLP1Su5G.js +1 -0
  111. package/web/dist/assets/DeviceGroups-2Pvk0Cds.js +1 -0
  112. package/web/dist/assets/DeviceGroups-CP7CcyPD.js +1 -0
  113. package/web/dist/assets/{Dropdown-CGXD0DfT.js โ†’ Dropdown-CQtstPGv.js} +1 -1
  114. package/web/dist/assets/FilePreview-BMB2tNyT.js +2 -0
  115. package/web/dist/assets/FilePreview-RGFQUbJo.js +2 -0
  116. package/web/dist/assets/{GlobalSearchModal-mevF-ySi.js โ†’ GlobalSearchModal-BM5wxiqU.js} +1 -1
  117. package/web/dist/assets/{GlobalSearchModal-qL99FN_F.js โ†’ GlobalSearchModal-DGv_WINq.js} +1 -1
  118. package/web/dist/assets/GroupConversation-B7SnuXj1.js +61 -0
  119. package/web/dist/assets/GroupConversation-Dda69q-2.js +61 -0
  120. package/web/dist/assets/{HintTip-LHwkS2jV.js โ†’ HintTip-ChTW8o1m.js} +1 -1
  121. package/web/dist/assets/ModelConfigModal-C-0Z4hUZ.js +2 -0
  122. package/web/dist/assets/ModelConfigModal-yqeadyab.js +2 -0
  123. package/web/dist/assets/{PiSetupModal-DE5-gEtI.js โ†’ PiSetupModal-BX5rUuoI.js} +1 -1
  124. package/web/dist/assets/{ProviderOAuthControls-6UMARucA.js โ†’ ProviderOAuthControls-DY4SCfXg.js} +1 -1
  125. package/web/dist/assets/SCMPanel-C4KbQvvK.js +2 -0
  126. package/web/dist/assets/SCMPanel-DPAyY2sW.js +2 -0
  127. package/web/dist/assets/SettingsModal-DxZp6D_g.js +32 -0
  128. package/web/dist/assets/SettingsModal-WhQzaOPt.js +32 -0
  129. package/web/dist/assets/{TerminalPanel-CTp_BZ4S.js โ†’ TerminalPanel-D4By_RVc.js} +2 -2
  130. package/web/dist/assets/{TerminalPanel-CkYxC-Gh.js โ†’ TerminalPanel-lZw8-i3j.js} +2 -2
  131. package/web/dist/assets/{TuiOverlayModal-1cRLP8IF.js โ†’ TuiOverlayModal-C3pAVuC8.js} +1 -1
  132. package/web/dist/assets/{TuiOverlayModal-2xlptqWX.js โ†’ TuiOverlayModal-D7_rEXcJ.js} +1 -1
  133. package/web/dist/assets/app-globals-KqOVtmp1.js +123 -0
  134. package/web/dist/assets/{canvas-client-Bye9nSFO.js โ†’ canvas-client-BY6ojmle.js} +1 -1
  135. package/web/dist/assets/{desktop-kjBoE3Nu.js โ†’ desktop-CV6KKp9R.js} +1 -1
  136. package/web/dist/assets/index-BawF7ZP5.js +397 -0
  137. package/web/dist/assets/index-BoGCoq5X.js +397 -0
  138. package/web/dist/assets/index-CVW9FoY2.css +1 -0
  139. package/web/dist/assets/{plugin-host-C8mNgghx.js โ†’ plugin-host-Dn8Dd6SC.js} +1 -1
  140. package/web/dist/assets/{remote-ssh-client-CeP3CLUW.js โ†’ remote-ssh-client-Dzi-eEyE.js} +1 -1
  141. package/web/dist/assets/{theme-BXGpyTMh.js โ†’ theme-D_bihpdN.js} +1 -1
  142. package/web/dist/index.html +11 -11
  143. package/web/dist/sw.js +1 -1
  144. package/dist/server/patch-turn-end-boundary.js +0 -77
  145. package/web/dist/assets/DeviceCenter-BcBhRgL6.js +0 -3
  146. package/web/dist/assets/DeviceCenter-CmL5FZmt.js +0 -3
  147. package/web/dist/assets/DeviceGroups-CLdpdnI7.js +0 -1
  148. package/web/dist/assets/DeviceGroups-CgBaDPrD.js +0 -1
  149. package/web/dist/assets/FilePreview-B8iqnBjy.js +0 -2
  150. package/web/dist/assets/FilePreview-BqviZKCN.js +0 -2
  151. package/web/dist/assets/GroupConversation-B88Yy-lt.js +0 -3
  152. package/web/dist/assets/GroupConversation-BwP5NVOE.js +0 -3
  153. package/web/dist/assets/ModelConfigModal-Do3Fe3jH.js +0 -2
  154. package/web/dist/assets/SCMPanel-Hi6QqC1Q.js +0 -2
  155. package/web/dist/assets/SCMPanel-ezY_ZtCu.js +0 -2
  156. package/web/dist/assets/SettingsModal-6HgeEsJ8.js +0 -20
  157. package/web/dist/assets/SettingsModal-CF-7MwqS.js +0 -20
  158. package/web/dist/assets/app-globals-DZNa9v8u.js +0 -325
  159. package/web/dist/assets/index-CsFs_HMb.css +0 -1
  160. package/web/dist/assets/index-DHeeHS_l.js +0 -85
  161. package/web/dist/assets/index-DTZch8uz.js +0 -85
@@ -0,0 +1,3 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$ as t,A as n,Bt as r,Dn as i,H as a,Nt as o,Ot as s,Sn as ee,Tn as te,Vt as c,Xt as ne,Z as l,bn as u,bt as d,fn as f,in as p,kn as m,pt as h,un as g,xn as _}from"./app-globals-KqOVtmp1.js";import{i as v,t as re}from"./react-CR5VJ85Q.js";import{Ht as ie,gt as ae}from"./index-BoGCoq5X.js";import{t as y}from"./DeviceExecutionSettings-BLP1Su5G.js";var b=e(v(),1),x=re();function S({href:e,children:t}){let n=ee(),[r,i]=(0,b.useState)(!1),[a,o]=(0,b.useState)(!1);return(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(`a`,{className:`dc-button`,href:e,target:`_blank`,rel:`noopener noreferrer`,onClick:t=>{let n=window.piDesktop;n?.openHub&&(t.preventDefault(),!a&&(o(!0),i(!1),n.openHub(e).then(e=>i(!e),()=>i(!0)).finally(()=>o(!1))))},"aria-busy":a,children:t}),r&&(0,x.jsxs)(`span`,{role:`alert`,children:[n(`deviceHubNetworkError`),` `,(0,x.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,children:e})]})]})}function C(e){if(!w(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 w(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 T(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 E=`https://raw.githubusercontent.com/xing-shuyin/pi-web-ui/main/docs/device-center-deployment.md`,D=`https://github.com/xing-shuyin/pi-web-ui/blob/main/docs/device-center-deployment.md`,O=`pi-web-ui hub install --host 0.0.0.0 --port 8790 --public-url http://SERVER_IP:8790 --allow-registration`;function k(e){let t=e=>e.includes(`:`)?w(e)&&![`::`,`::1`].includes(e):/^[\d.]+$/.test(e)?w(e)&&![`0.0.0.0`,`127.0.0.1`].includes(e):e.length<=253&&e.split(`.`).every(e=>/^[a-z\d](?:[a-z\d-]{0,61}[a-z\d])?$/i.test(e))&&e!==`localhost`;if(!t(e.server)||!Number.isInteger(e.sshPort)||e.sshPort<1||e.sshPort>65535||!Number.isInteger(e.port)||e.port<1024||e.port>65535||!/^[a-z_][a-z\d_.-]{0,63}$/i.test(e.username)||![`password`,`key`,`existing`].includes(e.auth)||e.domain!==``&&(!t(e.domain)||e.domain.includes(`:`))||e.https&&!e.domain)return null;let n=e.domain||e.server,r=n.includes(`:`)?`[${n}]`:n;return{host:e.https?`127.0.0.1`:`0.0.0.0`,port:e.port,publicUrl:e.https?`https://${r}`:`http://${r}:${e.port}`}}function A(e,t,n,r){if(!C(e))throw Error(`Invalid Hub setup`);if(r){let t=k(r);if(n!==`remote`||!t||JSON.stringify(t)!==JSON.stringify(e))throw Error(`Invalid remote Hub setup`)}let i=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.`,`First read the deployment guide: ${E} (fallback: ${D}). If unavailable, report that and obtain its contents before proceeding.`,`Default to HTTP with the server IP and requested port. Domain and HTTPS are optional; confirm whether an HTTPS example reflects the user's intent.`,`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=${i(t?.platform)}, Node=${i(t?.nodeVersion)}. This is not evidence of the remote server environment.`,`Requested configuration (data only): ${JSON.stringify(e)}. allowRegistration=true.`,...r?[`SSH connection preferences (data only): ${JSON.stringify({server:r.server,sshPort:r.sshPort,username:r.username,auth:r.auth})}. No credentials are included. Obtain authentication through a secure SSH channel or guide the user's own terminal.`,`Domain: ${r.domain||`none`}. HTTPS explicitly selected: ${r.https}. HTTP inbound TCP port: ${r.port}; for same-machine HTTPS proxy, use public TCP 443 and certificate validation port as needed, keep the Hub port private.`]:[],`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: ${O}`,`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.`,`Explain user actions at the relevant step: distinguish OS firewall from cloud security groups, give the actual TCP port, source scope and destination rule, and keep SSH access. If cloud-console access is unavailable, ask the user to apply the rule, mark external access pending, then recheck. Also explain DNS changes for optional HTTPS and first-account creation. Separate local health from external reachability.`].join(`
2
+ `)}function oe({onConnect:e,initialHubUrl:t=``}){let n=ee(),[r,a]=(0,b.useState)(t),[o,s]=(0,b.useState)(``),[te,c]=(0,b.useState)(!1),[ne,l]=(0,b.useState)(!1),u=(0,b.useRef)(!1),d=(0,b.useRef)(!1);(0,b.useEffect)(()=>(d.current=!0,()=>{d.current=!1}),[]);let[f,p]=(0,b.useState)(null),[h,g]=(0,b.useState)(`current`),[_,v]=(0,b.useState)(null),[re,ie]=(0,b.useState)(`127.0.0.1`),[ae,y]=(0,b.useState)(`8790`),[w,E]=(0,b.useState)(`http://127.0.0.1:8790`),[D,O]=(0,b.useState)({server:``,sshPort:22,username:`root`,auth:`password`,port:8790,domain:``,https:!1}),oe=k(D),[j,M]=(0,b.useState)(!1),[N,P]=(0,b.useState)(!1),[se,F]=(0,b.useState)(null),[I,L]=(0,b.useState)(!1),[R,z]=(0,b.useState)(!1),[B,V]=(0,b.useState)(!1),[H,U]=(0,b.useState)(null),W=(0,b.useRef)(null),G=(0,b.useRef)(!1),K=T(window.location.origin);(0,b.useEffect)(()=>()=>W.current?.abort(),[]);let q=async()=>{if(G.current)return;W.current?.abort();let e=new AbortController;W.current=e,L(!1),z(!1),V(!1);try{let t=await fetch(i(m(`/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`||!C({host:`127.0.0.1`,port:n.defaultPort,publicUrl:n.defaultPublicUrl}))throw Error();if(e.signal.aborted)return;v(n),n.installation?.installed?(ie(n.installation.host??`127.0.0.1`),y(String(n.installation.port)),E(n.installation.publicUrl??``),a(n.installation.publicUrl??``)):_||(y(String(n.defaultPort)),E(n.defaultPublicUrl))}catch{e.signal.aborted||(L(!0),V(!0))}finally{e.signal.aborted||z(!0)}},ce=async()=>{let e={host:re,port:Number(ae),publicUrl:w};if(G.current||!K||!_||!R||B||_.busy||_.installation?.installed||!C(e))return;G.current=!0,W.current?.abort(),M(!0),L(!1),s(``);let t=new AbortController;W.current=t;try{let n=await fetch(i(m(`/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){v(e=>e&&{...e,busy:!0}),G.current=!1,M(!1),await q();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(!C({...e,publicUrl:r.publicUrl})||typeof r.output!=`string`)throw Error();t.signal.aborted||U(r)}catch(e){t.signal.aborted||(L(!0),s(e instanceof Error?e.message.slice(0,4096):``))}finally{G.current=!1,t.signal.aborted||M(!1)}},J=async()=>{if(G.current||!K||!_||!R||B||_.busy||j||N)return;G.current=!0,W.current?.abort(),P(!0),L(!1),s(``),F(null);let e=new AbortController;W.current=e;try{let t=await fetch(i(m(`/api/device-center/setup/update`)),{credentials:`same-origin`,method:`POST`,headers:{"Content-Type":`application/json`},signal:e.signal});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(typeof e.error==`string`?e.error.slice(0,4096):`HTTP ${t.status}`)}let r=await t.json();e.signal.aborted||(F(r.output||n(`deviceSetupUpdateSuccess`)),await q())}catch(t){e.signal.aborted||(L(!0),s(t instanceof Error?t.message.slice(0,4096):``))}finally{G.current=!1,e.signal.aborted||P(!1)}},Y=_?.installation,X=!!Y?.installed,Z=X&&Y.running&&Y.owned,Q=h===`remote`?oe:{host:re,port:Number(ae),publicUrl:w},le=!!Q&&C(Q);return(0,x.jsxs)(`section`,{className:`dc-onboarding`,children:[(0,x.jsx)(`h3`,{children:n(`deviceSetupWelcome`)}),(0,x.jsx)(`p`,{children:n(`deviceSetupIntro`)}),(0,x.jsxs)(`div`,{className:`dc-actions`,children:[(0,x.jsx)(`button`,{className:`dc-button`,disabled:j,"aria-pressed":f===`connect`,onClick:()=>p(`connect`),children:n(`deviceSetupConnect`)}),(0,x.jsx)(`button`,{className:`dc-button`,disabled:j,"aria-pressed":f===`create`,onClick:()=>{p(`create`),!_&&K&&q()},children:n(`deviceSetupCreate`)})]}),f===`connect`&&(0,x.jsxs)(`form`,{onSubmit:t=>{t.preventDefault(),e(r.trim())},children:[(0,x.jsxs)(`label`,{className:`dc-field`,children:[(0,x.jsx)(`span`,{children:n(`deviceHubHubUrl`)}),(0,x.jsx)(`input`,{type:`url`,required:!0,maxLength:2048,value:r,onChange:e=>a(e.target.value),placeholder:`https://hub.example.com`})]}),(0,x.jsx)(`button`,{className:`dc-button is-primary`,disabled:!C({host:`localhost`,port:8790,publicUrl:r.trim()}),children:n(`deviceSetupPair`)})]}),f===`create`&&(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)(`label`,{className:`dc-field`,children:[(0,x.jsx)(`span`,{children:n(`deviceSetupTarget`)}),(0,x.jsxs)(`select`,{disabled:j,value:h,onChange:e=>g(e.target.value),children:[(0,x.jsx)(`option`,{value:`current`,children:n(`deviceSetupCurrent`)}),(0,x.jsx)(`option`,{value:`remote`,children:n(`deviceSetupRemote`)})]})]}),(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(`p`,{children:n(h===`current`?`deviceSetupCurrentHint`:`deviceSetupRemoteHint`)}),h===`current`&&(0,x.jsxs)(`div`,{className:`dc-setup-plan`,children:[(0,x.jsx)(`strong`,{children:n(`deviceSetupPlan`)}),(0,x.jsx)(`p`,{children:n(`deviceSetupPlanHint`)}),_&&(0,x.jsxs)(`dl`,{children:[(0,x.jsx)(`dt`,{children:n(`deviceSetupEnvironment`)}),(0,x.jsxs)(`dd`,{children:[_.platform,` ยท Node `,_.nodeVersion]}),(0,x.jsx)(`dt`,{children:n(`deviceSetupDataDir`)}),(0,x.jsx)(`dd`,{children:_.dataDir}),(0,x.jsx)(`dt`,{children:n(`deviceSetupCli`)}),(0,x.jsx)(`dd`,{children:_.cliPath})]}),!K&&(0,x.jsx)(`p`,{role:`status`,children:n(`deviceSetupLocalOnly`)}),(0,x.jsx)(`p`,{children:n(`deviceSetupBackground`)}),X&&(0,x.jsxs)(`div`,{role:`status`,children:[(0,x.jsx)(`h4`,{children:n(Z?`deviceSetupRestored`:`deviceSetupUnhealthy`)}),(0,x.jsx)(`p`,{children:Y.publicUrl}),Z&&le&&Y.publicUrl?(0,x.jsxs)(`div`,{className:`dc-actions`,children:[(0,x.jsx)(S,{href:Y.publicUrl,children:n(`deviceHubOpenHub`)}),(0,x.jsx)(`button`,{className:`dc-button`,onClick:()=>e(Y.publicUrl),children:n(`deviceSetupPair`)}),K&&(0,x.jsx)(`button`,{className:`dc-button`,disabled:j||N,onClick:()=>void J(),children:n(N?`deviceSetupUpdating`:`deviceSetupUpdate`)})]}):(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(`p`,{children:n(`deviceSetupRecovery`)}),(0,x.jsx)(`pre`,{className:`dc-setup-output`,children:`pi-web-ui hub status --json
3
+ pi-web-ui hub --help`}),K&&(0,x.jsx)(`button`,{className:`dc-button is-primary`,disabled:j||N,onClick:()=>void J(),children:n(N?`deviceSetupUpdating`:`deviceSetupUpdate`)})]}),se&&(0,x.jsx)(`pre`,{className:`dc-setup-output`,children:se.slice(0,16e3)})]}),_?.busy&&(0,x.jsx)(`p`,{role:`status`,children:n(`deviceSetupBusy`)}),K&&(0,x.jsx)(`button`,{className:`dc-button`,disabled:j||!R,onClick:()=>void q(),children:n(R?`deviceSetupRetry`:`deviceHubWorking`)})]}),h===`remote`?(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)(`div`,{className:`dc-setup-fields`,children:[(0,x.jsxs)(`label`,{className:`dc-field`,children:[(0,x.jsx)(`span`,{children:n(`deviceSetupServer`)}),(0,x.jsx)(`input`,{autoComplete:`off`,maxLength:253,placeholder:`203.0.113.10`,value:D.server,onChange:e=>O({...D,server:e.target.value.trim()})})]}),(0,x.jsxs)(`label`,{className:`dc-field`,children:[(0,x.jsx)(`span`,{children:n(`deviceSetupSshPort`)}),(0,x.jsx)(`input`,{type:`number`,min:1,max:65535,value:D.sshPort,onChange:e=>O({...D,sshPort:Number(e.target.value)})})]}),(0,x.jsxs)(`label`,{className:`dc-field`,children:[(0,x.jsx)(`span`,{children:n(`deviceSetupUsername`)}),(0,x.jsx)(`input`,{autoComplete:`off`,maxLength:64,value:D.username,onChange:e=>O({...D,username:e.target.value})})]}),(0,x.jsxs)(`label`,{className:`dc-field`,children:[(0,x.jsx)(`span`,{children:n(`deviceSetupAuth`)}),(0,x.jsxs)(`select`,{value:D.auth,onChange:e=>O({...D,auth:e.target.value}),children:[(0,x.jsx)(`option`,{value:`password`,children:n(`deviceSetupAuthPassword`)}),(0,x.jsx)(`option`,{value:`key`,children:n(`deviceSetupAuthKey`)}),(0,x.jsx)(`option`,{value:`existing`,children:n(`deviceSetupAuthExisting`)})]})]}),(0,x.jsxs)(`label`,{className:`dc-field`,children:[(0,x.jsx)(`span`,{children:n(`deviceSetupServicePort`)}),(0,x.jsx)(`input`,{type:`number`,min:1024,max:65535,value:D.port,onChange:e=>O({...D,port:Number(e.target.value)})})]})]}),(0,x.jsx)(`p`,{children:n(`deviceSetupCredentialHint`)}),(0,x.jsxs)(`details`,{children:[(0,x.jsx)(`summary`,{children:n(`deviceSetupOptionalTls`)}),(0,x.jsxs)(`label`,{className:`dc-field`,children:[(0,x.jsx)(`span`,{children:n(`deviceSetupDomain`)}),(0,x.jsx)(`input`,{maxLength:253,placeholder:`hub.example.com`,value:D.domain,onChange:e=>O({...D,domain:e.target.value.trim()})})]}),(0,x.jsxs)(`label`,{children:[(0,x.jsx)(`input`,{type:`checkbox`,checked:D.https,onChange:e=>O({...D,https:e.target.checked})}),` `,n(`deviceSetupEnableHttps`)]}),(0,x.jsx)(`p`,{children:n(`deviceSetupTlsHint`)})]}),(0,x.jsxs)(`p`,{children:[(0,x.jsx)(`strong`,{children:n(`deviceSetupPreview`)}),` `,oe?.publicUrl??n(`deviceSetupPreviewEmpty`)]}),(0,x.jsxs)(`div`,{className:`dc-setup-plan`,children:[(0,x.jsx)(`strong`,{children:n(`deviceSetupUserActions`)}),(0,x.jsx)(`p`,{children:n(`deviceSetupCloudPorts`).replace(`{ports}`,D.https?`443 / 80`:String(D.port))}),(0,x.jsx)(`p`,{children:n(`deviceSetupSourceScope`)}),(0,x.jsx)(`p`,{children:n(`deviceSetupAfterStart`)})]}),(0,x.jsx)(`a`,{href:`https://github.com/xing-shuyin/pi-web-ui/blob/main/docs/device-center-deployment.md`,target:`_blank`,rel:`noopener noreferrer`,children:n(`deviceSetupGuide`)})]}):(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)(`div`,{className:`dc-setup-fields`,children:[(0,x.jsxs)(`label`,{className:`dc-field`,children:[(0,x.jsx)(`span`,{children:n(`deviceSetupHost`)}),(0,x.jsx)(`input`,{disabled:j||!!H,maxLength:253,value:re,onChange:e=>ie(e.target.value)})]}),(0,x.jsxs)(`label`,{className:`dc-field`,children:[(0,x.jsx)(`span`,{children:n(`deviceSetupPort`)}),(0,x.jsx)(`input`,{disabled:j||!!H,type:`number`,min:1024,max:65535,value:ae,onChange:e=>y(e.target.value)})]}),(0,x.jsxs)(`label`,{className:`dc-field`,children:[(0,x.jsx)(`span`,{children:n(`deviceHubHubUrl`)}),(0,x.jsx)(`input`,{disabled:j||!!H,maxLength:2048,value:w,onChange:e=>E(e.target.value)})]})]}),(0,x.jsx)(`p`,{className:`dc-setup-warning`,children:n(`deviceSetupReachable`)})]}),(0,x.jsx)(`p`,{children:n(`deviceSetupRegistration`)}),!le&&(0,x.jsx)(`p`,{role:`alert`,children:n(h===`remote`?`deviceSetupRemoteInvalid`:`deviceSetupInvalid`)}),(0,x.jsxs)(`div`,{className:`dc-actions`,children:[h===`current`&&!H&&!X&&(0,x.jsx)(`button`,{className:`dc-button is-primary`,disabled:j||!K||!_||!R||B||!!_.busy||!le,onClick:()=>void ce(),children:n(j?`deviceSetupInstalling`:`deviceSetupInstall`)}),(0,x.jsx)(`button`,{className:`dc-button`,disabled:j||te||!le,onClick:()=>{if(!le||!Q||u.current)return;u.current=!0,c(!0),l(!1);let e=e=>{u.current=!1,d.current&&(c(!1),l(!e))},t=window.__piWebUiHost;try{t?.startChat({newChat:!0,prompt:A(Q,_,h,h===`remote`?D:void 0),onResult:e})||e(!1)}catch{e(!1)}},children:n(h===`remote`?`deviceSetupStartAi`:`deviceSetupAi`)})]}),(0,x.jsx)(`p`,{children:n(`deviceSetupAiHint`)}),te&&(0,x.jsx)(`p`,{role:`status`,children:n(`deviceSetupAiCreating`)}),ne&&(0,x.jsx)(`p`,{role:`alert`,children:n(`deviceSetupAiFailed`)})]})]}),I&&(0,x.jsxs)(`div`,{role:`alert`,children:[(0,x.jsx)(`p`,{children:n(`deviceSetupFailed`)}),o&&(0,x.jsx)(`pre`,{className:`dc-setup-output`,children:o})]}),H&&(0,x.jsxs)(`div`,{role:`status`,children:[(0,x.jsx)(`h4`,{children:n(`deviceSetupSuccess`)}),(0,x.jsx)(`pre`,{className:`dc-setup-output`,children:H.output.slice(0,16e3)}),(0,x.jsxs)(`div`,{className:`dc-actions`,children:[(0,x.jsx)(S,{href:H.publicUrl,children:n(`deviceHubOpenHub`)}),(0,x.jsx)(`button`,{className:`dc-button is-primary`,onClick:()=>e(H.publicUrl),children:n(`deviceSetupPair`)})]})]})]})}var j=`pi-web-ui:device-groups-changed`;function M(e){window.dispatchEvent(new CustomEvent(`pi-web-ui:device-group-open`,{detail:{roomId:e}}))}async function N(e,t,n){let r=await fetch(i(m(`/api/device-center/${e}`)),{method:n?`POST`:`GET`,credentials:`same-origin`,signal:t,...n?{headers:{"Content-Type":`application/json`},body:JSON.stringify(n)}:{}}),a=await r.json().catch(()=>({}));if(!r.ok)throw Error(a.error||a.message||`Request failed (${r.status})`);return a}function P(){let{locale:e}=u(),t=te(e),[i,a]=(0,b.useState)([]),[o,ee]=(0,b.useState)([]),[ne,d]=(0,b.useState)(!0),[m,h]=(0,b.useState)(``),[_,v]=(0,b.useState)(``),[re,ie]=(0,b.useState)(0),[ae,y]=(0,b.useState)(!1),[S,C]=(0,b.useState)(``),[w,T]=(0,b.useState)([]),[E,D]=(0,b.useState)(``),[O,k]=(0,b.useState)(null),[A,oe]=(0,b.useState)([]),[P,se]=(0,b.useState)(``),[F,I]=(0,b.useState)(null),[L,R]=(0,b.useState)(``),[z,B]=(0,b.useState)(!1),V=(0,b.useRef)(0);(0,b.useEffect)(()=>{let e=++V.current,t=new AbortController;async function n(){try{let[n,r]=await Promise.all([N(`rooms`,t.signal),N(`bots`,t.signal)]);if(V.current!==e||t.signal.aborted)return;a(Array.isArray(n.rooms)?n.rooms:[]),ee(Array.isArray(r.bots)?r.bots:[]),h(``)}catch(n){V.current===e&&!t.signal.aborted&&h(n instanceof Error?n.message:String(n))}finally{V.current===e&&!t.signal.aborted&&d(!1)}}return n(),()=>{t.abort()}},[re]),(0,b.useEffect)(()=>{let e=()=>ie(e=>e+1);return window.addEventListener(j,e),()=>window.removeEventListener(j,e)},[]);async function H(e){if(e.preventDefault(),!S.trim()||z)return;B(!0),h(``),v(``);let n=new AbortController;try{let e=w.includes(E)?E:``,r=await N(`rooms`,n.signal,{name:S.trim(),botIds:w,...e?{primaryBotId:e}:{}});a(e=>[...e.filter(e=>e.id!==r.room.id),r.room]),y(!1),C(``),T([]),D(``),v(t?`็พค่Šๅˆ›ๅปบๆˆๅŠŸ`:`Group created successfully`),window.dispatchEvent(new CustomEvent(j))}catch(e){h(e instanceof Error?e.message:String(e))}finally{B(!1)}}function U(e){k(e.id),oe([...e.botIds]),se(e.primaryBotId??``),I(null),y(!1),h(``),v(``)}async function W(e){if(z)return;B(!0),h(``),v(``);let n=new AbortController;try{let r=A.includes(P)?P:null,i=await N(`rooms/${encodeURIComponent(e)}/members`,n.signal,{botIds:A,primaryBotId:r});a(t=>t.map(t=>t.id===e?i.room:t)),k(null),v(t?`ๆˆๅ‘˜่ฎพ็ฝฎๅทฒไฟๅญ˜`:`Members updated successfully`),window.dispatchEvent(new CustomEvent(j))}catch(e){h(e instanceof Error?e.message:String(e))}finally{B(!1)}}async function G(e){if(!L.trim()||z)return;B(!0),h(``),v(``);let n=new AbortController;try{await N(`rooms/${encodeURIComponent(e)}/rename`,n.signal,{name:L.trim()}),a(t=>t.map(t=>t.id===e?{...t,name:L.trim()}:t)),I(null),v(t?`็พค่Šๅ็งฐๅทฒๆ›ดๆ–ฐ`:`Group renamed successfully`),window.dispatchEvent(new CustomEvent(j))}catch(e){h(e instanceof Error?e.message:String(e))}finally{B(!1)}}async function K(e){if(z||!window.confirm(t?`็กฎๅฎšๅˆ ้™ค็พค่Šโ€œ${e.name}โ€๏ผŸ`:`Are you sure you want to delete "${e.name}"?`))return;B(!0),h(``),v(``);let n=new AbortController;try{await N(`rooms/${encodeURIComponent(e.id)}/delete`,n.signal,{}),a(t=>t.filter(t=>t.id!==e.id)),O===e.id&&k(null),F===e.id&&I(null),v(t?`็พค่Šๅทฒๅˆ ้™ค`:`Group deleted successfully`),window.dispatchEvent(new CustomEvent(j))}catch(e){h(e instanceof Error?e.message:String(e))}finally{B(!1)}}return(0,x.jsxs)(`section`,{className:`dc-card`,"aria-label":t?`็พค่Šๅˆ—่กจ`:`Group list`,children:[(0,x.jsxs)(`div`,{className:`dc-card-header`,children:[(0,x.jsx)(`span`,{className:`dc-icon`,children:(0,x.jsx)(g,{"aria-hidden":!0})}),(0,x.jsxs)(`div`,{children:[(0,x.jsxs)(`h2`,{children:[t?`็พค่Šๅˆ—่กจ`:`Group List`,` ยท `,i.length]}),(0,x.jsx)(`p`,{children:t?`็ฎก็†็พค่ŠไธŽๆˆๅ‘˜ Bot๏ผŒๅœจๆญค้…็ฝฎๅไฝœ็พค็ป„ๆˆ–็›ดๆŽฅ่ฟ›ๅ…ฅ่Šๅคฉใ€‚`:`Manage groups and member Bots. Configure collaboration groups or open chats here.`})]}),(0,x.jsxs)(`div`,{className:`dc-actions`,style:{marginInlineStart:`auto`},children:[(0,x.jsxs)(`button`,{type:`button`,className:`dc-button is-primary`,disabled:z,onClick:()=>{y(e=>!e),k(null),I(null),C(``),T([]),D(``)},children:[(0,x.jsx)(r,{"aria-hidden":!0}),t?`ๆ–ฐๅปบ็พค่Š`:`Create Group`]}),(0,x.jsx)(`button`,{type:`button`,className:`dc-icon-button`,"aria-label":t?`ๅˆทๆ–ฐ็พค่Š`:`Refresh groups`,onClick:()=>ie(e=>e+1),children:(0,x.jsx)(c,{})})]})]}),m&&(0,x.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:m}),_&&(0,x.jsxs)(`p`,{className:`dc-notice is-success`,role:`status`,children:[(0,x.jsx)(n,{"aria-hidden":!0}),_]}),ae&&(0,x.jsxs)(`form`,{className:`dc-card`,style:{marginBottom:`16px`,background:`var(--bg)`,border:`1px solid var(--border)`},onSubmit:H,children:[(0,x.jsxs)(`div`,{className:`dg-heading`,style:{marginBottom:`12px`},children:[(0,x.jsx)(`h3`,{children:t?`ๆ–ฐๅปบ็พค่Š`:`Create Group`}),(0,x.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>y(!1),disabled:z,children:[(0,x.jsx)(f,{"aria-hidden":!0}),t?`ๅ…ณ้—ญ`:`Close`]})]}),(0,x.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`12px`},children:[(0,x.jsx)(`label`,{htmlFor:`dg-manager-new-name`,children:t?`็พคๅ็งฐ`:`Group Name`}),(0,x.jsx)(`input`,{id:`dg-manager-new-name`,type:`text`,required:!0,maxLength:80,value:S,placeholder:t?`่พ“ๅ…ฅ็พคๅ็งฐ๏ผŒๅฆ‚๏ผš็ ”ๅ‘ๅไฝœ็พค`:`Enter group name`,onChange:e=>C(e.target.value),disabled:z,style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`}})]}),(0,x.jsxs)(`div`,{style:{marginBottom:`12px`},children:[(0,x.jsx)(`label`,{style:{display:`block`,marginBottom:`6px`,fontSize:`12px`,color:`var(--text-dim)`},children:t?`้€‰ๆ‹ฉๆˆๅ‘˜ Bot`:`Select Member Bots`}),(0,x.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`6px`,maxHeight:`160px`,overflowY:`auto`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`8px`,background:`var(--bg-elev)`},children:o.length===0?(0,x.jsx)(`p`,{style:{margin:0,fontSize:`12px`,color:`var(--text-faint)`},children:t?`ๆš‚ๆ— ๅฏ็”จ Bot๏ผŒ่ฏทๅ…ˆๅˆ›ๅปบ Botใ€‚`:`No Bots available. Please create a Bot first.`}):o.map(e=>(0,x.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,cursor:`pointer`,fontSize:`12px`},children:[(0,x.jsx)(`input`,{type:`checkbox`,checked:w.includes(e.id),disabled:z||!e.enabled,onChange:t=>{T(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}}),(0,x.jsxs)(`span`,{children:[(0,x.jsx)(`strong`,{children:e.name}),(0,x.jsxs)(`small`,{style:{color:`var(--text-faint)`,marginInlineStart:`6px`},children:[e.online?t?`ๅœจ็บฟ`:`Online`:t?`็ฆป็บฟ`:`Offline`,e.enabled?``:t?` ยท ๅทฒ็ฆ็”จ`:` ยท Disabled`]})]})]},e.id))})]}),w.length>0&&(0,x.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`16px`},children:[(0,x.jsx)(`label`,{htmlFor:`dg-manager-new-primary`,children:t?`ไธป Bot`:`Primary Bot`}),(0,x.jsxs)(`select`,{id:`dg-manager-new-primary`,value:w.includes(E)?E:``,onChange:e=>D(e.target.value),disabled:z,style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`},children:[(0,x.jsx)(`option`,{value:``,children:t?`ไธ่ฎพ็ฝฎ๏ผˆ้œ€ @ Bot๏ผ‰`:`None (mention a Bot)`}),o.filter(e=>w.includes(e.id)).map(e=>(0,x.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,x.jsxs)(`div`,{className:`dc-actions`,children:[(0,x.jsxs)(`button`,{type:`submit`,className:`dc-button is-primary`,disabled:z||!S.trim(),children:[(0,x.jsx)(n,{"aria-hidden":!0}),z?t?`ๅˆ›ๅปบไธญโ€ฆ`:`Creatingโ€ฆ`:t?`ๅˆ›ๅปบ็พค่Š`:`Create`]}),(0,x.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>y(!1),disabled:z,children:t?`ๅ–ๆถˆ`:`Cancel`})]})]}),O&&(0,x.jsxs)(`div`,{className:`dc-card`,style:{marginBottom:`16px`,background:`var(--bg)`,border:`1px solid var(--border)`},children:[(0,x.jsxs)(`div`,{className:`dg-heading`,style:{marginBottom:`12px`},children:[(0,x.jsxs)(`h3`,{children:[t?`็ฎก็†ๆˆๅ‘˜`:`Manage Members`,` ยท `,i.find(e=>e.id===O)?.name]}),(0,x.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>k(null),disabled:z,children:[(0,x.jsx)(f,{"aria-hidden":!0}),t?`ๅ…ณ้—ญ`:`Close`]})]}),(0,x.jsxs)(`div`,{style:{marginBottom:`12px`},children:[(0,x.jsx)(`label`,{style:{display:`block`,marginBottom:`6px`,fontSize:`12px`,color:`var(--text-dim)`},children:t?`้€‰ๆ‹ฉๆˆๅ‘˜ Bot`:`Select Member Bots`}),(0,x.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`6px`,maxHeight:`160px`,overflowY:`auto`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`8px`,background:`var(--bg-elev)`},children:o.length===0?(0,x.jsx)(`p`,{style:{margin:0,fontSize:`12px`,color:`var(--text-faint)`},children:t?`ๆš‚ๆ— ๅฏ็”จ Bot`:`No Bots available`}):o.map(e=>(0,x.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,cursor:`pointer`,fontSize:`12px`},children:[(0,x.jsx)(`input`,{type:`checkbox`,checked:A.includes(e.id),disabled:z,onChange:t=>{oe(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}}),(0,x.jsxs)(`span`,{children:[(0,x.jsx)(`strong`,{children:e.name}),(0,x.jsxs)(`small`,{style:{color:`var(--text-faint)`,marginInlineStart:`6px`},children:[e.online?t?`ๅœจ็บฟ`:`Online`:t?`็ฆป็บฟ`:`Offline`,e.enabled?``:t?` ยท ๅทฒ็ฆ็”จ`:` ยท Disabled`]})]})]},e.id))})]}),(0,x.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`16px`},children:[(0,x.jsx)(`label`,{htmlFor:`dg-manager-edit-primary`,children:t?`ไธป Bot`:`Primary Bot`}),(0,x.jsxs)(`select`,{id:`dg-manager-edit-primary`,value:A.includes(P)?P:``,onChange:e=>se(e.target.value),disabled:z,style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`},children:[(0,x.jsx)(`option`,{value:``,children:t?`ไธ่ฎพ็ฝฎ๏ผˆ้œ€ @ Bot๏ผ‰`:`None (mention a Bot)`}),o.filter(e=>A.includes(e.id)).map(e=>(0,x.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,x.jsxs)(`div`,{className:`dc-actions`,children:[(0,x.jsxs)(`button`,{type:`button`,className:`dc-button is-primary`,disabled:z,onClick:()=>void W(O),children:[(0,x.jsx)(n,{"aria-hidden":!0}),z?t?`ไฟๅญ˜ไธญโ€ฆ`:`Savingโ€ฆ`:t?`ไฟๅญ˜ๆˆๅ‘˜่ฎพ็ฝฎ`:`Save Members`]}),(0,x.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>k(null),disabled:z,children:t?`ๅ–ๆถˆ`:`Cancel`})]})]}),ne&&(0,x.jsx)(`p`,{role:`status`,children:t?`ๅŠ ่ฝฝไธญโ€ฆ`:`Loadingโ€ฆ`}),!ne&&i.length===0&&(0,x.jsx)(`p`,{style:{color:`var(--text-faint)`,fontSize:`13px`,padding:`12px 0`},children:t?`่ฟ˜ๆฒกๆœ‰็พค่Š๏ผŒ็‚นๅ‡ปไธŠๆ–นโ€œๆ–ฐๅปบ็พค่Šโ€ๅผ€ๅง‹ๅไฝœใ€‚`:`No groups yet. Click 'Create Group' above to get started.`}),(0,x.jsx)(`div`,{className:`dd-list`,children:i.map(e=>{let r=F===e.id,i=o.filter(t=>e.botIds.includes(t.id)),a=o.find(t=>t.id===e.primaryBotId);return(0,x.jsxs)(`div`,{className:`dd-device`,style:r?{flexWrap:`wrap`}:void 0,children:[(0,x.jsx)(`span`,{className:`dc-device-icon`,children:(0,x.jsx)(g,{"aria-hidden":!0})}),(0,x.jsxs)(`div`,{className:`dd-identity`,style:{flex:1,minWidth:`200px`},children:[(0,x.jsx)(`strong`,{children:e.name}),(0,x.jsxs)(`span`,{style:{display:`flex`,gap:`8px`,flexWrap:`wrap`,alignItems:`center`},children:[(0,x.jsx)(`span`,{children:t?`${e.botIds.length} ไธช Bot${i.length?`: ${i.map(e=>e.name).join(`, `)}`:``}`:`${e.botIds.length} Bots${i.length?`: ${i.map(e=>e.name).join(`, `)}`:``}`}),a&&(0,x.jsx)(`span`,{style:{color:`var(--accent)`},children:t?`[ไธป Bot: ${a.name}]`:`[Primary: ${a.name}]`})]})]}),(0,x.jsxs)(`div`,{className:`dc-actions`,children:[(0,x.jsxs)(`button`,{type:`button`,className:`dc-button is-primary`,title:t?`ๆ‰“ๅผ€่Šๅคฉ`:`Open chat`,onClick:()=>M(e.id),children:[(0,x.jsx)(s,{"aria-hidden":!0}),t?`ๆ‰“ๅผ€่Šๅคฉ`:`Open chat`]}),(0,x.jsxs)(`button`,{type:`button`,className:`dc-button`,title:t?`็ฎก็†ๆˆๅ‘˜`:`Manage members`,onClick:()=>U(e),children:[(0,x.jsx)(g,{"aria-hidden":!0}),t?`็ฎก็†ๆˆๅ‘˜`:`Members`]}),(0,x.jsxs)(`button`,{type:`button`,className:`dc-button`,title:t?`้‡ๅ‘ฝๅ`:`Rename`,onClick:()=>{r?I(null):(I(e.id),R(e.name))},children:[(0,x.jsx)(l,{"aria-hidden":!0}),t?`้‡ๅ‘ฝๅ`:`Rename`]}),(0,x.jsx)(`button`,{type:`button`,className:`dc-button is-danger`,title:t?`ๅˆ ้™ค็พค่Š`:`Delete group`,disabled:z,onClick:()=>void K(e),children:(0,x.jsx)(p,{"aria-hidden":!0})})]}),r&&(0,x.jsxs)(`form`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,width:`100%`,paddingTop:`8px`,paddingBottom:`4px`},onSubmit:t=>{t.preventDefault(),G(e.id)},children:[(0,x.jsx)(`input`,{type:`text`,maxLength:80,autoFocus:!0,disabled:z,value:L,onChange:e=>R(e.target.value),placeholder:t?`่พ“ๅ…ฅๆ–ฐ็พคๅ็งฐ`:`Enter new name`,style:{flex:1,minWidth:`180px`,background:`var(--bg)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`12px`}}),(0,x.jsxs)(`button`,{type:`submit`,className:`dc-button is-primary`,disabled:z||!L.trim(),children:[(0,x.jsx)(n,{"aria-hidden":!0}),t?`ไฟๅญ˜`:`Save`]}),(0,x.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:z,onClick:()=>I(null),children:[(0,x.jsx)(f,{"aria-hidden":!0}),t?`ๅ–ๆถˆ`:`Cancel`]})]})]},e.id)})})]})}var se=class extends Error{status;constructor(e,t){super(t),this.status=e}};function F(e){try{let t=new URL(e);return[`http:`,`https:`].includes(t.protocol)&&!t.username&&!t.password?t.href:null}catch{return null}}function I(){let e=ee(),t=_().startsWith(`zh`),[n,r]=(0,b.useState)(null),[a,s]=(0,b.useState)(!1),[te,ne]=(0,b.useState)(!1),[l,u]=(0,b.useState)(!1),[d,f]=(0,b.useState)(!1),p=(0,b.useRef)(0),h=(0,b.useRef)(null);async function g(e,t){if(h.current)return;let n=++p.current,a=new AbortController;h.current=a,s(!0),ne(!1);try{let o=await fetch(i(m(`/api/device-desktop/local/${e}`)),{method:t?`POST`:`GET`,credentials:`same-origin`,signal:a.signal,...t?{headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}:{}});if(p.current!==n||a.signal.aborted)return;if(o.status===403){u(!0),r(null);return}if(!o.ok)throw Error(`Request failed`);let s=await o.json();if(p.current!==n||a.signal.aborted)return;if(e===`permissions`){if(typeof s?.screen!=`boolean`||typeof s?.accessibility!=`boolean`)throw Error(`Invalid permission status`);r(e=>e&&{...e,permissions:{supported:!0,screen:s.screen,accessibility:s.accessibility}}),f(!0)}else{if(typeof s?.os!=`string`||typeof s.enabled!=`boolean`||typeof s.environmentEnabled!=`boolean`||typeof s.supported!=`boolean`)throw Error(`Invalid desktop status`);r(s)}}catch{p.current===n&&!a.signal.aborted&&ne(!0)}finally{p.current===n&&!a.signal.aborted&&(h.current=null,s(!1))}}return(0,b.useEffect)(()=>(g(`status`),()=>{p.current++,h.current?.abort(),h.current=null}),[]),(0,x.jsxs)(`section`,{className:`dc-card`,"aria-label":t?`ๆœฌๆœบ่ฟœ็จ‹ๆกŒ้ข`:`Local remote desktop`,"aria-busy":a,children:[(0,x.jsxs)(`div`,{className:`dc-card-header`,children:[(0,x.jsx)(`span`,{className:`dc-icon`,children:(0,x.jsx)(o,{"aria-hidden":!0})}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`h2`,{children:t?`ๆœฌๆœบ่ฟœ็จ‹ๆกŒ้ข`:`Local remote desktop`}),(0,x.jsx)(`p`,{children:t?`็ฎก็†่ฟ™ๅฐ่ฎพๅค‡็š„่ฟœ็จ‹ๆกŒ้ขไธŽ็ณป็ปŸๆƒ้™๏ผŒๆ— ้œ€่ฟžๆŽฅ่ฎพๅค‡ไธญๅฟƒใ€‚`:`Manage remote desktop and system permissions on this device, even while the device center is offline.`})]})]}),l?(0,x.jsx)(`p`,{role:`status`,children:t?`่ฏทๅœจ่ฎพๅค‡ๆœฌๆœบๆ‰“ๅผ€ๆญค้กต้ขไปฅ็ฎก็†่ฟœ็จ‹ๆกŒ้ขๆƒ้™ใ€‚`:`Open this page on the device itself to manage remote desktop permissions.`}):(0,x.jsxs)(x.Fragment,{children:[n&&(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)(`div`,{className:`dc-permission-row`,children:[(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`h3`,{id:`dc-desktop-label`,children:t?`ๅฏ็”จ่ฟœ็จ‹ๆกŒ้ข`:`Enable remote desktop`}),(0,x.jsx)(`p`,{children:n.enabled?t?`ๅทฒๅฏ็”จ`:`Enabled`:t?`ๆœชๅฏ็”จ`:`Disabled`})]}),(0,x.jsx)(`button`,{type:`button`,className:`dc-toggle${n.enabled?` is-on`:``}`,role:`switch`,"aria-checked":n.enabled,"aria-labelledby":`dc-desktop-label`,disabled:a||n.environmentEnabled||!n.supported&&!n.enabled,onClick:()=>void g(`enable`,{enabled:!n.enabled}),children:(0,x.jsx)(`span`,{className:`dc-toggle-thumb`})})]}),!n.supported&&(0,x.jsx)(`p`,{children:t?`่ฟ™ๅฐ่ฎพๅค‡ๆš‚ไธๆ”ฏๆŒ่ฟœ็จ‹ๆกŒ้ขใ€‚`:`Remote desktop is currently unavailable on this device.`}),n.environmentEnabled&&(0,x.jsx)(`p`,{children:t?`่ฟœ็จ‹ๆกŒ้ข็”ฑๆœฌๆœบๆœๅŠก่ฎพ็ฝฎไฟๆŒๅฏ็”จใ€‚`:`Remote desktop is kept enabled by the service settings on this device.`}),n.os===`darwin`&&(0,x.jsxs)(x.Fragment,{children:[(0,x.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,x.jsxs)(`div`,{className:`dc-actions`,children:[(0,x.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:a||n.permissions?.supported===!1,onClick:()=>void g(`permissions`,{kind:`screen`}),children:t?`ๆŽˆไบˆๅฑๅน•ๅฝ•ๅˆถๆƒ้™`:`Grant screen recording permission`}),(0,x.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:a||n.permissions?.supported===!1,onClick:()=>void g(`permissions`,{kind:`control`}),children:t?`ๆŽˆไบˆ่ฟœ็จ‹ๆŽงๅˆถๆƒ้™`:`Grant remote control permission`})]}),n.permissions?.screen===!0&&(0,x.jsx)(`p`,{children:t?`ๅฑๅน•ๅฝ•ๅˆถ๏ผšๅทฒๆŽˆๆƒ`:`Screen recording: granted`}),n.permissions?.accessibility===!0&&(0,x.jsx)(`p`,{children:t?`่ฟœ็จ‹ๆŽงๅˆถ๏ผšๅทฒๆŽˆๆƒ`:`Remote control: granted`}),d&&(0,x.jsx)(`p`,{role:`status`,children:t?`ๅทฒๅ‘่ตทๆŽˆๆƒ่ฏทๆฑ‚๏ผŒ่ฏท็กฎ่ฎค็ณป็ปŸ่ฎพ็ฝฎๅŽๅˆทๆ–ฐ็Šถๆ€ใ€‚`:`Permission requested. Confirm in System Settings, then refresh the status.`})]})]}),te&&(0,x.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:t?`ๆ— ๆณ•ๆ›ดๆ–ฐๆœฌๆœบ่ฟœ็จ‹ๆกŒ้ข่ฎพ็ฝฎ๏ผŒ่ฏท้‡่ฏ•ใ€‚`:`Unable to update local remote desktop settings. Please retry.`}),(0,x.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:a,onClick:()=>void g(`status`),children:[(0,x.jsx)(c,{"aria-hidden":!0}),a?e(`deviceHubWorking`):t?`ๅˆทๆ–ฐ่ฟœ็จ‹ๆกŒ้ข็Šถๆ€`:`Refresh remote desktop status`]})]})]})}function L({pathCompletions:e=[]}){let r=ee(),[s,te]=(0,b.useState)(null),[l,u]=(0,b.useState)(``),[f,p]=(0,b.useState)(``),[g,_]=(0,b.useState)(null),[v,re]=(0,b.useState)(!1),[C,w]=(0,b.useState)(Date.now()),[T,E]=(0,b.useState)(null),[D,O]=(0,b.useState)(``),[k,A]=(0,b.useState)(``),[j,M]=(0,b.useState)(``),[N,L]=(0,b.useState)(!1),[R,z]=(0,b.useState)(!1),[B,V]=(0,b.useState)(!0),H=(0,b.useRef)(!1),U=(0,b.useRef)(0),W=(0,b.useRef)(new Set),G=(0,b.useRef)(!1),K=(0,b.useRef)(!1),q=(0,b.useRef)(null),ce=(0,b.useRef)(r);ce.current=r,(0,b.useEffect)(()=>{let e=e=>{let t=e;t.detail?.deviceId&&q.current?.deviceId===t.detail.deviceId&&(te(e=>e&&{...e,remark:t.detail.remark}),q.current&&(q.current.remark=t.detail.remark))};return window.addEventListener(`pi-web-ui:device-remark-updated`,e),()=>window.removeEventListener(`pi-web-ui:device-remark-updated`,e)},[]);async function J(e,t){let n=new AbortController;W.current.add(n);try{let r=await fetch(i(m(`/api/device-center/${e}`)),{method:t?`POST`:`GET`,credentials:`same-origin`,signal:n.signal,...t?{headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}:{}}),a=await r.json().catch(()=>({}));if(!r.ok)throw new se(r.status,typeof a.error==`string`?a.error:ce.current(`deviceHubRequestFailed`,{status:r.status}));return a}finally{W.current.delete(n)}}function Y(e){return H.current&&U.current===e}function X(e){return e instanceof se&&e.status===403?(z(!0),ce.current(`deviceHubLocalOnly`)):e instanceof Error?e.message:ce.current(`deviceHubNetworkError`)}function Z(e){q.current=e,te(e),K.current||(p(e.name),u(e.hubUrl??``))}async function Q(){let e=U.current;try{let t=await J(`status`);if(!Y(e)||G.current)return;Z(t),A(``),z(!1)}catch(t){Y(e)&&A(X(t))}finally{Y(e)&&V(!1)}}(0,b.useEffect)(()=>{H.current=!0;let e=!1,t,n=async()=>{await Q(),!e&&H.current&&(t=setTimeout(n,5e3))};return n(),()=>{e=!0,H.current=!1,U.current++,clearTimeout(t);for(let e of W.current)e.abort()}},[]),(0,b.useEffect)(()=>{if(!g)return;let e=U.current,t=!1,n,r=setInterval(()=>w(Date.now()),1e3),i=async()=>{if(!(t||!Y(e)||Date.now()>=g.expiresAt)){try{let n=await J(`poll`,{});if(t||!Y(e))return;if(n.paired){let n=await J(`status`);if(t||!Y(e))return;K.current=!1,Z(n),_(null),O(``),M(``);return}O(``)}catch(n){!t&&Y(e)&&O(`${ce.current(`deviceHubPollError`)} ${X(n)}`)}!t&&Y(e)&&(n=setTimeout(i,2e3))}};return n=setTimeout(i,2e3),()=>{t=!0,clearTimeout(n),clearInterval(r)}},[g]);async function le(){if(G.current)return;let e=F(l.trim());if(!e){O(r(`deviceHubInvalidUrl`));return}if(!f.trim()||f.trim().length>80){O(r(`deviceHubInvalidName`));return}let t=++U.current;G.current=!0,E(`pair`),O(``),M(``),_(null);try{let n=await J(`pair`,{hubUrl:e,name:f.trim()});if(!Y(t))return;if(!n.code||!Number.isFinite(n.expiresAt)||!F(n.hubUrl))throw Error(r(`deviceHubPairError`));w(Date.now()),_(n)}catch(e){Y(t)&&O(`${r(`deviceHubPairError`)} ${X(e)}`)}finally{Y(t)&&(G.current=!1,E(null))}}async function ue(){let e=q.current;if(!e?.deviceId||G.current)return;let t=++U.current;G.current=!0,E(`permission`),O(``),M(``),Z({...e,allowExecution:!e.allowExecution});try{await J(`execution`,{allowExecution:!e.allowExecution}),Y(t)&&M(r(`deviceHubSaved`))}catch(n){Y(t)&&(Z(e),O(`${r(`deviceHubPermissionError`)} ${X(n)}`))}finally{Y(t)&&(G.current=!1,E(null))}}async function de(){let e=q.current;if(!e?.deviceId||G.current||!window.confirm(r(`deviceHubDisconnectConfirm`,{name:e.name})))return;let t=++U.current;G.current=!0,E(`disconnect`),O(``),M(``);try{if(await J(`disconnect`,{}),!Y(t))return;K.current=!1,Z({name:e.name,allowExecution:!1,connected:!1}),_(null)}catch(e){Y(t)&&O(`${r(`deviceHubDisconnectError`)} ${X(e)}`)}finally{Y(t)&&(G.current=!1,E(null))}}async function fe(){if(!N&&!T&&$&&s?.hubUrl&&window.confirm(r(`deviceHubConfirmUpgrade`))){L(!0),O(``),M(``);try{let e=await J(`upgrade-hub`,{});if(e.ok)M(r(`deviceHubUpgradeSuccess`)),await Q();else throw Error(e.message||`Upgrade failed`)}catch(e){O(X(e))}finally{L(!1)}}}async function pe(){if(!g)return;let e=U.current;try{await navigator.clipboard.writeText(g.code),Y(e)&&M(r(`deviceHubCopied`))}catch{Y(e)&&O(r(`deviceHubCopyFailed`))}}let $=!!s?.deviceId,me=F($?s?.hubUrl??``:g?.hubUrl??``),he=Math.max(0,Math.ceil(((g?.expiresAt??0)-C)/1e3)),ge=`${Math.floor(he/60)}:${String(he%60).padStart(2,`0`)}`,_e=me?(0,x.jsxs)(S,{href:me,children:[(0,x.jsx)(t,{"aria-hidden":!0}),r(`deviceHubOpenHub`)]}):null;return(0,x.jsxs)(`section`,{className:`dc-page`,"aria-label":r(`deviceHubTitle`),children:[(0,x.jsxs)(`header`,{className:`dc-header`,children:[(0,x.jsxs)(`div`,{className:`dc-heading`,children:[(0,x.jsxs)(`span`,{className:`dc-eyebrow`,children:[(0,x.jsx)(o,{"aria-hidden":!0}),r(`deviceHubTitle`)]}),(0,x.jsx)(`h1`,{children:r(`deviceHubTitle`)}),(0,x.jsx)(`p`,{children:r(`deviceHubSubtitle`)})]}),(0,x.jsxs)(`div`,{className:`dc-actions`,children:[$&&_e,(0,x.jsxs)(`span`,{className:`dc-status ${$?s?.connected?`is-online`:`is-offline`:`is-unpaired`}`,children:[(0,x.jsx)(`span`,{className:`dc-status-dot`}),r($?s?.connected?`deviceHubOnline`:`deviceHubOffline`:`deviceHubUnpaired`)]})]})]}),(0,x.jsx)(`div`,{className:`dc-layout`,style:{display:`block`},children:(0,x.jsxs)(`main`,{className:`dc-content`,children:[B&&(0,x.jsxs)(`div`,{className:`dc-loading`,role:`status`,children:[(0,x.jsx)(c,{"aria-hidden":!0}),r(`deviceHubLoading`)]}),(R||k)&&(0,x.jsxs)(`div`,{className:`dc-notice is-error`,role:`alert`,children:[(0,x.jsx)(`span`,{children:R?r(`deviceHubLocalOnly`):`${r(`deviceHubStatusError`)} ${k}`}),(0,x.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>void Q(),children:[(0,x.jsx)(c,{"aria-hidden":!0}),r(`deviceHubRetry`)]})]}),D&&!R&&(0,x.jsx)(`div`,{className:`dc-notice is-error`,role:`alert`,children:D}),j&&(0,x.jsxs)(`div`,{className:`dc-notice is-success`,role:`status`,children:[(0,x.jsx)(n,{"aria-hidden":!0}),j]}),!$&&(s||R)&&(0,x.jsx)(oe,{initialHubUrl:l,onConnect:e=>{if(R){M(r(`deviceHubLocalOnly`));return}K.current=!0,u(e),re(!0)}}),s&&!R&&!$&&(0,x.jsxs)(`section`,{className:`dc-card`,children:[(0,x.jsxs)(`div`,{className:`dc-card-header`,children:[(0,x.jsx)(`span`,{className:`dc-icon`,children:(0,x.jsx)(d,{"aria-hidden":!0})}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`h2`,{children:r(`deviceHubPairTitle`)}),(0,x.jsx)(`p`,{children:r(`deviceHubPairHint`)})]})]}),(0,x.jsx)(`ol`,{className:`dc-steps`,children:[`deviceHubStepDetails`,`deviceHubStepApprove`,`deviceHubStepWait`].map((e,t)=>(0,x.jsxs)(`li`,{className:g?t===0?`is-complete`:`is-active`:t===0?`is-active`:``,children:[(0,x.jsx)(`span`,{className:`dc-step-number`,children:g&&t===0?(0,x.jsx)(n,{"aria-hidden":!0}):t+1}),(0,x.jsx)(`span`,{children:r(e)})]},e))}),(0,x.jsxs)(`form`,{className:`dc-form`,onSubmit:e=>{e.preventDefault(),le()},children:[(0,x.jsxs)(`div`,{className:`dc-field`,children:[(0,x.jsx)(`label`,{htmlFor:`dc-hub-url`,children:r(`deviceHubHubUrl`)}),(0,x.jsx)(`input`,{id:`dc-hub-url`,type:`url`,autoComplete:`url`,required:!0,placeholder:r(`deviceHubHubPlaceholder`),value:l,disabled:!!g||!!T,onChange:e=>{K.current=!0,u(e.target.value)}})]}),(0,x.jsxs)(`div`,{className:`dc-field`,children:[(0,x.jsx)(`label`,{htmlFor:`dc-device-name`,children:r(`deviceHubName`)}),(0,x.jsx)(`input`,{id:`dc-device-name`,maxLength:80,required:!0,autoComplete:`off`,placeholder:r(`deviceHubNamePlaceholder`),value:f,disabled:!!g||!!T,onChange:e=>{K.current=!0,p(e.target.value)}})]}),!g&&(0,x.jsx)(`div`,{className:`dc-actions`,children:(0,x.jsxs)(`button`,{className:`dc-button is-primary`,type:`submit`,disabled:!!T,children:[(0,x.jsx)(d,{"aria-hidden":!0}),r(T?`deviceHubWorking`:`deviceHubGetCode`)]})})]}),g&&(0,x.jsxs)(`div`,{className:`dc-pairing`,children:[(0,x.jsx)(`span`,{className:`dc-code-label`,children:r(`deviceHubCode`)}),(0,x.jsxs)(`div`,{className:`dc-code-row`,children:[(0,x.jsx)(`code`,{className:`dc-code`,children:g.code}),(0,x.jsx)(`button`,{className:`dc-icon-button`,type:`button`,"aria-label":r(`deviceHubCopy`),onClick:()=>void pe(),children:(0,x.jsx)(a,{"aria-hidden":!0})})]}),(0,x.jsx)(`div`,{className:`dc-pair-meta`,children:r(he?`deviceHubExpires`:`deviceHubExpired`,{time:ge})}),(0,x.jsxs)(`div`,{className:`dc-actions`,children:[_e,(0,x.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:!!T,onClick:()=>{++U.current,_(null),O(``),M(``)},children:[(0,x.jsx)(c,{"aria-hidden":!0}),r(`deviceHubNewCode`)]})]}),he>0&&(0,x.jsxs)(`p`,{className:`dc-progress`,role:`status`,children:[(0,x.jsx)(c,{"aria-hidden":!0}),r(`deviceHubWaiting`)]})]})]}),$&&s&&!R&&(0,x.jsxs)(`section`,{className:`dc-card`,children:[(0,x.jsxs)(`div`,{className:`dc-device-summary`,children:[(0,x.jsx)(`span`,{className:`dc-device-icon`,children:(0,x.jsx)(o,{"aria-hidden":!0})}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`h2`,{children:s.remark?.trim()||s.name}),(0,x.jsx)(`p`,{children:s.remark?.trim()?`${s.name} ยท ${r(`deviceHubDeviceTitle`)}`:r(`deviceHubDeviceTitle`)})]})]}),(0,x.jsxs)(`dl`,{className:`dc-details`,children:[(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`dt`,{children:r(`deviceHubDeviceId`)}),(0,x.jsx)(`dd`,{children:s.deviceId})]}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`dt`,{children:r(`deviceHubHubUrl`)}),(0,x.jsx)(`dd`,{children:s.hubUrl})]})]}),(0,x.jsx)(`div`,{className:`dc-actions`,style:{marginTop:`1rem`},children:(0,x.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:N||!!T,onClick:()=>void fe(),children:[(0,x.jsx)(c,{className:N?`spin`:``,"aria-hidden":!0}),r(N?`deviceHubUpgrading`:`deviceHubUpgradeAction`)]})})]}),$&&s?.hubUrl&&s.deviceId&&!R&&(0,x.jsx)(ie,{hubUrl:s.hubUrl,currentDeviceId:s.deviceId},`directory:${s.hubUrl}:${s.deviceId}`),!R&&(0,x.jsx)(ae,{pathCompletions:e},`bots:${s?.hubUrl??``}:${s?.deviceId??`unpaired`}`),$&&!R&&(0,x.jsx)(P,{}),(0,x.jsx)(I,{}),$&&s&&!R&&(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)(`section`,{className:`dc-card`,children:[(0,x.jsxs)(`div`,{className:`dc-card-header`,children:[(0,x.jsx)(`span`,{className:`dc-icon`,children:(0,x.jsx)(ne,{"aria-hidden":!0})}),(0,x.jsx)(`div`,{children:(0,x.jsx)(`h2`,{children:r(`deviceHubPermissions`)})})]}),(0,x.jsxs)(`div`,{className:`dc-permission-row`,children:[(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`h3`,{id:`dc-permission-label`,children:r(`deviceHubPermissionLabel`)}),(0,x.jsx)(`p`,{id:`dc-permission-hint`,children:r(`deviceHubPermissionHint`)})]}),(0,x.jsx)(`button`,{type:`button`,className:`dc-toggle${s.allowExecution?` is-on`:``}`,role:`switch`,"aria-checked":s.allowExecution,"aria-labelledby":`dc-permission-label`,"aria-describedby":`dc-permission-hint`,disabled:!!T,onClick:()=>void ue(),children:(0,x.jsx)(`span`,{className:`dc-toggle-thumb`})})]}),(0,x.jsx)(`p`,{className:`dc-permission-state`,role:`status`,children:r(T===`permission`?`deviceHubSaving`:s.allowExecution?`deviceHubEnabled`:`deviceHubReadOnly`)})]}),(0,x.jsx)(y,{hubUrl:s?.hubUrl,deviceId:s?.deviceId,onNotice:M}),(0,x.jsxs)(`details`,{className:`dc-advanced`,children:[(0,x.jsx)(`summary`,{children:r(`deviceHubAdvanced`)}),(0,x.jsxs)(`div`,{className:`dc-danger-zone`,children:[(0,x.jsx)(`h3`,{children:r(`deviceHubDisconnect`)}),(0,x.jsx)(`p`,{children:r(`deviceHubDisconnectHint`)}),(0,x.jsx)(`button`,{type:`button`,className:`dc-button is-danger`,disabled:!!T,onClick:()=>void de(),children:r(T===`disconnect`?`deviceHubWorking`:`deviceHubDisconnect`)})]})]})]}),(0,x.jsxs)(`aside`,{className:`dc-help`,children:[(0,x.jsx)(h,{className:`dc-help-icon`,"aria-hidden":!0}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`h3`,{children:r(`deviceHubHelpTitle`)}),(0,x.jsx)(`p`,{children:r(`deviceHubHelpText`)})]})]})]})})]})}export{L as DeviceCenter};
@@ -0,0 +1,3 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$ as t,A as n,Bt as r,Dn as i,H as a,Nt as o,Ot as s,Sn as ee,Tn as te,Vt as c,Xt as ne,Z as l,bn as u,bt as d,fn as f,in as p,kn as m,pt as h,un as g,xn as _}from"./app-globals-KqOVtmp1.js";import{i as v,t as re}from"./react-CR5VJ85Q.js";import{Ht as ie,gt as ae}from"./index-BawF7ZP5.js";import{t as y}from"./DeviceExecutionSettings-BLP1Su5G.js";var b=e(v(),1),x=re();function S({href:e,children:t}){let n=ee(),[r,i]=(0,b.useState)(!1),[a,o]=(0,b.useState)(!1);return(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(`a`,{className:`dc-button`,href:e,target:`_blank`,rel:`noopener noreferrer`,onClick:t=>{let n=window.piDesktop;n?.openHub&&(t.preventDefault(),!a&&(o(!0),i(!1),n.openHub(e).then(e=>i(!e),()=>i(!0)).finally(()=>o(!1))))},"aria-busy":a,children:t}),r&&(0,x.jsxs)(`span`,{role:`alert`,children:[n(`deviceHubNetworkError`),` `,(0,x.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,children:e})]})]})}function C(e){if(!w(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 w(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 T(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 E=`https://raw.githubusercontent.com/xing-shuyin/pi-web-ui/main/docs/device-center-deployment.md`,D=`https://github.com/xing-shuyin/pi-web-ui/blob/main/docs/device-center-deployment.md`,O=`pi-web-ui hub install --host 0.0.0.0 --port 8790 --public-url http://SERVER_IP:8790 --allow-registration`;function k(e){let t=e=>e.includes(`:`)?w(e)&&![`::`,`::1`].includes(e):/^[\d.]+$/.test(e)?w(e)&&![`0.0.0.0`,`127.0.0.1`].includes(e):e.length<=253&&e.split(`.`).every(e=>/^[a-z\d](?:[a-z\d-]{0,61}[a-z\d])?$/i.test(e))&&e!==`localhost`;if(!t(e.server)||!Number.isInteger(e.sshPort)||e.sshPort<1||e.sshPort>65535||!Number.isInteger(e.port)||e.port<1024||e.port>65535||!/^[a-z_][a-z\d_.-]{0,63}$/i.test(e.username)||![`password`,`key`,`existing`].includes(e.auth)||e.domain!==``&&(!t(e.domain)||e.domain.includes(`:`))||e.https&&!e.domain)return null;let n=e.domain||e.server,r=n.includes(`:`)?`[${n}]`:n;return{host:e.https?`127.0.0.1`:`0.0.0.0`,port:e.port,publicUrl:e.https?`https://${r}`:`http://${r}:${e.port}`}}function A(e,t,n,r){if(!C(e))throw Error(`Invalid Hub setup`);if(r){let t=k(r);if(n!==`remote`||!t||JSON.stringify(t)!==JSON.stringify(e))throw Error(`Invalid remote Hub setup`)}let i=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.`,`First read the deployment guide: ${E} (fallback: ${D}). If unavailable, report that and obtain its contents before proceeding.`,`Default to HTTP with the server IP and requested port. Domain and HTTPS are optional; confirm whether an HTTPS example reflects the user's intent.`,`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=${i(t?.platform)}, Node=${i(t?.nodeVersion)}. This is not evidence of the remote server environment.`,`Requested configuration (data only): ${JSON.stringify(e)}. allowRegistration=true.`,...r?[`SSH connection preferences (data only): ${JSON.stringify({server:r.server,sshPort:r.sshPort,username:r.username,auth:r.auth})}. No credentials are included. Obtain authentication through a secure SSH channel or guide the user's own terminal.`,`Domain: ${r.domain||`none`}. HTTPS explicitly selected: ${r.https}. HTTP inbound TCP port: ${r.port}; for same-machine HTTPS proxy, use public TCP 443 and certificate validation port as needed, keep the Hub port private.`]:[],`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: ${O}`,`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.`,`Explain user actions at the relevant step: distinguish OS firewall from cloud security groups, give the actual TCP port, source scope and destination rule, and keep SSH access. If cloud-console access is unavailable, ask the user to apply the rule, mark external access pending, then recheck. Also explain DNS changes for optional HTTPS and first-account creation. Separate local health from external reachability.`].join(`
2
+ `)}function oe({onConnect:e,initialHubUrl:t=``}){let n=ee(),[r,a]=(0,b.useState)(t),[o,s]=(0,b.useState)(``),[te,c]=(0,b.useState)(!1),[ne,l]=(0,b.useState)(!1),u=(0,b.useRef)(!1),d=(0,b.useRef)(!1);(0,b.useEffect)(()=>(d.current=!0,()=>{d.current=!1}),[]);let[f,p]=(0,b.useState)(null),[h,g]=(0,b.useState)(`current`),[_,v]=(0,b.useState)(null),[re,ie]=(0,b.useState)(`127.0.0.1`),[ae,y]=(0,b.useState)(`8790`),[w,E]=(0,b.useState)(`http://127.0.0.1:8790`),[D,O]=(0,b.useState)({server:``,sshPort:22,username:`root`,auth:`password`,port:8790,domain:``,https:!1}),oe=k(D),[j,M]=(0,b.useState)(!1),[N,P]=(0,b.useState)(!1),[se,F]=(0,b.useState)(null),[I,L]=(0,b.useState)(!1),[R,z]=(0,b.useState)(!1),[B,V]=(0,b.useState)(!1),[H,U]=(0,b.useState)(null),W=(0,b.useRef)(null),G=(0,b.useRef)(!1),K=T(window.location.origin);(0,b.useEffect)(()=>()=>W.current?.abort(),[]);let q=async()=>{if(G.current)return;W.current?.abort();let e=new AbortController;W.current=e,L(!1),z(!1),V(!1);try{let t=await fetch(i(m(`/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`||!C({host:`127.0.0.1`,port:n.defaultPort,publicUrl:n.defaultPublicUrl}))throw Error();if(e.signal.aborted)return;v(n),n.installation?.installed?(ie(n.installation.host??`127.0.0.1`),y(String(n.installation.port)),E(n.installation.publicUrl??``),a(n.installation.publicUrl??``)):_||(y(String(n.defaultPort)),E(n.defaultPublicUrl))}catch{e.signal.aborted||(L(!0),V(!0))}finally{e.signal.aborted||z(!0)}},ce=async()=>{let e={host:re,port:Number(ae),publicUrl:w};if(G.current||!K||!_||!R||B||_.busy||_.installation?.installed||!C(e))return;G.current=!0,W.current?.abort(),M(!0),L(!1),s(``);let t=new AbortController;W.current=t;try{let n=await fetch(i(m(`/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){v(e=>e&&{...e,busy:!0}),G.current=!1,M(!1),await q();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(!C({...e,publicUrl:r.publicUrl})||typeof r.output!=`string`)throw Error();t.signal.aborted||U(r)}catch(e){t.signal.aborted||(L(!0),s(e instanceof Error?e.message.slice(0,4096):``))}finally{G.current=!1,t.signal.aborted||M(!1)}},J=async()=>{if(G.current||!K||!_||!R||B||_.busy||j||N)return;G.current=!0,W.current?.abort(),P(!0),L(!1),s(``),F(null);let e=new AbortController;W.current=e;try{let t=await fetch(i(m(`/api/device-center/setup/update`)),{credentials:`same-origin`,method:`POST`,headers:{"Content-Type":`application/json`},signal:e.signal});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(typeof e.error==`string`?e.error.slice(0,4096):`HTTP ${t.status}`)}let r=await t.json();e.signal.aborted||(F(r.output||n(`deviceSetupUpdateSuccess`)),await q())}catch(t){e.signal.aborted||(L(!0),s(t instanceof Error?t.message.slice(0,4096):``))}finally{G.current=!1,e.signal.aborted||P(!1)}},Y=_?.installation,X=!!Y?.installed,Z=X&&Y.running&&Y.owned,Q=h===`remote`?oe:{host:re,port:Number(ae),publicUrl:w},le=!!Q&&C(Q);return(0,x.jsxs)(`section`,{className:`dc-onboarding`,children:[(0,x.jsx)(`h3`,{children:n(`deviceSetupWelcome`)}),(0,x.jsx)(`p`,{children:n(`deviceSetupIntro`)}),(0,x.jsxs)(`div`,{className:`dc-actions`,children:[(0,x.jsx)(`button`,{className:`dc-button`,disabled:j,"aria-pressed":f===`connect`,onClick:()=>p(`connect`),children:n(`deviceSetupConnect`)}),(0,x.jsx)(`button`,{className:`dc-button`,disabled:j,"aria-pressed":f===`create`,onClick:()=>{p(`create`),!_&&K&&q()},children:n(`deviceSetupCreate`)})]}),f===`connect`&&(0,x.jsxs)(`form`,{onSubmit:t=>{t.preventDefault(),e(r.trim())},children:[(0,x.jsxs)(`label`,{className:`dc-field`,children:[(0,x.jsx)(`span`,{children:n(`deviceHubHubUrl`)}),(0,x.jsx)(`input`,{type:`url`,required:!0,maxLength:2048,value:r,onChange:e=>a(e.target.value),placeholder:`https://hub.example.com`})]}),(0,x.jsx)(`button`,{className:`dc-button is-primary`,disabled:!C({host:`localhost`,port:8790,publicUrl:r.trim()}),children:n(`deviceSetupPair`)})]}),f===`create`&&(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)(`label`,{className:`dc-field`,children:[(0,x.jsx)(`span`,{children:n(`deviceSetupTarget`)}),(0,x.jsxs)(`select`,{disabled:j,value:h,onChange:e=>g(e.target.value),children:[(0,x.jsx)(`option`,{value:`current`,children:n(`deviceSetupCurrent`)}),(0,x.jsx)(`option`,{value:`remote`,children:n(`deviceSetupRemote`)})]})]}),(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(`p`,{children:n(h===`current`?`deviceSetupCurrentHint`:`deviceSetupRemoteHint`)}),h===`current`&&(0,x.jsxs)(`div`,{className:`dc-setup-plan`,children:[(0,x.jsx)(`strong`,{children:n(`deviceSetupPlan`)}),(0,x.jsx)(`p`,{children:n(`deviceSetupPlanHint`)}),_&&(0,x.jsxs)(`dl`,{children:[(0,x.jsx)(`dt`,{children:n(`deviceSetupEnvironment`)}),(0,x.jsxs)(`dd`,{children:[_.platform,` ยท Node `,_.nodeVersion]}),(0,x.jsx)(`dt`,{children:n(`deviceSetupDataDir`)}),(0,x.jsx)(`dd`,{children:_.dataDir}),(0,x.jsx)(`dt`,{children:n(`deviceSetupCli`)}),(0,x.jsx)(`dd`,{children:_.cliPath})]}),!K&&(0,x.jsx)(`p`,{role:`status`,children:n(`deviceSetupLocalOnly`)}),(0,x.jsx)(`p`,{children:n(`deviceSetupBackground`)}),X&&(0,x.jsxs)(`div`,{role:`status`,children:[(0,x.jsx)(`h4`,{children:n(Z?`deviceSetupRestored`:`deviceSetupUnhealthy`)}),(0,x.jsx)(`p`,{children:Y.publicUrl}),Z&&le&&Y.publicUrl?(0,x.jsxs)(`div`,{className:`dc-actions`,children:[(0,x.jsx)(S,{href:Y.publicUrl,children:n(`deviceHubOpenHub`)}),(0,x.jsx)(`button`,{className:`dc-button`,onClick:()=>e(Y.publicUrl),children:n(`deviceSetupPair`)}),K&&(0,x.jsx)(`button`,{className:`dc-button`,disabled:j||N,onClick:()=>void J(),children:n(N?`deviceSetupUpdating`:`deviceSetupUpdate`)})]}):(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(`p`,{children:n(`deviceSetupRecovery`)}),(0,x.jsx)(`pre`,{className:`dc-setup-output`,children:`pi-web-ui hub status --json
3
+ pi-web-ui hub --help`}),K&&(0,x.jsx)(`button`,{className:`dc-button is-primary`,disabled:j||N,onClick:()=>void J(),children:n(N?`deviceSetupUpdating`:`deviceSetupUpdate`)})]}),se&&(0,x.jsx)(`pre`,{className:`dc-setup-output`,children:se.slice(0,16e3)})]}),_?.busy&&(0,x.jsx)(`p`,{role:`status`,children:n(`deviceSetupBusy`)}),K&&(0,x.jsx)(`button`,{className:`dc-button`,disabled:j||!R,onClick:()=>void q(),children:n(R?`deviceSetupRetry`:`deviceHubWorking`)})]}),h===`remote`?(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)(`div`,{className:`dc-setup-fields`,children:[(0,x.jsxs)(`label`,{className:`dc-field`,children:[(0,x.jsx)(`span`,{children:n(`deviceSetupServer`)}),(0,x.jsx)(`input`,{autoComplete:`off`,maxLength:253,placeholder:`203.0.113.10`,value:D.server,onChange:e=>O({...D,server:e.target.value.trim()})})]}),(0,x.jsxs)(`label`,{className:`dc-field`,children:[(0,x.jsx)(`span`,{children:n(`deviceSetupSshPort`)}),(0,x.jsx)(`input`,{type:`number`,min:1,max:65535,value:D.sshPort,onChange:e=>O({...D,sshPort:Number(e.target.value)})})]}),(0,x.jsxs)(`label`,{className:`dc-field`,children:[(0,x.jsx)(`span`,{children:n(`deviceSetupUsername`)}),(0,x.jsx)(`input`,{autoComplete:`off`,maxLength:64,value:D.username,onChange:e=>O({...D,username:e.target.value})})]}),(0,x.jsxs)(`label`,{className:`dc-field`,children:[(0,x.jsx)(`span`,{children:n(`deviceSetupAuth`)}),(0,x.jsxs)(`select`,{value:D.auth,onChange:e=>O({...D,auth:e.target.value}),children:[(0,x.jsx)(`option`,{value:`password`,children:n(`deviceSetupAuthPassword`)}),(0,x.jsx)(`option`,{value:`key`,children:n(`deviceSetupAuthKey`)}),(0,x.jsx)(`option`,{value:`existing`,children:n(`deviceSetupAuthExisting`)})]})]}),(0,x.jsxs)(`label`,{className:`dc-field`,children:[(0,x.jsx)(`span`,{children:n(`deviceSetupServicePort`)}),(0,x.jsx)(`input`,{type:`number`,min:1024,max:65535,value:D.port,onChange:e=>O({...D,port:Number(e.target.value)})})]})]}),(0,x.jsx)(`p`,{children:n(`deviceSetupCredentialHint`)}),(0,x.jsxs)(`details`,{children:[(0,x.jsx)(`summary`,{children:n(`deviceSetupOptionalTls`)}),(0,x.jsxs)(`label`,{className:`dc-field`,children:[(0,x.jsx)(`span`,{children:n(`deviceSetupDomain`)}),(0,x.jsx)(`input`,{maxLength:253,placeholder:`hub.example.com`,value:D.domain,onChange:e=>O({...D,domain:e.target.value.trim()})})]}),(0,x.jsxs)(`label`,{children:[(0,x.jsx)(`input`,{type:`checkbox`,checked:D.https,onChange:e=>O({...D,https:e.target.checked})}),` `,n(`deviceSetupEnableHttps`)]}),(0,x.jsx)(`p`,{children:n(`deviceSetupTlsHint`)})]}),(0,x.jsxs)(`p`,{children:[(0,x.jsx)(`strong`,{children:n(`deviceSetupPreview`)}),` `,oe?.publicUrl??n(`deviceSetupPreviewEmpty`)]}),(0,x.jsxs)(`div`,{className:`dc-setup-plan`,children:[(0,x.jsx)(`strong`,{children:n(`deviceSetupUserActions`)}),(0,x.jsx)(`p`,{children:n(`deviceSetupCloudPorts`).replace(`{ports}`,D.https?`443 / 80`:String(D.port))}),(0,x.jsx)(`p`,{children:n(`deviceSetupSourceScope`)}),(0,x.jsx)(`p`,{children:n(`deviceSetupAfterStart`)})]}),(0,x.jsx)(`a`,{href:`https://github.com/xing-shuyin/pi-web-ui/blob/main/docs/device-center-deployment.md`,target:`_blank`,rel:`noopener noreferrer`,children:n(`deviceSetupGuide`)})]}):(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)(`div`,{className:`dc-setup-fields`,children:[(0,x.jsxs)(`label`,{className:`dc-field`,children:[(0,x.jsx)(`span`,{children:n(`deviceSetupHost`)}),(0,x.jsx)(`input`,{disabled:j||!!H,maxLength:253,value:re,onChange:e=>ie(e.target.value)})]}),(0,x.jsxs)(`label`,{className:`dc-field`,children:[(0,x.jsx)(`span`,{children:n(`deviceSetupPort`)}),(0,x.jsx)(`input`,{disabled:j||!!H,type:`number`,min:1024,max:65535,value:ae,onChange:e=>y(e.target.value)})]}),(0,x.jsxs)(`label`,{className:`dc-field`,children:[(0,x.jsx)(`span`,{children:n(`deviceHubHubUrl`)}),(0,x.jsx)(`input`,{disabled:j||!!H,maxLength:2048,value:w,onChange:e=>E(e.target.value)})]})]}),(0,x.jsx)(`p`,{className:`dc-setup-warning`,children:n(`deviceSetupReachable`)})]}),(0,x.jsx)(`p`,{children:n(`deviceSetupRegistration`)}),!le&&(0,x.jsx)(`p`,{role:`alert`,children:n(h===`remote`?`deviceSetupRemoteInvalid`:`deviceSetupInvalid`)}),(0,x.jsxs)(`div`,{className:`dc-actions`,children:[h===`current`&&!H&&!X&&(0,x.jsx)(`button`,{className:`dc-button is-primary`,disabled:j||!K||!_||!R||B||!!_.busy||!le,onClick:()=>void ce(),children:n(j?`deviceSetupInstalling`:`deviceSetupInstall`)}),(0,x.jsx)(`button`,{className:`dc-button`,disabled:j||te||!le,onClick:()=>{if(!le||!Q||u.current)return;u.current=!0,c(!0),l(!1);let e=e=>{u.current=!1,d.current&&(c(!1),l(!e))},t=window.__piWebUiHost;try{t?.startChat({newChat:!0,prompt:A(Q,_,h,h===`remote`?D:void 0),onResult:e})||e(!1)}catch{e(!1)}},children:n(h===`remote`?`deviceSetupStartAi`:`deviceSetupAi`)})]}),(0,x.jsx)(`p`,{children:n(`deviceSetupAiHint`)}),te&&(0,x.jsx)(`p`,{role:`status`,children:n(`deviceSetupAiCreating`)}),ne&&(0,x.jsx)(`p`,{role:`alert`,children:n(`deviceSetupAiFailed`)})]})]}),I&&(0,x.jsxs)(`div`,{role:`alert`,children:[(0,x.jsx)(`p`,{children:n(`deviceSetupFailed`)}),o&&(0,x.jsx)(`pre`,{className:`dc-setup-output`,children:o})]}),H&&(0,x.jsxs)(`div`,{role:`status`,children:[(0,x.jsx)(`h4`,{children:n(`deviceSetupSuccess`)}),(0,x.jsx)(`pre`,{className:`dc-setup-output`,children:H.output.slice(0,16e3)}),(0,x.jsxs)(`div`,{className:`dc-actions`,children:[(0,x.jsx)(S,{href:H.publicUrl,children:n(`deviceHubOpenHub`)}),(0,x.jsx)(`button`,{className:`dc-button is-primary`,onClick:()=>e(H.publicUrl),children:n(`deviceSetupPair`)})]})]})]})}var j=`pi-web-ui:device-groups-changed`;function M(e){window.dispatchEvent(new CustomEvent(`pi-web-ui:device-group-open`,{detail:{roomId:e}}))}async function N(e,t,n){let r=await fetch(i(m(`/api/device-center/${e}`)),{method:n?`POST`:`GET`,credentials:`same-origin`,signal:t,...n?{headers:{"Content-Type":`application/json`},body:JSON.stringify(n)}:{}}),a=await r.json().catch(()=>({}));if(!r.ok)throw Error(a.error||a.message||`Request failed (${r.status})`);return a}function P(){let{locale:e}=u(),t=te(e),[i,a]=(0,b.useState)([]),[o,ee]=(0,b.useState)([]),[ne,d]=(0,b.useState)(!0),[m,h]=(0,b.useState)(``),[_,v]=(0,b.useState)(``),[re,ie]=(0,b.useState)(0),[ae,y]=(0,b.useState)(!1),[S,C]=(0,b.useState)(``),[w,T]=(0,b.useState)([]),[E,D]=(0,b.useState)(``),[O,k]=(0,b.useState)(null),[A,oe]=(0,b.useState)([]),[P,se]=(0,b.useState)(``),[F,I]=(0,b.useState)(null),[L,R]=(0,b.useState)(``),[z,B]=(0,b.useState)(!1),V=(0,b.useRef)(0);(0,b.useEffect)(()=>{let e=++V.current,t=new AbortController;async function n(){try{let[n,r]=await Promise.all([N(`rooms`,t.signal),N(`bots`,t.signal)]);if(V.current!==e||t.signal.aborted)return;a(Array.isArray(n.rooms)?n.rooms:[]),ee(Array.isArray(r.bots)?r.bots:[]),h(``)}catch(n){V.current===e&&!t.signal.aborted&&h(n instanceof Error?n.message:String(n))}finally{V.current===e&&!t.signal.aborted&&d(!1)}}return n(),()=>{t.abort()}},[re]),(0,b.useEffect)(()=>{let e=()=>ie(e=>e+1);return window.addEventListener(j,e),()=>window.removeEventListener(j,e)},[]);async function H(e){if(e.preventDefault(),!S.trim()||z)return;B(!0),h(``),v(``);let n=new AbortController;try{let e=w.includes(E)?E:``,r=await N(`rooms`,n.signal,{name:S.trim(),botIds:w,...e?{primaryBotId:e}:{}});a(e=>[...e.filter(e=>e.id!==r.room.id),r.room]),y(!1),C(``),T([]),D(``),v(t?`็พค่Šๅˆ›ๅปบๆˆๅŠŸ`:`Group created successfully`),window.dispatchEvent(new CustomEvent(j))}catch(e){h(e instanceof Error?e.message:String(e))}finally{B(!1)}}function U(e){k(e.id),oe([...e.botIds]),se(e.primaryBotId??``),I(null),y(!1),h(``),v(``)}async function W(e){if(z)return;B(!0),h(``),v(``);let n=new AbortController;try{let r=A.includes(P)?P:null,i=await N(`rooms/${encodeURIComponent(e)}/members`,n.signal,{botIds:A,primaryBotId:r});a(t=>t.map(t=>t.id===e?i.room:t)),k(null),v(t?`ๆˆๅ‘˜่ฎพ็ฝฎๅทฒไฟๅญ˜`:`Members updated successfully`),window.dispatchEvent(new CustomEvent(j))}catch(e){h(e instanceof Error?e.message:String(e))}finally{B(!1)}}async function G(e){if(!L.trim()||z)return;B(!0),h(``),v(``);let n=new AbortController;try{await N(`rooms/${encodeURIComponent(e)}/rename`,n.signal,{name:L.trim()}),a(t=>t.map(t=>t.id===e?{...t,name:L.trim()}:t)),I(null),v(t?`็พค่Šๅ็งฐๅทฒๆ›ดๆ–ฐ`:`Group renamed successfully`),window.dispatchEvent(new CustomEvent(j))}catch(e){h(e instanceof Error?e.message:String(e))}finally{B(!1)}}async function K(e){if(z||!window.confirm(t?`็กฎๅฎšๅˆ ้™ค็พค่Šโ€œ${e.name}โ€๏ผŸ`:`Are you sure you want to delete "${e.name}"?`))return;B(!0),h(``),v(``);let n=new AbortController;try{await N(`rooms/${encodeURIComponent(e.id)}/delete`,n.signal,{}),a(t=>t.filter(t=>t.id!==e.id)),O===e.id&&k(null),F===e.id&&I(null),v(t?`็พค่Šๅทฒๅˆ ้™ค`:`Group deleted successfully`),window.dispatchEvent(new CustomEvent(j))}catch(e){h(e instanceof Error?e.message:String(e))}finally{B(!1)}}return(0,x.jsxs)(`section`,{className:`dc-card`,"aria-label":t?`็พค่Šๅˆ—่กจ`:`Group list`,children:[(0,x.jsxs)(`div`,{className:`dc-card-header`,children:[(0,x.jsx)(`span`,{className:`dc-icon`,children:(0,x.jsx)(g,{"aria-hidden":!0})}),(0,x.jsxs)(`div`,{children:[(0,x.jsxs)(`h2`,{children:[t?`็พค่Šๅˆ—่กจ`:`Group List`,` ยท `,i.length]}),(0,x.jsx)(`p`,{children:t?`็ฎก็†็พค่ŠไธŽๆˆๅ‘˜ Bot๏ผŒๅœจๆญค้…็ฝฎๅไฝœ็พค็ป„ๆˆ–็›ดๆŽฅ่ฟ›ๅ…ฅ่Šๅคฉใ€‚`:`Manage groups and member Bots. Configure collaboration groups or open chats here.`})]}),(0,x.jsxs)(`div`,{className:`dc-actions`,style:{marginInlineStart:`auto`},children:[(0,x.jsxs)(`button`,{type:`button`,className:`dc-button is-primary`,disabled:z,onClick:()=>{y(e=>!e),k(null),I(null),C(``),T([]),D(``)},children:[(0,x.jsx)(r,{"aria-hidden":!0}),t?`ๆ–ฐๅปบ็พค่Š`:`Create Group`]}),(0,x.jsx)(`button`,{type:`button`,className:`dc-icon-button`,"aria-label":t?`ๅˆทๆ–ฐ็พค่Š`:`Refresh groups`,onClick:()=>ie(e=>e+1),children:(0,x.jsx)(c,{})})]})]}),m&&(0,x.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:m}),_&&(0,x.jsxs)(`p`,{className:`dc-notice is-success`,role:`status`,children:[(0,x.jsx)(n,{"aria-hidden":!0}),_]}),ae&&(0,x.jsxs)(`form`,{className:`dc-card`,style:{marginBottom:`16px`,background:`var(--bg)`,border:`1px solid var(--border)`},onSubmit:H,children:[(0,x.jsxs)(`div`,{className:`dg-heading`,style:{marginBottom:`12px`},children:[(0,x.jsx)(`h3`,{children:t?`ๆ–ฐๅปบ็พค่Š`:`Create Group`}),(0,x.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>y(!1),disabled:z,children:[(0,x.jsx)(f,{"aria-hidden":!0}),t?`ๅ…ณ้—ญ`:`Close`]})]}),(0,x.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`12px`},children:[(0,x.jsx)(`label`,{htmlFor:`dg-manager-new-name`,children:t?`็พคๅ็งฐ`:`Group Name`}),(0,x.jsx)(`input`,{id:`dg-manager-new-name`,type:`text`,required:!0,maxLength:80,value:S,placeholder:t?`่พ“ๅ…ฅ็พคๅ็งฐ๏ผŒๅฆ‚๏ผš็ ”ๅ‘ๅไฝœ็พค`:`Enter group name`,onChange:e=>C(e.target.value),disabled:z,style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`}})]}),(0,x.jsxs)(`div`,{style:{marginBottom:`12px`},children:[(0,x.jsx)(`label`,{style:{display:`block`,marginBottom:`6px`,fontSize:`12px`,color:`var(--text-dim)`},children:t?`้€‰ๆ‹ฉๆˆๅ‘˜ Bot`:`Select Member Bots`}),(0,x.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`6px`,maxHeight:`160px`,overflowY:`auto`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`8px`,background:`var(--bg-elev)`},children:o.length===0?(0,x.jsx)(`p`,{style:{margin:0,fontSize:`12px`,color:`var(--text-faint)`},children:t?`ๆš‚ๆ— ๅฏ็”จ Bot๏ผŒ่ฏทๅ…ˆๅˆ›ๅปบ Botใ€‚`:`No Bots available. Please create a Bot first.`}):o.map(e=>(0,x.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,cursor:`pointer`,fontSize:`12px`},children:[(0,x.jsx)(`input`,{type:`checkbox`,checked:w.includes(e.id),disabled:z||!e.enabled,onChange:t=>{T(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}}),(0,x.jsxs)(`span`,{children:[(0,x.jsx)(`strong`,{children:e.name}),(0,x.jsxs)(`small`,{style:{color:`var(--text-faint)`,marginInlineStart:`6px`},children:[e.online?t?`ๅœจ็บฟ`:`Online`:t?`็ฆป็บฟ`:`Offline`,e.enabled?``:t?` ยท ๅทฒ็ฆ็”จ`:` ยท Disabled`]})]})]},e.id))})]}),w.length>0&&(0,x.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`16px`},children:[(0,x.jsx)(`label`,{htmlFor:`dg-manager-new-primary`,children:t?`ไธป Bot`:`Primary Bot`}),(0,x.jsxs)(`select`,{id:`dg-manager-new-primary`,value:w.includes(E)?E:``,onChange:e=>D(e.target.value),disabled:z,style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`},children:[(0,x.jsx)(`option`,{value:``,children:t?`ไธ่ฎพ็ฝฎ๏ผˆ้œ€ @ Bot๏ผ‰`:`None (mention a Bot)`}),o.filter(e=>w.includes(e.id)).map(e=>(0,x.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,x.jsxs)(`div`,{className:`dc-actions`,children:[(0,x.jsxs)(`button`,{type:`submit`,className:`dc-button is-primary`,disabled:z||!S.trim(),children:[(0,x.jsx)(n,{"aria-hidden":!0}),z?t?`ๅˆ›ๅปบไธญโ€ฆ`:`Creatingโ€ฆ`:t?`ๅˆ›ๅปบ็พค่Š`:`Create`]}),(0,x.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>y(!1),disabled:z,children:t?`ๅ–ๆถˆ`:`Cancel`})]})]}),O&&(0,x.jsxs)(`div`,{className:`dc-card`,style:{marginBottom:`16px`,background:`var(--bg)`,border:`1px solid var(--border)`},children:[(0,x.jsxs)(`div`,{className:`dg-heading`,style:{marginBottom:`12px`},children:[(0,x.jsxs)(`h3`,{children:[t?`็ฎก็†ๆˆๅ‘˜`:`Manage Members`,` ยท `,i.find(e=>e.id===O)?.name]}),(0,x.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>k(null),disabled:z,children:[(0,x.jsx)(f,{"aria-hidden":!0}),t?`ๅ…ณ้—ญ`:`Close`]})]}),(0,x.jsxs)(`div`,{style:{marginBottom:`12px`},children:[(0,x.jsx)(`label`,{style:{display:`block`,marginBottom:`6px`,fontSize:`12px`,color:`var(--text-dim)`},children:t?`้€‰ๆ‹ฉๆˆๅ‘˜ Bot`:`Select Member Bots`}),(0,x.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`6px`,maxHeight:`160px`,overflowY:`auto`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`8px`,background:`var(--bg-elev)`},children:o.length===0?(0,x.jsx)(`p`,{style:{margin:0,fontSize:`12px`,color:`var(--text-faint)`},children:t?`ๆš‚ๆ— ๅฏ็”จ Bot`:`No Bots available`}):o.map(e=>(0,x.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,cursor:`pointer`,fontSize:`12px`},children:[(0,x.jsx)(`input`,{type:`checkbox`,checked:A.includes(e.id),disabled:z,onChange:t=>{oe(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}}),(0,x.jsxs)(`span`,{children:[(0,x.jsx)(`strong`,{children:e.name}),(0,x.jsxs)(`small`,{style:{color:`var(--text-faint)`,marginInlineStart:`6px`},children:[e.online?t?`ๅœจ็บฟ`:`Online`:t?`็ฆป็บฟ`:`Offline`,e.enabled?``:t?` ยท ๅทฒ็ฆ็”จ`:` ยท Disabled`]})]})]},e.id))})]}),(0,x.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`16px`},children:[(0,x.jsx)(`label`,{htmlFor:`dg-manager-edit-primary`,children:t?`ไธป Bot`:`Primary Bot`}),(0,x.jsxs)(`select`,{id:`dg-manager-edit-primary`,value:A.includes(P)?P:``,onChange:e=>se(e.target.value),disabled:z,style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`},children:[(0,x.jsx)(`option`,{value:``,children:t?`ไธ่ฎพ็ฝฎ๏ผˆ้œ€ @ Bot๏ผ‰`:`None (mention a Bot)`}),o.filter(e=>A.includes(e.id)).map(e=>(0,x.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,x.jsxs)(`div`,{className:`dc-actions`,children:[(0,x.jsxs)(`button`,{type:`button`,className:`dc-button is-primary`,disabled:z,onClick:()=>void W(O),children:[(0,x.jsx)(n,{"aria-hidden":!0}),z?t?`ไฟๅญ˜ไธญโ€ฆ`:`Savingโ€ฆ`:t?`ไฟๅญ˜ๆˆๅ‘˜่ฎพ็ฝฎ`:`Save Members`]}),(0,x.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>k(null),disabled:z,children:t?`ๅ–ๆถˆ`:`Cancel`})]})]}),ne&&(0,x.jsx)(`p`,{role:`status`,children:t?`ๅŠ ่ฝฝไธญโ€ฆ`:`Loadingโ€ฆ`}),!ne&&i.length===0&&(0,x.jsx)(`p`,{style:{color:`var(--text-faint)`,fontSize:`13px`,padding:`12px 0`},children:t?`่ฟ˜ๆฒกๆœ‰็พค่Š๏ผŒ็‚นๅ‡ปไธŠๆ–นโ€œๆ–ฐๅปบ็พค่Šโ€ๅผ€ๅง‹ๅไฝœใ€‚`:`No groups yet. Click 'Create Group' above to get started.`}),(0,x.jsx)(`div`,{className:`dd-list`,children:i.map(e=>{let r=F===e.id,i=o.filter(t=>e.botIds.includes(t.id)),a=o.find(t=>t.id===e.primaryBotId);return(0,x.jsxs)(`div`,{className:`dd-device`,style:r?{flexWrap:`wrap`}:void 0,children:[(0,x.jsx)(`span`,{className:`dc-device-icon`,children:(0,x.jsx)(g,{"aria-hidden":!0})}),(0,x.jsxs)(`div`,{className:`dd-identity`,style:{flex:1,minWidth:`200px`},children:[(0,x.jsx)(`strong`,{children:e.name}),(0,x.jsxs)(`span`,{style:{display:`flex`,gap:`8px`,flexWrap:`wrap`,alignItems:`center`},children:[(0,x.jsx)(`span`,{children:t?`${e.botIds.length} ไธช Bot${i.length?`: ${i.map(e=>e.name).join(`, `)}`:``}`:`${e.botIds.length} Bots${i.length?`: ${i.map(e=>e.name).join(`, `)}`:``}`}),a&&(0,x.jsx)(`span`,{style:{color:`var(--accent)`},children:t?`[ไธป Bot: ${a.name}]`:`[Primary: ${a.name}]`})]})]}),(0,x.jsxs)(`div`,{className:`dc-actions`,children:[(0,x.jsxs)(`button`,{type:`button`,className:`dc-button is-primary`,title:t?`ๆ‰“ๅผ€่Šๅคฉ`:`Open chat`,onClick:()=>M(e.id),children:[(0,x.jsx)(s,{"aria-hidden":!0}),t?`ๆ‰“ๅผ€่Šๅคฉ`:`Open chat`]}),(0,x.jsxs)(`button`,{type:`button`,className:`dc-button`,title:t?`็ฎก็†ๆˆๅ‘˜`:`Manage members`,onClick:()=>U(e),children:[(0,x.jsx)(g,{"aria-hidden":!0}),t?`็ฎก็†ๆˆๅ‘˜`:`Members`]}),(0,x.jsxs)(`button`,{type:`button`,className:`dc-button`,title:t?`้‡ๅ‘ฝๅ`:`Rename`,onClick:()=>{r?I(null):(I(e.id),R(e.name))},children:[(0,x.jsx)(l,{"aria-hidden":!0}),t?`้‡ๅ‘ฝๅ`:`Rename`]}),(0,x.jsx)(`button`,{type:`button`,className:`dc-button is-danger`,title:t?`ๅˆ ้™ค็พค่Š`:`Delete group`,disabled:z,onClick:()=>void K(e),children:(0,x.jsx)(p,{"aria-hidden":!0})})]}),r&&(0,x.jsxs)(`form`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,width:`100%`,paddingTop:`8px`,paddingBottom:`4px`},onSubmit:t=>{t.preventDefault(),G(e.id)},children:[(0,x.jsx)(`input`,{type:`text`,maxLength:80,autoFocus:!0,disabled:z,value:L,onChange:e=>R(e.target.value),placeholder:t?`่พ“ๅ…ฅๆ–ฐ็พคๅ็งฐ`:`Enter new name`,style:{flex:1,minWidth:`180px`,background:`var(--bg)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`12px`}}),(0,x.jsxs)(`button`,{type:`submit`,className:`dc-button is-primary`,disabled:z||!L.trim(),children:[(0,x.jsx)(n,{"aria-hidden":!0}),t?`ไฟๅญ˜`:`Save`]}),(0,x.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:z,onClick:()=>I(null),children:[(0,x.jsx)(f,{"aria-hidden":!0}),t?`ๅ–ๆถˆ`:`Cancel`]})]})]},e.id)})})]})}var se=class extends Error{status;constructor(e,t){super(t),this.status=e}};function F(e){try{let t=new URL(e);return[`http:`,`https:`].includes(t.protocol)&&!t.username&&!t.password?t.href:null}catch{return null}}function I(){let e=ee(),t=_().startsWith(`zh`),[n,r]=(0,b.useState)(null),[a,s]=(0,b.useState)(!1),[te,ne]=(0,b.useState)(!1),[l,u]=(0,b.useState)(!1),[d,f]=(0,b.useState)(!1),p=(0,b.useRef)(0),h=(0,b.useRef)(null);async function g(e,t){if(h.current)return;let n=++p.current,a=new AbortController;h.current=a,s(!0),ne(!1);try{let o=await fetch(i(m(`/api/device-desktop/local/${e}`)),{method:t?`POST`:`GET`,credentials:`same-origin`,signal:a.signal,...t?{headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}:{}});if(p.current!==n||a.signal.aborted)return;if(o.status===403){u(!0),r(null);return}if(!o.ok)throw Error(`Request failed`);let s=await o.json();if(p.current!==n||a.signal.aborted)return;if(e===`permissions`){if(typeof s?.screen!=`boolean`||typeof s?.accessibility!=`boolean`)throw Error(`Invalid permission status`);r(e=>e&&{...e,permissions:{supported:!0,screen:s.screen,accessibility:s.accessibility}}),f(!0)}else{if(typeof s?.os!=`string`||typeof s.enabled!=`boolean`||typeof s.environmentEnabled!=`boolean`||typeof s.supported!=`boolean`)throw Error(`Invalid desktop status`);r(s)}}catch{p.current===n&&!a.signal.aborted&&ne(!0)}finally{p.current===n&&!a.signal.aborted&&(h.current=null,s(!1))}}return(0,b.useEffect)(()=>(g(`status`),()=>{p.current++,h.current?.abort(),h.current=null}),[]),(0,x.jsxs)(`section`,{className:`dc-card`,"aria-label":t?`ๆœฌๆœบ่ฟœ็จ‹ๆกŒ้ข`:`Local remote desktop`,"aria-busy":a,children:[(0,x.jsxs)(`div`,{className:`dc-card-header`,children:[(0,x.jsx)(`span`,{className:`dc-icon`,children:(0,x.jsx)(o,{"aria-hidden":!0})}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`h2`,{children:t?`ๆœฌๆœบ่ฟœ็จ‹ๆกŒ้ข`:`Local remote desktop`}),(0,x.jsx)(`p`,{children:t?`็ฎก็†่ฟ™ๅฐ่ฎพๅค‡็š„่ฟœ็จ‹ๆกŒ้ขไธŽ็ณป็ปŸๆƒ้™๏ผŒๆ— ้œ€่ฟžๆŽฅ่ฎพๅค‡ไธญๅฟƒใ€‚`:`Manage remote desktop and system permissions on this device, even while the device center is offline.`})]})]}),l?(0,x.jsx)(`p`,{role:`status`,children:t?`่ฏทๅœจ่ฎพๅค‡ๆœฌๆœบๆ‰“ๅผ€ๆญค้กต้ขไปฅ็ฎก็†่ฟœ็จ‹ๆกŒ้ขๆƒ้™ใ€‚`:`Open this page on the device itself to manage remote desktop permissions.`}):(0,x.jsxs)(x.Fragment,{children:[n&&(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)(`div`,{className:`dc-permission-row`,children:[(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`h3`,{id:`dc-desktop-label`,children:t?`ๅฏ็”จ่ฟœ็จ‹ๆกŒ้ข`:`Enable remote desktop`}),(0,x.jsx)(`p`,{children:n.enabled?t?`ๅทฒๅฏ็”จ`:`Enabled`:t?`ๆœชๅฏ็”จ`:`Disabled`})]}),(0,x.jsx)(`button`,{type:`button`,className:`dc-toggle${n.enabled?` is-on`:``}`,role:`switch`,"aria-checked":n.enabled,"aria-labelledby":`dc-desktop-label`,disabled:a||n.environmentEnabled||!n.supported&&!n.enabled,onClick:()=>void g(`enable`,{enabled:!n.enabled}),children:(0,x.jsx)(`span`,{className:`dc-toggle-thumb`})})]}),!n.supported&&(0,x.jsx)(`p`,{children:t?`่ฟ™ๅฐ่ฎพๅค‡ๆš‚ไธๆ”ฏๆŒ่ฟœ็จ‹ๆกŒ้ขใ€‚`:`Remote desktop is currently unavailable on this device.`}),n.environmentEnabled&&(0,x.jsx)(`p`,{children:t?`่ฟœ็จ‹ๆกŒ้ข็”ฑๆœฌๆœบๆœๅŠก่ฎพ็ฝฎไฟๆŒๅฏ็”จใ€‚`:`Remote desktop is kept enabled by the service settings on this device.`}),n.os===`darwin`&&(0,x.jsxs)(x.Fragment,{children:[(0,x.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,x.jsxs)(`div`,{className:`dc-actions`,children:[(0,x.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:a||n.permissions?.supported===!1,onClick:()=>void g(`permissions`,{kind:`screen`}),children:t?`ๆŽˆไบˆๅฑๅน•ๅฝ•ๅˆถๆƒ้™`:`Grant screen recording permission`}),(0,x.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:a||n.permissions?.supported===!1,onClick:()=>void g(`permissions`,{kind:`control`}),children:t?`ๆŽˆไบˆ่ฟœ็จ‹ๆŽงๅˆถๆƒ้™`:`Grant remote control permission`})]}),n.permissions?.screen===!0&&(0,x.jsx)(`p`,{children:t?`ๅฑๅน•ๅฝ•ๅˆถ๏ผšๅทฒๆŽˆๆƒ`:`Screen recording: granted`}),n.permissions?.accessibility===!0&&(0,x.jsx)(`p`,{children:t?`่ฟœ็จ‹ๆŽงๅˆถ๏ผšๅทฒๆŽˆๆƒ`:`Remote control: granted`}),d&&(0,x.jsx)(`p`,{role:`status`,children:t?`ๅทฒๅ‘่ตทๆŽˆๆƒ่ฏทๆฑ‚๏ผŒ่ฏท็กฎ่ฎค็ณป็ปŸ่ฎพ็ฝฎๅŽๅˆทๆ–ฐ็Šถๆ€ใ€‚`:`Permission requested. Confirm in System Settings, then refresh the status.`})]})]}),te&&(0,x.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:t?`ๆ— ๆณ•ๆ›ดๆ–ฐๆœฌๆœบ่ฟœ็จ‹ๆกŒ้ข่ฎพ็ฝฎ๏ผŒ่ฏท้‡่ฏ•ใ€‚`:`Unable to update local remote desktop settings. Please retry.`}),(0,x.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:a,onClick:()=>void g(`status`),children:[(0,x.jsx)(c,{"aria-hidden":!0}),a?e(`deviceHubWorking`):t?`ๅˆทๆ–ฐ่ฟœ็จ‹ๆกŒ้ข็Šถๆ€`:`Refresh remote desktop status`]})]})]})}function L({pathCompletions:e=[]}){let r=ee(),[s,te]=(0,b.useState)(null),[l,u]=(0,b.useState)(``),[f,p]=(0,b.useState)(``),[g,_]=(0,b.useState)(null),[v,re]=(0,b.useState)(!1),[C,w]=(0,b.useState)(Date.now()),[T,E]=(0,b.useState)(null),[D,O]=(0,b.useState)(``),[k,A]=(0,b.useState)(``),[j,M]=(0,b.useState)(``),[N,L]=(0,b.useState)(!1),[R,z]=(0,b.useState)(!1),[B,V]=(0,b.useState)(!0),H=(0,b.useRef)(!1),U=(0,b.useRef)(0),W=(0,b.useRef)(new Set),G=(0,b.useRef)(!1),K=(0,b.useRef)(!1),q=(0,b.useRef)(null),ce=(0,b.useRef)(r);ce.current=r,(0,b.useEffect)(()=>{let e=e=>{let t=e;t.detail?.deviceId&&q.current?.deviceId===t.detail.deviceId&&(te(e=>e&&{...e,remark:t.detail.remark}),q.current&&(q.current.remark=t.detail.remark))};return window.addEventListener(`pi-web-ui:device-remark-updated`,e),()=>window.removeEventListener(`pi-web-ui:device-remark-updated`,e)},[]);async function J(e,t){let n=new AbortController;W.current.add(n);try{let r=await fetch(i(m(`/api/device-center/${e}`)),{method:t?`POST`:`GET`,credentials:`same-origin`,signal:n.signal,...t?{headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}:{}}),a=await r.json().catch(()=>({}));if(!r.ok)throw new se(r.status,typeof a.error==`string`?a.error:ce.current(`deviceHubRequestFailed`,{status:r.status}));return a}finally{W.current.delete(n)}}function Y(e){return H.current&&U.current===e}function X(e){return e instanceof se&&e.status===403?(z(!0),ce.current(`deviceHubLocalOnly`)):e instanceof Error?e.message:ce.current(`deviceHubNetworkError`)}function Z(e){q.current=e,te(e),K.current||(p(e.name),u(e.hubUrl??``))}async function Q(){let e=U.current;try{let t=await J(`status`);if(!Y(e)||G.current)return;Z(t),A(``),z(!1)}catch(t){Y(e)&&A(X(t))}finally{Y(e)&&V(!1)}}(0,b.useEffect)(()=>{H.current=!0;let e=!1,t,n=async()=>{await Q(),!e&&H.current&&(t=setTimeout(n,5e3))};return n(),()=>{e=!0,H.current=!1,U.current++,clearTimeout(t);for(let e of W.current)e.abort()}},[]),(0,b.useEffect)(()=>{if(!g)return;let e=U.current,t=!1,n,r=setInterval(()=>w(Date.now()),1e3),i=async()=>{if(!(t||!Y(e)||Date.now()>=g.expiresAt)){try{let n=await J(`poll`,{});if(t||!Y(e))return;if(n.paired){let n=await J(`status`);if(t||!Y(e))return;K.current=!1,Z(n),_(null),O(``),M(``);return}O(``)}catch(n){!t&&Y(e)&&O(`${ce.current(`deviceHubPollError`)} ${X(n)}`)}!t&&Y(e)&&(n=setTimeout(i,2e3))}};return n=setTimeout(i,2e3),()=>{t=!0,clearTimeout(n),clearInterval(r)}},[g]);async function le(){if(G.current)return;let e=F(l.trim());if(!e){O(r(`deviceHubInvalidUrl`));return}if(!f.trim()||f.trim().length>80){O(r(`deviceHubInvalidName`));return}let t=++U.current;G.current=!0,E(`pair`),O(``),M(``),_(null);try{let n=await J(`pair`,{hubUrl:e,name:f.trim()});if(!Y(t))return;if(!n.code||!Number.isFinite(n.expiresAt)||!F(n.hubUrl))throw Error(r(`deviceHubPairError`));w(Date.now()),_(n)}catch(e){Y(t)&&O(`${r(`deviceHubPairError`)} ${X(e)}`)}finally{Y(t)&&(G.current=!1,E(null))}}async function ue(){let e=q.current;if(!e?.deviceId||G.current)return;let t=++U.current;G.current=!0,E(`permission`),O(``),M(``),Z({...e,allowExecution:!e.allowExecution});try{await J(`execution`,{allowExecution:!e.allowExecution}),Y(t)&&M(r(`deviceHubSaved`))}catch(n){Y(t)&&(Z(e),O(`${r(`deviceHubPermissionError`)} ${X(n)}`))}finally{Y(t)&&(G.current=!1,E(null))}}async function de(){let e=q.current;if(!e?.deviceId||G.current||!window.confirm(r(`deviceHubDisconnectConfirm`,{name:e.name})))return;let t=++U.current;G.current=!0,E(`disconnect`),O(``),M(``);try{if(await J(`disconnect`,{}),!Y(t))return;K.current=!1,Z({name:e.name,allowExecution:!1,connected:!1}),_(null)}catch(e){Y(t)&&O(`${r(`deviceHubDisconnectError`)} ${X(e)}`)}finally{Y(t)&&(G.current=!1,E(null))}}async function fe(){if(!N&&!T&&$&&s?.hubUrl&&window.confirm(r(`deviceHubConfirmUpgrade`))){L(!0),O(``),M(``);try{let e=await J(`upgrade-hub`,{});if(e.ok)M(r(`deviceHubUpgradeSuccess`)),await Q();else throw Error(e.message||`Upgrade failed`)}catch(e){O(X(e))}finally{L(!1)}}}async function pe(){if(!g)return;let e=U.current;try{await navigator.clipboard.writeText(g.code),Y(e)&&M(r(`deviceHubCopied`))}catch{Y(e)&&O(r(`deviceHubCopyFailed`))}}let $=!!s?.deviceId,me=F($?s?.hubUrl??``:g?.hubUrl??``),he=Math.max(0,Math.ceil(((g?.expiresAt??0)-C)/1e3)),ge=`${Math.floor(he/60)}:${String(he%60).padStart(2,`0`)}`,_e=me?(0,x.jsxs)(S,{href:me,children:[(0,x.jsx)(t,{"aria-hidden":!0}),r(`deviceHubOpenHub`)]}):null;return(0,x.jsxs)(`section`,{className:`dc-page`,"aria-label":r(`deviceHubTitle`),children:[(0,x.jsxs)(`header`,{className:`dc-header`,children:[(0,x.jsxs)(`div`,{className:`dc-heading`,children:[(0,x.jsxs)(`span`,{className:`dc-eyebrow`,children:[(0,x.jsx)(o,{"aria-hidden":!0}),r(`deviceHubTitle`)]}),(0,x.jsx)(`h1`,{children:r(`deviceHubTitle`)}),(0,x.jsx)(`p`,{children:r(`deviceHubSubtitle`)})]}),(0,x.jsxs)(`div`,{className:`dc-actions`,children:[$&&_e,(0,x.jsxs)(`span`,{className:`dc-status ${$?s?.connected?`is-online`:`is-offline`:`is-unpaired`}`,children:[(0,x.jsx)(`span`,{className:`dc-status-dot`}),r($?s?.connected?`deviceHubOnline`:`deviceHubOffline`:`deviceHubUnpaired`)]})]})]}),(0,x.jsx)(`div`,{className:`dc-layout`,style:{display:`block`},children:(0,x.jsxs)(`main`,{className:`dc-content`,children:[B&&(0,x.jsxs)(`div`,{className:`dc-loading`,role:`status`,children:[(0,x.jsx)(c,{"aria-hidden":!0}),r(`deviceHubLoading`)]}),(R||k)&&(0,x.jsxs)(`div`,{className:`dc-notice is-error`,role:`alert`,children:[(0,x.jsx)(`span`,{children:R?r(`deviceHubLocalOnly`):`${r(`deviceHubStatusError`)} ${k}`}),(0,x.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>void Q(),children:[(0,x.jsx)(c,{"aria-hidden":!0}),r(`deviceHubRetry`)]})]}),D&&!R&&(0,x.jsx)(`div`,{className:`dc-notice is-error`,role:`alert`,children:D}),j&&(0,x.jsxs)(`div`,{className:`dc-notice is-success`,role:`status`,children:[(0,x.jsx)(n,{"aria-hidden":!0}),j]}),!$&&(s||R)&&(0,x.jsx)(oe,{initialHubUrl:l,onConnect:e=>{if(R){M(r(`deviceHubLocalOnly`));return}K.current=!0,u(e),re(!0)}}),s&&!R&&!$&&(0,x.jsxs)(`section`,{className:`dc-card`,children:[(0,x.jsxs)(`div`,{className:`dc-card-header`,children:[(0,x.jsx)(`span`,{className:`dc-icon`,children:(0,x.jsx)(d,{"aria-hidden":!0})}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`h2`,{children:r(`deviceHubPairTitle`)}),(0,x.jsx)(`p`,{children:r(`deviceHubPairHint`)})]})]}),(0,x.jsx)(`ol`,{className:`dc-steps`,children:[`deviceHubStepDetails`,`deviceHubStepApprove`,`deviceHubStepWait`].map((e,t)=>(0,x.jsxs)(`li`,{className:g?t===0?`is-complete`:`is-active`:t===0?`is-active`:``,children:[(0,x.jsx)(`span`,{className:`dc-step-number`,children:g&&t===0?(0,x.jsx)(n,{"aria-hidden":!0}):t+1}),(0,x.jsx)(`span`,{children:r(e)})]},e))}),(0,x.jsxs)(`form`,{className:`dc-form`,onSubmit:e=>{e.preventDefault(),le()},children:[(0,x.jsxs)(`div`,{className:`dc-field`,children:[(0,x.jsx)(`label`,{htmlFor:`dc-hub-url`,children:r(`deviceHubHubUrl`)}),(0,x.jsx)(`input`,{id:`dc-hub-url`,type:`url`,autoComplete:`url`,required:!0,placeholder:r(`deviceHubHubPlaceholder`),value:l,disabled:!!g||!!T,onChange:e=>{K.current=!0,u(e.target.value)}})]}),(0,x.jsxs)(`div`,{className:`dc-field`,children:[(0,x.jsx)(`label`,{htmlFor:`dc-device-name`,children:r(`deviceHubName`)}),(0,x.jsx)(`input`,{id:`dc-device-name`,maxLength:80,required:!0,autoComplete:`off`,placeholder:r(`deviceHubNamePlaceholder`),value:f,disabled:!!g||!!T,onChange:e=>{K.current=!0,p(e.target.value)}})]}),!g&&(0,x.jsx)(`div`,{className:`dc-actions`,children:(0,x.jsxs)(`button`,{className:`dc-button is-primary`,type:`submit`,disabled:!!T,children:[(0,x.jsx)(d,{"aria-hidden":!0}),r(T?`deviceHubWorking`:`deviceHubGetCode`)]})})]}),g&&(0,x.jsxs)(`div`,{className:`dc-pairing`,children:[(0,x.jsx)(`span`,{className:`dc-code-label`,children:r(`deviceHubCode`)}),(0,x.jsxs)(`div`,{className:`dc-code-row`,children:[(0,x.jsx)(`code`,{className:`dc-code`,children:g.code}),(0,x.jsx)(`button`,{className:`dc-icon-button`,type:`button`,"aria-label":r(`deviceHubCopy`),onClick:()=>void pe(),children:(0,x.jsx)(a,{"aria-hidden":!0})})]}),(0,x.jsx)(`div`,{className:`dc-pair-meta`,children:r(he?`deviceHubExpires`:`deviceHubExpired`,{time:ge})}),(0,x.jsxs)(`div`,{className:`dc-actions`,children:[_e,(0,x.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:!!T,onClick:()=>{++U.current,_(null),O(``),M(``)},children:[(0,x.jsx)(c,{"aria-hidden":!0}),r(`deviceHubNewCode`)]})]}),he>0&&(0,x.jsxs)(`p`,{className:`dc-progress`,role:`status`,children:[(0,x.jsx)(c,{"aria-hidden":!0}),r(`deviceHubWaiting`)]})]})]}),$&&s&&!R&&(0,x.jsxs)(`section`,{className:`dc-card`,children:[(0,x.jsxs)(`div`,{className:`dc-device-summary`,children:[(0,x.jsx)(`span`,{className:`dc-device-icon`,children:(0,x.jsx)(o,{"aria-hidden":!0})}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`h2`,{children:s.remark?.trim()||s.name}),(0,x.jsx)(`p`,{children:s.remark?.trim()?`${s.name} ยท ${r(`deviceHubDeviceTitle`)}`:r(`deviceHubDeviceTitle`)})]})]}),(0,x.jsxs)(`dl`,{className:`dc-details`,children:[(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`dt`,{children:r(`deviceHubDeviceId`)}),(0,x.jsx)(`dd`,{children:s.deviceId})]}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`dt`,{children:r(`deviceHubHubUrl`)}),(0,x.jsx)(`dd`,{children:s.hubUrl})]})]}),(0,x.jsx)(`div`,{className:`dc-actions`,style:{marginTop:`1rem`},children:(0,x.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:N||!!T,onClick:()=>void fe(),children:[(0,x.jsx)(c,{className:N?`spin`:``,"aria-hidden":!0}),r(N?`deviceHubUpgrading`:`deviceHubUpgradeAction`)]})})]}),$&&s?.hubUrl&&s.deviceId&&!R&&(0,x.jsx)(ie,{hubUrl:s.hubUrl,currentDeviceId:s.deviceId},`directory:${s.hubUrl}:${s.deviceId}`),!R&&(0,x.jsx)(ae,{pathCompletions:e},`bots:${s?.hubUrl??``}:${s?.deviceId??`unpaired`}`),$&&!R&&(0,x.jsx)(P,{}),(0,x.jsx)(I,{}),$&&s&&!R&&(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)(`section`,{className:`dc-card`,children:[(0,x.jsxs)(`div`,{className:`dc-card-header`,children:[(0,x.jsx)(`span`,{className:`dc-icon`,children:(0,x.jsx)(ne,{"aria-hidden":!0})}),(0,x.jsx)(`div`,{children:(0,x.jsx)(`h2`,{children:r(`deviceHubPermissions`)})})]}),(0,x.jsxs)(`div`,{className:`dc-permission-row`,children:[(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`h3`,{id:`dc-permission-label`,children:r(`deviceHubPermissionLabel`)}),(0,x.jsx)(`p`,{id:`dc-permission-hint`,children:r(`deviceHubPermissionHint`)})]}),(0,x.jsx)(`button`,{type:`button`,className:`dc-toggle${s.allowExecution?` is-on`:``}`,role:`switch`,"aria-checked":s.allowExecution,"aria-labelledby":`dc-permission-label`,"aria-describedby":`dc-permission-hint`,disabled:!!T,onClick:()=>void ue(),children:(0,x.jsx)(`span`,{className:`dc-toggle-thumb`})})]}),(0,x.jsx)(`p`,{className:`dc-permission-state`,role:`status`,children:r(T===`permission`?`deviceHubSaving`:s.allowExecution?`deviceHubEnabled`:`deviceHubReadOnly`)})]}),(0,x.jsx)(y,{hubUrl:s?.hubUrl,deviceId:s?.deviceId,onNotice:M}),(0,x.jsxs)(`details`,{className:`dc-advanced`,children:[(0,x.jsx)(`summary`,{children:r(`deviceHubAdvanced`)}),(0,x.jsxs)(`div`,{className:`dc-danger-zone`,children:[(0,x.jsx)(`h3`,{children:r(`deviceHubDisconnect`)}),(0,x.jsx)(`p`,{children:r(`deviceHubDisconnectHint`)}),(0,x.jsx)(`button`,{type:`button`,className:`dc-button is-danger`,disabled:!!T,onClick:()=>void de(),children:r(T===`disconnect`?`deviceHubWorking`:`deviceHubDisconnect`)})]})]})]}),(0,x.jsxs)(`aside`,{className:`dc-help`,children:[(0,x.jsx)(h,{className:`dc-help-icon`,"aria-hidden":!0}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`h3`,{children:r(`deviceHubHelpTitle`)}),(0,x.jsx)(`p`,{children:r(`deviceHubHelpText`)})]})]})]})})]})}export{L as DeviceCenter};
@@ -0,0 +1 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{A as t,Dn as n,Ht as r,K as i,Ot as a,Sn as o,St as s,Vt as c,Xt as l,Yt as u,fn as d,kn as f,ot as p,p as m,z as h,zt as g}from"./app-globals-KqOVtmp1.js";import{i as _,t as v}from"./react-CR5VJ85Q.js";var y=e(_(),1),b=v(),x={maxActiveTasks:4,maxWaitingTasks:32,starvationThresholdMs:8e3,maxSkipsBeforeStarvation:3,maxDispatchDepth:8,maxDispatchBudget:16,allowBotMentions:!1,groupContextBytes:262144,groupRetentionLimit:2e3,fileSyncMaxBytes:104857600,fileSyncMaxFiles:1e3,fileSyncStagedBytes:1073741824,resourceLockDefaultTtlMs:18e5,blackboardMaxBytes:262144,taskReportExcerptBytes:131072,maxResourceLocksPerTask:128,botMentionBudgetPerTurn:3};function S(e,t,n,r){return typeof e==`number`&&Number.isFinite(e)?Math.max(t,Math.min(n,Math.round(e))):r}function C(e){if(!Number.isFinite(e)||e<=0)return`0 B`;let t=[`B`,`KiB`,`MiB`,`GiB`],n=0,r=e;for(;r>=1024&&n<t.length-1;)r/=1024,n++;return`${Number.isInteger(r)?r:r.toFixed(1)} ${t[n]}`}function w(e){return!Number.isFinite(e)||e<=0?`0 ms`:e<1e3?`${e} ms`:e<6e4?`${Math.round(e/1e3)} s`:`${(e/6e4).toFixed(1)} min`}function T(e){let t={settings:{...x},activeCount:0,waitingCount:0,blockedCount:0,running:[],waiting:[],blocked:[]};if(!e||typeof e!=`object`||Array.isArray(e))return t;let n=e,r=n.settings&&typeof n.settings==`object`&&!Array.isArray(n.settings)?n.settings:{},i={maxActiveTasks:S(r.maxActiveTasks,1,64,x.maxActiveTasks),maxWaitingTasks:S(r.maxWaitingTasks,0,1024,x.maxWaitingTasks),starvationThresholdMs:S(r.starvationThresholdMs,1e3,6e4,x.starvationThresholdMs),maxSkipsBeforeStarvation:S(r.maxSkipsBeforeStarvation,1,20,x.maxSkipsBeforeStarvation),maxDispatchDepth:S(r.maxDispatchDepth,1,64,x.maxDispatchDepth),maxDispatchBudget:S(r.maxDispatchBudget,1,256,x.maxDispatchBudget),allowBotMentions:typeof r.allowBotMentions==`boolean`?r.allowBotMentions:x.allowBotMentions,groupContextBytes:S(r.groupContextBytes,4096,2097152,x.groupContextBytes),groupRetentionLimit:S(r.groupRetentionLimit,50,2e4,x.groupRetentionLimit),fileSyncMaxBytes:S(r.fileSyncMaxBytes,1048576,10737418240,x.fileSyncMaxBytes),fileSyncMaxFiles:S(r.fileSyncMaxFiles,10,1e4,x.fileSyncMaxFiles),fileSyncStagedBytes:S(r.fileSyncStagedBytes,4194304,53687091200,x.fileSyncStagedBytes),resourceLockDefaultTtlMs:S(r.resourceLockDefaultTtlMs,6e4,864e5,x.resourceLockDefaultTtlMs),blackboardMaxBytes:S(r.blackboardMaxBytes,4096,4194304,x.blackboardMaxBytes),...typeof r.taskReportExcerptBytes==`number`?{taskReportExcerptBytes:r.taskReportExcerptBytes}:{},...typeof r.maxResourceLocksPerTask==`number`?{maxResourceLocksPerTask:r.maxResourceLocksPerTask}:{},...typeof r.botMentionBudgetPerTurn==`number`?{botMentionBudgetPerTurn:r.botMentionBudgetPerTurn}:{}},a=Array.isArray(n.running)?n.running:[],o=Array.isArray(n.waiting)?n.waiting:[],s=Array.isArray(n.blocked)?n.blocked:[];return{settings:i,activeCount:typeof n.activeCount==`number`?n.activeCount:a.length,waitingCount:typeof n.waitingCount==`number`?n.waitingCount:o.length,blockedCount:typeof n.blockedCount==`number`?n.blockedCount:s.length,running:a,waiting:o,blocked:s}}function E({hubUrl:e,deviceId:_,onNotice:v}){let E=o(),[D,O]=(0,y.useState)(null),[k,A]=(0,y.useState)(x),[j,M]=(0,y.useState)(!1),[N,P]=(0,y.useState)(!1),[F,I]=(0,y.useState)(null),[L,R]=(0,y.useState)(null),[z,B]=(0,y.useState)(null),V=(0,y.useRef)(!0),H=(0,y.useRef)(0),U=(0,y.useRef)(new Set),W=(0,y.useRef)(!1),G=(0,y.useRef)(!1),K=`${e??``}:${_??``}`,q=(0,y.useCallback)(async(e,t,r)=>{let i=new AbortController;U.current.add(i);let a=()=>i.abort();r&&(r.aborted?i.abort():r.addEventListener(`abort`,a,{once:!0}));try{let r=await fetch(n(f(`/api/device-center/${e}`)),{method:t?`POST`:`GET`,credentials:`same-origin`,signal:i.signal,headers:t?{"Content-Type":`application/json`}:void 0,body:t?JSON.stringify(t):void 0}),a=await r.json().catch(()=>({}));if(!r.ok){let e=typeof a.error==`string`?a.error:`HTTP ${r.status}`;throw Error(e)}return a}finally{r&&r.removeEventListener(`abort`,a),U.current.delete(i)}},[]),J=(0,y.useCallback)(async(e=!1)=>{if(!V.current||W.current)return;W.current=!0;let t=H.current;e||M(!0);try{let e=await q(`execution-queue`);if(!V.current||t!==H.current)return;let n=T(e);O(n),R(null),G.current||=(A({...n.settings}),!0)}catch(e){if(!V.current||t!==H.current)return;e.name!==`AbortError`&&R(e.message)}finally{W.current=!1,V.current&&t===H.current&&!e&&M(!1)}},[q]);(0,y.useEffect)(()=>{V.current=!0,H.current++;for(let e of U.current)e.abort();U.current.clear(),W.current=!1,G.current=!1,O(null),A({...x}),R(null),B(null),J(!1);let e=setInterval(()=>{J(!0)},3e3);return()=>{V.current=!1,H.current++;for(let e of U.current)e.abort();U.current.clear(),clearInterval(e)}},[K,J]);let Y=(e,t)=>{A(n=>({...n,[e]:t}))},X=(e,t)=>{A(n=>({...n,[e]:t}))},Z=()=>{A({...x})},Q=()=>{D?.settings?A({...D.settings}):A({...x})},$=async e=>{e.preventDefault();let t=H.current;P(!0),R(null),B(null);let n={maxActiveTasks:S(k.maxActiveTasks,1,64,x.maxActiveTasks),maxWaitingTasks:S(k.maxWaitingTasks,0,1024,x.maxWaitingTasks),starvationThresholdMs:S(k.starvationThresholdMs,1e3,6e4,x.starvationThresholdMs),maxSkipsBeforeStarvation:S(k.maxSkipsBeforeStarvation,1,20,x.maxSkipsBeforeStarvation),maxDispatchDepth:S(k.maxDispatchDepth,1,64,x.maxDispatchDepth),maxDispatchBudget:S(k.maxDispatchBudget,1,256,x.maxDispatchBudget),allowBotMentions:!!k.allowBotMentions,groupContextBytes:S(k.groupContextBytes,4096,2097152,x.groupContextBytes),groupRetentionLimit:S(k.groupRetentionLimit,50,2e4,x.groupRetentionLimit),fileSyncMaxBytes:S(k.fileSyncMaxBytes,1048576,10737418240,x.fileSyncMaxBytes),fileSyncMaxFiles:S(k.fileSyncMaxFiles,10,1e4,x.fileSyncMaxFiles),fileSyncStagedBytes:S(k.fileSyncStagedBytes,4194304,53687091200,x.fileSyncStagedBytes),resourceLockDefaultTtlMs:S(k.resourceLockDefaultTtlMs,6e4,864e5,x.resourceLockDefaultTtlMs),blackboardMaxBytes:S(k.blackboardMaxBytes,4096,4194304,x.blackboardMaxBytes),...k.taskReportExcerptBytes===void 0?{}:{taskReportExcerptBytes:k.taskReportExcerptBytes},...k.maxResourceLocksPerTask===void 0?{}:{maxResourceLocksPerTask:k.maxResourceLocksPerTask},...k.botMentionBudgetPerTurn===void 0?{}:{botMentionBudgetPerTurn:k.botMentionBudgetPerTurn}};try{let e=await q(`execution-settings`,n);if(!V.current||t!==H.current)return;e?.settings&&A({...e.settings}),B(E(`deviceExecSavedNotice`)),v?.(E(`deviceExecSavedNotice`)),await J(!0)}catch(e){if(!V.current||t!==H.current)return;e.name!==`AbortError`&&R(e.message)}finally{V.current&&t===H.current&&P(!1)}},ee=async(e,t)=>{let n=H.current;I(e),R(null);try{if(await q(`execution-queue/cancel`,{taskId:e,attemptId:t}),!V.current||n!==H.current)return;v?.(E(`deviceExecTaskCancelled`)),await J(!0)}catch(e){if(!V.current||n!==H.current)return;e.name!==`AbortError`&&R(e.message)}finally{V.current&&n===H.current&&I(null)}},te=e=>{switch(e){case`max_concurrency_reached`:return E(`deviceExecReasonMaxConcurrency`);case`bot_busy`:return E(`deviceExecReasonBotBusy`);case`workspace_conflict`:return E(`deviceExecReasonWorkspaceConflict`);case`workspace_blocked`:return E(`deviceExecReasonWorkspaceBlocked`);case`room_fairness_yield`:return E(`deviceExecReasonFairness`);default:return e}},ne=D?.settings?.maxActiveTasks??x.maxActiveTasks,re=D?.settings?.maxWaitingTasks??x.maxWaitingTasks;return(0,b.jsxs)(`div`,{className:`des-container`,children:[(0,b.jsxs)(`div`,{className:`des-header`,children:[(0,b.jsxs)(`div`,{className:`des-header-left`,children:[(0,b.jsx)(`h3`,{className:`des-title`,children:E(`deviceExecTitle`)}),(0,b.jsx)(`p`,{className:`des-subtitle`,children:E(`deviceExecSubtitle`)})]}),(0,b.jsx)(`button`,{type:`button`,className:`des-refresh-btn`,onClick:()=>void J(!1),disabled:j,title:E(`deviceExecRefresh`),children:(0,b.jsx)(c,{className:j?`des-spin`:``})})]}),L&&(0,b.jsxs)(`div`,{className:`des-alert des-alert-error`,role:`alert`,children:[(0,b.jsx)(m,{className:`des-alert-icon`}),(0,b.jsx)(`div`,{className:`des-alert-text`,children:L}),(0,b.jsx)(`button`,{type:`button`,className:`des-alert-close`,onClick:()=>R(null),children:(0,b.jsx)(d,{})})]}),z&&(0,b.jsxs)(`div`,{className:`des-alert des-alert-success`,role:`status`,children:[(0,b.jsx)(t,{className:`des-alert-icon`}),(0,b.jsx)(`div`,{className:`des-alert-text`,children:z}),(0,b.jsx)(`button`,{type:`button`,className:`des-alert-close`,onClick:()=>B(null),children:(0,b.jsx)(d,{})})]}),(0,b.jsxs)(`div`,{className:`des-stats-row`,children:[(0,b.jsxs)(`div`,{className:`des-stat-card`,children:[(0,b.jsxs)(`div`,{className:`des-stat-label`,children:[(0,b.jsx)(g,{className:`des-stat-icon is-running`}),` `,E(`deviceExecRunning`)]}),(0,b.jsxs)(`div`,{className:`des-stat-value`,children:[D?.activeCount??0,` `,(0,b.jsxs)(`span`,{className:`des-stat-sub`,children:[`/ `,ne]})]})]}),(0,b.jsxs)(`div`,{className:`des-stat-card`,children:[(0,b.jsxs)(`div`,{className:`des-stat-label`,children:[(0,b.jsx)(h,{className:`des-stat-icon is-waiting`}),` `,E(`deviceExecQueued`)]}),(0,b.jsxs)(`div`,{className:`des-stat-value`,children:[D?.waitingCount??0,` `,(0,b.jsxs)(`span`,{className:`des-stat-sub`,children:[`/ `,re]})]})]}),(0,b.jsxs)(`div`,{className:`des-stat-card`,children:[(0,b.jsxs)(`div`,{className:`des-stat-label`,children:[(0,b.jsx)(l,{className:`des-stat-icon is-blocked`}),` `,E(`deviceExecBlocked`)]}),(0,b.jsx)(`div`,{className:`des-stat-value${(D?.blockedCount??0)>0?` is-warn`:``}`,children:D?.blockedCount??0})]})]}),(0,b.jsxs)(`form`,{className:`des-form-card`,onSubmit:e=>void $(e),children:[(0,b.jsxs)(`div`,{className:`des-form-header`,children:[(0,b.jsx)(`h4`,{className:`des-form-title`,children:E(`deviceExecQuotaTitle`)}),(0,b.jsx)(`div`,{className:`des-form-header-actions`,children:(0,b.jsxs)(`button`,{type:`button`,className:`des-btn des-btn-secondary des-btn-sm`,disabled:N,onClick:Z,title:E(`deviceExecResetDefaultsTip`),children:[(0,b.jsx)(r,{className:`des-btn-icon`}),E(`deviceExecResetDefaults`)]})})]}),(0,b.jsxs)(`div`,{className:`des-group`,children:[(0,b.jsxs)(`div`,{className:`des-group-header`,children:[(0,b.jsx)(i,{className:`des-group-icon`}),(0,b.jsx)(`span`,{className:`des-group-title`,children:E(`deviceExecSchedulingTitle`)})]}),(0,b.jsxs)(`div`,{className:`des-fields-row`,children:[(0,b.jsxs)(`div`,{className:`des-field`,children:[(0,b.jsx)(`label`,{htmlFor:`des-max-active`,className:`des-label`,children:E(`deviceExecMaxActive`)}),(0,b.jsx)(`input`,{id:`des-max-active`,type:`number`,min:1,max:64,step:1,className:`des-input`,value:k.maxActiveTasks,onChange:e=>Y(`maxActiveTasks`,parseInt(e.target.value,10)||1),required:!0}),(0,b.jsx)(`span`,{className:`des-hint`,children:E(`deviceExecMaxActiveHint`)})]}),(0,b.jsxs)(`div`,{className:`des-field`,children:[(0,b.jsx)(`label`,{htmlFor:`des-max-waiting`,className:`des-label`,children:E(`deviceExecMaxWaiting`)}),(0,b.jsx)(`input`,{id:`des-max-waiting`,type:`number`,min:0,max:1024,step:1,className:`des-input`,value:k.maxWaitingTasks,onChange:e=>Y(`maxWaitingTasks`,parseInt(e.target.value,10)||0),required:!0}),(0,b.jsx)(`span`,{className:`des-hint`,children:E(`deviceExecMaxWaitingHint`)})]}),(0,b.jsxs)(`div`,{className:`des-field`,children:[(0,b.jsx)(`label`,{htmlFor:`des-starvation-ms`,className:`des-label`,children:E(`deviceExecStarvationMs`)}),(0,b.jsxs)(`div`,{className:`des-input-with-badge`,children:[(0,b.jsx)(`input`,{id:`des-starvation-ms`,type:`number`,min:1e3,max:6e4,step:500,className:`des-input`,value:k.starvationThresholdMs,onChange:e=>Y(`starvationThresholdMs`,parseInt(e.target.value,10)||1e3),required:!0}),(0,b.jsx)(`span`,{className:`des-input-badge`,children:w(k.starvationThresholdMs)})]}),(0,b.jsx)(`span`,{className:`des-hint`,children:E(`deviceExecStarvationMsHint`)})]}),(0,b.jsxs)(`div`,{className:`des-field`,children:[(0,b.jsx)(`label`,{htmlFor:`des-max-skips`,className:`des-label`,children:E(`deviceExecMaxSkips`)}),(0,b.jsx)(`input`,{id:`des-max-skips`,type:`number`,min:1,max:20,step:1,className:`des-input`,value:k.maxSkipsBeforeStarvation,onChange:e=>Y(`maxSkipsBeforeStarvation`,parseInt(e.target.value,10)||1),required:!0}),(0,b.jsx)(`span`,{className:`des-hint`,children:E(`deviceExecMaxSkipsHint`)})]})]})]}),(0,b.jsxs)(`div`,{className:`des-group`,children:[(0,b.jsxs)(`div`,{className:`des-group-header`,children:[(0,b.jsx)(u,{className:`des-group-icon`}),(0,b.jsx)(`span`,{className:`des-group-title`,children:E(`deviceExecDispatchTitle`)})]}),(0,b.jsxs)(`div`,{className:`des-fields-row`,children:[(0,b.jsxs)(`div`,{className:`des-field`,children:[(0,b.jsx)(`label`,{htmlFor:`des-max-depth`,className:`des-label`,children:E(`deviceExecMaxDepth`)}),(0,b.jsx)(`input`,{id:`des-max-depth`,type:`number`,min:1,max:64,step:1,className:`des-input`,value:k.maxDispatchDepth,onChange:e=>Y(`maxDispatchDepth`,parseInt(e.target.value,10)||1),required:!0}),(0,b.jsx)(`span`,{className:`des-hint`,children:E(`deviceExecMaxDepthHint`)})]}),(0,b.jsxs)(`div`,{className:`des-field`,children:[(0,b.jsx)(`label`,{htmlFor:`des-max-budget`,className:`des-label`,children:E(`deviceExecMaxBudget`)}),(0,b.jsx)(`input`,{id:`des-max-budget`,type:`number`,min:1,max:256,step:1,className:`des-input`,value:k.maxDispatchBudget,onChange:e=>Y(`maxDispatchBudget`,parseInt(e.target.value,10)||1),required:!0}),(0,b.jsx)(`span`,{className:`des-hint`,children:E(`deviceExecMaxBudgetHint`)})]}),(0,b.jsxs)(`div`,{className:`des-field des-field-checkbox`,children:[(0,b.jsxs)(`label`,{htmlFor:`des-allow-bot-mentions`,className:`des-checkbox-container`,children:[(0,b.jsx)(`input`,{id:`des-allow-bot-mentions`,type:`checkbox`,className:`des-checkbox`,checked:k.allowBotMentions,onChange:e=>X(`allowBotMentions`,e.target.checked)}),(0,b.jsx)(`span`,{className:`des-label`,children:E(`deviceExecAllowBotMentions`)})]}),(0,b.jsx)(`span`,{className:`des-hint`,children:E(`deviceExecAllowBotMentionsHint`)})]})]})]}),(0,b.jsxs)(`div`,{className:`des-group`,children:[(0,b.jsxs)(`div`,{className:`des-group-header`,children:[(0,b.jsx)(a,{className:`des-group-icon`}),(0,b.jsx)(`span`,{className:`des-group-title`,children:E(`deviceExecContextTitle`)})]}),(0,b.jsxs)(`div`,{className:`des-fields-row`,children:[(0,b.jsxs)(`div`,{className:`des-field`,children:[(0,b.jsx)(`label`,{htmlFor:`des-group-context-bytes`,className:`des-label`,children:E(`deviceExecContextBytes`)}),(0,b.jsxs)(`div`,{className:`des-input-with-badge`,children:[(0,b.jsx)(`input`,{id:`des-group-context-bytes`,type:`number`,min:4096,max:2097152,step:1024,className:`des-input`,value:k.groupContextBytes,onChange:e=>Y(`groupContextBytes`,parseInt(e.target.value,10)||4096),required:!0}),(0,b.jsx)(`span`,{className:`des-input-badge`,children:C(k.groupContextBytes)})]}),(0,b.jsx)(`span`,{className:`des-hint`,children:E(`deviceExecContextBytesHint`)})]}),(0,b.jsxs)(`div`,{className:`des-field`,children:[(0,b.jsx)(`label`,{htmlFor:`des-group-retention`,className:`des-label`,children:E(`deviceExecRetention`)}),(0,b.jsx)(`input`,{id:`des-group-retention`,type:`number`,min:50,max:2e4,step:10,className:`des-input`,value:k.groupRetentionLimit,onChange:e=>Y(`groupRetentionLimit`,parseInt(e.target.value,10)||50),required:!0}),(0,b.jsx)(`span`,{className:`des-hint`,children:E(`deviceExecRetentionHint`)})]})]})]}),(0,b.jsxs)(`div`,{className:`des-group`,children:[(0,b.jsxs)(`div`,{className:`des-group-header`,children:[(0,b.jsx)(p,{className:`des-group-icon`}),(0,b.jsx)(`span`,{className:`des-group-title`,children:E(`deviceExecFileSyncTitle`)})]}),(0,b.jsxs)(`div`,{className:`des-fields-row`,children:[(0,b.jsxs)(`div`,{className:`des-field`,children:[(0,b.jsx)(`label`,{htmlFor:`des-file-sync-bytes`,className:`des-label`,children:E(`deviceExecFileSyncBytes`)}),(0,b.jsxs)(`div`,{className:`des-input-with-badge`,children:[(0,b.jsx)(`input`,{id:`des-file-sync-bytes`,type:`number`,min:1048576,max:10737418240,step:1048576,className:`des-input`,value:k.fileSyncMaxBytes,onChange:e=>Y(`fileSyncMaxBytes`,parseInt(e.target.value,10)||1048576),required:!0}),(0,b.jsx)(`span`,{className:`des-input-badge`,children:C(k.fileSyncMaxBytes)})]}),(0,b.jsx)(`span`,{className:`des-hint`,children:E(`deviceExecFileSyncBytesHint`)})]}),(0,b.jsxs)(`div`,{className:`des-field`,children:[(0,b.jsx)(`label`,{htmlFor:`des-file-sync-files`,className:`des-label`,children:E(`deviceExecFileSyncFiles`)}),(0,b.jsx)(`input`,{id:`des-file-sync-files`,type:`number`,min:10,max:1e4,step:1,className:`des-input`,value:k.fileSyncMaxFiles,onChange:e=>Y(`fileSyncMaxFiles`,parseInt(e.target.value,10)||10),required:!0}),(0,b.jsx)(`span`,{className:`des-hint`,children:E(`deviceExecFileSyncFilesHint`)})]}),(0,b.jsxs)(`div`,{className:`des-field`,children:[(0,b.jsx)(`label`,{htmlFor:`des-file-sync-staged-bytes`,className:`des-label`,children:E(`deviceExecFileSyncStagedBytes`)}),(0,b.jsxs)(`div`,{className:`des-input-with-badge`,children:[(0,b.jsx)(`input`,{id:`des-file-sync-staged-bytes`,type:`number`,min:4194304,max:53687091200,step:1048576,className:`des-input`,value:k.fileSyncStagedBytes,onChange:e=>Y(`fileSyncStagedBytes`,parseInt(e.target.value,10)||4194304),required:!0}),(0,b.jsx)(`span`,{className:`des-input-badge`,children:C(k.fileSyncStagedBytes)})]}),(0,b.jsx)(`span`,{className:`des-hint`,children:E(`deviceExecFileSyncStagedBytesHint`)})]})]})]}),(0,b.jsxs)(`div`,{className:`des-group`,children:[(0,b.jsxs)(`div`,{className:`des-group-header`,children:[(0,b.jsx)(s,{className:`des-group-icon`}),(0,b.jsx)(`span`,{className:`des-group-title`,children:E(`deviceExecLocksTitle`)})]}),(0,b.jsxs)(`div`,{className:`des-fields-row`,children:[(0,b.jsxs)(`div`,{className:`des-field`,children:[(0,b.jsx)(`label`,{htmlFor:`des-resource-lock-ttl`,className:`des-label`,children:E(`deviceExecLockTtl`)}),(0,b.jsxs)(`div`,{className:`des-input-with-badge`,children:[(0,b.jsx)(`input`,{id:`des-resource-lock-ttl`,type:`number`,min:6e4,max:864e5,step:6e4,className:`des-input`,value:k.resourceLockDefaultTtlMs,onChange:e=>Y(`resourceLockDefaultTtlMs`,parseInt(e.target.value,10)||6e4),required:!0}),(0,b.jsx)(`span`,{className:`des-input-badge`,children:w(k.resourceLockDefaultTtlMs)})]}),(0,b.jsx)(`span`,{className:`des-hint`,children:E(`deviceExecLockTtlHint`)})]}),(0,b.jsxs)(`div`,{className:`des-field`,children:[(0,b.jsx)(`label`,{htmlFor:`des-blackboard-bytes`,className:`des-label`,children:E(`deviceExecBlackboardBytes`)}),(0,b.jsxs)(`div`,{className:`des-input-with-badge`,children:[(0,b.jsx)(`input`,{id:`des-blackboard-bytes`,type:`number`,min:4096,max:4194304,step:1024,className:`des-input`,value:k.blackboardMaxBytes,onChange:e=>Y(`blackboardMaxBytes`,parseInt(e.target.value,10)||4096),required:!0}),(0,b.jsx)(`span`,{className:`des-input-badge`,children:C(k.blackboardMaxBytes)})]}),(0,b.jsx)(`span`,{className:`des-hint`,children:E(`deviceExecBlackboardBytesHint`)})]})]})]}),(0,b.jsxs)(`div`,{className:`des-form-actions`,children:[(0,b.jsx)(`button`,{type:`button`,className:`des-btn des-btn-secondary`,disabled:N,onClick:Z,children:E(`deviceExecResetDefaults`)}),(0,b.jsx)(`button`,{type:`button`,className:`des-btn des-btn-secondary`,disabled:N,onClick:Q,children:E(`deviceExecReset`)}),(0,b.jsx)(`button`,{type:`submit`,className:`des-btn des-btn-primary`,disabled:N,children:E(N?`deviceExecSaving`:`deviceExecSave`)})]})]}),D&&D.blocked&&D.blocked.length>0&&(0,b.jsxs)(`div`,{className:`des-section des-blocked-section`,children:[(0,b.jsxs)(`h4`,{className:`des-section-title is-danger`,children:[(0,b.jsx)(m,{}),` `,E(`deviceExecBlockedTitle`)]}),(0,b.jsx)(`p`,{className:`des-section-desc`,children:E(`deviceExecBlockedDesc`)}),(0,b.jsx)(`div`,{className:`des-table-wrap`,children:(0,b.jsxs)(`table`,{className:`des-table`,children:[(0,b.jsx)(`thead`,{children:(0,b.jsxs)(`tr`,{children:[(0,b.jsx)(`th`,{children:`Task ID`}),(0,b.jsx)(`th`,{children:`Room ID`}),(0,b.jsx)(`th`,{children:`Bot ID`}),(0,b.jsx)(`th`,{children:E(`deviceExecReason`)})]})}),(0,b.jsx)(`tbody`,{children:D.blocked.map(e=>(0,b.jsxs)(`tr`,{className:`des-row-blocked`,children:[(0,b.jsxs)(`td`,{className:`des-mono`,children:[e.taskId.slice(0,8),`...`]}),(0,b.jsx)(`td`,{children:e.roomId}),(0,b.jsx)(`td`,{children:e.botId}),(0,b.jsx)(`td`,{children:(0,b.jsx)(`span`,{className:`des-badge is-danger`,children:e.reason})})]},`${e.taskId}-${e.attemptId}`))})]})})]}),(0,b.jsxs)(`div`,{className:`des-section`,children:[(0,b.jsxs)(`h4`,{className:`des-section-title`,children:[(0,b.jsx)(g,{}),` `,E(`deviceExecActiveTasks`),` (`,D?.running?.length??0,`)`]}),D&&D.running&&D.running.length>0?(0,b.jsx)(`div`,{className:`des-table-wrap`,children:(0,b.jsxs)(`table`,{className:`des-table`,children:[(0,b.jsx)(`thead`,{children:(0,b.jsxs)(`tr`,{children:[(0,b.jsx)(`th`,{children:`Task ID`}),(0,b.jsx)(`th`,{children:`Room ID`}),(0,b.jsx)(`th`,{children:`Bot ID`}),(0,b.jsx)(`th`,{children:E(`deviceExecQueuedTime`)})]})}),(0,b.jsx)(`tbody`,{children:D.running.map(e=>(0,b.jsxs)(`tr`,{children:[(0,b.jsxs)(`td`,{className:`des-mono`,title:e.taskId,children:[e.taskId.slice(0,8),`...`]}),(0,b.jsx)(`td`,{children:e.roomId}),(0,b.jsx)(`td`,{children:e.botId}),(0,b.jsx)(`td`,{children:new Date(e.startedAt).toLocaleTimeString()})]},`${e.taskId}-${e.attemptId}`))})]})}):(0,b.jsx)(`div`,{className:`des-empty`,children:E(`deviceExecNoActive`)})]}),(0,b.jsxs)(`div`,{className:`des-section`,children:[(0,b.jsxs)(`h4`,{className:`des-section-title`,children:[(0,b.jsx)(h,{}),` `,E(`deviceExecWaitingQueue`),` (`,D?.waiting?.length??0,`)`]}),D&&D.waiting&&D.waiting.length>0?(0,b.jsx)(`div`,{className:`des-table-wrap`,children:(0,b.jsxs)(`table`,{className:`des-table`,children:[(0,b.jsx)(`thead`,{children:(0,b.jsxs)(`tr`,{children:[(0,b.jsx)(`th`,{children:E(`deviceExecPosition`)}),(0,b.jsx)(`th`,{children:`Task ID`}),(0,b.jsx)(`th`,{children:`Room ID`}),(0,b.jsx)(`th`,{children:`Bot ID`}),(0,b.jsx)(`th`,{children:E(`deviceExecReason`)}),(0,b.jsx)(`th`,{children:E(`deviceExecQueuedTime`)}),(0,b.jsx)(`th`,{children:E(`deviceExecActions`)})]})}),(0,b.jsx)(`tbody`,{children:D.waiting.map(e=>(0,b.jsxs)(`tr`,{children:[(0,b.jsx)(`td`,{children:(0,b.jsxs)(`span`,{className:`des-pos-badge`,children:[`#`,e.queuePosition]})}),(0,b.jsxs)(`td`,{className:`des-mono`,title:e.taskId,children:[e.taskId.slice(0,8),`...`]}),(0,b.jsx)(`td`,{children:e.roomId}),(0,b.jsx)(`td`,{children:e.botId}),(0,b.jsx)(`td`,{children:(0,b.jsxs)(`div`,{className:`des-reason-cell`,children:[(0,b.jsx)(`span`,{className:`des-badge des-badge-${e.blockReason}`,children:te(e.blockReason)}),(0,b.jsx)(`span`,{className:`des-reason-detail`,children:e.blockReasonDetail})]})}),(0,b.jsx)(`td`,{children:new Date(e.queuedAt).toLocaleTimeString()}),(0,b.jsx)(`td`,{children:(0,b.jsx)(`button`,{type:`button`,className:`des-btn des-btn-danger-sm`,disabled:F===e.taskId,onClick:()=>void ee(e.taskId,e.attemptId),children:F===e.taskId?E(`deviceExecCancelling`):E(`deviceExecCancel`)})})]},`${e.taskId}-${e.attemptId}`))})]})}):(0,b.jsx)(`div`,{className:`des-empty`,children:E(`deviceExecNoWaiting`)})]})]})}export{E as t};
@@ -0,0 +1 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Bt as t,Dn as n,Gt as r,Nt as i,Ot as a,Tn as o,bn as s,kn as c,un as l}from"./app-globals-KqOVtmp1.js";import{i as u,r as d,t as f}from"./react-CR5VJ85Q.js";import{t as p}from"./shortcut-stack-hhrDyRBn.js";import{gt as ee}from"./index-BawF7ZP5.js";import{r as te,t as ne}from"./group-view-state-CGCzYF8k.js";var m=e(u(),1),h=d(),g=f(),_={zh:{groups:`็พค่Š`,manage:`็ฎก็†ๆˆๅ‘˜`,save:`ไฟๅญ˜่ฎพ็ฝฎ`,create:`ๅปบ็พค`,name:`็พคๅ็งฐ`,devices:`้€‰ๆ‹ฉ Bot๏ผˆ่ฎพๅค‡ไป…ๆ‰ฟ่ฝฝ Bot๏ผ‰`,empty:`่ฟ˜ๆฒกๆœ‰็พค่Š๏ผŒๅˆ›ๅปบไธ€ไธช็พคๅผ€ๅง‹ๅไฝœใ€‚`,choose:`้€‰ๆ‹ฉไธ€ไธช็พค่Š`,open:`ๆ‰“ๅผ€่Šๅคฉ`,online:`ๅœจ็บฟ`,offline:`็ฆป็บฟ`,cancel:`ๅ–ๆถˆ`,loading:`ๅŠ ่ฝฝไธญโ€ฆ`,rebind:`่ฎพๅค‡็ป‘ๅฎšๅทฒๅคฑๆ•ˆๆˆ–ๅทฒ่งฃ้™ค๏ผŒ่ฏทๅœจ่ฎพๅค‡่ฎพ็ฝฎไธญ้‡ๆ–ฐ็ป‘ๅฎšใ€‚`,forbidden:`ๆœฌๆœบ่ฎฟ้—ฎ่ขซๆ‹’็ป๏ผŒ่ฏทๆฃ€ๆŸฅๆœฌๆœบ็™ปๅฝ•็Šถๆ€ไธŽ่ฎฟ้—ฎๆƒ้™ใ€‚`,failed:`่ฏทๆฑ‚ๅคฑ่ดฅ`,searchPlaceholder:`ๆœ็ดข็พคๆˆ–ไปปๅŠกโ€ฆ`,matchedBot:`Bot: `,matchedTask:`ไปปๅŠก: `},en:{groups:`Groups`,manage:`Manage members`,save:`Save settings`,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`,searchPlaceholder:`Search groups or tasksโ€ฆ`,matchedBot:`Bot: `,matchedTask:`Task: `}},v=class extends Error{status;code;constructor(e,t,n){super(n),this.status=e,this.code=t}};async function y(e,t,r){let i=await fetch(n(c(`/api/device-center/${e}`)),{method:r?`POST`:`GET`,credentials:`same-origin`,signal:t,...r?{headers:{"Content-Type":`application/json`},body:JSON.stringify(r)}:{}}),a=await i.json().catch(()=>({}));if(!i.ok)throw new v(i.status,a.code??``,typeof a.error==`string`?a.error:String(i.status));return a}function b(e){window.dispatchEvent(new CustomEvent(`pi-web-ui:device-group-open`,{detail:{roomId:e}}))}function x({onClose:e}){let{locale:t}=s(),n=_[o(t)?`zh`:`en`];return p(()=>{document.querySelector(`dialog[open]`)||e()}),(0,h.createPortal)((0,g.jsx)(`div`,{className:`modal-backdrop`,onClick:e,children:(0,g.jsx)(`div`,{className:`device-group-create-dialog`,role:`dialog`,"aria-modal":`true`,"aria-label":n.create,onClick:e=>e.stopPropagation(),children:(0,g.jsx)(S,{createOnly:!0,onClose:e})})}),document.body)}function S({active:e=!0,navigation:n,createOnly:c=!1,onClose:u}){let{locale:d}=s(),f=_[o(d)?`zh`:`en`],[p,h]=(0,m.useState)([]),[x,S]=(0,m.useState)([]),[C,re]=(0,m.useState)(``),[w,T]=(0,m.useState)(null),[E,D]=(0,m.useState)(!0),[O,k]=(0,m.useState)(``),[ie,A]=(0,m.useState)(!1),[j,M]=(0,m.useState)(c),[N,P]=(0,m.useState)(!1),[ae,F]=(0,m.useState)(!1),[I,L]=(0,m.useState)(``),[R,z]=(0,m.useState)([]),[B,V]=(0,m.useState)(``),[H,U]=(0,m.useState)(!1),[oe,W]=(0,m.useState)(0),[G,se]=(0,m.useState)(``),[ce,le]=(0,m.useState)([]),K=(0,m.useRef)(new ne),q=(0,m.useRef)(null),J=(0,m.useRef)(void 0),Y=(0,m.useRef)(0),X=(0,m.useRef)(null),ue=(0,m.useRef)(f);ue.current=f;function de(e){let t=ue.current;if(e instanceof v){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 Z(){X.current?.abort(),X.current=null,U(!1)}function Q(e,t=!1){++Y.current,Z(),re(e),T(null),M(!1),P(t),A(!1),V(``),q.current=t?e:null,z([]),D(!0),k(``),W(e=>e+1)}function fe(){++Y.current,Z(),M(!0),A(!1),V(``),P(!1),q.current=null,T(null),z([]),L(``),k(``),W(e=>e+1)}(0,m.useEffect)(()=>{let t=++Y.current,n=null,r=!1,i=()=>Y.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([y(`bots`,t.signal),y(`rooms`,t.signal),N&&C?y(`rooms/${encodeURIComponent(C)}`,t.signal):Promise.resolve(null)]);if(!i()||t.signal.aborted)return;if(h(e.bots),S(n.rooms),T(r),r?.tasks){le(r.tasks);for(let e of r.tasks)e.status===`completed`?K.current.onTaskCompleted(e.roomId,e.id):e.status===`failed`&&K.current.onTaskFailed(e.roomId,e.id)}r&&q.current===r.room.id&&(q.current=null,z(r.room.botIds),V(r.room.primaryBotId??``)),k(``)}catch(e){i()&&!t.signal.aborted&&k(de(e))}finally{t.abort(),r=!1,i()&&D(!1)}}a();let o=window.setInterval(()=>void a(),3e3),s=()=>{document.visibilityState===`hidden`?n?.abort():a()};return document.addEventListener(`visibilitychange`,s),()=>{++Y.current,n?.abort(),clearInterval(o),document.removeEventListener(`visibilitychange`,s)}},[e,C,N,oe]),(0,m.useEffect)(()=>()=>X.current?.abort(),[]),(0,m.useEffect)(()=>{e||Z()},[e]),(0,m.useEffect)(()=>{e&&n&&n.revision!==J.current&&(J.current=n.revision,n.create?fe():n.roomId&&Q(n.roomId,n.manage))},[e,n?.revision]);async function pe(){if(!e||X.current||(j?!I.trim():!w))return;let t=new AbortController;X.current=t,U(!0),k(``),A(!1);let n=R.includes(B)?B:``,r=j,i=w?.room.id;try{let{room:e}=await y(r?`rooms`:`rooms/${encodeURIComponent(i)}/members`,t.signal,{...r?{name:I.trim()}:{},botIds:R,...B&&R.includes(B)?{primaryBotId:B}:!r&&w?.room.primaryBotId?{primaryBotId:null}:{}});if(t.signal.aborted||X.current!==t)return;if((e.primaryBotId??``)!==n)throw Error(o(d)?`ไธญๅฟƒๆœชไฟๅญ˜ไธป Bot ่ฎพ็ฝฎ๏ผŒ่ฏทๆ›ดๆ–ฐ็พค็ป„ๆ‰€ๅฑž็š„่ฎพๅค‡ไธญๅฟƒ๏ผˆHub๏ผ‰ๅŽ้‡่ฏ•ใ€‚`:`The Hub did not save the primary Bot setting. Update the group's Hub and retry.`);A(!0),S(t=>[...t.filter(t=>t.id!==e.id),e]),re(e.id),T({room:e}),M(!1),P(!r),L(``),z(r?[]:e.botIds),V(e.primaryBotId??``),W(e=>e+1),window.dispatchEvent(new CustomEvent(`pi-web-ui:device-groups-changed`)),r&&(b(e.id),c&&u?.())}catch(e){!t.signal.aborted&&X.current===t&&k(de(e))}finally{X.current===t&&(X.current=null,U(!1))}}let $=x.find(e=>e.id===C);return(0,g.jsxs)(`section`,{className:`dg-root`,"aria-label":f.groups,children:[!c&&(0,g.jsxs)(`div`,{className:`dc-card dg-sidebar`,children:[(0,g.jsxs)(`div`,{className:`dg-heading`,children:[(0,g.jsxs)(`h2`,{children:[(0,g.jsx)(l,{}),` `,f.groups]}),(0,g.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:fe,children:[(0,g.jsx)(t,{}),` `,f.create]})]}),(0,g.jsx)(`div`,{className:`dg-search-bar`,style:{padding:`0 10px 8px 10px`},children:(0,g.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`6px`,background:`var(--bg)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`4px 8px`},children:[(0,g.jsx)(r,{style:{color:`var(--text-dim)`,flex:`none`}}),(0,g.jsx)(`input`,{type:`search`,value:G,onChange:e=>se(e.target.value),placeholder:f.searchPlaceholder,style:{border:`none`,background:`transparent`,color:`var(--text)`,width:`100%`,fontSize:`12px`,outline:`none`}})]})}),(0,g.jsx)(`div`,{className:`dg-rooms`,children:te(G,x,ce).map(t=>{let n=x.find(e=>e.id===t.roomId);if(!n)return null;let r=K.current.getPendingInteractionsCount(n.id);return(0,g.jsxs)(`button`,{className:`dc-button dg-room`,type:`button`,"aria-current":n.id===C?`page`:void 0,disabled:!e,onClick:()=>{Q(n.id),b(n.id)},children:[(0,g.jsx)(a,{}),(0,g.jsxs)(`span`,{style:{flex:1,minWidth:0,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,textAlign:`left`},children:[n.name,t.matchedBy===`bot_id`&&(0,g.jsxs)(`small`,{style:{display:`block`,color:`var(--text-dim)`,fontSize:`11px`},children:[f.matchedBot,` `,G]}),t.matchedBy===`task_title`&&t.matchedTask&&(0,g.jsxs)(`small`,{style:{display:`block`,color:`var(--accent)`,fontSize:`11px`},children:[f.matchedTask,` `,t.matchedTask.title]}),t.matchedBy===`task_id`&&t.matchedTask&&(0,g.jsxs)(`small`,{style:{display:`block`,color:`var(--text-dim)`,fontSize:`11px`},children:[`ID: `,t.matchedTask.id.slice(0,8)]})]}),r>0&&(0,g.jsx)(`span`,{style:{flex:`none`,background:`var(--accent)`,color:`var(--accent-contrast, #fff)`,borderRadius:`10px`,padding:`1px 6px`,fontSize:`11px`,fontWeight:`bold`},children:r})]},t.matchedTask?`${n.id}:${t.matchedTask.id}`:n.id)})}),!E&&!x.length&&(0,g.jsx)(`p`,{className:`dg-empty`,children:f.empty})]}),(0,g.jsxs)(`div`,{className:`dc-card dg-chat`,children:[ie&&(0,g.jsx)(`p`,{role:`status`,children:o(d)?`ๅทฒไฟๅญ˜ๆˆๅ‘˜ๅ’Œไธป Bot ่ฎพ็ฝฎใ€‚`:`Members and primary Bot settings saved.`}),O&&(0,g.jsx)(`p`,{className:`dc-error`,role:`alert`,children:O}),E&&(0,g.jsx)(`p`,{role:`status`,children:f.loading}),j||N?(0,g.jsxs)(`form`,{className:`dg-create`,onSubmit:e=>{e.preventDefault(),pe()},children:[(0,g.jsx)(`h2`,{children:j?f.create:f.manage}),j&&(0,g.jsxs)(`div`,{className:`dc-field`,children:[(0,g.jsx)(`label`,{htmlFor:`device-group-name`,children:f.name}),(0,g.jsx)(`input`,{id:`device-group-name`,value:I,onChange:e=>L(e.target.value),disabled:H||!e})]}),(0,g.jsxs)(`fieldset`,{disabled:H||!e||N&&!w,children:[(0,g.jsx)(`legend`,{children:f.devices}),p.map(e=>(0,g.jsxs)(`label`,{className:`dg-device`,children:[(0,g.jsx)(`input`,{type:`checkbox`,disabled:!e.enabled&&!R.includes(e.id),checked:R.includes(e.id),onChange:t=>z(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}),(0,g.jsx)(i,{}),(0,g.jsxs)(`span`,{children:[e.name,` ยท `,e.id,` ยท `,e.deviceId,` ยท `,e.online?f.online:f.offline]})]},e.id))]}),(0,g.jsxs)(`div`,{className:`dc-field`,children:[(0,g.jsx)(`label`,{htmlFor:`device-group-primary-bot`,children:o(d)?`ไธป Bot`:`Primary Bot`}),(0,g.jsxs)(`select`,{id:`device-group-primary-bot`,value:R.includes(B)?B:``,disabled:H||!e||N&&!w,onChange:e=>V(e.target.value),children:[(0,g.jsx)(`option`,{value:``,children:o(d)?`ไธ่ฎพ็ฝฎ๏ผˆ้œ€ @ Bot๏ผ‰`:`None (mention a Bot)`}),p.filter(e=>e.enabled&&R.includes(e.id)).map(e=>(0,g.jsxs)(`option`,{value:e.id,children:[e.name,` ยท `,e.id]},e.id))]}),(0,g.jsx)(`p`,{children:o(d)?`ๆœช @ Bot ็š„ๆถˆๆฏ่‡ชๅŠจๅ‘้€็ป™ไธป Botใ€‚`:`Messages without a Bot mention go to the primary Bot.`})]}),(0,g.jsxs)(`div`,{className:`dc-actions`,children:[(0,g.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:H||!e||ae,onClick:()=>F(!0),children:[(0,g.jsx)(t,{}),` `,o(d)?`ๆ–ฐๅปบ Bot`:`Create Bot`]}),(0,g.jsx)(`button`,{className:`dc-button`,type:`submit`,disabled:H||!e||(j?!I.trim():!w),children:j?f.create:f.save}),(0,g.jsx)(`button`,{className:`dc-button`,type:`button`,onClick:()=>{Z(),q.current=null,c&&u?.(),M(!1),P(!1),k(``)},children:f.cancel})]})]}):$?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`div`,{className:`dg-title`,children:(0,g.jsxs)(`h2`,{children:[(0,g.jsx)(l,{}),` `,$.name]})}),(0,g.jsxs)(`div`,{className:`dc-actions`,children:[(0,g.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:()=>b($.id),children:[(0,g.jsx)(a,{}),f.open]}),(0,g.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:()=>Q($.id,!0),children:[(0,g.jsx)(l,{}),f.manage]})]})]}):(0,g.jsx)(`p`,{className:`dg-empty`,children:f.choose})]}),ae&&(0,g.jsx)(ee,{createOnly:!0,onCancel:()=>F(!1),onCreated:(e,t)=>{F(!1),t&&e.enabled?(h(t=>[...t.filter(t=>t.id!==e.id),e]),z(t=>[...new Set([...t,e.id])])):k(o(d)?`Bot ๅทฒไฟๅญ˜๏ผ›่ฏทๅฏ็”จๅนถๅŒๆญฅๅˆฐไธญๅฟƒๅŽ๏ผŒๅ†ๅŠ ๅ…ฅ็พค็ป„ใ€‚`:`Bot saved. Enable and sync it to the hub before adding it to the group.`)}})]})}export{x as DeviceGroupCreateDialog};
@@ -0,0 +1 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Bt as t,Dn as n,Gt as r,Nt as i,Ot as a,Tn as o,bn as s,kn as c,un as l}from"./app-globals-KqOVtmp1.js";import{i as u,r as d,t as f}from"./react-CR5VJ85Q.js";import{t as p}from"./shortcut-stack-hhrDyRBn.js";import{gt as ee}from"./index-BoGCoq5X.js";import{r as te,t as ne}from"./group-view-state-CGCzYF8k.js";var m=e(u(),1),h=d(),g=f(),_={zh:{groups:`็พค่Š`,manage:`็ฎก็†ๆˆๅ‘˜`,save:`ไฟๅญ˜่ฎพ็ฝฎ`,create:`ๅปบ็พค`,name:`็พคๅ็งฐ`,devices:`้€‰ๆ‹ฉ Bot๏ผˆ่ฎพๅค‡ไป…ๆ‰ฟ่ฝฝ Bot๏ผ‰`,empty:`่ฟ˜ๆฒกๆœ‰็พค่Š๏ผŒๅˆ›ๅปบไธ€ไธช็พคๅผ€ๅง‹ๅไฝœใ€‚`,choose:`้€‰ๆ‹ฉไธ€ไธช็พค่Š`,open:`ๆ‰“ๅผ€่Šๅคฉ`,online:`ๅœจ็บฟ`,offline:`็ฆป็บฟ`,cancel:`ๅ–ๆถˆ`,loading:`ๅŠ ่ฝฝไธญโ€ฆ`,rebind:`่ฎพๅค‡็ป‘ๅฎšๅทฒๅคฑๆ•ˆๆˆ–ๅทฒ่งฃ้™ค๏ผŒ่ฏทๅœจ่ฎพๅค‡่ฎพ็ฝฎไธญ้‡ๆ–ฐ็ป‘ๅฎšใ€‚`,forbidden:`ๆœฌๆœบ่ฎฟ้—ฎ่ขซๆ‹’็ป๏ผŒ่ฏทๆฃ€ๆŸฅๆœฌๆœบ็™ปๅฝ•็Šถๆ€ไธŽ่ฎฟ้—ฎๆƒ้™ใ€‚`,failed:`่ฏทๆฑ‚ๅคฑ่ดฅ`,searchPlaceholder:`ๆœ็ดข็พคๆˆ–ไปปๅŠกโ€ฆ`,matchedBot:`Bot: `,matchedTask:`ไปปๅŠก: `},en:{groups:`Groups`,manage:`Manage members`,save:`Save settings`,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`,searchPlaceholder:`Search groups or tasksโ€ฆ`,matchedBot:`Bot: `,matchedTask:`Task: `}},v=class extends Error{status;code;constructor(e,t,n){super(n),this.status=e,this.code=t}};async function y(e,t,r){let i=await fetch(n(c(`/api/device-center/${e}`)),{method:r?`POST`:`GET`,credentials:`same-origin`,signal:t,...r?{headers:{"Content-Type":`application/json`},body:JSON.stringify(r)}:{}}),a=await i.json().catch(()=>({}));if(!i.ok)throw new v(i.status,a.code??``,typeof a.error==`string`?a.error:String(i.status));return a}function b(e){window.dispatchEvent(new CustomEvent(`pi-web-ui:device-group-open`,{detail:{roomId:e}}))}function x({onClose:e}){let{locale:t}=s(),n=_[o(t)?`zh`:`en`];return p(()=>{document.querySelector(`dialog[open]`)||e()}),(0,h.createPortal)((0,g.jsx)(`div`,{className:`modal-backdrop`,onClick:e,children:(0,g.jsx)(`div`,{className:`device-group-create-dialog`,role:`dialog`,"aria-modal":`true`,"aria-label":n.create,onClick:e=>e.stopPropagation(),children:(0,g.jsx)(S,{createOnly:!0,onClose:e})})}),document.body)}function S({active:e=!0,navigation:n,createOnly:c=!1,onClose:u}){let{locale:d}=s(),f=_[o(d)?`zh`:`en`],[p,h]=(0,m.useState)([]),[x,S]=(0,m.useState)([]),[C,re]=(0,m.useState)(``),[w,T]=(0,m.useState)(null),[E,D]=(0,m.useState)(!0),[O,k]=(0,m.useState)(``),[ie,A]=(0,m.useState)(!1),[j,M]=(0,m.useState)(c),[N,P]=(0,m.useState)(!1),[ae,F]=(0,m.useState)(!1),[I,L]=(0,m.useState)(``),[R,z]=(0,m.useState)([]),[B,V]=(0,m.useState)(``),[H,U]=(0,m.useState)(!1),[oe,W]=(0,m.useState)(0),[G,se]=(0,m.useState)(``),[ce,le]=(0,m.useState)([]),K=(0,m.useRef)(new ne),q=(0,m.useRef)(null),J=(0,m.useRef)(void 0),Y=(0,m.useRef)(0),X=(0,m.useRef)(null),ue=(0,m.useRef)(f);ue.current=f;function de(e){let t=ue.current;if(e instanceof v){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 Z(){X.current?.abort(),X.current=null,U(!1)}function Q(e,t=!1){++Y.current,Z(),re(e),T(null),M(!1),P(t),A(!1),V(``),q.current=t?e:null,z([]),D(!0),k(``),W(e=>e+1)}function fe(){++Y.current,Z(),M(!0),A(!1),V(``),P(!1),q.current=null,T(null),z([]),L(``),k(``),W(e=>e+1)}(0,m.useEffect)(()=>{let t=++Y.current,n=null,r=!1,i=()=>Y.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([y(`bots`,t.signal),y(`rooms`,t.signal),N&&C?y(`rooms/${encodeURIComponent(C)}`,t.signal):Promise.resolve(null)]);if(!i()||t.signal.aborted)return;if(h(e.bots),S(n.rooms),T(r),r?.tasks){le(r.tasks);for(let e of r.tasks)e.status===`completed`?K.current.onTaskCompleted(e.roomId,e.id):e.status===`failed`&&K.current.onTaskFailed(e.roomId,e.id)}r&&q.current===r.room.id&&(q.current=null,z(r.room.botIds),V(r.room.primaryBotId??``)),k(``)}catch(e){i()&&!t.signal.aborted&&k(de(e))}finally{t.abort(),r=!1,i()&&D(!1)}}a();let o=window.setInterval(()=>void a(),3e3),s=()=>{document.visibilityState===`hidden`?n?.abort():a()};return document.addEventListener(`visibilitychange`,s),()=>{++Y.current,n?.abort(),clearInterval(o),document.removeEventListener(`visibilitychange`,s)}},[e,C,N,oe]),(0,m.useEffect)(()=>()=>X.current?.abort(),[]),(0,m.useEffect)(()=>{e||Z()},[e]),(0,m.useEffect)(()=>{e&&n&&n.revision!==J.current&&(J.current=n.revision,n.create?fe():n.roomId&&Q(n.roomId,n.manage))},[e,n?.revision]);async function pe(){if(!e||X.current||(j?!I.trim():!w))return;let t=new AbortController;X.current=t,U(!0),k(``),A(!1);let n=R.includes(B)?B:``,r=j,i=w?.room.id;try{let{room:e}=await y(r?`rooms`:`rooms/${encodeURIComponent(i)}/members`,t.signal,{...r?{name:I.trim()}:{},botIds:R,...B&&R.includes(B)?{primaryBotId:B}:!r&&w?.room.primaryBotId?{primaryBotId:null}:{}});if(t.signal.aborted||X.current!==t)return;if((e.primaryBotId??``)!==n)throw Error(o(d)?`ไธญๅฟƒๆœชไฟๅญ˜ไธป Bot ่ฎพ็ฝฎ๏ผŒ่ฏทๆ›ดๆ–ฐ็พค็ป„ๆ‰€ๅฑž็š„่ฎพๅค‡ไธญๅฟƒ๏ผˆHub๏ผ‰ๅŽ้‡่ฏ•ใ€‚`:`The Hub did not save the primary Bot setting. Update the group's Hub and retry.`);A(!0),S(t=>[...t.filter(t=>t.id!==e.id),e]),re(e.id),T({room:e}),M(!1),P(!r),L(``),z(r?[]:e.botIds),V(e.primaryBotId??``),W(e=>e+1),window.dispatchEvent(new CustomEvent(`pi-web-ui:device-groups-changed`)),r&&(b(e.id),c&&u?.())}catch(e){!t.signal.aborted&&X.current===t&&k(de(e))}finally{X.current===t&&(X.current=null,U(!1))}}let $=x.find(e=>e.id===C);return(0,g.jsxs)(`section`,{className:`dg-root`,"aria-label":f.groups,children:[!c&&(0,g.jsxs)(`div`,{className:`dc-card dg-sidebar`,children:[(0,g.jsxs)(`div`,{className:`dg-heading`,children:[(0,g.jsxs)(`h2`,{children:[(0,g.jsx)(l,{}),` `,f.groups]}),(0,g.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:fe,children:[(0,g.jsx)(t,{}),` `,f.create]})]}),(0,g.jsx)(`div`,{className:`dg-search-bar`,style:{padding:`0 10px 8px 10px`},children:(0,g.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`6px`,background:`var(--bg)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`4px 8px`},children:[(0,g.jsx)(r,{style:{color:`var(--text-dim)`,flex:`none`}}),(0,g.jsx)(`input`,{type:`search`,value:G,onChange:e=>se(e.target.value),placeholder:f.searchPlaceholder,style:{border:`none`,background:`transparent`,color:`var(--text)`,width:`100%`,fontSize:`12px`,outline:`none`}})]})}),(0,g.jsx)(`div`,{className:`dg-rooms`,children:te(G,x,ce).map(t=>{let n=x.find(e=>e.id===t.roomId);if(!n)return null;let r=K.current.getPendingInteractionsCount(n.id);return(0,g.jsxs)(`button`,{className:`dc-button dg-room`,type:`button`,"aria-current":n.id===C?`page`:void 0,disabled:!e,onClick:()=>{Q(n.id),b(n.id)},children:[(0,g.jsx)(a,{}),(0,g.jsxs)(`span`,{style:{flex:1,minWidth:0,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,textAlign:`left`},children:[n.name,t.matchedBy===`bot_id`&&(0,g.jsxs)(`small`,{style:{display:`block`,color:`var(--text-dim)`,fontSize:`11px`},children:[f.matchedBot,` `,G]}),t.matchedBy===`task_title`&&t.matchedTask&&(0,g.jsxs)(`small`,{style:{display:`block`,color:`var(--accent)`,fontSize:`11px`},children:[f.matchedTask,` `,t.matchedTask.title]}),t.matchedBy===`task_id`&&t.matchedTask&&(0,g.jsxs)(`small`,{style:{display:`block`,color:`var(--text-dim)`,fontSize:`11px`},children:[`ID: `,t.matchedTask.id.slice(0,8)]})]}),r>0&&(0,g.jsx)(`span`,{style:{flex:`none`,background:`var(--accent)`,color:`var(--accent-contrast, #fff)`,borderRadius:`10px`,padding:`1px 6px`,fontSize:`11px`,fontWeight:`bold`},children:r})]},t.matchedTask?`${n.id}:${t.matchedTask.id}`:n.id)})}),!E&&!x.length&&(0,g.jsx)(`p`,{className:`dg-empty`,children:f.empty})]}),(0,g.jsxs)(`div`,{className:`dc-card dg-chat`,children:[ie&&(0,g.jsx)(`p`,{role:`status`,children:o(d)?`ๅทฒไฟๅญ˜ๆˆๅ‘˜ๅ’Œไธป Bot ่ฎพ็ฝฎใ€‚`:`Members and primary Bot settings saved.`}),O&&(0,g.jsx)(`p`,{className:`dc-error`,role:`alert`,children:O}),E&&(0,g.jsx)(`p`,{role:`status`,children:f.loading}),j||N?(0,g.jsxs)(`form`,{className:`dg-create`,onSubmit:e=>{e.preventDefault(),pe()},children:[(0,g.jsx)(`h2`,{children:j?f.create:f.manage}),j&&(0,g.jsxs)(`div`,{className:`dc-field`,children:[(0,g.jsx)(`label`,{htmlFor:`device-group-name`,children:f.name}),(0,g.jsx)(`input`,{id:`device-group-name`,value:I,onChange:e=>L(e.target.value),disabled:H||!e})]}),(0,g.jsxs)(`fieldset`,{disabled:H||!e||N&&!w,children:[(0,g.jsx)(`legend`,{children:f.devices}),p.map(e=>(0,g.jsxs)(`label`,{className:`dg-device`,children:[(0,g.jsx)(`input`,{type:`checkbox`,disabled:!e.enabled&&!R.includes(e.id),checked:R.includes(e.id),onChange:t=>z(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}),(0,g.jsx)(i,{}),(0,g.jsxs)(`span`,{children:[e.name,` ยท `,e.id,` ยท `,e.deviceId,` ยท `,e.online?f.online:f.offline]})]},e.id))]}),(0,g.jsxs)(`div`,{className:`dc-field`,children:[(0,g.jsx)(`label`,{htmlFor:`device-group-primary-bot`,children:o(d)?`ไธป Bot`:`Primary Bot`}),(0,g.jsxs)(`select`,{id:`device-group-primary-bot`,value:R.includes(B)?B:``,disabled:H||!e||N&&!w,onChange:e=>V(e.target.value),children:[(0,g.jsx)(`option`,{value:``,children:o(d)?`ไธ่ฎพ็ฝฎ๏ผˆ้œ€ @ Bot๏ผ‰`:`None (mention a Bot)`}),p.filter(e=>e.enabled&&R.includes(e.id)).map(e=>(0,g.jsxs)(`option`,{value:e.id,children:[e.name,` ยท `,e.id]},e.id))]}),(0,g.jsx)(`p`,{children:o(d)?`ๆœช @ Bot ็š„ๆถˆๆฏ่‡ชๅŠจๅ‘้€็ป™ไธป Botใ€‚`:`Messages without a Bot mention go to the primary Bot.`})]}),(0,g.jsxs)(`div`,{className:`dc-actions`,children:[(0,g.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:H||!e||ae,onClick:()=>F(!0),children:[(0,g.jsx)(t,{}),` `,o(d)?`ๆ–ฐๅปบ Bot`:`Create Bot`]}),(0,g.jsx)(`button`,{className:`dc-button`,type:`submit`,disabled:H||!e||(j?!I.trim():!w),children:j?f.create:f.save}),(0,g.jsx)(`button`,{className:`dc-button`,type:`button`,onClick:()=>{Z(),q.current=null,c&&u?.(),M(!1),P(!1),k(``)},children:f.cancel})]})]}):$?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`div`,{className:`dg-title`,children:(0,g.jsxs)(`h2`,{children:[(0,g.jsx)(l,{}),` `,$.name]})}),(0,g.jsxs)(`div`,{className:`dc-actions`,children:[(0,g.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:()=>b($.id),children:[(0,g.jsx)(a,{}),f.open]}),(0,g.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:()=>Q($.id,!0),children:[(0,g.jsx)(l,{}),f.manage]})]})]}):(0,g.jsx)(`p`,{className:`dg-empty`,children:f.choose})]}),ae&&(0,g.jsx)(ee,{createOnly:!0,onCancel:()=>F(!1),onCreated:(e,t)=>{F(!1),t&&e.enabled?(h(t=>[...t.filter(t=>t.id!==e.id),e]),z(t=>[...new Set([...t,e.id])])):k(o(d)?`Bot ๅทฒไฟๅญ˜๏ผ›่ฏทๅฏ็”จๅนถๅŒๆญฅๅˆฐไธญๅฟƒๅŽ๏ผŒๅ†ๅŠ ๅ…ฅ็พค็ป„ใ€‚`:`Bot saved. Enable and sync it to the hub before adding it to the group.`)}})]})}export{x as DeviceGroupCreateDialog};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{j as t}from"./app-globals-DZNa9v8u.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};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{N as t}from"./app-globals-KqOVtmp1.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{$ as t,A as n,At as r,B as i,Dn as a,Q as ee,Sn as te,U as ne,Ut as re,X as ie,bt as ae,et as oe,fn as se,hn as ce,kn as le,mn as ue,t as de,wt as fe,xt as pe}from"./app-globals-KqOVtmp1.js";import{i as o,t as s}from"./react-CR5VJ85Q.js";import{G as me,H as he,ft as ge,st as _e,ut as ve}from"./index-BawF7ZP5.js";var c=e(o(),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=s(),p=5e3,be=`pi-web-ui:preview-toc`;function m({file:e,content:o,onAddLines:s,onAttach:l,onClose:u,uiFilePreviewToolbar:m,onUiAction:xe}){let v=te(),[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),de({type:`read_file`,path:e.path})},[e.path]),(0,c.useEffect)(()=>{o&&o.path===e.path&&(Se(o),C||E(o.text),Ce(!1),V.current&&(V.current=!1,H.current&&clearTimeout(H.current),z(!1),B(!1),w(!1),E(o.text),M.current&&(h(e.name)&&O(!0),_(e.name)&&A(!0)),S(null)))},[o,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&&(s(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&&de({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)(oe,{}):(0,f.jsx)(i,{})}):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)(pe,{})}):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)(i,{}):(0,f.jsx)(oe,{})}):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)(ee,{})}):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)(ne,{})}):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)(ce,{})}),(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)(ue,{})})]}):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)(ie,{})}),"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)(ae,{})}),"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)(r,{}):(0,f.jsx)(fe,{})}),"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=>a(le(`/api/file?clientId=${encodeURIComponent(me())}&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 a(le(`${n}?clientId=${encodeURIComponent(me())}${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&&` ยท ${_e(y.size)}`]}),(0,f.jsx)(`span`,{className:`fp-head-actions`,children:he($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)(se,{})})]}),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:_e(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)(t,{}),(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)(ge,{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)(re,{}),` `,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)(n,{}):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{$ as t,A as n,At as r,B as i,Dn as a,Q as ee,Sn as te,U as ne,Ut as re,X as ie,bt as ae,et as oe,fn as se,hn as ce,kn as le,mn as ue,t as de,wt as fe,xt as pe}from"./app-globals-KqOVtmp1.js";import{i as o,t as s}from"./react-CR5VJ85Q.js";import{G as me,H as he,ft as ge,st as _e,ut as ve}from"./index-BoGCoq5X.js";var c=e(o(),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=s(),p=5e3,be=`pi-web-ui:preview-toc`;function m({file:e,content:o,onAddLines:s,onAttach:l,onClose:u,uiFilePreviewToolbar:m,onUiAction:xe}){let v=te(),[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),de({type:`read_file`,path:e.path})},[e.path]),(0,c.useEffect)(()=>{o&&o.path===e.path&&(Se(o),C||E(o.text),Ce(!1),V.current&&(V.current=!1,H.current&&clearTimeout(H.current),z(!1),B(!1),w(!1),E(o.text),M.current&&(h(e.name)&&O(!0),_(e.name)&&A(!0)),S(null)))},[o,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&&(s(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&&de({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)(oe,{}):(0,f.jsx)(i,{})}):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)(pe,{})}):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)(i,{}):(0,f.jsx)(oe,{})}):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)(ee,{})}):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)(ne,{})}):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)(ce,{})}),(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)(ue,{})})]}):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)(ie,{})}),"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)(ae,{})}),"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)(r,{}):(0,f.jsx)(fe,{})}),"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=>a(le(`/api/file?clientId=${encodeURIComponent(me())}&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 a(le(`${n}?clientId=${encodeURIComponent(me())}${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&&` ยท ${_e(y.size)}`]}),(0,f.jsx)(`span`,{className:`fp-head-actions`,children:he($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)(se,{})})]}),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:_e(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)(t,{}),(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)(ge,{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)(re,{}),` `,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)(n,{}):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};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Mt as t,Tt as n,Vt as r,_n as i,i as a,it as o,o as s,rt as c,sn as l,t as u}from"./app-globals-DZNa9v8u.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-C8mNgghx.js";import{F as _}from"./index-DHeeHS_l.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=i(),D=s(),O=E(`pluginMenuTitle`),k=a(`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)(l,{})})]}),(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)(n,{})),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)(o,{})),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)(c,{})),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)(t,{})),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};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Gt as t,It as n,Ot as r,Sn as i,at as a,fn as o,i as s,o as c,ot as l,t as u}from"./app-globals-KqOVtmp1.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-Dn8Dd6SC.js";import{P as _}from"./index-BawF7ZP5.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=i(),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)(t,{}),(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)(r,{})),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)(a,{})),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};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Mt as t,Tt as n,Vt as r,_n as i,i as a,it as o,o as s,rt as c,sn as l,t as u}from"./app-globals-DZNa9v8u.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-C8mNgghx.js";import{F as _}from"./index-DTZch8uz.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=i(),D=s(),O=E(`pluginMenuTitle`),k=a(`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)(l,{})})]}),(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)(n,{})),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)(o,{})),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)(c,{})),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)(t,{})),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};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Gt as t,It as n,Ot as r,Sn as i,at as a,fn as o,i as s,o as c,ot as l,t as u}from"./app-globals-KqOVtmp1.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-Dn8Dd6SC.js";import{P as _}from"./index-BoGCoq5X.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=i(),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)(t,{}),(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)(r,{})),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)(a,{})),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};