pi-web-ui 0.114.2 → 0.114.3

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 (41) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/server/agent-service.js +29 -5
  3. package/dist/server/context-usage.js +105 -0
  4. package/dist/server/protocol-version.js +1 -1
  5. package/package.json +1 -1
  6. package/web/dist/.build-assets.json +1 -1
  7. package/web/dist/assets/{BgTasksModal-BIlQ89vr.js → BgTasksModal-BvnUHjFe.js} +1 -1
  8. package/web/dist/assets/{BgTasksModal-Ck2sjlPM.js → BgTasksModal-DSC8ncW3.js} +1 -1
  9. package/web/dist/assets/{CanvasStudio-B3W6b_rA.js → CanvasStudio-BSg9ghPV.js} +2 -2
  10. package/web/dist/assets/{CanvasStudio-Csv1Sj1-.js → CanvasStudio-DxW7C3Sz.js} +2 -2
  11. package/web/dist/assets/{DeviceCenter-BQdDcO8A.js → DeviceCenter-Bmgr-Bwm.js} +1 -1
  12. package/web/dist/assets/{DeviceCenter-CHRKL0Vy.js → DeviceCenter-Cl9MBXaH.js} +1 -1
  13. package/web/dist/assets/{DeviceGroups-D2rogxEN.js → DeviceGroups-aeLD2msl.js} +1 -1
  14. package/web/dist/assets/{Dropdown-ZLS04O8p.js → Dropdown-D1Jl35dw.js} +1 -1
  15. package/web/dist/assets/{FilePreview-B9xoU6ON.js → FilePreview-6CqoDF_P.js} +1 -1
  16. package/web/dist/assets/{FilePreview-DUQpVZkH.js → FilePreview-CJa27G_Q.js} +1 -1
  17. package/web/dist/assets/{GlobalSearchModal-BXEGvUZq.js → GlobalSearchModal-CJX35rZL.js} +1 -1
  18. package/web/dist/assets/{GlobalSearchModal-CnVPmfOI.js → GlobalSearchModal-CMW0xz0P.js} +1 -1
  19. package/web/dist/assets/{GroupConversation-CyIpQzDd.js → GroupConversation-Cq4daBFb.js} +1 -1
  20. package/web/dist/assets/{GroupConversation-DgYV3uYS.js → GroupConversation-DoELa83U.js} +1 -1
  21. package/web/dist/assets/{ModelConfigModal-DDZccDYt.js → ModelConfigModal-Bp7tfKYh.js} +1 -1
  22. package/web/dist/assets/{PiSetupModal-DHbqfx8T.js → PiSetupModal-DD8srwBJ.js} +1 -1
  23. package/web/dist/assets/{ProviderOAuthControls-C-MK36Dk.js → ProviderOAuthControls-C6tfXb88.js} +1 -1
  24. package/web/dist/assets/{SCMPanel-sVZcV7dR.js → SCMPanel-CghgsyBN.js} +1 -1
  25. package/web/dist/assets/{SCMPanel-imYI2Ecw.js → SCMPanel-D8-8aqwC.js} +1 -1
  26. package/web/dist/assets/{SettingsModal-Xw1Yoi3_.js → SettingsModal-BbBe2rYo.js} +1 -1
  27. package/web/dist/assets/{SettingsModal-mb4e34-0.js → SettingsModal-qETiVPKj.js} +1 -1
  28. package/web/dist/assets/{TerminalPanel-CLkJJvxg.js → TerminalPanel-Da-Xs4Wk.js} +1 -1
  29. package/web/dist/assets/{TerminalPanel-DpcIellm.js → TerminalPanel-DnS4tFQO.js} +1 -1
  30. package/web/dist/assets/{TuiOverlayModal-4-fFAZe7.js → TuiOverlayModal-CGyGkKYl.js} +1 -1
  31. package/web/dist/assets/{TuiOverlayModal-DCu01lks.js → TuiOverlayModal-CpBKjG6x.js} +1 -1
  32. package/web/dist/assets/{desktop-YguLbrX1.js → desktop-7EvUHhKQ.js} +1 -1
  33. package/web/dist/assets/{fi-DaSO0Q-m.js → fi-NyN-ZrgD.js} +2 -2
  34. package/web/dist/assets/{index-Cdh3sibd.js → index-DK3F5ZJo.js} +50 -50
  35. package/web/dist/assets/{index-DWw_SxRq.js → index-DQMii2he.js} +50 -50
  36. package/web/dist/assets/index-vwBnwzkr.css +1 -0
  37. package/web/dist/assets/{plugin-host-BRBg6zmQ.js → plugin-host-BCnX3P8U.js} +1 -1
  38. package/web/dist/assets/{theme-DDl-Oy1b.js → theme-D2DMH6tH.js} +1 -1
  39. package/web/dist/index.html +8 -8
  40. package/web/dist/sw.js +1 -1
  41. package/web/dist/assets/index-DDZMv6LO.css +0 -1
@@ -1,3 +1,3 @@
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(`
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-NyN-ZrgD.js";import{i as p,t as m}from"./react-CR5VJ85Q.js";import{T as h,_t as te,zt as g}from"./index-DQMii2he.js";import{DeviceGroups as _}from"./DeviceGroups-aeLD2msl.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
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
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 +1,3 @@
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(`
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-NyN-ZrgD.js";import{i as p,t as m}from"./react-CR5VJ85Q.js";import{T as h,_t as te,zt as g}from"./index-DK3F5ZJo.js";import{DeviceGroups as _}from"./DeviceGroups-aeLD2msl.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
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
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 +1 @@
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
+ 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-NyN-ZrgD.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 +1 @@
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
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{b as t}from"./fi-NyN-ZrgD.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 +1,2 @@
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(`
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-NyN-ZrgD.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-DK3F5ZJo.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
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 +1,2 @@
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(`
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-NyN-ZrgD.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-DQMii2he.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
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 +1 @@
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
+ 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-NyN-ZrgD.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-BCnX3P8U.js";import{i as m,o as h,t as g}from"./app-globals-DcyO0UPi.js";import{F as _}from"./index-DK3F5ZJo.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 +1 @@
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
+ 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-NyN-ZrgD.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-BCnX3P8U.js";import{i as m,o as h,t as g}from"./app-globals-DcyO0UPi.js";import{F as _}from"./index-DQMii2he.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 +1 @@
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
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{cn as t,fn as n,rn as r,un as i}from"./fi-NyN-ZrgD.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-DK3F5ZJo.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 +1 @@
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
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{cn as t,fn as n,rn as r,un as i}from"./fi-NyN-ZrgD.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-DQMii2he.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 +1,2 @@
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(`
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-NyN-ZrgD.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-C6tfXb88.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
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};