pi-web-ui 0.114.3 → 0.116.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 +62 -1
- package/bin/pi-web-ui.mjs +90 -8
- package/dist/gh-comment-781.md +5 -0
- package/dist/server/agent-service-daemon.js +522 -32
- package/dist/server/agent-service.js +954 -402
- package/dist/server/canvas/canvas-dispatch.js +13 -1
- package/dist/server/client-state.js +42 -2
- package/dist/server/communicate-tool.js +2 -0
- package/dist/server/conversation-communication.js +14 -0
- package/dist/server/conversation-identity.js +27 -0
- package/dist/server/device-center/approval-summary.js +31 -0
- package/dist/server/device-center/bot-catalog.js +21 -7
- package/dist/server/device-center/bot-execution.js +100 -9
- package/dist/server/device-center/bot-presets.js +46 -0
- package/dist/server/device-center/collab-service.js +362 -13
- package/dist/server/device-center/collab-tool.js +824 -13
- package/dist/server/device-center/connector.js +359 -23
- package/dist/server/device-center/desktop-page.js +22 -16
- package/dist/server/device-center/device-integration.js +595 -0
- package/dist/server/device-center/execution-guides.js +32 -0
- package/dist/server/device-center/execution-instructions.js +20 -0
- package/dist/server/device-center/execution-settings.js +213 -0
- package/dist/server/device-center/execution-system-prompt.js +38 -0
- package/dist/server/device-center/execution-workspace.js +20 -0
- package/dist/server/device-center/executor.js +392 -40
- package/dist/server/device-center/file-sync-paths.js +171 -0
- package/dist/server/device-center/file-sync.js +186 -96
- package/dist/server/device-center/group-context-delta.js +37 -0
- package/dist/server/device-center/group-context-message.js +210 -0
- package/dist/server/device-center/group-context.js +179 -0
- package/dist/server/device-center/group-events.js +136 -0
- package/dist/server/device-center/group-plan-guard.js +138 -0
- package/dist/server/device-center/hub-conversations.js +233 -0
- package/dist/server/device-center/hub-deliveries.js +277 -0
- package/dist/server/device-center/hub-integration.js +451 -0
- package/dist/server/device-center/hub-locks.js +320 -0
- package/dist/server/device-center/hub-page.js +13 -33
- package/dist/server/device-center/hub-webhooks.js +165 -0
- package/dist/server/device-center/hub.js +2379 -107
- package/dist/server/device-center/human-interaction.js +232 -0
- package/dist/server/device-center/integration-errors.js +25 -0
- package/dist/server/device-center/local-hub.js +20 -1
- package/dist/server/device-center/local-page.js +17 -0
- package/dist/server/device-center/local.js +430 -41
- package/dist/server/device-center/main.js +11 -1
- package/dist/server/device-center/partition-log.js +293 -0
- package/dist/server/device-center/path-portal.js +11 -3
- package/dist/server/device-center/relay.js +364 -35
- package/dist/server/device-center/report-metadata.js +66 -0
- package/dist/server/device-center/report-upload.js +63 -0
- package/dist/server/device-center/runtime.js +598 -41
- package/dist/server/device-center/smoke-preview.js +3 -0
- package/dist/server/device-center/store.js +203 -41
- package/dist/server/device-center/task-context-budget.js +161 -0
- package/dist/server/device-center/task-journal.js +385 -0
- package/dist/server/device-center/task-plan.js +33 -0
- package/dist/server/device-center/task-progress.js +141 -0
- package/dist/server/device-center/task-recovery.js +452 -0
- package/dist/server/device-center/task-report-outbox.js +216 -0
- package/dist/server/device-center/task-report.js +384 -0
- package/dist/server/device-center/task-scheduler.js +445 -0
- package/dist/server/device-center/task-state.js +333 -0
- package/dist/server/device-center/transfer-stream.js +1006 -0
- package/dist/server/device-center/transfers.js +841 -8
- package/dist/server/dispatch-domain-handlers.js +35 -6
- package/dist/server/dsh/dsh-agent-service.js +6 -0
- package/dist/server/durable/durable-capabilities.js +11 -0
- package/dist/server/engine-probe.js +112 -1
- package/dist/server/global-loader.js +119 -19
- package/dist/server/goal-service.js +10 -5
- package/dist/server/index.js +222 -29
- package/dist/server/managed.js +2 -0
- package/dist/server/markers/builtins/services.js +123 -0
- package/dist/server/markers/builtins/todo.js +189 -0
- package/dist/server/markers-list-tool.js +34 -0
- package/dist/server/message-deletion.js +40 -0
- package/dist/server/message-window.js +9 -0
- package/dist/server/model-admin.js +48 -6
- package/dist/server/model-enrich.js +10 -1
- package/dist/server/orchestrator.js +109 -0
- package/dist/server/patch-executable-lookup.js +396 -0
- package/dist/server/payload-limits.js +2 -0
- package/dist/server/plugin-llm.js +100 -9
- package/dist/server/plugins.js +65 -7
- package/dist/server/preset-fields.js +24 -0
- package/dist/server/preset-share.js +2 -0
- package/dist/server/prompt-base-store.js +85 -0
- package/dist/server/prompt-composer.js +44 -2
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/protocol.js +2 -2
- package/dist/server/reasoning-registry.js +207 -0
- package/dist/server/remote-ssh-service.js +22 -9
- package/dist/server/resolve-global-sdk.js +2 -0
- package/dist/server/session-search.js +1 -1
- package/dist/server/settings-service.js +90 -39
- package/dist/server/skill-content-filler.js +29 -8
- package/dist/server/skill-tool.js +12 -3
- package/dist/server/startup-banner.js +35 -0
- package/dist/server/subagent-helpers.js +4 -1
- package/dist/server/subagents.js +52 -37
- package/dist/server/system-prompt-soul.js +41 -0
- package/dist/server/tool-host-factories.js +1 -0
- package/dist/server/tool-manager.js +17 -9
- package/dist/server/unauthorized-page.js +319 -0
- package/dist/server/univer-service.js +448 -0
- package/dist/server/universal/drivers/dsh-driver.js +379 -0
- package/dist/server/universal/universal-session.js +5 -0
- package/dist/server/webui-context.js +25 -5
- package/dist/test-artifact.md +9 -0
- package/dist/test-preview-modal.md +11 -0
- package/dist/test-report.html +20 -0
- package/docs/README.md +94 -0
- package/docs/architecture-plugins.md +946 -0
- package/docs/device-center.md +106 -12
- package/docs/dsh-engine.md +10 -10
- package/extensions/webui.ts +43 -1
- package/package.json +2 -1
- package/themes/aetheris.css +5 -0
- package/themes/ayu-light.css +6 -0
- package/themes/bases/flow-base.css +68 -68
- package/themes/catppuccin-latte.css +6 -0
- package/themes/catppuccin.css +6 -0
- package/themes/claude-code-dark.css +5 -0
- package/themes/codex.css +6 -0
- package/themes/cyberpunk.css +6 -0
- package/themes/dark-teal.css +6 -1
- package/themes/dazzle.css +6 -0
- package/themes/everforest-light.css +6 -0
- package/themes/flow-light.css +8 -1
- package/themes/flow.css +6 -1
- package/themes/geist.css +6 -0
- package/themes/gruvbox-light.css +6 -0
- package/themes/kanagawa-lotus.css +6 -0
- package/themes/md-preview.css +6 -0
- package/themes/mist.css +6 -0
- package/themes/nord.css +6 -0
- package/themes/one-dark.css +6 -0
- package/themes/paper.css +6 -0
- package/themes/rose-pine-dawn.css +6 -0
- package/themes/sakura.css +6 -0
- package/themes/solarized-light.css +6 -0
- package/themes/tokyo-night.css +6 -0
- package/themes/translucent.css +6 -0
- package/themes/transparent.css +6 -0
- package/themes/vs-code-dark.css +5 -0
- package/themes/wallpaper-flow.css +5 -1
- package/themes/wallpaper-obsidian.css +6 -0
- package/themes/white.css +6 -0
- package/themes/zhujian-dark.css +6 -1
- package/themes/zhujian.css +6 -1
- package/themes/zhupi-dark.css +6 -1
- package/themes/zhupi.css +6 -1
- package/web/dist/.build-assets.json +1 -1
- package/web/dist/assets/BgTasksModal-BDoOpj-F.js +1 -0
- package/web/dist/assets/BgTasksModal-C0i3O1FT.js +1 -0
- package/web/dist/assets/{CanvasStudio-BSg9ghPV.js → CanvasStudio-B8thymBN.js} +3 -3
- package/web/dist/assets/{CanvasStudio-DxW7C3Sz.js → CanvasStudio-zSxyIx1R.js} +3 -3
- package/web/dist/assets/DeviceCenter-DfAHKcid.js +3 -0
- package/web/dist/assets/DeviceCenter-ydvOTlzE.js +3 -0
- package/web/dist/assets/DeviceExecutionSettings-q5Ik8oXg.js +1 -0
- package/web/dist/assets/DeviceGroups-CI14_SRb.js +1 -0
- package/web/dist/assets/DeviceGroups-DvsB5IEU.js +1 -0
- package/web/dist/assets/Dropdown-C4LIhshN.js +1 -0
- package/web/dist/assets/FilePreview-BgGongmv.js +2 -0
- package/web/dist/assets/FilePreview-D4NrhF-U.js +2 -0
- package/web/dist/assets/GlobalSearchModal-BWgU8yPd.js +1 -0
- package/web/dist/assets/GlobalSearchModal-F7fNimKk.js +1 -0
- package/web/dist/assets/GroupConversation-Dh71Pdb-.js +17 -0
- package/web/dist/assets/GroupConversation-ZK3nRmNm.js +17 -0
- package/web/dist/assets/HintTip-c6d0TJoh.js +1 -0
- package/web/dist/assets/ModelConfigModal-YVEgyy34.js +2 -0
- package/web/dist/assets/ModelConfigModal-vWtg3srp.js +2 -0
- package/web/dist/assets/PiSetupModal-BmMrrgB9.js +1 -0
- package/web/dist/assets/ProviderOAuthControls-BGSBIKD7.js +1 -0
- package/web/dist/assets/SCMPanel-B8_EDxNr.js +2 -0
- package/web/dist/assets/SCMPanel-BU58qk3T.js +2 -0
- package/web/dist/assets/SettingsModal-CMUybq3J.js +32 -0
- package/web/dist/assets/SettingsModal-OBmGTh-5.js +32 -0
- package/web/dist/assets/TerminalPanel-0CYvD72B.js +3 -0
- package/web/dist/assets/TerminalPanel-DDavKvFr.js +3 -0
- package/web/dist/assets/TuiOverlayModal-BsA-QTvN.js +1 -0
- package/web/dist/assets/TuiOverlayModal-DzoVQBuG.js +1 -0
- package/web/dist/assets/app-globals-CZxzGvIo.js +123 -0
- package/web/dist/assets/canvas-client-CUnXlQYX.js +1 -0
- package/web/dist/assets/{desktop-7EvUHhKQ.js → desktop-aAKpvKJV.js} +1 -1
- package/web/dist/assets/group-view-state-CGCzYF8k.js +1 -0
- package/web/dist/assets/index-C6DwztqE.css +1 -0
- package/web/dist/assets/index-CuN802Sj.js +93 -0
- package/web/dist/assets/index-EH5Fw9fa.js +93 -0
- package/web/dist/assets/plugin-host-BRWib9DF.js +1 -0
- package/web/dist/assets/remote-ssh-client-CfYSMEZg.js +1 -0
- package/web/dist/assets/theme-D2l_mLNo.js +1 -0
- package/web/dist/index.html +10 -9
- package/web/dist/sw.js +1 -1
- package/web/dist/assets/BgTasksModal-BvnUHjFe.js +0 -1
- package/web/dist/assets/BgTasksModal-DSC8ncW3.js +0 -1
- package/web/dist/assets/DeviceCenter-Bmgr-Bwm.js +0 -3
- package/web/dist/assets/DeviceCenter-Cl9MBXaH.js +0 -3
- package/web/dist/assets/DeviceGroups-aeLD2msl.js +0 -1
- package/web/dist/assets/Dropdown-D1Jl35dw.js +0 -1
- package/web/dist/assets/FilePreview-6CqoDF_P.js +0 -2
- package/web/dist/assets/FilePreview-CJa27G_Q.js +0 -2
- package/web/dist/assets/GlobalSearchModal-CJX35rZL.js +0 -1
- package/web/dist/assets/GlobalSearchModal-CMW0xz0P.js +0 -1
- package/web/dist/assets/GroupConversation-Cq4daBFb.js +0 -1
- package/web/dist/assets/GroupConversation-DoELa83U.js +0 -1
- package/web/dist/assets/ModelConfigModal-Bp7tfKYh.js +0 -2
- package/web/dist/assets/PiSetupModal-DD8srwBJ.js +0 -1
- package/web/dist/assets/ProviderOAuthControls-C6tfXb88.js +0 -1
- package/web/dist/assets/SCMPanel-CghgsyBN.js +0 -2
- package/web/dist/assets/SCMPanel-D8-8aqwC.js +0 -2
- package/web/dist/assets/SettingsModal-BbBe2rYo.js +0 -20
- package/web/dist/assets/SettingsModal-qETiVPKj.js +0 -20
- package/web/dist/assets/TerminalPanel-Da-Xs4Wk.js +0 -3
- package/web/dist/assets/TerminalPanel-DnS4tFQO.js +0 -3
- package/web/dist/assets/TuiOverlayModal-CGyGkKYl.js +0 -1
- package/web/dist/assets/TuiOverlayModal-CpBKjG6x.js +0 -1
- package/web/dist/assets/app-globals-DcyO0UPi.js +0 -1
- package/web/dist/assets/fi-NyN-ZrgD.js +0 -325
- package/web/dist/assets/index-DK3F5ZJo.js +0 -85
- package/web/dist/assets/index-DQMii2he.js +0 -85
- package/web/dist/assets/index-vwBnwzkr.css +0 -1
- package/web/dist/assets/plugin-host-BCnX3P8U.js +0 -1
- package/web/dist/assets/theme-D2DMH6tH.js +0 -1
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$ as t,A as n,Cn as r,Dn as i,Dt as a,H as o,Jt as s,Mt as ee,Rt as c,Tn as l,Z as u,bn as te,bt as d,cn as f,nn as p,pt as m,un as h,vn as g,yn as _,zt as v}from"./app-globals-CZxzGvIo.js";import{i as y,t as b}from"./react-CR5VJ85Q.js";import{Vt as ne,gt as re}from"./index-EH5Fw9fa.js";import{t as x}from"./DeviceExecutionSettings-q5Ik8oXg.js";var S=e(y(),1),C=b();function w({href:e,children:t}){let n=te(),[r,i]=(0,S.useState)(!1),[a,o]=(0,S.useState)(!1);return(0,C.jsxs)(C.Fragment,{children:[(0,C.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,C.jsxs)(`span`,{role:`alert`,children:[n(`deviceHubNetworkError`),` `,(0,C.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,children:e})]})]})}function T(e){if(!E(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 E(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 D(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 O=`https://raw.githubusercontent.com/xing-shuyin/pi-web-ui/main/docs/device-center-deployment.md`,k=`https://github.com/xing-shuyin/pi-web-ui/blob/main/docs/device-center-deployment.md`,A=`pi-web-ui hub install --host 0.0.0.0 --port 8790 --public-url http://SERVER_IP:8790 --allow-registration`;function j(e){let t=e=>e.includes(`:`)?E(e)&&![`::`,`::1`].includes(e):/^[\d.]+$/.test(e)?E(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 M(e,t,n,r){if(!T(e))throw Error(`Invalid Hub setup`);if(r){let t=j(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: ${O} (fallback: ${k}). 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: ${A}`,`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 ie({onConnect:e,initialHubUrl:t=``}){let n=te(),[r,a]=(0,S.useState)(t),[o,s]=(0,S.useState)(``),[ee,c]=(0,S.useState)(!1),[u,d]=(0,S.useState)(!1),f=(0,S.useRef)(!1),p=(0,S.useRef)(!1);(0,S.useEffect)(()=>(p.current=!0,()=>{p.current=!1}),[]);let[m,h]=(0,S.useState)(null),[g,_]=(0,S.useState)(`current`),[v,y]=(0,S.useState)(null),[b,ne]=(0,S.useState)(`127.0.0.1`),[re,x]=(0,S.useState)(`8790`),[E,O]=(0,S.useState)(`http://127.0.0.1:8790`),[k,A]=(0,S.useState)({server:``,sshPort:22,username:`root`,auth:`password`,port:8790,domain:``,https:!1}),ie=j(k),[N,P]=(0,S.useState)(!1),[F,I]=(0,S.useState)(!1),[L,R]=(0,S.useState)(!1),[z,B]=(0,S.useState)(!1),[V,H]=(0,S.useState)(null),U=(0,S.useRef)(null),W=(0,S.useRef)(!1),G=D(window.location.origin);(0,S.useEffect)(()=>()=>U.current?.abort(),[]);let K=async()=>{if(W.current)return;U.current?.abort();let e=new AbortController;U.current=e,I(!1),R(!1),B(!1);try{let t=await fetch(l(i(`/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`||!T({host:`127.0.0.1`,port:n.defaultPort,publicUrl:n.defaultPublicUrl}))throw Error();if(e.signal.aborted)return;y(n),n.installation?.installed?(ne(n.installation.host??`127.0.0.1`),x(String(n.installation.port)),O(n.installation.publicUrl??``),a(n.installation.publicUrl??``)):v||(x(String(n.defaultPort)),O(n.defaultPublicUrl))}catch{e.signal.aborted||(I(!0),B(!0))}finally{e.signal.aborted||R(!0)}},q=async()=>{let e={host:b,port:Number(re),publicUrl:E};if(W.current||!G||!v||!L||z||v.busy||v.installation?.installed||!T(e))return;W.current=!0,U.current?.abort(),P(!0),I(!1),s(``);let t=new AbortController;U.current=t;try{let n=await fetch(l(i(`/api/device-center/setup`)),{credentials:`same-origin`,method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({...e,allowRegistration:!0}),signal:t.signal});if(n.status===409){y(e=>e&&{...e,busy:!0}),W.current=!1,P(!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 r=await n.json();if(!T({...e,publicUrl:r.publicUrl})||typeof r.output!=`string`)throw Error();t.signal.aborted||H(r)}catch(e){t.signal.aborted||(I(!0),s(e instanceof Error?e.message.slice(0,4096):``))}finally{W.current=!1,t.signal.aborted||P(!1)}},J=v?.installation,Y=!!J?.installed,X=Y&&J.running&&J.owned,Z=g===`remote`?ie:{host:b,port:Number(re),publicUrl:E},Q=!!Z&&T(Z);return(0,C.jsxs)(`section`,{className:`dc-onboarding`,children:[(0,C.jsx)(`h3`,{children:n(`deviceSetupWelcome`)}),(0,C.jsx)(`p`,{children:n(`deviceSetupIntro`)}),(0,C.jsxs)(`div`,{className:`dc-actions`,children:[(0,C.jsx)(`button`,{className:`dc-button`,disabled:N,"aria-pressed":m===`connect`,onClick:()=>h(`connect`),children:n(`deviceSetupConnect`)}),(0,C.jsx)(`button`,{className:`dc-button`,disabled:N,"aria-pressed":m===`create`,onClick:()=>{h(`create`),!v&&G&&K()},children:n(`deviceSetupCreate`)})]}),m===`connect`&&(0,C.jsxs)(`form`,{onSubmit:t=>{t.preventDefault(),e(r.trim())},children:[(0,C.jsxs)(`label`,{className:`dc-field`,children:[(0,C.jsx)(`span`,{children:n(`deviceHubHubUrl`)}),(0,C.jsx)(`input`,{type:`url`,required:!0,maxLength:2048,value:r,onChange:e=>a(e.target.value),placeholder:`https://hub.example.com`})]}),(0,C.jsx)(`button`,{className:`dc-button is-primary`,disabled:!T({host:`localhost`,port:8790,publicUrl:r.trim()}),children:n(`deviceSetupPair`)})]}),m===`create`&&(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`label`,{className:`dc-field`,children:[(0,C.jsx)(`span`,{children:n(`deviceSetupTarget`)}),(0,C.jsxs)(`select`,{disabled:N,value:g,onChange:e=>_(e.target.value),children:[(0,C.jsx)(`option`,{value:`current`,children:n(`deviceSetupCurrent`)}),(0,C.jsx)(`option`,{value:`remote`,children:n(`deviceSetupRemote`)})]})]}),(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(`p`,{children:n(g===`current`?`deviceSetupCurrentHint`:`deviceSetupRemoteHint`)}),g===`current`&&(0,C.jsxs)(`div`,{className:`dc-setup-plan`,children:[(0,C.jsx)(`strong`,{children:n(`deviceSetupPlan`)}),(0,C.jsx)(`p`,{children:n(`deviceSetupPlanHint`)}),v&&(0,C.jsxs)(`dl`,{children:[(0,C.jsx)(`dt`,{children:n(`deviceSetupEnvironment`)}),(0,C.jsxs)(`dd`,{children:[v.platform,` · Node `,v.nodeVersion]}),(0,C.jsx)(`dt`,{children:n(`deviceSetupDataDir`)}),(0,C.jsx)(`dd`,{children:v.dataDir}),(0,C.jsx)(`dt`,{children:n(`deviceSetupCli`)}),(0,C.jsx)(`dd`,{children:v.cliPath})]}),!G&&(0,C.jsx)(`p`,{role:`status`,children:n(`deviceSetupLocalOnly`)}),(0,C.jsx)(`p`,{children:n(`deviceSetupBackground`)}),Y&&(0,C.jsxs)(`div`,{role:`status`,children:[(0,C.jsx)(`h4`,{children:n(X?`deviceSetupRestored`:`deviceSetupUnhealthy`)}),(0,C.jsx)(`p`,{children:J.publicUrl}),X&&Q&&J.publicUrl?(0,C.jsxs)(`div`,{className:`dc-actions`,children:[(0,C.jsx)(w,{href:J.publicUrl,children:n(`deviceHubOpenHub`)}),(0,C.jsx)(`button`,{className:`dc-button`,onClick:()=>e(J.publicUrl),children:n(`deviceSetupPair`)})]}):(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(`p`,{children:n(`deviceSetupRecovery`)}),(0,C.jsx)(`pre`,{className:`dc-setup-output`,children:`pi-web-ui hub status --json
|
|
3
|
+
pi-web-ui hub --help`})]})]}),v?.busy&&(0,C.jsx)(`p`,{role:`status`,children:n(`deviceSetupBusy`)}),G&&(0,C.jsx)(`button`,{className:`dc-button`,disabled:N||!L,onClick:()=>void K(),children:n(L?`deviceSetupRetry`:`deviceHubWorking`)})]}),g===`remote`?(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`div`,{className:`dc-setup-fields`,children:[(0,C.jsxs)(`label`,{className:`dc-field`,children:[(0,C.jsx)(`span`,{children:n(`deviceSetupServer`)}),(0,C.jsx)(`input`,{autoComplete:`off`,maxLength:253,placeholder:`203.0.113.10`,value:k.server,onChange:e=>A({...k,server:e.target.value.trim()})})]}),(0,C.jsxs)(`label`,{className:`dc-field`,children:[(0,C.jsx)(`span`,{children:n(`deviceSetupSshPort`)}),(0,C.jsx)(`input`,{type:`number`,min:1,max:65535,value:k.sshPort,onChange:e=>A({...k,sshPort:Number(e.target.value)})})]}),(0,C.jsxs)(`label`,{className:`dc-field`,children:[(0,C.jsx)(`span`,{children:n(`deviceSetupUsername`)}),(0,C.jsx)(`input`,{autoComplete:`off`,maxLength:64,value:k.username,onChange:e=>A({...k,username:e.target.value})})]}),(0,C.jsxs)(`label`,{className:`dc-field`,children:[(0,C.jsx)(`span`,{children:n(`deviceSetupAuth`)}),(0,C.jsxs)(`select`,{value:k.auth,onChange:e=>A({...k,auth:e.target.value}),children:[(0,C.jsx)(`option`,{value:`password`,children:n(`deviceSetupAuthPassword`)}),(0,C.jsx)(`option`,{value:`key`,children:n(`deviceSetupAuthKey`)}),(0,C.jsx)(`option`,{value:`existing`,children:n(`deviceSetupAuthExisting`)})]})]}),(0,C.jsxs)(`label`,{className:`dc-field`,children:[(0,C.jsx)(`span`,{children:n(`deviceSetupServicePort`)}),(0,C.jsx)(`input`,{type:`number`,min:1024,max:65535,value:k.port,onChange:e=>A({...k,port:Number(e.target.value)})})]})]}),(0,C.jsx)(`p`,{children:n(`deviceSetupCredentialHint`)}),(0,C.jsxs)(`details`,{children:[(0,C.jsx)(`summary`,{children:n(`deviceSetupOptionalTls`)}),(0,C.jsxs)(`label`,{className:`dc-field`,children:[(0,C.jsx)(`span`,{children:n(`deviceSetupDomain`)}),(0,C.jsx)(`input`,{maxLength:253,placeholder:`hub.example.com`,value:k.domain,onChange:e=>A({...k,domain:e.target.value.trim()})})]}),(0,C.jsxs)(`label`,{children:[(0,C.jsx)(`input`,{type:`checkbox`,checked:k.https,onChange:e=>A({...k,https:e.target.checked})}),` `,n(`deviceSetupEnableHttps`)]}),(0,C.jsx)(`p`,{children:n(`deviceSetupTlsHint`)})]}),(0,C.jsxs)(`p`,{children:[(0,C.jsx)(`strong`,{children:n(`deviceSetupPreview`)}),` `,ie?.publicUrl??n(`deviceSetupPreviewEmpty`)]}),(0,C.jsxs)(`div`,{className:`dc-setup-plan`,children:[(0,C.jsx)(`strong`,{children:n(`deviceSetupUserActions`)}),(0,C.jsx)(`p`,{children:n(`deviceSetupCloudPorts`).replace(`{ports}`,k.https?`443 / 80`:String(k.port))}),(0,C.jsx)(`p`,{children:n(`deviceSetupSourceScope`)}),(0,C.jsx)(`p`,{children:n(`deviceSetupAfterStart`)})]}),(0,C.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,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`div`,{className:`dc-setup-fields`,children:[(0,C.jsxs)(`label`,{className:`dc-field`,children:[(0,C.jsx)(`span`,{children:n(`deviceSetupHost`)}),(0,C.jsx)(`input`,{disabled:N||!!V,maxLength:253,value:b,onChange:e=>ne(e.target.value)})]}),(0,C.jsxs)(`label`,{className:`dc-field`,children:[(0,C.jsx)(`span`,{children:n(`deviceSetupPort`)}),(0,C.jsx)(`input`,{disabled:N||!!V,type:`number`,min:1024,max:65535,value:re,onChange:e=>x(e.target.value)})]}),(0,C.jsxs)(`label`,{className:`dc-field`,children:[(0,C.jsx)(`span`,{children:n(`deviceHubHubUrl`)}),(0,C.jsx)(`input`,{disabled:N||!!V,maxLength:2048,value:E,onChange:e=>O(e.target.value)})]})]}),(0,C.jsx)(`p`,{className:`dc-setup-warning`,children:n(`deviceSetupReachable`)})]}),(0,C.jsx)(`p`,{children:n(`deviceSetupRegistration`)}),!Q&&(0,C.jsx)(`p`,{role:`alert`,children:n(g===`remote`?`deviceSetupRemoteInvalid`:`deviceSetupInvalid`)}),(0,C.jsxs)(`div`,{className:`dc-actions`,children:[g===`current`&&!V&&!Y&&(0,C.jsx)(`button`,{className:`dc-button is-primary`,disabled:N||!G||!v||!L||z||!!v.busy||!Q,onClick:()=>void q(),children:n(N?`deviceSetupInstalling`:`deviceSetupInstall`)}),(0,C.jsx)(`button`,{className:`dc-button`,disabled:N||ee||!Q,onClick:()=>{if(!Q||!Z||f.current)return;f.current=!0,c(!0),d(!1);let e=e=>{f.current=!1,p.current&&(c(!1),d(!e))},t=window.__piWebUiHost;try{t?.startChat({newChat:!0,prompt:M(Z,v,g,g===`remote`?k:void 0),onResult:e})||e(!1)}catch{e(!1)}},children:n(g===`remote`?`deviceSetupStartAi`:`deviceSetupAi`)})]}),(0,C.jsx)(`p`,{children:n(`deviceSetupAiHint`)}),ee&&(0,C.jsx)(`p`,{role:`status`,children:n(`deviceSetupAiCreating`)}),u&&(0,C.jsx)(`p`,{role:`alert`,children:n(`deviceSetupAiFailed`)})]})]}),F&&(0,C.jsxs)(`div`,{role:`alert`,children:[(0,C.jsx)(`p`,{children:n(`deviceSetupFailed`)}),o&&(0,C.jsx)(`pre`,{className:`dc-setup-output`,children:o})]}),V&&(0,C.jsxs)(`div`,{role:`status`,children:[(0,C.jsx)(`h4`,{children:n(`deviceSetupSuccess`)}),(0,C.jsx)(`pre`,{className:`dc-setup-output`,children:V.output.slice(0,16e3)}),(0,C.jsxs)(`div`,{className:`dc-actions`,children:[(0,C.jsx)(w,{href:V.publicUrl,children:n(`deviceHubOpenHub`)}),(0,C.jsx)(`button`,{className:`dc-button is-primary`,onClick:()=>e(V.publicUrl),children:n(`deviceSetupPair`)})]})]})]})}var N=`pi-web-ui:device-groups-changed`;function P(e){window.dispatchEvent(new CustomEvent(`pi-web-ui:device-group-open`,{detail:{roomId:e}}))}async function F(e,t,n){let r=await fetch(l(i(`/api/device-center/${e}`)),{method:n?`POST`:`GET`,credentials:`same-origin`,signal:t,...n?{headers:{"Content-Type":`application/json`},body:JSON.stringify(n)}:{}}),a=await r.json().catch(()=>({}));if(!r.ok)throw Error(a.error||a.message||`Request failed (${r.status})`);return a}function I(){let{locale:e}=g(),t=r(e),[i,o]=(0,S.useState)([]),[s,ee]=(0,S.useState)([]),[l,te]=(0,S.useState)(!0),[d,m]=(0,S.useState)(``),[_,y]=(0,S.useState)(``),[b,ne]=(0,S.useState)(0),[re,x]=(0,S.useState)(!1),[w,T]=(0,S.useState)(``),[E,D]=(0,S.useState)([]),[O,k]=(0,S.useState)(``),[A,j]=(0,S.useState)(null),[M,ie]=(0,S.useState)([]),[I,L]=(0,S.useState)(``),[R,z]=(0,S.useState)(null),[B,V]=(0,S.useState)(``),[H,U]=(0,S.useState)(!1),W=(0,S.useRef)(0);(0,S.useEffect)(()=>{let e=++W.current,t=new AbortController;async function n(){try{let[n,r]=await Promise.all([F(`rooms`,t.signal),F(`bots`,t.signal)]);if(W.current!==e||t.signal.aborted)return;o(Array.isArray(n.rooms)?n.rooms:[]),ee(Array.isArray(r.bots)?r.bots:[]),m(``)}catch(n){W.current===e&&!t.signal.aborted&&m(n instanceof Error?n.message:String(n))}finally{W.current===e&&!t.signal.aborted&&te(!1)}}return n(),()=>{t.abort()}},[b]),(0,S.useEffect)(()=>{let e=()=>ne(e=>e+1);return window.addEventListener(N,e),()=>window.removeEventListener(N,e)},[]);async function G(e){if(e.preventDefault(),!w.trim()||H)return;U(!0),m(``),y(``);let n=new AbortController;try{let e=E.includes(O)?O:``,r=await F(`rooms`,n.signal,{name:w.trim(),botIds:E,...e?{primaryBotId:e}:{}});o(e=>[...e.filter(e=>e.id!==r.room.id),r.room]),x(!1),T(``),D([]),k(``),y(t?`群聊创建成功`:`Group created successfully`),window.dispatchEvent(new CustomEvent(N))}catch(e){m(e instanceof Error?e.message:String(e))}finally{U(!1)}}function K(e){j(e.id),ie([...e.botIds]),L(e.primaryBotId??``),z(null),x(!1),m(``),y(``)}async function q(e){if(H)return;U(!0),m(``),y(``);let n=new AbortController;try{let r=M.includes(I)?I:null,i=await F(`rooms/${encodeURIComponent(e)}/members`,n.signal,{botIds:M,primaryBotId:r});o(t=>t.map(t=>t.id===e?i.room:t)),j(null),y(t?`成员设置已保存`:`Members updated successfully`),window.dispatchEvent(new CustomEvent(N))}catch(e){m(e instanceof Error?e.message:String(e))}finally{U(!1)}}async function J(e){if(!B.trim()||H)return;U(!0),m(``),y(``);let n=new AbortController;try{await F(`rooms/${encodeURIComponent(e)}/rename`,n.signal,{name:B.trim()}),o(t=>t.map(t=>t.id===e?{...t,name:B.trim()}:t)),z(null),y(t?`群聊名称已更新`:`Group renamed successfully`),window.dispatchEvent(new CustomEvent(N))}catch(e){m(e instanceof Error?e.message:String(e))}finally{U(!1)}}async function Y(e){if(H||!window.confirm(t?`确定删除群聊“${e.name}”?`:`Are you sure you want to delete "${e.name}"?`))return;U(!0),m(``),y(``);let n=new AbortController;try{await F(`rooms/${encodeURIComponent(e.id)}/delete`,n.signal,{}),o(t=>t.filter(t=>t.id!==e.id)),A===e.id&&j(null),R===e.id&&z(null),y(t?`群聊已删除`:`Group deleted successfully`),window.dispatchEvent(new CustomEvent(N))}catch(e){m(e instanceof Error?e.message:String(e))}finally{U(!1)}}return(0,C.jsxs)(`section`,{className:`dc-card`,"aria-label":t?`群聊列表`:`Group list`,children:[(0,C.jsxs)(`div`,{className:`dc-card-header`,children:[(0,C.jsx)(`span`,{className:`dc-icon`,children:(0,C.jsx)(f,{"aria-hidden":!0})}),(0,C.jsxs)(`div`,{children:[(0,C.jsxs)(`h2`,{children:[t?`群聊列表`:`Group List`,` · `,i.length]}),(0,C.jsx)(`p`,{children:t?`管理群聊与成员 Bot,在此配置协作群组或直接进入聊天。`:`Manage groups and member Bots. Configure collaboration groups or open chats here.`})]}),(0,C.jsxs)(`div`,{className:`dc-actions`,style:{marginInlineStart:`auto`},children:[(0,C.jsxs)(`button`,{type:`button`,className:`dc-button is-primary`,disabled:H,onClick:()=>{x(e=>!e),j(null),z(null),T(``),D([]),k(``)},children:[(0,C.jsx)(c,{"aria-hidden":!0}),t?`新建群聊`:`Create Group`]}),(0,C.jsx)(`button`,{type:`button`,className:`dc-icon-button`,"aria-label":t?`刷新群聊`:`Refresh groups`,onClick:()=>ne(e=>e+1),children:(0,C.jsx)(v,{})})]})]}),d&&(0,C.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:d}),_&&(0,C.jsxs)(`p`,{className:`dc-notice is-success`,role:`status`,children:[(0,C.jsx)(n,{"aria-hidden":!0}),_]}),re&&(0,C.jsxs)(`form`,{className:`dc-card`,style:{marginBottom:`16px`,background:`var(--bg)`,border:`1px solid var(--border)`},onSubmit:G,children:[(0,C.jsxs)(`div`,{className:`dg-heading`,style:{marginBottom:`12px`},children:[(0,C.jsx)(`h3`,{children:t?`新建群聊`:`Create Group`}),(0,C.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>x(!1),disabled:H,children:[(0,C.jsx)(h,{"aria-hidden":!0}),t?`关闭`:`Close`]})]}),(0,C.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`12px`},children:[(0,C.jsx)(`label`,{htmlFor:`dg-manager-new-name`,children:t?`群名称`:`Group Name`}),(0,C.jsx)(`input`,{id:`dg-manager-new-name`,type:`text`,required:!0,maxLength:80,value:w,placeholder:t?`输入群名称,如:研发协作群`:`Enter group name`,onChange:e=>T(e.target.value),disabled:H,style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`}})]}),(0,C.jsxs)(`div`,{style:{marginBottom:`12px`},children:[(0,C.jsx)(`label`,{style:{display:`block`,marginBottom:`6px`,fontSize:`12px`,color:`var(--text-dim)`},children:t?`选择成员 Bot`:`Select Member Bots`}),(0,C.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:s.length===0?(0,C.jsx)(`p`,{style:{margin:0,fontSize:`12px`,color:`var(--text-faint)`},children:t?`暂无可用 Bot,请先创建 Bot。`:`No Bots available. Please create a Bot first.`}):s.map(e=>(0,C.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,cursor:`pointer`,fontSize:`12px`},children:[(0,C.jsx)(`input`,{type:`checkbox`,checked:E.includes(e.id),disabled:H||!e.enabled,onChange:t=>{D(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}}),(0,C.jsxs)(`span`,{children:[(0,C.jsx)(`strong`,{children:e.name}),(0,C.jsxs)(`small`,{style:{color:`var(--text-faint)`,marginInlineStart:`6px`},children:[e.online?t?`在线`:`Online`:t?`离线`:`Offline`,e.enabled?``:t?` · 已禁用`:` · Disabled`]})]})]},e.id))})]}),E.length>0&&(0,C.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`16px`},children:[(0,C.jsx)(`label`,{htmlFor:`dg-manager-new-primary`,children:t?`主 Bot`:`Primary Bot`}),(0,C.jsxs)(`select`,{id:`dg-manager-new-primary`,value:E.includes(O)?O:``,onChange:e=>k(e.target.value),disabled:H,style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`},children:[(0,C.jsx)(`option`,{value:``,children:t?`不设置(需 @ Bot)`:`None (mention a Bot)`}),s.filter(e=>E.includes(e.id)).map(e=>(0,C.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,C.jsxs)(`div`,{className:`dc-actions`,children:[(0,C.jsxs)(`button`,{type:`submit`,className:`dc-button is-primary`,disabled:H||!w.trim(),children:[(0,C.jsx)(n,{"aria-hidden":!0}),H?t?`创建中…`:`Creating…`:t?`创建群聊`:`Create`]}),(0,C.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>x(!1),disabled:H,children:t?`取消`:`Cancel`})]})]}),A&&(0,C.jsxs)(`div`,{className:`dc-card`,style:{marginBottom:`16px`,background:`var(--bg)`,border:`1px solid var(--border)`},children:[(0,C.jsxs)(`div`,{className:`dg-heading`,style:{marginBottom:`12px`},children:[(0,C.jsxs)(`h3`,{children:[t?`管理成员`:`Manage Members`,` · `,i.find(e=>e.id===A)?.name]}),(0,C.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>j(null),disabled:H,children:[(0,C.jsx)(h,{"aria-hidden":!0}),t?`关闭`:`Close`]})]}),(0,C.jsxs)(`div`,{style:{marginBottom:`12px`},children:[(0,C.jsx)(`label`,{style:{display:`block`,marginBottom:`6px`,fontSize:`12px`,color:`var(--text-dim)`},children:t?`选择成员 Bot`:`Select Member Bots`}),(0,C.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:s.length===0?(0,C.jsx)(`p`,{style:{margin:0,fontSize:`12px`,color:`var(--text-faint)`},children:t?`暂无可用 Bot`:`No Bots available`}):s.map(e=>(0,C.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,cursor:`pointer`,fontSize:`12px`},children:[(0,C.jsx)(`input`,{type:`checkbox`,checked:M.includes(e.id),disabled:H,onChange:t=>{ie(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}}),(0,C.jsxs)(`span`,{children:[(0,C.jsx)(`strong`,{children:e.name}),(0,C.jsxs)(`small`,{style:{color:`var(--text-faint)`,marginInlineStart:`6px`},children:[e.online?t?`在线`:`Online`:t?`离线`:`Offline`,e.enabled?``:t?` · 已禁用`:` · Disabled`]})]})]},e.id))})]}),(0,C.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`16px`},children:[(0,C.jsx)(`label`,{htmlFor:`dg-manager-edit-primary`,children:t?`主 Bot`:`Primary Bot`}),(0,C.jsxs)(`select`,{id:`dg-manager-edit-primary`,value:M.includes(I)?I:``,onChange:e=>L(e.target.value),disabled:H,style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`},children:[(0,C.jsx)(`option`,{value:``,children:t?`不设置(需 @ Bot)`:`None (mention a Bot)`}),s.filter(e=>M.includes(e.id)).map(e=>(0,C.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,C.jsxs)(`div`,{className:`dc-actions`,children:[(0,C.jsxs)(`button`,{type:`button`,className:`dc-button is-primary`,disabled:H,onClick:()=>void q(A),children:[(0,C.jsx)(n,{"aria-hidden":!0}),H?t?`保存中…`:`Saving…`:t?`保存成员设置`:`Save Members`]}),(0,C.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>j(null),disabled:H,children:t?`取消`:`Cancel`})]})]}),l&&(0,C.jsx)(`p`,{role:`status`,children:t?`加载中…`:`Loading…`}),!l&&i.length===0&&(0,C.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,C.jsx)(`div`,{className:`dd-list`,children:i.map(e=>{let r=R===e.id,i=s.filter(t=>e.botIds.includes(t.id)),o=s.find(t=>t.id===e.primaryBotId);return(0,C.jsxs)(`div`,{className:`dd-device`,style:r?{flexWrap:`wrap`}:void 0,children:[(0,C.jsx)(`span`,{className:`dc-device-icon`,children:(0,C.jsx)(f,{"aria-hidden":!0})}),(0,C.jsxs)(`div`,{className:`dd-identity`,style:{flex:1,minWidth:`200px`},children:[(0,C.jsx)(`strong`,{children:e.name}),(0,C.jsxs)(`span`,{style:{display:`flex`,gap:`8px`,flexWrap:`wrap`,alignItems:`center`},children:[(0,C.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(`, `)}`:``}`}),o&&(0,C.jsx)(`span`,{style:{color:`var(--accent)`},children:t?`[主 Bot: ${o.name}]`:`[Primary: ${o.name}]`})]})]}),(0,C.jsxs)(`div`,{className:`dc-actions`,children:[(0,C.jsxs)(`button`,{type:`button`,className:`dc-button is-primary`,title:t?`打开聊天`:`Open chat`,onClick:()=>P(e.id),children:[(0,C.jsx)(a,{"aria-hidden":!0}),t?`打开聊天`:`Open chat`]}),(0,C.jsxs)(`button`,{type:`button`,className:`dc-button`,title:t?`管理成员`:`Manage members`,onClick:()=>K(e),children:[(0,C.jsx)(f,{"aria-hidden":!0}),t?`管理成员`:`Members`]}),(0,C.jsxs)(`button`,{type:`button`,className:`dc-button`,title:t?`重命名`:`Rename`,onClick:()=>{r?z(null):(z(e.id),V(e.name))},children:[(0,C.jsx)(u,{"aria-hidden":!0}),t?`重命名`:`Rename`]}),(0,C.jsx)(`button`,{type:`button`,className:`dc-button is-danger`,title:t?`删除群聊`:`Delete group`,disabled:H,onClick:()=>void Y(e),children:(0,C.jsx)(p,{"aria-hidden":!0})})]}),r&&(0,C.jsxs)(`form`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,width:`100%`,paddingTop:`8px`,paddingBottom:`4px`},onSubmit:t=>{t.preventDefault(),J(e.id)},children:[(0,C.jsx)(`input`,{type:`text`,maxLength:80,autoFocus:!0,disabled:H,value:B,onChange:e=>V(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,C.jsxs)(`button`,{type:`submit`,className:`dc-button is-primary`,disabled:H||!B.trim(),children:[(0,C.jsx)(n,{"aria-hidden":!0}),t?`保存`:`Save`]}),(0,C.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:H,onClick:()=>z(null),children:[(0,C.jsx)(h,{"aria-hidden":!0}),t?`取消`:`Cancel`]})]})]},e.id)})})]})}var L=class extends Error{status;constructor(e,t){super(t),this.status=e}};function R(e){try{let t=new URL(e);return[`http:`,`https:`].includes(t.protocol)&&!t.username&&!t.password?t.href:null}catch{return null}}function z(){let e=te(),t=_().startsWith(`zh`),[n,r]=(0,S.useState)(null),[a,o]=(0,S.useState)(!1),[s,c]=(0,S.useState)(!1),[u,d]=(0,S.useState)(!1),[f,p]=(0,S.useState)(!1),m=(0,S.useRef)(0),h=(0,S.useRef)(null);async function g(e,t){if(h.current)return;let n=++m.current,a=new AbortController;h.current=a,o(!0),c(!1);try{let o=await fetch(l(i(`/api/device-desktop/local/${e}`)),{method:t?`POST`:`GET`,credentials:`same-origin`,signal:a.signal,...t?{headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}:{}});if(m.current!==n||a.signal.aborted)return;if(o.status===403){d(!0),r(null);return}if(!o.ok)throw Error(`Request failed`);let s=await o.json();if(m.current!==n||a.signal.aborted)return;if(e===`permissions`){if(typeof s?.screen!=`boolean`||typeof s?.accessibility!=`boolean`)throw Error(`Invalid permission status`);r(e=>e&&{...e,permissions:{supported:!0,screen:s.screen,accessibility:s.accessibility}}),p(!0)}else{if(typeof s?.os!=`string`||typeof s.enabled!=`boolean`||typeof s.environmentEnabled!=`boolean`||typeof s.supported!=`boolean`)throw Error(`Invalid desktop status`);r(s)}}catch{m.current===n&&!a.signal.aborted&&c(!0)}finally{m.current===n&&!a.signal.aborted&&(h.current=null,o(!1))}}return(0,S.useEffect)(()=>(g(`status`),()=>{m.current++,h.current?.abort(),h.current=null}),[]),(0,C.jsxs)(`section`,{className:`dc-card`,"aria-label":t?`本机远程桌面`:`Local remote desktop`,"aria-busy":a,children:[(0,C.jsxs)(`div`,{className:`dc-card-header`,children:[(0,C.jsx)(`span`,{className:`dc-icon`,children:(0,C.jsx)(ee,{"aria-hidden":!0})}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`h2`,{children:t?`本机远程桌面`:`Local remote desktop`}),(0,C.jsx)(`p`,{children:t?`管理这台设备的远程桌面与系统权限,无需连接设备中心。`:`Manage remote desktop and system permissions on this device, even while the device center is offline.`})]})]}),u?(0,C.jsx)(`p`,{role:`status`,children:t?`请在设备本机打开此页面以管理远程桌面权限。`:`Open this page on the device itself to manage remote desktop permissions.`}):(0,C.jsxs)(C.Fragment,{children:[n&&(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`div`,{className:`dc-permission-row`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`h3`,{id:`dc-desktop-label`,children:t?`启用远程桌面`:`Enable remote desktop`}),(0,C.jsx)(`p`,{children:n.enabled?t?`已启用`:`Enabled`:t?`未启用`:`Disabled`})]}),(0,C.jsx)(`button`,{type:`button`,className:`dc-toggle${n.enabled?` is-on`:``}`,role:`switch`,"aria-checked":n.enabled,"aria-labelledby":`dc-desktop-label`,disabled:a||n.environmentEnabled||!n.supported&&!n.enabled,onClick:()=>void g(`enable`,{enabled:!n.enabled}),children:(0,C.jsx)(`span`,{className:`dc-toggle-thumb`})})]}),!n.supported&&(0,C.jsx)(`p`,{children:t?`这台设备暂不支持远程桌面。`:`Remote desktop is currently unavailable on this device.`}),n.environmentEnabled&&(0,C.jsx)(`p`,{children:t?`远程桌面由本机服务设置保持启用。`:`Remote desktop is kept enabled by the service settings on this device.`}),n.os===`darwin`&&(0,C.jsxs)(C.Fragment,{children:[(0,C.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,C.jsxs)(`div`,{className:`dc-actions`,children:[(0,C.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:a||n.permissions?.supported===!1,onClick:()=>void g(`permissions`,{kind:`screen`}),children:t?`授予屏幕录制权限`:`Grant screen recording permission`}),(0,C.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:a||n.permissions?.supported===!1,onClick:()=>void g(`permissions`,{kind:`control`}),children:t?`授予远程控制权限`:`Grant remote control permission`})]}),n.permissions?.screen===!0&&(0,C.jsx)(`p`,{children:t?`屏幕录制:已授权`:`Screen recording: granted`}),n.permissions?.accessibility===!0&&(0,C.jsx)(`p`,{children:t?`远程控制:已授权`:`Remote control: granted`}),f&&(0,C.jsx)(`p`,{role:`status`,children:t?`已发起授权请求,请确认系统设置后刷新状态。`:`Permission requested. Confirm in System Settings, then refresh the status.`})]})]}),s&&(0,C.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:t?`无法更新本机远程桌面设置,请重试。`:`Unable to update local remote desktop settings. Please retry.`}),(0,C.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:a,onClick:()=>void g(`status`),children:[(0,C.jsx)(v,{"aria-hidden":!0}),a?e(`deviceHubWorking`):t?`刷新远程桌面状态`:`Refresh remote desktop status`]})]})]})}function B({pathCompletions:e=[]}){let r=te(),[a,c]=(0,S.useState)(null),[u,f]=(0,S.useState)(``),[p,h]=(0,S.useState)(``),[g,_]=(0,S.useState)(null),[y,b]=(0,S.useState)(!1),[T,E]=(0,S.useState)(Date.now()),[D,O]=(0,S.useState)(null),[k,A]=(0,S.useState)(``),[j,M]=(0,S.useState)(``),[N,P]=(0,S.useState)(``),[F,B]=(0,S.useState)(!1),[V,H]=(0,S.useState)(!0),U=(0,S.useRef)(!1),W=(0,S.useRef)(0),G=(0,S.useRef)(new Set),K=(0,S.useRef)(!1),q=(0,S.useRef)(!1),J=(0,S.useRef)(null),Y=(0,S.useRef)(r);Y.current=r,(0,S.useEffect)(()=>{let e=e=>{let t=e;t.detail?.deviceId&&J.current?.deviceId===t.detail.deviceId&&(c(e=>e&&{...e,remark:t.detail.remark}),J.current&&(J.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 X(e,t){let n=new AbortController;G.current.add(n);try{let r=await fetch(l(i(`/api/device-center/${e}`)),{method:t?`POST`:`GET`,credentials:`same-origin`,signal:n.signal,...t?{headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}:{}}),a=await r.json().catch(()=>({}));if(!r.ok)throw new L(r.status,typeof a.error==`string`?a.error:Y.current(`deviceHubRequestFailed`,{status:r.status}));return a}finally{G.current.delete(n)}}function Z(e){return U.current&&W.current===e}function Q(e){return e instanceof L&&e.status===403?(B(!0),Y.current(`deviceHubLocalOnly`)):e instanceof Error?e.message:Y.current(`deviceHubNetworkError`)}function ae(e){J.current=e,c(e),q.current||(h(e.name),f(e.hubUrl??``))}async function oe(){let e=W.current;try{let t=await X(`status`);if(!Z(e)||K.current)return;ae(t),M(``),B(!1)}catch(t){Z(e)&&M(Q(t))}finally{Z(e)&&H(!1)}}(0,S.useEffect)(()=>{U.current=!0;let e=!1,t,n=async()=>{await oe(),!e&&U.current&&(t=setTimeout(n,5e3))};return n(),()=>{e=!0,U.current=!1,W.current++,clearTimeout(t);for(let e of G.current)e.abort()}},[]),(0,S.useEffect)(()=>{if(!g)return;let e=W.current,t=!1,n,r=setInterval(()=>E(Date.now()),1e3),i=async()=>{if(!(t||!Z(e)||Date.now()>=g.expiresAt)){try{let n=await X(`poll`,{});if(t||!Z(e))return;if(n.paired){let n=await X(`status`);if(t||!Z(e))return;q.current=!1,ae(n),_(null),A(``),P(``);return}A(``)}catch(n){!t&&Z(e)&&A(`${Y.current(`deviceHubPollError`)} ${Q(n)}`)}!t&&Z(e)&&(n=setTimeout(i,2e3))}};return n=setTimeout(i,2e3),()=>{t=!0,clearTimeout(n),clearInterval(r)}},[g]);async function se(){if(K.current)return;let e=R(u.trim());if(!e){A(r(`deviceHubInvalidUrl`));return}if(!p.trim()||p.trim().length>80){A(r(`deviceHubInvalidName`));return}let t=++W.current;K.current=!0,O(`pair`),A(``),P(``),_(null);try{let n=await X(`pair`,{hubUrl:e,name:p.trim()});if(!Z(t))return;if(!n.code||!Number.isFinite(n.expiresAt)||!R(n.hubUrl))throw Error(r(`deviceHubPairError`));E(Date.now()),_(n)}catch(e){Z(t)&&A(`${r(`deviceHubPairError`)} ${Q(e)}`)}finally{Z(t)&&(K.current=!1,O(null))}}async function ce(){let e=J.current;if(!e?.deviceId||K.current)return;let t=++W.current;K.current=!0,O(`permission`),A(``),P(``),ae({...e,allowExecution:!e.allowExecution});try{await X(`execution`,{allowExecution:!e.allowExecution}),Z(t)&&P(r(`deviceHubSaved`))}catch(n){Z(t)&&(ae(e),A(`${r(`deviceHubPermissionError`)} ${Q(n)}`))}finally{Z(t)&&(K.current=!1,O(null))}}async function le(){let e=J.current;if(!e?.deviceId||K.current||!window.confirm(r(`deviceHubDisconnectConfirm`,{name:e.name})))return;let t=++W.current;K.current=!0,O(`disconnect`),A(``),P(``);try{if(await X(`disconnect`,{}),!Z(t))return;q.current=!1,ae({name:e.name,allowExecution:!1,connected:!1}),_(null)}catch(e){Z(t)&&A(`${r(`deviceHubDisconnectError`)} ${Q(e)}`)}finally{Z(t)&&(K.current=!1,O(null))}}async function ue(){if(!g)return;let e=W.current;try{await navigator.clipboard.writeText(g.code),Z(e)&&P(r(`deviceHubCopied`))}catch{Z(e)&&A(r(`deviceHubCopyFailed`))}}let $=!!a?.deviceId,de=R($?a?.hubUrl??``:g?.hubUrl??``),fe=Math.max(0,Math.ceil(((g?.expiresAt??0)-T)/1e3)),pe=`${Math.floor(fe/60)}:${String(fe%60).padStart(2,`0`)}`,me=de?(0,C.jsxs)(w,{href:de,children:[(0,C.jsx)(t,{"aria-hidden":!0}),r(`deviceHubOpenHub`)]}):null;return(0,C.jsxs)(`section`,{className:`dc-page`,"aria-label":r(`deviceHubTitle`),children:[(0,C.jsxs)(`header`,{className:`dc-header`,children:[(0,C.jsxs)(`div`,{className:`dc-heading`,children:[(0,C.jsxs)(`span`,{className:`dc-eyebrow`,children:[(0,C.jsx)(ee,{"aria-hidden":!0}),r(`deviceHubTitle`)]}),(0,C.jsx)(`h1`,{children:r(`deviceHubTitle`)}),(0,C.jsx)(`p`,{children:r(`deviceHubSubtitle`)})]}),(0,C.jsxs)(`div`,{className:`dc-actions`,children:[$&&me,(0,C.jsxs)(`span`,{className:`dc-status ${$?a?.connected?`is-online`:`is-offline`:`is-unpaired`}`,children:[(0,C.jsx)(`span`,{className:`dc-status-dot`}),r($?a?.connected?`deviceHubOnline`:`deviceHubOffline`:`deviceHubUnpaired`)]})]})]}),(0,C.jsx)(`div`,{className:`dc-layout`,style:{display:`block`},children:(0,C.jsxs)(`main`,{className:`dc-content`,children:[V&&(0,C.jsxs)(`div`,{className:`dc-loading`,role:`status`,children:[(0,C.jsx)(v,{"aria-hidden":!0}),r(`deviceHubLoading`)]}),(F||j)&&(0,C.jsxs)(`div`,{className:`dc-notice is-error`,role:`alert`,children:[(0,C.jsx)(`span`,{children:F?r(`deviceHubLocalOnly`):`${r(`deviceHubStatusError`)} ${j}`}),(0,C.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>void oe(),children:[(0,C.jsx)(v,{"aria-hidden":!0}),r(`deviceHubRetry`)]})]}),k&&!F&&(0,C.jsx)(`div`,{className:`dc-notice is-error`,role:`alert`,children:k}),N&&(0,C.jsxs)(`div`,{className:`dc-notice is-success`,role:`status`,children:[(0,C.jsx)(n,{"aria-hidden":!0}),N]}),!$&&(a||F)&&(0,C.jsx)(ie,{initialHubUrl:u,onConnect:e=>{if(F){P(r(`deviceHubLocalOnly`));return}q.current=!0,f(e),b(!0)}}),a&&!F&&!$&&(0,C.jsxs)(`section`,{className:`dc-card`,children:[(0,C.jsxs)(`div`,{className:`dc-card-header`,children:[(0,C.jsx)(`span`,{className:`dc-icon`,children:(0,C.jsx)(d,{"aria-hidden":!0})}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`h2`,{children:r(`deviceHubPairTitle`)}),(0,C.jsx)(`p`,{children:r(`deviceHubPairHint`)})]})]}),(0,C.jsx)(`ol`,{className:`dc-steps`,children:[`deviceHubStepDetails`,`deviceHubStepApprove`,`deviceHubStepWait`].map((e,t)=>(0,C.jsxs)(`li`,{className:g?t===0?`is-complete`:`is-active`:t===0?`is-active`:``,children:[(0,C.jsx)(`span`,{className:`dc-step-number`,children:g&&t===0?(0,C.jsx)(n,{"aria-hidden":!0}):t+1}),(0,C.jsx)(`span`,{children:r(e)})]},e))}),(0,C.jsxs)(`form`,{className:`dc-form`,onSubmit:e=>{e.preventDefault(),se()},children:[(0,C.jsxs)(`div`,{className:`dc-field`,children:[(0,C.jsx)(`label`,{htmlFor:`dc-hub-url`,children:r(`deviceHubHubUrl`)}),(0,C.jsx)(`input`,{id:`dc-hub-url`,type:`url`,autoComplete:`url`,required:!0,placeholder:r(`deviceHubHubPlaceholder`),value:u,disabled:!!g||!!D,onChange:e=>{q.current=!0,f(e.target.value)}})]}),(0,C.jsxs)(`div`,{className:`dc-field`,children:[(0,C.jsx)(`label`,{htmlFor:`dc-device-name`,children:r(`deviceHubName`)}),(0,C.jsx)(`input`,{id:`dc-device-name`,maxLength:80,required:!0,autoComplete:`off`,placeholder:r(`deviceHubNamePlaceholder`),value:p,disabled:!!g||!!D,onChange:e=>{q.current=!0,h(e.target.value)}})]}),!g&&(0,C.jsx)(`div`,{className:`dc-actions`,children:(0,C.jsxs)(`button`,{className:`dc-button is-primary`,type:`submit`,disabled:!!D,children:[(0,C.jsx)(d,{"aria-hidden":!0}),r(D?`deviceHubWorking`:`deviceHubGetCode`)]})})]}),g&&(0,C.jsxs)(`div`,{className:`dc-pairing`,children:[(0,C.jsx)(`span`,{className:`dc-code-label`,children:r(`deviceHubCode`)}),(0,C.jsxs)(`div`,{className:`dc-code-row`,children:[(0,C.jsx)(`code`,{className:`dc-code`,children:g.code}),(0,C.jsx)(`button`,{className:`dc-icon-button`,type:`button`,"aria-label":r(`deviceHubCopy`),onClick:()=>void ue(),children:(0,C.jsx)(o,{"aria-hidden":!0})})]}),(0,C.jsx)(`div`,{className:`dc-pair-meta`,children:r(fe?`deviceHubExpires`:`deviceHubExpired`,{time:pe})}),(0,C.jsxs)(`div`,{className:`dc-actions`,children:[me,(0,C.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:!!D,onClick:()=>{++W.current,_(null),A(``),P(``)},children:[(0,C.jsx)(v,{"aria-hidden":!0}),r(`deviceHubNewCode`)]})]}),fe>0&&(0,C.jsxs)(`p`,{className:`dc-progress`,role:`status`,children:[(0,C.jsx)(v,{"aria-hidden":!0}),r(`deviceHubWaiting`)]})]})]}),$&&a&&!F&&(0,C.jsxs)(`section`,{className:`dc-card`,children:[(0,C.jsxs)(`div`,{className:`dc-device-summary`,children:[(0,C.jsx)(`span`,{className:`dc-device-icon`,children:(0,C.jsx)(ee,{"aria-hidden":!0})}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`h2`,{children:a.remark?.trim()||a.name}),(0,C.jsx)(`p`,{children:a.remark?.trim()?`${a.name} · ${r(`deviceHubDeviceTitle`)}`:r(`deviceHubDeviceTitle`)})]})]}),(0,C.jsxs)(`dl`,{className:`dc-details`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`dt`,{children:r(`deviceHubDeviceId`)}),(0,C.jsx)(`dd`,{children:a.deviceId})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`dt`,{children:r(`deviceHubHubUrl`)}),(0,C.jsx)(`dd`,{children:a.hubUrl})]})]})]}),$&&a?.hubUrl&&a.deviceId&&!F&&(0,C.jsx)(ne,{hubUrl:a.hubUrl,currentDeviceId:a.deviceId},`directory:${a.hubUrl}:${a.deviceId}`),!F&&(0,C.jsx)(re,{pathCompletions:e},`bots:${a?.hubUrl??``}:${a?.deviceId??`unpaired`}`),$&&!F&&(0,C.jsx)(I,{}),(0,C.jsx)(z,{}),$&&a&&!F&&(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`section`,{className:`dc-card`,children:[(0,C.jsxs)(`div`,{className:`dc-card-header`,children:[(0,C.jsx)(`span`,{className:`dc-icon`,children:(0,C.jsx)(s,{"aria-hidden":!0})}),(0,C.jsx)(`div`,{children:(0,C.jsx)(`h2`,{children:r(`deviceHubPermissions`)})})]}),(0,C.jsxs)(`div`,{className:`dc-permission-row`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`h3`,{id:`dc-permission-label`,children:r(`deviceHubPermissionLabel`)}),(0,C.jsx)(`p`,{id:`dc-permission-hint`,children:r(`deviceHubPermissionHint`)})]}),(0,C.jsx)(`button`,{type:`button`,className:`dc-toggle${a.allowExecution?` is-on`:``}`,role:`switch`,"aria-checked":a.allowExecution,"aria-labelledby":`dc-permission-label`,"aria-describedby":`dc-permission-hint`,disabled:!!D,onClick:()=>void ce(),children:(0,C.jsx)(`span`,{className:`dc-toggle-thumb`})})]}),(0,C.jsx)(`p`,{className:`dc-permission-state`,role:`status`,children:r(D===`permission`?`deviceHubSaving`:a.allowExecution?`deviceHubEnabled`:`deviceHubReadOnly`)})]}),(0,C.jsx)(x,{hubUrl:a?.hubUrl,deviceId:a?.deviceId,onNotice:P}),(0,C.jsxs)(`details`,{className:`dc-advanced`,children:[(0,C.jsx)(`summary`,{children:r(`deviceHubAdvanced`)}),(0,C.jsxs)(`div`,{className:`dc-danger-zone`,children:[(0,C.jsx)(`h3`,{children:r(`deviceHubDisconnect`)}),(0,C.jsx)(`p`,{children:r(`deviceHubDisconnectHint`)}),(0,C.jsx)(`button`,{type:`button`,className:`dc-button is-danger`,disabled:!!D,onClick:()=>void le(),children:r(D===`disconnect`?`deviceHubWorking`:`deviceHubDisconnect`)})]})]})]}),(0,C.jsxs)(`aside`,{className:`dc-help`,children:[(0,C.jsx)(m,{className:`dc-help-icon`,"aria-hidden":!0}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`h3`,{children:r(`deviceHubHelpTitle`)}),(0,C.jsx)(`p`,{children:r(`deviceHubHelpText`)})]})]})]})})]})}export{B as DeviceCenter};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$ as t,A as n,Cn as r,Dn as i,Dt as a,H as o,Jt as s,Mt as ee,Rt as c,Tn as l,Z as u,bn as te,bt as d,cn as f,nn as p,pt as m,un as h,vn as g,yn as _,zt as v}from"./app-globals-CZxzGvIo.js";import{i as y,t as b}from"./react-CR5VJ85Q.js";import{Vt as ne,gt as re}from"./index-CuN802Sj.js";import{t as x}from"./DeviceExecutionSettings-q5Ik8oXg.js";var S=e(y(),1),C=b();function w({href:e,children:t}){let n=te(),[r,i]=(0,S.useState)(!1),[a,o]=(0,S.useState)(!1);return(0,C.jsxs)(C.Fragment,{children:[(0,C.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,C.jsxs)(`span`,{role:`alert`,children:[n(`deviceHubNetworkError`),` `,(0,C.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,children:e})]})]})}function T(e){if(!E(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 E(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 D(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 O=`https://raw.githubusercontent.com/xing-shuyin/pi-web-ui/main/docs/device-center-deployment.md`,k=`https://github.com/xing-shuyin/pi-web-ui/blob/main/docs/device-center-deployment.md`,A=`pi-web-ui hub install --host 0.0.0.0 --port 8790 --public-url http://SERVER_IP:8790 --allow-registration`;function j(e){let t=e=>e.includes(`:`)?E(e)&&![`::`,`::1`].includes(e):/^[\d.]+$/.test(e)?E(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 M(e,t,n,r){if(!T(e))throw Error(`Invalid Hub setup`);if(r){let t=j(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: ${O} (fallback: ${k}). 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: ${A}`,`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 ie({onConnect:e,initialHubUrl:t=``}){let n=te(),[r,a]=(0,S.useState)(t),[o,s]=(0,S.useState)(``),[ee,c]=(0,S.useState)(!1),[u,d]=(0,S.useState)(!1),f=(0,S.useRef)(!1),p=(0,S.useRef)(!1);(0,S.useEffect)(()=>(p.current=!0,()=>{p.current=!1}),[]);let[m,h]=(0,S.useState)(null),[g,_]=(0,S.useState)(`current`),[v,y]=(0,S.useState)(null),[b,ne]=(0,S.useState)(`127.0.0.1`),[re,x]=(0,S.useState)(`8790`),[E,O]=(0,S.useState)(`http://127.0.0.1:8790`),[k,A]=(0,S.useState)({server:``,sshPort:22,username:`root`,auth:`password`,port:8790,domain:``,https:!1}),ie=j(k),[N,P]=(0,S.useState)(!1),[F,I]=(0,S.useState)(!1),[L,R]=(0,S.useState)(!1),[z,B]=(0,S.useState)(!1),[V,H]=(0,S.useState)(null),U=(0,S.useRef)(null),W=(0,S.useRef)(!1),G=D(window.location.origin);(0,S.useEffect)(()=>()=>U.current?.abort(),[]);let K=async()=>{if(W.current)return;U.current?.abort();let e=new AbortController;U.current=e,I(!1),R(!1),B(!1);try{let t=await fetch(l(i(`/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`||!T({host:`127.0.0.1`,port:n.defaultPort,publicUrl:n.defaultPublicUrl}))throw Error();if(e.signal.aborted)return;y(n),n.installation?.installed?(ne(n.installation.host??`127.0.0.1`),x(String(n.installation.port)),O(n.installation.publicUrl??``),a(n.installation.publicUrl??``)):v||(x(String(n.defaultPort)),O(n.defaultPublicUrl))}catch{e.signal.aborted||(I(!0),B(!0))}finally{e.signal.aborted||R(!0)}},q=async()=>{let e={host:b,port:Number(re),publicUrl:E};if(W.current||!G||!v||!L||z||v.busy||v.installation?.installed||!T(e))return;W.current=!0,U.current?.abort(),P(!0),I(!1),s(``);let t=new AbortController;U.current=t;try{let n=await fetch(l(i(`/api/device-center/setup`)),{credentials:`same-origin`,method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({...e,allowRegistration:!0}),signal:t.signal});if(n.status===409){y(e=>e&&{...e,busy:!0}),W.current=!1,P(!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 r=await n.json();if(!T({...e,publicUrl:r.publicUrl})||typeof r.output!=`string`)throw Error();t.signal.aborted||H(r)}catch(e){t.signal.aborted||(I(!0),s(e instanceof Error?e.message.slice(0,4096):``))}finally{W.current=!1,t.signal.aborted||P(!1)}},J=v?.installation,Y=!!J?.installed,X=Y&&J.running&&J.owned,Z=g===`remote`?ie:{host:b,port:Number(re),publicUrl:E},Q=!!Z&&T(Z);return(0,C.jsxs)(`section`,{className:`dc-onboarding`,children:[(0,C.jsx)(`h3`,{children:n(`deviceSetupWelcome`)}),(0,C.jsx)(`p`,{children:n(`deviceSetupIntro`)}),(0,C.jsxs)(`div`,{className:`dc-actions`,children:[(0,C.jsx)(`button`,{className:`dc-button`,disabled:N,"aria-pressed":m===`connect`,onClick:()=>h(`connect`),children:n(`deviceSetupConnect`)}),(0,C.jsx)(`button`,{className:`dc-button`,disabled:N,"aria-pressed":m===`create`,onClick:()=>{h(`create`),!v&&G&&K()},children:n(`deviceSetupCreate`)})]}),m===`connect`&&(0,C.jsxs)(`form`,{onSubmit:t=>{t.preventDefault(),e(r.trim())},children:[(0,C.jsxs)(`label`,{className:`dc-field`,children:[(0,C.jsx)(`span`,{children:n(`deviceHubHubUrl`)}),(0,C.jsx)(`input`,{type:`url`,required:!0,maxLength:2048,value:r,onChange:e=>a(e.target.value),placeholder:`https://hub.example.com`})]}),(0,C.jsx)(`button`,{className:`dc-button is-primary`,disabled:!T({host:`localhost`,port:8790,publicUrl:r.trim()}),children:n(`deviceSetupPair`)})]}),m===`create`&&(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`label`,{className:`dc-field`,children:[(0,C.jsx)(`span`,{children:n(`deviceSetupTarget`)}),(0,C.jsxs)(`select`,{disabled:N,value:g,onChange:e=>_(e.target.value),children:[(0,C.jsx)(`option`,{value:`current`,children:n(`deviceSetupCurrent`)}),(0,C.jsx)(`option`,{value:`remote`,children:n(`deviceSetupRemote`)})]})]}),(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(`p`,{children:n(g===`current`?`deviceSetupCurrentHint`:`deviceSetupRemoteHint`)}),g===`current`&&(0,C.jsxs)(`div`,{className:`dc-setup-plan`,children:[(0,C.jsx)(`strong`,{children:n(`deviceSetupPlan`)}),(0,C.jsx)(`p`,{children:n(`deviceSetupPlanHint`)}),v&&(0,C.jsxs)(`dl`,{children:[(0,C.jsx)(`dt`,{children:n(`deviceSetupEnvironment`)}),(0,C.jsxs)(`dd`,{children:[v.platform,` · Node `,v.nodeVersion]}),(0,C.jsx)(`dt`,{children:n(`deviceSetupDataDir`)}),(0,C.jsx)(`dd`,{children:v.dataDir}),(0,C.jsx)(`dt`,{children:n(`deviceSetupCli`)}),(0,C.jsx)(`dd`,{children:v.cliPath})]}),!G&&(0,C.jsx)(`p`,{role:`status`,children:n(`deviceSetupLocalOnly`)}),(0,C.jsx)(`p`,{children:n(`deviceSetupBackground`)}),Y&&(0,C.jsxs)(`div`,{role:`status`,children:[(0,C.jsx)(`h4`,{children:n(X?`deviceSetupRestored`:`deviceSetupUnhealthy`)}),(0,C.jsx)(`p`,{children:J.publicUrl}),X&&Q&&J.publicUrl?(0,C.jsxs)(`div`,{className:`dc-actions`,children:[(0,C.jsx)(w,{href:J.publicUrl,children:n(`deviceHubOpenHub`)}),(0,C.jsx)(`button`,{className:`dc-button`,onClick:()=>e(J.publicUrl),children:n(`deviceSetupPair`)})]}):(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(`p`,{children:n(`deviceSetupRecovery`)}),(0,C.jsx)(`pre`,{className:`dc-setup-output`,children:`pi-web-ui hub status --json
|
|
3
|
+
pi-web-ui hub --help`})]})]}),v?.busy&&(0,C.jsx)(`p`,{role:`status`,children:n(`deviceSetupBusy`)}),G&&(0,C.jsx)(`button`,{className:`dc-button`,disabled:N||!L,onClick:()=>void K(),children:n(L?`deviceSetupRetry`:`deviceHubWorking`)})]}),g===`remote`?(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`div`,{className:`dc-setup-fields`,children:[(0,C.jsxs)(`label`,{className:`dc-field`,children:[(0,C.jsx)(`span`,{children:n(`deviceSetupServer`)}),(0,C.jsx)(`input`,{autoComplete:`off`,maxLength:253,placeholder:`203.0.113.10`,value:k.server,onChange:e=>A({...k,server:e.target.value.trim()})})]}),(0,C.jsxs)(`label`,{className:`dc-field`,children:[(0,C.jsx)(`span`,{children:n(`deviceSetupSshPort`)}),(0,C.jsx)(`input`,{type:`number`,min:1,max:65535,value:k.sshPort,onChange:e=>A({...k,sshPort:Number(e.target.value)})})]}),(0,C.jsxs)(`label`,{className:`dc-field`,children:[(0,C.jsx)(`span`,{children:n(`deviceSetupUsername`)}),(0,C.jsx)(`input`,{autoComplete:`off`,maxLength:64,value:k.username,onChange:e=>A({...k,username:e.target.value})})]}),(0,C.jsxs)(`label`,{className:`dc-field`,children:[(0,C.jsx)(`span`,{children:n(`deviceSetupAuth`)}),(0,C.jsxs)(`select`,{value:k.auth,onChange:e=>A({...k,auth:e.target.value}),children:[(0,C.jsx)(`option`,{value:`password`,children:n(`deviceSetupAuthPassword`)}),(0,C.jsx)(`option`,{value:`key`,children:n(`deviceSetupAuthKey`)}),(0,C.jsx)(`option`,{value:`existing`,children:n(`deviceSetupAuthExisting`)})]})]}),(0,C.jsxs)(`label`,{className:`dc-field`,children:[(0,C.jsx)(`span`,{children:n(`deviceSetupServicePort`)}),(0,C.jsx)(`input`,{type:`number`,min:1024,max:65535,value:k.port,onChange:e=>A({...k,port:Number(e.target.value)})})]})]}),(0,C.jsx)(`p`,{children:n(`deviceSetupCredentialHint`)}),(0,C.jsxs)(`details`,{children:[(0,C.jsx)(`summary`,{children:n(`deviceSetupOptionalTls`)}),(0,C.jsxs)(`label`,{className:`dc-field`,children:[(0,C.jsx)(`span`,{children:n(`deviceSetupDomain`)}),(0,C.jsx)(`input`,{maxLength:253,placeholder:`hub.example.com`,value:k.domain,onChange:e=>A({...k,domain:e.target.value.trim()})})]}),(0,C.jsxs)(`label`,{children:[(0,C.jsx)(`input`,{type:`checkbox`,checked:k.https,onChange:e=>A({...k,https:e.target.checked})}),` `,n(`deviceSetupEnableHttps`)]}),(0,C.jsx)(`p`,{children:n(`deviceSetupTlsHint`)})]}),(0,C.jsxs)(`p`,{children:[(0,C.jsx)(`strong`,{children:n(`deviceSetupPreview`)}),` `,ie?.publicUrl??n(`deviceSetupPreviewEmpty`)]}),(0,C.jsxs)(`div`,{className:`dc-setup-plan`,children:[(0,C.jsx)(`strong`,{children:n(`deviceSetupUserActions`)}),(0,C.jsx)(`p`,{children:n(`deviceSetupCloudPorts`).replace(`{ports}`,k.https?`443 / 80`:String(k.port))}),(0,C.jsx)(`p`,{children:n(`deviceSetupSourceScope`)}),(0,C.jsx)(`p`,{children:n(`deviceSetupAfterStart`)})]}),(0,C.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,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`div`,{className:`dc-setup-fields`,children:[(0,C.jsxs)(`label`,{className:`dc-field`,children:[(0,C.jsx)(`span`,{children:n(`deviceSetupHost`)}),(0,C.jsx)(`input`,{disabled:N||!!V,maxLength:253,value:b,onChange:e=>ne(e.target.value)})]}),(0,C.jsxs)(`label`,{className:`dc-field`,children:[(0,C.jsx)(`span`,{children:n(`deviceSetupPort`)}),(0,C.jsx)(`input`,{disabled:N||!!V,type:`number`,min:1024,max:65535,value:re,onChange:e=>x(e.target.value)})]}),(0,C.jsxs)(`label`,{className:`dc-field`,children:[(0,C.jsx)(`span`,{children:n(`deviceHubHubUrl`)}),(0,C.jsx)(`input`,{disabled:N||!!V,maxLength:2048,value:E,onChange:e=>O(e.target.value)})]})]}),(0,C.jsx)(`p`,{className:`dc-setup-warning`,children:n(`deviceSetupReachable`)})]}),(0,C.jsx)(`p`,{children:n(`deviceSetupRegistration`)}),!Q&&(0,C.jsx)(`p`,{role:`alert`,children:n(g===`remote`?`deviceSetupRemoteInvalid`:`deviceSetupInvalid`)}),(0,C.jsxs)(`div`,{className:`dc-actions`,children:[g===`current`&&!V&&!Y&&(0,C.jsx)(`button`,{className:`dc-button is-primary`,disabled:N||!G||!v||!L||z||!!v.busy||!Q,onClick:()=>void q(),children:n(N?`deviceSetupInstalling`:`deviceSetupInstall`)}),(0,C.jsx)(`button`,{className:`dc-button`,disabled:N||ee||!Q,onClick:()=>{if(!Q||!Z||f.current)return;f.current=!0,c(!0),d(!1);let e=e=>{f.current=!1,p.current&&(c(!1),d(!e))},t=window.__piWebUiHost;try{t?.startChat({newChat:!0,prompt:M(Z,v,g,g===`remote`?k:void 0),onResult:e})||e(!1)}catch{e(!1)}},children:n(g===`remote`?`deviceSetupStartAi`:`deviceSetupAi`)})]}),(0,C.jsx)(`p`,{children:n(`deviceSetupAiHint`)}),ee&&(0,C.jsx)(`p`,{role:`status`,children:n(`deviceSetupAiCreating`)}),u&&(0,C.jsx)(`p`,{role:`alert`,children:n(`deviceSetupAiFailed`)})]})]}),F&&(0,C.jsxs)(`div`,{role:`alert`,children:[(0,C.jsx)(`p`,{children:n(`deviceSetupFailed`)}),o&&(0,C.jsx)(`pre`,{className:`dc-setup-output`,children:o})]}),V&&(0,C.jsxs)(`div`,{role:`status`,children:[(0,C.jsx)(`h4`,{children:n(`deviceSetupSuccess`)}),(0,C.jsx)(`pre`,{className:`dc-setup-output`,children:V.output.slice(0,16e3)}),(0,C.jsxs)(`div`,{className:`dc-actions`,children:[(0,C.jsx)(w,{href:V.publicUrl,children:n(`deviceHubOpenHub`)}),(0,C.jsx)(`button`,{className:`dc-button is-primary`,onClick:()=>e(V.publicUrl),children:n(`deviceSetupPair`)})]})]})]})}var N=`pi-web-ui:device-groups-changed`;function P(e){window.dispatchEvent(new CustomEvent(`pi-web-ui:device-group-open`,{detail:{roomId:e}}))}async function F(e,t,n){let r=await fetch(l(i(`/api/device-center/${e}`)),{method:n?`POST`:`GET`,credentials:`same-origin`,signal:t,...n?{headers:{"Content-Type":`application/json`},body:JSON.stringify(n)}:{}}),a=await r.json().catch(()=>({}));if(!r.ok)throw Error(a.error||a.message||`Request failed (${r.status})`);return a}function I(){let{locale:e}=g(),t=r(e),[i,o]=(0,S.useState)([]),[s,ee]=(0,S.useState)([]),[l,te]=(0,S.useState)(!0),[d,m]=(0,S.useState)(``),[_,y]=(0,S.useState)(``),[b,ne]=(0,S.useState)(0),[re,x]=(0,S.useState)(!1),[w,T]=(0,S.useState)(``),[E,D]=(0,S.useState)([]),[O,k]=(0,S.useState)(``),[A,j]=(0,S.useState)(null),[M,ie]=(0,S.useState)([]),[I,L]=(0,S.useState)(``),[R,z]=(0,S.useState)(null),[B,V]=(0,S.useState)(``),[H,U]=(0,S.useState)(!1),W=(0,S.useRef)(0);(0,S.useEffect)(()=>{let e=++W.current,t=new AbortController;async function n(){try{let[n,r]=await Promise.all([F(`rooms`,t.signal),F(`bots`,t.signal)]);if(W.current!==e||t.signal.aborted)return;o(Array.isArray(n.rooms)?n.rooms:[]),ee(Array.isArray(r.bots)?r.bots:[]),m(``)}catch(n){W.current===e&&!t.signal.aborted&&m(n instanceof Error?n.message:String(n))}finally{W.current===e&&!t.signal.aborted&&te(!1)}}return n(),()=>{t.abort()}},[b]),(0,S.useEffect)(()=>{let e=()=>ne(e=>e+1);return window.addEventListener(N,e),()=>window.removeEventListener(N,e)},[]);async function G(e){if(e.preventDefault(),!w.trim()||H)return;U(!0),m(``),y(``);let n=new AbortController;try{let e=E.includes(O)?O:``,r=await F(`rooms`,n.signal,{name:w.trim(),botIds:E,...e?{primaryBotId:e}:{}});o(e=>[...e.filter(e=>e.id!==r.room.id),r.room]),x(!1),T(``),D([]),k(``),y(t?`群聊创建成功`:`Group created successfully`),window.dispatchEvent(new CustomEvent(N))}catch(e){m(e instanceof Error?e.message:String(e))}finally{U(!1)}}function K(e){j(e.id),ie([...e.botIds]),L(e.primaryBotId??``),z(null),x(!1),m(``),y(``)}async function q(e){if(H)return;U(!0),m(``),y(``);let n=new AbortController;try{let r=M.includes(I)?I:null,i=await F(`rooms/${encodeURIComponent(e)}/members`,n.signal,{botIds:M,primaryBotId:r});o(t=>t.map(t=>t.id===e?i.room:t)),j(null),y(t?`成员设置已保存`:`Members updated successfully`),window.dispatchEvent(new CustomEvent(N))}catch(e){m(e instanceof Error?e.message:String(e))}finally{U(!1)}}async function J(e){if(!B.trim()||H)return;U(!0),m(``),y(``);let n=new AbortController;try{await F(`rooms/${encodeURIComponent(e)}/rename`,n.signal,{name:B.trim()}),o(t=>t.map(t=>t.id===e?{...t,name:B.trim()}:t)),z(null),y(t?`群聊名称已更新`:`Group renamed successfully`),window.dispatchEvent(new CustomEvent(N))}catch(e){m(e instanceof Error?e.message:String(e))}finally{U(!1)}}async function Y(e){if(H||!window.confirm(t?`确定删除群聊“${e.name}”?`:`Are you sure you want to delete "${e.name}"?`))return;U(!0),m(``),y(``);let n=new AbortController;try{await F(`rooms/${encodeURIComponent(e.id)}/delete`,n.signal,{}),o(t=>t.filter(t=>t.id!==e.id)),A===e.id&&j(null),R===e.id&&z(null),y(t?`群聊已删除`:`Group deleted successfully`),window.dispatchEvent(new CustomEvent(N))}catch(e){m(e instanceof Error?e.message:String(e))}finally{U(!1)}}return(0,C.jsxs)(`section`,{className:`dc-card`,"aria-label":t?`群聊列表`:`Group list`,children:[(0,C.jsxs)(`div`,{className:`dc-card-header`,children:[(0,C.jsx)(`span`,{className:`dc-icon`,children:(0,C.jsx)(f,{"aria-hidden":!0})}),(0,C.jsxs)(`div`,{children:[(0,C.jsxs)(`h2`,{children:[t?`群聊列表`:`Group List`,` · `,i.length]}),(0,C.jsx)(`p`,{children:t?`管理群聊与成员 Bot,在此配置协作群组或直接进入聊天。`:`Manage groups and member Bots. Configure collaboration groups or open chats here.`})]}),(0,C.jsxs)(`div`,{className:`dc-actions`,style:{marginInlineStart:`auto`},children:[(0,C.jsxs)(`button`,{type:`button`,className:`dc-button is-primary`,disabled:H,onClick:()=>{x(e=>!e),j(null),z(null),T(``),D([]),k(``)},children:[(0,C.jsx)(c,{"aria-hidden":!0}),t?`新建群聊`:`Create Group`]}),(0,C.jsx)(`button`,{type:`button`,className:`dc-icon-button`,"aria-label":t?`刷新群聊`:`Refresh groups`,onClick:()=>ne(e=>e+1),children:(0,C.jsx)(v,{})})]})]}),d&&(0,C.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:d}),_&&(0,C.jsxs)(`p`,{className:`dc-notice is-success`,role:`status`,children:[(0,C.jsx)(n,{"aria-hidden":!0}),_]}),re&&(0,C.jsxs)(`form`,{className:`dc-card`,style:{marginBottom:`16px`,background:`var(--bg)`,border:`1px solid var(--border)`},onSubmit:G,children:[(0,C.jsxs)(`div`,{className:`dg-heading`,style:{marginBottom:`12px`},children:[(0,C.jsx)(`h3`,{children:t?`新建群聊`:`Create Group`}),(0,C.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>x(!1),disabled:H,children:[(0,C.jsx)(h,{"aria-hidden":!0}),t?`关闭`:`Close`]})]}),(0,C.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`12px`},children:[(0,C.jsx)(`label`,{htmlFor:`dg-manager-new-name`,children:t?`群名称`:`Group Name`}),(0,C.jsx)(`input`,{id:`dg-manager-new-name`,type:`text`,required:!0,maxLength:80,value:w,placeholder:t?`输入群名称,如:研发协作群`:`Enter group name`,onChange:e=>T(e.target.value),disabled:H,style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`}})]}),(0,C.jsxs)(`div`,{style:{marginBottom:`12px`},children:[(0,C.jsx)(`label`,{style:{display:`block`,marginBottom:`6px`,fontSize:`12px`,color:`var(--text-dim)`},children:t?`选择成员 Bot`:`Select Member Bots`}),(0,C.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:s.length===0?(0,C.jsx)(`p`,{style:{margin:0,fontSize:`12px`,color:`var(--text-faint)`},children:t?`暂无可用 Bot,请先创建 Bot。`:`No Bots available. Please create a Bot first.`}):s.map(e=>(0,C.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,cursor:`pointer`,fontSize:`12px`},children:[(0,C.jsx)(`input`,{type:`checkbox`,checked:E.includes(e.id),disabled:H||!e.enabled,onChange:t=>{D(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}}),(0,C.jsxs)(`span`,{children:[(0,C.jsx)(`strong`,{children:e.name}),(0,C.jsxs)(`small`,{style:{color:`var(--text-faint)`,marginInlineStart:`6px`},children:[e.online?t?`在线`:`Online`:t?`离线`:`Offline`,e.enabled?``:t?` · 已禁用`:` · Disabled`]})]})]},e.id))})]}),E.length>0&&(0,C.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`16px`},children:[(0,C.jsx)(`label`,{htmlFor:`dg-manager-new-primary`,children:t?`主 Bot`:`Primary Bot`}),(0,C.jsxs)(`select`,{id:`dg-manager-new-primary`,value:E.includes(O)?O:``,onChange:e=>k(e.target.value),disabled:H,style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`},children:[(0,C.jsx)(`option`,{value:``,children:t?`不设置(需 @ Bot)`:`None (mention a Bot)`}),s.filter(e=>E.includes(e.id)).map(e=>(0,C.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,C.jsxs)(`div`,{className:`dc-actions`,children:[(0,C.jsxs)(`button`,{type:`submit`,className:`dc-button is-primary`,disabled:H||!w.trim(),children:[(0,C.jsx)(n,{"aria-hidden":!0}),H?t?`创建中…`:`Creating…`:t?`创建群聊`:`Create`]}),(0,C.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>x(!1),disabled:H,children:t?`取消`:`Cancel`})]})]}),A&&(0,C.jsxs)(`div`,{className:`dc-card`,style:{marginBottom:`16px`,background:`var(--bg)`,border:`1px solid var(--border)`},children:[(0,C.jsxs)(`div`,{className:`dg-heading`,style:{marginBottom:`12px`},children:[(0,C.jsxs)(`h3`,{children:[t?`管理成员`:`Manage Members`,` · `,i.find(e=>e.id===A)?.name]}),(0,C.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>j(null),disabled:H,children:[(0,C.jsx)(h,{"aria-hidden":!0}),t?`关闭`:`Close`]})]}),(0,C.jsxs)(`div`,{style:{marginBottom:`12px`},children:[(0,C.jsx)(`label`,{style:{display:`block`,marginBottom:`6px`,fontSize:`12px`,color:`var(--text-dim)`},children:t?`选择成员 Bot`:`Select Member Bots`}),(0,C.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:s.length===0?(0,C.jsx)(`p`,{style:{margin:0,fontSize:`12px`,color:`var(--text-faint)`},children:t?`暂无可用 Bot`:`No Bots available`}):s.map(e=>(0,C.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,cursor:`pointer`,fontSize:`12px`},children:[(0,C.jsx)(`input`,{type:`checkbox`,checked:M.includes(e.id),disabled:H,onChange:t=>{ie(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}}),(0,C.jsxs)(`span`,{children:[(0,C.jsx)(`strong`,{children:e.name}),(0,C.jsxs)(`small`,{style:{color:`var(--text-faint)`,marginInlineStart:`6px`},children:[e.online?t?`在线`:`Online`:t?`离线`:`Offline`,e.enabled?``:t?` · 已禁用`:` · Disabled`]})]})]},e.id))})]}),(0,C.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`16px`},children:[(0,C.jsx)(`label`,{htmlFor:`dg-manager-edit-primary`,children:t?`主 Bot`:`Primary Bot`}),(0,C.jsxs)(`select`,{id:`dg-manager-edit-primary`,value:M.includes(I)?I:``,onChange:e=>L(e.target.value),disabled:H,style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`},children:[(0,C.jsx)(`option`,{value:``,children:t?`不设置(需 @ Bot)`:`None (mention a Bot)`}),s.filter(e=>M.includes(e.id)).map(e=>(0,C.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,C.jsxs)(`div`,{className:`dc-actions`,children:[(0,C.jsxs)(`button`,{type:`button`,className:`dc-button is-primary`,disabled:H,onClick:()=>void q(A),children:[(0,C.jsx)(n,{"aria-hidden":!0}),H?t?`保存中…`:`Saving…`:t?`保存成员设置`:`Save Members`]}),(0,C.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>j(null),disabled:H,children:t?`取消`:`Cancel`})]})]}),l&&(0,C.jsx)(`p`,{role:`status`,children:t?`加载中…`:`Loading…`}),!l&&i.length===0&&(0,C.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,C.jsx)(`div`,{className:`dd-list`,children:i.map(e=>{let r=R===e.id,i=s.filter(t=>e.botIds.includes(t.id)),o=s.find(t=>t.id===e.primaryBotId);return(0,C.jsxs)(`div`,{className:`dd-device`,style:r?{flexWrap:`wrap`}:void 0,children:[(0,C.jsx)(`span`,{className:`dc-device-icon`,children:(0,C.jsx)(f,{"aria-hidden":!0})}),(0,C.jsxs)(`div`,{className:`dd-identity`,style:{flex:1,minWidth:`200px`},children:[(0,C.jsx)(`strong`,{children:e.name}),(0,C.jsxs)(`span`,{style:{display:`flex`,gap:`8px`,flexWrap:`wrap`,alignItems:`center`},children:[(0,C.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(`, `)}`:``}`}),o&&(0,C.jsx)(`span`,{style:{color:`var(--accent)`},children:t?`[主 Bot: ${o.name}]`:`[Primary: ${o.name}]`})]})]}),(0,C.jsxs)(`div`,{className:`dc-actions`,children:[(0,C.jsxs)(`button`,{type:`button`,className:`dc-button is-primary`,title:t?`打开聊天`:`Open chat`,onClick:()=>P(e.id),children:[(0,C.jsx)(a,{"aria-hidden":!0}),t?`打开聊天`:`Open chat`]}),(0,C.jsxs)(`button`,{type:`button`,className:`dc-button`,title:t?`管理成员`:`Manage members`,onClick:()=>K(e),children:[(0,C.jsx)(f,{"aria-hidden":!0}),t?`管理成员`:`Members`]}),(0,C.jsxs)(`button`,{type:`button`,className:`dc-button`,title:t?`重命名`:`Rename`,onClick:()=>{r?z(null):(z(e.id),V(e.name))},children:[(0,C.jsx)(u,{"aria-hidden":!0}),t?`重命名`:`Rename`]}),(0,C.jsx)(`button`,{type:`button`,className:`dc-button is-danger`,title:t?`删除群聊`:`Delete group`,disabled:H,onClick:()=>void Y(e),children:(0,C.jsx)(p,{"aria-hidden":!0})})]}),r&&(0,C.jsxs)(`form`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,width:`100%`,paddingTop:`8px`,paddingBottom:`4px`},onSubmit:t=>{t.preventDefault(),J(e.id)},children:[(0,C.jsx)(`input`,{type:`text`,maxLength:80,autoFocus:!0,disabled:H,value:B,onChange:e=>V(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,C.jsxs)(`button`,{type:`submit`,className:`dc-button is-primary`,disabled:H||!B.trim(),children:[(0,C.jsx)(n,{"aria-hidden":!0}),t?`保存`:`Save`]}),(0,C.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:H,onClick:()=>z(null),children:[(0,C.jsx)(h,{"aria-hidden":!0}),t?`取消`:`Cancel`]})]})]},e.id)})})]})}var L=class extends Error{status;constructor(e,t){super(t),this.status=e}};function R(e){try{let t=new URL(e);return[`http:`,`https:`].includes(t.protocol)&&!t.username&&!t.password?t.href:null}catch{return null}}function z(){let e=te(),t=_().startsWith(`zh`),[n,r]=(0,S.useState)(null),[a,o]=(0,S.useState)(!1),[s,c]=(0,S.useState)(!1),[u,d]=(0,S.useState)(!1),[f,p]=(0,S.useState)(!1),m=(0,S.useRef)(0),h=(0,S.useRef)(null);async function g(e,t){if(h.current)return;let n=++m.current,a=new AbortController;h.current=a,o(!0),c(!1);try{let o=await fetch(l(i(`/api/device-desktop/local/${e}`)),{method:t?`POST`:`GET`,credentials:`same-origin`,signal:a.signal,...t?{headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}:{}});if(m.current!==n||a.signal.aborted)return;if(o.status===403){d(!0),r(null);return}if(!o.ok)throw Error(`Request failed`);let s=await o.json();if(m.current!==n||a.signal.aborted)return;if(e===`permissions`){if(typeof s?.screen!=`boolean`||typeof s?.accessibility!=`boolean`)throw Error(`Invalid permission status`);r(e=>e&&{...e,permissions:{supported:!0,screen:s.screen,accessibility:s.accessibility}}),p(!0)}else{if(typeof s?.os!=`string`||typeof s.enabled!=`boolean`||typeof s.environmentEnabled!=`boolean`||typeof s.supported!=`boolean`)throw Error(`Invalid desktop status`);r(s)}}catch{m.current===n&&!a.signal.aborted&&c(!0)}finally{m.current===n&&!a.signal.aborted&&(h.current=null,o(!1))}}return(0,S.useEffect)(()=>(g(`status`),()=>{m.current++,h.current?.abort(),h.current=null}),[]),(0,C.jsxs)(`section`,{className:`dc-card`,"aria-label":t?`本机远程桌面`:`Local remote desktop`,"aria-busy":a,children:[(0,C.jsxs)(`div`,{className:`dc-card-header`,children:[(0,C.jsx)(`span`,{className:`dc-icon`,children:(0,C.jsx)(ee,{"aria-hidden":!0})}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`h2`,{children:t?`本机远程桌面`:`Local remote desktop`}),(0,C.jsx)(`p`,{children:t?`管理这台设备的远程桌面与系统权限,无需连接设备中心。`:`Manage remote desktop and system permissions on this device, even while the device center is offline.`})]})]}),u?(0,C.jsx)(`p`,{role:`status`,children:t?`请在设备本机打开此页面以管理远程桌面权限。`:`Open this page on the device itself to manage remote desktop permissions.`}):(0,C.jsxs)(C.Fragment,{children:[n&&(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`div`,{className:`dc-permission-row`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`h3`,{id:`dc-desktop-label`,children:t?`启用远程桌面`:`Enable remote desktop`}),(0,C.jsx)(`p`,{children:n.enabled?t?`已启用`:`Enabled`:t?`未启用`:`Disabled`})]}),(0,C.jsx)(`button`,{type:`button`,className:`dc-toggle${n.enabled?` is-on`:``}`,role:`switch`,"aria-checked":n.enabled,"aria-labelledby":`dc-desktop-label`,disabled:a||n.environmentEnabled||!n.supported&&!n.enabled,onClick:()=>void g(`enable`,{enabled:!n.enabled}),children:(0,C.jsx)(`span`,{className:`dc-toggle-thumb`})})]}),!n.supported&&(0,C.jsx)(`p`,{children:t?`这台设备暂不支持远程桌面。`:`Remote desktop is currently unavailable on this device.`}),n.environmentEnabled&&(0,C.jsx)(`p`,{children:t?`远程桌面由本机服务设置保持启用。`:`Remote desktop is kept enabled by the service settings on this device.`}),n.os===`darwin`&&(0,C.jsxs)(C.Fragment,{children:[(0,C.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,C.jsxs)(`div`,{className:`dc-actions`,children:[(0,C.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:a||n.permissions?.supported===!1,onClick:()=>void g(`permissions`,{kind:`screen`}),children:t?`授予屏幕录制权限`:`Grant screen recording permission`}),(0,C.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:a||n.permissions?.supported===!1,onClick:()=>void g(`permissions`,{kind:`control`}),children:t?`授予远程控制权限`:`Grant remote control permission`})]}),n.permissions?.screen===!0&&(0,C.jsx)(`p`,{children:t?`屏幕录制:已授权`:`Screen recording: granted`}),n.permissions?.accessibility===!0&&(0,C.jsx)(`p`,{children:t?`远程控制:已授权`:`Remote control: granted`}),f&&(0,C.jsx)(`p`,{role:`status`,children:t?`已发起授权请求,请确认系统设置后刷新状态。`:`Permission requested. Confirm in System Settings, then refresh the status.`})]})]}),s&&(0,C.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:t?`无法更新本机远程桌面设置,请重试。`:`Unable to update local remote desktop settings. Please retry.`}),(0,C.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:a,onClick:()=>void g(`status`),children:[(0,C.jsx)(v,{"aria-hidden":!0}),a?e(`deviceHubWorking`):t?`刷新远程桌面状态`:`Refresh remote desktop status`]})]})]})}function B({pathCompletions:e=[]}){let r=te(),[a,c]=(0,S.useState)(null),[u,f]=(0,S.useState)(``),[p,h]=(0,S.useState)(``),[g,_]=(0,S.useState)(null),[y,b]=(0,S.useState)(!1),[T,E]=(0,S.useState)(Date.now()),[D,O]=(0,S.useState)(null),[k,A]=(0,S.useState)(``),[j,M]=(0,S.useState)(``),[N,P]=(0,S.useState)(``),[F,B]=(0,S.useState)(!1),[V,H]=(0,S.useState)(!0),U=(0,S.useRef)(!1),W=(0,S.useRef)(0),G=(0,S.useRef)(new Set),K=(0,S.useRef)(!1),q=(0,S.useRef)(!1),J=(0,S.useRef)(null),Y=(0,S.useRef)(r);Y.current=r,(0,S.useEffect)(()=>{let e=e=>{let t=e;t.detail?.deviceId&&J.current?.deviceId===t.detail.deviceId&&(c(e=>e&&{...e,remark:t.detail.remark}),J.current&&(J.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 X(e,t){let n=new AbortController;G.current.add(n);try{let r=await fetch(l(i(`/api/device-center/${e}`)),{method:t?`POST`:`GET`,credentials:`same-origin`,signal:n.signal,...t?{headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}:{}}),a=await r.json().catch(()=>({}));if(!r.ok)throw new L(r.status,typeof a.error==`string`?a.error:Y.current(`deviceHubRequestFailed`,{status:r.status}));return a}finally{G.current.delete(n)}}function Z(e){return U.current&&W.current===e}function Q(e){return e instanceof L&&e.status===403?(B(!0),Y.current(`deviceHubLocalOnly`)):e instanceof Error?e.message:Y.current(`deviceHubNetworkError`)}function ae(e){J.current=e,c(e),q.current||(h(e.name),f(e.hubUrl??``))}async function oe(){let e=W.current;try{let t=await X(`status`);if(!Z(e)||K.current)return;ae(t),M(``),B(!1)}catch(t){Z(e)&&M(Q(t))}finally{Z(e)&&H(!1)}}(0,S.useEffect)(()=>{U.current=!0;let e=!1,t,n=async()=>{await oe(),!e&&U.current&&(t=setTimeout(n,5e3))};return n(),()=>{e=!0,U.current=!1,W.current++,clearTimeout(t);for(let e of G.current)e.abort()}},[]),(0,S.useEffect)(()=>{if(!g)return;let e=W.current,t=!1,n,r=setInterval(()=>E(Date.now()),1e3),i=async()=>{if(!(t||!Z(e)||Date.now()>=g.expiresAt)){try{let n=await X(`poll`,{});if(t||!Z(e))return;if(n.paired){let n=await X(`status`);if(t||!Z(e))return;q.current=!1,ae(n),_(null),A(``),P(``);return}A(``)}catch(n){!t&&Z(e)&&A(`${Y.current(`deviceHubPollError`)} ${Q(n)}`)}!t&&Z(e)&&(n=setTimeout(i,2e3))}};return n=setTimeout(i,2e3),()=>{t=!0,clearTimeout(n),clearInterval(r)}},[g]);async function se(){if(K.current)return;let e=R(u.trim());if(!e){A(r(`deviceHubInvalidUrl`));return}if(!p.trim()||p.trim().length>80){A(r(`deviceHubInvalidName`));return}let t=++W.current;K.current=!0,O(`pair`),A(``),P(``),_(null);try{let n=await X(`pair`,{hubUrl:e,name:p.trim()});if(!Z(t))return;if(!n.code||!Number.isFinite(n.expiresAt)||!R(n.hubUrl))throw Error(r(`deviceHubPairError`));E(Date.now()),_(n)}catch(e){Z(t)&&A(`${r(`deviceHubPairError`)} ${Q(e)}`)}finally{Z(t)&&(K.current=!1,O(null))}}async function ce(){let e=J.current;if(!e?.deviceId||K.current)return;let t=++W.current;K.current=!0,O(`permission`),A(``),P(``),ae({...e,allowExecution:!e.allowExecution});try{await X(`execution`,{allowExecution:!e.allowExecution}),Z(t)&&P(r(`deviceHubSaved`))}catch(n){Z(t)&&(ae(e),A(`${r(`deviceHubPermissionError`)} ${Q(n)}`))}finally{Z(t)&&(K.current=!1,O(null))}}async function le(){let e=J.current;if(!e?.deviceId||K.current||!window.confirm(r(`deviceHubDisconnectConfirm`,{name:e.name})))return;let t=++W.current;K.current=!0,O(`disconnect`),A(``),P(``);try{if(await X(`disconnect`,{}),!Z(t))return;q.current=!1,ae({name:e.name,allowExecution:!1,connected:!1}),_(null)}catch(e){Z(t)&&A(`${r(`deviceHubDisconnectError`)} ${Q(e)}`)}finally{Z(t)&&(K.current=!1,O(null))}}async function ue(){if(!g)return;let e=W.current;try{await navigator.clipboard.writeText(g.code),Z(e)&&P(r(`deviceHubCopied`))}catch{Z(e)&&A(r(`deviceHubCopyFailed`))}}let $=!!a?.deviceId,de=R($?a?.hubUrl??``:g?.hubUrl??``),fe=Math.max(0,Math.ceil(((g?.expiresAt??0)-T)/1e3)),pe=`${Math.floor(fe/60)}:${String(fe%60).padStart(2,`0`)}`,me=de?(0,C.jsxs)(w,{href:de,children:[(0,C.jsx)(t,{"aria-hidden":!0}),r(`deviceHubOpenHub`)]}):null;return(0,C.jsxs)(`section`,{className:`dc-page`,"aria-label":r(`deviceHubTitle`),children:[(0,C.jsxs)(`header`,{className:`dc-header`,children:[(0,C.jsxs)(`div`,{className:`dc-heading`,children:[(0,C.jsxs)(`span`,{className:`dc-eyebrow`,children:[(0,C.jsx)(ee,{"aria-hidden":!0}),r(`deviceHubTitle`)]}),(0,C.jsx)(`h1`,{children:r(`deviceHubTitle`)}),(0,C.jsx)(`p`,{children:r(`deviceHubSubtitle`)})]}),(0,C.jsxs)(`div`,{className:`dc-actions`,children:[$&&me,(0,C.jsxs)(`span`,{className:`dc-status ${$?a?.connected?`is-online`:`is-offline`:`is-unpaired`}`,children:[(0,C.jsx)(`span`,{className:`dc-status-dot`}),r($?a?.connected?`deviceHubOnline`:`deviceHubOffline`:`deviceHubUnpaired`)]})]})]}),(0,C.jsx)(`div`,{className:`dc-layout`,style:{display:`block`},children:(0,C.jsxs)(`main`,{className:`dc-content`,children:[V&&(0,C.jsxs)(`div`,{className:`dc-loading`,role:`status`,children:[(0,C.jsx)(v,{"aria-hidden":!0}),r(`deviceHubLoading`)]}),(F||j)&&(0,C.jsxs)(`div`,{className:`dc-notice is-error`,role:`alert`,children:[(0,C.jsx)(`span`,{children:F?r(`deviceHubLocalOnly`):`${r(`deviceHubStatusError`)} ${j}`}),(0,C.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>void oe(),children:[(0,C.jsx)(v,{"aria-hidden":!0}),r(`deviceHubRetry`)]})]}),k&&!F&&(0,C.jsx)(`div`,{className:`dc-notice is-error`,role:`alert`,children:k}),N&&(0,C.jsxs)(`div`,{className:`dc-notice is-success`,role:`status`,children:[(0,C.jsx)(n,{"aria-hidden":!0}),N]}),!$&&(a||F)&&(0,C.jsx)(ie,{initialHubUrl:u,onConnect:e=>{if(F){P(r(`deviceHubLocalOnly`));return}q.current=!0,f(e),b(!0)}}),a&&!F&&!$&&(0,C.jsxs)(`section`,{className:`dc-card`,children:[(0,C.jsxs)(`div`,{className:`dc-card-header`,children:[(0,C.jsx)(`span`,{className:`dc-icon`,children:(0,C.jsx)(d,{"aria-hidden":!0})}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`h2`,{children:r(`deviceHubPairTitle`)}),(0,C.jsx)(`p`,{children:r(`deviceHubPairHint`)})]})]}),(0,C.jsx)(`ol`,{className:`dc-steps`,children:[`deviceHubStepDetails`,`deviceHubStepApprove`,`deviceHubStepWait`].map((e,t)=>(0,C.jsxs)(`li`,{className:g?t===0?`is-complete`:`is-active`:t===0?`is-active`:``,children:[(0,C.jsx)(`span`,{className:`dc-step-number`,children:g&&t===0?(0,C.jsx)(n,{"aria-hidden":!0}):t+1}),(0,C.jsx)(`span`,{children:r(e)})]},e))}),(0,C.jsxs)(`form`,{className:`dc-form`,onSubmit:e=>{e.preventDefault(),se()},children:[(0,C.jsxs)(`div`,{className:`dc-field`,children:[(0,C.jsx)(`label`,{htmlFor:`dc-hub-url`,children:r(`deviceHubHubUrl`)}),(0,C.jsx)(`input`,{id:`dc-hub-url`,type:`url`,autoComplete:`url`,required:!0,placeholder:r(`deviceHubHubPlaceholder`),value:u,disabled:!!g||!!D,onChange:e=>{q.current=!0,f(e.target.value)}})]}),(0,C.jsxs)(`div`,{className:`dc-field`,children:[(0,C.jsx)(`label`,{htmlFor:`dc-device-name`,children:r(`deviceHubName`)}),(0,C.jsx)(`input`,{id:`dc-device-name`,maxLength:80,required:!0,autoComplete:`off`,placeholder:r(`deviceHubNamePlaceholder`),value:p,disabled:!!g||!!D,onChange:e=>{q.current=!0,h(e.target.value)}})]}),!g&&(0,C.jsx)(`div`,{className:`dc-actions`,children:(0,C.jsxs)(`button`,{className:`dc-button is-primary`,type:`submit`,disabled:!!D,children:[(0,C.jsx)(d,{"aria-hidden":!0}),r(D?`deviceHubWorking`:`deviceHubGetCode`)]})})]}),g&&(0,C.jsxs)(`div`,{className:`dc-pairing`,children:[(0,C.jsx)(`span`,{className:`dc-code-label`,children:r(`deviceHubCode`)}),(0,C.jsxs)(`div`,{className:`dc-code-row`,children:[(0,C.jsx)(`code`,{className:`dc-code`,children:g.code}),(0,C.jsx)(`button`,{className:`dc-icon-button`,type:`button`,"aria-label":r(`deviceHubCopy`),onClick:()=>void ue(),children:(0,C.jsx)(o,{"aria-hidden":!0})})]}),(0,C.jsx)(`div`,{className:`dc-pair-meta`,children:r(fe?`deviceHubExpires`:`deviceHubExpired`,{time:pe})}),(0,C.jsxs)(`div`,{className:`dc-actions`,children:[me,(0,C.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:!!D,onClick:()=>{++W.current,_(null),A(``),P(``)},children:[(0,C.jsx)(v,{"aria-hidden":!0}),r(`deviceHubNewCode`)]})]}),fe>0&&(0,C.jsxs)(`p`,{className:`dc-progress`,role:`status`,children:[(0,C.jsx)(v,{"aria-hidden":!0}),r(`deviceHubWaiting`)]})]})]}),$&&a&&!F&&(0,C.jsxs)(`section`,{className:`dc-card`,children:[(0,C.jsxs)(`div`,{className:`dc-device-summary`,children:[(0,C.jsx)(`span`,{className:`dc-device-icon`,children:(0,C.jsx)(ee,{"aria-hidden":!0})}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`h2`,{children:a.remark?.trim()||a.name}),(0,C.jsx)(`p`,{children:a.remark?.trim()?`${a.name} · ${r(`deviceHubDeviceTitle`)}`:r(`deviceHubDeviceTitle`)})]})]}),(0,C.jsxs)(`dl`,{className:`dc-details`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`dt`,{children:r(`deviceHubDeviceId`)}),(0,C.jsx)(`dd`,{children:a.deviceId})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`dt`,{children:r(`deviceHubHubUrl`)}),(0,C.jsx)(`dd`,{children:a.hubUrl})]})]})]}),$&&a?.hubUrl&&a.deviceId&&!F&&(0,C.jsx)(ne,{hubUrl:a.hubUrl,currentDeviceId:a.deviceId},`directory:${a.hubUrl}:${a.deviceId}`),!F&&(0,C.jsx)(re,{pathCompletions:e},`bots:${a?.hubUrl??``}:${a?.deviceId??`unpaired`}`),$&&!F&&(0,C.jsx)(I,{}),(0,C.jsx)(z,{}),$&&a&&!F&&(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`section`,{className:`dc-card`,children:[(0,C.jsxs)(`div`,{className:`dc-card-header`,children:[(0,C.jsx)(`span`,{className:`dc-icon`,children:(0,C.jsx)(s,{"aria-hidden":!0})}),(0,C.jsx)(`div`,{children:(0,C.jsx)(`h2`,{children:r(`deviceHubPermissions`)})})]}),(0,C.jsxs)(`div`,{className:`dc-permission-row`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`h3`,{id:`dc-permission-label`,children:r(`deviceHubPermissionLabel`)}),(0,C.jsx)(`p`,{id:`dc-permission-hint`,children:r(`deviceHubPermissionHint`)})]}),(0,C.jsx)(`button`,{type:`button`,className:`dc-toggle${a.allowExecution?` is-on`:``}`,role:`switch`,"aria-checked":a.allowExecution,"aria-labelledby":`dc-permission-label`,"aria-describedby":`dc-permission-hint`,disabled:!!D,onClick:()=>void ce(),children:(0,C.jsx)(`span`,{className:`dc-toggle-thumb`})})]}),(0,C.jsx)(`p`,{className:`dc-permission-state`,role:`status`,children:r(D===`permission`?`deviceHubSaving`:a.allowExecution?`deviceHubEnabled`:`deviceHubReadOnly`)})]}),(0,C.jsx)(x,{hubUrl:a?.hubUrl,deviceId:a?.deviceId,onNotice:P}),(0,C.jsxs)(`details`,{className:`dc-advanced`,children:[(0,C.jsx)(`summary`,{children:r(`deviceHubAdvanced`)}),(0,C.jsxs)(`div`,{className:`dc-danger-zone`,children:[(0,C.jsx)(`h3`,{children:r(`deviceHubDisconnect`)}),(0,C.jsx)(`p`,{children:r(`deviceHubDisconnectHint`)}),(0,C.jsx)(`button`,{type:`button`,className:`dc-button is-danger`,disabled:!!D,onClick:()=>void le(),children:r(D===`disconnect`?`deviceHubWorking`:`deviceHubDisconnect`)})]})]})]}),(0,C.jsxs)(`aside`,{className:`dc-help`,children:[(0,C.jsx)(m,{className:`dc-help-icon`,"aria-hidden":!0}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`h3`,{children:r(`deviceHubHelpTitle`)}),(0,C.jsx)(`p`,{children:r(`deviceHubHelpText`)})]})]})]})})]})}export{B as DeviceCenter};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{A as t,Bt as n,Dn as r,Dt as i,Jt as a,K as o,Lt as s,St as c,Tn as l,bn as u,ot as d,p as f,qt as p,un as m,z as h,zt as g}from"./app-globals-CZxzGvIo.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=u(),[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,n)=>{let i=new AbortController;U.current.add(i);let a=()=>i.abort();n&&(n.aborted?i.abort():n.addEventListener(`abort`,a,{once:!0}));try{let n=await fetch(l(r(`/api/device-center/${e}`)),{method:t?`POST`:`GET`,credentials:`same-origin`,signal:i.signal,headers:t?{"Content-Type":`application/json`}:void 0,body:t?JSON.stringify(t):void 0}),a=await n.json().catch(()=>({}));if(!n.ok){let e=typeof a.error==`string`?a.error:`HTTP ${n.status}`;throw Error(e)}return a}finally{n&&n.removeEventListener(`abort`,a),U.current.delete(i)}},[]),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)(g,{className:j?`des-spin`:``})})]}),L&&(0,b.jsxs)(`div`,{className:`des-alert des-alert-error`,role:`alert`,children:[(0,b.jsx)(f,{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)(m,{})})]}),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)(m,{})})]}),(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)(s,{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)(h,{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)(a,{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)(n,{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)(o,{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)(p,{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)(i,{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)(d,{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)(c,{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)(f,{}),` `,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)(s,{}),` `,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)(h,{}),` `,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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Cn as t,Dn as n,Dt as r,Mt as i,Rt as a,Tn as o,Ut as s,cn as c,vn as l}from"./app-globals-CZxzGvIo.js";import{i as u,r as d,t as f}from"./react-CR5VJ85Q.js";import{t as p}from"./shortcut-stack-hhrDyRBn.js";import{gt as ee}from"./index-EH5Fw9fa.js";import{r as te,t as ne}from"./group-view-state-CGCzYF8k.js";var m=e(u(),1),h=d(),g=f(),re={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: `}},_=class extends Error{status;code;constructor(e,t,n){super(n),this.status=e,this.code=t}};async function v(e,t,r){let i=await fetch(o(n(`/api/device-center/${e}`)),{method:r?`POST`:`GET`,credentials:`same-origin`,signal:t,...r?{headers:{"Content-Type":`application/json`},body:JSON.stringify(r)}:{}}),a=await i.json().catch(()=>({}));if(!i.ok)throw new _(i.status,a.code??``,typeof a.error==`string`?a.error:String(i.status));return a}function y(e){window.dispatchEvent(new CustomEvent(`pi-web-ui:device-group-open`,{detail:{roomId:e}}))}function b({onClose:e}){let{locale:n}=l(),r=re[t(n)?`zh`:`en`];return p(()=>{document.querySelector(`dialog[open]`)||e()}),(0,h.createPortal)((0,g.jsx)(`div`,{className:`modal-backdrop`,onClick:e,children:(0,g.jsx)(`div`,{className:`device-group-create-dialog`,role:`dialog`,"aria-modal":`true`,"aria-label":r.create,onClick:e=>e.stopPropagation(),children:(0,g.jsx)(x,{createOnly:!0,onClose:e})})}),document.body)}function x({active:e=!0,navigation:n,createOnly:o=!1,onClose:u}){let{locale:d}=l(),f=re[t(d)?`zh`:`en`],[p,h]=(0,m.useState)([]),[b,x]=(0,m.useState)([]),[S,C]=(0,m.useState)(``),[w,T]=(0,m.useState)(null),[E,ie]=(0,m.useState)(!0),[D,O]=(0,m.useState)(``),[ae,k]=(0,m.useState)(!1),[A,j]=(0,m.useState)(o),[M,N]=(0,m.useState)(!1),[P,F]=(0,m.useState)(!1),[I,L]=(0,m.useState)(``),[R,z]=(0,m.useState)([]),[B,V]=(0,m.useState)(``),[H,U]=(0,m.useState)(!1),[oe,W]=(0,m.useState)(0),[G,se]=(0,m.useState)(``),[ce,le]=(0,m.useState)([]),K=(0,m.useRef)(new ne),q=(0,m.useRef)(null),J=(0,m.useRef)(void 0),Y=(0,m.useRef)(0),X=(0,m.useRef)(null),ue=(0,m.useRef)(f);ue.current=f;function de(e){let t=ue.current;if(e instanceof _){if(e.status===409&&/^(REPAIR_REQUIRED|NOT_PAIRED|DEVICE_CHANGED)$/.test(e.code)||e.status===403&&/binding|credential|unpaired|revoked|not_bound|hub_forbidden/i.test(e.code))return t.rebind;if(e.status===403)return t.forbidden}return`${t.failed}: ${e instanceof Error?e.message:String(e)}`}function Z(){X.current?.abort(),X.current=null,U(!1)}function Q(e,t=!1){++Y.current,Z(),C(e),T(null),j(!1),N(t),k(!1),V(``),q.current=t?e:null,z([]),ie(!0),O(``),W(e=>e+1)}function fe(){++Y.current,Z(),j(!0),k(!1),V(``),N(!1),q.current=null,T(null),z([]),L(``),O(``),W(e=>e+1)}(0,m.useEffect)(()=>{let t=++Y.current,n=null,r=!1,i=()=>Y.current===t;async function a(){if(!e||document.visibilityState===`hidden`||r)return;r=!0;let t=new AbortController;n=t;try{let[e,n,r]=await Promise.all([v(`bots`,t.signal),v(`rooms`,t.signal),M&&S?v(`rooms/${encodeURIComponent(S)}`,t.signal):Promise.resolve(null)]);if(!i()||t.signal.aborted)return;if(h(e.bots),x(n.rooms),T(r),r?.tasks){le(r.tasks);for(let e of r.tasks)e.status===`completed`?K.current.onTaskCompleted(e.roomId,e.id):e.status===`failed`&&K.current.onTaskFailed(e.roomId,e.id)}r&&q.current===r.room.id&&(q.current=null,z(r.room.botIds),V(r.room.primaryBotId??``)),O(``)}catch(e){i()&&!t.signal.aborted&&O(de(e))}finally{t.abort(),r=!1,i()&&ie(!1)}}a();let o=window.setInterval(()=>void a(),3e3),s=()=>{document.visibilityState===`hidden`?n?.abort():a()};return document.addEventListener(`visibilitychange`,s),()=>{++Y.current,n?.abort(),clearInterval(o),document.removeEventListener(`visibilitychange`,s)}},[e,S,M,oe]),(0,m.useEffect)(()=>()=>X.current?.abort(),[]),(0,m.useEffect)(()=>{e||Z()},[e]),(0,m.useEffect)(()=>{e&&n&&n.revision!==J.current&&(J.current=n.revision,n.create?fe():n.roomId&&Q(n.roomId,n.manage))},[e,n?.revision]);async function pe(){if(!e||X.current||(A?!I.trim():!w))return;let n=new AbortController;X.current=n,U(!0),O(``),k(!1);let r=R.includes(B)?B:``,i=A,a=w?.room.id;try{let{room:e}=await v(i?`rooms`:`rooms/${encodeURIComponent(a)}/members`,n.signal,{...i?{name:I.trim()}:{},botIds:R,...B&&R.includes(B)?{primaryBotId:B}:!i&&w?.room.primaryBotId?{primaryBotId:null}:{}});if(n.signal.aborted||X.current!==n)return;if((e.primaryBotId??``)!==r)throw Error(t(d)?`中心未保存主 Bot 设置,请更新群组所属的设备中心(Hub)后重试。`:`The Hub did not save the primary Bot setting. Update the group's Hub and retry.`);k(!0),x(t=>[...t.filter(t=>t.id!==e.id),e]),C(e.id),T({room:e}),j(!1),N(!i),L(``),z(i?[]:e.botIds),V(e.primaryBotId??``),W(e=>e+1),window.dispatchEvent(new CustomEvent(`pi-web-ui:device-groups-changed`)),i&&(y(e.id),o&&u?.())}catch(e){!n.signal.aborted&&X.current===n&&O(de(e))}finally{X.current===n&&(X.current=null,U(!1))}}let $=b.find(e=>e.id===S);return(0,g.jsxs)(`section`,{className:`dg-root`,"aria-label":f.groups,children:[!o&&(0,g.jsxs)(`div`,{className:`dc-card dg-sidebar`,children:[(0,g.jsxs)(`div`,{className:`dg-heading`,children:[(0,g.jsxs)(`h2`,{children:[(0,g.jsx)(c,{}),` `,f.groups]}),(0,g.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:fe,children:[(0,g.jsx)(a,{}),` `,f.create]})]}),(0,g.jsx)(`div`,{className:`dg-search-bar`,style:{padding:`0 10px 8px 10px`},children:(0,g.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`6px`,background:`var(--bg)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`4px 8px`},children:[(0,g.jsx)(s,{style:{color:`var(--text-dim)`,flex:`none`}}),(0,g.jsx)(`input`,{type:`search`,value:G,onChange:e=>se(e.target.value),placeholder:f.searchPlaceholder,style:{border:`none`,background:`transparent`,color:`var(--text)`,width:`100%`,fontSize:`12px`,outline:`none`}})]})}),(0,g.jsx)(`div`,{className:`dg-rooms`,children:te(G,b,ce).map(t=>{let n=b.find(e=>e.id===t.roomId);if(!n)return null;let i=K.current.getPendingInteractionsCount(n.id);return(0,g.jsxs)(`button`,{className:`dc-button dg-room`,type:`button`,"aria-current":n.id===S?`page`:void 0,disabled:!e,onClick:()=>{Q(n.id),y(n.id)},children:[(0,g.jsx)(r,{}),(0,g.jsxs)(`span`,{style:{flex:1,minWidth:0,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,textAlign:`left`},children:[n.name,t.matchedBy===`bot_id`&&(0,g.jsxs)(`small`,{style:{display:`block`,color:`var(--text-dim)`,fontSize:`11px`},children:[f.matchedBot,` `,G]}),t.matchedBy===`task_title`&&t.matchedTask&&(0,g.jsxs)(`small`,{style:{display:`block`,color:`var(--accent)`,fontSize:`11px`},children:[f.matchedTask,` `,t.matchedTask.title]}),t.matchedBy===`task_id`&&t.matchedTask&&(0,g.jsxs)(`small`,{style:{display:`block`,color:`var(--text-dim)`,fontSize:`11px`},children:[`ID: `,t.matchedTask.id.slice(0,8)]})]}),i>0&&(0,g.jsx)(`span`,{style:{flex:`none`,background:`var(--accent)`,color:`var(--accent-contrast, #fff)`,borderRadius:`10px`,padding:`1px 6px`,fontSize:`11px`,fontWeight:`bold`},children:i})]},t.matchedTask?`${n.id}:${t.matchedTask.id}`:n.id)})}),!E&&!b.length&&(0,g.jsx)(`p`,{className:`dg-empty`,children:f.empty})]}),(0,g.jsxs)(`div`,{className:`dc-card dg-chat`,children:[ae&&(0,g.jsx)(`p`,{role:`status`,children:t(d)?`已保存成员和主 Bot 设置。`:`Members and primary Bot settings saved.`}),D&&(0,g.jsx)(`p`,{className:`dc-error`,role:`alert`,children:D}),E&&(0,g.jsx)(`p`,{role:`status`,children:f.loading}),A||M?(0,g.jsxs)(`form`,{className:`dg-create`,onSubmit:e=>{e.preventDefault(),pe()},children:[(0,g.jsx)(`h2`,{children:A?f.create:f.manage}),A&&(0,g.jsxs)(`div`,{className:`dc-field`,children:[(0,g.jsx)(`label`,{htmlFor:`device-group-name`,children:f.name}),(0,g.jsx)(`input`,{id:`device-group-name`,value:I,onChange:e=>L(e.target.value),disabled:H||!e})]}),(0,g.jsxs)(`fieldset`,{disabled:H||!e||M&&!w,children:[(0,g.jsx)(`legend`,{children:f.devices}),p.map(e=>(0,g.jsxs)(`label`,{className:`dg-device`,children:[(0,g.jsx)(`input`,{type:`checkbox`,disabled:!e.enabled&&!R.includes(e.id),checked:R.includes(e.id),onChange:t=>z(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}),(0,g.jsx)(i,{}),(0,g.jsxs)(`span`,{children:[e.name,` · `,e.id,` · `,e.deviceId,` · `,e.online?f.online:f.offline]})]},e.id))]}),(0,g.jsxs)(`div`,{className:`dc-field`,children:[(0,g.jsx)(`label`,{htmlFor:`device-group-primary-bot`,children:t(d)?`主 Bot`:`Primary Bot`}),(0,g.jsxs)(`select`,{id:`device-group-primary-bot`,value:R.includes(B)?B:``,disabled:H||!e||M&&!w,onChange:e=>V(e.target.value),children:[(0,g.jsx)(`option`,{value:``,children:t(d)?`不设置(需 @ Bot)`:`None (mention a Bot)`}),p.filter(e=>e.enabled&&R.includes(e.id)).map(e=>(0,g.jsxs)(`option`,{value:e.id,children:[e.name,` · `,e.id]},e.id))]}),(0,g.jsx)(`p`,{children:t(d)?`未 @ Bot 的消息自动发送给主 Bot。`:`Messages without a Bot mention go to the primary Bot.`})]}),(0,g.jsxs)(`div`,{className:`dc-actions`,children:[(0,g.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:H||!e||P,onClick:()=>F(!0),children:[(0,g.jsx)(a,{}),` `,t(d)?`新建 Bot`:`Create Bot`]}),(0,g.jsx)(`button`,{className:`dc-button`,type:`submit`,disabled:H||!e||(A?!I.trim():!w),children:A?f.create:f.save}),(0,g.jsx)(`button`,{className:`dc-button`,type:`button`,onClick:()=>{Z(),q.current=null,o&&u?.(),j(!1),N(!1),O(``)},children:f.cancel})]})]}):$?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`div`,{className:`dg-title`,children:(0,g.jsxs)(`h2`,{children:[(0,g.jsx)(c,{}),` `,$.name]})}),(0,g.jsxs)(`div`,{className:`dc-actions`,children:[(0,g.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:()=>y($.id),children:[(0,g.jsx)(r,{}),f.open]}),(0,g.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:()=>Q($.id,!0),children:[(0,g.jsx)(c,{}),f.manage]})]})]}):(0,g.jsx)(`p`,{className:`dg-empty`,children:f.choose})]}),P&&(0,g.jsx)(ee,{createOnly:!0,onCancel:()=>F(!1),onCreated:(e,n)=>{F(!1),n&&e.enabled?(h(t=>[...t.filter(t=>t.id!==e.id),e]),z(t=>[...new Set([...t,e.id])])):O(t(d)?`Bot 已保存;请启用并同步到中心后,再加入群组。`:`Bot saved. Enable and sync it to the hub before adding it to the group.`)}})]})}export{b as DeviceGroupCreateDialog};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Cn as t,Dn as n,Dt as r,Mt as i,Rt as a,Tn as o,Ut as s,cn as c,vn as l}from"./app-globals-CZxzGvIo.js";import{i as u,r as d,t as f}from"./react-CR5VJ85Q.js";import{t as p}from"./shortcut-stack-hhrDyRBn.js";import{gt as ee}from"./index-CuN802Sj.js";import{r as te,t as ne}from"./group-view-state-CGCzYF8k.js";var m=e(u(),1),h=d(),g=f(),re={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: `}},_=class extends Error{status;code;constructor(e,t,n){super(n),this.status=e,this.code=t}};async function v(e,t,r){let i=await fetch(o(n(`/api/device-center/${e}`)),{method:r?`POST`:`GET`,credentials:`same-origin`,signal:t,...r?{headers:{"Content-Type":`application/json`},body:JSON.stringify(r)}:{}}),a=await i.json().catch(()=>({}));if(!i.ok)throw new _(i.status,a.code??``,typeof a.error==`string`?a.error:String(i.status));return a}function y(e){window.dispatchEvent(new CustomEvent(`pi-web-ui:device-group-open`,{detail:{roomId:e}}))}function b({onClose:e}){let{locale:n}=l(),r=re[t(n)?`zh`:`en`];return p(()=>{document.querySelector(`dialog[open]`)||e()}),(0,h.createPortal)((0,g.jsx)(`div`,{className:`modal-backdrop`,onClick:e,children:(0,g.jsx)(`div`,{className:`device-group-create-dialog`,role:`dialog`,"aria-modal":`true`,"aria-label":r.create,onClick:e=>e.stopPropagation(),children:(0,g.jsx)(x,{createOnly:!0,onClose:e})})}),document.body)}function x({active:e=!0,navigation:n,createOnly:o=!1,onClose:u}){let{locale:d}=l(),f=re[t(d)?`zh`:`en`],[p,h]=(0,m.useState)([]),[b,x]=(0,m.useState)([]),[S,C]=(0,m.useState)(``),[w,T]=(0,m.useState)(null),[E,ie]=(0,m.useState)(!0),[D,O]=(0,m.useState)(``),[ae,k]=(0,m.useState)(!1),[A,j]=(0,m.useState)(o),[M,N]=(0,m.useState)(!1),[P,F]=(0,m.useState)(!1),[I,L]=(0,m.useState)(``),[R,z]=(0,m.useState)([]),[B,V]=(0,m.useState)(``),[H,U]=(0,m.useState)(!1),[oe,W]=(0,m.useState)(0),[G,se]=(0,m.useState)(``),[ce,le]=(0,m.useState)([]),K=(0,m.useRef)(new ne),q=(0,m.useRef)(null),J=(0,m.useRef)(void 0),Y=(0,m.useRef)(0),X=(0,m.useRef)(null),ue=(0,m.useRef)(f);ue.current=f;function de(e){let t=ue.current;if(e instanceof _){if(e.status===409&&/^(REPAIR_REQUIRED|NOT_PAIRED|DEVICE_CHANGED)$/.test(e.code)||e.status===403&&/binding|credential|unpaired|revoked|not_bound|hub_forbidden/i.test(e.code))return t.rebind;if(e.status===403)return t.forbidden}return`${t.failed}: ${e instanceof Error?e.message:String(e)}`}function Z(){X.current?.abort(),X.current=null,U(!1)}function Q(e,t=!1){++Y.current,Z(),C(e),T(null),j(!1),N(t),k(!1),V(``),q.current=t?e:null,z([]),ie(!0),O(``),W(e=>e+1)}function fe(){++Y.current,Z(),j(!0),k(!1),V(``),N(!1),q.current=null,T(null),z([]),L(``),O(``),W(e=>e+1)}(0,m.useEffect)(()=>{let t=++Y.current,n=null,r=!1,i=()=>Y.current===t;async function a(){if(!e||document.visibilityState===`hidden`||r)return;r=!0;let t=new AbortController;n=t;try{let[e,n,r]=await Promise.all([v(`bots`,t.signal),v(`rooms`,t.signal),M&&S?v(`rooms/${encodeURIComponent(S)}`,t.signal):Promise.resolve(null)]);if(!i()||t.signal.aborted)return;if(h(e.bots),x(n.rooms),T(r),r?.tasks){le(r.tasks);for(let e of r.tasks)e.status===`completed`?K.current.onTaskCompleted(e.roomId,e.id):e.status===`failed`&&K.current.onTaskFailed(e.roomId,e.id)}r&&q.current===r.room.id&&(q.current=null,z(r.room.botIds),V(r.room.primaryBotId??``)),O(``)}catch(e){i()&&!t.signal.aborted&&O(de(e))}finally{t.abort(),r=!1,i()&&ie(!1)}}a();let o=window.setInterval(()=>void a(),3e3),s=()=>{document.visibilityState===`hidden`?n?.abort():a()};return document.addEventListener(`visibilitychange`,s),()=>{++Y.current,n?.abort(),clearInterval(o),document.removeEventListener(`visibilitychange`,s)}},[e,S,M,oe]),(0,m.useEffect)(()=>()=>X.current?.abort(),[]),(0,m.useEffect)(()=>{e||Z()},[e]),(0,m.useEffect)(()=>{e&&n&&n.revision!==J.current&&(J.current=n.revision,n.create?fe():n.roomId&&Q(n.roomId,n.manage))},[e,n?.revision]);async function pe(){if(!e||X.current||(A?!I.trim():!w))return;let n=new AbortController;X.current=n,U(!0),O(``),k(!1);let r=R.includes(B)?B:``,i=A,a=w?.room.id;try{let{room:e}=await v(i?`rooms`:`rooms/${encodeURIComponent(a)}/members`,n.signal,{...i?{name:I.trim()}:{},botIds:R,...B&&R.includes(B)?{primaryBotId:B}:!i&&w?.room.primaryBotId?{primaryBotId:null}:{}});if(n.signal.aborted||X.current!==n)return;if((e.primaryBotId??``)!==r)throw Error(t(d)?`中心未保存主 Bot 设置,请更新群组所属的设备中心(Hub)后重试。`:`The Hub did not save the primary Bot setting. Update the group's Hub and retry.`);k(!0),x(t=>[...t.filter(t=>t.id!==e.id),e]),C(e.id),T({room:e}),j(!1),N(!i),L(``),z(i?[]:e.botIds),V(e.primaryBotId??``),W(e=>e+1),window.dispatchEvent(new CustomEvent(`pi-web-ui:device-groups-changed`)),i&&(y(e.id),o&&u?.())}catch(e){!n.signal.aborted&&X.current===n&&O(de(e))}finally{X.current===n&&(X.current=null,U(!1))}}let $=b.find(e=>e.id===S);return(0,g.jsxs)(`section`,{className:`dg-root`,"aria-label":f.groups,children:[!o&&(0,g.jsxs)(`div`,{className:`dc-card dg-sidebar`,children:[(0,g.jsxs)(`div`,{className:`dg-heading`,children:[(0,g.jsxs)(`h2`,{children:[(0,g.jsx)(c,{}),` `,f.groups]}),(0,g.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:fe,children:[(0,g.jsx)(a,{}),` `,f.create]})]}),(0,g.jsx)(`div`,{className:`dg-search-bar`,style:{padding:`0 10px 8px 10px`},children:(0,g.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`6px`,background:`var(--bg)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`4px 8px`},children:[(0,g.jsx)(s,{style:{color:`var(--text-dim)`,flex:`none`}}),(0,g.jsx)(`input`,{type:`search`,value:G,onChange:e=>se(e.target.value),placeholder:f.searchPlaceholder,style:{border:`none`,background:`transparent`,color:`var(--text)`,width:`100%`,fontSize:`12px`,outline:`none`}})]})}),(0,g.jsx)(`div`,{className:`dg-rooms`,children:te(G,b,ce).map(t=>{let n=b.find(e=>e.id===t.roomId);if(!n)return null;let i=K.current.getPendingInteractionsCount(n.id);return(0,g.jsxs)(`button`,{className:`dc-button dg-room`,type:`button`,"aria-current":n.id===S?`page`:void 0,disabled:!e,onClick:()=>{Q(n.id),y(n.id)},children:[(0,g.jsx)(r,{}),(0,g.jsxs)(`span`,{style:{flex:1,minWidth:0,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,textAlign:`left`},children:[n.name,t.matchedBy===`bot_id`&&(0,g.jsxs)(`small`,{style:{display:`block`,color:`var(--text-dim)`,fontSize:`11px`},children:[f.matchedBot,` `,G]}),t.matchedBy===`task_title`&&t.matchedTask&&(0,g.jsxs)(`small`,{style:{display:`block`,color:`var(--accent)`,fontSize:`11px`},children:[f.matchedTask,` `,t.matchedTask.title]}),t.matchedBy===`task_id`&&t.matchedTask&&(0,g.jsxs)(`small`,{style:{display:`block`,color:`var(--text-dim)`,fontSize:`11px`},children:[`ID: `,t.matchedTask.id.slice(0,8)]})]}),i>0&&(0,g.jsx)(`span`,{style:{flex:`none`,background:`var(--accent)`,color:`var(--accent-contrast, #fff)`,borderRadius:`10px`,padding:`1px 6px`,fontSize:`11px`,fontWeight:`bold`},children:i})]},t.matchedTask?`${n.id}:${t.matchedTask.id}`:n.id)})}),!E&&!b.length&&(0,g.jsx)(`p`,{className:`dg-empty`,children:f.empty})]}),(0,g.jsxs)(`div`,{className:`dc-card dg-chat`,children:[ae&&(0,g.jsx)(`p`,{role:`status`,children:t(d)?`已保存成员和主 Bot 设置。`:`Members and primary Bot settings saved.`}),D&&(0,g.jsx)(`p`,{className:`dc-error`,role:`alert`,children:D}),E&&(0,g.jsx)(`p`,{role:`status`,children:f.loading}),A||M?(0,g.jsxs)(`form`,{className:`dg-create`,onSubmit:e=>{e.preventDefault(),pe()},children:[(0,g.jsx)(`h2`,{children:A?f.create:f.manage}),A&&(0,g.jsxs)(`div`,{className:`dc-field`,children:[(0,g.jsx)(`label`,{htmlFor:`device-group-name`,children:f.name}),(0,g.jsx)(`input`,{id:`device-group-name`,value:I,onChange:e=>L(e.target.value),disabled:H||!e})]}),(0,g.jsxs)(`fieldset`,{disabled:H||!e||M&&!w,children:[(0,g.jsx)(`legend`,{children:f.devices}),p.map(e=>(0,g.jsxs)(`label`,{className:`dg-device`,children:[(0,g.jsx)(`input`,{type:`checkbox`,disabled:!e.enabled&&!R.includes(e.id),checked:R.includes(e.id),onChange:t=>z(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}),(0,g.jsx)(i,{}),(0,g.jsxs)(`span`,{children:[e.name,` · `,e.id,` · `,e.deviceId,` · `,e.online?f.online:f.offline]})]},e.id))]}),(0,g.jsxs)(`div`,{className:`dc-field`,children:[(0,g.jsx)(`label`,{htmlFor:`device-group-primary-bot`,children:t(d)?`主 Bot`:`Primary Bot`}),(0,g.jsxs)(`select`,{id:`device-group-primary-bot`,value:R.includes(B)?B:``,disabled:H||!e||M&&!w,onChange:e=>V(e.target.value),children:[(0,g.jsx)(`option`,{value:``,children:t(d)?`不设置(需 @ Bot)`:`None (mention a Bot)`}),p.filter(e=>e.enabled&&R.includes(e.id)).map(e=>(0,g.jsxs)(`option`,{value:e.id,children:[e.name,` · `,e.id]},e.id))]}),(0,g.jsx)(`p`,{children:t(d)?`未 @ Bot 的消息自动发送给主 Bot。`:`Messages without a Bot mention go to the primary Bot.`})]}),(0,g.jsxs)(`div`,{className:`dc-actions`,children:[(0,g.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:H||!e||P,onClick:()=>F(!0),children:[(0,g.jsx)(a,{}),` `,t(d)?`新建 Bot`:`Create Bot`]}),(0,g.jsx)(`button`,{className:`dc-button`,type:`submit`,disabled:H||!e||(A?!I.trim():!w),children:A?f.create:f.save}),(0,g.jsx)(`button`,{className:`dc-button`,type:`button`,onClick:()=>{Z(),q.current=null,o&&u?.(),j(!1),N(!1),O(``)},children:f.cancel})]})]}):$?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`div`,{className:`dg-title`,children:(0,g.jsxs)(`h2`,{children:[(0,g.jsx)(c,{}),` `,$.name]})}),(0,g.jsxs)(`div`,{className:`dc-actions`,children:[(0,g.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:()=>y($.id),children:[(0,g.jsx)(r,{}),f.open]}),(0,g.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:()=>Q($.id,!0),children:[(0,g.jsx)(c,{}),f.manage]})]})]}):(0,g.jsx)(`p`,{className:`dg-empty`,children:f.choose})]}),P&&(0,g.jsx)(ee,{createOnly:!0,onCancel:()=>F(!1),onCreated:(e,n)=>{F(!1),n&&e.enabled?(h(t=>[...t.filter(t=>t.id!==e.id),e]),z(t=>[...new Set([...t,e.id])])):O(t(d)?`Bot 已保存;请启用并同步到中心后,再加入群组。`:`Bot saved. Enable and sync it to the hub before adding it to the group.`)}})]})}export{b as DeviceGroupCreateDialog};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{N as t}from"./app-globals-CZxzGvIo.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,Dn as i,Q as a,Tn as ee,U as te,Vt as ne,X as re,bn as ie,bt as ae,et as oe,fn as se,kt as ce,pn as le,t as ue,un as de,wt as fe,xt as pe}from"./app-globals-CZxzGvIo.js";import{i as o,t as me}from"./react-CR5VJ85Q.js";import{G as he,H as ge,ft as _e,st as ve,ut as ye}from"./index-CuN802Sj.js";var s=e(o(),1),c=`未命名章节`;function l(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 be(e){let t=new Map;return e.map(({level:e,label:n})=>{let r=String(n??``).replace(/\s+/g,` `).trim(),i=l(r||c),a=(t.get(i)??0)+1;return t.set(i,a),{level:e,id:a===1?i:`${i}-${a}`,label:r||c}})}function u(e){return e.length>=2}var d=me(),f=5e3,xe=`pi-web-ui:preview-toc`;function p({file:e,content:o,onAddLines:me,onAttach:c,onClose:l,uiFilePreviewToolbar:p,onUiAction:Se}){let _=ie(),[v,Ce]=(0,s.useState)(null),[y,we]=(0,s.useState)(!1),[b,x]=(0,s.useState)(null),[Te,Ee]=(0,s.useState)(!1),[De,Oe]=(0,s.useState)(!1),[S,C]=(0,s.useState)(!1),[w,T]=(0,s.useState)(``),[E,D]=(0,s.useState)(!0),[O,k]=(0,s.useState)(!0),[A,ke]=(0,s.useState)(!1),j=(0,s.useRef)(!1),[M,Ae]=(0,s.useState)(!0),[N,je]=(0,s.useState)(!1),[P,Me]=(0,s.useState)(100),F=(0,s.useRef)(0),I=(0,s.useRef)(!1),L=(0,s.useRef)(null),[Ne,R]=(0,s.useState)(!1),[Pe,z]=(0,s.useState)(!1),B=(0,s.useRef)(!1),V=(0,s.useRef)(null);(0,s.useEffect)(()=>()=>{L.current&&clearTimeout(L.current),V.current&&clearTimeout(V.current)},[]),(0,s.useEffect)(()=>{we(!0),Ce(null),x(null),C(!1),T(``),D(!0),k(!0),ke(!1),j.current=!1,B.current=!1,R(!1),z(!1),V.current&&clearTimeout(V.current),ue({type:`read_file`,path:e.path})},[e.path]),(0,s.useEffect)(()=>{o&&o.path===e.path&&(Ce(o),S||T(o.text),we(!1),B.current&&(B.current=!1,V.current&&clearTimeout(V.current),R(!1),z(!1),C(!1),T(o.text),j.current&&(m(e.name)&&D(!0),g(e.name)&&k(!0)),x(null)))},[o,S,e.path]),(0,s.useEffect)(()=>{let e=e=>{if(e.key===`Escape`){W();return}if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`s`&&S){e.preventDefault(),He();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(),Re())};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[l,v,S,w]),(0,s.useEffect)(()=>{let e=()=>{I.current=!1,Ee(!1)};return window.addEventListener(`mouseup`,e),()=>window.removeEventListener(`mouseup`,e)},[]);let H=(0,s.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]),Fe=v?.lines??0,Ie=Fe>f,Le=(e,t)=>{if(t){let t=F.current>0?F.current:e;x({start:Math.min(t,e),end:Math.max(t,e)})}else F.current=e,x({start:e,end:e})},Re=()=>{H.length!==0&&(F.current=1,x({start:1,end:H.length}))},ze=()=>{b&&(me(e.path,e.name,b.start,b.end),Oe(!0),L.current&&clearTimeout(L.current),L.current=setTimeout(()=>Oe(!1),1400))},U=v!==null&&v.kind===`text`&&!v.binary&&!v.truncated&&!h(e.name),Be=()=>{B.current=!1,V.current&&clearTimeout(V.current),R(!1),z(!1),T(v?.text??``),C(!1),j.current&&(m(e.name)&&D(!0),g(e.name)&&k(!0))},Ve=()=>{if(S){if(w!==(v?.text??``)&&!window.confirm(_(`discardFileChanges`)))return;Be();return}U&&v&&(j.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))},He=()=>{S&&v&&U&&ue({type:`write_file`,path:e.path,text:w})&&(B.current=!0,z(!1),R(!0),V.current&&clearTimeout(V.current),V.current=setTimeout(()=>{B.current=!1,R(!1),z(!0)},5e3))},W=()=>{(!S||w===(v?.text??``)||window.confirm(_(`discardFileChanges`)))&&l()},Ue=e=>{Me(Math.min(200,Math.max(50,e)))},We=b?b.end-b.start+1:0,G=v?.binary??!1,K=v?.truncated??!1,q=v?.kind??`text`,Ge=m(e.name)||h(e.name),Ke=g(e.name),qe=h(e.name),J=Ge&&E&&!S&&q===`text`&&!G,Y=Ke&&O&&!S&&q===`text`&&!G,[X,Je]=(0,s.useState)(()=>{try{return localStorage.getItem(xe)===`1`}catch{return!1}});(0,s.useEffect)(()=>{try{localStorage.setItem(xe,X?`1`:`0`)}catch{}},[X]);let[Z,Ye]=(0,s.useState)([]),[Xe,Ze]=(0,s.useState)(``),Q=(0,s.useRef)(null);(0,s.useEffect)(()=>{let e=Q.current;if(!e||!J){Ye([]);return}let t=[...e.querySelectorAll(`h1, h2, h3, h4, h5, h6`)],n=be(t.map(e=>({level:Number(e.tagName.slice(1)),label:e.textContent??``})));t.forEach((e,t)=>{e.id||=n[t].id}),Ye(n)},[J,v?.text,e.path]),(0,s.useEffect)(()=>{let e=Q.current;if(!e||!X||!u(Z))return;let t=Z.map(t=>e.querySelector(`#${CSS.escape(t.id)}`)).filter(e=>e!==null);if(t.length===0)return;let n=new IntersectionObserver(e=>{let t=e.filter(e=>e.isIntersecting).sort((e,t)=>e.boundingClientRect.top-t.boundingClientRect.top)[0];t?.target.id&&Ze(t.target.id)},{rootMargin:`0px 0px -70% 0px`});for(let e of t)n.observe(e);return()=>n.disconnect()},[Z,X]);let Qe={"host:fp-md":Ge&&q===`text`&&!G&&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)(oe,{}):(0,d.jsx)(r,{})}):null,"host:fp-toc":J&&u(Z)?(0,d.jsx)(`button`,{type:`button`,className:`fp-attach toc ${X?`on`:``}`,"data-tip":_(X?`previewTocHide`:`previewTocShow`),onClick:()=>Je(e=>!e),children:(0,d.jsx)(pe,{})}):null,"host:fp-html":Ke&&q===`text`&&!G&&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)(oe,{})}):null,"host:fp-edit":q===`text`&&!G&&v?(0,d.jsx)(`button`,{type:`button`,className:`fp-attach edit ${S?`on`:``}`,"data-tip":_(K?`fileEditTruncated`:S?`exitEditFile`:`editFile`),disabled:!U&&!S,onClick:Ve,children:(0,d.jsx)(a,{})}):null,"host:fp-wrap":q===`text`&&!G&&!J&&!Y?(0,d.jsx)(`button`,{type:`button`,className:`fp-attach wrap ${M?`on`:``}`,"data-tip":_(M?`disableWrap`:`enableWrap`),onClick:()=>Ae(e=>!e),children:(0,d.jsx)(te,{})}):null,"host:fp-zoom":q===`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:P<=50,onClick:()=>Ue(P-10),children:(0,d.jsx)(le,{})}),(0,d.jsxs)(`button`,{type:`button`,className:`fp-zoom-val`,title:_(`resetZoom`),onClick:()=>Me(100),children:[P,`%`]}),(0,d.jsx)(`button`,{type:`button`,className:`fp-attach zoom-in`,"data-tip":_(`zoomIn`),disabled:P>=200,onClick:()=>Ue(P+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 ye(e.path,e.name),children:(0,d.jsx)(re,{})}),"host:fp-ref":(0,d.jsx)(`button`,{type:`button`,className:`fp-attach ref`,"data-tip":_(`referenceTip`),onClick:()=>c(e.path,e.name,`reference`),children:(0,d.jsx)(ae,{})}),"host:fp-full":(0,d.jsx)(`button`,{type:`button`,className:`fp-attach full ${N?`on`:``}`,"data-tip":_(N?`exitFullscreen`:`fullscreen`),onClick:()=>je(e=>!e),children:N?(0,d.jsx)(ce,{}):(0,d.jsx)(fe,{})}),"host:fp-close":null},$e=p===void 0?[`host:fp-md`,`host:fp-toc`,`host:fp-html`,`host:fp-edit`,`host:fp-wrap`,`host:fp-zoom`,`host:fp-download`,`host:fp-ref`,`host:fp-full`].map(e=>({id:e,source:`host`})):p.filter(e=>!e.hidden&&e.id!==`host:fp-close`),$=e=>ee(i(`/api/file?clientId=${encodeURIComponent(he())}&path=${encodeURIComponent(e)}`)),et=e=>{let t=e.split(`/`).map(e=>encodeURIComponent(e)).join(`/`),n=/^[A-Za-z]:([\\/]|$)/.test(e)||e.startsWith(`/`)?`/api/preview/__abs__/${t}`:`/api/preview/${t}`;return ee(i(`${n}?clientId=${encodeURIComponent(he())}${A?`&allowJs=1`:``}`))};return(0,d.jsx)(`div`,{className:`fp-overlay ${N?`fullscreen`:``}`,onMouseDown:e=>{e.target===e.currentTarget&&W()},children:(0,d.jsxs)(`div`,{className:`fp ${N?`fullscreen`:``} ${qe?`is-ppt`:``}`,style:{"--fp-zoom":P/100},children:[(0,d.jsxs)(`div`,{className:`fp-head`,onDoubleClick:e=>{let t=e.target;t&&!t.closest(`button, a, input`)&&je(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&&q===`text`&&!G&&_(`fileLines`,{n:Fe}),v&&` · ${ve(v.size)}`]}),(0,d.jsx)(`span`,{className:`fp-head-actions`,children:ge($e,Qe,Se)}),(0,d.jsx)(`button`,{type:`button`,className:`fp-close`,title:_(`close`),"aria-label":_(`close`),onClick:W,children:(0,d.jsx)(de,{})})]}),K&&q===`text`&&!G&&(0,d.jsx)(`div`,{className:`fp-notice`,children:h(e.name)?_(`previewLinesTruncated`,{n:H.length}):_(`previewTruncated`)}),y&&!v&&(0,d.jsx)(`div`,{className:`fp-empty`,children:_(`loading`)}),!y&&q===`none`&&!G&&(0,d.jsx)(`div`,{className:`fp-empty`,children:_(`previewNotSupported`)}),!y&&q===`image`&&(0,d.jsx)(`div`,{className:`fp-media-wrap clickable`,onClick:W,title:_(`clickToCloseImage`),children:(0,d.jsx)(`img`,{className:`fp-media fp-media-clickable`,src:$(e.path),alt:e.name,onClick:W,title:_(`clickToCloseImage`)})}),!y&&q===`video`&&(0,d.jsx)(`div`,{className:`fp-media-wrap`,children:(0,d.jsx)(`video`,{className:`fp-media`,src:$(e.path),controls:!0,preload:`metadata`})}),!y&&q===`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:ve(v.size)}):null]}),(0,d.jsx)(`audio`,{className:`fp-audio-element`,src:$(e.path),controls:!0,autoPlay:!0,preload:`metadata`})]})}),!y&&Y&&v&&(0,d.jsxs)(`div`,{className:`fp-html`,children:[(0,d.jsxs)(`div`,{className:`fp-html-bar`,children:[(0,d.jsx)(`span`,{className:`fp-html-hint`,title:_(A?`htmlJsOnTip`:`htmlJsOffTip`),children:_(A?`htmlJsOn`:`htmlJsOff`)}),(0,d.jsx)(`button`,{type:`button`,className:`fp-html-js ${A?`on`:``}`,"data-tip":_(A?`htmlDisableJs`:`htmlEnableJs`),onClick:()=>ke(e=>!e),children:_(A?`htmlDisableJs`:`htmlEnableJs`)}),(0,d.jsxs)(`a`,{className:`fp-html-btn fp-html-external`,href:et(e.path),target:`_blank`,rel:`noopener noreferrer`,title:_(`openInNewTab`),children:[(0,d.jsx)(t,{}),(0,d.jsx)(`span`,{children:_(`openInNewTab`)})]})]}),(0,d.jsx)(`iframe`,{className:`fp-html-frame`,src:et(e.path),title:e.name,sandbox:A?`allow-scripts`:``,referrerPolicy:`no-referrer`},A?`js`:`nojs`)]}),!y&&J&&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:X&&u(Z)?`fp-toc-layout`:void 0,children:[X&&u(Z)&&(0,d.jsx)(`nav`,{className:`fp-toc`,"aria-label":_(`previewTocLabel`),children:Z.map(e=>(0,d.jsx)(`a`,{className:`l${Math.min(e.level,6)}${e.id===Xe?` on`:``}`,href:`#${e.id}`,title:e.label,onClick:t=>{t.preventDefault(),Q.current?.querySelector(`#${CSS.escape(e.id)}`)?.scrollIntoView({behavior:`smooth`,block:`start`})},children:e.label},e.id))}),(0,d.jsx)(`div`,{className:`fp-markdown-zoom`,ref:Q,children:(0,d.jsx)(_e,{text:v.text})})]})}),!y&&G&&q!==`image`&&q!==`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&&q===`text`&&!G&&v&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(`textarea`,{className:`fp-editor ${M?``:`no-wrap`}`,value:w,onChange:e=>T(e.target.value),wrap:M?`soft`:`off`,spellCheck:!1,autoFocus:!0}),Pe&&(0,d.jsx)(`div`,{className:`fp-notice`,role:`alert`,children:_(`saveResultUnknown`)})]}),!y&&!J&&!Y&&!S&&q===`text`&&!G&&v&&H.length===0&&(0,d.jsx)(`div`,{className:`fp-empty`,children:_(`emptyFile`)}),!y&&!J&&!Y&&!S&&q===`text`&&!G&&H.length>0&&(0,d.jsxs)(`div`,{className:`fp-code ${Te?`dragging`:``} ${M?``:`no-wrap`}`,onMouseDown:e=>{e.button===0&&e.preventDefault()},children:[H.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&&(Le(n,e.shiftKey),I.current=!0,Ee(!0))},onMouseEnter:()=>{I.current&&Le(n,!0)},children:[(0,d.jsx)(`span`,{className:`fp-num`,children:n}),(0,d.jsx)(`span`,{className:`fp-code-text`,children:e})]},n)}),Ie&&(0,d.jsx)(`div`,{className:`fp-lines-note`,children:_(`previewLinesTruncated`,{n:f})})]}),(S||!J&&!Y&&q===`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:Ve,children:_(`cancel`)}),(0,d.jsxs)(`button`,{type:`button`,className:`btn primary`,disabled:Ne||w===(v?.text??``),onClick:He,children:[(0,d.jsx)(ne,{}),` `,_(`saveFile`)]})]})]}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(`span`,{className:`fp-hint`,children:b?_(`selectedRange`,{n:We,start:b.start,end:b.end}):_(`selectLinesHint`)}),(0,d.jsxs)(`div`,{className:`fp-actions`,children:[(0,d.jsx)(`button`,{type:`button`,className:`btn`,disabled:H.length===0,onClick:Re,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||G,onClick:ze,children:[De?(0,d.jsx)(n,{}):null,_(De?`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};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$ as t,A as n,B as r,Dn as i,Q as a,Tn as ee,U as te,Vt as ne,X as re,bn as ie,bt as ae,et as oe,fn as se,kt as ce,pn as le,t as ue,un as de,wt as fe,xt as pe}from"./app-globals-CZxzGvIo.js";import{i as o,t as me}from"./react-CR5VJ85Q.js";import{G as he,H as ge,ft as _e,st as ve,ut as ye}from"./index-EH5Fw9fa.js";var s=e(o(),1),c=`未命名章节`;function l(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 be(e){let t=new Map;return e.map(({level:e,label:n})=>{let r=String(n??``).replace(/\s+/g,` `).trim(),i=l(r||c),a=(t.get(i)??0)+1;return t.set(i,a),{level:e,id:a===1?i:`${i}-${a}`,label:r||c}})}function u(e){return e.length>=2}var d=me(),f=5e3,xe=`pi-web-ui:preview-toc`;function p({file:e,content:o,onAddLines:me,onAttach:c,onClose:l,uiFilePreviewToolbar:p,onUiAction:Se}){let _=ie(),[v,Ce]=(0,s.useState)(null),[y,we]=(0,s.useState)(!1),[b,x]=(0,s.useState)(null),[Te,Ee]=(0,s.useState)(!1),[De,Oe]=(0,s.useState)(!1),[S,C]=(0,s.useState)(!1),[w,T]=(0,s.useState)(``),[E,D]=(0,s.useState)(!0),[O,k]=(0,s.useState)(!0),[A,ke]=(0,s.useState)(!1),j=(0,s.useRef)(!1),[M,Ae]=(0,s.useState)(!0),[N,je]=(0,s.useState)(!1),[P,Me]=(0,s.useState)(100),F=(0,s.useRef)(0),I=(0,s.useRef)(!1),L=(0,s.useRef)(null),[Ne,R]=(0,s.useState)(!1),[Pe,z]=(0,s.useState)(!1),B=(0,s.useRef)(!1),V=(0,s.useRef)(null);(0,s.useEffect)(()=>()=>{L.current&&clearTimeout(L.current),V.current&&clearTimeout(V.current)},[]),(0,s.useEffect)(()=>{we(!0),Ce(null),x(null),C(!1),T(``),D(!0),k(!0),ke(!1),j.current=!1,B.current=!1,R(!1),z(!1),V.current&&clearTimeout(V.current),ue({type:`read_file`,path:e.path})},[e.path]),(0,s.useEffect)(()=>{o&&o.path===e.path&&(Ce(o),S||T(o.text),we(!1),B.current&&(B.current=!1,V.current&&clearTimeout(V.current),R(!1),z(!1),C(!1),T(o.text),j.current&&(m(e.name)&&D(!0),g(e.name)&&k(!0)),x(null)))},[o,S,e.path]),(0,s.useEffect)(()=>{let e=e=>{if(e.key===`Escape`){W();return}if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`s`&&S){e.preventDefault(),He();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(),Re())};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[l,v,S,w]),(0,s.useEffect)(()=>{let e=()=>{I.current=!1,Ee(!1)};return window.addEventListener(`mouseup`,e),()=>window.removeEventListener(`mouseup`,e)},[]);let H=(0,s.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]),Fe=v?.lines??0,Ie=Fe>f,Le=(e,t)=>{if(t){let t=F.current>0?F.current:e;x({start:Math.min(t,e),end:Math.max(t,e)})}else F.current=e,x({start:e,end:e})},Re=()=>{H.length!==0&&(F.current=1,x({start:1,end:H.length}))},ze=()=>{b&&(me(e.path,e.name,b.start,b.end),Oe(!0),L.current&&clearTimeout(L.current),L.current=setTimeout(()=>Oe(!1),1400))},U=v!==null&&v.kind===`text`&&!v.binary&&!v.truncated&&!h(e.name),Be=()=>{B.current=!1,V.current&&clearTimeout(V.current),R(!1),z(!1),T(v?.text??``),C(!1),j.current&&(m(e.name)&&D(!0),g(e.name)&&k(!0))},Ve=()=>{if(S){if(w!==(v?.text??``)&&!window.confirm(_(`discardFileChanges`)))return;Be();return}U&&v&&(j.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))},He=()=>{S&&v&&U&&ue({type:`write_file`,path:e.path,text:w})&&(B.current=!0,z(!1),R(!0),V.current&&clearTimeout(V.current),V.current=setTimeout(()=>{B.current=!1,R(!1),z(!0)},5e3))},W=()=>{(!S||w===(v?.text??``)||window.confirm(_(`discardFileChanges`)))&&l()},Ue=e=>{Me(Math.min(200,Math.max(50,e)))},We=b?b.end-b.start+1:0,G=v?.binary??!1,K=v?.truncated??!1,q=v?.kind??`text`,Ge=m(e.name)||h(e.name),Ke=g(e.name),qe=h(e.name),J=Ge&&E&&!S&&q===`text`&&!G,Y=Ke&&O&&!S&&q===`text`&&!G,[X,Je]=(0,s.useState)(()=>{try{return localStorage.getItem(xe)===`1`}catch{return!1}});(0,s.useEffect)(()=>{try{localStorage.setItem(xe,X?`1`:`0`)}catch{}},[X]);let[Z,Ye]=(0,s.useState)([]),[Xe,Ze]=(0,s.useState)(``),Q=(0,s.useRef)(null);(0,s.useEffect)(()=>{let e=Q.current;if(!e||!J){Ye([]);return}let t=[...e.querySelectorAll(`h1, h2, h3, h4, h5, h6`)],n=be(t.map(e=>({level:Number(e.tagName.slice(1)),label:e.textContent??``})));t.forEach((e,t)=>{e.id||=n[t].id}),Ye(n)},[J,v?.text,e.path]),(0,s.useEffect)(()=>{let e=Q.current;if(!e||!X||!u(Z))return;let t=Z.map(t=>e.querySelector(`#${CSS.escape(t.id)}`)).filter(e=>e!==null);if(t.length===0)return;let n=new IntersectionObserver(e=>{let t=e.filter(e=>e.isIntersecting).sort((e,t)=>e.boundingClientRect.top-t.boundingClientRect.top)[0];t?.target.id&&Ze(t.target.id)},{rootMargin:`0px 0px -70% 0px`});for(let e of t)n.observe(e);return()=>n.disconnect()},[Z,X]);let Qe={"host:fp-md":Ge&&q===`text`&&!G&&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)(oe,{}):(0,d.jsx)(r,{})}):null,"host:fp-toc":J&&u(Z)?(0,d.jsx)(`button`,{type:`button`,className:`fp-attach toc ${X?`on`:``}`,"data-tip":_(X?`previewTocHide`:`previewTocShow`),onClick:()=>Je(e=>!e),children:(0,d.jsx)(pe,{})}):null,"host:fp-html":Ke&&q===`text`&&!G&&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)(oe,{})}):null,"host:fp-edit":q===`text`&&!G&&v?(0,d.jsx)(`button`,{type:`button`,className:`fp-attach edit ${S?`on`:``}`,"data-tip":_(K?`fileEditTruncated`:S?`exitEditFile`:`editFile`),disabled:!U&&!S,onClick:Ve,children:(0,d.jsx)(a,{})}):null,"host:fp-wrap":q===`text`&&!G&&!J&&!Y?(0,d.jsx)(`button`,{type:`button`,className:`fp-attach wrap ${M?`on`:``}`,"data-tip":_(M?`disableWrap`:`enableWrap`),onClick:()=>Ae(e=>!e),children:(0,d.jsx)(te,{})}):null,"host:fp-zoom":q===`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:P<=50,onClick:()=>Ue(P-10),children:(0,d.jsx)(le,{})}),(0,d.jsxs)(`button`,{type:`button`,className:`fp-zoom-val`,title:_(`resetZoom`),onClick:()=>Me(100),children:[P,`%`]}),(0,d.jsx)(`button`,{type:`button`,className:`fp-attach zoom-in`,"data-tip":_(`zoomIn`),disabled:P>=200,onClick:()=>Ue(P+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 ye(e.path,e.name),children:(0,d.jsx)(re,{})}),"host:fp-ref":(0,d.jsx)(`button`,{type:`button`,className:`fp-attach ref`,"data-tip":_(`referenceTip`),onClick:()=>c(e.path,e.name,`reference`),children:(0,d.jsx)(ae,{})}),"host:fp-full":(0,d.jsx)(`button`,{type:`button`,className:`fp-attach full ${N?`on`:``}`,"data-tip":_(N?`exitFullscreen`:`fullscreen`),onClick:()=>je(e=>!e),children:N?(0,d.jsx)(ce,{}):(0,d.jsx)(fe,{})}),"host:fp-close":null},$e=p===void 0?[`host:fp-md`,`host:fp-toc`,`host:fp-html`,`host:fp-edit`,`host:fp-wrap`,`host:fp-zoom`,`host:fp-download`,`host:fp-ref`,`host:fp-full`].map(e=>({id:e,source:`host`})):p.filter(e=>!e.hidden&&e.id!==`host:fp-close`),$=e=>ee(i(`/api/file?clientId=${encodeURIComponent(he())}&path=${encodeURIComponent(e)}`)),et=e=>{let t=e.split(`/`).map(e=>encodeURIComponent(e)).join(`/`),n=/^[A-Za-z]:([\\/]|$)/.test(e)||e.startsWith(`/`)?`/api/preview/__abs__/${t}`:`/api/preview/${t}`;return ee(i(`${n}?clientId=${encodeURIComponent(he())}${A?`&allowJs=1`:``}`))};return(0,d.jsx)(`div`,{className:`fp-overlay ${N?`fullscreen`:``}`,onMouseDown:e=>{e.target===e.currentTarget&&W()},children:(0,d.jsxs)(`div`,{className:`fp ${N?`fullscreen`:``} ${qe?`is-ppt`:``}`,style:{"--fp-zoom":P/100},children:[(0,d.jsxs)(`div`,{className:`fp-head`,onDoubleClick:e=>{let t=e.target;t&&!t.closest(`button, a, input`)&&je(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&&q===`text`&&!G&&_(`fileLines`,{n:Fe}),v&&` · ${ve(v.size)}`]}),(0,d.jsx)(`span`,{className:`fp-head-actions`,children:ge($e,Qe,Se)}),(0,d.jsx)(`button`,{type:`button`,className:`fp-close`,title:_(`close`),"aria-label":_(`close`),onClick:W,children:(0,d.jsx)(de,{})})]}),K&&q===`text`&&!G&&(0,d.jsx)(`div`,{className:`fp-notice`,children:h(e.name)?_(`previewLinesTruncated`,{n:H.length}):_(`previewTruncated`)}),y&&!v&&(0,d.jsx)(`div`,{className:`fp-empty`,children:_(`loading`)}),!y&&q===`none`&&!G&&(0,d.jsx)(`div`,{className:`fp-empty`,children:_(`previewNotSupported`)}),!y&&q===`image`&&(0,d.jsx)(`div`,{className:`fp-media-wrap clickable`,onClick:W,title:_(`clickToCloseImage`),children:(0,d.jsx)(`img`,{className:`fp-media fp-media-clickable`,src:$(e.path),alt:e.name,onClick:W,title:_(`clickToCloseImage`)})}),!y&&q===`video`&&(0,d.jsx)(`div`,{className:`fp-media-wrap`,children:(0,d.jsx)(`video`,{className:`fp-media`,src:$(e.path),controls:!0,preload:`metadata`})}),!y&&q===`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:ve(v.size)}):null]}),(0,d.jsx)(`audio`,{className:`fp-audio-element`,src:$(e.path),controls:!0,autoPlay:!0,preload:`metadata`})]})}),!y&&Y&&v&&(0,d.jsxs)(`div`,{className:`fp-html`,children:[(0,d.jsxs)(`div`,{className:`fp-html-bar`,children:[(0,d.jsx)(`span`,{className:`fp-html-hint`,title:_(A?`htmlJsOnTip`:`htmlJsOffTip`),children:_(A?`htmlJsOn`:`htmlJsOff`)}),(0,d.jsx)(`button`,{type:`button`,className:`fp-html-js ${A?`on`:``}`,"data-tip":_(A?`htmlDisableJs`:`htmlEnableJs`),onClick:()=>ke(e=>!e),children:_(A?`htmlDisableJs`:`htmlEnableJs`)}),(0,d.jsxs)(`a`,{className:`fp-html-btn fp-html-external`,href:et(e.path),target:`_blank`,rel:`noopener noreferrer`,title:_(`openInNewTab`),children:[(0,d.jsx)(t,{}),(0,d.jsx)(`span`,{children:_(`openInNewTab`)})]})]}),(0,d.jsx)(`iframe`,{className:`fp-html-frame`,src:et(e.path),title:e.name,sandbox:A?`allow-scripts`:``,referrerPolicy:`no-referrer`},A?`js`:`nojs`)]}),!y&&J&&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:X&&u(Z)?`fp-toc-layout`:void 0,children:[X&&u(Z)&&(0,d.jsx)(`nav`,{className:`fp-toc`,"aria-label":_(`previewTocLabel`),children:Z.map(e=>(0,d.jsx)(`a`,{className:`l${Math.min(e.level,6)}${e.id===Xe?` on`:``}`,href:`#${e.id}`,title:e.label,onClick:t=>{t.preventDefault(),Q.current?.querySelector(`#${CSS.escape(e.id)}`)?.scrollIntoView({behavior:`smooth`,block:`start`})},children:e.label},e.id))}),(0,d.jsx)(`div`,{className:`fp-markdown-zoom`,ref:Q,children:(0,d.jsx)(_e,{text:v.text})})]})}),!y&&G&&q!==`image`&&q!==`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&&q===`text`&&!G&&v&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(`textarea`,{className:`fp-editor ${M?``:`no-wrap`}`,value:w,onChange:e=>T(e.target.value),wrap:M?`soft`:`off`,spellCheck:!1,autoFocus:!0}),Pe&&(0,d.jsx)(`div`,{className:`fp-notice`,role:`alert`,children:_(`saveResultUnknown`)})]}),!y&&!J&&!Y&&!S&&q===`text`&&!G&&v&&H.length===0&&(0,d.jsx)(`div`,{className:`fp-empty`,children:_(`emptyFile`)}),!y&&!J&&!Y&&!S&&q===`text`&&!G&&H.length>0&&(0,d.jsxs)(`div`,{className:`fp-code ${Te?`dragging`:``} ${M?``:`no-wrap`}`,onMouseDown:e=>{e.button===0&&e.preventDefault()},children:[H.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&&(Le(n,e.shiftKey),I.current=!0,Ee(!0))},onMouseEnter:()=>{I.current&&Le(n,!0)},children:[(0,d.jsx)(`span`,{className:`fp-num`,children:n}),(0,d.jsx)(`span`,{className:`fp-code-text`,children:e})]},n)}),Ie&&(0,d.jsx)(`div`,{className:`fp-lines-note`,children:_(`previewLinesTruncated`,{n:f})})]}),(S||!J&&!Y&&q===`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:Ve,children:_(`cancel`)}),(0,d.jsxs)(`button`,{type:`button`,className:`btn primary`,disabled:Ne||w===(v?.text??``),onClick:He,children:[(0,d.jsx)(ne,{}),` `,_(`saveFile`)]})]})]}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(`span`,{className:`fp-hint`,children:b?_(`selectedRange`,{n:We,start:b.start,end:b.end}):_(`selectLinesHint`)}),(0,d.jsxs)(`div`,{className:`fp-actions`,children:[(0,d.jsx)(`button`,{type:`button`,className:`btn`,disabled:H.length===0,onClick:Re,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||G,onClick:ze,children:[De?(0,d.jsx)(n,{}):null,_(De?`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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Dt as t,Pt as n,Ut as r,at as i,bn as a,i as o,o as s,ot as c,t as l,un as u}from"./app-globals-CZxzGvIo.js";import{i as d,t as f}from"./react-CR5VJ85Q.js";import{b as p,d as m,h,s as g}from"./plugin-host-BRWib9DF.js";import{P as _}from"./index-CuN802Sj.js";var v=e(d(),1),y=f();function b(e,t){return e.toLowerCase().includes(t)}function x({open:e,projects:d,fileSearch:f,sessionSearch:x,onClose:S,onSwitchSession:C,onSwitchProject:w,onPreviewFile:T}){let E=a(),D=s(),O=E(`pluginMenuTitle`),k=o(`cwd`),A=(0,v.useRef)(null),[j,M]=(0,v.useState)(``),N=(0,v.useDeferredValue)(j),[P,F]=(0,v.useState)(0),I=(0,v.useRef)(0),L=(0,v.useRef)(null),[R,z]=(0,v.useState)(null);(0,v.useEffect)(()=>{if(!e)return;l({type:`list_sessions`}),l({type:`list_projects`});let t=j.trim();if(t){let e=_();I.current=e,V(!0),l({type:`search_files`,reqId:e,query:t}),l({type:`search_sessions`,reqId:e,query:t})}requestAnimationFrame(()=>A.current?.select())},[e]);let[B,V]=(0,v.useState)(!1);(0,v.useEffect)(()=>{L.current&&clearTimeout(L.current);let e=N.trim();if(!e){V(!1),z(null);return}return L.current=setTimeout(()=>{let t=_();I.current=t,V(!0),l({type:`search_files`,reqId:t,query:e}),l({type:`search_sessions`,reqId:t,query:e})},300),()=>{L.current&&clearTimeout(L.current)}},[N]),(0,v.useEffect)(()=>{f&&f.reqId===I.current&&z(f)},[f]);let H=N.trim().toLowerCase(),U=(0,v.useMemo)(()=>!H||!x||x.reqId!==I.current||!x.ok?[]:x.results,[x,H]),W=(0,v.useMemo)(()=>H?d.filter(e=>b(e.path,H)).slice(0,10):[],[d,H]),G=(0,v.useMemo)(()=>!H||!R||!R.ok?[]:R.results,[R,H]);(0,v.useEffect)(()=>{R&&R.reqId===I.current&&x&&x.reqId===I.current&&I.current!==0&&V(!1)},[R,x]);let K=!!R&&R.ok&&R.truncated,[q,J]=(0,v.useState)([]);(0,v.useEffect)(()=>{if(!e)return;let t=N.trim();if(!t){J([]);return}let n=!1,r=[];try{let e=window,t=e.__piWebUiHost?.searchProviders?.list;if(typeof t==`function`){let n=t.call(e.__piWebUiHost);Array.isArray(n)&&(r=n)}else typeof m==`function`&&(r=m())}catch{r=[]}let i=r.filter(e=>e&&typeof e.id==`string`).map(e=>{if(typeof e.search==`function`)return e;try{let t=g(e.id);return t&&typeof t.search==`function`?{...e,search:t.search}:null}catch{return null}}).filter(e=>!!e);if(i.length===0){J([]);return}return Promise.allSettled(i.map(e=>Promise.race([e.search(t),new Promise((e,t)=>setTimeout(()=>t(Error(`timeout`)),3e3))]).then(t=>({provider:e,items:Array.isArray(t)?t:[]}),()=>({provider:e,items:[]})))).then(e=>{if(n)return;let t=[];for(let n of e)if(n.status===`fulfilled`)for(let e of n.value.items){if(!e||typeof e!=`object`)continue;let r=e;typeof r.title==`string`&&typeof r.action==`string`&&t.push({providerId:n.value.provider.id,providerLabel:n.value.provider.label,title:r.title,...typeof r.hint==`string`?{hint:r.hint}:{},action:r.action})}J(t.slice(0,20))}),()=>{n=!0}},[e,N]);let Y=(0,v.useMemo)(()=>[...U.map(e=>({kind:`session`,path:e.path,anchors:e.anchors})),...W.map(e=>({kind:`project`,path:e.path})),...G.filter(e=>e.type===`file`).map(e=>({kind:`file`,path:e.path,name:e.name})),...q.map(e=>({kind:`plugin`,providerId:e.providerId,providerLabel:e.providerLabel,title:e.title,action:e.action}))],[U,W,G,q]);(0,v.useEffect)(()=>{F(0)},[N]);let X=(0,v.useCallback)(e=>{if(e){if(e.kind===`session`)C(e.path,e.anchors),S();else if(e.kind===`project`){w(e.path),l({type:`list_sessions`}),l({type:`list_projects`});let t=N.trim();if(t){let e=_();I.current=e,V(!0),l({type:`search_files`,reqId:e,query:t}),l({type:`search_sessions`,reqId:e,query:t})}}else e.kind===`plugin`?h(e.providerId,e.action,e.action).catch(()=>{}):T(e.path,e.name)}},[C,w,T,N]);(0,v.useEffect)(()=>{if(!e)return;let t=e=>{e.key===`Escape`?(e.preventDefault(),e.stopPropagation(),S()):e.key===`ArrowDown`?(e.preventDefault(),F(e=>Math.max(0,Math.min(e+1,Y.length-1)))):e.key===`ArrowUp`?(e.preventDefault(),F(e=>Math.max(e-1,0))):e.key===`Enter`&&(e.preventDefault(),X(Y[P]))};return window.addEventListener(`keydown`,t,!0),()=>window.removeEventListener(`keydown`,t,!0)},[Y,P,X,S,e]);let Z=U.length+W.length+G.length+q.length,Q=(e,t,n)=>(0,y.jsxs)(`div`,{className:`gs-section-head`,children:[n,(0,y.jsx)(`span`,{children:e}),(0,y.jsx)(`em`,{children:t})]}),$=-1;return e?(0,y.jsx)(`div`,{className:`modal-backdrop gs-backdrop`,onClick:S,children:(0,y.jsxs)(`div`,{className:`gs-modal`,onClick:e=>e.stopPropagation(),children:[(0,y.jsxs)(`div`,{className:`gs-input-row`,children:[(0,y.jsx)(r,{}),(0,y.jsx)(`input`,{ref:A,type:`text`,value:j,placeholder:E(`gsPlaceholder`),onChange:e=>M(e.target.value)}),(0,y.jsx)(`button`,{type:`button`,className:`gs-close`,title:E(`close`),onClick:S,children:(0,y.jsx)(u,{})})]}),(0,y.jsxs)(`div`,{className:`gs-results`,children:[!H&&(0,y.jsx)(`div`,{className:`gs-empty`,children:E(`gsHint`)}),H&&Z===0&&!K&&(0,y.jsx)(`div`,{className:`gs-empty`,children:E(B?`gsSearching`:`gsNoResults`)}),U.length>0&&(0,y.jsxs)(`div`,{className:`gs-section`,children:[Q(E(`gsSessions`),U.length,(0,y.jsx)(t,{})),U.map(e=>{$++;let t=$,n=e.displayName||e.name||e.firstMessage?.trim()||(e.path.split(/[\\/]/).pop()||e.path).replace(/\.jsonl$/i,``);return(0,y.jsxs)(`div`,{className:`gs-item-wrap`,children:[(0,y.jsxs)(`button`,{type:`button`,className:t===P?`gs-item active`:`gs-item`,onMouseEnter:()=>F(t),onClick:()=>X({kind:`session`,path:e.path,anchors:e.anchors}),children:[(0,y.jsxs)(`span`,{className:`gs-item-title`,children:[n,(0,y.jsx)(`em`,{className:`gs-item-meta`,children:e.messageCount})]}),(0,y.jsx)(`span`,{className:`gs-item-sub`,children:e.firstMessage})]}),D.conversationRef&&(0,y.jsxs)(`button`,{type:`button`,className:`gs-quote`,title:E(`quoteConversation`),onClick:t=>{t.stopPropagation(),p({attachments:[{path:``,key:`conv||${e.path}`,name:n,mode:`conversation`,sessionPath:e.path}]})},children:[`💬 `,E(`quoteConversationShort`)]})]},e.path)})]}),W.length>0&&(0,y.jsxs)(`div`,{className:`gs-section`,children:[Q(E(`gsProjects`),W.length,(0,y.jsx)(c,{})),W.map(e=>{$++;let t=$,n=k&&e.path===k;return(0,y.jsxs)(`button`,{type:`button`,className:t===P?`gs-item active`:`gs-item`,onMouseEnter:()=>F(t),onClick:()=>X({kind:`project`,path:e.path}),children:[(0,y.jsxs)(`span`,{className:`gs-item-title`,children:[e.path.split(/[\\/]/).pop(),n&&(0,y.jsx)(`em`,{className:`gs-item-meta`,children:E(`gsCurrentProject`)})]}),(0,y.jsx)(`span`,{className:`gs-item-sub`,children:e.path})]},e.path)})]}),(G.length>0||H&&K)&&(0,y.jsxs)(`div`,{className:`gs-section`,children:[Q(E(`gsFiles`),G.length,(0,y.jsx)(i,{})),G.map(e=>{$++;let t=$;return(0,y.jsxs)(`button`,{type:`button`,className:t===P?`gs-item active`:`gs-item`,disabled:e.type===`dir`,title:e.type===`dir`?void 0:E(`gsOpenPreview`),onMouseEnter:()=>F(t),onClick:()=>{e.type===`file`&&X({kind:`file`,path:e.path,name:e.name})},children:[(0,y.jsx)(`span`,{className:`gs-item-title`,children:e.name}),(0,y.jsx)(`span`,{className:`gs-item-sub`,children:e.path})]},`${e.type}:${e.path}`)}),K&&(0,y.jsx)(`div`,{className:`gs-truncated`,children:E(`gsTruncated`)})]}),q.length>0&&(0,y.jsxs)(`div`,{className:`gs-section`,children:[Q(O,q.length,(0,y.jsx)(n,{})),q.map((e,t)=>{$++;let n=$;return(0,y.jsxs)(`button`,{type:`button`,className:n===P?`gs-item active`:`gs-item`,title:e.providerLabel,onMouseEnter:()=>F(n),onClick:()=>X({kind:`plugin`,providerId:e.providerId,providerLabel:e.providerLabel,title:e.title,action:e.action}),children:[(0,y.jsx)(`span`,{className:`gs-item-title`,children:e.title}),(0,y.jsx)(`span`,{className:`gs-item-sub`,children:e.hint??e.providerLabel})]},`${e.providerId}:${e.action}:${t}`)})]})]}),(0,y.jsxs)(`div`,{className:`gs-foot`,children:[(0,y.jsxs)(`span`,{children:[`↑↓ `,E(`gsNavigate`)]}),(0,y.jsxs)(`span`,{children:[`Enter `,E(`gsOpen`)]}),(0,y.jsxs)(`span`,{children:[`Esc `,E(`gsCloseHint`)]})]})]})}):null}export{x as GlobalSearchModal};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Dt as t,Pt as n,Ut as r,at as i,bn as a,i as o,o as s,ot as c,t as l,un as u}from"./app-globals-CZxzGvIo.js";import{i as d,t as f}from"./react-CR5VJ85Q.js";import{b as p,d as m,h,s as g}from"./plugin-host-BRWib9DF.js";import{P as _}from"./index-EH5Fw9fa.js";var v=e(d(),1),y=f();function b(e,t){return e.toLowerCase().includes(t)}function x({open:e,projects:d,fileSearch:f,sessionSearch:x,onClose:S,onSwitchSession:C,onSwitchProject:w,onPreviewFile:T}){let E=a(),D=s(),O=E(`pluginMenuTitle`),k=o(`cwd`),A=(0,v.useRef)(null),[j,M]=(0,v.useState)(``),N=(0,v.useDeferredValue)(j),[P,F]=(0,v.useState)(0),I=(0,v.useRef)(0),L=(0,v.useRef)(null),[R,z]=(0,v.useState)(null);(0,v.useEffect)(()=>{if(!e)return;l({type:`list_sessions`}),l({type:`list_projects`});let t=j.trim();if(t){let e=_();I.current=e,V(!0),l({type:`search_files`,reqId:e,query:t}),l({type:`search_sessions`,reqId:e,query:t})}requestAnimationFrame(()=>A.current?.select())},[e]);let[B,V]=(0,v.useState)(!1);(0,v.useEffect)(()=>{L.current&&clearTimeout(L.current);let e=N.trim();if(!e){V(!1),z(null);return}return L.current=setTimeout(()=>{let t=_();I.current=t,V(!0),l({type:`search_files`,reqId:t,query:e}),l({type:`search_sessions`,reqId:t,query:e})},300),()=>{L.current&&clearTimeout(L.current)}},[N]),(0,v.useEffect)(()=>{f&&f.reqId===I.current&&z(f)},[f]);let H=N.trim().toLowerCase(),U=(0,v.useMemo)(()=>!H||!x||x.reqId!==I.current||!x.ok?[]:x.results,[x,H]),W=(0,v.useMemo)(()=>H?d.filter(e=>b(e.path,H)).slice(0,10):[],[d,H]),G=(0,v.useMemo)(()=>!H||!R||!R.ok?[]:R.results,[R,H]);(0,v.useEffect)(()=>{R&&R.reqId===I.current&&x&&x.reqId===I.current&&I.current!==0&&V(!1)},[R,x]);let K=!!R&&R.ok&&R.truncated,[q,J]=(0,v.useState)([]);(0,v.useEffect)(()=>{if(!e)return;let t=N.trim();if(!t){J([]);return}let n=!1,r=[];try{let e=window,t=e.__piWebUiHost?.searchProviders?.list;if(typeof t==`function`){let n=t.call(e.__piWebUiHost);Array.isArray(n)&&(r=n)}else typeof m==`function`&&(r=m())}catch{r=[]}let i=r.filter(e=>e&&typeof e.id==`string`).map(e=>{if(typeof e.search==`function`)return e;try{let t=g(e.id);return t&&typeof t.search==`function`?{...e,search:t.search}:null}catch{return null}}).filter(e=>!!e);if(i.length===0){J([]);return}return Promise.allSettled(i.map(e=>Promise.race([e.search(t),new Promise((e,t)=>setTimeout(()=>t(Error(`timeout`)),3e3))]).then(t=>({provider:e,items:Array.isArray(t)?t:[]}),()=>({provider:e,items:[]})))).then(e=>{if(n)return;let t=[];for(let n of e)if(n.status===`fulfilled`)for(let e of n.value.items){if(!e||typeof e!=`object`)continue;let r=e;typeof r.title==`string`&&typeof r.action==`string`&&t.push({providerId:n.value.provider.id,providerLabel:n.value.provider.label,title:r.title,...typeof r.hint==`string`?{hint:r.hint}:{},action:r.action})}J(t.slice(0,20))}),()=>{n=!0}},[e,N]);let Y=(0,v.useMemo)(()=>[...U.map(e=>({kind:`session`,path:e.path,anchors:e.anchors})),...W.map(e=>({kind:`project`,path:e.path})),...G.filter(e=>e.type===`file`).map(e=>({kind:`file`,path:e.path,name:e.name})),...q.map(e=>({kind:`plugin`,providerId:e.providerId,providerLabel:e.providerLabel,title:e.title,action:e.action}))],[U,W,G,q]);(0,v.useEffect)(()=>{F(0)},[N]);let X=(0,v.useCallback)(e=>{if(e){if(e.kind===`session`)C(e.path,e.anchors),S();else if(e.kind===`project`){w(e.path),l({type:`list_sessions`}),l({type:`list_projects`});let t=N.trim();if(t){let e=_();I.current=e,V(!0),l({type:`search_files`,reqId:e,query:t}),l({type:`search_sessions`,reqId:e,query:t})}}else e.kind===`plugin`?h(e.providerId,e.action,e.action).catch(()=>{}):T(e.path,e.name)}},[C,w,T,N]);(0,v.useEffect)(()=>{if(!e)return;let t=e=>{e.key===`Escape`?(e.preventDefault(),e.stopPropagation(),S()):e.key===`ArrowDown`?(e.preventDefault(),F(e=>Math.max(0,Math.min(e+1,Y.length-1)))):e.key===`ArrowUp`?(e.preventDefault(),F(e=>Math.max(e-1,0))):e.key===`Enter`&&(e.preventDefault(),X(Y[P]))};return window.addEventListener(`keydown`,t,!0),()=>window.removeEventListener(`keydown`,t,!0)},[Y,P,X,S,e]);let Z=U.length+W.length+G.length+q.length,Q=(e,t,n)=>(0,y.jsxs)(`div`,{className:`gs-section-head`,children:[n,(0,y.jsx)(`span`,{children:e}),(0,y.jsx)(`em`,{children:t})]}),$=-1;return e?(0,y.jsx)(`div`,{className:`modal-backdrop gs-backdrop`,onClick:S,children:(0,y.jsxs)(`div`,{className:`gs-modal`,onClick:e=>e.stopPropagation(),children:[(0,y.jsxs)(`div`,{className:`gs-input-row`,children:[(0,y.jsx)(r,{}),(0,y.jsx)(`input`,{ref:A,type:`text`,value:j,placeholder:E(`gsPlaceholder`),onChange:e=>M(e.target.value)}),(0,y.jsx)(`button`,{type:`button`,className:`gs-close`,title:E(`close`),onClick:S,children:(0,y.jsx)(u,{})})]}),(0,y.jsxs)(`div`,{className:`gs-results`,children:[!H&&(0,y.jsx)(`div`,{className:`gs-empty`,children:E(`gsHint`)}),H&&Z===0&&!K&&(0,y.jsx)(`div`,{className:`gs-empty`,children:E(B?`gsSearching`:`gsNoResults`)}),U.length>0&&(0,y.jsxs)(`div`,{className:`gs-section`,children:[Q(E(`gsSessions`),U.length,(0,y.jsx)(t,{})),U.map(e=>{$++;let t=$,n=e.displayName||e.name||e.firstMessage?.trim()||(e.path.split(/[\\/]/).pop()||e.path).replace(/\.jsonl$/i,``);return(0,y.jsxs)(`div`,{className:`gs-item-wrap`,children:[(0,y.jsxs)(`button`,{type:`button`,className:t===P?`gs-item active`:`gs-item`,onMouseEnter:()=>F(t),onClick:()=>X({kind:`session`,path:e.path,anchors:e.anchors}),children:[(0,y.jsxs)(`span`,{className:`gs-item-title`,children:[n,(0,y.jsx)(`em`,{className:`gs-item-meta`,children:e.messageCount})]}),(0,y.jsx)(`span`,{className:`gs-item-sub`,children:e.firstMessage})]}),D.conversationRef&&(0,y.jsxs)(`button`,{type:`button`,className:`gs-quote`,title:E(`quoteConversation`),onClick:t=>{t.stopPropagation(),p({attachments:[{path:``,key:`conv||${e.path}`,name:n,mode:`conversation`,sessionPath:e.path}]})},children:[`💬 `,E(`quoteConversationShort`)]})]},e.path)})]}),W.length>0&&(0,y.jsxs)(`div`,{className:`gs-section`,children:[Q(E(`gsProjects`),W.length,(0,y.jsx)(c,{})),W.map(e=>{$++;let t=$,n=k&&e.path===k;return(0,y.jsxs)(`button`,{type:`button`,className:t===P?`gs-item active`:`gs-item`,onMouseEnter:()=>F(t),onClick:()=>X({kind:`project`,path:e.path}),children:[(0,y.jsxs)(`span`,{className:`gs-item-title`,children:[e.path.split(/[\\/]/).pop(),n&&(0,y.jsx)(`em`,{className:`gs-item-meta`,children:E(`gsCurrentProject`)})]}),(0,y.jsx)(`span`,{className:`gs-item-sub`,children:e.path})]},e.path)})]}),(G.length>0||H&&K)&&(0,y.jsxs)(`div`,{className:`gs-section`,children:[Q(E(`gsFiles`),G.length,(0,y.jsx)(i,{})),G.map(e=>{$++;let t=$;return(0,y.jsxs)(`button`,{type:`button`,className:t===P?`gs-item active`:`gs-item`,disabled:e.type===`dir`,title:e.type===`dir`?void 0:E(`gsOpenPreview`),onMouseEnter:()=>F(t),onClick:()=>{e.type===`file`&&X({kind:`file`,path:e.path,name:e.name})},children:[(0,y.jsx)(`span`,{className:`gs-item-title`,children:e.name}),(0,y.jsx)(`span`,{className:`gs-item-sub`,children:e.path})]},`${e.type}:${e.path}`)}),K&&(0,y.jsx)(`div`,{className:`gs-truncated`,children:E(`gsTruncated`)})]}),q.length>0&&(0,y.jsxs)(`div`,{className:`gs-section`,children:[Q(O,q.length,(0,y.jsx)(n,{})),q.map((e,t)=>{$++;let n=$;return(0,y.jsxs)(`button`,{type:`button`,className:n===P?`gs-item active`:`gs-item`,title:e.providerLabel,onMouseEnter:()=>F(n),onClick:()=>X({kind:`plugin`,providerId:e.providerId,providerLabel:e.providerLabel,title:e.title,action:e.action}),children:[(0,y.jsx)(`span`,{className:`gs-item-title`,children:e.title}),(0,y.jsx)(`span`,{className:`gs-item-sub`,children:e.hint??e.providerLabel})]},`${e.providerId}:${e.action}:${t}`)})]})]}),(0,y.jsxs)(`div`,{className:`gs-foot`,children:[(0,y.jsxs)(`span`,{children:[`↑↓ `,E(`gsNavigate`)]}),(0,y.jsxs)(`span`,{children:[`Enter `,E(`gsOpen`)]}),(0,y.jsxs)(`span`,{children:[`Esc `,E(`gsCloseHint`)]})]})]})}):null}export{x as GlobalSearchModal};
|