pi-web-ui 0.114.2 → 0.115.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 (195) hide show
  1. package/CHANGELOG.md +55 -1
  2. package/bin/pi-web-ui.mjs +69 -7
  3. package/dist/server/agent-service-daemon.js +440 -32
  4. package/dist/server/agent-service.js +878 -383
  5. package/dist/server/canvas/canvas-dispatch.js +13 -1
  6. package/dist/server/client-state.js +25 -0
  7. package/dist/server/communicate-tool.js +2 -0
  8. package/dist/server/context-usage.js +105 -0
  9. package/dist/server/conversation-communication.js +14 -0
  10. package/dist/server/conversation-identity.js +27 -0
  11. package/dist/server/device-center/approval-summary.js +31 -0
  12. package/dist/server/device-center/bot-catalog.js +21 -7
  13. package/dist/server/device-center/bot-execution.js +72 -9
  14. package/dist/server/device-center/bot-presets.js +46 -0
  15. package/dist/server/device-center/collab-service.js +328 -10
  16. package/dist/server/device-center/collab-tool.js +738 -12
  17. package/dist/server/device-center/connector.js +359 -23
  18. package/dist/server/device-center/desktop-page.js +22 -16
  19. package/dist/server/device-center/device-integration.js +595 -0
  20. package/dist/server/device-center/execution-guides.js +32 -0
  21. package/dist/server/device-center/execution-instructions.js +19 -0
  22. package/dist/server/device-center/execution-settings.js +100 -0
  23. package/dist/server/device-center/execution-system-prompt.js +38 -0
  24. package/dist/server/device-center/execution-workspace.js +20 -0
  25. package/dist/server/device-center/executor.js +389 -40
  26. package/dist/server/device-center/file-sync-paths.js +171 -0
  27. package/dist/server/device-center/file-sync.js +180 -91
  28. package/dist/server/device-center/group-context-delta.js +37 -0
  29. package/dist/server/device-center/group-context-message.js +208 -0
  30. package/dist/server/device-center/group-context.js +109 -0
  31. package/dist/server/device-center/group-events.js +136 -0
  32. package/dist/server/device-center/group-plan-guard.js +138 -0
  33. package/dist/server/device-center/hub-conversations.js +178 -0
  34. package/dist/server/device-center/hub-deliveries.js +277 -0
  35. package/dist/server/device-center/hub-integration.js +451 -0
  36. package/dist/server/device-center/hub.js +1544 -80
  37. package/dist/server/device-center/human-interaction.js +232 -0
  38. package/dist/server/device-center/integration-errors.js +25 -0
  39. package/dist/server/device-center/local-hub.js +18 -0
  40. package/dist/server/device-center/local.js +356 -40
  41. package/dist/server/device-center/main.js +11 -1
  42. package/dist/server/device-center/path-portal.js +11 -3
  43. package/dist/server/device-center/relay.js +364 -35
  44. package/dist/server/device-center/report-metadata.js +66 -0
  45. package/dist/server/device-center/report-upload.js +63 -0
  46. package/dist/server/device-center/runtime.js +549 -41
  47. package/dist/server/device-center/store.js +66 -3
  48. package/dist/server/device-center/task-context-budget.js +161 -0
  49. package/dist/server/device-center/task-journal.js +385 -0
  50. package/dist/server/device-center/task-plan.js +33 -0
  51. package/dist/server/device-center/task-progress.js +141 -0
  52. package/dist/server/device-center/task-recovery.js +452 -0
  53. package/dist/server/device-center/task-report-outbox.js +216 -0
  54. package/dist/server/device-center/task-report.js +384 -0
  55. package/dist/server/device-center/task-scheduler.js +400 -0
  56. package/dist/server/device-center/task-state.js +333 -0
  57. package/dist/server/device-center/transfer-stream.js +1006 -0
  58. package/dist/server/device-center/transfers.js +815 -8
  59. package/dist/server/dispatch-domain-handlers.js +21 -3
  60. package/dist/server/dsh/dsh-agent-service.js +6 -0
  61. package/dist/server/goal-service.js +10 -5
  62. package/dist/server/index.js +89 -13
  63. package/dist/server/message-deletion.js +40 -0
  64. package/dist/server/message-window.js +9 -0
  65. package/dist/server/patch-executable-lookup.js +396 -0
  66. package/dist/server/payload-limits.js +2 -0
  67. package/dist/server/plugin-llm.js +100 -9
  68. package/dist/server/plugins.js +1 -0
  69. package/dist/server/preset-fields.js +24 -0
  70. package/dist/server/preset-share.js +2 -0
  71. package/dist/server/prompt-base-store.js +85 -0
  72. package/dist/server/prompt-composer.js +5 -2
  73. package/dist/server/protocol-version.js +1 -1
  74. package/dist/server/protocol.js +2 -2
  75. package/dist/server/remote-ssh-service.js +22 -9
  76. package/dist/server/resolve-global-sdk.js +2 -0
  77. package/dist/server/session-search.js +1 -1
  78. package/dist/server/settings-service.js +90 -39
  79. package/dist/server/skill-content-filler.js +29 -8
  80. package/dist/server/skill-tool.js +12 -3
  81. package/dist/server/subagent-helpers.js +4 -1
  82. package/dist/server/subagents.js +50 -36
  83. package/dist/server/tool-host-factories.js +1 -0
  84. package/dist/server/universal/universal-session.js +5 -0
  85. package/dist/server/webui-context.js +25 -5
  86. package/docs/README.md +94 -0
  87. package/docs/device-center.md +100 -12
  88. package/docs/dsh-engine.md +10 -10
  89. package/extensions/webui.ts +43 -1
  90. package/package.json +1 -1
  91. package/themes/aetheris.css +5 -0
  92. package/themes/ayu-light.css +6 -0
  93. package/themes/bases/flow-base.css +68 -68
  94. package/themes/catppuccin-latte.css +6 -0
  95. package/themes/catppuccin.css +6 -0
  96. package/themes/claude-code-dark.css +5 -0
  97. package/themes/codex.css +6 -0
  98. package/themes/cyberpunk.css +6 -0
  99. package/themes/dark-teal.css +6 -1
  100. package/themes/dazzle.css +6 -0
  101. package/themes/everforest-light.css +6 -0
  102. package/themes/flow-light.css +8 -1
  103. package/themes/flow.css +6 -1
  104. package/themes/geist.css +6 -0
  105. package/themes/gruvbox-light.css +6 -0
  106. package/themes/kanagawa-lotus.css +6 -0
  107. package/themes/md-preview.css +6 -0
  108. package/themes/mist.css +6 -0
  109. package/themes/nord.css +6 -0
  110. package/themes/one-dark.css +6 -0
  111. package/themes/paper.css +6 -0
  112. package/themes/rose-pine-dawn.css +6 -0
  113. package/themes/sakura.css +6 -0
  114. package/themes/solarized-light.css +6 -0
  115. package/themes/tokyo-night.css +6 -0
  116. package/themes/translucent.css +6 -0
  117. package/themes/transparent.css +6 -0
  118. package/themes/vs-code-dark.css +5 -0
  119. package/themes/wallpaper-flow.css +5 -1
  120. package/themes/wallpaper-obsidian.css +6 -0
  121. package/themes/white.css +6 -0
  122. package/themes/zhujian-dark.css +6 -1
  123. package/themes/zhujian.css +6 -1
  124. package/themes/zhupi-dark.css +6 -1
  125. package/themes/zhupi.css +6 -1
  126. package/web/dist/.build-assets.json +1 -1
  127. package/web/dist/assets/BgTasksModal-BYzPgmoq.js +1 -0
  128. package/web/dist/assets/BgTasksModal-ni0VTmAQ.js +1 -0
  129. package/web/dist/assets/{CanvasStudio-B3W6b_rA.js → CanvasStudio-BCUeEf25.js} +3 -3
  130. package/web/dist/assets/{CanvasStudio-Csv1Sj1-.js → CanvasStudio-DNmDNBod.js} +3 -3
  131. package/web/dist/assets/DeviceCenter-BcBhRgL6.js +3 -0
  132. package/web/dist/assets/DeviceCenter-CmL5FZmt.js +3 -0
  133. package/web/dist/assets/DeviceGroups-CLdpdnI7.js +1 -0
  134. package/web/dist/assets/DeviceGroups-CgBaDPrD.js +1 -0
  135. package/web/dist/assets/Dropdown-CGXD0DfT.js +1 -0
  136. package/web/dist/assets/FilePreview-B8iqnBjy.js +2 -0
  137. package/web/dist/assets/FilePreview-BqviZKCN.js +2 -0
  138. package/web/dist/assets/GlobalSearchModal-mevF-ySi.js +1 -0
  139. package/web/dist/assets/GlobalSearchModal-qL99FN_F.js +1 -0
  140. package/web/dist/assets/GroupConversation-B88Yy-lt.js +3 -0
  141. package/web/dist/assets/GroupConversation-BwP5NVOE.js +3 -0
  142. package/web/dist/assets/HintTip-LHwkS2jV.js +1 -0
  143. package/web/dist/assets/ModelConfigModal-Do3Fe3jH.js +2 -0
  144. package/web/dist/assets/PiSetupModal-DE5-gEtI.js +1 -0
  145. package/web/dist/assets/ProviderOAuthControls-6UMARucA.js +1 -0
  146. package/web/dist/assets/SCMPanel-Hi6QqC1Q.js +2 -0
  147. package/web/dist/assets/SCMPanel-ezY_ZtCu.js +2 -0
  148. package/web/dist/assets/SettingsModal-6HgeEsJ8.js +20 -0
  149. package/web/dist/assets/SettingsModal-CF-7MwqS.js +20 -0
  150. package/web/dist/assets/TerminalPanel-CTp_BZ4S.js +3 -0
  151. package/web/dist/assets/TerminalPanel-CkYxC-Gh.js +3 -0
  152. package/web/dist/assets/TuiOverlayModal-1cRLP8IF.js +1 -0
  153. package/web/dist/assets/TuiOverlayModal-2xlptqWX.js +1 -0
  154. package/web/dist/assets/app-globals-DZNa9v8u.js +325 -0
  155. package/web/dist/assets/canvas-client-Bye9nSFO.js +1 -0
  156. package/web/dist/assets/{desktop-YguLbrX1.js → desktop-kjBoE3Nu.js} +1 -1
  157. package/web/dist/assets/group-view-state-CGCzYF8k.js +1 -0
  158. package/web/dist/assets/index-CsFs_HMb.css +1 -0
  159. package/web/dist/assets/index-DHeeHS_l.js +85 -0
  160. package/web/dist/assets/index-DTZch8uz.js +85 -0
  161. package/web/dist/assets/plugin-host-C8mNgghx.js +1 -0
  162. package/web/dist/assets/remote-ssh-client-CeP3CLUW.js +1 -0
  163. package/web/dist/assets/theme-BXGpyTMh.js +1 -0
  164. package/web/dist/index.html +10 -9
  165. package/web/dist/sw.js +1 -1
  166. package/web/dist/assets/BgTasksModal-BIlQ89vr.js +0 -1
  167. package/web/dist/assets/BgTasksModal-Ck2sjlPM.js +0 -1
  168. package/web/dist/assets/DeviceCenter-BQdDcO8A.js +0 -3
  169. package/web/dist/assets/DeviceCenter-CHRKL0Vy.js +0 -3
  170. package/web/dist/assets/DeviceGroups-D2rogxEN.js +0 -1
  171. package/web/dist/assets/Dropdown-ZLS04O8p.js +0 -1
  172. package/web/dist/assets/FilePreview-B9xoU6ON.js +0 -2
  173. package/web/dist/assets/FilePreview-DUQpVZkH.js +0 -2
  174. package/web/dist/assets/GlobalSearchModal-BXEGvUZq.js +0 -1
  175. package/web/dist/assets/GlobalSearchModal-CnVPmfOI.js +0 -1
  176. package/web/dist/assets/GroupConversation-CyIpQzDd.js +0 -1
  177. package/web/dist/assets/GroupConversation-DgYV3uYS.js +0 -1
  178. package/web/dist/assets/ModelConfigModal-DDZccDYt.js +0 -2
  179. package/web/dist/assets/PiSetupModal-DHbqfx8T.js +0 -1
  180. package/web/dist/assets/ProviderOAuthControls-C-MK36Dk.js +0 -1
  181. package/web/dist/assets/SCMPanel-imYI2Ecw.js +0 -2
  182. package/web/dist/assets/SCMPanel-sVZcV7dR.js +0 -2
  183. package/web/dist/assets/SettingsModal-Xw1Yoi3_.js +0 -20
  184. package/web/dist/assets/SettingsModal-mb4e34-0.js +0 -20
  185. package/web/dist/assets/TerminalPanel-CLkJJvxg.js +0 -3
  186. package/web/dist/assets/TerminalPanel-DpcIellm.js +0 -3
  187. package/web/dist/assets/TuiOverlayModal-4-fFAZe7.js +0 -1
  188. package/web/dist/assets/TuiOverlayModal-DCu01lks.js +0 -1
  189. package/web/dist/assets/app-globals-DcyO0UPi.js +0 -1
  190. package/web/dist/assets/fi-DaSO0Q-m.js +0 -325
  191. package/web/dist/assets/index-Cdh3sibd.js +0 -85
  192. package/web/dist/assets/index-DDZMv6LO.css +0 -1
  193. package/web/dist/assets/index-DWw_SxRq.js +0 -85
  194. package/web/dist/assets/plugin-host-BRBg6zmQ.js +0 -1
  195. package/web/dist/assets/theme-DDl-Oy1b.js +0 -1
@@ -0,0 +1 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t}from"./react-CR5VJ85Q.js";import{t as n}from"./uuid-BzDIGCwP.js";import{r}from"./desktop-kjBoE3Nu.js";var i=e(t(),1),a=null,o=null,s=null,c=null,l=null;function u(e){c=e}function d(e){l=e}function f(e){return c?(c(e),!0):!1}function p(e){return l?(l(e),!0):!1}function m(e){a=e}function h(e){o=e}function g(e){s=e}function _(){return s?(s(),!0):!1}var v=0,y=null;function ee(e){y=e}function te(){v=Date.now(),y?.(),_()}function ne(){return v}function re(){return!!(a||o)}function b(e){let t=typeof e?.text==`string`?e.text:``,n=Array.isArray(e?.attachments)?e.attachments:[],r=t.trim()!==``,i=n.length>0;return!r&&!i||r&&!a||i&&!o?!1:(i&&o?.(n),r&&a?.(t),!0)}var x=`pi-web-ui:cost-currency`,S=null,C=0,w=new Set;function T(){C+=1;for(let e of[...w])try{e()}catch{}}function ie(e){return w.add(e),()=>{w.delete(e)}}function E(){return C}function ae(e){return!Number.isFinite(e)||e<=0?`0`:e<1e-4?`<0.0001`:e.toFixed(4).replace(/\.?0+$/,``)}function D(){try{if(typeof localStorage<`u`){let e=localStorage.getItem(x);if(typeof e==`string`&&e.trim().length>0)return e.trim().slice(0,8)}}catch{}return`$`}function oe(e){try{if(typeof localStorage<`u`){let t=typeof e==`string`?e.trim().slice(0,8):``;!t||t===`$`?localStorage.removeItem(x):localStorage.setItem(x,t)}}catch{}T()}function se(e){return typeof e==`function`?(S=e,T(),()=>{S===e&&(S=null,T())}):(S=null,T(),()=>{})}function ce(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 O(e,t){let n=typeof e==`number`&&Number.isFinite(e)?e:0,r=D(),i=typeof t?.fixedDigits==`number`?n.toFixed(t.fixedDigits):ae(n);if(S)try{let e=S(n,{defaultSymbol:r,defaultValue:i});if(typeof e==`string`)return ce(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 le(e,t){return(0,i.useSyncExternalStore)(ie,E,E),O(e,t)}var k=new Map,ue=0;function de(e){k.get(e.requestId)?.(e.ok&&e.conversationId?e.conversationId:null)}function A(e,t=8e3){let n=`host-new-chat-${Date.now()}-${++ue}`;return new Promise(r=>{let i=e=>{clearTimeout(a),k.delete(n),r(e)},a=setTimeout(()=>i(null),t);k.set(n,i);try{e({type:`new_chat`,requestId:n})||i(null)}catch{i(null)}})}var j=`__piWebUiHost`,M=e=>new Promise(t=>setTimeout(t,e));async function fe(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 M(100)}}var N=Promise.resolve(),P=0;function pe(e){let t=Math.max(1,Number(e.pollMs??100)),i=Math.max(t,Number(e.timeoutMs??8e3)),a=async e=>{let n=Date.now()+i;for(;;){if(e())return!0;if(Date.now()>=n)return e();await M(t)}},o=()=>{try{let t=e.listModels?.()??[];return Array.isArray(t)?[...t]:[]}catch{return[]}},s=e=>{if(!e)return!0;try{return o().some(t=>t&&t.id===e)}catch{return!1}},c=async t=>{t&&(e.send({type:`set_model`,modelId:t}),typeof e.getCurrentModelId==`function`&&await a(()=>e.getCurrentModelId?.()===t))},l=async(t,n)=>{let r=String(n.cwd??``).trim();if(r&&e.getCwd()!==r&&(!e.send({type:`set_cwd`,path:r})||!await a(()=>e.getCwd()===r))||!e.isReady())return!1;let o=n.newChat===!1?e.getConversationId():await A(e.send,i);if(n.newChat!==!1&&o&&!await a(()=>e.getConversationId()===o)||!o||!e.isReady())return!1;let s=String(n.model??``).trim();return s&&await c(s),!e.isReady()||e.getConversationId()!==o||r&&e.getCwd()!==r?!1:(e.setView(`chat`),e.send({type:`prompt`,text:t,targetConversationId:o}))};return{version:14,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&&!s(r))return!1;let i=async()=>{let e=!1;try{e=await l(n,t??{prompt:n})}finally{try{t?.onResult?.(e)}catch{}}},a;return a=P>0?N.then(i):i(),P++,N=a.then(()=>{P--},()=>{P--}),a.catch(()=>{}),!0},models:{list:()=>o(),active:()=>e.getCurrentModelId?.()??null,onChange:e=>je(e)},compose(e){return re()?b({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}},closeModal(){if(typeof e.closeModal!=`function`)return!0;try{e.closeModal()}catch{}return!0},async openSession(t){let n=L,r=Array.isArray(t?.folders)?t.folders.filter(e=>typeof e==`string`&&e.trim().length>0).map(e=>e.trim()):[],o=Array.isArray(t?.roots)?t.roots.filter(e=>typeof e==`string`&&e.trim().length>0).map(e=>e.trim()):[],l=String(t?.cwd??``).trim(),u=[...new Set([...r,...o])],d=l||u[0]||``;if(!d)return{ok:!1,error:`openSession 需要 cwd / folders / roots(绝对路径)`};if(!e.isReady())return{ok:!1,error:`尚未连接到服务器(还没有快照)`};let f=u.filter(e=>e!==d).slice(0,7),p=new Set([...e.listProjects?.()??[],...e.grantedPaths?.(n)??[]]);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,n)}if(e.getCwd()!==d&&(e.send({type:`set_cwd`,path:d}),!await a(()=>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 A(e.send,i)??void 0,!m||!await a(()=>e.getConversationId()===m)))return{ok:!1,error:`Conversation creation failed or timed out`};let h=String(t?.model??``).trim();if(h){if(!s(h))return{ok:!1,error:`未知模型:${h}(先调 models.list() 取可用列表)`};if(await c(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=L,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 a(()=>e.getCwd()===i.cwd))return{ok:!1,error:`切换工作目录失败或超时:${i.cwd}`}}let o=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 a(()=>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 a(()=>i.kind===`running`?e.getConversationId()===i.id&&!e.getConversationOwner?.():e.getConversationId()!==o)?{ok:!0,sessionId:e.getConversationId()??void 0}:{ok:!1,error:`切换会话超时:${i.title}`})}},async reloadCatalog(t,r){let i=String(t??``).trim();if(!i)return{ok:!1,error:`reloadCatalog 需要一个目录来源(http(s) URL 或本地文件路径)`};if(!e.isReady())return{ok:!1,error:`尚未连接到服务器(还没有快照)`};let a=n();return new Promise(t=>{let n=setTimeout(()=>{$.delete(a),t({ok:!1,error:`目录同步超时(服务端未在等待窗口内回执)`})},Math.max(1e3,Number(e.catalogTimeoutMs??18e4)));$.set(a,e=>{clearTimeout(n),t(e)}),e.send({type:`plugin_catalog_sync`,requestId:a,source:i,...r?.install?{install:!0}:{},...r?.replace?{replace:!0}:{}})})},onUiAction(e,t){return R(I,String(e??``).trim(),t)},onTopbarAction(e,t){return R(I,String(e??``).trim(),t)},async pageCall(t){let n=String(t?.op??``).trim();if(!n)return{ok:!1,error:`pageCall 需要一个动作名(op)`};if(r())return{ok:!1,error:`桌面版(Electron 外壳)不支持 browser_page:窗口里没有 Chrome 扩展运行时。请让用户改用系统浏览器打开同一个 pi-web-ui 地址(网页版)再试。/ The desktop app cannot run browser_page (no Chrome extension runtime); ask the user to open the same pi-web-ui address in a regular browser instead.`};let i=await fe(e.bridgeWaitMs??3e3);if(!i)return{ok:!1,error:`浏览器扩展的页面桥没就绪:确认已安装并启用 page-picker 扩展、本页地址已绑定,然后刷新本页`};try{let e=await i.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(ve,{detail:{text:n}}))}catch{}return null},shortcuts:{register:(e,t)=>Ce(String(e??``),t)},searchProviders:{register:e=>we(e),list:()=>U()},composerProviders:{register:e=>Te(e),list:()=>G()},ttsProviders:{register:e=>Oe(e),list:()=>J()},onTheme:e=>Ne(e),onLocale:e=>Pe(e),onViewChange:e=>Fe(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=>se(e),setCostCurrency:e=>oe(e),getCostCurrency:()=>D()}}function me(e){try{let t=window;e?t[j]=e:delete t[j]}catch{}}var F=new Map,I=null;async function he(e,t){let n=I;I=e;try{return await t()}finally{I=n}}var L=void 0;function ge(e,t){let n=L;L=e;try{return t()}finally{L=n}}function R(e,t,n){if(!t||typeof n!=`function`)return()=>{};let r=e?`${e}:${t}`:t,i=F.get(r);i||(i=new Set,F.set(r,i));let a=i;return a.add(n),()=>{a.delete(n),a.size===0&&F.delete(r)}}async function _e(e,t,n,r){let i=i=>{let a=F.get(i);if(!a||a.size===0)return!1;for(let i of[...a])try{ge(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 ve=`pi-web-ui:toast`,z=new Map,B=!1;function ye(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 be(){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 V(e){try{if(be())return;let t=`${e.ctrlKey?`ctrl+`:``}${e.shiftKey?`shift+`:``}${e.altKey?`alt+`:``}${e.metaKey?`meta+`:``}${(e.key??``).toLowerCase()}`,n=z.get(t);if(!n||n.size===0)return;for(let e of[...n])try{e()}catch(e){console.error(`[plugin-host] 快捷键处理器抛错:`,e)}}catch{}}function xe(){if(!B)try{if(typeof window>`u`||typeof window.addEventListener!=`function`)return;window.addEventListener(`keydown`,V),B=!0}catch{}}function Se(){if(!(z.size>0||!B))try{window.removeEventListener(`keydown`,V)}catch{}finally{B=!1}}function Ce(e,t){if(typeof t!=`function`)return()=>{};let n=ye(e);if(!n)return()=>{};let r=z.get(n.combo);r||(r=new Set,z.set(n.combo,r));let i=r;return i.add(t),xe(),()=>{i.delete(t),i.size===0&&z.delete(n.combo),Se()}}var H=new Map;function we(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 H.set(t,n),()=>{H.get(t)===n&&H.delete(t)}}function U(){return[...H.values()].map(e=>({id:e.id,label:e.label}))}var W=new Map;function Te(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 W.set(t,n),()=>{W.get(t)===n&&W.delete(t)}}function G(){return[...W.values()].map(e=>({id:e.id,label:e.label}))}function Ee(e){return W.get(String(e??``))}function De(e){return H.get(String(e??``))}var K=new Map,q=new Set;function Oe(e){let t=String(e?.id??``).trim();if(!t||typeof e?.play!=`function`)return()=>{};let n={id:t,label:String(e.label??t),labelEn:e.labelEn?String(e.labelEn):void 0,play:e.play,getVoices:e.getVoices};K.set(t,n);for(let e of q)try{e()}catch{}return()=>{if(K.get(t)===n){K.delete(t);for(let e of q)try{e()}catch{}}}}function J(){return[...K.values()].map(e=>({id:e.id,label:e.label,labelEn:e.labelEn}))}function ke(e){return K.get(String(e??``))}function Ae(e){return q.add(e),()=>{q.delete(e)}}var Y=new Set,X=new Set,Z=new Set,Q=new Set;function je(e){return Q.add(e),()=>{Q.delete(e)}}function Me(e){for(let t of Q)try{t(e)}catch(e){console.error(`[plugin-host] onModelChange 处理器抛错:`,e)}}function Ne(e){return typeof e==`function`?(Y.add(e),()=>{Y.delete(e)}):()=>{}}function Pe(e){return typeof e==`function`?(X.add(e),()=>{X.delete(e)}):()=>{}}function Fe(e){return typeof e==`function`?(Z.add(e),()=>{Z.delete(e)}):()=>{}}function Ie(e){let t=String(e??``);for(let e of Y)try{e(t)}catch(e){console.error(`[plugin-host] onTheme 处理器抛错:`,e)}}function Le(e){let t=String(e??``);for(let e of X)try{e(t)}catch(e){console.error(`[plugin-host] onLocale 处理器抛错:`,e)}}function Re(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 ze(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{ee as A,f as C,g as D,m as E,u as O,ne as S,h as T,de as _,Re as a,b,ke as c,U as d,J as f,he as g,_e as h,Ie as i,p as j,d as k,me as l,ze as m,Le as n,Ee as o,Ae as p,Me as r,De as s,pe as t,G as u,O as v,te as w,_ as x,le as y};
@@ -0,0 +1 @@
1
+ import{t as e}from"./app-globals-DZNa9v8u.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}))});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})}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};
@@ -0,0 +1 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Sn as t,i as n,wn as r}from"./app-globals-DZNa9v8u.js";import{i}from"./react-CR5VJ85Q.js";var a=e(i(),1),o=`pi-web-ui:theme`,s=`dark`,c=`theme-stylesheet`,l=Date.now().toString(36),u=0,d=3,f=0,p=`pi-web-ui:theme-change`;function m(){try{let e=localStorage.getItem(o);if(e&&e!==s)return e}catch{}return null}function h(e){try{e?localStorage.setItem(o,e):localStorage.removeItem(o)}catch{}}function g(e){return`${r(`/themes/${encodeURIComponent(e)}.css`)}?v=${l}.${u}`}function _(e,t={}){t.reload&&(u++,f=0),typeof document<`u`&&(e?document.documentElement.dataset.theme=e:delete document.documentElement.dataset.theme);let n=document.getElementById(c);if(!e){n?.remove(),window.dispatchEvent(new CustomEvent(p));return}n||(n=document.createElement(`link`),n.id=c,n.rel=`stylesheet`,document.head.appendChild(n));let r=n;r.href=g(e),r.onload=()=>{f=0,window.dispatchEvent(new CustomEvent(p))},r.onerror=()=>{if(f>=d)return;let t=400*2**f++;window.setTimeout(()=>{document.getElementById(c)===r&&(u++,r.href=g(e))},t)}}async function v(){try{let e=await fetch(t(r(`/api/themes`)));if(!e.ok)return[];let n=await e.json();return Array.isArray(n.themes)?n.themes:[]}catch{return[]}}function y(){let[e,t]=(0,a.useState)([]),[r,i]=(0,a.useState)(()=>m()),o=n(`status`)===`open`;(0,a.useEffect)(()=>{let e=!1;return v().then(n=>{e||t(n)}),()=>{e=!0}},[o]);let c=(0,a.useCallback)(()=>{v().then(t)},[]);return(0,a.useEffect)(()=>{_(r,{reload:o}),h(r)},[r,o]),{themes:e,theme:r,switchTheme:e=>i(e===s?null:e),reloadThemes:c}}function b(){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{y as a,m as i,_ as n,b as r,p as t};
@@ -21,21 +21,22 @@
21
21
  }
22
22
  }
23
23
  </script>
24
- <script type="module" crossorigin src="./assets/index-Cdh3sibd.js"></script>
24
+ <script type="module" crossorigin src="./assets/index-DHeeHS_l.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/fi-DaSO0Q-m.js">
27
+ <link rel="modulepreload" crossorigin href="./assets/app-globals-DZNa9v8u.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-ZLS04O8p.js">
31
- <link rel="modulepreload" crossorigin href="./assets/theme-DDl-Oy1b.js">
32
- <link rel="modulepreload" crossorigin href="./assets/desktop-YguLbrX1.js">
33
- <link rel="modulepreload" crossorigin href="./assets/plugin-host-BRBg6zmQ.js">
34
- <link rel="modulepreload" crossorigin href="./assets/app-globals-DcyO0UPi.js">
30
+ <link rel="modulepreload" crossorigin href="./assets/Dropdown-CGXD0DfT.js">
31
+ <link rel="modulepreload" crossorigin href="./assets/theme-BXGpyTMh.js">
32
+ <link rel="modulepreload" crossorigin href="./assets/desktop-kjBoE3Nu.js">
33
+ <link rel="modulepreload" crossorigin href="./assets/plugin-host-C8mNgghx.js">
34
+ <link rel="modulepreload" crossorigin href="./assets/HintTip-LHwkS2jV.js">
35
+ <link rel="modulepreload" crossorigin href="./assets/remote-ssh-client-CeP3CLUW.js">
35
36
  <link rel="modulepreload" crossorigin href="./assets/markdown-BggnuQ4H.js">
36
37
  <link rel="stylesheet" crossorigin href="./assets/markdown-C8LL_u4z.css">
37
- <link rel="stylesheet" crossorigin href="./assets/index-DDZMv6LO.css">
38
- <meta name="pi-web-build-id" content="20261031T04501">
38
+ <link rel="stylesheet" crossorigin href="./assets/index-CsFs_HMb.css">
39
+ <meta name="pi-web-build-id" content="20261102T03402">
39
40
  </head>
40
41
  <body>
41
42
  <div id="root"></div>
package/web/dist/sw.js CHANGED
@@ -22,7 +22,7 @@
22
22
  * risk serving stale theme/plugin code or caching anything sensitive.
23
23
  */
24
24
 
25
- const BUILD_ID = "20261031T04501";
25
+ const BUILD_ID = "20261102T03402";
26
26
  const STATIC_CACHE = BUILD_ID.startsWith("__") ? "pi-web-ui-static-dev" : `pi-web-ui-static-${BUILD_ID}`;
27
27
  const SHELL_CACHE = "pi-web-ui-shell-v1";
28
28
 
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Bt as t,Ht as n,Lt as r,Tt as i,Yt as a,an as o,at as s,rn as c}from"./fi-DaSO0Q-m.js";import{i as l,t as u}from"./react-CR5VJ85Q.js";import{t as d}from"./app-globals-DcyO0UPi.js";import{Ct as f,G as p,Ot as m,jt as h}from"./index-DWw_SxRq.js";var g=e(l(),1),_=u();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:l,plugins:u=[],epoch:y=0,send:b,onUiAction:x,autoCleanupMin:S=0}){let C=o(),{locale:w}=c(),[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)(()=>{d({type:`list_bg_servers`})},[]);let O=(0,g.useMemo)(()=>(m(h(u),{locale:w,t:e=>C(e)})[`tasks.panel`]??[]).filter(e=>!e.hidden&&e.source!==`host`&&e.kind!==`divider`),[u,w,C]);return(0,_.jsxs)(f,{className:`bg-task-modal`,onClose:l,showCloseButton:!1,children:[(0,_.jsxs)(`div`,{className:`bg-task-head`,children:[(0,_.jsxs)(`span`,{className:`bg-task-title`,children:[(0,_.jsx)(s,{}),` `,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:()=>d({type:`list_bg_servers`}),children:(0,_.jsx)(i,{})}),(0,_.jsx)(`button`,{type:`button`,className:`btn bg-task-head-btn`,title:C(`close`),onClick:l,children:(0,_.jsx)(a,{})})]})]}),e.length===0?(0,_.jsxs)(`div`,{className:`bg-task-empty`,children:[(0,_.jsx)(s,{}),(0,_.jsx)(`span`,{children:C(`bgTasksEmpty`)}),(0,_.jsx)(`small`,{children:C(`bgTasksDesc`)})]}):(0,_.jsx)(`ul`,{className:`bg-task-list`,children:e.map(e=>{let n=!!e.taskId,i=e.taskId??String(e.port);return(0,_.jsxs)(`li`,{className:`bg-task-item`,children:[(0,_.jsx)(`span`,{className:`bg-task-icon`,title:n?e.plugin:C(`bgTaskPort`)}),(0,_.jsxs)(`div`,{className:`bg-task-info`,children:[(0,_.jsxs)(`div`,{className:`bg-task-line1`,children:[n?(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:[!n&&(0,_.jsxs)(`span`,{children:[C(`bgTaskPid`),` `,e.pid]}),(0,_.jsxs)(`span`,{children:[C(`bgTaskSince`),` `,v(e.since,C)]}),n&&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(i)?`open`:``}`,title:`${C(`bgTaskCommand`)}: ${e.command}`,onClick:()=>D(i),children:[(0,_.jsx)(t,{}),(0,_.jsx)(`code`,{children:e.command})]})]}),!n&&(0,_.jsx)(`button`,{type:`button`,className:`btn bg-task-keep`,title:e.keep?C(`bgTaskKeepOn`):C(`bgTaskKeep`),"aria-pressed":!!e.keep,onClick:()=>d({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:()=>d(n?{type:`kill_background_server`,taskId:e.taskId}:{type:`kill_background_server`,port:e.port}),children:[(0,_.jsx)(r,{}),(0,_.jsx)(`span`,{children:C(`bgTaskStop`)})]})]},i)})}),O.map(e=>{let t=u.find(t=>t.id===e.source.slice(7));return e.kind===`view`?t?(0,_.jsx)(`div`,{children:(0,_.jsx)(p,{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=>d({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:()=>d({type:`clean_bg_leftovers`}),children:[(0,_.jsx)(n,{}),(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:()=>d({type:`list_bg_servers`}),children:[(0,_.jsx)(i,{}),(0,_.jsx)(`span`,{children:C(`bgTaskRefresh`)})]}),(0,_.jsxs)(`button`,{type:`button`,className:`btn bg-task-stopall`,disabled:e.length===0,title:C(`bgTaskStopAll`),onClick:()=>d({type:`kill_background_servers`}),children:[(0,_.jsx)(r,{}),(0,_.jsx)(`span`,{children:C(`bgTaskStopAll`)})]})]})]})]})}export{y as BgTasksModal};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Bt as t,Ht as n,Lt as r,Tt as i,Yt as a,an as o,at as s,rn as c}from"./fi-DaSO0Q-m.js";import{i as l,t as u}from"./react-CR5VJ85Q.js";import{t as d}from"./app-globals-DcyO0UPi.js";import{Ct as f,G as p,Ot as m,jt as h}from"./index-Cdh3sibd.js";var g=e(l(),1),_=u();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:l,plugins:u=[],epoch:y=0,send:b,onUiAction:x,autoCleanupMin:S=0}){let C=o(),{locale:w}=c(),[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)(()=>{d({type:`list_bg_servers`})},[]);let O=(0,g.useMemo)(()=>(m(h(u),{locale:w,t:e=>C(e)})[`tasks.panel`]??[]).filter(e=>!e.hidden&&e.source!==`host`&&e.kind!==`divider`),[u,w,C]);return(0,_.jsxs)(f,{className:`bg-task-modal`,onClose:l,showCloseButton:!1,children:[(0,_.jsxs)(`div`,{className:`bg-task-head`,children:[(0,_.jsxs)(`span`,{className:`bg-task-title`,children:[(0,_.jsx)(s,{}),` `,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:()=>d({type:`list_bg_servers`}),children:(0,_.jsx)(i,{})}),(0,_.jsx)(`button`,{type:`button`,className:`btn bg-task-head-btn`,title:C(`close`),onClick:l,children:(0,_.jsx)(a,{})})]})]}),e.length===0?(0,_.jsxs)(`div`,{className:`bg-task-empty`,children:[(0,_.jsx)(s,{}),(0,_.jsx)(`span`,{children:C(`bgTasksEmpty`)}),(0,_.jsx)(`small`,{children:C(`bgTasksDesc`)})]}):(0,_.jsx)(`ul`,{className:`bg-task-list`,children:e.map(e=>{let n=!!e.taskId,i=e.taskId??String(e.port);return(0,_.jsxs)(`li`,{className:`bg-task-item`,children:[(0,_.jsx)(`span`,{className:`bg-task-icon`,title:n?e.plugin:C(`bgTaskPort`)}),(0,_.jsxs)(`div`,{className:`bg-task-info`,children:[(0,_.jsxs)(`div`,{className:`bg-task-line1`,children:[n?(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:[!n&&(0,_.jsxs)(`span`,{children:[C(`bgTaskPid`),` `,e.pid]}),(0,_.jsxs)(`span`,{children:[C(`bgTaskSince`),` `,v(e.since,C)]}),n&&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(i)?`open`:``}`,title:`${C(`bgTaskCommand`)}: ${e.command}`,onClick:()=>D(i),children:[(0,_.jsx)(t,{}),(0,_.jsx)(`code`,{children:e.command})]})]}),!n&&(0,_.jsx)(`button`,{type:`button`,className:`btn bg-task-keep`,title:e.keep?C(`bgTaskKeepOn`):C(`bgTaskKeep`),"aria-pressed":!!e.keep,onClick:()=>d({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:()=>d(n?{type:`kill_background_server`,taskId:e.taskId}:{type:`kill_background_server`,port:e.port}),children:[(0,_.jsx)(r,{}),(0,_.jsx)(`span`,{children:C(`bgTaskStop`)})]})]},i)})}),O.map(e=>{let t=u.find(t=>t.id===e.source.slice(7));return e.kind===`view`?t?(0,_.jsx)(`div`,{children:(0,_.jsx)(p,{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=>d({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:()=>d({type:`clean_bg_leftovers`}),children:[(0,_.jsx)(n,{}),(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:()=>d({type:`list_bg_servers`}),children:[(0,_.jsx)(i,{}),(0,_.jsx)(`span`,{children:C(`bgTaskRefresh`)})]}),(0,_.jsxs)(`button`,{type:`button`,className:`btn bg-task-stopall`,disabled:e.length===0,title:C(`bgTaskStopAll`),onClick:()=>d({type:`kill_background_servers`}),children:[(0,_.jsx)(r,{}),(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{B as t,Pt as n,Tt as r,_ as i,an as a,et as o,fn as s,in as c,k as l,mt as ee,st as u,un as d,yt as f}from"./fi-DaSO0Q-m.js";import{i as p,t as m}from"./react-CR5VJ85Q.js";import{T as h,_t as te,zt as g}from"./index-DWw_SxRq.js";import{DeviceGroups as _}from"./DeviceGroups-D2rogxEN.js";var v=e(p(),1),y=m();function b({href:e,children:t}){let n=a(),[r,i]=(0,v.useState)(!1),[o,s]=(0,v.useState)(!1);return(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(`a`,{className:`dc-button`,href:e,target:`_blank`,rel:`noopener noreferrer`,onClick:t=>{let n=window.piDesktop;n?.openHub&&(t.preventDefault(),!o&&(s(!0),i(!1),n.openHub(e).then(e=>i(!e),()=>i(!0)).finally(()=>s(!1))))},"aria-busy":o,children:t}),r&&(0,y.jsxs)(`span`,{role:`alert`,children:[n(`deviceHubNetworkError`),` `,(0,y.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,children:e})]})]})}function x(e){if(!S(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 S(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 ne(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 C=`https://raw.githubusercontent.com/xing-shuyin/pi-web-ui/main/docs/device-center-deployment.md`,w=`https://github.com/xing-shuyin/pi-web-ui/blob/main/docs/device-center-deployment.md`,T=`pi-web-ui hub install --host 0.0.0.0 --port 8790 --public-url http://SERVER_IP:8790 --allow-registration`;function E(e){let t=e=>e.includes(`:`)?S(e)&&![`::`,`::1`].includes(e):/^[\d.]+$/.test(e)?S(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 D(e,t,n,r){if(!x(e))throw Error(`Invalid Hub setup`);if(r){let t=E(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: ${C} (fallback: ${w}). 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: ${T}`,`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 re({onConnect:e,initialHubUrl:t=``}){let n=a(),[r,i]=(0,v.useState)(t),[o,c]=(0,v.useState)(``),[l,ee]=(0,v.useState)(!1),[u,f]=(0,v.useState)(!1),p=(0,v.useRef)(!1),m=(0,v.useRef)(!1);(0,v.useEffect)(()=>(m.current=!0,()=>{m.current=!1}),[]);let[h,te]=(0,v.useState)(null),[g,_]=(0,v.useState)(`current`),[S,C]=(0,v.useState)(null),[w,T]=(0,v.useState)(`127.0.0.1`),[re,O]=(0,v.useState)(`8790`),[k,A]=(0,v.useState)(`http://127.0.0.1:8790`),[j,M]=(0,v.useState)({server:``,sshPort:22,username:`root`,auth:`password`,port:8790,domain:``,https:!1}),N=E(j),[P,F]=(0,v.useState)(!1),[ie,I]=(0,v.useState)(!1),[L,ae]=(0,v.useState)(!1),[oe,R]=(0,v.useState)(!1),[z,se]=(0,v.useState)(null),B=(0,v.useRef)(null),V=(0,v.useRef)(!1),H=ne(window.location.origin);(0,v.useEffect)(()=>()=>B.current?.abort(),[]);let U=async()=>{if(V.current)return;B.current?.abort();let e=new AbortController;B.current=e,I(!1),ae(!1),R(!1);try{let t=await fetch(d(s(`/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`||!x({host:`127.0.0.1`,port:n.defaultPort,publicUrl:n.defaultPublicUrl}))throw Error();if(e.signal.aborted)return;C(n),n.installation?.installed?(T(n.installation.host??`127.0.0.1`),O(String(n.installation.port)),A(n.installation.publicUrl??``),i(n.installation.publicUrl??``)):S||(O(String(n.defaultPort)),A(n.defaultPublicUrl))}catch{e.signal.aborted||(I(!0),R(!0))}finally{e.signal.aborted||ae(!0)}},W=async()=>{let e={host:w,port:Number(re),publicUrl:k};if(V.current||!H||!S||!L||oe||S.busy||S.installation?.installed||!x(e))return;V.current=!0,B.current?.abort(),F(!0),I(!1),c(``);let t=new AbortController;B.current=t;try{let n=await fetch(d(s(`/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){C(e=>e&&{...e,busy:!0}),V.current=!1,F(!1),await U();return}if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(typeof e.error==`string`?e.error.slice(0,4096):`HTTP ${n.status}`)}let r=await n.json();if(!x({...e,publicUrl:r.publicUrl})||typeof r.output!=`string`)throw Error();t.signal.aborted||se(r)}catch(e){t.signal.aborted||(I(!0),c(e instanceof Error?e.message.slice(0,4096):``))}finally{V.current=!1,t.signal.aborted||F(!1)}},G=S?.installation,K=!!G?.installed,q=K&&G.running&&G.owned,J=g===`remote`?N:{host:w,port:Number(re),publicUrl:k},Y=!!J&&x(J);return(0,y.jsxs)(`section`,{className:`dc-onboarding`,children:[(0,y.jsx)(`h3`,{children:n(`deviceSetupWelcome`)}),(0,y.jsx)(`p`,{children:n(`deviceSetupIntro`)}),(0,y.jsxs)(`div`,{className:`dc-actions`,children:[(0,y.jsx)(`button`,{className:`dc-button`,disabled:P,"aria-pressed":h===`connect`,onClick:()=>te(`connect`),children:n(`deviceSetupConnect`)}),(0,y.jsx)(`button`,{className:`dc-button`,disabled:P,"aria-pressed":h===`create`,onClick:()=>{te(`create`),!S&&H&&U()},children:n(`deviceSetupCreate`)})]}),h===`connect`&&(0,y.jsxs)(`form`,{onSubmit:t=>{t.preventDefault(),e(r.trim())},children:[(0,y.jsxs)(`label`,{className:`dc-field`,children:[(0,y.jsx)(`span`,{children:n(`deviceHubHubUrl`)}),(0,y.jsx)(`input`,{type:`url`,required:!0,maxLength:2048,value:r,onChange:e=>i(e.target.value),placeholder:`https://hub.example.com`})]}),(0,y.jsx)(`button`,{className:`dc-button is-primary`,disabled:!x({host:`localhost`,port:8790,publicUrl:r.trim()}),children:n(`deviceSetupPair`)})]}),h===`create`&&(0,y.jsxs)(y.Fragment,{children:[(0,y.jsxs)(`label`,{className:`dc-field`,children:[(0,y.jsx)(`span`,{children:n(`deviceSetupTarget`)}),(0,y.jsxs)(`select`,{disabled:P,value:g,onChange:e=>_(e.target.value),children:[(0,y.jsx)(`option`,{value:`current`,children:n(`deviceSetupCurrent`)}),(0,y.jsx)(`option`,{value:`remote`,children:n(`deviceSetupRemote`)})]})]}),(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(`p`,{children:n(g===`current`?`deviceSetupCurrentHint`:`deviceSetupRemoteHint`)}),g===`current`&&(0,y.jsxs)(`div`,{className:`dc-setup-plan`,children:[(0,y.jsx)(`strong`,{children:n(`deviceSetupPlan`)}),(0,y.jsx)(`p`,{children:n(`deviceSetupPlanHint`)}),S&&(0,y.jsxs)(`dl`,{children:[(0,y.jsx)(`dt`,{children:n(`deviceSetupEnvironment`)}),(0,y.jsxs)(`dd`,{children:[S.platform,` · Node `,S.nodeVersion]}),(0,y.jsx)(`dt`,{children:n(`deviceSetupDataDir`)}),(0,y.jsx)(`dd`,{children:S.dataDir}),(0,y.jsx)(`dt`,{children:n(`deviceSetupCli`)}),(0,y.jsx)(`dd`,{children:S.cliPath})]}),!H&&(0,y.jsx)(`p`,{role:`status`,children:n(`deviceSetupLocalOnly`)}),(0,y.jsx)(`p`,{children:n(`deviceSetupBackground`)}),K&&(0,y.jsxs)(`div`,{role:`status`,children:[(0,y.jsx)(`h4`,{children:n(q?`deviceSetupRestored`:`deviceSetupUnhealthy`)}),(0,y.jsx)(`p`,{children:G.publicUrl}),q&&Y&&G.publicUrl?(0,y.jsxs)(`div`,{className:`dc-actions`,children:[(0,y.jsx)(b,{href:G.publicUrl,children:n(`deviceHubOpenHub`)}),(0,y.jsx)(`button`,{className:`dc-button`,onClick:()=>e(G.publicUrl),children:n(`deviceSetupPair`)})]}):(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(`p`,{children:n(`deviceSetupRecovery`)}),(0,y.jsx)(`pre`,{className:`dc-setup-output`,children:`pi-web-ui hub status --json
3
- pi-web-ui hub --help`})]})]}),S?.busy&&(0,y.jsx)(`p`,{role:`status`,children:n(`deviceSetupBusy`)}),H&&(0,y.jsx)(`button`,{className:`dc-button`,disabled:P||!L,onClick:()=>void U(),children:n(L?`deviceSetupRetry`:`deviceHubWorking`)})]}),g===`remote`?(0,y.jsxs)(y.Fragment,{children:[(0,y.jsxs)(`div`,{className:`dc-setup-fields`,children:[(0,y.jsxs)(`label`,{className:`dc-field`,children:[(0,y.jsx)(`span`,{children:n(`deviceSetupServer`)}),(0,y.jsx)(`input`,{autoComplete:`off`,maxLength:253,placeholder:`203.0.113.10`,value:j.server,onChange:e=>M({...j,server:e.target.value.trim()})})]}),(0,y.jsxs)(`label`,{className:`dc-field`,children:[(0,y.jsx)(`span`,{children:n(`deviceSetupSshPort`)}),(0,y.jsx)(`input`,{type:`number`,min:1,max:65535,value:j.sshPort,onChange:e=>M({...j,sshPort:Number(e.target.value)})})]}),(0,y.jsxs)(`label`,{className:`dc-field`,children:[(0,y.jsx)(`span`,{children:n(`deviceSetupUsername`)}),(0,y.jsx)(`input`,{autoComplete:`off`,maxLength:64,value:j.username,onChange:e=>M({...j,username:e.target.value})})]}),(0,y.jsxs)(`label`,{className:`dc-field`,children:[(0,y.jsx)(`span`,{children:n(`deviceSetupAuth`)}),(0,y.jsxs)(`select`,{value:j.auth,onChange:e=>M({...j,auth:e.target.value}),children:[(0,y.jsx)(`option`,{value:`password`,children:n(`deviceSetupAuthPassword`)}),(0,y.jsx)(`option`,{value:`key`,children:n(`deviceSetupAuthKey`)}),(0,y.jsx)(`option`,{value:`existing`,children:n(`deviceSetupAuthExisting`)})]})]}),(0,y.jsxs)(`label`,{className:`dc-field`,children:[(0,y.jsx)(`span`,{children:n(`deviceSetupServicePort`)}),(0,y.jsx)(`input`,{type:`number`,min:1024,max:65535,value:j.port,onChange:e=>M({...j,port:Number(e.target.value)})})]})]}),(0,y.jsx)(`p`,{children:n(`deviceSetupCredentialHint`)}),(0,y.jsxs)(`details`,{children:[(0,y.jsx)(`summary`,{children:n(`deviceSetupOptionalTls`)}),(0,y.jsxs)(`label`,{className:`dc-field`,children:[(0,y.jsx)(`span`,{children:n(`deviceSetupDomain`)}),(0,y.jsx)(`input`,{maxLength:253,placeholder:`hub.example.com`,value:j.domain,onChange:e=>M({...j,domain:e.target.value.trim()})})]}),(0,y.jsxs)(`label`,{children:[(0,y.jsx)(`input`,{type:`checkbox`,checked:j.https,onChange:e=>M({...j,https:e.target.checked})}),` `,n(`deviceSetupEnableHttps`)]}),(0,y.jsx)(`p`,{children:n(`deviceSetupTlsHint`)})]}),(0,y.jsxs)(`p`,{children:[(0,y.jsx)(`strong`,{children:n(`deviceSetupPreview`)}),` `,N?.publicUrl??n(`deviceSetupPreviewEmpty`)]}),(0,y.jsxs)(`div`,{className:`dc-setup-plan`,children:[(0,y.jsx)(`strong`,{children:n(`deviceSetupUserActions`)}),(0,y.jsx)(`p`,{children:n(`deviceSetupCloudPorts`).replace(`{ports}`,j.https?`443 / 80`:String(j.port))}),(0,y.jsx)(`p`,{children:n(`deviceSetupSourceScope`)}),(0,y.jsx)(`p`,{children:n(`deviceSetupAfterStart`)})]}),(0,y.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,y.jsxs)(y.Fragment,{children:[(0,y.jsxs)(`div`,{className:`dc-setup-fields`,children:[(0,y.jsxs)(`label`,{className:`dc-field`,children:[(0,y.jsx)(`span`,{children:n(`deviceSetupHost`)}),(0,y.jsx)(`input`,{disabled:P||!!z,maxLength:253,value:w,onChange:e=>T(e.target.value)})]}),(0,y.jsxs)(`label`,{className:`dc-field`,children:[(0,y.jsx)(`span`,{children:n(`deviceSetupPort`)}),(0,y.jsx)(`input`,{disabled:P||!!z,type:`number`,min:1024,max:65535,value:re,onChange:e=>O(e.target.value)})]}),(0,y.jsxs)(`label`,{className:`dc-field`,children:[(0,y.jsx)(`span`,{children:n(`deviceHubHubUrl`)}),(0,y.jsx)(`input`,{disabled:P||!!z,maxLength:2048,value:k,onChange:e=>A(e.target.value)})]})]}),(0,y.jsx)(`p`,{className:`dc-setup-warning`,children:n(`deviceSetupReachable`)})]}),(0,y.jsx)(`p`,{children:n(`deviceSetupRegistration`)}),!Y&&(0,y.jsx)(`p`,{role:`alert`,children:n(g===`remote`?`deviceSetupRemoteInvalid`:`deviceSetupInvalid`)}),(0,y.jsxs)(`div`,{className:`dc-actions`,children:[g===`current`&&!z&&!K&&(0,y.jsx)(`button`,{className:`dc-button is-primary`,disabled:P||!H||!S||!L||oe||!!S.busy||!Y,onClick:()=>void W(),children:n(P?`deviceSetupInstalling`:`deviceSetupInstall`)}),(0,y.jsx)(`button`,{className:`dc-button`,disabled:P||l||!Y,onClick:()=>{if(!Y||!J||p.current)return;p.current=!0,ee(!0),f(!1);let e=e=>{p.current=!1,m.current&&(ee(!1),f(!e))},t=window.__piWebUiHost;try{t?.startChat({newChat:!0,prompt:D(J,S,g,g===`remote`?j:void 0),onResult:e})||e(!1)}catch{e(!1)}},children:n(g===`remote`?`deviceSetupStartAi`:`deviceSetupAi`)})]}),(0,y.jsx)(`p`,{children:n(`deviceSetupAiHint`)}),l&&(0,y.jsx)(`p`,{role:`status`,children:n(`deviceSetupAiCreating`)}),u&&(0,y.jsx)(`p`,{role:`alert`,children:n(`deviceSetupAiFailed`)})]})]}),ie&&(0,y.jsxs)(`div`,{role:`alert`,children:[(0,y.jsx)(`p`,{children:n(`deviceSetupFailed`)}),o&&(0,y.jsx)(`pre`,{className:`dc-setup-output`,children:o})]}),z&&(0,y.jsxs)(`div`,{role:`status`,children:[(0,y.jsx)(`h4`,{children:n(`deviceSetupSuccess`)}),(0,y.jsx)(`pre`,{className:`dc-setup-output`,children:z.output.slice(0,16e3)}),(0,y.jsxs)(`div`,{className:`dc-actions`,children:[(0,y.jsx)(b,{href:z.publicUrl,children:n(`deviceHubOpenHub`)}),(0,y.jsx)(`button`,{className:`dc-button is-primary`,onClick:()=>e(z.publicUrl),children:n(`deviceSetupPair`)})]})]})]})}var O=class extends Error{status;constructor(e,t){super(t),this.status=e}};function k(e){try{let t=new URL(e);return[`http:`,`https:`].includes(t.protocol)&&!t.username&&!t.password?t.href:null}catch{return null}}function A(){let e=a(),t=c().startsWith(`zh`),[n,i]=(0,v.useState)(null),[o,l]=(0,v.useState)(!1),[ee,u]=(0,v.useState)(!1),[p,m]=(0,v.useState)(!1),[h,te]=(0,v.useState)(!1),g=(0,v.useRef)(0),_=(0,v.useRef)(null);async function b(e,t){if(_.current)return;let n=++g.current,r=new AbortController;_.current=r,l(!0),u(!1);try{let a=await fetch(d(s(`/api/device-desktop/local/${e}`)),{method:t?`POST`:`GET`,credentials:`same-origin`,signal:r.signal,...t?{headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}:{}});if(g.current!==n||r.signal.aborted)return;if(a.status===403){m(!0),i(null);return}if(!a.ok)throw Error(`Request failed`);let o=await a.json();if(g.current!==n||r.signal.aborted)return;if(e===`permissions`){if(typeof o?.screen!=`boolean`||typeof o?.accessibility!=`boolean`)throw Error(`Invalid permission status`);i(e=>e&&{...e,permissions:{supported:!0,screen:o.screen,accessibility:o.accessibility}}),te(!0)}else{if(typeof o?.os!=`string`||typeof o.enabled!=`boolean`||typeof o.environmentEnabled!=`boolean`||typeof o.supported!=`boolean`)throw Error(`Invalid desktop status`);i(o)}}catch{g.current===n&&!r.signal.aborted&&u(!0)}finally{g.current===n&&!r.signal.aborted&&(_.current=null,l(!1))}}return(0,v.useEffect)(()=>(b(`status`),()=>{g.current++,_.current?.abort(),_.current=null}),[]),(0,y.jsxs)(`section`,{className:`dc-card`,"aria-label":t?`本机远程桌面`:`Local remote desktop`,"aria-busy":o,children:[(0,y.jsxs)(`div`,{className:`dc-card-header`,children:[(0,y.jsx)(`span`,{className:`dc-icon`,children:(0,y.jsx)(f,{"aria-hidden":!0})}),(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`h2`,{children:t?`本机远程桌面`:`Local remote desktop`}),(0,y.jsx)(`p`,{children:t?`管理这台设备的远程桌面与系统权限,无需连接设备中心。`:`Manage remote desktop and system permissions on this device, even while the device center is offline.`})]})]}),p?(0,y.jsx)(`p`,{role:`status`,children:t?`请在设备本机打开此页面以管理远程桌面权限。`:`Open this page on the device itself to manage remote desktop permissions.`}):(0,y.jsxs)(y.Fragment,{children:[n&&(0,y.jsxs)(y.Fragment,{children:[(0,y.jsxs)(`div`,{className:`dc-permission-row`,children:[(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`h3`,{id:`dc-desktop-label`,children:t?`启用远程桌面`:`Enable remote desktop`}),(0,y.jsx)(`p`,{children:n.enabled?t?`已启用`:`Enabled`:t?`未启用`:`Disabled`})]}),(0,y.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 b(`enable`,{enabled:!n.enabled}),children:(0,y.jsx)(`span`,{className:`dc-toggle-thumb`})})]}),!n.supported&&(0,y.jsx)(`p`,{children:t?`这台设备暂不支持远程桌面。`:`Remote desktop is currently unavailable on this device.`}),n.environmentEnabled&&(0,y.jsx)(`p`,{children:t?`远程桌面由本机服务设置保持启用。`:`Remote desktop is kept enabled by the service settings on this device.`}),n.os===`darwin`&&(0,y.jsxs)(y.Fragment,{children:[(0,y.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,y.jsxs)(`div`,{className:`dc-actions`,children:[(0,y.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:o||n.permissions?.supported===!1,onClick:()=>void b(`permissions`,{kind:`screen`}),children:t?`授予屏幕录制权限`:`Grant screen recording permission`}),(0,y.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:o||n.permissions?.supported===!1,onClick:()=>void b(`permissions`,{kind:`control`}),children:t?`授予远程控制权限`:`Grant remote control permission`})]}),n.permissions?.screen===!0&&(0,y.jsx)(`p`,{children:t?`屏幕录制:已授权`:`Screen recording: granted`}),n.permissions?.accessibility===!0&&(0,y.jsx)(`p`,{children:t?`远程控制:已授权`:`Remote control: granted`}),h&&(0,y.jsx)(`p`,{role:`status`,children:t?`已发起授权请求,请确认系统设置后刷新状态。`:`Permission requested. Confirm in System Settings, then refresh the status.`})]})]}),ee&&(0,y.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:t?`无法更新本机远程桌面设置,请重试。`:`Unable to update local remote desktop settings. Please retry.`}),(0,y.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:o,onClick:()=>void b(`status`),children:[(0,y.jsx)(r,{"aria-hidden":!0}),o?e(`deviceHubWorking`):t?`刷新远程桌面状态`:`Refresh remote desktop status`]})]})]})}function j({pathCompletions:e=[]}){let c=a(),p=h(),[m,x]=(0,v.useState)(p.revision?`groups`:`overview`);(0,v.useEffect)(()=>{p.revision&&x(`groups`)},[p.revision]);let[S,ne]=(0,v.useState)(null),[C,w]=(0,v.useState)(``),[T,E]=(0,v.useState)(``),[D,j]=(0,v.useState)(null),[M,N]=(0,v.useState)(Date.now()),[P,F]=(0,v.useState)(null),[ie,I]=(0,v.useState)(``),[L,ae]=(0,v.useState)(``),[oe,R]=(0,v.useState)(``),[z,se]=(0,v.useState)(!1),[B,V]=(0,v.useState)(!0),H=(0,v.useRef)(!1),U=(0,v.useRef)(0),W=(0,v.useRef)(new Set),G=(0,v.useRef)(!1),K=(0,v.useRef)(!1),q=(0,v.useRef)(null),J=(0,v.useRef)(c);J.current=c;async function Y(e,t){let n=new AbortController;W.current.add(n);try{let r=await fetch(d(s(`/api/device-center/${e}`)),{method:t?`POST`:`GET`,credentials:`same-origin`,signal:n.signal,...t?{headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}:{}}),i=await r.json().catch(()=>({}));if(!r.ok)throw new O(r.status,typeof i.error==`string`?i.error:J.current(`deviceHubRequestFailed`,{status:r.status}));return i}finally{W.current.delete(n)}}function X(e){return H.current&&U.current===e}function Z(e){return e instanceof O&&e.status===403?(se(!0),J.current(`deviceHubLocalOnly`)):e instanceof Error?e.message:J.current(`deviceHubNetworkError`)}function Q(e){q.current=e,ne(e),K.current||(E(e.name),w(e.hubUrl??``))}async function ce(){let e=U.current;try{let t=await Y(`status`);if(!X(e)||G.current)return;Q(t),ae(``),se(!1)}catch(t){X(e)&&ae(Z(t))}finally{X(e)&&V(!1)}}(0,v.useEffect)(()=>{H.current=!0;let e=!1,t,n=async()=>{await ce(),!e&&H.current&&(t=setTimeout(n,5e3))};return n(),()=>{e=!0,H.current=!1,U.current++,clearTimeout(t);for(let e of W.current)e.abort()}},[]),(0,v.useEffect)(()=>{if(!D)return;let e=U.current,t=!1,n,r=setInterval(()=>N(Date.now()),1e3),i=async()=>{if(!(t||!X(e)||Date.now()>=D.expiresAt)){try{let n=await Y(`poll`,{});if(t||!X(e))return;if(n.paired){let n=await Y(`status`);if(t||!X(e))return;K.current=!1,Q(n),j(null),I(``),R(``);return}I(``)}catch(n){!t&&X(e)&&I(`${J.current(`deviceHubPollError`)} ${Z(n)}`)}!t&&X(e)&&(n=setTimeout(i,2e3))}};return n=setTimeout(i,2e3),()=>{t=!0,clearTimeout(n),clearInterval(r)}},[D]);async function le(){if(G.current)return;let e=k(C.trim());if(!e){I(c(`deviceHubInvalidUrl`));return}if(!T.trim()||T.trim().length>80){I(c(`deviceHubInvalidName`));return}let t=++U.current;G.current=!0,F(`pair`),I(``),R(``),j(null);try{let n=await Y(`pair`,{hubUrl:e,name:T.trim()});if(!X(t))return;if(!n.code||!Number.isFinite(n.expiresAt)||!k(n.hubUrl))throw Error(c(`deviceHubPairError`));N(Date.now()),j(n)}catch(e){X(t)&&I(`${c(`deviceHubPairError`)} ${Z(e)}`)}finally{X(t)&&(G.current=!1,F(null))}}async function ue(){let e=q.current;if(!e?.deviceId||G.current)return;let t=++U.current;G.current=!0,F(`permission`),I(``),R(``),Q({...e,allowExecution:!e.allowExecution});try{await Y(`execution`,{allowExecution:!e.allowExecution}),X(t)&&R(c(`deviceHubSaved`))}catch(n){X(t)&&(Q(e),I(`${c(`deviceHubPermissionError`)} ${Z(n)}`))}finally{X(t)&&(G.current=!1,F(null))}}async function de(){let e=q.current;if(!e?.deviceId||G.current||!window.confirm(c(`deviceHubDisconnectConfirm`,{name:e.name})))return;let t=++U.current;G.current=!0,F(`disconnect`),I(``),R(``);try{if(await Y(`disconnect`,{}),!X(t))return;K.current=!1,Q({name:e.name,allowExecution:!1,connected:!1}),j(null)}catch(e){X(t)&&I(`${c(`deviceHubDisconnectError`)} ${Z(e)}`)}finally{X(t)&&(G.current=!1,F(null))}}async function fe(){if(!D)return;let e=U.current;try{await navigator.clipboard.writeText(D.code),X(e)&&R(c(`deviceHubCopied`))}catch{X(e)&&I(c(`deviceHubCopyFailed`))}}let $=!!S?.deviceId,pe=k($?S?.hubUrl??``:D?.hubUrl??``),me=Math.max(0,Math.ceil(((D?.expiresAt??0)-M)/1e3)),he=`${Math.floor(me/60)}:${String(me%60).padStart(2,`0`)}`,ge=pe?(0,y.jsxs)(b,{href:pe,children:[(0,y.jsx)(t,{"aria-hidden":!0}),c(`deviceHubOpenHub`)]}):null;return(0,y.jsxs)(`section`,{className:`dc-page`,"aria-label":c(`deviceHubTitle`),children:[(0,y.jsxs)(`header`,{className:`dc-header`,children:[(0,y.jsxs)(`div`,{className:`dc-heading`,children:[(0,y.jsxs)(`span`,{className:`dc-eyebrow`,children:[(0,y.jsx)(f,{"aria-hidden":!0}),c(`deviceHubTitle`)]}),(0,y.jsx)(`h1`,{children:c(`deviceHubTitle`)}),(0,y.jsx)(`p`,{children:c(`deviceHubSubtitle`)})]}),(0,y.jsxs)(`div`,{className:`dc-actions`,children:[$&&ge,(0,y.jsxs)(`span`,{className:`dc-status ${$?S?.connected?`is-online`:`is-offline`:`is-unpaired`}`,children:[(0,y.jsx)(`span`,{className:`dc-status-dot`}),c($?S?.connected?`deviceHubOnline`:`deviceHubOffline`:`deviceHubUnpaired`)]})]})]}),(0,y.jsxs)(`div`,{className:`dc-layout`,children:[(0,y.jsxs)(`nav`,{className:`dc-sidebar`,"aria-label":c(`deviceHubTitle`),children:[(0,y.jsxs)(`button`,{type:`button`,className:`dc-nav-item${m===`overview`?` is-active`:``}`,"aria-current":m===`overview`?`page`:void 0,onClick:()=>x(`overview`),children:[(0,y.jsx)(f,{"aria-hidden":!0}),c(`deviceHubOverview`)]}),(0,y.jsxs)(`button`,{type:`button`,className:`dc-nav-item${m===`groups`?` is-active`:``}`,"aria-current":m===`groups`?`page`:void 0,onClick:()=>x(`groups`),children:[(0,y.jsx)(ee,{"aria-hidden":!0}),c(`deviceHubGroups`)]}),(0,y.jsxs)(`button`,{type:`button`,className:`dc-nav-item${m===`settings`?` is-active`:``}`,"aria-current":m===`settings`?`page`:void 0,onClick:()=>x(`settings`),children:[(0,y.jsx)(u,{"aria-hidden":!0}),c(`deviceHubSettings`)]})]}),(0,y.jsxs)(`main`,{className:`dc-content`,children:[B&&(0,y.jsxs)(`div`,{className:`dc-loading`,role:`status`,children:[(0,y.jsx)(r,{"aria-hidden":!0}),c(`deviceHubLoading`)]}),(z||L)&&(0,y.jsxs)(`div`,{className:`dc-notice is-error`,role:`alert`,children:[(0,y.jsx)(`span`,{children:z?c(`deviceHubLocalOnly`):`${c(`deviceHubStatusError`)} ${L}`}),(0,y.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>void ce(),children:[(0,y.jsx)(r,{"aria-hidden":!0}),c(`deviceHubRetry`)]})]}),ie&&!z&&(0,y.jsx)(`div`,{className:`dc-notice is-error`,role:`alert`,children:ie}),oe&&(0,y.jsxs)(`div`,{className:`dc-notice is-success`,role:`status`,children:[(0,y.jsx)(i,{"aria-hidden":!0}),oe]}),!$&&(S||z)&&m===`overview`&&(0,y.jsx)(re,{initialHubUrl:C,onConnect:e=>{if(z){R(c(`deviceHubLocalOnly`));return}K.current=!0,w(e),x(`settings`)}}),!z&&m===`overview`&&(0,y.jsxs)(`section`,{className:`dc-card`,children:[(0,y.jsx)(`h3`,{children:c(`deviceSetupNext`)}),(0,y.jsx)(`p`,{children:c(`deviceSetupNextHint`)}),(0,y.jsx)(`button`,{className:`dc-button is-primary`,onClick:()=>x(`groups`),children:c(`deviceSetupManage`)})]}),m===`settings`&&(0,y.jsx)(A,{}),S&&!z&&!$&&m===`settings`&&(0,y.jsxs)(`section`,{className:`dc-card`,children:[(0,y.jsxs)(`div`,{className:`dc-card-header`,children:[(0,y.jsx)(`span`,{className:`dc-icon`,children:(0,y.jsx)(u,{"aria-hidden":!0})}),(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`h2`,{children:c(`deviceHubPairTitle`)}),(0,y.jsx)(`p`,{children:c(`deviceHubPairHint`)})]})]}),(0,y.jsx)(`ol`,{className:`dc-steps`,children:[`deviceHubStepDetails`,`deviceHubStepApprove`,`deviceHubStepWait`].map((e,t)=>(0,y.jsxs)(`li`,{className:D?t===0?`is-complete`:`is-active`:t===0?`is-active`:``,children:[(0,y.jsx)(`span`,{className:`dc-step-number`,children:D&&t===0?(0,y.jsx)(i,{"aria-hidden":!0}):t+1}),(0,y.jsx)(`span`,{children:c(e)})]},e))}),(0,y.jsxs)(`form`,{className:`dc-form`,onSubmit:e=>{e.preventDefault(),le()},children:[(0,y.jsxs)(`div`,{className:`dc-field`,children:[(0,y.jsx)(`label`,{htmlFor:`dc-hub-url`,children:c(`deviceHubHubUrl`)}),(0,y.jsx)(`input`,{id:`dc-hub-url`,type:`url`,autoComplete:`url`,required:!0,placeholder:c(`deviceHubHubPlaceholder`),value:C,disabled:!!D||!!P,onChange:e=>{K.current=!0,w(e.target.value)}})]}),(0,y.jsxs)(`div`,{className:`dc-field`,children:[(0,y.jsx)(`label`,{htmlFor:`dc-device-name`,children:c(`deviceHubName`)}),(0,y.jsx)(`input`,{id:`dc-device-name`,maxLength:80,required:!0,autoComplete:`off`,placeholder:c(`deviceHubNamePlaceholder`),value:T,disabled:!!D||!!P,onChange:e=>{K.current=!0,E(e.target.value)}})]}),!D&&(0,y.jsx)(`div`,{className:`dc-actions`,children:(0,y.jsxs)(`button`,{className:`dc-button is-primary`,type:`submit`,disabled:!!P,children:[(0,y.jsx)(u,{"aria-hidden":!0}),c(P?`deviceHubWorking`:`deviceHubGetCode`)]})})]}),D&&(0,y.jsxs)(`div`,{className:`dc-pairing`,children:[(0,y.jsx)(`span`,{className:`dc-code-label`,children:c(`deviceHubCode`)}),(0,y.jsxs)(`div`,{className:`dc-code-row`,children:[(0,y.jsx)(`code`,{className:`dc-code`,children:D.code}),(0,y.jsx)(`button`,{className:`dc-icon-button`,type:`button`,"aria-label":c(`deviceHubCopy`),onClick:()=>void fe(),children:(0,y.jsx)(l,{"aria-hidden":!0})})]}),(0,y.jsx)(`div`,{className:`dc-pair-meta`,children:c(me?`deviceHubExpires`:`deviceHubExpired`,{time:he})}),(0,y.jsxs)(`div`,{className:`dc-actions`,children:[ge,(0,y.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:!!P,onClick:()=>{++U.current,j(null),I(``),R(``)},children:[(0,y.jsx)(r,{"aria-hidden":!0}),c(`deviceHubNewCode`)]})]}),me>0&&(0,y.jsxs)(`p`,{className:`dc-progress`,role:`status`,children:[(0,y.jsx)(r,{"aria-hidden":!0}),c(`deviceHubWaiting`)]})]})]}),$&&S&&!z&&(0,y.jsxs)(y.Fragment,{children:[m===`overview`&&(0,y.jsxs)(`section`,{className:`dc-card`,children:[(0,y.jsxs)(`div`,{className:`dc-device-summary`,children:[(0,y.jsx)(`span`,{className:`dc-device-icon`,children:(0,y.jsx)(f,{"aria-hidden":!0})}),(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`h2`,{children:S.name}),(0,y.jsx)(`p`,{children:c(`deviceHubDeviceTitle`)})]})]}),(0,y.jsxs)(`dl`,{className:`dc-details`,children:[(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`dt`,{children:c(`deviceHubDeviceId`)}),(0,y.jsx)(`dd`,{children:S.deviceId})]}),(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`dt`,{children:c(`deviceHubHubUrl`)}),(0,y.jsx)(`dd`,{children:S.hubUrl})]})]})]}),m===`settings`&&(0,y.jsxs)(`section`,{className:`dc-card`,children:[(0,y.jsxs)(`div`,{className:`dc-card-header`,children:[(0,y.jsx)(`span`,{className:`dc-icon`,children:(0,y.jsx)(n,{"aria-hidden":!0})}),(0,y.jsx)(`div`,{children:(0,y.jsx)(`h2`,{children:c(`deviceHubPermissions`)})})]}),(0,y.jsxs)(`div`,{className:`dc-permission-row`,children:[(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`h3`,{id:`dc-permission-label`,children:c(`deviceHubPermissionLabel`)}),(0,y.jsx)(`p`,{id:`dc-permission-hint`,children:c(`deviceHubPermissionHint`)})]}),(0,y.jsx)(`button`,{type:`button`,className:`dc-toggle${S.allowExecution?` is-on`:``}`,role:`switch`,"aria-checked":S.allowExecution,"aria-labelledby":`dc-permission-label`,"aria-describedby":`dc-permission-hint`,disabled:!!P,onClick:()=>void ue(),children:(0,y.jsx)(`span`,{className:`dc-toggle-thumb`})})]}),(0,y.jsx)(`p`,{className:`dc-permission-state`,role:`status`,children:c(P===`permission`?`deviceHubSaving`:S.allowExecution?`deviceHubEnabled`:`deviceHubReadOnly`)})]}),m===`settings`&&(0,y.jsxs)(`details`,{className:`dc-advanced`,children:[(0,y.jsx)(`summary`,{children:c(`deviceHubAdvanced`)}),(0,y.jsxs)(`div`,{className:`dc-danger-zone`,children:[(0,y.jsx)(`h3`,{children:c(`deviceHubDisconnect`)}),(0,y.jsx)(`p`,{children:c(`deviceHubDisconnectHint`)}),(0,y.jsx)(`button`,{type:`button`,className:`dc-button is-danger`,disabled:!!P,onClick:()=>void de(),children:c(P===`disconnect`?`deviceHubWorking`:`deviceHubDisconnect`)})]})]})]}),$&&S?.hubUrl&&S.deviceId&&!z&&m!==`groups`&&(0,y.jsx)(g,{hubUrl:S.hubUrl,currentDeviceId:S.deviceId},`directory:${S.hubUrl}:${S.deviceId}`),!z&&(m===`settings`||m===`groups`)&&(0,y.jsx)(te,{pathCompletions:e},`bots:${S?.hubUrl??``}:${S?.deviceId??`unpaired`}`),m===`groups`&&(0,y.jsx)(_,{navigation:p}),(0,y.jsxs)(`aside`,{className:`dc-help`,children:[(0,y.jsx)(o,{className:`dc-help-icon`,"aria-hidden":!0}),(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`h3`,{children:c(`deviceHubHelpTitle`)}),(0,y.jsx)(`p`,{children:c(`deviceHubHelpText`)})]})]})]})]})]})}export{j as DeviceCenter};
@@ -1,3 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{B as t,Pt as n,Tt as r,_ as i,an as a,et as o,fn as s,in as c,k as l,mt as ee,st as u,un as d,yt as f}from"./fi-DaSO0Q-m.js";import{i as p,t as m}from"./react-CR5VJ85Q.js";import{T as h,_t as te,zt as g}from"./index-Cdh3sibd.js";import{DeviceGroups as _}from"./DeviceGroups-D2rogxEN.js";var v=e(p(),1),y=m();function b({href:e,children:t}){let n=a(),[r,i]=(0,v.useState)(!1),[o,s]=(0,v.useState)(!1);return(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(`a`,{className:`dc-button`,href:e,target:`_blank`,rel:`noopener noreferrer`,onClick:t=>{let n=window.piDesktop;n?.openHub&&(t.preventDefault(),!o&&(s(!0),i(!1),n.openHub(e).then(e=>i(!e),()=>i(!0)).finally(()=>s(!1))))},"aria-busy":o,children:t}),r&&(0,y.jsxs)(`span`,{role:`alert`,children:[n(`deviceHubNetworkError`),` `,(0,y.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,children:e})]})]})}function x(e){if(!S(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 S(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 ne(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 C=`https://raw.githubusercontent.com/xing-shuyin/pi-web-ui/main/docs/device-center-deployment.md`,w=`https://github.com/xing-shuyin/pi-web-ui/blob/main/docs/device-center-deployment.md`,T=`pi-web-ui hub install --host 0.0.0.0 --port 8790 --public-url http://SERVER_IP:8790 --allow-registration`;function E(e){let t=e=>e.includes(`:`)?S(e)&&![`::`,`::1`].includes(e):/^[\d.]+$/.test(e)?S(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 D(e,t,n,r){if(!x(e))throw Error(`Invalid Hub setup`);if(r){let t=E(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: ${C} (fallback: ${w}). 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: ${T}`,`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 re({onConnect:e,initialHubUrl:t=``}){let n=a(),[r,i]=(0,v.useState)(t),[o,c]=(0,v.useState)(``),[l,ee]=(0,v.useState)(!1),[u,f]=(0,v.useState)(!1),p=(0,v.useRef)(!1),m=(0,v.useRef)(!1);(0,v.useEffect)(()=>(m.current=!0,()=>{m.current=!1}),[]);let[h,te]=(0,v.useState)(null),[g,_]=(0,v.useState)(`current`),[S,C]=(0,v.useState)(null),[w,T]=(0,v.useState)(`127.0.0.1`),[re,O]=(0,v.useState)(`8790`),[k,A]=(0,v.useState)(`http://127.0.0.1:8790`),[j,M]=(0,v.useState)({server:``,sshPort:22,username:`root`,auth:`password`,port:8790,domain:``,https:!1}),N=E(j),[P,F]=(0,v.useState)(!1),[ie,I]=(0,v.useState)(!1),[L,ae]=(0,v.useState)(!1),[oe,R]=(0,v.useState)(!1),[z,se]=(0,v.useState)(null),B=(0,v.useRef)(null),V=(0,v.useRef)(!1),H=ne(window.location.origin);(0,v.useEffect)(()=>()=>B.current?.abort(),[]);let U=async()=>{if(V.current)return;B.current?.abort();let e=new AbortController;B.current=e,I(!1),ae(!1),R(!1);try{let t=await fetch(d(s(`/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`||!x({host:`127.0.0.1`,port:n.defaultPort,publicUrl:n.defaultPublicUrl}))throw Error();if(e.signal.aborted)return;C(n),n.installation?.installed?(T(n.installation.host??`127.0.0.1`),O(String(n.installation.port)),A(n.installation.publicUrl??``),i(n.installation.publicUrl??``)):S||(O(String(n.defaultPort)),A(n.defaultPublicUrl))}catch{e.signal.aborted||(I(!0),R(!0))}finally{e.signal.aborted||ae(!0)}},W=async()=>{let e={host:w,port:Number(re),publicUrl:k};if(V.current||!H||!S||!L||oe||S.busy||S.installation?.installed||!x(e))return;V.current=!0,B.current?.abort(),F(!0),I(!1),c(``);let t=new AbortController;B.current=t;try{let n=await fetch(d(s(`/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){C(e=>e&&{...e,busy:!0}),V.current=!1,F(!1),await U();return}if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(typeof e.error==`string`?e.error.slice(0,4096):`HTTP ${n.status}`)}let r=await n.json();if(!x({...e,publicUrl:r.publicUrl})||typeof r.output!=`string`)throw Error();t.signal.aborted||se(r)}catch(e){t.signal.aborted||(I(!0),c(e instanceof Error?e.message.slice(0,4096):``))}finally{V.current=!1,t.signal.aborted||F(!1)}},G=S?.installation,K=!!G?.installed,q=K&&G.running&&G.owned,J=g===`remote`?N:{host:w,port:Number(re),publicUrl:k},Y=!!J&&x(J);return(0,y.jsxs)(`section`,{className:`dc-onboarding`,children:[(0,y.jsx)(`h3`,{children:n(`deviceSetupWelcome`)}),(0,y.jsx)(`p`,{children:n(`deviceSetupIntro`)}),(0,y.jsxs)(`div`,{className:`dc-actions`,children:[(0,y.jsx)(`button`,{className:`dc-button`,disabled:P,"aria-pressed":h===`connect`,onClick:()=>te(`connect`),children:n(`deviceSetupConnect`)}),(0,y.jsx)(`button`,{className:`dc-button`,disabled:P,"aria-pressed":h===`create`,onClick:()=>{te(`create`),!S&&H&&U()},children:n(`deviceSetupCreate`)})]}),h===`connect`&&(0,y.jsxs)(`form`,{onSubmit:t=>{t.preventDefault(),e(r.trim())},children:[(0,y.jsxs)(`label`,{className:`dc-field`,children:[(0,y.jsx)(`span`,{children:n(`deviceHubHubUrl`)}),(0,y.jsx)(`input`,{type:`url`,required:!0,maxLength:2048,value:r,onChange:e=>i(e.target.value),placeholder:`https://hub.example.com`})]}),(0,y.jsx)(`button`,{className:`dc-button is-primary`,disabled:!x({host:`localhost`,port:8790,publicUrl:r.trim()}),children:n(`deviceSetupPair`)})]}),h===`create`&&(0,y.jsxs)(y.Fragment,{children:[(0,y.jsxs)(`label`,{className:`dc-field`,children:[(0,y.jsx)(`span`,{children:n(`deviceSetupTarget`)}),(0,y.jsxs)(`select`,{disabled:P,value:g,onChange:e=>_(e.target.value),children:[(0,y.jsx)(`option`,{value:`current`,children:n(`deviceSetupCurrent`)}),(0,y.jsx)(`option`,{value:`remote`,children:n(`deviceSetupRemote`)})]})]}),(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(`p`,{children:n(g===`current`?`deviceSetupCurrentHint`:`deviceSetupRemoteHint`)}),g===`current`&&(0,y.jsxs)(`div`,{className:`dc-setup-plan`,children:[(0,y.jsx)(`strong`,{children:n(`deviceSetupPlan`)}),(0,y.jsx)(`p`,{children:n(`deviceSetupPlanHint`)}),S&&(0,y.jsxs)(`dl`,{children:[(0,y.jsx)(`dt`,{children:n(`deviceSetupEnvironment`)}),(0,y.jsxs)(`dd`,{children:[S.platform,` · Node `,S.nodeVersion]}),(0,y.jsx)(`dt`,{children:n(`deviceSetupDataDir`)}),(0,y.jsx)(`dd`,{children:S.dataDir}),(0,y.jsx)(`dt`,{children:n(`deviceSetupCli`)}),(0,y.jsx)(`dd`,{children:S.cliPath})]}),!H&&(0,y.jsx)(`p`,{role:`status`,children:n(`deviceSetupLocalOnly`)}),(0,y.jsx)(`p`,{children:n(`deviceSetupBackground`)}),K&&(0,y.jsxs)(`div`,{role:`status`,children:[(0,y.jsx)(`h4`,{children:n(q?`deviceSetupRestored`:`deviceSetupUnhealthy`)}),(0,y.jsx)(`p`,{children:G.publicUrl}),q&&Y&&G.publicUrl?(0,y.jsxs)(`div`,{className:`dc-actions`,children:[(0,y.jsx)(b,{href:G.publicUrl,children:n(`deviceHubOpenHub`)}),(0,y.jsx)(`button`,{className:`dc-button`,onClick:()=>e(G.publicUrl),children:n(`deviceSetupPair`)})]}):(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(`p`,{children:n(`deviceSetupRecovery`)}),(0,y.jsx)(`pre`,{className:`dc-setup-output`,children:`pi-web-ui hub status --json
3
- pi-web-ui hub --help`})]})]}),S?.busy&&(0,y.jsx)(`p`,{role:`status`,children:n(`deviceSetupBusy`)}),H&&(0,y.jsx)(`button`,{className:`dc-button`,disabled:P||!L,onClick:()=>void U(),children:n(L?`deviceSetupRetry`:`deviceHubWorking`)})]}),g===`remote`?(0,y.jsxs)(y.Fragment,{children:[(0,y.jsxs)(`div`,{className:`dc-setup-fields`,children:[(0,y.jsxs)(`label`,{className:`dc-field`,children:[(0,y.jsx)(`span`,{children:n(`deviceSetupServer`)}),(0,y.jsx)(`input`,{autoComplete:`off`,maxLength:253,placeholder:`203.0.113.10`,value:j.server,onChange:e=>M({...j,server:e.target.value.trim()})})]}),(0,y.jsxs)(`label`,{className:`dc-field`,children:[(0,y.jsx)(`span`,{children:n(`deviceSetupSshPort`)}),(0,y.jsx)(`input`,{type:`number`,min:1,max:65535,value:j.sshPort,onChange:e=>M({...j,sshPort:Number(e.target.value)})})]}),(0,y.jsxs)(`label`,{className:`dc-field`,children:[(0,y.jsx)(`span`,{children:n(`deviceSetupUsername`)}),(0,y.jsx)(`input`,{autoComplete:`off`,maxLength:64,value:j.username,onChange:e=>M({...j,username:e.target.value})})]}),(0,y.jsxs)(`label`,{className:`dc-field`,children:[(0,y.jsx)(`span`,{children:n(`deviceSetupAuth`)}),(0,y.jsxs)(`select`,{value:j.auth,onChange:e=>M({...j,auth:e.target.value}),children:[(0,y.jsx)(`option`,{value:`password`,children:n(`deviceSetupAuthPassword`)}),(0,y.jsx)(`option`,{value:`key`,children:n(`deviceSetupAuthKey`)}),(0,y.jsx)(`option`,{value:`existing`,children:n(`deviceSetupAuthExisting`)})]})]}),(0,y.jsxs)(`label`,{className:`dc-field`,children:[(0,y.jsx)(`span`,{children:n(`deviceSetupServicePort`)}),(0,y.jsx)(`input`,{type:`number`,min:1024,max:65535,value:j.port,onChange:e=>M({...j,port:Number(e.target.value)})})]})]}),(0,y.jsx)(`p`,{children:n(`deviceSetupCredentialHint`)}),(0,y.jsxs)(`details`,{children:[(0,y.jsx)(`summary`,{children:n(`deviceSetupOptionalTls`)}),(0,y.jsxs)(`label`,{className:`dc-field`,children:[(0,y.jsx)(`span`,{children:n(`deviceSetupDomain`)}),(0,y.jsx)(`input`,{maxLength:253,placeholder:`hub.example.com`,value:j.domain,onChange:e=>M({...j,domain:e.target.value.trim()})})]}),(0,y.jsxs)(`label`,{children:[(0,y.jsx)(`input`,{type:`checkbox`,checked:j.https,onChange:e=>M({...j,https:e.target.checked})}),` `,n(`deviceSetupEnableHttps`)]}),(0,y.jsx)(`p`,{children:n(`deviceSetupTlsHint`)})]}),(0,y.jsxs)(`p`,{children:[(0,y.jsx)(`strong`,{children:n(`deviceSetupPreview`)}),` `,N?.publicUrl??n(`deviceSetupPreviewEmpty`)]}),(0,y.jsxs)(`div`,{className:`dc-setup-plan`,children:[(0,y.jsx)(`strong`,{children:n(`deviceSetupUserActions`)}),(0,y.jsx)(`p`,{children:n(`deviceSetupCloudPorts`).replace(`{ports}`,j.https?`443 / 80`:String(j.port))}),(0,y.jsx)(`p`,{children:n(`deviceSetupSourceScope`)}),(0,y.jsx)(`p`,{children:n(`deviceSetupAfterStart`)})]}),(0,y.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,y.jsxs)(y.Fragment,{children:[(0,y.jsxs)(`div`,{className:`dc-setup-fields`,children:[(0,y.jsxs)(`label`,{className:`dc-field`,children:[(0,y.jsx)(`span`,{children:n(`deviceSetupHost`)}),(0,y.jsx)(`input`,{disabled:P||!!z,maxLength:253,value:w,onChange:e=>T(e.target.value)})]}),(0,y.jsxs)(`label`,{className:`dc-field`,children:[(0,y.jsx)(`span`,{children:n(`deviceSetupPort`)}),(0,y.jsx)(`input`,{disabled:P||!!z,type:`number`,min:1024,max:65535,value:re,onChange:e=>O(e.target.value)})]}),(0,y.jsxs)(`label`,{className:`dc-field`,children:[(0,y.jsx)(`span`,{children:n(`deviceHubHubUrl`)}),(0,y.jsx)(`input`,{disabled:P||!!z,maxLength:2048,value:k,onChange:e=>A(e.target.value)})]})]}),(0,y.jsx)(`p`,{className:`dc-setup-warning`,children:n(`deviceSetupReachable`)})]}),(0,y.jsx)(`p`,{children:n(`deviceSetupRegistration`)}),!Y&&(0,y.jsx)(`p`,{role:`alert`,children:n(g===`remote`?`deviceSetupRemoteInvalid`:`deviceSetupInvalid`)}),(0,y.jsxs)(`div`,{className:`dc-actions`,children:[g===`current`&&!z&&!K&&(0,y.jsx)(`button`,{className:`dc-button is-primary`,disabled:P||!H||!S||!L||oe||!!S.busy||!Y,onClick:()=>void W(),children:n(P?`deviceSetupInstalling`:`deviceSetupInstall`)}),(0,y.jsx)(`button`,{className:`dc-button`,disabled:P||l||!Y,onClick:()=>{if(!Y||!J||p.current)return;p.current=!0,ee(!0),f(!1);let e=e=>{p.current=!1,m.current&&(ee(!1),f(!e))},t=window.__piWebUiHost;try{t?.startChat({newChat:!0,prompt:D(J,S,g,g===`remote`?j:void 0),onResult:e})||e(!1)}catch{e(!1)}},children:n(g===`remote`?`deviceSetupStartAi`:`deviceSetupAi`)})]}),(0,y.jsx)(`p`,{children:n(`deviceSetupAiHint`)}),l&&(0,y.jsx)(`p`,{role:`status`,children:n(`deviceSetupAiCreating`)}),u&&(0,y.jsx)(`p`,{role:`alert`,children:n(`deviceSetupAiFailed`)})]})]}),ie&&(0,y.jsxs)(`div`,{role:`alert`,children:[(0,y.jsx)(`p`,{children:n(`deviceSetupFailed`)}),o&&(0,y.jsx)(`pre`,{className:`dc-setup-output`,children:o})]}),z&&(0,y.jsxs)(`div`,{role:`status`,children:[(0,y.jsx)(`h4`,{children:n(`deviceSetupSuccess`)}),(0,y.jsx)(`pre`,{className:`dc-setup-output`,children:z.output.slice(0,16e3)}),(0,y.jsxs)(`div`,{className:`dc-actions`,children:[(0,y.jsx)(b,{href:z.publicUrl,children:n(`deviceHubOpenHub`)}),(0,y.jsx)(`button`,{className:`dc-button is-primary`,onClick:()=>e(z.publicUrl),children:n(`deviceSetupPair`)})]})]})]})}var O=class extends Error{status;constructor(e,t){super(t),this.status=e}};function k(e){try{let t=new URL(e);return[`http:`,`https:`].includes(t.protocol)&&!t.username&&!t.password?t.href:null}catch{return null}}function A(){let e=a(),t=c().startsWith(`zh`),[n,i]=(0,v.useState)(null),[o,l]=(0,v.useState)(!1),[ee,u]=(0,v.useState)(!1),[p,m]=(0,v.useState)(!1),[h,te]=(0,v.useState)(!1),g=(0,v.useRef)(0),_=(0,v.useRef)(null);async function b(e,t){if(_.current)return;let n=++g.current,r=new AbortController;_.current=r,l(!0),u(!1);try{let a=await fetch(d(s(`/api/device-desktop/local/${e}`)),{method:t?`POST`:`GET`,credentials:`same-origin`,signal:r.signal,...t?{headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}:{}});if(g.current!==n||r.signal.aborted)return;if(a.status===403){m(!0),i(null);return}if(!a.ok)throw Error(`Request failed`);let o=await a.json();if(g.current!==n||r.signal.aborted)return;if(e===`permissions`){if(typeof o?.screen!=`boolean`||typeof o?.accessibility!=`boolean`)throw Error(`Invalid permission status`);i(e=>e&&{...e,permissions:{supported:!0,screen:o.screen,accessibility:o.accessibility}}),te(!0)}else{if(typeof o?.os!=`string`||typeof o.enabled!=`boolean`||typeof o.environmentEnabled!=`boolean`||typeof o.supported!=`boolean`)throw Error(`Invalid desktop status`);i(o)}}catch{g.current===n&&!r.signal.aborted&&u(!0)}finally{g.current===n&&!r.signal.aborted&&(_.current=null,l(!1))}}return(0,v.useEffect)(()=>(b(`status`),()=>{g.current++,_.current?.abort(),_.current=null}),[]),(0,y.jsxs)(`section`,{className:`dc-card`,"aria-label":t?`本机远程桌面`:`Local remote desktop`,"aria-busy":o,children:[(0,y.jsxs)(`div`,{className:`dc-card-header`,children:[(0,y.jsx)(`span`,{className:`dc-icon`,children:(0,y.jsx)(f,{"aria-hidden":!0})}),(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`h2`,{children:t?`本机远程桌面`:`Local remote desktop`}),(0,y.jsx)(`p`,{children:t?`管理这台设备的远程桌面与系统权限,无需连接设备中心。`:`Manage remote desktop and system permissions on this device, even while the device center is offline.`})]})]}),p?(0,y.jsx)(`p`,{role:`status`,children:t?`请在设备本机打开此页面以管理远程桌面权限。`:`Open this page on the device itself to manage remote desktop permissions.`}):(0,y.jsxs)(y.Fragment,{children:[n&&(0,y.jsxs)(y.Fragment,{children:[(0,y.jsxs)(`div`,{className:`dc-permission-row`,children:[(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`h3`,{id:`dc-desktop-label`,children:t?`启用远程桌面`:`Enable remote desktop`}),(0,y.jsx)(`p`,{children:n.enabled?t?`已启用`:`Enabled`:t?`未启用`:`Disabled`})]}),(0,y.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 b(`enable`,{enabled:!n.enabled}),children:(0,y.jsx)(`span`,{className:`dc-toggle-thumb`})})]}),!n.supported&&(0,y.jsx)(`p`,{children:t?`这台设备暂不支持远程桌面。`:`Remote desktop is currently unavailable on this device.`}),n.environmentEnabled&&(0,y.jsx)(`p`,{children:t?`远程桌面由本机服务设置保持启用。`:`Remote desktop is kept enabled by the service settings on this device.`}),n.os===`darwin`&&(0,y.jsxs)(y.Fragment,{children:[(0,y.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,y.jsxs)(`div`,{className:`dc-actions`,children:[(0,y.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:o||n.permissions?.supported===!1,onClick:()=>void b(`permissions`,{kind:`screen`}),children:t?`授予屏幕录制权限`:`Grant screen recording permission`}),(0,y.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:o||n.permissions?.supported===!1,onClick:()=>void b(`permissions`,{kind:`control`}),children:t?`授予远程控制权限`:`Grant remote control permission`})]}),n.permissions?.screen===!0&&(0,y.jsx)(`p`,{children:t?`屏幕录制:已授权`:`Screen recording: granted`}),n.permissions?.accessibility===!0&&(0,y.jsx)(`p`,{children:t?`远程控制:已授权`:`Remote control: granted`}),h&&(0,y.jsx)(`p`,{role:`status`,children:t?`已发起授权请求,请确认系统设置后刷新状态。`:`Permission requested. Confirm in System Settings, then refresh the status.`})]})]}),ee&&(0,y.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:t?`无法更新本机远程桌面设置,请重试。`:`Unable to update local remote desktop settings. Please retry.`}),(0,y.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:o,onClick:()=>void b(`status`),children:[(0,y.jsx)(r,{"aria-hidden":!0}),o?e(`deviceHubWorking`):t?`刷新远程桌面状态`:`Refresh remote desktop status`]})]})]})}function j({pathCompletions:e=[]}){let c=a(),p=h(),[m,x]=(0,v.useState)(p.revision?`groups`:`overview`);(0,v.useEffect)(()=>{p.revision&&x(`groups`)},[p.revision]);let[S,ne]=(0,v.useState)(null),[C,w]=(0,v.useState)(``),[T,E]=(0,v.useState)(``),[D,j]=(0,v.useState)(null),[M,N]=(0,v.useState)(Date.now()),[P,F]=(0,v.useState)(null),[ie,I]=(0,v.useState)(``),[L,ae]=(0,v.useState)(``),[oe,R]=(0,v.useState)(``),[z,se]=(0,v.useState)(!1),[B,V]=(0,v.useState)(!0),H=(0,v.useRef)(!1),U=(0,v.useRef)(0),W=(0,v.useRef)(new Set),G=(0,v.useRef)(!1),K=(0,v.useRef)(!1),q=(0,v.useRef)(null),J=(0,v.useRef)(c);J.current=c;async function Y(e,t){let n=new AbortController;W.current.add(n);try{let r=await fetch(d(s(`/api/device-center/${e}`)),{method:t?`POST`:`GET`,credentials:`same-origin`,signal:n.signal,...t?{headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}:{}}),i=await r.json().catch(()=>({}));if(!r.ok)throw new O(r.status,typeof i.error==`string`?i.error:J.current(`deviceHubRequestFailed`,{status:r.status}));return i}finally{W.current.delete(n)}}function X(e){return H.current&&U.current===e}function Z(e){return e instanceof O&&e.status===403?(se(!0),J.current(`deviceHubLocalOnly`)):e instanceof Error?e.message:J.current(`deviceHubNetworkError`)}function Q(e){q.current=e,ne(e),K.current||(E(e.name),w(e.hubUrl??``))}async function ce(){let e=U.current;try{let t=await Y(`status`);if(!X(e)||G.current)return;Q(t),ae(``),se(!1)}catch(t){X(e)&&ae(Z(t))}finally{X(e)&&V(!1)}}(0,v.useEffect)(()=>{H.current=!0;let e=!1,t,n=async()=>{await ce(),!e&&H.current&&(t=setTimeout(n,5e3))};return n(),()=>{e=!0,H.current=!1,U.current++,clearTimeout(t);for(let e of W.current)e.abort()}},[]),(0,v.useEffect)(()=>{if(!D)return;let e=U.current,t=!1,n,r=setInterval(()=>N(Date.now()),1e3),i=async()=>{if(!(t||!X(e)||Date.now()>=D.expiresAt)){try{let n=await Y(`poll`,{});if(t||!X(e))return;if(n.paired){let n=await Y(`status`);if(t||!X(e))return;K.current=!1,Q(n),j(null),I(``),R(``);return}I(``)}catch(n){!t&&X(e)&&I(`${J.current(`deviceHubPollError`)} ${Z(n)}`)}!t&&X(e)&&(n=setTimeout(i,2e3))}};return n=setTimeout(i,2e3),()=>{t=!0,clearTimeout(n),clearInterval(r)}},[D]);async function le(){if(G.current)return;let e=k(C.trim());if(!e){I(c(`deviceHubInvalidUrl`));return}if(!T.trim()||T.trim().length>80){I(c(`deviceHubInvalidName`));return}let t=++U.current;G.current=!0,F(`pair`),I(``),R(``),j(null);try{let n=await Y(`pair`,{hubUrl:e,name:T.trim()});if(!X(t))return;if(!n.code||!Number.isFinite(n.expiresAt)||!k(n.hubUrl))throw Error(c(`deviceHubPairError`));N(Date.now()),j(n)}catch(e){X(t)&&I(`${c(`deviceHubPairError`)} ${Z(e)}`)}finally{X(t)&&(G.current=!1,F(null))}}async function ue(){let e=q.current;if(!e?.deviceId||G.current)return;let t=++U.current;G.current=!0,F(`permission`),I(``),R(``),Q({...e,allowExecution:!e.allowExecution});try{await Y(`execution`,{allowExecution:!e.allowExecution}),X(t)&&R(c(`deviceHubSaved`))}catch(n){X(t)&&(Q(e),I(`${c(`deviceHubPermissionError`)} ${Z(n)}`))}finally{X(t)&&(G.current=!1,F(null))}}async function de(){let e=q.current;if(!e?.deviceId||G.current||!window.confirm(c(`deviceHubDisconnectConfirm`,{name:e.name})))return;let t=++U.current;G.current=!0,F(`disconnect`),I(``),R(``);try{if(await Y(`disconnect`,{}),!X(t))return;K.current=!1,Q({name:e.name,allowExecution:!1,connected:!1}),j(null)}catch(e){X(t)&&I(`${c(`deviceHubDisconnectError`)} ${Z(e)}`)}finally{X(t)&&(G.current=!1,F(null))}}async function fe(){if(!D)return;let e=U.current;try{await navigator.clipboard.writeText(D.code),X(e)&&R(c(`deviceHubCopied`))}catch{X(e)&&I(c(`deviceHubCopyFailed`))}}let $=!!S?.deviceId,pe=k($?S?.hubUrl??``:D?.hubUrl??``),me=Math.max(0,Math.ceil(((D?.expiresAt??0)-M)/1e3)),he=`${Math.floor(me/60)}:${String(me%60).padStart(2,`0`)}`,ge=pe?(0,y.jsxs)(b,{href:pe,children:[(0,y.jsx)(t,{"aria-hidden":!0}),c(`deviceHubOpenHub`)]}):null;return(0,y.jsxs)(`section`,{className:`dc-page`,"aria-label":c(`deviceHubTitle`),children:[(0,y.jsxs)(`header`,{className:`dc-header`,children:[(0,y.jsxs)(`div`,{className:`dc-heading`,children:[(0,y.jsxs)(`span`,{className:`dc-eyebrow`,children:[(0,y.jsx)(f,{"aria-hidden":!0}),c(`deviceHubTitle`)]}),(0,y.jsx)(`h1`,{children:c(`deviceHubTitle`)}),(0,y.jsx)(`p`,{children:c(`deviceHubSubtitle`)})]}),(0,y.jsxs)(`div`,{className:`dc-actions`,children:[$&&ge,(0,y.jsxs)(`span`,{className:`dc-status ${$?S?.connected?`is-online`:`is-offline`:`is-unpaired`}`,children:[(0,y.jsx)(`span`,{className:`dc-status-dot`}),c($?S?.connected?`deviceHubOnline`:`deviceHubOffline`:`deviceHubUnpaired`)]})]})]}),(0,y.jsxs)(`div`,{className:`dc-layout`,children:[(0,y.jsxs)(`nav`,{className:`dc-sidebar`,"aria-label":c(`deviceHubTitle`),children:[(0,y.jsxs)(`button`,{type:`button`,className:`dc-nav-item${m===`overview`?` is-active`:``}`,"aria-current":m===`overview`?`page`:void 0,onClick:()=>x(`overview`),children:[(0,y.jsx)(f,{"aria-hidden":!0}),c(`deviceHubOverview`)]}),(0,y.jsxs)(`button`,{type:`button`,className:`dc-nav-item${m===`groups`?` is-active`:``}`,"aria-current":m===`groups`?`page`:void 0,onClick:()=>x(`groups`),children:[(0,y.jsx)(ee,{"aria-hidden":!0}),c(`deviceHubGroups`)]}),(0,y.jsxs)(`button`,{type:`button`,className:`dc-nav-item${m===`settings`?` is-active`:``}`,"aria-current":m===`settings`?`page`:void 0,onClick:()=>x(`settings`),children:[(0,y.jsx)(u,{"aria-hidden":!0}),c(`deviceHubSettings`)]})]}),(0,y.jsxs)(`main`,{className:`dc-content`,children:[B&&(0,y.jsxs)(`div`,{className:`dc-loading`,role:`status`,children:[(0,y.jsx)(r,{"aria-hidden":!0}),c(`deviceHubLoading`)]}),(z||L)&&(0,y.jsxs)(`div`,{className:`dc-notice is-error`,role:`alert`,children:[(0,y.jsx)(`span`,{children:z?c(`deviceHubLocalOnly`):`${c(`deviceHubStatusError`)} ${L}`}),(0,y.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>void ce(),children:[(0,y.jsx)(r,{"aria-hidden":!0}),c(`deviceHubRetry`)]})]}),ie&&!z&&(0,y.jsx)(`div`,{className:`dc-notice is-error`,role:`alert`,children:ie}),oe&&(0,y.jsxs)(`div`,{className:`dc-notice is-success`,role:`status`,children:[(0,y.jsx)(i,{"aria-hidden":!0}),oe]}),!$&&(S||z)&&m===`overview`&&(0,y.jsx)(re,{initialHubUrl:C,onConnect:e=>{if(z){R(c(`deviceHubLocalOnly`));return}K.current=!0,w(e),x(`settings`)}}),!z&&m===`overview`&&(0,y.jsxs)(`section`,{className:`dc-card`,children:[(0,y.jsx)(`h3`,{children:c(`deviceSetupNext`)}),(0,y.jsx)(`p`,{children:c(`deviceSetupNextHint`)}),(0,y.jsx)(`button`,{className:`dc-button is-primary`,onClick:()=>x(`groups`),children:c(`deviceSetupManage`)})]}),m===`settings`&&(0,y.jsx)(A,{}),S&&!z&&!$&&m===`settings`&&(0,y.jsxs)(`section`,{className:`dc-card`,children:[(0,y.jsxs)(`div`,{className:`dc-card-header`,children:[(0,y.jsx)(`span`,{className:`dc-icon`,children:(0,y.jsx)(u,{"aria-hidden":!0})}),(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`h2`,{children:c(`deviceHubPairTitle`)}),(0,y.jsx)(`p`,{children:c(`deviceHubPairHint`)})]})]}),(0,y.jsx)(`ol`,{className:`dc-steps`,children:[`deviceHubStepDetails`,`deviceHubStepApprove`,`deviceHubStepWait`].map((e,t)=>(0,y.jsxs)(`li`,{className:D?t===0?`is-complete`:`is-active`:t===0?`is-active`:``,children:[(0,y.jsx)(`span`,{className:`dc-step-number`,children:D&&t===0?(0,y.jsx)(i,{"aria-hidden":!0}):t+1}),(0,y.jsx)(`span`,{children:c(e)})]},e))}),(0,y.jsxs)(`form`,{className:`dc-form`,onSubmit:e=>{e.preventDefault(),le()},children:[(0,y.jsxs)(`div`,{className:`dc-field`,children:[(0,y.jsx)(`label`,{htmlFor:`dc-hub-url`,children:c(`deviceHubHubUrl`)}),(0,y.jsx)(`input`,{id:`dc-hub-url`,type:`url`,autoComplete:`url`,required:!0,placeholder:c(`deviceHubHubPlaceholder`),value:C,disabled:!!D||!!P,onChange:e=>{K.current=!0,w(e.target.value)}})]}),(0,y.jsxs)(`div`,{className:`dc-field`,children:[(0,y.jsx)(`label`,{htmlFor:`dc-device-name`,children:c(`deviceHubName`)}),(0,y.jsx)(`input`,{id:`dc-device-name`,maxLength:80,required:!0,autoComplete:`off`,placeholder:c(`deviceHubNamePlaceholder`),value:T,disabled:!!D||!!P,onChange:e=>{K.current=!0,E(e.target.value)}})]}),!D&&(0,y.jsx)(`div`,{className:`dc-actions`,children:(0,y.jsxs)(`button`,{className:`dc-button is-primary`,type:`submit`,disabled:!!P,children:[(0,y.jsx)(u,{"aria-hidden":!0}),c(P?`deviceHubWorking`:`deviceHubGetCode`)]})})]}),D&&(0,y.jsxs)(`div`,{className:`dc-pairing`,children:[(0,y.jsx)(`span`,{className:`dc-code-label`,children:c(`deviceHubCode`)}),(0,y.jsxs)(`div`,{className:`dc-code-row`,children:[(0,y.jsx)(`code`,{className:`dc-code`,children:D.code}),(0,y.jsx)(`button`,{className:`dc-icon-button`,type:`button`,"aria-label":c(`deviceHubCopy`),onClick:()=>void fe(),children:(0,y.jsx)(l,{"aria-hidden":!0})})]}),(0,y.jsx)(`div`,{className:`dc-pair-meta`,children:c(me?`deviceHubExpires`:`deviceHubExpired`,{time:he})}),(0,y.jsxs)(`div`,{className:`dc-actions`,children:[ge,(0,y.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:!!P,onClick:()=>{++U.current,j(null),I(``),R(``)},children:[(0,y.jsx)(r,{"aria-hidden":!0}),c(`deviceHubNewCode`)]})]}),me>0&&(0,y.jsxs)(`p`,{className:`dc-progress`,role:`status`,children:[(0,y.jsx)(r,{"aria-hidden":!0}),c(`deviceHubWaiting`)]})]})]}),$&&S&&!z&&(0,y.jsxs)(y.Fragment,{children:[m===`overview`&&(0,y.jsxs)(`section`,{className:`dc-card`,children:[(0,y.jsxs)(`div`,{className:`dc-device-summary`,children:[(0,y.jsx)(`span`,{className:`dc-device-icon`,children:(0,y.jsx)(f,{"aria-hidden":!0})}),(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`h2`,{children:S.name}),(0,y.jsx)(`p`,{children:c(`deviceHubDeviceTitle`)})]})]}),(0,y.jsxs)(`dl`,{className:`dc-details`,children:[(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`dt`,{children:c(`deviceHubDeviceId`)}),(0,y.jsx)(`dd`,{children:S.deviceId})]}),(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`dt`,{children:c(`deviceHubHubUrl`)}),(0,y.jsx)(`dd`,{children:S.hubUrl})]})]})]}),m===`settings`&&(0,y.jsxs)(`section`,{className:`dc-card`,children:[(0,y.jsxs)(`div`,{className:`dc-card-header`,children:[(0,y.jsx)(`span`,{className:`dc-icon`,children:(0,y.jsx)(n,{"aria-hidden":!0})}),(0,y.jsx)(`div`,{children:(0,y.jsx)(`h2`,{children:c(`deviceHubPermissions`)})})]}),(0,y.jsxs)(`div`,{className:`dc-permission-row`,children:[(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`h3`,{id:`dc-permission-label`,children:c(`deviceHubPermissionLabel`)}),(0,y.jsx)(`p`,{id:`dc-permission-hint`,children:c(`deviceHubPermissionHint`)})]}),(0,y.jsx)(`button`,{type:`button`,className:`dc-toggle${S.allowExecution?` is-on`:``}`,role:`switch`,"aria-checked":S.allowExecution,"aria-labelledby":`dc-permission-label`,"aria-describedby":`dc-permission-hint`,disabled:!!P,onClick:()=>void ue(),children:(0,y.jsx)(`span`,{className:`dc-toggle-thumb`})})]}),(0,y.jsx)(`p`,{className:`dc-permission-state`,role:`status`,children:c(P===`permission`?`deviceHubSaving`:S.allowExecution?`deviceHubEnabled`:`deviceHubReadOnly`)})]}),m===`settings`&&(0,y.jsxs)(`details`,{className:`dc-advanced`,children:[(0,y.jsx)(`summary`,{children:c(`deviceHubAdvanced`)}),(0,y.jsxs)(`div`,{className:`dc-danger-zone`,children:[(0,y.jsx)(`h3`,{children:c(`deviceHubDisconnect`)}),(0,y.jsx)(`p`,{children:c(`deviceHubDisconnectHint`)}),(0,y.jsx)(`button`,{type:`button`,className:`dc-button is-danger`,disabled:!!P,onClick:()=>void de(),children:c(P===`disconnect`?`deviceHubWorking`:`deviceHubDisconnect`)})]})]})]}),$&&S?.hubUrl&&S.deviceId&&!z&&m!==`groups`&&(0,y.jsx)(g,{hubUrl:S.hubUrl,currentDeviceId:S.deviceId},`directory:${S.hubUrl}:${S.deviceId}`),!z&&(m===`settings`||m===`groups`)&&(0,y.jsx)(te,{pathCompletions:e},`bots:${S?.hubUrl??``}:${S?.deviceId??`unpaired`}`),m===`groups`&&(0,y.jsx)(_,{navigation:p}),(0,y.jsxs)(`aside`,{className:`dc-help`,children:[(0,y.jsx)(o,{className:`dc-help-icon`,"aria-hidden":!0}),(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`h3`,{children:c(`deviceHubHelpTitle`)}),(0,y.jsx)(`p`,{children:c(`deviceHubHelpText`)})]})]})]})]})]})}export{j as DeviceCenter};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{cn as t,fn as n,mt as r,qt as i,rn as a,un as o,wt as s,yt as c}from"./fi-DaSO0Q-m.js";import{i as l,r as u,t as d}from"./react-CR5VJ85Q.js";import{t as f}from"./shortcut-stack-hhrDyRBn.js";var p=e(l(),1),m=u(),h=d(),g={zh:{groups:`群聊`,manage:`管理成员`,save:`保存成员`,create:`建群`,name:`群名称`,devices:`选择 Bot(设备仅承载 Bot)`,empty:`还没有群聊,创建一个群开始协作。`,choose:`选择一个群聊`,open:`打开聊天`,online:`在线`,offline:`离线`,cancel:`取消`,loading:`加载中…`,rebind:`设备绑定已失效或已解除,请在设备设置中重新绑定。`,forbidden:`本机访问被拒绝,请检查本机登录状态与访问权限。`,failed:`请求失败`},en:{groups:`Groups`,manage:`Manage members`,save:`Save members`,create:`Create group`,name:`Group name`,devices:`Select Bots (devices host Bots)`,empty:`No groups yet. Create a group to collaborate.`,choose:`Select a group`,open:`Open chat`,online:`Online`,offline:`Offline`,cancel:`Cancel`,loading:`Loading…`,rebind:`The device binding has expired or was removed. Bind again in device settings.`,forbidden:`Local access denied. Check your local sign-in and access permissions.`,failed:`Request failed`}},_=class extends Error{status;code;constructor(e,t,n){super(n),this.status=e,this.code=t}};async function v(e,t,r){let i=await fetch(o(n(`/api/device-center/${e}`)),{method:r?`POST`:`GET`,credentials:`same-origin`,signal:t,...r?{headers:{"Content-Type":`application/json`},body:JSON.stringify(r)}:{}}),a=await i.json().catch(()=>({}));if(!i.ok)throw new _(i.status,a.code??``,typeof a.error==`string`?a.error:String(i.status));return a}function y(e){window.dispatchEvent(new CustomEvent(`pi-web-ui:device-group-open`,{detail:{roomId:e}}))}function b({onClose:e}){let{locale:n}=a(),r=g[t(n)?`zh`:`en`];return f(e),(0,m.createPortal)((0,h.jsx)(`div`,{className:`modal-backdrop`,onClick:e,children:(0,h.jsx)(`div`,{className:`device-group-create-dialog`,role:`dialog`,"aria-modal":`true`,"aria-label":r.create,onClick:e=>e.stopPropagation(),children:(0,h.jsx)(x,{createOnly:!0,onClose:e})})}),document.body)}function x({active:e=!0,navigation:n,createOnly:o=!1,onClose:l}){let{locale:u}=a(),d=g[t(u)?`zh`:`en`],[f,m]=(0,p.useState)([]),[b,x]=(0,p.useState)([]),[S,C]=(0,p.useState)(``),[w,T]=(0,p.useState)(null),[E,D]=(0,p.useState)(!0),[O,k]=(0,p.useState)(``),[A,j]=(0,p.useState)(o),[M,N]=(0,p.useState)(!1),[P,F]=(0,p.useState)(``),[I,L]=(0,p.useState)([]),[R,z]=(0,p.useState)(!1),[B,V]=(0,p.useState)(0),H=(0,p.useRef)(null),U=(0,p.useRef)(void 0),W=(0,p.useRef)(0),G=(0,p.useRef)(null),K=(0,p.useRef)(d);K.current=d;function q(e){let t=K.current;if(e instanceof _){if(e.status===409&&/^(REPAIR_REQUIRED|NOT_PAIRED|DEVICE_CHANGED)$/.test(e.code)||e.status===403&&/binding|credential|unpaired|revoked|not_bound|hub_forbidden/i.test(e.code))return t.rebind;if(e.status===403)return t.forbidden}return`${t.failed}: ${e instanceof Error?e.message:String(e)}`}function J(){G.current?.abort(),G.current=null,z(!1)}function Y(e,t=!1){++W.current,J(),C(e),T(null),j(!1),N(t),H.current=t?e:null,L([]),D(!0),k(``),V(e=>e+1)}function X(){++W.current,J(),j(!0),N(!1),H.current=null,T(null),L([]),F(``),k(``),V(e=>e+1)}(0,p.useEffect)(()=>{let t=++W.current,n=null,r=!1,i=()=>W.current===t;async function a(){if(!e||document.visibilityState===`hidden`||r)return;r=!0;let t=new AbortController;n=t;try{let[e,n,r]=await Promise.all([v(`bots`,t.signal),v(`rooms`,t.signal),M&&S?v(`rooms/${encodeURIComponent(S)}`,t.signal):Promise.resolve(null)]);if(!i()||t.signal.aborted)return;m(e.bots),x(n.rooms),T(r),r&&H.current===r.room.id&&(H.current=null,L(r.room.botIds)),k(``)}catch(e){i()&&!t.signal.aborted&&k(q(e))}finally{t.abort(),r=!1,i()&&D(!1)}}a();let o=window.setInterval(()=>void a(),3e3),s=()=>{document.visibilityState===`hidden`?n?.abort():a()};return document.addEventListener(`visibilitychange`,s),()=>{++W.current,n?.abort(),clearInterval(o),document.removeEventListener(`visibilitychange`,s)}},[e,S,M,B]),(0,p.useEffect)(()=>()=>G.current?.abort(),[]),(0,p.useEffect)(()=>{e||J()},[e]),(0,p.useEffect)(()=>{e&&n&&n.revision!==U.current&&(U.current=n.revision,n.create?X():n.roomId&&Y(n.roomId,n.manage))},[e,n?.revision]);async function Z(){if(!e||G.current||(A?!P.trim():!w))return;let t=new AbortController;G.current=t,z(!0),k(``);let n=A,r=w?.room.id;try{let{room:e}=await v(n?`rooms`:`rooms/${encodeURIComponent(r)}/members`,t.signal,n?{name:P.trim(),botIds:I}:{botIds:I});if(t.signal.aborted||G.current!==t)return;x(t=>[...t.filter(t=>t.id!==e.id),e]),C(e.id),T({room:e}),j(!1),N(!1),F(``),L([]),V(e=>e+1),window.dispatchEvent(new CustomEvent(`pi-web-ui:device-groups-changed`)),n&&(y(e.id),o&&l?.())}catch(e){!t.signal.aborted&&G.current===t&&k(q(e))}finally{G.current===t&&(G.current=null,z(!1))}}let Q=b.find(e=>e.id===S);return(0,h.jsxs)(`section`,{className:`dg-root`,"aria-label":d.groups,children:[!o&&(0,h.jsxs)(`div`,{className:`dc-card dg-sidebar`,children:[(0,h.jsxs)(`div`,{className:`dg-heading`,children:[(0,h.jsxs)(`h2`,{children:[(0,h.jsx)(i,{}),` `,d.groups]}),(0,h.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:X,children:[(0,h.jsx)(s,{}),` `,d.create]})]}),(0,h.jsx)(`div`,{className:`dg-rooms`,children:b.map(t=>(0,h.jsxs)(`button`,{className:`dc-button dg-room`,type:`button`,"aria-current":t.id===S?`page`:void 0,disabled:!e,onClick:()=>{Y(t.id),y(t.id)},children:[(0,h.jsx)(r,{}),` `,t.name]},t.id))}),!E&&!b.length&&(0,h.jsx)(`p`,{className:`dg-empty`,children:d.empty})]}),(0,h.jsxs)(`div`,{className:`dc-card dg-chat`,children:[O&&(0,h.jsx)(`p`,{className:`dc-error`,role:`alert`,children:O}),E&&(0,h.jsx)(`p`,{role:`status`,children:d.loading}),A||M?(0,h.jsxs)(`form`,{className:`dg-create`,onSubmit:e=>{e.preventDefault(),Z()},children:[(0,h.jsx)(`h2`,{children:A?d.create:d.manage}),A&&(0,h.jsxs)(`div`,{className:`dc-field`,children:[(0,h.jsx)(`label`,{htmlFor:`device-group-name`,children:d.name}),(0,h.jsx)(`input`,{id:`device-group-name`,value:P,onChange:e=>F(e.target.value),disabled:R||!e})]}),(0,h.jsxs)(`fieldset`,{disabled:R||!e||M&&!w,children:[(0,h.jsx)(`legend`,{children:d.devices}),f.map(e=>(0,h.jsxs)(`label`,{className:`dg-device`,children:[(0,h.jsx)(`input`,{type:`checkbox`,disabled:!e.enabled&&!I.includes(e.id),checked:I.includes(e.id),onChange:t=>L(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}),(0,h.jsx)(c,{}),(0,h.jsxs)(`span`,{children:[e.name,` · `,e.id,` · `,e.deviceId,` · `,e.online?d.online:d.offline]})]},e.id))]}),(0,h.jsxs)(`div`,{className:`dc-actions`,children:[(0,h.jsx)(`button`,{className:`dc-button`,type:`submit`,disabled:R||!e||(A?!P.trim():!w),children:A?d.create:d.save}),(0,h.jsx)(`button`,{className:`dc-button`,type:`button`,onClick:()=>{J(),H.current=null,o&&l?.(),j(!1),N(!1),k(``)},children:d.cancel})]})]}):Q?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`div`,{className:`dg-title`,children:(0,h.jsxs)(`h2`,{children:[(0,h.jsx)(i,{}),` `,Q.name]})}),(0,h.jsxs)(`div`,{className:`dc-actions`,children:[(0,h.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:()=>y(Q.id),children:[(0,h.jsx)(r,{}),d.open]}),(0,h.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:()=>Y(Q.id,!0),children:[(0,h.jsx)(i,{}),d.manage]})]})]}):(0,h.jsx)(`p`,{className:`dg-empty`,children:d.choose})]})]})}export{b as DeviceGroupCreateDialog,x as DeviceGroups};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{b as t}from"./fi-DaSO0Q-m.js";import{i as n,r,t as i}from"./react-CR5VJ85Q.js";import{t as a}from"./shortcut-stack-hhrDyRBn.js";var o=r(),s=e(n(),1);function c(e,t,n={}){let{enabled:r=!0,ignore:i}=n,a=(0,s.useRef)(t);(0,s.useLayoutEffect)(()=>{a.current=t}),(0,s.useEffect)(()=>{if(!r)return;let t=(e,t)=>{if(!t)return!1;let n=`current`in t?t.current:t;return n?n.contains(e):!1},n=n=>{let r=n.target;r instanceof Node&&(e.current?.contains(r)||i&&(Array.isArray(i)?i:[i]).some(e=>t(r,e))||a.current(n))};return document.addEventListener(`mousedown`,n),document.addEventListener(`touchstart`,n),()=>{document.removeEventListener(`mousedown`,n),document.removeEventListener(`touchstart`,n)}},[r,e,i])}var l=i();function u({align:e,triggerLeft:t,triggerRight:n,menuWidth:r,viewportWidth:i,margin:a=8}){if(r<=0||i<=0)return 0;let o=e===`left`?t:n-r,s=Math.max(a,i-a-r);return Math.round(Math.max(a,Math.min(o,s))-o)}function d({triggerRect:e,menuWidth:t,menuHeight:n,viewportWidth:r,viewportHeight:i,direction:a=`down`,align:o=`right`,gap:s=6,margin:c=8}){if(t<=0||r<=0||i<=0)return{left:Math.round(e.left),top:Math.round(e.bottom+s)};let l=Math.max(c,r-c-t),u=Math.max(c,i-c-n),d=c,f=c,p,m=Math.max(0,e.top-s-c),h=Math.max(0,i-e.bottom-s-c);if(a===`right`)d=e.right+s,d+t>r-c&&e.left-t-s>=c&&(d=e.left-t-s),d=Math.max(c,Math.min(d,l)),f=e.top,f+n>i-c&&(f=i-c-n),f=Math.max(c,Math.min(f,u)),p=Math.max(0,i-2*c);else if(a===`left`)d=e.left-t-s,d<c&&e.right+s+t<=r-c&&(d=e.right+s),d=Math.max(c,Math.min(d,l)),f=e.top,f+n>i-c&&(f=i-c-n),f=Math.max(c,Math.min(f,u)),p=Math.max(0,i-2*c);else if(a===`up`){m>=n?(f=e.top-n-s,p=m):h>=n||h>m?(f=e.bottom+s,p=h):(p=m,f=e.top-Math.min(n,m)-s);let r=Math.max(c,i-c-Math.min(n,p));f=Math.max(c,Math.min(f,r));let a=o===`left`?e.left:e.right-t;d=Math.max(c,Math.min(a,l))}else{h>=n?(f=e.bottom+s,p=h):m>=n?(f=e.top-n-s,p=m):m>h?(f=e.top-Math.min(n,m)-s,p=m):(f=e.bottom+s,p=h);let r=Math.max(c,i-c-Math.min(n,p));f=Math.max(c,Math.min(f,r));let a=o===`left`?e.left:e.right-t;d=Math.max(c,Math.min(a,l))}return{left:Math.round(d),top:Math.round(f),...p===void 0?{}:{maxHeight:Math.round(p)}}}function f({trigger:e,open:n,onOpenChange:r,children:i,align:f=`right`,fit:p=!1,direction:m=`down`,portal:h=!1,tip:g,caret:_=!0,menuClassName:v,triggerClassName:y,onContextMenu:b,dataBarItem:x,menuRef:S,menuStyle:C,className:w}){let T=(0,s.useRef)(null),E=(0,s.useRef)(null),[D,O]=(0,s.useState)(0),[k,A]=(0,s.useState)(null),j=e=>{E.current=e,typeof S==`function`?S(e):S&&`current`in S&&(S.current=e)},M=()=>{let e=T.current,t=E.current;if(!e||!t)return;if(window.innerWidth<=768){D!==0&&O(0);return}let n=t.getBoundingClientRect(),r=e.getBoundingClientRect();if(r.width===0&&r.height===0||n.width===0){D!==0&&O(0);return}if(h){let e=d({triggerRect:r,menuWidth:n.width,menuHeight:n.height,viewportWidth:window.innerWidth,viewportHeight:window.innerHeight,direction:m,align:f,gap:6,margin:8});A(t=>t?.left===e.left&&t?.top===e.top&&t?.maxHeight===e.maxHeight?t:e)}else{let e=n.width,t=u({align:f,triggerLeft:r.left,triggerRight:r.right,menuWidth:e,viewportWidth:window.innerWidth,margin:8});t!==D&&O(t)}};(0,s.useLayoutEffect)(()=>{n?M():(D!==0&&O(0),k!==null&&A(null))}),(0,s.useEffect)(()=>{if(n)return window.addEventListener(`resize`,M),h&&window.addEventListener(`scroll`,M,!0),()=>{window.removeEventListener(`resize`,M),h&&window.removeEventListener(`scroll`,M,!0)}},[n,D,h,m,f]),c(T,()=>r(!1),{enabled:n,ignore:E}),a(()=>r(!1),n);let N=typeof window<`u`&&window.innerWidth<=768?{...C,pointerEvents:`auto`}:{...C,position:`fixed`,left:k?`${k.left}px`:`-9999px`,top:k?`${k.top}px`:`-9999px`,maxHeight:k?.maxHeight==null?C?.maxHeight:C?.maxHeight==null?`${k.maxHeight}px`:`min(${k.maxHeight}px, ${C.maxHeight})`,right:`auto`,bottom:`auto`,pointerEvents:`auto`,visibility:k?`visible`:`hidden`},P=k!=null&&T.current?k.top<T.current.getBoundingClientRect().top:m===`up`;return(0,l.jsxs)(`div`,{className:`dropdown ${f} ${p?`fit`:``} ${m===`up`?`dd-up`:``} ${w??``}`.trim(),ref:T,children:[(0,l.jsxs)(`button`,{type:`button`,className:y??`chip`,onClick:()=>r(!n),onContextMenu:b,"aria-expanded":n,"data-tip":g,"data-bar-item":x,children:[e,_&&(0,l.jsx)(t,{className:`dd-caret ${n?`up`:``}`})]}),n&&(h?(0,o.createPortal)((0,l.jsx)(`div`,{className:`dd-portal-wrapper dropdown ${f} ${p?`fit`:``} ${P?`dd-up`:``}`,style:{position:`fixed`,left:0,top:0,width:`100%`,height:`100%`,pointerEvents:`none`,zIndex:9999},children:(0,l.jsx)(`div`,{className:`dd-menu ${v??``}`,ref:j,style:N,onPointerDown:e=>e.stopPropagation(),onMouseDown:e=>e.stopPropagation(),onWheel:e=>e.stopPropagation(),children:i})}),document.body):(0,l.jsx)(`div`,{className:`dd-menu ${v??``}`,ref:j,onPointerDown:e=>e.stopPropagation(),onMouseDown:e=>e.stopPropagation(),onWheel:e=>e.stopPropagation(),style:D===0?C:{...C,transform:C?.transform?`${C.transform} translateX(${D}px)`:`translateX(${D}px)`},children:i}))]})}function p({active:e,disabled:t=!1,title:n,onClick:r,children:i}){return(0,l.jsx)(`button`,{type:`button`,className:`dd-item ${e?`active`:``}`,disabled:t,title:n,onClick:r,children:i})}export{p as n,f as t};
@@ -1,2 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{A as t,B as n,D as r,Dt as i,L as a,Qt as ee,V as te,Yt as ne,Zt as re,_ as ie,an as ae,ct as oe,dt as se,fn as ce,gt as le,st as ue,un as de,z as fe}from"./fi-DaSO0Q-m.js";import{i as o,t as s}from"./react-CR5VJ85Q.js";import{t as pe}from"./app-globals-DcyO0UPi.js";import{K as me,U as he,ct as ge,dt as _e,pt as ve}from"./index-DWw_SxRq.js";var c=e(o(),1),l=`未命名章节`;function u(e){return String(e??``).trim().replace(/[\s\u3000]+/g,`-`).replace(/[^\p{L}\p{N}_-]+/gu,`-`).replace(/-{2,}/g,`-`).replace(/^-+|-+$/g,``).slice(0,80)||`section`}function ye(e){let t=new Map;return e.map(({level:e,label:n})=>{let r=String(n??``).replace(/\s+/g,` `).trim(),i=u(r||l),a=(t.get(i)??0)+1;return t.set(i,a),{level:e,id:a===1?i:`${i}-${a}`,label:r||l}})}function d(e){return e.length>=2}var f=s(),p=5e3,be=`pi-web-ui:preview-toc`;function m({file:e,content:o,onAddLines:s,onAttach:l,onClose:u,uiFilePreviewToolbar:m,onUiAction:xe}){let v=ae(),[y,Se]=(0,c.useState)(null),[b,Ce]=(0,c.useState)(!1),[x,S]=(0,c.useState)(null),[we,Te]=(0,c.useState)(!1),[Ee,De]=(0,c.useState)(!1),[C,w]=(0,c.useState)(!1),[T,E]=(0,c.useState)(``),[D,O]=(0,c.useState)(!0),[k,A]=(0,c.useState)(!0),[j,Oe]=(0,c.useState)(!1),M=(0,c.useRef)(!1),[N,ke]=(0,c.useState)(!0),[P,Ae]=(0,c.useState)(!1),[F,je]=(0,c.useState)(100),I=(0,c.useRef)(0),L=(0,c.useRef)(!1),R=(0,c.useRef)(null),[Me,z]=(0,c.useState)(!1),[Ne,B]=(0,c.useState)(!1),V=(0,c.useRef)(!1),H=(0,c.useRef)(null);(0,c.useEffect)(()=>()=>{R.current&&clearTimeout(R.current),H.current&&clearTimeout(H.current)},[]),(0,c.useEffect)(()=>{Ce(!0),Se(null),S(null),w(!1),E(``),O(!0),A(!0),Oe(!1),M.current=!1,V.current=!1,z(!1),B(!1),H.current&&clearTimeout(H.current),pe({type:`read_file`,path:e.path})},[e.path]),(0,c.useEffect)(()=>{o&&o.path===e.path&&(Se(o),C||E(o.text),Ce(!1),V.current&&(V.current=!1,H.current&&clearTimeout(H.current),z(!1),B(!1),w(!1),E(o.text),M.current&&(h(e.name)&&O(!0),_(e.name)&&A(!0)),S(null)))},[o,C,e.path]),(0,c.useEffect)(()=>{let e=e=>{if(e.key===`Escape`){G();return}if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`s`&&C){e.preventDefault(),Ve();return}let t=e.target,n=t&&(t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.isContentEditable);(e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`a`&&!n&&(e.preventDefault(),Le())};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[u,y,C,T]),(0,c.useEffect)(()=>{let e=()=>{L.current=!1,Te(!1)};return window.addEventListener(`mouseup`,e),()=>window.removeEventListener(`mouseup`,e)},[]);let U=(0,c.useMemo)(()=>{if(!y)return[];let e=y.text.split(`
2
- `);return e.length>0&&e[e.length-1]===``&&e.pop(),e.slice(0,p)},[y]),Pe=y?.lines??0,Fe=Pe>p,Ie=(e,t)=>{if(t){let t=I.current>0?I.current:e;S({start:Math.min(t,e),end:Math.max(t,e)})}else I.current=e,S({start:e,end:e})},Le=()=>{U.length!==0&&(I.current=1,S({start:1,end:U.length}))},Re=()=>{x&&(s(e.path,e.name,x.start,x.end),De(!0),R.current&&clearTimeout(R.current),R.current=setTimeout(()=>De(!1),1400))},W=y!==null&&y.kind===`text`&&!y.binary&&!y.truncated&&!g(e.name),ze=()=>{V.current=!1,H.current&&clearTimeout(H.current),z(!1),B(!1),E(y?.text??``),w(!1),M.current&&(h(e.name)&&O(!0),_(e.name)&&A(!0))},Be=()=>{if(C){if(T!==(y?.text??``)&&!window.confirm(v(`discardFileChanges`)))return;ze();return}W&&y&&(M.current=h(e.name)&&D||_(e.name)&&k,h(e.name)&&O(!1),_(e.name)&&A(!1),S(null),E(y.text),w(!0))},Ve=()=>{C&&y&&W&&pe({type:`write_file`,path:e.path,text:T})&&(V.current=!0,B(!1),z(!0),H.current&&clearTimeout(H.current),H.current=setTimeout(()=>{V.current=!1,z(!1),B(!0)},5e3))},G=()=>{(!C||T===(y?.text??``)||window.confirm(v(`discardFileChanges`)))&&u()},He=e=>{je(Math.min(200,Math.max(50,e)))},Ue=x?x.end-x.start+1:0,K=y?.binary??!1,We=y?.truncated??!1,q=y?.kind??`text`,Ge=h(e.name)||g(e.name),Ke=_(e.name),qe=g(e.name),J=Ge&&D&&!C&&q===`text`&&!K,Y=Ke&&k&&!C&&q===`text`&&!K,[X,Je]=(0,c.useState)(()=>{try{return localStorage.getItem(be)===`1`}catch{return!1}});(0,c.useEffect)(()=>{try{localStorage.setItem(be,X?`1`:`0`)}catch{}},[X]);let[Z,Ye]=(0,c.useState)([]),[Xe,Ze]=(0,c.useState)(``),Q=(0,c.useRef)(null);(0,c.useEffect)(()=>{let e=Q.current;if(!e||!J){Ye([]);return}let t=[...e.querySelectorAll(`h1, h2, h3, h4, h5, h6`)],n=ye(t.map(e=>({level:Number(e.tagName.slice(1)),label:e.textContent??``})));t.forEach((e,t)=>{e.id||=n[t].id}),Ye(n)},[J,y?.text,e.path]),(0,c.useEffect)(()=>{let e=Q.current;if(!e||!X||!d(Z))return;let t=Z.map(t=>e.querySelector(`#${CSS.escape(t.id)}`)).filter(e=>e!==null);if(t.length===0)return;let n=new IntersectionObserver(e=>{let t=e.filter(e=>e.isIntersecting).sort((e,t)=>e.boundingClientRect.top-t.boundingClientRect.top)[0];t?.target.id&&Ze(t.target.id)},{rootMargin:`0px 0px -70% 0px`});for(let e of t)n.observe(e);return()=>n.disconnect()},[Z,X]);let Qe={"host:fp-md":Ge&&q===`text`&&!K&&y?(0,f.jsx)(`button`,{type:`button`,className:`fp-attach markdown ${D?`on`:``}`,"data-tip":v(D?`showMarkdownSource`:`showMarkdownPreview`),disabled:C,onClick:()=>O(e=>!e),children:D?(0,f.jsx)(te,{}):(0,f.jsx)(r,{})}):null,"host:fp-toc":J&&d(Z)?(0,f.jsx)(`button`,{type:`button`,className:`fp-attach toc ${X?`on`:``}`,"data-tip":v(X?`previewTocHide`:`previewTocShow`),onClick:()=>Je(e=>!e),children:(0,f.jsx)(oe,{})}):null,"host:fp-html":Ke&&q===`text`&&!K&&y?(0,f.jsx)(`button`,{type:`button`,className:`fp-attach html ${k?`on`:``}`,"data-tip":v(k?`showHtmlSource`:`showHtmlPreview`),disabled:C,onClick:()=>A(e=>!e),children:k?(0,f.jsx)(r,{}):(0,f.jsx)(te,{})}):null,"host:fp-edit":q===`text`&&!K&&y?(0,f.jsx)(`button`,{type:`button`,className:`fp-attach edit ${C?`on`:``}`,"data-tip":v(We?`fileEditTruncated`:C?`exitEditFile`:`editFile`),disabled:!W&&!C,onClick:Be,children:(0,f.jsx)(fe,{})}):null,"host:fp-wrap":q===`text`&&!K&&!J&&!Y?(0,f.jsx)(`button`,{type:`button`,className:`fp-attach wrap ${N?`on`:``}`,"data-tip":v(N?`disableWrap`:`enableWrap`),onClick:()=>ke(e=>!e),children:(0,f.jsx)(t,{})}):null,"host:fp-zoom":q===`text`&&y?(0,f.jsxs)(`span`,{className:`fp-zoom`,children:[(0,f.jsx)(`button`,{type:`button`,className:`fp-attach zoom-out`,"data-tip":v(`zoomOut`),disabled:F<=50,onClick:()=>He(F-10),children:(0,f.jsx)(ee,{})}),(0,f.jsxs)(`button`,{type:`button`,className:`fp-zoom-val`,title:v(`resetZoom`),onClick:()=>je(100),children:[F,`%`]}),(0,f.jsx)(`button`,{type:`button`,className:`fp-attach zoom-in`,"data-tip":v(`zoomIn`),disabled:F>=200,onClick:()=>He(F+10),children:(0,f.jsx)(re,{})})]}):null,"host:fp-download":(0,f.jsx)(`button`,{type:`button`,className:`fp-attach download`,"data-tip":v(`downloadFile`),onClick:()=>void _e(e.path,e.name),children:(0,f.jsx)(a,{})}),"host:fp-ref":(0,f.jsx)(`button`,{type:`button`,className:`fp-attach ref`,"data-tip":v(`referenceTip`),onClick:()=>l(e.path,e.name,`reference`),children:(0,f.jsx)(ue,{})}),"host:fp-full":(0,f.jsx)(`button`,{type:`button`,className:`fp-attach full ${P?`on`:``}`,"data-tip":v(P?`exitFullscreen`:`fullscreen`),onClick:()=>Ae(e=>!e),children:P?(0,f.jsx)(le,{}):(0,f.jsx)(se,{})}),"host:fp-close":null},$e=m===void 0?[`host:fp-md`,`host:fp-toc`,`host:fp-html`,`host:fp-edit`,`host:fp-wrap`,`host:fp-zoom`,`host:fp-download`,`host:fp-ref`,`host:fp-full`].map(e=>({id:e,source:`host`})):m.filter(e=>!e.hidden&&e.id!==`host:fp-close`),$=e=>de(ce(`/api/file?clientId=${encodeURIComponent(me())}&path=${encodeURIComponent(e)}`)),et=e=>{let t=e.split(`/`).map(e=>encodeURIComponent(e)).join(`/`),n=/^[A-Za-z]:([\\/]|$)/.test(e)||e.startsWith(`/`)?`/api/preview/__abs__/${t}`:`/api/preview/${t}`;return de(ce(`${n}?clientId=${encodeURIComponent(me())}${j?`&allowJs=1`:``}`))};return(0,f.jsx)(`div`,{className:`fp-overlay ${P?`fullscreen`:``}`,onMouseDown:e=>{e.target===e.currentTarget&&G()},children:(0,f.jsxs)(`div`,{className:`fp ${P?`fullscreen`:``} ${qe?`is-ppt`:``}`,style:{"--fp-zoom":F/100},children:[(0,f.jsxs)(`div`,{className:`fp-head`,onDoubleClick:e=>{let t=e.target;t&&!t.closest(`button, a, input`)&&Ae(e=>!e)},children:[(0,f.jsx)(`span`,{className:`fp-name`,title:e.path,children:e.name}),(0,f.jsx)(`span`,{className:`fp-path`,children:e.path}),(0,f.jsxs)(`span`,{className:`fp-meta`,children:[y&&q===`text`&&!K&&v(`fileLines`,{n:Pe}),y&&` · ${ge(y.size)}`]}),(0,f.jsx)(`span`,{className:`fp-head-actions`,children:he($e,Qe,xe)}),(0,f.jsx)(`button`,{type:`button`,className:`fp-close`,title:v(`close`),"aria-label":v(`close`),onClick:G,children:(0,f.jsx)(ne,{})})]}),We&&q===`text`&&!K&&(0,f.jsx)(`div`,{className:`fp-notice`,children:g(e.name)?v(`previewLinesTruncated`,{n:U.length}):v(`previewTruncated`)}),b&&!y&&(0,f.jsx)(`div`,{className:`fp-empty`,children:v(`loading`)}),!b&&q===`none`&&!K&&(0,f.jsx)(`div`,{className:`fp-empty`,children:v(`previewNotSupported`)}),!b&&q===`image`&&(0,f.jsx)(`div`,{className:`fp-media-wrap clickable`,onClick:G,title:v(`clickToCloseImage`),children:(0,f.jsx)(`img`,{className:`fp-media fp-media-clickable`,src:$(e.path),alt:e.name,onClick:G,title:v(`clickToCloseImage`)})}),!b&&q===`video`&&(0,f.jsx)(`div`,{className:`fp-media-wrap`,children:(0,f.jsx)(`video`,{className:`fp-media`,src:$(e.path),controls:!0,preload:`metadata`})}),!b&&q===`audio`&&(0,f.jsx)(`div`,{className:`fp-media-wrap fp-audio-wrap`,children:(0,f.jsxs)(`div`,{className:`fp-audio-card`,children:[(0,f.jsx)(`div`,{className:`fp-audio-icon`,"aria-hidden":`true`,children:`🎵`}),(0,f.jsxs)(`div`,{className:`fp-audio-info`,children:[(0,f.jsx)(`div`,{className:`fp-audio-name`,title:e.name,children:e.name}),y?.size?(0,f.jsx)(`div`,{className:`fp-audio-size`,children:ge(y.size)}):null]}),(0,f.jsx)(`audio`,{className:`fp-audio-element`,src:$(e.path),controls:!0,autoPlay:!0,preload:`metadata`})]})}),!b&&Y&&y&&(0,f.jsxs)(`div`,{className:`fp-html`,children:[(0,f.jsxs)(`div`,{className:`fp-html-bar`,children:[(0,f.jsx)(`span`,{className:`fp-html-hint`,title:v(j?`htmlJsOnTip`:`htmlJsOffTip`),children:v(j?`htmlJsOn`:`htmlJsOff`)}),(0,f.jsx)(`button`,{type:`button`,className:`fp-html-js ${j?`on`:``}`,"data-tip":v(j?`htmlDisableJs`:`htmlEnableJs`),onClick:()=>Oe(e=>!e),children:v(j?`htmlDisableJs`:`htmlEnableJs`)}),(0,f.jsxs)(`a`,{className:`fp-html-btn fp-html-external`,href:et(e.path),target:`_blank`,rel:`noopener noreferrer`,title:v(`openInNewTab`),children:[(0,f.jsx)(n,{}),(0,f.jsx)(`span`,{children:v(`openInNewTab`)})]})]}),(0,f.jsx)(`iframe`,{className:`fp-html-frame`,src:et(e.path),title:e.name,sandbox:j?`allow-scripts`:``,referrerPolicy:`no-referrer`},j?`js`:`nojs`)]}),!b&&J&&y&&(0,f.jsx)(`div`,{className:g(e.name)?`fp-markdown msg-text fp-office`:`fp-markdown msg-text`,children:(0,f.jsxs)(`div`,{className:X&&d(Z)?`fp-toc-layout`:void 0,children:[X&&d(Z)&&(0,f.jsx)(`nav`,{className:`fp-toc`,"aria-label":v(`previewTocLabel`),children:Z.map(e=>(0,f.jsx)(`a`,{className:`l${Math.min(e.level,6)}${e.id===Xe?` on`:``}`,href:`#${e.id}`,title:e.label,onClick:t=>{t.preventDefault(),Q.current?.querySelector(`#${CSS.escape(e.id)}`)?.scrollIntoView({behavior:`smooth`,block:`start`})},children:e.label},e.id))}),(0,f.jsx)(`div`,{className:`fp-markdown-zoom`,ref:Q,children:(0,f.jsx)(ve,{text:y.text})})]})}),!b&&K&&q!==`image`&&q!==`video`&&y&&(0,f.jsxs)(`div`,{className:`fp-hex-wrap`,children:[(0,f.jsxs)(`div`,{className:`fp-notice`,children:[v(`binaryFile`),y.truncated&&v(`binaryHexTruncated`)]}),(0,f.jsx)(`pre`,{className:`fp-hex`,children:y.text})]}),!b&&C&&q===`text`&&!K&&y&&(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`textarea`,{className:`fp-editor ${N?``:`no-wrap`}`,value:T,onChange:e=>E(e.target.value),wrap:N?`soft`:`off`,spellCheck:!1,autoFocus:!0}),Ne&&(0,f.jsx)(`div`,{className:`fp-notice`,role:`alert`,children:v(`saveResultUnknown`)})]}),!b&&!J&&!Y&&!C&&q===`text`&&!K&&y&&U.length===0&&(0,f.jsx)(`div`,{className:`fp-empty`,children:v(`emptyFile`)}),!b&&!J&&!Y&&!C&&q===`text`&&!K&&U.length>0&&(0,f.jsxs)(`div`,{className:`fp-code ${we?`dragging`:``} ${N?``:`no-wrap`}`,onMouseDown:e=>{e.button===0&&e.preventDefault()},children:[U.map((e,t)=>{let n=t+1,r=x!==null&&n>=x.start&&n<=x.end;return(0,f.jsxs)(`div`,{className:`fp-line ${r?`sel`:``}`,onMouseDown:e=>{e.button===0&&(Ie(n,e.shiftKey),L.current=!0,Te(!0))},onMouseEnter:()=>{L.current&&Ie(n,!0)},children:[(0,f.jsx)(`span`,{className:`fp-num`,children:n}),(0,f.jsx)(`span`,{className:`fp-code-text`,children:e})]},n)}),Fe&&(0,f.jsx)(`div`,{className:`fp-lines-note`,children:v(`previewLinesTruncated`,{n:p})})]}),(C||!J&&!Y&&q===`text`)&&(0,f.jsx)(`div`,{className:`fp-foot`,children:C?(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`span`,{className:`fp-hint`,children:v(`editFile`)}),(0,f.jsxs)(`div`,{className:`fp-actions`,children:[(0,f.jsx)(`button`,{type:`button`,className:`btn`,onClick:Be,children:v(`cancel`)}),(0,f.jsxs)(`button`,{type:`button`,className:`btn primary`,disabled:Me||T===(y?.text??``),onClick:Ve,children:[(0,f.jsx)(i,{}),` `,v(`saveFile`)]})]})]}):(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`span`,{className:`fp-hint`,children:x?v(`selectedRange`,{n:Ue,start:x.start,end:x.end}):v(`selectLinesHint`)}),(0,f.jsxs)(`div`,{className:`fp-actions`,children:[(0,f.jsx)(`button`,{type:`button`,className:`btn`,disabled:U.length===0,onClick:Le,children:v(`selectAll`)}),(0,f.jsx)(`button`,{type:`button`,className:`btn`,disabled:!x,onClick:()=>S(null),children:v(`clearSelection`)}),(0,f.jsxs)(`button`,{type:`button`,className:`btn primary`,disabled:!x||K,onClick:Re,children:[Ee?(0,f.jsx)(ie,{}):null,v(Ee?`addedToChat`:`addToChat`)]})]})]})})]})})}function h(e){let t=e.toLowerCase();return t.endsWith(`.md`)||t.endsWith(`.markdown`)}function g(e){let t=e.toLowerCase();return t.endsWith(`.docx`)||t.endsWith(`.xlsx`)||t.endsWith(`.xlsm`)||t.endsWith(`.pptx`)||t.endsWith(`.pptm`)||t.endsWith(`.ppsx`)||t.endsWith(`.potx`)}function _(e){let t=e.toLowerCase();return t.endsWith(`.html`)||t.endsWith(`.htm`)||t.endsWith(`.xhtml`)}export{m as FilePreview};
@@ -1,2 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{A as t,B as n,D as r,Dt as i,L as a,Qt as ee,V as te,Yt as ne,Zt as re,_ as ie,an as ae,ct as oe,dt as se,fn as ce,gt as le,st as ue,un as de,z as fe}from"./fi-DaSO0Q-m.js";import{i as o,t as s}from"./react-CR5VJ85Q.js";import{t as pe}from"./app-globals-DcyO0UPi.js";import{K as me,U as he,ct as ge,dt as _e,pt as ve}from"./index-Cdh3sibd.js";var c=e(o(),1),l=`未命名章节`;function u(e){return String(e??``).trim().replace(/[\s\u3000]+/g,`-`).replace(/[^\p{L}\p{N}_-]+/gu,`-`).replace(/-{2,}/g,`-`).replace(/^-+|-+$/g,``).slice(0,80)||`section`}function ye(e){let t=new Map;return e.map(({level:e,label:n})=>{let r=String(n??``).replace(/\s+/g,` `).trim(),i=u(r||l),a=(t.get(i)??0)+1;return t.set(i,a),{level:e,id:a===1?i:`${i}-${a}`,label:r||l}})}function d(e){return e.length>=2}var f=s(),p=5e3,be=`pi-web-ui:preview-toc`;function m({file:e,content:o,onAddLines:s,onAttach:l,onClose:u,uiFilePreviewToolbar:m,onUiAction:xe}){let v=ae(),[y,Se]=(0,c.useState)(null),[b,Ce]=(0,c.useState)(!1),[x,S]=(0,c.useState)(null),[we,Te]=(0,c.useState)(!1),[Ee,De]=(0,c.useState)(!1),[C,w]=(0,c.useState)(!1),[T,E]=(0,c.useState)(``),[D,O]=(0,c.useState)(!0),[k,A]=(0,c.useState)(!0),[j,Oe]=(0,c.useState)(!1),M=(0,c.useRef)(!1),[N,ke]=(0,c.useState)(!0),[P,Ae]=(0,c.useState)(!1),[F,je]=(0,c.useState)(100),I=(0,c.useRef)(0),L=(0,c.useRef)(!1),R=(0,c.useRef)(null),[Me,z]=(0,c.useState)(!1),[Ne,B]=(0,c.useState)(!1),V=(0,c.useRef)(!1),H=(0,c.useRef)(null);(0,c.useEffect)(()=>()=>{R.current&&clearTimeout(R.current),H.current&&clearTimeout(H.current)},[]),(0,c.useEffect)(()=>{Ce(!0),Se(null),S(null),w(!1),E(``),O(!0),A(!0),Oe(!1),M.current=!1,V.current=!1,z(!1),B(!1),H.current&&clearTimeout(H.current),pe({type:`read_file`,path:e.path})},[e.path]),(0,c.useEffect)(()=>{o&&o.path===e.path&&(Se(o),C||E(o.text),Ce(!1),V.current&&(V.current=!1,H.current&&clearTimeout(H.current),z(!1),B(!1),w(!1),E(o.text),M.current&&(h(e.name)&&O(!0),_(e.name)&&A(!0)),S(null)))},[o,C,e.path]),(0,c.useEffect)(()=>{let e=e=>{if(e.key===`Escape`){G();return}if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`s`&&C){e.preventDefault(),Ve();return}let t=e.target,n=t&&(t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.isContentEditable);(e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`a`&&!n&&(e.preventDefault(),Le())};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[u,y,C,T]),(0,c.useEffect)(()=>{let e=()=>{L.current=!1,Te(!1)};return window.addEventListener(`mouseup`,e),()=>window.removeEventListener(`mouseup`,e)},[]);let U=(0,c.useMemo)(()=>{if(!y)return[];let e=y.text.split(`
2
- `);return e.length>0&&e[e.length-1]===``&&e.pop(),e.slice(0,p)},[y]),Pe=y?.lines??0,Fe=Pe>p,Ie=(e,t)=>{if(t){let t=I.current>0?I.current:e;S({start:Math.min(t,e),end:Math.max(t,e)})}else I.current=e,S({start:e,end:e})},Le=()=>{U.length!==0&&(I.current=1,S({start:1,end:U.length}))},Re=()=>{x&&(s(e.path,e.name,x.start,x.end),De(!0),R.current&&clearTimeout(R.current),R.current=setTimeout(()=>De(!1),1400))},W=y!==null&&y.kind===`text`&&!y.binary&&!y.truncated&&!g(e.name),ze=()=>{V.current=!1,H.current&&clearTimeout(H.current),z(!1),B(!1),E(y?.text??``),w(!1),M.current&&(h(e.name)&&O(!0),_(e.name)&&A(!0))},Be=()=>{if(C){if(T!==(y?.text??``)&&!window.confirm(v(`discardFileChanges`)))return;ze();return}W&&y&&(M.current=h(e.name)&&D||_(e.name)&&k,h(e.name)&&O(!1),_(e.name)&&A(!1),S(null),E(y.text),w(!0))},Ve=()=>{C&&y&&W&&pe({type:`write_file`,path:e.path,text:T})&&(V.current=!0,B(!1),z(!0),H.current&&clearTimeout(H.current),H.current=setTimeout(()=>{V.current=!1,z(!1),B(!0)},5e3))},G=()=>{(!C||T===(y?.text??``)||window.confirm(v(`discardFileChanges`)))&&u()},He=e=>{je(Math.min(200,Math.max(50,e)))},Ue=x?x.end-x.start+1:0,K=y?.binary??!1,We=y?.truncated??!1,q=y?.kind??`text`,Ge=h(e.name)||g(e.name),Ke=_(e.name),qe=g(e.name),J=Ge&&D&&!C&&q===`text`&&!K,Y=Ke&&k&&!C&&q===`text`&&!K,[X,Je]=(0,c.useState)(()=>{try{return localStorage.getItem(be)===`1`}catch{return!1}});(0,c.useEffect)(()=>{try{localStorage.setItem(be,X?`1`:`0`)}catch{}},[X]);let[Z,Ye]=(0,c.useState)([]),[Xe,Ze]=(0,c.useState)(``),Q=(0,c.useRef)(null);(0,c.useEffect)(()=>{let e=Q.current;if(!e||!J){Ye([]);return}let t=[...e.querySelectorAll(`h1, h2, h3, h4, h5, h6`)],n=ye(t.map(e=>({level:Number(e.tagName.slice(1)),label:e.textContent??``})));t.forEach((e,t)=>{e.id||=n[t].id}),Ye(n)},[J,y?.text,e.path]),(0,c.useEffect)(()=>{let e=Q.current;if(!e||!X||!d(Z))return;let t=Z.map(t=>e.querySelector(`#${CSS.escape(t.id)}`)).filter(e=>e!==null);if(t.length===0)return;let n=new IntersectionObserver(e=>{let t=e.filter(e=>e.isIntersecting).sort((e,t)=>e.boundingClientRect.top-t.boundingClientRect.top)[0];t?.target.id&&Ze(t.target.id)},{rootMargin:`0px 0px -70% 0px`});for(let e of t)n.observe(e);return()=>n.disconnect()},[Z,X]);let Qe={"host:fp-md":Ge&&q===`text`&&!K&&y?(0,f.jsx)(`button`,{type:`button`,className:`fp-attach markdown ${D?`on`:``}`,"data-tip":v(D?`showMarkdownSource`:`showMarkdownPreview`),disabled:C,onClick:()=>O(e=>!e),children:D?(0,f.jsx)(te,{}):(0,f.jsx)(r,{})}):null,"host:fp-toc":J&&d(Z)?(0,f.jsx)(`button`,{type:`button`,className:`fp-attach toc ${X?`on`:``}`,"data-tip":v(X?`previewTocHide`:`previewTocShow`),onClick:()=>Je(e=>!e),children:(0,f.jsx)(oe,{})}):null,"host:fp-html":Ke&&q===`text`&&!K&&y?(0,f.jsx)(`button`,{type:`button`,className:`fp-attach html ${k?`on`:``}`,"data-tip":v(k?`showHtmlSource`:`showHtmlPreview`),disabled:C,onClick:()=>A(e=>!e),children:k?(0,f.jsx)(r,{}):(0,f.jsx)(te,{})}):null,"host:fp-edit":q===`text`&&!K&&y?(0,f.jsx)(`button`,{type:`button`,className:`fp-attach edit ${C?`on`:``}`,"data-tip":v(We?`fileEditTruncated`:C?`exitEditFile`:`editFile`),disabled:!W&&!C,onClick:Be,children:(0,f.jsx)(fe,{})}):null,"host:fp-wrap":q===`text`&&!K&&!J&&!Y?(0,f.jsx)(`button`,{type:`button`,className:`fp-attach wrap ${N?`on`:``}`,"data-tip":v(N?`disableWrap`:`enableWrap`),onClick:()=>ke(e=>!e),children:(0,f.jsx)(t,{})}):null,"host:fp-zoom":q===`text`&&y?(0,f.jsxs)(`span`,{className:`fp-zoom`,children:[(0,f.jsx)(`button`,{type:`button`,className:`fp-attach zoom-out`,"data-tip":v(`zoomOut`),disabled:F<=50,onClick:()=>He(F-10),children:(0,f.jsx)(ee,{})}),(0,f.jsxs)(`button`,{type:`button`,className:`fp-zoom-val`,title:v(`resetZoom`),onClick:()=>je(100),children:[F,`%`]}),(0,f.jsx)(`button`,{type:`button`,className:`fp-attach zoom-in`,"data-tip":v(`zoomIn`),disabled:F>=200,onClick:()=>He(F+10),children:(0,f.jsx)(re,{})})]}):null,"host:fp-download":(0,f.jsx)(`button`,{type:`button`,className:`fp-attach download`,"data-tip":v(`downloadFile`),onClick:()=>void _e(e.path,e.name),children:(0,f.jsx)(a,{})}),"host:fp-ref":(0,f.jsx)(`button`,{type:`button`,className:`fp-attach ref`,"data-tip":v(`referenceTip`),onClick:()=>l(e.path,e.name,`reference`),children:(0,f.jsx)(ue,{})}),"host:fp-full":(0,f.jsx)(`button`,{type:`button`,className:`fp-attach full ${P?`on`:``}`,"data-tip":v(P?`exitFullscreen`:`fullscreen`),onClick:()=>Ae(e=>!e),children:P?(0,f.jsx)(le,{}):(0,f.jsx)(se,{})}),"host:fp-close":null},$e=m===void 0?[`host:fp-md`,`host:fp-toc`,`host:fp-html`,`host:fp-edit`,`host:fp-wrap`,`host:fp-zoom`,`host:fp-download`,`host:fp-ref`,`host:fp-full`].map(e=>({id:e,source:`host`})):m.filter(e=>!e.hidden&&e.id!==`host:fp-close`),$=e=>de(ce(`/api/file?clientId=${encodeURIComponent(me())}&path=${encodeURIComponent(e)}`)),et=e=>{let t=e.split(`/`).map(e=>encodeURIComponent(e)).join(`/`),n=/^[A-Za-z]:([\\/]|$)/.test(e)||e.startsWith(`/`)?`/api/preview/__abs__/${t}`:`/api/preview/${t}`;return de(ce(`${n}?clientId=${encodeURIComponent(me())}${j?`&allowJs=1`:``}`))};return(0,f.jsx)(`div`,{className:`fp-overlay ${P?`fullscreen`:``}`,onMouseDown:e=>{e.target===e.currentTarget&&G()},children:(0,f.jsxs)(`div`,{className:`fp ${P?`fullscreen`:``} ${qe?`is-ppt`:``}`,style:{"--fp-zoom":F/100},children:[(0,f.jsxs)(`div`,{className:`fp-head`,onDoubleClick:e=>{let t=e.target;t&&!t.closest(`button, a, input`)&&Ae(e=>!e)},children:[(0,f.jsx)(`span`,{className:`fp-name`,title:e.path,children:e.name}),(0,f.jsx)(`span`,{className:`fp-path`,children:e.path}),(0,f.jsxs)(`span`,{className:`fp-meta`,children:[y&&q===`text`&&!K&&v(`fileLines`,{n:Pe}),y&&` · ${ge(y.size)}`]}),(0,f.jsx)(`span`,{className:`fp-head-actions`,children:he($e,Qe,xe)}),(0,f.jsx)(`button`,{type:`button`,className:`fp-close`,title:v(`close`),"aria-label":v(`close`),onClick:G,children:(0,f.jsx)(ne,{})})]}),We&&q===`text`&&!K&&(0,f.jsx)(`div`,{className:`fp-notice`,children:g(e.name)?v(`previewLinesTruncated`,{n:U.length}):v(`previewTruncated`)}),b&&!y&&(0,f.jsx)(`div`,{className:`fp-empty`,children:v(`loading`)}),!b&&q===`none`&&!K&&(0,f.jsx)(`div`,{className:`fp-empty`,children:v(`previewNotSupported`)}),!b&&q===`image`&&(0,f.jsx)(`div`,{className:`fp-media-wrap clickable`,onClick:G,title:v(`clickToCloseImage`),children:(0,f.jsx)(`img`,{className:`fp-media fp-media-clickable`,src:$(e.path),alt:e.name,onClick:G,title:v(`clickToCloseImage`)})}),!b&&q===`video`&&(0,f.jsx)(`div`,{className:`fp-media-wrap`,children:(0,f.jsx)(`video`,{className:`fp-media`,src:$(e.path),controls:!0,preload:`metadata`})}),!b&&q===`audio`&&(0,f.jsx)(`div`,{className:`fp-media-wrap fp-audio-wrap`,children:(0,f.jsxs)(`div`,{className:`fp-audio-card`,children:[(0,f.jsx)(`div`,{className:`fp-audio-icon`,"aria-hidden":`true`,children:`🎵`}),(0,f.jsxs)(`div`,{className:`fp-audio-info`,children:[(0,f.jsx)(`div`,{className:`fp-audio-name`,title:e.name,children:e.name}),y?.size?(0,f.jsx)(`div`,{className:`fp-audio-size`,children:ge(y.size)}):null]}),(0,f.jsx)(`audio`,{className:`fp-audio-element`,src:$(e.path),controls:!0,autoPlay:!0,preload:`metadata`})]})}),!b&&Y&&y&&(0,f.jsxs)(`div`,{className:`fp-html`,children:[(0,f.jsxs)(`div`,{className:`fp-html-bar`,children:[(0,f.jsx)(`span`,{className:`fp-html-hint`,title:v(j?`htmlJsOnTip`:`htmlJsOffTip`),children:v(j?`htmlJsOn`:`htmlJsOff`)}),(0,f.jsx)(`button`,{type:`button`,className:`fp-html-js ${j?`on`:``}`,"data-tip":v(j?`htmlDisableJs`:`htmlEnableJs`),onClick:()=>Oe(e=>!e),children:v(j?`htmlDisableJs`:`htmlEnableJs`)}),(0,f.jsxs)(`a`,{className:`fp-html-btn fp-html-external`,href:et(e.path),target:`_blank`,rel:`noopener noreferrer`,title:v(`openInNewTab`),children:[(0,f.jsx)(n,{}),(0,f.jsx)(`span`,{children:v(`openInNewTab`)})]})]}),(0,f.jsx)(`iframe`,{className:`fp-html-frame`,src:et(e.path),title:e.name,sandbox:j?`allow-scripts`:``,referrerPolicy:`no-referrer`},j?`js`:`nojs`)]}),!b&&J&&y&&(0,f.jsx)(`div`,{className:g(e.name)?`fp-markdown msg-text fp-office`:`fp-markdown msg-text`,children:(0,f.jsxs)(`div`,{className:X&&d(Z)?`fp-toc-layout`:void 0,children:[X&&d(Z)&&(0,f.jsx)(`nav`,{className:`fp-toc`,"aria-label":v(`previewTocLabel`),children:Z.map(e=>(0,f.jsx)(`a`,{className:`l${Math.min(e.level,6)}${e.id===Xe?` on`:``}`,href:`#${e.id}`,title:e.label,onClick:t=>{t.preventDefault(),Q.current?.querySelector(`#${CSS.escape(e.id)}`)?.scrollIntoView({behavior:`smooth`,block:`start`})},children:e.label},e.id))}),(0,f.jsx)(`div`,{className:`fp-markdown-zoom`,ref:Q,children:(0,f.jsx)(ve,{text:y.text})})]})}),!b&&K&&q!==`image`&&q!==`video`&&y&&(0,f.jsxs)(`div`,{className:`fp-hex-wrap`,children:[(0,f.jsxs)(`div`,{className:`fp-notice`,children:[v(`binaryFile`),y.truncated&&v(`binaryHexTruncated`)]}),(0,f.jsx)(`pre`,{className:`fp-hex`,children:y.text})]}),!b&&C&&q===`text`&&!K&&y&&(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`textarea`,{className:`fp-editor ${N?``:`no-wrap`}`,value:T,onChange:e=>E(e.target.value),wrap:N?`soft`:`off`,spellCheck:!1,autoFocus:!0}),Ne&&(0,f.jsx)(`div`,{className:`fp-notice`,role:`alert`,children:v(`saveResultUnknown`)})]}),!b&&!J&&!Y&&!C&&q===`text`&&!K&&y&&U.length===0&&(0,f.jsx)(`div`,{className:`fp-empty`,children:v(`emptyFile`)}),!b&&!J&&!Y&&!C&&q===`text`&&!K&&U.length>0&&(0,f.jsxs)(`div`,{className:`fp-code ${we?`dragging`:``} ${N?``:`no-wrap`}`,onMouseDown:e=>{e.button===0&&e.preventDefault()},children:[U.map((e,t)=>{let n=t+1,r=x!==null&&n>=x.start&&n<=x.end;return(0,f.jsxs)(`div`,{className:`fp-line ${r?`sel`:``}`,onMouseDown:e=>{e.button===0&&(Ie(n,e.shiftKey),L.current=!0,Te(!0))},onMouseEnter:()=>{L.current&&Ie(n,!0)},children:[(0,f.jsx)(`span`,{className:`fp-num`,children:n}),(0,f.jsx)(`span`,{className:`fp-code-text`,children:e})]},n)}),Fe&&(0,f.jsx)(`div`,{className:`fp-lines-note`,children:v(`previewLinesTruncated`,{n:p})})]}),(C||!J&&!Y&&q===`text`)&&(0,f.jsx)(`div`,{className:`fp-foot`,children:C?(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`span`,{className:`fp-hint`,children:v(`editFile`)}),(0,f.jsxs)(`div`,{className:`fp-actions`,children:[(0,f.jsx)(`button`,{type:`button`,className:`btn`,onClick:Be,children:v(`cancel`)}),(0,f.jsxs)(`button`,{type:`button`,className:`btn primary`,disabled:Me||T===(y?.text??``),onClick:Ve,children:[(0,f.jsx)(i,{}),` `,v(`saveFile`)]})]})]}):(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`span`,{className:`fp-hint`,children:x?v(`selectedRange`,{n:Ue,start:x.start,end:x.end}):v(`selectLinesHint`)}),(0,f.jsxs)(`div`,{className:`fp-actions`,children:[(0,f.jsx)(`button`,{type:`button`,className:`btn`,disabled:U.length===0,onClick:Le,children:v(`selectAll`)}),(0,f.jsx)(`button`,{type:`button`,className:`btn`,disabled:!x,onClick:()=>S(null),children:v(`clearSelection`)}),(0,f.jsxs)(`button`,{type:`button`,className:`btn primary`,disabled:!x||K,onClick:Re,children:[Ee?(0,f.jsx)(ie,{}):null,v(Ee?`addedToChat`:`addToChat`)]})]})]})})]})})}function h(e){let t=e.toLowerCase();return t.endsWith(`.md`)||t.endsWith(`.markdown`)}function g(e){let t=e.toLowerCase();return t.endsWith(`.docx`)||t.endsWith(`.xlsx`)||t.endsWith(`.xlsm`)||t.endsWith(`.pptx`)||t.endsWith(`.pptm`)||t.endsWith(`.ppsx`)||t.endsWith(`.potx`)}function _(e){let t=e.toLowerCase();return t.endsWith(`.html`)||t.endsWith(`.htm`)||t.endsWith(`.xhtml`)}export{m as FilePreview};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{K as t,Yt as n,an as r,kt as i,mt as a,q as o,xt as s}from"./fi-DaSO0Q-m.js";import{i as c,t as l}from"./react-CR5VJ85Q.js";import{b as u,d,h as f,s as p}from"./plugin-host-BRBg6zmQ.js";import{i as m,o as h,t as g}from"./app-globals-DcyO0UPi.js";import{F as _}from"./index-DWw_SxRq.js";var v=e(c(),1),y=l();function b(e,t){return e.toLowerCase().includes(t)}function x({open:e,projects:c,fileSearch:l,sessionSearch:x,onClose:S,onSwitchSession:C,onSwitchProject:w,onPreviewFile:T}){let E=r(),D=h(),O=E(`pluginMenuTitle`),k=m(`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;g({type:`list_sessions`}),g({type:`list_projects`});let t=j.trim();if(t){let e=_();I.current=e,V(!0),g({type:`search_files`,reqId:e,query:t}),g({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),g({type:`search_files`,reqId:t,query:e}),g({type:`search_sessions`,reqId:t,query:e})},300),()=>{L.current&&clearTimeout(L.current)}},[N]),(0,v.useEffect)(()=>{l&&l.reqId===I.current&&z(l)},[l]);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?c.filter(e=>b(e.path,H)).slice(0,10):[],[c,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 d==`function`&&(r=d())}catch{r=[]}let i=r.filter(e=>e&&typeof e.id==`string`).map(e=>{if(typeof e.search==`function`)return e;try{let t=p(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),g({type:`list_sessions`}),g({type:`list_projects`});let t=N.trim();if(t){let e=_();I.current=e,V(!0),g({type:`search_files`,reqId:e,query:t}),g({type:`search_sessions`,reqId:e,query:t})}}else e.kind===`plugin`?f(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)(i,{}),(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)(n,{})})]}),(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)(a,{})),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(),u({attachments:[{path:``,key:`conv||${e.path}`,name:n,mode:`conversation`,sessionPath:e.path}]})},children:[`💬 `,E(`quoteConversationShort`)]})]},e.path)})]}),W.length>0&&(0,y.jsxs)(`div`,{className:`gs-section`,children:[Q(E(`gsProjects`),W.length,(0,y.jsx)(o,{})),W.map(e=>{$++;let t=$,n=k&&e.path===k;return(0,y.jsxs)(`button`,{type:`button`,className:t===P?`gs-item active`:`gs-item`,onMouseEnter:()=>F(t),onClick:()=>X({kind:`project`,path:e.path}),children:[(0,y.jsxs)(`span`,{className:`gs-item-title`,children:[e.path.split(/[\\/]/).pop(),n&&(0,y.jsx)(`em`,{className:`gs-item-meta`,children:E(`gsCurrentProject`)})]}),(0,y.jsx)(`span`,{className:`gs-item-sub`,children:e.path})]},e.path)})]}),(G.length>0||H&&K)&&(0,y.jsxs)(`div`,{className:`gs-section`,children:[Q(E(`gsFiles`),G.length,(0,y.jsx)(t,{})),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)(s,{})),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{K as t,Yt as n,an as r,kt as i,mt as a,q as o,xt as s}from"./fi-DaSO0Q-m.js";import{i as c,t as l}from"./react-CR5VJ85Q.js";import{b as u,d,h as f,s as p}from"./plugin-host-BRBg6zmQ.js";import{i as m,o as h,t as g}from"./app-globals-DcyO0UPi.js";import{F as _}from"./index-Cdh3sibd.js";var v=e(c(),1),y=l();function b(e,t){return e.toLowerCase().includes(t)}function x({open:e,projects:c,fileSearch:l,sessionSearch:x,onClose:S,onSwitchSession:C,onSwitchProject:w,onPreviewFile:T}){let E=r(),D=h(),O=E(`pluginMenuTitle`),k=m(`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;g({type:`list_sessions`}),g({type:`list_projects`});let t=j.trim();if(t){let e=_();I.current=e,V(!0),g({type:`search_files`,reqId:e,query:t}),g({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),g({type:`search_files`,reqId:t,query:e}),g({type:`search_sessions`,reqId:t,query:e})},300),()=>{L.current&&clearTimeout(L.current)}},[N]),(0,v.useEffect)(()=>{l&&l.reqId===I.current&&z(l)},[l]);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?c.filter(e=>b(e.path,H)).slice(0,10):[],[c,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 d==`function`&&(r=d())}catch{r=[]}let i=r.filter(e=>e&&typeof e.id==`string`).map(e=>{if(typeof e.search==`function`)return e;try{let t=p(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),g({type:`list_sessions`}),g({type:`list_projects`});let t=N.trim();if(t){let e=_();I.current=e,V(!0),g({type:`search_files`,reqId:e,query:t}),g({type:`search_sessions`,reqId:e,query:t})}}else e.kind===`plugin`?f(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)(i,{}),(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)(n,{})})]}),(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)(a,{})),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(),u({attachments:[{path:``,key:`conv||${e.path}`,name:n,mode:`conversation`,sessionPath:e.path}]})},children:[`💬 `,E(`quoteConversationShort`)]})]},e.path)})]}),W.length>0&&(0,y.jsxs)(`div`,{className:`gs-section`,children:[Q(E(`gsProjects`),W.length,(0,y.jsx)(o,{})),W.map(e=>{$++;let t=$,n=k&&e.path===k;return(0,y.jsxs)(`button`,{type:`button`,className:t===P?`gs-item active`:`gs-item`,onMouseEnter:()=>F(t),onClick:()=>X({kind:`project`,path:e.path}),children:[(0,y.jsxs)(`span`,{className:`gs-item-title`,children:[e.path.split(/[\\/]/).pop(),n&&(0,y.jsx)(`em`,{className:`gs-item-meta`,children:E(`gsCurrentProject`)})]}),(0,y.jsx)(`span`,{className:`gs-item-sub`,children:e.path})]},e.path)})]}),(G.length>0||H&&K)&&(0,y.jsxs)(`div`,{className:`gs-section`,children:[Q(E(`gsFiles`),G.length,(0,y.jsx)(t,{})),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)(s,{})),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{cn as t,fn as n,rn as r,un as i}from"./fi-DaSO0Q-m.js";import{i as a,t as o}from"./react-CR5VJ85Q.js";import{t as s}from"./uuid-BzDIGCwP.js";import{H as c,O as l,bt as u,yt as d}from"./index-DWw_SxRq.js";var f=e(a(),1),p=o(),m=class extends Error{status;code;constructor(e,t,n=``){super(t),this.status=e,this.code=n}};async function h(e,t,r){let a=await fetch(i(n(`/api/device-center/${e}`)),{method:r?`POST`:`GET`,credentials:`same-origin`,signal:t,...r?{headers:{"Content-Type":`application/json`},body:JSON.stringify(r)}:{}}),o=await a.json().catch(()=>({}));if(!a.ok)throw new m(a.status,o.error||String(a.status),o.code??``);return o}var g=new Map,_=()=>{};function v({roomId:e,active:t=!0,onBack:n}){return(0,p.jsx)(y,{roomId:e,active:t,onBack:n},e)}function y({roomId:e,active:n,onBack:i}){let{locale:a}=r(),o=t(a),[v,y]=(0,f.useState)(null),b=v?.bots??[],[x,S]=(0,f.useState)(``),[C,w]=(0,f.useState)(!1),[T,E]=(0,f.useState)(0);function D(e){return e instanceof m&&(e.status===404||e.status===403||e.status===409&&e.code===`REPAIR_REQUIRED`)}function O(e){return e instanceof m&&e.status===409&&e.code===`REPAIR_REQUIRED`?o?`设备绑定已失效,请返回设备设置重新绑定。`:`Device binding expired. Return to device settings and bind again.`:e instanceof Error?e.message:String(e)}let k=(0,f.useRef)(0),A=(0,f.useRef)(null),j=(0,f.useRef)(null),M=(0,f.useRef)(!1);(0,f.useEffect)(()=>{let t=++k.current,r=null,i=!1;async function a(){if(!n||i||document.visibilityState===`hidden`)return;i=!0,r=new AbortController;let a=r.signal;try{let n=await h(`rooms/${encodeURIComponent(e)}`,a);if(k.current!==t||a.aborted)return;y(n),w(!1),S(``)}catch(e){if(k.current!==t||a.aborted)return;D(e)&&(y(null),w(!0)),S(O(e))}finally{i=!1}}a();let o=window.setInterval(()=>void a(),2e3),s=()=>{document.visibilityState===`hidden`?r?.abort():a()};return document.addEventListener(`visibilitychange`,s),()=>{++k.current,r?.abort(),A.current?.abort(),clearInterval(o),document.removeEventListener(`visibilitychange`,s)}},[e,n,T]);let{state:N,labels:P}=(0,f.useMemo)(()=>d(e,v,b,o),[e,v,b,o]),F=b.filter(e=>e.enabled!==!1&&v?.room.botIds.includes(e.id));async function I(t,r){if(!n||C||!v||M.current||r.some(e=>!v.room.botIds.includes(e)))return!1;j.current=u(j.current,e,t,r,s);let i=new AbortController;A.current=i;let a=k.current;M.current=!0;try{return await h(`rooms/${encodeURIComponent(e)}/messages`,i.signal,{text:t,targetBotIds:r,idempotencyKey:j.current.key}),i.signal.aborted||k.current!==a?!1:(j.current=null,S(``),E(e=>e+1),!0)}catch(e){return!i.signal.aborted&&k.current===a&&(D(e)&&(y(null),w(!0)),S(O(e))),!1}finally{A.current===i&&(M.current=!1,A.current=null)}}return(0,p.jsxs)(p.Fragment,{children:[(0,p.jsxs)(`div`,{className:`dg-head`,children:[(0,p.jsx)(`strong`,{children:v?.room.name??(o?`群聊`:`Group`)}),i&&(0,p.jsx)(`button`,{type:`button`,className:`btn`,onClick:i,children:o?`返回对话`:`Back to chat`})]}),x&&(0,p.jsxs)(`div`,{role:`alert`,children:[x,C?o?`此群聊已删除或你已不在群中,请返回。`:`This group is unavailable or you are no longer a member. Return to chat.`:x]}),(0,p.jsx)(c,{state:N,liveOutputs:g,toolStatuses:g,messageLabels:P,readOnly:!0}),(0,p.jsx)(l,{groupDevices:F,onGroupSend:I,streaming:!1,messages:N.messages,slashCommands:[],modelState:null,models:[],modelsLoading:!1,attachments:[],onRemoveAttachment:_,onAddImageFiles:_,onAddLocalFiles:_,onNotice:(e,t)=>S(t),onSent:_,onManageModels:_,providerKeys:{},quickPhrases:[],quickPhrasesEnabled:!1,groupReady:n&&!!v&&!C,sessionId:`device-group:${e}`,conversationId:`device-group:${e}`})]})}export{v as GroupConversation};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{cn as t,fn as n,rn as r,un as i}from"./fi-DaSO0Q-m.js";import{i as a,t as o}from"./react-CR5VJ85Q.js";import{t as s}from"./uuid-BzDIGCwP.js";import{H as c,O as l,bt as u,yt as d}from"./index-Cdh3sibd.js";var f=e(a(),1),p=o(),m=class extends Error{status;code;constructor(e,t,n=``){super(t),this.status=e,this.code=n}};async function h(e,t,r){let a=await fetch(i(n(`/api/device-center/${e}`)),{method:r?`POST`:`GET`,credentials:`same-origin`,signal:t,...r?{headers:{"Content-Type":`application/json`},body:JSON.stringify(r)}:{}}),o=await a.json().catch(()=>({}));if(!a.ok)throw new m(a.status,o.error||String(a.status),o.code??``);return o}var g=new Map,_=()=>{};function v({roomId:e,active:t=!0,onBack:n}){return(0,p.jsx)(y,{roomId:e,active:t,onBack:n},e)}function y({roomId:e,active:n,onBack:i}){let{locale:a}=r(),o=t(a),[v,y]=(0,f.useState)(null),b=v?.bots??[],[x,S]=(0,f.useState)(``),[C,w]=(0,f.useState)(!1),[T,E]=(0,f.useState)(0);function D(e){return e instanceof m&&(e.status===404||e.status===403||e.status===409&&e.code===`REPAIR_REQUIRED`)}function O(e){return e instanceof m&&e.status===409&&e.code===`REPAIR_REQUIRED`?o?`设备绑定已失效,请返回设备设置重新绑定。`:`Device binding expired. Return to device settings and bind again.`:e instanceof Error?e.message:String(e)}let k=(0,f.useRef)(0),A=(0,f.useRef)(null),j=(0,f.useRef)(null),M=(0,f.useRef)(!1);(0,f.useEffect)(()=>{let t=++k.current,r=null,i=!1;async function a(){if(!n||i||document.visibilityState===`hidden`)return;i=!0,r=new AbortController;let a=r.signal;try{let n=await h(`rooms/${encodeURIComponent(e)}`,a);if(k.current!==t||a.aborted)return;y(n),w(!1),S(``)}catch(e){if(k.current!==t||a.aborted)return;D(e)&&(y(null),w(!0)),S(O(e))}finally{i=!1}}a();let o=window.setInterval(()=>void a(),2e3),s=()=>{document.visibilityState===`hidden`?r?.abort():a()};return document.addEventListener(`visibilitychange`,s),()=>{++k.current,r?.abort(),A.current?.abort(),clearInterval(o),document.removeEventListener(`visibilitychange`,s)}},[e,n,T]);let{state:N,labels:P}=(0,f.useMemo)(()=>d(e,v,b,o),[e,v,b,o]),F=b.filter(e=>e.enabled!==!1&&v?.room.botIds.includes(e.id));async function I(t,r){if(!n||C||!v||M.current||r.some(e=>!v.room.botIds.includes(e)))return!1;j.current=u(j.current,e,t,r,s);let i=new AbortController;A.current=i;let a=k.current;M.current=!0;try{return await h(`rooms/${encodeURIComponent(e)}/messages`,i.signal,{text:t,targetBotIds:r,idempotencyKey:j.current.key}),i.signal.aborted||k.current!==a?!1:(j.current=null,S(``),E(e=>e+1),!0)}catch(e){return!i.signal.aborted&&k.current===a&&(D(e)&&(y(null),w(!0)),S(O(e))),!1}finally{A.current===i&&(M.current=!1,A.current=null)}}return(0,p.jsxs)(p.Fragment,{children:[(0,p.jsxs)(`div`,{className:`dg-head`,children:[(0,p.jsx)(`strong`,{children:v?.room.name??(o?`群聊`:`Group`)}),i&&(0,p.jsx)(`button`,{type:`button`,className:`btn`,onClick:i,children:o?`返回对话`:`Back to chat`})]}),x&&(0,p.jsxs)(`div`,{role:`alert`,children:[x,C?o?`此群聊已删除或你已不在群中,请返回。`:`This group is unavailable or you are no longer a member. Return to chat.`:x]}),(0,p.jsx)(c,{state:N,liveOutputs:g,toolStatuses:g,messageLabels:P,readOnly:!0}),(0,p.jsx)(l,{groupDevices:F,onGroupSend:I,streaming:!1,messages:N.messages,slashCommands:[],modelState:null,models:[],modelsLoading:!1,attachments:[],onRemoveAttachment:_,onAddImageFiles:_,onAddLocalFiles:_,onNotice:(e,t)=>S(t),onSent:_,onManageModels:_,providerKeys:{},quickPhrases:[],quickPhrasesEnabled:!1,groupReady:n&&!!v&&!C,sessionId:`device-group:${e}`,conversationId:`device-group:${e}`})]})}export{v as GroupConversation};
@@ -1,2 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Ht as t,L as n,N as r,Tt as i,Xt as a,Yt as o,_ as s,an as ee,k as te,kt as c,t as l,wt as u}from"./fi-DaSO0Q-m.js";import{i as d,t as f}from"./react-CR5VJ85Q.js";import{t as p}from"./app-globals-DcyO0UPi.js";import{t as ne}from"./ProviderOAuthControls-C-MK36Dk.js";var m=e(d(),1);function re(e,t,n){if(JSON.stringify(e)===JSON.stringify(t))return n;let r=new Map(t.map(e=>[e.id,e])),i=new Map(n.map(e=>[e.id,e])),a=new Set(e.map(e=>e.id)),o=e.flatMap(e=>{let t=r.get(e.id);if(!t||JSON.stringify(t)!==JSON.stringify(e))return[e];let n=i.get(e.id);return n?[n]:[]});for(let e of n)!r.has(e.id)&&!a.has(e.id)&&o.push(e);return o}var h=f(),ie=[`openai-completions`,`openai-responses`,`anthropic-messages`,`google-generative-ai`],ae=[{id:`magpie`,name:`Magpie`,api:`openai-completions`,baseUrl:`http://127.0.0.1:3425/v1`,authHeader:!0,apiKey:`magpie`},{id:`deepseek`,name:`DeepSeek`,api:`openai-completions`,baseUrl:`https://api.deepseek.com/v1`,authHeader:!0,tag:`官方`},{id:`openrouter`,name:`OpenRouter`,api:`openai-completions`,baseUrl:`https://openrouter.ai/api/v1`,authHeader:!0,tag:`聚合`},{id:`moonshot`,name:`Moonshot (Kimi)`,api:`openai-completions`,baseUrl:`https://api.moonshot.cn/v1`,authHeader:!0,tag:`官方`},{id:`zhipu`,name:`智谱 GLM`,api:`openai-completions`,baseUrl:`https://open.bigmodel.cn/api/paas/v4`,authHeader:!0,tag:`官方`},{id:`siliconflow`,name:`硅基流动`,api:`openai-completions`,baseUrl:`https://api.siliconflow.cn/v1`,authHeader:!0,tag:`云端`},{id:`ollama`,name:`Ollama`,api:`openai-completions`,baseUrl:`http://127.0.0.1:11434/v1`,authHeader:!0,tag:`本地`},{id:`vllm`,name:`vLLM / LM Studio`,api:`openai-completions`,baseUrl:`http://127.0.0.1:8000/v1`,authHeader:!0,tag:`本地`},{id:`antigravity`,name:`Antigravity (OpenAI)`,api:`openai-completions`,baseUrl:`http://127.0.0.1:8045/v1`,authHeader:!0,tag:`反代`},{id:`antigravity-anthropic`,name:`Antigravity (Anthropic)`,api:`anthropic-messages`,baseUrl:`http://127.0.0.1:8045`,authHeader:!0,tag:`反代`}],g=[{label:`8K`,value:`8192`},{label:`16K`,value:`16384`},{label:`32K`,value:`32768`},{label:`64K`,value:`65536`},{label:`128K`,value:`131072`},{label:`200K`,value:`200000`},{label:`1M`,value:`1000000`}],_=[{label:`2K`,value:`2048`},{label:`4K`,value:`4096`},{label:`8K`,value:`8192`},{label:`16K`,value:`16384`},{label:`32K`,value:`32768`},{label:`64K`,value:`65536`}];function oe(e,t){switch(e){case`官方`:return t(`presetTagOfficial`);case`聚合`:return t(`presetTagAggregator`);case`云端`:return t(`presetTagCloud`);case`本地`:return t(`presetTagLocal`);case`反代`:return t(`presetTagProxy`);default:return e}}var v=()=>({id:``,name:``,reasoning:!1,input:`text`,contextWindow:``,maxTokens:``}),y=()=>({providerId:``,name:``,api:`openai-completions`,baseUrl:``,apiKey:``,hasApiKey:!1,authHeader:!0,models:[v()]});function b(e){return{providerId:e.providerId,name:e.name??``,api:e.api??`openai-completions`,baseUrl:e.baseUrl??``,apiKey:``,hasApiKey:e.hasApiKey??!1,authHeader:e.authHeader??!1,models:(e.models.length?e.models:[v()]).map(e=>({id:e.id,name:e.name??``,reasoning:e.reasoning??!1,input:e.input?.includes(`image`)?`text-image`:`text`,contextWindow:e.contextWindow?String(e.contextWindow):``,maxTokens:e.maxTokens?String(e.maxTokens):``,...e.thinkingLevelMap?{thinkingLevelMap:e.thinkingLevelMap}:{}}))}}function se(e){let t={};for(let n of e.split(`
2
- `)){let e=n.indexOf(`=`);if(e<=0)continue;let r=n.slice(0,e).trim(),i=n.slice(e+1).trim();r&&i&&(t[r]=i)}return t}function ce({candidates:e,preselectedIds:t,onAdopt:n,onClose:r}){let i=ee(),[s,te]=(0,m.useState)(``),[l,u]=(0,m.useState)(()=>{let n=new Set(e.map(e=>e.id)),r=(t??[]).map(e=>e.trim()).filter(e=>n.has(e));if(r.length>0)return new Set(r);let i=new Set;for(let t of e){let e=t.id.toLowerCase();!e.includes(`embed`)&&!e.includes(`audio`)&&!e.includes(`tts`)&&!e.includes(`whisper`)&&i.add(t.id)}if(i.size===0)for(let t of e)i.add(t.id);return i}),d=(0,m.useMemo)(()=>{let t=s.trim().toLowerCase();return t?e.filter(e=>e.id.toLowerCase().includes(t)||e.name&&e.name.toLowerCase().includes(t)):e},[e,s]),f=e=>{u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,h.jsx)(`div`,{className:`candidate-picker-backdrop`,onClick:r,children:(0,h.jsxs)(`div`,{className:`candidate-picker-modal`,onClick:e=>e.stopPropagation(),children:[(0,h.jsxs)(`div`,{className:`candidate-header`,children:[(0,h.jsxs)(`div`,{className:`candidate-title-group`,children:[(0,h.jsx)(`span`,{className:`candidate-title`,children:i(`candidatePickerTitle`)}),(0,h.jsx)(`span`,{className:`candidate-subtitle`,children:i(`candidatePickerSubtitle`,{n:e.length})})]}),(0,h.jsx)(`button`,{type:`button`,className:`iconbtn`,onClick:r,"aria-label":i(`close`),children:(0,h.jsx)(o,{})})]}),(0,h.jsxs)(`div`,{className:`candidate-filter-bar`,children:[(0,h.jsx)(c,{style:{color:`var(--text-faint)`,flexShrink:0}}),(0,h.jsx)(`input`,{type:`text`,className:`candidate-search-input`,placeholder:i(`searchCandidatePlaceholder`),value:s,onChange:e=>te(e.target.value),autoFocus:!0}),(0,h.jsxs)(`div`,{style:{display:`flex`,gap:6,flexShrink:0},children:[(0,h.jsx)(`button`,{type:`button`,className:`btn sm`,onClick:()=>{u(new Set(d.map(e=>e.id)))},children:i(`selectAll`)}),(0,h.jsx)(`button`,{type:`button`,className:`btn sm`,onClick:()=>{u(new Set)},children:i(`deselectAll`)})]})]}),(0,h.jsxs)(`div`,{className:`candidate-list-scroll`,children:[d.length===0&&(0,h.jsx)(`div`,{style:{padding:`32px 0`,textAlign:`center`,color:`var(--text-faint)`,fontSize:13},children:i(`noCandidateMatches`)}),d.map(e=>{let t=l.has(e.id);return(0,h.jsxs)(`div`,{className:`candidate-item-card ${t?`selected`:``}`,onClick:()=>f(e.id),children:[(0,h.jsxs)(`div`,{className:`candidate-item-left`,children:[(0,h.jsx)(`input`,{type:`checkbox`,className:`candidate-checkbox`,checked:t,onChange:()=>{},onClick:e=>e.stopPropagation()}),(0,h.jsxs)(`div`,{className:`candidate-id-info`,children:[(0,h.jsx)(`span`,{className:`candidate-id-name`,children:e.id}),e.name&&e.name!==e.id&&(0,h.jsx)(`span`,{style:{fontSize:11.5,color:`var(--text-dim)`},children:e.name})]})]}),(0,h.jsxs)(`div`,{className:`candidate-item-meta`,children:[e.contextWindow&&(0,h.jsx)(`span`,{className:`spec-badge ctx`,title:i(`contextWindowTooltip`),children:e.contextWindow>=1e6?`${Math.round(e.contextWindow/1e6)}M`:`${Math.round(e.contextWindow/1024)}K`}),e.reasoning&&(0,h.jsxs)(`span`,{className:`spec-badge reasoning`,title:i(`reasoningTooltip`),children:[(0,h.jsx)(a,{}),` `,i(`reasoning`)]}),e.input?.includes(`image`)&&(0,h.jsx)(`span`,{className:`spec-badge vision`,title:i(`visionTooltip`),children:i(`vision`)})]})]},e.id)})]}),(0,h.jsxs)(`div`,{className:`candidate-actions-footer`,children:[(0,h.jsx)(`span`,{className:`candidate-select-summary`,children:i(`selectedCandidatesCount`,{count:l.size,total:e.length})}),(0,h.jsxs)(`div`,{style:{display:`flex`,gap:8},children:[(0,h.jsx)(`button`,{type:`button`,className:`btn`,onClick:r,children:i(`cancel`)}),(0,h.jsx)(`button`,{type:`button`,className:`btn primary`,disabled:l.size===0,onClick:()=>{n(e.filter(e=>l.has(e.id)))},children:i(`adoptSelectedModels`,{count:l.size})})]})]})]})})}function x({providers:e,providerStatus:a,providerKeys:c,providerOAuthFlows:d,providerOAuthResults:f,fetchModelsResult:x,testModelConnectionResult:S,enrichModelsResult:C,enrichModelsProgress:le,cloneProviderResult:w,refreshBuiltinResult:T,refreshProviderResult:E,appendBuiltinResult:D,defaultModel:O,onClose:k}){let A=ee(),[j,M]=(0,m.useState)(()=>e.length>0?{type:`custom`,id:e[0].providerId}:a.length>0?{type:`builtin`,id:a[0].id}:{type:`custom`,id:``}),[N,P]=(0,m.useState)(()=>e.length>0?b(e[0]):a.length>0?null:y()),ue=(0,m.useRef)(e);(0,m.useEffect)(()=>{let t=ue.current;ue.current=e,P(n=>{if(!n)return n;let r=e.find(e=>e.providerId===n.providerId),i=t.find(e=>e.providerId===n.providerId);return!r||r===i?n:{...n,hasApiKey:r.hasApiKey??!1,models:re(n.models,i?b(i).models:[],b(r).models)}})},[e]);let[de,F]=(0,m.useState)(null),[fe,pe]=(0,m.useState)(!1),[me,he]=(0,m.useState)(0),[I,L]=(0,m.useState)(null),ge=(0,m.useRef)(0),[R,_e]=(0,m.useState)({}),[ve,ye]=(0,m.useState)({}),[z,B]=(0,m.useState)(null),be=(0,m.useRef)(c),V=(0,m.useRef)(null);(0,m.useEffect)(()=>{let e=z;e&&c[e]!==be.current[e]&&(B(null),_e(t=>({...t,[e]:``})),ye(t=>({...t,[e]:``})),V.current&&clearTimeout(V.current)),be.current=c},[c,z]),(0,m.useEffect)(()=>()=>{V.current&&clearTimeout(V.current)},[]);let[H,xe]=(0,m.useState)(!1),[Se,Ce]=(0,m.useState)(0),[U,W]=(0,m.useState)(null),we=(0,m.useRef)(0),[G,Te]=(0,m.useState)(!1),[K,q]=(0,m.useState)(!1),[Ee,De]=(0,m.useState)(0),[J,Y]=(0,m.useState)(null),[Oe,ke]=(0,m.useState)([]),[Ae]=(0,m.useState)(``),je=(0,m.useRef)(0),[X,Me]=(0,m.useState)(!1),[Ne,Pe]=(0,m.useState)(0),[Fe,Ie]=(0,m.useState)(null),Le=(0,m.useRef)(0),[Re,ze]=(0,m.useState)(null),[Be,Ve]=(0,m.useState)(``),[He,Ue]=(0,m.useState)(``),[We,Ge]=(0,m.useState)(``),[Ke,qe]=(0,m.useState)(``),[Je,Ye]=(0,m.useState)(!1),[Xe,Ze]=(0,m.useState)(0),[Qe,Z]=(0,m.useState)(null),$e=(0,m.useRef)(0),[et,tt]=(0,m.useState)(null),[nt,rt]=(0,m.useState)(``),[it,at]=(0,m.useState)(null),[ot,st]=(0,m.useState)({}),ct=(0,m.useRef)(0),lt=(0,m.useRef)(0),[ut,Q]=(0,m.useState)(null),dt=(0,m.useRef)(0),ft=(0,m.useRef)(0),pt=e=>{if(ot[e])return;let t=++ct.current+Date.now();st(t=>({...t,[e]:!0})),p({type:`refresh_provider_models`,providerId:e,reqId:t})};(0,m.useEffect)(()=>{E&&E.reqId!==lt.current&&(lt.current=E.reqId,st({}))},[E]);let mt=e=>{if(ut)return;Q(e.id);let t=++dt.current+Date.now();p({type:`clone_provider`,provider:e.id,reqId:t})||Q(null)};(0,m.useEffect)(()=>{p({type:`list_models_config`}),p({type:`list_providers`}),p({type:`list_provider_keys`}),p({type:`list_provider_oauth_flows`})},[]),(0,m.useEffect)(()=>{S&&S.reqId!==ge.current&&(ge.current=S.reqId,pe(!1),L({ok:S.ok,latencyMs:S.latencyMs,error:S.error}))},[S]),(0,m.useEffect)(()=>{x&&x.reqId!==we.current&&(we.current=x.reqId,xe(!1),x.ok&&x.models?.length?(F(x.models),W({ok:!0,text:A(`fetchModelsOk`,{n:x.models.length})})):W({ok:!1,text:x.error||A(`fetchModelsEmpty`)}))},[x,A]),(0,m.useEffect)(()=>{if(C&&C.reqId!==je.current){if(je.current=C.reqId,Te(!1),q(!1),C.ok&&C.results?.length){let e=C.results,t=new Map(e.map(e=>[e.id.trim(),e]));P(e=>e&&{...e,models:e.models.map(e=>{let n=t.get(e.id.trim());return!n||n.status!==`matched`?e:{...e,name:e.name||n.name||``,contextWindow:e.contextWindow||(n.contextWindow?String(n.contextWindow):``),maxTokens:e.maxTokens||(n.maxTokens?String(n.maxTokens):``),input:e.input===`text`&&n.input?.includes(`image`)?`text-image`:e.input,reasoning:e.reasoning||(n.reasoning??!1),src:n.source}})});let n=e.filter(e=>e.status===`matched`).length,r=e.length-n;Y({ok:!0,text:A(`enrichModelsOk`,{n,m:r})});let i=e.filter(e=>e.status!==`matched`&&(e.suggestions?.length||e.note)).map(e=>({id:e.id,suggestions:e.suggestions??[],note:e.note}));ke(i)}else Y({ok:!1,text:C.error||A(`enrichModelsErr`,{msg:``})})}},[C,A]),(0,m.useEffect)(()=>{T&&T.reqId!==Le.current&&(Le.current=T.reqId,Me(!1),T.ok?Ie({ok:!0,text:A(`refreshBuiltinOk`)}):Ie({ok:!1,text:T.error||A(`refreshBuiltinFail`)}))},[T,A]),(0,m.useEffect)(()=>{D&&D.reqId!==$e.current&&($e.current=D.reqId,Ye(!1),D.ok?(Z({ok:!0,text:A(`appendModelOk`)}),Ve(``),Ue(``),Ge(``),qe(``),ze(null),p({type:`list_models_config`})):Z({ok:!1,text:D.error||A(`appendModelFail`)}))},[D,A]),(0,m.useEffect)(()=>{if(w&&w.reqId!==ft.current&&(ft.current=w.reqId,Q(null),w.ok)){let e=w.configs;if(e&&e.length>1){tt(e.map(e=>b(e))),rt(``);return}w.config&&at(b(w.config))}},[w]);let ht=()=>{if(!N)return;let e=N.baseUrl.trim();if(!e){L({ok:!1,error:A(`fetchModelsNeedBaseUrl`)});return}pe(!0),L(null);let t=me+1;he(t),p({type:`test_model_connection`,reqId:t,baseUrl:e,apiKey:N.apiKey.trim()||void 0,...N.apiKey.trim()?{}:N.hasApiKey?{providerId:N.providerId.trim()}:{},authHeader:N.authHeader,api:N.api})},gt=()=>{if(!N)return;let e=N.baseUrl.trim();if(!e){W({ok:!1,text:A(`fetchModelsNeedBaseUrl`)});return}if(H)return;xe(!0),W(null);let t=Se+1;Ce(t),p({type:`fetch_models`,reqId:t,baseUrl:e,apiKey:N.apiKey.trim()||void 0,...N.apiKey.trim()?{}:N.hasApiKey?{providerId:N.providerId.trim()}:{},authHeader:N.authHeader,api:N.api})},_t=e=>{N&&(P(t=>{if(!t)return t;let n=t.models.filter(e=>e.id.trim()),r=new Set(n.map(e=>e.id.trim())),i=e.filter(e=>!r.has(e.id)).map(e=>({id:e.id,name:e.name??``,reasoning:e.reasoning??!1,input:e.input?.includes(`image`)?`text-image`:`text`,contextWindow:e.contextWindow?String(e.contextWindow):``,maxTokens:e.maxTokens?String(e.maxTokens):``,...e.thinkingLevelMap?{thinkingLevelMap:e.thinkingLevelMap}:{}}));return{...t,models:n.length===0?i:[...n,...i]}}),F(null))},vt=()=>{if(!N||G)return;let e=N.models.map(e=>e.id.trim()).filter(Boolean);if(e.length===0){Y({ok:!1,text:A(`enrichModelsNeedIds`)});return}Te(!0),q(!1),Y(null),ke([]);let t=Ee+1;De(t),p({type:`enrich_models`,reqId:t,ids:e,hints:se(Ae)})},yt=()=>{G&&!K&&(q(!0),p({type:`abort_enrich_models`,reqId:Ee}))},bt=e=>{P(t=>({providerId:t?.providerId.trim()||e.id,name:t?.name.trim()||e.name,api:e.api,baseUrl:e.baseUrl,apiKey:t?.apiKey||(t?.hasApiKey?``:e.apiKey)||``,hasApiKey:t?.hasApiKey??!1,authHeader:e.authHeader,models:t?.models.length?t.models:[v()]})),L(null),W(null)},xt=()=>{if(!N)return;let e=N.providerId.trim();if(!e)return;let t=N.models.filter(e=>e.id.trim()).map(e=>({id:e.id.trim(),name:e.name.trim()||void 0,reasoning:e.reasoning||void 0,input:e.input===`text-image`?[`text`,`image`]:void 0,contextWindow:e.contextWindow?Number(e.contextWindow):void 0,maxTokens:e.maxTokens?Number(e.maxTokens):void 0,...e.thinkingLevelMap?{thinkingLevelMap:e.thinkingLevelMap}:{}})),n={providerId:e,name:N.name.trim()||void 0,api:N.api.trim()||void 0,baseUrl:N.baseUrl.trim()||void 0,...N.apiKey.trim()?{apiKey:N.apiKey.trim()}:{},authHeader:N.authHeader||void 0,models:t};p({type:`save_model_config`,providerId:e,config:n}),k()},$=(e,t)=>{N&&P({...N,models:N.models.map((n,r)=>r===e?{...n,...t}:n)})},St=()=>{N&&P({...N,models:[...N.models,v()]})},Ct=e=>{N&&P({...N,models:N.models.filter((t,n)=>n!==e)})},wt=e=>{let t=(R[e.id]??``).trim();t&&!z&&(B(e.id),p({type:`add_provider_key`,provider:e.id,apiKey:t,name:(ve[e.id]??``).trim()||void 0}),V.current&&clearTimeout(V.current),V.current=setTimeout(()=>{B(t=>t===e.id?null:t)},1e4))},Tt=(e,t)=>{p({type:`activate_provider_key`,provider:e,keyName:t}),p({type:`list_provider_keys`})},Et=(e,t)=>{window.confirm(A(`removeKeyConfirm`))&&(p({type:`remove_provider_key`,provider:e,keyName:t}),p({type:`list_provider_keys`}))},Dt=e=>{window.confirm(A(`clearKeyConfirm`,{id:e}))&&p({type:`clear_provider_api_key`,provider:e})},Ot=t=>{if(window.confirm(A(`deleteProviderConfirm`,{id:t.providerId,n:t.models.length}))&&(p({type:`delete_model_config`,providerId:t.providerId}),j.type===`custom`&&j.id===t.providerId)){let n=e.filter(e=>e.providerId!==t.providerId);n.length>0?(M({type:`custom`,id:n[0].providerId}),P(b(n[0]))):(M({type:`custom`,id:``}),P(y()))}},kt=e=>{let t=Be.trim();if(!t||Je)return;Ye(!0),Z(null);let n=Xe+1;Ze(n),p({type:`append_builtin_model`,providerId:e,model:{id:t,...He.trim()?{name:He.trim()}:{},...We?{api:We}:{},...Ke.trim()?{baseUrl:Ke.trim()}:{}},reqId:n})};return(0,h.jsx)(`div`,{className:`modal-backdrop`,onClick:k,children:(0,h.jsxs)(`div`,{className:`modal model-studio-modal`,onClick:e=>e.stopPropagation(),children:[(0,h.jsxs)(`div`,{className:`studio-header`,children:[(0,h.jsxs)(`div`,{className:`studio-header-left`,children:[(0,h.jsx)(`div`,{className:`studio-header-icon-box`,children:(0,h.jsx)(r,{})}),(0,h.jsxs)(`div`,{className:`studio-header-title-wrap`,children:[(0,h.jsx)(`h2`,{className:`studio-header-title`,children:A(`modelManagementTitle`)}),(0,h.jsx)(`span`,{className:`studio-header-badge`,children:`Studio`})]})]}),(0,h.jsxs)(`div`,{className:`studio-header-actions`,children:[O!==void 0&&O&&(0,h.jsxs)(`div`,{style:{display:`inline-flex`,alignItems:`center`,gap:5,padding:`3px 8px`,borderRadius:6,background:`rgba(251, 191, 36, 0.08)`,border:`1px solid rgba(251, 191, 36, 0.3)`,fontSize:11.5,color:`var(--amber)`},title:A(`defaultModelLabel`,{model:O}),children:[(0,h.jsx)(`span`,{children:`★`}),(0,h.jsx)(`span`,{style:{maxWidth:120,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,fontFamily:`var(--mono)`},children:O.split(`/`).slice(1).join(`/`)}),(0,h.jsx)(`button`,{type:`button`,style:{background:`transparent`,border:`none`,color:`var(--amber)`,cursor:`pointer`,fontSize:10,padding:`0 2px`,opacity:.7},title:A(`clearDefaultModel`),onClick:()=>p({type:`clear_default_model`}),children:`✕`})]}),(0,h.jsxs)(`button`,{type:`button`,className:`studio-header-btn`,title:A(`refreshBuiltinHint`),disabled:X,onClick:()=>{if(X)return;Me(!0),Ie(null);let e=Ne+1;Pe(e),p({type:`refresh_builtin_models`,reqId:e})},children:[(0,h.jsx)(n,{}),(0,h.jsx)(`span`,{children:A(X?`refreshBuiltinBusy`:`refreshBuiltinCatalog`)})]}),(0,h.jsx)(`button`,{type:`button`,className:`studio-header-iconbtn`,title:A(`reloadModelsHint`),onClick:()=>p({type:`reload_models_config`}),children:(0,h.jsx)(i,{})}),(0,h.jsx)(`button`,{type:`button`,className:`studio-header-iconbtn close-btn`,"aria-label":A(`close`),onClick:k,children:(0,h.jsx)(o,{})})]})]}),Fe&&(0,h.jsx)(`div`,{style:{padding:`6px 20px`,background:`var(--bg-elev2)`,fontSize:12,borderBottom:`1px solid var(--border-soft)`},children:(0,h.jsx)(`span`,{className:`fetch-msg ${Fe.ok?`ok`:`err`}`,children:Fe.text})}),(0,h.jsxs)(`div`,{className:`model-studio-body`,children:[(0,h.jsxs)(`div`,{className:`model-studio-sidebar`,children:[(0,h.jsx)(`div`,{style:{padding:`12px 10px 6px`},children:(0,h.jsxs)(`button`,{type:`button`,className:`btn primary sm`,style:{width:`100%`,justifyContent:`center`},onClick:()=>{M({type:`custom`,id:``}),P(y()),L(null),W(null)},children:[(0,h.jsx)(u,{}),` `,A(`addCustomProvider`)]})}),(0,h.jsxs)(`div`,{className:`studio-sidebar-section`,children:[(0,h.jsx)(`span`,{className:`studio-sidebar-title`,children:A(`customProvidersCount`,{n:e.length})}),e.length===0&&(0,h.jsx)(`div`,{style:{fontSize:11.5,color:`var(--text-faint)`,padding:`6px 8px`},children:A(`noCustomProviders`)}),e.map(e=>{let t=j.type===`custom`&&j.id===e.providerId;return(0,h.jsxs)(`div`,{className:`studio-nav-item ${t?`active`:``}`,onClick:()=>{M({type:`custom`,id:e.providerId}),P(b(e)),L(null),W(null)},children:[(0,h.jsxs)(`span`,{className:`studio-nav-label`,children:[(0,h.jsx)(`span`,{className:`studio-nav-dot configured`}),(0,h.jsx)(`span`,{children:e.name||e.providerId})]}),(0,h.jsxs)(`span`,{style:{fontSize:10.5,color:`var(--text-faint)`,fontFamily:`var(--mono)`},children:[e.models.length,`m`]})]},e.providerId)})]}),(0,h.jsxs)(`div`,{className:`studio-sidebar-section`,children:[(0,h.jsx)(`span`,{className:`studio-sidebar-title`,children:A(`builtinProvidersCount`,{n:a.length})}),a.map(e=>{let t=j.type===`builtin`&&j.id===e.id,n=c[e.id]??[];return(0,h.jsxs)(`div`,{className:`studio-nav-item ${t?`active`:``}`,onClick:()=>{M({type:`builtin`,id:e.id}),P(null)},children:[(0,h.jsxs)(`span`,{className:`studio-nav-label`,children:[(0,h.jsx)(`span`,{className:`studio-nav-dot ${e.configured?`configured`:``}`}),(0,h.jsx)(`span`,{children:e.name})]}),n.length>0&&(0,h.jsxs)(`span`,{style:{fontSize:10.5,color:`var(--text-faint)`,fontFamily:`var(--mono)`},children:[n.length,`k`]})]},e.id)})]})]}),(0,h.jsxs)(`div`,{className:`model-studio-main`,children:[N&&(0,h.jsxs)(`div`,{className:`studio-card`,children:[(0,h.jsxs)(`div`,{className:`studio-card-head`,children:[(0,h.jsxs)(`div`,{className:`studio-card-title`,children:[(0,h.jsx)(`span`,{children:N.providerId?A(`editProviderTitle`,{id:N.providerId}):A(`newCustomProviderTitle`)}),N.providerId&&e.some(e=>e.providerId===N.providerId)&&(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`button`,{type:`button`,className:`iconbtn sm`,title:A(`refreshModels`),disabled:ot[N.providerId],onClick:()=>pt(N.providerId),children:(0,h.jsx)(i,{className:ot[N.providerId]?`spin`:``})}),(0,h.jsx)(`button`,{type:`button`,className:`iconbtn danger sm`,title:A(`deleteProviderTooltip`),onClick:()=>{let t=e.find(e=>e.providerId===N.providerId);t&&Ot(t)},children:(0,h.jsx)(t,{})})]})]}),(0,h.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8},children:[(0,h.jsxs)(`div`,{className:`conn-test-box`,children:[(0,h.jsxs)(`button`,{type:`button`,className:`conn-test-btn`,disabled:fe||!N.baseUrl.trim(),onClick:ht,children:[(0,h.jsx)(l,{}),` `,A(fe?`testingConnection`:`testConnection`)]}),I&&(0,h.jsxs)(`span`,{className:`ping-indicator ${I.ok?`ok`:`err`}`,children:[(0,h.jsx)(`span`,{className:`ping-dot`}),(0,h.jsx)(`span`,{children:I.ok?A(`connSuccess`,{latency:I.latencyMs??0}):A(`connFailed`)})]})]}),(0,h.jsx)(`button`,{type:`button`,className:`btn primary sm`,onClick:xt,children:A(`save`)})]})]}),(0,h.jsxs)(`div`,{className:`quick-chips-wrapper`,children:[(0,h.jsx)(`span`,{className:`quick-chips-label`,children:A(`quickPresetsLabel`)}),(0,h.jsx)(`div`,{className:`quick-chips-grid`,children:ae.map(e=>(0,h.jsxs)(`button`,{type:`button`,className:`quick-chip`,onClick:()=>bt(e),children:[(0,h.jsx)(`span`,{className:`quick-chip-name`,children:e.name}),e.tag&&(0,h.jsx)(`span`,{className:`quick-chip-tag`,children:oe(e.tag,A)})]},e.id))})]}),(0,h.jsxs)(`div`,{className:`form-grid`,children:[(0,h.jsxs)(`label`,{className:`field`,children:[(0,h.jsxs)(`span`,{className:`field-label`,children:[A(`providerId`),` `,(0,h.jsx)(`em`,{children:A(`providerIdHint`)})]}),(0,h.jsx)(`input`,{type:`text`,value:N.providerId,disabled:e.some(e=>e.providerId===N.providerId),onChange:e=>P({...N,providerId:e.target.value}),placeholder:A(`providerIdPlaceholder`)})]}),(0,h.jsxs)(`label`,{className:`field`,children:[(0,h.jsx)(`span`,{className:`field-label`,children:A(`displayName`)}),(0,h.jsx)(`input`,{type:`text`,value:N.name,onChange:e=>P({...N,name:e.target.value}),placeholder:A(`displayNamePh`)})]}),(0,h.jsxs)(`label`,{className:`field`,children:[(0,h.jsx)(`span`,{className:`field-label`,children:A(`apiType`)}),(0,h.jsx)(`select`,{value:N.api,onChange:e=>P({...N,api:e.target.value}),children:ie.map(e=>(0,h.jsx)(`option`,{value:e,children:e},e))})]}),(0,h.jsxs)(`label`,{className:`field`,children:[(0,h.jsxs)(`span`,{className:`field-label`,children:[`baseUrl `,(0,h.jsx)(`em`,{children:A(`baseUrlHint`)})]}),(0,h.jsx)(`input`,{type:`text`,value:N.baseUrl,onChange:e=>P({...N,baseUrl:e.target.value}),placeholder:`https://api.deepseek.com/v1`})]}),(0,h.jsxs)(`label`,{className:`field`,children:[(0,h.jsx)(`span`,{className:`field-label`,children:A(`apiKey`)}),(0,h.jsx)(`input`,{type:`password`,value:N.apiKey,onChange:e=>P({...N,apiKey:e.target.value}),placeholder:N.hasApiKey?A(`apiKeySavedHint`):A(`apiKeyHint`)})]}),(0,h.jsxs)(`label`,{className:`field check`,style:{alignSelf:`center`,paddingTop:16},children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:N.authHeader,onChange:e=>P({...N,authHeader:e.target.checked})}),(0,h.jsx)(`span`,{children:A(`authHeader`)})]})]}),(0,h.jsxs)(`div`,{style:{marginTop:8},children:[(0,h.jsxs)(`div`,{className:`model-section-head`,children:[(0,h.jsx)(`span`,{className:`form-section-title`,style:{fontSize:13,fontWeight:600},children:A(`modelMatrixCount`,{n:N.models.filter(e=>e.id.trim()).length})}),(0,h.jsxs)(`div`,{className:`model-section-actions`,children:[U&&(0,h.jsx)(`span`,{className:`fetch-msg ${U.ok?`ok`:`err`}`,title:U.text,children:U.text}),J&&(0,h.jsx)(`span`,{className:`fetch-msg ${J.ok?`ok`:`err`}`,title:J.text,children:J.text}),(0,h.jsxs)(`button`,{type:`button`,className:`btn sm`,disabled:H||!N.baseUrl.trim(),title:A(`fetchModelsHint`),onClick:gt,children:[(0,h.jsx)(n,{}),` `,A(H?`fetchingModels`:`autoFetchAndAdopt`)]}),(0,h.jsxs)(`button`,{type:`button`,className:`btn sm`,disabled:G,title:A(`enrichModelsHint`),onClick:vt,children:[(0,h.jsx)(n,{}),` `,A(G?`enrichingModels`:`enrichModels`)]}),G&&(0,h.jsxs)(`button`,{type:`button`,className:`btn sm`,disabled:K,title:A(`enrichModelsAbort`),onClick:yt,style:{color:`var(--red)`},children:[(0,h.jsx)(o,{}),` `,A(K?`enrichCancelling`:`enrichModelsCancel`)]})]})]}),(0,h.jsxs)(`div`,{className:`model-matrix-list`,children:[N.models.map((e,n)=>(0,h.jsxs)(`div`,{className:`model-matrix-card`,children:[(0,h.jsxs)(`div`,{className:`matrix-main-row`,children:[(0,h.jsxs)(`div`,{className:`matrix-input-group id-group`,children:[(0,h.jsxs)(`span`,{className:`matrix-input-prefix`,children:[(0,h.jsx)(r,{}),` ID`]}),(0,h.jsx)(`input`,{type:`text`,className:`matrix-input-field mono`,value:e.id,onChange:e=>$(n,{id:e.target.value}),placeholder:A(`modelIdPlaceholder`)})]}),(0,h.jsxs)(`div`,{className:`matrix-input-group name-group`,children:[(0,h.jsx)(`span`,{className:`matrix-input-prefix`,children:A(`modelAliasPrefix`)}),(0,h.jsx)(`input`,{type:`text`,className:`matrix-input-field`,value:e.name,onChange:e=>$(n,{name:e.target.value}),placeholder:A(`modelAliasPlaceholder`)})]}),(0,h.jsxs)(`div`,{className:`matrix-toggles`,children:[(0,h.jsx)(`button`,{type:`button`,className:`matrix-toggle-tag ${e.input===`text-image`?`active vision`:``}`,onClick:()=>$(n,{input:e.input===`text-image`?`text`:`text-image`}),title:A(`visionCheckboxTitle`),children:A(`visionCheckboxLabel`)}),(0,h.jsx)(`button`,{type:`button`,className:`matrix-toggle-tag ${e.reasoning?`active reasoning`:``}`,onClick:()=>$(n,{reasoning:!e.reasoning}),title:A(`reasoningCheckboxTitle`),children:A(`reasoningCheckboxLabel`)}),O!==void 0&&e.id.trim()&&(()=>{let t=`${N.providerId}/${e.id.trim()}`,n=O===t||O===e.id.trim();return(0,h.jsxs)(`button`,{type:`button`,className:`matrix-star-btn ${n?`active`:``}`,title:A(n?`cancelDefaultTooltip`:`setDefaultTooltip`),onClick:()=>{p(n?{type:`clear_default_model`}:{type:`set_default_model`,modelId:t})},children:[(0,h.jsx)(`span`,{className:`matrix-star-icon`,children:n?`★`:`☆`}),(0,h.jsx)(`span`,{children:A(n?`defaultModelBadge`:`setDefaultModelBtn`)})]})})(),(0,h.jsx)(`button`,{type:`button`,className:`matrix-delete-btn`,title:A(`delete`),onClick:()=>Ct(n),children:(0,h.jsx)(t,{})})]})]}),(0,h.jsxs)(`div`,{className:`matrix-spec-bar`,children:[(0,h.jsxs)(`div`,{className:`spec-combobox`,children:[(0,h.jsx)(`span`,{className:`spec-combobox-label`,children:A(`contextWindowLabel`)}),(0,h.jsxs)(`select`,{className:`spec-combobox-select`,value:g.some(t=>t.value===e.contextWindow)?e.contextWindow:`custom`,onChange:e=>{e.target.value!==`custom`&&$(n,{contextWindow:e.target.value})},children:[g.map(e=>(0,h.jsxs)(`option`,{value:e.value,children:[e.label,` (`,Math.round(Number(e.value)/1024),`K)`]},e.value)),(0,h.jsx)(`option`,{value:`custom`,children:A(`customOption`)})]}),(!g.some(t=>t.value===e.contextWindow)||e.contextWindow===``)&&(0,h.jsx)(`input`,{type:`text`,className:`spec-combobox-custom-input`,value:e.contextWindow,onChange:e=>$(n,{contextWindow:e.target.value}),placeholder:A(`contextPlaceholder`)})]}),(0,h.jsxs)(`div`,{className:`spec-combobox`,children:[(0,h.jsx)(`span`,{className:`spec-combobox-label`,children:A(`maxOutputLabel`)}),(0,h.jsxs)(`select`,{className:`spec-combobox-select`,value:_.some(t=>t.value===e.maxTokens)?e.maxTokens:`custom`,onChange:e=>{e.target.value!==`custom`&&$(n,{maxTokens:e.target.value})},children:[_.map(e=>(0,h.jsxs)(`option`,{value:e.value,children:[e.label,` (`,Math.round(Number(e.value)/1024),`K)`]},e.value)),(0,h.jsx)(`option`,{value:`custom`,children:A(`customOption`)})]}),(!_.some(t=>t.value===e.maxTokens)||e.maxTokens===``)&&(0,h.jsx)(`input`,{type:`text`,className:`spec-combobox-custom-input`,value:e.maxTokens,onChange:e=>$(n,{maxTokens:e.target.value}),placeholder:A(`maxOutputPlaceholder`)})]}),(0,h.jsx)(`div`,{className:`matrix-spec-quick-pills`,children:[`32K`,`128K`,`200K`].map(t=>{let r=g.find(e=>e.label===t);return r?(0,h.jsx)(`button`,{type:`button`,className:`param-pill ${e.contextWindow===r.value?`active`:``}`,onClick:()=>$(n,{contextWindow:r.value}),title:A(`contextPresetTooltip`,{label:t}),children:t},t):null})})]})]},n)),(0,h.jsxs)(`button`,{type:`button`,className:`btn sm`,style:{alignSelf:`flex-start`,marginTop:4},onClick:St,children:[(0,h.jsx)(u,{}),` `,A(`addModelRow`)]})]})]})]}),j.type===`builtin`&&(()=>{let e=a.find(e=>e.id===j.id);if(!e)return null;let n=c[e.id]??[];return(0,h.jsxs)(`div`,{className:`studio-card`,children:[(0,h.jsxs)(`div`,{className:`studio-card-head`,children:[(0,h.jsxs)(`div`,{className:`studio-card-title`,children:[(0,h.jsx)(`span`,{children:A(`builtinProviderTitle`,{name:e.name})}),e.configured&&(0,h.jsx)(`span`,{className:`auth-badge`,children:A(`configuredBadge`)}),e.source&&!e.configured&&(0,h.jsx)(`span`,{className:`auth-badge dim`,children:e.source})]}),(0,h.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:6},children:[(0,h.jsxs)(`button`,{type:`button`,className:`btn sm`,title:A(`cloneProvider`),disabled:ut===e.id,onClick:()=>mt(e),children:[(0,h.jsx)(te,{}),` `,A(`cloneProvider`)]}),(0,h.jsxs)(`button`,{type:`button`,className:`btn sm`,onClick:()=>{ze(Re===e.id?null:e.id),Z(null)},children:[(0,h.jsx)(u,{}),` `,A(`appendModel`)]}),e.supportsApiKey&&e.source===`stored`&&!e.usingOAuth&&(0,h.jsxs)(`button`,{type:`button`,className:`btn sm danger`,title:A(`clearKeyTitle`),onClick:()=>Dt(e.id),children:[(0,h.jsx)(t,{}),` `,A(`clearKey`)]})]})]}),e.supportsOAuth&&(0,h.jsx)(ne,{provider:e,flow:d.find(t=>t.provider===e.id),result:f[e.id]}),e.supportsApiKey&&(0,h.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:10},children:[(0,h.jsx)(`span`,{style:{fontSize:12.5,fontWeight:600},children:A(`apiKeyManagement`)}),(0,h.jsxs)(`div`,{className:`provider-keys`,children:[n.length===0&&(0,h.jsx)(`div`,{className:`provider-key-empty`,children:A(`noKeyYet`)}),n.map(n=>(0,h.jsxs)(`div`,{className:`provider-key-item ${n.active?`active`:``}`,children:[(0,h.jsx)(`span`,{className:`provider-key-dot`,children:n.active?`●`:`○`}),(0,h.jsx)(`span`,{className:`provider-key-label`,children:n.name}),!n.active&&(0,h.jsx)(`button`,{type:`button`,className:`iconbtn`,title:A(`activateKey`),onClick:()=>Tt(e.id,n.name),children:(0,h.jsx)(s,{})}),(0,h.jsx)(`button`,{type:`button`,className:`iconbtn danger`,title:A(`removeKey`),onClick:()=>Et(e.id,n.name),children:(0,h.jsx)(t,{})})]},n.name))]}),(0,h.jsxs)(`div`,{className:`provider-add-key`,style:{marginTop:6},children:[(0,h.jsx)(`input`,{type:`text`,className:`key-input key-input-name`,placeholder:A(`keyNamePh`),value:ve[e.id]??``,onChange:t=>ye(n=>({...n,[e.id]:t.target.value}))}),(0,h.jsx)(`input`,{type:`password`,className:`key-input key-input-value`,placeholder:A(`addKeyPlaceholder`),value:R[e.id]??``,onChange:t=>_e(n=>({...n,[e.id]:t.target.value}))}),(0,h.jsxs)(`button`,{type:`button`,className:`btn primary sm`,disabled:!(R[e.id]??``).trim()||z===e.id,onClick:()=>wt(e),children:[(0,h.jsx)(u,{}),` `,z===e.id?A(`savingKey`):A(`addKey`)]})]})]}),Re===e.id&&(0,h.jsxs)(`div`,{style:{marginTop:12,padding:12,background:`var(--bg)`,borderRadius:8,border:`1px dashed var(--border-soft)`},children:[(0,h.jsx)(`span`,{style:{fontSize:12,fontWeight:600,display:`block`,marginBottom:8},children:A(`addBuiltinOverlay`)}),(0,h.jsxs)(`div`,{style:{display:`flex`,gap:8,flexWrap:`wrap`},children:[(0,h.jsx)(`input`,{type:`text`,className:`key-input`,placeholder:A(`overlayModelIdPlaceholder`),value:Be,onChange:e=>Ve(e.target.value)}),(0,h.jsx)(`input`,{type:`text`,className:`key-input`,placeholder:A(`overlayModelNamePlaceholder`),value:He,onChange:e=>Ue(e.target.value)}),(0,h.jsxs)(`button`,{type:`button`,className:`btn primary sm`,disabled:!Be.trim()||Je,onClick:()=>kt(e.id),children:[(0,h.jsx)(u,{}),` `,A(`submitOverlayBtn`)]})]}),Qe&&(0,h.jsx)(`span`,{style:{fontSize:12,color:Qe.ok?`var(--green)`:`var(--red)`,marginTop:6},children:Qe.text})]})]})})()]})]}),de&&(0,h.jsx)(ce,{candidates:de,preselectedIds:N?.models.map(e=>e.id.trim()).filter(Boolean)??[],onAdopt:_t,onClose:()=>F(null)})]})})}export{x as ModelConfigModal};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{N as t,Tt as n,Yt as r,an as i}from"./fi-DaSO0Q-m.js";import{i as a,t as o}from"./react-CR5VJ85Q.js";import{r as s}from"./desktop-YguLbrX1.js";import{l as c,t as l}from"./app-globals-DcyO0UPi.js";import{t as u}from"./ProviderOAuthControls-C-MK36Dk.js";var d=e(a(),1),f=o();function p({piConfigured:e,piAgentInstalled:a,providers:o,providerOAuthFlows:p,providerOAuthResults:m,installResult:h,onClose:g}){let _=i(),v=s(),y=c(),[b,x]=(0,d.useState)(!1),[S,C]=(0,d.useState)(``),[w,T]=(0,d.useState)(``),[E,D]=(0,d.useState)(!1);(0,d.useEffect)(()=>{l({type:`list_providers`}),l({type:`list_provider_oauth_flows`})},[]),(0,d.useEffect)(()=>{e&&g()},[e,g]),(0,d.useEffect)(()=>{h&&x(!1)},[h]),(0,d.useEffect)(()=>{!S&&o.length>0&&C(o.find(e=>!e.configured)?.id??o[0].id)},[o,S]);let O=()=>{b||(x(!0),l({type:`install_pi_agent`}))},k=()=>{w.trim()&&!E&&(D(!0),l({type:`set_provider_api_key`,provider:S.trim(),apiKey:w.trim()}),setTimeout(()=>D(!1),3e3))},A=()=>{l({type:`get_state`}),l({type:`list_providers`})},j=o.find(e=>e.id===S),M=h!==null&&!h.ok;return(0,f.jsx)(`div`,{className:`modal-backdrop`,children:(0,f.jsxs)(`div`,{className:`modal setup-modal`,children:[(0,f.jsx)(`button`,{type:`button`,className:`modal-close`,"aria-label":_(`close`),onClick:g,children:(0,f.jsx)(r,{})}),(0,f.jsxs)(`div`,{className:`modal-head`,children:[(0,f.jsx)(t,{className:`modal-head-icon`}),(0,f.jsx)(`h2`,{children:_(`setupTitle`)})]}),(0,f.jsx)(`p`,{className:`modal-desc`,children:_(`setupDesc`)}),M?(0,f.jsxs)(`div`,{className:`setup-failed`,children:[(0,f.jsx)(`div`,{className:`setup-done`,children:_(`installFailed`)}),(0,f.jsx)(`pre`,{className:`setup-detail`,children:h.detail}),(0,f.jsxs)(`div`,{className:`setup-actions`,children:[(0,f.jsx)(`button`,{type:`button`,className:`btn primary`,disabled:b,onClick:O,children:_(`retryInstall`)}),(0,f.jsx)(`button`,{type:`button`,className:`btn`,onClick:g,children:_(`skip`)})]})]}):a||h?.ok||v?(0,f.jsxs)(`div`,{className:`setup-key-form`,children:[(0,f.jsx)(`div`,{className:`setup-done`,children:h?.ok?_(`installDone`):_(`cliReadyHint`)}),(0,f.jsxs)(`label`,{className:`field`,children:[(0,f.jsx)(`span`,{className:`field-label`,children:_(`provider`)}),(0,f.jsxs)(`select`,{value:S,onChange:e=>C(e.target.value),children:[o.length===0&&(0,f.jsx)(`option`,{value:``,children:_(`loading`)}),o.map(e=>(0,f.jsxs)(`option`,{value:e.id,children:[e.name,`(`,e.id,`)`,e.configured?` · ${_(`configured`)}`:``]},e.id))]}),j?.configured&&(0,f.jsx)(`div`,{className:`field-hint`,children:_(`providerKeyReady`)})]}),j?.supportsOAuth&&(0,f.jsx)(u,{provider:j,flow:p.find(e=>e.provider===j.id),result:m[j.id]}),j?.supportsApiKey&&(0,f.jsxs)(`label`,{className:`field`,children:[(0,f.jsx)(`span`,{className:`field-label`,children:_(`apiKey`)}),(0,f.jsx)(`input`,{type:`password`,value:w,onChange:e=>T(e.target.value),placeholder:`sk-…`})]}),(0,f.jsxs)(`div`,{className:`setup-actions`,children:[j?.supportsApiKey&&(0,f.jsx)(`button`,{type:`button`,className:`btn primary`,disabled:!w.trim()||E||!S,onClick:k,children:_(E?`saving`:`saveAndStart`)}),(0,f.jsxs)(`button`,{type:`button`,className:`btn`,onClick:A,children:[(0,f.jsx)(n,{}),` `,_(`recheck`)]})]})]}):y?(0,f.jsxs)(`div`,{className:`setup-actions`,children:[(0,f.jsx)(`div`,{className:`setup-done`,children:_(`updatesManaged`)}),(0,f.jsx)(`button`,{type:`button`,className:`btn`,onClick:g,children:_(`skip`)})]}):(0,f.jsxs)(`div`,{className:`setup-actions`,children:[(0,f.jsx)(`button`,{type:`button`,className:`btn primary`,disabled:b,onClick:O,children:_(b?`installing`:`autoInstall`)}),(0,f.jsx)(`button`,{type:`button`,className:`btn`,onClick:g,children:_(`skip`)})]})]})})}export{p as PiSetupModal};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{an as t}from"./fi-DaSO0Q-m.js";import{i as n,t as r}from"./react-CR5VJ85Q.js";import{t as i}from"./app-globals-DcyO0UPi.js";var a=e(n(),1),o=r();function s({provider:e,flow:n,result:r}){let s=t(),c=n?.event,l=e.oauthName??e.name,[u,d]=(0,a.useState)(``);return(0,a.useEffect)(()=>d(``),[n?.promptId]),e.usingOAuth?(0,o.jsxs)(`div`,{className:`provider-oauth`,children:[(0,o.jsx)(`span`,{className:`provider-oauth-status`,children:s(`oauthConnected`,{name:l})}),(0,o.jsx)(`button`,{type:`button`,className:`btn sm danger`,"data-provider-oauth-logout":e.id,onClick:()=>i({type:`provider_oauth_logout`,provider:e.id}),children:s(`oauthLogout`)}),r?.error&&(0,o.jsx)(`div`,{className:`provider-oauth-error`,children:r.error})]}):(0,o.jsxs)(`div`,{className:`provider-oauth`,children:[n?(0,o.jsxs)(o.Fragment,{children:[c?.type===`device_code`&&(0,o.jsxs)(`div`,{className:`provider-oauth-device`,children:[(0,o.jsx)(`div`,{children:s(`oauthDeviceCode`)}),(0,o.jsx)(`code`,{"data-oauth-device-code":!0,children:c.userCode}),(0,o.jsx)(`a`,{"data-oauth-verification-url":!0,href:c.verificationUri,target:`_blank`,rel:`noreferrer`,children:s(`oauthOpenVerification`)})]}),c?.type===`auth_url`&&(0,o.jsxs)(`div`,{className:`provider-oauth-event`,children:[c.instructions&&(0,o.jsx)(`div`,{children:c.instructions}),(0,o.jsx)(`a`,{href:c.url,target:`_blank`,rel:`noreferrer`,children:s(`oauthOpenVerification`)})]}),c?.type===`progress`&&(0,o.jsx)(`div`,{className:`provider-oauth-message`,children:c.message}),c?.type===`info`&&(0,o.jsxs)(`div`,{className:`provider-oauth-event`,children:[(0,o.jsx)(`div`,{children:c.message}),c.links?.map(e=>(0,o.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noreferrer`,children:e.label??e.url},e.url))]}),n.prompt&&(0,o.jsx)(`div`,{className:`provider-oauth-message`,children:n.prompt.message}),n.prompt?.type===`select`&&n.promptId&&(0,o.jsx)(`div`,{className:`provider-oauth-options`,children:n.prompt.options.map(e=>(0,o.jsx)(`button`,{type:`button`,className:`btn sm`,"data-oauth-option":e.id,onClick:()=>i({type:`provider_oauth_reply`,flowId:n.flowId,promptId:n.promptId,value:e.id}),children:e.label},e.id))}),n.prompt&&n.prompt.type!==`select`&&n.promptId&&(0,o.jsxs)(`form`,{className:`provider-oauth-prompt`,onSubmit:e=>{e.preventDefault(),u.trim()&&i({type:`provider_oauth_reply`,flowId:n.flowId,promptId:n.promptId,value:u.trim()})},children:[(0,o.jsx)(`input`,{"data-oauth-prompt-input":!0,type:n.prompt.type===`secret`?`password`:`text`,className:`key-input`,placeholder:n.prompt.placeholder,value:u,onChange:e=>d(e.target.value)}),(0,o.jsx)(`button`,{type:`submit`,className:`btn primary sm`,"data-oauth-prompt-submit":!0,disabled:!u.trim(),children:s(`oauthContinue`)})]}),(0,o.jsx)(`button`,{type:`button`,className:`btn sm danger`,"data-oauth-cancel":n.flowId,onClick:()=>i({type:`provider_oauth_cancel`,flowId:n.flowId}),children:s(`cancel`)})]}):(0,o.jsx)(`button`,{type:`button`,className:`btn primary sm`,"data-provider-oauth-login":e.id,onClick:()=>i({type:`provider_oauth_start`,provider:e.id}),children:s(`oauthLogin`,{name:l})}),r?.error&&(0,o.jsx)(`div`,{className:`provider-oauth-error`,children:r.error})]})}export{s as t};