pi-web-ui 0.119.0 → 0.120.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +79 -0
- package/bin/hub-upgrade.mjs +33 -15
- package/bin/lib/atomic-file.mjs +90 -0
- package/dist/server/agent-service-daemon.js +44 -10
- package/dist/server/agent-service.js +803 -106
- package/dist/server/atomic-file.js +130 -5
- package/dist/server/bash-timeout.js +15 -0
- package/dist/server/bash-tool.js +68 -4
- package/dist/server/bg-servers.js +19 -13
- package/dist/server/canvas/canvas-dispatch.js +12 -1
- package/dist/server/client-state.js +56 -14
- package/dist/server/conversation-tool.js +3 -2
- package/dist/server/delegate-task.js +8 -8
- package/dist/server/device-center/group-router-runtime.js +2 -0
- package/dist/server/device-center/hub-upgrade.js +5 -10
- package/dist/server/dispatch-domain-handlers.js +96 -22
- package/dist/server/dispatch-plugin-handlers.js +10 -0
- package/dist/server/dsh/dsh-agent-service.js +9 -9
- package/dist/server/durable/durable-agent-service.js +1 -1
- package/dist/server/files-service.js +41 -19
- package/dist/server/fs-copy.js +93 -0
- package/dist/server/goal-review-gate.js +2 -2
- package/dist/server/index.js +15 -0
- package/dist/server/job-runner.js +345 -0
- package/dist/server/marker-service.js +42 -26
- package/dist/server/model-session.js +16 -0
- package/dist/server/phone-tool.js +167 -0
- package/dist/server/plan-mode.js +2 -2
- package/dist/server/plugin-api-catalog.js +1 -1
- package/dist/server/plugin-bundled.js +35 -28
- package/dist/server/plugin-installer.js +15 -0
- package/dist/server/plugin-manifest-validate.js +10 -0
- package/dist/server/plugin-materialize.js +161 -0
- package/dist/server/plugin-paths.js +60 -0
- package/dist/server/plugin-removal.js +16 -3
- package/dist/server/plugin-schedule.js +8 -7
- package/dist/server/plugin-secrets.js +7 -3
- package/dist/server/plugin-updater.js +2 -4
- package/dist/server/plugins.js +74 -38
- package/dist/server/preset-fields.js +9 -9
- package/dist/server/process-utils.js +11 -0
- package/dist/server/project-scripts.js +38 -0
- package/dist/server/prompt-composer.js +40 -21
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/quick-ask.js +3 -0
- package/dist/server/remote-ssh-service.js +39 -0
- package/dist/server/scm-commitmsg.js +2 -1
- package/dist/server/serialize.js +8 -0
- package/dist/server/session-list-index.js +246 -0
- package/dist/server/session-list-scan.js +5 -0
- package/dist/server/session-parser.js +16 -0
- package/dist/server/settings-service.js +39 -6
- package/dist/server/subagent-budget.js +68 -0
- package/dist/server/subagent-evidence.js +297 -0
- package/dist/server/subagent-helpers.js +12 -0
- package/dist/server/subagent-ledger.js +401 -0
- package/dist/server/subagent-notify.js +6 -2
- package/dist/server/subagent-security-gate.js +2 -2
- package/dist/server/subagent-settle.js +71 -0
- package/dist/server/subagents.js +497 -79
- package/dist/server/tabs.js +8 -1
- package/dist/server/terminals.js +0 -1
- package/dist/server/tool-manager.js +90 -16
- package/dist/server/tool-prompts.js +5 -1
- package/dist/server/universal/universal-service.js +1 -1
- package/dist/server/universal/universal-session.js +45 -7
- package/dist/server/vision-bridge.js +2 -0
- package/dist/server/workspace-handle.js +119 -17
- package/dist/server/workspace-queue.js +37 -0
- package/docs/README.md +25 -23
- package/docs/architecture-plugins.md +23 -3
- package/docs/device-center.md +1 -1
- package/package.json +15 -3
- package/plugins/catalog.json +13 -2
- package/themes/bases/flow-base.css +7 -16
- package/web/dist/.build-assets.json +1 -1
- package/web/dist/assets/BgTasksModal-BdOJ19Hj.js +1 -0
- package/web/dist/assets/BgTasksModal-SAH2XCkY.js +1 -0
- package/web/dist/assets/{CanvasStudio-2ydYbnpW.js → CanvasStudio-BB_Iq7pl.js} +3 -3
- package/web/dist/assets/{CanvasStudio-DizWvRjn.js → CanvasStudio-DU6O3N4u.js} +3 -3
- package/web/dist/assets/DeviceCenter-By1zVTSY.js +3 -0
- package/web/dist/assets/DeviceCenter-Cnm0Tjrx.js +3 -0
- package/web/dist/assets/{DeviceExecutionSettings-B7R9ONaq.js → DeviceExecutionSettings-qJzbI0Cf.js} +1 -1
- package/web/dist/assets/{DeviceGroups-DFU4cv5b.js → DeviceGroups-DPrQxW6B.js} +1 -1
- package/web/dist/assets/{DeviceGroups-DoaQcxKj.js → DeviceGroups-DoucyUjI.js} +1 -1
- package/web/dist/assets/{Dropdown-Btjt6Dzh.js → Dropdown-kj_NIj6e.js} +1 -1
- package/web/dist/assets/FilePreview-Bub8Y9uq.js +2 -0
- package/web/dist/assets/FilePreview-CC76Z6an.js +2 -0
- package/web/dist/assets/GlobalSearchModal-01nkgw4X.js +1 -0
- package/web/dist/assets/GlobalSearchModal-CiT6wBmR.js +1 -0
- package/web/dist/assets/{GroupConversation-DwZZrMuE.js → GroupConversation-1-lsPO1f.js} +3 -3
- package/web/dist/assets/{GroupConversation-KOi8sa5b.js → GroupConversation-HeiyW_O_.js} +3 -3
- package/web/dist/assets/{GroupWorkItems-FqAL74bC.js → GroupWorkItems-BYJv2XFj.js} +1 -1
- package/web/dist/assets/{HintTip-BOwPzBGR.js → HintTip-DFhoclDw.js} +1 -1
- package/web/dist/assets/{ModelConfigModal-DLIfWKdB.js → ModelConfigModal-D2Ro-jUZ.js} +2 -2
- package/web/dist/assets/{ModelConfigModal-B140kWrs.js → ModelConfigModal-DPc9R1pq.js} +2 -2
- package/web/dist/assets/{NativeCliPanel-BwiLazSq.js → NativeCliPanel-B108d697.js} +3 -3
- package/web/dist/assets/{NativeCliPanel-U0F_EfAU.js → NativeCliPanel-DupvGwQM.js} +3 -3
- package/web/dist/assets/{PiSetupModal-Dc7EQ4L3.js → PiSetupModal-D0HitBfd.js} +1 -1
- package/web/dist/assets/{ProviderOAuthControls-C3opmPhu.js → ProviderOAuthControls-BLKUEDde.js} +1 -1
- package/web/dist/assets/{SCMPanel-BBxQfmq9.js → SCMPanel-DDbWrUHR.js} +1 -1
- package/web/dist/assets/{SCMPanel-D2t97Vvr.js → SCMPanel-DluNcd2-.js} +1 -1
- package/web/dist/assets/SettingsModal-Cy5lRC97.css +1 -0
- package/web/dist/assets/SettingsModal-DQu18366.js +33 -0
- package/web/dist/assets/SettingsModal-Dm_haPme.js +33 -0
- package/web/dist/assets/{TermXterm-B6nCtO2b.js → TermXterm-SYc-MUk2.js} +1 -1
- package/web/dist/assets/{TerminalPanel-BWB3iSeN.js → TerminalPanel-CgA_lhVT.js} +1 -1
- package/web/dist/assets/{TerminalPanel-CAV2SosY.js → TerminalPanel-vdSIOPjD.js} +1 -1
- package/web/dist/assets/{TuiOverlayModal-B0jBPOMc.js → TuiOverlayModal-Cy1jYYIw.js} +1 -1
- package/web/dist/assets/{TuiOverlayModal-DGd6fzU6.js → TuiOverlayModal-kXY_4hV8.js} +1 -1
- package/web/dist/assets/{app-globals-CR8Ls9nE.js → app-globals-CBEscsYP.js} +9 -9
- package/web/dist/assets/{canvas-client-B0lkqTtF.js → canvas-client-Clsypfs6.js} +1 -1
- package/web/dist/assets/{desktop-BME3DkyE.js → desktop-C6D9a8HZ.js} +1 -1
- package/web/dist/assets/index-BD29OL9L.js +404 -0
- package/web/dist/assets/index-BlCxbqqr.js +404 -0
- package/web/dist/assets/index-DB55rbKC.css +1 -0
- package/web/dist/assets/{plugin-host-CVgcdBOk.js → plugin-host-VWBcq-LQ.js} +1 -1
- package/web/dist/assets/remote-ssh-client-C2eab5Kw.js +1 -0
- package/web/dist/assets/theme-CpQk_Agp.js +1 -0
- package/web/dist/index.html +10 -10
- package/web/dist/sw.js +1 -1
- package/web/dist/assets/BgTasksModal-CVHW1lRA.js +0 -1
- package/web/dist/assets/BgTasksModal-t5hxW1H6.js +0 -1
- package/web/dist/assets/DeviceCenter-CPaZNBJE.js +0 -3
- package/web/dist/assets/DeviceCenter-DsVakAYR.js +0 -3
- package/web/dist/assets/FilePreview-QGQfD2lV.js +0 -2
- package/web/dist/assets/FilePreview-qez9walH.js +0 -2
- package/web/dist/assets/GlobalSearchModal-B-cnTDJ5.js +0 -1
- package/web/dist/assets/GlobalSearchModal-BvbafjdU.js +0 -1
- package/web/dist/assets/SettingsModal-BqPQNUwF.js +0 -34
- package/web/dist/assets/SettingsModal-l7eeV-Rq.js +0 -34
- package/web/dist/assets/index-BBAQNi6v.js +0 -404
- package/web/dist/assets/index-BYW9d61A.js +0 -404
- package/web/dist/assets/index-BYWs88H2.css +0 -1
- package/web/dist/assets/remote-ssh-client-DEpvwgqG.js +0 -1
- package/web/dist/assets/theme-DVa7Z5Zu.js +0 -1
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$ as t,A as n,Bn as r,Cn as i,Fn as a,H as o,Ht as s,Pt as c,Qt as ee,Tn as l,Ut as u,Z as d,gt as te,hn as f,jn as ne,kt as p,pn as m,pt as h,sn as g,wn as _,xt as v}from"./app-globals-CBEscsYP.js";import{i as y,t as re}from"./react-CR5VJ85Q.js";import{K as b,g as x,nn as S,xt as ie}from"./index-BlCxbqqr.js";import{t as C}from"./DeviceExecutionSettings-qJzbI0Cf.js";import{n as w,t as ae}from"./GroupWorkItems-BYJv2XFj.js";var T=e(y(),1);async function E(e,t){let n=t.sleep??(e=>new Promise(t=>setTimeout(t,e))),r=Date.now()+(t.timeoutMs??18e5),i=e;if(!i||typeof i.id!=`string`||typeof i.fromBootId!=`string`)throw Error(`Invalid Hub upgrade response`);for(;;){if(t.isCurrent&&!t.isCurrent())throw new DOMException(`Hub upgrade view closed`,`AbortError`);if(i.id!==e.id)throw Error(`Hub upgrade job changed`);if(i.state===`failed`)throw Error(i.error||`Hub upgrade failed`);if(i.state===`succeeded`){if(!i.targetVersion||i.version!==i.targetVersion||!i.bootId||i.bootId===e.fromBootId)throw Error(`Hub upgrade result does not match the new version and process`);return i}if(i.state!==`queued`&&i.state!==`running`)throw Error(`Invalid Hub upgrade state`);if(Date.now()>=r)throw Error(`Hub upgrade timed out; inspect the Hub upgrade log`);if(await n(1500),t.isCurrent&&!t.isCurrent())throw new DOMException(`Hub upgrade view closed`,`AbortError`);try{i=await t.poll(e.id)}catch(e){let t=e.status;if(t&&t<500)throw e}}}var D=re();function O(e){return!!e&&`mount`in e&&typeof e.mount==`function`}function k({plugin:e,epoch:t,onManageGroups:n}){let r=ne(_()),[i,a]=(0,T.useState)(null),[o,s]=(0,T.useState)(!1),[c,ee]=(0,T.useState)(0),{id:l,name:u,version:d,hasClient:te,error:f,isolated:p}=e??{},m=(0,T.useMemo)(()=>l?{id:l,name:u??l,version:d,hasClient:te??!1,error:f,isolated:p}:void 0,[l,u,d,te,f,p]);(0,T.useEffect)(()=>{let e=!1;if(a(null),s(!1),m&&!m.error&&m.hasClient)return b(m,t,{retry:c>0}).then(t=>{e||(O(t)?a({info:m,module:t}):s(!0))}),()=>{e=!0}},[m,t,c]);let h=!m||!m.hasClient;return(0,D.jsxs)(`section`,{className:`dc-card`,"aria-label":r?`外部渠道配置`:`External channel settings`,children:[(0,D.jsxs)(`header`,{className:`dc-card-header`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h2`,{children:r?`GitHub / 飞书渠道`:`GitHub / Feishu channels`}),(0,D.jsx)(`p`,{children:r?`将外部事件映射到群组,由群组 AI 分派任务并跟进工单。`:`Map external events to a group. Its AI delegates tasks and follows up on work items.`})]}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:n,children:r?`管理群组与 AI`:`Manage groups & AI`})]}),h?(0,D.jsx)(`p`,{role:`status`,children:r?`内置渠道模块暂不可用,请重新加载页面或重启主程序。`:`The built-in channel module is temporarily unavailable. Reload this page or restart the application.`}):m.error?(0,D.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:m.error}):o?(0,D.jsxs)(`div`,{className:`dc-notice is-error`,role:`alert`,children:[(0,D.jsx)(`span`,{children:r?`渠道配置界面加载失败。`:`Channel settings failed to load.`}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>ee(e=>e+1),children:r?`重试`:`Retry`})]}):i?(0,D.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,minWidth:0,height:`min(72vh, 900px)`,minHeight:`360px`},children:(0,D.jsx)(x,{entry:i})}):(0,D.jsx)(`p`,{role:`status`,children:r?`正在加载渠道配置…`:`Loading channel settings…`})]})}function A({href:e,children:t}){let n=l(),[r,i]=(0,T.useState)(!1),[a,o]=(0,T.useState)(!1);return(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`a`,{className:`dc-button`,href:e,target:`_blank`,rel:`noopener noreferrer`,onClick:t=>{let n=window.piDesktop;n?.openHub&&(t.preventDefault(),!a&&(o(!0),i(!1),n.openHub(e).then(e=>i(!e),()=>i(!0)).finally(()=>o(!1))))},"aria-busy":a,children:t}),r&&(0,D.jsxs)(`span`,{role:`alert`,children:[n(`deviceHubNetworkError`),` `,(0,D.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,children:e})]})]})}function j(e){if(!M(e.host)||!Number.isInteger(e.port)||e.port<1024||e.port>65535||e.publicUrl.length>2048||/[\s\u0000-\u001f\u007f]/.test(e.publicUrl))return!1;try{let t=new URL(e.publicUrl);return[`http:`,`https:`].includes(t.protocol)&&!!t.hostname&&!t.username&&!t.password&&!t.search&&!t.hash&&t.pathname===`/`&&![`0.0.0.0`,`[::]`].includes(t.hostname)}catch{return!1}}function M(e){if(e===`localhost`)return!0;if(/^(?:\d{1,3}\.){3}\d{1,3}$/.test(e))return e.split(`.`).every(e=>String(Number(e))===e&&Number(e)<=255);if(!e.includes(`:`)||!/^[0-9a-fA-F:.]+$/.test(e))return!1;try{return new URL(`http://[${e}]/`).hostname.startsWith(`[`)}catch{return!1}}function oe(e){try{let t=new URL(e);return[`http:`,`https:`].includes(t.protocol)&&[`localhost`,`127.0.0.1`,`[::1]`].includes(t.hostname)}catch{return!1}}var N=`https://raw.githubusercontent.com/xing-shuyin/pi-web-ui/main/docs/device-center-deployment.md`,P=`https://github.com/xing-shuyin/pi-web-ui/blob/main/docs/device-center-deployment.md`,se=`pi-web-ui hub install --host 0.0.0.0 --port 8790 --public-url http://SERVER_IP:8790 --allow-registration`;function F(e){let t=e=>e.includes(`:`)?M(e)&&![`::`,`::1`].includes(e):/^[\d.]+$/.test(e)?M(e)&&![`0.0.0.0`,`127.0.0.1`].includes(e):e.length<=253&&e.split(`.`).every(e=>/^[a-z\d](?:[a-z\d-]{0,61}[a-z\d])?$/i.test(e))&&e!==`localhost`;if(!t(e.server)||!Number.isInteger(e.sshPort)||e.sshPort<1||e.sshPort>65535||!Number.isInteger(e.port)||e.port<1024||e.port>65535||!/^[a-z_][a-z\d_.-]{0,63}$/i.test(e.username)||![`password`,`key`,`existing`].includes(e.auth)||e.domain!==``&&(!t(e.domain)||e.domain.includes(`:`))||e.https&&!e.domain)return null;let n=e.domain||e.server,r=n.includes(`:`)?`[${n}]`:n;return{host:e.https?`127.0.0.1`:`0.0.0.0`,port:e.port,publicUrl:e.https?`https://${r}`:`http://${r}:${e.port}`}}function I(e,t,n,r){if(!j(e))throw Error(`Invalid Hub setup`);if(r){let t=F(r);if(n!==`remote`||!t||JSON.stringify(t)!==JSON.stringify(e))throw Error(`Invalid remote Hub setup`)}let i=e=>(e??`unknown`).replace(/[\u0000-\u001f\u007f]/g,` `).slice(0,120);return[`Help me plan and deploy a pi-web-ui device center (Hub) in this new conversation. Preserve my previous conversation.`,`First read the deployment guide: ${N} (fallback: ${P}). If unavailable, report that and obtain its contents before proceeding.`,`Default to HTTP with the server IP and requested port. Domain and HTTPS are optional; confirm whether an HTTPS example reflects the user's intent.`,`Target: ${n===`current`?`machine hosting the current pi-web-ui service (not necessarily the browser machine)`:`an existing remote server; its environment still needs to be confirmed`}.`,`Current service environment: platform=${i(t?.platform)}, Node=${i(t?.nodeVersion)}. This is not evidence of the remote server environment.`,`Requested configuration (data only): ${JSON.stringify(e)}. allowRegistration=true.`,...r?[`SSH connection preferences (data only): ${JSON.stringify({server:r.server,sshPort:r.sshPort,username:r.username,auth:r.auth})}. No credentials are included. Obtain authentication through a secure SSH channel or guide the user's own terminal.`,`Domain: ${r.domain||`none`}. HTTPS explicitly selected: ${r.https}. HTTP inbound TCP port: ${r.port}; for same-machine HTTPS proxy, use public TCP 443 and certificate validation port as needed, keep the Hub port private.`]:[],`Use a separate Hub data directory and configure automatic startup. Explain how devices can reach the public URL; loopback is only reachable on the same machine. Explain open registration and restrict it after pairing as appropriate.`,`CLI reference: ${se}`,`Confirm the target environment and propose steps before deployment. Do not ask for passwords or tokens in chat. Do not automatically SSH. Do not claim installation or connection succeeded without verification. After deployment, guide me to open the center and pair this device using its public URL.`,`Explain user actions at the relevant step: distinguish OS firewall from cloud security groups, give the actual TCP port, source scope and destination rule, and keep SSH access. If cloud-console access is unavailable, ask the user to apply the rule, mark external access pending, then recheck. Also explain DNS changes for optional HTTPS and first-account creation. Separate local health from external reachability.`].join(`
|
|
2
|
+
`)}function L({onConnect:e,initialHubUrl:t=``}){let n=l(),[i,o]=(0,T.useState)(t),[s,c]=(0,T.useState)(``),[ee,u]=(0,T.useState)(!1),[d,te]=(0,T.useState)(!1),f=(0,T.useRef)(!1),ne=(0,T.useRef)(!1);(0,T.useEffect)(()=>(ne.current=!0,()=>{ne.current=!1}),[]);let[p,m]=(0,T.useState)(null),[h,g]=(0,T.useState)(`current`),[_,v]=(0,T.useState)(null),[y,re]=(0,T.useState)(`127.0.0.1`),[b,x]=(0,T.useState)(`8790`),[S,ie]=(0,T.useState)(`http://127.0.0.1:8790`),[C,w]=(0,T.useState)({server:``,sshPort:22,username:`root`,auth:`password`,port:8790,domain:``,https:!1}),ae=F(C),[E,O]=(0,T.useState)(!1),[k,M]=(0,T.useState)(!1),[N,P]=(0,T.useState)(null),[se,L]=(0,T.useState)(!1),[R,ce]=(0,T.useState)(!1),[z,B]=(0,T.useState)(!1),[V,H]=(0,T.useState)(null),U=(0,T.useRef)(null),W=(0,T.useRef)(!1),G=oe(window.location.origin);(0,T.useEffect)(()=>()=>U.current?.abort(),[]);let K=async()=>{if(W.current)return;U.current?.abort();let e=new AbortController;U.current=e,L(!1),ce(!1),B(!1);try{let t=await fetch(r(a(`/api/device-center/setup`)),{credentials:`same-origin`,signal:e.signal});if(!t.ok)throw Error();let n=await t.json();if(!n||typeof n.platform!=`string`||typeof n.nodeVersion!=`string`||typeof n.dataDir!=`string`||typeof n.cliPath!=`string`||!j({host:`127.0.0.1`,port:n.defaultPort,publicUrl:n.defaultPublicUrl}))throw Error();if(e.signal.aborted)return;v(n),n.installation?.installed?(re(n.installation.host??`127.0.0.1`),x(String(n.installation.port)),ie(n.installation.publicUrl??``),o(n.installation.publicUrl??``)):_||(x(String(n.defaultPort)),ie(n.defaultPublicUrl))}catch{e.signal.aborted||(L(!0),B(!0))}finally{e.signal.aborted||ce(!0)}},q=async()=>{let e={host:y,port:Number(b),publicUrl:S};if(W.current||!G||!_||!R||z||_.busy||_.installation?.installed||!j(e))return;W.current=!0,U.current?.abort(),O(!0),L(!1),c(``);let t=new AbortController;U.current=t;try{let n=await fetch(r(a(`/api/device-center/setup`)),{credentials:`same-origin`,method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({...e,allowRegistration:!0}),signal:t.signal});if(n.status===409){v(e=>e&&{...e,busy:!0}),W.current=!1,O(!1),await K();return}if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(typeof e.error==`string`?e.error.slice(0,4096):`HTTP ${n.status}`)}let i=await n.json();if(!j({...e,publicUrl:i.publicUrl})||typeof i.output!=`string`)throw Error();t.signal.aborted||H(i)}catch(e){t.signal.aborted||(L(!0),c(e instanceof Error?e.message.slice(0,4096):``))}finally{W.current=!1,t.signal.aborted||O(!1)}},le=async()=>{if(W.current||!G||!_||!R||z||_.busy||E||k)return;W.current=!0,U.current?.abort(),M(!0),L(!1),c(``),P(null);let e=new AbortController;U.current=e;try{let t=await fetch(r(a(`/api/device-center/setup/update`)),{credentials:`same-origin`,method:`POST`,headers:{"Content-Type":`application/json`},signal:e.signal});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(typeof e.error==`string`?e.error.slice(0,4096):`HTTP ${t.status}`)}let i=await t.json();e.signal.aborted||(P(i.output||n(`deviceSetupUpdateSuccess`)),await K())}catch(t){e.signal.aborted||(L(!0),c(t instanceof Error?t.message.slice(0,4096):``))}finally{W.current=!1,e.signal.aborted||M(!1)}},J=_?.installation,ue=!!J?.installed,de=ue&&J.running&&J.owned,Y=h===`remote`?ae:{host:y,port:Number(b),publicUrl:S},X=!!Y&&j(Y);return(0,D.jsxs)(`section`,{className:`dc-onboarding`,children:[(0,D.jsx)(`h3`,{children:n(`deviceSetupWelcome`)}),(0,D.jsx)(`p`,{children:n(`deviceSetupIntro`)}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[(0,D.jsx)(`button`,{className:`dc-button`,disabled:E,"aria-pressed":p===`connect`,onClick:()=>m(`connect`),children:n(`deviceSetupConnect`)}),(0,D.jsx)(`button`,{className:`dc-button`,disabled:E,"aria-pressed":p===`create`,onClick:()=>{m(`create`),!_&&G&&K()},children:n(`deviceSetupCreate`)})]}),p===`connect`&&(0,D.jsxs)(`form`,{onSubmit:t=>{t.preventDefault(),e(i.trim())},children:[(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceHubHubUrl`)}),(0,D.jsx)(`input`,{type:`url`,required:!0,maxLength:2048,value:i,onChange:e=>o(e.target.value),placeholder:`https://hub.example.com`})]}),(0,D.jsx)(`button`,{className:`dc-button is-primary`,disabled:!j({host:`localhost`,port:8790,publicUrl:i.trim()}),children:n(`deviceSetupPair`)})]}),p===`create`&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupTarget`)}),(0,D.jsxs)(`select`,{disabled:E,value:h,onChange:e=>g(e.target.value),children:[(0,D.jsx)(`option`,{value:`current`,children:n(`deviceSetupCurrent`)}),(0,D.jsx)(`option`,{value:`remote`,children:n(`deviceSetupRemote`)})]})]}),(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`p`,{children:n(h===`current`?`deviceSetupCurrentHint`:`deviceSetupRemoteHint`)}),h===`current`&&(0,D.jsxs)(`div`,{className:`dc-setup-plan`,children:[(0,D.jsx)(`strong`,{children:n(`deviceSetupPlan`)}),(0,D.jsx)(`p`,{children:n(`deviceSetupPlanHint`)}),_&&(0,D.jsxs)(`dl`,{children:[(0,D.jsx)(`dt`,{children:n(`deviceSetupEnvironment`)}),(0,D.jsxs)(`dd`,{children:[_.platform,` · Node `,_.nodeVersion]}),(0,D.jsx)(`dt`,{children:n(`deviceSetupDataDir`)}),(0,D.jsx)(`dd`,{children:_.dataDir}),(0,D.jsx)(`dt`,{children:n(`deviceSetupCli`)}),(0,D.jsx)(`dd`,{children:_.cliPath})]}),!G&&(0,D.jsx)(`p`,{role:`status`,children:n(`deviceSetupLocalOnly`)}),(0,D.jsx)(`p`,{children:n(`deviceSetupBackground`)}),ue&&(0,D.jsxs)(`div`,{role:`status`,children:[(0,D.jsx)(`h4`,{children:n(de?`deviceSetupRestored`:`deviceSetupUnhealthy`)}),(0,D.jsx)(`p`,{children:J.publicUrl}),de&&X&&J.publicUrl?(0,D.jsxs)(`div`,{className:`dc-actions`,children:[(0,D.jsx)(A,{href:J.publicUrl,children:n(`deviceHubOpenHub`)}),(0,D.jsx)(`button`,{className:`dc-button`,onClick:()=>e(J.publicUrl),children:n(`deviceSetupPair`)}),G&&(0,D.jsx)(`button`,{className:`dc-button`,disabled:E||k,onClick:()=>void le(),children:n(k?`deviceSetupUpdating`:`deviceSetupUpdate`)})]}):(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`p`,{children:n(`deviceSetupRecovery`)}),(0,D.jsx)(`pre`,{className:`dc-setup-output`,children:`pi-web-ui hub status --json
|
|
3
|
+
pi-web-ui hub --help`}),G&&(0,D.jsx)(`button`,{className:`dc-button is-primary`,disabled:E||k,onClick:()=>void le(),children:n(k?`deviceSetupUpdating`:`deviceSetupUpdate`)})]}),N&&(0,D.jsx)(`pre`,{className:`dc-setup-output`,children:N.slice(0,16e3)})]}),_?.busy&&(0,D.jsx)(`p`,{role:`status`,children:n(`deviceSetupBusy`)}),G&&(0,D.jsx)(`button`,{className:`dc-button`,disabled:E||!R,onClick:()=>void K(),children:n(R?`deviceSetupRetry`:`deviceHubWorking`)})]}),h===`remote`?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`div`,{className:`dc-setup-fields`,children:[(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupServer`)}),(0,D.jsx)(`input`,{autoComplete:`off`,maxLength:253,placeholder:`203.0.113.10`,value:C.server,onChange:e=>w({...C,server:e.target.value.trim()})})]}),(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupSshPort`)}),(0,D.jsx)(`input`,{type:`number`,min:1,max:65535,value:C.sshPort,onChange:e=>w({...C,sshPort:Number(e.target.value)})})]}),(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupUsername`)}),(0,D.jsx)(`input`,{autoComplete:`off`,maxLength:64,value:C.username,onChange:e=>w({...C,username:e.target.value})})]}),(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupAuth`)}),(0,D.jsxs)(`select`,{value:C.auth,onChange:e=>w({...C,auth:e.target.value}),children:[(0,D.jsx)(`option`,{value:`password`,children:n(`deviceSetupAuthPassword`)}),(0,D.jsx)(`option`,{value:`key`,children:n(`deviceSetupAuthKey`)}),(0,D.jsx)(`option`,{value:`existing`,children:n(`deviceSetupAuthExisting`)})]})]}),(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupServicePort`)}),(0,D.jsx)(`input`,{type:`number`,min:1024,max:65535,value:C.port,onChange:e=>w({...C,port:Number(e.target.value)})})]})]}),(0,D.jsx)(`p`,{children:n(`deviceSetupCredentialHint`)}),(0,D.jsxs)(`details`,{children:[(0,D.jsx)(`summary`,{children:n(`deviceSetupOptionalTls`)}),(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupDomain`)}),(0,D.jsx)(`input`,{maxLength:253,placeholder:`hub.example.com`,value:C.domain,onChange:e=>w({...C,domain:e.target.value.trim()})})]}),(0,D.jsxs)(`label`,{children:[(0,D.jsx)(`input`,{type:`checkbox`,checked:C.https,onChange:e=>w({...C,https:e.target.checked})}),` `,n(`deviceSetupEnableHttps`)]}),(0,D.jsx)(`p`,{children:n(`deviceSetupTlsHint`)})]}),(0,D.jsxs)(`p`,{children:[(0,D.jsx)(`strong`,{children:n(`deviceSetupPreview`)}),` `,ae?.publicUrl??n(`deviceSetupPreviewEmpty`)]}),(0,D.jsxs)(`div`,{className:`dc-setup-plan`,children:[(0,D.jsx)(`strong`,{children:n(`deviceSetupUserActions`)}),(0,D.jsx)(`p`,{children:n(`deviceSetupCloudPorts`).replace(`{ports}`,C.https?`443 / 80`:String(C.port))}),(0,D.jsx)(`p`,{children:n(`deviceSetupSourceScope`)}),(0,D.jsx)(`p`,{children:n(`deviceSetupAfterStart`)})]}),(0,D.jsx)(`a`,{href:`https://github.com/xing-shuyin/pi-web-ui/blob/main/docs/device-center-deployment.md`,target:`_blank`,rel:`noopener noreferrer`,children:n(`deviceSetupGuide`)})]}):(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`div`,{className:`dc-setup-fields`,children:[(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupHost`)}),(0,D.jsx)(`input`,{disabled:E||!!V,maxLength:253,value:y,onChange:e=>re(e.target.value)})]}),(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupPort`)}),(0,D.jsx)(`input`,{disabled:E||!!V,type:`number`,min:1024,max:65535,value:b,onChange:e=>x(e.target.value)})]}),(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceHubHubUrl`)}),(0,D.jsx)(`input`,{disabled:E||!!V,maxLength:2048,value:S,onChange:e=>ie(e.target.value)})]})]}),(0,D.jsx)(`p`,{className:`dc-setup-warning`,children:n(`deviceSetupReachable`)})]}),(0,D.jsx)(`p`,{children:n(`deviceSetupRegistration`)}),!X&&(0,D.jsx)(`p`,{role:`alert`,children:n(h===`remote`?`deviceSetupRemoteInvalid`:`deviceSetupInvalid`)}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[h===`current`&&!V&&!ue&&(0,D.jsx)(`button`,{className:`dc-button is-primary`,disabled:E||!G||!_||!R||z||!!_.busy||!X,onClick:()=>void q(),children:n(E?`deviceSetupInstalling`:`deviceSetupInstall`)}),(0,D.jsx)(`button`,{className:`dc-button`,disabled:E||ee||!X,onClick:()=>{if(!X||!Y||f.current)return;f.current=!0,u(!0),te(!1);let e=e=>{f.current=!1,ne.current&&(u(!1),te(!e))},t=window.__piWebUiHost;try{t?.startChat({newChat:!0,prompt:I(Y,_,h,h===`remote`?C:void 0),onResult:e})||e(!1)}catch{e(!1)}},children:n(h===`remote`?`deviceSetupStartAi`:`deviceSetupAi`)})]}),(0,D.jsx)(`p`,{children:n(`deviceSetupAiHint`)}),ee&&(0,D.jsx)(`p`,{role:`status`,children:n(`deviceSetupAiCreating`)}),d&&(0,D.jsx)(`p`,{role:`alert`,children:n(`deviceSetupAiFailed`)})]})]}),se&&(0,D.jsxs)(`div`,{role:`alert`,children:[(0,D.jsx)(`p`,{children:n(`deviceSetupFailed`)}),s&&(0,D.jsx)(`pre`,{className:`dc-setup-output`,children:s})]}),V&&(0,D.jsxs)(`div`,{role:`status`,children:[(0,D.jsx)(`h4`,{children:n(`deviceSetupSuccess`)}),(0,D.jsx)(`pre`,{className:`dc-setup-output`,children:V.output.slice(0,16e3)}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[(0,D.jsx)(A,{href:V.publicUrl,children:n(`deviceHubOpenHub`)}),(0,D.jsx)(`button`,{className:`dc-button is-primary`,onClick:()=>e(V.publicUrl),children:n(`deviceSetupPair`)})]})]})]})}var R=`pi-web-ui:device-groups-changed`;function ce(e){window.dispatchEvent(new CustomEvent(`pi-web-ui:device-group-open`,{detail:{roomId:e}}))}async function z(e,t,n){let i=await fetch(r(a(`/api/device-center/${e}`)),{method:n?`POST`:`GET`,credentials:`same-origin`,signal:t,...n?{headers:{"Content-Type":`application/json`},body:JSON.stringify(n)}:{}}),o=await i.json().catch(()=>({}));if(!i.ok)throw Error(o.error||o.message||`Request failed (${i.status})`);return o}function B({bindingKey:e=``}){return(0,D.jsx)(V,{},e)}function V(){let{locale:e}=i(),t=ne(e),[r,a]=(0,T.useState)([]),[o,c]=(0,T.useState)([]),[ee,l]=(0,T.useState)(!0),[te,h]=(0,T.useState)(``),[_,v]=(0,T.useState)(``),[y,re]=(0,T.useState)(0),[b,x]=(0,T.useState)(!1),[S,ie]=(0,T.useState)(``),[C,E]=(0,T.useState)([]),[O,k]=(0,T.useState)(``),[A,j]=(0,T.useState)(null),[M,oe]=(0,T.useState)([]),[N,P]=(0,T.useState)(``),[se,F]=(0,T.useState)(null),[I,L]=(0,T.useState)(``),[B,V]=(0,T.useState)(!1),[H,U]=(0,T.useState)(null),W=r.find(e=>e.id===H?.roomId),G=(0,T.useRef)(0),K=(0,T.useRef)(null),q=(0,T.useRef)(null);function le(){++G.current,K.current?.abort(),re(e=>e+1)}function J(){q.current?.abort();let e=new AbortController;return q.current=e,e}(0,T.useEffect)(()=>()=>q.current?.abort(),[]),(0,T.useEffect)(()=>{let e=++G.current,t=new AbortController;K.current=t;async function n(){try{let[n,r]=await Promise.all([z(`rooms`,t.signal),z(`bots`,t.signal)]);if(G.current!==e||t.signal.aborted)return;let i=Array.isArray(n.rooms)?n.rooms:[];a(i),U(e=>e&&i.some(t=>t.id===e.roomId)?e:null),c(Array.isArray(r.bots)?r.bots:[]),h(``)}catch(n){G.current===e&&!t.signal.aborted&&h(n instanceof Error?n.message:String(n))}finally{G.current===e&&!t.signal.aborted&&l(!1)}}return n(),()=>{t.abort()}},[y]),(0,T.useEffect)(()=>{let e=()=>le();return window.addEventListener(R,e),()=>window.removeEventListener(R,e)},[]);async function ue(e){if(e.preventDefault(),!S.trim()||B)return;V(!0),h(``),v(``);let n=J();try{let e=C.includes(O)?O:``,r=await z(`rooms`,n.signal,{name:S.trim(),botIds:C,...e?{primaryBotId:e}:{}});if(n.signal.aborted)return;a(e=>[...e.filter(e=>e.id!==r.room.id),r.room]),x(!1),ie(``),E([]),k(``),v(t?`群聊创建成功`:`Group created successfully`),window.dispatchEvent(new CustomEvent(R))}catch(e){n.signal.aborted||h(e instanceof Error?e.message:String(e))}finally{n.signal.aborted||V(!1)}}function de(e){j(e.id),oe([...e.botIds]),P(e.primaryBotId??``),F(null),x(!1),h(``),v(``)}async function Y(e){if(B)return;V(!0),h(``),v(``);let n=J();try{let r=M.includes(N)?N:null,i=await z(`rooms/${encodeURIComponent(e)}/members`,n.signal,{botIds:M,primaryBotId:r});if(n.signal.aborted)return;a(t=>t.map(t=>t.id===e?i.room:t)),j(null),v(t?`成员设置已保存`:`Members updated successfully`),window.dispatchEvent(new CustomEvent(R))}catch(e){n.signal.aborted||h(e instanceof Error?e.message:String(e))}finally{n.signal.aborted||V(!1)}}async function X(e){if(!I.trim()||B)return;V(!0),h(``),v(``);let n=J();try{if(await z(`rooms/${encodeURIComponent(e)}/rename`,n.signal,{name:I.trim()}),n.signal.aborted)return;a(t=>t.map(t=>t.id===e?{...t,name:I.trim()}:t)),F(null),v(t?`群聊名称已更新`:`Group renamed successfully`),window.dispatchEvent(new CustomEvent(R))}catch(e){n.signal.aborted||h(e instanceof Error?e.message:String(e))}finally{n.signal.aborted||V(!1)}}async function Z(e){if(B||!window.confirm(t?`确定删除群聊“${e.name}”?`:`Are you sure you want to delete "${e.name}"?`))return;V(!0),h(``),v(``);let n=J();try{if(await z(`rooms/${encodeURIComponent(e.id)}/delete`,n.signal,{}),n.signal.aborted)return;U(t=>t?.roomId===e.id?null:t),a(t=>t.filter(t=>t.id!==e.id)),A===e.id&&j(null),se===e.id&&F(null),v(t?`群聊已删除`:`Group deleted successfully`),window.dispatchEvent(new CustomEvent(R))}catch(e){n.signal.aborted||h(e instanceof Error?e.message:String(e))}finally{n.signal.aborted||V(!1)}}return(0,D.jsxs)(`section`,{className:`dc-card`,"aria-label":t?`群聊列表`:`Group list`,children:[(0,D.jsxs)(`div`,{className:`dc-card-header`,children:[(0,D.jsx)(`span`,{className:`dc-icon`,children:(0,D.jsx)(m,{"aria-hidden":!0})}),(0,D.jsxs)(`div`,{children:[(0,D.jsxs)(`h2`,{children:[t?`群聊列表`:`Group List`,` · `,r.length]}),(0,D.jsx)(`p`,{children:t?`管理群聊与成员 Bot,在此配置协作群组或直接进入聊天。`:`Manage groups and member Bots. Configure collaboration groups or open chats here.`})]}),(0,D.jsxs)(`div`,{className:`dc-actions`,style:{marginInlineStart:`auto`},children:[(0,D.jsxs)(`button`,{type:`button`,className:`dc-button is-primary`,disabled:B,onClick:()=>{x(e=>!e),j(null),F(null),ie(``),E([]),k(``)},children:[(0,D.jsx)(s,{"aria-hidden":!0}),t?`新建群聊`:`Create Group`]}),(0,D.jsx)(`button`,{type:`button`,className:`dc-icon-button`,"aria-label":t?`刷新群聊`:`Refresh groups`,onClick:le,children:(0,D.jsx)(u,{})})]})]}),te&&(0,D.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:te}),_&&(0,D.jsxs)(`p`,{className:`dc-notice is-success`,role:`status`,children:[(0,D.jsx)(n,{"aria-hidden":!0}),_]}),b&&(0,D.jsxs)(`form`,{className:`dc-card`,style:{marginBottom:`16px`,background:`var(--bg)`,border:`1px solid var(--border)`},onSubmit:ue,children:[(0,D.jsxs)(`div`,{className:`dg-heading`,style:{marginBottom:`12px`},children:[(0,D.jsx)(`h3`,{children:t?`新建群聊`:`Create Group`}),(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>x(!1),disabled:B,children:[(0,D.jsx)(f,{"aria-hidden":!0}),t?`关闭`:`Close`]})]}),(0,D.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`12px`},children:[(0,D.jsx)(`label`,{htmlFor:`dg-manager-new-name`,children:t?`群名称`:`Group Name`}),(0,D.jsx)(`input`,{id:`dg-manager-new-name`,type:`text`,required:!0,maxLength:80,value:S,placeholder:t?`输入群名称,如:研发协作群`:`Enter group name`,onChange:e=>ie(e.target.value),disabled:B,style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`}})]}),(0,D.jsxs)(`div`,{style:{marginBottom:`12px`},children:[(0,D.jsx)(`label`,{style:{display:`block`,marginBottom:`6px`,fontSize:`12px`,color:`var(--text-dim)`},children:t?`选择成员 Bot`:`Select Member Bots`}),(0,D.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`6px`,maxHeight:`160px`,overflowY:`auto`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`8px`,background:`var(--bg-elev)`},children:o.length===0?(0,D.jsx)(`p`,{style:{margin:0,fontSize:`12px`,color:`var(--text-faint)`},children:t?`暂无可用 Bot,请先创建 Bot。`:`No Bots available. Please create a Bot first.`}):o.map(e=>(0,D.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,cursor:`pointer`,fontSize:`12px`},children:[(0,D.jsx)(`input`,{type:`checkbox`,checked:C.includes(e.id),disabled:B||!e.enabled,onChange:t=>{E(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}}),(0,D.jsxs)(`span`,{children:[(0,D.jsx)(`strong`,{children:e.name}),(0,D.jsxs)(`small`,{style:{color:`var(--text-faint)`,marginInlineStart:`6px`},children:[e.online?t?`在线`:`Online`:t?`离线`:`Offline`,e.enabled?``:t?` · 已禁用`:` · Disabled`]})]})]},e.id))})]}),C.length>0&&(0,D.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`16px`},children:[(0,D.jsx)(`label`,{htmlFor:`dg-manager-new-primary`,children:t?`原主 Bot(Router 未启用时)`:`Legacy primary Bot (when Router is disabled)`}),(0,D.jsxs)(`select`,{id:`dg-manager-new-primary`,value:C.includes(O)?O:``,onChange:e=>k(e.target.value),disabled:B,style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`},children:[(0,D.jsx)(`option`,{value:``,children:t?`不设置(需 @ Bot)`:`None (mention a Bot)`}),o.filter(e=>C.includes(e.id)).map(e=>(0,D.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[(0,D.jsxs)(`button`,{type:`submit`,className:`dc-button is-primary`,disabled:B||!S.trim(),children:[(0,D.jsx)(n,{"aria-hidden":!0}),B?t?`创建中…`:`Creating…`:t?`创建群聊`:`Create`]}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>x(!1),disabled:B,children:t?`取消`:`Cancel`})]})]}),A&&(0,D.jsxs)(`div`,{className:`dc-card`,style:{marginBottom:`16px`,background:`var(--bg)`,border:`1px solid var(--border)`},children:[(0,D.jsxs)(`div`,{className:`dg-heading`,style:{marginBottom:`12px`},children:[(0,D.jsxs)(`h3`,{children:[t?`管理成员`:`Manage Members`,` · `,r.find(e=>e.id===A)?.name]}),(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>j(null),disabled:B,children:[(0,D.jsx)(f,{"aria-hidden":!0}),t?`关闭`:`Close`]})]}),(0,D.jsxs)(`div`,{style:{marginBottom:`12px`},children:[(0,D.jsx)(`label`,{style:{display:`block`,marginBottom:`6px`,fontSize:`12px`,color:`var(--text-dim)`},children:t?`选择成员 Bot`:`Select Member Bots`}),(0,D.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`6px`,maxHeight:`160px`,overflowY:`auto`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`8px`,background:`var(--bg-elev)`},children:o.length===0?(0,D.jsx)(`p`,{style:{margin:0,fontSize:`12px`,color:`var(--text-faint)`},children:t?`暂无可用 Bot`:`No Bots available`}):o.map(e=>(0,D.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,cursor:`pointer`,fontSize:`12px`},children:[(0,D.jsx)(`input`,{type:`checkbox`,checked:M.includes(e.id),disabled:B,onChange:t=>{oe(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}}),(0,D.jsxs)(`span`,{children:[(0,D.jsx)(`strong`,{children:e.name}),(0,D.jsxs)(`small`,{style:{color:`var(--text-faint)`,marginInlineStart:`6px`},children:[e.online?t?`在线`:`Online`:t?`离线`:`Offline`,e.enabled?``:t?` · 已禁用`:` · Disabled`]})]})]},e.id))})]}),!r.find(e=>e.id===A)?.router?.enabled&&(0,D.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`16px`},children:[(0,D.jsx)(`label`,{htmlFor:`dg-manager-edit-primary`,children:t?`原主 Bot(Router 未启用时)`:`Legacy primary Bot (when Router is disabled)`}),(0,D.jsxs)(`select`,{id:`dg-manager-edit-primary`,value:M.includes(N)?N:``,onChange:e=>P(e.target.value),disabled:B,style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`},children:[(0,D.jsx)(`option`,{value:``,children:t?`不设置(需 @ Bot)`:`None (mention a Bot)`}),o.filter(e=>M.includes(e.id)).map(e=>(0,D.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[(0,D.jsxs)(`button`,{type:`button`,className:`dc-button is-primary`,disabled:B,onClick:()=>void Y(A),children:[(0,D.jsx)(n,{"aria-hidden":!0}),B?t?`保存中…`:`Saving…`:t?`保存成员设置`:`Save Members`]}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>j(null),disabled:B,children:t?`取消`:`Cancel`})]})]}),ee&&(0,D.jsx)(`p`,{role:`status`,children:t?`加载中…`:`Loading…`}),!ee&&r.length===0&&(0,D.jsx)(`p`,{style:{color:`var(--text-faint)`,fontSize:`13px`,padding:`12px 0`},children:t?`还没有群聊,点击上方“新建群聊”开始协作。`:`No groups yet. Click 'Create Group' above to get started.`}),(0,D.jsx)(`div`,{className:`dd-list`,children:r.map(e=>{let r=se===e.id,i=o.filter(t=>e.botIds.includes(t.id)),a=o.find(t=>t.id===e.primaryBotId);return(0,D.jsxs)(`div`,{className:`dd-device`,style:r?{flexWrap:`wrap`}:void 0,children:[(0,D.jsx)(`span`,{className:`dc-device-icon`,children:(0,D.jsx)(m,{"aria-hidden":!0})}),(0,D.jsxs)(`div`,{className:`dd-identity`,style:{flex:1,minWidth:`200px`},children:[(0,D.jsx)(`strong`,{children:e.name}),(0,D.jsxs)(`span`,{style:{display:`flex`,gap:`8px`,flexWrap:`wrap`,alignItems:`center`},children:[(0,D.jsx)(`span`,{children:t?`${e.botIds.length} 个 Bot${i.length?`: ${i.map(e=>e.name).join(`, `)}`:``}`:`${e.botIds.length} Bots${i.length?`: ${i.map(e=>e.name).join(`, `)}`:``}`}),e.router?.enabled&&(0,D.jsxs)(`span`,{children:[`AI Router · `,e.router.deviceId,` · `,e.router.model,` · `,e.router.thinkingLevel]}),!e.router?.enabled&&a&&(0,D.jsx)(`span`,{style:{color:`var(--accent)`},children:t?`[主 Bot: ${a.name}]`:`[Primary: ${a.name}]`})]})]}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[(0,D.jsxs)(`button`,{type:`button`,className:`dc-button is-primary`,title:t?`打开聊天`:`Open chat`,onClick:()=>ce(e.id),children:[(0,D.jsx)(p,{"aria-hidden":!0}),t?`打开聊天`:`Open chat`]}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button`,"aria-expanded":H?.roomId===e.id&&H.kind===`router`,onClick:()=>U({roomId:e.id,kind:`router`}),children:`AI Router`}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button`,"aria-expanded":H?.roomId===e.id&&H.kind===`work`,onClick:()=>U({roomId:e.id,kind:`work`}),children:t?`工单与运行`:`Work items & runs`}),(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,title:t?`管理成员`:`Manage members`,onClick:()=>de(e),children:[(0,D.jsx)(m,{"aria-hidden":!0}),t?`管理成员`:`Members`]}),(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,title:t?`重命名`:`Rename`,onClick:()=>{r?F(null):(F(e.id),L(e.name))},children:[(0,D.jsx)(d,{"aria-hidden":!0}),t?`重命名`:`Rename`]}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button is-danger`,title:t?`删除群聊`:`Delete group`,disabled:B,onClick:()=>void Z(e),children:(0,D.jsx)(g,{"aria-hidden":!0})})]}),r&&(0,D.jsxs)(`form`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,width:`100%`,paddingTop:`8px`,paddingBottom:`4px`},onSubmit:t=>{t.preventDefault(),X(e.id)},children:[(0,D.jsx)(`input`,{type:`text`,maxLength:80,autoFocus:!0,disabled:B,value:I,onChange:e=>L(e.target.value),placeholder:t?`输入新群名称`:`Enter new name`,style:{flex:1,minWidth:`180px`,background:`var(--bg)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`12px`}}),(0,D.jsxs)(`button`,{type:`submit`,className:`dc-button is-primary`,disabled:B||!I.trim(),children:[(0,D.jsx)(n,{"aria-hidden":!0}),t?`保存`:`Save`]}),(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:B,onClick:()=>F(null),children:[(0,D.jsx)(f,{"aria-hidden":!0}),t?`取消`:`Cancel`]})]})]},e.id)})}),W&&H&&(0,D.jsxs)(`section`,{className:`dc-card`,"aria-label":t?`群组设置`:`Group settings`,children:[(0,D.jsxs)(`div`,{className:`dg-heading`,children:[(0,D.jsx)(`h3`,{children:W.name}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[(0,D.jsx)(`button`,{type:`button`,className:`dc-button${H.kind===`router`?` is-primary`:``}`,"aria-pressed":H.kind===`router`,onClick:()=>U({roomId:W.id,kind:`router`}),children:`AI Router`}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button${H.kind===`work`?` is-primary`:``}`,"aria-pressed":H.kind===`work`,onClick:()=>U({roomId:W.id,kind:`work`}),children:t?`工单与运行`:`Work items & runs`}),(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>U(null),children:[(0,D.jsx)(f,{"aria-hidden":!0}),t?`关闭`:`Close`]})]})]}),H.kind===`router`?(0,D.jsx)(w,{roomId:W.id,router:W.router,disabled:B,onSaved:le},W.id):(0,D.jsx)(ae,{roomId:W.id,disabled:B},W.id)]})]})}var H=class extends Error{status;constructor(e,t){super(t),this.status=e}};function U(e){try{let t=new URL(e);return[`http:`,`https:`].includes(t.protocol)&&!t.username&&!t.password?t.href:null}catch{return null}}function W(){let e=l(),t=_().startsWith(`zh`),[n,i]=(0,T.useState)(null),[o,s]=(0,T.useState)(!1),[ee,d]=(0,T.useState)(!1),[te,f]=(0,T.useState)(!1),[ne,p]=(0,T.useState)(!1),m=(0,T.useRef)(0),h=(0,T.useRef)(null);async function g(e,t){if(h.current)return;let n=++m.current,o=new AbortController;h.current=o,s(!0),d(!1);try{let s=await fetch(r(a(`/api/device-desktop/local/${e}`)),{method:t?`POST`:`GET`,credentials:`same-origin`,signal:o.signal,...t?{headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}:{}});if(m.current!==n||o.signal.aborted)return;if(s.status===403){f(!0),i(null);return}if(!s.ok)throw Error(`Request failed`);let c=await s.json();if(m.current!==n||o.signal.aborted)return;if(e===`permissions`){if(typeof c?.screen!=`boolean`||typeof c?.accessibility!=`boolean`)throw Error(`Invalid permission status`);i(e=>e&&{...e,permissions:{supported:!0,screen:c.screen,accessibility:c.accessibility}}),p(!0)}else{if(typeof c?.os!=`string`||typeof c.enabled!=`boolean`||typeof c.environmentEnabled!=`boolean`||typeof c.supported!=`boolean`)throw Error(`Invalid desktop status`);i(c)}}catch{m.current===n&&!o.signal.aborted&&d(!0)}finally{m.current===n&&!o.signal.aborted&&(h.current=null,s(!1))}}return(0,T.useEffect)(()=>(g(`status`),()=>{m.current++,h.current?.abort(),h.current=null}),[]),(0,D.jsxs)(`section`,{className:`dc-card`,"aria-label":t?`本机远程桌面`:`Local remote desktop`,"aria-busy":o,children:[(0,D.jsxs)(`div`,{className:`dc-card-header`,children:[(0,D.jsx)(`span`,{className:`dc-icon`,children:(0,D.jsx)(c,{"aria-hidden":!0})}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h2`,{children:t?`本机远程桌面`:`Local remote desktop`}),(0,D.jsx)(`p`,{children:t?`管理这台设备的远程桌面与系统权限,无需连接设备中心。`:`Manage remote desktop and system permissions on this device, even while the device center is offline.`})]})]}),te?(0,D.jsx)(`p`,{role:`status`,children:t?`请在设备本机打开此页面以管理远程桌面权限。`:`Open this page on the device itself to manage remote desktop permissions.`}):(0,D.jsxs)(D.Fragment,{children:[n&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`div`,{className:`dc-permission-row`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h3`,{id:`dc-desktop-label`,children:t?`启用远程桌面`:`Enable remote desktop`}),(0,D.jsx)(`p`,{children:n.enabled?t?`已启用`:`Enabled`:t?`未启用`:`Disabled`})]}),(0,D.jsx)(`button`,{type:`button`,className:`dc-toggle${n.enabled?` is-on`:``}`,role:`switch`,"aria-checked":n.enabled,"aria-labelledby":`dc-desktop-label`,disabled:o||n.environmentEnabled||!n.supported&&!n.enabled,onClick:()=>void g(`enable`,{enabled:!n.enabled}),children:(0,D.jsx)(`span`,{className:`dc-toggle-thumb`})})]}),!n.supported&&(0,D.jsx)(`p`,{children:t?`这台设备暂不支持远程桌面。`:`Remote desktop is currently unavailable on this device.`}),n.environmentEnabled&&(0,D.jsx)(`p`,{children:t?`远程桌面由本机服务设置保持启用。`:`Remote desktop is kept enabled by the service settings on this device.`}),n.os===`darwin`&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`p`,{children:t?`点击下方按钮发起系统授权,请在这台 Mac 的系统设置中确认。授权后可能需要重启服务。`:`Use the buttons below to request system permission, then confirm in System Settings on this Mac. You may need to restart the service afterward.`}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[(0,D.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:o||n.permissions?.supported===!1,onClick:()=>void g(`permissions`,{kind:`screen`}),children:t?`授予屏幕录制权限`:`Grant screen recording permission`}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:o||n.permissions?.supported===!1,onClick:()=>void g(`permissions`,{kind:`control`}),children:t?`授予远程控制权限`:`Grant remote control permission`})]}),n.permissions?.screen===!0&&(0,D.jsx)(`p`,{children:t?`屏幕录制:已授权`:`Screen recording: granted`}),n.permissions?.accessibility===!0&&(0,D.jsx)(`p`,{children:t?`远程控制:已授权`:`Remote control: granted`}),ne&&(0,D.jsx)(`p`,{role:`status`,children:t?`已发起授权请求,请确认系统设置后刷新状态。`:`Permission requested. Confirm in System Settings, then refresh the status.`})]})]}),ee&&(0,D.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:t?`无法更新本机远程桌面设置,请重试。`:`Unable to update local remote desktop settings. Please retry.`}),(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:o,onClick:()=>void g(`status`),children:[(0,D.jsx)(u,{"aria-hidden":!0}),o?e(`deviceHubWorking`):t?`刷新远程桌面状态`:`Refresh remote desktop status`]})]})]})}function G({pathCompletions:e=[],plugins:i=[],pluginsEpoch:s=0}){let d=l(),f=ne(_()),[p,g]=(0,T.useState)(`devices`),[y,re]=(0,T.useState)(null),[b,x]=(0,T.useState)(``),[w,ae]=(0,T.useState)(``),[O,j]=(0,T.useState)(null),[M,oe]=(0,T.useState)(Date.now()),[N,P]=(0,T.useState)(null),[se,F]=(0,T.useState)(``),[I,R]=(0,T.useState)(``),[ce,z]=(0,T.useState)(``),[V,G]=(0,T.useState)(!1),K=(0,T.useRef)(!1),[q,le]=(0,T.useState)(!1),[J,ue]=(0,T.useState)(!0),de=(0,T.useRef)(!1),Y=(0,T.useRef)(0),X=(0,T.useRef)(new Set),Z=(0,T.useRef)(!1),fe=(0,T.useRef)(!1),pe=(0,T.useRef)(null),me=(0,T.useRef)(d);me.current=d,(0,T.useEffect)(()=>{let e=e=>{let t=e;t.detail?.deviceId&&pe.current?.deviceId===t.detail.deviceId&&(re(e=>e&&{...e,remark:t.detail.remark}),pe.current&&(pe.current.remark=t.detail.remark))};return window.addEventListener(`pi-web-ui:device-remark-updated`,e),()=>window.removeEventListener(`pi-web-ui:device-remark-updated`,e)},[]);async function he(e,t){let n=new AbortController;X.current.add(n);try{let i=await fetch(r(a(`/api/device-center/${e}`)),{method:t?`POST`:`GET`,credentials:`same-origin`,signal:n.signal,...t?{headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}:{}}),o=await i.json().catch(()=>({}));if(!i.ok)throw new H(i.status,typeof o.error==`string`?o.error:me.current(`deviceHubRequestFailed`,{status:i.status}));return o}finally{X.current.delete(n)}}function Q(e){return de.current&&Y.current===e}function ge(e){return e instanceof H&&e.status===403?(le(!0),me.current(`deviceHubLocalOnly`)):e instanceof Error?e.message:me.current(`deviceHubNetworkError`)}function _e(e){pe.current=e,re(e),fe.current||(ae(e.name),x(e.hubUrl??``))}async function ve(){let e=Y.current;try{let t=await he(`status`);if(!Q(e)||Z.current)return;_e(t),R(``),le(!1)}catch(t){Q(e)&&R(ge(t))}finally{Q(e)&&ue(!1)}}(0,T.useEffect)(()=>{de.current=!0;let e=!1,t,n=async()=>{await ve(),!e&&de.current&&(t=setTimeout(n,5e3))};return n(),()=>{e=!0,de.current=!1,Y.current++,clearTimeout(t);for(let e of X.current)e.abort()}},[]),(0,T.useEffect)(()=>{if(!O)return;let e=Y.current,t=!1,n,r=setInterval(()=>oe(Date.now()),1e3),i=async()=>{if(!(t||!Q(e)||Date.now()>=O.expiresAt)){try{let n=await he(`poll`,{});if(t||!Q(e))return;if(n.paired){let n=await he(`status`);if(t||!Q(e))return;fe.current=!1,_e(n),j(null),F(``),z(``);return}F(``)}catch(n){!t&&Q(e)&&F(`${me.current(`deviceHubPollError`)} ${ge(n)}`)}!t&&Q(e)&&(n=setTimeout(i,2e3))}};return n=setTimeout(i,2e3),()=>{t=!0,clearTimeout(n),clearInterval(r)}},[O]);async function ye(){if(Z.current)return;let e=U(b.trim());if(!e){F(d(`deviceHubInvalidUrl`));return}if(!w.trim()||w.trim().length>80){F(d(`deviceHubInvalidName`));return}let t=++Y.current;Z.current=!0,P(`pair`),F(``),z(``),j(null);try{let n=await he(`pair`,{hubUrl:e,name:w.trim()});if(!Q(t))return;if(!n.code||!Number.isFinite(n.expiresAt)||!U(n.hubUrl))throw Error(d(`deviceHubPairError`));oe(Date.now()),j(n)}catch(e){Q(t)&&F(`${d(`deviceHubPairError`)} ${ge(e)}`)}finally{Q(t)&&(Z.current=!1,P(null))}}async function be(){let e=pe.current;if(!e?.deviceId||Z.current)return;let t=++Y.current;Z.current=!0,P(`permission`),F(``),z(``),_e({...e,allowExecution:!e.allowExecution});try{await he(`execution`,{allowExecution:!e.allowExecution}),Q(t)&&z(d(`deviceHubSaved`))}catch(n){Q(t)&&(_e(e),F(`${d(`deviceHubPermissionError`)} ${ge(n)}`))}finally{Q(t)&&(Z.current=!1,P(null))}}async function xe(){let e=pe.current;if(!e?.deviceId||Z.current||!window.confirm(d(`deviceHubDisconnectConfirm`,{name:e.name})))return;let t=++Y.current;Z.current=!0,P(`disconnect`),F(``),z(``);try{if(await he(`disconnect`,{}),!Q(t))return;fe.current=!1,_e({name:e.name,allowExecution:!1,connected:!1}),j(null)}catch(e){Q(t)&&F(`${d(`deviceHubDisconnectError`)} ${ge(e)}`)}finally{Q(t)&&(Z.current=!1,P(null))}}async function Se(){if(K.current||N||!$||!y?.hubUrl||!window.confirm(d(`deviceHubConfirmUpgrade`)))return;let e=Y.current;K.current=!0,G(!0),F(``),z(``);try{let t=await he(`upgrade-hub`,{});if(!t.ok)throw Error(`Hub upgrade was not accepted`);await E(t.job,{isCurrent:()=>Q(e),poll:async e=>(await he(`upgrade-hub-status`,{id:e})).job}),Q(e)&&(z(d(`deviceHubUpgradeSuccess`)),await ve())}catch(t){Q(e)&&F(t instanceof Error?t.message:d(`deviceHubNetworkError`))}finally{K.current=!1,Q(e)&&G(!1)}}async function Ce(){if(!O)return;let e=Y.current;try{await navigator.clipboard.writeText(O.code),Q(e)&&z(d(`deviceHubCopied`))}catch{Q(e)&&F(d(`deviceHubCopyFailed`))}}let $=!!y?.deviceId,we=U($?y?.hubUrl??``:O?.hubUrl??``),Te=Math.max(0,Math.ceil(((O?.expiresAt??0)-M)/1e3)),Ee=`${Math.floor(Te/60)}:${String(Te%60).padStart(2,`0`)}`,De=we?(0,D.jsxs)(A,{href:we,children:[(0,D.jsx)(t,{"aria-hidden":!0}),d(`deviceHubOpenHub`)]}):null;return(0,D.jsxs)(`section`,{className:`dc-page`,"aria-label":d(`deviceHubTitle`),children:[(0,D.jsxs)(`header`,{className:`dc-header`,children:[(0,D.jsxs)(`div`,{className:`dc-heading`,children:[(0,D.jsxs)(`span`,{className:`dc-eyebrow`,children:[(0,D.jsx)(c,{"aria-hidden":!0}),d(`deviceHubTitle`)]}),(0,D.jsx)(`h1`,{children:d(`deviceHubTitle`)}),(0,D.jsx)(`p`,{children:d(`deviceHubSubtitle`)})]}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[$&&De,(0,D.jsxs)(`span`,{className:`dc-status ${$?y?.connected?`is-online`:`is-offline`:`is-unpaired`}`,children:[(0,D.jsx)(`span`,{className:`dc-status-dot`}),d($?y?.connected?`deviceHubOnline`:`deviceHubOffline`:`deviceHubUnpaired`)]})]})]}),(0,D.jsxs)(`div`,{className:`dc-layout`,children:[(0,D.jsx)(`nav`,{className:`dc-sidebar`,"aria-label":f?`设备与协作导航`:`Devices and collaboration`,children:[[`devices`,c,f?`设备与连接`:`Devices & connections`],[`groups`,m,f?`群组与工单`:`Groups & work items`],[`channels`,te,f?`外部渠道`:`External channels`]].map(([e,t,n])=>(0,D.jsxs)(`button`,{type:`button`,className:`dc-nav-item${p===e?` is-active`:``}`,"aria-pressed":p===e,onClick:()=>g(e),children:[(0,D.jsx)(t,{"aria-hidden":!0}),n]},e))}),(0,D.jsxs)(`main`,{className:`dc-content`,children:[J&&(0,D.jsxs)(`div`,{className:`dc-loading`,role:`status`,children:[(0,D.jsx)(u,{"aria-hidden":!0}),d(`deviceHubLoading`)]}),(q||I)&&(0,D.jsxs)(`div`,{className:`dc-notice is-error`,role:`alert`,children:[(0,D.jsx)(`span`,{children:q?d(`deviceHubLocalOnly`):`${d(`deviceHubStatusError`)} ${I}`}),(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>void ve(),children:[(0,D.jsx)(u,{"aria-hidden":!0}),d(`deviceHubRetry`)]})]}),se&&!q&&(0,D.jsx)(`div`,{className:`dc-notice is-error`,role:`alert`,children:se}),ce&&(0,D.jsxs)(`div`,{className:`dc-notice is-success`,role:`status`,children:[(0,D.jsx)(n,{"aria-hidden":!0}),ce]}),p!==`devices`&&(!$||q)&&(0,D.jsxs)(`section`,{className:`dc-card`,children:[(0,D.jsx)(`h2`,{children:p===`groups`?f?`群组与工单`:`Groups & work items`:f?`外部渠道`:`External channels`}),(0,D.jsx)(`p`,{children:f?`先连接设备中心,再创建群组、配置群组 AI 并接入外部渠道。`:`Connect to a device hub before creating groups, configuring group AI, and connecting external channels.`}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button is-primary`,onClick:()=>g(`devices`),children:f?`前往设备连接`:`Connect a device`})]}),p===`groups`&&$&&!q&&(0,D.jsx)(B,{},`groups:${y?.hubUrl??``}:${y?.deviceId??``}`),p===`channels`&&$&&!q&&(0,D.jsx)(k,{plugin:i.find(e=>e.id===`superagent`),epoch:s,onManageGroups:()=>g(`groups`)},`channels:${y?.hubUrl??``}:${y?.deviceId??``}`),p===`devices`&&(0,D.jsxs)(D.Fragment,{children:[!$&&(y||q)&&(0,D.jsx)(L,{initialHubUrl:b,onConnect:e=>{if(q){z(d(`deviceHubLocalOnly`));return}fe.current=!0,x(e)}}),y&&!q&&!$&&(0,D.jsxs)(`section`,{className:`dc-card`,children:[(0,D.jsxs)(`div`,{className:`dc-card-header`,children:[(0,D.jsx)(`span`,{className:`dc-icon`,children:(0,D.jsx)(v,{"aria-hidden":!0})}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h2`,{children:d(`deviceHubPairTitle`)}),(0,D.jsx)(`p`,{children:d(`deviceHubPairHint`)})]})]}),(0,D.jsx)(`ol`,{className:`dc-steps`,children:[`deviceHubStepDetails`,`deviceHubStepApprove`,`deviceHubStepWait`].map((e,t)=>(0,D.jsxs)(`li`,{className:O?t===0?`is-complete`:`is-active`:t===0?`is-active`:``,children:[(0,D.jsx)(`span`,{className:`dc-step-number`,children:O&&t===0?(0,D.jsx)(n,{"aria-hidden":!0}):t+1}),(0,D.jsx)(`span`,{children:d(e)})]},e))}),(0,D.jsxs)(`form`,{className:`dc-form`,onSubmit:e=>{e.preventDefault(),ye()},children:[(0,D.jsxs)(`div`,{className:`dc-field`,children:[(0,D.jsx)(`label`,{htmlFor:`dc-hub-url`,children:d(`deviceHubHubUrl`)}),(0,D.jsx)(`input`,{id:`dc-hub-url`,type:`url`,autoComplete:`url`,required:!0,placeholder:d(`deviceHubHubPlaceholder`),value:b,disabled:!!O||!!N,onChange:e=>{fe.current=!0,x(e.target.value)}})]}),(0,D.jsxs)(`div`,{className:`dc-field`,children:[(0,D.jsx)(`label`,{htmlFor:`dc-device-name`,children:d(`deviceHubName`)}),(0,D.jsx)(`input`,{id:`dc-device-name`,maxLength:80,required:!0,autoComplete:`off`,placeholder:d(`deviceHubNamePlaceholder`),value:w,disabled:!!O||!!N,onChange:e=>{fe.current=!0,ae(e.target.value)}})]}),!O&&(0,D.jsx)(`div`,{className:`dc-actions`,children:(0,D.jsxs)(`button`,{className:`dc-button is-primary`,type:`submit`,disabled:!!N,children:[(0,D.jsx)(v,{"aria-hidden":!0}),d(N?`deviceHubWorking`:`deviceHubGetCode`)]})})]}),O&&(0,D.jsxs)(`div`,{className:`dc-pairing`,children:[(0,D.jsx)(`span`,{className:`dc-code-label`,children:d(`deviceHubCode`)}),(0,D.jsxs)(`div`,{className:`dc-code-row`,children:[(0,D.jsx)(`code`,{className:`dc-code`,children:O.code}),(0,D.jsx)(`button`,{className:`dc-icon-button`,type:`button`,"aria-label":d(`deviceHubCopy`),onClick:()=>void Ce(),children:(0,D.jsx)(o,{"aria-hidden":!0})})]}),(0,D.jsx)(`div`,{className:`dc-pair-meta`,children:d(Te?`deviceHubExpires`:`deviceHubExpired`,{time:Ee})}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[De,(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:!!N,onClick:()=>{++Y.current,j(null),F(``),z(``)},children:[(0,D.jsx)(u,{"aria-hidden":!0}),d(`deviceHubNewCode`)]})]}),Te>0&&(0,D.jsxs)(`p`,{className:`dc-progress`,role:`status`,children:[(0,D.jsx)(u,{"aria-hidden":!0}),d(`deviceHubWaiting`)]})]})]}),$&&y&&!q&&(0,D.jsxs)(`section`,{className:`dc-card`,children:[(0,D.jsxs)(`div`,{className:`dc-device-summary`,children:[(0,D.jsx)(`span`,{className:`dc-device-icon`,children:(0,D.jsx)(c,{"aria-hidden":!0})}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h2`,{children:y.remark?.trim()||y.name}),(0,D.jsx)(`p`,{children:y.remark?.trim()?`${y.name} · ${d(`deviceHubDeviceTitle`)}`:d(`deviceHubDeviceTitle`)})]})]}),(0,D.jsxs)(`dl`,{className:`dc-details`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`dt`,{children:d(`deviceHubDeviceId`)}),(0,D.jsx)(`dd`,{children:y.deviceId})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`dt`,{children:d(`deviceHubHubUrl`)}),(0,D.jsx)(`dd`,{children:y.hubUrl})]})]}),(0,D.jsx)(`div`,{className:`dc-actions`,style:{marginTop:`1rem`},children:(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:V||!!N,onClick:()=>void Se(),children:[(0,D.jsx)(u,{className:V?`spin`:``,"aria-hidden":!0}),d(V?`deviceHubUpgrading`:`deviceHubUpgradeAction`)]})})]}),$&&y?.hubUrl&&y.deviceId&&!q&&(0,D.jsx)(S,{hubUrl:y.hubUrl,currentDeviceId:y.deviceId},`directory:${y.hubUrl}:${y.deviceId}`),!q&&(0,D.jsx)(ie,{pathCompletions:e},`bots:${y?.hubUrl??``}:${y?.deviceId??`unpaired`}`),(0,D.jsx)(W,{}),$&&y&&!q&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`section`,{className:`dc-card`,children:[(0,D.jsxs)(`div`,{className:`dc-card-header`,children:[(0,D.jsx)(`span`,{className:`dc-icon`,children:(0,D.jsx)(ee,{"aria-hidden":!0})}),(0,D.jsx)(`div`,{children:(0,D.jsx)(`h2`,{children:d(`deviceHubPermissions`)})})]}),(0,D.jsxs)(`div`,{className:`dc-permission-row`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h3`,{id:`dc-permission-label`,children:d(`deviceHubPermissionLabel`)}),(0,D.jsx)(`p`,{id:`dc-permission-hint`,children:d(`deviceHubPermissionHint`)})]}),(0,D.jsx)(`button`,{type:`button`,className:`dc-toggle${y.allowExecution?` is-on`:``}`,role:`switch`,"aria-checked":y.allowExecution,"aria-labelledby":`dc-permission-label`,"aria-describedby":`dc-permission-hint`,disabled:!!N,onClick:()=>void be(),children:(0,D.jsx)(`span`,{className:`dc-toggle-thumb`})})]}),(0,D.jsx)(`p`,{className:`dc-permission-state`,role:`status`,children:d(N===`permission`?`deviceHubSaving`:y.allowExecution?`deviceHubEnabled`:`deviceHubReadOnly`)})]}),(0,D.jsx)(C,{hubUrl:y?.hubUrl,deviceId:y?.deviceId,onNotice:z}),(0,D.jsxs)(`details`,{className:`dc-advanced`,children:[(0,D.jsx)(`summary`,{children:d(`deviceHubAdvanced`)}),(0,D.jsxs)(`div`,{className:`dc-danger-zone`,children:[(0,D.jsx)(`h3`,{children:d(`deviceHubDisconnect`)}),(0,D.jsx)(`p`,{children:d(`deviceHubDisconnectHint`)}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button is-danger`,disabled:!!N,onClick:()=>void xe(),children:d(N===`disconnect`?`deviceHubWorking`:`deviceHubDisconnect`)})]})]})]}),(0,D.jsxs)(`aside`,{className:`dc-help`,children:[(0,D.jsx)(h,{className:`dc-help-icon`,"aria-hidden":!0}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h3`,{children:d(`deviceHubHelpTitle`)}),(0,D.jsx)(`p`,{children:d(`deviceHubHelpText`)})]})]})]})]})]})]})}export{G as DeviceCenter};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$ as t,A as n,Bn as r,Cn as i,Fn as a,H as o,Ht as s,Pt as c,Qt as ee,Tn as l,Ut as u,Z as d,gt as te,hn as f,jn as ne,kt as p,pn as m,pt as h,sn as g,wn as _,xt as v}from"./app-globals-CBEscsYP.js";import{i as y,t as re}from"./react-CR5VJ85Q.js";import{K as b,g as x,nn as S,xt as ie}from"./index-BD29OL9L.js";import{t as C}from"./DeviceExecutionSettings-qJzbI0Cf.js";import{n as w,t as ae}from"./GroupWorkItems-BYJv2XFj.js";var T=e(y(),1);async function E(e,t){let n=t.sleep??(e=>new Promise(t=>setTimeout(t,e))),r=Date.now()+(t.timeoutMs??18e5),i=e;if(!i||typeof i.id!=`string`||typeof i.fromBootId!=`string`)throw Error(`Invalid Hub upgrade response`);for(;;){if(t.isCurrent&&!t.isCurrent())throw new DOMException(`Hub upgrade view closed`,`AbortError`);if(i.id!==e.id)throw Error(`Hub upgrade job changed`);if(i.state===`failed`)throw Error(i.error||`Hub upgrade failed`);if(i.state===`succeeded`){if(!i.targetVersion||i.version!==i.targetVersion||!i.bootId||i.bootId===e.fromBootId)throw Error(`Hub upgrade result does not match the new version and process`);return i}if(i.state!==`queued`&&i.state!==`running`)throw Error(`Invalid Hub upgrade state`);if(Date.now()>=r)throw Error(`Hub upgrade timed out; inspect the Hub upgrade log`);if(await n(1500),t.isCurrent&&!t.isCurrent())throw new DOMException(`Hub upgrade view closed`,`AbortError`);try{i=await t.poll(e.id)}catch(e){let t=e.status;if(t&&t<500)throw e}}}var D=re();function O(e){return!!e&&`mount`in e&&typeof e.mount==`function`}function k({plugin:e,epoch:t,onManageGroups:n}){let r=ne(_()),[i,a]=(0,T.useState)(null),[o,s]=(0,T.useState)(!1),[c,ee]=(0,T.useState)(0),{id:l,name:u,version:d,hasClient:te,error:f,isolated:p}=e??{},m=(0,T.useMemo)(()=>l?{id:l,name:u??l,version:d,hasClient:te??!1,error:f,isolated:p}:void 0,[l,u,d,te,f,p]);(0,T.useEffect)(()=>{let e=!1;if(a(null),s(!1),m&&!m.error&&m.hasClient)return b(m,t,{retry:c>0}).then(t=>{e||(O(t)?a({info:m,module:t}):s(!0))}),()=>{e=!0}},[m,t,c]);let h=!m||!m.hasClient;return(0,D.jsxs)(`section`,{className:`dc-card`,"aria-label":r?`外部渠道配置`:`External channel settings`,children:[(0,D.jsxs)(`header`,{className:`dc-card-header`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h2`,{children:r?`GitHub / 飞书渠道`:`GitHub / Feishu channels`}),(0,D.jsx)(`p`,{children:r?`将外部事件映射到群组,由群组 AI 分派任务并跟进工单。`:`Map external events to a group. Its AI delegates tasks and follows up on work items.`})]}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:n,children:r?`管理群组与 AI`:`Manage groups & AI`})]}),h?(0,D.jsx)(`p`,{role:`status`,children:r?`内置渠道模块暂不可用,请重新加载页面或重启主程序。`:`The built-in channel module is temporarily unavailable. Reload this page or restart the application.`}):m.error?(0,D.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:m.error}):o?(0,D.jsxs)(`div`,{className:`dc-notice is-error`,role:`alert`,children:[(0,D.jsx)(`span`,{children:r?`渠道配置界面加载失败。`:`Channel settings failed to load.`}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>ee(e=>e+1),children:r?`重试`:`Retry`})]}):i?(0,D.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,minWidth:0,height:`min(72vh, 900px)`,minHeight:`360px`},children:(0,D.jsx)(x,{entry:i})}):(0,D.jsx)(`p`,{role:`status`,children:r?`正在加载渠道配置…`:`Loading channel settings…`})]})}function A({href:e,children:t}){let n=l(),[r,i]=(0,T.useState)(!1),[a,o]=(0,T.useState)(!1);return(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`a`,{className:`dc-button`,href:e,target:`_blank`,rel:`noopener noreferrer`,onClick:t=>{let n=window.piDesktop;n?.openHub&&(t.preventDefault(),!a&&(o(!0),i(!1),n.openHub(e).then(e=>i(!e),()=>i(!0)).finally(()=>o(!1))))},"aria-busy":a,children:t}),r&&(0,D.jsxs)(`span`,{role:`alert`,children:[n(`deviceHubNetworkError`),` `,(0,D.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,children:e})]})]})}function j(e){if(!M(e.host)||!Number.isInteger(e.port)||e.port<1024||e.port>65535||e.publicUrl.length>2048||/[\s\u0000-\u001f\u007f]/.test(e.publicUrl))return!1;try{let t=new URL(e.publicUrl);return[`http:`,`https:`].includes(t.protocol)&&!!t.hostname&&!t.username&&!t.password&&!t.search&&!t.hash&&t.pathname===`/`&&![`0.0.0.0`,`[::]`].includes(t.hostname)}catch{return!1}}function M(e){if(e===`localhost`)return!0;if(/^(?:\d{1,3}\.){3}\d{1,3}$/.test(e))return e.split(`.`).every(e=>String(Number(e))===e&&Number(e)<=255);if(!e.includes(`:`)||!/^[0-9a-fA-F:.]+$/.test(e))return!1;try{return new URL(`http://[${e}]/`).hostname.startsWith(`[`)}catch{return!1}}function oe(e){try{let t=new URL(e);return[`http:`,`https:`].includes(t.protocol)&&[`localhost`,`127.0.0.1`,`[::1]`].includes(t.hostname)}catch{return!1}}var N=`https://raw.githubusercontent.com/xing-shuyin/pi-web-ui/main/docs/device-center-deployment.md`,P=`https://github.com/xing-shuyin/pi-web-ui/blob/main/docs/device-center-deployment.md`,se=`pi-web-ui hub install --host 0.0.0.0 --port 8790 --public-url http://SERVER_IP:8790 --allow-registration`;function F(e){let t=e=>e.includes(`:`)?M(e)&&![`::`,`::1`].includes(e):/^[\d.]+$/.test(e)?M(e)&&![`0.0.0.0`,`127.0.0.1`].includes(e):e.length<=253&&e.split(`.`).every(e=>/^[a-z\d](?:[a-z\d-]{0,61}[a-z\d])?$/i.test(e))&&e!==`localhost`;if(!t(e.server)||!Number.isInteger(e.sshPort)||e.sshPort<1||e.sshPort>65535||!Number.isInteger(e.port)||e.port<1024||e.port>65535||!/^[a-z_][a-z\d_.-]{0,63}$/i.test(e.username)||![`password`,`key`,`existing`].includes(e.auth)||e.domain!==``&&(!t(e.domain)||e.domain.includes(`:`))||e.https&&!e.domain)return null;let n=e.domain||e.server,r=n.includes(`:`)?`[${n}]`:n;return{host:e.https?`127.0.0.1`:`0.0.0.0`,port:e.port,publicUrl:e.https?`https://${r}`:`http://${r}:${e.port}`}}function I(e,t,n,r){if(!j(e))throw Error(`Invalid Hub setup`);if(r){let t=F(r);if(n!==`remote`||!t||JSON.stringify(t)!==JSON.stringify(e))throw Error(`Invalid remote Hub setup`)}let i=e=>(e??`unknown`).replace(/[\u0000-\u001f\u007f]/g,` `).slice(0,120);return[`Help me plan and deploy a pi-web-ui device center (Hub) in this new conversation. Preserve my previous conversation.`,`First read the deployment guide: ${N} (fallback: ${P}). If unavailable, report that and obtain its contents before proceeding.`,`Default to HTTP with the server IP and requested port. Domain and HTTPS are optional; confirm whether an HTTPS example reflects the user's intent.`,`Target: ${n===`current`?`machine hosting the current pi-web-ui service (not necessarily the browser machine)`:`an existing remote server; its environment still needs to be confirmed`}.`,`Current service environment: platform=${i(t?.platform)}, Node=${i(t?.nodeVersion)}. This is not evidence of the remote server environment.`,`Requested configuration (data only): ${JSON.stringify(e)}. allowRegistration=true.`,...r?[`SSH connection preferences (data only): ${JSON.stringify({server:r.server,sshPort:r.sshPort,username:r.username,auth:r.auth})}. No credentials are included. Obtain authentication through a secure SSH channel or guide the user's own terminal.`,`Domain: ${r.domain||`none`}. HTTPS explicitly selected: ${r.https}. HTTP inbound TCP port: ${r.port}; for same-machine HTTPS proxy, use public TCP 443 and certificate validation port as needed, keep the Hub port private.`]:[],`Use a separate Hub data directory and configure automatic startup. Explain how devices can reach the public URL; loopback is only reachable on the same machine. Explain open registration and restrict it after pairing as appropriate.`,`CLI reference: ${se}`,`Confirm the target environment and propose steps before deployment. Do not ask for passwords or tokens in chat. Do not automatically SSH. Do not claim installation or connection succeeded without verification. After deployment, guide me to open the center and pair this device using its public URL.`,`Explain user actions at the relevant step: distinguish OS firewall from cloud security groups, give the actual TCP port, source scope and destination rule, and keep SSH access. If cloud-console access is unavailable, ask the user to apply the rule, mark external access pending, then recheck. Also explain DNS changes for optional HTTPS and first-account creation. Separate local health from external reachability.`].join(`
|
|
2
|
+
`)}function L({onConnect:e,initialHubUrl:t=``}){let n=l(),[i,o]=(0,T.useState)(t),[s,c]=(0,T.useState)(``),[ee,u]=(0,T.useState)(!1),[d,te]=(0,T.useState)(!1),f=(0,T.useRef)(!1),ne=(0,T.useRef)(!1);(0,T.useEffect)(()=>(ne.current=!0,()=>{ne.current=!1}),[]);let[p,m]=(0,T.useState)(null),[h,g]=(0,T.useState)(`current`),[_,v]=(0,T.useState)(null),[y,re]=(0,T.useState)(`127.0.0.1`),[b,x]=(0,T.useState)(`8790`),[S,ie]=(0,T.useState)(`http://127.0.0.1:8790`),[C,w]=(0,T.useState)({server:``,sshPort:22,username:`root`,auth:`password`,port:8790,domain:``,https:!1}),ae=F(C),[E,O]=(0,T.useState)(!1),[k,M]=(0,T.useState)(!1),[N,P]=(0,T.useState)(null),[se,L]=(0,T.useState)(!1),[R,ce]=(0,T.useState)(!1),[z,B]=(0,T.useState)(!1),[V,H]=(0,T.useState)(null),U=(0,T.useRef)(null),W=(0,T.useRef)(!1),G=oe(window.location.origin);(0,T.useEffect)(()=>()=>U.current?.abort(),[]);let K=async()=>{if(W.current)return;U.current?.abort();let e=new AbortController;U.current=e,L(!1),ce(!1),B(!1);try{let t=await fetch(r(a(`/api/device-center/setup`)),{credentials:`same-origin`,signal:e.signal});if(!t.ok)throw Error();let n=await t.json();if(!n||typeof n.platform!=`string`||typeof n.nodeVersion!=`string`||typeof n.dataDir!=`string`||typeof n.cliPath!=`string`||!j({host:`127.0.0.1`,port:n.defaultPort,publicUrl:n.defaultPublicUrl}))throw Error();if(e.signal.aborted)return;v(n),n.installation?.installed?(re(n.installation.host??`127.0.0.1`),x(String(n.installation.port)),ie(n.installation.publicUrl??``),o(n.installation.publicUrl??``)):_||(x(String(n.defaultPort)),ie(n.defaultPublicUrl))}catch{e.signal.aborted||(L(!0),B(!0))}finally{e.signal.aborted||ce(!0)}},q=async()=>{let e={host:y,port:Number(b),publicUrl:S};if(W.current||!G||!_||!R||z||_.busy||_.installation?.installed||!j(e))return;W.current=!0,U.current?.abort(),O(!0),L(!1),c(``);let t=new AbortController;U.current=t;try{let n=await fetch(r(a(`/api/device-center/setup`)),{credentials:`same-origin`,method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({...e,allowRegistration:!0}),signal:t.signal});if(n.status===409){v(e=>e&&{...e,busy:!0}),W.current=!1,O(!1),await K();return}if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(typeof e.error==`string`?e.error.slice(0,4096):`HTTP ${n.status}`)}let i=await n.json();if(!j({...e,publicUrl:i.publicUrl})||typeof i.output!=`string`)throw Error();t.signal.aborted||H(i)}catch(e){t.signal.aborted||(L(!0),c(e instanceof Error?e.message.slice(0,4096):``))}finally{W.current=!1,t.signal.aborted||O(!1)}},le=async()=>{if(W.current||!G||!_||!R||z||_.busy||E||k)return;W.current=!0,U.current?.abort(),M(!0),L(!1),c(``),P(null);let e=new AbortController;U.current=e;try{let t=await fetch(r(a(`/api/device-center/setup/update`)),{credentials:`same-origin`,method:`POST`,headers:{"Content-Type":`application/json`},signal:e.signal});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(typeof e.error==`string`?e.error.slice(0,4096):`HTTP ${t.status}`)}let i=await t.json();e.signal.aborted||(P(i.output||n(`deviceSetupUpdateSuccess`)),await K())}catch(t){e.signal.aborted||(L(!0),c(t instanceof Error?t.message.slice(0,4096):``))}finally{W.current=!1,e.signal.aborted||M(!1)}},J=_?.installation,ue=!!J?.installed,de=ue&&J.running&&J.owned,Y=h===`remote`?ae:{host:y,port:Number(b),publicUrl:S},X=!!Y&&j(Y);return(0,D.jsxs)(`section`,{className:`dc-onboarding`,children:[(0,D.jsx)(`h3`,{children:n(`deviceSetupWelcome`)}),(0,D.jsx)(`p`,{children:n(`deviceSetupIntro`)}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[(0,D.jsx)(`button`,{className:`dc-button`,disabled:E,"aria-pressed":p===`connect`,onClick:()=>m(`connect`),children:n(`deviceSetupConnect`)}),(0,D.jsx)(`button`,{className:`dc-button`,disabled:E,"aria-pressed":p===`create`,onClick:()=>{m(`create`),!_&&G&&K()},children:n(`deviceSetupCreate`)})]}),p===`connect`&&(0,D.jsxs)(`form`,{onSubmit:t=>{t.preventDefault(),e(i.trim())},children:[(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceHubHubUrl`)}),(0,D.jsx)(`input`,{type:`url`,required:!0,maxLength:2048,value:i,onChange:e=>o(e.target.value),placeholder:`https://hub.example.com`})]}),(0,D.jsx)(`button`,{className:`dc-button is-primary`,disabled:!j({host:`localhost`,port:8790,publicUrl:i.trim()}),children:n(`deviceSetupPair`)})]}),p===`create`&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupTarget`)}),(0,D.jsxs)(`select`,{disabled:E,value:h,onChange:e=>g(e.target.value),children:[(0,D.jsx)(`option`,{value:`current`,children:n(`deviceSetupCurrent`)}),(0,D.jsx)(`option`,{value:`remote`,children:n(`deviceSetupRemote`)})]})]}),(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`p`,{children:n(h===`current`?`deviceSetupCurrentHint`:`deviceSetupRemoteHint`)}),h===`current`&&(0,D.jsxs)(`div`,{className:`dc-setup-plan`,children:[(0,D.jsx)(`strong`,{children:n(`deviceSetupPlan`)}),(0,D.jsx)(`p`,{children:n(`deviceSetupPlanHint`)}),_&&(0,D.jsxs)(`dl`,{children:[(0,D.jsx)(`dt`,{children:n(`deviceSetupEnvironment`)}),(0,D.jsxs)(`dd`,{children:[_.platform,` · Node `,_.nodeVersion]}),(0,D.jsx)(`dt`,{children:n(`deviceSetupDataDir`)}),(0,D.jsx)(`dd`,{children:_.dataDir}),(0,D.jsx)(`dt`,{children:n(`deviceSetupCli`)}),(0,D.jsx)(`dd`,{children:_.cliPath})]}),!G&&(0,D.jsx)(`p`,{role:`status`,children:n(`deviceSetupLocalOnly`)}),(0,D.jsx)(`p`,{children:n(`deviceSetupBackground`)}),ue&&(0,D.jsxs)(`div`,{role:`status`,children:[(0,D.jsx)(`h4`,{children:n(de?`deviceSetupRestored`:`deviceSetupUnhealthy`)}),(0,D.jsx)(`p`,{children:J.publicUrl}),de&&X&&J.publicUrl?(0,D.jsxs)(`div`,{className:`dc-actions`,children:[(0,D.jsx)(A,{href:J.publicUrl,children:n(`deviceHubOpenHub`)}),(0,D.jsx)(`button`,{className:`dc-button`,onClick:()=>e(J.publicUrl),children:n(`deviceSetupPair`)}),G&&(0,D.jsx)(`button`,{className:`dc-button`,disabled:E||k,onClick:()=>void le(),children:n(k?`deviceSetupUpdating`:`deviceSetupUpdate`)})]}):(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`p`,{children:n(`deviceSetupRecovery`)}),(0,D.jsx)(`pre`,{className:`dc-setup-output`,children:`pi-web-ui hub status --json
|
|
3
|
+
pi-web-ui hub --help`}),G&&(0,D.jsx)(`button`,{className:`dc-button is-primary`,disabled:E||k,onClick:()=>void le(),children:n(k?`deviceSetupUpdating`:`deviceSetupUpdate`)})]}),N&&(0,D.jsx)(`pre`,{className:`dc-setup-output`,children:N.slice(0,16e3)})]}),_?.busy&&(0,D.jsx)(`p`,{role:`status`,children:n(`deviceSetupBusy`)}),G&&(0,D.jsx)(`button`,{className:`dc-button`,disabled:E||!R,onClick:()=>void K(),children:n(R?`deviceSetupRetry`:`deviceHubWorking`)})]}),h===`remote`?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`div`,{className:`dc-setup-fields`,children:[(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupServer`)}),(0,D.jsx)(`input`,{autoComplete:`off`,maxLength:253,placeholder:`203.0.113.10`,value:C.server,onChange:e=>w({...C,server:e.target.value.trim()})})]}),(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupSshPort`)}),(0,D.jsx)(`input`,{type:`number`,min:1,max:65535,value:C.sshPort,onChange:e=>w({...C,sshPort:Number(e.target.value)})})]}),(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupUsername`)}),(0,D.jsx)(`input`,{autoComplete:`off`,maxLength:64,value:C.username,onChange:e=>w({...C,username:e.target.value})})]}),(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupAuth`)}),(0,D.jsxs)(`select`,{value:C.auth,onChange:e=>w({...C,auth:e.target.value}),children:[(0,D.jsx)(`option`,{value:`password`,children:n(`deviceSetupAuthPassword`)}),(0,D.jsx)(`option`,{value:`key`,children:n(`deviceSetupAuthKey`)}),(0,D.jsx)(`option`,{value:`existing`,children:n(`deviceSetupAuthExisting`)})]})]}),(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupServicePort`)}),(0,D.jsx)(`input`,{type:`number`,min:1024,max:65535,value:C.port,onChange:e=>w({...C,port:Number(e.target.value)})})]})]}),(0,D.jsx)(`p`,{children:n(`deviceSetupCredentialHint`)}),(0,D.jsxs)(`details`,{children:[(0,D.jsx)(`summary`,{children:n(`deviceSetupOptionalTls`)}),(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupDomain`)}),(0,D.jsx)(`input`,{maxLength:253,placeholder:`hub.example.com`,value:C.domain,onChange:e=>w({...C,domain:e.target.value.trim()})})]}),(0,D.jsxs)(`label`,{children:[(0,D.jsx)(`input`,{type:`checkbox`,checked:C.https,onChange:e=>w({...C,https:e.target.checked})}),` `,n(`deviceSetupEnableHttps`)]}),(0,D.jsx)(`p`,{children:n(`deviceSetupTlsHint`)})]}),(0,D.jsxs)(`p`,{children:[(0,D.jsx)(`strong`,{children:n(`deviceSetupPreview`)}),` `,ae?.publicUrl??n(`deviceSetupPreviewEmpty`)]}),(0,D.jsxs)(`div`,{className:`dc-setup-plan`,children:[(0,D.jsx)(`strong`,{children:n(`deviceSetupUserActions`)}),(0,D.jsx)(`p`,{children:n(`deviceSetupCloudPorts`).replace(`{ports}`,C.https?`443 / 80`:String(C.port))}),(0,D.jsx)(`p`,{children:n(`deviceSetupSourceScope`)}),(0,D.jsx)(`p`,{children:n(`deviceSetupAfterStart`)})]}),(0,D.jsx)(`a`,{href:`https://github.com/xing-shuyin/pi-web-ui/blob/main/docs/device-center-deployment.md`,target:`_blank`,rel:`noopener noreferrer`,children:n(`deviceSetupGuide`)})]}):(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`div`,{className:`dc-setup-fields`,children:[(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupHost`)}),(0,D.jsx)(`input`,{disabled:E||!!V,maxLength:253,value:y,onChange:e=>re(e.target.value)})]}),(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupPort`)}),(0,D.jsx)(`input`,{disabled:E||!!V,type:`number`,min:1024,max:65535,value:b,onChange:e=>x(e.target.value)})]}),(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceHubHubUrl`)}),(0,D.jsx)(`input`,{disabled:E||!!V,maxLength:2048,value:S,onChange:e=>ie(e.target.value)})]})]}),(0,D.jsx)(`p`,{className:`dc-setup-warning`,children:n(`deviceSetupReachable`)})]}),(0,D.jsx)(`p`,{children:n(`deviceSetupRegistration`)}),!X&&(0,D.jsx)(`p`,{role:`alert`,children:n(h===`remote`?`deviceSetupRemoteInvalid`:`deviceSetupInvalid`)}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[h===`current`&&!V&&!ue&&(0,D.jsx)(`button`,{className:`dc-button is-primary`,disabled:E||!G||!_||!R||z||!!_.busy||!X,onClick:()=>void q(),children:n(E?`deviceSetupInstalling`:`deviceSetupInstall`)}),(0,D.jsx)(`button`,{className:`dc-button`,disabled:E||ee||!X,onClick:()=>{if(!X||!Y||f.current)return;f.current=!0,u(!0),te(!1);let e=e=>{f.current=!1,ne.current&&(u(!1),te(!e))},t=window.__piWebUiHost;try{t?.startChat({newChat:!0,prompt:I(Y,_,h,h===`remote`?C:void 0),onResult:e})||e(!1)}catch{e(!1)}},children:n(h===`remote`?`deviceSetupStartAi`:`deviceSetupAi`)})]}),(0,D.jsx)(`p`,{children:n(`deviceSetupAiHint`)}),ee&&(0,D.jsx)(`p`,{role:`status`,children:n(`deviceSetupAiCreating`)}),d&&(0,D.jsx)(`p`,{role:`alert`,children:n(`deviceSetupAiFailed`)})]})]}),se&&(0,D.jsxs)(`div`,{role:`alert`,children:[(0,D.jsx)(`p`,{children:n(`deviceSetupFailed`)}),s&&(0,D.jsx)(`pre`,{className:`dc-setup-output`,children:s})]}),V&&(0,D.jsxs)(`div`,{role:`status`,children:[(0,D.jsx)(`h4`,{children:n(`deviceSetupSuccess`)}),(0,D.jsx)(`pre`,{className:`dc-setup-output`,children:V.output.slice(0,16e3)}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[(0,D.jsx)(A,{href:V.publicUrl,children:n(`deviceHubOpenHub`)}),(0,D.jsx)(`button`,{className:`dc-button is-primary`,onClick:()=>e(V.publicUrl),children:n(`deviceSetupPair`)})]})]})]})}var R=`pi-web-ui:device-groups-changed`;function ce(e){window.dispatchEvent(new CustomEvent(`pi-web-ui:device-group-open`,{detail:{roomId:e}}))}async function z(e,t,n){let i=await fetch(r(a(`/api/device-center/${e}`)),{method:n?`POST`:`GET`,credentials:`same-origin`,signal:t,...n?{headers:{"Content-Type":`application/json`},body:JSON.stringify(n)}:{}}),o=await i.json().catch(()=>({}));if(!i.ok)throw Error(o.error||o.message||`Request failed (${i.status})`);return o}function B({bindingKey:e=``}){return(0,D.jsx)(V,{},e)}function V(){let{locale:e}=i(),t=ne(e),[r,a]=(0,T.useState)([]),[o,c]=(0,T.useState)([]),[ee,l]=(0,T.useState)(!0),[te,h]=(0,T.useState)(``),[_,v]=(0,T.useState)(``),[y,re]=(0,T.useState)(0),[b,x]=(0,T.useState)(!1),[S,ie]=(0,T.useState)(``),[C,E]=(0,T.useState)([]),[O,k]=(0,T.useState)(``),[A,j]=(0,T.useState)(null),[M,oe]=(0,T.useState)([]),[N,P]=(0,T.useState)(``),[se,F]=(0,T.useState)(null),[I,L]=(0,T.useState)(``),[B,V]=(0,T.useState)(!1),[H,U]=(0,T.useState)(null),W=r.find(e=>e.id===H?.roomId),G=(0,T.useRef)(0),K=(0,T.useRef)(null),q=(0,T.useRef)(null);function le(){++G.current,K.current?.abort(),re(e=>e+1)}function J(){q.current?.abort();let e=new AbortController;return q.current=e,e}(0,T.useEffect)(()=>()=>q.current?.abort(),[]),(0,T.useEffect)(()=>{let e=++G.current,t=new AbortController;K.current=t;async function n(){try{let[n,r]=await Promise.all([z(`rooms`,t.signal),z(`bots`,t.signal)]);if(G.current!==e||t.signal.aborted)return;let i=Array.isArray(n.rooms)?n.rooms:[];a(i),U(e=>e&&i.some(t=>t.id===e.roomId)?e:null),c(Array.isArray(r.bots)?r.bots:[]),h(``)}catch(n){G.current===e&&!t.signal.aborted&&h(n instanceof Error?n.message:String(n))}finally{G.current===e&&!t.signal.aborted&&l(!1)}}return n(),()=>{t.abort()}},[y]),(0,T.useEffect)(()=>{let e=()=>le();return window.addEventListener(R,e),()=>window.removeEventListener(R,e)},[]);async function ue(e){if(e.preventDefault(),!S.trim()||B)return;V(!0),h(``),v(``);let n=J();try{let e=C.includes(O)?O:``,r=await z(`rooms`,n.signal,{name:S.trim(),botIds:C,...e?{primaryBotId:e}:{}});if(n.signal.aborted)return;a(e=>[...e.filter(e=>e.id!==r.room.id),r.room]),x(!1),ie(``),E([]),k(``),v(t?`群聊创建成功`:`Group created successfully`),window.dispatchEvent(new CustomEvent(R))}catch(e){n.signal.aborted||h(e instanceof Error?e.message:String(e))}finally{n.signal.aborted||V(!1)}}function de(e){j(e.id),oe([...e.botIds]),P(e.primaryBotId??``),F(null),x(!1),h(``),v(``)}async function Y(e){if(B)return;V(!0),h(``),v(``);let n=J();try{let r=M.includes(N)?N:null,i=await z(`rooms/${encodeURIComponent(e)}/members`,n.signal,{botIds:M,primaryBotId:r});if(n.signal.aborted)return;a(t=>t.map(t=>t.id===e?i.room:t)),j(null),v(t?`成员设置已保存`:`Members updated successfully`),window.dispatchEvent(new CustomEvent(R))}catch(e){n.signal.aborted||h(e instanceof Error?e.message:String(e))}finally{n.signal.aborted||V(!1)}}async function X(e){if(!I.trim()||B)return;V(!0),h(``),v(``);let n=J();try{if(await z(`rooms/${encodeURIComponent(e)}/rename`,n.signal,{name:I.trim()}),n.signal.aborted)return;a(t=>t.map(t=>t.id===e?{...t,name:I.trim()}:t)),F(null),v(t?`群聊名称已更新`:`Group renamed successfully`),window.dispatchEvent(new CustomEvent(R))}catch(e){n.signal.aborted||h(e instanceof Error?e.message:String(e))}finally{n.signal.aborted||V(!1)}}async function Z(e){if(B||!window.confirm(t?`确定删除群聊“${e.name}”?`:`Are you sure you want to delete "${e.name}"?`))return;V(!0),h(``),v(``);let n=J();try{if(await z(`rooms/${encodeURIComponent(e.id)}/delete`,n.signal,{}),n.signal.aborted)return;U(t=>t?.roomId===e.id?null:t),a(t=>t.filter(t=>t.id!==e.id)),A===e.id&&j(null),se===e.id&&F(null),v(t?`群聊已删除`:`Group deleted successfully`),window.dispatchEvent(new CustomEvent(R))}catch(e){n.signal.aborted||h(e instanceof Error?e.message:String(e))}finally{n.signal.aborted||V(!1)}}return(0,D.jsxs)(`section`,{className:`dc-card`,"aria-label":t?`群聊列表`:`Group list`,children:[(0,D.jsxs)(`div`,{className:`dc-card-header`,children:[(0,D.jsx)(`span`,{className:`dc-icon`,children:(0,D.jsx)(m,{"aria-hidden":!0})}),(0,D.jsxs)(`div`,{children:[(0,D.jsxs)(`h2`,{children:[t?`群聊列表`:`Group List`,` · `,r.length]}),(0,D.jsx)(`p`,{children:t?`管理群聊与成员 Bot,在此配置协作群组或直接进入聊天。`:`Manage groups and member Bots. Configure collaboration groups or open chats here.`})]}),(0,D.jsxs)(`div`,{className:`dc-actions`,style:{marginInlineStart:`auto`},children:[(0,D.jsxs)(`button`,{type:`button`,className:`dc-button is-primary`,disabled:B,onClick:()=>{x(e=>!e),j(null),F(null),ie(``),E([]),k(``)},children:[(0,D.jsx)(s,{"aria-hidden":!0}),t?`新建群聊`:`Create Group`]}),(0,D.jsx)(`button`,{type:`button`,className:`dc-icon-button`,"aria-label":t?`刷新群聊`:`Refresh groups`,onClick:le,children:(0,D.jsx)(u,{})})]})]}),te&&(0,D.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:te}),_&&(0,D.jsxs)(`p`,{className:`dc-notice is-success`,role:`status`,children:[(0,D.jsx)(n,{"aria-hidden":!0}),_]}),b&&(0,D.jsxs)(`form`,{className:`dc-card`,style:{marginBottom:`16px`,background:`var(--bg)`,border:`1px solid var(--border)`},onSubmit:ue,children:[(0,D.jsxs)(`div`,{className:`dg-heading`,style:{marginBottom:`12px`},children:[(0,D.jsx)(`h3`,{children:t?`新建群聊`:`Create Group`}),(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>x(!1),disabled:B,children:[(0,D.jsx)(f,{"aria-hidden":!0}),t?`关闭`:`Close`]})]}),(0,D.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`12px`},children:[(0,D.jsx)(`label`,{htmlFor:`dg-manager-new-name`,children:t?`群名称`:`Group Name`}),(0,D.jsx)(`input`,{id:`dg-manager-new-name`,type:`text`,required:!0,maxLength:80,value:S,placeholder:t?`输入群名称,如:研发协作群`:`Enter group name`,onChange:e=>ie(e.target.value),disabled:B,style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`}})]}),(0,D.jsxs)(`div`,{style:{marginBottom:`12px`},children:[(0,D.jsx)(`label`,{style:{display:`block`,marginBottom:`6px`,fontSize:`12px`,color:`var(--text-dim)`},children:t?`选择成员 Bot`:`Select Member Bots`}),(0,D.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`6px`,maxHeight:`160px`,overflowY:`auto`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`8px`,background:`var(--bg-elev)`},children:o.length===0?(0,D.jsx)(`p`,{style:{margin:0,fontSize:`12px`,color:`var(--text-faint)`},children:t?`暂无可用 Bot,请先创建 Bot。`:`No Bots available. Please create a Bot first.`}):o.map(e=>(0,D.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,cursor:`pointer`,fontSize:`12px`},children:[(0,D.jsx)(`input`,{type:`checkbox`,checked:C.includes(e.id),disabled:B||!e.enabled,onChange:t=>{E(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}}),(0,D.jsxs)(`span`,{children:[(0,D.jsx)(`strong`,{children:e.name}),(0,D.jsxs)(`small`,{style:{color:`var(--text-faint)`,marginInlineStart:`6px`},children:[e.online?t?`在线`:`Online`:t?`离线`:`Offline`,e.enabled?``:t?` · 已禁用`:` · Disabled`]})]})]},e.id))})]}),C.length>0&&(0,D.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`16px`},children:[(0,D.jsx)(`label`,{htmlFor:`dg-manager-new-primary`,children:t?`原主 Bot(Router 未启用时)`:`Legacy primary Bot (when Router is disabled)`}),(0,D.jsxs)(`select`,{id:`dg-manager-new-primary`,value:C.includes(O)?O:``,onChange:e=>k(e.target.value),disabled:B,style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`},children:[(0,D.jsx)(`option`,{value:``,children:t?`不设置(需 @ Bot)`:`None (mention a Bot)`}),o.filter(e=>C.includes(e.id)).map(e=>(0,D.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[(0,D.jsxs)(`button`,{type:`submit`,className:`dc-button is-primary`,disabled:B||!S.trim(),children:[(0,D.jsx)(n,{"aria-hidden":!0}),B?t?`创建中…`:`Creating…`:t?`创建群聊`:`Create`]}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>x(!1),disabled:B,children:t?`取消`:`Cancel`})]})]}),A&&(0,D.jsxs)(`div`,{className:`dc-card`,style:{marginBottom:`16px`,background:`var(--bg)`,border:`1px solid var(--border)`},children:[(0,D.jsxs)(`div`,{className:`dg-heading`,style:{marginBottom:`12px`},children:[(0,D.jsxs)(`h3`,{children:[t?`管理成员`:`Manage Members`,` · `,r.find(e=>e.id===A)?.name]}),(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>j(null),disabled:B,children:[(0,D.jsx)(f,{"aria-hidden":!0}),t?`关闭`:`Close`]})]}),(0,D.jsxs)(`div`,{style:{marginBottom:`12px`},children:[(0,D.jsx)(`label`,{style:{display:`block`,marginBottom:`6px`,fontSize:`12px`,color:`var(--text-dim)`},children:t?`选择成员 Bot`:`Select Member Bots`}),(0,D.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`6px`,maxHeight:`160px`,overflowY:`auto`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`8px`,background:`var(--bg-elev)`},children:o.length===0?(0,D.jsx)(`p`,{style:{margin:0,fontSize:`12px`,color:`var(--text-faint)`},children:t?`暂无可用 Bot`:`No Bots available`}):o.map(e=>(0,D.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,cursor:`pointer`,fontSize:`12px`},children:[(0,D.jsx)(`input`,{type:`checkbox`,checked:M.includes(e.id),disabled:B,onChange:t=>{oe(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}}),(0,D.jsxs)(`span`,{children:[(0,D.jsx)(`strong`,{children:e.name}),(0,D.jsxs)(`small`,{style:{color:`var(--text-faint)`,marginInlineStart:`6px`},children:[e.online?t?`在线`:`Online`:t?`离线`:`Offline`,e.enabled?``:t?` · 已禁用`:` · Disabled`]})]})]},e.id))})]}),!r.find(e=>e.id===A)?.router?.enabled&&(0,D.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`16px`},children:[(0,D.jsx)(`label`,{htmlFor:`dg-manager-edit-primary`,children:t?`原主 Bot(Router 未启用时)`:`Legacy primary Bot (when Router is disabled)`}),(0,D.jsxs)(`select`,{id:`dg-manager-edit-primary`,value:M.includes(N)?N:``,onChange:e=>P(e.target.value),disabled:B,style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`},children:[(0,D.jsx)(`option`,{value:``,children:t?`不设置(需 @ Bot)`:`None (mention a Bot)`}),o.filter(e=>M.includes(e.id)).map(e=>(0,D.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[(0,D.jsxs)(`button`,{type:`button`,className:`dc-button is-primary`,disabled:B,onClick:()=>void Y(A),children:[(0,D.jsx)(n,{"aria-hidden":!0}),B?t?`保存中…`:`Saving…`:t?`保存成员设置`:`Save Members`]}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>j(null),disabled:B,children:t?`取消`:`Cancel`})]})]}),ee&&(0,D.jsx)(`p`,{role:`status`,children:t?`加载中…`:`Loading…`}),!ee&&r.length===0&&(0,D.jsx)(`p`,{style:{color:`var(--text-faint)`,fontSize:`13px`,padding:`12px 0`},children:t?`还没有群聊,点击上方“新建群聊”开始协作。`:`No groups yet. Click 'Create Group' above to get started.`}),(0,D.jsx)(`div`,{className:`dd-list`,children:r.map(e=>{let r=se===e.id,i=o.filter(t=>e.botIds.includes(t.id)),a=o.find(t=>t.id===e.primaryBotId);return(0,D.jsxs)(`div`,{className:`dd-device`,style:r?{flexWrap:`wrap`}:void 0,children:[(0,D.jsx)(`span`,{className:`dc-device-icon`,children:(0,D.jsx)(m,{"aria-hidden":!0})}),(0,D.jsxs)(`div`,{className:`dd-identity`,style:{flex:1,minWidth:`200px`},children:[(0,D.jsx)(`strong`,{children:e.name}),(0,D.jsxs)(`span`,{style:{display:`flex`,gap:`8px`,flexWrap:`wrap`,alignItems:`center`},children:[(0,D.jsx)(`span`,{children:t?`${e.botIds.length} 个 Bot${i.length?`: ${i.map(e=>e.name).join(`, `)}`:``}`:`${e.botIds.length} Bots${i.length?`: ${i.map(e=>e.name).join(`, `)}`:``}`}),e.router?.enabled&&(0,D.jsxs)(`span`,{children:[`AI Router · `,e.router.deviceId,` · `,e.router.model,` · `,e.router.thinkingLevel]}),!e.router?.enabled&&a&&(0,D.jsx)(`span`,{style:{color:`var(--accent)`},children:t?`[主 Bot: ${a.name}]`:`[Primary: ${a.name}]`})]})]}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[(0,D.jsxs)(`button`,{type:`button`,className:`dc-button is-primary`,title:t?`打开聊天`:`Open chat`,onClick:()=>ce(e.id),children:[(0,D.jsx)(p,{"aria-hidden":!0}),t?`打开聊天`:`Open chat`]}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button`,"aria-expanded":H?.roomId===e.id&&H.kind===`router`,onClick:()=>U({roomId:e.id,kind:`router`}),children:`AI Router`}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button`,"aria-expanded":H?.roomId===e.id&&H.kind===`work`,onClick:()=>U({roomId:e.id,kind:`work`}),children:t?`工单与运行`:`Work items & runs`}),(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,title:t?`管理成员`:`Manage members`,onClick:()=>de(e),children:[(0,D.jsx)(m,{"aria-hidden":!0}),t?`管理成员`:`Members`]}),(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,title:t?`重命名`:`Rename`,onClick:()=>{r?F(null):(F(e.id),L(e.name))},children:[(0,D.jsx)(d,{"aria-hidden":!0}),t?`重命名`:`Rename`]}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button is-danger`,title:t?`删除群聊`:`Delete group`,disabled:B,onClick:()=>void Z(e),children:(0,D.jsx)(g,{"aria-hidden":!0})})]}),r&&(0,D.jsxs)(`form`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,width:`100%`,paddingTop:`8px`,paddingBottom:`4px`},onSubmit:t=>{t.preventDefault(),X(e.id)},children:[(0,D.jsx)(`input`,{type:`text`,maxLength:80,autoFocus:!0,disabled:B,value:I,onChange:e=>L(e.target.value),placeholder:t?`输入新群名称`:`Enter new name`,style:{flex:1,minWidth:`180px`,background:`var(--bg)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`12px`}}),(0,D.jsxs)(`button`,{type:`submit`,className:`dc-button is-primary`,disabled:B||!I.trim(),children:[(0,D.jsx)(n,{"aria-hidden":!0}),t?`保存`:`Save`]}),(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:B,onClick:()=>F(null),children:[(0,D.jsx)(f,{"aria-hidden":!0}),t?`取消`:`Cancel`]})]})]},e.id)})}),W&&H&&(0,D.jsxs)(`section`,{className:`dc-card`,"aria-label":t?`群组设置`:`Group settings`,children:[(0,D.jsxs)(`div`,{className:`dg-heading`,children:[(0,D.jsx)(`h3`,{children:W.name}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[(0,D.jsx)(`button`,{type:`button`,className:`dc-button${H.kind===`router`?` is-primary`:``}`,"aria-pressed":H.kind===`router`,onClick:()=>U({roomId:W.id,kind:`router`}),children:`AI Router`}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button${H.kind===`work`?` is-primary`:``}`,"aria-pressed":H.kind===`work`,onClick:()=>U({roomId:W.id,kind:`work`}),children:t?`工单与运行`:`Work items & runs`}),(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>U(null),children:[(0,D.jsx)(f,{"aria-hidden":!0}),t?`关闭`:`Close`]})]})]}),H.kind===`router`?(0,D.jsx)(w,{roomId:W.id,router:W.router,disabled:B,onSaved:le},W.id):(0,D.jsx)(ae,{roomId:W.id,disabled:B},W.id)]})]})}var H=class extends Error{status;constructor(e,t){super(t),this.status=e}};function U(e){try{let t=new URL(e);return[`http:`,`https:`].includes(t.protocol)&&!t.username&&!t.password?t.href:null}catch{return null}}function W(){let e=l(),t=_().startsWith(`zh`),[n,i]=(0,T.useState)(null),[o,s]=(0,T.useState)(!1),[ee,d]=(0,T.useState)(!1),[te,f]=(0,T.useState)(!1),[ne,p]=(0,T.useState)(!1),m=(0,T.useRef)(0),h=(0,T.useRef)(null);async function g(e,t){if(h.current)return;let n=++m.current,o=new AbortController;h.current=o,s(!0),d(!1);try{let s=await fetch(r(a(`/api/device-desktop/local/${e}`)),{method:t?`POST`:`GET`,credentials:`same-origin`,signal:o.signal,...t?{headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}:{}});if(m.current!==n||o.signal.aborted)return;if(s.status===403){f(!0),i(null);return}if(!s.ok)throw Error(`Request failed`);let c=await s.json();if(m.current!==n||o.signal.aborted)return;if(e===`permissions`){if(typeof c?.screen!=`boolean`||typeof c?.accessibility!=`boolean`)throw Error(`Invalid permission status`);i(e=>e&&{...e,permissions:{supported:!0,screen:c.screen,accessibility:c.accessibility}}),p(!0)}else{if(typeof c?.os!=`string`||typeof c.enabled!=`boolean`||typeof c.environmentEnabled!=`boolean`||typeof c.supported!=`boolean`)throw Error(`Invalid desktop status`);i(c)}}catch{m.current===n&&!o.signal.aborted&&d(!0)}finally{m.current===n&&!o.signal.aborted&&(h.current=null,s(!1))}}return(0,T.useEffect)(()=>(g(`status`),()=>{m.current++,h.current?.abort(),h.current=null}),[]),(0,D.jsxs)(`section`,{className:`dc-card`,"aria-label":t?`本机远程桌面`:`Local remote desktop`,"aria-busy":o,children:[(0,D.jsxs)(`div`,{className:`dc-card-header`,children:[(0,D.jsx)(`span`,{className:`dc-icon`,children:(0,D.jsx)(c,{"aria-hidden":!0})}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h2`,{children:t?`本机远程桌面`:`Local remote desktop`}),(0,D.jsx)(`p`,{children:t?`管理这台设备的远程桌面与系统权限,无需连接设备中心。`:`Manage remote desktop and system permissions on this device, even while the device center is offline.`})]})]}),te?(0,D.jsx)(`p`,{role:`status`,children:t?`请在设备本机打开此页面以管理远程桌面权限。`:`Open this page on the device itself to manage remote desktop permissions.`}):(0,D.jsxs)(D.Fragment,{children:[n&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`div`,{className:`dc-permission-row`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h3`,{id:`dc-desktop-label`,children:t?`启用远程桌面`:`Enable remote desktop`}),(0,D.jsx)(`p`,{children:n.enabled?t?`已启用`:`Enabled`:t?`未启用`:`Disabled`})]}),(0,D.jsx)(`button`,{type:`button`,className:`dc-toggle${n.enabled?` is-on`:``}`,role:`switch`,"aria-checked":n.enabled,"aria-labelledby":`dc-desktop-label`,disabled:o||n.environmentEnabled||!n.supported&&!n.enabled,onClick:()=>void g(`enable`,{enabled:!n.enabled}),children:(0,D.jsx)(`span`,{className:`dc-toggle-thumb`})})]}),!n.supported&&(0,D.jsx)(`p`,{children:t?`这台设备暂不支持远程桌面。`:`Remote desktop is currently unavailable on this device.`}),n.environmentEnabled&&(0,D.jsx)(`p`,{children:t?`远程桌面由本机服务设置保持启用。`:`Remote desktop is kept enabled by the service settings on this device.`}),n.os===`darwin`&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`p`,{children:t?`点击下方按钮发起系统授权,请在这台 Mac 的系统设置中确认。授权后可能需要重启服务。`:`Use the buttons below to request system permission, then confirm in System Settings on this Mac. You may need to restart the service afterward.`}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[(0,D.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:o||n.permissions?.supported===!1,onClick:()=>void g(`permissions`,{kind:`screen`}),children:t?`授予屏幕录制权限`:`Grant screen recording permission`}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:o||n.permissions?.supported===!1,onClick:()=>void g(`permissions`,{kind:`control`}),children:t?`授予远程控制权限`:`Grant remote control permission`})]}),n.permissions?.screen===!0&&(0,D.jsx)(`p`,{children:t?`屏幕录制:已授权`:`Screen recording: granted`}),n.permissions?.accessibility===!0&&(0,D.jsx)(`p`,{children:t?`远程控制:已授权`:`Remote control: granted`}),ne&&(0,D.jsx)(`p`,{role:`status`,children:t?`已发起授权请求,请确认系统设置后刷新状态。`:`Permission requested. Confirm in System Settings, then refresh the status.`})]})]}),ee&&(0,D.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:t?`无法更新本机远程桌面设置,请重试。`:`Unable to update local remote desktop settings. Please retry.`}),(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:o,onClick:()=>void g(`status`),children:[(0,D.jsx)(u,{"aria-hidden":!0}),o?e(`deviceHubWorking`):t?`刷新远程桌面状态`:`Refresh remote desktop status`]})]})]})}function G({pathCompletions:e=[],plugins:i=[],pluginsEpoch:s=0}){let d=l(),f=ne(_()),[p,g]=(0,T.useState)(`devices`),[y,re]=(0,T.useState)(null),[b,x]=(0,T.useState)(``),[w,ae]=(0,T.useState)(``),[O,j]=(0,T.useState)(null),[M,oe]=(0,T.useState)(Date.now()),[N,P]=(0,T.useState)(null),[se,F]=(0,T.useState)(``),[I,R]=(0,T.useState)(``),[ce,z]=(0,T.useState)(``),[V,G]=(0,T.useState)(!1),K=(0,T.useRef)(!1),[q,le]=(0,T.useState)(!1),[J,ue]=(0,T.useState)(!0),de=(0,T.useRef)(!1),Y=(0,T.useRef)(0),X=(0,T.useRef)(new Set),Z=(0,T.useRef)(!1),fe=(0,T.useRef)(!1),pe=(0,T.useRef)(null),me=(0,T.useRef)(d);me.current=d,(0,T.useEffect)(()=>{let e=e=>{let t=e;t.detail?.deviceId&&pe.current?.deviceId===t.detail.deviceId&&(re(e=>e&&{...e,remark:t.detail.remark}),pe.current&&(pe.current.remark=t.detail.remark))};return window.addEventListener(`pi-web-ui:device-remark-updated`,e),()=>window.removeEventListener(`pi-web-ui:device-remark-updated`,e)},[]);async function he(e,t){let n=new AbortController;X.current.add(n);try{let i=await fetch(r(a(`/api/device-center/${e}`)),{method:t?`POST`:`GET`,credentials:`same-origin`,signal:n.signal,...t?{headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}:{}}),o=await i.json().catch(()=>({}));if(!i.ok)throw new H(i.status,typeof o.error==`string`?o.error:me.current(`deviceHubRequestFailed`,{status:i.status}));return o}finally{X.current.delete(n)}}function Q(e){return de.current&&Y.current===e}function ge(e){return e instanceof H&&e.status===403?(le(!0),me.current(`deviceHubLocalOnly`)):e instanceof Error?e.message:me.current(`deviceHubNetworkError`)}function _e(e){pe.current=e,re(e),fe.current||(ae(e.name),x(e.hubUrl??``))}async function ve(){let e=Y.current;try{let t=await he(`status`);if(!Q(e)||Z.current)return;_e(t),R(``),le(!1)}catch(t){Q(e)&&R(ge(t))}finally{Q(e)&&ue(!1)}}(0,T.useEffect)(()=>{de.current=!0;let e=!1,t,n=async()=>{await ve(),!e&&de.current&&(t=setTimeout(n,5e3))};return n(),()=>{e=!0,de.current=!1,Y.current++,clearTimeout(t);for(let e of X.current)e.abort()}},[]),(0,T.useEffect)(()=>{if(!O)return;let e=Y.current,t=!1,n,r=setInterval(()=>oe(Date.now()),1e3),i=async()=>{if(!(t||!Q(e)||Date.now()>=O.expiresAt)){try{let n=await he(`poll`,{});if(t||!Q(e))return;if(n.paired){let n=await he(`status`);if(t||!Q(e))return;fe.current=!1,_e(n),j(null),F(``),z(``);return}F(``)}catch(n){!t&&Q(e)&&F(`${me.current(`deviceHubPollError`)} ${ge(n)}`)}!t&&Q(e)&&(n=setTimeout(i,2e3))}};return n=setTimeout(i,2e3),()=>{t=!0,clearTimeout(n),clearInterval(r)}},[O]);async function ye(){if(Z.current)return;let e=U(b.trim());if(!e){F(d(`deviceHubInvalidUrl`));return}if(!w.trim()||w.trim().length>80){F(d(`deviceHubInvalidName`));return}let t=++Y.current;Z.current=!0,P(`pair`),F(``),z(``),j(null);try{let n=await he(`pair`,{hubUrl:e,name:w.trim()});if(!Q(t))return;if(!n.code||!Number.isFinite(n.expiresAt)||!U(n.hubUrl))throw Error(d(`deviceHubPairError`));oe(Date.now()),j(n)}catch(e){Q(t)&&F(`${d(`deviceHubPairError`)} ${ge(e)}`)}finally{Q(t)&&(Z.current=!1,P(null))}}async function be(){let e=pe.current;if(!e?.deviceId||Z.current)return;let t=++Y.current;Z.current=!0,P(`permission`),F(``),z(``),_e({...e,allowExecution:!e.allowExecution});try{await he(`execution`,{allowExecution:!e.allowExecution}),Q(t)&&z(d(`deviceHubSaved`))}catch(n){Q(t)&&(_e(e),F(`${d(`deviceHubPermissionError`)} ${ge(n)}`))}finally{Q(t)&&(Z.current=!1,P(null))}}async function xe(){let e=pe.current;if(!e?.deviceId||Z.current||!window.confirm(d(`deviceHubDisconnectConfirm`,{name:e.name})))return;let t=++Y.current;Z.current=!0,P(`disconnect`),F(``),z(``);try{if(await he(`disconnect`,{}),!Q(t))return;fe.current=!1,_e({name:e.name,allowExecution:!1,connected:!1}),j(null)}catch(e){Q(t)&&F(`${d(`deviceHubDisconnectError`)} ${ge(e)}`)}finally{Q(t)&&(Z.current=!1,P(null))}}async function Se(){if(K.current||N||!$||!y?.hubUrl||!window.confirm(d(`deviceHubConfirmUpgrade`)))return;let e=Y.current;K.current=!0,G(!0),F(``),z(``);try{let t=await he(`upgrade-hub`,{});if(!t.ok)throw Error(`Hub upgrade was not accepted`);await E(t.job,{isCurrent:()=>Q(e),poll:async e=>(await he(`upgrade-hub-status`,{id:e})).job}),Q(e)&&(z(d(`deviceHubUpgradeSuccess`)),await ve())}catch(t){Q(e)&&F(t instanceof Error?t.message:d(`deviceHubNetworkError`))}finally{K.current=!1,Q(e)&&G(!1)}}async function Ce(){if(!O)return;let e=Y.current;try{await navigator.clipboard.writeText(O.code),Q(e)&&z(d(`deviceHubCopied`))}catch{Q(e)&&F(d(`deviceHubCopyFailed`))}}let $=!!y?.deviceId,we=U($?y?.hubUrl??``:O?.hubUrl??``),Te=Math.max(0,Math.ceil(((O?.expiresAt??0)-M)/1e3)),Ee=`${Math.floor(Te/60)}:${String(Te%60).padStart(2,`0`)}`,De=we?(0,D.jsxs)(A,{href:we,children:[(0,D.jsx)(t,{"aria-hidden":!0}),d(`deviceHubOpenHub`)]}):null;return(0,D.jsxs)(`section`,{className:`dc-page`,"aria-label":d(`deviceHubTitle`),children:[(0,D.jsxs)(`header`,{className:`dc-header`,children:[(0,D.jsxs)(`div`,{className:`dc-heading`,children:[(0,D.jsxs)(`span`,{className:`dc-eyebrow`,children:[(0,D.jsx)(c,{"aria-hidden":!0}),d(`deviceHubTitle`)]}),(0,D.jsx)(`h1`,{children:d(`deviceHubTitle`)}),(0,D.jsx)(`p`,{children:d(`deviceHubSubtitle`)})]}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[$&&De,(0,D.jsxs)(`span`,{className:`dc-status ${$?y?.connected?`is-online`:`is-offline`:`is-unpaired`}`,children:[(0,D.jsx)(`span`,{className:`dc-status-dot`}),d($?y?.connected?`deviceHubOnline`:`deviceHubOffline`:`deviceHubUnpaired`)]})]})]}),(0,D.jsxs)(`div`,{className:`dc-layout`,children:[(0,D.jsx)(`nav`,{className:`dc-sidebar`,"aria-label":f?`设备与协作导航`:`Devices and collaboration`,children:[[`devices`,c,f?`设备与连接`:`Devices & connections`],[`groups`,m,f?`群组与工单`:`Groups & work items`],[`channels`,te,f?`外部渠道`:`External channels`]].map(([e,t,n])=>(0,D.jsxs)(`button`,{type:`button`,className:`dc-nav-item${p===e?` is-active`:``}`,"aria-pressed":p===e,onClick:()=>g(e),children:[(0,D.jsx)(t,{"aria-hidden":!0}),n]},e))}),(0,D.jsxs)(`main`,{className:`dc-content`,children:[J&&(0,D.jsxs)(`div`,{className:`dc-loading`,role:`status`,children:[(0,D.jsx)(u,{"aria-hidden":!0}),d(`deviceHubLoading`)]}),(q||I)&&(0,D.jsxs)(`div`,{className:`dc-notice is-error`,role:`alert`,children:[(0,D.jsx)(`span`,{children:q?d(`deviceHubLocalOnly`):`${d(`deviceHubStatusError`)} ${I}`}),(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>void ve(),children:[(0,D.jsx)(u,{"aria-hidden":!0}),d(`deviceHubRetry`)]})]}),se&&!q&&(0,D.jsx)(`div`,{className:`dc-notice is-error`,role:`alert`,children:se}),ce&&(0,D.jsxs)(`div`,{className:`dc-notice is-success`,role:`status`,children:[(0,D.jsx)(n,{"aria-hidden":!0}),ce]}),p!==`devices`&&(!$||q)&&(0,D.jsxs)(`section`,{className:`dc-card`,children:[(0,D.jsx)(`h2`,{children:p===`groups`?f?`群组与工单`:`Groups & work items`:f?`外部渠道`:`External channels`}),(0,D.jsx)(`p`,{children:f?`先连接设备中心,再创建群组、配置群组 AI 并接入外部渠道。`:`Connect to a device hub before creating groups, configuring group AI, and connecting external channels.`}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button is-primary`,onClick:()=>g(`devices`),children:f?`前往设备连接`:`Connect a device`})]}),p===`groups`&&$&&!q&&(0,D.jsx)(B,{},`groups:${y?.hubUrl??``}:${y?.deviceId??``}`),p===`channels`&&$&&!q&&(0,D.jsx)(k,{plugin:i.find(e=>e.id===`superagent`),epoch:s,onManageGroups:()=>g(`groups`)},`channels:${y?.hubUrl??``}:${y?.deviceId??``}`),p===`devices`&&(0,D.jsxs)(D.Fragment,{children:[!$&&(y||q)&&(0,D.jsx)(L,{initialHubUrl:b,onConnect:e=>{if(q){z(d(`deviceHubLocalOnly`));return}fe.current=!0,x(e)}}),y&&!q&&!$&&(0,D.jsxs)(`section`,{className:`dc-card`,children:[(0,D.jsxs)(`div`,{className:`dc-card-header`,children:[(0,D.jsx)(`span`,{className:`dc-icon`,children:(0,D.jsx)(v,{"aria-hidden":!0})}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h2`,{children:d(`deviceHubPairTitle`)}),(0,D.jsx)(`p`,{children:d(`deviceHubPairHint`)})]})]}),(0,D.jsx)(`ol`,{className:`dc-steps`,children:[`deviceHubStepDetails`,`deviceHubStepApprove`,`deviceHubStepWait`].map((e,t)=>(0,D.jsxs)(`li`,{className:O?t===0?`is-complete`:`is-active`:t===0?`is-active`:``,children:[(0,D.jsx)(`span`,{className:`dc-step-number`,children:O&&t===0?(0,D.jsx)(n,{"aria-hidden":!0}):t+1}),(0,D.jsx)(`span`,{children:d(e)})]},e))}),(0,D.jsxs)(`form`,{className:`dc-form`,onSubmit:e=>{e.preventDefault(),ye()},children:[(0,D.jsxs)(`div`,{className:`dc-field`,children:[(0,D.jsx)(`label`,{htmlFor:`dc-hub-url`,children:d(`deviceHubHubUrl`)}),(0,D.jsx)(`input`,{id:`dc-hub-url`,type:`url`,autoComplete:`url`,required:!0,placeholder:d(`deviceHubHubPlaceholder`),value:b,disabled:!!O||!!N,onChange:e=>{fe.current=!0,x(e.target.value)}})]}),(0,D.jsxs)(`div`,{className:`dc-field`,children:[(0,D.jsx)(`label`,{htmlFor:`dc-device-name`,children:d(`deviceHubName`)}),(0,D.jsx)(`input`,{id:`dc-device-name`,maxLength:80,required:!0,autoComplete:`off`,placeholder:d(`deviceHubNamePlaceholder`),value:w,disabled:!!O||!!N,onChange:e=>{fe.current=!0,ae(e.target.value)}})]}),!O&&(0,D.jsx)(`div`,{className:`dc-actions`,children:(0,D.jsxs)(`button`,{className:`dc-button is-primary`,type:`submit`,disabled:!!N,children:[(0,D.jsx)(v,{"aria-hidden":!0}),d(N?`deviceHubWorking`:`deviceHubGetCode`)]})})]}),O&&(0,D.jsxs)(`div`,{className:`dc-pairing`,children:[(0,D.jsx)(`span`,{className:`dc-code-label`,children:d(`deviceHubCode`)}),(0,D.jsxs)(`div`,{className:`dc-code-row`,children:[(0,D.jsx)(`code`,{className:`dc-code`,children:O.code}),(0,D.jsx)(`button`,{className:`dc-icon-button`,type:`button`,"aria-label":d(`deviceHubCopy`),onClick:()=>void Ce(),children:(0,D.jsx)(o,{"aria-hidden":!0})})]}),(0,D.jsx)(`div`,{className:`dc-pair-meta`,children:d(Te?`deviceHubExpires`:`deviceHubExpired`,{time:Ee})}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[De,(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:!!N,onClick:()=>{++Y.current,j(null),F(``),z(``)},children:[(0,D.jsx)(u,{"aria-hidden":!0}),d(`deviceHubNewCode`)]})]}),Te>0&&(0,D.jsxs)(`p`,{className:`dc-progress`,role:`status`,children:[(0,D.jsx)(u,{"aria-hidden":!0}),d(`deviceHubWaiting`)]})]})]}),$&&y&&!q&&(0,D.jsxs)(`section`,{className:`dc-card`,children:[(0,D.jsxs)(`div`,{className:`dc-device-summary`,children:[(0,D.jsx)(`span`,{className:`dc-device-icon`,children:(0,D.jsx)(c,{"aria-hidden":!0})}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h2`,{children:y.remark?.trim()||y.name}),(0,D.jsx)(`p`,{children:y.remark?.trim()?`${y.name} · ${d(`deviceHubDeviceTitle`)}`:d(`deviceHubDeviceTitle`)})]})]}),(0,D.jsxs)(`dl`,{className:`dc-details`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`dt`,{children:d(`deviceHubDeviceId`)}),(0,D.jsx)(`dd`,{children:y.deviceId})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`dt`,{children:d(`deviceHubHubUrl`)}),(0,D.jsx)(`dd`,{children:y.hubUrl})]})]}),(0,D.jsx)(`div`,{className:`dc-actions`,style:{marginTop:`1rem`},children:(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:V||!!N,onClick:()=>void Se(),children:[(0,D.jsx)(u,{className:V?`spin`:``,"aria-hidden":!0}),d(V?`deviceHubUpgrading`:`deviceHubUpgradeAction`)]})})]}),$&&y?.hubUrl&&y.deviceId&&!q&&(0,D.jsx)(S,{hubUrl:y.hubUrl,currentDeviceId:y.deviceId},`directory:${y.hubUrl}:${y.deviceId}`),!q&&(0,D.jsx)(ie,{pathCompletions:e},`bots:${y?.hubUrl??``}:${y?.deviceId??`unpaired`}`),(0,D.jsx)(W,{}),$&&y&&!q&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`section`,{className:`dc-card`,children:[(0,D.jsxs)(`div`,{className:`dc-card-header`,children:[(0,D.jsx)(`span`,{className:`dc-icon`,children:(0,D.jsx)(ee,{"aria-hidden":!0})}),(0,D.jsx)(`div`,{children:(0,D.jsx)(`h2`,{children:d(`deviceHubPermissions`)})})]}),(0,D.jsxs)(`div`,{className:`dc-permission-row`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h3`,{id:`dc-permission-label`,children:d(`deviceHubPermissionLabel`)}),(0,D.jsx)(`p`,{id:`dc-permission-hint`,children:d(`deviceHubPermissionHint`)})]}),(0,D.jsx)(`button`,{type:`button`,className:`dc-toggle${y.allowExecution?` is-on`:``}`,role:`switch`,"aria-checked":y.allowExecution,"aria-labelledby":`dc-permission-label`,"aria-describedby":`dc-permission-hint`,disabled:!!N,onClick:()=>void be(),children:(0,D.jsx)(`span`,{className:`dc-toggle-thumb`})})]}),(0,D.jsx)(`p`,{className:`dc-permission-state`,role:`status`,children:d(N===`permission`?`deviceHubSaving`:y.allowExecution?`deviceHubEnabled`:`deviceHubReadOnly`)})]}),(0,D.jsx)(C,{hubUrl:y?.hubUrl,deviceId:y?.deviceId,onNotice:z}),(0,D.jsxs)(`details`,{className:`dc-advanced`,children:[(0,D.jsx)(`summary`,{children:d(`deviceHubAdvanced`)}),(0,D.jsxs)(`div`,{className:`dc-danger-zone`,children:[(0,D.jsx)(`h3`,{children:d(`deviceHubDisconnect`)}),(0,D.jsx)(`p`,{children:d(`deviceHubDisconnectHint`)}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button is-danger`,disabled:!!N,onClick:()=>void xe(),children:d(N===`disconnect`?`deviceHubWorking`:`deviceHubDisconnect`)})]})]})]}),(0,D.jsxs)(`aside`,{className:`dc-help`,children:[(0,D.jsx)(h,{className:`dc-help-icon`,"aria-hidden":!0}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h3`,{children:d(`deviceHubHelpTitle`)}),(0,D.jsx)(`p`,{children:d(`deviceHubHelpText`)})]})]})]})]})]})]})}export{G as DeviceCenter};
|
package/web/dist/assets/{DeviceExecutionSettings-B7R9ONaq.js → DeviceExecutionSettings-qJzbI0Cf.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{A as t,Bn as n,Ct as r,Fn as i,K as a,Qt as o,Tn as s,Ut as c,Vt as l,Wt as u,Zt as d,hn as f,kt as p,ot as m,p as h,z as g}from"./app-globals-CR8Ls9nE.js";import{i as _,t as v}from"./react-CR5VJ85Q.js";var y=e(_(),1),b=v(),x={maxActiveTasks:4,maxWaitingTasks:32,starvationThresholdMs:8e3,maxSkipsBeforeStarvation:3,maxDispatchDepth:8,maxDispatchBudget:16,allowBotMentions:!1,groupContextBytes:262144,groupRetentionLimit:2e3,fileSyncMaxBytes:104857600,fileSyncMaxFiles:1e3,fileSyncStagedBytes:1073741824,resourceLockDefaultTtlMs:18e5,blackboardMaxBytes:262144,taskReportExcerptBytes:131072,maxResourceLocksPerTask:128,botMentionBudgetPerTurn:3};function S(e,t,n,r){return typeof e==`number`&&Number.isFinite(e)?Math.max(t,Math.min(n,Math.round(e))):r}function C(e){if(!Number.isFinite(e)||e<=0)return`0 B`;let t=[`B`,`KiB`,`MiB`,`GiB`],n=0,r=e;for(;r>=1024&&n<t.length-1;)r/=1024,n++;return`${Number.isInteger(r)?r:r.toFixed(1)} ${t[n]}`}function w(e){return!Number.isFinite(e)||e<=0?`0 ms`:e<1e3?`${e} ms`:e<6e4?`${Math.round(e/1e3)} s`:`${(e/6e4).toFixed(1)} min`}function T(e){let t={settings:{...x},activeCount:0,waitingCount:0,blockedCount:0,running:[],waiting:[],blocked:[]};if(!e||typeof e!=`object`||Array.isArray(e))return t;let n=e,r=n.settings&&typeof n.settings==`object`&&!Array.isArray(n.settings)?n.settings:{},i={maxActiveTasks:S(r.maxActiveTasks,1,64,x.maxActiveTasks),maxWaitingTasks:S(r.maxWaitingTasks,0,1024,x.maxWaitingTasks),starvationThresholdMs:S(r.starvationThresholdMs,1e3,6e4,x.starvationThresholdMs),maxSkipsBeforeStarvation:S(r.maxSkipsBeforeStarvation,1,20,x.maxSkipsBeforeStarvation),maxDispatchDepth:S(r.maxDispatchDepth,1,64,x.maxDispatchDepth),maxDispatchBudget:S(r.maxDispatchBudget,1,256,x.maxDispatchBudget),allowBotMentions:typeof r.allowBotMentions==`boolean`?r.allowBotMentions:x.allowBotMentions,groupContextBytes:S(r.groupContextBytes,4096,2097152,x.groupContextBytes),groupRetentionLimit:S(r.groupRetentionLimit,50,2e4,x.groupRetentionLimit),fileSyncMaxBytes:S(r.fileSyncMaxBytes,1048576,10737418240,x.fileSyncMaxBytes),fileSyncMaxFiles:S(r.fileSyncMaxFiles,10,1e4,x.fileSyncMaxFiles),fileSyncStagedBytes:S(r.fileSyncStagedBytes,4194304,53687091200,x.fileSyncStagedBytes),resourceLockDefaultTtlMs:S(r.resourceLockDefaultTtlMs,6e4,864e5,x.resourceLockDefaultTtlMs),blackboardMaxBytes:S(r.blackboardMaxBytes,4096,4194304,x.blackboardMaxBytes),...typeof r.taskReportExcerptBytes==`number`?{taskReportExcerptBytes:r.taskReportExcerptBytes}:{},...typeof r.maxResourceLocksPerTask==`number`?{maxResourceLocksPerTask:r.maxResourceLocksPerTask}:{},...typeof r.botMentionBudgetPerTurn==`number`?{botMentionBudgetPerTurn:r.botMentionBudgetPerTurn}:{}},a=Array.isArray(n.running)?n.running:[],o=Array.isArray(n.waiting)?n.waiting:[],s=Array.isArray(n.blocked)?n.blocked:[];return{settings:i,activeCount:typeof n.activeCount==`number`?n.activeCount:a.length,waitingCount:typeof n.waitingCount==`number`?n.waitingCount:o.length,blockedCount:typeof n.blockedCount==`number`?n.blockedCount:s.length,running:a,waiting:o,blocked:s}}function E({hubUrl:e,deviceId:_,onNotice:v}){let E=s(),[D,O]=(0,y.useState)(null),[k,A]=(0,y.useState)(x),[j,M]=(0,y.useState)(!1),[N,P]=(0,y.useState)(!1),[F,I]=(0,y.useState)(null),[L,R]=(0,y.useState)(null),[z,B]=(0,y.useState)(null),V=(0,y.useRef)(!0),H=(0,y.useRef)(0),U=(0,y.useRef)(new Set),W=(0,y.useRef)(!1),G=(0,y.useRef)(!1),K=`${e??``}:${_??``}`,q=(0,y.useCallback)(async(e,t,r)=>{let a=new AbortController;U.current.add(a);let o=()=>a.abort();r&&(r.aborted?a.abort():r.addEventListener(`abort`,o,{once:!0}));try{let r=await fetch(n(i(`/api/device-center/${e}`)),{method:t?`POST`:`GET`,credentials:`same-origin`,signal:a.signal,headers:t?{"Content-Type":`application/json`}:void 0,body:t?JSON.stringify(t):void 0}),o=await r.json().catch(()=>({}));if(!r.ok){let e=typeof o.error==`string`?o.error:`HTTP ${r.status}`;throw Error(e)}return o}finally{r&&r.removeEventListener(`abort`,o),U.current.delete(a)}},[]),J=(0,y.useCallback)(async(e=!1)=>{if(!V.current||W.current)return;W.current=!0;let t=H.current;e||M(!0);try{let e=await q(`execution-queue`);if(!V.current||t!==H.current)return;let n=T(e);O(n),R(null),G.current||=(A({...n.settings}),!0)}catch(e){if(!V.current||t!==H.current)return;e.name!==`AbortError`&&R(e.message)}finally{W.current=!1,V.current&&t===H.current&&!e&&M(!1)}},[q]);(0,y.useEffect)(()=>{V.current=!0,H.current++;for(let e of U.current)e.abort();U.current.clear(),W.current=!1,G.current=!1,O(null),A({...x}),R(null),B(null),J(!1);let e=setInterval(()=>{J(!0)},3e3);return()=>{V.current=!1,H.current++;for(let e of U.current)e.abort();U.current.clear(),clearInterval(e)}},[K,J]);let Y=(e,t)=>{A(n=>({...n,[e]:t}))},X=(e,t)=>{A(n=>({...n,[e]:t}))},Z=()=>{A({...x})},Q=()=>{D?.settings?A({...D.settings}):A({...x})},$=async e=>{e.preventDefault();let t=H.current;P(!0),R(null),B(null);let n={maxActiveTasks:S(k.maxActiveTasks,1,64,x.maxActiveTasks),maxWaitingTasks:S(k.maxWaitingTasks,0,1024,x.maxWaitingTasks),starvationThresholdMs:S(k.starvationThresholdMs,1e3,6e4,x.starvationThresholdMs),maxSkipsBeforeStarvation:S(k.maxSkipsBeforeStarvation,1,20,x.maxSkipsBeforeStarvation),maxDispatchDepth:S(k.maxDispatchDepth,1,64,x.maxDispatchDepth),maxDispatchBudget:S(k.maxDispatchBudget,1,256,x.maxDispatchBudget),allowBotMentions:!!k.allowBotMentions,groupContextBytes:S(k.groupContextBytes,4096,2097152,x.groupContextBytes),groupRetentionLimit:S(k.groupRetentionLimit,50,2e4,x.groupRetentionLimit),fileSyncMaxBytes:S(k.fileSyncMaxBytes,1048576,10737418240,x.fileSyncMaxBytes),fileSyncMaxFiles:S(k.fileSyncMaxFiles,10,1e4,x.fileSyncMaxFiles),fileSyncStagedBytes:S(k.fileSyncStagedBytes,4194304,53687091200,x.fileSyncStagedBytes),resourceLockDefaultTtlMs:S(k.resourceLockDefaultTtlMs,6e4,864e5,x.resourceLockDefaultTtlMs),blackboardMaxBytes:S(k.blackboardMaxBytes,4096,4194304,x.blackboardMaxBytes),...k.taskReportExcerptBytes===void 0?{}:{taskReportExcerptBytes:k.taskReportExcerptBytes},...k.maxResourceLocksPerTask===void 0?{}:{maxResourceLocksPerTask:k.maxResourceLocksPerTask},...k.botMentionBudgetPerTurn===void 0?{}:{botMentionBudgetPerTurn:k.botMentionBudgetPerTurn}};try{let e=await q(`execution-settings`,n);if(!V.current||t!==H.current)return;e?.settings&&A({...e.settings}),B(E(`deviceExecSavedNotice`)),v?.(E(`deviceExecSavedNotice`)),await J(!0)}catch(e){if(!V.current||t!==H.current)return;e.name!==`AbortError`&&R(e.message)}finally{V.current&&t===H.current&&P(!1)}},ee=async(e,t)=>{let n=H.current;I(e),R(null);try{if(await q(`execution-queue/cancel`,{taskId:e,attemptId:t}),!V.current||n!==H.current)return;v?.(E(`deviceExecTaskCancelled`)),await J(!0)}catch(e){if(!V.current||n!==H.current)return;e.name!==`AbortError`&&R(e.message)}finally{V.current&&n===H.current&&I(null)}},te=e=>{switch(e){case`max_concurrency_reached`:return E(`deviceExecReasonMaxConcurrency`);case`bot_busy`:return E(`deviceExecReasonBotBusy`);case`workspace_conflict`:return E(`deviceExecReasonWorkspaceConflict`);case`workspace_blocked`:return E(`deviceExecReasonWorkspaceBlocked`);case`room_fairness_yield`:return E(`deviceExecReasonFairness`);default:return e}},ne=D?.settings?.maxActiveTasks??x.maxActiveTasks,re=D?.settings?.maxWaitingTasks??x.maxWaitingTasks;return(0,b.jsxs)(`div`,{className:`des-container`,children:[(0,b.jsxs)(`div`,{className:`des-header`,children:[(0,b.jsxs)(`div`,{className:`des-header-left`,children:[(0,b.jsx)(`h3`,{className:`des-title`,children:E(`deviceExecTitle`)}),(0,b.jsx)(`p`,{className:`des-subtitle`,children:E(`deviceExecSubtitle`)})]}),(0,b.jsx)(`button`,{type:`button`,className:`des-refresh-btn`,onClick:()=>void J(!1),disabled:j,title:E(`deviceExecRefresh`),children:(0,b.jsx)(c,{className:j?`des-spin`:``})})]}),L&&(0,b.jsxs)(`div`,{className:`des-alert des-alert-error`,role:`alert`,children:[(0,b.jsx)(h,{className:`des-alert-icon`}),(0,b.jsx)(`div`,{className:`des-alert-text`,children:L}),(0,b.jsx)(`button`,{type:`button`,className:`des-alert-close`,onClick:()=>R(null),children:(0,b.jsx)(f,{})})]}),z&&(0,b.jsxs)(`div`,{className:`des-alert des-alert-success`,role:`status`,children:[(0,b.jsx)(t,{className:`des-alert-icon`}),(0,b.jsx)(`div`,{className:`des-alert-text`,children:z}),(0,b.jsx)(`button`,{type:`button`,className:`des-alert-close`,onClick:()=>B(null),children:(0,b.jsx)(f,{})})]}),(0,b.jsxs)(`div`,{className:`des-stats-row`,children:[(0,b.jsxs)(`div`,{className:`des-stat-card`,children:[(0,b.jsxs)(`div`,{className:`des-stat-label`,children:[(0,b.jsx)(l,{className:`des-stat-icon is-running`}),` `,E(`deviceExecRunning`)]}),(0,b.jsxs)(`div`,{className:`des-stat-value`,children:[D?.activeCount??0,` `,(0,b.jsxs)(`span`,{className:`des-stat-sub`,children:[`/ `,ne]})]})]}),(0,b.jsxs)(`div`,{className:`des-stat-card`,children:[(0,b.jsxs)(`div`,{className:`des-stat-label`,children:[(0,b.jsx)(g,{className:`des-stat-icon is-waiting`}),` `,E(`deviceExecQueued`)]}),(0,b.jsxs)(`div`,{className:`des-stat-value`,children:[D?.waitingCount??0,` `,(0,b.jsxs)(`span`,{className:`des-stat-sub`,children:[`/ `,re]})]})]}),(0,b.jsxs)(`div`,{className:`des-stat-card`,children:[(0,b.jsxs)(`div`,{className:`des-stat-label`,children:[(0,b.jsx)(o,{className:`des-stat-icon is-blocked`}),` `,E(`deviceExecBlocked`)]}),(0,b.jsx)(`div`,{className:`des-stat-value${(D?.blockedCount??0)>0?` is-warn`:``}`,children:D?.blockedCount??0})]})]}),(0,b.jsxs)(`form`,{className:`des-form-card`,onSubmit:e=>void $(e),children:[(0,b.jsxs)(`div`,{className:`des-form-header`,children:[(0,b.jsx)(`h4`,{className:`des-form-title`,children:E(`deviceExecQuotaTitle`)}),(0,b.jsx)(`div`,{className:`des-form-header-actions`,children:(0,b.jsxs)(`button`,{type:`button`,className:`des-btn des-btn-secondary des-btn-sm`,disabled:N,onClick:Z,title:E(`deviceExecResetDefaultsTip`),children:[(0,b.jsx)(u,{className:`des-btn-icon`}),E(`deviceExecResetDefaults`)]})})]}),(0,b.jsxs)(`div`,{className:`des-group`,children:[(0,b.jsxs)(`div`,{className:`des-group-header`,children:[(0,b.jsx)(a,{className:`des-group-icon`}),(0,b.jsx)(`span`,{className:`des-group-title`,children:E(`deviceExecSchedulingTitle`)})]}),(0,b.jsxs)(`div`,{className:`des-fields-row`,children:[(0,b.jsxs)(`div`,{className:`des-field`,children:[(0,b.jsx)(`label`,{htmlFor:`des-max-active`,className:`des-label`,children:E(`deviceExecMaxActive`)}),(0,b.jsx)(`input`,{id:`des-max-active`,type:`number`,min:1,max:64,step:1,className:`des-input`,value:k.maxActiveTasks,onChange:e=>Y(`maxActiveTasks`,parseInt(e.target.value,10)||1),required:!0}),(0,b.jsx)(`span`,{className:`des-hint`,children:E(`deviceExecMaxActiveHint`)})]}),(0,b.jsxs)(`div`,{className:`des-field`,children:[(0,b.jsx)(`label`,{htmlFor:`des-max-waiting`,className:`des-label`,children:E(`deviceExecMaxWaiting`)}),(0,b.jsx)(`input`,{id:`des-max-waiting`,type:`number`,min:0,max:1024,step:1,className:`des-input`,value:k.maxWaitingTasks,onChange:e=>Y(`maxWaitingTasks`,parseInt(e.target.value,10)||0),required:!0}),(0,b.jsx)(`span`,{className:`des-hint`,children:E(`deviceExecMaxWaitingHint`)})]}),(0,b.jsxs)(`div`,{className:`des-field`,children:[(0,b.jsx)(`label`,{htmlFor:`des-starvation-ms`,className:`des-label`,children:E(`deviceExecStarvationMs`)}),(0,b.jsxs)(`div`,{className:`des-input-with-badge`,children:[(0,b.jsx)(`input`,{id:`des-starvation-ms`,type:`number`,min:1e3,max:6e4,step:500,className:`des-input`,value:k.starvationThresholdMs,onChange:e=>Y(`starvationThresholdMs`,parseInt(e.target.value,10)||1e3),required:!0}),(0,b.jsx)(`span`,{className:`des-input-badge`,children:w(k.starvationThresholdMs)})]}),(0,b.jsx)(`span`,{className:`des-hint`,children:E(`deviceExecStarvationMsHint`)})]}),(0,b.jsxs)(`div`,{className:`des-field`,children:[(0,b.jsx)(`label`,{htmlFor:`des-max-skips`,className:`des-label`,children:E(`deviceExecMaxSkips`)}),(0,b.jsx)(`input`,{id:`des-max-skips`,type:`number`,min:1,max:20,step:1,className:`des-input`,value:k.maxSkipsBeforeStarvation,onChange:e=>Y(`maxSkipsBeforeStarvation`,parseInt(e.target.value,10)||1),required:!0}),(0,b.jsx)(`span`,{className:`des-hint`,children:E(`deviceExecMaxSkipsHint`)})]})]})]}),(0,b.jsxs)(`div`,{className:`des-group`,children:[(0,b.jsxs)(`div`,{className:`des-group-header`,children:[(0,b.jsx)(d,{className:`des-group-icon`}),(0,b.jsx)(`span`,{className:`des-group-title`,children:E(`deviceExecDispatchTitle`)})]}),(0,b.jsxs)(`div`,{className:`des-fields-row`,children:[(0,b.jsxs)(`div`,{className:`des-field`,children:[(0,b.jsx)(`label`,{htmlFor:`des-max-depth`,className:`des-label`,children:E(`deviceExecMaxDepth`)}),(0,b.jsx)(`input`,{id:`des-max-depth`,type:`number`,min:1,max:64,step:1,className:`des-input`,value:k.maxDispatchDepth,onChange:e=>Y(`maxDispatchDepth`,parseInt(e.target.value,10)||1),required:!0}),(0,b.jsx)(`span`,{className:`des-hint`,children:E(`deviceExecMaxDepthHint`)})]}),(0,b.jsxs)(`div`,{className:`des-field`,children:[(0,b.jsx)(`label`,{htmlFor:`des-max-budget`,className:`des-label`,children:E(`deviceExecMaxBudget`)}),(0,b.jsx)(`input`,{id:`des-max-budget`,type:`number`,min:1,max:256,step:1,className:`des-input`,value:k.maxDispatchBudget,onChange:e=>Y(`maxDispatchBudget`,parseInt(e.target.value,10)||1),required:!0}),(0,b.jsx)(`span`,{className:`des-hint`,children:E(`deviceExecMaxBudgetHint`)})]}),(0,b.jsxs)(`div`,{className:`des-field des-field-checkbox`,children:[(0,b.jsxs)(`label`,{htmlFor:`des-allow-bot-mentions`,className:`des-checkbox-container`,children:[(0,b.jsx)(`input`,{id:`des-allow-bot-mentions`,type:`checkbox`,className:`des-checkbox`,checked:k.allowBotMentions,onChange:e=>X(`allowBotMentions`,e.target.checked)}),(0,b.jsx)(`span`,{className:`des-label`,children:E(`deviceExecAllowBotMentions`)})]}),(0,b.jsx)(`span`,{className:`des-hint`,children:E(`deviceExecAllowBotMentionsHint`)})]})]})]}),(0,b.jsxs)(`div`,{className:`des-group`,children:[(0,b.jsxs)(`div`,{className:`des-group-header`,children:[(0,b.jsx)(p,{className:`des-group-icon`}),(0,b.jsx)(`span`,{className:`des-group-title`,children:E(`deviceExecContextTitle`)})]}),(0,b.jsxs)(`div`,{className:`des-fields-row`,children:[(0,b.jsxs)(`div`,{className:`des-field`,children:[(0,b.jsx)(`label`,{htmlFor:`des-group-context-bytes`,className:`des-label`,children:E(`deviceExecContextBytes`)}),(0,b.jsxs)(`div`,{className:`des-input-with-badge`,children:[(0,b.jsx)(`input`,{id:`des-group-context-bytes`,type:`number`,min:4096,max:2097152,step:1024,className:`des-input`,value:k.groupContextBytes,onChange:e=>Y(`groupContextBytes`,parseInt(e.target.value,10)||4096),required:!0}),(0,b.jsx)(`span`,{className:`des-input-badge`,children:C(k.groupContextBytes)})]}),(0,b.jsx)(`span`,{className:`des-hint`,children:E(`deviceExecContextBytesHint`)})]}),(0,b.jsxs)(`div`,{className:`des-field`,children:[(0,b.jsx)(`label`,{htmlFor:`des-group-retention`,className:`des-label`,children:E(`deviceExecRetention`)}),(0,b.jsx)(`input`,{id:`des-group-retention`,type:`number`,min:50,max:2e4,step:10,className:`des-input`,value:k.groupRetentionLimit,onChange:e=>Y(`groupRetentionLimit`,parseInt(e.target.value,10)||50),required:!0}),(0,b.jsx)(`span`,{className:`des-hint`,children:E(`deviceExecRetentionHint`)})]})]})]}),(0,b.jsxs)(`div`,{className:`des-group`,children:[(0,b.jsxs)(`div`,{className:`des-group-header`,children:[(0,b.jsx)(m,{className:`des-group-icon`}),(0,b.jsx)(`span`,{className:`des-group-title`,children:E(`deviceExecFileSyncTitle`)})]}),(0,b.jsxs)(`div`,{className:`des-fields-row`,children:[(0,b.jsxs)(`div`,{className:`des-field`,children:[(0,b.jsx)(`label`,{htmlFor:`des-file-sync-bytes`,className:`des-label`,children:E(`deviceExecFileSyncBytes`)}),(0,b.jsxs)(`div`,{className:`des-input-with-badge`,children:[(0,b.jsx)(`input`,{id:`des-file-sync-bytes`,type:`number`,min:1048576,max:10737418240,step:1048576,className:`des-input`,value:k.fileSyncMaxBytes,onChange:e=>Y(`fileSyncMaxBytes`,parseInt(e.target.value,10)||1048576),required:!0}),(0,b.jsx)(`span`,{className:`des-input-badge`,children:C(k.fileSyncMaxBytes)})]}),(0,b.jsx)(`span`,{className:`des-hint`,children:E(`deviceExecFileSyncBytesHint`)})]}),(0,b.jsxs)(`div`,{className:`des-field`,children:[(0,b.jsx)(`label`,{htmlFor:`des-file-sync-files`,className:`des-label`,children:E(`deviceExecFileSyncFiles`)}),(0,b.jsx)(`input`,{id:`des-file-sync-files`,type:`number`,min:10,max:1e4,step:1,className:`des-input`,value:k.fileSyncMaxFiles,onChange:e=>Y(`fileSyncMaxFiles`,parseInt(e.target.value,10)||10),required:!0}),(0,b.jsx)(`span`,{className:`des-hint`,children:E(`deviceExecFileSyncFilesHint`)})]}),(0,b.jsxs)(`div`,{className:`des-field`,children:[(0,b.jsx)(`label`,{htmlFor:`des-file-sync-staged-bytes`,className:`des-label`,children:E(`deviceExecFileSyncStagedBytes`)}),(0,b.jsxs)(`div`,{className:`des-input-with-badge`,children:[(0,b.jsx)(`input`,{id:`des-file-sync-staged-bytes`,type:`number`,min:4194304,max:53687091200,step:1048576,className:`des-input`,value:k.fileSyncStagedBytes,onChange:e=>Y(`fileSyncStagedBytes`,parseInt(e.target.value,10)||4194304),required:!0}),(0,b.jsx)(`span`,{className:`des-input-badge`,children:C(k.fileSyncStagedBytes)})]}),(0,b.jsx)(`span`,{className:`des-hint`,children:E(`deviceExecFileSyncStagedBytesHint`)})]})]})]}),(0,b.jsxs)(`div`,{className:`des-group`,children:[(0,b.jsxs)(`div`,{className:`des-group-header`,children:[(0,b.jsx)(r,{className:`des-group-icon`}),(0,b.jsx)(`span`,{className:`des-group-title`,children:E(`deviceExecLocksTitle`)})]}),(0,b.jsxs)(`div`,{className:`des-fields-row`,children:[(0,b.jsxs)(`div`,{className:`des-field`,children:[(0,b.jsx)(`label`,{htmlFor:`des-resource-lock-ttl`,className:`des-label`,children:E(`deviceExecLockTtl`)}),(0,b.jsxs)(`div`,{className:`des-input-with-badge`,children:[(0,b.jsx)(`input`,{id:`des-resource-lock-ttl`,type:`number`,min:6e4,max:864e5,step:6e4,className:`des-input`,value:k.resourceLockDefaultTtlMs,onChange:e=>Y(`resourceLockDefaultTtlMs`,parseInt(e.target.value,10)||6e4),required:!0}),(0,b.jsx)(`span`,{className:`des-input-badge`,children:w(k.resourceLockDefaultTtlMs)})]}),(0,b.jsx)(`span`,{className:`des-hint`,children:E(`deviceExecLockTtlHint`)})]}),(0,b.jsxs)(`div`,{className:`des-field`,children:[(0,b.jsx)(`label`,{htmlFor:`des-blackboard-bytes`,className:`des-label`,children:E(`deviceExecBlackboardBytes`)}),(0,b.jsxs)(`div`,{className:`des-input-with-badge`,children:[(0,b.jsx)(`input`,{id:`des-blackboard-bytes`,type:`number`,min:4096,max:4194304,step:1024,className:`des-input`,value:k.blackboardMaxBytes,onChange:e=>Y(`blackboardMaxBytes`,parseInt(e.target.value,10)||4096),required:!0}),(0,b.jsx)(`span`,{className:`des-input-badge`,children:C(k.blackboardMaxBytes)})]}),(0,b.jsx)(`span`,{className:`des-hint`,children:E(`deviceExecBlackboardBytesHint`)})]})]})]}),(0,b.jsxs)(`div`,{className:`des-form-actions`,children:[(0,b.jsx)(`button`,{type:`button`,className:`des-btn des-btn-secondary`,disabled:N,onClick:Z,children:E(`deviceExecResetDefaults`)}),(0,b.jsx)(`button`,{type:`button`,className:`des-btn des-btn-secondary`,disabled:N,onClick:Q,children:E(`deviceExecReset`)}),(0,b.jsx)(`button`,{type:`submit`,className:`des-btn des-btn-primary`,disabled:N,children:E(N?`deviceExecSaving`:`deviceExecSave`)})]})]}),D&&D.blocked&&D.blocked.length>0&&(0,b.jsxs)(`div`,{className:`des-section des-blocked-section`,children:[(0,b.jsxs)(`h4`,{className:`des-section-title is-danger`,children:[(0,b.jsx)(h,{}),` `,E(`deviceExecBlockedTitle`)]}),(0,b.jsx)(`p`,{className:`des-section-desc`,children:E(`deviceExecBlockedDesc`)}),(0,b.jsx)(`div`,{className:`des-table-wrap`,children:(0,b.jsxs)(`table`,{className:`des-table`,children:[(0,b.jsx)(`thead`,{children:(0,b.jsxs)(`tr`,{children:[(0,b.jsx)(`th`,{children:`Task ID`}),(0,b.jsx)(`th`,{children:`Room ID`}),(0,b.jsx)(`th`,{children:`Bot ID`}),(0,b.jsx)(`th`,{children:E(`deviceExecReason`)})]})}),(0,b.jsx)(`tbody`,{children:D.blocked.map(e=>(0,b.jsxs)(`tr`,{className:`des-row-blocked`,children:[(0,b.jsxs)(`td`,{className:`des-mono`,children:[e.taskId.slice(0,8),`...`]}),(0,b.jsx)(`td`,{children:e.roomId}),(0,b.jsx)(`td`,{children:e.botId}),(0,b.jsx)(`td`,{children:(0,b.jsx)(`span`,{className:`des-badge is-danger`,children:e.reason})})]},`${e.taskId}-${e.attemptId}`))})]})})]}),(0,b.jsxs)(`div`,{className:`des-section`,children:[(0,b.jsxs)(`h4`,{className:`des-section-title`,children:[(0,b.jsx)(l,{}),` `,E(`deviceExecActiveTasks`),` (`,D?.running?.length??0,`)`]}),D&&D.running&&D.running.length>0?(0,b.jsx)(`div`,{className:`des-table-wrap`,children:(0,b.jsxs)(`table`,{className:`des-table`,children:[(0,b.jsx)(`thead`,{children:(0,b.jsxs)(`tr`,{children:[(0,b.jsx)(`th`,{children:`Task ID`}),(0,b.jsx)(`th`,{children:`Room ID`}),(0,b.jsx)(`th`,{children:`Bot ID`}),(0,b.jsx)(`th`,{children:E(`deviceExecQueuedTime`)})]})}),(0,b.jsx)(`tbody`,{children:D.running.map(e=>(0,b.jsxs)(`tr`,{children:[(0,b.jsxs)(`td`,{className:`des-mono`,title:e.taskId,children:[e.taskId.slice(0,8),`...`]}),(0,b.jsx)(`td`,{children:e.roomId}),(0,b.jsx)(`td`,{children:e.botId}),(0,b.jsx)(`td`,{children:new Date(e.startedAt).toLocaleTimeString()})]},`${e.taskId}-${e.attemptId}`))})]})}):(0,b.jsx)(`div`,{className:`des-empty`,children:E(`deviceExecNoActive`)})]}),(0,b.jsxs)(`div`,{className:`des-section`,children:[(0,b.jsxs)(`h4`,{className:`des-section-title`,children:[(0,b.jsx)(g,{}),` `,E(`deviceExecWaitingQueue`),` (`,D?.waiting?.length??0,`)`]}),D&&D.waiting&&D.waiting.length>0?(0,b.jsx)(`div`,{className:`des-table-wrap`,children:(0,b.jsxs)(`table`,{className:`des-table`,children:[(0,b.jsx)(`thead`,{children:(0,b.jsxs)(`tr`,{children:[(0,b.jsx)(`th`,{children:E(`deviceExecPosition`)}),(0,b.jsx)(`th`,{children:`Task ID`}),(0,b.jsx)(`th`,{children:`Room ID`}),(0,b.jsx)(`th`,{children:`Bot ID`}),(0,b.jsx)(`th`,{children:E(`deviceExecReason`)}),(0,b.jsx)(`th`,{children:E(`deviceExecQueuedTime`)}),(0,b.jsx)(`th`,{children:E(`deviceExecActions`)})]})}),(0,b.jsx)(`tbody`,{children:D.waiting.map(e=>(0,b.jsxs)(`tr`,{children:[(0,b.jsx)(`td`,{children:(0,b.jsxs)(`span`,{className:`des-pos-badge`,children:[`#`,e.queuePosition]})}),(0,b.jsxs)(`td`,{className:`des-mono`,title:e.taskId,children:[e.taskId.slice(0,8),`...`]}),(0,b.jsx)(`td`,{children:e.roomId}),(0,b.jsx)(`td`,{children:e.botId}),(0,b.jsx)(`td`,{children:(0,b.jsxs)(`div`,{className:`des-reason-cell`,children:[(0,b.jsx)(`span`,{className:`des-badge des-badge-${e.blockReason}`,children:te(e.blockReason)}),(0,b.jsx)(`span`,{className:`des-reason-detail`,children:e.blockReasonDetail})]})}),(0,b.jsx)(`td`,{children:new Date(e.queuedAt).toLocaleTimeString()}),(0,b.jsx)(`td`,{children:(0,b.jsx)(`button`,{type:`button`,className:`des-btn des-btn-danger-sm`,disabled:F===e.taskId,onClick:()=>void ee(e.taskId,e.attemptId),children:F===e.taskId?E(`deviceExecCancelling`):E(`deviceExecCancel`)})})]},`${e.taskId}-${e.attemptId}`))})]})}):(0,b.jsx)(`div`,{className:`des-empty`,children:E(`deviceExecNoWaiting`)})]})]})}export{E as t};
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{A as t,Bn as n,Ct as r,Fn as i,K as a,Qt as o,Tn as s,Ut as c,Vt as l,Wt as u,Zt as d,hn as f,kt as p,ot as m,p as h,z as g}from"./app-globals-CBEscsYP.js";import{i as _,t as v}from"./react-CR5VJ85Q.js";var y=e(_(),1),b=v(),x={maxActiveTasks:4,maxWaitingTasks:32,starvationThresholdMs:8e3,maxSkipsBeforeStarvation:3,maxDispatchDepth:8,maxDispatchBudget:16,allowBotMentions:!1,groupContextBytes:262144,groupRetentionLimit:2e3,fileSyncMaxBytes:104857600,fileSyncMaxFiles:1e3,fileSyncStagedBytes:1073741824,resourceLockDefaultTtlMs:18e5,blackboardMaxBytes:262144,taskReportExcerptBytes:131072,maxResourceLocksPerTask:128,botMentionBudgetPerTurn:3};function S(e,t,n,r){return typeof e==`number`&&Number.isFinite(e)?Math.max(t,Math.min(n,Math.round(e))):r}function C(e){if(!Number.isFinite(e)||e<=0)return`0 B`;let t=[`B`,`KiB`,`MiB`,`GiB`],n=0,r=e;for(;r>=1024&&n<t.length-1;)r/=1024,n++;return`${Number.isInteger(r)?r:r.toFixed(1)} ${t[n]}`}function w(e){return!Number.isFinite(e)||e<=0?`0 ms`:e<1e3?`${e} ms`:e<6e4?`${Math.round(e/1e3)} s`:`${(e/6e4).toFixed(1)} min`}function T(e){let t={settings:{...x},activeCount:0,waitingCount:0,blockedCount:0,running:[],waiting:[],blocked:[]};if(!e||typeof e!=`object`||Array.isArray(e))return t;let n=e,r=n.settings&&typeof n.settings==`object`&&!Array.isArray(n.settings)?n.settings:{},i={maxActiveTasks:S(r.maxActiveTasks,1,64,x.maxActiveTasks),maxWaitingTasks:S(r.maxWaitingTasks,0,1024,x.maxWaitingTasks),starvationThresholdMs:S(r.starvationThresholdMs,1e3,6e4,x.starvationThresholdMs),maxSkipsBeforeStarvation:S(r.maxSkipsBeforeStarvation,1,20,x.maxSkipsBeforeStarvation),maxDispatchDepth:S(r.maxDispatchDepth,1,64,x.maxDispatchDepth),maxDispatchBudget:S(r.maxDispatchBudget,1,256,x.maxDispatchBudget),allowBotMentions:typeof r.allowBotMentions==`boolean`?r.allowBotMentions:x.allowBotMentions,groupContextBytes:S(r.groupContextBytes,4096,2097152,x.groupContextBytes),groupRetentionLimit:S(r.groupRetentionLimit,50,2e4,x.groupRetentionLimit),fileSyncMaxBytes:S(r.fileSyncMaxBytes,1048576,10737418240,x.fileSyncMaxBytes),fileSyncMaxFiles:S(r.fileSyncMaxFiles,10,1e4,x.fileSyncMaxFiles),fileSyncStagedBytes:S(r.fileSyncStagedBytes,4194304,53687091200,x.fileSyncStagedBytes),resourceLockDefaultTtlMs:S(r.resourceLockDefaultTtlMs,6e4,864e5,x.resourceLockDefaultTtlMs),blackboardMaxBytes:S(r.blackboardMaxBytes,4096,4194304,x.blackboardMaxBytes),...typeof r.taskReportExcerptBytes==`number`?{taskReportExcerptBytes:r.taskReportExcerptBytes}:{},...typeof r.maxResourceLocksPerTask==`number`?{maxResourceLocksPerTask:r.maxResourceLocksPerTask}:{},...typeof r.botMentionBudgetPerTurn==`number`?{botMentionBudgetPerTurn:r.botMentionBudgetPerTurn}:{}},a=Array.isArray(n.running)?n.running:[],o=Array.isArray(n.waiting)?n.waiting:[],s=Array.isArray(n.blocked)?n.blocked:[];return{settings:i,activeCount:typeof n.activeCount==`number`?n.activeCount:a.length,waitingCount:typeof n.waitingCount==`number`?n.waitingCount:o.length,blockedCount:typeof n.blockedCount==`number`?n.blockedCount:s.length,running:a,waiting:o,blocked:s}}function E({hubUrl:e,deviceId:_,onNotice:v}){let E=s(),[D,O]=(0,y.useState)(null),[k,A]=(0,y.useState)(x),[j,M]=(0,y.useState)(!1),[N,P]=(0,y.useState)(!1),[F,I]=(0,y.useState)(null),[L,R]=(0,y.useState)(null),[z,B]=(0,y.useState)(null),V=(0,y.useRef)(!0),H=(0,y.useRef)(0),U=(0,y.useRef)(new Set),W=(0,y.useRef)(!1),G=(0,y.useRef)(!1),K=`${e??``}:${_??``}`,q=(0,y.useCallback)(async(e,t,r)=>{let a=new AbortController;U.current.add(a);let o=()=>a.abort();r&&(r.aborted?a.abort():r.addEventListener(`abort`,o,{once:!0}));try{let r=await fetch(n(i(`/api/device-center/${e}`)),{method:t?`POST`:`GET`,credentials:`same-origin`,signal:a.signal,headers:t?{"Content-Type":`application/json`}:void 0,body:t?JSON.stringify(t):void 0}),o=await r.json().catch(()=>({}));if(!r.ok){let e=typeof o.error==`string`?o.error:`HTTP ${r.status}`;throw Error(e)}return o}finally{r&&r.removeEventListener(`abort`,o),U.current.delete(a)}},[]),J=(0,y.useCallback)(async(e=!1)=>{if(!V.current||W.current)return;W.current=!0;let t=H.current;e||M(!0);try{let e=await q(`execution-queue`);if(!V.current||t!==H.current)return;let n=T(e);O(n),R(null),G.current||=(A({...n.settings}),!0)}catch(e){if(!V.current||t!==H.current)return;e.name!==`AbortError`&&R(e.message)}finally{W.current=!1,V.current&&t===H.current&&!e&&M(!1)}},[q]);(0,y.useEffect)(()=>{V.current=!0,H.current++;for(let e of U.current)e.abort();U.current.clear(),W.current=!1,G.current=!1,O(null),A({...x}),R(null),B(null),J(!1);let e=setInterval(()=>{J(!0)},3e3);return()=>{V.current=!1,H.current++;for(let e of U.current)e.abort();U.current.clear(),clearInterval(e)}},[K,J]);let Y=(e,t)=>{A(n=>({...n,[e]:t}))},X=(e,t)=>{A(n=>({...n,[e]:t}))},Z=()=>{A({...x})},Q=()=>{D?.settings?A({...D.settings}):A({...x})},$=async e=>{e.preventDefault();let t=H.current;P(!0),R(null),B(null);let n={maxActiveTasks:S(k.maxActiveTasks,1,64,x.maxActiveTasks),maxWaitingTasks:S(k.maxWaitingTasks,0,1024,x.maxWaitingTasks),starvationThresholdMs:S(k.starvationThresholdMs,1e3,6e4,x.starvationThresholdMs),maxSkipsBeforeStarvation:S(k.maxSkipsBeforeStarvation,1,20,x.maxSkipsBeforeStarvation),maxDispatchDepth:S(k.maxDispatchDepth,1,64,x.maxDispatchDepth),maxDispatchBudget:S(k.maxDispatchBudget,1,256,x.maxDispatchBudget),allowBotMentions:!!k.allowBotMentions,groupContextBytes:S(k.groupContextBytes,4096,2097152,x.groupContextBytes),groupRetentionLimit:S(k.groupRetentionLimit,50,2e4,x.groupRetentionLimit),fileSyncMaxBytes:S(k.fileSyncMaxBytes,1048576,10737418240,x.fileSyncMaxBytes),fileSyncMaxFiles:S(k.fileSyncMaxFiles,10,1e4,x.fileSyncMaxFiles),fileSyncStagedBytes:S(k.fileSyncStagedBytes,4194304,53687091200,x.fileSyncStagedBytes),resourceLockDefaultTtlMs:S(k.resourceLockDefaultTtlMs,6e4,864e5,x.resourceLockDefaultTtlMs),blackboardMaxBytes:S(k.blackboardMaxBytes,4096,4194304,x.blackboardMaxBytes),...k.taskReportExcerptBytes===void 0?{}:{taskReportExcerptBytes:k.taskReportExcerptBytes},...k.maxResourceLocksPerTask===void 0?{}:{maxResourceLocksPerTask:k.maxResourceLocksPerTask},...k.botMentionBudgetPerTurn===void 0?{}:{botMentionBudgetPerTurn:k.botMentionBudgetPerTurn}};try{let e=await q(`execution-settings`,n);if(!V.current||t!==H.current)return;e?.settings&&A({...e.settings}),B(E(`deviceExecSavedNotice`)),v?.(E(`deviceExecSavedNotice`)),await J(!0)}catch(e){if(!V.current||t!==H.current)return;e.name!==`AbortError`&&R(e.message)}finally{V.current&&t===H.current&&P(!1)}},ee=async(e,t)=>{let n=H.current;I(e),R(null);try{if(await q(`execution-queue/cancel`,{taskId:e,attemptId:t}),!V.current||n!==H.current)return;v?.(E(`deviceExecTaskCancelled`)),await J(!0)}catch(e){if(!V.current||n!==H.current)return;e.name!==`AbortError`&&R(e.message)}finally{V.current&&n===H.current&&I(null)}},te=e=>{switch(e){case`max_concurrency_reached`:return E(`deviceExecReasonMaxConcurrency`);case`bot_busy`:return E(`deviceExecReasonBotBusy`);case`workspace_conflict`:return E(`deviceExecReasonWorkspaceConflict`);case`workspace_blocked`:return E(`deviceExecReasonWorkspaceBlocked`);case`room_fairness_yield`:return E(`deviceExecReasonFairness`);default:return e}},ne=D?.settings?.maxActiveTasks??x.maxActiveTasks,re=D?.settings?.maxWaitingTasks??x.maxWaitingTasks;return(0,b.jsxs)(`div`,{className:`des-container`,children:[(0,b.jsxs)(`div`,{className:`des-header`,children:[(0,b.jsxs)(`div`,{className:`des-header-left`,children:[(0,b.jsx)(`h3`,{className:`des-title`,children:E(`deviceExecTitle`)}),(0,b.jsx)(`p`,{className:`des-subtitle`,children:E(`deviceExecSubtitle`)})]}),(0,b.jsx)(`button`,{type:`button`,className:`des-refresh-btn`,onClick:()=>void J(!1),disabled:j,title:E(`deviceExecRefresh`),children:(0,b.jsx)(c,{className:j?`des-spin`:``})})]}),L&&(0,b.jsxs)(`div`,{className:`des-alert des-alert-error`,role:`alert`,children:[(0,b.jsx)(h,{className:`des-alert-icon`}),(0,b.jsx)(`div`,{className:`des-alert-text`,children:L}),(0,b.jsx)(`button`,{type:`button`,className:`des-alert-close`,onClick:()=>R(null),children:(0,b.jsx)(f,{})})]}),z&&(0,b.jsxs)(`div`,{className:`des-alert des-alert-success`,role:`status`,children:[(0,b.jsx)(t,{className:`des-alert-icon`}),(0,b.jsx)(`div`,{className:`des-alert-text`,children:z}),(0,b.jsx)(`button`,{type:`button`,className:`des-alert-close`,onClick:()=>B(null),children:(0,b.jsx)(f,{})})]}),(0,b.jsxs)(`div`,{className:`des-stats-row`,children:[(0,b.jsxs)(`div`,{className:`des-stat-card`,children:[(0,b.jsxs)(`div`,{className:`des-stat-label`,children:[(0,b.jsx)(l,{className:`des-stat-icon is-running`}),` `,E(`deviceExecRunning`)]}),(0,b.jsxs)(`div`,{className:`des-stat-value`,children:[D?.activeCount??0,` `,(0,b.jsxs)(`span`,{className:`des-stat-sub`,children:[`/ `,ne]})]})]}),(0,b.jsxs)(`div`,{className:`des-stat-card`,children:[(0,b.jsxs)(`div`,{className:`des-stat-label`,children:[(0,b.jsx)(g,{className:`des-stat-icon is-waiting`}),` `,E(`deviceExecQueued`)]}),(0,b.jsxs)(`div`,{className:`des-stat-value`,children:[D?.waitingCount??0,` `,(0,b.jsxs)(`span`,{className:`des-stat-sub`,children:[`/ `,re]})]})]}),(0,b.jsxs)(`div`,{className:`des-stat-card`,children:[(0,b.jsxs)(`div`,{className:`des-stat-label`,children:[(0,b.jsx)(o,{className:`des-stat-icon is-blocked`}),` `,E(`deviceExecBlocked`)]}),(0,b.jsx)(`div`,{className:`des-stat-value${(D?.blockedCount??0)>0?` is-warn`:``}`,children:D?.blockedCount??0})]})]}),(0,b.jsxs)(`form`,{className:`des-form-card`,onSubmit:e=>void $(e),children:[(0,b.jsxs)(`div`,{className:`des-form-header`,children:[(0,b.jsx)(`h4`,{className:`des-form-title`,children:E(`deviceExecQuotaTitle`)}),(0,b.jsx)(`div`,{className:`des-form-header-actions`,children:(0,b.jsxs)(`button`,{type:`button`,className:`des-btn des-btn-secondary des-btn-sm`,disabled:N,onClick:Z,title:E(`deviceExecResetDefaultsTip`),children:[(0,b.jsx)(u,{className:`des-btn-icon`}),E(`deviceExecResetDefaults`)]})})]}),(0,b.jsxs)(`div`,{className:`des-group`,children:[(0,b.jsxs)(`div`,{className:`des-group-header`,children:[(0,b.jsx)(a,{className:`des-group-icon`}),(0,b.jsx)(`span`,{className:`des-group-title`,children:E(`deviceExecSchedulingTitle`)})]}),(0,b.jsxs)(`div`,{className:`des-fields-row`,children:[(0,b.jsxs)(`div`,{className:`des-field`,children:[(0,b.jsx)(`label`,{htmlFor:`des-max-active`,className:`des-label`,children:E(`deviceExecMaxActive`)}),(0,b.jsx)(`input`,{id:`des-max-active`,type:`number`,min:1,max:64,step:1,className:`des-input`,value:k.maxActiveTasks,onChange:e=>Y(`maxActiveTasks`,parseInt(e.target.value,10)||1),required:!0}),(0,b.jsx)(`span`,{className:`des-hint`,children:E(`deviceExecMaxActiveHint`)})]}),(0,b.jsxs)(`div`,{className:`des-field`,children:[(0,b.jsx)(`label`,{htmlFor:`des-max-waiting`,className:`des-label`,children:E(`deviceExecMaxWaiting`)}),(0,b.jsx)(`input`,{id:`des-max-waiting`,type:`number`,min:0,max:1024,step:1,className:`des-input`,value:k.maxWaitingTasks,onChange:e=>Y(`maxWaitingTasks`,parseInt(e.target.value,10)||0),required:!0}),(0,b.jsx)(`span`,{className:`des-hint`,children:E(`deviceExecMaxWaitingHint`)})]}),(0,b.jsxs)(`div`,{className:`des-field`,children:[(0,b.jsx)(`label`,{htmlFor:`des-starvation-ms`,className:`des-label`,children:E(`deviceExecStarvationMs`)}),(0,b.jsxs)(`div`,{className:`des-input-with-badge`,children:[(0,b.jsx)(`input`,{id:`des-starvation-ms`,type:`number`,min:1e3,max:6e4,step:500,className:`des-input`,value:k.starvationThresholdMs,onChange:e=>Y(`starvationThresholdMs`,parseInt(e.target.value,10)||1e3),required:!0}),(0,b.jsx)(`span`,{className:`des-input-badge`,children:w(k.starvationThresholdMs)})]}),(0,b.jsx)(`span`,{className:`des-hint`,children:E(`deviceExecStarvationMsHint`)})]}),(0,b.jsxs)(`div`,{className:`des-field`,children:[(0,b.jsx)(`label`,{htmlFor:`des-max-skips`,className:`des-label`,children:E(`deviceExecMaxSkips`)}),(0,b.jsx)(`input`,{id:`des-max-skips`,type:`number`,min:1,max:20,step:1,className:`des-input`,value:k.maxSkipsBeforeStarvation,onChange:e=>Y(`maxSkipsBeforeStarvation`,parseInt(e.target.value,10)||1),required:!0}),(0,b.jsx)(`span`,{className:`des-hint`,children:E(`deviceExecMaxSkipsHint`)})]})]})]}),(0,b.jsxs)(`div`,{className:`des-group`,children:[(0,b.jsxs)(`div`,{className:`des-group-header`,children:[(0,b.jsx)(d,{className:`des-group-icon`}),(0,b.jsx)(`span`,{className:`des-group-title`,children:E(`deviceExecDispatchTitle`)})]}),(0,b.jsxs)(`div`,{className:`des-fields-row`,children:[(0,b.jsxs)(`div`,{className:`des-field`,children:[(0,b.jsx)(`label`,{htmlFor:`des-max-depth`,className:`des-label`,children:E(`deviceExecMaxDepth`)}),(0,b.jsx)(`input`,{id:`des-max-depth`,type:`number`,min:1,max:64,step:1,className:`des-input`,value:k.maxDispatchDepth,onChange:e=>Y(`maxDispatchDepth`,parseInt(e.target.value,10)||1),required:!0}),(0,b.jsx)(`span`,{className:`des-hint`,children:E(`deviceExecMaxDepthHint`)})]}),(0,b.jsxs)(`div`,{className:`des-field`,children:[(0,b.jsx)(`label`,{htmlFor:`des-max-budget`,className:`des-label`,children:E(`deviceExecMaxBudget`)}),(0,b.jsx)(`input`,{id:`des-max-budget`,type:`number`,min:1,max:256,step:1,className:`des-input`,value:k.maxDispatchBudget,onChange:e=>Y(`maxDispatchBudget`,parseInt(e.target.value,10)||1),required:!0}),(0,b.jsx)(`span`,{className:`des-hint`,children:E(`deviceExecMaxBudgetHint`)})]}),(0,b.jsxs)(`div`,{className:`des-field des-field-checkbox`,children:[(0,b.jsxs)(`label`,{htmlFor:`des-allow-bot-mentions`,className:`des-checkbox-container`,children:[(0,b.jsx)(`input`,{id:`des-allow-bot-mentions`,type:`checkbox`,className:`des-checkbox`,checked:k.allowBotMentions,onChange:e=>X(`allowBotMentions`,e.target.checked)}),(0,b.jsx)(`span`,{className:`des-label`,children:E(`deviceExecAllowBotMentions`)})]}),(0,b.jsx)(`span`,{className:`des-hint`,children:E(`deviceExecAllowBotMentionsHint`)})]})]})]}),(0,b.jsxs)(`div`,{className:`des-group`,children:[(0,b.jsxs)(`div`,{className:`des-group-header`,children:[(0,b.jsx)(p,{className:`des-group-icon`}),(0,b.jsx)(`span`,{className:`des-group-title`,children:E(`deviceExecContextTitle`)})]}),(0,b.jsxs)(`div`,{className:`des-fields-row`,children:[(0,b.jsxs)(`div`,{className:`des-field`,children:[(0,b.jsx)(`label`,{htmlFor:`des-group-context-bytes`,className:`des-label`,children:E(`deviceExecContextBytes`)}),(0,b.jsxs)(`div`,{className:`des-input-with-badge`,children:[(0,b.jsx)(`input`,{id:`des-group-context-bytes`,type:`number`,min:4096,max:2097152,step:1024,className:`des-input`,value:k.groupContextBytes,onChange:e=>Y(`groupContextBytes`,parseInt(e.target.value,10)||4096),required:!0}),(0,b.jsx)(`span`,{className:`des-input-badge`,children:C(k.groupContextBytes)})]}),(0,b.jsx)(`span`,{className:`des-hint`,children:E(`deviceExecContextBytesHint`)})]}),(0,b.jsxs)(`div`,{className:`des-field`,children:[(0,b.jsx)(`label`,{htmlFor:`des-group-retention`,className:`des-label`,children:E(`deviceExecRetention`)}),(0,b.jsx)(`input`,{id:`des-group-retention`,type:`number`,min:50,max:2e4,step:10,className:`des-input`,value:k.groupRetentionLimit,onChange:e=>Y(`groupRetentionLimit`,parseInt(e.target.value,10)||50),required:!0}),(0,b.jsx)(`span`,{className:`des-hint`,children:E(`deviceExecRetentionHint`)})]})]})]}),(0,b.jsxs)(`div`,{className:`des-group`,children:[(0,b.jsxs)(`div`,{className:`des-group-header`,children:[(0,b.jsx)(m,{className:`des-group-icon`}),(0,b.jsx)(`span`,{className:`des-group-title`,children:E(`deviceExecFileSyncTitle`)})]}),(0,b.jsxs)(`div`,{className:`des-fields-row`,children:[(0,b.jsxs)(`div`,{className:`des-field`,children:[(0,b.jsx)(`label`,{htmlFor:`des-file-sync-bytes`,className:`des-label`,children:E(`deviceExecFileSyncBytes`)}),(0,b.jsxs)(`div`,{className:`des-input-with-badge`,children:[(0,b.jsx)(`input`,{id:`des-file-sync-bytes`,type:`number`,min:1048576,max:10737418240,step:1048576,className:`des-input`,value:k.fileSyncMaxBytes,onChange:e=>Y(`fileSyncMaxBytes`,parseInt(e.target.value,10)||1048576),required:!0}),(0,b.jsx)(`span`,{className:`des-input-badge`,children:C(k.fileSyncMaxBytes)})]}),(0,b.jsx)(`span`,{className:`des-hint`,children:E(`deviceExecFileSyncBytesHint`)})]}),(0,b.jsxs)(`div`,{className:`des-field`,children:[(0,b.jsx)(`label`,{htmlFor:`des-file-sync-files`,className:`des-label`,children:E(`deviceExecFileSyncFiles`)}),(0,b.jsx)(`input`,{id:`des-file-sync-files`,type:`number`,min:10,max:1e4,step:1,className:`des-input`,value:k.fileSyncMaxFiles,onChange:e=>Y(`fileSyncMaxFiles`,parseInt(e.target.value,10)||10),required:!0}),(0,b.jsx)(`span`,{className:`des-hint`,children:E(`deviceExecFileSyncFilesHint`)})]}),(0,b.jsxs)(`div`,{className:`des-field`,children:[(0,b.jsx)(`label`,{htmlFor:`des-file-sync-staged-bytes`,className:`des-label`,children:E(`deviceExecFileSyncStagedBytes`)}),(0,b.jsxs)(`div`,{className:`des-input-with-badge`,children:[(0,b.jsx)(`input`,{id:`des-file-sync-staged-bytes`,type:`number`,min:4194304,max:53687091200,step:1048576,className:`des-input`,value:k.fileSyncStagedBytes,onChange:e=>Y(`fileSyncStagedBytes`,parseInt(e.target.value,10)||4194304),required:!0}),(0,b.jsx)(`span`,{className:`des-input-badge`,children:C(k.fileSyncStagedBytes)})]}),(0,b.jsx)(`span`,{className:`des-hint`,children:E(`deviceExecFileSyncStagedBytesHint`)})]})]})]}),(0,b.jsxs)(`div`,{className:`des-group`,children:[(0,b.jsxs)(`div`,{className:`des-group-header`,children:[(0,b.jsx)(r,{className:`des-group-icon`}),(0,b.jsx)(`span`,{className:`des-group-title`,children:E(`deviceExecLocksTitle`)})]}),(0,b.jsxs)(`div`,{className:`des-fields-row`,children:[(0,b.jsxs)(`div`,{className:`des-field`,children:[(0,b.jsx)(`label`,{htmlFor:`des-resource-lock-ttl`,className:`des-label`,children:E(`deviceExecLockTtl`)}),(0,b.jsxs)(`div`,{className:`des-input-with-badge`,children:[(0,b.jsx)(`input`,{id:`des-resource-lock-ttl`,type:`number`,min:6e4,max:864e5,step:6e4,className:`des-input`,value:k.resourceLockDefaultTtlMs,onChange:e=>Y(`resourceLockDefaultTtlMs`,parseInt(e.target.value,10)||6e4),required:!0}),(0,b.jsx)(`span`,{className:`des-input-badge`,children:w(k.resourceLockDefaultTtlMs)})]}),(0,b.jsx)(`span`,{className:`des-hint`,children:E(`deviceExecLockTtlHint`)})]}),(0,b.jsxs)(`div`,{className:`des-field`,children:[(0,b.jsx)(`label`,{htmlFor:`des-blackboard-bytes`,className:`des-label`,children:E(`deviceExecBlackboardBytes`)}),(0,b.jsxs)(`div`,{className:`des-input-with-badge`,children:[(0,b.jsx)(`input`,{id:`des-blackboard-bytes`,type:`number`,min:4096,max:4194304,step:1024,className:`des-input`,value:k.blackboardMaxBytes,onChange:e=>Y(`blackboardMaxBytes`,parseInt(e.target.value,10)||4096),required:!0}),(0,b.jsx)(`span`,{className:`des-input-badge`,children:C(k.blackboardMaxBytes)})]}),(0,b.jsx)(`span`,{className:`des-hint`,children:E(`deviceExecBlackboardBytesHint`)})]})]})]}),(0,b.jsxs)(`div`,{className:`des-form-actions`,children:[(0,b.jsx)(`button`,{type:`button`,className:`des-btn des-btn-secondary`,disabled:N,onClick:Z,children:E(`deviceExecResetDefaults`)}),(0,b.jsx)(`button`,{type:`button`,className:`des-btn des-btn-secondary`,disabled:N,onClick:Q,children:E(`deviceExecReset`)}),(0,b.jsx)(`button`,{type:`submit`,className:`des-btn des-btn-primary`,disabled:N,children:E(N?`deviceExecSaving`:`deviceExecSave`)})]})]}),D&&D.blocked&&D.blocked.length>0&&(0,b.jsxs)(`div`,{className:`des-section des-blocked-section`,children:[(0,b.jsxs)(`h4`,{className:`des-section-title is-danger`,children:[(0,b.jsx)(h,{}),` `,E(`deviceExecBlockedTitle`)]}),(0,b.jsx)(`p`,{className:`des-section-desc`,children:E(`deviceExecBlockedDesc`)}),(0,b.jsx)(`div`,{className:`des-table-wrap`,children:(0,b.jsxs)(`table`,{className:`des-table`,children:[(0,b.jsx)(`thead`,{children:(0,b.jsxs)(`tr`,{children:[(0,b.jsx)(`th`,{children:`Task ID`}),(0,b.jsx)(`th`,{children:`Room ID`}),(0,b.jsx)(`th`,{children:`Bot ID`}),(0,b.jsx)(`th`,{children:E(`deviceExecReason`)})]})}),(0,b.jsx)(`tbody`,{children:D.blocked.map(e=>(0,b.jsxs)(`tr`,{className:`des-row-blocked`,children:[(0,b.jsxs)(`td`,{className:`des-mono`,children:[e.taskId.slice(0,8),`...`]}),(0,b.jsx)(`td`,{children:e.roomId}),(0,b.jsx)(`td`,{children:e.botId}),(0,b.jsx)(`td`,{children:(0,b.jsx)(`span`,{className:`des-badge is-danger`,children:e.reason})})]},`${e.taskId}-${e.attemptId}`))})]})})]}),(0,b.jsxs)(`div`,{className:`des-section`,children:[(0,b.jsxs)(`h4`,{className:`des-section-title`,children:[(0,b.jsx)(l,{}),` `,E(`deviceExecActiveTasks`),` (`,D?.running?.length??0,`)`]}),D&&D.running&&D.running.length>0?(0,b.jsx)(`div`,{className:`des-table-wrap`,children:(0,b.jsxs)(`table`,{className:`des-table`,children:[(0,b.jsx)(`thead`,{children:(0,b.jsxs)(`tr`,{children:[(0,b.jsx)(`th`,{children:`Task ID`}),(0,b.jsx)(`th`,{children:`Room ID`}),(0,b.jsx)(`th`,{children:`Bot ID`}),(0,b.jsx)(`th`,{children:E(`deviceExecQueuedTime`)})]})}),(0,b.jsx)(`tbody`,{children:D.running.map(e=>(0,b.jsxs)(`tr`,{children:[(0,b.jsxs)(`td`,{className:`des-mono`,title:e.taskId,children:[e.taskId.slice(0,8),`...`]}),(0,b.jsx)(`td`,{children:e.roomId}),(0,b.jsx)(`td`,{children:e.botId}),(0,b.jsx)(`td`,{children:new Date(e.startedAt).toLocaleTimeString()})]},`${e.taskId}-${e.attemptId}`))})]})}):(0,b.jsx)(`div`,{className:`des-empty`,children:E(`deviceExecNoActive`)})]}),(0,b.jsxs)(`div`,{className:`des-section`,children:[(0,b.jsxs)(`h4`,{className:`des-section-title`,children:[(0,b.jsx)(g,{}),` `,E(`deviceExecWaitingQueue`),` (`,D?.waiting?.length??0,`)`]}),D&&D.waiting&&D.waiting.length>0?(0,b.jsx)(`div`,{className:`des-table-wrap`,children:(0,b.jsxs)(`table`,{className:`des-table`,children:[(0,b.jsx)(`thead`,{children:(0,b.jsxs)(`tr`,{children:[(0,b.jsx)(`th`,{children:E(`deviceExecPosition`)}),(0,b.jsx)(`th`,{children:`Task ID`}),(0,b.jsx)(`th`,{children:`Room ID`}),(0,b.jsx)(`th`,{children:`Bot ID`}),(0,b.jsx)(`th`,{children:E(`deviceExecReason`)}),(0,b.jsx)(`th`,{children:E(`deviceExecQueuedTime`)}),(0,b.jsx)(`th`,{children:E(`deviceExecActions`)})]})}),(0,b.jsx)(`tbody`,{children:D.waiting.map(e=>(0,b.jsxs)(`tr`,{children:[(0,b.jsx)(`td`,{children:(0,b.jsxs)(`span`,{className:`des-pos-badge`,children:[`#`,e.queuePosition]})}),(0,b.jsxs)(`td`,{className:`des-mono`,title:e.taskId,children:[e.taskId.slice(0,8),`...`]}),(0,b.jsx)(`td`,{children:e.roomId}),(0,b.jsx)(`td`,{children:e.botId}),(0,b.jsx)(`td`,{children:(0,b.jsxs)(`div`,{className:`des-reason-cell`,children:[(0,b.jsx)(`span`,{className:`des-badge des-badge-${e.blockReason}`,children:te(e.blockReason)}),(0,b.jsx)(`span`,{className:`des-reason-detail`,children:e.blockReasonDetail})]})}),(0,b.jsx)(`td`,{children:new Date(e.queuedAt).toLocaleTimeString()}),(0,b.jsx)(`td`,{children:(0,b.jsx)(`button`,{type:`button`,className:`des-btn des-btn-danger-sm`,disabled:F===e.taskId,onClick:()=>void ee(e.taskId,e.attemptId),children:F===e.taskId?E(`deviceExecCancelling`):E(`deviceExecCancel`)})})]},`${e.taskId}-${e.attemptId}`))})]})}):(0,b.jsx)(`div`,{className:`des-empty`,children:E(`deviceExecNoWaiting`)})]})]})}export{E as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Bn as t,Cn as n,Fn as r,Ht as i,Pt as a,jn as o,kt as s,pn as c,qt as ee}from"./app-globals-CR8Ls9nE.js";import{i as l,r as u,t as d}from"./react-CR5VJ85Q.js";import{t as f}from"./shortcut-stack-hhrDyRBn.js";import{xt as te}from"./index-BYW9d61A.js";import{r as ne,t as re}from"./group-view-state-CGCzYF8k.js";var p=e(l(),1),m=u(),h=d();function ie(e,t){let n=e?.room;if(!n||typeof n.id!=`string`||!n.id||t!==void 0&&n.id!==t||typeof n.name!=`string`||!Array.isArray(n.botIds)||n.botIds.some(e=>typeof e!=`string`))throw Error(`Invalid group detail response`);return e}var ae={zh:{groups:`群聊`,manage:`管理成员`,save:`保存设置`,create:`建群`,name:`群名称`,devices:`选择 Bot(设备仅承载 Bot)`,empty:`还没有群聊,创建一个群开始协作。`,choose:`选择一个群聊`,open:`打开聊天`,online:`在线`,offline:`离线`,cancel:`取消`,loading:`加载中…`,rebind:`设备绑定已失效或已解除,请在设备设置中重新绑定。`,forbidden:`本机访问被拒绝,请检查本机登录状态与访问权限。`,failed:`请求失败`,searchPlaceholder:`搜索群或任务…`,matchedBot:`Bot: `,matchedTask:`任务: `},en:{groups:`Groups`,manage:`Manage members`,save:`Save settings`,create:`Create group`,name:`Group name`,devices:`Select Bots (devices host Bots)`,empty:`No groups yet. Create a group to collaborate.`,choose:`Select a group`,open:`Open chat`,online:`Online`,offline:`Offline`,cancel:`Cancel`,loading:`Loading…`,rebind:`The device binding has expired or was removed. Bind again in device settings.`,forbidden:`Local access denied. Check your local sign-in and access permissions.`,failed:`Request failed`,searchPlaceholder:`Search groups or tasks…`,matchedBot:`Bot: `,matchedTask:`Task: `}},oe=class extends Error{status;code;constructor(e,t,n){super(n),this.status=e,this.code=t}};async function g(e,n,i){let a=await fetch(t(r(`/api/device-center/${e}`)),{method:i?`POST`:`GET`,credentials:`same-origin`,signal:n,...i?{headers:{"Content-Type":`application/json`},body:JSON.stringify(i)}:{}}),o=await a.json().catch(()=>({}));if(!a.ok)throw new oe(a.status,o.code??``,typeof o.error==`string`?o.error:String(a.status));return o}function _(e){window.dispatchEvent(new CustomEvent(`pi-web-ui:device-group-open`,{detail:{roomId:e}}))}function v({onClose:e}){let{locale:t}=n(),r=ae[o(t)?`zh`:`en`];return f(()=>{document.querySelector(`dialog[open]`)||e()}),(0,m.createPortal)((0,h.jsx)(`div`,{className:`modal-backdrop`,onClick:e,children:(0,h.jsx)(`div`,{className:`device-group-create-dialog`,role:`dialog`,"aria-modal":`true`,"aria-label":r.create,onClick:e=>e.stopPropagation(),children:(0,h.jsx)(y,{createOnly:!0,onClose:e})})}),document.body)}function y({active:e=!0,navigation:t,createOnly:r=!1,onClose:l}){let{locale:u}=n(),d=ae[o(u)?`zh`:`en`],[f,m]=(0,p.useState)([]),[v,y]=(0,p.useState)([]),[b,x]=(0,p.useState)(``),[S,C]=(0,p.useState)(null),[w,T]=(0,p.useState)(!0),[E,D]=(0,p.useState)(``),[se,O]=(0,p.useState)(!1),[k,A]=(0,p.useState)(r),[j,M]=(0,p.useState)(!1),[N,P]=(0,p.useState)(!1),[F,I]=(0,p.useState)(``),[L,R]=(0,p.useState)([]),[z,B]=(0,p.useState)(``),[V,H]=(0,p.useState)(!1),[ce,U]=(0,p.useState)(0),[W,le]=(0,p.useState)(``),[ue,de]=(0,p.useState)([]),G=(0,p.useRef)(new re),K=(0,p.useRef)(null),q=(0,p.useRef)(void 0),J=(0,p.useRef)(0),Y=(0,p.useRef)(null),X=(0,p.useRef)(d);X.current=d;function fe(e){let t=X.current;if(e instanceof oe){if(e.status===409&&/^(REPAIR_REQUIRED|NOT_PAIRED|DEVICE_CHANGED)$/.test(e.code)||e.status===403&&/binding|credential|unpaired|revoked|not_bound|hub_forbidden/i.test(e.code))return t.rebind;if(e.status===403)return t.forbidden}return`${t.failed}: ${e instanceof Error?e.message:String(e)}`}function Z(){Y.current?.abort(),Y.current=null,H(!1)}function Q(e,t=!1){++J.current,Z(),x(e),C(null),A(!1),M(t),O(!1),B(``),K.current=t?e:null,R([]),T(!0),D(``),U(e=>e+1)}function pe(){++J.current,Z(),A(!0),O(!1),B(``),M(!1),K.current=null,C(null),R([]),I(``),D(``),U(e=>e+1)}(0,p.useEffect)(()=>{let t=++J.current,n=null,r=!1,i=()=>J.current===t;async function a(){if(!e||document.visibilityState===`hidden`||r)return;r=!0;let t=new AbortController;n=t;try{let[e,n,r]=await Promise.all([g(`bots`,t.signal),g(`rooms`,t.signal),j&&b?g(`rooms/${encodeURIComponent(b)}`,t.signal).then(e=>ie(e,b)):Promise.resolve(null)]);if(!i()||t.signal.aborted)return;if(m(e.bots),y(n.rooms),C(r),r?.tasks){de(r.tasks);for(let e of r.tasks)e.status===`completed`?G.current.onTaskCompleted(e.roomId,e.id):e.status===`failed`&&G.current.onTaskFailed(e.roomId,e.id)}r&&K.current===r.room.id&&(K.current=null,R(r.room.botIds),B(r.room.primaryBotId??``)),D(``)}catch(e){i()&&!t.signal.aborted&&D(fe(e))}finally{t.abort(),r=!1,i()&&T(!1)}}a();let o=window.setInterval(()=>void a(),3e3),s=()=>{document.visibilityState===`hidden`?n?.abort():a()};return document.addEventListener(`visibilitychange`,s),()=>{++J.current,n?.abort(),clearInterval(o),document.removeEventListener(`visibilitychange`,s)}},[e,b,j,ce]),(0,p.useEffect)(()=>()=>Y.current?.abort(),[]),(0,p.useEffect)(()=>{e||Z()},[e]),(0,p.useEffect)(()=>{e&&t&&t.revision!==q.current&&(q.current=t.revision,t.create?pe():t.roomId&&Q(t.roomId,t.manage))},[e,t?.revision]);async function me(){if(!e||Y.current||(k?!F.trim():!S))return;let t=new AbortController;Y.current=t,H(!0),D(``),O(!1);let n=L.includes(z)?z:``,i=k,a=S?.room.id;try{let e=await g(i?`rooms`:`rooms/${encodeURIComponent(a)}/members`,t.signal,{...i?{name:F.trim()}:{},botIds:L,...z&&L.includes(z)?{primaryBotId:z}:!i&&S?.room.primaryBotId?{primaryBotId:null}:{}});if(t.signal.aborted||Y.current!==t)return;let{room:s}=ie(e,i?void 0:a);if((s.primaryBotId??``)!==n)throw Error(o(u)?`中心未保存主 Bot 设置,请更新群组所属的设备中心(Hub)后重试。`:`The Hub did not save the primary Bot setting. Update the group's Hub and retry.`);O(!0),y(e=>[...e.filter(e=>e.id!==s.id),s]),x(s.id),C({room:s}),A(!1),M(!i),I(``),R(i?[]:s.botIds),B(s.primaryBotId??``),U(e=>e+1),window.dispatchEvent(new CustomEvent(`pi-web-ui:device-groups-changed`)),i&&(_(s.id),r&&l?.())}catch(e){!t.signal.aborted&&Y.current===t&&D(fe(e))}finally{Y.current===t&&(Y.current=null,H(!1))}}let $=v.find(e=>e.id===b);return(0,h.jsxs)(`section`,{className:`dg-root`,"aria-label":d.groups,children:[!r&&(0,h.jsxs)(`div`,{className:`dc-card dg-sidebar`,children:[(0,h.jsxs)(`div`,{className:`dg-heading`,children:[(0,h.jsxs)(`h2`,{children:[(0,h.jsx)(c,{}),` `,d.groups]}),(0,h.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:pe,children:[(0,h.jsx)(i,{}),` `,d.create]})]}),(0,h.jsx)(`div`,{className:`dg-search-bar`,style:{padding:`0 10px 8px 10px`},children:(0,h.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`6px`,background:`var(--bg)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`4px 8px`},children:[(0,h.jsx)(ee,{style:{color:`var(--text-dim)`,flex:`none`}}),(0,h.jsx)(`input`,{type:`search`,value:W,onChange:e=>le(e.target.value),placeholder:d.searchPlaceholder,style:{border:`none`,background:`transparent`,color:`var(--text)`,width:`100%`,fontSize:`12px`,outline:`none`}})]})}),(0,h.jsx)(`div`,{className:`dg-rooms`,children:ne(W,v,ue).map(t=>{let n=v.find(e=>e.id===t.roomId);if(!n)return null;let r=G.current.getPendingInteractionsCount(n.id);return(0,h.jsxs)(`button`,{className:`dc-button dg-room`,type:`button`,"aria-current":n.id===b?`page`:void 0,disabled:!e,onClick:()=>{Q(n.id),_(n.id)},children:[(0,h.jsx)(s,{}),(0,h.jsxs)(`span`,{style:{flex:1,minWidth:0,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,textAlign:`left`},children:[n.name,t.matchedBy===`bot_id`&&(0,h.jsxs)(`small`,{style:{display:`block`,color:`var(--text-dim)`,fontSize:`11px`},children:[d.matchedBot,` `,W]}),t.matchedBy===`task_title`&&t.matchedTask&&(0,h.jsxs)(`small`,{style:{display:`block`,color:`var(--accent)`,fontSize:`11px`},children:[d.matchedTask,` `,t.matchedTask.title]}),t.matchedBy===`task_id`&&t.matchedTask&&(0,h.jsxs)(`small`,{style:{display:`block`,color:`var(--text-dim)`,fontSize:`11px`},children:[`ID: `,t.matchedTask.id.slice(0,8)]})]}),r>0&&(0,h.jsx)(`span`,{style:{flex:`none`,background:`var(--accent)`,color:`var(--accent-contrast, #fff)`,borderRadius:`10px`,padding:`1px 6px`,fontSize:`11px`,fontWeight:`bold`},children:r})]},t.matchedTask?`${n.id}:${t.matchedTask.id}`:n.id)})}),!w&&!v.length&&(0,h.jsx)(`p`,{className:`dg-empty`,children:d.empty})]}),(0,h.jsxs)(`div`,{className:`dc-card dg-chat`,children:[se&&(0,h.jsx)(`p`,{role:`status`,children:o(u)?`已保存成员和主 Bot 设置。`:`Members and primary Bot settings saved.`}),E&&(0,h.jsx)(`p`,{className:`dc-error`,role:`alert`,children:E}),w&&(0,h.jsx)(`p`,{role:`status`,children:d.loading}),k||j?(0,h.jsxs)(`form`,{className:`dg-create`,onSubmit:e=>{e.preventDefault(),me()},children:[(0,h.jsx)(`h2`,{children:k?d.create:d.manage}),k&&(0,h.jsxs)(`div`,{className:`dc-field`,children:[(0,h.jsx)(`label`,{htmlFor:`device-group-name`,children:d.name}),(0,h.jsx)(`input`,{id:`device-group-name`,value:F,onChange:e=>I(e.target.value),disabled:V||!e})]}),(0,h.jsxs)(`fieldset`,{disabled:V||!e||j&&!S,children:[(0,h.jsx)(`legend`,{children:d.devices}),f.map(e=>(0,h.jsxs)(`label`,{className:`dg-device`,children:[(0,h.jsx)(`input`,{type:`checkbox`,disabled:!e.enabled&&!L.includes(e.id),checked:L.includes(e.id),onChange:t=>R(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}),(0,h.jsx)(a,{}),(0,h.jsxs)(`span`,{children:[e.name,` · `,e.id,` · `,e.deviceId,` · `,e.online?d.online:d.offline]})]},e.id))]}),!S?.room.router?.enabled&&(0,h.jsxs)(`div`,{className:`dc-field`,children:[(0,h.jsx)(`label`,{htmlFor:`device-group-primary-bot`,children:o(u)?`原主 Bot(Router 未启用时)`:`Legacy primary Bot (when Router is disabled)`}),(0,h.jsxs)(`select`,{id:`device-group-primary-bot`,value:L.includes(z)?z:``,disabled:V||!e||j&&!S,onChange:e=>B(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:o(u)?`不设置(需 @ Bot)`:`None (mention a Bot)`}),f.filter(e=>e.enabled&&L.includes(e.id)).map(e=>(0,h.jsxs)(`option`,{value:e.id,children:[e.name,` · `,e.id]},e.id))]}),(0,h.jsx)(`p`,{children:o(u)?`未启用 Router 时,未 @ Bot 的消息发送给原主 Bot。独立 AI Router 请在群聊顶部配置。`:`When Router is disabled, messages without mentions go to the legacy primary Bot. Configure the independent AI Router from the group chat header.`})]}),S?.room.router?.enabled&&(0,h.jsxs)(`p`,{children:[`AI Router · `,S.room.router.deviceId,` · `,S.room.router.model,` ·`,` `,S.room.router.thinkingLevel]}),(0,h.jsxs)(`div`,{className:`dc-actions`,children:[(0,h.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:V||!e||N,onClick:()=>P(!0),children:[(0,h.jsx)(i,{}),` `,o(u)?`新建 Bot`:`Create Bot`]}),(0,h.jsx)(`button`,{className:`dc-button`,type:`submit`,disabled:V||!e||(k?!F.trim():!S),children:k?d.create:d.save}),(0,h.jsx)(`button`,{className:`dc-button`,type:`button`,onClick:()=>{Z(),K.current=null,r&&l?.(),A(!1),M(!1),D(``)},children:d.cancel})]})]}):$?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`div`,{className:`dg-title`,children:(0,h.jsxs)(`h2`,{children:[(0,h.jsx)(c,{}),` `,$.name]})}),(0,h.jsxs)(`div`,{className:`dc-actions`,children:[(0,h.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:()=>_($.id),children:[(0,h.jsx)(s,{}),d.open]}),(0,h.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:()=>Q($.id,!0),children:[(0,h.jsx)(c,{}),d.manage]})]})]}):(0,h.jsx)(`p`,{className:`dg-empty`,children:d.choose})]}),N&&(0,h.jsx)(te,{createOnly:!0,onCancel:()=>P(!1),onCreated:(e,t)=>{P(!1),t&&e.enabled?(m(t=>[...t.filter(t=>t.id!==e.id),e]),R(t=>[...new Set([...t,e.id])])):D(o(u)?`Bot 已保存;请启用并同步到中心后,再加入群组。`:`Bot saved. Enable and sync it to the hub before adding it to the group.`)}})]})}export{v as DeviceGroupCreateDialog};
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Bn as t,Cn as n,Fn as r,Ht as i,Pt as a,jn as o,kt as s,pn as c,qt as ee}from"./app-globals-CBEscsYP.js";import{i as l,r as u,t as d}from"./react-CR5VJ85Q.js";import{t as f}from"./shortcut-stack-hhrDyRBn.js";import{xt as te}from"./index-BlCxbqqr.js";import{r as ne,t as re}from"./group-view-state-CGCzYF8k.js";var p=e(l(),1),m=u(),h=d();function ie(e,t){let n=e?.room;if(!n||typeof n.id!=`string`||!n.id||t!==void 0&&n.id!==t||typeof n.name!=`string`||!Array.isArray(n.botIds)||n.botIds.some(e=>typeof e!=`string`))throw Error(`Invalid group detail response`);return e}var ae={zh:{groups:`群聊`,manage:`管理成员`,save:`保存设置`,create:`建群`,name:`群名称`,devices:`选择 Bot(设备仅承载 Bot)`,empty:`还没有群聊,创建一个群开始协作。`,choose:`选择一个群聊`,open:`打开聊天`,online:`在线`,offline:`离线`,cancel:`取消`,loading:`加载中…`,rebind:`设备绑定已失效或已解除,请在设备设置中重新绑定。`,forbidden:`本机访问被拒绝,请检查本机登录状态与访问权限。`,failed:`请求失败`,searchPlaceholder:`搜索群或任务…`,matchedBot:`Bot: `,matchedTask:`任务: `},en:{groups:`Groups`,manage:`Manage members`,save:`Save settings`,create:`Create group`,name:`Group name`,devices:`Select Bots (devices host Bots)`,empty:`No groups yet. Create a group to collaborate.`,choose:`Select a group`,open:`Open chat`,online:`Online`,offline:`Offline`,cancel:`Cancel`,loading:`Loading…`,rebind:`The device binding has expired or was removed. Bind again in device settings.`,forbidden:`Local access denied. Check your local sign-in and access permissions.`,failed:`Request failed`,searchPlaceholder:`Search groups or tasks…`,matchedBot:`Bot: `,matchedTask:`Task: `}},oe=class extends Error{status;code;constructor(e,t,n){super(n),this.status=e,this.code=t}};async function g(e,n,i){let a=await fetch(t(r(`/api/device-center/${e}`)),{method:i?`POST`:`GET`,credentials:`same-origin`,signal:n,...i?{headers:{"Content-Type":`application/json`},body:JSON.stringify(i)}:{}}),o=await a.json().catch(()=>({}));if(!a.ok)throw new oe(a.status,o.code??``,typeof o.error==`string`?o.error:String(a.status));return o}function _(e){window.dispatchEvent(new CustomEvent(`pi-web-ui:device-group-open`,{detail:{roomId:e}}))}function v({onClose:e}){let{locale:t}=n(),r=ae[o(t)?`zh`:`en`];return f(()=>{document.querySelector(`dialog[open]`)||e()}),(0,m.createPortal)((0,h.jsx)(`div`,{className:`modal-backdrop`,onClick:e,children:(0,h.jsx)(`div`,{className:`device-group-create-dialog`,role:`dialog`,"aria-modal":`true`,"aria-label":r.create,onClick:e=>e.stopPropagation(),children:(0,h.jsx)(y,{createOnly:!0,onClose:e})})}),document.body)}function y({active:e=!0,navigation:t,createOnly:r=!1,onClose:l}){let{locale:u}=n(),d=ae[o(u)?`zh`:`en`],[f,m]=(0,p.useState)([]),[v,y]=(0,p.useState)([]),[b,x]=(0,p.useState)(``),[S,C]=(0,p.useState)(null),[w,T]=(0,p.useState)(!0),[E,D]=(0,p.useState)(``),[se,O]=(0,p.useState)(!1),[k,A]=(0,p.useState)(r),[j,M]=(0,p.useState)(!1),[N,P]=(0,p.useState)(!1),[F,I]=(0,p.useState)(``),[L,R]=(0,p.useState)([]),[z,B]=(0,p.useState)(``),[V,H]=(0,p.useState)(!1),[ce,U]=(0,p.useState)(0),[W,le]=(0,p.useState)(``),[ue,de]=(0,p.useState)([]),G=(0,p.useRef)(new re),K=(0,p.useRef)(null),q=(0,p.useRef)(void 0),J=(0,p.useRef)(0),Y=(0,p.useRef)(null),X=(0,p.useRef)(d);X.current=d;function fe(e){let t=X.current;if(e instanceof oe){if(e.status===409&&/^(REPAIR_REQUIRED|NOT_PAIRED|DEVICE_CHANGED)$/.test(e.code)||e.status===403&&/binding|credential|unpaired|revoked|not_bound|hub_forbidden/i.test(e.code))return t.rebind;if(e.status===403)return t.forbidden}return`${t.failed}: ${e instanceof Error?e.message:String(e)}`}function Z(){Y.current?.abort(),Y.current=null,H(!1)}function Q(e,t=!1){++J.current,Z(),x(e),C(null),A(!1),M(t),O(!1),B(``),K.current=t?e:null,R([]),T(!0),D(``),U(e=>e+1)}function pe(){++J.current,Z(),A(!0),O(!1),B(``),M(!1),K.current=null,C(null),R([]),I(``),D(``),U(e=>e+1)}(0,p.useEffect)(()=>{let t=++J.current,n=null,r=!1,i=()=>J.current===t;async function a(){if(!e||document.visibilityState===`hidden`||r)return;r=!0;let t=new AbortController;n=t;try{let[e,n,r]=await Promise.all([g(`bots`,t.signal),g(`rooms`,t.signal),j&&b?g(`rooms/${encodeURIComponent(b)}`,t.signal).then(e=>ie(e,b)):Promise.resolve(null)]);if(!i()||t.signal.aborted)return;if(m(e.bots),y(n.rooms),C(r),r?.tasks){de(r.tasks);for(let e of r.tasks)e.status===`completed`?G.current.onTaskCompleted(e.roomId,e.id):e.status===`failed`&&G.current.onTaskFailed(e.roomId,e.id)}r&&K.current===r.room.id&&(K.current=null,R(r.room.botIds),B(r.room.primaryBotId??``)),D(``)}catch(e){i()&&!t.signal.aborted&&D(fe(e))}finally{t.abort(),r=!1,i()&&T(!1)}}a();let o=window.setInterval(()=>void a(),3e3),s=()=>{document.visibilityState===`hidden`?n?.abort():a()};return document.addEventListener(`visibilitychange`,s),()=>{++J.current,n?.abort(),clearInterval(o),document.removeEventListener(`visibilitychange`,s)}},[e,b,j,ce]),(0,p.useEffect)(()=>()=>Y.current?.abort(),[]),(0,p.useEffect)(()=>{e||Z()},[e]),(0,p.useEffect)(()=>{e&&t&&t.revision!==q.current&&(q.current=t.revision,t.create?pe():t.roomId&&Q(t.roomId,t.manage))},[e,t?.revision]);async function me(){if(!e||Y.current||(k?!F.trim():!S))return;let t=new AbortController;Y.current=t,H(!0),D(``),O(!1);let n=L.includes(z)?z:``,i=k,a=S?.room.id;try{let e=await g(i?`rooms`:`rooms/${encodeURIComponent(a)}/members`,t.signal,{...i?{name:F.trim()}:{},botIds:L,...z&&L.includes(z)?{primaryBotId:z}:!i&&S?.room.primaryBotId?{primaryBotId:null}:{}});if(t.signal.aborted||Y.current!==t)return;let{room:s}=ie(e,i?void 0:a);if((s.primaryBotId??``)!==n)throw Error(o(u)?`中心未保存主 Bot 设置,请更新群组所属的设备中心(Hub)后重试。`:`The Hub did not save the primary Bot setting. Update the group's Hub and retry.`);O(!0),y(e=>[...e.filter(e=>e.id!==s.id),s]),x(s.id),C({room:s}),A(!1),M(!i),I(``),R(i?[]:s.botIds),B(s.primaryBotId??``),U(e=>e+1),window.dispatchEvent(new CustomEvent(`pi-web-ui:device-groups-changed`)),i&&(_(s.id),r&&l?.())}catch(e){!t.signal.aborted&&Y.current===t&&D(fe(e))}finally{Y.current===t&&(Y.current=null,H(!1))}}let $=v.find(e=>e.id===b);return(0,h.jsxs)(`section`,{className:`dg-root`,"aria-label":d.groups,children:[!r&&(0,h.jsxs)(`div`,{className:`dc-card dg-sidebar`,children:[(0,h.jsxs)(`div`,{className:`dg-heading`,children:[(0,h.jsxs)(`h2`,{children:[(0,h.jsx)(c,{}),` `,d.groups]}),(0,h.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:pe,children:[(0,h.jsx)(i,{}),` `,d.create]})]}),(0,h.jsx)(`div`,{className:`dg-search-bar`,style:{padding:`0 10px 8px 10px`},children:(0,h.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`6px`,background:`var(--bg)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`4px 8px`},children:[(0,h.jsx)(ee,{style:{color:`var(--text-dim)`,flex:`none`}}),(0,h.jsx)(`input`,{type:`search`,value:W,onChange:e=>le(e.target.value),placeholder:d.searchPlaceholder,style:{border:`none`,background:`transparent`,color:`var(--text)`,width:`100%`,fontSize:`12px`,outline:`none`}})]})}),(0,h.jsx)(`div`,{className:`dg-rooms`,children:ne(W,v,ue).map(t=>{let n=v.find(e=>e.id===t.roomId);if(!n)return null;let r=G.current.getPendingInteractionsCount(n.id);return(0,h.jsxs)(`button`,{className:`dc-button dg-room`,type:`button`,"aria-current":n.id===b?`page`:void 0,disabled:!e,onClick:()=>{Q(n.id),_(n.id)},children:[(0,h.jsx)(s,{}),(0,h.jsxs)(`span`,{style:{flex:1,minWidth:0,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,textAlign:`left`},children:[n.name,t.matchedBy===`bot_id`&&(0,h.jsxs)(`small`,{style:{display:`block`,color:`var(--text-dim)`,fontSize:`11px`},children:[d.matchedBot,` `,W]}),t.matchedBy===`task_title`&&t.matchedTask&&(0,h.jsxs)(`small`,{style:{display:`block`,color:`var(--accent)`,fontSize:`11px`},children:[d.matchedTask,` `,t.matchedTask.title]}),t.matchedBy===`task_id`&&t.matchedTask&&(0,h.jsxs)(`small`,{style:{display:`block`,color:`var(--text-dim)`,fontSize:`11px`},children:[`ID: `,t.matchedTask.id.slice(0,8)]})]}),r>0&&(0,h.jsx)(`span`,{style:{flex:`none`,background:`var(--accent)`,color:`var(--accent-contrast, #fff)`,borderRadius:`10px`,padding:`1px 6px`,fontSize:`11px`,fontWeight:`bold`},children:r})]},t.matchedTask?`${n.id}:${t.matchedTask.id}`:n.id)})}),!w&&!v.length&&(0,h.jsx)(`p`,{className:`dg-empty`,children:d.empty})]}),(0,h.jsxs)(`div`,{className:`dc-card dg-chat`,children:[se&&(0,h.jsx)(`p`,{role:`status`,children:o(u)?`已保存成员和主 Bot 设置。`:`Members and primary Bot settings saved.`}),E&&(0,h.jsx)(`p`,{className:`dc-error`,role:`alert`,children:E}),w&&(0,h.jsx)(`p`,{role:`status`,children:d.loading}),k||j?(0,h.jsxs)(`form`,{className:`dg-create`,onSubmit:e=>{e.preventDefault(),me()},children:[(0,h.jsx)(`h2`,{children:k?d.create:d.manage}),k&&(0,h.jsxs)(`div`,{className:`dc-field`,children:[(0,h.jsx)(`label`,{htmlFor:`device-group-name`,children:d.name}),(0,h.jsx)(`input`,{id:`device-group-name`,value:F,onChange:e=>I(e.target.value),disabled:V||!e})]}),(0,h.jsxs)(`fieldset`,{disabled:V||!e||j&&!S,children:[(0,h.jsx)(`legend`,{children:d.devices}),f.map(e=>(0,h.jsxs)(`label`,{className:`dg-device`,children:[(0,h.jsx)(`input`,{type:`checkbox`,disabled:!e.enabled&&!L.includes(e.id),checked:L.includes(e.id),onChange:t=>R(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}),(0,h.jsx)(a,{}),(0,h.jsxs)(`span`,{children:[e.name,` · `,e.id,` · `,e.deviceId,` · `,e.online?d.online:d.offline]})]},e.id))]}),!S?.room.router?.enabled&&(0,h.jsxs)(`div`,{className:`dc-field`,children:[(0,h.jsx)(`label`,{htmlFor:`device-group-primary-bot`,children:o(u)?`原主 Bot(Router 未启用时)`:`Legacy primary Bot (when Router is disabled)`}),(0,h.jsxs)(`select`,{id:`device-group-primary-bot`,value:L.includes(z)?z:``,disabled:V||!e||j&&!S,onChange:e=>B(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:o(u)?`不设置(需 @ Bot)`:`None (mention a Bot)`}),f.filter(e=>e.enabled&&L.includes(e.id)).map(e=>(0,h.jsxs)(`option`,{value:e.id,children:[e.name,` · `,e.id]},e.id))]}),(0,h.jsx)(`p`,{children:o(u)?`未启用 Router 时,未 @ Bot 的消息发送给原主 Bot。独立 AI Router 请在群聊顶部配置。`:`When Router is disabled, messages without mentions go to the legacy primary Bot. Configure the independent AI Router from the group chat header.`})]}),S?.room.router?.enabled&&(0,h.jsxs)(`p`,{children:[`AI Router · `,S.room.router.deviceId,` · `,S.room.router.model,` ·`,` `,S.room.router.thinkingLevel]}),(0,h.jsxs)(`div`,{className:`dc-actions`,children:[(0,h.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:V||!e||N,onClick:()=>P(!0),children:[(0,h.jsx)(i,{}),` `,o(u)?`新建 Bot`:`Create Bot`]}),(0,h.jsx)(`button`,{className:`dc-button`,type:`submit`,disabled:V||!e||(k?!F.trim():!S),children:k?d.create:d.save}),(0,h.jsx)(`button`,{className:`dc-button`,type:`button`,onClick:()=>{Z(),K.current=null,r&&l?.(),A(!1),M(!1),D(``)},children:d.cancel})]})]}):$?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`div`,{className:`dg-title`,children:(0,h.jsxs)(`h2`,{children:[(0,h.jsx)(c,{}),` `,$.name]})}),(0,h.jsxs)(`div`,{className:`dc-actions`,children:[(0,h.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:()=>_($.id),children:[(0,h.jsx)(s,{}),d.open]}),(0,h.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:()=>Q($.id,!0),children:[(0,h.jsx)(c,{}),d.manage]})]})]}):(0,h.jsx)(`p`,{className:`dg-empty`,children:d.choose})]}),N&&(0,h.jsx)(te,{createOnly:!0,onCancel:()=>P(!1),onCreated:(e,t)=>{P(!1),t&&e.enabled?(m(t=>[...t.filter(t=>t.id!==e.id),e]),R(t=>[...new Set([...t,e.id])])):D(o(u)?`Bot 已保存;请启用并同步到中心后,再加入群组。`:`Bot saved. Enable and sync it to the hub before adding it to the group.`)}})]})}export{v as DeviceGroupCreateDialog};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Bn as t,Cn as n,Fn as r,Ht as i,Pt as a,jn as o,kt as s,pn as c,qt as ee}from"./app-globals-CR8Ls9nE.js";import{i as l,r as u,t as d}from"./react-CR5VJ85Q.js";import{t as f}from"./shortcut-stack-hhrDyRBn.js";import{xt as te}from"./index-BBAQNi6v.js";import{r as ne,t as re}from"./group-view-state-CGCzYF8k.js";var p=e(l(),1),m=u(),h=d();function ie(e,t){let n=e?.room;if(!n||typeof n.id!=`string`||!n.id||t!==void 0&&n.id!==t||typeof n.name!=`string`||!Array.isArray(n.botIds)||n.botIds.some(e=>typeof e!=`string`))throw Error(`Invalid group detail response`);return e}var ae={zh:{groups:`群聊`,manage:`管理成员`,save:`保存设置`,create:`建群`,name:`群名称`,devices:`选择 Bot(设备仅承载 Bot)`,empty:`还没有群聊,创建一个群开始协作。`,choose:`选择一个群聊`,open:`打开聊天`,online:`在线`,offline:`离线`,cancel:`取消`,loading:`加载中…`,rebind:`设备绑定已失效或已解除,请在设备设置中重新绑定。`,forbidden:`本机访问被拒绝,请检查本机登录状态与访问权限。`,failed:`请求失败`,searchPlaceholder:`搜索群或任务…`,matchedBot:`Bot: `,matchedTask:`任务: `},en:{groups:`Groups`,manage:`Manage members`,save:`Save settings`,create:`Create group`,name:`Group name`,devices:`Select Bots (devices host Bots)`,empty:`No groups yet. Create a group to collaborate.`,choose:`Select a group`,open:`Open chat`,online:`Online`,offline:`Offline`,cancel:`Cancel`,loading:`Loading…`,rebind:`The device binding has expired or was removed. Bind again in device settings.`,forbidden:`Local access denied. Check your local sign-in and access permissions.`,failed:`Request failed`,searchPlaceholder:`Search groups or tasks…`,matchedBot:`Bot: `,matchedTask:`Task: `}},oe=class extends Error{status;code;constructor(e,t,n){super(n),this.status=e,this.code=t}};async function g(e,n,i){let a=await fetch(t(r(`/api/device-center/${e}`)),{method:i?`POST`:`GET`,credentials:`same-origin`,signal:n,...i?{headers:{"Content-Type":`application/json`},body:JSON.stringify(i)}:{}}),o=await a.json().catch(()=>({}));if(!a.ok)throw new oe(a.status,o.code??``,typeof o.error==`string`?o.error:String(a.status));return o}function _(e){window.dispatchEvent(new CustomEvent(`pi-web-ui:device-group-open`,{detail:{roomId:e}}))}function v({onClose:e}){let{locale:t}=n(),r=ae[o(t)?`zh`:`en`];return f(()=>{document.querySelector(`dialog[open]`)||e()}),(0,m.createPortal)((0,h.jsx)(`div`,{className:`modal-backdrop`,onClick:e,children:(0,h.jsx)(`div`,{className:`device-group-create-dialog`,role:`dialog`,"aria-modal":`true`,"aria-label":r.create,onClick:e=>e.stopPropagation(),children:(0,h.jsx)(y,{createOnly:!0,onClose:e})})}),document.body)}function y({active:e=!0,navigation:t,createOnly:r=!1,onClose:l}){let{locale:u}=n(),d=ae[o(u)?`zh`:`en`],[f,m]=(0,p.useState)([]),[v,y]=(0,p.useState)([]),[b,x]=(0,p.useState)(``),[S,C]=(0,p.useState)(null),[w,T]=(0,p.useState)(!0),[E,D]=(0,p.useState)(``),[se,O]=(0,p.useState)(!1),[k,A]=(0,p.useState)(r),[j,M]=(0,p.useState)(!1),[N,P]=(0,p.useState)(!1),[F,I]=(0,p.useState)(``),[L,R]=(0,p.useState)([]),[z,B]=(0,p.useState)(``),[V,H]=(0,p.useState)(!1),[ce,U]=(0,p.useState)(0),[W,le]=(0,p.useState)(``),[ue,de]=(0,p.useState)([]),G=(0,p.useRef)(new re),K=(0,p.useRef)(null),q=(0,p.useRef)(void 0),J=(0,p.useRef)(0),Y=(0,p.useRef)(null),X=(0,p.useRef)(d);X.current=d;function fe(e){let t=X.current;if(e instanceof oe){if(e.status===409&&/^(REPAIR_REQUIRED|NOT_PAIRED|DEVICE_CHANGED)$/.test(e.code)||e.status===403&&/binding|credential|unpaired|revoked|not_bound|hub_forbidden/i.test(e.code))return t.rebind;if(e.status===403)return t.forbidden}return`${t.failed}: ${e instanceof Error?e.message:String(e)}`}function Z(){Y.current?.abort(),Y.current=null,H(!1)}function Q(e,t=!1){++J.current,Z(),x(e),C(null),A(!1),M(t),O(!1),B(``),K.current=t?e:null,R([]),T(!0),D(``),U(e=>e+1)}function pe(){++J.current,Z(),A(!0),O(!1),B(``),M(!1),K.current=null,C(null),R([]),I(``),D(``),U(e=>e+1)}(0,p.useEffect)(()=>{let t=++J.current,n=null,r=!1,i=()=>J.current===t;async function a(){if(!e||document.visibilityState===`hidden`||r)return;r=!0;let t=new AbortController;n=t;try{let[e,n,r]=await Promise.all([g(`bots`,t.signal),g(`rooms`,t.signal),j&&b?g(`rooms/${encodeURIComponent(b)}`,t.signal).then(e=>ie(e,b)):Promise.resolve(null)]);if(!i()||t.signal.aborted)return;if(m(e.bots),y(n.rooms),C(r),r?.tasks){de(r.tasks);for(let e of r.tasks)e.status===`completed`?G.current.onTaskCompleted(e.roomId,e.id):e.status===`failed`&&G.current.onTaskFailed(e.roomId,e.id)}r&&K.current===r.room.id&&(K.current=null,R(r.room.botIds),B(r.room.primaryBotId??``)),D(``)}catch(e){i()&&!t.signal.aborted&&D(fe(e))}finally{t.abort(),r=!1,i()&&T(!1)}}a();let o=window.setInterval(()=>void a(),3e3),s=()=>{document.visibilityState===`hidden`?n?.abort():a()};return document.addEventListener(`visibilitychange`,s),()=>{++J.current,n?.abort(),clearInterval(o),document.removeEventListener(`visibilitychange`,s)}},[e,b,j,ce]),(0,p.useEffect)(()=>()=>Y.current?.abort(),[]),(0,p.useEffect)(()=>{e||Z()},[e]),(0,p.useEffect)(()=>{e&&t&&t.revision!==q.current&&(q.current=t.revision,t.create?pe():t.roomId&&Q(t.roomId,t.manage))},[e,t?.revision]);async function me(){if(!e||Y.current||(k?!F.trim():!S))return;let t=new AbortController;Y.current=t,H(!0),D(``),O(!1);let n=L.includes(z)?z:``,i=k,a=S?.room.id;try{let e=await g(i?`rooms`:`rooms/${encodeURIComponent(a)}/members`,t.signal,{...i?{name:F.trim()}:{},botIds:L,...z&&L.includes(z)?{primaryBotId:z}:!i&&S?.room.primaryBotId?{primaryBotId:null}:{}});if(t.signal.aborted||Y.current!==t)return;let{room:s}=ie(e,i?void 0:a);if((s.primaryBotId??``)!==n)throw Error(o(u)?`中心未保存主 Bot 设置,请更新群组所属的设备中心(Hub)后重试。`:`The Hub did not save the primary Bot setting. Update the group's Hub and retry.`);O(!0),y(e=>[...e.filter(e=>e.id!==s.id),s]),x(s.id),C({room:s}),A(!1),M(!i),I(``),R(i?[]:s.botIds),B(s.primaryBotId??``),U(e=>e+1),window.dispatchEvent(new CustomEvent(`pi-web-ui:device-groups-changed`)),i&&(_(s.id),r&&l?.())}catch(e){!t.signal.aborted&&Y.current===t&&D(fe(e))}finally{Y.current===t&&(Y.current=null,H(!1))}}let $=v.find(e=>e.id===b);return(0,h.jsxs)(`section`,{className:`dg-root`,"aria-label":d.groups,children:[!r&&(0,h.jsxs)(`div`,{className:`dc-card dg-sidebar`,children:[(0,h.jsxs)(`div`,{className:`dg-heading`,children:[(0,h.jsxs)(`h2`,{children:[(0,h.jsx)(c,{}),` `,d.groups]}),(0,h.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:pe,children:[(0,h.jsx)(i,{}),` `,d.create]})]}),(0,h.jsx)(`div`,{className:`dg-search-bar`,style:{padding:`0 10px 8px 10px`},children:(0,h.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`6px`,background:`var(--bg)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`4px 8px`},children:[(0,h.jsx)(ee,{style:{color:`var(--text-dim)`,flex:`none`}}),(0,h.jsx)(`input`,{type:`search`,value:W,onChange:e=>le(e.target.value),placeholder:d.searchPlaceholder,style:{border:`none`,background:`transparent`,color:`var(--text)`,width:`100%`,fontSize:`12px`,outline:`none`}})]})}),(0,h.jsx)(`div`,{className:`dg-rooms`,children:ne(W,v,ue).map(t=>{let n=v.find(e=>e.id===t.roomId);if(!n)return null;let r=G.current.getPendingInteractionsCount(n.id);return(0,h.jsxs)(`button`,{className:`dc-button dg-room`,type:`button`,"aria-current":n.id===b?`page`:void 0,disabled:!e,onClick:()=>{Q(n.id),_(n.id)},children:[(0,h.jsx)(s,{}),(0,h.jsxs)(`span`,{style:{flex:1,minWidth:0,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,textAlign:`left`},children:[n.name,t.matchedBy===`bot_id`&&(0,h.jsxs)(`small`,{style:{display:`block`,color:`var(--text-dim)`,fontSize:`11px`},children:[d.matchedBot,` `,W]}),t.matchedBy===`task_title`&&t.matchedTask&&(0,h.jsxs)(`small`,{style:{display:`block`,color:`var(--accent)`,fontSize:`11px`},children:[d.matchedTask,` `,t.matchedTask.title]}),t.matchedBy===`task_id`&&t.matchedTask&&(0,h.jsxs)(`small`,{style:{display:`block`,color:`var(--text-dim)`,fontSize:`11px`},children:[`ID: `,t.matchedTask.id.slice(0,8)]})]}),r>0&&(0,h.jsx)(`span`,{style:{flex:`none`,background:`var(--accent)`,color:`var(--accent-contrast, #fff)`,borderRadius:`10px`,padding:`1px 6px`,fontSize:`11px`,fontWeight:`bold`},children:r})]},t.matchedTask?`${n.id}:${t.matchedTask.id}`:n.id)})}),!w&&!v.length&&(0,h.jsx)(`p`,{className:`dg-empty`,children:d.empty})]}),(0,h.jsxs)(`div`,{className:`dc-card dg-chat`,children:[se&&(0,h.jsx)(`p`,{role:`status`,children:o(u)?`已保存成员和主 Bot 设置。`:`Members and primary Bot settings saved.`}),E&&(0,h.jsx)(`p`,{className:`dc-error`,role:`alert`,children:E}),w&&(0,h.jsx)(`p`,{role:`status`,children:d.loading}),k||j?(0,h.jsxs)(`form`,{className:`dg-create`,onSubmit:e=>{e.preventDefault(),me()},children:[(0,h.jsx)(`h2`,{children:k?d.create:d.manage}),k&&(0,h.jsxs)(`div`,{className:`dc-field`,children:[(0,h.jsx)(`label`,{htmlFor:`device-group-name`,children:d.name}),(0,h.jsx)(`input`,{id:`device-group-name`,value:F,onChange:e=>I(e.target.value),disabled:V||!e})]}),(0,h.jsxs)(`fieldset`,{disabled:V||!e||j&&!S,children:[(0,h.jsx)(`legend`,{children:d.devices}),f.map(e=>(0,h.jsxs)(`label`,{className:`dg-device`,children:[(0,h.jsx)(`input`,{type:`checkbox`,disabled:!e.enabled&&!L.includes(e.id),checked:L.includes(e.id),onChange:t=>R(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}),(0,h.jsx)(a,{}),(0,h.jsxs)(`span`,{children:[e.name,` · `,e.id,` · `,e.deviceId,` · `,e.online?d.online:d.offline]})]},e.id))]}),!S?.room.router?.enabled&&(0,h.jsxs)(`div`,{className:`dc-field`,children:[(0,h.jsx)(`label`,{htmlFor:`device-group-primary-bot`,children:o(u)?`原主 Bot(Router 未启用时)`:`Legacy primary Bot (when Router is disabled)`}),(0,h.jsxs)(`select`,{id:`device-group-primary-bot`,value:L.includes(z)?z:``,disabled:V||!e||j&&!S,onChange:e=>B(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:o(u)?`不设置(需 @ Bot)`:`None (mention a Bot)`}),f.filter(e=>e.enabled&&L.includes(e.id)).map(e=>(0,h.jsxs)(`option`,{value:e.id,children:[e.name,` · `,e.id]},e.id))]}),(0,h.jsx)(`p`,{children:o(u)?`未启用 Router 时,未 @ Bot 的消息发送给原主 Bot。独立 AI Router 请在群聊顶部配置。`:`When Router is disabled, messages without mentions go to the legacy primary Bot. Configure the independent AI Router from the group chat header.`})]}),S?.room.router?.enabled&&(0,h.jsxs)(`p`,{children:[`AI Router · `,S.room.router.deviceId,` · `,S.room.router.model,` ·`,` `,S.room.router.thinkingLevel]}),(0,h.jsxs)(`div`,{className:`dc-actions`,children:[(0,h.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:V||!e||N,onClick:()=>P(!0),children:[(0,h.jsx)(i,{}),` `,o(u)?`新建 Bot`:`Create Bot`]}),(0,h.jsx)(`button`,{className:`dc-button`,type:`submit`,disabled:V||!e||(k?!F.trim():!S),children:k?d.create:d.save}),(0,h.jsx)(`button`,{className:`dc-button`,type:`button`,onClick:()=>{Z(),K.current=null,r&&l?.(),A(!1),M(!1),D(``)},children:d.cancel})]})]}):$?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`div`,{className:`dg-title`,children:(0,h.jsxs)(`h2`,{children:[(0,h.jsx)(c,{}),` `,$.name]})}),(0,h.jsxs)(`div`,{className:`dc-actions`,children:[(0,h.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:()=>_($.id),children:[(0,h.jsx)(s,{}),d.open]}),(0,h.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:()=>Q($.id,!0),children:[(0,h.jsx)(c,{}),d.manage]})]})]}):(0,h.jsx)(`p`,{className:`dg-empty`,children:d.choose})]}),N&&(0,h.jsx)(te,{createOnly:!0,onCancel:()=>P(!1),onCreated:(e,t)=>{P(!1),t&&e.enabled?(m(t=>[...t.filter(t=>t.id!==e.id),e]),R(t=>[...new Set([...t,e.id])])):D(o(u)?`Bot 已保存;请启用并同步到中心后,再加入群组。`:`Bot saved. Enable and sync it to the hub before adding it to the group.`)}})]})}export{v as DeviceGroupCreateDialog};
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Bn as t,Cn as n,Fn as r,Ht as i,Pt as a,jn as o,kt as s,pn as c,qt as ee}from"./app-globals-CBEscsYP.js";import{i as l,r as u,t as d}from"./react-CR5VJ85Q.js";import{t as f}from"./shortcut-stack-hhrDyRBn.js";import{xt as te}from"./index-BD29OL9L.js";import{r as ne,t as re}from"./group-view-state-CGCzYF8k.js";var p=e(l(),1),m=u(),h=d();function ie(e,t){let n=e?.room;if(!n||typeof n.id!=`string`||!n.id||t!==void 0&&n.id!==t||typeof n.name!=`string`||!Array.isArray(n.botIds)||n.botIds.some(e=>typeof e!=`string`))throw Error(`Invalid group detail response`);return e}var ae={zh:{groups:`群聊`,manage:`管理成员`,save:`保存设置`,create:`建群`,name:`群名称`,devices:`选择 Bot(设备仅承载 Bot)`,empty:`还没有群聊,创建一个群开始协作。`,choose:`选择一个群聊`,open:`打开聊天`,online:`在线`,offline:`离线`,cancel:`取消`,loading:`加载中…`,rebind:`设备绑定已失效或已解除,请在设备设置中重新绑定。`,forbidden:`本机访问被拒绝,请检查本机登录状态与访问权限。`,failed:`请求失败`,searchPlaceholder:`搜索群或任务…`,matchedBot:`Bot: `,matchedTask:`任务: `},en:{groups:`Groups`,manage:`Manage members`,save:`Save settings`,create:`Create group`,name:`Group name`,devices:`Select Bots (devices host Bots)`,empty:`No groups yet. Create a group to collaborate.`,choose:`Select a group`,open:`Open chat`,online:`Online`,offline:`Offline`,cancel:`Cancel`,loading:`Loading…`,rebind:`The device binding has expired or was removed. Bind again in device settings.`,forbidden:`Local access denied. Check your local sign-in and access permissions.`,failed:`Request failed`,searchPlaceholder:`Search groups or tasks…`,matchedBot:`Bot: `,matchedTask:`Task: `}},oe=class extends Error{status;code;constructor(e,t,n){super(n),this.status=e,this.code=t}};async function g(e,n,i){let a=await fetch(t(r(`/api/device-center/${e}`)),{method:i?`POST`:`GET`,credentials:`same-origin`,signal:n,...i?{headers:{"Content-Type":`application/json`},body:JSON.stringify(i)}:{}}),o=await a.json().catch(()=>({}));if(!a.ok)throw new oe(a.status,o.code??``,typeof o.error==`string`?o.error:String(a.status));return o}function _(e){window.dispatchEvent(new CustomEvent(`pi-web-ui:device-group-open`,{detail:{roomId:e}}))}function v({onClose:e}){let{locale:t}=n(),r=ae[o(t)?`zh`:`en`];return f(()=>{document.querySelector(`dialog[open]`)||e()}),(0,m.createPortal)((0,h.jsx)(`div`,{className:`modal-backdrop`,onClick:e,children:(0,h.jsx)(`div`,{className:`device-group-create-dialog`,role:`dialog`,"aria-modal":`true`,"aria-label":r.create,onClick:e=>e.stopPropagation(),children:(0,h.jsx)(y,{createOnly:!0,onClose:e})})}),document.body)}function y({active:e=!0,navigation:t,createOnly:r=!1,onClose:l}){let{locale:u}=n(),d=ae[o(u)?`zh`:`en`],[f,m]=(0,p.useState)([]),[v,y]=(0,p.useState)([]),[b,x]=(0,p.useState)(``),[S,C]=(0,p.useState)(null),[w,T]=(0,p.useState)(!0),[E,D]=(0,p.useState)(``),[se,O]=(0,p.useState)(!1),[k,A]=(0,p.useState)(r),[j,M]=(0,p.useState)(!1),[N,P]=(0,p.useState)(!1),[F,I]=(0,p.useState)(``),[L,R]=(0,p.useState)([]),[z,B]=(0,p.useState)(``),[V,H]=(0,p.useState)(!1),[ce,U]=(0,p.useState)(0),[W,le]=(0,p.useState)(``),[ue,de]=(0,p.useState)([]),G=(0,p.useRef)(new re),K=(0,p.useRef)(null),q=(0,p.useRef)(void 0),J=(0,p.useRef)(0),Y=(0,p.useRef)(null),X=(0,p.useRef)(d);X.current=d;function fe(e){let t=X.current;if(e instanceof oe){if(e.status===409&&/^(REPAIR_REQUIRED|NOT_PAIRED|DEVICE_CHANGED)$/.test(e.code)||e.status===403&&/binding|credential|unpaired|revoked|not_bound|hub_forbidden/i.test(e.code))return t.rebind;if(e.status===403)return t.forbidden}return`${t.failed}: ${e instanceof Error?e.message:String(e)}`}function Z(){Y.current?.abort(),Y.current=null,H(!1)}function Q(e,t=!1){++J.current,Z(),x(e),C(null),A(!1),M(t),O(!1),B(``),K.current=t?e:null,R([]),T(!0),D(``),U(e=>e+1)}function pe(){++J.current,Z(),A(!0),O(!1),B(``),M(!1),K.current=null,C(null),R([]),I(``),D(``),U(e=>e+1)}(0,p.useEffect)(()=>{let t=++J.current,n=null,r=!1,i=()=>J.current===t;async function a(){if(!e||document.visibilityState===`hidden`||r)return;r=!0;let t=new AbortController;n=t;try{let[e,n,r]=await Promise.all([g(`bots`,t.signal),g(`rooms`,t.signal),j&&b?g(`rooms/${encodeURIComponent(b)}`,t.signal).then(e=>ie(e,b)):Promise.resolve(null)]);if(!i()||t.signal.aborted)return;if(m(e.bots),y(n.rooms),C(r),r?.tasks){de(r.tasks);for(let e of r.tasks)e.status===`completed`?G.current.onTaskCompleted(e.roomId,e.id):e.status===`failed`&&G.current.onTaskFailed(e.roomId,e.id)}r&&K.current===r.room.id&&(K.current=null,R(r.room.botIds),B(r.room.primaryBotId??``)),D(``)}catch(e){i()&&!t.signal.aborted&&D(fe(e))}finally{t.abort(),r=!1,i()&&T(!1)}}a();let o=window.setInterval(()=>void a(),3e3),s=()=>{document.visibilityState===`hidden`?n?.abort():a()};return document.addEventListener(`visibilitychange`,s),()=>{++J.current,n?.abort(),clearInterval(o),document.removeEventListener(`visibilitychange`,s)}},[e,b,j,ce]),(0,p.useEffect)(()=>()=>Y.current?.abort(),[]),(0,p.useEffect)(()=>{e||Z()},[e]),(0,p.useEffect)(()=>{e&&t&&t.revision!==q.current&&(q.current=t.revision,t.create?pe():t.roomId&&Q(t.roomId,t.manage))},[e,t?.revision]);async function me(){if(!e||Y.current||(k?!F.trim():!S))return;let t=new AbortController;Y.current=t,H(!0),D(``),O(!1);let n=L.includes(z)?z:``,i=k,a=S?.room.id;try{let e=await g(i?`rooms`:`rooms/${encodeURIComponent(a)}/members`,t.signal,{...i?{name:F.trim()}:{},botIds:L,...z&&L.includes(z)?{primaryBotId:z}:!i&&S?.room.primaryBotId?{primaryBotId:null}:{}});if(t.signal.aborted||Y.current!==t)return;let{room:s}=ie(e,i?void 0:a);if((s.primaryBotId??``)!==n)throw Error(o(u)?`中心未保存主 Bot 设置,请更新群组所属的设备中心(Hub)后重试。`:`The Hub did not save the primary Bot setting. Update the group's Hub and retry.`);O(!0),y(e=>[...e.filter(e=>e.id!==s.id),s]),x(s.id),C({room:s}),A(!1),M(!i),I(``),R(i?[]:s.botIds),B(s.primaryBotId??``),U(e=>e+1),window.dispatchEvent(new CustomEvent(`pi-web-ui:device-groups-changed`)),i&&(_(s.id),r&&l?.())}catch(e){!t.signal.aborted&&Y.current===t&&D(fe(e))}finally{Y.current===t&&(Y.current=null,H(!1))}}let $=v.find(e=>e.id===b);return(0,h.jsxs)(`section`,{className:`dg-root`,"aria-label":d.groups,children:[!r&&(0,h.jsxs)(`div`,{className:`dc-card dg-sidebar`,children:[(0,h.jsxs)(`div`,{className:`dg-heading`,children:[(0,h.jsxs)(`h2`,{children:[(0,h.jsx)(c,{}),` `,d.groups]}),(0,h.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:pe,children:[(0,h.jsx)(i,{}),` `,d.create]})]}),(0,h.jsx)(`div`,{className:`dg-search-bar`,style:{padding:`0 10px 8px 10px`},children:(0,h.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`6px`,background:`var(--bg)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`4px 8px`},children:[(0,h.jsx)(ee,{style:{color:`var(--text-dim)`,flex:`none`}}),(0,h.jsx)(`input`,{type:`search`,value:W,onChange:e=>le(e.target.value),placeholder:d.searchPlaceholder,style:{border:`none`,background:`transparent`,color:`var(--text)`,width:`100%`,fontSize:`12px`,outline:`none`}})]})}),(0,h.jsx)(`div`,{className:`dg-rooms`,children:ne(W,v,ue).map(t=>{let n=v.find(e=>e.id===t.roomId);if(!n)return null;let r=G.current.getPendingInteractionsCount(n.id);return(0,h.jsxs)(`button`,{className:`dc-button dg-room`,type:`button`,"aria-current":n.id===b?`page`:void 0,disabled:!e,onClick:()=>{Q(n.id),_(n.id)},children:[(0,h.jsx)(s,{}),(0,h.jsxs)(`span`,{style:{flex:1,minWidth:0,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,textAlign:`left`},children:[n.name,t.matchedBy===`bot_id`&&(0,h.jsxs)(`small`,{style:{display:`block`,color:`var(--text-dim)`,fontSize:`11px`},children:[d.matchedBot,` `,W]}),t.matchedBy===`task_title`&&t.matchedTask&&(0,h.jsxs)(`small`,{style:{display:`block`,color:`var(--accent)`,fontSize:`11px`},children:[d.matchedTask,` `,t.matchedTask.title]}),t.matchedBy===`task_id`&&t.matchedTask&&(0,h.jsxs)(`small`,{style:{display:`block`,color:`var(--text-dim)`,fontSize:`11px`},children:[`ID: `,t.matchedTask.id.slice(0,8)]})]}),r>0&&(0,h.jsx)(`span`,{style:{flex:`none`,background:`var(--accent)`,color:`var(--accent-contrast, #fff)`,borderRadius:`10px`,padding:`1px 6px`,fontSize:`11px`,fontWeight:`bold`},children:r})]},t.matchedTask?`${n.id}:${t.matchedTask.id}`:n.id)})}),!w&&!v.length&&(0,h.jsx)(`p`,{className:`dg-empty`,children:d.empty})]}),(0,h.jsxs)(`div`,{className:`dc-card dg-chat`,children:[se&&(0,h.jsx)(`p`,{role:`status`,children:o(u)?`已保存成员和主 Bot 设置。`:`Members and primary Bot settings saved.`}),E&&(0,h.jsx)(`p`,{className:`dc-error`,role:`alert`,children:E}),w&&(0,h.jsx)(`p`,{role:`status`,children:d.loading}),k||j?(0,h.jsxs)(`form`,{className:`dg-create`,onSubmit:e=>{e.preventDefault(),me()},children:[(0,h.jsx)(`h2`,{children:k?d.create:d.manage}),k&&(0,h.jsxs)(`div`,{className:`dc-field`,children:[(0,h.jsx)(`label`,{htmlFor:`device-group-name`,children:d.name}),(0,h.jsx)(`input`,{id:`device-group-name`,value:F,onChange:e=>I(e.target.value),disabled:V||!e})]}),(0,h.jsxs)(`fieldset`,{disabled:V||!e||j&&!S,children:[(0,h.jsx)(`legend`,{children:d.devices}),f.map(e=>(0,h.jsxs)(`label`,{className:`dg-device`,children:[(0,h.jsx)(`input`,{type:`checkbox`,disabled:!e.enabled&&!L.includes(e.id),checked:L.includes(e.id),onChange:t=>R(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}),(0,h.jsx)(a,{}),(0,h.jsxs)(`span`,{children:[e.name,` · `,e.id,` · `,e.deviceId,` · `,e.online?d.online:d.offline]})]},e.id))]}),!S?.room.router?.enabled&&(0,h.jsxs)(`div`,{className:`dc-field`,children:[(0,h.jsx)(`label`,{htmlFor:`device-group-primary-bot`,children:o(u)?`原主 Bot(Router 未启用时)`:`Legacy primary Bot (when Router is disabled)`}),(0,h.jsxs)(`select`,{id:`device-group-primary-bot`,value:L.includes(z)?z:``,disabled:V||!e||j&&!S,onChange:e=>B(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:o(u)?`不设置(需 @ Bot)`:`None (mention a Bot)`}),f.filter(e=>e.enabled&&L.includes(e.id)).map(e=>(0,h.jsxs)(`option`,{value:e.id,children:[e.name,` · `,e.id]},e.id))]}),(0,h.jsx)(`p`,{children:o(u)?`未启用 Router 时,未 @ Bot 的消息发送给原主 Bot。独立 AI Router 请在群聊顶部配置。`:`When Router is disabled, messages without mentions go to the legacy primary Bot. Configure the independent AI Router from the group chat header.`})]}),S?.room.router?.enabled&&(0,h.jsxs)(`p`,{children:[`AI Router · `,S.room.router.deviceId,` · `,S.room.router.model,` ·`,` `,S.room.router.thinkingLevel]}),(0,h.jsxs)(`div`,{className:`dc-actions`,children:[(0,h.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:V||!e||N,onClick:()=>P(!0),children:[(0,h.jsx)(i,{}),` `,o(u)?`新建 Bot`:`Create Bot`]}),(0,h.jsx)(`button`,{className:`dc-button`,type:`submit`,disabled:V||!e||(k?!F.trim():!S),children:k?d.create:d.save}),(0,h.jsx)(`button`,{className:`dc-button`,type:`button`,onClick:()=>{Z(),K.current=null,r&&l?.(),A(!1),M(!1),D(``)},children:d.cancel})]})]}):$?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`div`,{className:`dg-title`,children:(0,h.jsxs)(`h2`,{children:[(0,h.jsx)(c,{}),` `,$.name]})}),(0,h.jsxs)(`div`,{className:`dc-actions`,children:[(0,h.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:()=>_($.id),children:[(0,h.jsx)(s,{}),d.open]}),(0,h.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:()=>Q($.id,!0),children:[(0,h.jsx)(c,{}),d.manage]})]})]}):(0,h.jsx)(`p`,{className:`dg-empty`,children:d.choose})]}),N&&(0,h.jsx)(te,{createOnly:!0,onCancel:()=>P(!1),onCreated:(e,t)=>{P(!1),t&&e.enabled?(m(t=>[...t.filter(t=>t.id!==e.id),e]),R(t=>[...new Set([...t,e.id])])):D(o(u)?`Bot 已保存;请启用并同步到中心后,再加入群组。`:`Bot saved. Enable and sync it to the hub before adding it to the group.`)}})]})}export{v as DeviceGroupCreateDialog};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{N as t}from"./app-globals-
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{N as t}from"./app-globals-CBEscsYP.js";import{i as n,r,t as i}from"./react-CR5VJ85Q.js";import{t as a}from"./shortcut-stack-hhrDyRBn.js";var o=r(),s=e(n(),1);function c(e,t,n={}){let{enabled:r=!0,ignore:i}=n,a=(0,s.useRef)(t);(0,s.useLayoutEffect)(()=>{a.current=t}),(0,s.useEffect)(()=>{if(!r)return;let t=(e,t)=>{if(!t)return!1;let n=`current`in t?t.current:t;return n?n.contains(e):!1},n=n=>{let r=n.target;r instanceof Node&&(e.current?.contains(r)||i&&(Array.isArray(i)?i:[i]).some(e=>t(r,e))||a.current(n))};return document.addEventListener(`mousedown`,n),document.addEventListener(`touchstart`,n),()=>{document.removeEventListener(`mousedown`,n),document.removeEventListener(`touchstart`,n)}},[r,e,i])}var l=i();function u({align:e,triggerLeft:t,triggerRight:n,menuWidth:r,viewportWidth:i,margin:a=8}){if(r<=0||i<=0)return 0;let o=e===`left`?t:n-r,s=Math.max(a,i-a-r);return Math.round(Math.max(a,Math.min(o,s))-o)}function d({triggerRect:e,menuWidth:t,menuHeight:n,viewportWidth:r,viewportHeight:i,direction:a=`down`,align:o=`right`,gap:s=6,margin:c=8}){if(t<=0||r<=0||i<=0)return{left:Math.round(e.left),top:Math.round(e.bottom+s)};let l=Math.max(c,r-c-t),u=Math.max(c,i-c-n),d=c,f=c,p,m=Math.max(0,e.top-s-c),h=Math.max(0,i-e.bottom-s-c);if(a===`right`)d=e.right+s,d+t>r-c&&e.left-t-s>=c&&(d=e.left-t-s),d=Math.max(c,Math.min(d,l)),f=e.top,f+n>i-c&&(f=i-c-n),f=Math.max(c,Math.min(f,u)),p=Math.max(0,i-2*c);else if(a===`left`)d=e.left-t-s,d<c&&e.right+s+t<=r-c&&(d=e.right+s),d=Math.max(c,Math.min(d,l)),f=e.top,f+n>i-c&&(f=i-c-n),f=Math.max(c,Math.min(f,u)),p=Math.max(0,i-2*c);else if(a===`up`){m>=n?(f=e.top-n-s,p=m):h>=n||h>m?(f=e.bottom+s,p=h):(p=m,f=e.top-Math.min(n,m)-s);let r=Math.max(c,i-c-Math.min(n,p));f=Math.max(c,Math.min(f,r));let a=o===`left`?e.left:e.right-t;d=Math.max(c,Math.min(a,l))}else{h>=n?(f=e.bottom+s,p=h):m>=n?(f=e.top-n-s,p=m):m>h?(f=e.top-Math.min(n,m)-s,p=m):(f=e.bottom+s,p=h);let r=Math.max(c,i-c-Math.min(n,p));f=Math.max(c,Math.min(f,r));let a=o===`left`?e.left:e.right-t;d=Math.max(c,Math.min(a,l))}return{left:Math.round(d),top:Math.round(f),...p===void 0?{}:{maxHeight:Math.round(p)}}}function f({trigger:e,open:n,onOpenChange:r,children:i,align:f=`right`,fit:p=!1,direction:m=`down`,portal:h=!1,tip:g,caret:_=!0,menuClassName:v,triggerClassName:y,onContextMenu:b,dataBarItem:x,menuRef:S,menuStyle:C,className:w}){let T=(0,s.useRef)(null),E=(0,s.useRef)(null),[D,O]=(0,s.useState)(0),[k,A]=(0,s.useState)(null),j=e=>{E.current=e,typeof S==`function`?S(e):S&&`current`in S&&(S.current=e)},M=()=>{let e=T.current,t=E.current;if(!e||!t)return;if(window.innerWidth<=768){D!==0&&O(0);return}let n=t.getBoundingClientRect(),r=e.getBoundingClientRect();if(r.width===0&&r.height===0||n.width===0){D!==0&&O(0);return}if(h){let e=d({triggerRect:r,menuWidth:n.width,menuHeight:n.height,viewportWidth:window.innerWidth,viewportHeight:window.innerHeight,direction:m,align:f,gap:6,margin:8});A(t=>t?.left===e.left&&t?.top===e.top&&t?.maxHeight===e.maxHeight?t:e)}else{let e=n.width,t=u({align:f,triggerLeft:r.left,triggerRight:r.right,menuWidth:e,viewportWidth:window.innerWidth,margin:8});t!==D&&O(t)}};(0,s.useLayoutEffect)(()=>{n?M():(D!==0&&O(0),k!==null&&A(null))}),(0,s.useEffect)(()=>{if(n)return window.addEventListener(`resize`,M),h&&window.addEventListener(`scroll`,M,!0),()=>{window.removeEventListener(`resize`,M),h&&window.removeEventListener(`scroll`,M,!0)}},[n,D,h,m,f]),c(T,()=>r(!1),{enabled:n,ignore:E}),a(()=>r(!1),n);let N=typeof window<`u`&&window.innerWidth<=768?{...C,pointerEvents:`auto`}:{...C,position:`fixed`,left:k?`${k.left}px`:`-9999px`,top:k?`${k.top}px`:`-9999px`,maxHeight:k?.maxHeight==null?C?.maxHeight:C?.maxHeight==null?`${k.maxHeight}px`:`min(${k.maxHeight}px, ${C.maxHeight})`,right:`auto`,bottom:`auto`,pointerEvents:`auto`,visibility:k?`visible`:`hidden`},P=k!=null&&T.current?k.top<T.current.getBoundingClientRect().top:m===`up`;return(0,l.jsxs)(`div`,{className:`dropdown ${f} ${p?`fit`:``} ${m===`up`?`dd-up`:``} ${w??``}`.trim(),ref:T,children:[(0,l.jsxs)(`button`,{type:`button`,className:y??`chip`,onClick:()=>r(!n),onContextMenu:b,"aria-expanded":n,"data-tip":g,"data-bar-item":x,children:[e,_&&(0,l.jsx)(t,{className:`dd-caret ${n?`up`:``}`})]}),n&&(h?(0,o.createPortal)((0,l.jsx)(`div`,{className:`dd-portal-wrapper dropdown ${f} ${p?`fit`:``} ${P?`dd-up`:``}`,style:{position:`fixed`,left:0,top:0,width:`100%`,height:`100%`,pointerEvents:`none`,zIndex:9999},children:(0,l.jsx)(`div`,{className:`dd-menu ${v??``}`,ref:j,style:N,onPointerDown:e=>e.stopPropagation(),onMouseDown:e=>e.stopPropagation(),onWheel:e=>e.stopPropagation(),children:i})}),document.body):(0,l.jsx)(`div`,{className:`dd-menu ${v??``}`,ref:j,onPointerDown:e=>e.stopPropagation(),onMouseDown:e=>e.stopPropagation(),onWheel:e=>e.stopPropagation(),style:D===0?C:{...C,transform:C?.transform?`${C.transform} translateX(${D}px)`:`translateX(${D}px)`},children:i}))]})}function p({active:e,disabled:t=!1,title:n,onClick:r,children:i}){return(0,l.jsx)(`button`,{type:`button`,className:`dd-item ${e?`active`:``}`,disabled:t,title:n,onClick:r,children:i})}export{p as n,f as t};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$ as t,A as n,B as r,Bn as i,Fn as a,Gt as ee,Q as te,St as ne,Tn as re,Tt as ie,U as ae,X as oe,_n as se,et as ce,hn as le,jt as ue,t as de,vn as fe,xt as pe}from"./app-globals-CBEscsYP.js";import{i as o,t as s}from"./react-CR5VJ85Q.js";import{B as me,L as he,at as ge,nt as _e,st as ve,tt as ye,u as be}from"./index-BD29OL9L.js";var c=e(o(),1),l=`未命名章节`;function xe(e){return String(e??``).trim().replace(/[\s\u3000]+/g,`-`).replace(/[^\p{L}\p{N}_-]+/gu,`-`).replace(/-{2,}/g,`-`).replace(/^-+|-+$/g,``).slice(0,80)||`section`}function Se(e){let t=new Map;return e.map(({level:e,label:n})=>{let r=String(n??``).replace(/\s+/g,` `).trim(),i=xe(r||l),a=(t.get(i)??0)+1;return t.set(i,a),{level:e,id:a===1?i:`${i}-${a}`,label:r||l}})}function u(e){return e.length>=2}var d=s(),f=5e3,Ce=`pi-web-ui:preview-toc`;function p({file:e,files:o,activeIndex:s,onSelectFile:l,composerSessionId:xe,content:p,onAddLines:we,onAttach:Te,onClose:Ee,uiFilePreviewToolbar:De,onUiAction:Oe}){let _=re(),ke=_e(),[v,Ae]=(0,c.useState)(null),[y,je]=(0,c.useState)(!1),[b,x]=(0,c.useState)(null),[Me,Ne]=(0,c.useState)(!1),[Pe,Fe]=(0,c.useState)(!1),[S,C]=(0,c.useState)(!1),[w,T]=(0,c.useState)(``),[E,D]=(0,c.useState)(!0),[O,k]=(0,c.useState)(!0),A=(0,c.useRef)(!1),[j,Ie]=(0,c.useState)(!0),[M,Le]=(0,c.useState)(!1),[N,Re]=(0,c.useState)(100),P=(0,c.useRef)(0),F=(0,c.useRef)(!1),I=(0,c.useRef)(null),[ze,L]=(0,c.useState)(!1),[Be,R]=(0,c.useState)(!1),z=(0,c.useRef)(!1),B=(0,c.useRef)(null);(0,c.useEffect)(()=>()=>{I.current&&clearTimeout(I.current),B.current&&clearTimeout(B.current)},[]),(0,c.useEffect)(()=>{je(!0),Ae(null),x(null),C(!1),T(``),D(!0),k(!0),A.current=!1,z.current=!1,L(!1),R(!1),B.current&&clearTimeout(B.current),de({type:`read_file`,path:e.path})},[e.path]),(0,c.useEffect)(()=>{p&&p.path===e.path&&(Ae(p),S||T(p.text),je(!1),z.current&&(z.current=!1,B.current&&clearTimeout(B.current),L(!1),R(!1),C(!1),T(p.text),A.current&&(m(e.name)&&D(!0),g(e.name)&&k(!0)),x(null)))},[p,S,e.path]),(0,c.useEffect)(()=>{let e=e=>{if(e.key===`Escape`){e.preventDefault(),U();return}if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`s`&&S){e.preventDefault(),Je();return}let t=e.target,n=t&&(t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.isContentEditable);(e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`a`&&!n&&(e.preventDefault(),We())};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[Ee,v,S,w]),(0,c.useEffect)(()=>{let e=()=>{F.current=!1,Ne(!1)};return window.addEventListener(`mouseup`,e),()=>window.removeEventListener(`mouseup`,e)},[]);let V=(0,c.useMemo)(()=>{if(!v)return[];let e=v.text.split(`
|
|
2
|
+
`);return e.length>0&&e[e.length-1]===``&&e.pop(),e.slice(0,f)},[v]),Ve=v?.lines??0,He=Ve>f,Ue=(e,t)=>{if(t){let t=P.current>0?P.current:e;x({start:Math.min(t,e),end:Math.max(t,e)})}else P.current=e,x({start:e,end:e})},We=()=>{V.length!==0&&(P.current=1,x({start:1,end:V.length}))},Ge=()=>{b&&(we(e.path,e.name,b.start,b.end),Fe(!0),I.current&&clearTimeout(I.current),I.current=setTimeout(()=>Fe(!1),1400))},H=v!==null&&v.kind===`text`&&!v.binary&&!v.truncated&&!h(e.name),Ke=()=>{z.current=!1,B.current&&clearTimeout(B.current),L(!1),R(!1),T(v?.text??``),C(!1),A.current&&(m(e.name)&&D(!0),g(e.name)&&k(!0))},qe=()=>{if(S){if(w!==(v?.text??``)&&!window.confirm(_(`discardFileChanges`)))return;Ke();return}H&&v&&(A.current=m(e.name)&&E||g(e.name)&&O,m(e.name)&&D(!1),g(e.name)&&k(!1),x(null),T(v.text),C(!0))},Je=()=>{S&&v&&H&&de({type:`write_file`,path:e.path,text:w})&&(z.current=!0,R(!1),L(!0),B.current&&clearTimeout(B.current),B.current=setTimeout(()=>{z.current=!1,L(!1),R(!0)},5e3))},U=()=>{(!S||w===(v?.text??``)||window.confirm(_(`discardFileChanges`)))&&Ee()},Ye=e=>{Re(Math.min(200,Math.max(50,e)))},Xe=b?b.end-b.start+1:0,W=v?.binary??!1,Ze=v?.truncated??!1,G=v?.kind??`text`,Qe=m(e.name)||h(e.name),K=g(e.name),$e=h(e.name),q=Qe&&E&&!S&&G===`text`&&!W,J=K&&O&&!S&&G===`text`&&!W,[Y,et]=(0,c.useState)(()=>{try{return localStorage.getItem(Ce)===`1`}catch{return!1}});(0,c.useEffect)(()=>{try{localStorage.setItem(Ce,Y?`1`:`0`)}catch{}},[Y]);let[X,tt]=(0,c.useState)([]),[nt,rt]=(0,c.useState)(``),Z=(0,c.useRef)(null);(0,c.useEffect)(()=>{let e=Z.current;if(!e||!q){tt([]);return}let t=[...e.querySelectorAll(`h1, h2, h3, h4, h5, h6`)],n=Se(t.map(e=>({level:Number(e.tagName.slice(1)),label:e.textContent??``})));t.forEach((e,t)=>{e.id||=n[t].id}),tt(n)},[q,v?.text,e.path]),(0,c.useEffect)(()=>{let e=Z.current;if(!e||!Y||!u(X))return;let t=X.map(t=>e.querySelector(`#${CSS.escape(t.id)}`)).filter(e=>e!==null);if(t.length===0)return;let n=new IntersectionObserver(e=>{let t=e.filter(e=>e.isIntersecting).sort((e,t)=>e.boundingClientRect.top-t.boundingClientRect.top)[0];t?.target.id&&rt(t.target.id)},{rootMargin:`0px 0px -70% 0px`});for(let e of t)n.observe(e);return()=>n.disconnect()},[X,Y]);let Q=e=>i(a(`/api/file?clientId=${encodeURIComponent(me())}&path=${encodeURIComponent(e)}`)),it=e=>{let t=e.split(`/`).map(e=>encodeURIComponent(e)).join(`/`),n=/^[A-Za-z]:([\\/]|$)/.test(e)||e.startsWith(`/`)?`/api/preview/__abs__/${t}`:`/api/preview/${t}`;return i(a(`${n}?clientId=${encodeURIComponent(me())}&allowJs=1`))},at={"host:fp-md":Qe&&G===`text`&&!W&&v?(0,d.jsx)(`button`,{type:`button`,className:`fp-attach markdown ${E?`on`:``}`,"data-tip":_(E?`showMarkdownSource`:`showMarkdownPreview`),disabled:S,onClick:()=>D(e=>!e),children:E?(0,d.jsx)(ce,{}):(0,d.jsx)(r,{})}):null,"host:fp-toc":q&&u(X)?(0,d.jsx)(`button`,{type:`button`,className:`fp-attach toc ${Y?`on`:``}`,"data-tip":_(Y?`previewTocHide`:`previewTocShow`),onClick:()=>et(e=>!e),children:(0,d.jsx)(ne,{})}):null,"host:fp-html":K&&G===`text`&&!W&&v?(0,d.jsx)(`button`,{type:`button`,className:`fp-attach html ${O?`on`:``}`,"data-tip":_(O?`showHtmlSource`:`showHtmlPreview`),disabled:S,onClick:()=>k(e=>!e),children:O?(0,d.jsx)(r,{}):(0,d.jsx)(ce,{})}):null,"host:fp-external":K&&G===`text`&&!W&&v?(0,d.jsx)(`a`,{className:`fp-attach open`,href:it(e.path),target:`_blank`,rel:`noopener noreferrer`,"data-tip":_(`openInNewTab`),"aria-label":_(`openInNewTab`),children:(0,d.jsx)(t,{})}):null,"host:fp-edit":G===`text`&&!W&&v?(0,d.jsx)(`button`,{type:`button`,className:`fp-attach edit ${S?`on`:``}`,"data-tip":_(Ze?`fileEditTruncated`:S?`exitEditFile`:`editFile`),disabled:!H&&!S,onClick:qe,children:(0,d.jsx)(te,{})}):null,"host:fp-wrap":G===`text`&&!W&&!q&&!J?(0,d.jsx)(`button`,{type:`button`,className:`fp-attach wrap ${j?`on`:``}`,"data-tip":_(j?`disableWrap`:`enableWrap`),onClick:()=>Ie(e=>!e),children:(0,d.jsx)(ae,{})}):null,"host:fp-zoom":G===`text`&&v?(0,d.jsxs)(`span`,{className:`fp-zoom`,children:[(0,d.jsx)(`button`,{type:`button`,className:`fp-attach zoom-out`,"data-tip":_(`zoomOut`),disabled:N<=50,onClick:()=>Ye(N-10),children:(0,d.jsx)(fe,{})}),(0,d.jsxs)(`button`,{type:`button`,className:`fp-zoom-val`,title:_(`resetZoom`),onClick:()=>Re(100),children:[N,`%`]}),(0,d.jsx)(`button`,{type:`button`,className:`fp-attach zoom-in`,"data-tip":_(`zoomIn`),disabled:N>=200,onClick:()=>Ye(N+10),children:(0,d.jsx)(se,{})})]}):null,"host:fp-download":(0,d.jsx)(`button`,{type:`button`,className:`fp-attach download`,"data-tip":_(`downloadFile`),onClick:()=>void ge(e.path,e.name),children:(0,d.jsx)(oe,{})}),"host:fp-ref":(0,d.jsx)(`button`,{type:`button`,className:`fp-attach ref`,"data-tip":_(`referenceTip`),onClick:()=>Te(e.path,e.name,`reference`),children:(0,d.jsx)(pe,{})}),"host:fp-full":(0,d.jsx)(`button`,{type:`button`,className:`fp-attach full ${M?`on`:``}`,"data-tip":_(M?`exitFullscreen`:`fullscreen`),onClick:()=>Le(e=>!e),children:M?(0,d.jsx)(ue,{}):(0,d.jsx)(ie,{})}),"host:fp-close":null},ot=De===void 0?[`host:fp-md`,`host:fp-toc`,`host:fp-html`,`host:fp-external`,`host:fp-edit`,`host:fp-wrap`,`host:fp-zoom`,`host:fp-download`,`host:fp-ref`,`host:fp-full`].map(e=>({id:e,source:`host`})):De.filter(e=>!e.hidden&&e.id!==`host:fp-close`),$=Array.isArray(o)&&o.length>1?o:null,st=typeof s==`number`?s:0;return!$&&G===`image`&&!y?(0,d.jsx)(be,{src:Q(e.path),alt:e.name,onClose:U,composerSessionId:xe}):(0,d.jsx)(`div`,{className:`fp-overlay ${M?`fullscreen`:``}`,style:{zIndex:ke},onMouseDown:e=>{e.target===e.currentTarget&&U()},children:(0,d.jsxs)(`div`,{className:`fp ${M?`fullscreen`:``} ${$e?`is-ppt`:``}`,style:{"--fp-zoom":N/100},children:[(0,d.jsxs)(`div`,{className:`fp-head`,onDoubleClick:e=>{let t=e.target;t&&!t.closest(`button, a, input`)&&Le(e=>!e)},children:[(0,d.jsx)(`span`,{className:`fp-name`,title:e.path,children:e.name}),(0,d.jsx)(`span`,{className:`fp-path`,children:e.path}),(0,d.jsxs)(`span`,{className:`fp-meta`,children:[v&&G===`text`&&!W&&_(`fileLines`,{n:Ve}),v&&` · ${ye(v.size)}`]}),(0,d.jsx)(`span`,{className:`fp-head-actions`,children:he(ot,at,Oe)}),(0,d.jsx)(`button`,{type:`button`,className:`fp-close`,title:_(`close`),"aria-label":_(`close`),onClick:U,children:(0,d.jsx)(le,{})})]}),$&&(0,d.jsx)(`div`,{className:`fp-tabs`,role:`tablist`,"aria-label":e.path,children:$.map((e,t)=>(0,d.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":t===st,className:`fp-tab${t===st?` on`:``}`,title:e.path,onClick:()=>l?.(t),children:[(0,d.jsx)(`span`,{className:`fp-tab-name`,children:e.name}),(0,d.jsx)(`span`,{className:`fp-tab-index`,children:t+1})]},`${e.path}\u0000${t}`))}),Ze&&G===`text`&&!W&&(0,d.jsx)(`div`,{className:`fp-notice`,children:h(e.name)?_(`previewLinesTruncated`,{n:V.length}):_(`previewTruncated`)}),y&&!v&&(0,d.jsx)(`div`,{className:`fp-empty`,children:_(`loading`)}),!y&&G===`none`&&!W&&(0,d.jsx)(`div`,{className:`fp-empty`,children:_(`previewNotSupported`)}),!y&&G===`image`&&v&&$&&(0,d.jsx)(`div`,{className:`fp-media-wrap`,children:(0,d.jsx)(`img`,{className:`fp-media`,src:Q(e.path),alt:e.name})}),!y&&G===`video`&&(0,d.jsx)(`div`,{className:`fp-media-wrap`,children:(0,d.jsx)(`video`,{className:`fp-media`,src:Q(e.path),controls:!0,preload:`metadata`})}),!y&&G===`audio`&&(0,d.jsx)(`div`,{className:`fp-media-wrap fp-audio-wrap`,children:(0,d.jsxs)(`div`,{className:`fp-audio-card`,children:[(0,d.jsx)(`div`,{className:`fp-audio-icon`,"aria-hidden":`true`,children:`🎵`}),(0,d.jsxs)(`div`,{className:`fp-audio-info`,children:[(0,d.jsx)(`div`,{className:`fp-audio-name`,title:e.name,children:e.name}),v?.size?(0,d.jsx)(`div`,{className:`fp-audio-size`,children:ye(v.size)}):null]}),(0,d.jsx)(`audio`,{className:`fp-audio-element`,src:Q(e.path),controls:!0,autoPlay:!0,preload:`metadata`})]})}),!y&&J&&v&&(0,d.jsx)(`div`,{className:`fp-html`,children:(0,d.jsx)(`iframe`,{className:`fp-html-frame`,src:it(e.path),title:e.name,sandbox:`allow-scripts`,referrerPolicy:`no-referrer`})}),!y&&q&&v&&(0,d.jsx)(`div`,{className:h(e.name)?`fp-markdown msg-text fp-office`:`fp-markdown msg-text`,children:(0,d.jsxs)(`div`,{className:Y&&u(X)?`fp-toc-layout`:void 0,children:[Y&&u(X)&&(0,d.jsx)(`nav`,{className:`fp-toc`,"aria-label":_(`previewTocLabel`),children:X.map(e=>(0,d.jsx)(`a`,{className:`l${Math.min(e.level,6)}${e.id===nt?` on`:``}`,href:`#${e.id}`,title:e.label,onClick:t=>{t.preventDefault(),Z.current?.querySelector(`#${CSS.escape(e.id)}`)?.scrollIntoView({behavior:`smooth`,block:`start`})},children:e.label},e.id))}),(0,d.jsx)(`div`,{className:`fp-markdown-zoom`,ref:Z,children:(0,d.jsx)(ve,{text:v.text})})]})}),!y&&W&&G!==`image`&&G!==`video`&&v&&(0,d.jsxs)(`div`,{className:`fp-hex-wrap`,children:[(0,d.jsxs)(`div`,{className:`fp-notice`,children:[_(`binaryFile`),v.truncated&&_(`binaryHexTruncated`)]}),(0,d.jsx)(`pre`,{className:`fp-hex`,children:v.text})]}),!y&&S&&G===`text`&&!W&&v&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(`textarea`,{className:`fp-editor ${j?``:`no-wrap`}`,value:w,onChange:e=>T(e.target.value),wrap:j?`soft`:`off`,spellCheck:!1,autoFocus:!0}),Be&&(0,d.jsx)(`div`,{className:`fp-notice`,role:`alert`,children:_(`saveResultUnknown`)})]}),!y&&!q&&!J&&!S&&G===`text`&&!W&&v&&V.length===0&&(0,d.jsx)(`div`,{className:`fp-empty`,children:_(`emptyFile`)}),!y&&!q&&!J&&!S&&G===`text`&&!W&&V.length>0&&(0,d.jsxs)(`div`,{className:`fp-code ${Me?`dragging`:``} ${j?``:`no-wrap`}`,onMouseDown:e=>{e.button===0&&e.preventDefault()},children:[V.map((e,t)=>{let n=t+1,r=b!==null&&n>=b.start&&n<=b.end;return(0,d.jsxs)(`div`,{className:`fp-line ${r?`sel`:``}`,onMouseDown:e=>{e.button===0&&(Ue(n,e.shiftKey),F.current=!0,Ne(!0))},onMouseEnter:()=>{F.current&&Ue(n,!0)},children:[(0,d.jsx)(`span`,{className:`fp-num`,children:n}),(0,d.jsx)(`span`,{className:`fp-code-text`,children:e})]},n)}),He&&(0,d.jsx)(`div`,{className:`fp-lines-note`,children:_(`previewLinesTruncated`,{n:f})})]}),(S||!q&&!J&&G===`text`)&&(0,d.jsx)(`div`,{className:`fp-foot`,children:S?(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(`span`,{className:`fp-hint`,children:_(`editFile`)}),(0,d.jsxs)(`div`,{className:`fp-actions`,children:[(0,d.jsx)(`button`,{type:`button`,className:`btn`,onClick:qe,children:_(`cancel`)}),(0,d.jsxs)(`button`,{type:`button`,className:`btn primary`,disabled:ze||w===(v?.text??``),onClick:Je,children:[(0,d.jsx)(ee,{}),` `,_(`saveFile`)]})]})]}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(`span`,{className:`fp-hint`,children:b?_(`selectedRange`,{n:Xe,start:b.start,end:b.end}):_(`selectLinesHint`)}),(0,d.jsxs)(`div`,{className:`fp-actions`,children:[(0,d.jsx)(`button`,{type:`button`,className:`btn`,disabled:V.length===0,onClick:We,children:_(`selectAll`)}),(0,d.jsx)(`button`,{type:`button`,className:`btn`,disabled:!b,onClick:()=>x(null),children:_(`clearSelection`)}),(0,d.jsxs)(`button`,{type:`button`,className:`btn primary`,disabled:!b||W,onClick:Ge,children:[Pe?(0,d.jsx)(n,{}):null,_(Pe?`addedToChat`:`addToChat`)]})]})]})})]})})}function m(e){let t=e.toLowerCase();return t.endsWith(`.md`)||t.endsWith(`.markdown`)}function h(e){let t=e.toLowerCase();return t.endsWith(`.docx`)||t.endsWith(`.xlsx`)||t.endsWith(`.xlsm`)||t.endsWith(`.pptx`)||t.endsWith(`.pptm`)||t.endsWith(`.ppsx`)||t.endsWith(`.potx`)}function g(e){let t=e.toLowerCase();return t.endsWith(`.html`)||t.endsWith(`.htm`)||t.endsWith(`.xhtml`)}export{p as FilePreview};
|