pi-web-ui 0.119.0 → 0.120.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 (136) hide show
  1. package/CHANGELOG.md +79 -0
  2. package/bin/hub-upgrade.mjs +33 -15
  3. package/bin/lib/atomic-file.mjs +90 -0
  4. package/dist/server/agent-service-daemon.js +44 -10
  5. package/dist/server/agent-service.js +803 -106
  6. package/dist/server/atomic-file.js +130 -5
  7. package/dist/server/bash-timeout.js +15 -0
  8. package/dist/server/bash-tool.js +68 -4
  9. package/dist/server/bg-servers.js +19 -13
  10. package/dist/server/canvas/canvas-dispatch.js +12 -1
  11. package/dist/server/client-state.js +56 -14
  12. package/dist/server/conversation-tool.js +3 -2
  13. package/dist/server/delegate-task.js +8 -8
  14. package/dist/server/device-center/group-router-runtime.js +2 -0
  15. package/dist/server/device-center/hub-upgrade.js +5 -10
  16. package/dist/server/dispatch-domain-handlers.js +96 -22
  17. package/dist/server/dispatch-plugin-handlers.js +10 -0
  18. package/dist/server/dsh/dsh-agent-service.js +9 -9
  19. package/dist/server/durable/durable-agent-service.js +1 -1
  20. package/dist/server/files-service.js +41 -19
  21. package/dist/server/fs-copy.js +93 -0
  22. package/dist/server/goal-review-gate.js +2 -2
  23. package/dist/server/index.js +15 -0
  24. package/dist/server/job-runner.js +345 -0
  25. package/dist/server/marker-service.js +42 -26
  26. package/dist/server/model-session.js +16 -0
  27. package/dist/server/phone-tool.js +167 -0
  28. package/dist/server/plan-mode.js +2 -2
  29. package/dist/server/plugin-api-catalog.js +1 -1
  30. package/dist/server/plugin-bundled.js +35 -28
  31. package/dist/server/plugin-installer.js +15 -0
  32. package/dist/server/plugin-manifest-validate.js +10 -0
  33. package/dist/server/plugin-materialize.js +161 -0
  34. package/dist/server/plugin-paths.js +60 -0
  35. package/dist/server/plugin-removal.js +16 -3
  36. package/dist/server/plugin-schedule.js +8 -7
  37. package/dist/server/plugin-secrets.js +7 -3
  38. package/dist/server/plugin-updater.js +2 -4
  39. package/dist/server/plugins.js +74 -38
  40. package/dist/server/preset-fields.js +9 -9
  41. package/dist/server/process-utils.js +11 -0
  42. package/dist/server/project-scripts.js +38 -0
  43. package/dist/server/prompt-composer.js +40 -21
  44. package/dist/server/protocol-version.js +1 -1
  45. package/dist/server/quick-ask.js +3 -0
  46. package/dist/server/remote-ssh-service.js +39 -0
  47. package/dist/server/scm-commitmsg.js +2 -1
  48. package/dist/server/serialize.js +8 -0
  49. package/dist/server/session-list-index.js +246 -0
  50. package/dist/server/session-list-scan.js +5 -0
  51. package/dist/server/session-parser.js +16 -0
  52. package/dist/server/settings-service.js +39 -6
  53. package/dist/server/subagent-budget.js +68 -0
  54. package/dist/server/subagent-evidence.js +297 -0
  55. package/dist/server/subagent-helpers.js +12 -0
  56. package/dist/server/subagent-ledger.js +401 -0
  57. package/dist/server/subagent-notify.js +6 -2
  58. package/dist/server/subagent-security-gate.js +2 -2
  59. package/dist/server/subagent-settle.js +71 -0
  60. package/dist/server/subagents.js +497 -79
  61. package/dist/server/tabs.js +8 -1
  62. package/dist/server/terminals.js +0 -1
  63. package/dist/server/tool-manager.js +90 -16
  64. package/dist/server/tool-prompts.js +5 -1
  65. package/dist/server/universal/universal-service.js +1 -1
  66. package/dist/server/universal/universal-session.js +45 -7
  67. package/dist/server/vision-bridge.js +2 -0
  68. package/dist/server/workspace-handle.js +119 -17
  69. package/dist/server/workspace-queue.js +37 -0
  70. package/docs/README.md +25 -23
  71. package/docs/architecture-plugins.md +23 -3
  72. package/docs/device-center.md +1 -1
  73. package/package.json +15 -3
  74. package/plugins/catalog.json +13 -2
  75. package/themes/bases/flow-base.css +7 -16
  76. package/web/dist/.build-assets.json +1 -1
  77. package/web/dist/assets/BgTasksModal-BdOJ19Hj.js +1 -0
  78. package/web/dist/assets/BgTasksModal-SAH2XCkY.js +1 -0
  79. package/web/dist/assets/{CanvasStudio-2ydYbnpW.js → CanvasStudio-BB_Iq7pl.js} +3 -3
  80. package/web/dist/assets/{CanvasStudio-DizWvRjn.js → CanvasStudio-DU6O3N4u.js} +3 -3
  81. package/web/dist/assets/DeviceCenter-By1zVTSY.js +3 -0
  82. package/web/dist/assets/DeviceCenter-Cnm0Tjrx.js +3 -0
  83. package/web/dist/assets/{DeviceExecutionSettings-B7R9ONaq.js → DeviceExecutionSettings-qJzbI0Cf.js} +1 -1
  84. package/web/dist/assets/{DeviceGroups-DFU4cv5b.js → DeviceGroups-DPrQxW6B.js} +1 -1
  85. package/web/dist/assets/{DeviceGroups-DoaQcxKj.js → DeviceGroups-DoucyUjI.js} +1 -1
  86. package/web/dist/assets/{Dropdown-Btjt6Dzh.js → Dropdown-kj_NIj6e.js} +1 -1
  87. package/web/dist/assets/FilePreview-Bub8Y9uq.js +2 -0
  88. package/web/dist/assets/FilePreview-CC76Z6an.js +2 -0
  89. package/web/dist/assets/GlobalSearchModal-01nkgw4X.js +1 -0
  90. package/web/dist/assets/GlobalSearchModal-CiT6wBmR.js +1 -0
  91. package/web/dist/assets/{GroupConversation-DwZZrMuE.js → GroupConversation-1-lsPO1f.js} +3 -3
  92. package/web/dist/assets/{GroupConversation-KOi8sa5b.js → GroupConversation-HeiyW_O_.js} +3 -3
  93. package/web/dist/assets/{GroupWorkItems-FqAL74bC.js → GroupWorkItems-BYJv2XFj.js} +1 -1
  94. package/web/dist/assets/{HintTip-BOwPzBGR.js → HintTip-DFhoclDw.js} +1 -1
  95. package/web/dist/assets/{ModelConfigModal-DLIfWKdB.js → ModelConfigModal-D2Ro-jUZ.js} +2 -2
  96. package/web/dist/assets/{ModelConfigModal-B140kWrs.js → ModelConfigModal-DPc9R1pq.js} +2 -2
  97. package/web/dist/assets/{NativeCliPanel-BwiLazSq.js → NativeCliPanel-B108d697.js} +3 -3
  98. package/web/dist/assets/{NativeCliPanel-U0F_EfAU.js → NativeCliPanel-DupvGwQM.js} +3 -3
  99. package/web/dist/assets/{PiSetupModal-Dc7EQ4L3.js → PiSetupModal-D0HitBfd.js} +1 -1
  100. package/web/dist/assets/{ProviderOAuthControls-C3opmPhu.js → ProviderOAuthControls-BLKUEDde.js} +1 -1
  101. package/web/dist/assets/{SCMPanel-BBxQfmq9.js → SCMPanel-DDbWrUHR.js} +1 -1
  102. package/web/dist/assets/{SCMPanel-D2t97Vvr.js → SCMPanel-DluNcd2-.js} +1 -1
  103. package/web/dist/assets/SettingsModal-Cy5lRC97.css +1 -0
  104. package/web/dist/assets/SettingsModal-DQu18366.js +33 -0
  105. package/web/dist/assets/SettingsModal-Dm_haPme.js +33 -0
  106. package/web/dist/assets/{TermXterm-B6nCtO2b.js → TermXterm-SYc-MUk2.js} +1 -1
  107. package/web/dist/assets/{TerminalPanel-BWB3iSeN.js → TerminalPanel-CgA_lhVT.js} +1 -1
  108. package/web/dist/assets/{TerminalPanel-CAV2SosY.js → TerminalPanel-vdSIOPjD.js} +1 -1
  109. package/web/dist/assets/{TuiOverlayModal-B0jBPOMc.js → TuiOverlayModal-Cy1jYYIw.js} +1 -1
  110. package/web/dist/assets/{TuiOverlayModal-DGd6fzU6.js → TuiOverlayModal-kXY_4hV8.js} +1 -1
  111. package/web/dist/assets/{app-globals-CR8Ls9nE.js → app-globals-CBEscsYP.js} +9 -9
  112. package/web/dist/assets/{canvas-client-B0lkqTtF.js → canvas-client-Clsypfs6.js} +1 -1
  113. package/web/dist/assets/{desktop-BME3DkyE.js → desktop-C6D9a8HZ.js} +1 -1
  114. package/web/dist/assets/index-BD29OL9L.js +404 -0
  115. package/web/dist/assets/index-BlCxbqqr.js +404 -0
  116. package/web/dist/assets/index-DB55rbKC.css +1 -0
  117. package/web/dist/assets/{plugin-host-CVgcdBOk.js → plugin-host-VWBcq-LQ.js} +1 -1
  118. package/web/dist/assets/remote-ssh-client-C2eab5Kw.js +1 -0
  119. package/web/dist/assets/theme-CpQk_Agp.js +1 -0
  120. package/web/dist/index.html +10 -10
  121. package/web/dist/sw.js +1 -1
  122. package/web/dist/assets/BgTasksModal-CVHW1lRA.js +0 -1
  123. package/web/dist/assets/BgTasksModal-t5hxW1H6.js +0 -1
  124. package/web/dist/assets/DeviceCenter-CPaZNBJE.js +0 -3
  125. package/web/dist/assets/DeviceCenter-DsVakAYR.js +0 -3
  126. package/web/dist/assets/FilePreview-QGQfD2lV.js +0 -2
  127. package/web/dist/assets/FilePreview-qez9walH.js +0 -2
  128. package/web/dist/assets/GlobalSearchModal-B-cnTDJ5.js +0 -1
  129. package/web/dist/assets/GlobalSearchModal-BvbafjdU.js +0 -1
  130. package/web/dist/assets/SettingsModal-BqPQNUwF.js +0 -34
  131. package/web/dist/assets/SettingsModal-l7eeV-Rq.js +0 -34
  132. package/web/dist/assets/index-BBAQNi6v.js +0 -404
  133. package/web/dist/assets/index-BYW9d61A.js +0 -404
  134. package/web/dist/assets/index-BYWs88H2.css +0 -1
  135. package/web/dist/assets/remote-ssh-client-DEpvwgqG.js +0 -1
  136. package/web/dist/assets/theme-DVa7Z5Zu.js +0 -1
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Fn as t}from"./app-globals-CR8Ls9nE.js";import{i as n}from"./react-CR5VJ85Q.js";import{t as r}from"./uuid-BzDIGCwP.js";import{r as i}from"./desktop-BME3DkyE.js";import{o as a,t as o}from"./composer-bridge-CImnjDHq.js";var s=e(n(),1),c=`pi-web-ui:cost-currency`,l=null,u=0,d=new Set;function f(){u+=1;for(let e of[...d])try{e()}catch{}}function p(e){return d.add(e),()=>{d.delete(e)}}function m(){return u}function h(e){return!Number.isFinite(e)||e<=0?`0`:e<1e-4?`<0.0001`:e.toFixed(4).replace(/\.?0+$/,``)}function g(){try{if(typeof localStorage<`u`){let e=localStorage.getItem(c);if(typeof e==`string`&&e.trim().length>0)return e.trim().slice(0,8)}}catch{}return`$`}function ee(e){try{if(typeof localStorage<`u`){let t=typeof e==`string`?e.trim().slice(0,8):``;!t||t===`$`?localStorage.removeItem(c):localStorage.setItem(c,t)}}catch{}f()}function te(e){return typeof e==`function`?(l=e,f(),()=>{l===e&&(l=null,f())}):(l=null,f(),()=>{})}function ne(e,t){let n=String(e??``).trim();if(!n)return{symbol:t,value:`0`};let r=n.match(/^([^\d<>+-]+)\s*(.+)$/);return r?{symbol:r[1],value:r[2]}:{symbol:``,value:n}}function _(e,t){let n=typeof e==`number`&&Number.isFinite(e)?e:0,r=g(),i=typeof t?.fixedDigits==`number`?n.toFixed(t.fixedDigits):h(n);if(l)try{let e=l(n,{defaultSymbol:r,defaultValue:i});if(typeof e==`string`)return ne(e,r);if(e&&typeof e==`object`&&typeof e.value==`string`)return{symbol:typeof e.symbol==`string`?e.symbol:r,value:e.value,tooltip:typeof e.tooltip==`string`?e.tooltip:void 0}}catch(e){console.error(`[cost-format] custom cost formatter threw:`,e)}return{symbol:r,value:i}}function re(e,t){return(0,s.useSyncExternalStore)(p,m,m),_(e,t)}var v=null;function ie(e){v=e?.open??null,e?.close,e?.isOpen}function y(e){return!v||!e?.src?!1:(v(e),!0)}var b=[{id:`builtin`,label:`系统语音`,labelEn:`System speech`}],x=new Set,S,C;async function w(e){let t=await e.json().catch(()=>({}));return Error(t.error||`TTS HTTP ${e.status}`)}function T(){return S||=(async()=>{let e=await fetch(t(`/api/tts/engines`));if(!e.ok)throw await w(e);b=(await e.json()).engines;for(let e of x)e()})().finally(()=>{S=void 0}),S}function ae(){return[...b]}function oe(e){if(e)return{...b.find(t=>t.id===e)||{id:e,label:e},getVoices:async()=>{let n=await fetch(t(`/api/tts/voices?engine=${encodeURIComponent(e)}`));if(!n.ok)throw await w(n);return(await n.json()).voices.map(e=>({voiceURI:e.id,name:e.label,lang:e.lang}))},play:({text:n,rate:r,voiceURI:i,onStart:a,onEnd:o,onError:s})=>{let c=new AbortController,l,u,d=!1,f=()=>{c.abort(),l&&(l.pause(),l.removeAttribute(`src`),l.load()),u&&=(URL.revokeObjectURL(u),void 0)},p=e=>{d||(d=!0,f(),e?s?.(e):o?.())};return(async()=>{try{let o=await fetch(t(`/api/tts/synthesize`),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:n,engine:e,voice:i||``,rate:r}),signal:c.signal});if(!o.ok)throw await w(o);let s=await o.blob();if(d)return;u=URL.createObjectURL(s),l=new Audio(u),l.onplay=()=>{d||a?.()},l.onended=()=>p(),l.onerror=()=>p(Error(`语音播放失败`)),await l.play()}catch(e){d||p(e)}})(),()=>{d||(d=!0,f())}}}}function se(e){return x.add(e),T().catch(()=>{}),C||=setInterval(()=>{T().catch(()=>{})},15e3),()=>{x.delete(e),!x.size&&C&&(clearInterval(C),C=void 0)}}var E=new Map,D=new Set,O=[],k=null;function A(){O=[...E.values()].map(e=>e.provider);for(let e of D)e()}function ce(e,t=null){let n=String(e?.id??``).trim();if(!n||typeof e?.recognize!=`function`||t&&k&&!k.has(t))return()=>{};let r={provider:{...e,id:n},owner:t};return E.set(n,r),A(),()=>{E.get(n)===r&&(E.delete(n),A())}}function le(){return O}function ue(e){return D.add(e),()=>{D.delete(e)}}function de(e){k=e;for(let t of E.values())t.owner&&!e.has(t.owner)&&j(t.owner)}function j(e){let t=!1;for(let[n,r]of E)(e===void 0||r.owner===e)&&(E.delete(n),t=!0);t&&A()}var M=new Map,fe=0;function pe(e){M.get(e.requestId)?.(e.ok&&e.conversationId?e.conversationId:null)}function N(e,t,n){let r=`host-new-chat-${Date.now()}-${++fe}`;return new Promise(i=>{let a=e=>{clearTimeout(o),M.delete(r),i(e)},o=setTimeout(()=>a(null),n);M.set(r,a);try{e(t(r))||a(null)}catch{a(null)}})}function P(e,t=8e3){return N(e,e=>({type:`new_chat`,requestId:e}),t)}function me(e,t,n,r=n?.trim().startsWith(`ssh://`)?12e4:3e4){return N(e,e=>({type:`new_cli_chat`,config:t,cwd:n,requestId:e}),r)}var F=`__piWebUiHost`,I=e=>new Promise(t=>setTimeout(t,e));async function he(e=3e3){let t=Date.now()+e;for(;;){let e=window.__piBridge;if(e&&typeof e.call==`function`)return e;if(Date.now()>=t)return null;await I(100)}}var L=Promise.resolve(),R=0;function ge(e){let t=Math.max(1,Number(e.pollMs??100)),n=Math.max(t,Number(e.timeoutMs??8e3)),s=async e=>{let r=Date.now()+n;for(;;){if(e())return!0;if(Date.now()>=r)return e();await I(t)}},c=()=>{try{let t=e.listModels?.()??[];return Array.isArray(t)?[...t]:[]}catch{return[]}},l=e=>{if(!e)return!0;try{return c().some(t=>t&&t.id===e)}catch{return!1}},u=async t=>{t&&(e.send({type:`set_model`,modelId:t}),typeof e.getCurrentModelId==`function`&&await s(()=>e.getCurrentModelId?.()===t))},d=async(t,r)=>{let i=String(r.cwd??``).trim();if(i&&e.getCwd()!==i&&(!e.send({type:`set_cwd`,path:i})||!await s(()=>e.getCwd()===i))||!e.isReady())return!1;let a=r.newChat===!1?e.getConversationId():await P(e.send,n);if(r.newChat!==!1&&a&&!await s(()=>e.getConversationId()===a)||!a||!e.isReady())return!1;let o=String(r.model??``).trim();return o&&await u(o),!e.isReady()||e.getConversationId()!==a||i&&e.getCwd()!==i?!1:(e.setView(`chat`),e.send({type:`prompt`,text:t,targetConversationId:a}))};return{version:18,setView(t){let n=String(t??``).trim();n&&e.setView(n)},startChat(t){let n=String(t?.prompt??``).trim();if(!n||!e.isReady())return!1;let r=String(t?.model??``).trim();if(r&&!l(r))return!1;let i=async()=>{let e=!1;try{e=await d(n,t??{prompt:n})}finally{try{t?.onResult?.(e)}catch{}}},a;return a=R>0?L.then(i):i(),R++,L=a.then(()=>{R--},()=>{R--}),a.catch(()=>{}),!0},models:{list:()=>c(),active:()=>e.getCurrentModelId?.()??null,onChange:e=>Me(e)},compose(e){return a()?o({text:typeof e?.text==`string`?e.text:void 0,attachments:Array.isArray(e?.attachments)?e.attachments:void 0}):!1},openModal(t){let n=String(t??``).trim();if(!n||typeof e.openModal!=`function`)return!1;try{return e.openModal(n)}catch{return!1}},setFooterStatus(t,n){if(typeof e.setFooterStatus!=`function`)return!1;try{return e.setFooterStatus(String(t??``),n)}catch{return!1}},closeModal(){if(typeof e.closeModal!=`function`)return!0;try{e.closeModal()}catch{}return!0},async openSession(t){let r=V,i=Array.isArray(t?.folders)?t.folders.filter(e=>typeof e==`string`&&e.trim().length>0).map(e=>e.trim()):[],a=Array.isArray(t?.roots)?t.roots.filter(e=>typeof e==`string`&&e.trim().length>0).map(e=>e.trim()):[],o=String(t?.cwd??``).trim(),c=[...new Set([...i,...a])],d=o||c[0]||``;if(!d)return{ok:!1,error:`openSession 需要 cwd / folders / roots(绝对路径)`};if(!e.isReady())return{ok:!1,error:`尚未连接到服务器(还没有快照)`};let f=c.filter(e=>e!==d).slice(0,7),p=new Set([...e.listProjects?.()??[],...e.grantedPaths?.(r)??[]]);for(let t of[d,...f])if(!p.has(t)){if(!(e.confirm&&await e.confirm({path:t}).catch(()=>!1)))return{ok:!1,error:`用户拒绝了该目录的访问:${t}`};e.grantPath?.(t,r)}if(e.getCwd()!==d&&(e.send({type:`set_cwd`,path:d}),!await s(()=>e.getCwd()===d)))return{ok:!1,error:`切换工作目录失败或超时:${d}`};(f.length>0||e.getWorkspaceRoots().length>0)&&e.send({type:`set_workspace_roots`,roots:f});let m=e.getConversationId()??void 0;if(t?.newChat!==!1&&(m=await P(e.send,n)??void 0,!m||!await s(()=>e.getConversationId()===m)))return{ok:!1,error:`Conversation creation failed or timed out`};let h=String(t?.model??``).trim();if(h){if(!l(h))return{ok:!1,error:`未知模型:${h}(先调 models.list() 取可用列表)`};if(await u(h),e.getConversationId()!==m)return{ok:!1,error:`Conversation changed`}}let g=String(t?.prompt??``).trim();return!m||!e.isReady()?{ok:!1,error:`Conversation unavailable`}:(g&&(e.setView(`chat`),e.send({type:`prompt`,text:g,targetConversationId:m})),{ok:!0,...m?{sessionId:m}:{}})},sessions:{list:()=>e.listSessions(),async open(t){let n=V,r=String(t??``).trim();if(!r)return{ok:!1,error:`sessions.open 需要一个会话 id(先调 list)`};if(!e.isReady())return{ok:!1,error:`尚未连接到服务器(还没有快照)`};let i=e.listSessions().find(e=>e.id===r);if(!i)return{ok:!1,error:`找不到会话:${r}`};if(i.cwd&&i.cwd!==e.getCwd()){if(!new Set([...e.listProjects?.()??[],...e.grantedPaths?.(n)??[]]).has(i.cwd)){if(!(e.confirm&&await e.confirm({path:i.cwd}).catch(()=>!1)))return{ok:!1,error:`用户拒绝了该目录的访问:${i.cwd}`};e.grantPath?.(i.cwd,n)}if(e.send({type:`set_cwd`,path:i.cwd}),!await s(()=>e.getCwd()===i.cwd))return{ok:!1,error:`切换工作目录失败或超时:${i.cwd}`}}let a=e.getConversationId();return i.kind===`elsewhere`&&i.owner?(e.send({type:i.independent===!1?`open_shared_conversation`:`take_over_conversation`,owner:i.owner,id:i.conversationId??i.id}),await s(()=>e.getConversationId()===(i.conversationId??i.id)&&(i.independent!==!1||e.getConversationOwner?.()===i.owner))?{ok:!0,sessionId:e.getConversationId()??void 0}:{ok:!1,error:`打开并接入会话超时:${i.title}`}):(i.kind===`running`?e.send({type:`switch_conversation`,id:i.id}):e.send({type:`switch_session`,path:i.id}),await s(()=>i.kind===`running`?e.getConversationId()===i.id&&!e.getConversationOwner?.():e.getConversationId()!==a)?{ok:!0,sessionId:e.getConversationId()??void 0}:{ok:!1,error:`切换会话超时:${i.title}`})}},async reloadCatalog(t,n){let i=String(t??``).trim();if(!i)return{ok:!1,error:`reloadCatalog 需要一个目录来源(http(s) URL 或本地文件路径)`};if(!e.isReady())return{ok:!1,error:`尚未连接到服务器(还没有快照)`};let a=r();return new Promise(t=>{let r=setTimeout(()=>{$.delete(a),t({ok:!1,error:`目录同步超时(服务端未在等待窗口内回执)`})},Math.max(1e3,Number(e.catalogTimeoutMs??18e4)));$.set(a,e=>{clearTimeout(r),t(e)}),e.send({type:`plugin_catalog_sync`,requestId:a,source:i,...n?.install?{install:!0}:{},...n?.replace?{replace:!0}:{}})})},onUiAction(e,t){return H(B,String(e??``).trim(),t)},onTopbarAction(e,t){return H(B,String(e??``).trim(),t)},async pageCall(t){let n=String(t?.op??``).trim();if(!n)return{ok:!1,error:`pageCall 需要一个动作名(op)`};let r=window.__piBrowser;if(r?.version===1&&typeof r.pageCall==`function`)try{return await r.pageCall({...t,op:n,timeoutMs:t.timeoutMs??3e4})}catch(e){return{ok:!1,error:e instanceof Error?e.message:String(e)}}if(i())return{ok:!1,error:`此桌面版尚未提供原生浏览器桥;请升级到支持 AI Browser 的桌面版,或在系统浏览器中使用 page-picker 扩展。/ Native browser bridge unavailable; upgrade the desktop app or use page-picker in a regular browser.`};let a=await he(e.bridgeWaitMs??3e3);if(!a)return{ok:!1,error:`浏览器扩展的页面桥没就绪:确认已安装并启用 page-picker 扩展、本页地址已绑定,然后刷新本页`};try{let e=await a.call({op:n,...t.args===void 0?{}:{args:t.args},...t.target?{to:t.target}:{},...t.timeoutMs?{timeoutMs:t.timeoutMs}:{}});return e===void 0?{ok:!0}:{ok:!0,result:e}}catch(e){return{ok:!1,error:e instanceof Error?e.message:String(e)}}},dom:{anchors(){let e=e=>{try{return document.querySelector(`[data-pi-anchor="${e}"]`)}catch{return null}};return{app:e(`app`),topbar:e(`topbar`),composer:e(`composer`)}}},dialogs:{async select(t){try{let n=e.select;if(typeof n!=`function`)return{ok:!1};let r=Array.isArray(t?.options)?t.options:[],i=await n({title:String(t?.title??``),options:r.filter(e=>typeof e==`object`&&!!e&&typeof e.label==`string`).map(e=>({label:String(e.label),...typeof e.description==`string`?{description:e.description}:{}})),...t?.multi?{multi:!0}:{}});return!i||typeof i!=`object`||i.ok!==!0?{ok:!1,...i&&typeof i==`object`&&typeof i.error==`string`?{error:i.error}:{}}:{ok:!0,selected:Array.isArray(i.selected)?i.selected.filter(e=>typeof e==`string`):[]}}catch{return{ok:!1}}},async confirm(t){let n=String(t?.title??``),r=typeof t?.detail==`string`?t.detail:``;try{if(typeof e.dialogConfirm==`function`)try{return await e.dialogConfirm({title:n,...r?{detail:r}:{}})===!0}catch{}if(typeof window<`u`&&typeof window.confirm==`function`)try{return window.confirm(r?`${n}\n\n${r}`:n)}catch{return!1}return!1}catch{return!1}},async input(t){try{let n=e.input;if(typeof n!=`function`)return{ok:!1};let r=await n({title:String(t?.title??``),...typeof t?.placeholder==`string`?{placeholder:t.placeholder}:{},...typeof t?.initial==`string`?{initial:t.initial}:{}});return!r||typeof r!=`object`||r.ok!==!0?{ok:!1}:typeof r.value==`string`?{ok:!0,value:r.value}:{ok:!0}}catch{return{ok:!1}}}},async notifyAction(t){let n=String(t?.text??``),r=(Array.isArray(t?.actions)?t.actions:[]).filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`&&typeof e.label==`string`);try{if(typeof e.notifyAction==`function`){let t=await e.notifyAction({text:n,actions:r});return typeof t==`string`?t:null}}catch{return null}try{typeof window<`u`&&typeof window.dispatchEvent==`function`&&window.dispatchEvent(new CustomEvent(xe,{detail:{text:n}}))}catch{}return null},shortcuts:{register:(e,t)=>Ee(String(e??``),t)},searchProviders:{register:e=>De(e),list:()=>q()},composerProviders:{register:e=>Oe(e),list:()=>ke()},ttsProviders:{list:()=>ae()},openImagePreview:y,imageOcrProviders:{register:e=>ce(e,B),list:()=>le().map(({id:e,label:t,labelEn:n})=>({id:e,label:t,labelEn:n}))},onTheme:e=>Pe(e),onLocale:e=>Fe(e),onViewChange:e=>Ie(e),listProjects:()=>e.listProjects?.()??[],pickDirectory:t=>e.pickDirectory?e.pickDirectory(t):Promise.resolve({ok:!1,canceled:!0}),pickModel:t=>e.pickModel?e.pickModel(t):Promise.resolve({ok:!1,canceled:!0}),openFileContextMenu:t=>e.openFileContextMenu?.(t),setCostFormatter:e=>te(e),setCostCurrency:e=>ee(e),getCostCurrency:()=>g()}}function _e(e){try{let t=window;e?t[F]=e:delete t[F]}catch{}}var z=new Map,B=null;async function ve(e,t){let n=B;B=e;try{return await t()}finally{B=n}}var V=void 0;function ye(e,t){let n=V;V=e;try{return t()}finally{V=n}}function H(e,t,n){if(!t||typeof n!=`function`)return()=>{};let r=e?`${e}:${t}`:t,i=z.get(r);i||(i=new Set,z.set(r,i));let a=i;return a.add(n),()=>{a.delete(n),a.size===0&&z.delete(r)}}async function be(e,t,n,r){let i=i=>{let a=z.get(i);if(!a||a.size===0)return!1;for(let i of[...a])try{ye(e,()=>i(n,r?.value,r?.target))}catch(n){console.error(`[plugin:${e}] 顶栏动作 ${t} 抛错:`,n)}return!0};if(i(`${e}:${t}`)||i(t))return!0;if(r?.loadBundle&&await r.loadBundle(e).catch(()=>!1)){let n=Date.now()+Math.max(100,Number(r.waitMs??1500));for(;;){if(i(`${e}:${t}`)||i(t))return!0;if(Date.now()>=n)break;await new Promise(e=>setTimeout(e,100))}}return!1}var xe=`pi-web-ui:toast`,U=new Map,W=!1;function Se(e){let t=e.split(`+`).map(e=>e.trim().toLowerCase()).filter(e=>e.length>0);if(t.length===0)return null;let n=!1,r=!1,i=!1,a=!1;for(let e of t.slice(0,-1))if(e===`ctrl`||e===`control`)n=!0;else if(e===`shift`)r=!0;else if(e===`alt`||e===`option`)i=!0;else if(e===`meta`||e===`cmd`||e===`command`||e===`win`||e===`super`)a=!0;else return null;let o=t[t.length-1]??``;return!o||[`ctrl`,`control`,`shift`,`alt`,`option`,`meta`,`cmd`,`command`,`win`,`super`].includes(o)?null:{combo:`${n?`ctrl+`:``}${r?`shift+`:``}${i?`alt+`:``}${a?`meta+`:``}${o}`,key:o,ctrl:n,shift:r,alt:i,meta:a}}function Ce(){try{if(typeof document>`u`)return!1;let e=document.activeElement;if(!e)return!1;let t=(e.tagName||``).toUpperCase();return!!(t===`INPUT`||t===`TEXTAREA`||t===`SELECT`||e.isContentEditable)}catch{return!1}}function G(e){try{if(Ce())return;let t=`${e.ctrlKey?`ctrl+`:``}${e.shiftKey?`shift+`:``}${e.altKey?`alt+`:``}${e.metaKey?`meta+`:``}${(e.key??``).toLowerCase()}`,n=U.get(t);if(!n||n.size===0)return;for(let e of[...n])try{e()}catch(e){console.error(`[plugin-host] 快捷键处理器抛错:`,e)}}catch{}}function we(){if(!W)try{if(typeof window>`u`||typeof window.addEventListener!=`function`)return;window.addEventListener(`keydown`,G),W=!0}catch{}}function Te(){if(!(U.size>0||!W))try{window.removeEventListener(`keydown`,G)}catch{}finally{W=!1}}function Ee(e,t){if(typeof t!=`function`)return()=>{};let n=Se(e);if(!n)return()=>{};let r=U.get(n.combo);r||(r=new Set,U.set(n.combo,r));let i=r;return i.add(t),we(),()=>{i.delete(t),i.size===0&&U.delete(n.combo),Te()}}var K=new Map;function De(e){let t=String(e?.id??``).trim();if(!t||typeof e?.search!=`function`)return()=>{};let n={id:t,label:String(e.label??t),search:e.search};return K.set(t,n),()=>{K.get(t)===n&&K.delete(t)}}function q(){return[...K.values()].map(e=>({id:e.id,label:e.label}))}var J=new Map;function Oe(e){let t=String(e?.id??``).trim();if(!t||typeof e?.search!=`function`)return()=>{};let n={id:t,label:String(e.label??t),search:e.search};return J.set(t,n),()=>{J.get(t)===n&&J.delete(t)}}function ke(){return[...J.values()].map(e=>({id:e.id,label:e.label}))}function Ae(e){return J.get(String(e??``))}function je(e){return K.get(String(e??``))}var Y=new Set,X=new Set,Z=new Set,Q=new Set;function Me(e){return Q.add(e),()=>{Q.delete(e)}}function Ne(e){for(let t of Q)try{t(e)}catch(e){console.error(`[plugin-host] onModelChange 处理器抛错:`,e)}}function Pe(e){return typeof e==`function`?(Y.add(e),()=>{Y.delete(e)}):()=>{}}function Fe(e){return typeof e==`function`?(X.add(e),()=>{X.delete(e)}):()=>{}}function Ie(e){return typeof e==`function`?(Z.add(e),()=>{Z.delete(e)}):()=>{}}function Le(e){let t=String(e??``);for(let e of Y)try{e(t)}catch(e){console.error(`[plugin-host] onTheme 处理器抛错:`,e)}}function Re(e){let t=String(e??``);for(let e of X)try{e(t)}catch(e){console.error(`[plugin-host] onLocale 处理器抛错:`,e)}}function ze(e){let t=String(e??``);for(let e of Z)try{e(t)}catch(e){console.error(`[plugin-host] onViewChange 处理器抛错:`,e)}}var $=new Map;function Be(e){let t=$.get(e.requestId);if(t){if($.delete(e.requestId),!e.ok){t({ok:!1,error:e.error??`目录同步失败`});return}t({ok:!0,...e.entries?{entries:e.entries}:{},...e.installed?{installed:e.installed}:{}})}}export{y as C,re as E,se as S,_ as T,le as _,ze as a,oe as b,_e as c,Be as d,be as f,j as g,pe as h,Le as i,ke as l,me as m,Re as n,Ae as o,ve as p,Ne as r,je as s,ge as t,q as u,ue as v,ie as w,ae as x,de as y};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Fn as t}from"./app-globals-CBEscsYP.js";import{i as n}from"./react-CR5VJ85Q.js";import{t as r}from"./uuid-BzDIGCwP.js";import{r as i}from"./desktop-C6D9a8HZ.js";import{o as a,t as o}from"./composer-bridge-CImnjDHq.js";var s=e(n(),1),c=`pi-web-ui:cost-currency`,l=null,u=0,d=new Set;function f(){u+=1;for(let e of[...d])try{e()}catch{}}function p(e){return d.add(e),()=>{d.delete(e)}}function m(){return u}function h(e){return!Number.isFinite(e)||e<=0?`0`:e<1e-4?`<0.0001`:e.toFixed(4).replace(/\.?0+$/,``)}function g(){try{if(typeof localStorage<`u`){let e=localStorage.getItem(c);if(typeof e==`string`&&e.trim().length>0)return e.trim().slice(0,8)}}catch{}return`$`}function ee(e){try{if(typeof localStorage<`u`){let t=typeof e==`string`?e.trim().slice(0,8):``;!t||t===`$`?localStorage.removeItem(c):localStorage.setItem(c,t)}}catch{}f()}function te(e){return typeof e==`function`?(l=e,f(),()=>{l===e&&(l=null,f())}):(l=null,f(),()=>{})}function ne(e,t){let n=String(e??``).trim();if(!n)return{symbol:t,value:`0`};let r=n.match(/^([^\d<>+-]+)\s*(.+)$/);return r?{symbol:r[1],value:r[2]}:{symbol:``,value:n}}function _(e,t){let n=typeof e==`number`&&Number.isFinite(e)?e:0,r=g(),i=typeof t?.fixedDigits==`number`?n.toFixed(t.fixedDigits):h(n);if(l)try{let e=l(n,{defaultSymbol:r,defaultValue:i});if(typeof e==`string`)return ne(e,r);if(e&&typeof e==`object`&&typeof e.value==`string`)return{symbol:typeof e.symbol==`string`?e.symbol:r,value:e.value,tooltip:typeof e.tooltip==`string`?e.tooltip:void 0}}catch(e){console.error(`[cost-format] custom cost formatter threw:`,e)}return{symbol:r,value:i}}function re(e,t){return(0,s.useSyncExternalStore)(p,m,m),_(e,t)}var v=null;function ie(e){v=e?.open??null,e?.close,e?.isOpen}function y(e){return!v||!e?.src?!1:(v(e),!0)}var b=[{id:`builtin`,label:`系统语音`,labelEn:`System speech`}],x=new Set,S,C;async function w(e){let t=await e.json().catch(()=>({}));return Error(t.error||`TTS HTTP ${e.status}`)}function T(){return S||=(async()=>{let e=await fetch(t(`/api/tts/engines`));if(!e.ok)throw await w(e);b=(await e.json()).engines;for(let e of x)e()})().finally(()=>{S=void 0}),S}function ae(){return[...b]}function oe(e){if(e)return{...b.find(t=>t.id===e)||{id:e,label:e},getVoices:async()=>{let n=await fetch(t(`/api/tts/voices?engine=${encodeURIComponent(e)}`));if(!n.ok)throw await w(n);return(await n.json()).voices.map(e=>({voiceURI:e.id,name:e.label,lang:e.lang}))},play:({text:n,rate:r,voiceURI:i,onStart:a,onEnd:o,onError:s})=>{let c=new AbortController,l,u,d=!1,f=()=>{c.abort(),l&&(l.pause(),l.removeAttribute(`src`),l.load()),u&&=(URL.revokeObjectURL(u),void 0)},p=e=>{d||(d=!0,f(),e?s?.(e):o?.())};return(async()=>{try{let o=await fetch(t(`/api/tts/synthesize`),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:n,engine:e,voice:i||``,rate:r}),signal:c.signal});if(!o.ok)throw await w(o);let s=await o.blob();if(d)return;u=URL.createObjectURL(s),l=new Audio(u),l.onplay=()=>{d||a?.()},l.onended=()=>p(),l.onerror=()=>p(Error(`语音播放失败`)),await l.play()}catch(e){d||p(e)}})(),()=>{d||(d=!0,f())}}}}function se(e){return x.add(e),T().catch(()=>{}),C||=setInterval(()=>{T().catch(()=>{})},15e3),()=>{x.delete(e),!x.size&&C&&(clearInterval(C),C=void 0)}}var E=new Map,D=new Set,O=[],k=null;function A(){O=[...E.values()].map(e=>e.provider);for(let e of D)e()}function ce(e,t=null){let n=String(e?.id??``).trim();if(!n||typeof e?.recognize!=`function`||t&&k&&!k.has(t))return()=>{};let r={provider:{...e,id:n},owner:t};return E.set(n,r),A(),()=>{E.get(n)===r&&(E.delete(n),A())}}function le(){return O}function ue(e){return D.add(e),()=>{D.delete(e)}}function de(e){k=e;for(let t of E.values())t.owner&&!e.has(t.owner)&&j(t.owner)}function j(e){let t=!1;for(let[n,r]of E)(e===void 0||r.owner===e)&&(E.delete(n),t=!0);t&&A()}var M=new Map,fe=0;function pe(e){M.get(e.requestId)?.(e.ok&&e.conversationId?e.conversationId:null)}function N(e,t,n){let r=`host-new-chat-${Date.now()}-${++fe}`;return new Promise(i=>{let a=e=>{clearTimeout(o),M.delete(r),i(e)},o=setTimeout(()=>a(null),n);M.set(r,a);try{e(t(r))||a(null)}catch{a(null)}})}function P(e,t=8e3){return N(e,e=>({type:`new_chat`,requestId:e}),t)}function me(e,t,n,r=n?.trim().startsWith(`ssh://`)?12e4:3e4){return N(e,e=>({type:`new_cli_chat`,config:t,cwd:n,requestId:e}),r)}var F=`__piWebUiHost`,I=e=>new Promise(t=>setTimeout(t,e));async function he(e=3e3){let t=Date.now()+e;for(;;){let e=window.__piBridge;if(e&&typeof e.call==`function`)return e;if(Date.now()>=t)return null;await I(100)}}var L=Promise.resolve(),R=0;function ge(e){let t=Math.max(1,Number(e.pollMs??100)),n=Math.max(t,Number(e.timeoutMs??8e3)),s=async e=>{let r=Date.now()+n;for(;;){if(e())return!0;if(Date.now()>=r)return e();await I(t)}},c=()=>{try{let t=e.listModels?.()??[];return Array.isArray(t)?[...t]:[]}catch{return[]}},l=e=>{if(!e)return!0;try{return c().some(t=>t&&t.id===e)}catch{return!1}},u=async t=>{t&&(e.send({type:`set_model`,modelId:t}),typeof e.getCurrentModelId==`function`&&await s(()=>e.getCurrentModelId?.()===t))},d=async(t,r)=>{let i=String(r.cwd??``).trim();if(i&&e.getCwd()!==i&&(!e.send({type:`set_cwd`,path:i})||!await s(()=>e.getCwd()===i))||!e.isReady())return!1;let a=r.newChat===!1?e.getConversationId():await P(e.send,n);if(r.newChat!==!1&&a&&!await s(()=>e.getConversationId()===a)||!a||!e.isReady())return!1;let o=String(r.model??``).trim();return o&&await u(o),!e.isReady()||e.getConversationId()!==a||i&&e.getCwd()!==i?!1:(e.setView(`chat`),e.send({type:`prompt`,text:t,targetConversationId:a}))};return{version:18,setView(t){let n=String(t??``).trim();n&&e.setView(n)},startChat(t){let n=String(t?.prompt??``).trim();if(!n||!e.isReady())return!1;let r=String(t?.model??``).trim();if(r&&!l(r))return!1;let i=async()=>{let e=!1;try{e=await d(n,t??{prompt:n})}finally{try{t?.onResult?.(e)}catch{}}},a;return a=R>0?L.then(i):i(),R++,L=a.then(()=>{R--},()=>{R--}),a.catch(()=>{}),!0},models:{list:()=>c(),active:()=>e.getCurrentModelId?.()??null,onChange:e=>Me(e)},compose(e){return a()?o({text:typeof e?.text==`string`?e.text:void 0,attachments:Array.isArray(e?.attachments)?e.attachments:void 0}):!1},openModal(t){let n=String(t??``).trim();if(!n||typeof e.openModal!=`function`)return!1;try{return e.openModal(n)}catch{return!1}},setFooterStatus(t,n){if(typeof e.setFooterStatus!=`function`)return!1;try{return e.setFooterStatus(String(t??``),n)}catch{return!1}},closeModal(){if(typeof e.closeModal!=`function`)return!0;try{e.closeModal()}catch{}return!0},async openSession(t){let r=V,i=Array.isArray(t?.folders)?t.folders.filter(e=>typeof e==`string`&&e.trim().length>0).map(e=>e.trim()):[],a=Array.isArray(t?.roots)?t.roots.filter(e=>typeof e==`string`&&e.trim().length>0).map(e=>e.trim()):[],o=String(t?.cwd??``).trim(),c=[...new Set([...i,...a])],d=o||c[0]||``;if(!d)return{ok:!1,error:`openSession 需要 cwd / folders / roots(绝对路径)`};if(!e.isReady())return{ok:!1,error:`尚未连接到服务器(还没有快照)`};let f=c.filter(e=>e!==d).slice(0,7),p=new Set([...e.listProjects?.()??[],...e.grantedPaths?.(r)??[]]);for(let t of[d,...f])if(!p.has(t)){if(!(e.confirm&&await e.confirm({path:t}).catch(()=>!1)))return{ok:!1,error:`用户拒绝了该目录的访问:${t}`};e.grantPath?.(t,r)}if(e.getCwd()!==d&&(e.send({type:`set_cwd`,path:d}),!await s(()=>e.getCwd()===d)))return{ok:!1,error:`切换工作目录失败或超时:${d}`};(f.length>0||e.getWorkspaceRoots().length>0)&&e.send({type:`set_workspace_roots`,roots:f});let m=e.getConversationId()??void 0;if(t?.newChat!==!1&&(m=await P(e.send,n)??void 0,!m||!await s(()=>e.getConversationId()===m)))return{ok:!1,error:`Conversation creation failed or timed out`};let h=String(t?.model??``).trim();if(h){if(!l(h))return{ok:!1,error:`未知模型:${h}(先调 models.list() 取可用列表)`};if(await u(h),e.getConversationId()!==m)return{ok:!1,error:`Conversation changed`}}let g=String(t?.prompt??``).trim();return!m||!e.isReady()?{ok:!1,error:`Conversation unavailable`}:(g&&(e.setView(`chat`),e.send({type:`prompt`,text:g,targetConversationId:m})),{ok:!0,...m?{sessionId:m}:{}})},sessions:{list:()=>e.listSessions(),async open(t){let n=V,r=String(t??``).trim();if(!r)return{ok:!1,error:`sessions.open 需要一个会话 id(先调 list)`};if(!e.isReady())return{ok:!1,error:`尚未连接到服务器(还没有快照)`};let i=e.listSessions().find(e=>e.id===r);if(!i)return{ok:!1,error:`找不到会话:${r}`};if(i.cwd&&i.cwd!==e.getCwd()){if(!new Set([...e.listProjects?.()??[],...e.grantedPaths?.(n)??[]]).has(i.cwd)){if(!(e.confirm&&await e.confirm({path:i.cwd}).catch(()=>!1)))return{ok:!1,error:`用户拒绝了该目录的访问:${i.cwd}`};e.grantPath?.(i.cwd,n)}if(e.send({type:`set_cwd`,path:i.cwd}),!await s(()=>e.getCwd()===i.cwd))return{ok:!1,error:`切换工作目录失败或超时:${i.cwd}`}}let a=e.getConversationId();return i.kind===`elsewhere`&&i.owner?(e.send({type:i.independent===!1?`open_shared_conversation`:`take_over_conversation`,owner:i.owner,id:i.conversationId??i.id}),await s(()=>e.getConversationId()===(i.conversationId??i.id)&&(i.independent!==!1||e.getConversationOwner?.()===i.owner))?{ok:!0,sessionId:e.getConversationId()??void 0}:{ok:!1,error:`打开并接入会话超时:${i.title}`}):(i.kind===`running`?e.send({type:`switch_conversation`,id:i.id}):e.send({type:`switch_session`,path:i.id}),await s(()=>i.kind===`running`?e.getConversationId()===i.id&&!e.getConversationOwner?.():e.getConversationId()!==a)?{ok:!0,sessionId:e.getConversationId()??void 0}:{ok:!1,error:`切换会话超时:${i.title}`})}},async reloadCatalog(t,n){let i=String(t??``).trim();if(!i)return{ok:!1,error:`reloadCatalog 需要一个目录来源(http(s) URL 或本地文件路径)`};if(!e.isReady())return{ok:!1,error:`尚未连接到服务器(还没有快照)`};let a=r();return new Promise(t=>{let r=setTimeout(()=>{$.delete(a),t({ok:!1,error:`目录同步超时(服务端未在等待窗口内回执)`})},Math.max(1e3,Number(e.catalogTimeoutMs??18e4)));$.set(a,e=>{clearTimeout(r),t(e)}),e.send({type:`plugin_catalog_sync`,requestId:a,source:i,...n?.install?{install:!0}:{},...n?.replace?{replace:!0}:{}})})},onUiAction(e,t){return H(B,String(e??``).trim(),t)},onTopbarAction(e,t){return H(B,String(e??``).trim(),t)},async pageCall(t){let n=String(t?.op??``).trim();if(!n)return{ok:!1,error:`pageCall 需要一个动作名(op)`};let r=window.__piBrowser;if(r?.version===1&&typeof r.pageCall==`function`)try{return await r.pageCall({...t,op:n,timeoutMs:t.timeoutMs??3e4})}catch(e){return{ok:!1,error:e instanceof Error?e.message:String(e)}}if(i())return{ok:!1,error:`此桌面版尚未提供原生浏览器桥;请升级到支持 AI Browser 的桌面版,或在系统浏览器中使用 page-picker 扩展。/ Native browser bridge unavailable; upgrade the desktop app or use page-picker in a regular browser.`};let a=await he(e.bridgeWaitMs??3e3);if(!a)return{ok:!1,error:`浏览器扩展的页面桥没就绪:确认已安装并启用 page-picker 扩展、本页地址已绑定,然后刷新本页`};try{let e=await a.call({op:n,...t.args===void 0?{}:{args:t.args},...t.target?{to:t.target}:{},...t.timeoutMs?{timeoutMs:t.timeoutMs}:{}});return e===void 0?{ok:!0}:{ok:!0,result:e}}catch(e){return{ok:!1,error:e instanceof Error?e.message:String(e)}}},dom:{anchors(){let e=e=>{try{return document.querySelector(`[data-pi-anchor="${e}"]`)}catch{return null}};return{app:e(`app`),topbar:e(`topbar`),composer:e(`composer`)}}},dialogs:{async select(t){try{let n=e.select;if(typeof n!=`function`)return{ok:!1};let r=Array.isArray(t?.options)?t.options:[],i=await n({title:String(t?.title??``),options:r.filter(e=>typeof e==`object`&&!!e&&typeof e.label==`string`).map(e=>({label:String(e.label),...typeof e.description==`string`?{description:e.description}:{}})),...t?.multi?{multi:!0}:{}});return!i||typeof i!=`object`||i.ok!==!0?{ok:!1,...i&&typeof i==`object`&&typeof i.error==`string`?{error:i.error}:{}}:{ok:!0,selected:Array.isArray(i.selected)?i.selected.filter(e=>typeof e==`string`):[]}}catch{return{ok:!1}}},async confirm(t){let n=String(t?.title??``),r=typeof t?.detail==`string`?t.detail:``;try{if(typeof e.dialogConfirm==`function`)try{return await e.dialogConfirm({title:n,...r?{detail:r}:{}})===!0}catch{}if(typeof window<`u`&&typeof window.confirm==`function`)try{return window.confirm(r?`${n}\n\n${r}`:n)}catch{return!1}return!1}catch{return!1}},async input(t){try{let n=e.input;if(typeof n!=`function`)return{ok:!1};let r=await n({title:String(t?.title??``),...typeof t?.placeholder==`string`?{placeholder:t.placeholder}:{},...typeof t?.initial==`string`?{initial:t.initial}:{}});return!r||typeof r!=`object`||r.ok!==!0?{ok:!1}:typeof r.value==`string`?{ok:!0,value:r.value}:{ok:!0}}catch{return{ok:!1}}}},async notifyAction(t){let n=String(t?.text??``),r=(Array.isArray(t?.actions)?t.actions:[]).filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`&&typeof e.label==`string`);try{if(typeof e.notifyAction==`function`){let t=await e.notifyAction({text:n,actions:r});return typeof t==`string`?t:null}}catch{return null}try{typeof window<`u`&&typeof window.dispatchEvent==`function`&&window.dispatchEvent(new CustomEvent(xe,{detail:{text:n}}))}catch{}return null},shortcuts:{register:(e,t)=>Ee(String(e??``),t)},searchProviders:{register:e=>De(e),list:()=>q()},composerProviders:{register:e=>Oe(e),list:()=>ke()},ttsProviders:{list:()=>ae()},openImagePreview:y,imageOcrProviders:{register:e=>ce(e,B),list:()=>le().map(({id:e,label:t,labelEn:n})=>({id:e,label:t,labelEn:n}))},onTheme:e=>Pe(e),onLocale:e=>Fe(e),onViewChange:e=>Ie(e),listProjects:()=>e.listProjects?.()??[],pickDirectory:t=>e.pickDirectory?e.pickDirectory(t):Promise.resolve({ok:!1,canceled:!0}),pickModel:t=>e.pickModel?e.pickModel(t):Promise.resolve({ok:!1,canceled:!0}),openFileContextMenu:t=>e.openFileContextMenu?.(t),setCostFormatter:e=>te(e),setCostCurrency:e=>ee(e),getCostCurrency:()=>g()}}function _e(e){try{let t=window;e?t[F]=e:delete t[F]}catch{}}var z=new Map,B=null;async function ve(e,t){let n=B;B=e;try{return await t()}finally{B=n}}var V=void 0;function ye(e,t){let n=V;V=e;try{return t()}finally{V=n}}function H(e,t,n){if(!t||typeof n!=`function`)return()=>{};let r=e?`${e}:${t}`:t,i=z.get(r);i||(i=new Set,z.set(r,i));let a=i;return a.add(n),()=>{a.delete(n),a.size===0&&z.delete(r)}}async function be(e,t,n,r){let i=i=>{let a=z.get(i);if(!a||a.size===0)return!1;for(let i of[...a])try{ye(e,()=>i(n,r?.value,r?.target))}catch(n){console.error(`[plugin:${e}] 顶栏动作 ${t} 抛错:`,n)}return!0};if(i(`${e}:${t}`)||i(t))return!0;if(r?.loadBundle&&await r.loadBundle(e).catch(()=>!1)){let n=Date.now()+Math.max(100,Number(r.waitMs??1500));for(;;){if(i(`${e}:${t}`)||i(t))return!0;if(Date.now()>=n)break;await new Promise(e=>setTimeout(e,100))}}return!1}var xe=`pi-web-ui:toast`,U=new Map,W=!1;function Se(e){let t=e.split(`+`).map(e=>e.trim().toLowerCase()).filter(e=>e.length>0);if(t.length===0)return null;let n=!1,r=!1,i=!1,a=!1;for(let e of t.slice(0,-1))if(e===`ctrl`||e===`control`)n=!0;else if(e===`shift`)r=!0;else if(e===`alt`||e===`option`)i=!0;else if(e===`meta`||e===`cmd`||e===`command`||e===`win`||e===`super`)a=!0;else return null;let o=t[t.length-1]??``;return!o||[`ctrl`,`control`,`shift`,`alt`,`option`,`meta`,`cmd`,`command`,`win`,`super`].includes(o)?null:{combo:`${n?`ctrl+`:``}${r?`shift+`:``}${i?`alt+`:``}${a?`meta+`:``}${o}`,key:o,ctrl:n,shift:r,alt:i,meta:a}}function Ce(){try{if(typeof document>`u`)return!1;let e=document.activeElement;if(!e)return!1;let t=(e.tagName||``).toUpperCase();return!!(t===`INPUT`||t===`TEXTAREA`||t===`SELECT`||e.isContentEditable)}catch{return!1}}function G(e){try{if(Ce())return;let t=`${e.ctrlKey?`ctrl+`:``}${e.shiftKey?`shift+`:``}${e.altKey?`alt+`:``}${e.metaKey?`meta+`:``}${(e.key??``).toLowerCase()}`,n=U.get(t);if(!n||n.size===0)return;for(let e of[...n])try{e()}catch(e){console.error(`[plugin-host] 快捷键处理器抛错:`,e)}}catch{}}function we(){if(!W)try{if(typeof window>`u`||typeof window.addEventListener!=`function`)return;window.addEventListener(`keydown`,G),W=!0}catch{}}function Te(){if(!(U.size>0||!W))try{window.removeEventListener(`keydown`,G)}catch{}finally{W=!1}}function Ee(e,t){if(typeof t!=`function`)return()=>{};let n=Se(e);if(!n)return()=>{};let r=U.get(n.combo);r||(r=new Set,U.set(n.combo,r));let i=r;return i.add(t),we(),()=>{i.delete(t),i.size===0&&U.delete(n.combo),Te()}}var K=new Map;function De(e){let t=String(e?.id??``).trim();if(!t||typeof e?.search!=`function`)return()=>{};let n={id:t,label:String(e.label??t),search:e.search};return K.set(t,n),()=>{K.get(t)===n&&K.delete(t)}}function q(){return[...K.values()].map(e=>({id:e.id,label:e.label}))}var J=new Map;function Oe(e){let t=String(e?.id??``).trim();if(!t||typeof e?.search!=`function`)return()=>{};let n={id:t,label:String(e.label??t),search:e.search};return J.set(t,n),()=>{J.get(t)===n&&J.delete(t)}}function ke(){return[...J.values()].map(e=>({id:e.id,label:e.label}))}function Ae(e){return J.get(String(e??``))}function je(e){return K.get(String(e??``))}var Y=new Set,X=new Set,Z=new Set,Q=new Set;function Me(e){return Q.add(e),()=>{Q.delete(e)}}function Ne(e){for(let t of Q)try{t(e)}catch(e){console.error(`[plugin-host] onModelChange 处理器抛错:`,e)}}function Pe(e){return typeof e==`function`?(Y.add(e),()=>{Y.delete(e)}):()=>{}}function Fe(e){return typeof e==`function`?(X.add(e),()=>{X.delete(e)}):()=>{}}function Ie(e){return typeof e==`function`?(Z.add(e),()=>{Z.delete(e)}):()=>{}}function Le(e){let t=String(e??``);for(let e of Y)try{e(t)}catch(e){console.error(`[plugin-host] onTheme 处理器抛错:`,e)}}function Re(e){let t=String(e??``);for(let e of X)try{e(t)}catch(e){console.error(`[plugin-host] onLocale 处理器抛错:`,e)}}function ze(e){let t=String(e??``);for(let e of Z)try{e(t)}catch(e){console.error(`[plugin-host] onViewChange 处理器抛错:`,e)}}var $=new Map;function Be(e){let t=$.get(e.requestId);if(t){if($.delete(e.requestId),!e.ok){t({ok:!1,error:e.error??`目录同步失败`});return}t({ok:!0,...e.entries?{entries:e.entries}:{},...e.installed?{installed:e.installed}:{}})}}export{y as C,re as E,se as S,_ as T,le as _,ze as a,oe as b,_e as c,Be as d,be as f,j as g,pe as h,Le as i,ke as l,me as m,Re as n,Ae as o,ve as p,Ne as r,je as s,ge as t,q as u,ue as v,ie as w,ae as x,de as y};
@@ -0,0 +1 @@
1
+ import{t as e}from"./app-globals-CBEscsYP.js";var t=new Set;function n(e){return t.add(e),()=>{t.delete(e)}}function r(e){for(let n of t)try{n(e)}catch(e){console.error(`[remote-ssh-client] listener error:`,e)}}function i(e,t,n,r){return`ssh://${e}@${t}:${n}${r.startsWith(`/`)?r:`/${r}`}`}function a(e){return!!(e&&e.startsWith(`ssh://`))}function o(e){if(!a(e))return null;let t=/^ssh:\/\/([^@]+)@([^:]+):(\d+)(\/.*)$/.exec(e);return t?{username:t[1],host:t[2],port:parseInt(t[3],10),remotePath:t[4]}:null}var s=1;function c(t){let r=`probe_${Date.now()}_${s++}`;return new Promise(i=>{let a=n(e=>{e.type===`remote_ssh_probe_result`&&e.reqId===r&&(a(),i({ok:e.ok,connectionId:e.connectionId,error:e.error,system:e.system,tools:e.tools,packageManager:e.packageManager,suggestedInstall:e.suggestedInstall,hostTrust:e.hostTrust}))});e({type:`remote_ssh_probe`,reqId:r,params:t})||(a(),i({ok:!1,error:`WebSocket 连接不可用,请稍候重试`}))})}function l(t,r){let i=`listdir_${Date.now()}_${s++}`;return new Promise(a=>{let o=n(e=>{e.type===`remote_ssh_list_dir_result`&&e.reqId===i&&(o(),a({ok:e.ok,connectionId:e.connectionId,path:e.path,parentPath:e.parentPath,items:e.items,error:e.error}))});e({type:`remote_ssh_list_dir`,reqId:i,connectionId:t,path:r})||(o(),a({ok:!1,connectionId:t,path:r||`/`,items:[],error:`WebSocket 连接不可用`}))})}function u(t,r){let i=`install_${Date.now()}_${s++}`;return new Promise(a=>{let o=n(e=>{e.type===`remote_ssh_install_result`&&e.reqId===i&&(o(),a({ok:e.ok,connectionId:e.connectionId,tool:e.tool,output:e.output,error:e.error}))});e({type:`remote_ssh_install_tools`,reqId:i,connectionId:t,tools:r})||(o(),a({ok:!1,connectionId:t,tool:r[0]||``,error:`WebSocket 连接不可用`}))})}function d(){let t=`profiles_${Date.now()}_${s++}`;return new Promise(r=>{let i=n(e=>{e.type===`remote_ssh_profiles_result`&&e.reqId===t&&(i(),r(e.profiles))});e({type:`remote_ssh_list_profiles`,reqId:t})||(i(),r([]))})}function f(t){e({type:`remote_ssh_delete_profile`,name:t})}function p(t){let r=`trust_${Date.now()}_${s++}`;return new Promise(i=>{let a=n(e=>{e.type===`remote_ssh_trust_host_result`&&e.reqId===r&&(a(),i({ok:e.ok,error:e.error}))});e({type:`remote_ssh_trust_host`,reqId:r,...t})||(a(),i({ok:!1,error:`WebSocket 连接不可用`}))})}export{o as a,c,a as i,d as l,r as n,u as o,i as r,l as s,f as t,p as u};
@@ -0,0 +1 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Bn as t,Fn as n,Nn as r,Pn as i,i as a}from"./app-globals-CBEscsYP.js";import{i as o}from"./react-CR5VJ85Q.js";var s=e(o(),1),c=`pi-web-ui:theme`,l=`flow-ink`,u=`theme-stylesheet`,d=Date.now().toString(36),f=0,p=3,m=0,h=new WeakMap,g=0,_=`pi-web-ui:theme-change`;function v(){try{let e=localStorage.getItem(c);if(e===`none`)return null;if(e&&e!==`dark`)return e}catch{}return l}function y(e){try{e===null?localStorage.setItem(c,`none`):localStorage.setItem(c,e)}catch{}}function b(e){return i(`/themes/${encodeURIComponent(e)}.css?v=${d}.${f}`)}function x(){if(typeof document>`u`)return!1;let e=document.getElementById(u),t=e?h.get(e):void 0;return!!t&&t.loaded!==null&&t.loaded===t.href}function S(e,t={}){if(t.reload&&(f++,m=0),typeof document<`u`&&(e?document.documentElement.dataset.theme=e:delete document.documentElement.dataset.theme),!e){document.getElementById(u)?.remove(),m=0,window.dispatchEvent(new CustomEvent(_));return}let n=document.getElementById(u);n||(n=document.createElement(`link`),n.id=u,n.rel=`stylesheet`,m=0,document.head.appendChild(n));let i=b(e),a=h.get(n);if(a&&a.href===i)return;let o=n,s=++g,c={href:i,loaded:null,seq:s};h.set(o,c);let l=r(i);l?o.crossOrigin=l:o.removeAttribute(`crossorigin`),o.href=i,o.onload=()=>{let e=h.get(o);e&&e.seq===s&&(e.loaded=i,m=0,window.dispatchEvent(new CustomEvent(_)))},o.onerror=()=>{let t=h.get(o);if(!t||t.seq!==s||t.loaded===i||m>=p)return;let n=400*2**m++;window.setTimeout(()=>{let t=h.get(o);t&&t.seq===s&&(f++,S(e))},n)}}async function C(){try{let e=await fetch(t(n(`/api/themes`)));if(!e.ok)return[];let r=await e.json();return Array.isArray(r.themes)?r.themes:[]}catch{return[]}}function w(){let[e,t]=(0,s.useState)([]),[n,r]=(0,s.useState)(()=>v()),i=a(`status`)===`open`;(0,s.useEffect)(()=>{let e=!1;return C().then(n=>{e||t(n)}),()=>{e=!0}},[i]);let o=(0,s.useCallback)(()=>{C().then(t)},[]);return(0,s.useEffect)(()=>{i&&!x()?S(n,{reload:!0}):S(n),y(n)},[n,i]),{themes:e,theme:n,switchTheme:e=>r(e),reloadThemes:o}}function T(){let e=getComputedStyle(document.documentElement),t=(t,n)=>e.getPropertyValue(t).trim()||n;return{background:t(`--term-bg`,`#0b0d12`),foreground:t(`--term-fg`,`#e6e8ef`),cursor:t(`--term-cursor`,`#8b5cf6`),cursorAccent:t(`--term-cursor-accent`,`#0b0d12`),selectionBackground:t(`--term-selection`,`rgba(139, 92, 246, 0.35)`),black:t(`--term-black`,`#1a1d26`),red:t(`--term-red`,`#f87171`),green:t(`--term-green`,`#34d399`),yellow:t(`--term-yellow`,`#fbbf24`),blue:t(`--term-blue`,`#60a5fa`),magenta:t(`--term-magenta`,`#c084fc`),cyan:t(`--term-cyan`,`#22d3ee`),white:t(`--term-white`,`#e6e8ef`),brightBlack:t(`--term-bright-black`,`#6b7284`),brightRed:t(`--term-bright-red`,`#f87171`),brightGreen:t(`--term-bright-green`,`#34d399`),brightYellow:t(`--term-bright-yellow`,`#fbbf24`),brightBlue:t(`--term-bright-blue`,`#60a5fa`),brightMagenta:t(`--term-bright-magenta`,`#c084fc`),brightCyan:t(`--term-bright-cyan`,`#22d3ee`),brightWhite:t(`--term-bright-white`,`#ffffff`)}}export{w as a,v as i,S as n,T as r,_ as t};
@@ -21,23 +21,23 @@
21
21
  }
22
22
  }
23
23
  </script>
24
- <script type="module" crossorigin src="./assets/index-BBAQNi6v.js"></script>
24
+ <script type="module" crossorigin src="./assets/index-BlCxbqqr.js"></script>
25
25
  <link rel="modulepreload" crossorigin href="./assets/rolldown-runtime-hePW80VL.js">
26
26
  <link rel="modulepreload" crossorigin href="./assets/react-CR5VJ85Q.js">
27
- <link rel="modulepreload" crossorigin href="./assets/app-globals-CR8Ls9nE.js">
27
+ <link rel="modulepreload" crossorigin href="./assets/app-globals-CBEscsYP.js">
28
28
  <link rel="modulepreload" crossorigin href="./assets/shortcut-stack-hhrDyRBn.js">
29
29
  <link rel="modulepreload" crossorigin href="./assets/uuid-BzDIGCwP.js">
30
- <link rel="modulepreload" crossorigin href="./assets/Dropdown-Btjt6Dzh.js">
31
- <link rel="modulepreload" crossorigin href="./assets/theme-DVa7Z5Zu.js">
32
- <link rel="modulepreload" crossorigin href="./assets/desktop-BME3DkyE.js">
30
+ <link rel="modulepreload" crossorigin href="./assets/Dropdown-kj_NIj6e.js">
31
+ <link rel="modulepreload" crossorigin href="./assets/theme-CpQk_Agp.js">
32
+ <link rel="modulepreload" crossorigin href="./assets/desktop-C6D9a8HZ.js">
33
33
  <link rel="modulepreload" crossorigin href="./assets/composer-bridge-CImnjDHq.js">
34
- <link rel="modulepreload" crossorigin href="./assets/plugin-host-CVgcdBOk.js">
35
- <link rel="modulepreload" crossorigin href="./assets/HintTip-BOwPzBGR.js">
36
- <link rel="modulepreload" crossorigin href="./assets/remote-ssh-client-DEpvwgqG.js">
34
+ <link rel="modulepreload" crossorigin href="./assets/plugin-host-VWBcq-LQ.js">
35
+ <link rel="modulepreload" crossorigin href="./assets/HintTip-DFhoclDw.js">
36
+ <link rel="modulepreload" crossorigin href="./assets/remote-ssh-client-C2eab5Kw.js">
37
37
  <link rel="modulepreload" crossorigin href="./assets/markdown-BggnuQ4H.js">
38
38
  <link rel="stylesheet" crossorigin href="./assets/markdown-C8LL_u4z.css">
39
- <link rel="stylesheet" crossorigin href="./assets/index-BYWs88H2.css">
40
- <meta name="pi-web-build-id" content="20261108T12484">
39
+ <link rel="stylesheet" crossorigin href="./assets/index-DB55rbKC.css">
40
+ <meta name="pi-web-build-id" content="20261112T05452">
41
41
  </head>
42
42
  <body>
43
43
  <div id="root"></div>
package/web/dist/sw.js CHANGED
@@ -1,4 +1,4 @@
1
- const BUILD_ID = "20261108T12484";
1
+ const BUILD_ID = "20261112T05452";
2
2
  const STATIC_CACHE = BUILD_ID.startsWith("__") ? "pi-web-ui-static-dev" : `pi-web-ui-static-${BUILD_ID}`;
3
3
  const SHELL_CACHE = "pi-web-ui-shell-v1";
4
4
 
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Cn as t,Tn as n,Ut as r,an as i,hn as a,nn as o,sn as s,t as c,yt as l}from"./app-globals-CR8Ls9nE.js";import{i as u,t as d}from"./react-CR5VJ85Q.js";import{Rt as f,Vt as p,jt as m,z as h}from"./index-BYW9d61A.js";var g=e(u(),1),_=d();function v(e,t){let n=Math.max(0,Date.now()-e),r=Math.floor(n/6e4);if(r<1)return t(`bgTaskJustNow`);if(r<60)return t(`bgTaskMinutes`,{n:r});let i=Math.floor(r/60);return i<24?t(`bgTaskHours`,{n:i}):t(`bgTaskDays`,{n:Math.floor(i/24)})}function y({servers:e,onClose:u,plugins:d=[],epoch:y=0,send:b,onUiAction:x,autoCleanupMin:S=0}){let C=n(),{locale:w}=t(),[T,E]=(0,g.useState)(new Set),D=e=>E(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n});(0,g.useEffect)(()=>{c({type:`list_bg_servers`})},[]);let O=(0,g.useMemo)(()=>(f(p(d),{locale:w,t:e=>C(e)})[`tasks.panel`]??[]).filter(e=>!e.hidden&&e.source!==`host`&&e.kind!==`divider`),[d,w,C]);return(0,_.jsxs)(m,{className:`bg-task-modal`,onClose:u,showCloseButton:!1,children:[(0,_.jsxs)(`div`,{className:`bg-task-head`,children:[(0,_.jsxs)(`span`,{className:`bg-task-title`,children:[(0,_.jsx)(l,{}),` `,C(`bgTasks`),e.length>0&&(0,_.jsx)(`em`,{className:`bg-task-count`,children:e.length})]}),(0,_.jsxs)(`div`,{className:`bg-task-head-actions`,children:[(0,_.jsx)(`button`,{type:`button`,className:`btn bg-task-head-btn`,title:C(`bgTaskRefresh`),onClick:()=>c({type:`list_bg_servers`}),children:(0,_.jsx)(r,{})}),(0,_.jsx)(`button`,{type:`button`,className:`btn bg-task-head-btn`,title:C(`close`),onClick:u,children:(0,_.jsx)(a,{})})]})]}),e.length===0?(0,_.jsxs)(`div`,{className:`bg-task-empty`,children:[(0,_.jsx)(l,{}),(0,_.jsx)(`span`,{children:C(`bgTasksEmpty`)}),(0,_.jsx)(`small`,{children:C(`bgTasksDesc`)})]}):(0,_.jsx)(`ul`,{className:`bg-task-list`,children:e.map(e=>{let t=!!e.taskId,n=e.taskId??String(e.port);return(0,_.jsxs)(`li`,{className:`bg-task-item`,children:[(0,_.jsx)(`span`,{className:`bg-task-icon`,title:t?e.plugin:C(`bgTaskPort`)}),(0,_.jsxs)(`div`,{className:`bg-task-info`,children:[(0,_.jsxs)(`div`,{className:`bg-task-line1`,children:[t?(0,_.jsxs)(`span`,{className:`bg-task-port`,title:e.taskId,children:[`🧩 `,e.plugin]}):(0,_.jsxs)(`span`,{className:`bg-task-port`,children:[`:`,e.port]}),e.name&&(0,_.jsx)(`span`,{className:`bg-task-name`,children:e.name})]}),(0,_.jsxs)(`div`,{className:`bg-task-line2`,children:[!t&&(0,_.jsxs)(`span`,{children:[C(`bgTaskPid`),` `,e.pid]}),(0,_.jsxs)(`span`,{children:[C(`bgTaskSince`),` `,v(e.since,C)]}),t&&e.status&&(0,_.jsx)(`span`,{className:`bg-task-status`,children:e.status})]}),e.command&&(0,_.jsxs)(`button`,{type:`button`,className:`bg-task-cmd ${T.has(n)?`open`:``}`,title:`${C(`bgTaskCommand`)}: ${e.command}`,onClick:()=>D(n),children:[(0,_.jsx)(i,{}),(0,_.jsx)(`code`,{children:e.command})]})]}),!t&&(0,_.jsx)(`button`,{type:`button`,className:`btn bg-task-keep`,title:e.keep?C(`bgTaskKeepOn`):C(`bgTaskKeep`),"aria-pressed":!!e.keep,onClick:()=>c({type:`set_bg_keep`,port:e.port??0,keep:!e.keep}),children:e.keep?`📌`:`📍`}),(0,_.jsxs)(`button`,{type:`button`,className:`btn bg-task-stop`,title:C(`bgTaskStop`),onClick:()=>c(t?{type:`kill_background_server`,taskId:e.taskId}:{type:`kill_background_server`,port:e.port}),children:[(0,_.jsx)(o,{}),(0,_.jsx)(`span`,{children:C(`bgTaskStop`)})]})]},n)})}),O.map(e=>{let t=d.find(t=>t.id===e.source.slice(7));return e.kind===`view`?t?(0,_.jsx)(`div`,{children:(0,_.jsx)(h,{plugin:t,epoch:y,send:b??(()=>{})})},e.id):null:(0,_.jsx)(`button`,{type:`button`,className:`btn`,title:e.hint??e.label,onClick:()=>x?.(e),children:e.label},e.id)}),(0,_.jsxs)(`div`,{className:`bg-task-foot`,children:[(0,_.jsxs)(`div`,{className:`bg-task-cleanup-bar`,children:[(0,_.jsxs)(`label`,{className:`bg-task-cleanup-field`,title:C(`bgTaskCleanupHint`),children:[(0,_.jsx)(`span`,{className:`bg-task-cleanup-label`,children:C(`bgTaskCleanup`)}),(0,_.jsxs)(`select`,{className:`bg-task-cleanup-select`,value:String(S),onChange:e=>c({type:`set_settings`,bgAutoCleanupMin:Number(e.target.value)}),children:[(0,_.jsx)(`option`,{value:`0`,children:C(`bgTaskCleanupOff`)}),[15,30,60,120].map(e=>(0,_.jsx)(`option`,{value:String(e),children:C(`bgTaskCleanupMinutes`,{n:e})},e))]})]}),(0,_.jsxs)(`button`,{type:`button`,className:`btn bg-task-clean-btn`,title:C(`bgTaskCleanNowHint`),onClick:()=>c({type:`clean_bg_leftovers`}),children:[(0,_.jsx)(s,{}),(0,_.jsx)(`span`,{children:C(`bgTaskCleanNow`)})]})]}),(0,_.jsxs)(`div`,{className:`bg-task-actions-bar`,children:[(0,_.jsxs)(`button`,{type:`button`,className:`btn bg-task-refresh-btn`,title:C(`bgTaskRefresh`),onClick:()=>c({type:`list_bg_servers`}),children:[(0,_.jsx)(r,{}),(0,_.jsx)(`span`,{children:C(`bgTaskRefresh`)})]}),(0,_.jsxs)(`button`,{type:`button`,className:`btn bg-task-stopall`,disabled:e.length===0,title:C(`bgTaskStopAll`),onClick:()=>c({type:`kill_background_servers`}),children:[(0,_.jsx)(o,{}),(0,_.jsx)(`span`,{children:C(`bgTaskStopAll`)})]})]})]})]})}export{y as BgTasksModal};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Cn as t,Tn as n,Ut as r,an as i,hn as a,nn as o,sn as s,t as c,yt as l}from"./app-globals-CR8Ls9nE.js";import{i as u,t as d}from"./react-CR5VJ85Q.js";import{Rt as f,Vt as p,jt as m,z as h}from"./index-BBAQNi6v.js";var g=e(u(),1),_=d();function v(e,t){let n=Math.max(0,Date.now()-e),r=Math.floor(n/6e4);if(r<1)return t(`bgTaskJustNow`);if(r<60)return t(`bgTaskMinutes`,{n:r});let i=Math.floor(r/60);return i<24?t(`bgTaskHours`,{n:i}):t(`bgTaskDays`,{n:Math.floor(i/24)})}function y({servers:e,onClose:u,plugins:d=[],epoch:y=0,send:b,onUiAction:x,autoCleanupMin:S=0}){let C=n(),{locale:w}=t(),[T,E]=(0,g.useState)(new Set),D=e=>E(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n});(0,g.useEffect)(()=>{c({type:`list_bg_servers`})},[]);let O=(0,g.useMemo)(()=>(f(p(d),{locale:w,t:e=>C(e)})[`tasks.panel`]??[]).filter(e=>!e.hidden&&e.source!==`host`&&e.kind!==`divider`),[d,w,C]);return(0,_.jsxs)(m,{className:`bg-task-modal`,onClose:u,showCloseButton:!1,children:[(0,_.jsxs)(`div`,{className:`bg-task-head`,children:[(0,_.jsxs)(`span`,{className:`bg-task-title`,children:[(0,_.jsx)(l,{}),` `,C(`bgTasks`),e.length>0&&(0,_.jsx)(`em`,{className:`bg-task-count`,children:e.length})]}),(0,_.jsxs)(`div`,{className:`bg-task-head-actions`,children:[(0,_.jsx)(`button`,{type:`button`,className:`btn bg-task-head-btn`,title:C(`bgTaskRefresh`),onClick:()=>c({type:`list_bg_servers`}),children:(0,_.jsx)(r,{})}),(0,_.jsx)(`button`,{type:`button`,className:`btn bg-task-head-btn`,title:C(`close`),onClick:u,children:(0,_.jsx)(a,{})})]})]}),e.length===0?(0,_.jsxs)(`div`,{className:`bg-task-empty`,children:[(0,_.jsx)(l,{}),(0,_.jsx)(`span`,{children:C(`bgTasksEmpty`)}),(0,_.jsx)(`small`,{children:C(`bgTasksDesc`)})]}):(0,_.jsx)(`ul`,{className:`bg-task-list`,children:e.map(e=>{let t=!!e.taskId,n=e.taskId??String(e.port);return(0,_.jsxs)(`li`,{className:`bg-task-item`,children:[(0,_.jsx)(`span`,{className:`bg-task-icon`,title:t?e.plugin:C(`bgTaskPort`)}),(0,_.jsxs)(`div`,{className:`bg-task-info`,children:[(0,_.jsxs)(`div`,{className:`bg-task-line1`,children:[t?(0,_.jsxs)(`span`,{className:`bg-task-port`,title:e.taskId,children:[`🧩 `,e.plugin]}):(0,_.jsxs)(`span`,{className:`bg-task-port`,children:[`:`,e.port]}),e.name&&(0,_.jsx)(`span`,{className:`bg-task-name`,children:e.name})]}),(0,_.jsxs)(`div`,{className:`bg-task-line2`,children:[!t&&(0,_.jsxs)(`span`,{children:[C(`bgTaskPid`),` `,e.pid]}),(0,_.jsxs)(`span`,{children:[C(`bgTaskSince`),` `,v(e.since,C)]}),t&&e.status&&(0,_.jsx)(`span`,{className:`bg-task-status`,children:e.status})]}),e.command&&(0,_.jsxs)(`button`,{type:`button`,className:`bg-task-cmd ${T.has(n)?`open`:``}`,title:`${C(`bgTaskCommand`)}: ${e.command}`,onClick:()=>D(n),children:[(0,_.jsx)(i,{}),(0,_.jsx)(`code`,{children:e.command})]})]}),!t&&(0,_.jsx)(`button`,{type:`button`,className:`btn bg-task-keep`,title:e.keep?C(`bgTaskKeepOn`):C(`bgTaskKeep`),"aria-pressed":!!e.keep,onClick:()=>c({type:`set_bg_keep`,port:e.port??0,keep:!e.keep}),children:e.keep?`📌`:`📍`}),(0,_.jsxs)(`button`,{type:`button`,className:`btn bg-task-stop`,title:C(`bgTaskStop`),onClick:()=>c(t?{type:`kill_background_server`,taskId:e.taskId}:{type:`kill_background_server`,port:e.port}),children:[(0,_.jsx)(o,{}),(0,_.jsx)(`span`,{children:C(`bgTaskStop`)})]})]},n)})}),O.map(e=>{let t=d.find(t=>t.id===e.source.slice(7));return e.kind===`view`?t?(0,_.jsx)(`div`,{children:(0,_.jsx)(h,{plugin:t,epoch:y,send:b??(()=>{})})},e.id):null:(0,_.jsx)(`button`,{type:`button`,className:`btn`,title:e.hint??e.label,onClick:()=>x?.(e),children:e.label},e.id)}),(0,_.jsxs)(`div`,{className:`bg-task-foot`,children:[(0,_.jsxs)(`div`,{className:`bg-task-cleanup-bar`,children:[(0,_.jsxs)(`label`,{className:`bg-task-cleanup-field`,title:C(`bgTaskCleanupHint`),children:[(0,_.jsx)(`span`,{className:`bg-task-cleanup-label`,children:C(`bgTaskCleanup`)}),(0,_.jsxs)(`select`,{className:`bg-task-cleanup-select`,value:String(S),onChange:e=>c({type:`set_settings`,bgAutoCleanupMin:Number(e.target.value)}),children:[(0,_.jsx)(`option`,{value:`0`,children:C(`bgTaskCleanupOff`)}),[15,30,60,120].map(e=>(0,_.jsx)(`option`,{value:String(e),children:C(`bgTaskCleanupMinutes`,{n:e})},e))]})]}),(0,_.jsxs)(`button`,{type:`button`,className:`btn bg-task-clean-btn`,title:C(`bgTaskCleanNowHint`),onClick:()=>c({type:`clean_bg_leftovers`}),children:[(0,_.jsx)(s,{}),(0,_.jsx)(`span`,{children:C(`bgTaskCleanNow`)})]})]}),(0,_.jsxs)(`div`,{className:`bg-task-actions-bar`,children:[(0,_.jsxs)(`button`,{type:`button`,className:`btn bg-task-refresh-btn`,title:C(`bgTaskRefresh`),onClick:()=>c({type:`list_bg_servers`}),children:[(0,_.jsx)(r,{}),(0,_.jsx)(`span`,{children:C(`bgTaskRefresh`)})]}),(0,_.jsxs)(`button`,{type:`button`,className:`btn bg-task-stopall`,disabled:e.length===0,title:C(`bgTaskStopAll`),onClick:()=>c({type:`kill_background_servers`}),children:[(0,_.jsx)(o,{}),(0,_.jsx)(`span`,{children:C(`bgTaskStopAll`)})]})]})]})]})}export{y as BgTasksModal};
@@ -1,3 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$ as t,A as n,Bn as r,Cn as i,Fn as a,H as o,Ht as s,Pt as c,Qt as ee,Tn as l,Ut as u,Z as d,gt as f,hn as p,jn as te,kt as m,pn as h,pt as g,sn as _,wn as v,xt as y}from"./app-globals-CR8Ls9nE.js";import{i as b,t as ne}from"./react-CR5VJ85Q.js";import{K as re,Zt as x,v as S,xt as ie}from"./index-BYW9d61A.js";import{t as C}from"./DeviceExecutionSettings-B7R9ONaq.js";import{n as w,t as ae}from"./GroupWorkItems-FqAL74bC.js";var T=e(b(),1);async function E(e,t){let n=t.sleep??(e=>new Promise(t=>setTimeout(t,e))),r=Date.now()+(t.timeoutMs??18e5),i=e;if(!i||typeof i.id!=`string`||typeof i.fromBootId!=`string`)throw Error(`Invalid Hub upgrade response`);for(;;){if(t.isCurrent&&!t.isCurrent())throw new DOMException(`Hub upgrade view closed`,`AbortError`);if(i.id!==e.id)throw Error(`Hub upgrade job changed`);if(i.state===`failed`)throw Error(i.error||`Hub upgrade failed`);if(i.state===`succeeded`){if(!i.targetVersion||i.version!==i.targetVersion||!i.bootId||i.bootId===e.fromBootId)throw Error(`Hub upgrade result does not match the new version and process`);return i}if(i.state!==`queued`&&i.state!==`running`)throw Error(`Invalid Hub upgrade state`);if(Date.now()>=r)throw Error(`Hub upgrade timed out; inspect the Hub upgrade log`);if(await n(1500),t.isCurrent&&!t.isCurrent())throw new DOMException(`Hub upgrade view closed`,`AbortError`);try{i=await t.poll(e.id)}catch(e){let t=e.status;if(t&&t<500)throw e}}}var D=ne();function O(e){return!!e&&`mount`in e&&typeof e.mount==`function`}function k({plugin:e,epoch:t,onManageGroups:n}){let r=te(v()),[i,a]=(0,T.useState)(null),[o,s]=(0,T.useState)(!1),[c,ee]=(0,T.useState)(0),{id:l,name:u,version:d,hasClient:f,error:p,isolated:m}=e??{},h=(0,T.useMemo)(()=>l?{id:l,name:u??l,version:d,hasClient:f??!1,error:p,isolated:m}:void 0,[l,u,d,f,p,m]);(0,T.useEffect)(()=>{let e=!1;if(a(null),s(!1),h&&!h.error&&h.hasClient)return re(h,t,{retry:c>0}).then(t=>{e||(O(t)?a({info:h,module:t}):s(!0))}),()=>{e=!0}},[h,t,c]);let g=!h||!h.hasClient;return(0,D.jsxs)(`section`,{className:`dc-card`,"aria-label":r?`外部渠道配置`:`External channel settings`,children:[(0,D.jsxs)(`header`,{className:`dc-card-header`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h2`,{children:r?`GitHub / 飞书渠道`:`GitHub / Feishu channels`}),(0,D.jsx)(`p`,{children:r?`将外部事件映射到群组,由群组 AI 分派任务并跟进工单。`:`Map external events to a group. Its AI delegates tasks and follows up on work items.`})]}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:n,children:r?`管理群组与 AI`:`Manage groups & AI`})]}),g?(0,D.jsx)(`p`,{role:`status`,children:r?`内置渠道模块暂不可用,请重新加载页面或重启主程序。`:`The built-in channel module is temporarily unavailable. Reload this page or restart the application.`}):h.error?(0,D.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:h.error}):o?(0,D.jsxs)(`div`,{className:`dc-notice is-error`,role:`alert`,children:[(0,D.jsx)(`span`,{children:r?`渠道配置界面加载失败。`:`Channel settings failed to load.`}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>ee(e=>e+1),children:r?`重试`:`Retry`})]}):i?(0,D.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,minWidth:0,height:`min(72vh, 900px)`,minHeight:`360px`},children:(0,D.jsx)(S,{entry:i})}):(0,D.jsx)(`p`,{role:`status`,children:r?`正在加载渠道配置…`:`Loading channel settings…`})]})}function A({href:e,children:t}){let n=l(),[r,i]=(0,T.useState)(!1),[a,o]=(0,T.useState)(!1);return(0,D.jsxs)(D.Fragment,{children:[(0,D.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,D.jsxs)(`span`,{role:`alert`,children:[n(`deviceHubNetworkError`),` `,(0,D.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,children:e})]})]})}function j(e){if(!M(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 M(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 oe(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 N=`https://raw.githubusercontent.com/xing-shuyin/pi-web-ui/main/docs/device-center-deployment.md`,P=`https://github.com/xing-shuyin/pi-web-ui/blob/main/docs/device-center-deployment.md`,se=`pi-web-ui hub install --host 0.0.0.0 --port 8790 --public-url http://SERVER_IP:8790 --allow-registration`;function F(e){let t=e=>e.includes(`:`)?M(e)&&![`::`,`::1`].includes(e):/^[\d.]+$/.test(e)?M(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 I(e,t,n,r){if(!j(e))throw Error(`Invalid Hub setup`);if(r){let t=F(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: ${N} (fallback: ${P}). 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: ${se}`,`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 L({onConnect:e,initialHubUrl:t=``}){let n=l(),[i,o]=(0,T.useState)(t),[s,c]=(0,T.useState)(``),[ee,u]=(0,T.useState)(!1),[d,f]=(0,T.useState)(!1),p=(0,T.useRef)(!1),te=(0,T.useRef)(!1);(0,T.useEffect)(()=>(te.current=!0,()=>{te.current=!1}),[]);let[m,h]=(0,T.useState)(null),[g,_]=(0,T.useState)(`current`),[v,y]=(0,T.useState)(null),[b,ne]=(0,T.useState)(`127.0.0.1`),[re,x]=(0,T.useState)(`8790`),[S,ie]=(0,T.useState)(`http://127.0.0.1:8790`),[C,w]=(0,T.useState)({server:``,sshPort:22,username:`root`,auth:`password`,port:8790,domain:``,https:!1}),ae=F(C),[E,O]=(0,T.useState)(!1),[k,M]=(0,T.useState)(!1),[N,P]=(0,T.useState)(null),[se,L]=(0,T.useState)(!1),[R,ce]=(0,T.useState)(!1),[z,B]=(0,T.useState)(!1),[V,H]=(0,T.useState)(null),U=(0,T.useRef)(null),W=(0,T.useRef)(!1),G=oe(window.location.origin);(0,T.useEffect)(()=>()=>U.current?.abort(),[]);let K=async()=>{if(W.current)return;U.current?.abort();let e=new AbortController;U.current=e,L(!1),ce(!1),B(!1);try{let t=await fetch(r(a(`/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`||!j({host:`127.0.0.1`,port:n.defaultPort,publicUrl:n.defaultPublicUrl}))throw Error();if(e.signal.aborted)return;y(n),n.installation?.installed?(ne(n.installation.host??`127.0.0.1`),x(String(n.installation.port)),ie(n.installation.publicUrl??``),o(n.installation.publicUrl??``)):v||(x(String(n.defaultPort)),ie(n.defaultPublicUrl))}catch{e.signal.aborted||(L(!0),B(!0))}finally{e.signal.aborted||ce(!0)}},q=async()=>{let e={host:b,port:Number(re),publicUrl:S};if(W.current||!G||!v||!R||z||v.busy||v.installation?.installed||!j(e))return;W.current=!0,U.current?.abort(),O(!0),L(!1),c(``);let t=new AbortController;U.current=t;try{let n=await fetch(r(a(`/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){y(e=>e&&{...e,busy:!0}),W.current=!1,O(!1),await K();return}if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(typeof e.error==`string`?e.error.slice(0,4096):`HTTP ${n.status}`)}let i=await n.json();if(!j({...e,publicUrl:i.publicUrl})||typeof i.output!=`string`)throw Error();t.signal.aborted||H(i)}catch(e){t.signal.aborted||(L(!0),c(e instanceof Error?e.message.slice(0,4096):``))}finally{W.current=!1,t.signal.aborted||O(!1)}},le=async()=>{if(W.current||!G||!v||!R||z||v.busy||E||k)return;W.current=!0,U.current?.abort(),M(!0),L(!1),c(``),P(null);let e=new AbortController;U.current=e;try{let t=await fetch(r(a(`/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 i=await t.json();e.signal.aborted||(P(i.output||n(`deviceSetupUpdateSuccess`)),await K())}catch(t){e.signal.aborted||(L(!0),c(t instanceof Error?t.message.slice(0,4096):``))}finally{W.current=!1,e.signal.aborted||M(!1)}},J=v?.installation,ue=!!J?.installed,de=ue&&J.running&&J.owned,Y=g===`remote`?ae:{host:b,port:Number(re),publicUrl:S},X=!!Y&&j(Y);return(0,D.jsxs)(`section`,{className:`dc-onboarding`,children:[(0,D.jsx)(`h3`,{children:n(`deviceSetupWelcome`)}),(0,D.jsx)(`p`,{children:n(`deviceSetupIntro`)}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[(0,D.jsx)(`button`,{className:`dc-button`,disabled:E,"aria-pressed":m===`connect`,onClick:()=>h(`connect`),children:n(`deviceSetupConnect`)}),(0,D.jsx)(`button`,{className:`dc-button`,disabled:E,"aria-pressed":m===`create`,onClick:()=>{h(`create`),!v&&G&&K()},children:n(`deviceSetupCreate`)})]}),m===`connect`&&(0,D.jsxs)(`form`,{onSubmit:t=>{t.preventDefault(),e(i.trim())},children:[(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceHubHubUrl`)}),(0,D.jsx)(`input`,{type:`url`,required:!0,maxLength:2048,value:i,onChange:e=>o(e.target.value),placeholder:`https://hub.example.com`})]}),(0,D.jsx)(`button`,{className:`dc-button is-primary`,disabled:!j({host:`localhost`,port:8790,publicUrl:i.trim()}),children:n(`deviceSetupPair`)})]}),m===`create`&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupTarget`)}),(0,D.jsxs)(`select`,{disabled:E,value:g,onChange:e=>_(e.target.value),children:[(0,D.jsx)(`option`,{value:`current`,children:n(`deviceSetupCurrent`)}),(0,D.jsx)(`option`,{value:`remote`,children:n(`deviceSetupRemote`)})]})]}),(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`p`,{children:n(g===`current`?`deviceSetupCurrentHint`:`deviceSetupRemoteHint`)}),g===`current`&&(0,D.jsxs)(`div`,{className:`dc-setup-plan`,children:[(0,D.jsx)(`strong`,{children:n(`deviceSetupPlan`)}),(0,D.jsx)(`p`,{children:n(`deviceSetupPlanHint`)}),v&&(0,D.jsxs)(`dl`,{children:[(0,D.jsx)(`dt`,{children:n(`deviceSetupEnvironment`)}),(0,D.jsxs)(`dd`,{children:[v.platform,` · Node `,v.nodeVersion]}),(0,D.jsx)(`dt`,{children:n(`deviceSetupDataDir`)}),(0,D.jsx)(`dd`,{children:v.dataDir}),(0,D.jsx)(`dt`,{children:n(`deviceSetupCli`)}),(0,D.jsx)(`dd`,{children:v.cliPath})]}),!G&&(0,D.jsx)(`p`,{role:`status`,children:n(`deviceSetupLocalOnly`)}),(0,D.jsx)(`p`,{children:n(`deviceSetupBackground`)}),ue&&(0,D.jsxs)(`div`,{role:`status`,children:[(0,D.jsx)(`h4`,{children:n(de?`deviceSetupRestored`:`deviceSetupUnhealthy`)}),(0,D.jsx)(`p`,{children:J.publicUrl}),de&&X&&J.publicUrl?(0,D.jsxs)(`div`,{className:`dc-actions`,children:[(0,D.jsx)(A,{href:J.publicUrl,children:n(`deviceHubOpenHub`)}),(0,D.jsx)(`button`,{className:`dc-button`,onClick:()=>e(J.publicUrl),children:n(`deviceSetupPair`)}),G&&(0,D.jsx)(`button`,{className:`dc-button`,disabled:E||k,onClick:()=>void le(),children:n(k?`deviceSetupUpdating`:`deviceSetupUpdate`)})]}):(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`p`,{children:n(`deviceSetupRecovery`)}),(0,D.jsx)(`pre`,{className:`dc-setup-output`,children:`pi-web-ui hub status --json
3
- pi-web-ui hub --help`}),G&&(0,D.jsx)(`button`,{className:`dc-button is-primary`,disabled:E||k,onClick:()=>void le(),children:n(k?`deviceSetupUpdating`:`deviceSetupUpdate`)})]}),N&&(0,D.jsx)(`pre`,{className:`dc-setup-output`,children:N.slice(0,16e3)})]}),v?.busy&&(0,D.jsx)(`p`,{role:`status`,children:n(`deviceSetupBusy`)}),G&&(0,D.jsx)(`button`,{className:`dc-button`,disabled:E||!R,onClick:()=>void K(),children:n(R?`deviceSetupRetry`:`deviceHubWorking`)})]}),g===`remote`?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`div`,{className:`dc-setup-fields`,children:[(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupServer`)}),(0,D.jsx)(`input`,{autoComplete:`off`,maxLength:253,placeholder:`203.0.113.10`,value:C.server,onChange:e=>w({...C,server:e.target.value.trim()})})]}),(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupSshPort`)}),(0,D.jsx)(`input`,{type:`number`,min:1,max:65535,value:C.sshPort,onChange:e=>w({...C,sshPort:Number(e.target.value)})})]}),(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupUsername`)}),(0,D.jsx)(`input`,{autoComplete:`off`,maxLength:64,value:C.username,onChange:e=>w({...C,username:e.target.value})})]}),(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupAuth`)}),(0,D.jsxs)(`select`,{value:C.auth,onChange:e=>w({...C,auth:e.target.value}),children:[(0,D.jsx)(`option`,{value:`password`,children:n(`deviceSetupAuthPassword`)}),(0,D.jsx)(`option`,{value:`key`,children:n(`deviceSetupAuthKey`)}),(0,D.jsx)(`option`,{value:`existing`,children:n(`deviceSetupAuthExisting`)})]})]}),(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupServicePort`)}),(0,D.jsx)(`input`,{type:`number`,min:1024,max:65535,value:C.port,onChange:e=>w({...C,port:Number(e.target.value)})})]})]}),(0,D.jsx)(`p`,{children:n(`deviceSetupCredentialHint`)}),(0,D.jsxs)(`details`,{children:[(0,D.jsx)(`summary`,{children:n(`deviceSetupOptionalTls`)}),(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupDomain`)}),(0,D.jsx)(`input`,{maxLength:253,placeholder:`hub.example.com`,value:C.domain,onChange:e=>w({...C,domain:e.target.value.trim()})})]}),(0,D.jsxs)(`label`,{children:[(0,D.jsx)(`input`,{type:`checkbox`,checked:C.https,onChange:e=>w({...C,https:e.target.checked})}),` `,n(`deviceSetupEnableHttps`)]}),(0,D.jsx)(`p`,{children:n(`deviceSetupTlsHint`)})]}),(0,D.jsxs)(`p`,{children:[(0,D.jsx)(`strong`,{children:n(`deviceSetupPreview`)}),` `,ae?.publicUrl??n(`deviceSetupPreviewEmpty`)]}),(0,D.jsxs)(`div`,{className:`dc-setup-plan`,children:[(0,D.jsx)(`strong`,{children:n(`deviceSetupUserActions`)}),(0,D.jsx)(`p`,{children:n(`deviceSetupCloudPorts`).replace(`{ports}`,C.https?`443 / 80`:String(C.port))}),(0,D.jsx)(`p`,{children:n(`deviceSetupSourceScope`)}),(0,D.jsx)(`p`,{children:n(`deviceSetupAfterStart`)})]}),(0,D.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,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`div`,{className:`dc-setup-fields`,children:[(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupHost`)}),(0,D.jsx)(`input`,{disabled:E||!!V,maxLength:253,value:b,onChange:e=>ne(e.target.value)})]}),(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupPort`)}),(0,D.jsx)(`input`,{disabled:E||!!V,type:`number`,min:1024,max:65535,value:re,onChange:e=>x(e.target.value)})]}),(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceHubHubUrl`)}),(0,D.jsx)(`input`,{disabled:E||!!V,maxLength:2048,value:S,onChange:e=>ie(e.target.value)})]})]}),(0,D.jsx)(`p`,{className:`dc-setup-warning`,children:n(`deviceSetupReachable`)})]}),(0,D.jsx)(`p`,{children:n(`deviceSetupRegistration`)}),!X&&(0,D.jsx)(`p`,{role:`alert`,children:n(g===`remote`?`deviceSetupRemoteInvalid`:`deviceSetupInvalid`)}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[g===`current`&&!V&&!ue&&(0,D.jsx)(`button`,{className:`dc-button is-primary`,disabled:E||!G||!v||!R||z||!!v.busy||!X,onClick:()=>void q(),children:n(E?`deviceSetupInstalling`:`deviceSetupInstall`)}),(0,D.jsx)(`button`,{className:`dc-button`,disabled:E||ee||!X,onClick:()=>{if(!X||!Y||p.current)return;p.current=!0,u(!0),f(!1);let e=e=>{p.current=!1,te.current&&(u(!1),f(!e))},t=window.__piWebUiHost;try{t?.startChat({newChat:!0,prompt:I(Y,v,g,g===`remote`?C:void 0),onResult:e})||e(!1)}catch{e(!1)}},children:n(g===`remote`?`deviceSetupStartAi`:`deviceSetupAi`)})]}),(0,D.jsx)(`p`,{children:n(`deviceSetupAiHint`)}),ee&&(0,D.jsx)(`p`,{role:`status`,children:n(`deviceSetupAiCreating`)}),d&&(0,D.jsx)(`p`,{role:`alert`,children:n(`deviceSetupAiFailed`)})]})]}),se&&(0,D.jsxs)(`div`,{role:`alert`,children:[(0,D.jsx)(`p`,{children:n(`deviceSetupFailed`)}),s&&(0,D.jsx)(`pre`,{className:`dc-setup-output`,children:s})]}),V&&(0,D.jsxs)(`div`,{role:`status`,children:[(0,D.jsx)(`h4`,{children:n(`deviceSetupSuccess`)}),(0,D.jsx)(`pre`,{className:`dc-setup-output`,children:V.output.slice(0,16e3)}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[(0,D.jsx)(A,{href:V.publicUrl,children:n(`deviceHubOpenHub`)}),(0,D.jsx)(`button`,{className:`dc-button is-primary`,onClick:()=>e(V.publicUrl),children:n(`deviceSetupPair`)})]})]})]})}var R=`pi-web-ui:device-groups-changed`;function ce(e){window.dispatchEvent(new CustomEvent(`pi-web-ui:device-group-open`,{detail:{roomId:e}}))}async function z(e,t,n){let i=await fetch(r(a(`/api/device-center/${e}`)),{method:n?`POST`:`GET`,credentials:`same-origin`,signal:t,...n?{headers:{"Content-Type":`application/json`},body:JSON.stringify(n)}:{}}),o=await i.json().catch(()=>({}));if(!i.ok)throw Error(o.error||o.message||`Request failed (${i.status})`);return o}function B({bindingKey:e=``}){return(0,D.jsx)(V,{},e)}function V(){let{locale:e}=i(),t=te(e),[r,a]=(0,T.useState)([]),[o,c]=(0,T.useState)([]),[ee,l]=(0,T.useState)(!0),[f,g]=(0,T.useState)(``),[v,y]=(0,T.useState)(``),[b,ne]=(0,T.useState)(0),[re,x]=(0,T.useState)(!1),[S,ie]=(0,T.useState)(``),[C,E]=(0,T.useState)([]),[O,k]=(0,T.useState)(``),[A,j]=(0,T.useState)(null),[M,oe]=(0,T.useState)([]),[N,P]=(0,T.useState)(``),[se,F]=(0,T.useState)(null),[I,L]=(0,T.useState)(``),[B,V]=(0,T.useState)(!1),[H,U]=(0,T.useState)(null),W=r.find(e=>e.id===H?.roomId),G=(0,T.useRef)(0),K=(0,T.useRef)(null),q=(0,T.useRef)(null);function le(){++G.current,K.current?.abort(),ne(e=>e+1)}function J(){q.current?.abort();let e=new AbortController;return q.current=e,e}(0,T.useEffect)(()=>()=>q.current?.abort(),[]),(0,T.useEffect)(()=>{let e=++G.current,t=new AbortController;K.current=t;async function n(){try{let[n,r]=await Promise.all([z(`rooms`,t.signal),z(`bots`,t.signal)]);if(G.current!==e||t.signal.aborted)return;let i=Array.isArray(n.rooms)?n.rooms:[];a(i),U(e=>e&&i.some(t=>t.id===e.roomId)?e:null),c(Array.isArray(r.bots)?r.bots:[]),g(``)}catch(n){G.current===e&&!t.signal.aborted&&g(n instanceof Error?n.message:String(n))}finally{G.current===e&&!t.signal.aborted&&l(!1)}}return n(),()=>{t.abort()}},[b]),(0,T.useEffect)(()=>{let e=()=>le();return window.addEventListener(R,e),()=>window.removeEventListener(R,e)},[]);async function ue(e){if(e.preventDefault(),!S.trim()||B)return;V(!0),g(``),y(``);let n=J();try{let e=C.includes(O)?O:``,r=await z(`rooms`,n.signal,{name:S.trim(),botIds:C,...e?{primaryBotId:e}:{}});if(n.signal.aborted)return;a(e=>[...e.filter(e=>e.id!==r.room.id),r.room]),x(!1),ie(``),E([]),k(``),y(t?`群聊创建成功`:`Group created successfully`),window.dispatchEvent(new CustomEvent(R))}catch(e){n.signal.aborted||g(e instanceof Error?e.message:String(e))}finally{n.signal.aborted||V(!1)}}function de(e){j(e.id),oe([...e.botIds]),P(e.primaryBotId??``),F(null),x(!1),g(``),y(``)}async function Y(e){if(B)return;V(!0),g(``),y(``);let n=J();try{let r=M.includes(N)?N:null,i=await z(`rooms/${encodeURIComponent(e)}/members`,n.signal,{botIds:M,primaryBotId:r});if(n.signal.aborted)return;a(t=>t.map(t=>t.id===e?i.room:t)),j(null),y(t?`成员设置已保存`:`Members updated successfully`),window.dispatchEvent(new CustomEvent(R))}catch(e){n.signal.aborted||g(e instanceof Error?e.message:String(e))}finally{n.signal.aborted||V(!1)}}async function X(e){if(!I.trim()||B)return;V(!0),g(``),y(``);let n=J();try{if(await z(`rooms/${encodeURIComponent(e)}/rename`,n.signal,{name:I.trim()}),n.signal.aborted)return;a(t=>t.map(t=>t.id===e?{...t,name:I.trim()}:t)),F(null),y(t?`群聊名称已更新`:`Group renamed successfully`),window.dispatchEvent(new CustomEvent(R))}catch(e){n.signal.aborted||g(e instanceof Error?e.message:String(e))}finally{n.signal.aborted||V(!1)}}async function Z(e){if(B||!window.confirm(t?`确定删除群聊“${e.name}”?`:`Are you sure you want to delete "${e.name}"?`))return;V(!0),g(``),y(``);let n=J();try{if(await z(`rooms/${encodeURIComponent(e.id)}/delete`,n.signal,{}),n.signal.aborted)return;U(t=>t?.roomId===e.id?null:t),a(t=>t.filter(t=>t.id!==e.id)),A===e.id&&j(null),se===e.id&&F(null),y(t?`群聊已删除`:`Group deleted successfully`),window.dispatchEvent(new CustomEvent(R))}catch(e){n.signal.aborted||g(e instanceof Error?e.message:String(e))}finally{n.signal.aborted||V(!1)}}return(0,D.jsxs)(`section`,{className:`dc-card`,"aria-label":t?`群聊列表`:`Group list`,children:[(0,D.jsxs)(`div`,{className:`dc-card-header`,children:[(0,D.jsx)(`span`,{className:`dc-icon`,children:(0,D.jsx)(h,{"aria-hidden":!0})}),(0,D.jsxs)(`div`,{children:[(0,D.jsxs)(`h2`,{children:[t?`群聊列表`:`Group List`,` · `,r.length]}),(0,D.jsx)(`p`,{children:t?`管理群聊与成员 Bot,在此配置协作群组或直接进入聊天。`:`Manage groups and member Bots. Configure collaboration groups or open chats here.`})]}),(0,D.jsxs)(`div`,{className:`dc-actions`,style:{marginInlineStart:`auto`},children:[(0,D.jsxs)(`button`,{type:`button`,className:`dc-button is-primary`,disabled:B,onClick:()=>{x(e=>!e),j(null),F(null),ie(``),E([]),k(``)},children:[(0,D.jsx)(s,{"aria-hidden":!0}),t?`新建群聊`:`Create Group`]}),(0,D.jsx)(`button`,{type:`button`,className:`dc-icon-button`,"aria-label":t?`刷新群聊`:`Refresh groups`,onClick:le,children:(0,D.jsx)(u,{})})]})]}),f&&(0,D.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:f}),v&&(0,D.jsxs)(`p`,{className:`dc-notice is-success`,role:`status`,children:[(0,D.jsx)(n,{"aria-hidden":!0}),v]}),re&&(0,D.jsxs)(`form`,{className:`dc-card`,style:{marginBottom:`16px`,background:`var(--bg)`,border:`1px solid var(--border)`},onSubmit:ue,children:[(0,D.jsxs)(`div`,{className:`dg-heading`,style:{marginBottom:`12px`},children:[(0,D.jsx)(`h3`,{children:t?`新建群聊`:`Create Group`}),(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>x(!1),disabled:B,children:[(0,D.jsx)(p,{"aria-hidden":!0}),t?`关闭`:`Close`]})]}),(0,D.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`12px`},children:[(0,D.jsx)(`label`,{htmlFor:`dg-manager-new-name`,children:t?`群名称`:`Group Name`}),(0,D.jsx)(`input`,{id:`dg-manager-new-name`,type:`text`,required:!0,maxLength:80,value:S,placeholder:t?`输入群名称,如:研发协作群`:`Enter group name`,onChange:e=>ie(e.target.value),disabled:B,style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`}})]}),(0,D.jsxs)(`div`,{style:{marginBottom:`12px`},children:[(0,D.jsx)(`label`,{style:{display:`block`,marginBottom:`6px`,fontSize:`12px`,color:`var(--text-dim)`},children:t?`选择成员 Bot`:`Select Member Bots`}),(0,D.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,D.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,D.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,cursor:`pointer`,fontSize:`12px`},children:[(0,D.jsx)(`input`,{type:`checkbox`,checked:C.includes(e.id),disabled:B||!e.enabled,onChange:t=>{E(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}}),(0,D.jsxs)(`span`,{children:[(0,D.jsx)(`strong`,{children:e.name}),(0,D.jsxs)(`small`,{style:{color:`var(--text-faint)`,marginInlineStart:`6px`},children:[e.online?t?`在线`:`Online`:t?`离线`:`Offline`,e.enabled?``:t?` · 已禁用`:` · Disabled`]})]})]},e.id))})]}),C.length>0&&(0,D.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`16px`},children:[(0,D.jsx)(`label`,{htmlFor:`dg-manager-new-primary`,children:t?`原主 Bot(Router 未启用时)`:`Legacy primary Bot (when Router is disabled)`}),(0,D.jsxs)(`select`,{id:`dg-manager-new-primary`,value:C.includes(O)?O:``,onChange:e=>k(e.target.value),disabled:B,style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`},children:[(0,D.jsx)(`option`,{value:``,children:t?`不设置(需 @ Bot)`:`None (mention a Bot)`}),o.filter(e=>C.includes(e.id)).map(e=>(0,D.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[(0,D.jsxs)(`button`,{type:`submit`,className:`dc-button is-primary`,disabled:B||!S.trim(),children:[(0,D.jsx)(n,{"aria-hidden":!0}),B?t?`创建中…`:`Creating…`:t?`创建群聊`:`Create`]}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>x(!1),disabled:B,children:t?`取消`:`Cancel`})]})]}),A&&(0,D.jsxs)(`div`,{className:`dc-card`,style:{marginBottom:`16px`,background:`var(--bg)`,border:`1px solid var(--border)`},children:[(0,D.jsxs)(`div`,{className:`dg-heading`,style:{marginBottom:`12px`},children:[(0,D.jsxs)(`h3`,{children:[t?`管理成员`:`Manage Members`,` · `,r.find(e=>e.id===A)?.name]}),(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>j(null),disabled:B,children:[(0,D.jsx)(p,{"aria-hidden":!0}),t?`关闭`:`Close`]})]}),(0,D.jsxs)(`div`,{style:{marginBottom:`12px`},children:[(0,D.jsx)(`label`,{style:{display:`block`,marginBottom:`6px`,fontSize:`12px`,color:`var(--text-dim)`},children:t?`选择成员 Bot`:`Select Member Bots`}),(0,D.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,D.jsx)(`p`,{style:{margin:0,fontSize:`12px`,color:`var(--text-faint)`},children:t?`暂无可用 Bot`:`No Bots available`}):o.map(e=>(0,D.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,cursor:`pointer`,fontSize:`12px`},children:[(0,D.jsx)(`input`,{type:`checkbox`,checked:M.includes(e.id),disabled:B,onChange:t=>{oe(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}}),(0,D.jsxs)(`span`,{children:[(0,D.jsx)(`strong`,{children:e.name}),(0,D.jsxs)(`small`,{style:{color:`var(--text-faint)`,marginInlineStart:`6px`},children:[e.online?t?`在线`:`Online`:t?`离线`:`Offline`,e.enabled?``:t?` · 已禁用`:` · Disabled`]})]})]},e.id))})]}),!r.find(e=>e.id===A)?.router?.enabled&&(0,D.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`16px`},children:[(0,D.jsx)(`label`,{htmlFor:`dg-manager-edit-primary`,children:t?`原主 Bot(Router 未启用时)`:`Legacy primary Bot (when Router is disabled)`}),(0,D.jsxs)(`select`,{id:`dg-manager-edit-primary`,value:M.includes(N)?N:``,onChange:e=>P(e.target.value),disabled:B,style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`},children:[(0,D.jsx)(`option`,{value:``,children:t?`不设置(需 @ Bot)`:`None (mention a Bot)`}),o.filter(e=>M.includes(e.id)).map(e=>(0,D.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[(0,D.jsxs)(`button`,{type:`button`,className:`dc-button is-primary`,disabled:B,onClick:()=>void Y(A),children:[(0,D.jsx)(n,{"aria-hidden":!0}),B?t?`保存中…`:`Saving…`:t?`保存成员设置`:`Save Members`]}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>j(null),disabled:B,children:t?`取消`:`Cancel`})]})]}),ee&&(0,D.jsx)(`p`,{role:`status`,children:t?`加载中…`:`Loading…`}),!ee&&r.length===0&&(0,D.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,D.jsx)(`div`,{className:`dd-list`,children:r.map(e=>{let r=se===e.id,i=o.filter(t=>e.botIds.includes(t.id)),a=o.find(t=>t.id===e.primaryBotId);return(0,D.jsxs)(`div`,{className:`dd-device`,style:r?{flexWrap:`wrap`}:void 0,children:[(0,D.jsx)(`span`,{className:`dc-device-icon`,children:(0,D.jsx)(h,{"aria-hidden":!0})}),(0,D.jsxs)(`div`,{className:`dd-identity`,style:{flex:1,minWidth:`200px`},children:[(0,D.jsx)(`strong`,{children:e.name}),(0,D.jsxs)(`span`,{style:{display:`flex`,gap:`8px`,flexWrap:`wrap`,alignItems:`center`},children:[(0,D.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(`, `)}`:``}`}),e.router?.enabled&&(0,D.jsxs)(`span`,{children:[`AI Router · `,e.router.deviceId,` · `,e.router.model,` · `,e.router.thinkingLevel]}),!e.router?.enabled&&a&&(0,D.jsx)(`span`,{style:{color:`var(--accent)`},children:t?`[主 Bot: ${a.name}]`:`[Primary: ${a.name}]`})]})]}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[(0,D.jsxs)(`button`,{type:`button`,className:`dc-button is-primary`,title:t?`打开聊天`:`Open chat`,onClick:()=>ce(e.id),children:[(0,D.jsx)(m,{"aria-hidden":!0}),t?`打开聊天`:`Open chat`]}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button`,"aria-expanded":H?.roomId===e.id&&H.kind===`router`,onClick:()=>U({roomId:e.id,kind:`router`}),children:`AI Router`}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button`,"aria-expanded":H?.roomId===e.id&&H.kind===`work`,onClick:()=>U({roomId:e.id,kind:`work`}),children:t?`工单与运行`:`Work items & runs`}),(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,title:t?`管理成员`:`Manage members`,onClick:()=>de(e),children:[(0,D.jsx)(h,{"aria-hidden":!0}),t?`管理成员`:`Members`]}),(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,title:t?`重命名`:`Rename`,onClick:()=>{r?F(null):(F(e.id),L(e.name))},children:[(0,D.jsx)(d,{"aria-hidden":!0}),t?`重命名`:`Rename`]}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button is-danger`,title:t?`删除群聊`:`Delete group`,disabled:B,onClick:()=>void Z(e),children:(0,D.jsx)(_,{"aria-hidden":!0})})]}),r&&(0,D.jsxs)(`form`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,width:`100%`,paddingTop:`8px`,paddingBottom:`4px`},onSubmit:t=>{t.preventDefault(),X(e.id)},children:[(0,D.jsx)(`input`,{type:`text`,maxLength:80,autoFocus:!0,disabled:B,value:I,onChange:e=>L(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,D.jsxs)(`button`,{type:`submit`,className:`dc-button is-primary`,disabled:B||!I.trim(),children:[(0,D.jsx)(n,{"aria-hidden":!0}),t?`保存`:`Save`]}),(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:B,onClick:()=>F(null),children:[(0,D.jsx)(p,{"aria-hidden":!0}),t?`取消`:`Cancel`]})]})]},e.id)})}),W&&H&&(0,D.jsxs)(`section`,{className:`dc-card`,"aria-label":t?`群组设置`:`Group settings`,children:[(0,D.jsxs)(`div`,{className:`dg-heading`,children:[(0,D.jsx)(`h3`,{children:W.name}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[(0,D.jsx)(`button`,{type:`button`,className:`dc-button${H.kind===`router`?` is-primary`:``}`,"aria-pressed":H.kind===`router`,onClick:()=>U({roomId:W.id,kind:`router`}),children:`AI Router`}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button${H.kind===`work`?` is-primary`:``}`,"aria-pressed":H.kind===`work`,onClick:()=>U({roomId:W.id,kind:`work`}),children:t?`工单与运行`:`Work items & runs`}),(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>U(null),children:[(0,D.jsx)(p,{"aria-hidden":!0}),t?`关闭`:`Close`]})]})]}),H.kind===`router`?(0,D.jsx)(w,{roomId:W.id,router:W.router,disabled:B,onSaved:le},W.id):(0,D.jsx)(ae,{roomId:W.id,disabled:B},W.id)]})]})}var H=class extends Error{status;constructor(e,t){super(t),this.status=e}};function U(e){try{let t=new URL(e);return[`http:`,`https:`].includes(t.protocol)&&!t.username&&!t.password?t.href:null}catch{return null}}function W(){let e=l(),t=v().startsWith(`zh`),[n,i]=(0,T.useState)(null),[o,s]=(0,T.useState)(!1),[ee,d]=(0,T.useState)(!1),[f,p]=(0,T.useState)(!1),[te,m]=(0,T.useState)(!1),h=(0,T.useRef)(0),g=(0,T.useRef)(null);async function _(e,t){if(g.current)return;let n=++h.current,o=new AbortController;g.current=o,s(!0),d(!1);try{let s=await fetch(r(a(`/api/device-desktop/local/${e}`)),{method:t?`POST`:`GET`,credentials:`same-origin`,signal:o.signal,...t?{headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}:{}});if(h.current!==n||o.signal.aborted)return;if(s.status===403){p(!0),i(null);return}if(!s.ok)throw Error(`Request failed`);let c=await s.json();if(h.current!==n||o.signal.aborted)return;if(e===`permissions`){if(typeof c?.screen!=`boolean`||typeof c?.accessibility!=`boolean`)throw Error(`Invalid permission status`);i(e=>e&&{...e,permissions:{supported:!0,screen:c.screen,accessibility:c.accessibility}}),m(!0)}else{if(typeof c?.os!=`string`||typeof c.enabled!=`boolean`||typeof c.environmentEnabled!=`boolean`||typeof c.supported!=`boolean`)throw Error(`Invalid desktop status`);i(c)}}catch{h.current===n&&!o.signal.aborted&&d(!0)}finally{h.current===n&&!o.signal.aborted&&(g.current=null,s(!1))}}return(0,T.useEffect)(()=>(_(`status`),()=>{h.current++,g.current?.abort(),g.current=null}),[]),(0,D.jsxs)(`section`,{className:`dc-card`,"aria-label":t?`本机远程桌面`:`Local remote desktop`,"aria-busy":o,children:[(0,D.jsxs)(`div`,{className:`dc-card-header`,children:[(0,D.jsx)(`span`,{className:`dc-icon`,children:(0,D.jsx)(c,{"aria-hidden":!0})}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h2`,{children:t?`本机远程桌面`:`Local remote desktop`}),(0,D.jsx)(`p`,{children:t?`管理这台设备的远程桌面与系统权限,无需连接设备中心。`:`Manage remote desktop and system permissions on this device, even while the device center is offline.`})]})]}),f?(0,D.jsx)(`p`,{role:`status`,children:t?`请在设备本机打开此页面以管理远程桌面权限。`:`Open this page on the device itself to manage remote desktop permissions.`}):(0,D.jsxs)(D.Fragment,{children:[n&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`div`,{className:`dc-permission-row`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h3`,{id:`dc-desktop-label`,children:t?`启用远程桌面`:`Enable remote desktop`}),(0,D.jsx)(`p`,{children:n.enabled?t?`已启用`:`Enabled`:t?`未启用`:`Disabled`})]}),(0,D.jsx)(`button`,{type:`button`,className:`dc-toggle${n.enabled?` is-on`:``}`,role:`switch`,"aria-checked":n.enabled,"aria-labelledby":`dc-desktop-label`,disabled:o||n.environmentEnabled||!n.supported&&!n.enabled,onClick:()=>void _(`enable`,{enabled:!n.enabled}),children:(0,D.jsx)(`span`,{className:`dc-toggle-thumb`})})]}),!n.supported&&(0,D.jsx)(`p`,{children:t?`这台设备暂不支持远程桌面。`:`Remote desktop is currently unavailable on this device.`}),n.environmentEnabled&&(0,D.jsx)(`p`,{children:t?`远程桌面由本机服务设置保持启用。`:`Remote desktop is kept enabled by the service settings on this device.`}),n.os===`darwin`&&(0,D.jsxs)(D.Fragment,{children:[(0,D.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,D.jsxs)(`div`,{className:`dc-actions`,children:[(0,D.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:o||n.permissions?.supported===!1,onClick:()=>void _(`permissions`,{kind:`screen`}),children:t?`授予屏幕录制权限`:`Grant screen recording permission`}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:o||n.permissions?.supported===!1,onClick:()=>void _(`permissions`,{kind:`control`}),children:t?`授予远程控制权限`:`Grant remote control permission`})]}),n.permissions?.screen===!0&&(0,D.jsx)(`p`,{children:t?`屏幕录制:已授权`:`Screen recording: granted`}),n.permissions?.accessibility===!0&&(0,D.jsx)(`p`,{children:t?`远程控制:已授权`:`Remote control: granted`}),te&&(0,D.jsx)(`p`,{role:`status`,children:t?`已发起授权请求,请确认系统设置后刷新状态。`:`Permission requested. Confirm in System Settings, then refresh the status.`})]})]}),ee&&(0,D.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:t?`无法更新本机远程桌面设置,请重试。`:`Unable to update local remote desktop settings. Please retry.`}),(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:o,onClick:()=>void _(`status`),children:[(0,D.jsx)(u,{"aria-hidden":!0}),o?e(`deviceHubWorking`):t?`刷新远程桌面状态`:`Refresh remote desktop status`]})]})]})}function G({pathCompletions:e=[],plugins:i=[],pluginsEpoch:s=0}){let d=l(),p=te(v()),[m,_]=(0,T.useState)(`devices`),[b,ne]=(0,T.useState)(null),[re,S]=(0,T.useState)(``),[w,ae]=(0,T.useState)(``),[O,j]=(0,T.useState)(null),[M,oe]=(0,T.useState)(Date.now()),[N,P]=(0,T.useState)(null),[se,F]=(0,T.useState)(``),[I,R]=(0,T.useState)(``),[ce,z]=(0,T.useState)(``),[V,G]=(0,T.useState)(!1),K=(0,T.useRef)(!1),[q,le]=(0,T.useState)(!1),[J,ue]=(0,T.useState)(!0),de=(0,T.useRef)(!1),Y=(0,T.useRef)(0),X=(0,T.useRef)(new Set),Z=(0,T.useRef)(!1),fe=(0,T.useRef)(!1),pe=(0,T.useRef)(null),me=(0,T.useRef)(d);me.current=d,(0,T.useEffect)(()=>{let e=e=>{let t=e;t.detail?.deviceId&&pe.current?.deviceId===t.detail.deviceId&&(ne(e=>e&&{...e,remark:t.detail.remark}),pe.current&&(pe.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 he(e,t){let n=new AbortController;X.current.add(n);try{let i=await fetch(r(a(`/api/device-center/${e}`)),{method:t?`POST`:`GET`,credentials:`same-origin`,signal:n.signal,...t?{headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}:{}}),o=await i.json().catch(()=>({}));if(!i.ok)throw new H(i.status,typeof o.error==`string`?o.error:me.current(`deviceHubRequestFailed`,{status:i.status}));return o}finally{X.current.delete(n)}}function Q(e){return de.current&&Y.current===e}function ge(e){return e instanceof H&&e.status===403?(le(!0),me.current(`deviceHubLocalOnly`)):e instanceof Error?e.message:me.current(`deviceHubNetworkError`)}function _e(e){pe.current=e,ne(e),fe.current||(ae(e.name),S(e.hubUrl??``))}async function ve(){let e=Y.current;try{let t=await he(`status`);if(!Q(e)||Z.current)return;_e(t),R(``),le(!1)}catch(t){Q(e)&&R(ge(t))}finally{Q(e)&&ue(!1)}}(0,T.useEffect)(()=>{de.current=!0;let e=!1,t,n=async()=>{await ve(),!e&&de.current&&(t=setTimeout(n,5e3))};return n(),()=>{e=!0,de.current=!1,Y.current++,clearTimeout(t);for(let e of X.current)e.abort()}},[]),(0,T.useEffect)(()=>{if(!O)return;let e=Y.current,t=!1,n,r=setInterval(()=>oe(Date.now()),1e3),i=async()=>{if(!(t||!Q(e)||Date.now()>=O.expiresAt)){try{let n=await he(`poll`,{});if(t||!Q(e))return;if(n.paired){let n=await he(`status`);if(t||!Q(e))return;fe.current=!1,_e(n),j(null),F(``),z(``);return}F(``)}catch(n){!t&&Q(e)&&F(`${me.current(`deviceHubPollError`)} ${ge(n)}`)}!t&&Q(e)&&(n=setTimeout(i,2e3))}};return n=setTimeout(i,2e3),()=>{t=!0,clearTimeout(n),clearInterval(r)}},[O]);async function ye(){if(Z.current)return;let e=U(re.trim());if(!e){F(d(`deviceHubInvalidUrl`));return}if(!w.trim()||w.trim().length>80){F(d(`deviceHubInvalidName`));return}let t=++Y.current;Z.current=!0,P(`pair`),F(``),z(``),j(null);try{let n=await he(`pair`,{hubUrl:e,name:w.trim()});if(!Q(t))return;if(!n.code||!Number.isFinite(n.expiresAt)||!U(n.hubUrl))throw Error(d(`deviceHubPairError`));oe(Date.now()),j(n)}catch(e){Q(t)&&F(`${d(`deviceHubPairError`)} ${ge(e)}`)}finally{Q(t)&&(Z.current=!1,P(null))}}async function be(){let e=pe.current;if(!e?.deviceId||Z.current)return;let t=++Y.current;Z.current=!0,P(`permission`),F(``),z(``),_e({...e,allowExecution:!e.allowExecution});try{await he(`execution`,{allowExecution:!e.allowExecution}),Q(t)&&z(d(`deviceHubSaved`))}catch(n){Q(t)&&(_e(e),F(`${d(`deviceHubPermissionError`)} ${ge(n)}`))}finally{Q(t)&&(Z.current=!1,P(null))}}async function xe(){let e=pe.current;if(!e?.deviceId||Z.current||!window.confirm(d(`deviceHubDisconnectConfirm`,{name:e.name})))return;let t=++Y.current;Z.current=!0,P(`disconnect`),F(``),z(``);try{if(await he(`disconnect`,{}),!Q(t))return;fe.current=!1,_e({name:e.name,allowExecution:!1,connected:!1}),j(null)}catch(e){Q(t)&&F(`${d(`deviceHubDisconnectError`)} ${ge(e)}`)}finally{Q(t)&&(Z.current=!1,P(null))}}async function Se(){if(K.current||N||!$||!b?.hubUrl||!window.confirm(d(`deviceHubConfirmUpgrade`)))return;let e=Y.current;K.current=!0,G(!0),F(``),z(``);try{let t=await he(`upgrade-hub`,{});if(!t.ok)throw Error(`Hub upgrade was not accepted`);await E(t.job,{isCurrent:()=>Q(e),poll:async e=>(await he(`upgrade-hub-status`,{id:e})).job}),Q(e)&&(z(d(`deviceHubUpgradeSuccess`)),await ve())}catch(t){Q(e)&&F(t instanceof Error?t.message:d(`deviceHubNetworkError`))}finally{K.current=!1,Q(e)&&G(!1)}}async function Ce(){if(!O)return;let e=Y.current;try{await navigator.clipboard.writeText(O.code),Q(e)&&z(d(`deviceHubCopied`))}catch{Q(e)&&F(d(`deviceHubCopyFailed`))}}let $=!!b?.deviceId,we=U($?b?.hubUrl??``:O?.hubUrl??``),Te=Math.max(0,Math.ceil(((O?.expiresAt??0)-M)/1e3)),Ee=`${Math.floor(Te/60)}:${String(Te%60).padStart(2,`0`)}`,De=we?(0,D.jsxs)(A,{href:we,children:[(0,D.jsx)(t,{"aria-hidden":!0}),d(`deviceHubOpenHub`)]}):null;return(0,D.jsxs)(`section`,{className:`dc-page`,"aria-label":d(`deviceHubTitle`),children:[(0,D.jsxs)(`header`,{className:`dc-header`,children:[(0,D.jsxs)(`div`,{className:`dc-heading`,children:[(0,D.jsxs)(`span`,{className:`dc-eyebrow`,children:[(0,D.jsx)(c,{"aria-hidden":!0}),d(`deviceHubTitle`)]}),(0,D.jsx)(`h1`,{children:d(`deviceHubTitle`)}),(0,D.jsx)(`p`,{children:d(`deviceHubSubtitle`)})]}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[$&&De,(0,D.jsxs)(`span`,{className:`dc-status ${$?b?.connected?`is-online`:`is-offline`:`is-unpaired`}`,children:[(0,D.jsx)(`span`,{className:`dc-status-dot`}),d($?b?.connected?`deviceHubOnline`:`deviceHubOffline`:`deviceHubUnpaired`)]})]})]}),(0,D.jsxs)(`div`,{className:`dc-layout`,children:[(0,D.jsx)(`nav`,{className:`dc-sidebar`,"aria-label":p?`设备与协作导航`:`Devices and collaboration`,children:[[`devices`,c,p?`设备与连接`:`Devices & connections`],[`groups`,h,p?`群组与工单`:`Groups & work items`],[`channels`,f,p?`外部渠道`:`External channels`]].map(([e,t,n])=>(0,D.jsxs)(`button`,{type:`button`,className:`dc-nav-item${m===e?` is-active`:``}`,"aria-pressed":m===e,onClick:()=>_(e),children:[(0,D.jsx)(t,{"aria-hidden":!0}),n]},e))}),(0,D.jsxs)(`main`,{className:`dc-content`,children:[J&&(0,D.jsxs)(`div`,{className:`dc-loading`,role:`status`,children:[(0,D.jsx)(u,{"aria-hidden":!0}),d(`deviceHubLoading`)]}),(q||I)&&(0,D.jsxs)(`div`,{className:`dc-notice is-error`,role:`alert`,children:[(0,D.jsx)(`span`,{children:q?d(`deviceHubLocalOnly`):`${d(`deviceHubStatusError`)} ${I}`}),(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>void ve(),children:[(0,D.jsx)(u,{"aria-hidden":!0}),d(`deviceHubRetry`)]})]}),se&&!q&&(0,D.jsx)(`div`,{className:`dc-notice is-error`,role:`alert`,children:se}),ce&&(0,D.jsxs)(`div`,{className:`dc-notice is-success`,role:`status`,children:[(0,D.jsx)(n,{"aria-hidden":!0}),ce]}),m!==`devices`&&(!$||q)&&(0,D.jsxs)(`section`,{className:`dc-card`,children:[(0,D.jsx)(`h2`,{children:m===`groups`?p?`群组与工单`:`Groups & work items`:p?`外部渠道`:`External channels`}),(0,D.jsx)(`p`,{children:p?`先连接设备中心,再创建群组、配置群组 AI 并接入外部渠道。`:`Connect to a device hub before creating groups, configuring group AI, and connecting external channels.`}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button is-primary`,onClick:()=>_(`devices`),children:p?`前往设备连接`:`Connect a device`})]}),m===`groups`&&$&&!q&&(0,D.jsx)(B,{},`groups:${b?.hubUrl??``}:${b?.deviceId??``}`),m===`channels`&&$&&!q&&(0,D.jsx)(k,{plugin:i.find(e=>e.id===`superagent`),epoch:s,onManageGroups:()=>_(`groups`)},`channels:${b?.hubUrl??``}:${b?.deviceId??``}`),m===`devices`&&(0,D.jsxs)(D.Fragment,{children:[!$&&(b||q)&&(0,D.jsx)(L,{initialHubUrl:re,onConnect:e=>{if(q){z(d(`deviceHubLocalOnly`));return}fe.current=!0,S(e)}}),b&&!q&&!$&&(0,D.jsxs)(`section`,{className:`dc-card`,children:[(0,D.jsxs)(`div`,{className:`dc-card-header`,children:[(0,D.jsx)(`span`,{className:`dc-icon`,children:(0,D.jsx)(y,{"aria-hidden":!0})}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h2`,{children:d(`deviceHubPairTitle`)}),(0,D.jsx)(`p`,{children:d(`deviceHubPairHint`)})]})]}),(0,D.jsx)(`ol`,{className:`dc-steps`,children:[`deviceHubStepDetails`,`deviceHubStepApprove`,`deviceHubStepWait`].map((e,t)=>(0,D.jsxs)(`li`,{className:O?t===0?`is-complete`:`is-active`:t===0?`is-active`:``,children:[(0,D.jsx)(`span`,{className:`dc-step-number`,children:O&&t===0?(0,D.jsx)(n,{"aria-hidden":!0}):t+1}),(0,D.jsx)(`span`,{children:d(e)})]},e))}),(0,D.jsxs)(`form`,{className:`dc-form`,onSubmit:e=>{e.preventDefault(),ye()},children:[(0,D.jsxs)(`div`,{className:`dc-field`,children:[(0,D.jsx)(`label`,{htmlFor:`dc-hub-url`,children:d(`deviceHubHubUrl`)}),(0,D.jsx)(`input`,{id:`dc-hub-url`,type:`url`,autoComplete:`url`,required:!0,placeholder:d(`deviceHubHubPlaceholder`),value:re,disabled:!!O||!!N,onChange:e=>{fe.current=!0,S(e.target.value)}})]}),(0,D.jsxs)(`div`,{className:`dc-field`,children:[(0,D.jsx)(`label`,{htmlFor:`dc-device-name`,children:d(`deviceHubName`)}),(0,D.jsx)(`input`,{id:`dc-device-name`,maxLength:80,required:!0,autoComplete:`off`,placeholder:d(`deviceHubNamePlaceholder`),value:w,disabled:!!O||!!N,onChange:e=>{fe.current=!0,ae(e.target.value)}})]}),!O&&(0,D.jsx)(`div`,{className:`dc-actions`,children:(0,D.jsxs)(`button`,{className:`dc-button is-primary`,type:`submit`,disabled:!!N,children:[(0,D.jsx)(y,{"aria-hidden":!0}),d(N?`deviceHubWorking`:`deviceHubGetCode`)]})})]}),O&&(0,D.jsxs)(`div`,{className:`dc-pairing`,children:[(0,D.jsx)(`span`,{className:`dc-code-label`,children:d(`deviceHubCode`)}),(0,D.jsxs)(`div`,{className:`dc-code-row`,children:[(0,D.jsx)(`code`,{className:`dc-code`,children:O.code}),(0,D.jsx)(`button`,{className:`dc-icon-button`,type:`button`,"aria-label":d(`deviceHubCopy`),onClick:()=>void Ce(),children:(0,D.jsx)(o,{"aria-hidden":!0})})]}),(0,D.jsx)(`div`,{className:`dc-pair-meta`,children:d(Te?`deviceHubExpires`:`deviceHubExpired`,{time:Ee})}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[De,(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:!!N,onClick:()=>{++Y.current,j(null),F(``),z(``)},children:[(0,D.jsx)(u,{"aria-hidden":!0}),d(`deviceHubNewCode`)]})]}),Te>0&&(0,D.jsxs)(`p`,{className:`dc-progress`,role:`status`,children:[(0,D.jsx)(u,{"aria-hidden":!0}),d(`deviceHubWaiting`)]})]})]}),$&&b&&!q&&(0,D.jsxs)(`section`,{className:`dc-card`,children:[(0,D.jsxs)(`div`,{className:`dc-device-summary`,children:[(0,D.jsx)(`span`,{className:`dc-device-icon`,children:(0,D.jsx)(c,{"aria-hidden":!0})}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h2`,{children:b.remark?.trim()||b.name}),(0,D.jsx)(`p`,{children:b.remark?.trim()?`${b.name} · ${d(`deviceHubDeviceTitle`)}`:d(`deviceHubDeviceTitle`)})]})]}),(0,D.jsxs)(`dl`,{className:`dc-details`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`dt`,{children:d(`deviceHubDeviceId`)}),(0,D.jsx)(`dd`,{children:b.deviceId})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`dt`,{children:d(`deviceHubHubUrl`)}),(0,D.jsx)(`dd`,{children:b.hubUrl})]})]}),(0,D.jsx)(`div`,{className:`dc-actions`,style:{marginTop:`1rem`},children:(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:V||!!N,onClick:()=>void Se(),children:[(0,D.jsx)(u,{className:V?`spin`:``,"aria-hidden":!0}),d(V?`deviceHubUpgrading`:`deviceHubUpgradeAction`)]})})]}),$&&b?.hubUrl&&b.deviceId&&!q&&(0,D.jsx)(x,{hubUrl:b.hubUrl,currentDeviceId:b.deviceId},`directory:${b.hubUrl}:${b.deviceId}`),!q&&(0,D.jsx)(ie,{pathCompletions:e},`bots:${b?.hubUrl??``}:${b?.deviceId??`unpaired`}`),(0,D.jsx)(W,{}),$&&b&&!q&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`section`,{className:`dc-card`,children:[(0,D.jsxs)(`div`,{className:`dc-card-header`,children:[(0,D.jsx)(`span`,{className:`dc-icon`,children:(0,D.jsx)(ee,{"aria-hidden":!0})}),(0,D.jsx)(`div`,{children:(0,D.jsx)(`h2`,{children:d(`deviceHubPermissions`)})})]}),(0,D.jsxs)(`div`,{className:`dc-permission-row`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h3`,{id:`dc-permission-label`,children:d(`deviceHubPermissionLabel`)}),(0,D.jsx)(`p`,{id:`dc-permission-hint`,children:d(`deviceHubPermissionHint`)})]}),(0,D.jsx)(`button`,{type:`button`,className:`dc-toggle${b.allowExecution?` is-on`:``}`,role:`switch`,"aria-checked":b.allowExecution,"aria-labelledby":`dc-permission-label`,"aria-describedby":`dc-permission-hint`,disabled:!!N,onClick:()=>void be(),children:(0,D.jsx)(`span`,{className:`dc-toggle-thumb`})})]}),(0,D.jsx)(`p`,{className:`dc-permission-state`,role:`status`,children:d(N===`permission`?`deviceHubSaving`:b.allowExecution?`deviceHubEnabled`:`deviceHubReadOnly`)})]}),(0,D.jsx)(C,{hubUrl:b?.hubUrl,deviceId:b?.deviceId,onNotice:z}),(0,D.jsxs)(`details`,{className:`dc-advanced`,children:[(0,D.jsx)(`summary`,{children:d(`deviceHubAdvanced`)}),(0,D.jsxs)(`div`,{className:`dc-danger-zone`,children:[(0,D.jsx)(`h3`,{children:d(`deviceHubDisconnect`)}),(0,D.jsx)(`p`,{children:d(`deviceHubDisconnectHint`)}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button is-danger`,disabled:!!N,onClick:()=>void xe(),children:d(N===`disconnect`?`deviceHubWorking`:`deviceHubDisconnect`)})]})]})]}),(0,D.jsxs)(`aside`,{className:`dc-help`,children:[(0,D.jsx)(g,{className:`dc-help-icon`,"aria-hidden":!0}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h3`,{children:d(`deviceHubHelpTitle`)}),(0,D.jsx)(`p`,{children:d(`deviceHubHelpText`)})]})]})]})]})]})]})}export{G as DeviceCenter};
@@ -1,3 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$ as t,A as n,Bn as r,Cn as i,Fn as a,H as o,Ht as s,Pt as c,Qt as ee,Tn as l,Ut as u,Z as d,gt as f,hn as p,jn as te,kt as m,pn as h,pt as g,sn as _,wn as v,xt as y}from"./app-globals-CR8Ls9nE.js";import{i as b,t as ne}from"./react-CR5VJ85Q.js";import{K as re,Zt as x,v as S,xt as ie}from"./index-BBAQNi6v.js";import{t as C}from"./DeviceExecutionSettings-B7R9ONaq.js";import{n as w,t as ae}from"./GroupWorkItems-FqAL74bC.js";var T=e(b(),1);async function E(e,t){let n=t.sleep??(e=>new Promise(t=>setTimeout(t,e))),r=Date.now()+(t.timeoutMs??18e5),i=e;if(!i||typeof i.id!=`string`||typeof i.fromBootId!=`string`)throw Error(`Invalid Hub upgrade response`);for(;;){if(t.isCurrent&&!t.isCurrent())throw new DOMException(`Hub upgrade view closed`,`AbortError`);if(i.id!==e.id)throw Error(`Hub upgrade job changed`);if(i.state===`failed`)throw Error(i.error||`Hub upgrade failed`);if(i.state===`succeeded`){if(!i.targetVersion||i.version!==i.targetVersion||!i.bootId||i.bootId===e.fromBootId)throw Error(`Hub upgrade result does not match the new version and process`);return i}if(i.state!==`queued`&&i.state!==`running`)throw Error(`Invalid Hub upgrade state`);if(Date.now()>=r)throw Error(`Hub upgrade timed out; inspect the Hub upgrade log`);if(await n(1500),t.isCurrent&&!t.isCurrent())throw new DOMException(`Hub upgrade view closed`,`AbortError`);try{i=await t.poll(e.id)}catch(e){let t=e.status;if(t&&t<500)throw e}}}var D=ne();function O(e){return!!e&&`mount`in e&&typeof e.mount==`function`}function k({plugin:e,epoch:t,onManageGroups:n}){let r=te(v()),[i,a]=(0,T.useState)(null),[o,s]=(0,T.useState)(!1),[c,ee]=(0,T.useState)(0),{id:l,name:u,version:d,hasClient:f,error:p,isolated:m}=e??{},h=(0,T.useMemo)(()=>l?{id:l,name:u??l,version:d,hasClient:f??!1,error:p,isolated:m}:void 0,[l,u,d,f,p,m]);(0,T.useEffect)(()=>{let e=!1;if(a(null),s(!1),h&&!h.error&&h.hasClient)return re(h,t,{retry:c>0}).then(t=>{e||(O(t)?a({info:h,module:t}):s(!0))}),()=>{e=!0}},[h,t,c]);let g=!h||!h.hasClient;return(0,D.jsxs)(`section`,{className:`dc-card`,"aria-label":r?`外部渠道配置`:`External channel settings`,children:[(0,D.jsxs)(`header`,{className:`dc-card-header`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h2`,{children:r?`GitHub / 飞书渠道`:`GitHub / Feishu channels`}),(0,D.jsx)(`p`,{children:r?`将外部事件映射到群组,由群组 AI 分派任务并跟进工单。`:`Map external events to a group. Its AI delegates tasks and follows up on work items.`})]}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:n,children:r?`管理群组与 AI`:`Manage groups & AI`})]}),g?(0,D.jsx)(`p`,{role:`status`,children:r?`内置渠道模块暂不可用,请重新加载页面或重启主程序。`:`The built-in channel module is temporarily unavailable. Reload this page or restart the application.`}):h.error?(0,D.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:h.error}):o?(0,D.jsxs)(`div`,{className:`dc-notice is-error`,role:`alert`,children:[(0,D.jsx)(`span`,{children:r?`渠道配置界面加载失败。`:`Channel settings failed to load.`}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>ee(e=>e+1),children:r?`重试`:`Retry`})]}):i?(0,D.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,minWidth:0,height:`min(72vh, 900px)`,minHeight:`360px`},children:(0,D.jsx)(S,{entry:i})}):(0,D.jsx)(`p`,{role:`status`,children:r?`正在加载渠道配置…`:`Loading channel settings…`})]})}function A({href:e,children:t}){let n=l(),[r,i]=(0,T.useState)(!1),[a,o]=(0,T.useState)(!1);return(0,D.jsxs)(D.Fragment,{children:[(0,D.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,D.jsxs)(`span`,{role:`alert`,children:[n(`deviceHubNetworkError`),` `,(0,D.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,children:e})]})]})}function j(e){if(!M(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 M(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 oe(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 N=`https://raw.githubusercontent.com/xing-shuyin/pi-web-ui/main/docs/device-center-deployment.md`,P=`https://github.com/xing-shuyin/pi-web-ui/blob/main/docs/device-center-deployment.md`,se=`pi-web-ui hub install --host 0.0.0.0 --port 8790 --public-url http://SERVER_IP:8790 --allow-registration`;function F(e){let t=e=>e.includes(`:`)?M(e)&&![`::`,`::1`].includes(e):/^[\d.]+$/.test(e)?M(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 I(e,t,n,r){if(!j(e))throw Error(`Invalid Hub setup`);if(r){let t=F(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: ${N} (fallback: ${P}). 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: ${se}`,`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 L({onConnect:e,initialHubUrl:t=``}){let n=l(),[i,o]=(0,T.useState)(t),[s,c]=(0,T.useState)(``),[ee,u]=(0,T.useState)(!1),[d,f]=(0,T.useState)(!1),p=(0,T.useRef)(!1),te=(0,T.useRef)(!1);(0,T.useEffect)(()=>(te.current=!0,()=>{te.current=!1}),[]);let[m,h]=(0,T.useState)(null),[g,_]=(0,T.useState)(`current`),[v,y]=(0,T.useState)(null),[b,ne]=(0,T.useState)(`127.0.0.1`),[re,x]=(0,T.useState)(`8790`),[S,ie]=(0,T.useState)(`http://127.0.0.1:8790`),[C,w]=(0,T.useState)({server:``,sshPort:22,username:`root`,auth:`password`,port:8790,domain:``,https:!1}),ae=F(C),[E,O]=(0,T.useState)(!1),[k,M]=(0,T.useState)(!1),[N,P]=(0,T.useState)(null),[se,L]=(0,T.useState)(!1),[R,ce]=(0,T.useState)(!1),[z,B]=(0,T.useState)(!1),[V,H]=(0,T.useState)(null),U=(0,T.useRef)(null),W=(0,T.useRef)(!1),G=oe(window.location.origin);(0,T.useEffect)(()=>()=>U.current?.abort(),[]);let K=async()=>{if(W.current)return;U.current?.abort();let e=new AbortController;U.current=e,L(!1),ce(!1),B(!1);try{let t=await fetch(r(a(`/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`||!j({host:`127.0.0.1`,port:n.defaultPort,publicUrl:n.defaultPublicUrl}))throw Error();if(e.signal.aborted)return;y(n),n.installation?.installed?(ne(n.installation.host??`127.0.0.1`),x(String(n.installation.port)),ie(n.installation.publicUrl??``),o(n.installation.publicUrl??``)):v||(x(String(n.defaultPort)),ie(n.defaultPublicUrl))}catch{e.signal.aborted||(L(!0),B(!0))}finally{e.signal.aborted||ce(!0)}},q=async()=>{let e={host:b,port:Number(re),publicUrl:S};if(W.current||!G||!v||!R||z||v.busy||v.installation?.installed||!j(e))return;W.current=!0,U.current?.abort(),O(!0),L(!1),c(``);let t=new AbortController;U.current=t;try{let n=await fetch(r(a(`/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){y(e=>e&&{...e,busy:!0}),W.current=!1,O(!1),await K();return}if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(typeof e.error==`string`?e.error.slice(0,4096):`HTTP ${n.status}`)}let i=await n.json();if(!j({...e,publicUrl:i.publicUrl})||typeof i.output!=`string`)throw Error();t.signal.aborted||H(i)}catch(e){t.signal.aborted||(L(!0),c(e instanceof Error?e.message.slice(0,4096):``))}finally{W.current=!1,t.signal.aborted||O(!1)}},le=async()=>{if(W.current||!G||!v||!R||z||v.busy||E||k)return;W.current=!0,U.current?.abort(),M(!0),L(!1),c(``),P(null);let e=new AbortController;U.current=e;try{let t=await fetch(r(a(`/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 i=await t.json();e.signal.aborted||(P(i.output||n(`deviceSetupUpdateSuccess`)),await K())}catch(t){e.signal.aborted||(L(!0),c(t instanceof Error?t.message.slice(0,4096):``))}finally{W.current=!1,e.signal.aborted||M(!1)}},J=v?.installation,ue=!!J?.installed,de=ue&&J.running&&J.owned,Y=g===`remote`?ae:{host:b,port:Number(re),publicUrl:S},X=!!Y&&j(Y);return(0,D.jsxs)(`section`,{className:`dc-onboarding`,children:[(0,D.jsx)(`h3`,{children:n(`deviceSetupWelcome`)}),(0,D.jsx)(`p`,{children:n(`deviceSetupIntro`)}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[(0,D.jsx)(`button`,{className:`dc-button`,disabled:E,"aria-pressed":m===`connect`,onClick:()=>h(`connect`),children:n(`deviceSetupConnect`)}),(0,D.jsx)(`button`,{className:`dc-button`,disabled:E,"aria-pressed":m===`create`,onClick:()=>{h(`create`),!v&&G&&K()},children:n(`deviceSetupCreate`)})]}),m===`connect`&&(0,D.jsxs)(`form`,{onSubmit:t=>{t.preventDefault(),e(i.trim())},children:[(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceHubHubUrl`)}),(0,D.jsx)(`input`,{type:`url`,required:!0,maxLength:2048,value:i,onChange:e=>o(e.target.value),placeholder:`https://hub.example.com`})]}),(0,D.jsx)(`button`,{className:`dc-button is-primary`,disabled:!j({host:`localhost`,port:8790,publicUrl:i.trim()}),children:n(`deviceSetupPair`)})]}),m===`create`&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupTarget`)}),(0,D.jsxs)(`select`,{disabled:E,value:g,onChange:e=>_(e.target.value),children:[(0,D.jsx)(`option`,{value:`current`,children:n(`deviceSetupCurrent`)}),(0,D.jsx)(`option`,{value:`remote`,children:n(`deviceSetupRemote`)})]})]}),(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`p`,{children:n(g===`current`?`deviceSetupCurrentHint`:`deviceSetupRemoteHint`)}),g===`current`&&(0,D.jsxs)(`div`,{className:`dc-setup-plan`,children:[(0,D.jsx)(`strong`,{children:n(`deviceSetupPlan`)}),(0,D.jsx)(`p`,{children:n(`deviceSetupPlanHint`)}),v&&(0,D.jsxs)(`dl`,{children:[(0,D.jsx)(`dt`,{children:n(`deviceSetupEnvironment`)}),(0,D.jsxs)(`dd`,{children:[v.platform,` · Node `,v.nodeVersion]}),(0,D.jsx)(`dt`,{children:n(`deviceSetupDataDir`)}),(0,D.jsx)(`dd`,{children:v.dataDir}),(0,D.jsx)(`dt`,{children:n(`deviceSetupCli`)}),(0,D.jsx)(`dd`,{children:v.cliPath})]}),!G&&(0,D.jsx)(`p`,{role:`status`,children:n(`deviceSetupLocalOnly`)}),(0,D.jsx)(`p`,{children:n(`deviceSetupBackground`)}),ue&&(0,D.jsxs)(`div`,{role:`status`,children:[(0,D.jsx)(`h4`,{children:n(de?`deviceSetupRestored`:`deviceSetupUnhealthy`)}),(0,D.jsx)(`p`,{children:J.publicUrl}),de&&X&&J.publicUrl?(0,D.jsxs)(`div`,{className:`dc-actions`,children:[(0,D.jsx)(A,{href:J.publicUrl,children:n(`deviceHubOpenHub`)}),(0,D.jsx)(`button`,{className:`dc-button`,onClick:()=>e(J.publicUrl),children:n(`deviceSetupPair`)}),G&&(0,D.jsx)(`button`,{className:`dc-button`,disabled:E||k,onClick:()=>void le(),children:n(k?`deviceSetupUpdating`:`deviceSetupUpdate`)})]}):(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`p`,{children:n(`deviceSetupRecovery`)}),(0,D.jsx)(`pre`,{className:`dc-setup-output`,children:`pi-web-ui hub status --json
3
- pi-web-ui hub --help`}),G&&(0,D.jsx)(`button`,{className:`dc-button is-primary`,disabled:E||k,onClick:()=>void le(),children:n(k?`deviceSetupUpdating`:`deviceSetupUpdate`)})]}),N&&(0,D.jsx)(`pre`,{className:`dc-setup-output`,children:N.slice(0,16e3)})]}),v?.busy&&(0,D.jsx)(`p`,{role:`status`,children:n(`deviceSetupBusy`)}),G&&(0,D.jsx)(`button`,{className:`dc-button`,disabled:E||!R,onClick:()=>void K(),children:n(R?`deviceSetupRetry`:`deviceHubWorking`)})]}),g===`remote`?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`div`,{className:`dc-setup-fields`,children:[(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupServer`)}),(0,D.jsx)(`input`,{autoComplete:`off`,maxLength:253,placeholder:`203.0.113.10`,value:C.server,onChange:e=>w({...C,server:e.target.value.trim()})})]}),(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupSshPort`)}),(0,D.jsx)(`input`,{type:`number`,min:1,max:65535,value:C.sshPort,onChange:e=>w({...C,sshPort:Number(e.target.value)})})]}),(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupUsername`)}),(0,D.jsx)(`input`,{autoComplete:`off`,maxLength:64,value:C.username,onChange:e=>w({...C,username:e.target.value})})]}),(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupAuth`)}),(0,D.jsxs)(`select`,{value:C.auth,onChange:e=>w({...C,auth:e.target.value}),children:[(0,D.jsx)(`option`,{value:`password`,children:n(`deviceSetupAuthPassword`)}),(0,D.jsx)(`option`,{value:`key`,children:n(`deviceSetupAuthKey`)}),(0,D.jsx)(`option`,{value:`existing`,children:n(`deviceSetupAuthExisting`)})]})]}),(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupServicePort`)}),(0,D.jsx)(`input`,{type:`number`,min:1024,max:65535,value:C.port,onChange:e=>w({...C,port:Number(e.target.value)})})]})]}),(0,D.jsx)(`p`,{children:n(`deviceSetupCredentialHint`)}),(0,D.jsxs)(`details`,{children:[(0,D.jsx)(`summary`,{children:n(`deviceSetupOptionalTls`)}),(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupDomain`)}),(0,D.jsx)(`input`,{maxLength:253,placeholder:`hub.example.com`,value:C.domain,onChange:e=>w({...C,domain:e.target.value.trim()})})]}),(0,D.jsxs)(`label`,{children:[(0,D.jsx)(`input`,{type:`checkbox`,checked:C.https,onChange:e=>w({...C,https:e.target.checked})}),` `,n(`deviceSetupEnableHttps`)]}),(0,D.jsx)(`p`,{children:n(`deviceSetupTlsHint`)})]}),(0,D.jsxs)(`p`,{children:[(0,D.jsx)(`strong`,{children:n(`deviceSetupPreview`)}),` `,ae?.publicUrl??n(`deviceSetupPreviewEmpty`)]}),(0,D.jsxs)(`div`,{className:`dc-setup-plan`,children:[(0,D.jsx)(`strong`,{children:n(`deviceSetupUserActions`)}),(0,D.jsx)(`p`,{children:n(`deviceSetupCloudPorts`).replace(`{ports}`,C.https?`443 / 80`:String(C.port))}),(0,D.jsx)(`p`,{children:n(`deviceSetupSourceScope`)}),(0,D.jsx)(`p`,{children:n(`deviceSetupAfterStart`)})]}),(0,D.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,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`div`,{className:`dc-setup-fields`,children:[(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupHost`)}),(0,D.jsx)(`input`,{disabled:E||!!V,maxLength:253,value:b,onChange:e=>ne(e.target.value)})]}),(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupPort`)}),(0,D.jsx)(`input`,{disabled:E||!!V,type:`number`,min:1024,max:65535,value:re,onChange:e=>x(e.target.value)})]}),(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceHubHubUrl`)}),(0,D.jsx)(`input`,{disabled:E||!!V,maxLength:2048,value:S,onChange:e=>ie(e.target.value)})]})]}),(0,D.jsx)(`p`,{className:`dc-setup-warning`,children:n(`deviceSetupReachable`)})]}),(0,D.jsx)(`p`,{children:n(`deviceSetupRegistration`)}),!X&&(0,D.jsx)(`p`,{role:`alert`,children:n(g===`remote`?`deviceSetupRemoteInvalid`:`deviceSetupInvalid`)}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[g===`current`&&!V&&!ue&&(0,D.jsx)(`button`,{className:`dc-button is-primary`,disabled:E||!G||!v||!R||z||!!v.busy||!X,onClick:()=>void q(),children:n(E?`deviceSetupInstalling`:`deviceSetupInstall`)}),(0,D.jsx)(`button`,{className:`dc-button`,disabled:E||ee||!X,onClick:()=>{if(!X||!Y||p.current)return;p.current=!0,u(!0),f(!1);let e=e=>{p.current=!1,te.current&&(u(!1),f(!e))},t=window.__piWebUiHost;try{t?.startChat({newChat:!0,prompt:I(Y,v,g,g===`remote`?C:void 0),onResult:e})||e(!1)}catch{e(!1)}},children:n(g===`remote`?`deviceSetupStartAi`:`deviceSetupAi`)})]}),(0,D.jsx)(`p`,{children:n(`deviceSetupAiHint`)}),ee&&(0,D.jsx)(`p`,{role:`status`,children:n(`deviceSetupAiCreating`)}),d&&(0,D.jsx)(`p`,{role:`alert`,children:n(`deviceSetupAiFailed`)})]})]}),se&&(0,D.jsxs)(`div`,{role:`alert`,children:[(0,D.jsx)(`p`,{children:n(`deviceSetupFailed`)}),s&&(0,D.jsx)(`pre`,{className:`dc-setup-output`,children:s})]}),V&&(0,D.jsxs)(`div`,{role:`status`,children:[(0,D.jsx)(`h4`,{children:n(`deviceSetupSuccess`)}),(0,D.jsx)(`pre`,{className:`dc-setup-output`,children:V.output.slice(0,16e3)}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[(0,D.jsx)(A,{href:V.publicUrl,children:n(`deviceHubOpenHub`)}),(0,D.jsx)(`button`,{className:`dc-button is-primary`,onClick:()=>e(V.publicUrl),children:n(`deviceSetupPair`)})]})]})]})}var R=`pi-web-ui:device-groups-changed`;function ce(e){window.dispatchEvent(new CustomEvent(`pi-web-ui:device-group-open`,{detail:{roomId:e}}))}async function z(e,t,n){let i=await fetch(r(a(`/api/device-center/${e}`)),{method:n?`POST`:`GET`,credentials:`same-origin`,signal:t,...n?{headers:{"Content-Type":`application/json`},body:JSON.stringify(n)}:{}}),o=await i.json().catch(()=>({}));if(!i.ok)throw Error(o.error||o.message||`Request failed (${i.status})`);return o}function B({bindingKey:e=``}){return(0,D.jsx)(V,{},e)}function V(){let{locale:e}=i(),t=te(e),[r,a]=(0,T.useState)([]),[o,c]=(0,T.useState)([]),[ee,l]=(0,T.useState)(!0),[f,g]=(0,T.useState)(``),[v,y]=(0,T.useState)(``),[b,ne]=(0,T.useState)(0),[re,x]=(0,T.useState)(!1),[S,ie]=(0,T.useState)(``),[C,E]=(0,T.useState)([]),[O,k]=(0,T.useState)(``),[A,j]=(0,T.useState)(null),[M,oe]=(0,T.useState)([]),[N,P]=(0,T.useState)(``),[se,F]=(0,T.useState)(null),[I,L]=(0,T.useState)(``),[B,V]=(0,T.useState)(!1),[H,U]=(0,T.useState)(null),W=r.find(e=>e.id===H?.roomId),G=(0,T.useRef)(0),K=(0,T.useRef)(null),q=(0,T.useRef)(null);function le(){++G.current,K.current?.abort(),ne(e=>e+1)}function J(){q.current?.abort();let e=new AbortController;return q.current=e,e}(0,T.useEffect)(()=>()=>q.current?.abort(),[]),(0,T.useEffect)(()=>{let e=++G.current,t=new AbortController;K.current=t;async function n(){try{let[n,r]=await Promise.all([z(`rooms`,t.signal),z(`bots`,t.signal)]);if(G.current!==e||t.signal.aborted)return;let i=Array.isArray(n.rooms)?n.rooms:[];a(i),U(e=>e&&i.some(t=>t.id===e.roomId)?e:null),c(Array.isArray(r.bots)?r.bots:[]),g(``)}catch(n){G.current===e&&!t.signal.aborted&&g(n instanceof Error?n.message:String(n))}finally{G.current===e&&!t.signal.aborted&&l(!1)}}return n(),()=>{t.abort()}},[b]),(0,T.useEffect)(()=>{let e=()=>le();return window.addEventListener(R,e),()=>window.removeEventListener(R,e)},[]);async function ue(e){if(e.preventDefault(),!S.trim()||B)return;V(!0),g(``),y(``);let n=J();try{let e=C.includes(O)?O:``,r=await z(`rooms`,n.signal,{name:S.trim(),botIds:C,...e?{primaryBotId:e}:{}});if(n.signal.aborted)return;a(e=>[...e.filter(e=>e.id!==r.room.id),r.room]),x(!1),ie(``),E([]),k(``),y(t?`群聊创建成功`:`Group created successfully`),window.dispatchEvent(new CustomEvent(R))}catch(e){n.signal.aborted||g(e instanceof Error?e.message:String(e))}finally{n.signal.aborted||V(!1)}}function de(e){j(e.id),oe([...e.botIds]),P(e.primaryBotId??``),F(null),x(!1),g(``),y(``)}async function Y(e){if(B)return;V(!0),g(``),y(``);let n=J();try{let r=M.includes(N)?N:null,i=await z(`rooms/${encodeURIComponent(e)}/members`,n.signal,{botIds:M,primaryBotId:r});if(n.signal.aborted)return;a(t=>t.map(t=>t.id===e?i.room:t)),j(null),y(t?`成员设置已保存`:`Members updated successfully`),window.dispatchEvent(new CustomEvent(R))}catch(e){n.signal.aborted||g(e instanceof Error?e.message:String(e))}finally{n.signal.aborted||V(!1)}}async function X(e){if(!I.trim()||B)return;V(!0),g(``),y(``);let n=J();try{if(await z(`rooms/${encodeURIComponent(e)}/rename`,n.signal,{name:I.trim()}),n.signal.aborted)return;a(t=>t.map(t=>t.id===e?{...t,name:I.trim()}:t)),F(null),y(t?`群聊名称已更新`:`Group renamed successfully`),window.dispatchEvent(new CustomEvent(R))}catch(e){n.signal.aborted||g(e instanceof Error?e.message:String(e))}finally{n.signal.aborted||V(!1)}}async function Z(e){if(B||!window.confirm(t?`确定删除群聊“${e.name}”?`:`Are you sure you want to delete "${e.name}"?`))return;V(!0),g(``),y(``);let n=J();try{if(await z(`rooms/${encodeURIComponent(e.id)}/delete`,n.signal,{}),n.signal.aborted)return;U(t=>t?.roomId===e.id?null:t),a(t=>t.filter(t=>t.id!==e.id)),A===e.id&&j(null),se===e.id&&F(null),y(t?`群聊已删除`:`Group deleted successfully`),window.dispatchEvent(new CustomEvent(R))}catch(e){n.signal.aborted||g(e instanceof Error?e.message:String(e))}finally{n.signal.aborted||V(!1)}}return(0,D.jsxs)(`section`,{className:`dc-card`,"aria-label":t?`群聊列表`:`Group list`,children:[(0,D.jsxs)(`div`,{className:`dc-card-header`,children:[(0,D.jsx)(`span`,{className:`dc-icon`,children:(0,D.jsx)(h,{"aria-hidden":!0})}),(0,D.jsxs)(`div`,{children:[(0,D.jsxs)(`h2`,{children:[t?`群聊列表`:`Group List`,` · `,r.length]}),(0,D.jsx)(`p`,{children:t?`管理群聊与成员 Bot,在此配置协作群组或直接进入聊天。`:`Manage groups and member Bots. Configure collaboration groups or open chats here.`})]}),(0,D.jsxs)(`div`,{className:`dc-actions`,style:{marginInlineStart:`auto`},children:[(0,D.jsxs)(`button`,{type:`button`,className:`dc-button is-primary`,disabled:B,onClick:()=>{x(e=>!e),j(null),F(null),ie(``),E([]),k(``)},children:[(0,D.jsx)(s,{"aria-hidden":!0}),t?`新建群聊`:`Create Group`]}),(0,D.jsx)(`button`,{type:`button`,className:`dc-icon-button`,"aria-label":t?`刷新群聊`:`Refresh groups`,onClick:le,children:(0,D.jsx)(u,{})})]})]}),f&&(0,D.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:f}),v&&(0,D.jsxs)(`p`,{className:`dc-notice is-success`,role:`status`,children:[(0,D.jsx)(n,{"aria-hidden":!0}),v]}),re&&(0,D.jsxs)(`form`,{className:`dc-card`,style:{marginBottom:`16px`,background:`var(--bg)`,border:`1px solid var(--border)`},onSubmit:ue,children:[(0,D.jsxs)(`div`,{className:`dg-heading`,style:{marginBottom:`12px`},children:[(0,D.jsx)(`h3`,{children:t?`新建群聊`:`Create Group`}),(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>x(!1),disabled:B,children:[(0,D.jsx)(p,{"aria-hidden":!0}),t?`关闭`:`Close`]})]}),(0,D.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`12px`},children:[(0,D.jsx)(`label`,{htmlFor:`dg-manager-new-name`,children:t?`群名称`:`Group Name`}),(0,D.jsx)(`input`,{id:`dg-manager-new-name`,type:`text`,required:!0,maxLength:80,value:S,placeholder:t?`输入群名称,如:研发协作群`:`Enter group name`,onChange:e=>ie(e.target.value),disabled:B,style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`}})]}),(0,D.jsxs)(`div`,{style:{marginBottom:`12px`},children:[(0,D.jsx)(`label`,{style:{display:`block`,marginBottom:`6px`,fontSize:`12px`,color:`var(--text-dim)`},children:t?`选择成员 Bot`:`Select Member Bots`}),(0,D.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,D.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,D.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,cursor:`pointer`,fontSize:`12px`},children:[(0,D.jsx)(`input`,{type:`checkbox`,checked:C.includes(e.id),disabled:B||!e.enabled,onChange:t=>{E(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}}),(0,D.jsxs)(`span`,{children:[(0,D.jsx)(`strong`,{children:e.name}),(0,D.jsxs)(`small`,{style:{color:`var(--text-faint)`,marginInlineStart:`6px`},children:[e.online?t?`在线`:`Online`:t?`离线`:`Offline`,e.enabled?``:t?` · 已禁用`:` · Disabled`]})]})]},e.id))})]}),C.length>0&&(0,D.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`16px`},children:[(0,D.jsx)(`label`,{htmlFor:`dg-manager-new-primary`,children:t?`原主 Bot(Router 未启用时)`:`Legacy primary Bot (when Router is disabled)`}),(0,D.jsxs)(`select`,{id:`dg-manager-new-primary`,value:C.includes(O)?O:``,onChange:e=>k(e.target.value),disabled:B,style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`},children:[(0,D.jsx)(`option`,{value:``,children:t?`不设置(需 @ Bot)`:`None (mention a Bot)`}),o.filter(e=>C.includes(e.id)).map(e=>(0,D.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[(0,D.jsxs)(`button`,{type:`submit`,className:`dc-button is-primary`,disabled:B||!S.trim(),children:[(0,D.jsx)(n,{"aria-hidden":!0}),B?t?`创建中…`:`Creating…`:t?`创建群聊`:`Create`]}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>x(!1),disabled:B,children:t?`取消`:`Cancel`})]})]}),A&&(0,D.jsxs)(`div`,{className:`dc-card`,style:{marginBottom:`16px`,background:`var(--bg)`,border:`1px solid var(--border)`},children:[(0,D.jsxs)(`div`,{className:`dg-heading`,style:{marginBottom:`12px`},children:[(0,D.jsxs)(`h3`,{children:[t?`管理成员`:`Manage Members`,` · `,r.find(e=>e.id===A)?.name]}),(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>j(null),disabled:B,children:[(0,D.jsx)(p,{"aria-hidden":!0}),t?`关闭`:`Close`]})]}),(0,D.jsxs)(`div`,{style:{marginBottom:`12px`},children:[(0,D.jsx)(`label`,{style:{display:`block`,marginBottom:`6px`,fontSize:`12px`,color:`var(--text-dim)`},children:t?`选择成员 Bot`:`Select Member Bots`}),(0,D.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,D.jsx)(`p`,{style:{margin:0,fontSize:`12px`,color:`var(--text-faint)`},children:t?`暂无可用 Bot`:`No Bots available`}):o.map(e=>(0,D.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,cursor:`pointer`,fontSize:`12px`},children:[(0,D.jsx)(`input`,{type:`checkbox`,checked:M.includes(e.id),disabled:B,onChange:t=>{oe(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}}),(0,D.jsxs)(`span`,{children:[(0,D.jsx)(`strong`,{children:e.name}),(0,D.jsxs)(`small`,{style:{color:`var(--text-faint)`,marginInlineStart:`6px`},children:[e.online?t?`在线`:`Online`:t?`离线`:`Offline`,e.enabled?``:t?` · 已禁用`:` · Disabled`]})]})]},e.id))})]}),!r.find(e=>e.id===A)?.router?.enabled&&(0,D.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`16px`},children:[(0,D.jsx)(`label`,{htmlFor:`dg-manager-edit-primary`,children:t?`原主 Bot(Router 未启用时)`:`Legacy primary Bot (when Router is disabled)`}),(0,D.jsxs)(`select`,{id:`dg-manager-edit-primary`,value:M.includes(N)?N:``,onChange:e=>P(e.target.value),disabled:B,style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`},children:[(0,D.jsx)(`option`,{value:``,children:t?`不设置(需 @ Bot)`:`None (mention a Bot)`}),o.filter(e=>M.includes(e.id)).map(e=>(0,D.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[(0,D.jsxs)(`button`,{type:`button`,className:`dc-button is-primary`,disabled:B,onClick:()=>void Y(A),children:[(0,D.jsx)(n,{"aria-hidden":!0}),B?t?`保存中…`:`Saving…`:t?`保存成员设置`:`Save Members`]}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>j(null),disabled:B,children:t?`取消`:`Cancel`})]})]}),ee&&(0,D.jsx)(`p`,{role:`status`,children:t?`加载中…`:`Loading…`}),!ee&&r.length===0&&(0,D.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,D.jsx)(`div`,{className:`dd-list`,children:r.map(e=>{let r=se===e.id,i=o.filter(t=>e.botIds.includes(t.id)),a=o.find(t=>t.id===e.primaryBotId);return(0,D.jsxs)(`div`,{className:`dd-device`,style:r?{flexWrap:`wrap`}:void 0,children:[(0,D.jsx)(`span`,{className:`dc-device-icon`,children:(0,D.jsx)(h,{"aria-hidden":!0})}),(0,D.jsxs)(`div`,{className:`dd-identity`,style:{flex:1,minWidth:`200px`},children:[(0,D.jsx)(`strong`,{children:e.name}),(0,D.jsxs)(`span`,{style:{display:`flex`,gap:`8px`,flexWrap:`wrap`,alignItems:`center`},children:[(0,D.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(`, `)}`:``}`}),e.router?.enabled&&(0,D.jsxs)(`span`,{children:[`AI Router · `,e.router.deviceId,` · `,e.router.model,` · `,e.router.thinkingLevel]}),!e.router?.enabled&&a&&(0,D.jsx)(`span`,{style:{color:`var(--accent)`},children:t?`[主 Bot: ${a.name}]`:`[Primary: ${a.name}]`})]})]}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[(0,D.jsxs)(`button`,{type:`button`,className:`dc-button is-primary`,title:t?`打开聊天`:`Open chat`,onClick:()=>ce(e.id),children:[(0,D.jsx)(m,{"aria-hidden":!0}),t?`打开聊天`:`Open chat`]}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button`,"aria-expanded":H?.roomId===e.id&&H.kind===`router`,onClick:()=>U({roomId:e.id,kind:`router`}),children:`AI Router`}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button`,"aria-expanded":H?.roomId===e.id&&H.kind===`work`,onClick:()=>U({roomId:e.id,kind:`work`}),children:t?`工单与运行`:`Work items & runs`}),(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,title:t?`管理成员`:`Manage members`,onClick:()=>de(e),children:[(0,D.jsx)(h,{"aria-hidden":!0}),t?`管理成员`:`Members`]}),(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,title:t?`重命名`:`Rename`,onClick:()=>{r?F(null):(F(e.id),L(e.name))},children:[(0,D.jsx)(d,{"aria-hidden":!0}),t?`重命名`:`Rename`]}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button is-danger`,title:t?`删除群聊`:`Delete group`,disabled:B,onClick:()=>void Z(e),children:(0,D.jsx)(_,{"aria-hidden":!0})})]}),r&&(0,D.jsxs)(`form`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,width:`100%`,paddingTop:`8px`,paddingBottom:`4px`},onSubmit:t=>{t.preventDefault(),X(e.id)},children:[(0,D.jsx)(`input`,{type:`text`,maxLength:80,autoFocus:!0,disabled:B,value:I,onChange:e=>L(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,D.jsxs)(`button`,{type:`submit`,className:`dc-button is-primary`,disabled:B||!I.trim(),children:[(0,D.jsx)(n,{"aria-hidden":!0}),t?`保存`:`Save`]}),(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:B,onClick:()=>F(null),children:[(0,D.jsx)(p,{"aria-hidden":!0}),t?`取消`:`Cancel`]})]})]},e.id)})}),W&&H&&(0,D.jsxs)(`section`,{className:`dc-card`,"aria-label":t?`群组设置`:`Group settings`,children:[(0,D.jsxs)(`div`,{className:`dg-heading`,children:[(0,D.jsx)(`h3`,{children:W.name}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[(0,D.jsx)(`button`,{type:`button`,className:`dc-button${H.kind===`router`?` is-primary`:``}`,"aria-pressed":H.kind===`router`,onClick:()=>U({roomId:W.id,kind:`router`}),children:`AI Router`}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button${H.kind===`work`?` is-primary`:``}`,"aria-pressed":H.kind===`work`,onClick:()=>U({roomId:W.id,kind:`work`}),children:t?`工单与运行`:`Work items & runs`}),(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>U(null),children:[(0,D.jsx)(p,{"aria-hidden":!0}),t?`关闭`:`Close`]})]})]}),H.kind===`router`?(0,D.jsx)(w,{roomId:W.id,router:W.router,disabled:B,onSaved:le},W.id):(0,D.jsx)(ae,{roomId:W.id,disabled:B},W.id)]})]})}var H=class extends Error{status;constructor(e,t){super(t),this.status=e}};function U(e){try{let t=new URL(e);return[`http:`,`https:`].includes(t.protocol)&&!t.username&&!t.password?t.href:null}catch{return null}}function W(){let e=l(),t=v().startsWith(`zh`),[n,i]=(0,T.useState)(null),[o,s]=(0,T.useState)(!1),[ee,d]=(0,T.useState)(!1),[f,p]=(0,T.useState)(!1),[te,m]=(0,T.useState)(!1),h=(0,T.useRef)(0),g=(0,T.useRef)(null);async function _(e,t){if(g.current)return;let n=++h.current,o=new AbortController;g.current=o,s(!0),d(!1);try{let s=await fetch(r(a(`/api/device-desktop/local/${e}`)),{method:t?`POST`:`GET`,credentials:`same-origin`,signal:o.signal,...t?{headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}:{}});if(h.current!==n||o.signal.aborted)return;if(s.status===403){p(!0),i(null);return}if(!s.ok)throw Error(`Request failed`);let c=await s.json();if(h.current!==n||o.signal.aborted)return;if(e===`permissions`){if(typeof c?.screen!=`boolean`||typeof c?.accessibility!=`boolean`)throw Error(`Invalid permission status`);i(e=>e&&{...e,permissions:{supported:!0,screen:c.screen,accessibility:c.accessibility}}),m(!0)}else{if(typeof c?.os!=`string`||typeof c.enabled!=`boolean`||typeof c.environmentEnabled!=`boolean`||typeof c.supported!=`boolean`)throw Error(`Invalid desktop status`);i(c)}}catch{h.current===n&&!o.signal.aborted&&d(!0)}finally{h.current===n&&!o.signal.aborted&&(g.current=null,s(!1))}}return(0,T.useEffect)(()=>(_(`status`),()=>{h.current++,g.current?.abort(),g.current=null}),[]),(0,D.jsxs)(`section`,{className:`dc-card`,"aria-label":t?`本机远程桌面`:`Local remote desktop`,"aria-busy":o,children:[(0,D.jsxs)(`div`,{className:`dc-card-header`,children:[(0,D.jsx)(`span`,{className:`dc-icon`,children:(0,D.jsx)(c,{"aria-hidden":!0})}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h2`,{children:t?`本机远程桌面`:`Local remote desktop`}),(0,D.jsx)(`p`,{children:t?`管理这台设备的远程桌面与系统权限,无需连接设备中心。`:`Manage remote desktop and system permissions on this device, even while the device center is offline.`})]})]}),f?(0,D.jsx)(`p`,{role:`status`,children:t?`请在设备本机打开此页面以管理远程桌面权限。`:`Open this page on the device itself to manage remote desktop permissions.`}):(0,D.jsxs)(D.Fragment,{children:[n&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`div`,{className:`dc-permission-row`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h3`,{id:`dc-desktop-label`,children:t?`启用远程桌面`:`Enable remote desktop`}),(0,D.jsx)(`p`,{children:n.enabled?t?`已启用`:`Enabled`:t?`未启用`:`Disabled`})]}),(0,D.jsx)(`button`,{type:`button`,className:`dc-toggle${n.enabled?` is-on`:``}`,role:`switch`,"aria-checked":n.enabled,"aria-labelledby":`dc-desktop-label`,disabled:o||n.environmentEnabled||!n.supported&&!n.enabled,onClick:()=>void _(`enable`,{enabled:!n.enabled}),children:(0,D.jsx)(`span`,{className:`dc-toggle-thumb`})})]}),!n.supported&&(0,D.jsx)(`p`,{children:t?`这台设备暂不支持远程桌面。`:`Remote desktop is currently unavailable on this device.`}),n.environmentEnabled&&(0,D.jsx)(`p`,{children:t?`远程桌面由本机服务设置保持启用。`:`Remote desktop is kept enabled by the service settings on this device.`}),n.os===`darwin`&&(0,D.jsxs)(D.Fragment,{children:[(0,D.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,D.jsxs)(`div`,{className:`dc-actions`,children:[(0,D.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:o||n.permissions?.supported===!1,onClick:()=>void _(`permissions`,{kind:`screen`}),children:t?`授予屏幕录制权限`:`Grant screen recording permission`}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:o||n.permissions?.supported===!1,onClick:()=>void _(`permissions`,{kind:`control`}),children:t?`授予远程控制权限`:`Grant remote control permission`})]}),n.permissions?.screen===!0&&(0,D.jsx)(`p`,{children:t?`屏幕录制:已授权`:`Screen recording: granted`}),n.permissions?.accessibility===!0&&(0,D.jsx)(`p`,{children:t?`远程控制:已授权`:`Remote control: granted`}),te&&(0,D.jsx)(`p`,{role:`status`,children:t?`已发起授权请求,请确认系统设置后刷新状态。`:`Permission requested. Confirm in System Settings, then refresh the status.`})]})]}),ee&&(0,D.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:t?`无法更新本机远程桌面设置,请重试。`:`Unable to update local remote desktop settings. Please retry.`}),(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:o,onClick:()=>void _(`status`),children:[(0,D.jsx)(u,{"aria-hidden":!0}),o?e(`deviceHubWorking`):t?`刷新远程桌面状态`:`Refresh remote desktop status`]})]})]})}function G({pathCompletions:e=[],plugins:i=[],pluginsEpoch:s=0}){let d=l(),p=te(v()),[m,_]=(0,T.useState)(`devices`),[b,ne]=(0,T.useState)(null),[re,S]=(0,T.useState)(``),[w,ae]=(0,T.useState)(``),[O,j]=(0,T.useState)(null),[M,oe]=(0,T.useState)(Date.now()),[N,P]=(0,T.useState)(null),[se,F]=(0,T.useState)(``),[I,R]=(0,T.useState)(``),[ce,z]=(0,T.useState)(``),[V,G]=(0,T.useState)(!1),K=(0,T.useRef)(!1),[q,le]=(0,T.useState)(!1),[J,ue]=(0,T.useState)(!0),de=(0,T.useRef)(!1),Y=(0,T.useRef)(0),X=(0,T.useRef)(new Set),Z=(0,T.useRef)(!1),fe=(0,T.useRef)(!1),pe=(0,T.useRef)(null),me=(0,T.useRef)(d);me.current=d,(0,T.useEffect)(()=>{let e=e=>{let t=e;t.detail?.deviceId&&pe.current?.deviceId===t.detail.deviceId&&(ne(e=>e&&{...e,remark:t.detail.remark}),pe.current&&(pe.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 he(e,t){let n=new AbortController;X.current.add(n);try{let i=await fetch(r(a(`/api/device-center/${e}`)),{method:t?`POST`:`GET`,credentials:`same-origin`,signal:n.signal,...t?{headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}:{}}),o=await i.json().catch(()=>({}));if(!i.ok)throw new H(i.status,typeof o.error==`string`?o.error:me.current(`deviceHubRequestFailed`,{status:i.status}));return o}finally{X.current.delete(n)}}function Q(e){return de.current&&Y.current===e}function ge(e){return e instanceof H&&e.status===403?(le(!0),me.current(`deviceHubLocalOnly`)):e instanceof Error?e.message:me.current(`deviceHubNetworkError`)}function _e(e){pe.current=e,ne(e),fe.current||(ae(e.name),S(e.hubUrl??``))}async function ve(){let e=Y.current;try{let t=await he(`status`);if(!Q(e)||Z.current)return;_e(t),R(``),le(!1)}catch(t){Q(e)&&R(ge(t))}finally{Q(e)&&ue(!1)}}(0,T.useEffect)(()=>{de.current=!0;let e=!1,t,n=async()=>{await ve(),!e&&de.current&&(t=setTimeout(n,5e3))};return n(),()=>{e=!0,de.current=!1,Y.current++,clearTimeout(t);for(let e of X.current)e.abort()}},[]),(0,T.useEffect)(()=>{if(!O)return;let e=Y.current,t=!1,n,r=setInterval(()=>oe(Date.now()),1e3),i=async()=>{if(!(t||!Q(e)||Date.now()>=O.expiresAt)){try{let n=await he(`poll`,{});if(t||!Q(e))return;if(n.paired){let n=await he(`status`);if(t||!Q(e))return;fe.current=!1,_e(n),j(null),F(``),z(``);return}F(``)}catch(n){!t&&Q(e)&&F(`${me.current(`deviceHubPollError`)} ${ge(n)}`)}!t&&Q(e)&&(n=setTimeout(i,2e3))}};return n=setTimeout(i,2e3),()=>{t=!0,clearTimeout(n),clearInterval(r)}},[O]);async function ye(){if(Z.current)return;let e=U(re.trim());if(!e){F(d(`deviceHubInvalidUrl`));return}if(!w.trim()||w.trim().length>80){F(d(`deviceHubInvalidName`));return}let t=++Y.current;Z.current=!0,P(`pair`),F(``),z(``),j(null);try{let n=await he(`pair`,{hubUrl:e,name:w.trim()});if(!Q(t))return;if(!n.code||!Number.isFinite(n.expiresAt)||!U(n.hubUrl))throw Error(d(`deviceHubPairError`));oe(Date.now()),j(n)}catch(e){Q(t)&&F(`${d(`deviceHubPairError`)} ${ge(e)}`)}finally{Q(t)&&(Z.current=!1,P(null))}}async function be(){let e=pe.current;if(!e?.deviceId||Z.current)return;let t=++Y.current;Z.current=!0,P(`permission`),F(``),z(``),_e({...e,allowExecution:!e.allowExecution});try{await he(`execution`,{allowExecution:!e.allowExecution}),Q(t)&&z(d(`deviceHubSaved`))}catch(n){Q(t)&&(_e(e),F(`${d(`deviceHubPermissionError`)} ${ge(n)}`))}finally{Q(t)&&(Z.current=!1,P(null))}}async function xe(){let e=pe.current;if(!e?.deviceId||Z.current||!window.confirm(d(`deviceHubDisconnectConfirm`,{name:e.name})))return;let t=++Y.current;Z.current=!0,P(`disconnect`),F(``),z(``);try{if(await he(`disconnect`,{}),!Q(t))return;fe.current=!1,_e({name:e.name,allowExecution:!1,connected:!1}),j(null)}catch(e){Q(t)&&F(`${d(`deviceHubDisconnectError`)} ${ge(e)}`)}finally{Q(t)&&(Z.current=!1,P(null))}}async function Se(){if(K.current||N||!$||!b?.hubUrl||!window.confirm(d(`deviceHubConfirmUpgrade`)))return;let e=Y.current;K.current=!0,G(!0),F(``),z(``);try{let t=await he(`upgrade-hub`,{});if(!t.ok)throw Error(`Hub upgrade was not accepted`);await E(t.job,{isCurrent:()=>Q(e),poll:async e=>(await he(`upgrade-hub-status`,{id:e})).job}),Q(e)&&(z(d(`deviceHubUpgradeSuccess`)),await ve())}catch(t){Q(e)&&F(t instanceof Error?t.message:d(`deviceHubNetworkError`))}finally{K.current=!1,Q(e)&&G(!1)}}async function Ce(){if(!O)return;let e=Y.current;try{await navigator.clipboard.writeText(O.code),Q(e)&&z(d(`deviceHubCopied`))}catch{Q(e)&&F(d(`deviceHubCopyFailed`))}}let $=!!b?.deviceId,we=U($?b?.hubUrl??``:O?.hubUrl??``),Te=Math.max(0,Math.ceil(((O?.expiresAt??0)-M)/1e3)),Ee=`${Math.floor(Te/60)}:${String(Te%60).padStart(2,`0`)}`,De=we?(0,D.jsxs)(A,{href:we,children:[(0,D.jsx)(t,{"aria-hidden":!0}),d(`deviceHubOpenHub`)]}):null;return(0,D.jsxs)(`section`,{className:`dc-page`,"aria-label":d(`deviceHubTitle`),children:[(0,D.jsxs)(`header`,{className:`dc-header`,children:[(0,D.jsxs)(`div`,{className:`dc-heading`,children:[(0,D.jsxs)(`span`,{className:`dc-eyebrow`,children:[(0,D.jsx)(c,{"aria-hidden":!0}),d(`deviceHubTitle`)]}),(0,D.jsx)(`h1`,{children:d(`deviceHubTitle`)}),(0,D.jsx)(`p`,{children:d(`deviceHubSubtitle`)})]}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[$&&De,(0,D.jsxs)(`span`,{className:`dc-status ${$?b?.connected?`is-online`:`is-offline`:`is-unpaired`}`,children:[(0,D.jsx)(`span`,{className:`dc-status-dot`}),d($?b?.connected?`deviceHubOnline`:`deviceHubOffline`:`deviceHubUnpaired`)]})]})]}),(0,D.jsxs)(`div`,{className:`dc-layout`,children:[(0,D.jsx)(`nav`,{className:`dc-sidebar`,"aria-label":p?`设备与协作导航`:`Devices and collaboration`,children:[[`devices`,c,p?`设备与连接`:`Devices & connections`],[`groups`,h,p?`群组与工单`:`Groups & work items`],[`channels`,f,p?`外部渠道`:`External channels`]].map(([e,t,n])=>(0,D.jsxs)(`button`,{type:`button`,className:`dc-nav-item${m===e?` is-active`:``}`,"aria-pressed":m===e,onClick:()=>_(e),children:[(0,D.jsx)(t,{"aria-hidden":!0}),n]},e))}),(0,D.jsxs)(`main`,{className:`dc-content`,children:[J&&(0,D.jsxs)(`div`,{className:`dc-loading`,role:`status`,children:[(0,D.jsx)(u,{"aria-hidden":!0}),d(`deviceHubLoading`)]}),(q||I)&&(0,D.jsxs)(`div`,{className:`dc-notice is-error`,role:`alert`,children:[(0,D.jsx)(`span`,{children:q?d(`deviceHubLocalOnly`):`${d(`deviceHubStatusError`)} ${I}`}),(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>void ve(),children:[(0,D.jsx)(u,{"aria-hidden":!0}),d(`deviceHubRetry`)]})]}),se&&!q&&(0,D.jsx)(`div`,{className:`dc-notice is-error`,role:`alert`,children:se}),ce&&(0,D.jsxs)(`div`,{className:`dc-notice is-success`,role:`status`,children:[(0,D.jsx)(n,{"aria-hidden":!0}),ce]}),m!==`devices`&&(!$||q)&&(0,D.jsxs)(`section`,{className:`dc-card`,children:[(0,D.jsx)(`h2`,{children:m===`groups`?p?`群组与工单`:`Groups & work items`:p?`外部渠道`:`External channels`}),(0,D.jsx)(`p`,{children:p?`先连接设备中心,再创建群组、配置群组 AI 并接入外部渠道。`:`Connect to a device hub before creating groups, configuring group AI, and connecting external channels.`}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button is-primary`,onClick:()=>_(`devices`),children:p?`前往设备连接`:`Connect a device`})]}),m===`groups`&&$&&!q&&(0,D.jsx)(B,{},`groups:${b?.hubUrl??``}:${b?.deviceId??``}`),m===`channels`&&$&&!q&&(0,D.jsx)(k,{plugin:i.find(e=>e.id===`superagent`),epoch:s,onManageGroups:()=>_(`groups`)},`channels:${b?.hubUrl??``}:${b?.deviceId??``}`),m===`devices`&&(0,D.jsxs)(D.Fragment,{children:[!$&&(b||q)&&(0,D.jsx)(L,{initialHubUrl:re,onConnect:e=>{if(q){z(d(`deviceHubLocalOnly`));return}fe.current=!0,S(e)}}),b&&!q&&!$&&(0,D.jsxs)(`section`,{className:`dc-card`,children:[(0,D.jsxs)(`div`,{className:`dc-card-header`,children:[(0,D.jsx)(`span`,{className:`dc-icon`,children:(0,D.jsx)(y,{"aria-hidden":!0})}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h2`,{children:d(`deviceHubPairTitle`)}),(0,D.jsx)(`p`,{children:d(`deviceHubPairHint`)})]})]}),(0,D.jsx)(`ol`,{className:`dc-steps`,children:[`deviceHubStepDetails`,`deviceHubStepApprove`,`deviceHubStepWait`].map((e,t)=>(0,D.jsxs)(`li`,{className:O?t===0?`is-complete`:`is-active`:t===0?`is-active`:``,children:[(0,D.jsx)(`span`,{className:`dc-step-number`,children:O&&t===0?(0,D.jsx)(n,{"aria-hidden":!0}):t+1}),(0,D.jsx)(`span`,{children:d(e)})]},e))}),(0,D.jsxs)(`form`,{className:`dc-form`,onSubmit:e=>{e.preventDefault(),ye()},children:[(0,D.jsxs)(`div`,{className:`dc-field`,children:[(0,D.jsx)(`label`,{htmlFor:`dc-hub-url`,children:d(`deviceHubHubUrl`)}),(0,D.jsx)(`input`,{id:`dc-hub-url`,type:`url`,autoComplete:`url`,required:!0,placeholder:d(`deviceHubHubPlaceholder`),value:re,disabled:!!O||!!N,onChange:e=>{fe.current=!0,S(e.target.value)}})]}),(0,D.jsxs)(`div`,{className:`dc-field`,children:[(0,D.jsx)(`label`,{htmlFor:`dc-device-name`,children:d(`deviceHubName`)}),(0,D.jsx)(`input`,{id:`dc-device-name`,maxLength:80,required:!0,autoComplete:`off`,placeholder:d(`deviceHubNamePlaceholder`),value:w,disabled:!!O||!!N,onChange:e=>{fe.current=!0,ae(e.target.value)}})]}),!O&&(0,D.jsx)(`div`,{className:`dc-actions`,children:(0,D.jsxs)(`button`,{className:`dc-button is-primary`,type:`submit`,disabled:!!N,children:[(0,D.jsx)(y,{"aria-hidden":!0}),d(N?`deviceHubWorking`:`deviceHubGetCode`)]})})]}),O&&(0,D.jsxs)(`div`,{className:`dc-pairing`,children:[(0,D.jsx)(`span`,{className:`dc-code-label`,children:d(`deviceHubCode`)}),(0,D.jsxs)(`div`,{className:`dc-code-row`,children:[(0,D.jsx)(`code`,{className:`dc-code`,children:O.code}),(0,D.jsx)(`button`,{className:`dc-icon-button`,type:`button`,"aria-label":d(`deviceHubCopy`),onClick:()=>void Ce(),children:(0,D.jsx)(o,{"aria-hidden":!0})})]}),(0,D.jsx)(`div`,{className:`dc-pair-meta`,children:d(Te?`deviceHubExpires`:`deviceHubExpired`,{time:Ee})}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[De,(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:!!N,onClick:()=>{++Y.current,j(null),F(``),z(``)},children:[(0,D.jsx)(u,{"aria-hidden":!0}),d(`deviceHubNewCode`)]})]}),Te>0&&(0,D.jsxs)(`p`,{className:`dc-progress`,role:`status`,children:[(0,D.jsx)(u,{"aria-hidden":!0}),d(`deviceHubWaiting`)]})]})]}),$&&b&&!q&&(0,D.jsxs)(`section`,{className:`dc-card`,children:[(0,D.jsxs)(`div`,{className:`dc-device-summary`,children:[(0,D.jsx)(`span`,{className:`dc-device-icon`,children:(0,D.jsx)(c,{"aria-hidden":!0})}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h2`,{children:b.remark?.trim()||b.name}),(0,D.jsx)(`p`,{children:b.remark?.trim()?`${b.name} · ${d(`deviceHubDeviceTitle`)}`:d(`deviceHubDeviceTitle`)})]})]}),(0,D.jsxs)(`dl`,{className:`dc-details`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`dt`,{children:d(`deviceHubDeviceId`)}),(0,D.jsx)(`dd`,{children:b.deviceId})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`dt`,{children:d(`deviceHubHubUrl`)}),(0,D.jsx)(`dd`,{children:b.hubUrl})]})]}),(0,D.jsx)(`div`,{className:`dc-actions`,style:{marginTop:`1rem`},children:(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:V||!!N,onClick:()=>void Se(),children:[(0,D.jsx)(u,{className:V?`spin`:``,"aria-hidden":!0}),d(V?`deviceHubUpgrading`:`deviceHubUpgradeAction`)]})})]}),$&&b?.hubUrl&&b.deviceId&&!q&&(0,D.jsx)(x,{hubUrl:b.hubUrl,currentDeviceId:b.deviceId},`directory:${b.hubUrl}:${b.deviceId}`),!q&&(0,D.jsx)(ie,{pathCompletions:e},`bots:${b?.hubUrl??``}:${b?.deviceId??`unpaired`}`),(0,D.jsx)(W,{}),$&&b&&!q&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`section`,{className:`dc-card`,children:[(0,D.jsxs)(`div`,{className:`dc-card-header`,children:[(0,D.jsx)(`span`,{className:`dc-icon`,children:(0,D.jsx)(ee,{"aria-hidden":!0})}),(0,D.jsx)(`div`,{children:(0,D.jsx)(`h2`,{children:d(`deviceHubPermissions`)})})]}),(0,D.jsxs)(`div`,{className:`dc-permission-row`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h3`,{id:`dc-permission-label`,children:d(`deviceHubPermissionLabel`)}),(0,D.jsx)(`p`,{id:`dc-permission-hint`,children:d(`deviceHubPermissionHint`)})]}),(0,D.jsx)(`button`,{type:`button`,className:`dc-toggle${b.allowExecution?` is-on`:``}`,role:`switch`,"aria-checked":b.allowExecution,"aria-labelledby":`dc-permission-label`,"aria-describedby":`dc-permission-hint`,disabled:!!N,onClick:()=>void be(),children:(0,D.jsx)(`span`,{className:`dc-toggle-thumb`})})]}),(0,D.jsx)(`p`,{className:`dc-permission-state`,role:`status`,children:d(N===`permission`?`deviceHubSaving`:b.allowExecution?`deviceHubEnabled`:`deviceHubReadOnly`)})]}),(0,D.jsx)(C,{hubUrl:b?.hubUrl,deviceId:b?.deviceId,onNotice:z}),(0,D.jsxs)(`details`,{className:`dc-advanced`,children:[(0,D.jsx)(`summary`,{children:d(`deviceHubAdvanced`)}),(0,D.jsxs)(`div`,{className:`dc-danger-zone`,children:[(0,D.jsx)(`h3`,{children:d(`deviceHubDisconnect`)}),(0,D.jsx)(`p`,{children:d(`deviceHubDisconnectHint`)}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button is-danger`,disabled:!!N,onClick:()=>void xe(),children:d(N===`disconnect`?`deviceHubWorking`:`deviceHubDisconnect`)})]})]})]}),(0,D.jsxs)(`aside`,{className:`dc-help`,children:[(0,D.jsx)(g,{className:`dc-help-icon`,"aria-hidden":!0}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h3`,{children:d(`deviceHubHelpTitle`)}),(0,D.jsx)(`p`,{children:d(`deviceHubHelpText`)})]})]})]})]})]})]})}export{G as DeviceCenter};
@@ -1,2 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$ as t,A as n,B as r,Bn as i,Fn as a,Gt as ee,Q as te,St as ne,Tn as re,Tt as ie,U as ae,X as oe,_n as se,et as ce,hn as le,jt as ue,t as de,vn as fe,xt as pe}from"./app-globals-CR8Ls9nE.js";import{i as me,t as o}from"./react-CR5VJ85Q.js";import{B as he,L as ge,at as _e,f as ve,nt as ye,st as be,tt as xe}from"./index-BBAQNi6v.js";var s=e(me(),1),c=`未命名章节`;function Se(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 Ce(e){let t=new Map;return e.map(({level:e,label:n})=>{let r=String(n??``).replace(/\s+/g,` `).trim(),i=Se(r||c),a=(t.get(i)??0)+1;return t.set(i,a),{level:e,id:a===1?i:`${i}-${a}`,label:r||c}})}function l(e){return e.length>=2}var u=o(),d=5e3,we=`pi-web-ui:preview-toc`;function f({file:e,composerSessionId:me,content:o,onAddLines:c,onAttach:Se,onClose:f,uiFilePreviewToolbar:Te,onUiAction:Ee}){let g=re(),De=ye(),[_,Oe]=(0,s.useState)(null),[v,ke]=(0,s.useState)(!1),[y,b]=(0,s.useState)(null),[Ae,je]=(0,s.useState)(!1),[Me,x]=(0,s.useState)(!1),[S,C]=(0,s.useState)(!1),[w,T]=(0,s.useState)(``),[E,D]=(0,s.useState)(!0),[O,k]=(0,s.useState)(!0),A=(0,s.useRef)(!1),[j,Ne]=(0,s.useState)(!0),[M,Pe]=(0,s.useState)(!1),[N,Fe]=(0,s.useState)(100),P=(0,s.useRef)(0),F=(0,s.useRef)(!1),I=(0,s.useRef)(null),[Ie,L]=(0,s.useState)(!1),[Le,R]=(0,s.useState)(!1),z=(0,s.useRef)(!1),B=(0,s.useRef)(null);(0,s.useEffect)(()=>()=>{I.current&&clearTimeout(I.current),B.current&&clearTimeout(B.current)},[]),(0,s.useEffect)(()=>{ke(!0),Oe(null),b(null),C(!1),T(``),D(!0),k(!0),A.current=!1,z.current=!1,L(!1),R(!1),B.current&&clearTimeout(B.current),de({type:`read_file`,path:e.path})},[e.path]),(0,s.useEffect)(()=>{o&&o.path===e.path&&(Oe(o),S||T(o.text),ke(!1),z.current&&(z.current=!1,B.current&&clearTimeout(B.current),L(!1),R(!1),C(!1),T(o.text),A.current&&(p(e.name)&&D(!0),h(e.name)&&k(!0)),b(null)))},[o,S,e.path]),(0,s.useEffect)(()=>{let e=e=>{if(e.key===`Escape`){U();return}if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`s`&&S){e.preventDefault(),Ge();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(),Ve())};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[f,_,S,w]),(0,s.useEffect)(()=>{let e=()=>{F.current=!1,je(!1)};return window.addEventListener(`mouseup`,e),()=>window.removeEventListener(`mouseup`,e)},[]);let V=(0,s.useMemo)(()=>{if(!_)return[];let e=_.text.split(`
2
- `);return e.length>0&&e[e.length-1]===``&&e.pop(),e.slice(0,d)},[_]),Re=_?.lines??0,ze=Re>d,Be=(e,t)=>{if(t){let t=P.current>0?P.current:e;b({start:Math.min(t,e),end:Math.max(t,e)})}else P.current=e,b({start:e,end:e})},Ve=()=>{V.length!==0&&(P.current=1,b({start:1,end:V.length}))},He=()=>{y&&(c(e.path,e.name,y.start,y.end),x(!0),I.current&&clearTimeout(I.current),I.current=setTimeout(()=>x(!1),1400))},H=_!==null&&_.kind===`text`&&!_.binary&&!_.truncated&&!m(e.name),Ue=()=>{z.current=!1,B.current&&clearTimeout(B.current),L(!1),R(!1),T(_?.text??``),C(!1),A.current&&(p(e.name)&&D(!0),h(e.name)&&k(!0))},We=()=>{if(S){if(w!==(_?.text??``)&&!window.confirm(g(`discardFileChanges`)))return;Ue();return}H&&_&&(A.current=p(e.name)&&E||h(e.name)&&O,p(e.name)&&D(!1),h(e.name)&&k(!1),b(null),T(_.text),C(!0))},Ge=()=>{S&&_&&H&&de({type:`write_file`,path:e.path,text:w})&&(z.current=!0,R(!1),L(!0),B.current&&clearTimeout(B.current),B.current=setTimeout(()=>{z.current=!1,L(!1),R(!0)},5e3))},U=()=>{(!S||w===(_?.text??``)||window.confirm(g(`discardFileChanges`)))&&f()},Ke=e=>{Fe(Math.min(200,Math.max(50,e)))},qe=y?y.end-y.start+1:0,W=_?.binary??!1,Je=_?.truncated??!1,G=_?.kind??`text`,Ye=p(e.name)||m(e.name),K=h(e.name),Xe=m(e.name),q=Ye&&E&&!S&&G===`text`&&!W,J=K&&O&&!S&&G===`text`&&!W,[Y,Ze]=(0,s.useState)(()=>{try{return localStorage.getItem(we)===`1`}catch{return!1}});(0,s.useEffect)(()=>{try{localStorage.setItem(we,Y?`1`:`0`)}catch{}},[Y]);let[X,Z]=(0,s.useState)([]),[Qe,$e]=(0,s.useState)(``),Q=(0,s.useRef)(null);(0,s.useEffect)(()=>{let e=Q.current;if(!e||!q){Z([]);return}let t=[...e.querySelectorAll(`h1, h2, h3, h4, h5, h6`)],n=Ce(t.map(e=>({level:Number(e.tagName.slice(1)),label:e.textContent??``})));t.forEach((e,t)=>{e.id||=n[t].id}),Z(n)},[q,_?.text,e.path]),(0,s.useEffect)(()=>{let e=Q.current;if(!e||!Y||!l(X))return;let t=X.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&&$e(t.target.id)},{rootMargin:`0px 0px -70% 0px`});for(let e of t)n.observe(e);return()=>n.disconnect()},[X,Y]);let $=e=>i(a(`/api/file?clientId=${encodeURIComponent(he())}&path=${encodeURIComponent(e)}`)),et=e=>{let t=e.split(`/`).map(e=>encodeURIComponent(e)).join(`/`),n=/^[A-Za-z]:([\\/]|$)/.test(e)||e.startsWith(`/`)?`/api/preview/__abs__/${t}`:`/api/preview/${t}`;return i(a(`${n}?clientId=${encodeURIComponent(he())}&allowJs=1`))},tt={"host:fp-md":Ye&&G===`text`&&!W&&_?(0,u.jsx)(`button`,{type:`button`,className:`fp-attach markdown ${E?`on`:``}`,"data-tip":g(E?`showMarkdownSource`:`showMarkdownPreview`),disabled:S,onClick:()=>D(e=>!e),children:E?(0,u.jsx)(ce,{}):(0,u.jsx)(r,{})}):null,"host:fp-toc":q&&l(X)?(0,u.jsx)(`button`,{type:`button`,className:`fp-attach toc ${Y?`on`:``}`,"data-tip":g(Y?`previewTocHide`:`previewTocShow`),onClick:()=>Ze(e=>!e),children:(0,u.jsx)(ne,{})}):null,"host:fp-html":K&&G===`text`&&!W&&_?(0,u.jsx)(`button`,{type:`button`,className:`fp-attach html ${O?`on`:``}`,"data-tip":g(O?`showHtmlSource`:`showHtmlPreview`),disabled:S,onClick:()=>k(e=>!e),children:O?(0,u.jsx)(r,{}):(0,u.jsx)(ce,{})}):null,"host:fp-external":K&&G===`text`&&!W&&_?(0,u.jsx)(`a`,{className:`fp-attach open`,href:et(e.path),target:`_blank`,rel:`noopener noreferrer`,"data-tip":g(`openInNewTab`),"aria-label":g(`openInNewTab`),children:(0,u.jsx)(t,{})}):null,"host:fp-edit":G===`text`&&!W&&_?(0,u.jsx)(`button`,{type:`button`,className:`fp-attach edit ${S?`on`:``}`,"data-tip":g(Je?`fileEditTruncated`:S?`exitEditFile`:`editFile`),disabled:!H&&!S,onClick:We,children:(0,u.jsx)(te,{})}):null,"host:fp-wrap":G===`text`&&!W&&!q&&!J?(0,u.jsx)(`button`,{type:`button`,className:`fp-attach wrap ${j?`on`:``}`,"data-tip":g(j?`disableWrap`:`enableWrap`),onClick:()=>Ne(e=>!e),children:(0,u.jsx)(ae,{})}):null,"host:fp-zoom":G===`text`&&_?(0,u.jsxs)(`span`,{className:`fp-zoom`,children:[(0,u.jsx)(`button`,{type:`button`,className:`fp-attach zoom-out`,"data-tip":g(`zoomOut`),disabled:N<=50,onClick:()=>Ke(N-10),children:(0,u.jsx)(fe,{})}),(0,u.jsxs)(`button`,{type:`button`,className:`fp-zoom-val`,title:g(`resetZoom`),onClick:()=>Fe(100),children:[N,`%`]}),(0,u.jsx)(`button`,{type:`button`,className:`fp-attach zoom-in`,"data-tip":g(`zoomIn`),disabled:N>=200,onClick:()=>Ke(N+10),children:(0,u.jsx)(se,{})})]}):null,"host:fp-download":(0,u.jsx)(`button`,{type:`button`,className:`fp-attach download`,"data-tip":g(`downloadFile`),onClick:()=>void _e(e.path,e.name),children:(0,u.jsx)(oe,{})}),"host:fp-ref":(0,u.jsx)(`button`,{type:`button`,className:`fp-attach ref`,"data-tip":g(`referenceTip`),onClick:()=>Se(e.path,e.name,`reference`),children:(0,u.jsx)(pe,{})}),"host:fp-full":(0,u.jsx)(`button`,{type:`button`,className:`fp-attach full ${M?`on`:``}`,"data-tip":g(M?`exitFullscreen`:`fullscreen`),onClick:()=>Pe(e=>!e),children:M?(0,u.jsx)(ue,{}):(0,u.jsx)(ie,{})}),"host:fp-close":null},nt=Te===void 0?[`host:fp-md`,`host:fp-toc`,`host:fp-html`,`host:fp-external`,`host:fp-edit`,`host:fp-wrap`,`host:fp-zoom`,`host:fp-download`,`host:fp-ref`,`host:fp-full`].map(e=>({id:e,source:`host`})):Te.filter(e=>!e.hidden&&e.id!==`host:fp-close`);return G===`image`&&!v?(0,u.jsx)(ve,{src:$(e.path),alt:e.name,onClose:U,composerSessionId:me}):(0,u.jsx)(`div`,{className:`fp-overlay ${M?`fullscreen`:``}`,style:{zIndex:De},onMouseDown:e=>{e.target===e.currentTarget&&U()},children:(0,u.jsxs)(`div`,{className:`fp ${M?`fullscreen`:``} ${Xe?`is-ppt`:``}`,style:{"--fp-zoom":N/100},children:[(0,u.jsxs)(`div`,{className:`fp-head`,onDoubleClick:e=>{let t=e.target;t&&!t.closest(`button, a, input`)&&Pe(e=>!e)},children:[(0,u.jsx)(`span`,{className:`fp-name`,title:e.path,children:e.name}),(0,u.jsx)(`span`,{className:`fp-path`,children:e.path}),(0,u.jsxs)(`span`,{className:`fp-meta`,children:[_&&G===`text`&&!W&&g(`fileLines`,{n:Re}),_&&` · ${xe(_.size)}`]}),(0,u.jsx)(`span`,{className:`fp-head-actions`,children:ge(nt,tt,Ee)}),(0,u.jsx)(`button`,{type:`button`,className:`fp-close`,title:g(`close`),"aria-label":g(`close`),onClick:U,children:(0,u.jsx)(le,{})})]}),Je&&G===`text`&&!W&&(0,u.jsx)(`div`,{className:`fp-notice`,children:m(e.name)?g(`previewLinesTruncated`,{n:V.length}):g(`previewTruncated`)}),v&&!_&&(0,u.jsx)(`div`,{className:`fp-empty`,children:g(`loading`)}),!v&&G===`none`&&!W&&(0,u.jsx)(`div`,{className:`fp-empty`,children:g(`previewNotSupported`)}),!v&&G===`video`&&(0,u.jsx)(`div`,{className:`fp-media-wrap`,children:(0,u.jsx)(`video`,{className:`fp-media`,src:$(e.path),controls:!0,preload:`metadata`})}),!v&&G===`audio`&&(0,u.jsx)(`div`,{className:`fp-media-wrap fp-audio-wrap`,children:(0,u.jsxs)(`div`,{className:`fp-audio-card`,children:[(0,u.jsx)(`div`,{className:`fp-audio-icon`,"aria-hidden":`true`,children:`🎵`}),(0,u.jsxs)(`div`,{className:`fp-audio-info`,children:[(0,u.jsx)(`div`,{className:`fp-audio-name`,title:e.name,children:e.name}),_?.size?(0,u.jsx)(`div`,{className:`fp-audio-size`,children:xe(_.size)}):null]}),(0,u.jsx)(`audio`,{className:`fp-audio-element`,src:$(e.path),controls:!0,autoPlay:!0,preload:`metadata`})]})}),!v&&J&&_&&(0,u.jsx)(`div`,{className:`fp-html`,children:(0,u.jsx)(`iframe`,{className:`fp-html-frame`,src:et(e.path),title:e.name,sandbox:`allow-scripts`,referrerPolicy:`no-referrer`})}),!v&&q&&_&&(0,u.jsx)(`div`,{className:m(e.name)?`fp-markdown msg-text fp-office`:`fp-markdown msg-text`,children:(0,u.jsxs)(`div`,{className:Y&&l(X)?`fp-toc-layout`:void 0,children:[Y&&l(X)&&(0,u.jsx)(`nav`,{className:`fp-toc`,"aria-label":g(`previewTocLabel`),children:X.map(e=>(0,u.jsx)(`a`,{className:`l${Math.min(e.level,6)}${e.id===Qe?` 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,u.jsx)(`div`,{className:`fp-markdown-zoom`,ref:Q,children:(0,u.jsx)(be,{text:_.text})})]})}),!v&&W&&G!==`image`&&G!==`video`&&_&&(0,u.jsxs)(`div`,{className:`fp-hex-wrap`,children:[(0,u.jsxs)(`div`,{className:`fp-notice`,children:[g(`binaryFile`),_.truncated&&g(`binaryHexTruncated`)]}),(0,u.jsx)(`pre`,{className:`fp-hex`,children:_.text})]}),!v&&S&&G===`text`&&!W&&_&&(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(`textarea`,{className:`fp-editor ${j?``:`no-wrap`}`,value:w,onChange:e=>T(e.target.value),wrap:j?`soft`:`off`,spellCheck:!1,autoFocus:!0}),Le&&(0,u.jsx)(`div`,{className:`fp-notice`,role:`alert`,children:g(`saveResultUnknown`)})]}),!v&&!q&&!J&&!S&&G===`text`&&!W&&_&&V.length===0&&(0,u.jsx)(`div`,{className:`fp-empty`,children:g(`emptyFile`)}),!v&&!q&&!J&&!S&&G===`text`&&!W&&V.length>0&&(0,u.jsxs)(`div`,{className:`fp-code ${Ae?`dragging`:``} ${j?``:`no-wrap`}`,onMouseDown:e=>{e.button===0&&e.preventDefault()},children:[V.map((e,t)=>{let n=t+1,r=y!==null&&n>=y.start&&n<=y.end;return(0,u.jsxs)(`div`,{className:`fp-line ${r?`sel`:``}`,onMouseDown:e=>{e.button===0&&(Be(n,e.shiftKey),F.current=!0,je(!0))},onMouseEnter:()=>{F.current&&Be(n,!0)},children:[(0,u.jsx)(`span`,{className:`fp-num`,children:n}),(0,u.jsx)(`span`,{className:`fp-code-text`,children:e})]},n)}),ze&&(0,u.jsx)(`div`,{className:`fp-lines-note`,children:g(`previewLinesTruncated`,{n:d})})]}),(S||!q&&!J&&G===`text`)&&(0,u.jsx)(`div`,{className:`fp-foot`,children:S?(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(`span`,{className:`fp-hint`,children:g(`editFile`)}),(0,u.jsxs)(`div`,{className:`fp-actions`,children:[(0,u.jsx)(`button`,{type:`button`,className:`btn`,onClick:We,children:g(`cancel`)}),(0,u.jsxs)(`button`,{type:`button`,className:`btn primary`,disabled:Ie||w===(_?.text??``),onClick:Ge,children:[(0,u.jsx)(ee,{}),` `,g(`saveFile`)]})]})]}):(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(`span`,{className:`fp-hint`,children:y?g(`selectedRange`,{n:qe,start:y.start,end:y.end}):g(`selectLinesHint`)}),(0,u.jsxs)(`div`,{className:`fp-actions`,children:[(0,u.jsx)(`button`,{type:`button`,className:`btn`,disabled:V.length===0,onClick:Ve,children:g(`selectAll`)}),(0,u.jsx)(`button`,{type:`button`,className:`btn`,disabled:!y,onClick:()=>b(null),children:g(`clearSelection`)}),(0,u.jsxs)(`button`,{type:`button`,className:`btn primary`,disabled:!y||W,onClick:He,children:[Me?(0,u.jsx)(n,{}):null,g(Me?`addedToChat`:`addToChat`)]})]})]})})]})})}function p(e){let t=e.toLowerCase();return t.endsWith(`.md`)||t.endsWith(`.markdown`)}function m(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 h(e){let t=e.toLowerCase();return t.endsWith(`.html`)||t.endsWith(`.htm`)||t.endsWith(`.xhtml`)}export{f as FilePreview};
@@ -1,2 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$ as t,A as n,B as r,Bn as i,Fn as a,Gt as ee,Q as te,St as ne,Tn as re,Tt as ie,U as ae,X as oe,_n as se,et as ce,hn as le,jt as ue,t as de,vn as fe,xt as pe}from"./app-globals-CR8Ls9nE.js";import{i as me,t as o}from"./react-CR5VJ85Q.js";import{B as he,L as ge,at as _e,f as ve,nt as ye,st as be,tt as xe}from"./index-BYW9d61A.js";var s=e(me(),1),c=`未命名章节`;function Se(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 Ce(e){let t=new Map;return e.map(({level:e,label:n})=>{let r=String(n??``).replace(/\s+/g,` `).trim(),i=Se(r||c),a=(t.get(i)??0)+1;return t.set(i,a),{level:e,id:a===1?i:`${i}-${a}`,label:r||c}})}function l(e){return e.length>=2}var u=o(),d=5e3,we=`pi-web-ui:preview-toc`;function f({file:e,composerSessionId:me,content:o,onAddLines:c,onAttach:Se,onClose:f,uiFilePreviewToolbar:Te,onUiAction:Ee}){let g=re(),De=ye(),[_,Oe]=(0,s.useState)(null),[v,ke]=(0,s.useState)(!1),[y,b]=(0,s.useState)(null),[Ae,je]=(0,s.useState)(!1),[Me,x]=(0,s.useState)(!1),[S,C]=(0,s.useState)(!1),[w,T]=(0,s.useState)(``),[E,D]=(0,s.useState)(!0),[O,k]=(0,s.useState)(!0),A=(0,s.useRef)(!1),[j,Ne]=(0,s.useState)(!0),[M,Pe]=(0,s.useState)(!1),[N,Fe]=(0,s.useState)(100),P=(0,s.useRef)(0),F=(0,s.useRef)(!1),I=(0,s.useRef)(null),[Ie,L]=(0,s.useState)(!1),[Le,R]=(0,s.useState)(!1),z=(0,s.useRef)(!1),B=(0,s.useRef)(null);(0,s.useEffect)(()=>()=>{I.current&&clearTimeout(I.current),B.current&&clearTimeout(B.current)},[]),(0,s.useEffect)(()=>{ke(!0),Oe(null),b(null),C(!1),T(``),D(!0),k(!0),A.current=!1,z.current=!1,L(!1),R(!1),B.current&&clearTimeout(B.current),de({type:`read_file`,path:e.path})},[e.path]),(0,s.useEffect)(()=>{o&&o.path===e.path&&(Oe(o),S||T(o.text),ke(!1),z.current&&(z.current=!1,B.current&&clearTimeout(B.current),L(!1),R(!1),C(!1),T(o.text),A.current&&(p(e.name)&&D(!0),h(e.name)&&k(!0)),b(null)))},[o,S,e.path]),(0,s.useEffect)(()=>{let e=e=>{if(e.key===`Escape`){U();return}if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`s`&&S){e.preventDefault(),Ge();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(),Ve())};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[f,_,S,w]),(0,s.useEffect)(()=>{let e=()=>{F.current=!1,je(!1)};return window.addEventListener(`mouseup`,e),()=>window.removeEventListener(`mouseup`,e)},[]);let V=(0,s.useMemo)(()=>{if(!_)return[];let e=_.text.split(`
2
- `);return e.length>0&&e[e.length-1]===``&&e.pop(),e.slice(0,d)},[_]),Re=_?.lines??0,ze=Re>d,Be=(e,t)=>{if(t){let t=P.current>0?P.current:e;b({start:Math.min(t,e),end:Math.max(t,e)})}else P.current=e,b({start:e,end:e})},Ve=()=>{V.length!==0&&(P.current=1,b({start:1,end:V.length}))},He=()=>{y&&(c(e.path,e.name,y.start,y.end),x(!0),I.current&&clearTimeout(I.current),I.current=setTimeout(()=>x(!1),1400))},H=_!==null&&_.kind===`text`&&!_.binary&&!_.truncated&&!m(e.name),Ue=()=>{z.current=!1,B.current&&clearTimeout(B.current),L(!1),R(!1),T(_?.text??``),C(!1),A.current&&(p(e.name)&&D(!0),h(e.name)&&k(!0))},We=()=>{if(S){if(w!==(_?.text??``)&&!window.confirm(g(`discardFileChanges`)))return;Ue();return}H&&_&&(A.current=p(e.name)&&E||h(e.name)&&O,p(e.name)&&D(!1),h(e.name)&&k(!1),b(null),T(_.text),C(!0))},Ge=()=>{S&&_&&H&&de({type:`write_file`,path:e.path,text:w})&&(z.current=!0,R(!1),L(!0),B.current&&clearTimeout(B.current),B.current=setTimeout(()=>{z.current=!1,L(!1),R(!0)},5e3))},U=()=>{(!S||w===(_?.text??``)||window.confirm(g(`discardFileChanges`)))&&f()},Ke=e=>{Fe(Math.min(200,Math.max(50,e)))},qe=y?y.end-y.start+1:0,W=_?.binary??!1,Je=_?.truncated??!1,G=_?.kind??`text`,Ye=p(e.name)||m(e.name),K=h(e.name),Xe=m(e.name),q=Ye&&E&&!S&&G===`text`&&!W,J=K&&O&&!S&&G===`text`&&!W,[Y,Ze]=(0,s.useState)(()=>{try{return localStorage.getItem(we)===`1`}catch{return!1}});(0,s.useEffect)(()=>{try{localStorage.setItem(we,Y?`1`:`0`)}catch{}},[Y]);let[X,Z]=(0,s.useState)([]),[Qe,$e]=(0,s.useState)(``),Q=(0,s.useRef)(null);(0,s.useEffect)(()=>{let e=Q.current;if(!e||!q){Z([]);return}let t=[...e.querySelectorAll(`h1, h2, h3, h4, h5, h6`)],n=Ce(t.map(e=>({level:Number(e.tagName.slice(1)),label:e.textContent??``})));t.forEach((e,t)=>{e.id||=n[t].id}),Z(n)},[q,_?.text,e.path]),(0,s.useEffect)(()=>{let e=Q.current;if(!e||!Y||!l(X))return;let t=X.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&&$e(t.target.id)},{rootMargin:`0px 0px -70% 0px`});for(let e of t)n.observe(e);return()=>n.disconnect()},[X,Y]);let $=e=>i(a(`/api/file?clientId=${encodeURIComponent(he())}&path=${encodeURIComponent(e)}`)),et=e=>{let t=e.split(`/`).map(e=>encodeURIComponent(e)).join(`/`),n=/^[A-Za-z]:([\\/]|$)/.test(e)||e.startsWith(`/`)?`/api/preview/__abs__/${t}`:`/api/preview/${t}`;return i(a(`${n}?clientId=${encodeURIComponent(he())}&allowJs=1`))},tt={"host:fp-md":Ye&&G===`text`&&!W&&_?(0,u.jsx)(`button`,{type:`button`,className:`fp-attach markdown ${E?`on`:``}`,"data-tip":g(E?`showMarkdownSource`:`showMarkdownPreview`),disabled:S,onClick:()=>D(e=>!e),children:E?(0,u.jsx)(ce,{}):(0,u.jsx)(r,{})}):null,"host:fp-toc":q&&l(X)?(0,u.jsx)(`button`,{type:`button`,className:`fp-attach toc ${Y?`on`:``}`,"data-tip":g(Y?`previewTocHide`:`previewTocShow`),onClick:()=>Ze(e=>!e),children:(0,u.jsx)(ne,{})}):null,"host:fp-html":K&&G===`text`&&!W&&_?(0,u.jsx)(`button`,{type:`button`,className:`fp-attach html ${O?`on`:``}`,"data-tip":g(O?`showHtmlSource`:`showHtmlPreview`),disabled:S,onClick:()=>k(e=>!e),children:O?(0,u.jsx)(r,{}):(0,u.jsx)(ce,{})}):null,"host:fp-external":K&&G===`text`&&!W&&_?(0,u.jsx)(`a`,{className:`fp-attach open`,href:et(e.path),target:`_blank`,rel:`noopener noreferrer`,"data-tip":g(`openInNewTab`),"aria-label":g(`openInNewTab`),children:(0,u.jsx)(t,{})}):null,"host:fp-edit":G===`text`&&!W&&_?(0,u.jsx)(`button`,{type:`button`,className:`fp-attach edit ${S?`on`:``}`,"data-tip":g(Je?`fileEditTruncated`:S?`exitEditFile`:`editFile`),disabled:!H&&!S,onClick:We,children:(0,u.jsx)(te,{})}):null,"host:fp-wrap":G===`text`&&!W&&!q&&!J?(0,u.jsx)(`button`,{type:`button`,className:`fp-attach wrap ${j?`on`:``}`,"data-tip":g(j?`disableWrap`:`enableWrap`),onClick:()=>Ne(e=>!e),children:(0,u.jsx)(ae,{})}):null,"host:fp-zoom":G===`text`&&_?(0,u.jsxs)(`span`,{className:`fp-zoom`,children:[(0,u.jsx)(`button`,{type:`button`,className:`fp-attach zoom-out`,"data-tip":g(`zoomOut`),disabled:N<=50,onClick:()=>Ke(N-10),children:(0,u.jsx)(fe,{})}),(0,u.jsxs)(`button`,{type:`button`,className:`fp-zoom-val`,title:g(`resetZoom`),onClick:()=>Fe(100),children:[N,`%`]}),(0,u.jsx)(`button`,{type:`button`,className:`fp-attach zoom-in`,"data-tip":g(`zoomIn`),disabled:N>=200,onClick:()=>Ke(N+10),children:(0,u.jsx)(se,{})})]}):null,"host:fp-download":(0,u.jsx)(`button`,{type:`button`,className:`fp-attach download`,"data-tip":g(`downloadFile`),onClick:()=>void _e(e.path,e.name),children:(0,u.jsx)(oe,{})}),"host:fp-ref":(0,u.jsx)(`button`,{type:`button`,className:`fp-attach ref`,"data-tip":g(`referenceTip`),onClick:()=>Se(e.path,e.name,`reference`),children:(0,u.jsx)(pe,{})}),"host:fp-full":(0,u.jsx)(`button`,{type:`button`,className:`fp-attach full ${M?`on`:``}`,"data-tip":g(M?`exitFullscreen`:`fullscreen`),onClick:()=>Pe(e=>!e),children:M?(0,u.jsx)(ue,{}):(0,u.jsx)(ie,{})}),"host:fp-close":null},nt=Te===void 0?[`host:fp-md`,`host:fp-toc`,`host:fp-html`,`host:fp-external`,`host:fp-edit`,`host:fp-wrap`,`host:fp-zoom`,`host:fp-download`,`host:fp-ref`,`host:fp-full`].map(e=>({id:e,source:`host`})):Te.filter(e=>!e.hidden&&e.id!==`host:fp-close`);return G===`image`&&!v?(0,u.jsx)(ve,{src:$(e.path),alt:e.name,onClose:U,composerSessionId:me}):(0,u.jsx)(`div`,{className:`fp-overlay ${M?`fullscreen`:``}`,style:{zIndex:De},onMouseDown:e=>{e.target===e.currentTarget&&U()},children:(0,u.jsxs)(`div`,{className:`fp ${M?`fullscreen`:``} ${Xe?`is-ppt`:``}`,style:{"--fp-zoom":N/100},children:[(0,u.jsxs)(`div`,{className:`fp-head`,onDoubleClick:e=>{let t=e.target;t&&!t.closest(`button, a, input`)&&Pe(e=>!e)},children:[(0,u.jsx)(`span`,{className:`fp-name`,title:e.path,children:e.name}),(0,u.jsx)(`span`,{className:`fp-path`,children:e.path}),(0,u.jsxs)(`span`,{className:`fp-meta`,children:[_&&G===`text`&&!W&&g(`fileLines`,{n:Re}),_&&` · ${xe(_.size)}`]}),(0,u.jsx)(`span`,{className:`fp-head-actions`,children:ge(nt,tt,Ee)}),(0,u.jsx)(`button`,{type:`button`,className:`fp-close`,title:g(`close`),"aria-label":g(`close`),onClick:U,children:(0,u.jsx)(le,{})})]}),Je&&G===`text`&&!W&&(0,u.jsx)(`div`,{className:`fp-notice`,children:m(e.name)?g(`previewLinesTruncated`,{n:V.length}):g(`previewTruncated`)}),v&&!_&&(0,u.jsx)(`div`,{className:`fp-empty`,children:g(`loading`)}),!v&&G===`none`&&!W&&(0,u.jsx)(`div`,{className:`fp-empty`,children:g(`previewNotSupported`)}),!v&&G===`video`&&(0,u.jsx)(`div`,{className:`fp-media-wrap`,children:(0,u.jsx)(`video`,{className:`fp-media`,src:$(e.path),controls:!0,preload:`metadata`})}),!v&&G===`audio`&&(0,u.jsx)(`div`,{className:`fp-media-wrap fp-audio-wrap`,children:(0,u.jsxs)(`div`,{className:`fp-audio-card`,children:[(0,u.jsx)(`div`,{className:`fp-audio-icon`,"aria-hidden":`true`,children:`🎵`}),(0,u.jsxs)(`div`,{className:`fp-audio-info`,children:[(0,u.jsx)(`div`,{className:`fp-audio-name`,title:e.name,children:e.name}),_?.size?(0,u.jsx)(`div`,{className:`fp-audio-size`,children:xe(_.size)}):null]}),(0,u.jsx)(`audio`,{className:`fp-audio-element`,src:$(e.path),controls:!0,autoPlay:!0,preload:`metadata`})]})}),!v&&J&&_&&(0,u.jsx)(`div`,{className:`fp-html`,children:(0,u.jsx)(`iframe`,{className:`fp-html-frame`,src:et(e.path),title:e.name,sandbox:`allow-scripts`,referrerPolicy:`no-referrer`})}),!v&&q&&_&&(0,u.jsx)(`div`,{className:m(e.name)?`fp-markdown msg-text fp-office`:`fp-markdown msg-text`,children:(0,u.jsxs)(`div`,{className:Y&&l(X)?`fp-toc-layout`:void 0,children:[Y&&l(X)&&(0,u.jsx)(`nav`,{className:`fp-toc`,"aria-label":g(`previewTocLabel`),children:X.map(e=>(0,u.jsx)(`a`,{className:`l${Math.min(e.level,6)}${e.id===Qe?` 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,u.jsx)(`div`,{className:`fp-markdown-zoom`,ref:Q,children:(0,u.jsx)(be,{text:_.text})})]})}),!v&&W&&G!==`image`&&G!==`video`&&_&&(0,u.jsxs)(`div`,{className:`fp-hex-wrap`,children:[(0,u.jsxs)(`div`,{className:`fp-notice`,children:[g(`binaryFile`),_.truncated&&g(`binaryHexTruncated`)]}),(0,u.jsx)(`pre`,{className:`fp-hex`,children:_.text})]}),!v&&S&&G===`text`&&!W&&_&&(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(`textarea`,{className:`fp-editor ${j?``:`no-wrap`}`,value:w,onChange:e=>T(e.target.value),wrap:j?`soft`:`off`,spellCheck:!1,autoFocus:!0}),Le&&(0,u.jsx)(`div`,{className:`fp-notice`,role:`alert`,children:g(`saveResultUnknown`)})]}),!v&&!q&&!J&&!S&&G===`text`&&!W&&_&&V.length===0&&(0,u.jsx)(`div`,{className:`fp-empty`,children:g(`emptyFile`)}),!v&&!q&&!J&&!S&&G===`text`&&!W&&V.length>0&&(0,u.jsxs)(`div`,{className:`fp-code ${Ae?`dragging`:``} ${j?``:`no-wrap`}`,onMouseDown:e=>{e.button===0&&e.preventDefault()},children:[V.map((e,t)=>{let n=t+1,r=y!==null&&n>=y.start&&n<=y.end;return(0,u.jsxs)(`div`,{className:`fp-line ${r?`sel`:``}`,onMouseDown:e=>{e.button===0&&(Be(n,e.shiftKey),F.current=!0,je(!0))},onMouseEnter:()=>{F.current&&Be(n,!0)},children:[(0,u.jsx)(`span`,{className:`fp-num`,children:n}),(0,u.jsx)(`span`,{className:`fp-code-text`,children:e})]},n)}),ze&&(0,u.jsx)(`div`,{className:`fp-lines-note`,children:g(`previewLinesTruncated`,{n:d})})]}),(S||!q&&!J&&G===`text`)&&(0,u.jsx)(`div`,{className:`fp-foot`,children:S?(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(`span`,{className:`fp-hint`,children:g(`editFile`)}),(0,u.jsxs)(`div`,{className:`fp-actions`,children:[(0,u.jsx)(`button`,{type:`button`,className:`btn`,onClick:We,children:g(`cancel`)}),(0,u.jsxs)(`button`,{type:`button`,className:`btn primary`,disabled:Ie||w===(_?.text??``),onClick:Ge,children:[(0,u.jsx)(ee,{}),` `,g(`saveFile`)]})]})]}):(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(`span`,{className:`fp-hint`,children:y?g(`selectedRange`,{n:qe,start:y.start,end:y.end}):g(`selectLinesHint`)}),(0,u.jsxs)(`div`,{className:`fp-actions`,children:[(0,u.jsx)(`button`,{type:`button`,className:`btn`,disabled:V.length===0,onClick:Ve,children:g(`selectAll`)}),(0,u.jsx)(`button`,{type:`button`,className:`btn`,disabled:!y,onClick:()=>b(null),children:g(`clearSelection`)}),(0,u.jsxs)(`button`,{type:`button`,className:`btn primary`,disabled:!y||W,onClick:He,children:[Me?(0,u.jsx)(n,{}):null,g(Me?`addedToChat`:`addToChat`)]})]})]})})]})})}function p(e){let t=e.toLowerCase();return t.endsWith(`.md`)||t.endsWith(`.markdown`)}function m(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 h(e){let t=e.toLowerCase();return t.endsWith(`.html`)||t.endsWith(`.htm`)||t.endsWith(`.xhtml`)}export{f as FilePreview};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Rt as t,Tn as n,at as r,hn as i,i as a,kt as o,o as s,ot as c,qt as l,t as u}from"./app-globals-CR8Ls9nE.js";import{i as d,t as f}from"./react-CR5VJ85Q.js";import{t as p}from"./composer-bridge-CImnjDHq.js";import{f as m,s as h,u as g}from"./plugin-host-CVgcdBOk.js";import{O as _}from"./index-BBAQNi6v.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=n(),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 g==`function`&&(r=g())}catch{r=[]}let i=r.filter(e=>e&&typeof e.id==`string`).map(e=>{if(typeof e.search==`function`)return e;try{let t=h(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`?m(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)(l,{}),(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)(i,{})})]}),(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)(o,{})),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)(c,{})),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)(r,{})),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 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Rt as t,Tn as n,at as r,hn as i,i as a,kt as o,o as s,ot as c,qt as l,t as u}from"./app-globals-CR8Ls9nE.js";import{i as d,t as f}from"./react-CR5VJ85Q.js";import{t as p}from"./composer-bridge-CImnjDHq.js";import{f as m,s as h,u as g}from"./plugin-host-CVgcdBOk.js";import{O as _}from"./index-BYW9d61A.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=n(),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 g==`function`&&(r=g())}catch{r=[]}let i=r.filter(e=>e&&typeof e.id==`string`).map(e=>{if(typeof e.search==`function`)return e;try{let t=h(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`?m(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)(l,{}),(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)(i,{})})]}),(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)(o,{})),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)(c,{})),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)(r,{})),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};