keel-agent 0.124.0 → 0.125.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/dist/packages/keel/src/adapters/sdk/prompt-render.js +5 -2
- package/dist/packages/keel/src/app/core-engine.js +16 -0
- package/dist/packages/keel/src/app/engine-dismiss.js +44 -0
- package/dist/packages/keel/src/app/session-registry.js +7 -1
- package/dist/packages/keel/src/app/subagent-runtime.js +8 -1
- package/dist/packages/keel/src/tool-catalog.js +5 -5
- package/dist/server/core-settings-adapter.js +48 -13
- package/dist/server/device-center/bot-chat.js +25 -0
- package/dist/server/device-center/bot-home.js +6 -0
- package/dist/server/device-center/bot-prompt.js +110 -0
- package/dist/server/device-center/bots.js +12 -0
- package/dist/server/device-center/execution-system-prompt.js +28 -13
- package/dist/server/device-center/local.js +126 -2
- package/dist/server/index.js +1 -0
- package/dist/server/universal/universal-session.js +8 -1
- package/package.json +1 -1
- package/web/dist/.build-assets.json +1 -1
- package/web/dist/assets/{BgTasksModal-D9NVLipp.js → BgTasksModal-B58Pn34o.js} +1 -1
- package/web/dist/assets/{BgTasksModal-CeowQkSk.js → BgTasksModal-DlRMULTX.js} +1 -1
- package/web/dist/assets/{BottomDock-DnXJHyg7.js → BottomDock-ix2rdS6N.js} +1 -1
- package/web/dist/assets/{CanvasStudio-D_RAeDdS.js → CanvasStudio-BRCkVMbW.js} +1 -1
- package/web/dist/assets/{CanvasStudio-BRWqZIVu.js → CanvasStudio-Cjxb3q3B.js} +1 -1
- package/web/dist/assets/{DeviceCenter-USAoAkin.js → DeviceCenter-BWMmB-CF.js} +1 -1
- package/web/dist/assets/{DeviceCenter-d49w4XXm.js → DeviceCenter-DfLlGGBZ.js} +1 -1
- package/web/dist/assets/{DeviceExecutionSettings-2hoZaBQ0.js → DeviceExecutionSettings-BjduyZOy.js} +1 -1
- package/web/dist/assets/DeviceGroupSection-B98LzFoj.js +7 -0
- package/web/dist/assets/DeviceGroupSection-BD3CKMFH.js +7 -0
- package/web/dist/assets/{DeviceGroups-BPE61M6w.js → DeviceGroups-C_lcfK5h.js} +1 -1
- package/web/dist/assets/DeviceGroups-ob27f-Ha.js +1 -0
- package/web/dist/assets/{Dropdown-DAiTWOzs.js → Dropdown-C8yx9mqF.js} +1 -1
- package/web/dist/assets/{FilePreview-CtSZWiJB.js → FilePreview-OxK_pI6p.js} +1 -1
- package/web/dist/assets/{FilePreview-xePo9QMY.js → FilePreview-inPVGc1j.js} +1 -1
- package/web/dist/assets/{GlobalSearchModal-CQhENYtf.js → GlobalSearchModal-3g1PplIg.js} +1 -1
- package/web/dist/assets/GlobalSearchModal-DG-HC0vV.js +1 -0
- package/web/dist/assets/{GroupConversation-DXDC1d3x.js → GroupConversation-BJnwTtT2.js} +2 -2
- package/web/dist/assets/{GroupConversation-CFv2RYwI.js → GroupConversation-Clt5o_lo.js} +1 -1
- package/web/dist/assets/{GroupWorkItems-BeZvaxV9.js → GroupWorkItems-7yTbAr_f.js} +1 -1
- package/web/dist/assets/{ModelConfigModal-drDDlawe.js → ModelConfigModal-CNnEGfep.js} +1 -1
- package/web/dist/assets/{ModelConfigModal-BI6ekcG4.js → ModelConfigModal-CYqDNXap.js} +1 -1
- package/web/dist/assets/{NativeCliPanel-B029dN9l.js → NativeCliPanel-B407C4qC.js} +1 -1
- package/web/dist/assets/{NativeCliPanel-BsehkHXc.js → NativeCliPanel-CVbFXUSf.js} +1 -1
- package/web/dist/assets/{PiSetupModal-D46ea4Wb.js → PiSetupModal-CrjDf0j6.js} +1 -1
- package/web/dist/assets/{ProviderOAuthControls-t8myaqZa.js → ProviderOAuthControls-Crhc6icP.js} +1 -1
- package/web/dist/assets/{SCMPanel-DUrKyvGV.js → SCMPanel-DuRJx0nl.js} +1 -1
- package/web/dist/assets/{SCMPanel-BKgGm9au.js → SCMPanel-rUAKnxBo.js} +1 -1
- package/web/dist/assets/SettingsModal-B3Q5EoVC.js +29 -0
- package/web/dist/assets/{SettingsModal-Bn0GTNgo.js → SettingsModal-CnJsUyvi.js} +1 -1
- package/web/dist/assets/{TermXterm-2oOzNy1G.js → TermXterm-BDLmWqim.js} +1 -1
- package/web/dist/assets/{TermXterm-D_VbvSyY.js → TermXterm-DhbhRp0B.js} +1 -1
- package/web/dist/assets/{TerminalPanel-CJ4ykxfy.js → TerminalPanel-D6oMxabb.js} +1 -1
- package/web/dist/assets/{TerminalPanel-mTL87sXL.js → TerminalPanel-Ds_hnvxz.js} +1 -1
- package/web/dist/assets/{ThemeMarketModal-B55xZq9j.js → ThemeMarketModal-5lH7k1in.js} +1 -1
- package/web/dist/assets/{ThemeMarketModal-EahvoJAf.js → ThemeMarketModal-WSOd5c6j.js} +1 -1
- package/web/dist/assets/{TuiOverlayModal-B2B5yRVf.js → TuiOverlayModal-Dh_HsAvo.js} +1 -1
- package/web/dist/assets/{TuiOverlayModal-C1uwsm1r.js → TuiOverlayModal-dKDCTdt8.js} +1 -1
- package/web/dist/assets/{api-client-CGqoOWHJ.js → api-client-BbDlV0jR.js} +1 -1
- package/web/dist/assets/{canvas-client-LIotRrYf.js → canvas-client-OwhfLxJx.js} +1 -1
- package/web/dist/assets/{desktop-BHN7gNP2.js → desktop-D1lGoY5p.js} +1 -1
- package/web/dist/assets/{fi-DjvtEEnZ.js → fi-CcqqfamG.js} +6 -6
- package/web/dist/assets/index-BQb8EOhk.js +410 -0
- package/web/dist/assets/index-Dbv9RJwm.js +410 -0
- package/web/dist/assets/index-xAdOV6os.css +1 -0
- package/web/dist/assets/{plugin-host-VdvQxFkv.js → plugin-host-DjGRLyyK.js} +1 -1
- package/web/dist/assets/{theme-DGfXszyo.js → theme-Dl8KLbt-.js} +1 -1
- package/web/dist/assets/use-copy-feedback-B3di-fnu.js +1 -0
- package/web/dist/index.html +11 -10
- package/web/dist/sw.js +1 -1
- package/web/dist/assets/DeviceGroupSection-CRdMGDwE.js +0 -7
- package/web/dist/assets/GlobalSearchModal-DpHvykpb.js +0 -1
- package/web/dist/assets/SettingsModal-ComFBXCj.js +0 -29
- package/web/dist/assets/index-4-PoF3xB.css +0 -1
- package/web/dist/assets/index-CXTnvcJF.js +0 -409
- package/web/dist/assets/index-Y0yKgBrc.js +0 -409
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$t as t,Et as n,Fn as r,Ft as i,H as a,N as o,Pt as s,W as c,Wt as l,an as u,b as d,ft as f,it as p,kn as m,sn as h,st as g,vn as ee,xt as _}from"./fi-
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$t as t,Et as n,Fn as r,Ft as i,H as a,N as o,Pt as s,W as c,Wt as l,an as u,b as d,ft as f,it as p,kn as m,sn as h,st as g,vn as ee,xt as _}from"./fi-CcqqfamG.js";import{i as v,r as y,t as b}from"./react-CR5VJ85Q.js";import{a as te,i as x,n as S}from"./api-client-BbDlV0jR.js";import{o as ne}from"./DeviceGroupSection-B98LzFoj.js";import{ct as C,f as w,in as T}from"./index-Dbv9RJwm.js";import{t as E}from"./DeviceExecutionSettings-BjduyZOy.js";import{n as re,t as D}from"./GroupWorkItems-7yTbAr_f.js";var O=e(v(),1);async function ie(e,t){let n=t.sleep??(e=>new Promise(t=>setTimeout(t,e))),r=Date.now()+(t.timeoutMs??18e5),i=e;if(!i||typeof i.id!=`string`||typeof i.fromBootId!=`string`)throw Error(`Invalid Hub upgrade response`);for(;;){if(t.isCurrent&&!t.isCurrent())throw new DOMException(`Hub upgrade view closed`,`AbortError`);if(i.id!==e.id)throw Error(`Hub upgrade job changed`);if(i.state===`failed`)throw Error(i.error||`Hub upgrade failed`);if(i.state===`succeeded`){if(!i.targetVersion||i.version!==i.targetVersion||!i.bootId||i.bootId===e.fromBootId)throw Error(`Hub upgrade result does not match the new version and process`);return i}if(i.state!==`queued`&&i.state!==`running`)throw Error(`Invalid Hub upgrade state`);if(Date.now()>=r)throw Error(`Hub upgrade timed out; inspect the Hub upgrade log`);if(await n(1500),t.isCurrent&&!t.isCurrent())throw new DOMException(`Hub upgrade view closed`,`AbortError`);try{i=await t.poll(e.id)}catch(e){let t=e.status;if(t&&t<500)throw e}}}var k=b();function A(e){return!!e&&`mount`in e&&typeof e.mount==`function`}function ae({plugin:e,epoch:t,onManageGroups:n}){let r=ee(),[i,a]=(0,O.useState)(null),[o,s]=(0,O.useState)(!1),[c,l]=(0,O.useState)(0),{id:u,name:d,version:f,hasClient:p,error:m,isolated:h}=e??{},g=(0,O.useMemo)(()=>u?{id:u,name:d??u,version:f,hasClient:p??!1,error:m,isolated:h}:void 0,[u,d,f,p,m,h]);(0,O.useEffect)(()=>{let e=!1;if(a(null),s(!1),g&&!g.error&&g.hasClient)return C(g,t,{retry:c>0}).then(t=>{e||(A(t)?a({info:g,module:t}):s(!0))}),()=>{e=!0}},[g,t,c]);let _=!g||!g.hasClient;return(0,k.jsxs)(`section`,{className:`dc-card`,"aria-label":r(`deviceChannelsLabel`),children:[(0,k.jsxs)(`header`,{className:`dc-card-header`,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`h2`,{children:r(`deviceChannelsTitle`)}),(0,k.jsx)(`p`,{children:r(`deviceChannelsDesc`)})]}),(0,k.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:n,children:r(`deviceChannelsManage`)})]}),_?(0,k.jsx)(`p`,{role:`status`,children:r(`deviceChannelsUnavailable`)}):g.error?(0,k.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:g.error}):o?(0,k.jsxs)(`div`,{className:`dc-notice is-error`,role:`alert`,children:[(0,k.jsx)(`span`,{children:r(`deviceChannelsLoadFailed`)}),(0,k.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>l(e=>e+1),children:r(`retryNow`)})]}):i?(0,k.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,minWidth:0,height:`min(72vh, 900px)`,minHeight:`360px`},children:(0,k.jsx)(w,{entry:i})}):(0,k.jsx)(`p`,{role:`status`,children:r(`deviceChannelsLoading`)})]})}function oe({href:e,children:t}){let n=ee(),[r,i]=(0,O.useState)(!1),[a,o]=(0,O.useState)(!1);return(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`a`,{className:`dc-button`,href:e,target:`_blank`,rel:`noopener noreferrer`,onClick:t=>{let n=window.piDesktop;n?.openHub&&(t.preventDefault(),!a&&(o(!0),i(!1),n.openHub(e).then(e=>i(!e),()=>i(!0)).finally(()=>o(!1))))},"aria-busy":a,children:t}),r&&(0,k.jsxs)(`span`,{role:`alert`,children:[n(`deviceHubNetworkError`),` `,(0,k.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,children:e})]})]})}function j(e){if(!M(e.host)||!Number.isInteger(e.port)||e.port<1024||e.port>65535||e.publicUrl.length>2048||/[\s\u0000-\u001f\u007f]/.test(e.publicUrl))return!1;try{let t=new URL(e.publicUrl);return[`http:`,`https:`].includes(t.protocol)&&!!t.hostname&&!t.username&&!t.password&&!t.search&&!t.hash&&t.pathname===`/`&&![`0.0.0.0`,`[::]`].includes(t.hostname)}catch{return!1}}function M(e){if(e===`localhost`)return!0;if(/^(?:\d{1,3}\.){3}\d{1,3}$/.test(e))return e.split(`.`).every(e=>String(Number(e))===e&&Number(e)<=255);if(!e.includes(`:`)||!/^[0-9a-fA-F:.]+$/.test(e))return!1;try{return new URL(`http://[${e}]/`).hostname.startsWith(`[`)}catch{return!1}}function N(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 se=`https://raw.githubusercontent.com/xing-shuyin/keel/main/docs/device-center-deployment.md`,ce=`https://github.com/xing-shuyin/keel/blob/main/docs/device-center-deployment.md`,P=`keel hub install --public-url https://SERVER_IP --allow-registration`;function F(e){let t=e=>e.includes(`:`)?M(e)&&![`::`,`::1`].includes(e):/^[\d.]+$/.test(e)?M(e)&&![`0.0.0.0`,`127.0.0.1`].includes(e):e.length<=253&&e.split(`.`).every(e=>/^[a-z\d](?:[a-z\d-]{0,61}[a-z\d])?$/i.test(e))&&e!==`localhost`;if(!t(e.server)||!Number.isInteger(e.sshPort)||e.sshPort<1||e.sshPort>65535||!Number.isInteger(e.port)||e.port<1024||e.port>65535||!/^[a-z_][a-z\d_.-]{0,63}$/i.test(e.username)||![`password`,`key`,`existing`].includes(e.auth)||e.domain!==``&&(!t(e.domain)||e.domain.includes(`:`)))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 le(e,t,n,r){if(!j(e))throw Error(`Invalid Hub setup`);if(r){let t=F(r);if(n!==`remote`||!t||JSON.stringify(t)!==JSON.stringify(e))throw Error(`Invalid remote Hub setup`)}let i=e=>(e??`unknown`).replace(/[\u0000-\u001f\u007f]/g,` `).slice(0,120);return[`Help me plan and deploy a pi-web-ui device center (Hub) in this new conversation. Preserve my previous conversation.`,`First read the deployment guide: ${se} (fallback: ${ce}). If unavailable, report that and obtain its contents before proceeding.`,`Public Linux deployments default to managed HTTPS with a public IPv4 or domain. Domain is optional. Use hub install --https=off only when HTTP is explicitly requested, or --https=external with an existing TLS proxy. Check port conflicts first.`,`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 selected: ${r.https}. ${r.https?`Use managed HTTPS on Linux, public TCP 443/80 and a private Hub port.`:`Explicit HTTP: use --https=off. HTTP inbound TCP port: ${r.port}.`}`]:[],`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: ${P}`,`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 I({onConnect:e,initialHubUrl:t=``}){let n=ee(),[r,i]=(0,O.useState)(t),[a,o]=(0,O.useState)(``),[s,c]=(0,O.useState)(!1),[l,u]=(0,O.useState)(!1),d=(0,O.useRef)(!1),f=(0,O.useRef)(!1);(0,O.useEffect)(()=>(f.current=!0,()=>{f.current=!1}),[]);let[p,m]=(0,O.useState)(null),[h,g]=(0,O.useState)(`current`),[_,v]=(0,O.useState)(null),[y,b]=(0,O.useState)(`127.0.0.1`),[te,ne]=(0,O.useState)(`8790`),[C,w]=(0,O.useState)(`http://127.0.0.1:8790`),[T,E]=(0,O.useState)({server:``,sshPort:22,username:`root`,auth:`password`,port:8790,domain:``,https:!0}),re=F(T),[D,ie]=(0,O.useState)(!1),[A,ae]=(0,O.useState)(!1),[M,se]=(0,O.useState)(null),[ce,P]=(0,O.useState)(!1),[I,ue]=(0,O.useState)(!1),[L,de]=(0,O.useState)(!1),[R,z]=(0,O.useState)(null),B=(0,O.useRef)(null),V=(0,O.useRef)(!1),H=N(window.location.origin);(0,O.useEffect)(()=>()=>B.current?.abort(),[]);let U=async()=>{if(V.current)return;B.current?.abort();let e=new AbortController;B.current=e,P(!1),ue(!1),de(!1);try{let t=await S(`/api/device-center/setup`,{signal:e.signal});if(!t.ok)throw Error();let n=await t.json();if(!n||typeof n.platform!=`string`||typeof n.nodeVersion!=`string`||typeof n.dataDir!=`string`||typeof n.cliPath!=`string`||!j({host:`127.0.0.1`,port:n.defaultPort,publicUrl:n.defaultPublicUrl}))throw Error();if(e.signal.aborted)return;v(n),n.installation?.installed?(b(n.installation.host??`127.0.0.1`),ne(String(n.installation.port)),w(n.installation.publicUrl??``),i(n.installation.publicUrl??``)):_||(ne(String(n.defaultPort)),w(n.defaultPublicUrl))}catch{e.signal.aborted||(P(!0),de(!0))}finally{e.signal.aborted||ue(!0)}},W=async()=>{let e={host:y,port:Number(te),publicUrl:C};if(V.current||!H||!_||!I||L||_.busy||_.installation?.installed||!j(e))return;V.current=!0,B.current?.abort(),ie(!0),P(!1),o(``);let t=new AbortController;B.current=t;try{let n=await S(`/api/device-center/setup`,{body:{...e,allowRegistration:!0},signal:t.signal});if(n.status===409){v(e=>e&&{...e,busy:!0}),V.current=!1,ie(!1),await U();return}if(!n.ok){let e=await x(n);throw Error(e.error.slice(0,4096))}let r=await n.json();if(!j({...e,publicUrl:r.publicUrl})||typeof r.output!=`string`)throw Error();t.signal.aborted||z(r)}catch(e){t.signal.aborted||(P(!0),o(e instanceof Error?e.message.slice(0,4096):``))}finally{V.current=!1,t.signal.aborted||ie(!1)}},G=async()=>{if(V.current||!H||!_||!I||L||_.busy||D||A)return;V.current=!0,B.current?.abort(),ae(!0),P(!1),o(``),se(null);let e=new AbortController;B.current=e;try{let t=await S(`/api/device-center/setup/update`,{method:`POST`,signal:e.signal});if(!t.ok){let e=await x(t);throw Error(e.error.slice(0,4096))}let r=await t.json();e.signal.aborted||(se(r.output||n(`deviceSetupUpdateSuccess`)),await U())}catch(t){e.signal.aborted||(P(!0),o(t instanceof Error?t.message.slice(0,4096):``))}finally{V.current=!1,e.signal.aborted||ae(!1)}},K=_?.installation,q=!!K?.installed,J=q&&K.running&&K.owned,Y=h===`remote`?re:{host:y,port:Number(te),publicUrl:C},X=!!Y&&j(Y);return(0,k.jsxs)(`section`,{className:`dc-onboarding`,children:[(0,k.jsx)(`h3`,{children:n(`deviceSetupWelcome`)}),(0,k.jsx)(`p`,{children:n(`deviceSetupIntro`)}),(0,k.jsxs)(`div`,{className:`dc-actions`,children:[(0,k.jsx)(`button`,{className:`dc-button`,disabled:D,"aria-pressed":p===`connect`,onClick:()=>m(`connect`),children:n(`deviceSetupConnect`)}),(0,k.jsx)(`button`,{className:`dc-button`,disabled:D,"aria-pressed":p===`create`,onClick:()=>{m(`create`),!_&&H&&U()},children:n(`deviceSetupCreate`)})]}),p===`connect`&&(0,k.jsxs)(`form`,{onSubmit:t=>{t.preventDefault(),e(r.trim())},children:[(0,k.jsxs)(`label`,{className:`dc-field`,children:[(0,k.jsx)(`span`,{children:n(`deviceHubHubUrl`)}),(0,k.jsx)(`input`,{type:`url`,required:!0,maxLength:2048,value:r,onChange:e=>i(e.target.value),placeholder:`https://hub.example.com`})]}),(0,k.jsx)(`button`,{className:`dc-button is-primary`,disabled:!j({host:`localhost`,port:8790,publicUrl:r.trim()}),children:n(`deviceSetupPair`)})]}),p===`create`&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`label`,{className:`dc-field`,children:[(0,k.jsx)(`span`,{children:n(`deviceSetupTarget`)}),(0,k.jsxs)(`select`,{disabled:D,value:h,onChange:e=>g(e.target.value),children:[(0,k.jsx)(`option`,{value:`current`,children:n(`deviceSetupCurrent`)}),(0,k.jsx)(`option`,{value:`remote`,children:n(`deviceSetupRemote`)})]})]}),(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`p`,{children:n(h===`current`?`deviceSetupCurrentHint`:`deviceSetupRemoteHint`)}),h===`current`&&(0,k.jsxs)(`div`,{className:`dc-setup-plan`,children:[(0,k.jsx)(`strong`,{children:n(`deviceSetupPlan`)}),(0,k.jsx)(`p`,{children:n(`deviceSetupPlanHint`)}),_&&(0,k.jsxs)(`dl`,{children:[(0,k.jsx)(`dt`,{children:n(`deviceSetupEnvironment`)}),(0,k.jsxs)(`dd`,{children:[_.platform,` · Node `,_.nodeVersion]}),(0,k.jsx)(`dt`,{children:n(`deviceSetupDataDir`)}),(0,k.jsx)(`dd`,{children:_.dataDir}),(0,k.jsx)(`dt`,{children:n(`deviceSetupCli`)}),(0,k.jsx)(`dd`,{children:_.cliPath})]}),!H&&(0,k.jsx)(`p`,{role:`status`,children:n(`deviceSetupLocalOnly`)}),(0,k.jsx)(`p`,{children:n(`deviceSetupBackground`)}),q&&(0,k.jsxs)(`div`,{role:`status`,children:[(0,k.jsx)(`h4`,{children:n(J?`deviceSetupRestored`:`deviceSetupUnhealthy`)}),(0,k.jsx)(`p`,{children:K.publicUrl}),J&&X&&K.publicUrl?(0,k.jsxs)(`div`,{className:`dc-actions`,children:[(0,k.jsx)(oe,{href:K.publicUrl,children:n(`deviceHubOpenHub`)}),(0,k.jsx)(`button`,{className:`dc-button`,onClick:()=>e(K.publicUrl),children:n(`deviceSetupPair`)}),H&&(0,k.jsx)(`button`,{className:`dc-button`,disabled:D||A,onClick:()=>void G(),children:n(A?`deviceSetupUpdating`:`deviceSetupUpdate`)})]}):(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`p`,{children:n(`deviceSetupRecovery`)}),(0,k.jsx)(`pre`,{className:`dc-setup-output`,children:`pi-web-ui hub status --json
|
|
3
3
|
pi-web-ui hub --help`}),H&&(0,k.jsx)(`button`,{className:`dc-button is-primary`,disabled:D||A,onClick:()=>void G(),children:n(A?`deviceSetupUpdating`:`deviceSetupUpdate`)})]}),M&&(0,k.jsx)(`pre`,{className:`dc-setup-output`,children:M.slice(0,16e3)})]}),_?.busy&&(0,k.jsx)(`p`,{role:`status`,children:n(`deviceSetupBusy`)}),H&&(0,k.jsx)(`button`,{className:`dc-button`,disabled:D||!I,onClick:()=>void U(),children:n(I?`deviceSetupRetry`:`deviceHubWorking`)})]}),h===`remote`?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:`dc-setup-fields`,children:[(0,k.jsxs)(`label`,{className:`dc-field`,children:[(0,k.jsx)(`span`,{children:n(`deviceSetupServer`)}),(0,k.jsx)(`input`,{autoComplete:`off`,maxLength:253,placeholder:`203.0.113.10`,value:T.server,onChange:e=>E({...T,server:e.target.value.trim()})})]}),(0,k.jsxs)(`label`,{className:`dc-field`,children:[(0,k.jsx)(`span`,{children:n(`deviceSetupSshPort`)}),(0,k.jsx)(`input`,{type:`number`,min:1,max:65535,value:T.sshPort,onChange:e=>E({...T,sshPort:Number(e.target.value)})})]}),(0,k.jsxs)(`label`,{className:`dc-field`,children:[(0,k.jsx)(`span`,{children:n(`deviceSetupUsername`)}),(0,k.jsx)(`input`,{autoComplete:`off`,maxLength:64,value:T.username,onChange:e=>E({...T,username:e.target.value})})]}),(0,k.jsxs)(`label`,{className:`dc-field`,children:[(0,k.jsx)(`span`,{children:n(`deviceSetupAuth`)}),(0,k.jsxs)(`select`,{value:T.auth,onChange:e=>E({...T,auth:e.target.value}),children:[(0,k.jsx)(`option`,{value:`password`,children:n(`deviceSetupAuthPassword`)}),(0,k.jsx)(`option`,{value:`key`,children:n(`deviceSetupAuthKey`)}),(0,k.jsx)(`option`,{value:`existing`,children:n(`deviceSetupAuthExisting`)})]})]}),(0,k.jsxs)(`label`,{className:`dc-field`,children:[(0,k.jsx)(`span`,{children:n(`deviceSetupServicePort`)}),(0,k.jsx)(`input`,{type:`number`,min:1024,max:65535,value:T.port,onChange:e=>E({...T,port:Number(e.target.value)})})]})]}),(0,k.jsx)(`p`,{children:n(`deviceSetupCredentialHint`)}),(0,k.jsxs)(`details`,{children:[(0,k.jsx)(`summary`,{children:n(`deviceSetupOptionalTls`)}),(0,k.jsxs)(`label`,{className:`dc-field`,children:[(0,k.jsx)(`span`,{children:n(`deviceSetupDomain`)}),(0,k.jsx)(`input`,{maxLength:253,placeholder:`hub.example.com`,value:T.domain,onChange:e=>E({...T,domain:e.target.value.trim()})})]}),(0,k.jsxs)(`label`,{children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:T.https,onChange:e=>E({...T,https:e.target.checked})}),` `,n(`deviceSetupEnableHttps`)]}),(0,k.jsx)(`p`,{children:n(`deviceSetupTlsHint`)})]}),(0,k.jsxs)(`p`,{children:[(0,k.jsx)(`strong`,{children:n(`deviceSetupPreview`)}),` `,re?.publicUrl??n(`deviceSetupPreviewEmpty`)]}),(0,k.jsxs)(`div`,{className:`dc-setup-plan`,children:[(0,k.jsx)(`strong`,{children:n(`deviceSetupUserActions`)}),(0,k.jsx)(`p`,{children:n(`deviceSetupCloudPorts`).replace(`{ports}`,T.https?`443 / 80`:String(T.port))}),(0,k.jsx)(`p`,{children:n(`deviceSetupSourceScope`)}),(0,k.jsx)(`p`,{children:n(`deviceSetupAfterStart`)})]}),(0,k.jsx)(`a`,{href:`https://github.com/xing-shuyin/keel/blob/main/docs/device-center-deployment.md`,target:`_blank`,rel:`noopener noreferrer`,children:n(`deviceSetupGuide`)})]}):(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:`dc-setup-fields`,children:[(0,k.jsxs)(`label`,{className:`dc-field`,children:[(0,k.jsx)(`span`,{children:n(`deviceSetupHost`)}),(0,k.jsx)(`input`,{disabled:D||!!R,maxLength:253,value:y,onChange:e=>b(e.target.value)})]}),(0,k.jsxs)(`label`,{className:`dc-field`,children:[(0,k.jsx)(`span`,{children:n(`deviceSetupPort`)}),(0,k.jsx)(`input`,{disabled:D||!!R,type:`number`,min:1024,max:65535,value:te,onChange:e=>ne(e.target.value)})]}),(0,k.jsxs)(`label`,{className:`dc-field`,children:[(0,k.jsx)(`span`,{children:n(`deviceHubHubUrl`)}),(0,k.jsx)(`input`,{disabled:D||!!R,maxLength:2048,value:C,onChange:e=>w(e.target.value)})]})]}),(0,k.jsx)(`p`,{className:`dc-setup-warning`,children:n(`deviceSetupReachable`)})]}),(0,k.jsx)(`p`,{children:n(`deviceSetupRegistration`)}),!X&&(0,k.jsx)(`p`,{role:`alert`,children:n(h===`remote`?`deviceSetupRemoteInvalid`:`deviceSetupInvalid`)}),(0,k.jsxs)(`div`,{className:`dc-actions`,children:[h===`current`&&!R&&!q&&(0,k.jsx)(`button`,{className:`dc-button is-primary`,disabled:D||!H||!_||!I||L||!!_.busy||!X,onClick:()=>void W(),children:n(D?`deviceSetupInstalling`:`deviceSetupInstall`)}),(0,k.jsx)(`button`,{className:`dc-button`,disabled:D||s||!X,onClick:()=>{if(!X||!Y||d.current)return;d.current=!0,c(!0),u(!1);let e=e=>{d.current=!1,f.current&&(c(!1),u(!e))},t=window.__piWebUiHost;try{t?.startChat({newChat:!0,prompt:le(Y,_,h,h===`remote`?T:void 0),onResult:e})||e(!1)}catch{e(!1)}},children:n(h===`remote`?`deviceSetupStartAi`:`deviceSetupAi`)})]}),(0,k.jsx)(`p`,{children:n(`deviceSetupAiHint`)}),s&&(0,k.jsx)(`p`,{role:`status`,children:n(`deviceSetupAiCreating`)}),l&&(0,k.jsx)(`p`,{role:`alert`,children:n(`deviceSetupAiFailed`)})]})]}),ce&&(0,k.jsxs)(`div`,{role:`alert`,children:[(0,k.jsx)(`p`,{children:n(`deviceSetupFailed`)}),a&&(0,k.jsx)(`pre`,{className:`dc-setup-output`,children:a})]}),R&&(0,k.jsxs)(`div`,{role:`status`,children:[(0,k.jsx)(`h4`,{children:n(`deviceSetupSuccess`)}),(0,k.jsx)(`pre`,{className:`dc-setup-output`,children:R.output.slice(0,16e3)}),(0,k.jsxs)(`div`,{className:`dc-actions`,children:[(0,k.jsx)(oe,{href:R.publicUrl,children:n(`deviceHubOpenHub`)}),(0,k.jsx)(`button`,{className:`dc-button is-primary`,onClick:()=>e(R.publicUrl),children:n(`deviceSetupPair`)})]})]})]})}var ue=y(),L=`pi-web-ui:device-groups-changed`;function de(e){window.dispatchEvent(new CustomEvent(`pi-web-ui:device-group-open`,{detail:{roomId:e}}))}async function R(e,t,n){return te(`/api/device-center/${e}`,{body:n,signal:t})}function z({bindingKey:e=``}){return(0,k.jsx)(B,{},e)}function B(){let e=ee(),[n,r]=(0,O.useState)([]),[o,c]=(0,O.useState)([]),[l,f]=(0,O.useState)(!0),[p,m]=(0,O.useState)(``),[g,v]=(0,O.useState)(``),[y,b]=(0,O.useState)(0),[te,x]=(0,O.useState)(!1),[S,ne]=(0,O.useState)(``),[C,w]=(0,O.useState)([]),[T,E]=(0,O.useState)(``),[ie,A]=(0,O.useState)(null),[ae,oe]=(0,O.useState)(``),[j,M]=(0,O.useState)([]),[N,se]=(0,O.useState)(``),[ce,P]=(0,O.useState)(null),[F,le]=(0,O.useState)(``),[I,z]=(0,O.useState)(!1),[B,V]=(0,O.useState)(null),H=n.find(e=>e.id===B?.roomId),U=(0,O.useRef)(0),W=(0,O.useRef)(null),G=(0,O.useRef)(null);function K(){++U.current,W.current?.abort(),b(e=>e+1)}function q(){G.current?.abort();let e=new AbortController;return G.current=e,e}(0,O.useEffect)(()=>()=>G.current?.abort(),[]),(0,O.useEffect)(()=>{let e=++U.current,t=new AbortController;W.current=t;async function n(){try{let[n,i]=await Promise.all([R(`rooms`,t.signal),R(`bots`,t.signal)]);if(U.current!==e||t.signal.aborted)return;let a=Array.isArray(n.rooms)?n.rooms:[];r(a),V(e=>e&&a.some(t=>t.id===e.roomId)?e:null),c(Array.isArray(i.bots)?i.bots:[]),m(``)}catch(n){U.current===e&&!t.signal.aborted&&m(n instanceof Error?n.message:String(n))}finally{U.current===e&&!t.signal.aborted&&f(!1)}}return n(),()=>{t.abort()}},[y]),(0,O.useEffect)(()=>{let e=()=>K();return window.addEventListener(L,e),()=>window.removeEventListener(L,e)},[]);async function J(t){if(t.preventDefault(),!S.trim()||I)return;z(!0),m(``),v(``);let n=q();try{let t=C.includes(T)?T:``,i=await R(`rooms`,n.signal,{name:S.trim(),botIds:C,...t?{primaryBotId:t}:{}});if(n.signal.aborted)return;r(e=>[...e.filter(e=>e.id!==i.room.id),i.room]),x(!1),ne(``),w([]),E(``),v(e(`deviceGroupManagerCreateSuccess`)),window.dispatchEvent(new CustomEvent(L))}catch(e){n.signal.aborted||m(e instanceof Error?e.message:String(e))}finally{n.signal.aborted||z(!1)}}function Y(e){A(e.id),oe(e.name),M([...e.botIds]),se(e.primaryBotId??``),P(null),x(!1),m(``),v(``)}function X(){A(null)}async function Z(t){if(I)return;let i=n.find(e=>e.id===t);if(!i)return;let a=ae.trim();if(!a)return;z(!0),m(``),v(``);let o=q();try{if(a!==i.name&&(await R(`rooms/${encodeURIComponent(t)}/rename`,o.signal,{name:a}),o.signal.aborted))return;let n=j.includes(N)?N:null,s=await R(`rooms/${encodeURIComponent(t)}/members`,o.signal,{botIds:j,primaryBotId:n});if(o.signal.aborted)return;let c={...s.room,name:a};r(e=>e.map(e=>e.id===t?c:e)),X(),v(e(`deviceGroupManagerMembersSaved`)),window.dispatchEvent(new CustomEvent(L))}catch(e){o.signal.aborted||m(e instanceof Error?e.message:String(e))}finally{o.signal.aborted||z(!1)}}async function Q(t){if(!F.trim()||I)return;z(!0),m(``),v(``);let n=q();try{if(await R(`rooms/${encodeURIComponent(t)}/rename`,n.signal,{name:F.trim()}),n.signal.aborted)return;r(e=>e.map(e=>e.id===t?{...e,name:F.trim()}:e)),P(null),v(e(`deviceGroupManagerRenameSuccess`)),window.dispatchEvent(new CustomEvent(L))}catch(e){n.signal.aborted||m(e instanceof Error?e.message:String(e))}finally{n.signal.aborted||z(!1)}}async function fe(t){if(I||!window.confirm(e(`deviceGroupManagerDeleteConfirm`,{name:t.name})))return;z(!0),m(``),v(``);let n=q();try{if(await R(`rooms/${encodeURIComponent(t.id)}/delete`,n.signal,{}),n.signal.aborted)return;V(e=>e?.roomId===t.id?null:e),r(e=>e.filter(e=>e.id!==t.id)),ie===t.id&&X(),ce===t.id&&P(null),v(e(`deviceGroupManagerDeleteSuccess`)),window.dispatchEvent(new CustomEvent(L))}catch(e){n.signal.aborted||m(e instanceof Error?e.message:String(e))}finally{n.signal.aborted||z(!1)}}return(0,k.jsxs)(`section`,{className:`dc-card`,"aria-label":e(`deviceGroupManagerTitle`),children:[(0,k.jsxs)(`div`,{className:`dc-card-header`,children:[(0,k.jsx)(`span`,{className:`dc-icon`,children:(0,k.jsx)(u,{"aria-hidden":!0})}),(0,k.jsxs)(`div`,{children:[(0,k.jsxs)(`h2`,{children:[e(`deviceGroupManagerTitle`),` · `,n.length]}),(0,k.jsx)(`p`,{children:e(`deviceGroupManagerDescription`)})]}),(0,k.jsxs)(`div`,{className:`dc-actions`,style:{marginInlineStart:`auto`},children:[(0,k.jsxs)(`button`,{type:`button`,className:`dc-button is-primary`,disabled:I,onClick:()=>{x(e=>!e),A(null),P(null),ne(``),w([]),E(``)},children:[(0,k.jsx)(s,{"aria-hidden":!0}),e(`deviceGroupManagerCreate`)]}),(0,k.jsx)(`button`,{type:`button`,className:`dc-icon-button`,"aria-label":e(`deviceGroupManagerRefresh`),onClick:K,children:(0,k.jsx)(i,{})})]})]}),p&&(0,k.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:p}),g&&(0,k.jsxs)(`p`,{className:`dc-notice is-success`,role:`status`,children:[(0,k.jsx)(d,{"aria-hidden":!0}),g]}),te&&(0,k.jsxs)(`form`,{className:`dc-card`,style:{marginBottom:`16px`,background:`var(--bg)`,border:`1px solid var(--border)`},onSubmit:J,children:[(0,k.jsxs)(`div`,{className:`dg-heading`,style:{marginBottom:`12px`},children:[(0,k.jsx)(`h3`,{children:e(`deviceGroupManagerCreate`)}),(0,k.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>x(!1),disabled:I,children:[(0,k.jsx)(h,{"aria-hidden":!0}),e(`close`)]})]}),(0,k.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`12px`},children:[(0,k.jsx)(`label`,{htmlFor:`dg-manager-new-name`,children:e(`deviceGroupManagerNameLabel`)}),(0,k.jsx)(`input`,{id:`dg-manager-new-name`,type:`text`,required:!0,maxLength:80,value:S,placeholder:e(`deviceGroupManagerNamePlaceholder`),onChange:e=>ne(e.target.value),disabled:I,style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`}})]}),(0,k.jsxs)(`div`,{style:{marginBottom:`12px`},children:[(0,k.jsx)(`label`,{style:{display:`block`,marginBottom:`6px`,fontSize:`12px`,color:`var(--text-dim)`},children:e(`deviceGroupManagerSelectMembers`)}),(0,k.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`6px`,maxHeight:`160px`,overflowY:`auto`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`8px`,background:`var(--bg-elev)`},children:o.length===0?(0,k.jsx)(`p`,{style:{margin:0,fontSize:`12px`,color:`var(--text-faint)`},children:e(`deviceGroupManagerNoBotsCreate`)}):o.map(t=>(0,k.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,cursor:`pointer`,fontSize:`12px`},children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:C.includes(t.id),disabled:I||!t.enabled,onChange:e=>{w(n=>e.target.checked?[...n,t.id]:n.filter(e=>e!==t.id))}}),(0,k.jsxs)(`span`,{children:[(0,k.jsx)(`strong`,{children:t.name}),(0,k.jsxs)(`small`,{style:{color:`var(--text-faint)`,marginInlineStart:`6px`},children:[t.online?e(`deviceHubOnline`):e(`deviceHubOffline`),t.enabled?``:e(`deviceGroupManagerDisabledSuffix`)]})]})]},t.id))})]}),C.length>0&&(0,k.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`16px`},children:[(0,k.jsx)(`label`,{htmlFor:`dg-manager-new-primary`,children:e(`deviceGroupManagerLegacyPrimary`)}),(0,k.jsxs)(`select`,{id:`dg-manager-new-primary`,value:C.includes(T)?T:``,onChange:e=>E(e.target.value),disabled:I,style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`},children:[(0,k.jsx)(`option`,{value:``,children:e(`deviceGroupManagerNoPrimary`)}),o.filter(e=>C.includes(e.id)).map(e=>(0,k.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,k.jsxs)(`div`,{className:`dc-actions`,children:[(0,k.jsxs)(`button`,{type:`submit`,className:`dc-button is-primary`,disabled:I||!S.trim(),children:[(0,k.jsx)(d,{"aria-hidden":!0}),e(I?`deviceGroupManagerCreating`:`deviceGroupManagerCreateSubmit`)]}),(0,k.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>x(!1),disabled:I,children:e(`cancel`)})]})]}),(()=>{let t=ie;if(!t)return null;let r=n.find(e=>e.id===t);return(0,ue.createPortal)((0,k.jsx)(`div`,{className:`modal-backdrop`,onClick:()=>{I||X()},children:(0,k.jsxs)(`div`,{className:`dc-card device-group-create-dialog`,role:`dialog`,"aria-modal":`true`,"aria-label":`${e(`edit`)} · ${r?.name??t}`,onClick:e=>e.stopPropagation(),style:{minWidth:`min(480px, 92vw)`},children:[(0,k.jsxs)(`div`,{className:`dg-heading`,style:{marginBottom:`12px`},children:[(0,k.jsxs)(`h3`,{children:[e(`edit`),` · `,r?.name??t]}),(0,k.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>X(),disabled:I,children:[(0,k.jsx)(h,{"aria-hidden":!0}),e(`close`)]})]}),r?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`12px`},children:[(0,k.jsx)(`label`,{htmlFor:`dg-manager-edit-name`,children:e(`deviceGroupManagerNameLabel`)}),(0,k.jsx)(`input`,{id:`dg-manager-edit-name`,type:`text`,maxLength:80,value:ae,onChange:e=>oe(e.target.value),disabled:I,placeholder:e(`deviceGroupManagerRenamePlaceholder`),style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`}})]}),(0,k.jsxs)(`div`,{style:{marginBottom:`12px`},children:[(0,k.jsx)(`label`,{style:{display:`block`,marginBottom:`6px`,fontSize:`12px`,color:`var(--text-dim)`},children:e(`deviceGroupManagerSelectMembers`)}),(0,k.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`6px`,maxHeight:`220px`,overflowY:`auto`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`8px`,background:`var(--bg-elev)`},children:o.length===0?(0,k.jsx)(`p`,{style:{margin:0,fontSize:`12px`,color:`var(--text-faint)`},children:e(`deviceGroupManagerNoBots`)}):o.map(t=>(0,k.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,cursor:`pointer`,fontSize:`12px`},children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:j.includes(t.id),disabled:I,onChange:e=>{M(n=>e.target.checked?[...n,t.id]:n.filter(e=>e!==t.id))}}),(0,k.jsxs)(`span`,{children:[(0,k.jsx)(`strong`,{children:t.name}),(0,k.jsxs)(`small`,{style:{color:`var(--text-faint)`,marginInlineStart:`6px`},children:[t.online?e(`deviceHubOnline`):e(`deviceHubOffline`),t.enabled?``:e(`deviceGroupManagerDisabledSuffix`)]})]})]},t.id))})]}),!r.router?.enabled&&(0,k.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`16px`},children:[(0,k.jsx)(`label`,{htmlFor:`dg-manager-edit-primary`,children:e(`deviceGroupManagerLegacyPrimary`)}),(0,k.jsxs)(`select`,{id:`dg-manager-edit-primary`,value:j.includes(N)?N:``,onChange:e=>se(e.target.value),disabled:I,style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`},children:[(0,k.jsx)(`option`,{value:``,children:e(`deviceGroupManagerNoPrimary`)}),o.filter(e=>j.includes(e.id)).map(e=>(0,k.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,k.jsxs)(`div`,{className:`dc-actions`,children:[(0,k.jsxs)(`button`,{type:`button`,className:`dc-button is-primary`,disabled:I||!ae.trim(),onClick:()=>void Z(t),children:[(0,k.jsx)(d,{"aria-hidden":!0}),e(I?`saving`:`deviceGroupManagerSaveMembers`)]}),(0,k.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>X(),disabled:I,children:e(`cancel`)})]})]}):(0,k.jsx)(`p`,{role:`status`,children:e(`loading`)})]})}),document.body)})(),l&&(0,k.jsx)(`p`,{role:`status`,children:e(`loading`)}),!l&&n.length===0&&(0,k.jsx)(`p`,{style:{color:`var(--text-faint)`,fontSize:`13px`,padding:`12px 0`},children:e(`deviceGroupManagerEmpty`)}),(0,k.jsx)(`div`,{className:`dd-list`,children:n.map(n=>{let r=ce===n.id,i=o.filter(e=>n.botIds.includes(e.id)),s=o.find(e=>e.id===n.primaryBotId);return(0,k.jsxs)(`div`,{className:`dd-device`,style:r?{flexWrap:`wrap`}:void 0,children:[(0,k.jsx)(`span`,{className:`dc-device-icon`,children:(0,k.jsx)(u,{"aria-hidden":!0})}),(0,k.jsxs)(`div`,{className:`dd-identity`,style:{flex:1,minWidth:`200px`},children:[(0,k.jsx)(`strong`,{children:n.name}),(0,k.jsxs)(`span`,{style:{display:`flex`,gap:`8px`,flexWrap:`wrap`,alignItems:`center`},children:[(0,k.jsx)(`span`,{children:e(`deviceGroupManagerBotCount`,{count:n.botIds.length,members:i.length?`: ${i.map(e=>e.name).join(`, `)}`:``})}),n.router?.enabled&&(0,k.jsxs)(`span`,{children:[`AI Router · `,n.router.deviceId,` · `,n.router.model,` · `,n.router.thinkingLevel]}),!n.router?.enabled&&s&&(0,k.jsx)(`span`,{style:{color:`var(--accent)`},children:e(`deviceGroupManagerPrimaryBadge`,{name:s.name})})]})]}),(0,k.jsxs)(`div`,{className:`dc-actions`,children:[(0,k.jsxs)(`button`,{type:`button`,className:`dc-button is-primary`,title:e(`deviceGroupManagerOpenChat`),onClick:()=>de(n.id),children:[(0,k.jsx)(_,{"aria-hidden":!0}),e(`deviceGroupManagerOpenChat`)]}),(0,k.jsx)(`button`,{type:`button`,className:`dc-button`,"aria-expanded":B?.roomId===n.id&&B.kind===`router`,onClick:()=>V({roomId:n.id,kind:`router`}),children:`AI Router`}),(0,k.jsx)(`button`,{type:`button`,className:`dc-button`,"aria-expanded":B?.roomId===n.id&&B.kind===`work`,onClick:()=>V({roomId:n.id,kind:`work`}),children:e(`deviceGroupManagerWorkItems`)}),(0,k.jsxs)(`button`,{type:`button`,className:`dc-button`,title:e(`edit`),onClick:()=>Y(n),children:[(0,k.jsx)(u,{"aria-hidden":!0}),e(`edit`)]}),(0,k.jsxs)(`button`,{type:`button`,className:`dc-button`,title:e(`deviceGroupManagerRename`),onClick:()=>{r?P(null):(P(n.id),le(n.name))},children:[(0,k.jsx)(a,{"aria-hidden":!0}),e(`deviceGroupManagerRename`)]}),(0,k.jsx)(`button`,{type:`button`,className:`dc-button is-danger`,title:e(`deviceGroupManagerDelete`),disabled:I,onClick:()=>void fe(n),children:(0,k.jsx)(t,{"aria-hidden":!0})})]}),r&&(0,k.jsxs)(`form`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,width:`100%`,paddingTop:`8px`,paddingBottom:`4px`},onSubmit:e=>{e.preventDefault(),Q(n.id)},children:[(0,k.jsx)(`input`,{type:`text`,maxLength:80,autoFocus:!0,disabled:I,value:F,onChange:e=>le(e.target.value),placeholder:e(`deviceGroupManagerRenamePlaceholder`),style:{flex:1,minWidth:`180px`,background:`var(--bg)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`12px`}}),(0,k.jsxs)(`button`,{type:`submit`,className:`dc-button is-primary`,disabled:I||!F.trim(),children:[(0,k.jsx)(d,{"aria-hidden":!0}),e(`save`)]}),(0,k.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:I,onClick:()=>P(null),children:[(0,k.jsx)(h,{"aria-hidden":!0}),e(`cancel`)]})]})]},n.id)})}),H&&B&&(0,k.jsxs)(`section`,{className:`dc-card`,"aria-label":e(`deviceGroupManagerSettingsAria`),children:[(0,k.jsxs)(`div`,{className:`dg-heading`,children:[(0,k.jsx)(`h3`,{children:H.name}),(0,k.jsxs)(`div`,{className:`dc-actions`,children:[(0,k.jsx)(`button`,{type:`button`,className:`dc-button${B.kind===`router`?` is-primary`:``}`,"aria-pressed":B.kind===`router`,onClick:()=>V({roomId:H.id,kind:`router`}),children:`AI Router`}),(0,k.jsx)(`button`,{type:`button`,className:`dc-button${B.kind===`work`?` is-primary`:``}`,"aria-pressed":B.kind===`work`,onClick:()=>V({roomId:H.id,kind:`work`}),children:e(`deviceGroupManagerWorkItems`)}),(0,k.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>V(null),children:[(0,k.jsx)(h,{"aria-hidden":!0}),e(`close`)]})]})]}),B.kind===`router`?(0,k.jsx)(re,{roomId:H.id,router:H.router,disabled:I,onSaved:K},H.id):(0,k.jsx)(D,{roomId:H.id,disabled:I},H.id)]})]})}var V=class extends Error{status;constructor(e,t){super(t),this.status=e}};function H(e){try{let t=new URL(e);return[`http:`,`https:`].includes(t.protocol)&&!t.username&&!t.password?t.href:null}catch{return null}}function U(){let e=ee(),[t,a]=(0,O.useState)(null),[o,s]=(0,O.useState)(!1),[c,l]=(0,O.useState)(!1),[u,d]=(0,O.useState)(!1),[f,p]=(0,O.useState)(!1),h=(0,O.useRef)(0),g=(0,O.useRef)(null);async function _(e,t){if(g.current)return;let n=++h.current,i=new AbortController;g.current=i,s(!0),l(!1);try{let o=await fetch(r(m(`/api/device-desktop/local/${e}`)),{method:t?`POST`:`GET`,credentials:`same-origin`,signal:i.signal,...t?{headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}:{}});if(h.current!==n||i.signal.aborted)return;if(o.status===403){d(!0),a(null);return}if(!o.ok)throw Error(`Request failed`);let s=await o.json();if(h.current!==n||i.signal.aborted)return;if(e===`permissions`){if(typeof s?.screen!=`boolean`||typeof s?.accessibility!=`boolean`)throw Error(`Invalid permission status`);a(e=>e&&{...e,permissions:{supported:!0,screen:s.screen,accessibility:s.accessibility}}),p(!0)}else{if(typeof s?.os!=`string`||typeof s.enabled!=`boolean`||typeof s.environmentEnabled!=`boolean`||typeof s.supported!=`boolean`)throw Error(`Invalid desktop status`);a(s)}}catch{h.current===n&&!i.signal.aborted&&l(!0)}finally{h.current===n&&!i.signal.aborted&&(g.current=null,s(!1))}}return(0,O.useEffect)(()=>(_(`status`),()=>{h.current++,g.current?.abort(),g.current=null}),[]),(0,k.jsxs)(`section`,{className:`dc-card`,"aria-label":e(`deviceCenterLocalDesktopTitle`),"aria-busy":o,children:[(0,k.jsxs)(`div`,{className:`dc-card-header`,children:[(0,k.jsx)(`span`,{className:`dc-icon`,children:(0,k.jsx)(n,{"aria-hidden":!0})}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`h2`,{children:e(`deviceCenterLocalDesktopTitle`)}),(0,k.jsx)(`p`,{children:e(`deviceCenterLocalDesktopHint`)})]})]}),u?(0,k.jsx)(`p`,{role:`status`,children:e(`deviceCenterLocalOnly`)}):(0,k.jsxs)(k.Fragment,{children:[t&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:`dc-permission-row`,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`h3`,{id:`dc-desktop-label`,children:e(`deviceCenterRemoteDesktopEnable`)}),(0,k.jsx)(`p`,{children:e(t.enabled?`deviceCenterRemoteDesktopEnabled`:`deviceCenterRemoteDesktopDisabled`)})]}),(0,k.jsx)(`button`,{type:`button`,className:`dc-toggle${t.enabled?` is-on`:``}`,role:`switch`,"aria-checked":t.enabled,"aria-labelledby":`dc-desktop-label`,disabled:o||t.environmentEnabled||!t.supported&&!t.enabled,onClick:()=>void _(`enable`,{enabled:!t.enabled}),children:(0,k.jsx)(`span`,{className:`dc-toggle-thumb`})})]}),!t.supported&&(0,k.jsx)(`p`,{children:e(`deviceCenterRemoteDesktopUnsupported`)}),t.environmentEnabled&&(0,k.jsx)(`p`,{children:e(`deviceCenterRemoteDesktopManaged`)}),t.os===`darwin`&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`p`,{children:e(`deviceCenterRemoteDesktopPermissionHint`)}),(0,k.jsxs)(`div`,{className:`dc-actions`,children:[(0,k.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:o||t.permissions?.supported===!1,onClick:()=>void _(`permissions`,{kind:`screen`}),children:e(`deviceCenterGrantScreenRecording`)}),(0,k.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:o||t.permissions?.supported===!1,onClick:()=>void _(`permissions`,{kind:`control`}),children:e(`deviceCenterGrantRemoteControl`)})]}),t.permissions?.screen===!0&&(0,k.jsx)(`p`,{children:e(`deviceCenterScreenRecordingGranted`)}),t.permissions?.accessibility===!0&&(0,k.jsx)(`p`,{children:e(`deviceCenterRemoteControlGranted`)}),f&&(0,k.jsx)(`p`,{role:`status`,children:e(`deviceCenterPermissionRequested`)})]})]}),c&&(0,k.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:e(`deviceCenterRemoteDesktopUpdateFailed`)}),(0,k.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:o,onClick:()=>void _(`status`),children:[(0,k.jsx)(i,{"aria-hidden":!0}),e(o?`deviceHubWorking`:`deviceCenterRefreshRemoteDesktop`)]})]})]})}function W({pathCompletions:e=[],plugins:t=[],pluginsEpoch:r=0}){let a=ee(),[s,m]=(0,O.useState)(`devices`),[h,_]=(0,O.useState)(null),[v,y]=(0,O.useState)(``),[b,x]=(0,O.useState)(``),[S,C]=(0,O.useState)(null),[w,re]=(0,O.useState)(Date.now()),[D,A]=(0,O.useState)(null),[j,M]=(0,O.useState)(``),[N,se]=(0,O.useState)(``),[ce,P]=(0,O.useState)(``),[F,le]=(0,O.useState)(!1),ue=(0,O.useRef)(!1),[L,de]=(0,O.useState)(!1),[R,B]=(0,O.useState)(!0),W=(0,O.useRef)(!1),G=(0,O.useRef)(0),K=(0,O.useRef)(new Set),q=(0,O.useRef)(!1),J=(0,O.useRef)(!1),Y=(0,O.useRef)(null),X=(0,O.useRef)(a);X.current=a,(0,O.useEffect)(()=>{let e=e=>{let t=e;t.detail?.deviceId&&Y.current?.deviceId===t.detail.deviceId&&(_(e=>e&&{...e,remark:t.detail.remark}),Y.current&&(Y.current.remark=t.detail.remark))};return window.addEventListener(`pi-web-ui:device-remark-updated`,e),()=>window.removeEventListener(`pi-web-ui:device-remark-updated`,e)},[]);async function Z(e,t){let n=new AbortController;K.current.add(n);try{return await te(`/api/device-center/${e}`,{body:t,signal:n.signal,errorFor:e=>new V(e.status,e.serverError||X.current(`deviceHubRequestFailed`,{status:e.status}))})}finally{K.current.delete(n)}}function Q(e){return W.current&&G.current===e}function fe(e){return e instanceof V&&e.status===403?(de(!0),X.current(`deviceHubLocalOnly`)):e instanceof Error?e.message:X.current(`deviceHubNetworkError`)}function pe(e){Y.current=e,_(e),J.current||(x(e.name),y(e.hubUrl??``))}async function me(){let e=G.current;try{let t=await Z(`status`);if(!Q(e)||q.current)return;pe(t),se(``),de(!1)}catch(t){Q(e)&&se(fe(t))}finally{Q(e)&&B(!1)}}(0,O.useEffect)(()=>{W.current=!0;let e=!1,t,n=async()=>{await me(),!e&&W.current&&(t=setTimeout(n,5e3))};return n(),()=>{e=!0,W.current=!1,G.current++,clearTimeout(t);for(let e of K.current)e.abort()}},[]),(0,O.useEffect)(()=>{if(!S)return;let e=G.current,t=!1,n,r=setInterval(()=>re(Date.now()),1e3),i=async()=>{if(!(t||!Q(e)||Date.now()>=S.expiresAt)){try{let n=await Z(`poll`,{});if(t||!Q(e))return;if(n.paired){let n=await Z(`status`);if(t||!Q(e))return;J.current=!1,pe(n),C(null),M(``),P(``);return}M(``)}catch(n){!t&&Q(e)&&M(`${X.current(`deviceHubPollError`)} ${fe(n)}`)}!t&&Q(e)&&(n=setTimeout(i,2e3))}};return n=setTimeout(i,2e3),()=>{t=!0,clearTimeout(n),clearInterval(r)}},[S]);async function he(){if(q.current)return;let e=H(v.trim());if(!e){M(a(`deviceHubInvalidUrl`));return}if(!b.trim()||b.trim().length>80){M(a(`deviceHubInvalidName`));return}let t=++G.current;q.current=!0,A(`pair`),M(``),P(``),C(null);try{let n=await Z(`pair`,{hubUrl:e,name:b.trim()});if(!Q(t))return;if(!n.code||!Number.isFinite(n.expiresAt)||!H(n.hubUrl))throw Error(a(`deviceHubPairError`));re(Date.now()),C(n)}catch(e){Q(t)&&M(`${a(`deviceHubPairError`)} ${fe(e)}`)}finally{Q(t)&&(q.current=!1,A(null))}}async function ge(){let e=Y.current;if(!e?.deviceId||q.current)return;let t=++G.current;q.current=!0,A(`permission`),M(``),P(``),pe({...e,allowExecution:!e.allowExecution});try{await Z(`execution`,{allowExecution:!e.allowExecution}),Q(t)&&P(a(`deviceHubSaved`))}catch(n){Q(t)&&(pe(e),M(`${a(`deviceHubPermissionError`)} ${fe(n)}`))}finally{Q(t)&&(q.current=!1,A(null))}}async function _e(){let e=Y.current;if(!e?.deviceId||q.current||!window.confirm(a(`deviceHubDisconnectConfirm`,{name:e.name})))return;let t=++G.current;q.current=!0,A(`disconnect`),M(``),P(``);try{if(await Z(`disconnect`,{}),!Q(t))return;J.current=!1,pe({name:e.name,allowExecution:!1,connected:!1}),C(null)}catch(e){Q(t)&&M(`${a(`deviceHubDisconnectError`)} ${fe(e)}`)}finally{Q(t)&&(q.current=!1,A(null))}}async function ve(){if(ue.current||D||!$||!h?.hubUrl||!window.confirm(a(`deviceHubConfirmUpgrade`)))return;let e=G.current;ue.current=!0,le(!0),M(``),P(``);try{let t=await Z(`upgrade-hub`,{});if(!t.ok)throw Error(`Hub upgrade was not accepted`);await ie(t.job,{isCurrent:()=>Q(e),poll:async e=>(await Z(`upgrade-hub-status`,{id:e})).job}),Q(e)&&(P(a(`deviceHubUpgradeSuccess`)),await me())}catch(t){Q(e)&&M(t instanceof Error?t.message:a(`deviceHubNetworkError`))}finally{ue.current=!1,Q(e)&&le(!1)}}async function ye(){if(!S)return;let e=G.current;try{await navigator.clipboard.writeText(S.code),Q(e)&&P(a(`deviceHubCopied`))}catch{Q(e)&&M(a(`deviceHubCopyFailed`))}}let $=!!h?.deviceId,be=H($?h?.hubUrl??``:S?.hubUrl??``),xe=Math.max(0,Math.ceil(((S?.expiresAt??0)-w)/1e3)),Se=`${Math.floor(xe/60)}:${String(xe%60).padStart(2,`0`)}`,Ce=be?(0,k.jsxs)(oe,{href:be,children:[(0,k.jsx)(c,{"aria-hidden":!0}),a(`deviceHubOpenHub`)]}):null;return(0,k.jsxs)(`section`,{className:`dc-page`,"aria-label":a(`deviceHubTitle`),children:[(0,k.jsxs)(`header`,{className:`dc-header`,children:[(0,k.jsxs)(`div`,{className:`dc-heading`,children:[(0,k.jsxs)(`span`,{className:`dc-eyebrow`,children:[(0,k.jsx)(n,{"aria-hidden":!0}),a(`deviceHubTitle`)]}),(0,k.jsx)(`h1`,{children:a(`deviceHubTitle`)}),(0,k.jsx)(`p`,{children:a(`deviceHubSubtitle`)})]}),(0,k.jsxs)(`div`,{className:`dc-actions`,children:[$&&Ce,(0,k.jsxs)(`span`,{className:`dc-status ${$?h?.connected?`is-online`:`is-offline`:`is-unpaired`}`,children:[(0,k.jsx)(`span`,{className:`dc-status-dot`}),a($?h?.connected?`deviceHubOnline`:`deviceHubOffline`:`deviceHubUnpaired`)]})]})]}),(0,k.jsxs)(`div`,{className:`dc-layout`,children:[(0,k.jsx)(`nav`,{className:`dc-sidebar`,"aria-label":a(`deviceCenterNavLabel`),children:[[`devices`,n,a(`deviceCenterNavDevices`)],[`groups`,u,a(`deviceCenterGroupsTitle`)],[`channels`,g,a(`deviceCenterExternalChannelsTitle`)]].map(([e,t,n])=>(0,k.jsxs)(`button`,{type:`button`,className:`dc-nav-item${s===e?` is-active`:``}`,"aria-pressed":s===e,onClick:()=>m(e),children:[(0,k.jsx)(t,{"aria-hidden":!0}),n]},e))}),(0,k.jsxs)(`main`,{className:`dc-content`,children:[R&&(0,k.jsxs)(`div`,{className:`dc-loading`,role:`status`,children:[(0,k.jsx)(i,{"aria-hidden":!0}),a(`deviceHubLoading`)]}),(L||N)&&(0,k.jsxs)(`div`,{className:`dc-notice is-error`,role:`alert`,children:[(0,k.jsx)(`span`,{children:L?a(`deviceHubLocalOnly`):`${a(`deviceHubStatusError`)} ${N}`}),(0,k.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>void me(),children:[(0,k.jsx)(i,{"aria-hidden":!0}),a(`deviceHubRetry`)]})]}),j&&!L&&(0,k.jsx)(`div`,{className:`dc-notice is-error`,role:`alert`,children:j}),ce&&(0,k.jsxs)(`div`,{className:`dc-notice is-success`,role:`status`,children:[(0,k.jsx)(d,{"aria-hidden":!0}),ce]}),s!==`devices`&&(!$||L)&&(0,k.jsxs)(`section`,{className:`dc-card`,children:[(0,k.jsx)(`h2`,{children:a(s===`groups`?`deviceCenterGroupsTitle`:`deviceCenterExternalChannelsTitle`)}),(0,k.jsx)(`p`,{children:a(`deviceCenterConnectFirstHint`)}),(0,k.jsx)(`button`,{type:`button`,className:`dc-button is-primary`,onClick:()=>m(`devices`),children:a(`deviceCenterGoConnectDevice`)})]}),s===`groups`&&$&&!L&&(0,k.jsx)(z,{},`groups:${h?.hubUrl??``}:${h?.deviceId??``}`),s===`channels`&&$&&!L&&(0,k.jsx)(ae,{plugin:t.find(e=>e.id===`superagent`),epoch:r,onManageGroups:()=>m(`groups`)},`channels:${h?.hubUrl??``}:${h?.deviceId??``}`),s===`devices`&&(0,k.jsxs)(k.Fragment,{children:[!$&&(h||L)&&(0,k.jsx)(I,{initialHubUrl:v,onConnect:e=>{if(L){P(a(`deviceHubLocalOnly`));return}J.current=!0,y(e)}}),h&&!L&&!$&&(0,k.jsxs)(`section`,{className:`dc-card`,children:[(0,k.jsxs)(`div`,{className:`dc-card-header`,children:[(0,k.jsx)(`span`,{className:`dc-icon`,children:(0,k.jsx)(f,{"aria-hidden":!0})}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`h2`,{children:a(`deviceHubPairTitle`)}),(0,k.jsx)(`p`,{children:a(`deviceHubPairHint`)})]})]}),(0,k.jsx)(`ol`,{className:`dc-steps`,children:[`deviceHubStepDetails`,`deviceHubStepApprove`,`deviceHubStepWait`].map((e,t)=>(0,k.jsxs)(`li`,{className:S?t===0?`is-complete`:`is-active`:t===0?`is-active`:``,children:[(0,k.jsx)(`span`,{className:`dc-step-number`,children:S&&t===0?(0,k.jsx)(d,{"aria-hidden":!0}):t+1}),(0,k.jsx)(`span`,{children:a(e)})]},e))}),(0,k.jsxs)(`form`,{className:`dc-form`,onSubmit:e=>{e.preventDefault(),he()},children:[(0,k.jsxs)(`div`,{className:`dc-field`,children:[(0,k.jsx)(`label`,{htmlFor:`dc-hub-url`,children:a(`deviceHubHubUrl`)}),(0,k.jsx)(`input`,{id:`dc-hub-url`,type:`url`,autoComplete:`url`,required:!0,placeholder:a(`deviceHubHubPlaceholder`),value:v,disabled:!!S||!!D,onChange:e=>{J.current=!0,y(e.target.value)}})]}),(0,k.jsxs)(`div`,{className:`dc-field`,children:[(0,k.jsx)(`label`,{htmlFor:`dc-device-name`,children:a(`deviceHubName`)}),(0,k.jsx)(`input`,{id:`dc-device-name`,maxLength:80,required:!0,autoComplete:`off`,placeholder:a(`deviceHubNamePlaceholder`),value:b,disabled:!!S||!!D,onChange:e=>{J.current=!0,x(e.target.value)}})]}),!S&&(0,k.jsx)(`div`,{className:`dc-actions`,children:(0,k.jsxs)(`button`,{className:`dc-button is-primary`,type:`submit`,disabled:!!D,children:[(0,k.jsx)(f,{"aria-hidden":!0}),a(D?`deviceHubWorking`:`deviceHubGetCode`)]})})]}),S&&(0,k.jsxs)(`div`,{className:`dc-pairing`,children:[(0,k.jsx)(`span`,{className:`dc-code-label`,children:a(`deviceHubCode`)}),(0,k.jsxs)(`div`,{className:`dc-code-row`,children:[(0,k.jsx)(`code`,{className:`dc-code`,children:S.code}),(0,k.jsx)(`button`,{className:`dc-icon-button`,type:`button`,"aria-label":a(`deviceHubCopy`),onClick:()=>void ye(),children:(0,k.jsx)(o,{"aria-hidden":!0})})]}),(0,k.jsx)(`div`,{className:`dc-pair-meta`,children:a(xe?`deviceHubExpires`:`deviceHubExpired`,{time:Se})}),(0,k.jsxs)(`div`,{className:`dc-actions`,children:[Ce,(0,k.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:!!D,onClick:()=>{++G.current,C(null),M(``),P(``)},children:[(0,k.jsx)(i,{"aria-hidden":!0}),a(`deviceHubNewCode`)]})]}),xe>0&&(0,k.jsxs)(`p`,{className:`dc-progress`,role:`status`,children:[(0,k.jsx)(i,{"aria-hidden":!0}),a(`deviceHubWaiting`)]})]})]}),$&&h&&!L&&(0,k.jsxs)(`section`,{className:`dc-card`,children:[(0,k.jsxs)(`div`,{className:`dc-device-summary`,children:[(0,k.jsx)(`span`,{className:`dc-device-icon`,children:(0,k.jsx)(n,{"aria-hidden":!0})}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`h2`,{children:h.remark?.trim()||h.name}),(0,k.jsx)(`p`,{children:h.remark?.trim()?`${h.name} · ${a(`deviceHubDeviceTitle`)}`:a(`deviceHubDeviceTitle`)})]})]}),(0,k.jsxs)(`dl`,{className:`dc-details`,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`dt`,{children:a(`deviceHubDeviceId`)}),(0,k.jsx)(`dd`,{children:h.deviceId})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`dt`,{children:a(`deviceHubHubUrl`)}),(0,k.jsx)(`dd`,{children:h.hubUrl})]})]}),(0,k.jsx)(`div`,{className:`dc-actions`,style:{marginTop:`1rem`},children:(0,k.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:F||!!D,onClick:()=>void ve(),children:[(0,k.jsx)(i,{className:F?`spin`:``,"aria-hidden":!0}),a(F?`deviceHubUpgrading`:`deviceHubUpgradeAction`)]})})]}),$&&h?.hubUrl&&h.deviceId&&!L&&(0,k.jsx)(T,{hubUrl:h.hubUrl,currentDeviceId:h.deviceId},`directory:${h.hubUrl}:${h.deviceId}`),!L&&(0,k.jsx)(ne,{},`bots:${h?.hubUrl??``}:${h?.deviceId??`unpaired`}`),(0,k.jsx)(U,{}),$&&h&&!L&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`section`,{className:`dc-card`,children:[(0,k.jsxs)(`div`,{className:`dc-card-header`,children:[(0,k.jsx)(`span`,{className:`dc-icon`,children:(0,k.jsx)(l,{"aria-hidden":!0})}),(0,k.jsx)(`div`,{children:(0,k.jsx)(`h2`,{children:a(`deviceHubPermissions`)})})]}),(0,k.jsxs)(`div`,{className:`dc-permission-row`,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`h3`,{id:`dc-permission-label`,children:a(`deviceHubPermissionLabel`)}),(0,k.jsx)(`p`,{id:`dc-permission-hint`,children:a(`deviceHubPermissionHint`)})]}),(0,k.jsx)(`button`,{type:`button`,className:`dc-toggle${h.allowExecution?` is-on`:``}`,role:`switch`,"aria-checked":h.allowExecution,"aria-labelledby":`dc-permission-label`,"aria-describedby":`dc-permission-hint`,disabled:!!D,onClick:()=>void ge(),children:(0,k.jsx)(`span`,{className:`dc-toggle-thumb`})})]}),(0,k.jsx)(`p`,{className:`dc-permission-state`,role:`status`,children:a(D===`permission`?`deviceHubSaving`:h.allowExecution?`deviceHubEnabled`:`deviceHubReadOnly`)})]}),(0,k.jsx)(E,{hubUrl:h?.hubUrl,deviceId:h?.deviceId,onNotice:P}),(0,k.jsxs)(`details`,{className:`dc-advanced`,children:[(0,k.jsx)(`summary`,{children:a(`deviceHubAdvanced`)}),(0,k.jsxs)(`div`,{className:`dc-danger-zone`,children:[(0,k.jsx)(`h3`,{children:a(`deviceHubDisconnect`)}),(0,k.jsx)(`p`,{children:a(`deviceHubDisconnectHint`)}),(0,k.jsx)(`button`,{type:`button`,className:`dc-button is-danger`,disabled:!!D,onClick:()=>void _e(),children:a(D===`disconnect`?`deviceHubWorking`:`deviceHubDisconnect`)})]})]})]}),(0,k.jsxs)(`aside`,{className:`dc-help`,children:[(0,k.jsx)(p,{className:`dc-help-icon`,"aria-hidden":!0}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`h3`,{children:a(`deviceHubHelpTitle`)}),(0,k.jsx)(`p`,{children:a(`deviceHubHelpText`)})]})]})]})]})]})]})}export{W as DeviceCenter};
|
package/web/dist/assets/{DeviceExecutionSettings-2hoZaBQ0.js → DeviceExecutionSettings-BjduyZOy.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Ft as t,It as n,L as r,Nt as i,Ut as a,Wt as o,Z as s,b as c,k as l,mt as u,r as d,sn as f,vn as p,xt as m}from"./fi-DjvtEEnZ.js";import{i as h,t as g}from"./react-CR5VJ85Q.js";import{a as _}from"./api-client-CGqoOWHJ.js";var v=e(h(),1),y=g(),b={maxActiveTasks:4,maxWaitingTasks:32,starvationThresholdMs:8e3,maxSkipsBeforeStarvation:3,maxDispatchDepth:8,maxDispatchBudget:16,allowBotMentions:!1,groupContextBytes:262144,groupRetentionLimit:2e3,fileSyncMaxBytes:104857600,fileSyncMaxFiles:1e3,fileSyncStagedBytes:1073741824,resourceLockDefaultTtlMs:18e5,blackboardMaxBytes:262144,taskReportExcerptBytes:131072,maxResourceLocksPerTask:128,botMentionBudgetPerTurn:3};function x(e,t,n,r){return typeof e==`number`&&Number.isFinite(e)?Math.max(t,Math.min(n,Math.round(e))):r}function S(e){if(!Number.isFinite(e)||e<=0)return`0 B`;let t=[`B`,`KiB`,`MiB`,`GiB`],n=0,r=e;for(;r>=1024&&n<t.length-1;)r/=1024,n++;return`${Number.isInteger(r)?r:r.toFixed(1)} ${t[n]}`}function C(e){return!Number.isFinite(e)||e<=0?`0 ms`:e<1e3?`${e} ms`:e<6e4?`${Math.round(e/1e3)} s`:`${(e/6e4).toFixed(1)} min`}function w(e){let t={settings:{...b},activeCount:0,waitingCount:0,blockedCount:0,running:[],waiting:[],blocked:[]};if(!e||typeof e!=`object`||Array.isArray(e))return t;let n=e,r=n.settings&&typeof n.settings==`object`&&!Array.isArray(n.settings)?n.settings:{},i={maxActiveTasks:x(r.maxActiveTasks,1,64,b.maxActiveTasks),maxWaitingTasks:x(r.maxWaitingTasks,0,1024,b.maxWaitingTasks),starvationThresholdMs:x(r.starvationThresholdMs,1e3,6e4,b.starvationThresholdMs),maxSkipsBeforeStarvation:x(r.maxSkipsBeforeStarvation,1,20,b.maxSkipsBeforeStarvation),maxDispatchDepth:x(r.maxDispatchDepth,1,64,b.maxDispatchDepth),maxDispatchBudget:x(r.maxDispatchBudget,1,256,b.maxDispatchBudget),allowBotMentions:typeof r.allowBotMentions==`boolean`?r.allowBotMentions:b.allowBotMentions,groupContextBytes:x(r.groupContextBytes,4096,2097152,b.groupContextBytes),groupRetentionLimit:x(r.groupRetentionLimit,50,2e4,b.groupRetentionLimit),fileSyncMaxBytes:x(r.fileSyncMaxBytes,1048576,10737418240,b.fileSyncMaxBytes),fileSyncMaxFiles:x(r.fileSyncMaxFiles,10,1e4,b.fileSyncMaxFiles),fileSyncStagedBytes:x(r.fileSyncStagedBytes,4194304,53687091200,b.fileSyncStagedBytes),resourceLockDefaultTtlMs:x(r.resourceLockDefaultTtlMs,6e4,864e5,b.resourceLockDefaultTtlMs),blackboardMaxBytes:x(r.blackboardMaxBytes,4096,4194304,b.blackboardMaxBytes),...typeof r.taskReportExcerptBytes==`number`?{taskReportExcerptBytes:r.taskReportExcerptBytes}:{},...typeof r.maxResourceLocksPerTask==`number`?{maxResourceLocksPerTask:r.maxResourceLocksPerTask}:{},...typeof r.botMentionBudgetPerTurn==`number`?{botMentionBudgetPerTurn:r.botMentionBudgetPerTurn}:{}},a=Array.isArray(n.running)?n.running:[],o=Array.isArray(n.waiting)?n.waiting:[],s=Array.isArray(n.blocked)?n.blocked:[];return{settings:i,activeCount:typeof n.activeCount==`number`?n.activeCount:a.length,waitingCount:typeof n.waitingCount==`number`?n.waitingCount:o.length,blockedCount:typeof n.blockedCount==`number`?n.blockedCount:s.length,running:a,waiting:o,blocked:s}}function T({hubUrl:e,deviceId:h,onNotice:g}){let T=p(),[E,D]=(0,v.useState)(null),[O,k]=(0,v.useState)(b),[A,j]=(0,v.useState)(!1),[M,N]=(0,v.useState)(!1),[P,F]=(0,v.useState)(null),[I,L]=(0,v.useState)(null),[R,z]=(0,v.useState)(null),B=(0,v.useRef)(!0),V=(0,v.useRef)(0),H=(0,v.useRef)(new Set),U=(0,v.useRef)(!1),W=(0,v.useRef)(!1),G=`${e??``}:${h??``}`,K=(0,v.useCallback)(async(e,t,n)=>{let r=new AbortController;H.current.add(r);let i=()=>r.abort();n&&(n.aborted?r.abort():n.addEventListener(`abort`,i,{once:!0}));try{return await _(`/api/device-center/${e}`,{body:t,signal:r.signal})}finally{n&&n.removeEventListener(`abort`,i),H.current.delete(r)}},[]),q=(0,v.useCallback)(async(e=!1)=>{if(!B.current||U.current)return;U.current=!0;let t=V.current;e||j(!0);try{let e=await K(`execution-queue`);if(!B.current||t!==V.current)return;let n=w(e);D(n),L(null),W.current||=(k({...n.settings}),!0)}catch(e){if(!B.current||t!==V.current)return;e.name!==`AbortError`&&L(e.message)}finally{U.current=!1,B.current&&t===V.current&&!e&&j(!1)}},[K]);(0,v.useEffect)(()=>{B.current=!0,V.current++;for(let e of H.current)e.abort();H.current.clear(),U.current=!1,W.current=!1,D(null),k({...b}),L(null),z(null),q(!1);let e=setInterval(()=>{q(!0)},3e3);return()=>{B.current=!1,V.current++;for(let e of H.current)e.abort();H.current.clear(),clearInterval(e)}},[G,q]);let J=(e,t)=>{k(n=>({...n,[e]:t}))},Y=(e,t)=>{k(n=>({...n,[e]:t}))},X=()=>{k({...b})},Z=()=>{E?.settings?k({...E.settings}):k({...b})},Q=async e=>{e.preventDefault();let t=V.current;N(!0),L(null),z(null);let n={maxActiveTasks:x(O.maxActiveTasks,1,64,b.maxActiveTasks),maxWaitingTasks:x(O.maxWaitingTasks,0,1024,b.maxWaitingTasks),starvationThresholdMs:x(O.starvationThresholdMs,1e3,6e4,b.starvationThresholdMs),maxSkipsBeforeStarvation:x(O.maxSkipsBeforeStarvation,1,20,b.maxSkipsBeforeStarvation),maxDispatchDepth:x(O.maxDispatchDepth,1,64,b.maxDispatchDepth),maxDispatchBudget:x(O.maxDispatchBudget,1,256,b.maxDispatchBudget),allowBotMentions:!!O.allowBotMentions,groupContextBytes:x(O.groupContextBytes,4096,2097152,b.groupContextBytes),groupRetentionLimit:x(O.groupRetentionLimit,50,2e4,b.groupRetentionLimit),fileSyncMaxBytes:x(O.fileSyncMaxBytes,1048576,10737418240,b.fileSyncMaxBytes),fileSyncMaxFiles:x(O.fileSyncMaxFiles,10,1e4,b.fileSyncMaxFiles),fileSyncStagedBytes:x(O.fileSyncStagedBytes,4194304,53687091200,b.fileSyncStagedBytes),resourceLockDefaultTtlMs:x(O.resourceLockDefaultTtlMs,6e4,864e5,b.resourceLockDefaultTtlMs),blackboardMaxBytes:x(O.blackboardMaxBytes,4096,4194304,b.blackboardMaxBytes),...O.taskReportExcerptBytes===void 0?{}:{taskReportExcerptBytes:O.taskReportExcerptBytes},...O.maxResourceLocksPerTask===void 0?{}:{maxResourceLocksPerTask:O.maxResourceLocksPerTask},...O.botMentionBudgetPerTurn===void 0?{}:{botMentionBudgetPerTurn:O.botMentionBudgetPerTurn}};try{let e=await K(`execution-settings`,n);if(!B.current||t!==V.current)return;e?.settings&&k({...e.settings}),z(T(`deviceExecSavedNotice`)),g?.(T(`deviceExecSavedNotice`)),await q(!0)}catch(e){if(!B.current||t!==V.current)return;e.name!==`AbortError`&&L(e.message)}finally{B.current&&t===V.current&&N(!1)}},$=async(e,t)=>{let n=V.current;F(e),L(null);try{if(await K(`execution-queue/cancel`,{taskId:e,attemptId:t}),!B.current||n!==V.current)return;g?.(T(`deviceExecTaskCancelled`)),await q(!0)}catch(e){if(!B.current||n!==V.current)return;e.name!==`AbortError`&&L(e.message)}finally{B.current&&n===V.current&&F(null)}},ee=e=>{switch(e){case`max_concurrency_reached`:return T(`deviceExecReasonMaxConcurrency`);case`bot_busy`:return T(`deviceExecReasonBotBusy`);case`workspace_conflict`:return T(`deviceExecReasonWorkspaceConflict`);case`workspace_blocked`:return T(`deviceExecReasonWorkspaceBlocked`);case`room_fairness_yield`:return T(`deviceExecReasonFairness`);default:return e}},te=E?.settings?.maxActiveTasks??b.maxActiveTasks,ne=E?.settings?.maxWaitingTasks??b.maxWaitingTasks;return(0,y.jsxs)(`div`,{className:`des-container`,children:[(0,y.jsxs)(`div`,{className:`des-header`,children:[(0,y.jsxs)(`div`,{className:`des-header-left`,children:[(0,y.jsx)(`h3`,{className:`des-title`,children:T(`deviceExecTitle`)}),(0,y.jsx)(`p`,{className:`des-subtitle`,children:T(`deviceExecSubtitle`)})]}),(0,y.jsx)(`button`,{type:`button`,className:`des-refresh-btn`,onClick:()=>void q(!1),disabled:A,title:T(`deviceExecRefresh`),children:(0,y.jsx)(t,{className:A?`des-spin`:``})})]}),I&&(0,y.jsxs)(`div`,{className:`des-alert des-alert-error`,role:`alert`,children:[(0,y.jsx)(d,{className:`des-alert-icon`}),(0,y.jsx)(`div`,{className:`des-alert-text`,children:I}),(0,y.jsx)(`button`,{type:`button`,className:`des-alert-close`,onClick:()=>L(null),children:(0,y.jsx)(f,{})})]}),R&&(0,y.jsxs)(`div`,{className:`des-alert des-alert-success`,role:`status`,children:[(0,y.jsx)(c,{className:`des-alert-icon`}),(0,y.jsx)(`div`,{className:`des-alert-text`,children:R}),(0,y.jsx)(`button`,{type:`button`,className:`des-alert-close`,onClick:()=>z(null),children:(0,y.jsx)(f,{})})]}),(0,y.jsxs)(`div`,{className:`des-stats-row`,children:[(0,y.jsxs)(`div`,{className:`des-stat-card`,children:[(0,y.jsxs)(`div`,{className:`des-stat-label`,children:[(0,y.jsx)(i,{className:`des-stat-icon is-running`}),` `,T(`deviceExecRunning`)]}),(0,y.jsxs)(`div`,{className:`des-stat-value`,children:[E?.activeCount??0,` `,(0,y.jsxs)(`span`,{className:`des-stat-sub`,children:[`/ `,te]})]})]}),(0,y.jsxs)(`div`,{className:`des-stat-card`,children:[(0,y.jsxs)(`div`,{className:`des-stat-label`,children:[(0,y.jsx)(l,{className:`des-stat-icon is-waiting`}),` `,T(`deviceExecQueued`)]}),(0,y.jsxs)(`div`,{className:`des-stat-value`,children:[E?.waitingCount??0,` `,(0,y.jsxs)(`span`,{className:`des-stat-sub`,children:[`/ `,ne]})]})]}),(0,y.jsxs)(`div`,{className:`des-stat-card`,children:[(0,y.jsxs)(`div`,{className:`des-stat-label`,children:[(0,y.jsx)(o,{className:`des-stat-icon is-blocked`}),` `,T(`deviceExecBlocked`)]}),(0,y.jsx)(`div`,{className:`des-stat-value${(E?.blockedCount??0)>0?` is-warn`:``}`,children:E?.blockedCount??0})]})]}),(0,y.jsxs)(`form`,{className:`des-form-card`,onSubmit:e=>void Q(e),children:[(0,y.jsxs)(`div`,{className:`des-form-header`,children:[(0,y.jsx)(`h4`,{className:`des-form-title`,children:T(`deviceExecQuotaTitle`)}),(0,y.jsx)(`div`,{className:`des-form-header-actions`,children:(0,y.jsxs)(`button`,{type:`button`,className:`des-btn des-btn-secondary des-btn-sm`,disabled:M,onClick:X,title:T(`deviceExecResetDefaultsTip`),children:[(0,y.jsx)(n,{className:`des-btn-icon`}),T(`deviceExecResetDefaults`)]})})]}),(0,y.jsxs)(`div`,{className:`des-group`,children:[(0,y.jsxs)(`div`,{className:`des-group-header`,children:[(0,y.jsx)(r,{className:`des-group-icon`}),(0,y.jsx)(`span`,{className:`des-group-title`,children:T(`deviceExecSchedulingTitle`)})]}),(0,y.jsxs)(`div`,{className:`des-fields-row`,children:[(0,y.jsxs)(`div`,{className:`des-field`,children:[(0,y.jsx)(`label`,{htmlFor:`des-max-active`,className:`des-label`,children:T(`deviceExecMaxActive`)}),(0,y.jsx)(`input`,{id:`des-max-active`,type:`number`,min:1,max:64,step:1,className:`des-input`,value:O.maxActiveTasks,onChange:e=>J(`maxActiveTasks`,parseInt(e.target.value,10)||1),required:!0}),(0,y.jsx)(`span`,{className:`des-hint`,children:T(`deviceExecMaxActiveHint`)})]}),(0,y.jsxs)(`div`,{className:`des-field`,children:[(0,y.jsx)(`label`,{htmlFor:`des-max-waiting`,className:`des-label`,children:T(`deviceExecMaxWaiting`)}),(0,y.jsx)(`input`,{id:`des-max-waiting`,type:`number`,min:0,max:1024,step:1,className:`des-input`,value:O.maxWaitingTasks,onChange:e=>J(`maxWaitingTasks`,parseInt(e.target.value,10)||0),required:!0}),(0,y.jsx)(`span`,{className:`des-hint`,children:T(`deviceExecMaxWaitingHint`)})]}),(0,y.jsxs)(`div`,{className:`des-field`,children:[(0,y.jsx)(`label`,{htmlFor:`des-starvation-ms`,className:`des-label`,children:T(`deviceExecStarvationMs`)}),(0,y.jsxs)(`div`,{className:`des-input-with-badge`,children:[(0,y.jsx)(`input`,{id:`des-starvation-ms`,type:`number`,min:1e3,max:6e4,step:500,className:`des-input`,value:O.starvationThresholdMs,onChange:e=>J(`starvationThresholdMs`,parseInt(e.target.value,10)||1e3),required:!0}),(0,y.jsx)(`span`,{className:`des-input-badge`,children:C(O.starvationThresholdMs)})]}),(0,y.jsx)(`span`,{className:`des-hint`,children:T(`deviceExecStarvationMsHint`)})]}),(0,y.jsxs)(`div`,{className:`des-field`,children:[(0,y.jsx)(`label`,{htmlFor:`des-max-skips`,className:`des-label`,children:T(`deviceExecMaxSkips`)}),(0,y.jsx)(`input`,{id:`des-max-skips`,type:`number`,min:1,max:20,step:1,className:`des-input`,value:O.maxSkipsBeforeStarvation,onChange:e=>J(`maxSkipsBeforeStarvation`,parseInt(e.target.value,10)||1),required:!0}),(0,y.jsx)(`span`,{className:`des-hint`,children:T(`deviceExecMaxSkipsHint`)})]})]})]}),(0,y.jsxs)(`div`,{className:`des-group`,children:[(0,y.jsxs)(`div`,{className:`des-group-header`,children:[(0,y.jsx)(a,{className:`des-group-icon`}),(0,y.jsx)(`span`,{className:`des-group-title`,children:T(`deviceExecDispatchTitle`)})]}),(0,y.jsxs)(`div`,{className:`des-fields-row`,children:[(0,y.jsxs)(`div`,{className:`des-field`,children:[(0,y.jsx)(`label`,{htmlFor:`des-max-depth`,className:`des-label`,children:T(`deviceExecMaxDepth`)}),(0,y.jsx)(`input`,{id:`des-max-depth`,type:`number`,min:1,max:64,step:1,className:`des-input`,value:O.maxDispatchDepth,onChange:e=>J(`maxDispatchDepth`,parseInt(e.target.value,10)||1),required:!0}),(0,y.jsx)(`span`,{className:`des-hint`,children:T(`deviceExecMaxDepthHint`)})]}),(0,y.jsxs)(`div`,{className:`des-field`,children:[(0,y.jsx)(`label`,{htmlFor:`des-max-budget`,className:`des-label`,children:T(`deviceExecMaxBudget`)}),(0,y.jsx)(`input`,{id:`des-max-budget`,type:`number`,min:1,max:256,step:1,className:`des-input`,value:O.maxDispatchBudget,onChange:e=>J(`maxDispatchBudget`,parseInt(e.target.value,10)||1),required:!0}),(0,y.jsx)(`span`,{className:`des-hint`,children:T(`deviceExecMaxBudgetHint`)})]}),(0,y.jsxs)(`div`,{className:`des-field des-field-checkbox`,children:[(0,y.jsxs)(`label`,{htmlFor:`des-allow-bot-mentions`,className:`des-checkbox-container`,children:[(0,y.jsx)(`input`,{id:`des-allow-bot-mentions`,type:`checkbox`,className:`des-checkbox`,checked:O.allowBotMentions,onChange:e=>Y(`allowBotMentions`,e.target.checked)}),(0,y.jsx)(`span`,{className:`des-label`,children:T(`deviceExecAllowBotMentions`)})]}),(0,y.jsx)(`span`,{className:`des-hint`,children:T(`deviceExecAllowBotMentionsHint`)})]})]})]}),(0,y.jsxs)(`div`,{className:`des-group`,children:[(0,y.jsxs)(`div`,{className:`des-group-header`,children:[(0,y.jsx)(m,{className:`des-group-icon`}),(0,y.jsx)(`span`,{className:`des-group-title`,children:T(`deviceExecContextTitle`)})]}),(0,y.jsxs)(`div`,{className:`des-fields-row`,children:[(0,y.jsxs)(`div`,{className:`des-field`,children:[(0,y.jsx)(`label`,{htmlFor:`des-group-context-bytes`,className:`des-label`,children:T(`deviceExecContextBytes`)}),(0,y.jsxs)(`div`,{className:`des-input-with-badge`,children:[(0,y.jsx)(`input`,{id:`des-group-context-bytes`,type:`number`,min:4096,max:2097152,step:1024,className:`des-input`,value:O.groupContextBytes,onChange:e=>J(`groupContextBytes`,parseInt(e.target.value,10)||4096),required:!0}),(0,y.jsx)(`span`,{className:`des-input-badge`,children:S(O.groupContextBytes)})]}),(0,y.jsx)(`span`,{className:`des-hint`,children:T(`deviceExecContextBytesHint`)})]}),(0,y.jsxs)(`div`,{className:`des-field`,children:[(0,y.jsx)(`label`,{htmlFor:`des-group-retention`,className:`des-label`,children:T(`deviceExecRetention`)}),(0,y.jsx)(`input`,{id:`des-group-retention`,type:`number`,min:50,max:2e4,step:10,className:`des-input`,value:O.groupRetentionLimit,onChange:e=>J(`groupRetentionLimit`,parseInt(e.target.value,10)||50),required:!0}),(0,y.jsx)(`span`,{className:`des-hint`,children:T(`deviceExecRetentionHint`)})]})]})]}),(0,y.jsxs)(`div`,{className:`des-group`,children:[(0,y.jsxs)(`div`,{className:`des-group-header`,children:[(0,y.jsx)(s,{className:`des-group-icon`}),(0,y.jsx)(`span`,{className:`des-group-title`,children:T(`deviceExecFileSyncTitle`)})]}),(0,y.jsxs)(`div`,{className:`des-fields-row`,children:[(0,y.jsxs)(`div`,{className:`des-field`,children:[(0,y.jsx)(`label`,{htmlFor:`des-file-sync-bytes`,className:`des-label`,children:T(`deviceExecFileSyncBytes`)}),(0,y.jsxs)(`div`,{className:`des-input-with-badge`,children:[(0,y.jsx)(`input`,{id:`des-file-sync-bytes`,type:`number`,min:1048576,max:10737418240,step:1048576,className:`des-input`,value:O.fileSyncMaxBytes,onChange:e=>J(`fileSyncMaxBytes`,parseInt(e.target.value,10)||1048576),required:!0}),(0,y.jsx)(`span`,{className:`des-input-badge`,children:S(O.fileSyncMaxBytes)})]}),(0,y.jsx)(`span`,{className:`des-hint`,children:T(`deviceExecFileSyncBytesHint`)})]}),(0,y.jsxs)(`div`,{className:`des-field`,children:[(0,y.jsx)(`label`,{htmlFor:`des-file-sync-files`,className:`des-label`,children:T(`deviceExecFileSyncFiles`)}),(0,y.jsx)(`input`,{id:`des-file-sync-files`,type:`number`,min:10,max:1e4,step:1,className:`des-input`,value:O.fileSyncMaxFiles,onChange:e=>J(`fileSyncMaxFiles`,parseInt(e.target.value,10)||10),required:!0}),(0,y.jsx)(`span`,{className:`des-hint`,children:T(`deviceExecFileSyncFilesHint`)})]}),(0,y.jsxs)(`div`,{className:`des-field`,children:[(0,y.jsx)(`label`,{htmlFor:`des-file-sync-staged-bytes`,className:`des-label`,children:T(`deviceExecFileSyncStagedBytes`)}),(0,y.jsxs)(`div`,{className:`des-input-with-badge`,children:[(0,y.jsx)(`input`,{id:`des-file-sync-staged-bytes`,type:`number`,min:4194304,max:53687091200,step:1048576,className:`des-input`,value:O.fileSyncStagedBytes,onChange:e=>J(`fileSyncStagedBytes`,parseInt(e.target.value,10)||4194304),required:!0}),(0,y.jsx)(`span`,{className:`des-input-badge`,children:S(O.fileSyncStagedBytes)})]}),(0,y.jsx)(`span`,{className:`des-hint`,children:T(`deviceExecFileSyncStagedBytesHint`)})]})]})]}),(0,y.jsxs)(`div`,{className:`des-group`,children:[(0,y.jsxs)(`div`,{className:`des-group-header`,children:[(0,y.jsx)(u,{className:`des-group-icon`}),(0,y.jsx)(`span`,{className:`des-group-title`,children:T(`deviceExecLocksTitle`)})]}),(0,y.jsxs)(`div`,{className:`des-fields-row`,children:[(0,y.jsxs)(`div`,{className:`des-field`,children:[(0,y.jsx)(`label`,{htmlFor:`des-resource-lock-ttl`,className:`des-label`,children:T(`deviceExecLockTtl`)}),(0,y.jsxs)(`div`,{className:`des-input-with-badge`,children:[(0,y.jsx)(`input`,{id:`des-resource-lock-ttl`,type:`number`,min:6e4,max:864e5,step:6e4,className:`des-input`,value:O.resourceLockDefaultTtlMs,onChange:e=>J(`resourceLockDefaultTtlMs`,parseInt(e.target.value,10)||6e4),required:!0}),(0,y.jsx)(`span`,{className:`des-input-badge`,children:C(O.resourceLockDefaultTtlMs)})]}),(0,y.jsx)(`span`,{className:`des-hint`,children:T(`deviceExecLockTtlHint`)})]}),(0,y.jsxs)(`div`,{className:`des-field`,children:[(0,y.jsx)(`label`,{htmlFor:`des-blackboard-bytes`,className:`des-label`,children:T(`deviceExecBlackboardBytes`)}),(0,y.jsxs)(`div`,{className:`des-input-with-badge`,children:[(0,y.jsx)(`input`,{id:`des-blackboard-bytes`,type:`number`,min:4096,max:4194304,step:1024,className:`des-input`,value:O.blackboardMaxBytes,onChange:e=>J(`blackboardMaxBytes`,parseInt(e.target.value,10)||4096),required:!0}),(0,y.jsx)(`span`,{className:`des-input-badge`,children:S(O.blackboardMaxBytes)})]}),(0,y.jsx)(`span`,{className:`des-hint`,children:T(`deviceExecBlackboardBytesHint`)})]})]})]}),(0,y.jsxs)(`div`,{className:`des-form-actions`,children:[(0,y.jsx)(`button`,{type:`button`,className:`des-btn des-btn-secondary`,disabled:M,onClick:X,children:T(`deviceExecResetDefaults`)}),(0,y.jsx)(`button`,{type:`button`,className:`des-btn des-btn-secondary`,disabled:M,onClick:Z,children:T(`deviceExecReset`)}),(0,y.jsx)(`button`,{type:`submit`,className:`des-btn des-btn-primary`,disabled:M,children:T(M?`deviceExecSaving`:`deviceExecSave`)})]})]}),E&&E.blocked&&E.blocked.length>0&&(0,y.jsxs)(`div`,{className:`des-section des-blocked-section`,children:[(0,y.jsxs)(`h4`,{className:`des-section-title is-danger`,children:[(0,y.jsx)(d,{}),` `,T(`deviceExecBlockedTitle`)]}),(0,y.jsx)(`p`,{className:`des-section-desc`,children:T(`deviceExecBlockedDesc`)}),(0,y.jsx)(`div`,{className:`des-table-wrap`,children:(0,y.jsxs)(`table`,{className:`des-table`,children:[(0,y.jsx)(`thead`,{children:(0,y.jsxs)(`tr`,{children:[(0,y.jsx)(`th`,{children:`Task ID`}),(0,y.jsx)(`th`,{children:`Room ID`}),(0,y.jsx)(`th`,{children:`Bot ID`}),(0,y.jsx)(`th`,{children:T(`deviceExecReason`)})]})}),(0,y.jsx)(`tbody`,{children:E.blocked.map(e=>(0,y.jsxs)(`tr`,{className:`des-row-blocked`,children:[(0,y.jsxs)(`td`,{className:`des-mono`,children:[e.taskId.slice(0,8),`...`]}),(0,y.jsx)(`td`,{children:e.roomId}),(0,y.jsx)(`td`,{children:e.botId}),(0,y.jsx)(`td`,{children:(0,y.jsx)(`span`,{className:`des-badge is-danger`,children:e.reason})})]},`${e.taskId}-${e.attemptId}`))})]})})]}),(0,y.jsxs)(`div`,{className:`des-section`,children:[(0,y.jsxs)(`h4`,{className:`des-section-title`,children:[(0,y.jsx)(i,{}),` `,T(`deviceExecActiveTasks`),` (`,E?.running?.length??0,`)`]}),E&&E.running&&E.running.length>0?(0,y.jsx)(`div`,{className:`des-table-wrap`,children:(0,y.jsxs)(`table`,{className:`des-table`,children:[(0,y.jsx)(`thead`,{children:(0,y.jsxs)(`tr`,{children:[(0,y.jsx)(`th`,{children:`Task ID`}),(0,y.jsx)(`th`,{children:`Room ID`}),(0,y.jsx)(`th`,{children:`Bot ID`}),(0,y.jsx)(`th`,{children:T(`deviceExecQueuedTime`)})]})}),(0,y.jsx)(`tbody`,{children:E.running.map(e=>(0,y.jsxs)(`tr`,{children:[(0,y.jsxs)(`td`,{className:`des-mono`,title:e.taskId,children:[e.taskId.slice(0,8),`...`]}),(0,y.jsx)(`td`,{children:e.roomId}),(0,y.jsx)(`td`,{children:e.botId}),(0,y.jsx)(`td`,{children:new Date(e.startedAt).toLocaleTimeString()})]},`${e.taskId}-${e.attemptId}`))})]})}):(0,y.jsx)(`div`,{className:`des-empty`,children:T(`deviceExecNoActive`)})]}),(0,y.jsxs)(`div`,{className:`des-section`,children:[(0,y.jsxs)(`h4`,{className:`des-section-title`,children:[(0,y.jsx)(l,{}),` `,T(`deviceExecWaitingQueue`),` (`,E?.waiting?.length??0,`)`]}),E&&E.waiting&&E.waiting.length>0?(0,y.jsx)(`div`,{className:`des-table-wrap`,children:(0,y.jsxs)(`table`,{className:`des-table`,children:[(0,y.jsx)(`thead`,{children:(0,y.jsxs)(`tr`,{children:[(0,y.jsx)(`th`,{children:T(`deviceExecPosition`)}),(0,y.jsx)(`th`,{children:`Task ID`}),(0,y.jsx)(`th`,{children:`Room ID`}),(0,y.jsx)(`th`,{children:`Bot ID`}),(0,y.jsx)(`th`,{children:T(`deviceExecReason`)}),(0,y.jsx)(`th`,{children:T(`deviceExecQueuedTime`)}),(0,y.jsx)(`th`,{children:T(`deviceExecActions`)})]})}),(0,y.jsx)(`tbody`,{children:E.waiting.map(e=>(0,y.jsxs)(`tr`,{children:[(0,y.jsx)(`td`,{children:(0,y.jsxs)(`span`,{className:`des-pos-badge`,children:[`#`,e.queuePosition]})}),(0,y.jsxs)(`td`,{className:`des-mono`,title:e.taskId,children:[e.taskId.slice(0,8),`...`]}),(0,y.jsx)(`td`,{children:e.roomId}),(0,y.jsx)(`td`,{children:e.botId}),(0,y.jsx)(`td`,{children:(0,y.jsxs)(`div`,{className:`des-reason-cell`,children:[(0,y.jsx)(`span`,{className:`des-badge des-badge-${e.blockReason}`,children:ee(e.blockReason)}),(0,y.jsx)(`span`,{className:`des-reason-detail`,children:e.blockReasonDetail})]})}),(0,y.jsx)(`td`,{children:new Date(e.queuedAt).toLocaleTimeString()}),(0,y.jsx)(`td`,{children:(0,y.jsx)(`button`,{type:`button`,className:`des-btn des-btn-danger-sm`,disabled:P===e.taskId,onClick:()=>void $(e.taskId,e.attemptId),children:P===e.taskId?T(`deviceExecCancelling`):T(`deviceExecCancel`)})})]},`${e.taskId}-${e.attemptId}`))})]})}):(0,y.jsx)(`div`,{className:`des-empty`,children:T(`deviceExecNoWaiting`)})]})]})}export{T as t};
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Ft as t,It as n,L as r,Nt as i,Ut as a,Wt as o,Z as s,b as c,k as l,mt as u,r as d,sn as f,vn as p,xt as m}from"./fi-CcqqfamG.js";import{i as h,t as g}from"./react-CR5VJ85Q.js";import{a as _}from"./api-client-BbDlV0jR.js";var v=e(h(),1),y=g(),b={maxActiveTasks:4,maxWaitingTasks:32,starvationThresholdMs:8e3,maxSkipsBeforeStarvation:3,maxDispatchDepth:8,maxDispatchBudget:16,allowBotMentions:!1,groupContextBytes:262144,groupRetentionLimit:2e3,fileSyncMaxBytes:104857600,fileSyncMaxFiles:1e3,fileSyncStagedBytes:1073741824,resourceLockDefaultTtlMs:18e5,blackboardMaxBytes:262144,taskReportExcerptBytes:131072,maxResourceLocksPerTask:128,botMentionBudgetPerTurn:3};function x(e,t,n,r){return typeof e==`number`&&Number.isFinite(e)?Math.max(t,Math.min(n,Math.round(e))):r}function S(e){if(!Number.isFinite(e)||e<=0)return`0 B`;let t=[`B`,`KiB`,`MiB`,`GiB`],n=0,r=e;for(;r>=1024&&n<t.length-1;)r/=1024,n++;return`${Number.isInteger(r)?r:r.toFixed(1)} ${t[n]}`}function C(e){return!Number.isFinite(e)||e<=0?`0 ms`:e<1e3?`${e} ms`:e<6e4?`${Math.round(e/1e3)} s`:`${(e/6e4).toFixed(1)} min`}function w(e){let t={settings:{...b},activeCount:0,waitingCount:0,blockedCount:0,running:[],waiting:[],blocked:[]};if(!e||typeof e!=`object`||Array.isArray(e))return t;let n=e,r=n.settings&&typeof n.settings==`object`&&!Array.isArray(n.settings)?n.settings:{},i={maxActiveTasks:x(r.maxActiveTasks,1,64,b.maxActiveTasks),maxWaitingTasks:x(r.maxWaitingTasks,0,1024,b.maxWaitingTasks),starvationThresholdMs:x(r.starvationThresholdMs,1e3,6e4,b.starvationThresholdMs),maxSkipsBeforeStarvation:x(r.maxSkipsBeforeStarvation,1,20,b.maxSkipsBeforeStarvation),maxDispatchDepth:x(r.maxDispatchDepth,1,64,b.maxDispatchDepth),maxDispatchBudget:x(r.maxDispatchBudget,1,256,b.maxDispatchBudget),allowBotMentions:typeof r.allowBotMentions==`boolean`?r.allowBotMentions:b.allowBotMentions,groupContextBytes:x(r.groupContextBytes,4096,2097152,b.groupContextBytes),groupRetentionLimit:x(r.groupRetentionLimit,50,2e4,b.groupRetentionLimit),fileSyncMaxBytes:x(r.fileSyncMaxBytes,1048576,10737418240,b.fileSyncMaxBytes),fileSyncMaxFiles:x(r.fileSyncMaxFiles,10,1e4,b.fileSyncMaxFiles),fileSyncStagedBytes:x(r.fileSyncStagedBytes,4194304,53687091200,b.fileSyncStagedBytes),resourceLockDefaultTtlMs:x(r.resourceLockDefaultTtlMs,6e4,864e5,b.resourceLockDefaultTtlMs),blackboardMaxBytes:x(r.blackboardMaxBytes,4096,4194304,b.blackboardMaxBytes),...typeof r.taskReportExcerptBytes==`number`?{taskReportExcerptBytes:r.taskReportExcerptBytes}:{},...typeof r.maxResourceLocksPerTask==`number`?{maxResourceLocksPerTask:r.maxResourceLocksPerTask}:{},...typeof r.botMentionBudgetPerTurn==`number`?{botMentionBudgetPerTurn:r.botMentionBudgetPerTurn}:{}},a=Array.isArray(n.running)?n.running:[],o=Array.isArray(n.waiting)?n.waiting:[],s=Array.isArray(n.blocked)?n.blocked:[];return{settings:i,activeCount:typeof n.activeCount==`number`?n.activeCount:a.length,waitingCount:typeof n.waitingCount==`number`?n.waitingCount:o.length,blockedCount:typeof n.blockedCount==`number`?n.blockedCount:s.length,running:a,waiting:o,blocked:s}}function T({hubUrl:e,deviceId:h,onNotice:g}){let T=p(),[E,D]=(0,v.useState)(null),[O,k]=(0,v.useState)(b),[A,j]=(0,v.useState)(!1),[M,N]=(0,v.useState)(!1),[P,F]=(0,v.useState)(null),[I,L]=(0,v.useState)(null),[R,z]=(0,v.useState)(null),B=(0,v.useRef)(!0),V=(0,v.useRef)(0),H=(0,v.useRef)(new Set),U=(0,v.useRef)(!1),W=(0,v.useRef)(!1),G=`${e??``}:${h??``}`,K=(0,v.useCallback)(async(e,t,n)=>{let r=new AbortController;H.current.add(r);let i=()=>r.abort();n&&(n.aborted?r.abort():n.addEventListener(`abort`,i,{once:!0}));try{return await _(`/api/device-center/${e}`,{body:t,signal:r.signal})}finally{n&&n.removeEventListener(`abort`,i),H.current.delete(r)}},[]),q=(0,v.useCallback)(async(e=!1)=>{if(!B.current||U.current)return;U.current=!0;let t=V.current;e||j(!0);try{let e=await K(`execution-queue`);if(!B.current||t!==V.current)return;let n=w(e);D(n),L(null),W.current||=(k({...n.settings}),!0)}catch(e){if(!B.current||t!==V.current)return;e.name!==`AbortError`&&L(e.message)}finally{U.current=!1,B.current&&t===V.current&&!e&&j(!1)}},[K]);(0,v.useEffect)(()=>{B.current=!0,V.current++;for(let e of H.current)e.abort();H.current.clear(),U.current=!1,W.current=!1,D(null),k({...b}),L(null),z(null),q(!1);let e=setInterval(()=>{q(!0)},3e3);return()=>{B.current=!1,V.current++;for(let e of H.current)e.abort();H.current.clear(),clearInterval(e)}},[G,q]);let J=(e,t)=>{k(n=>({...n,[e]:t}))},Y=(e,t)=>{k(n=>({...n,[e]:t}))},X=()=>{k({...b})},Z=()=>{E?.settings?k({...E.settings}):k({...b})},Q=async e=>{e.preventDefault();let t=V.current;N(!0),L(null),z(null);let n={maxActiveTasks:x(O.maxActiveTasks,1,64,b.maxActiveTasks),maxWaitingTasks:x(O.maxWaitingTasks,0,1024,b.maxWaitingTasks),starvationThresholdMs:x(O.starvationThresholdMs,1e3,6e4,b.starvationThresholdMs),maxSkipsBeforeStarvation:x(O.maxSkipsBeforeStarvation,1,20,b.maxSkipsBeforeStarvation),maxDispatchDepth:x(O.maxDispatchDepth,1,64,b.maxDispatchDepth),maxDispatchBudget:x(O.maxDispatchBudget,1,256,b.maxDispatchBudget),allowBotMentions:!!O.allowBotMentions,groupContextBytes:x(O.groupContextBytes,4096,2097152,b.groupContextBytes),groupRetentionLimit:x(O.groupRetentionLimit,50,2e4,b.groupRetentionLimit),fileSyncMaxBytes:x(O.fileSyncMaxBytes,1048576,10737418240,b.fileSyncMaxBytes),fileSyncMaxFiles:x(O.fileSyncMaxFiles,10,1e4,b.fileSyncMaxFiles),fileSyncStagedBytes:x(O.fileSyncStagedBytes,4194304,53687091200,b.fileSyncStagedBytes),resourceLockDefaultTtlMs:x(O.resourceLockDefaultTtlMs,6e4,864e5,b.resourceLockDefaultTtlMs),blackboardMaxBytes:x(O.blackboardMaxBytes,4096,4194304,b.blackboardMaxBytes),...O.taskReportExcerptBytes===void 0?{}:{taskReportExcerptBytes:O.taskReportExcerptBytes},...O.maxResourceLocksPerTask===void 0?{}:{maxResourceLocksPerTask:O.maxResourceLocksPerTask},...O.botMentionBudgetPerTurn===void 0?{}:{botMentionBudgetPerTurn:O.botMentionBudgetPerTurn}};try{let e=await K(`execution-settings`,n);if(!B.current||t!==V.current)return;e?.settings&&k({...e.settings}),z(T(`deviceExecSavedNotice`)),g?.(T(`deviceExecSavedNotice`)),await q(!0)}catch(e){if(!B.current||t!==V.current)return;e.name!==`AbortError`&&L(e.message)}finally{B.current&&t===V.current&&N(!1)}},$=async(e,t)=>{let n=V.current;F(e),L(null);try{if(await K(`execution-queue/cancel`,{taskId:e,attemptId:t}),!B.current||n!==V.current)return;g?.(T(`deviceExecTaskCancelled`)),await q(!0)}catch(e){if(!B.current||n!==V.current)return;e.name!==`AbortError`&&L(e.message)}finally{B.current&&n===V.current&&F(null)}},ee=e=>{switch(e){case`max_concurrency_reached`:return T(`deviceExecReasonMaxConcurrency`);case`bot_busy`:return T(`deviceExecReasonBotBusy`);case`workspace_conflict`:return T(`deviceExecReasonWorkspaceConflict`);case`workspace_blocked`:return T(`deviceExecReasonWorkspaceBlocked`);case`room_fairness_yield`:return T(`deviceExecReasonFairness`);default:return e}},te=E?.settings?.maxActiveTasks??b.maxActiveTasks,ne=E?.settings?.maxWaitingTasks??b.maxWaitingTasks;return(0,y.jsxs)(`div`,{className:`des-container`,children:[(0,y.jsxs)(`div`,{className:`des-header`,children:[(0,y.jsxs)(`div`,{className:`des-header-left`,children:[(0,y.jsx)(`h3`,{className:`des-title`,children:T(`deviceExecTitle`)}),(0,y.jsx)(`p`,{className:`des-subtitle`,children:T(`deviceExecSubtitle`)})]}),(0,y.jsx)(`button`,{type:`button`,className:`des-refresh-btn`,onClick:()=>void q(!1),disabled:A,title:T(`deviceExecRefresh`),children:(0,y.jsx)(t,{className:A?`des-spin`:``})})]}),I&&(0,y.jsxs)(`div`,{className:`des-alert des-alert-error`,role:`alert`,children:[(0,y.jsx)(d,{className:`des-alert-icon`}),(0,y.jsx)(`div`,{className:`des-alert-text`,children:I}),(0,y.jsx)(`button`,{type:`button`,className:`des-alert-close`,onClick:()=>L(null),children:(0,y.jsx)(f,{})})]}),R&&(0,y.jsxs)(`div`,{className:`des-alert des-alert-success`,role:`status`,children:[(0,y.jsx)(c,{className:`des-alert-icon`}),(0,y.jsx)(`div`,{className:`des-alert-text`,children:R}),(0,y.jsx)(`button`,{type:`button`,className:`des-alert-close`,onClick:()=>z(null),children:(0,y.jsx)(f,{})})]}),(0,y.jsxs)(`div`,{className:`des-stats-row`,children:[(0,y.jsxs)(`div`,{className:`des-stat-card`,children:[(0,y.jsxs)(`div`,{className:`des-stat-label`,children:[(0,y.jsx)(i,{className:`des-stat-icon is-running`}),` `,T(`deviceExecRunning`)]}),(0,y.jsxs)(`div`,{className:`des-stat-value`,children:[E?.activeCount??0,` `,(0,y.jsxs)(`span`,{className:`des-stat-sub`,children:[`/ `,te]})]})]}),(0,y.jsxs)(`div`,{className:`des-stat-card`,children:[(0,y.jsxs)(`div`,{className:`des-stat-label`,children:[(0,y.jsx)(l,{className:`des-stat-icon is-waiting`}),` `,T(`deviceExecQueued`)]}),(0,y.jsxs)(`div`,{className:`des-stat-value`,children:[E?.waitingCount??0,` `,(0,y.jsxs)(`span`,{className:`des-stat-sub`,children:[`/ `,ne]})]})]}),(0,y.jsxs)(`div`,{className:`des-stat-card`,children:[(0,y.jsxs)(`div`,{className:`des-stat-label`,children:[(0,y.jsx)(o,{className:`des-stat-icon is-blocked`}),` `,T(`deviceExecBlocked`)]}),(0,y.jsx)(`div`,{className:`des-stat-value${(E?.blockedCount??0)>0?` is-warn`:``}`,children:E?.blockedCount??0})]})]}),(0,y.jsxs)(`form`,{className:`des-form-card`,onSubmit:e=>void Q(e),children:[(0,y.jsxs)(`div`,{className:`des-form-header`,children:[(0,y.jsx)(`h4`,{className:`des-form-title`,children:T(`deviceExecQuotaTitle`)}),(0,y.jsx)(`div`,{className:`des-form-header-actions`,children:(0,y.jsxs)(`button`,{type:`button`,className:`des-btn des-btn-secondary des-btn-sm`,disabled:M,onClick:X,title:T(`deviceExecResetDefaultsTip`),children:[(0,y.jsx)(n,{className:`des-btn-icon`}),T(`deviceExecResetDefaults`)]})})]}),(0,y.jsxs)(`div`,{className:`des-group`,children:[(0,y.jsxs)(`div`,{className:`des-group-header`,children:[(0,y.jsx)(r,{className:`des-group-icon`}),(0,y.jsx)(`span`,{className:`des-group-title`,children:T(`deviceExecSchedulingTitle`)})]}),(0,y.jsxs)(`div`,{className:`des-fields-row`,children:[(0,y.jsxs)(`div`,{className:`des-field`,children:[(0,y.jsx)(`label`,{htmlFor:`des-max-active`,className:`des-label`,children:T(`deviceExecMaxActive`)}),(0,y.jsx)(`input`,{id:`des-max-active`,type:`number`,min:1,max:64,step:1,className:`des-input`,value:O.maxActiveTasks,onChange:e=>J(`maxActiveTasks`,parseInt(e.target.value,10)||1),required:!0}),(0,y.jsx)(`span`,{className:`des-hint`,children:T(`deviceExecMaxActiveHint`)})]}),(0,y.jsxs)(`div`,{className:`des-field`,children:[(0,y.jsx)(`label`,{htmlFor:`des-max-waiting`,className:`des-label`,children:T(`deviceExecMaxWaiting`)}),(0,y.jsx)(`input`,{id:`des-max-waiting`,type:`number`,min:0,max:1024,step:1,className:`des-input`,value:O.maxWaitingTasks,onChange:e=>J(`maxWaitingTasks`,parseInt(e.target.value,10)||0),required:!0}),(0,y.jsx)(`span`,{className:`des-hint`,children:T(`deviceExecMaxWaitingHint`)})]}),(0,y.jsxs)(`div`,{className:`des-field`,children:[(0,y.jsx)(`label`,{htmlFor:`des-starvation-ms`,className:`des-label`,children:T(`deviceExecStarvationMs`)}),(0,y.jsxs)(`div`,{className:`des-input-with-badge`,children:[(0,y.jsx)(`input`,{id:`des-starvation-ms`,type:`number`,min:1e3,max:6e4,step:500,className:`des-input`,value:O.starvationThresholdMs,onChange:e=>J(`starvationThresholdMs`,parseInt(e.target.value,10)||1e3),required:!0}),(0,y.jsx)(`span`,{className:`des-input-badge`,children:C(O.starvationThresholdMs)})]}),(0,y.jsx)(`span`,{className:`des-hint`,children:T(`deviceExecStarvationMsHint`)})]}),(0,y.jsxs)(`div`,{className:`des-field`,children:[(0,y.jsx)(`label`,{htmlFor:`des-max-skips`,className:`des-label`,children:T(`deviceExecMaxSkips`)}),(0,y.jsx)(`input`,{id:`des-max-skips`,type:`number`,min:1,max:20,step:1,className:`des-input`,value:O.maxSkipsBeforeStarvation,onChange:e=>J(`maxSkipsBeforeStarvation`,parseInt(e.target.value,10)||1),required:!0}),(0,y.jsx)(`span`,{className:`des-hint`,children:T(`deviceExecMaxSkipsHint`)})]})]})]}),(0,y.jsxs)(`div`,{className:`des-group`,children:[(0,y.jsxs)(`div`,{className:`des-group-header`,children:[(0,y.jsx)(a,{className:`des-group-icon`}),(0,y.jsx)(`span`,{className:`des-group-title`,children:T(`deviceExecDispatchTitle`)})]}),(0,y.jsxs)(`div`,{className:`des-fields-row`,children:[(0,y.jsxs)(`div`,{className:`des-field`,children:[(0,y.jsx)(`label`,{htmlFor:`des-max-depth`,className:`des-label`,children:T(`deviceExecMaxDepth`)}),(0,y.jsx)(`input`,{id:`des-max-depth`,type:`number`,min:1,max:64,step:1,className:`des-input`,value:O.maxDispatchDepth,onChange:e=>J(`maxDispatchDepth`,parseInt(e.target.value,10)||1),required:!0}),(0,y.jsx)(`span`,{className:`des-hint`,children:T(`deviceExecMaxDepthHint`)})]}),(0,y.jsxs)(`div`,{className:`des-field`,children:[(0,y.jsx)(`label`,{htmlFor:`des-max-budget`,className:`des-label`,children:T(`deviceExecMaxBudget`)}),(0,y.jsx)(`input`,{id:`des-max-budget`,type:`number`,min:1,max:256,step:1,className:`des-input`,value:O.maxDispatchBudget,onChange:e=>J(`maxDispatchBudget`,parseInt(e.target.value,10)||1),required:!0}),(0,y.jsx)(`span`,{className:`des-hint`,children:T(`deviceExecMaxBudgetHint`)})]}),(0,y.jsxs)(`div`,{className:`des-field des-field-checkbox`,children:[(0,y.jsxs)(`label`,{htmlFor:`des-allow-bot-mentions`,className:`des-checkbox-container`,children:[(0,y.jsx)(`input`,{id:`des-allow-bot-mentions`,type:`checkbox`,className:`des-checkbox`,checked:O.allowBotMentions,onChange:e=>Y(`allowBotMentions`,e.target.checked)}),(0,y.jsx)(`span`,{className:`des-label`,children:T(`deviceExecAllowBotMentions`)})]}),(0,y.jsx)(`span`,{className:`des-hint`,children:T(`deviceExecAllowBotMentionsHint`)})]})]})]}),(0,y.jsxs)(`div`,{className:`des-group`,children:[(0,y.jsxs)(`div`,{className:`des-group-header`,children:[(0,y.jsx)(m,{className:`des-group-icon`}),(0,y.jsx)(`span`,{className:`des-group-title`,children:T(`deviceExecContextTitle`)})]}),(0,y.jsxs)(`div`,{className:`des-fields-row`,children:[(0,y.jsxs)(`div`,{className:`des-field`,children:[(0,y.jsx)(`label`,{htmlFor:`des-group-context-bytes`,className:`des-label`,children:T(`deviceExecContextBytes`)}),(0,y.jsxs)(`div`,{className:`des-input-with-badge`,children:[(0,y.jsx)(`input`,{id:`des-group-context-bytes`,type:`number`,min:4096,max:2097152,step:1024,className:`des-input`,value:O.groupContextBytes,onChange:e=>J(`groupContextBytes`,parseInt(e.target.value,10)||4096),required:!0}),(0,y.jsx)(`span`,{className:`des-input-badge`,children:S(O.groupContextBytes)})]}),(0,y.jsx)(`span`,{className:`des-hint`,children:T(`deviceExecContextBytesHint`)})]}),(0,y.jsxs)(`div`,{className:`des-field`,children:[(0,y.jsx)(`label`,{htmlFor:`des-group-retention`,className:`des-label`,children:T(`deviceExecRetention`)}),(0,y.jsx)(`input`,{id:`des-group-retention`,type:`number`,min:50,max:2e4,step:10,className:`des-input`,value:O.groupRetentionLimit,onChange:e=>J(`groupRetentionLimit`,parseInt(e.target.value,10)||50),required:!0}),(0,y.jsx)(`span`,{className:`des-hint`,children:T(`deviceExecRetentionHint`)})]})]})]}),(0,y.jsxs)(`div`,{className:`des-group`,children:[(0,y.jsxs)(`div`,{className:`des-group-header`,children:[(0,y.jsx)(s,{className:`des-group-icon`}),(0,y.jsx)(`span`,{className:`des-group-title`,children:T(`deviceExecFileSyncTitle`)})]}),(0,y.jsxs)(`div`,{className:`des-fields-row`,children:[(0,y.jsxs)(`div`,{className:`des-field`,children:[(0,y.jsx)(`label`,{htmlFor:`des-file-sync-bytes`,className:`des-label`,children:T(`deviceExecFileSyncBytes`)}),(0,y.jsxs)(`div`,{className:`des-input-with-badge`,children:[(0,y.jsx)(`input`,{id:`des-file-sync-bytes`,type:`number`,min:1048576,max:10737418240,step:1048576,className:`des-input`,value:O.fileSyncMaxBytes,onChange:e=>J(`fileSyncMaxBytes`,parseInt(e.target.value,10)||1048576),required:!0}),(0,y.jsx)(`span`,{className:`des-input-badge`,children:S(O.fileSyncMaxBytes)})]}),(0,y.jsx)(`span`,{className:`des-hint`,children:T(`deviceExecFileSyncBytesHint`)})]}),(0,y.jsxs)(`div`,{className:`des-field`,children:[(0,y.jsx)(`label`,{htmlFor:`des-file-sync-files`,className:`des-label`,children:T(`deviceExecFileSyncFiles`)}),(0,y.jsx)(`input`,{id:`des-file-sync-files`,type:`number`,min:10,max:1e4,step:1,className:`des-input`,value:O.fileSyncMaxFiles,onChange:e=>J(`fileSyncMaxFiles`,parseInt(e.target.value,10)||10),required:!0}),(0,y.jsx)(`span`,{className:`des-hint`,children:T(`deviceExecFileSyncFilesHint`)})]}),(0,y.jsxs)(`div`,{className:`des-field`,children:[(0,y.jsx)(`label`,{htmlFor:`des-file-sync-staged-bytes`,className:`des-label`,children:T(`deviceExecFileSyncStagedBytes`)}),(0,y.jsxs)(`div`,{className:`des-input-with-badge`,children:[(0,y.jsx)(`input`,{id:`des-file-sync-staged-bytes`,type:`number`,min:4194304,max:53687091200,step:1048576,className:`des-input`,value:O.fileSyncStagedBytes,onChange:e=>J(`fileSyncStagedBytes`,parseInt(e.target.value,10)||4194304),required:!0}),(0,y.jsx)(`span`,{className:`des-input-badge`,children:S(O.fileSyncStagedBytes)})]}),(0,y.jsx)(`span`,{className:`des-hint`,children:T(`deviceExecFileSyncStagedBytesHint`)})]})]})]}),(0,y.jsxs)(`div`,{className:`des-group`,children:[(0,y.jsxs)(`div`,{className:`des-group-header`,children:[(0,y.jsx)(u,{className:`des-group-icon`}),(0,y.jsx)(`span`,{className:`des-group-title`,children:T(`deviceExecLocksTitle`)})]}),(0,y.jsxs)(`div`,{className:`des-fields-row`,children:[(0,y.jsxs)(`div`,{className:`des-field`,children:[(0,y.jsx)(`label`,{htmlFor:`des-resource-lock-ttl`,className:`des-label`,children:T(`deviceExecLockTtl`)}),(0,y.jsxs)(`div`,{className:`des-input-with-badge`,children:[(0,y.jsx)(`input`,{id:`des-resource-lock-ttl`,type:`number`,min:6e4,max:864e5,step:6e4,className:`des-input`,value:O.resourceLockDefaultTtlMs,onChange:e=>J(`resourceLockDefaultTtlMs`,parseInt(e.target.value,10)||6e4),required:!0}),(0,y.jsx)(`span`,{className:`des-input-badge`,children:C(O.resourceLockDefaultTtlMs)})]}),(0,y.jsx)(`span`,{className:`des-hint`,children:T(`deviceExecLockTtlHint`)})]}),(0,y.jsxs)(`div`,{className:`des-field`,children:[(0,y.jsx)(`label`,{htmlFor:`des-blackboard-bytes`,className:`des-label`,children:T(`deviceExecBlackboardBytes`)}),(0,y.jsxs)(`div`,{className:`des-input-with-badge`,children:[(0,y.jsx)(`input`,{id:`des-blackboard-bytes`,type:`number`,min:4096,max:4194304,step:1024,className:`des-input`,value:O.blackboardMaxBytes,onChange:e=>J(`blackboardMaxBytes`,parseInt(e.target.value,10)||4096),required:!0}),(0,y.jsx)(`span`,{className:`des-input-badge`,children:S(O.blackboardMaxBytes)})]}),(0,y.jsx)(`span`,{className:`des-hint`,children:T(`deviceExecBlackboardBytesHint`)})]})]})]}),(0,y.jsxs)(`div`,{className:`des-form-actions`,children:[(0,y.jsx)(`button`,{type:`button`,className:`des-btn des-btn-secondary`,disabled:M,onClick:X,children:T(`deviceExecResetDefaults`)}),(0,y.jsx)(`button`,{type:`button`,className:`des-btn des-btn-secondary`,disabled:M,onClick:Z,children:T(`deviceExecReset`)}),(0,y.jsx)(`button`,{type:`submit`,className:`des-btn des-btn-primary`,disabled:M,children:T(M?`deviceExecSaving`:`deviceExecSave`)})]})]}),E&&E.blocked&&E.blocked.length>0&&(0,y.jsxs)(`div`,{className:`des-section des-blocked-section`,children:[(0,y.jsxs)(`h4`,{className:`des-section-title is-danger`,children:[(0,y.jsx)(d,{}),` `,T(`deviceExecBlockedTitle`)]}),(0,y.jsx)(`p`,{className:`des-section-desc`,children:T(`deviceExecBlockedDesc`)}),(0,y.jsx)(`div`,{className:`des-table-wrap`,children:(0,y.jsxs)(`table`,{className:`des-table`,children:[(0,y.jsx)(`thead`,{children:(0,y.jsxs)(`tr`,{children:[(0,y.jsx)(`th`,{children:`Task ID`}),(0,y.jsx)(`th`,{children:`Room ID`}),(0,y.jsx)(`th`,{children:`Bot ID`}),(0,y.jsx)(`th`,{children:T(`deviceExecReason`)})]})}),(0,y.jsx)(`tbody`,{children:E.blocked.map(e=>(0,y.jsxs)(`tr`,{className:`des-row-blocked`,children:[(0,y.jsxs)(`td`,{className:`des-mono`,children:[e.taskId.slice(0,8),`...`]}),(0,y.jsx)(`td`,{children:e.roomId}),(0,y.jsx)(`td`,{children:e.botId}),(0,y.jsx)(`td`,{children:(0,y.jsx)(`span`,{className:`des-badge is-danger`,children:e.reason})})]},`${e.taskId}-${e.attemptId}`))})]})})]}),(0,y.jsxs)(`div`,{className:`des-section`,children:[(0,y.jsxs)(`h4`,{className:`des-section-title`,children:[(0,y.jsx)(i,{}),` `,T(`deviceExecActiveTasks`),` (`,E?.running?.length??0,`)`]}),E&&E.running&&E.running.length>0?(0,y.jsx)(`div`,{className:`des-table-wrap`,children:(0,y.jsxs)(`table`,{className:`des-table`,children:[(0,y.jsx)(`thead`,{children:(0,y.jsxs)(`tr`,{children:[(0,y.jsx)(`th`,{children:`Task ID`}),(0,y.jsx)(`th`,{children:`Room ID`}),(0,y.jsx)(`th`,{children:`Bot ID`}),(0,y.jsx)(`th`,{children:T(`deviceExecQueuedTime`)})]})}),(0,y.jsx)(`tbody`,{children:E.running.map(e=>(0,y.jsxs)(`tr`,{children:[(0,y.jsxs)(`td`,{className:`des-mono`,title:e.taskId,children:[e.taskId.slice(0,8),`...`]}),(0,y.jsx)(`td`,{children:e.roomId}),(0,y.jsx)(`td`,{children:e.botId}),(0,y.jsx)(`td`,{children:new Date(e.startedAt).toLocaleTimeString()})]},`${e.taskId}-${e.attemptId}`))})]})}):(0,y.jsx)(`div`,{className:`des-empty`,children:T(`deviceExecNoActive`)})]}),(0,y.jsxs)(`div`,{className:`des-section`,children:[(0,y.jsxs)(`h4`,{className:`des-section-title`,children:[(0,y.jsx)(l,{}),` `,T(`deviceExecWaitingQueue`),` (`,E?.waiting?.length??0,`)`]}),E&&E.waiting&&E.waiting.length>0?(0,y.jsx)(`div`,{className:`des-table-wrap`,children:(0,y.jsxs)(`table`,{className:`des-table`,children:[(0,y.jsx)(`thead`,{children:(0,y.jsxs)(`tr`,{children:[(0,y.jsx)(`th`,{children:T(`deviceExecPosition`)}),(0,y.jsx)(`th`,{children:`Task ID`}),(0,y.jsx)(`th`,{children:`Room ID`}),(0,y.jsx)(`th`,{children:`Bot ID`}),(0,y.jsx)(`th`,{children:T(`deviceExecReason`)}),(0,y.jsx)(`th`,{children:T(`deviceExecQueuedTime`)}),(0,y.jsx)(`th`,{children:T(`deviceExecActions`)})]})}),(0,y.jsx)(`tbody`,{children:E.waiting.map(e=>(0,y.jsxs)(`tr`,{children:[(0,y.jsx)(`td`,{children:(0,y.jsxs)(`span`,{className:`des-pos-badge`,children:[`#`,e.queuePosition]})}),(0,y.jsxs)(`td`,{className:`des-mono`,title:e.taskId,children:[e.taskId.slice(0,8),`...`]}),(0,y.jsx)(`td`,{children:e.roomId}),(0,y.jsx)(`td`,{children:e.botId}),(0,y.jsx)(`td`,{children:(0,y.jsxs)(`div`,{className:`des-reason-cell`,children:[(0,y.jsx)(`span`,{className:`des-badge des-badge-${e.blockReason}`,children:ee(e.blockReason)}),(0,y.jsx)(`span`,{className:`des-reason-detail`,children:e.blockReasonDetail})]})}),(0,y.jsx)(`td`,{children:new Date(e.queuedAt).toLocaleTimeString()}),(0,y.jsx)(`td`,{children:(0,y.jsx)(`button`,{type:`button`,className:`des-btn des-btn-danger-sm`,disabled:P===e.taskId,onClick:()=>void $(e.taskId,e.attemptId),children:P===e.taskId?T(`deviceExecCancelling`):T(`deviceExecCancel`)})})]},`${e.taskId}-${e.attemptId}`))})]})}):(0,y.jsx)(`div`,{className:`des-empty`,children:T(`deviceExecNoWaiting`)})]})]})}export{T as t};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$ as t,$t as n,A as r,B as i,Bt as a,C as o,E as s,En as c,Et as l,Fn as u,Ft as d,G as f,H as p,Ht as m,I as h,J as g,L as _,Lt as v,N as y,O as b,P as x,Pt as S,Q as C,R as w,Rn as T,Rt as E,V as D,Vt as O,W as k,X as A,Yt as j,Z as M,Zt as N,_ as P,a as F,an as I,at as L,b as R,cn as ee,ct as z,d as te,dn as B,en as V,et as ne,ft as re,i as ie,it as ae,k as oe,kn as H,ln as se,m as ce,mt as le,nn as ue,nt as de,on as fe,ot as pe,pt as me,q as he,rt as ge,sn as _e,t as ve,tt as ye,u as be,ut as xe,vn as U,vt as Se,wt as Ce,xt as we,yt as Te,z as Ee,zt as De}from"./fi-CcqqfamG.js";import{i as Oe,r as ke,t as Ae}from"./react-CR5VJ85Q.js";import{t as je}from"./shortcut-stack-hhrDyRBn.js";import{a as Me,n as Ne,t as Pe}from"./api-client-BbDlV0jR.js";import{t as Fe}from"./uuid-BzDIGCwP.js";import{n as Ie}from"./Dropdown-C8yx9mqF.js";import{i as Le,o as Re,t as W}from"./app-globals-wu8LLlnA.js";import{d as ze}from"./context-menu-state-CEfR7_Lz.js";function Be(e,t,n=`Device`){let r=e=>typeof e==`string`?e.trim().slice(0,256):``,i=r(e),a=r(t);return a&&i&&a!==i?`${a} · ${i}`:a||i||n}function Ve(e){if(e.transport===`p2p`)return e.relayed===!0?`turn`:e.route===`peer`?`peer`:`p2p`;if(e.transport===`lan`||e.transport===`hub`)return e.transport}function G(e,t){switch(e){case`lan`:return t(`desktop.lan`);case`p2p`:return t(`desktop.p2p`);case`turn`:return`TURN`;case`peer`:return t(`connected`);case`hub`:return t(`desktop.hub`);case`current`:return t(`desktop.currentConnection`);default:return t(`desktop.connecting`)}}function He(){return c().match(/\/(?:device|device-lan)\/([a-z0-9][a-z0-9-]{0,62})\/__relay\/[a-f0-9]{64}\/$/)?.[1]}async function K(e,t,n){let r=He();if(!r)return;let i=We;if(q)return;let a=await fetch(u(H(`/api/device-center/chat-status`)),{credentials:`same-origin`,signal:n?AbortSignal.any([n,AbortSignal.timeout(15e3)]):AbortSignal.timeout(15e3)});if(!a.ok)throw Error(`Device status unavailable`);let o=await a.json();n?.aborted||We!==i||q||await Ze(r,typeof o.hubUrl==`string`?o.hubUrl:``,!0,e,!1,Be(o.name,o.remark,t))}function Ue(e){return e.local===!0&&!He()}var q=null,We=0,Ge=new Set,Ke=()=>Ge.forEach(e=>e()),qe=e=>(Ge.add(e),()=>{Ge.delete(e)}),Je=()=>q;function Ye(e){q?.revision===e.revision&&(q=null,Ke())}function Xe(e,t){q?.revision===e.revision&&(q={...q,mode:t},Ke(),t===`preview`&&window.dispatchEvent(new Event(`pi:desktop-open`)))}async function J(e,t,n,r,i=!1,a,o=!1){if(n&&(o||e===He()))return{url:new URL(u(H(i?`/desktop-preview`:`/desktop`)),window.location.href).href,transport:`current`,fallbackOrigin:void 0};if(n&&He()){let t=new URL(H(`/__desktop_target`),window.location.href);return t.searchParams.set(`device`,e),t.searchParams.set(`preview`,i?`1`:`0`),{url:t.href,transport:`hub`,fallbackOrigin:void 0}}let s=await fetch(u(H(`/api/device-center/devices/${encodeURIComponent(e)}/open`)),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({preferLan:!0,desktop:n,basePath:new URL(H(`/`),window.location.href).pathname}),credentials:`same-origin`,signal:a?AbortSignal.any([a,AbortSignal.timeout(3e4)]):AbortSignal.timeout(3e4)});if(!s.ok)throw Error(r(`deviceAccessOpenFailed`));let c=await s.json(),l=c.transport===`lan`||c.transport===`p2p`,d=l?new URL(H(c.url),window.location.href):new URL(c.url),f=new URL(t),p=new URL(H(`/device-lan/${e}/__open`),window.location.href),m=l?typeof c.url==`string`&&/^\/device-lan\/[a-z0-9][a-z0-9-]{0,62}\/__open\?ticket=[a-f0-9]{64}$/.test(c.url)&&d.origin===p.origin&&d.pathname===p.pathname:d.hostname===f.hostname&&(d.pathname===`/__device/open`||d.origin===f.origin&&d.pathname===`/device/${encodeURIComponent(e)}/__open`);if(![`http:`,`https:`].includes(d.protocol)||d.username||d.password||!m)throw Error(`Invalid device access URL`);return d.searchParams.delete(`next`),n&&d.searchParams.set(`next`,i?`/desktop-preview`:`/desktop`),{url:d.href,transport:Ve(c)??`hub`,fallbackOrigin:c.fallbackOrigin}}async function Ze(e,t,n,r,i=!1,a,o){let s=T();if(s){if(!s.deviceAdapter)throw Error(`Native device access is unavailable`);await s.deviceAdapter.openDevice(e,t);return}if(n&&!i){q={id:e,hubUrl:t,name:a,revision:++We,...o,mode:o?.mode??`preview`},Ke(),window.dispatchEvent(new Event(`pi:desktop-open`));return}if(n&&i&&He()&&window.parent!==window){await Qe(r,e);return}let c=window.piDesktop,l=c?.openHub?null:window.open(`about:blank`,`_blank`);if(!c?.openHub&&!l)throw Error(r(`deviceAccessPopupBlocked`));if(l){try{l.document.open(),l.document.write(`<!doctype html><meta charset="utf-8"><title>${r(`deviceAccessOpening`)}</title><style>html,body{height:100%;margin:0}body{display:grid;place-items:center;background:#0d0e12;color:#9aa1b4;font:14px/1.6 -apple-system,"PingFang SC","Microsoft YaHei",sans-serif}</style><body>${r(`deviceAccessOpening`)}</body>`),l.document.close()}catch{}l.opener=null}try{let i=await J(e,t,n,r,!1,void 0,o?.local),a=new URL(i.url);if(c?.openHub){if(i.transport!==`hub`&&(a.searchParams.set(`hub`,new URL(t).origin),typeof i.fallbackOrigin==`string`&&a.searchParams.set(`portal`,i.fallbackOrigin)),!await c.openHub(a.href))throw Error(r(`deviceAccessWindowFailed`))}else l&&l.location.replace(a.href)}catch(e){throw l?.close(),e}}function Qe(e,t){let n=Fe(),r=new URL(H(`/`),window.location.href).origin;return new Promise((i,a)=>{let o=e=>{clearTimeout(l),window.removeEventListener(`message`,c),e?a(Error(e)):i()},s=e(`deviceAccessTabFailed`),c=t=>{t.source===window.parent&&t.origin===r&&t.data?.type===`device-desktop-open-result`&&t.data.requestId===n&&o(t.data.ok===!0?void 0:t.data.error===`popup`?e(`deviceAccessPopupBlocked`):s)},l=setTimeout(()=>o(s),3e4);window.addEventListener(`message`,c),window.parent.postMessage({type:`device-desktop-open`,requestId:n,deviceId:t},r)})}function $e(e){return B({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`rect`,attr:{width:`8`,height:`8`,x:`3`,y:`3`,rx:`2`},child:[]},{tag:`path`,attr:{d:`M7 11v4a2 2 0 0 0 2 2h4`},child:[]},{tag:`rect`,attr:{width:`8`,height:`8`,x:`13`,y:`13`,rx:`2`},child:[]}]})(e)}function et(e){return B({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M18 8V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v7a2 2 0 0 0 2 2h8`},child:[]},{tag:`path`,attr:{d:`M10 19v-3.96 3.15`},child:[]},{tag:`path`,attr:{d:`M7 19h5`},child:[]},{tag:`rect`,attr:{width:`6`,height:`10`,x:`16`,y:`12`,rx:`2`},child:[]}]})(e)}function tt(e){return B({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M14 9a2 2 0 0 1-2 2H6l-4 4V4a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2z`},child:[]},{tag:`path`,attr:{d:`M18 9h2a2 2 0 0 1 2 2v11l-4-4h-6a2 2 0 0 1-2-2v-1`},child:[]}]})(e)}function nt(e){return B({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M10 17H7l-4 4v-7`},child:[]},{tag:`path`,attr:{d:`M14 17h1`},child:[]},{tag:`path`,attr:{d:`M14 3h1`},child:[]},{tag:`path`,attr:{d:`M19 3a2 2 0 0 1 2 2`},child:[]},{tag:`path`,attr:{d:`M21 14v1a2 2 0 0 1-2 2`},child:[]},{tag:`path`,attr:{d:`M21 9v1`},child:[]},{tag:`path`,attr:{d:`M3 9v1`},child:[]},{tag:`path`,attr:{d:`M5 3a2 2 0 0 0-2 2`},child:[]},{tag:`path`,attr:{d:`M9 3h1`},child:[]}]})(e)}function rt(e){return B({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`m5 8 6 6`},child:[]},{tag:`path`,attr:{d:`m4 14 6-6 2-3`},child:[]},{tag:`path`,attr:{d:`M2 5h12`},child:[]},{tag:`path`,attr:{d:`M7 2h1`},child:[]},{tag:`path`,attr:{d:`m22 22-5-10-5 10`},child:[]},{tag:`path`,attr:{d:`M14 18h6`},child:[]}]})(e)}function it(e){return B({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M20 17a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-3.9a2 2 0 0 1-1.69-.9l-.81-1.2a2 2 0 0 0-1.67-.9H8a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2Z`},child:[]},{tag:`path`,attr:{d:`M2 8v11a2 2 0 0 0 2 2h14`},child:[]}]})(e)}function at(e){return B({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M20 10a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1h-2.5a1 1 0 0 1-.8-.4l-.9-1.2A1 1 0 0 0 15 3h-2a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z`},child:[]},{tag:`path`,attr:{d:`M20 21a1 1 0 0 0 1-1v-3a1 1 0 0 0-1-1h-2.9a1 1 0 0 1-.88-.55l-.42-.85a1 1 0 0 0-.92-.6H13a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z`},child:[]},{tag:`path`,attr:{d:`M3 5a2 2 0 0 0 2 2h3`},child:[]},{tag:`path`,attr:{d:`M3 3v13a2 2 0 0 0 2 2h3`},child:[]}]})(e)}function ot(e){return B({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M10 2v7.527a2 2 0 0 1-.211.896L4.72 20.55a1 1 0 0 0 .9 1.45h12.76a1 1 0 0 0 .9-1.45l-5.069-10.127A2 2 0 0 1 14 9.527V2`},child:[]},{tag:`path`,attr:{d:`M8.5 2h7`},child:[]},{tag:`path`,attr:{d:`M7 16h10`},child:[]}]})(e)}function st(e){return B({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`m16.24 7.76-1.804 5.411a2 2 0 0 1-1.265 1.265L7.76 16.24l1.804-5.411a2 2 0 0 1 1.265-1.265z`},child:[]},{tag:`circle`,attr:{cx:`12`,cy:`12`,r:`10`},child:[]}]})(e)}var Y=Ae(),ct=new Set([`svg`,`g`,`path`,`circle`,`rect`,`line`,`polyline`,`polygon`,`ellipse`,`use`,`defs`,`clipPath`,`linearGradient`,`radialGradient`,`stop`]),lt=new Set(`viewBox.xmlns.d.fill.stroke.stroke-width.stroke-linecap.stroke-linejoin.stroke-dasharray.opacity.x.y.x1.y1.x2.y2.cx.cy.r.rx.ry.width.height.points.offset.stop-color.stop-opacity.fill-opacity.stroke-opacity.stroke-miterlimit.fill-rule.clip-rule.vector-effect.preserveAspectRatio.transform.clip-path.id.href.xlink:href.xmlns:xlink.gradientUnits.gradientTransform`.split(`.`)),ut=new Set([`script`,`style`,`title`,`desc`,`foreignobject`]),dt=new Set([...ct].map(e=>e.toLowerCase())),ft=new Set([...lt].map(e=>e.toLowerCase()));function pt(e){return dt.has(e.toLowerCase())}function mt(e){return ft.has(e.toLowerCase())}function ht(e){if(typeof e!=`string`)return null;let t=e.trim();if(!t||t.length>8192||!/^<svg[\s>]/.test(t.startsWith(`<?xml`)?t.slice(t.indexOf(`?>`)+2).trimStart():t))return null;if(typeof DOMParser>`u`)return/<script[\s>]/i.test(t)||/\son\w+\s*=/i.test(t)||/javascript\s*:/i.test(t)?null:t;let n=new DOMParser().parseFromString(t,`image/svg+xml`);if(n.querySelector(`parsererror`))return null;let r=n.documentElement;if(r.tagName.toLowerCase()!==`svg`)return null;let i=e=>{for(let t of Array.from(e.children)){let e=t.tagName.toLowerCase();if(!pt(e)){ut.has(e)?t.remove():(i(t),t.replaceWith(...t.childNodes));continue}for(let e of Array.from(t.attributes)){let n=e.name.toLowerCase();(!mt(n)||/^on/i.test(n)||/^(javascript|data|vbscript):/i.test(e.value.trim()))&&t.removeAttribute(e.name)}i(t)}};for(let e of Array.from(r.attributes)){let t=e.name.toLowerCase();(!mt(t)||/^on/i.test(t))&&r.removeAttribute(e.name)}return i(r),new XMLSerializer().serializeToString(r)}function gt({icon:e,iconSvg:t,className:n}){let r=ht(t);return r?(0,Y.jsx)(`span`,{className:n??`plugin-icon-svg`,"aria-hidden":!0,dangerouslySetInnerHTML:{__html:r}}):e?(0,Y.jsx)(`span`,{className:n?`${n} plugin-icon-glyph`:`plugin-icon-glyph`,"aria-hidden":!0,children:e}):null}function _t(e,t){e&&W({type:`open_bot_chat`,botId:e,...t?.fresh?{fresh:!0}:{}})}function vt(){window.dispatchEvent(new CustomEvent(`pi-web-ui:device-group-open`,{detail:{}}))}function yt(e,t,n,r){return e.flatMap(e=>[{providerId:`host:group-devices`,providerLabel:r(`newChat`),title:e.name,hint:e.id,text:`@${e.name} · ${r(`newChat`)}`},...t.filter(t=>t.botId===e.id&&t.status!==`closed`&&!t.stale).map(t=>({providerId:`host:group-conversations`,providerLabel:r(`deviceGroupMentionContinue`),title:`${e.name} · ${t.name||r(`groupDeliveriesUntitledConversation`)}`,hint:t.id,text:`@${e.name} · ${r(`deviceGroupMentionContinuePrefix`)}${t.name||r(`groupDeliveriesUntitledConversation`)}`}))].filter(t=>`${t.title} ${t.providerLabel} ${e.id}`.toLocaleLowerCase().includes(n.toLocaleLowerCase())))}function bt(e){return`@${e.name}(${e.id})`}function X(e){return e.replace(/@([^\s()]+)\([a-f0-9-]{8,}\)/g,`@$1`)}function xt(e,t){let n=X(e),r=n.match(/^@([^\s()]+)\s*(.*)$/);return r?{botPrefix:`@${r[1]}`,summary:r[2].trim()||n}:{botPrefix:t?`@${t}`:``,summary:n}}function Z(e,t){if(!e.includes(`Device task failed`))return X(e);let n=e.match(/Device task failed\s*\[phase=([^;]+);\s*category=([^\]]+)\]\.\s*(.*)/s);if(!n)return X(e);let[,r,i,a]=n,o={model:t(`deviceGroupFailurePhaseModel`),tool:t(`deviceGroupFailurePhaseTool`),approval:t(`deviceGroupFailurePhaseApproval`),connection:t(`deviceGroupFailurePhaseConnection`),handshake:t(`deviceGroupFailurePhaseHandshake`),init:t(`deviceGroupFailurePhaseInit`),switch_session:t(`deviceGroupFailurePhaseSwitchSession`),new_chat:t(`deviceGroupFailurePhaseNewChat`)}[r]||r,s=a.trim();return[t(`deviceGroupFailureTitle`,{phase:o}),`>`,t(`deviceGroupFailureMeta`,{phase:r,category:i}),`>`,`> ${s||t(`deviceGroupFailureDetailFallback`)}`].join(`
|
|
2
|
+
`)}function St(e,t){return[...new Set(t.filter(t=>e.includes(bt(t))).map(e=>e.id))]}function Ct(e,t,n,r){let i=new Map,a=[],o=new Map(n.map(e=>[e.id,e]));for(let e of t?.bots??[])o.set(e.id,{...o.get(e.id),...e});let s={queued:r(`groupWorkItemsStatusQueued`),waiting:r(`deviceGroupStatusWaitingDependency`),running:r(`tabRunning`),completed:r(`groupWorkItemsStatusCompleted`),failed:r(`groupWorkItemsStatusFailed`),interrupted:r(`groupWorkItemsStatusInterrupted`)},c=new Map((t?.tasks??[]).map(e=>[e.id,e])),l=new Set,u=(e,t,n)=>{let r=e?o.get(e):void 0,i=r?.deviceName||n||r?.deviceId;return i?`${t} · ${i}`:t};for(let e of t?.messages??[]){let n=`group-message:${e.id}`,d=e.sender.type===`bot`,f=e.text,p=d?Z(f,r):X(f);if(e.sharedFrom){let t=o.get(e.sharedFrom.botId)?.name??e.sharedFrom.botId;p=`${e.sharedFrom.mode===`as_bot`?r(`deviceGroupSharedFromBot`,{bot:t}):r(`deviceGroupSharedFromForward`,{bot:t})}\n\n${p}`}let m=e.replyToMessageId?t?.messages.find(t=>t.id===e.replyToMessageId):void 0;if(m){let e=X(m.text).replace(/\s+/g,` `).slice(0,120);p=`> ↩ ${m.sender.name}: ${e}\n\n${p}`}if(a.push({id:n,role:d?`assistant`:`user`,timestamp:e.createdAt,content:[{type:`text`,text:p}]}),!d){let t=e.sender.type===`webhook`?` [Webhook]`:``;i.set(n,`${e.sender.name}${t}`);continue}let h=(e.taskIds??[]).map(e=>c.get(e)).filter(t=>!!t&&t.botId===e.sender.id);for(let e of h)e.report&&l.add(e.id);let g=[...new Set(h.map(e=>s[e.status]))].join(` · `),_=t?.room.primaryBotId&&e.sender.id===t.room.primaryBotId?` [${r(`deviceGroupCoordinatorTag`)}]`:``,v=`${u(e.sender.id,e.sender.name,e.sender.sourceDeviceId)}${_}`;i.set(n,g?`${v} · ${g}`:v)}for(let e of t?.tasks??[]){if(l.has(e.id)||e.kind===`result`)continue;let t=`group-task:${e.id}`,n=o.get(e.botId),d=!!(e.parentTaskId||e.sourceBotId&&e.sourceBotId!==e.botId),f=r(`deviceGroupWorkerSubagent`),p=u(e.botId,n?.name??e.botId,e.deviceId),m=e.status===`waiting`?e.dependsOnTaskId?r(`groupConversationWaitingUpstream`):r(`deviceGroupStatusWaitingDependency`):s[e.status]??e.status;i.set(t,d?`${p} [${f}] · ${m}`:`${p} · ${m}`);let h=e.report,g=X(e.text),_;if(h){if(d){let t=r(`deviceGroupSubagentSummary`);_=[r(`deviceGroupSubagentCompleted`,{bot:n?.name??e.botId}),r(`deviceGroupInstructionLine`,{label:r(`deviceGroupInstructionAssigned`),text:g}),``,`<details>`,`<summary>${t}</summary>`,``,Z(h,r),``,`</details>`].join(`
|
|
3
|
+
`)}else _=Z(h,r)}else if(e.status===`running`){let t=r(d?`deviceGroupSubagentRunning`:`deviceGroupTaskRunning`),i=e.progress?.phase,a=e.progress?.toolName,o=e.progress?.text?.trim();_=[`⏳ **${t}**${d?` · \`@${n?.name??e.botId}\``:``}`,r(`deviceGroupInstructionLine`,{label:r(d?`deviceGroupInstructionAssigned`:`deviceGroupInstructionGoal`),text:g}),...i?[r(`deviceGroupProgressPhaseLine`,{phase:i,tool:a?` · \`${a}\``:``})]:[],...o?[``,`> ${o}`]:[]].join(`
|
|
4
|
+
`)}else if(e.status===`waiting`){let t=e.dependsOnTaskId?c.get(e.dependsOnTaskId):void 0,i=t?o.get(t.botId)?.name??t.botId:void 0,a=t?xt(t.text,i).summary:e.dependsOnTaskId;_=[`${r(`deviceGroupWaitingUpstreamTitle`)}${d?` · \`@${n?.name??e.botId}\``:``}`,r(`deviceGroupInstructionLine`,{label:r(d?`deviceGroupInstructionAssigned`:`deviceGroupInstructionGoal`),text:g}),...e.dependsOnTaskId?[r(`deviceGroupDependsOnLine`,{dep:`${i?`@${i} · `:``}${a||e.dependsOnTaskId}`})]:[]].join(`
|
|
5
|
+
`)}else _=e.status===`queued`?[`⏱️ **${r(d?`deviceGroupSubagentQueued`:`deviceGroupTaskQueued`)}**${d?` · \`@${n?.name??e.botId}\``:``}`,r(`deviceGroupInstructionLine`,{label:r(d?`deviceGroupInstructionAssigned`:`deviceGroupInstructionGoal`),text:g})].join(`
|
|
6
|
+
`):e.status===`failed`&&d?[r(`deviceGroupSubagentFailed`,{bot:n?.name??e.botId}),r(`deviceGroupInstructionLine`,{label:r(`deviceGroupInstructionAssigned`),text:g}),...h?[``,Z(h,r)]:[]].join(`
|
|
7
|
+
`):`${s[e.status]||e.status}\n\n${g}`;a.push({id:t,role:`assistant`,timestamp:e.createdAt,content:[{type:`text`,text:_}]})}return a.sort((e,t)=>(e.timestamp??0)-(t.timestamp??0)),{state:{clientId:`device-group`,cwd:``,sessionId:`device-group:${e}`,conversationId:`device-group:${e}`,rev:0,messages:a,streamingMessage:null,isStreaming:!1,model:null,thinkingLevel:``,availableThinkingLevels:[],queue:{steering:[],followUp:[]},tools:[],version:0,piConfigured:!0,piAgentInstalled:!0,stats:{totalMessages:a.length,tokens:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0},cost:0,contextUsage:{tokens:null,contextWindow:0,percent:null}}},labels:i}}function wt(e,t,n,r,i){let a=JSON.stringify({roomId:t,text:n,targetBotIds:[...r].sort()});return e?.fingerprint===a?e:{fingerprint:a,key:i()}}function Tt(e){let t=e.filter(e=>e.conversationId);if(!t.length)return;let n=t[0].conversationId;if(e.some(e=>e.conversationId!==n))throw Error(`同一条消息只能继续一个对话,请移除其他 @ 目标。 / Continue one conversation per message. Remove other @ targets.`);return n}function Et(e,t,n){let r=0;for(;r<e.length&&r<t.length&&e[r]===t[r];)r++;let i=e.length,a=t.length;for(;i>r&&a>r&&e[i-1]===t[a-1];)i--,a--;return n.flatMap(e=>{if(e.end<=r)return[e];if(e.start>=i){let t=a-i;return[{...e,start:e.start+t,end:e.end+t}]}return[]})}function Dt(e,t){let n=e;for(let e of[...t].sort((e,t)=>t.start-e.start))n=n.slice(0,e.start)+bt(e.member)+n.slice(e.end);return{text:n,targets:[...new Set(t.map(e=>e.member.id))]}}function Ot(e,t,n,r,i){let a=i.filter(i=>t===n?r===`Backspace`?t>i.start&&t<=i.end+ +(e[i.end]===` `):t>=i.start&&t<i.end:t<i.end&&n>i.start);return a.length?{start:Math.min(t,...a.map(e=>e.start)),end:Math.max(n,...a.map(e=>e.end))}:null}var kt=new Map,At=new Map;function jt(e,t){let n=At.get(e);if(n)n(t);else{let n=kt.get(e)??[];n.some(e=>e.id===t.id)||n.push(t),kt.set(e,n)}window.dispatchEvent(new CustomEvent(`pi-web-ui:device-group-open`,{detail:{roomId:e}}))}function Mt(e,t){At.set(e,t);let n=kt.get(e)??[];kt.delete(e);for(let e of n)t(e);return()=>{At.get(e)===t&&At.delete(e)}}function Nt(e,t,n){let r=`@${n.name}`,i=e.slice(0,t),a=`${i&&!/\s$/.test(i)?` `:``}${r} `;return{text:i+a+e.slice(t),cursor:t+a.length}}var Q=e(Oe(),1);function Pt({botIds:e,roomId:t}){let n=U(),[r,i]=(0,Q.useState)(null),[a,o]=(0,Q.useState)(``),[s,c]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{let e=!1,t,r;async function a(){t=new AbortController;try{let r=async e=>{let r=await fetch(u(H(`/api/device-center/${e}`)),{credentials:`same-origin`,signal:AbortSignal.any([t.signal,AbortSignal.timeout(15e3)])});if(!r.ok)throw Error(n(`deviceGroupMembers.loadFailed`));return r.json()},[a,s]=await Promise.all([r(`chat-status`),r(`bots`)]);if(!a.hubUrl||!Array.isArray(s.bots))throw Error(n(`deviceGroupMembers.invalidBinding`));e||(i({hubUrl:a.hubUrl,deviceId:a.deviceId,bots:s.bots}),o(``))}catch(t){e||o(t instanceof Error?t.message:String(t))}finally{t.abort(),e||(r=setTimeout(a,15e3))}}return a(),()=>{e=!0,t?.abort(),clearTimeout(r)}},[n]);async function d(e,t){if(r&&!s){c(!0);try{await Ze(e.deviceId,r.hubUrl,t,n,!1,e.name),o(``)}catch(e){o(e instanceof Error?e.message:String(e))}finally{c(!1)}}}return(0,Y.jsxs)(`div`,{className:`dg-side-members`,children:[a&&(0,Y.jsx)(`div`,{className:`dg-side-error`,role:`alert`,children:a}),!r&&!a&&(0,Y.jsx)(`div`,{className:`dg-side-empty`,children:n(`loading`)}),e.length===0&&(0,Y.jsx)(`div`,{className:`dg-side-empty`,children:n(`deviceGroupMembers.empty`)}),r&&e.map(e=>{let i=r.bots.find(t=>t.id===e);return(0,Y.jsx)(`div`,{className:`dg-side-member`,children:(0,Y.jsxs)(`div`,{className:`dg-side-member-name`,title:i?.name||e,children:[(0,Y.jsx)(`span`,{children:i?.name||e}),(0,Y.jsx)(`small`,{children:i?.online?n(`deviceHubOnline`):n(`deviceHubOffline`)}),t&&i&&(0,Y.jsx)(`button`,{type:`button`,className:`dg-side-toggle`,title:n(`deviceGroupMembers.reference`),"aria-label":`${n(`deviceGroupMembers.reference`)} · ${i.name}`,onClick:()=>jt(t,i),children:(0,Y.jsx)(ce,{"aria-hidden":!0})}),i?.deviceId&&r.deviceId&&i.deviceId!==r.deviceId&&(0,Y.jsxs)(`div`,{className:`dg-side-member-actions`,children:[(0,Y.jsx)(`button`,{type:`button`,className:`dg-side-toggle`,title:n(`deviceDirectory.remoteDesktop`),"aria-label":n(`deviceDirectory.remoteDesktop`),disabled:s||!i?.deviceId,onClick:()=>i&&void d(i,!0),children:(0,Y.jsx)(l,{"aria-hidden":!0})}),(0,Y.jsx)(`button`,{type:`button`,className:`dg-side-toggle`,title:n(`deviceGroupMembers.openDevice`),"aria-label":n(`deviceGroupMembers.openDevice`),disabled:s||!i?.deviceId,onClick:()=>i&&void d(i,!1),children:(0,Y.jsx)(k,{"aria-hidden":!0})})]})]})},e)})]})}async function Ft(e,t){let n;try{n=JSON.parse(await e.text())}catch{throw Error(`Bot bundle is not valid JSON`)}let r=await Xn(`bot-import`,t??new AbortController().signal,{bundle:n});return window.dispatchEvent(new CustomEvent(`pi-web-ui:device-bots-changed`)),{name:r?.bot?.name??e.name,imported:r?.imported??0,skipped:r?.skipped??0}}function It(e,t){let n=e.trim();if(/^ssh:\/\//i.test(n))return n;let r=n.replace(/\\/g,`/`);if(!r)return``;let i=/^(?:[a-z]:\/|\/)/i.test(r)?r:`${t.replace(/\\/g,`/`).replace(/\/$/,``)}/${r}`,a=i.match(/^(?:[a-z]:\/|\/\/[^/]+\/[^/]+\/?|\/)/i)?.[0];if(!a)return r;let o=[];for(let e of i.slice(a.length).split(`/`))e===`..`?o.pop():e&&e!==`.`&&o.push(e);return a.replace(/\/$/,``)+`/`+o.join(`/`)}function Lt(e,t,n){let r=Math.max(8,e.left-8),i=e.bottom+8;return r+t.width>n.width-8&&(r=Math.max(8,e.right+8-t.width)),i+t.height>n.height-8&&(i=Math.max(8,e.top-8-t.height)),{left:r,top:i}}function Rt(){return typeof window<`u`&&window.matchMedia?.(`(hover: hover) and (pointer: fine)`)?.matches===!0}var zt=ke();function Bt(e){let t=(0,Q.useRef)(null),n=(0,Q.useRef)(null),[r,i]=(0,Q.useState)(!1),[a,o]=(0,Q.useState)({left:0,top:0});return(0,Q.useEffect)(()=>{if(!r)return;let e=n.current,i=t.current;if(!e||!i)return;let a=e.getBoundingClientRect(),s=Lt(i.getBoundingClientRect(),a,{width:window.innerWidth,height:window.innerHeight});o(e=>e.left===s.left&&e.top===s.top?e:s)},[r,e]),(0,Q.useEffect)(()=>{if(!r)return;let e=0,a=()=>{cancelAnimationFrame(e),e=requestAnimationFrame(()=>{let e=t.current,r=n.current;if(!e||!r)return;let a=e.getBoundingClientRect();if(a.bottom<0||a.top>window.innerHeight||a.right<0||a.left>window.innerWidth){i(!1);return}let s=Lt(a,r.getBoundingClientRect(),{width:window.innerWidth,height:window.innerHeight});o(e=>e.left===s.left&&e.top===s.top?e:s)})};return window.addEventListener(`scroll`,a,!0),window.addEventListener(`resize`,a),()=>{cancelAnimationFrame(e),window.removeEventListener(`scroll`,a,!0),window.removeEventListener(`resize`,a)}},[r]),{anchorRef:t,show:()=>{let e=t.current?.getBoundingClientRect();e&&(o({left:Math.max(8,e.left-8),top:e.bottom+8}),i(!0))},hide:()=>i(!1),onKeyDown:e=>{e.key===`Escape`&&e.target.blur()},tipPortal:r&&(0,zt.createPortal)((0,Y.jsx)(`span`,{ref:n,className:`set-tip-bubble open`,role:`tooltip`,style:{position:`fixed`,left:a.left,top:a.top},children:e}),document.body)}}function Vt({text:e}){let{anchorRef:t,show:n,hide:r,onKeyDown:i,tipPortal:a}=Bt(e);return(0,Y.jsxs)(`span`,{ref:t,className:`set-tip`,tabIndex:0,"aria-label":e,onMouseEnter:n,onMouseLeave:r,onFocus:n,onBlur:r,onKeyDown:i,children:[(0,Y.jsx)(ae,{}),a]})}function $({tip:e,children:t,onMouseEnter:n,onMouseLeave:r,onFocus:i,onBlur:a,onKeyDown:o,...s}){let{anchorRef:c,show:l,hide:u,onKeyDown:d,tipPortal:f}=Bt(e);return(0,Y.jsxs)(`button`,{ref:c,type:`button`,"aria-label":s[`aria-label`]??e,...s,onMouseEnter:e=>{l(),n?.(e)},onMouseLeave:e=>{u(),r?.(e)},onFocus:e=>{l(),i?.(e)},onBlur:e=>{u(),a?.(e)},onKeyDown:e=>{d(e),o?.(e)},children:[t,f]})}var Ht=new Set;function Ut(e){return Ht.add(e),()=>{Ht.delete(e)}}function Wt(e){for(let t of Ht)try{t(e)}catch(e){console.error(`[remote-ssh-client] listener error:`,e)}}function Gt(e,t,n,r){return`ssh://${e}@${t}:${n}${r.startsWith(`/`)?r:`/${r}`}`}function Kt(e){return!!(e&&e.startsWith(`ssh://`))}function qt(e){if(!Kt(e))return null;let t=/^ssh:\/\/([^@]+)@([^:]+):(\d+)(\/.*)$/.exec(e);return t?{username:t[1],host:t[2],port:parseInt(t[3],10),remotePath:t[4]}:null}var Jt=1;function Yt(e,t){let n=`probe_${Date.now()}_${Jt++}`;return new Promise(r=>{let i=Ut(e=>{e.type===`remote_ssh_probe_result`&&e.reqId===n&&(i(),r({ok:e.ok,connectionId:e.connectionId,error:e.error,system:e.system,tools:e.tools,packageManager:e.packageManager,suggestedInstall:e.suggestedInstall,hostTrust:e.hostTrust,profileSaveError:e.profileSaveError}))});W({type:`remote_ssh_probe`,reqId:n,params:e})||(i(),r({ok:!1,error:t(`remoteSshSocketDownRetry`)}))})}function Xt(e,t,n){let r=`listdir_${Date.now()}_${Jt++}`;return new Promise(i=>{let a=Ut(e=>{e.type===`remote_ssh_list_dir_result`&&e.reqId===r&&(a(),i({ok:e.ok,connectionId:e.connectionId,path:e.path,parentPath:e.parentPath,items:e.items,error:e.error}))});W({type:`remote_ssh_list_dir`,reqId:r,connectionId:e,path:n})||(a(),i({ok:!1,connectionId:e,path:n||`/`,items:[],error:t(`remoteSshSocketDown`)}))})}function Zt(e,t,n){let r=`install_${Date.now()}_${Jt++}`;return new Promise(i=>{let a=Ut(e=>{e.type===`remote_ssh_install_result`&&e.reqId===r&&(a(),i({ok:e.ok,connectionId:e.connectionId,tool:e.tool,output:e.output,error:e.error}))});W({type:`remote_ssh_install_tools`,reqId:r,connectionId:e,tools:t})||(a(),i({ok:!1,connectionId:e,tool:t[0]||``,error:n(`remoteSshSocketDown`)}))})}function Qt(){let e=`profiles_${Date.now()}_${Jt++}`;return new Promise(t=>{let n=Ut(r=>{r.type===`remote_ssh_profiles_result`&&r.reqId===e&&(n(),t({profiles:r.profiles,localKeys:r.localKeys??[]}))});W({type:`remote_ssh_list_profiles`,reqId:e})||(n(),t({profiles:[],localKeys:[]}))})}function $t(e){W({type:`remote_ssh_delete_profile`,name:e})}function en(e,t){let n=`trust_${Date.now()}_${Jt++}`;return new Promise(r=>{let i=Ut(e=>{e.type===`remote_ssh_trust_host_result`&&e.reqId===n&&(i(),r({ok:e.ok,error:e.error}))});W({type:`remote_ssh_trust_host`,reqId:n,...e})||(i(),r({ok:!1,error:t(`remoteSshSocketDown`)}))})}var tn=`@root`,nn=e=>e.endsWith(`/`)?e:e+`/`;function rn(e,t){let n=t.trim(),r=e.replace(/\\/g,`/`);return r.endsWith(`/`)?r+n:(/^[A-Za-z]:$/.test(r),r+`/`+n)}function an(e){let t=e.trim();return!(!t||t===`.`||t===`..`||t.includes(`/`)||t.includes(`\\`))}var on=e=>{let t=e.endsWith(`/`)&&e!==`/`?e.slice(0,-1):e;if(t===`@root`||t===`/`)return null;let n=t.lastIndexOf(`/`);if(n<0)return/^[A-Za-z]:$/.test(t)?tn:null;if(n===0)return`/`;let r=t.slice(0,n);return/^[A-Za-z]:$/.test(r)?r+`/`:r},sn=`pi-web-ui:project-picker-tab`;function cn(){try{let e=localStorage.getItem(sn);return e===`local`||e===`remote`?e:null}catch{return null}}function ln({currentCwd:e,pathCompletions:t,workspaceRoots:r,onClose:i,onSelectDirectory:a,mode:o=`folder`,onCreateProject:s,className:c,backdropClassName:u,role:d,ariaLabel:f,localOnly:p=!1,initialTab:m,portalContainer:h}){let g=U(),_=Re().remoteSsh&&!p,v=Le(`homeDir`),y=Le(`desktopDir`),b=Le(`pathCompletions`),x=Le(`workspaceRoots`),S=t&&t.length>0?t:b??[],w=r&&r.length>0?r:x??[],[T,E]=(0,Q.useState)(()=>_?m===`local`||m===`remote`?m:cn()||(Kt(e)?`remote`:`local`):`local`),D=e=>{E(e);try{localStorage.setItem(sn,e)}catch{}};(0,Q.useEffect)(()=>{!_&&T===`remote`&&D(`local`)},[_,T]);let[k,A]=(0,Q.useState)(``),[j,N]=(0,Q.useState)(``),[F,I]=(0,Q.useState)(!1),[ee,z]=(0,Q.useState)(``),[B,V]=(0,Q.useState)(null),[ne,re]=(0,Q.useState)(-1),ie=(0,Q.useRef)(null),ae=(0,Q.useRef)(null),[oe,H]=(0,Q.useState)([]),[se,ce]=(0,Q.useState)(``),[le,ue]=(0,Q.useState)(`22`),[de,fe]=(0,Q.useState)(``),[pe,me]=(0,Q.useState)(`password`),[he,ve]=(0,Q.useState)(``),[xe,Se]=(0,Q.useState)(``),[Ce,we]=(0,Q.useState)([]),[Te,Ee]=(0,Q.useState)(!1),[De,Oe]=(0,Q.useState)(!0),[ke,Ae]=(0,Q.useState)(``),[Me,Ne]=(0,Q.useState)(!1),[Pe,Fe]=(0,Q.useState)(null),[Ie,ze]=(0,Q.useState)(!1),[Be,Ve]=(0,Q.useState)(!1),[G,He]=(0,Q.useState)(null),[K,Ue]=(0,Q.useState)(null),[q,We]=(0,Q.useState)(null),[Ge,Ke]=(0,Q.useState)(null),[qe,Je]=(0,Q.useState)([]),[Ye,Xe]=(0,Q.useState)(!1),[J,Ze]=(0,Q.useState)(`/`),[Qe,$e]=(0,Q.useState)(`/`),[et,tt]=(0,Q.useState)([]),[nt,rt]=(0,Q.useState)(!1),[it,at]=(0,Q.useState)(!1),[ot,st]=(0,Q.useState)(``),[ct,lt]=(0,Q.useState)(null),ut=S.filter(e=>e.type===`dir`);(0,Q.useEffect)(()=>{if(Kt(e)){let t=qt(e);t&&(ce(t.host),ue(String(t.port)),fe(t.username),Ze(t.remotePath),$e(t.remotePath))}else{let t=(e||``).replace(/\\/g,`/`);A(t),N(t)}I(!1),z(``),V(null),re(-1)},[e]),(0,Q.useEffect)(()=>{let e=requestAnimationFrame(()=>{ie.current?.focus()});return()=>cancelAnimationFrame(e)},[T]),je(()=>{F||it?(I(!1),z(``),V(null),at(!1),st(``),lt(null)):i()}),(0,Q.useEffect)(()=>{if(T!==`local`)return;let e=setTimeout(()=>{W({type:`complete_path`,path:nn(k)})},60);return()=>clearTimeout(e)},[k,T]),(0,Q.useEffect)(()=>{if(T!==`local`||j===k)return;let e=setTimeout(()=>{W({type:`complete_path`,path:j})},150);return()=>clearTimeout(e)},[j,k,T]);let dt=e=>{let t=e.trim();t&&t!==`@root`&&a(t)},ft=e=>{A(e),N(e),re(-1),V(null)},pt=()=>{let e=ee.trim();if(e&&k!==`@root`){if(o===`project`){if(!an(e)){V(g(`invalidProjectName`));return}let t=rn(k,e);s?s(t):(W({type:`make_dir`,path:t}),a(t)),I(!1),z(``),V(null),i()}else W({type:`make_dir`,path:`${nn(k)}${e}`}),setTimeout(()=>{W({type:`complete_path`,path:nn(k)})},80),z(``),I(!1)}},mt=e=>{if(e.key===`Escape`)e.stopPropagation(),F?(I(!1),z(``),V(null)):i();else if(e.key===`Enter`&&!e.nativeEvent.isComposing)dt(j);else if(e.key===`Tab`){if(ut.length===0)return;e.preventDefault();let t=ne>=0?(ne+1)%ut.length:0;re(t),N(ut[t].path),A(ut[t].path)}},ht=async t=>{let n=(t?.host??se).trim(),r=t?.port??(parseInt(le,10)||22),i=(t?.username??de).trim();if(!n||!i){Fe(g(`directoryBrowser.missingHost`));return}Ne(!0),Fe(null);let a=await Yt({host:n,port:r,username:i,auth:t?.auth??(pe===`password`?{type:`password`,password:he}:pe===`key`?{type:`key`,privateKeyPath:xe}:{type:`agent`}),saveProfile:De,profileName:t?.profileName||ke.trim()||void 0},g);if(Ne(!1),!a.ok||!a.connectionId){He(a.hostTrust??null),ze(!1),Fe(a.error||g(`directoryBrowser.connectFailed`));return}Ue(a.connectionId),a.profileSaveError&&Fe(a.profileSaveError),We(a.system??null),Ke(a.tools??null),Je(a.suggestedInstall??[]);let o=Kt(e)?qt(e)?.remotePath:null,s=o&&o!==`/`?o:a.system?.homeDir||`/`;Ze(s),$e(s),_t(a.connectionId,s),Qt().then(({profiles:e,localKeys:t})=>{H(e),we(t)})},gt=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{T===`remote`&&Qt().then(({profiles:t,localKeys:n})=>{if(H(t),we(n),Se(e=>e||n[0]||``),!gt.current&&!K&&!Me&&Kt(e)){let n=qt(e);if(n){let e=t.find(e=>e.host===n.host&&(e.username===n.username||!n.username)&&(e.port===n.port||!n.port&&e.port===22))||t.find(e=>e.host===n.host&&e.username===n.username)||t.find(e=>e.host===n.host);e&&(gt.current=!0,ce(e.host),ue(String(e.port)),fe(e.username),me(e.authType),e.privateKeyPath&&Se(e.privateKeyPath),ht({host:e.host,port:e.port,username:e.username,profileName:e.name,auth:e.authType===`password`?{type:`password`,password:``}:e.authType===`key`?{type:`key`,privateKeyPath:e.privateKeyPath}:{type:`agent`}}))}}})},[T,e,K,Me]);let _t=async(e,t)=>{rt(!0),Fe(null);let n=await Xt(e,g,t);rt(!1),n.ok?(Ze(n.path),$e(n.path),tt(n.items)):Fe(n.error||g(`directoryBrowser.readDirFailed`))},vt=async e=>{if(!K)return;Xe(!0),Fe(null);let t=await Zt(K,[e],g);Xe(!1),t.ok?(Je(t=>t.filter(t=>t!==e)),Ge&&e===`git`&&Ke({...Ge,git:{installed:!0,version:g(`directoryBrowser.installed`)}})):Fe(t.error||g(`directoryBrowser.installToolFailed`,{tool:e}))},yt=e=>{let t=parseInt(le,10)||22,n=q?.homeDir||`/`,r=(e||``).trim()||J||`/`;r===`~`?r=n:(r.startsWith(`~/`)||r.startsWith(`~\\`))&&(r=`${n.replace(/\/+$/,``)}/${r.slice(2).replace(/\\/g,`/`)}`),a(Gt(de,se,t,r)),i()},bt=()=>{let e=ot.trim();if(!e||!K)return;if(!an(e)){lt(g(`invalidProjectName`));return}let t=parseInt(le,10)||22,n=J.replace(/\/+$/,``)||`/`,r=n===`/`?`/${e}`:`${n}/${e}`,c=Gt(de,se,t,r);if(o===`project`)s?s(c):(W({type:`make_dir`,path:c}),a(c)),at(!1),st(``),lt(null),i();else{W({type:`make_dir`,path:c}),st(``),at(!1),lt(null);let e=K,t=J;setTimeout(()=>{_t(e,t)},300)}},X=on(k),xt=on(J),Z=e=>{let t=e.replace(/\\/g,`/`).replace(/\/+$/,``);return/^[A-Za-z]:/.test(t)?t.toLowerCase():t},St=Z(k),Ct=!!k&&k!==`@root`&&St!==Z(e)&&!w.some(e=>Z(e)===St);return(0,zt.createPortal)((0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`status-cwd-backdrop ${u??``}`.trim(),onClick:i,onPointerDown:e=>e.stopPropagation(),onMouseDown:e=>e.stopPropagation()}),(0,Y.jsxs)(`div`,{className:`cwd-picker ${c??``}`.trim(),role:d,"aria-label":f,onPointerDown:e=>e.stopPropagation(),onMouseDown:e=>e.stopPropagation(),onWheel:e=>e.stopPropagation(),children:[_?(0,Y.jsxs)(`div`,{className:`cwd-mode-tabs`,children:[(0,Y.jsxs)(`button`,{type:`button`,className:`cwd-mode-tab ${T===`local`?`active`:``}`,onClick:()=>D(`local`),children:[`💻 `,g(`workspaceModeLocal`)]}),(0,Y.jsxs)(`button`,{type:`button`,className:`cwd-mode-tab ${T===`remote`?`active`:``}`,onClick:()=>D(`remote`),children:[`🌐 `,g(`workspaceModeRemote`)]}),(0,Y.jsx)(`button`,{type:`button`,className:`cwd-close`,title:g(`close`),"aria-label":g(`close`),onClick:i,children:(0,Y.jsx)(_e,{})})]}):(0,Y.jsxs)(`div`,{className:`cwd-mode-tabs cwd-mode-tabs-single`,children:[(0,Y.jsxs)(`div`,{className:`cwd-mode-tab active`,style:{cursor:`default`},children:[`💻 `,g(`workspaceModeLocal`)]}),(0,Y.jsx)(`button`,{type:`button`,className:`cwd-close`,title:g(`close`),"aria-label":g(`close`),onClick:i,children:(0,Y.jsx)(_e,{})})]}),T===`local`&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`cwd-picker-head`,children:(0,Y.jsxs)(`span`,{className:`cwd-picker-title`,title:k===`@root`?g(`computer`):k,children:[k===`@root`?(0,Y.jsx)(ge,{}):(0,Y.jsx)(M,{}),(0,Y.jsx)(`span`,{children:k===`@root`?g(`computer`):k})]})}),(0,Y.jsxs)(`div`,{className:`cwd-toolbar`,role:`toolbar`,"aria-label":g(`projectPickerTitle`),children:[(0,Y.jsx)($,{className:`cwd-jump ${k===`@root`?`active`:``}`,tip:g(`computer`),onClick:()=>ft(`@root`),children:(0,Y.jsx)(ge,{})}),v!==``&&(0,Y.jsx)($,{className:`cwd-jump ${Z(k)===Z(v)?`active`:``}`,tip:`${g(`homeDir`)} ${v}`,onClick:()=>ft(v),children:(0,Y.jsx)(L,{})}),y!==``&&(0,Y.jsx)($,{className:`cwd-jump ${Z(k)===Z(y)?`active`:``}`,tip:`${g(`desktopDir`)} ${y}`,onClick:()=>ft(y),children:(0,Y.jsx)(l,{})}),(0,Y.jsx)(`span`,{className:`cwd-toolbar-sep`,"aria-hidden":`true`}),(0,Y.jsx)($,{className:`cwd-jump tool-up`,tip:X?`${g(`cwdGoUp`)} · ${X}`:`${g(`cwdGoUp`)} · ${g(`directoryBrowser.alreadyAtTop`)}`,"aria-disabled":!X,onClick:()=>{X&&ft(X)},children:(0,Y.jsx)(te,{})}),(0,Y.jsx)($,{className:`cwd-jump tool-root`,tip:Ct?g(`addWorkspaceRootHint`):k===`@root`?`${g(`addWorkspaceRoot`)} · ${g(`directoryBrowser.thisPcNotDirectory`)}`:St===Z(e)?`${g(`addWorkspaceRoot`)} · ${g(`directoryBrowser.alreadyCurrentProject`)}`:`${g(`addWorkspaceRoot`)} · ${g(`directoryBrowser.alreadyWorkspaceRoot`)}`,"aria-disabled":!Ct,onClick:()=>{Ct&&W({type:`set_workspace_roots`,roots:[...w,k]})},children:(0,Y.jsx)(P,{})}),(0,Y.jsx)($,{className:`cwd-jump tool-new ${F?`active`:``}`,tip:k===`@root`?`${g(`cwdNewFolder`)} · ${g(`directoryBrowser.cannotCreateHere`)}`:g(F?`cwdCancel`:`cwdNewFolder`),"aria-disabled":k===`@root`,onClick:()=>{k!==`@root`&&(F?(I(!1),z(``),V(null)):(z(``),V(null),I(!0)))},children:(0,Y.jsx)(C,{})}),(0,Y.jsx)(`span`,{className:`cwd-toolbar-spacer`}),(0,Y.jsx)($,{className:`cwd-jump primary tool-pick`,tip:k===`@root`?`${g(`cwdPickCurrent`)} · ${g(`directoryBrowser.thisPcCannotBeWorkspace`)}`:`${g(`cwdPickCurrent`)} · ${k}`,"aria-disabled":k===`@root`,onClick:()=>dt(k),children:(0,Y.jsx)(R,{})})]}),(0,Y.jsxs)(`div`,{className:`cwd-picker-row`,children:[(0,Y.jsx)(`input`,{ref:ie,className:`status-cwd-input cwd-picker-input`,value:j,placeholder:g(`enterPath`),spellCheck:!1,onChange:e=>{N(e.target.value),re(-1)},onKeyDown:mt}),j.trim()!==``&&j!==k&&(0,Y.jsx)($,{className:`cwd-jump tool-enter`,tip:`${g(`cwdEnter`)} · ${j.trim()}`,onClick:()=>{A(j.trim()),re(-1)},children:(0,Y.jsx)(be,{})})]}),(0,Y.jsxs)(`div`,{className:`cwd-list`,children:[X&&(0,Y.jsx)(`div`,{className:`cwd-item`,children:(0,Y.jsxs)(`button`,{type:`button`,className:`cwd-enter`,title:`${g(`cwdGoUp`)} · ${X}`,onClick:()=>ft(X),children:[(0,Y.jsx)(M,{}),(0,Y.jsx)(`span`,{className:`cwd-name`,children:`..`})]})},`..`),ut.length===0&&!X&&(0,Y.jsx)(`div`,{className:`cwd-empty`,children:g(`cwdEmpty`)}),ut.map(e=>(0,Y.jsxs)(`div`,{className:`cwd-item`,children:[(0,Y.jsxs)(`button`,{type:`button`,className:`cwd-enter`,title:`${g(`cwdEnter`)} ${e.path}`,onClick:()=>{A(e.path),N(e.path),re(-1)},children:[(0,Y.jsx)(M,{}),(0,Y.jsx)(`span`,{className:`cwd-name`,children:e.name})]}),(0,Y.jsx)($,{className:`cwd-jump tool-choose`,tip:`${g(`cwdChoose`)} · ${e.path}`,onClick:()=>dt(e.path),children:(0,Y.jsx)(R,{})})]},e.path))]}),F&&(0,Y.jsxs)(`div`,{className:`cwd-picker-foot`,children:[(0,Y.jsxs)(`div`,{className:`cwd-newrow`,children:[(0,Y.jsx)(`input`,{ref:ae,value:ee,autoFocus:!0,spellCheck:!1,placeholder:g(`cwdNewName`),onChange:e=>{z(e.target.value),B&&V(null)},onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing?(e.preventDefault(),pt()):e.key===`Escape`&&(e.stopPropagation(),I(!1),z(``),V(null))}}),(0,Y.jsx)($,{className:`cwd-jump primary`,tip:g(`cwdCreate`),onClick:pt,children:(0,Y.jsx)(R,{})}),(0,Y.jsx)($,{className:`cwd-jump`,tip:g(`cwdCancel`),onClick:()=>{I(!1),z(``),V(null)},children:(0,Y.jsx)(_e,{})})]}),B&&(0,Y.jsx)(`div`,{className:`project-picker-error`,style:{color:`var(--red)`,fontSize:`11px`,marginTop:`4px`},children:B})]})]}),T===`remote`&&(0,Y.jsx)(`div`,{className:`cwd-ssh-container`,children:K?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`cwd-ssh-probe-box`,children:[(0,Y.jsxs)(`div`,{className:`cwd-ssh-probe-header`,children:[(0,Y.jsxs)(`span`,{children:[`🌐 `,de,`@`,se,` (`,q?.os,` `,q?.arch,`)`]}),(0,Y.jsx)(`button`,{type:`button`,className:`cwd-ssh-profile-del`,onClick:()=>{Ue(null),We(null),Ke(null)},children:g(`sshDisconnect`)})]}),(0,Y.jsxs)(`div`,{style:{display:`flex`,gap:`6px`,flexWrap:`wrap`,fontSize:`10px`},children:[(0,Y.jsxs)(`span`,{className:`cwd-ssh-tool-badge ${Ge?.git.installed?`ok`:`missing`}`,children:[`Git: `,Ge?.git.installed?`✓`:`✗`]}),(0,Y.jsxs)(`span`,{className:`cwd-ssh-tool-badge ${Ge?.node.installed?`ok`:`missing`}`,children:[`Node: `,Ge?.node.installed?`✓`:`✗`]}),(0,Y.jsxs)(`span`,{className:`cwd-ssh-tool-badge ${Ge?.bash.installed?`ok`:`missing`}`,children:[`Bash: `,Ge?.bash.installed?`✓`:`✗`]})]}),qe.length>0&&(0,Y.jsxs)(`div`,{className:`cwd-ssh-install-box`,children:[(0,Y.jsxs)(`div`,{children:[`⚠️ `,g(`directoryBrowser.remoteToolsMissing`)]}),(0,Y.jsxs)(`div`,{style:{display:`flex`,gap:`6px`,marginTop:`2px`},children:[(0,Y.jsx)(`button`,{type:`button`,className:`cwd-choose-btn primary`,disabled:Ye,onClick:()=>void vt(qe[0]),children:Ye?g(`sshInstalling`):`⚡ ${g(`sshInstallTool`)} ${qe[0]}`}),(0,Y.jsx)(`button`,{type:`button`,className:`cwd-choose-btn`,onClick:()=>Je([]),children:g(`sshSkipAndBrowse`)})]})]})]}),(0,Y.jsx)(`div`,{className:`cwd-picker-head`,children:(0,Y.jsxs)(`span`,{className:`cwd-picker-title`,title:J,children:[(0,Y.jsx)(ye,{}),(0,Y.jsx)(`span`,{children:J})]})}),(0,Y.jsxs)(`div`,{className:`cwd-toolbar`,role:`toolbar`,"aria-label":g(`workspaceModeRemote`),children:[(0,Y.jsx)($,{className:`cwd-jump tool-up`,tip:J===`/`?`${g(`cwdGoUp`)} · ${g(`directoryBrowser.alreadyAtTop`)}`:`${g(`cwdGoUp`)} · ${on(J)||`/`}`,"aria-disabled":J===`/`||nt,onClick:()=>{if(nt)return;let e=on(J);e&&K&&_t(K,e)},children:(0,Y.jsx)(te,{})}),(0,Y.jsx)($,{className:`cwd-jump tool-new ${it?`active`:``}`,tip:g(it?`cwdCancel`:`cwdNewFolder`),onClick:()=>at(e=>!e),children:(0,Y.jsx)(C,{})}),(0,Y.jsx)(`span`,{className:`cwd-toolbar-spacer`})]}),(0,Y.jsxs)(`div`,{className:`cwd-picker-row`,children:[(0,Y.jsx)(`input`,{className:`status-cwd-input cwd-picker-input`,value:Qe,placeholder:g(`enterPath`),spellCheck:!1,onChange:e=>$e(e.target.value),onKeyDown:e=>{e.key===`Enter`&&K&&_t(K,Qe)}}),Qe.trim()&&Qe.trim()!==J&&K&&(0,Y.jsx)($,{className:`cwd-jump tool-enter`,tip:`${g(`cwdEnter`)} · ${Qe.trim()}`,onClick:()=>void _t(K,Qe),children:(0,Y.jsx)(be,{})}),(0,Y.jsx)($,{className:`cwd-jump primary tool-pick`,tip:`${g(`sshOpenRemoteWorkspace`)} · ${Qe.trim()||J}`,onClick:()=>yt(Qe.trim()||J),children:(0,Y.jsx)(R,{})})]}),(0,Y.jsxs)(`div`,{className:`cwd-list`,children:[!nt&&xt&&(0,Y.jsx)(`div`,{className:`cwd-item`,children:(0,Y.jsxs)(`button`,{type:`button`,className:`cwd-enter`,title:`${g(`cwdGoUp`)} · ${xt}`,onClick:()=>{K&&_t(K,xt)},children:[(0,Y.jsx)(M,{}),(0,Y.jsx)(`span`,{className:`cwd-name`,children:`..`})]})},`..`),nt?(0,Y.jsx)(`div`,{className:`cwd-empty`,children:g(`directoryBrowser.loadingRemoteDir`)}):et.length===0?(0,Y.jsx)(`div`,{className:`cwd-empty`,children:g(`cwdEmpty`)}):et.map(e=>(0,Y.jsxs)(`div`,{className:`cwd-item`,children:[(0,Y.jsxs)(`button`,{type:`button`,className:`cwd-enter`,title:`${e.type===`dir`?g(`cwdEnter`):``} ${e.path}`,onClick:()=>{e.type===`dir`&&K&&_t(K,e.path)},children:[e.type===`dir`?(0,Y.jsx)(M,{}):(0,Y.jsx)(`span`,{children:`📄`}),(0,Y.jsx)(`span`,{className:`cwd-name`,children:e.name})]}),e.type===`dir`&&(0,Y.jsx)($,{className:`cwd-jump tool-choose`,tip:`${g(`cwdChoose`)} · ${e.path}`,onClick:()=>yt(e.path),children:(0,Y.jsx)(R,{})})]},e.path))]}),K&&it&&(0,Y.jsxs)(`div`,{className:`cwd-picker-foot`,children:[(0,Y.jsxs)(`div`,{className:`cwd-newrow`,children:[(0,Y.jsx)(`input`,{value:ot,autoFocus:!0,spellCheck:!1,placeholder:g(`cwdNewName`),onChange:e=>{st(e.target.value),ct&<(null)},onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing?(e.preventDefault(),bt()):e.key===`Escape`&&(e.stopPropagation(),at(!1),st(``),lt(null))}}),(0,Y.jsx)($,{className:`cwd-jump primary`,tip:g(`cwdCreate`),onClick:bt,children:(0,Y.jsx)(R,{})}),(0,Y.jsx)($,{className:`cwd-jump`,tip:g(`cwdCancel`),onClick:()=>{at(!1),st(``),lt(null)},children:(0,Y.jsx)(_e,{})})]}),ct&&(0,Y.jsx)(`div`,{className:`project-picker-error`,style:{color:`var(--red)`,fontSize:`11px`,marginTop:`4px`},children:ct})]})]}):(0,Y.jsxs)(`div`,{className:`cwd-ssh-form`,children:[oe.length>0&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`cwd-ssh-profiles-title`,children:[`📋 `,g(`sshSavedProfiles`)]}),oe.map(e=>(0,Y.jsxs)(`div`,{className:`cwd-ssh-profile-card`,onClick:()=>{ce(e.host),ue(String(e.port)),fe(e.username),me(e.authType),e.privateKeyPath&&Se(e.privateKeyPath),ht({host:e.host,port:e.port,username:e.username,profileName:e.name,auth:e.authType===`password`?{type:`password`,password:``}:e.authType===`key`?{type:`key`,privateKeyPath:e.privateKeyPath}:{type:`agent`}})},children:[(0,Y.jsxs)(`div`,{className:`cwd-ssh-profile-meta`,children:[(0,Y.jsxs)(`span`,{className:`cwd-ssh-profile-name`,children:[(0,Y.jsx)(O,{style:{marginRight:`4px`}}),e.name]}),(0,Y.jsxs)(`span`,{className:`cwd-ssh-profile-addr`,children:[e.username,`@`,e.host,`:`,e.port]})]}),(0,Y.jsx)(`button`,{type:`button`,className:`cwd-ssh-profile-del`,title:g(`delete`),onClick:t=>{t.stopPropagation(),confirm(g(`sshDeleteProfileConfirm`))&&($t(e.name),H(t=>t.filter(t=>t.name!==e.name)))},children:(0,Y.jsx)(n,{})})]},e.name))]}),(0,Y.jsxs)(`div`,{className:`cwd-ssh-row`,style:{marginTop:`4px`},children:[(0,Y.jsxs)(`label`,{children:[g(`sshHost`),`:`]}),(0,Y.jsx)(`input`,{className:`cwd-ssh-input`,value:se,placeholder:`192.168.1.100`,onChange:e=>ce(e.target.value)}),(0,Y.jsxs)(`label`,{style:{width:`32px`,textAlign:`right`},children:[g(`sshPort`),`:`]}),(0,Y.jsx)(`input`,{className:`cwd-ssh-input`,style:{width:`45px`,flex:`none`},value:le,onChange:e=>ue(e.target.value)})]}),(0,Y.jsxs)(`div`,{className:`cwd-ssh-row`,children:[(0,Y.jsxs)(`label`,{children:[g(`sshUser`),`:`]}),(0,Y.jsx)(`input`,{className:`cwd-ssh-input`,value:de,placeholder:`root / ubuntu`,onChange:e=>fe(e.target.value)})]}),(0,Y.jsxs)(`div`,{className:`cwd-ssh-row`,children:[(0,Y.jsxs)(`label`,{children:[g(`sshAuthType`),`:`]}),(0,Y.jsxs)(`select`,{className:`cwd-ssh-select`,value:pe,onChange:e=>me(e.target.value),children:[(0,Y.jsx)(`option`,{value:`password`,children:g(`sshPassword`)}),(0,Y.jsx)(`option`,{value:`key`,children:g(`sshKeyPath`)}),(0,Y.jsx)(`option`,{value:`agent`,children:g(`sshAgent`)})]})]}),pe===`password`&&(0,Y.jsxs)(`div`,{className:`cwd-ssh-row`,children:[(0,Y.jsxs)(`label`,{children:[g(`sshPassword`),`:`]}),(0,Y.jsx)(`input`,{type:`password`,className:`cwd-ssh-input`,value:he,placeholder:`••••••••`,onChange:e=>ve(e.target.value)})]}),pe===`key`&&(0,Y.jsx)(Y.Fragment,{children:Ce.length>0?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`cwd-ssh-row`,children:[(0,Y.jsxs)(`label`,{children:[g(`sshKeyPath`),`:`]}),(0,Y.jsxs)(`select`,{className:`cwd-ssh-select`,value:Te||xe&&!Ce.includes(xe)?`__custom__`:xe,onChange:e=>{let t=e.target.value;t===`__custom__`?Ee(!0):(Ee(!1),Se(t))},children:[Ce.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e)),(0,Y.jsx)(`option`,{value:`__custom__`,children:g(`sshKeyCustom`)})]})]}),(Te||xe&&!Ce.includes(xe))&&(0,Y.jsxs)(`div`,{className:`cwd-ssh-row`,children:[(0,Y.jsx)(`label`,{}),(0,Y.jsx)(`input`,{className:`cwd-ssh-input`,value:xe,placeholder:`~/.ssh/id_ed25519`,onChange:e=>Se(e.target.value)})]})]}):(0,Y.jsxs)(`div`,{className:`cwd-ssh-row`,children:[(0,Y.jsxs)(`label`,{children:[g(`sshKeyPath`),`:`]}),(0,Y.jsx)(`input`,{className:`cwd-ssh-input`,value:xe,placeholder:`~/.ssh/id_ed25519`,onChange:e=>Se(e.target.value)})]})}),(0,Y.jsx)(`div`,{className:`cwd-ssh-row`,style:{fontSize:`11px`,color:`var(--text-dim)`},children:(0,Y.jsxs)(`label`,{style:{width:`auto`},children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:De,onChange:e=>Oe(e.target.checked),style:{marginRight:`4px`}}),g(`sshSaveProfile`)]})}),De&&(0,Y.jsxs)(`div`,{className:`cwd-ssh-row`,children:[(0,Y.jsxs)(`label`,{children:[g(`sshProfileName`),`:`]}),(0,Y.jsx)(`input`,{className:`cwd-ssh-input`,value:ke,placeholder:`my-server`,onChange:e=>Ae(e.target.value)})]}),G&&(0,Y.jsxs)(`div`,{style:{border:`1px solid #d97706`,borderRadius:`8px`,padding:`8px`,marginTop:`6px`},children:[(0,Y.jsx)(`div`,{style:{fontSize:`12px`,fontWeight:600,marginBottom:`4px`},children:G.status===`changed`?g(`directoryBrowser.hostKeyChanged`):g(`directoryBrowser.newHostKey`)}),(0,Y.jsxs)(`div`,{style:{fontSize:`11px`,wordBreak:`break-all`,marginBottom:`4px`},children:[G.host,`:`,G.port,` `,G.algorithm,` `,G.fingerprint]}),(0,Y.jsx)(`div`,{style:{fontSize:`11px`,color:`var(--text-dim)`,marginBottom:`6px`},children:g(`directoryBrowser.fingerprintHint`)}),(0,Y.jsxs)(`label`,{style:{fontSize:`11px`,display:`flex`,gap:`6px`,marginBottom:`6px`},children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:Ie,onChange:e=>ze(e.target.checked)}),(0,Y.jsx)(`span`,{children:g(`directoryBrowser.fingerprintVerified`)})]}),(0,Y.jsxs)(`div`,{style:{display:`flex`,gap:`8px`},children:[(0,Y.jsx)(`button`,{type:`button`,className:`cwd-choose-btn primary`,disabled:!Ie||Be,onClick:async()=>{Ve(!0);let e=await en({host:G.host,port:G.port,fingerprint:G.fingerprint,replace:G.status===`changed`},g);if(Ve(!1),!e.ok){Fe(e.error||g(`directoryBrowser.trustFailed`));return}He(null),ht()},children:g(`directoryBrowser.trustAndRetry`)}),(0,Y.jsx)(`button`,{type:`button`,className:`cwd-choose-btn`,onClick:()=>{He(null),ze(!1)},children:g(`cancel`)})]})]}),Pe&&(0,Y.jsxs)(`div`,{style:{color:`var(--red)`,fontSize:`11px`,padding:`2px 0`},children:[`⚠️ `,Pe]}),(0,Y.jsx)(`button`,{type:`button`,className:`cwd-choose-btn primary`,style:{marginTop:`4px`},disabled:Me,onClick:()=>void ht(),children:g(Me?`sshConnecting`:`sshConnectAndProbe`)})]})})]})]}),h??document.body)}function un({open:e,currentCwd:t,pathCompletions:n,workspaceRoots:r,onClose:i,onSelectDirectory:a,onCreateProject:o,mode:s=`project`,localOnly:c,initialTab:l,portalContainer:u}){let d=U();return e?(0,Y.jsx)(ln,{portalContainer:u,localOnly:c,initialTab:l,currentCwd:t,pathCompletions:n,workspaceRoots:r,onClose:i,onSelectDirectory:e=>{a(e),i()},onCreateProject:o,mode:s,className:`project-picker`,backdropClassName:`project-picker-backdrop`,role:`dialog`,ariaLabel:d(`projectPickerTitle`)}):null}function dn({cwd:e,onSelectCwd:t,onOpenProjectPicker:n,projects:r=[],workspaceRoots:i,pathCompletions:a,mode:s=`project`,baseCwd:c,onCreateProject:l,className:u=``,placeholder:d,inputId:f,disabled:p=!1,commitOnBlur:m=!1,localOnly:h=!1,onPickerOpenChange:g}){let _=Le(`pathCompletions`),v=Le(`workspaceRoots`),y=a&&a.length>0?a:_??[],b=i&&i.length>0?i:v??[],[x,S]=(0,Q.useState)(!1),[w,T]=(0,Q.useState)(e);(0,Q.useEffect)(()=>T(e),[e]);let[E,D]=(0,Q.useState)(!1),O=(0,Q.useRef)(null),k=U();(0,Q.useEffect)(()=>{let e=e=>{O.current&&!O.current.contains(e.target)&&S(!1)};if(x)return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[x]);let A=[{label:k(`universalPathDirRoot`),value:`.`},{label:k(`universalPathDirWeb`),value:`web`},{label:k(`universalPathDirServer`),value:`server`},{label:k(`universalPathDirTests`),value:`tests`},{label:k(`universalPathDirSrc`),value:`src`},{label:k(`universalPathDirDocs`),value:`docs`}],j=()=>{D(!1),g?.(!1)},N=()=>{p||(n?n():(S(!1),D(!0),g?.(!0)))},P=e&&e!==`.`?e:c||e||`.`;return(0,Y.jsxs)(`div`,{className:`universal-path-picker-root ${u}`,ref:O,children:[(0,Y.jsxs)(`div`,{className:`universal-path-input-group`,children:[(0,Y.jsx)(M,{className:`universal-path-icon`}),(0,Y.jsx)(`input`,{type:`text`,className:`universal-path-input`,value:m?w:e,id:f,disabled:p,onChange:e=>m?T(e.target.value):t(e.target.value),onBlur:()=>{m&&w!==e&&t(w)},onKeyDown:n=>{m&&n.key===`Enter`&&(n.preventDefault(),w!==e&&t(w))},placeholder:d??k(`universalPathPlaceholder`),title:k(`universalPathCwdTitle`,{cwd:e||`.`})}),(0,Y.jsx)(`button`,{type:`button`,className:`universal-path-dropdown-toggle`,disabled:p,onClick:()=>S(!x),title:k(`universalPathDropdownTip`),children:(0,Y.jsx)(o,{})})]}),(0,Y.jsx)($,{className:`universal-path-browse-btn`,tip:k(`projectPickerTitle`),disabled:p,onClick:N,children:(0,Y.jsx)(C,{})}),x&&(0,Y.jsxs)(`div`,{className:`universal-path-menu`,onPointerDown:e=>e.stopPropagation(),onMouseDown:e=>e.stopPropagation(),onWheel:e=>e.stopPropagation(),children:[b.length>0&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`universal-path-menu-header`,children:`工作区根目录`}),b.map(e=>(0,Y.jsx)(`button`,{type:`button`,className:`universal-path-menu-item`,onClick:()=>{t(e),S(!1)},children:(0,Y.jsx)(`span`,{className:`path-label`,children:e})},e))]}),(0,Y.jsx)(`div`,{className:`universal-path-menu-header`,children:`推荐子目录`}),A.map(e=>(0,Y.jsx)(`button`,{type:`button`,className:`universal-path-menu-item`,onClick:()=>{t(e.value),S(!1)},children:(0,Y.jsx)(`span`,{className:`path-label`,children:e.label})},e.value)),r.length>0&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`universal-path-menu-header`,children:[(0,Y.jsx)(oe,{}),` 最近项目`]}),r.slice(0,6).map(e=>{let n=e.path.split(/[/\\]/).filter(Boolean).pop()||e.path;return(0,Y.jsxs)(`button`,{type:`button`,className:`universal-path-menu-item`,onClick:()=>{t(e.path),S(!1)},title:e.path,children:[(0,Y.jsx)(`span`,{className:`path-title`,children:n}),(0,Y.jsx)(`span`,{className:`path-sub`,children:e.path})]},e.path)})]})]}),!n&&E&&(0,Y.jsx)(un,{portalContainer:O.current?.closest(`dialog`)??void 0,localOnly:h,open:!0,currentCwd:P,pathCompletions:y,workspaceRoots:b,onClose:j,onSelectDirectory:e=>{t(e),j()},onCreateProject:l?e=>{l(e),j()}:void 0,mode:s})]})}var fn=`pi-web-model-usage`;function pn(e){if(!e||typeof e!=`object`)return{};let t={};for(let[n,r]of Object.entries(e)){let e=typeof r==`number`?Math.floor(r):0;Number.isFinite(e)&&e>0&&(t[n]=e)}return t}function mn(e,t){return t?{...e,[t]:(e[t]??0)+1}:e}function hn(e,t){let n=t;return e.map((e,t)=>({m:e,i:t,count:n[e.id]??0})).sort((e,t)=>t.count-e.count||e.i-t.i).map(e=>e.m)}function gn(){try{let e=localStorage.getItem(fn);return e?pn(JSON.parse(e)):{}}catch{return{}}}function _n(e){try{localStorage.setItem(fn,JSON.stringify(e))}catch{}}function vn(e){let t=mn(gn(),e);return _n(t),t}function yn(e,t){return t?t===e.id||`${e.provider}/${e.id}`===t||t.includes(`/`)&&t.split(`/`)[1]===e.id:!1}function bn(e,t){return(e?t?.find(t=>t.id===e)?.name?.trim():``)||e}function xn(e,t){return W(t?{type:`clear_default_model`}:{type:`set_default_model`,modelId:e.id})}function Sn(e,t,n,r){let i=e?.trim();if(!i)return null;let a=i.indexOf(`/`),o=a>0?i.slice(0,a):``,s=a>0?i.slice(a+1):i,c=e=>e.includes(`/`)?e.slice(e.indexOf(`/`)+1):e,l=t.find(e=>e.id===i)??t.find(e=>`${e.provider}/${c(e.id)}`===i)??t.find(e=>e.provider===o&&c(e.id)===s)??null,u=l?.provider||o,d=u?r?.[u]:void 0;return{modelName:l?.name||s,modelId:l?c(l.id):s,provider:u,providerLabel:bn(u,n),keyName:d&&d.length>1?d.find(e=>e.active)?.name??null:null}}function Cn({models:e,modelsLoading:t=!1,providerKeys:n={},providers:r,defaultModel:i,currentModelId:a,active:o,onEnsureModels:s,loading:c=!1,onRefresh:l,onManageModels:u,onPickModel:f,onToggleDefault:p,isRowActive:h,extraTopRow:g,listRef:_,autoFocusSearch:v=!1,hideTitle:y=!1,bodyStyle:b,scrollStyle:x}){let S=U(),[C,w]=(0,Q.useState)(``),[T,E]=(0,Q.useState)(null),[D,O]=(0,Q.useState)({}),[k,A]=(0,Q.useState)(!1),j=(0,Q.useRef)(s);j.current=s;let M=(0,Q.useRef)(null),N=(0,Q.useCallback)(e=>{M.current=e,_&&(_.current=e)},[_]),P=(0,Q.useMemo)(()=>Sn(a,e,r,n),[a,e,r,n]),F=()=>{w(``),E(null),requestAnimationFrame(()=>{let e=M.current?.querySelector(`.dd-item.active`);e&&typeof e.scrollIntoView==`function`&&e.scrollIntoView({block:`nearest`})})};(0,Q.useEffect)(()=>{if(!o){w(``),E(null),A(!1);return}O(gn()),j.current()},[o]);let I=(0,Q.useMemo)(()=>e.filter(e=>e.enabled!==!1).length,[e]),L=e.some(e=>e.enabled===!1),R=(0,Q.useMemo)(()=>!L||k?e:e.filter(e=>e.enabled!==!1||yn(e,a)),[e,L,k,a]),ee=(0,Q.useMemo)(()=>{let e=C.trim().toLowerCase(),t=R;return T&&(t=t.filter(e=>e.provider===T.provider)),hn(e?t.filter(t=>t.name.toLowerCase().includes(e)||t.id.toLowerCase().includes(e)||t.provider.toLowerCase().includes(e)):t,D)},[R,C,T,D]),z=(0,Q.useMemo)(()=>{let e=new Map;for(let t of R)e.set(t.provider,(e.get(t.provider)??0)+1);let t=[];for(let[r,i]of[...e.entries()].sort((e,t)=>e[0].localeCompare(t[0]))){let e=n[r];if(e&&e.length>1)for(let n of e)t.push({provider:r,count:i,keyName:n.name});else t.push({provider:r,count:i,keyName:null})}return t},[R,n]),te=(0,Q.useMemo)(()=>{let e=[];for(let t of ee){let r=null,i=n[t.provider];if(i&&i.length>1&&(r=i.find(e=>e.active)??i[0],T?.provider===t.provider&&T.keyName)){let e=i.find(e=>e.name===T.keyName);e&&(r=e)}let o=h?h(t,r):yn(t,a)&&(!r||r.active);e.push({model:t,key:r,active:o})}return e},[ee,n,T,h,a]),B=i!==void 0;return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`dd-header dd-header-flex`,children:[!y&&(0,Y.jsx)(`span`,{className:`dd-header-title`,children:S(`availableModels`)}),(0,Y.jsxs)(`div`,{className:`dd-header-actions`,style:y?{marginLeft:`auto`}:void 0,children:[!!i&&(0,Y.jsxs)(`div`,{className:`dd-header-default`,title:S(`defaultModelLabel`,{model:i??``}),children:[(0,Y.jsx)(`span`,{className:`dd-header-default-star`,children:`★`}),(0,Y.jsx)(`span`,{className:`dd-header-default-name`,children:i.includes(`/`)?i.split(`/`).slice(1).join(`/`):i}),(0,Y.jsx)(`button`,{type:`button`,className:`dd-header-default-clear`,title:S(`clearDefaultModel`),onClick:e=>{e.stopPropagation(),W({type:`clear_default_model`})},children:`✕`})]}),L&&(0,Y.jsx)(`button`,{type:`button`,className:`dd-scope-toggle ${k?`active`:``}`,onClick:()=>A(e=>!e),title:k?S(`showEnabledModelsTitle`,{n:I}):S(`showAllModelsTitle`,{n:e.length}),children:k?S(`showEnabledModels`,{n:I}):S(`showAllModels`,{n:e.length})}),(0,Y.jsx)(`button`,{type:`button`,className:`dd-header-btn dd-refresh-btn`,onClick:l,title:S(`refreshModels`),"aria-label":S(`refreshModels`),children:(0,Y.jsx)(d,{className:c||t?`spin`:``})}),u&&(0,Y.jsx)(`button`,{type:`button`,className:`dd-header-btn dd-manage-btn`,onClick:u,title:S(`manageModels`),"aria-label":S(`manageModels`),children:(0,Y.jsx)(m,{})})]})]}),(0,Y.jsxs)(`div`,{className:`dd-search-row`,children:[(0,Y.jsx)(De,{}),(0,Y.jsx)(`input`,{className:`dd-search`,type:`text`,autoFocus:v,placeholder:S(`searchModels`),value:C,onChange:e=>w(e.target.value)})]}),P&&(0,Y.jsxs)(`button`,{type:`button`,className:`dd-current-row`,title:S(`currentModelHint`),onClick:F,children:[(0,Y.jsx)(`span`,{className:`dd-current-tag`,children:S(`currentModelLabel`)}),(0,Y.jsx)(`span`,{className:`dd-current-name`,children:P.modelName}),(0,Y.jsx)(`span`,{className:`dd-current-provider`,title:P.provider,children:P.providerLabel}),P.keyName&&(0,Y.jsx)(`span`,{className:`dd-current-key`,children:P.keyName})]}),(0,Y.jsxs)(`div`,{className:`dd-model-body`,style:b,children:[z.length>1&&(0,Y.jsxs)(`div`,{className:`dd-provider-col`,children:[(0,Y.jsx)(`div`,{className:`dd-provider-head`,children:S(`providers`)}),(0,Y.jsx)(`button`,{type:`button`,className:`dd-provider-item ${T===null?`active`:``}`,onClick:()=>E(null),children:(0,Y.jsx)(`span`,{children:S(`allProviders`)})}),z.map(e=>{let t=T?.provider===e.provider&&T?.keyName===e.keyName;return(0,Y.jsxs)(`button`,{type:`button`,className:`dd-provider-item ${t?`active`:``}`,onClick:()=>E(t?null:{provider:e.provider,keyName:e.keyName}),title:e.keyName?`${bn(e.provider,r)} (${e.provider}) · ${e.keyName}`:`${bn(e.provider,r)} (${e.provider}) · ${e.count}`,children:[(0,Y.jsxs)(`span`,{className:`dd-provider-txt`,children:[(0,Y.jsx)(`span`,{className:`dd-provider-name`,children:bn(e.provider,r)}),e.keyName&&(0,Y.jsx)(`span`,{className:`dd-provider-key`,children:e.keyName})]}),(0,Y.jsx)(`span`,{className:`dd-provider-count`,children:e.count})]},e.keyName?`${e.provider}::${e.keyName}`:e.provider)})]}),(0,Y.jsxs)(`div`,{className:`dd-model-scroll`,ref:N,style:x,children:[(c||t)&&(0,Y.jsx)(`div`,{className:`dd-loading`,children:S(`loading`)}),e.length===0&&!c&&!t&&(0,Y.jsx)(`div`,{className:`dd-loading`,children:S(`noModels`)}),g,ee.length===0&&R.length>0&&(0,Y.jsxs)(`div`,{className:`dd-loading`,children:[(0,Y.jsx)(`div`,{children:S(`noModelMatches`)}),L&&!k&&(0,Y.jsx)(`button`,{type:`button`,className:`dd-scope-switch-link`,onClick:()=>A(!0),children:S(`searchAllModelsHint`,{n:e.length})})]}),te.map(e=>{let t=e.model,n=i!==void 0&&i===t.id;return(0,Y.jsxs)(Ie,{active:e.active,onClick:()=>f(t,e.key),children:[(0,Y.jsxs)(`span`,{className:`dd-model-cell`,children:[(0,Y.jsxs)(`span`,{className:`dd-model-head`,children:[(0,Y.jsx)(`span`,{className:`dd-model-name`,children:t.name}),e.active&&(0,Y.jsx)(`span`,{className:`dd-model-current`,children:S(`currentModelBadge`)})]}),(0,Y.jsxs)(`span`,{className:`dd-model-meta`,children:[(0,Y.jsx)(`span`,{className:`dd-model-provider`,title:t.provider,children:bn(t.provider,r)}),(0,Y.jsx)(`span`,{className:`dd-model-id`,children:t.id.includes(`/`)?t.id.split(`/`).slice(1).join(`/`):t.id}),e.key&&(0,Y.jsxs)(`span`,{className:`dd-model-key ${e.key.active?`active`:``}`,children:[e.key.active?`●`:`○`,` `,e.key.name]}),(D[t.id]??0)>0&&(0,Y.jsx)(`span`,{className:`dd-model-usage`,children:S(`modelUsedCount`,{n:D[t.id]})}),(t.reasoning||t.vision||k&&t.enabled===!1)&&(0,Y.jsxs)(`span`,{className:`dd-model-badges`,children:[t.reasoning&&(0,Y.jsx)(`span`,{className:`dd-model-badge`,children:S(`reasoning`)}),t.vision&&(0,Y.jsx)(`span`,{className:`dd-model-badge`,children:S(`vision`)}),k&&t.enabled===!1&&(0,Y.jsx)(`span`,{className:`dd-model-badge out-of-scope`,children:S(`notInScopeBadge`)})]})]})]}),B&&(p?(0,Y.jsx)(`button`,{type:`button`,className:`dd-star-btn ${n?`active`:``}`,title:S(n?`cancelDefaultTooltip`:`setDefaultTooltip`),onClick:e=>{e.stopPropagation(),p(t,n)},children:n?`★`:`☆`}):(0,Y.jsx)(`span`,{className:`dd-star-btn ${n?`active`:``}`,children:n?`★`:`☆`}))]},e.key?`${t.id}::${e.key.name}`:t.id)})]})]})]})}function wn({title:e,entries:t,selected:n,onChange:r,disabled:i,pending:a}){let o=U(),s=(0,Q.useId)(),[c,l]=(0,Q.useState)(``),u=new Set(t.map(e=>e.id)),d=n.filter(e=>!u.has(e)),f=[...t,...d.map(e=>({id:e,name:e}))],p=c.trim().toLowerCase(),m=f.filter(e=>[e.name,e.id,e.description,e.path].some(e=>e?.toLowerCase().includes(p))),h=m.filter(e=>u.has(e.id)&&e.status!==`disabled`);return(0,Y.jsxs)(`fieldset`,{className:`dc-bot-catalog`,disabled:i,children:[(0,Y.jsxs)(`legend`,{children:[e,` `,(0,Y.jsxs)(`span`,{className:`dc-bot-count`,children:[n.length,` `,o(`localBotSelected`)]})]}),(0,Y.jsxs)(`div`,{className:`dc-bot-catalog-actions`,children:[(0,Y.jsx)(`input`,{type:`search`,"aria-label":`${o(`localBotSearch`)} ${e}`,placeholder:o(`localBotSearch`),value:c,onChange:e=>l(e.target.value)}),(0,Y.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:a||!h.length,onClick:()=>r([...new Set([...n,...h.map(e=>e.id)])]),children:o(p?`localBotSelectVisible`:`localBotSelectAll`)}),(0,Y.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:!n.length,onClick:()=>r([]),children:o(`localBotClear`)})]}),(0,Y.jsxs)(`div`,{className:`dc-bot-catalog-list`,children:[m.map((e,t)=>(0,Y.jsxs)(`label`,{className:`dc-bot-option${n.includes(e.id)?` is-selected`:``}`,htmlFor:`${s}-${t}`,children:[(0,Y.jsx)(`input`,{id:`${s}-${t}`,type:`checkbox`,checked:n.includes(e.id),disabled:e.status===`disabled`&&!n.includes(e.id),onChange:t=>r(t.target.checked?[...new Set([...n,e.id])]:n.filter(t=>t!==e.id))}),(0,Y.jsxs)(`span`,{children:[(0,Y.jsx)(`strong`,{children:e.name}),e.warning===`high_privilege`&&(0,Y.jsx)(`small`,{children:o(`localBotToolHighPrivilege`)}),e.warning===`unsupported_platform`&&(0,Y.jsx)(`small`,{children:o(`localBotToolUnsupportedPlatform`)}),!u.has(e.id)&&(0,Y.jsx)(`small`,{children:o(a?`localBotUnverified`:`localBotUnavailable`)}),e.description&&(0,Y.jsx)(`small`,{className:`dc-bot-option-description`,title:e.description,children:e.description}),e.status===`not_loaded`&&(0,Y.jsx)(`small`,{children:o(`localBotMcpNotLoaded`)}),e.status===`disabled`&&(0,Y.jsx)(`small`,{children:o(`localBotMcpDisabled`)}),e.source&&e.source!==`builtin`&&(0,Y.jsx)(`small`,{className:`dc-bot-option-source`,children:e.source}),e.path&&(0,Y.jsx)(`small`,{className:`dc-bot-option-path`,title:e.path,children:e.path})]})]},e.id)),!m.length&&(0,Y.jsx)(`p`,{children:o(a?`localBotOptionsLoading`:`localBotNoOptions`)})]})]})}var Tn=e=>e.id.startsWith(`${e.provider}/`)?e.id.slice(e.provider.length+1):e.id;function En(e){let[t,n]=(0,Q.useState)(null),[r,i]=(0,Q.useState)(!1),[a,o]=(0,Q.useState)(``),[s,c]=(0,Q.useState)(0);return(0,Q.useEffect)(()=>{if(!e)return;let t=new AbortController;return i(!0),o(``),Ne(`/api/device-center/local-bot-options`,{method:`GET`,credentials:`same-origin`,signal:t.signal}).then(async e=>{let t=await e.json();if(!e.ok)throw Error(t.error||String(e.status));return t}).then(e=>{t.signal.aborted||(n(e),i(!1))}).catch(e=>{t.signal.aborted||(o(e instanceof Error?e.message:String(e)),i(!1))}),()=>t.abort()},[e,s]),{options:t,loading:r,error:a,reload:(0,Q.useCallback)(()=>c(e=>e+1),[])}}var Dn=[`soul`,`context`,`tools`,`markers`,`skills`,`cwd`,`append`,`plugin_dev`,`execution`,`memory`],On=new Set([`soul`,`context`,`markers`,`append`,`plugin_dev`]),kn=[`soul`,`context`,`tools`,`skills`,`cwd`,`append`,`execution`,`memory`],An=[`tools`,`skills`,`cwd`,`memory`];function jn(e){return Array.isArray(e.promptSections)?e.promptSections:e.useGlobalPrompt===!1?[...An]:[...kn]}function Mn({value:e,onChange:t,options:n,optionsLoading:r,optionsError:i,onReloadOptions:a,busy:o=!1,baseCwd:s=``,variant:c=`dialog`,modelPortalTarget:l,modelOpen:u,onModelOpenChange:d,dialogChrome:f}){let p=U(),m=(0,Q.useId)(),[h,g]=(0,Q.useState)(`identity`),[_,v]=(0,Q.useState)(`tools`),[y,b]=(0,Q.useState)(!1),x=u??y,S=(0,Q.useCallback)(e=>{d?d(e):b(e)},[d]),C=(0,Q.useRef)(s||e.cwd);s&&(C.current=s);let[w,T]=(0,Q.useState)(null),[E,D]=(0,Q.useState)(!1),[O,k]=(0,Q.useState)(``),[A,j]=(0,Q.useState)(!1),M=jn(e);(0,Q.useEffect)(()=>{if(h!==`identity`)return;let t=new AbortController,n=setTimeout(()=>{D(!0),k(``),Me(`/api/device-center/local-bot-prompt-preview`,{body:{id:e.id,systemPrompt:e.systemPrompt,cwd:e.cwd,tools:e.tools,skills:e.skills,promptSections:e.promptSections,useGlobalPrompt:e.useGlobalPrompt},signal:t.signal}).then(e=>{t.signal.aborted||(T(e),D(!1))}).catch(e=>{t.signal.aborted||(k(e instanceof Error?e.message:String(e)),D(!1))})},220);return()=>{clearTimeout(n),t.abort()}},[h,e.id,e.systemPrompt,e.cwd,e.tools,e.skills,e.promptSections,e.useGlobalPrompt]);let N=(0,Q.useCallback)(n=>{let r=n.some(e=>On.has(e));t({...e,promptSections:n,useGlobalPrompt:r})},[t,e]);je(()=>S(!1),x);let P=n?.models.find(t=>t.provider===e.model?.provider&&Tn(t)===e.model?.modelId),F=c===`inline`,I=!F&&!!f,L=F?m:`bot`,R=F?`${m}-cwd`:`local-bot-cwd`,ee=F?5:3,z=[[`identity`,p(`localBotIdentity`),void 0],[`runtime`,p(`localBotRuntime`),void 0],[`permissions`,p(`localBotPermissions`),e.tools.length+e.skills.length+e.mcpServers.length]],te=(0,Y.jsx)(`div`,{className:I?`dc-bot-b-nav`:F?`bot-form-tabs`:`dc-bot-tabs`,role:`tablist`,"aria-label":p(`localBotTitle`),children:z.map(([e,t,n],r,i)=>(0,Y.jsxs)(`button`,{type:`button`,role:`tab`,id:`${L}-tab-${e}`,"aria-controls":`${L}-panel-${e}`,"aria-selected":h===e,tabIndex:h===e?0:-1,onClick:()=>g(e),onKeyDown:e=>{let t=r;if(e.key===`ArrowRight`||I&&e.key===`ArrowDown`)t=(r+1)%i.length;else if(e.key===`ArrowLeft`||I&&e.key===`ArrowUp`)t=(r+i.length-1)%i.length;else if(e.key===`Home`)t=0;else if(e.key===`End`)t=i.length-1;else return;e.preventDefault(),g(i[t][0]),document.getElementById(`${L}-tab-${i[t][0]}`)?.focus()},children:[(0,Y.jsx)(`span`,{children:t}),n!==void 0&&n>0&&(0,Y.jsx)(`span`,{style:{fontSize:`11px`,opacity:.65},children:n})]},e))}),B=z.find(([e])=>e===h)?.[1]??p(`localBotIdentity`),V=(0,Y.jsxs)(`div`,{className:F?`bot-form-body`:void 0,children:[(0,Y.jsx)(`div`,{role:`tabpanel`,id:`${L}-panel-identity`,"aria-labelledby":`${L}-tab-identity`,hidden:h!==`identity`,children:(0,Y.jsxs)(`div`,{className:F?`bot-form-stack`:`dc-bot-section`,style:F?void 0:{gap:`12px`},children:[(0,Y.jsxs)(`div`,{className:F?void 0:`dc-bot-row-2`,children:[(0,Y.jsxs)(`label`,{className:F?`bot-form-field`:`dc-field`,children:[(0,Y.jsx)(`span`,{children:p(`localBotName`)}),(0,Y.jsx)(`input`,{required:!0,disabled:o,value:e.name,onChange:n=>t({...e,name:n.target.value})})]}),(0,Y.jsxs)(`label`,{className:F?`bot-form-field`:`dc-field`,children:[(0,Y.jsx)(`span`,{children:p(`localBotDescription`)}),(0,Y.jsx)(`textarea`,{rows:F?2:1,disabled:o,value:e.description,onChange:n=>t({...e,description:n.target.value}),style:F?void 0:{minHeight:`36px`,resize:`none`}})]})]}),(0,Y.jsxs)(`label`,{className:F?`bot-form-field`:`dc-field`,children:[(0,Y.jsx)(`span`,{children:p(`localBotSystemPrompt`)}),(0,Y.jsx)(`textarea`,{rows:ee,className:F?`bot-form-prompt`:`dc-bot-prompt`,spellCheck:!1,disabled:o,value:e.systemPrompt,onChange:n=>t({...e,systemPrompt:n.target.value})})]}),(0,Y.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`6px`},children:[(0,Y.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,justifyContent:`space-between`,gap:`8px`,flexWrap:`wrap`},children:[(0,Y.jsx)(`span`,{style:{fontSize:`12px`,fontWeight:500,color:`var(--text-dim)`},children:p(`localBotPromptComposition`)}),(0,Y.jsxs)(`div`,{style:{display:`inline-flex`,gap:`4px`,flexWrap:`wrap`},children:[(0,Y.jsx)(`button`,{type:`button`,className:`dc-button`,style:{padding:`3px 8px`,fontSize:`11px`},disabled:o,onClick:()=>N([...Dn]),children:p(`localBotSelectAll`)}),(0,Y.jsx)(`button`,{type:`button`,className:`dc-button`,style:{padding:`3px 8px`,fontSize:`11px`},disabled:o,onClick:()=>N([]),children:p(`localBotPromptPureOnly`)}),(0,Y.jsx)(`button`,{type:`button`,className:`dc-button`,style:{padding:`3px 8px`,fontSize:`11px`},disabled:o,onClick:()=>N([...kn]),children:p(`localBotPromptResetDefault`)})]})]}),(0,Y.jsx)(`div`,{className:`dc-bot-chips`,children:Dn.map(e=>{let t=M.includes(e),n=w?.sections.find(t=>t.id===e),r=`promptTok_${e}`,i=`promptTok_${e}_desc`;return(0,Y.jsxs)(`label`,{className:`dc-bot-chip${t?` is-on`:``}`,title:p(i),children:[(0,Y.jsx)(`input`,{type:`checkbox`,disabled:o,checked:t,onChange:t=>{let n=t.target.checked?[...M,e]:M.filter(t=>t!==e);N(n)}}),(0,Y.jsx)(`span`,{children:p(r)}),n&&(0,Y.jsx)(`span`,{className:`tok dc-bot-chip-tok`,children:n.tokens})]},e)})})]}),(0,Y.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`6px`},children:[(0,Y.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,justifyContent:`space-between`,gap:`8px`},children:[(0,Y.jsxs)(`span`,{style:{fontSize:`12px`,fontWeight:500,color:`var(--text-dim)`},children:[p(`localBotPromptFullPreview`),w?` (≈${w.totalTokens} tokens)`:``]}),(0,Y.jsx)(`button`,{type:`button`,className:`dc-button`,style:{padding:`3px 8px`,fontSize:`11px`},disabled:!w?.full,onClick:()=>{w?.full&&navigator.clipboard?.writeText(w.full).then(()=>{j(!0),setTimeout(()=>j(!1),1500)})},children:p(A?`localBotPromptCopied`:`localBotPromptCopy`)})]}),O&&(0,Y.jsx)(`small`,{role:`alert`,style:{color:`var(--err-text, #e5534b)`},children:O}),(0,Y.jsx)(`textarea`,{readOnly:!0,rows:F?5:4,className:F?`bot-form-prompt`:`dc-bot-prompt`,spellCheck:!1,value:E&&!w?p(`localBotPromptPreviewLoading`):w?.full??``,style:{width:`100%`,minHeight:F?void 0:`88px`,opacity:E?.75:1,fontFamily:`var(--mono)`,fontSize:`11.5px`,lineHeight:1.5,padding:`8px 10px`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`7px`,color:`var(--text)`}})]})]})}),(0,Y.jsx)(`div`,{role:`tabpanel`,id:`${L}-panel-runtime`,"aria-labelledby":`${L}-tab-runtime`,hidden:h!==`runtime`,children:(0,Y.jsxs)(`div`,{className:F?`bot-form-stack`:`dc-bot-section`,children:[(0,Y.jsxs)(`div`,{className:F?`bot-form-field`:`dc-field`,children:[(0,Y.jsx)(`label`,{htmlFor:R,children:p(`localBotCwd`)}),(0,Y.jsx)(dn,{inputId:R,commitOnBlur:!0,cwd:e.cwd,baseCwd:C.current||e.cwd,projects:n?.projects.map(e=>({...e,lastUsed:0}))??[],disabled:o,onSelectCwd:n=>t({...e,cwd:It(n,C.current||e.cwd)})})]}),(0,Y.jsxs)(`div`,{className:F?`bot-form-field`:`dc-field`,children:[(0,Y.jsx)(`span`,{children:p(`localBotModel`)}),(0,Y.jsxs)(`div`,{className:`dc-actions`,children:[(0,Y.jsx)(`button`,{className:`dc-button`,type:`button`,disabled:o,"aria-haspopup":`dialog`,onClick:()=>S(!0),children:e.model?P?.name??`${e.model.provider}/${e.model.modelId}`:p(`localBotInheritModel`)}),e.model&&(0,Y.jsx)(`button`,{className:`dc-button`,type:`button`,disabled:o,onClick:()=>t({...e,model:void 0}),children:p(`localBotInheritModel`)})]}),e.model&&!P&&(0,Y.jsx)(`small`,{children:p(r?`localBotUnverified`:`localBotUnavailable`)})]})]})}),(0,Y.jsxs)(`div`,{role:`tabpanel`,id:`${L}-panel-permissions`,"aria-labelledby":`${L}-tab-permissions`,hidden:h!==`permissions`,children:[(0,Y.jsxs)(`div`,{className:`dc-bot-options-status`,"aria-live":`polite`,children:[r&&(0,Y.jsx)(`span`,{children:p(`localBotOptionsLoading`)}),i&&(0,Y.jsx)(`span`,{role:`alert`,children:i}),(0,Y.jsx)(`button`,{className:`dc-button`,type:`button`,disabled:r||o,onClick:a,children:p(i?`deviceHubRetry`:`localBotReload`)})]}),(0,Y.jsx)(`div`,{className:`dc-bot-catalog-tabs`,role:`tablist`,"aria-label":p(`localBotPermissions`),children:[[`tools`,p(`localBotTools`)],[`skills`,p(`localBotSkills`)],[`mcpServers`,p(`localBotMcpServers`)]].map(([t,n])=>(0,Y.jsxs)(`button`,{type:`button`,role:`tab`,id:`${m}-catalog-tab-${t}`,"aria-controls":`${m}-catalog-${t}`,"aria-selected":_===t,onClick:()=>v(t),children:[n,(0,Y.jsx)(`span`,{children:e[t].length})]},t))}),(0,Y.jsx)(`div`,{className:`dc-bot-permissions`,children:[[`tools`,p(`localBotTools`)],[`skills`,p(`localBotSkills`)],[`mcpServers`,p(`localBotMcpServers`)]].map(([a,s])=>(0,Y.jsx)(`div`,{role:`tabpanel`,id:`${m}-catalog-${a}`,"aria-labelledby":`${m}-catalog-tab-${a}`,hidden:_!==a,children:(0,Y.jsx)(wn,{title:s,entries:n?.[a]??[],selected:e[a],disabled:o,pending:r||!!i,onChange:n=>t({...e,[a]:n})})},a))})]})]});return(0,Y.jsxs)(Y.Fragment,{children:[I&&f?(0,Y.jsxs)(`div`,{className:`dc-bot-b-shell`,children:[(0,Y.jsxs)(`aside`,{className:`dc-bot-b-rail`,children:[f.railHeader,te,f.railFooter]}),(0,Y.jsxs)(`div`,{className:`dc-bot-b-main`,children:[(0,Y.jsxs)(`header`,{className:`dc-bot-b-head`,children:[(0,Y.jsx)(`strong`,{children:B}),f.closeButton]}),(0,Y.jsxs)(`div`,{className:`dc-bot-b-body`,children:[f.errorBanner,V]}),(0,Y.jsx)(`footer`,{className:`dc-actions dc-bot-b-foot`,children:f.footer})]})]}):(0,Y.jsxs)(`div`,{className:`bot-form${F?` is-inline`:``}`,children:[te,V]}),x&&(0,zt.createPortal)((0,Y.jsx)(`div`,{className:`modal-backdrop dc-bot-model-backdrop`,onClick:e=>{e.target===e.currentTarget&&S(!1)},children:(0,Y.jsxs)(`div`,{className:`dc-bot-model-modal dd-menu-model`,role:`dialog`,"aria-modal":`true`,"aria-label":p(`localBotModel`),children:[(0,Y.jsxs)(`div`,{className:`dg-heading`,children:[(0,Y.jsx)(`h3`,{children:p(`localBotModel`)}),(0,Y.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>S(!1),children:p(`localBotCancel`)})]}),(0,Y.jsx)(Cn,{models:n?.models??[],modelsLoading:r,defaultModel:n?.defaultModel,currentModelId:e.model?`${e.model.provider}/${e.model.modelId}`:null,active:!0,onEnsureModels:()=>{},onRefresh:a,onPickModel:n=>{t({...e,model:{provider:n.provider,modelId:Tn(n)}}),S(!1)},isRowActive:t=>t.provider===e.model?.provider&&Tn(t)===e.model.modelId,extraTopRow:(0,Y.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>{t({...e,model:void 0}),S(!1)},children:p(`localBotInheritModel`)}),autoFocusSearch:!0,hideTitle:!0,bodyStyle:{flex:1,minHeight:0},scrollStyle:{overflowY:`auto`,minHeight:0}}),i&&(0,Y.jsx)(`p`,{role:`alert`,children:i})]})}),l??document.body)]})}var Nn=(e=``)=>({name:``,description:``,systemPrompt:``,useGlobalPrompt:!0,cwd:e,tools:[],skills:[],mcpServers:[],enabled:!0});async function Pn(e,t,n){let r=await fetch(u(H(`/api/device-center/${e}`)),{method:n?`POST`:`GET`,credentials:`same-origin`,signal:t,...n?{headers:{"Content-Type":`application/json`},body:JSON.stringify(n)}:{}}),i=await r.json();if(!r.ok)throw Error(i.error||String(r.status));return i}function Fn({createOnly:e=!1,initialCwd:t,editBot:n,onCreated:r,onFinished:i,onCancel:a}){let o=U(),[s,c]=(0,Q.useState)([]),[l,u]=(0,Q.useState)(null),[d,f]=(0,Q.useState)(()=>n?structuredClone(n):e?Nn(t??``):null),p=()=>{f(null),a?.()},[m,h]=(0,Q.useState)(!1),[g,_]=(0,Q.useState)(``),[v,y]=(0,Q.useState)(``),[b,x]=(0,Q.useState)(null),[S,C]=(0,Q.useState)(``),[w,T]=(0,Q.useState)(!1),[E,D]=(0,Q.useState)(0),[O,k]=(0,Q.useState)(!1),[A,j]=(0,Q.useState)(!1),M=(0,Q.useRef)(null),N=(0,Q.useRef)(null),P=e,F=(0,Q.useRef)(``),I=(0,Q.useRef)(null),L=d!==null,R=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{if(R.current=!1,!L)return;let e=I.current,t=document.activeElement,n=document.body.style.overflow;return document.body.style.overflow=`hidden`,e?.showModal?.(),()=>{e?.close?.(),document.body.style.overflow=n,t?.focus()}},[L]),(0,Q.useEffect)(()=>{if(P)return;let e=new AbortController;return Pn(`local-bots`,e.signal).then(t=>{if(!e.signal.aborted){if(!Array.isArray(t.bots))throw Error(`Invalid Bot list`);c(t.bots)}}).catch(t=>{e.signal.aborted||_(String(t))}),()=>e.abort()},[P]),(0,Q.useEffect)(()=>()=>N.current?.abort(),[]);let ee=async e=>{j(!0),_(``);try{let t=await Ft(e);y(o(`agentBotsImportReceipt`,{name:t.name,imported:t.imported,skipped:t.skipped})),D(e=>e+1),Pn(`local-bots`,new AbortController().signal).then(e=>{Array.isArray(e.bots)&&c(e.bots)}).catch(()=>{})}catch(e){_(e instanceof Error?e.message:o(`localBotImportFailed`))}finally{j(!1)}},z=d?.cwd;(0,Q.useEffect)(()=>{if(z===void 0)return;let e=new AbortController;return T(!0),C(``),x(null),Pn(z?`local-bot-options?cwd=${encodeURIComponent(z)}`:`local-bot-options`,e.signal).then(t=>{if(e.signal.aborted)return;if(![t.models,t.tools,t.skills,t.mcpServers,t.projects].every(Array.isArray)||!t.defaultCwd||!t.cwd)throw Error(o(`localBotOptionsInvalid`));F.current=t.defaultCwd,x(t);let n=!R.current;R.current=!0,f(e=>e&&{...e,...e.cwd?{}:{cwd:t.cwd},...n&&!e.id?{tools:[...t.defaultTools??[]]}:{}})}).catch(t=>{e.signal.aborted||C(String(t))}).finally(()=>{e.signal.aborted||T(!1)}),()=>e.abort()},[z,E]);async function te(e=!1){if(!d||m)return;let t=new AbortController;N.current=t,h(!0),_(``),y(``);try{let n=await Pn(e?`local-bots/${encodeURIComponent(d.id)}/delete`:`local-bots`,t.signal,e?{revision:d.revision}:d);if(t.signal.aborted)return;c(t=>e?t.filter(e=>e.id!==d.id):[...t.filter(e=>e.id!==n.bot.id),n.bot]),f(null),k(!1),y(n.synced===!1?o(`localBotSyncFailed`):o(`localBotSaved`)),e||r?.(n.bot,n.synced!==!1),i?.(),window.dispatchEvent(new CustomEvent(`pi-web-ui:device-bots-changed`))}catch(e){t.signal.aborted||_(e instanceof Error?e.message:String(e))}finally{t.signal.aborted||h(!1)}}async function B(e){if(!l){u(e),_(``);try{_t(e)}catch(e){_(e instanceof Error?e.message:String(e))}finally{u(null)}}}return(0,Y.jsxs)(`section`,{className:`dc-card dc-bots${P?` is-solo`:``}`,"aria-label":o(`localBotTitle`),children:[(0,Y.jsxs)(`div`,{className:`dg-heading`,children:[(0,Y.jsx)(`h2`,{children:o(`localBotTitle`)}),(0,Y.jsxs)(`div`,{className:`dc-bots-actions`,children:[(0,Y.jsx)(`button`,{className:`dc-button`,type:`button`,disabled:m,onClick:()=>{f(Nn()),_(``),k(!1)},children:o(`localBotCreate`)}),(0,Y.jsx)(`button`,{className:`dc-button`,type:`button`,disabled:m||A,title:o(`localBotImportTip`),onClick:()=>M.current?.click(),children:o(A?`localBotImporting`:`localBotImport`)}),(0,Y.jsx)(`input`,{ref:M,type:`file`,accept:`application/json,.json`,hidden:!0,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t&&ee(t)}})]})]}),(0,Y.jsx)(`p`,{children:o(`localBotHint`)}),g&&!d&&(0,Y.jsx)(`p`,{role:`alert`,children:g}),v&&(0,Y.jsx)(`p`,{role:`status`,children:v}),(0,Y.jsxs)(`div`,{className:`dc-bot-workspace${d?` is-editing`:``}`,children:[(0,Y.jsx)(`div`,{className:`dc-bot-list`,"aria-label":o(`localBotTitle`),children:s.map(e=>(0,Y.jsxs)(`div`,{className:`dc-bot-entry`,children:[(0,Y.jsxs)(`button`,{className:`dc-button dc-bot-item${d?.id===e.id?` is-selected`:``}`,"aria-pressed":d?.id===e.id,disabled:m,onClick:()=>{f(structuredClone(e)),_(``),k(!1)},children:[(0,Y.jsx)(`span`,{className:`dc-bot-avatar`,"aria-hidden":`true`,children:e.name.slice(0,2).toUpperCase()}),(0,Y.jsxs)(`span`,{className:`dc-bot-item-copy`,children:[(0,Y.jsx)(`strong`,{children:e.name}),(0,Y.jsxs)(`small`,{className:e.enabled?`is-enabled`:``,children:[e.enabled?o(`localBotEnabled`):o(`localBotDisabled`),` · r`,e.revision]}),e.cwd.startsWith(`ssh://`)&&(0,Y.jsx)(`small`,{title:e.cwd,children:o(`nativeCliRemoteLocation`,{host:e.cwd.replace(/^ssh:\/\/([^@]+)@([^:/]+).*$/,`$1@$2`)})})]})]}),(0,Y.jsx)(`button`,{type:`button`,className:`dc-bot-chat`,title:o(`botChat`,{name:e.name}),"aria-label":o(`botChat`,{name:e.name}),disabled:m||l!==null,onClick:()=>void B(e.id),children:l===e.id?`…`:o(`botChatShort`)})]},e.id))}),d&&(0,Y.jsx)(`dialog`,{ref:I,className:`dc-bot-drawer`,"aria-label":o(`localBotTitle`),onCancel:e=>{e.preventDefault(),!m&&!O&&p()},onClick:e=>{if(e.target!==e.currentTarget||m)return;let t=e.currentTarget.getBoundingClientRect();(e.clientX<t.left||e.clientX>t.right||e.clientY<t.top||e.clientY>t.bottom)&&p()},children:(0,Y.jsx)(`form`,{className:`dc-bot-editor`,onSubmit:e=>{e.preventDefault(),te()},children:(0,Y.jsx)(Mn,{variant:`dialog`,value:d,onChange:e=>f({...d,...e}),options:b,optionsLoading:w,optionsError:S,onReloadOptions:()=>D(e=>e+1),busy:m,baseCwd:F.current||d.cwd,modelPortalTarget:I.current??document.body,modelOpen:O,onModelOpenChange:k,dialogChrome:{railHeader:(0,Y.jsxs)(`div`,{className:`dc-bot-b-badge`,children:[(0,Y.jsx)(`span`,{className:`dc-bot-avatar`,"aria-hidden":`true`,children:d.name.slice(0,2).toUpperCase()||`B`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{children:d.name||o(`localBotCreate`)}),d.id&&(0,Y.jsxs)(`small`,{children:[d.id,` · r`,d.revision]})]})]}),railFooter:(0,Y.jsxs)(`div`,{className:`dc-bot-b-rail-foot`,children:[(0,Y.jsxs)(`label`,{className:`dc-bot-enabled`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,role:`switch`,disabled:m,checked:d.enabled,onChange:e=>f({...d,enabled:e.target.checked})}),o(`localBotEnable`)]}),d.id&&(0,Y.jsx)(`button`,{className:`dc-button is-danger`,type:`button`,style:{width:`100%`},disabled:m,onClick:()=>{window.confirm(o(`localBotDeleteConfirm`))&&te(!0)},children:o(`localBotDelete`)})]}),closeButton:(0,Y.jsx)(`button`,{className:`dc-button dc-bot-drawer-close`,type:`button`,"aria-label":o(`localBotCancel`),disabled:m,onClick:p,children:`×`}),errorBanner:g?(0,Y.jsx)(`p`,{className:`dc-bot-error`,role:`alert`,children:g}):void 0,footer:(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`button`,{className:`dc-button`,type:`button`,disabled:m,onClick:()=>{p(),k(!1)},children:o(`localBotCancel`)}),(0,Y.jsx)(`button`,{className:`dc-button dc-bot-save`,disabled:m||!d.cwd||!d.name.trim(),children:o(`localBotSave`)})]})}})})})]})]})}function In({room:e,onClose:t}){let n=U(),[r,i]=(0,Q.useState)([]),[a,o]=(0,Q.useState)(e.botIds),[s,c]=(0,Q.useState)([]),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(!0),[p,m]=(0,Q.useState)(!1),[h,g]=(0,Q.useState)(``),[_,v]=(0,Q.useState)(0),y=(0,Q.useRef)(null),b=()=>{!p&&!l&&t()};je(b),(0,Q.useEffect)(()=>()=>y.current?.abort(),[]),(0,Q.useEffect)(()=>{let t=new AbortController;return f(!0),Promise.all([Xn(`bots`,t.signal),Xn(`rooms/${encodeURIComponent(e.id)}`,t.signal)]).then(([e,n])=>{t.signal.aborted||(i(e.bots),o(n.room.botIds))}).catch(e=>{t.signal.aborted||g(e instanceof Error?e.message:String(e))}).finally(()=>{t.signal.aborted||f(!1)}),()=>t.abort()},[e.id,_]);async function x(n){if(y.current)return;let r=new AbortController;y.current=r,m(!0),g(``);try{let i=`rooms/${encodeURIComponent(e.id)}`,a=await Xn(i,r.signal);if(r.signal.aborted||(await Xn(`${i}/members`,r.signal,{botIds:[...new Set([...a.room.botIds,...n])]}),r.signal.aborted))return;window.dispatchEvent(new CustomEvent(Hn)),t()}catch(e){r.signal.aborted||g(e instanceof Error?e.message:String(e))}finally{y.current=null,r.signal.aborted||m(!1)}}return(0,zt.createPortal)((0,Y.jsx)(`div`,{className:`modal-backdrop`,onClick:b,children:(0,Y.jsxs)(`div`,{className:`device-group-bot-dialog`,role:`dialog`,"aria-modal":`true`,"aria-label":n(`deviceGroupSectionAddOrCreateBot`),onClick:e=>e.stopPropagation(),children:[(0,Y.jsxs)(`div`,{className:`dg-heading`,children:[(0,Y.jsxs)(`h2`,{children:[n(`deviceGroupSectionAddBot`),` · `,e.name]}),(0,Y.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:p||l,onClick:b,children:n(`close`)})]}),h&&(0,Y.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:h}),(0,Y.jsx)(`p`,{children:n(`deviceGroupBotDialogLead`)}),d?(0,Y.jsx)(`p`,{children:n(`loading`)}):(0,Y.jsxs)(`div`,{className:`dg-bot-choices`,children:[r.filter(e=>e.enabled&&!a.includes(e.id)).map(e=>(0,Y.jsxs)(`label`,{className:`dg-bot-choice`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,disabled:p||l,checked:s.includes(e.id),onChange:t=>c(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}),(0,Y.jsxs)(`span`,{children:[e.name,e.deviceName&&(0,Y.jsx)(`small`,{children:e.deviceName})]})]},e.id)),!r.some(e=>e.enabled&&!a.includes(e.id))&&(0,Y.jsx)(`p`,{children:n(`deviceGroupBotDialogEmpty`)})]}),(0,Y.jsxs)(`div`,{className:`dc-actions`,children:[(0,Y.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:p||l,onClick:()=>{u(!0),g(``)},children:n(`deviceGroupsCreateBot`)}),(0,Y.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:d||p||l||!s.length,onClick:()=>void x(s),children:n(p?`deviceGroupBotDialogAdding`:`deviceGroupBotDialogAddToGroup`)})]}),l&&(0,Y.jsx)(Fn,{createOnly:!0,onCancel:()=>u(!1),onCreated:(e,t)=>{if(u(!1),v(e=>e+1),!t||!e.enabled){g(n(`deviceGroupBotDialogSaved`));return}x([e.id])}})]})}),document.body)}var Ln=`pi-web-ui:device-groups-changed`;async function Rn(e,t,n){return Me(`/api/device-center/${e}`,{body:n,signal:AbortSignal.any([t,AbortSignal.timeout(15e3)]),errorFor:e=>new Pe(e.status,e.error,e.code)})}function zn({roomId:e,onClose:t,onSaved:n}){let r=U();je(t);let[i,a]=(0,Q.useState)(!0),[o,s]=(0,Q.useState)(``),[c,l]=(0,Q.useState)([]),[u,d]=(0,Q.useState)(new Set),[f,p]=(0,Q.useState)(!1),[m,h]=(0,Q.useState)(`local`),[g,_]=(0,Q.useState)(!1),[v,y]=(0,Q.useState)(``),[b,x]=(0,Q.useState)([]),[S,C]=(0,Q.useState)(``),[w,T]=(0,Q.useState)(!1),E=(0,Q.useRef)(0);(0,Q.useEffect)(()=>{let t=++E.current,n=new AbortController,r=()=>E.current===t&&!n.signal.aborted;return(async()=>{try{let[t,i]=await Promise.all([Rn(`bots`,n.signal).catch(()=>({bots:[]})),Rn(`shared-bots`,n.signal).then(e=>({...e,ok:!0})).catch(()=>({bots:[],ok:!1}))]);if(!r())return;let a=Array.isArray(t.bots)?t.bots:[],o=Array.isArray(i.bots)?i.bots:[];p(!!i.ok&&o.length>0),d(new Set(a.map(e=>e.id)));let c=new Map;for(let e of a)c.set(e.id,e);for(let e of o)c.has(e.id)||c.set(e.id,e);l([...c.values()]);let u=null,f=`local`;try{u=(await Rn(`rooms/${encodeURIComponent(e)}`,n.signal)).room,f=`local`}catch(t){if(t.status!==404)throw t;u=(await Rn(`shared-rooms/${encodeURIComponent(e)}`,n.signal)).room,f=`shared`}if(!r()||!u)return;h(u.scope===`shared`?`shared`:f),_(!!u.router?.enabled),y(u.name??``),x([...u.botIds??[]]),C(u.primaryBotId??``),s(``)}catch(e){r()&&s(e instanceof Error?e.message:String(e))}finally{r()&&a(!1)}})(),()=>{n.abort()}},[e]);let D=b.every(e=>u.has(e))?`local`:`shared`,O=!i&&!o&&D!==m;async function k(){if(w||i)return;let a=v.trim();if(!a||b.length===0)return;if(D===`shared`&&!f&&m!==`shared`){s(r(`deviceGroupManagerNoBots`));return}T(!0),s(``);let o=new AbortController;try{let i=D===`shared`?`shared-rooms`:`rooms`;if(D===m){a&&await Rn(`${i}/${encodeURIComponent(e)}/rename`,o.signal,{name:a});let r=(await Rn(`${i}/${encodeURIComponent(e)}/members`,o.signal,{botIds:b,primaryBotId:b.includes(S)?S:null})).room?.id??e;window.dispatchEvent(new CustomEvent(Ln)),n?.(r),t()}else{let s=(await Rn(i,o.signal,{name:a,botIds:b,...b.includes(S)?{primaryBotId:S}:{}})).room?.id;if(!s)throw Error(r(`deviceGroupsFailed`));await Rn(`${m===`shared`?`shared-rooms`:`rooms`}/${encodeURIComponent(e)}/delete`,o.signal,{}),window.dispatchEvent(new CustomEvent(Ln)),n?.(s),t()}}catch(e){o.signal.aborted||s(e instanceof Error?e.message:String(e))}finally{T(!1)}}return(0,zt.createPortal)((0,Y.jsx)(`div`,{className:`modal-backdrop`,onClick:()=>!w&&t(),children:(0,Y.jsxs)(`div`,{className:`dc-card device-group-create-dialog`,role:`dialog`,"aria-modal":`true`,"aria-label":`${r(`edit`)} · ${v||e}`,onClick:e=>e.stopPropagation(),style:{minWidth:`min(480px, 92vw)`},children:[(0,Y.jsxs)(`div`,{className:`dg-heading`,style:{marginBottom:`12px`},children:[(0,Y.jsxs)(`h3`,{children:[r(`edit`),` · `,v||e,m===`shared`?` · ${r(`deviceGroupManagerSharedSuffix`)}`:``]}),(0,Y.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:t,disabled:w,children:[(0,Y.jsx)(_e,{"aria-hidden":!0}),r(`close`)]})]}),i&&(0,Y.jsx)(`p`,{role:`status`,children:r(`loading`)}),o&&(0,Y.jsx)(`p`,{className:`dc-error`,role:`alert`,children:o}),!i&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`12px`},children:[(0,Y.jsx)(`label`,{htmlFor:`dg-edit-name`,children:r(`deviceGroupManagerNameLabel`)}),(0,Y.jsx)(`input`,{id:`dg-edit-name`,type:`text`,maxLength:80,value:v,onChange:e=>y(e.target.value),disabled:w,placeholder:r(`deviceGroupManagerRenamePlaceholder`),style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`}})]}),(0,Y.jsxs)(`div`,{style:{marginBottom:`12px`},children:[(0,Y.jsx)(`label`,{style:{display:`block`,marginBottom:`6px`,fontSize:`12px`,color:`var(--text-dim)`},children:r(`deviceGroupManagerSelectMembers`)}),(0,Y.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`6px`,maxHeight:`220px`,overflowY:`auto`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`8px`,background:`var(--bg-elev)`},children:c.length===0?(0,Y.jsx)(`p`,{style:{margin:0,fontSize:`12px`,color:`var(--text-faint)`},children:r(`deviceGroupManagerNoBots`)}):c.map(e=>(0,Y.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,cursor:`pointer`,fontSize:`12px`},children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:b.includes(e.id),disabled:w,onChange:t=>{x(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}}),(0,Y.jsxs)(`span`,{children:[(0,Y.jsx)(`strong`,{children:e.name}),(0,Y.jsxs)(`small`,{style:{color:`var(--text-faint)`,marginInlineStart:`6px`},children:[e.deviceName??(u.has(e.id)?``:e.deviceId??``),e.online===void 0?``:` · ${e.online?r(`deviceHubOnline`):r(`deviceHubOffline`)}`,e.enabled?``:r(`deviceGroupManagerDisabledSuffix`),u.has(e.id)?``:` · ${r(`deviceGroupManagerSharedSuffix`)}`]})]})]},e.id))})]}),!g&&(0,Y.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`16px`},children:[(0,Y.jsx)(`label`,{htmlFor:`dg-edit-primary`,children:r(`deviceGroupManagerLegacyPrimary`)}),(0,Y.jsxs)(`select`,{id:`dg-edit-primary`,value:b.includes(S)?S:``,onChange:e=>C(e.target.value),disabled:w,style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`},children:[(0,Y.jsx)(`option`,{value:``,children:r(`deviceGroupManagerNoPrimary`)}),c.filter(e=>b.includes(e.id)).map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),O&&(0,Y.jsx)(`p`,{className:`dc-notice`,role:`status`,children:r(D===`shared`?`deviceGroupManagerMigrateToSharedHint`:`deviceGroupManagerMigrateToLocalHint`)}),(0,Y.jsxs)(`div`,{className:`dc-actions`,children:[(0,Y.jsxs)(`button`,{type:`button`,className:`dc-button is-primary`,disabled:w||!v.trim()||b.length===0,onClick:()=>void k(),children:[(0,Y.jsx)(R,{"aria-hidden":!0}),r(w?`saving`:`deviceGroupManagerSaveMembers`)]}),(0,Y.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:t,disabled:w,children:r(`cancel`)})]})]})]})}),document.body)}var Bn={activity:(0,Y.jsx)(ve,{}),aperture:(0,Y.jsx)(F,{}),branch:(0,Y.jsx)(t,{}),browser:(0,Y.jsx)(ye,{}),chat:(0,Y.jsx)(we,{}),check:(0,Y.jsx)(R,{}),"chevron-up":(0,Y.jsx)(s,{}),clock:(0,Y.jsx)(oe,{}),code:(0,Y.jsx)(r,{}),coins:(0,Y.jsx)(i,{}),copy:(0,Y.jsx)(y,{}),cpu:(0,Y.jsx)(_,{}),cut:(0,Y.jsx)(E,{}),database:(0,Y.jsx)(Ee,{}),dot:(0,Y.jsx)(`span`,{className:`host-icon-char`,children:`●`}),download:(0,Y.jsx)(D,{}),edit:(0,Y.jsx)(p,{}),engine:(0,Y.jsx)(F,{}),eye:(0,Y.jsx)(f,{}),feather:(0,Y.jsx)(he,{}),file:(0,Y.jsx)(g,{}),folder:(0,Y.jsx)(M,{}),folders:(0,Y.jsx)(it,{}),gauge:(0,Y.jsx)(ve,{}),git:(0,Y.jsx)(t,{}),github:(0,Y.jsx)(ne,{}),globe:(0,Y.jsx)(ye,{}),grid:(0,Y.jsx)(de,{}),hash:(0,Y.jsx)(`span`,{className:`host-icon-char`,children:`#`}),image:(0,Y.jsx)(pe,{}),info:(0,Y.jsx)(z,{}),layers:(0,Y.jsx)(xe,{}),link:(0,Y.jsx)(re,{}),list:(0,Y.jsx)(me,{}),lock:(0,Y.jsx)(le,{}),markdown:(0,Y.jsx)(A,{}),maximize:(0,Y.jsx)(Se,{}),menu:(0,Y.jsx)(Te,{}),minimize:(0,Y.jsx)(Ce,{}),message:(0,Y.jsx)(we,{}),open:(0,Y.jsx)(k,{}),paste:(0,Y.jsx)(b,{}),pin:(0,Y.jsx)(ie,{}),plus:(0,Y.jsx)(S,{}),refresh:(0,Y.jsx)(d,{}),sandbox:(0,Y.jsx)(ot,{}),save:(0,Y.jsx)(v,{}),share:(0,Y.jsx)($e,{}),search:(0,Y.jsx)(De,{}),send:(0,Y.jsx)(a,{}),settings:(0,Y.jsx)(m,{}),sound:(0,Y.jsx)(fe,{}),sun:(0,Y.jsx)(j,{}),target:(0,Y.jsx)(w,{}),terminal:(0,Y.jsx)(N,{}),text:(0,Y.jsx)(V,{}),trash:(0,Y.jsx)(n,{}),undo:(0,Y.jsx)(h,{}),upload:(0,Y.jsx)(ue,{}),users:(0,Y.jsx)(I,{}),volume:(0,Y.jsx)(fe,{}),wrap:(0,Y.jsx)(x,{}),x:(0,Y.jsx)(_e,{}),zap:(0,Y.jsx)(ee,{}),zoom:(0,Y.jsx)(se,{})};Object.keys(Bn);function Vn(e){if(e.iconSvg)return(0,Y.jsx)(gt,{icon:e.icon,iconSvg:e.iconSvg});if(!e.icon)return null;let t=Bn[e.icon];return t===void 0?/[a-z]/i.test(e.icon)?null:(0,Y.jsx)(`span`,{className:`plugin-icon-glyph`,children:e.icon}):t}var Hn=`pi-web-ui:device-groups-changed`,Un={rename:`deviceGroupManagerRename`,edit:`edit`,clear:`deviceGroupSectionClearMessages`,delete:`deviceGroupSectionDeleteGroup`},Wn={bind:`deviceGroupSectionBind`,running:`deviceGroupSectionRunning`,forbidden:`deviceGroupSectionForbidden`,failed:`deviceGroupSectionFailed`},Gn=class extends Error{status;code;detail;constructor(e,t,n=``){super(`Device group request failed (${e})`),this.status=e,this.code=t,this.detail=n}},Kn=[`bot-drafts`],qn=15e3,Jn=12e4;function Yn(e){return Kn.some(t=>e===t||e.startsWith(`${t}/`))}async function Xn(e,t,n){return Me(`/api/device-center/${e}`,{body:n,signal:AbortSignal.any([t,AbortSignal.timeout(Yn(e)?Jn:qn)]),errorFor:t=>new Gn(t.status,t.code,Yn(e)?t.detail.trim():``)})}function Zn(e){return e instanceof Gn?[`NOT_PAIRED`,`REPAIR_REQUIRED`,`DEVICE_CHANGED`].includes(e.code)?`bind`:[`ROOM_BUSY`,`ROOM_RUNNING`,`TASKS_RUNNING`,`ACTIVE_TASKS`].includes(e.code)?`running`:e.status===403?`forbidden`:`failed`:`failed`}function Qn(e,t,n){let r,i=0,a=!1,o=!1,s=()=>{if(o)return;let c=++i;if(r){a=!0;return}let l=new AbortController;r=l,e(l.signal).then(e=>{!o&&c===i&&t(e)},e=>{!o&&c===i&&!l.signal.aborted&&n(e)}).finally(()=>{r=void 0,a&&!o&&(a=!1,s())})};return{refresh:s,pause:()=>{i++,a=!1,r?.abort()},stop:()=>{o=!0,i++,a=!1,r?.abort()}}}function $n(e){window.dispatchEvent(new CustomEvent(`pi-web-ui:device-group-open`,{detail:e}))}function er({active:e=!0,entry:t,selectedRoomId:n,flex:r,onCollapsedChange:i,hideWhenEmpty:a=!1,autoHeight:c=!1}){let l=U(),u=t?.labelExplicit?t.label:l(`deviceGroups`),[d,f]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(null),[h,g]=(0,Q.useState)(null),[_,v]=(0,Q.useState)(()=>new Set);(0,Q.useEffect)(()=>i?.(d),[d,i]);let[y,b]=(0,Q.useState)([]),[x,C]=(0,Q.useState)(null),[w,T]=(0,Q.useState)(!0),[E,D]=(0,Q.useState)(null),[O,k]=(0,Q.useState)(null),[A,j]=(0,Q.useState)(``),[M,N]=(0,Q.useState)(!1),P=(0,Q.useRef)(null),F=(0,Q.useRef)(null),L=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>(L.current=!0,()=>{L.current=!1,F.current?.abort()}),[]),(0,Q.useEffect)(()=>{if(!e)return;let t=!1,n=Qn(async e=>{let n=await Xn(`chat-status`,e);if(t=n.roomsReady===!0||!!(n.hubUrl&&n.deviceId),!t)return[];let[r,i]=await Promise.all([Xn(`rooms`,e),Xn(`shared-rooms`,e).catch(()=>({rooms:[]}))]);if(!Array.isArray(r.rooms))throw Error(`Invalid rooms response`);let a=new Set,o=[];for(let e of r.rooms)a.add(e.id),o.push(e.scope?e:{...e,scope:`local`});for(let e of Array.isArray(i.rooms)?i.rooms:[])a.has(e.id)||(a.add(e.id),o.push(e.scope?e:{...e,scope:`shared`}));return o},e=>{C(t),b(e),D(null),T(!1)},e=>{D(Zn(e)),T(!1)});P.current=n;let r=()=>{document.hidden||n.refresh()},i=()=>{document.hidden?n.pause():r()};r();let a=window.setInterval(r,15e3);return window.addEventListener(Hn,r),document.addEventListener(`visibilitychange`,i),()=>{n.stop(),P.current=null,window.clearInterval(a),window.removeEventListener(Hn,r),document.removeEventListener(`visibilitychange`,i)}},[e]);let R=async(e,t)=>{if(F.current||t===`delete`&&!window.confirm(l(`deviceGroupSectionConfirmDelete`,{name:e.name}))||t===`clear`&&!window.confirm(l(`deviceGroupSectionConfirmClear`,{name:e.name})))return;let n=new AbortController;F.current=n,N(!0),D(null);try{if(await Xn(`${e.scope===`shared`?`shared-rooms`:`rooms`}/${encodeURIComponent(e.id)}/${t}`,n.signal,t===`rename`?{name:A.trim()}:{}),!L.current||n.signal.aborted)return;k(null),window.dispatchEvent(new CustomEvent(Hn))}catch(e){L.current&&!n.signal.aborted&&D(Zn(e))}finally{F.current=null,L.current&&N(!1)}},ee=(e,t)=>{e.preventDefault(),e.stopPropagation();let n=[`rename`,`edit`,`clear`,`delete`].map((e,t)=>({id:`host:device-group-${e}`,slot:`contextmenu.project`,source:`host`,label:l(Un[e]),kind:`action`,action:e,order:t,align:`start`,hidden:!1,userOverrides:[],arrangedBy:[]}));ze({x:e.clientX,y:e.clientY,slot:`contextmenu.project`,target:{id:t.id,kind:`device-group`,label:t.name},entries:n,onHostAction:e=>{F.current||(e.action===`rename`?(k(t.id),j(t.name)):e.action===`edit`?g(t):(e.action===`clear`||e.action===`delete`)&&R(t,e.action))}})};if(x===!1||x===null&&w||a&&y.length===0&&!E)return null;let z=(0,Y.jsxs)(`div`,{className:`lp-section-body dg-side-body`,children:[E&&(0,Y.jsxs)(`div`,{className:`dg-side-error`,role:`status`,children:[l(Wn[E]),E===`bind`?(0,Y.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>$n({}),children:l(`deviceGroupSectionOpenDeviceCenter`)}):(0,Y.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>P.current?.refresh(),children:l(`retryNow`)})]}),!E&&y.length===0&&(0,Y.jsx)(`div`,{className:`dg-side-empty`,children:l(w?`loading`:`deviceGroupSectionEmpty`)}),y.map(e=>(0,Y.jsxs)(`div`,{className:`dg-side-item`,children:[(0,Y.jsxs)(`div`,{className:`dg-side-heading`,children:[(0,Y.jsx)(`button`,{type:`button`,className:`dg-side-toggle`,"aria-expanded":_.has(e.id),"aria-label":`${e.name} · ${l(`deviceGroupSectionMembers`)}`,onClick:()=>v(t=>{let n=new Set(t);return n.has(e.id)?n.delete(e.id):n.add(e.id),n}),children:_.has(e.id)?(0,Y.jsx)(s,{}):(0,Y.jsx)(o,{})}),(0,Y.jsxs)(`div`,{role:`button`,tabIndex:0,className:`dg-side-row${n===e.id?` is-selected`:``}`,"aria-current":n===e.id?`page`:void 0,title:e.name,onClick:()=>$n({roomId:e.id}),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),$n({roomId:e.id}))},onContextMenu:t=>ee(t,e),children:[(0,Y.jsx)(I,{}),(0,Y.jsxs)(`span`,{className:`dg-side-name`,children:[e.name,e.scope===`shared`&&(0,Y.jsx)(`small`,{style:{marginInlineStart:6,opacity:.75},children:l(`deviceGroupManagerSharedSuffix`)})]})]}),(0,Y.jsx)(`button`,{type:`button`,className:`dg-side-toggle`,"aria-label":`${e.name} · ${l(`deviceGroupSectionAddBot`)}`,title:l(`deviceGroupSectionAddOrCreateBot`),onClick:()=>m(e),children:(0,Y.jsx)(S,{})})]}),_.has(e.id)&&(0,Y.jsx)(Pt,{botIds:e.botIds,roomId:e.id}),O===e.id&&(0,Y.jsxs)(`form`,{className:`dg-side-rename`,onSubmit:t=>{t.preventDefault(),A.trim()&&R(e,`rename`)},children:[(0,Y.jsx)(`input`,{className:`dc-input`,"aria-label":l(`deviceGroupManagerNameLabel`),value:A,maxLength:120,autoFocus:!0,disabled:M,onChange:e=>j(e.target.value),onKeyDown:e=>{e.key===`Escape`&&k(null)}}),(0,Y.jsx)(`button`,{type:`submit`,className:`dc-button`,disabled:M||!A.trim(),children:l(`save`)}),(0,Y.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:M,onClick:()=>k(null),children:l(`cancel`)})]})]},e.id))]});return(0,Y.jsxs)(`section`,{className:`lp-section dg-side-section${d?` collapsed`:``}${c?` lp-section-auto`:``}`,"aria-label":u,style:!d&&r!==void 0?{flex:`${r} 1 0px`}:void 0,children:[(0,Y.jsxs)(`div`,{className:`lp-section-header`,children:[(0,Y.jsxs)(`button`,{type:`button`,className:`lp-section-title panel-section-title`,"aria-expanded":!d,title:l(d?`deviceGroupSectionExpand`:`deviceGroupSectionCollapse`),onClick:()=>f(!d),children:[(0,Y.jsxs)(`span`,{className:`lp-section-title-text lp-section-title-chip`,children:[t&&Vn(t),(0,Y.jsx)(`span`,{children:u}),(0,Y.jsxs)(`span`,{className:`lp-section-count`,children:[`(`,y.length,`)`]})]}),(0,Y.jsx)(`span`,{className:`lp-section-chevron`,children:d?(0,Y.jsx)(o,{}):(0,Y.jsx)(s,{})})]}),(0,Y.jsx)(`div`,{className:`lp-section-actions`,children:(0,Y.jsx)(`button`,{type:`button`,className:`lp-section-action`,title:l(`deviceGroupsCreate`),"aria-label":l(`deviceGroupsCreate`),onClick:()=>$n({create:!0}),children:(0,Y.jsx)(S,{})})})]}),!d&&z,p&&(0,Y.jsx)(In,{room:p,onClose:()=>m(null)}),h&&(0,Y.jsx)(zn,{roomId:h.id,onClose:()=>g(null)})]})}export{K as $,xt as A,at as B,Ot as C,Dt as D,Mt as E,_t as F,et as G,rt as H,vt as I,Ve as J,$e as K,gt as L,Ct as M,St as N,Et as O,wt as P,Ze as Q,st as R,Rt as S,Nt as T,nt as U,it as V,tt as W,Je as X,G as Y,Ue as Z,Kt as _,Vn as a,$ as b,En as c,xn as d,He as et,vn as f,Wt as g,ln as h,Xn as i,Be as it,yt as j,X as k,Cn as l,un as m,Gn as n,Xe as nt,Fn as o,dn as p,Ye as q,er as r,qe as rt,Mn as s,Hn as t,J as tt,yn as u,qt as v,Tt as w,Lt as x,Vt as y,ot as z};
|