pi-web-ui 0.118.0 → 0.120.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +143 -1
- package/bin/hub-upgrade.mjs +33 -15
- package/bin/lib/atomic-file.mjs +90 -0
- package/dist/server/agent-service-daemon.js +44 -10
- package/dist/server/agent-service.js +930 -166
- package/dist/server/approval-default-rules.js +4 -4
- package/dist/server/ask-user-question-tool.js +3 -40
- package/dist/server/atomic-file.js +130 -5
- package/dist/server/background-executors.js +235 -0
- package/dist/server/bash-timeout.js +47 -0
- package/dist/server/bash-tool.js +72 -5
- package/dist/server/bg-servers.js +19 -13
- package/dist/server/browser-page-tool.js +38 -29
- package/dist/server/browser-script-tool.js +119 -0
- package/dist/server/canvas/canvas-agent-tool.js +46 -35
- package/dist/server/canvas/canvas-dispatch.js +12 -1
- package/dist/server/claim-files-tool.js +6 -7
- package/dist/server/client-state.js +457 -41
- package/dist/server/communicate-tool.js +59 -77
- package/dist/server/compact-context-tool.js +4 -13
- package/dist/server/conversation-communication.js +23 -1
- package/dist/server/conversation-read-tool.js +14 -23
- package/dist/server/conversation-rows.js +17 -0
- package/dist/server/conversation-tool-names.js +2 -2
- package/dist/server/conversation-tool.js +23 -15
- package/dist/server/conversation-touches.js +1 -1
- package/dist/server/delegate-mode.js +0 -1
- package/dist/server/delegate-task.js +18 -39
- package/dist/server/device-center/approval-summary.js +0 -1
- package/dist/server/device-center/bot-execution.js +0 -1
- package/dist/server/device-center/group-router-runtime.js +2 -0
- package/dist/server/device-center/hub-upgrade.js +5 -10
- package/dist/server/device-center/task-progress.js +2 -2
- package/dist/server/dispatch-domain-handlers.js +97 -24
- package/dist/server/dispatch-plugin-handlers.js +10 -0
- package/dist/server/dsh/dsh-agent-service.js +21 -19
- package/dist/server/durable/durable-agent-service.js +1 -1
- package/dist/server/edit-tool.js +293 -0
- package/dist/server/engine-catalog.js +8 -2
- package/dist/server/engine-cli.js +29 -7
- package/dist/server/engine-probe.js +11 -6
- package/dist/server/eval-tool.js +5 -19
- package/dist/server/files-service.js +41 -19
- package/dist/server/fs-copy.js +93 -0
- package/dist/server/goal-review-gate.js +2 -3
- package/dist/server/index.js +92 -3
- package/dist/server/job-runner.js +345 -0
- package/dist/server/lsp-tool.js +10 -28
- package/dist/server/marker-service.js +42 -30
- package/dist/server/mcp-agent-tool.js +22 -47
- package/dist/server/model-session.js +16 -0
- package/dist/server/native-cli-session-hooks.js +3 -2
- package/dist/server/native-cli-session.js +27 -2
- package/dist/server/patch-tool.js +2 -8
- package/dist/server/phone-tool.js +167 -0
- package/dist/server/plan-mode.js +7 -4
- package/dist/server/plan-update-tool.js +5 -8
- package/dist/server/plugin-api-catalog.js +13 -1
- package/dist/server/plugin-bundled.js +35 -28
- package/dist/server/plugin-catalog.js +6 -0
- package/dist/server/plugin-delivery.js +358 -0
- package/dist/server/plugin-inbox.js +152 -0
- package/dist/server/plugin-installer.js +15 -0
- package/dist/server/plugin-ledger.js +183 -0
- package/dist/server/plugin-manifest-validate.js +19 -0
- package/dist/server/plugin-materialize.js +161 -0
- package/dist/server/plugin-paths.js +60 -0
- package/dist/server/plugin-removal.js +16 -3
- package/dist/server/plugin-schedule.js +8 -7
- package/dist/server/plugin-secrets.js +7 -3
- package/dist/server/plugin-updater.js +2 -4
- package/dist/server/plugins.js +205 -48
- package/dist/server/present-files-tool.js +7 -13
- package/dist/server/preset-fields.js +23 -12
- package/dist/server/preset-share.js +1 -1
- package/dist/server/process-utils.js +11 -0
- package/dist/server/project-scripts.js +38 -0
- package/dist/server/prompt-composer.js +40 -21
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/question-params.js +98 -0
- package/dist/server/quick-ask-settings.js +0 -1
- package/dist/server/quick-ask.js +3 -0
- package/dist/server/read-tool.js +10 -17
- package/dist/server/remote-ssh-service.js +40 -1
- package/dist/server/sandbox-runtime-gate.js +1 -1
- package/dist/server/sandbox-service.js +0 -1
- package/dist/server/sandbox-tool.js +25 -34
- package/dist/server/schedule-agent-tool.js +9 -19
- package/dist/server/scm-commitmsg.js +2 -1
- package/dist/server/serialize.js +8 -0
- package/dist/server/session-list-index.js +246 -0
- package/dist/server/session-list-scan.js +5 -0
- package/dist/server/session-parser.js +16 -0
- package/dist/server/settings-service.js +49 -19
- package/dist/server/skill-tool.js +4 -6
- package/dist/server/subagent-budget.js +68 -0
- package/dist/server/subagent-evidence.js +297 -0
- package/dist/server/subagent-helpers.js +12 -0
- package/dist/server/subagent-ledger.js +401 -0
- package/dist/server/subagent-notify.js +6 -2
- package/dist/server/subagent-security-gate.js +2 -3
- package/dist/server/subagent-settle.js +71 -0
- package/dist/server/subagents.js +566 -211
- package/dist/server/tabs.js +8 -1
- package/dist/server/terminals.js +34 -28
- package/dist/server/tool-approval.js +15 -1
- package/dist/server/tool-guards.js +0 -91
- package/dist/server/tool-manager.js +127 -47
- package/dist/server/tool-overrides.js +8 -1
- package/dist/server/tool-prompt-overrides.js +3 -6
- package/dist/server/tool-prompts.js +60 -17
- package/dist/server/universal/driver-base.js +2 -0
- package/dist/server/universal/drivers/claude-code.js +210 -211
- package/dist/server/universal/drivers/codex.js +29 -24
- package/dist/server/universal/engine-mcp.js +107 -0
- package/dist/server/universal/universal-attachments.js +77 -1
- package/dist/server/universal/universal-service.js +1 -1
- package/dist/server/universal/universal-session.js +106 -69
- package/dist/server/vision-bridge.js +2 -0
- package/dist/server/workspace-handle.js +119 -17
- package/dist/server/workspace-queue.js +37 -0
- package/dist/server/worktree-tool.js +13 -20
- package/docs/README.md +40 -36
- package/docs/architecture-plugins.md +64 -35
- package/docs/device-center.md +1 -1
- package/package.json +16 -4
- package/plugin-sdk/index.d.ts +102 -0
- package/plugins/catalog.json +23 -51
- package/themes/bases/flow-base.css +8 -17
- package/themes/dark-teal.css +0 -3
- package/web/dist/.build-assets.json +1 -1
- package/web/dist/assets/BgTasksModal-BdOJ19Hj.js +1 -0
- package/web/dist/assets/BgTasksModal-SAH2XCkY.js +1 -0
- package/web/dist/assets/{CanvasStudio-CAWcs9tm.js → CanvasStudio-BB_Iq7pl.js} +3 -3
- package/web/dist/assets/CanvasStudio-DU6O3N4u.js +1579 -0
- package/web/dist/assets/DeviceCenter-By1zVTSY.js +3 -0
- package/web/dist/assets/DeviceCenter-Cnm0Tjrx.js +3 -0
- package/web/dist/assets/DeviceExecutionSettings-qJzbI0Cf.js +1 -0
- package/web/dist/assets/{DeviceGroups-C_fZMNeK.js → DeviceGroups-DPrQxW6B.js} +1 -1
- package/web/dist/assets/DeviceGroups-DoucyUjI.js +1 -0
- package/web/dist/assets/{Dropdown-CTgVLUbp.js → Dropdown-kj_NIj6e.js} +1 -1
- package/web/dist/assets/FilePreview-Bub8Y9uq.js +2 -0
- package/web/dist/assets/FilePreview-CC76Z6an.js +2 -0
- package/web/dist/assets/GlobalSearchModal-01nkgw4X.js +1 -0
- package/web/dist/assets/GlobalSearchModal-CiT6wBmR.js +1 -0
- package/web/dist/assets/GroupConversation-1-lsPO1f.js +61 -0
- package/web/dist/assets/GroupConversation-HeiyW_O_.js +61 -0
- package/web/dist/assets/{GroupWorkItems-BIvZtr10.js → GroupWorkItems-BYJv2XFj.js} +1 -1
- package/web/dist/assets/{HintTip-Da6qc566.js → HintTip-DFhoclDw.js} +1 -1
- package/web/dist/assets/ModelConfigModal-D2Ro-jUZ.js +2 -0
- package/web/dist/assets/ModelConfigModal-DPc9R1pq.js +2 -0
- package/web/dist/assets/{NativeCliPanel-CU1rZmyu.js → NativeCliPanel-B108d697.js} +3 -3
- package/web/dist/assets/NativeCliPanel-DupvGwQM.js +5 -0
- package/web/dist/assets/{PiSetupModal-DZKY5Wiw.js → PiSetupModal-D0HitBfd.js} +1 -1
- package/web/dist/assets/ProviderOAuthControls-BLKUEDde.js +1 -0
- package/web/dist/assets/SCMPanel-DDbWrUHR.js +2 -0
- package/web/dist/assets/SCMPanel-DluNcd2-.js +2 -0
- package/web/dist/assets/SettingsModal-Cy5lRC97.css +1 -0
- package/web/dist/assets/SettingsModal-DQu18366.js +33 -0
- package/web/dist/assets/SettingsModal-Dm_haPme.js +33 -0
- package/web/dist/assets/{TermXterm-Bt5WKAxP.js → TermXterm-SYc-MUk2.js} +2 -2
- package/web/dist/assets/TerminalPanel-CgA_lhVT.js +1 -0
- package/web/dist/assets/TerminalPanel-vdSIOPjD.js +1 -0
- package/web/dist/assets/TuiOverlayModal-Cy1jYYIw.js +1 -0
- package/web/dist/assets/TuiOverlayModal-kXY_4hV8.js +1 -0
- package/web/dist/assets/app-globals-CBEscsYP.js +129 -0
- package/web/dist/assets/{canvas-client-WkhM55mR.js → canvas-client-Clsypfs6.js} +1 -1
- package/web/dist/assets/{desktop-B8NZ3KW-.js → desktop-C6D9a8HZ.js} +1 -1
- package/web/dist/assets/index-BD29OL9L.js +404 -0
- package/web/dist/assets/index-BlCxbqqr.js +404 -0
- package/web/dist/assets/index-DB55rbKC.css +1 -0
- package/web/dist/assets/plugin-host-VWBcq-LQ.js +1 -0
- package/web/dist/assets/remote-ssh-client-C2eab5Kw.js +1 -0
- package/web/dist/assets/theme-CpQk_Agp.js +1 -0
- package/web/dist/index.html +10 -10
- package/web/dist/sw.js +1 -1
- package/dist/server/edit-soft-tool.js +0 -297
- package/web/dist/assets/BgTasksModal-D-x7kA63.js +0 -1
- package/web/dist/assets/DeviceCenter-Dc0whRcu.js +0 -3
- package/web/dist/assets/DeviceExecutionSettings-BoX7-0h7.js +0 -1
- package/web/dist/assets/FilePreview-C6W0PvaK.js +0 -2
- package/web/dist/assets/GlobalSearchModal-HR9LSspC.js +0 -1
- package/web/dist/assets/GroupConversation-C81YjF2C.js +0 -61
- package/web/dist/assets/ModelConfigModal-DhSyuIuV.js +0 -2
- package/web/dist/assets/ProviderOAuthControls-CIL85nA7.js +0 -1
- package/web/dist/assets/SCMPanel-CuEgzAlO.js +0 -2
- package/web/dist/assets/SettingsModal-Cdu5h29p.js +0 -33
- package/web/dist/assets/TerminalPanel-BCIBV8se.js +0 -1
- package/web/dist/assets/TuiOverlayModal-3NDd9T97.js +0 -1
- package/web/dist/assets/app-globals-CZjFtI4F.js +0 -129
- package/web/dist/assets/index-CQc3VrWa.css +0 -1
- package/web/dist/assets/index-D_AGu4Zv.js +0 -404
- package/web/dist/assets/plugin-host-uqZGpvCs.js +0 -1
- package/web/dist/assets/remote-ssh-client-Cdf-cTUe.js +0 -1
- package/web/dist/assets/theme-DGL7hLUs.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Fn as t}from"./app-globals-CBEscsYP.js";import{i as n}from"./react-CR5VJ85Q.js";import{t as r}from"./uuid-BzDIGCwP.js";import{r as i}from"./desktop-C6D9a8HZ.js";import{o as a,t as o}from"./composer-bridge-CImnjDHq.js";var s=e(n(),1),c=`pi-web-ui:cost-currency`,l=null,u=0,d=new Set;function f(){u+=1;for(let e of[...d])try{e()}catch{}}function p(e){return d.add(e),()=>{d.delete(e)}}function m(){return u}function h(e){return!Number.isFinite(e)||e<=0?`0`:e<1e-4?`<0.0001`:e.toFixed(4).replace(/\.?0+$/,``)}function g(){try{if(typeof localStorage<`u`){let e=localStorage.getItem(c);if(typeof e==`string`&&e.trim().length>0)return e.trim().slice(0,8)}}catch{}return`$`}function ee(e){try{if(typeof localStorage<`u`){let t=typeof e==`string`?e.trim().slice(0,8):``;!t||t===`$`?localStorage.removeItem(c):localStorage.setItem(c,t)}}catch{}f()}function te(e){return typeof e==`function`?(l=e,f(),()=>{l===e&&(l=null,f())}):(l=null,f(),()=>{})}function ne(e,t){let n=String(e??``).trim();if(!n)return{symbol:t,value:`0`};let r=n.match(/^([^\d<>+-]+)\s*(.+)$/);return r?{symbol:r[1],value:r[2]}:{symbol:``,value:n}}function _(e,t){let n=typeof e==`number`&&Number.isFinite(e)?e:0,r=g(),i=typeof t?.fixedDigits==`number`?n.toFixed(t.fixedDigits):h(n);if(l)try{let e=l(n,{defaultSymbol:r,defaultValue:i});if(typeof e==`string`)return ne(e,r);if(e&&typeof e==`object`&&typeof e.value==`string`)return{symbol:typeof e.symbol==`string`?e.symbol:r,value:e.value,tooltip:typeof e.tooltip==`string`?e.tooltip:void 0}}catch(e){console.error(`[cost-format] custom cost formatter threw:`,e)}return{symbol:r,value:i}}function re(e,t){return(0,s.useSyncExternalStore)(p,m,m),_(e,t)}var v=null;function ie(e){v=e?.open??null,e?.close,e?.isOpen}function y(e){return!v||!e?.src?!1:(v(e),!0)}var b=[{id:`builtin`,label:`系统语音`,labelEn:`System speech`}],x=new Set,S,C;async function w(e){let t=await e.json().catch(()=>({}));return Error(t.error||`TTS HTTP ${e.status}`)}function T(){return S||=(async()=>{let e=await fetch(t(`/api/tts/engines`));if(!e.ok)throw await w(e);b=(await e.json()).engines;for(let e of x)e()})().finally(()=>{S=void 0}),S}function ae(){return[...b]}function oe(e){if(e)return{...b.find(t=>t.id===e)||{id:e,label:e},getVoices:async()=>{let n=await fetch(t(`/api/tts/voices?engine=${encodeURIComponent(e)}`));if(!n.ok)throw await w(n);return(await n.json()).voices.map(e=>({voiceURI:e.id,name:e.label,lang:e.lang}))},play:({text:n,rate:r,voiceURI:i,onStart:a,onEnd:o,onError:s})=>{let c=new AbortController,l,u,d=!1,f=()=>{c.abort(),l&&(l.pause(),l.removeAttribute(`src`),l.load()),u&&=(URL.revokeObjectURL(u),void 0)},p=e=>{d||(d=!0,f(),e?s?.(e):o?.())};return(async()=>{try{let o=await fetch(t(`/api/tts/synthesize`),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:n,engine:e,voice:i||``,rate:r}),signal:c.signal});if(!o.ok)throw await w(o);let s=await o.blob();if(d)return;u=URL.createObjectURL(s),l=new Audio(u),l.onplay=()=>{d||a?.()},l.onended=()=>p(),l.onerror=()=>p(Error(`语音播放失败`)),await l.play()}catch(e){d||p(e)}})(),()=>{d||(d=!0,f())}}}}function se(e){return x.add(e),T().catch(()=>{}),C||=setInterval(()=>{T().catch(()=>{})},15e3),()=>{x.delete(e),!x.size&&C&&(clearInterval(C),C=void 0)}}var E=new Map,D=new Set,O=[],k=null;function A(){O=[...E.values()].map(e=>e.provider);for(let e of D)e()}function ce(e,t=null){let n=String(e?.id??``).trim();if(!n||typeof e?.recognize!=`function`||t&&k&&!k.has(t))return()=>{};let r={provider:{...e,id:n},owner:t};return E.set(n,r),A(),()=>{E.get(n)===r&&(E.delete(n),A())}}function le(){return O}function ue(e){return D.add(e),()=>{D.delete(e)}}function de(e){k=e;for(let t of E.values())t.owner&&!e.has(t.owner)&&j(t.owner)}function j(e){let t=!1;for(let[n,r]of E)(e===void 0||r.owner===e)&&(E.delete(n),t=!0);t&&A()}var M=new Map,fe=0;function pe(e){M.get(e.requestId)?.(e.ok&&e.conversationId?e.conversationId:null)}function N(e,t,n){let r=`host-new-chat-${Date.now()}-${++fe}`;return new Promise(i=>{let a=e=>{clearTimeout(o),M.delete(r),i(e)},o=setTimeout(()=>a(null),n);M.set(r,a);try{e(t(r))||a(null)}catch{a(null)}})}function P(e,t=8e3){return N(e,e=>({type:`new_chat`,requestId:e}),t)}function me(e,t,n,r=n?.trim().startsWith(`ssh://`)?12e4:3e4){return N(e,e=>({type:`new_cli_chat`,config:t,cwd:n,requestId:e}),r)}var F=`__piWebUiHost`,I=e=>new Promise(t=>setTimeout(t,e));async function he(e=3e3){let t=Date.now()+e;for(;;){let e=window.__piBridge;if(e&&typeof e.call==`function`)return e;if(Date.now()>=t)return null;await I(100)}}var L=Promise.resolve(),R=0;function ge(e){let t=Math.max(1,Number(e.pollMs??100)),n=Math.max(t,Number(e.timeoutMs??8e3)),s=async e=>{let r=Date.now()+n;for(;;){if(e())return!0;if(Date.now()>=r)return e();await I(t)}},c=()=>{try{let t=e.listModels?.()??[];return Array.isArray(t)?[...t]:[]}catch{return[]}},l=e=>{if(!e)return!0;try{return c().some(t=>t&&t.id===e)}catch{return!1}},u=async t=>{t&&(e.send({type:`set_model`,modelId:t}),typeof e.getCurrentModelId==`function`&&await s(()=>e.getCurrentModelId?.()===t))},d=async(t,r)=>{let i=String(r.cwd??``).trim();if(i&&e.getCwd()!==i&&(!e.send({type:`set_cwd`,path:i})||!await s(()=>e.getCwd()===i))||!e.isReady())return!1;let a=r.newChat===!1?e.getConversationId():await P(e.send,n);if(r.newChat!==!1&&a&&!await s(()=>e.getConversationId()===a)||!a||!e.isReady())return!1;let o=String(r.model??``).trim();return o&&await u(o),!e.isReady()||e.getConversationId()!==a||i&&e.getCwd()!==i?!1:(e.setView(`chat`),e.send({type:`prompt`,text:t,targetConversationId:a}))};return{version:18,setView(t){let n=String(t??``).trim();n&&e.setView(n)},startChat(t){let n=String(t?.prompt??``).trim();if(!n||!e.isReady())return!1;let r=String(t?.model??``).trim();if(r&&!l(r))return!1;let i=async()=>{let e=!1;try{e=await d(n,t??{prompt:n})}finally{try{t?.onResult?.(e)}catch{}}},a;return a=R>0?L.then(i):i(),R++,L=a.then(()=>{R--},()=>{R--}),a.catch(()=>{}),!0},models:{list:()=>c(),active:()=>e.getCurrentModelId?.()??null,onChange:e=>Me(e)},compose(e){return a()?o({text:typeof e?.text==`string`?e.text:void 0,attachments:Array.isArray(e?.attachments)?e.attachments:void 0}):!1},openModal(t){let n=String(t??``).trim();if(!n||typeof e.openModal!=`function`)return!1;try{return e.openModal(n)}catch{return!1}},setFooterStatus(t,n){if(typeof e.setFooterStatus!=`function`)return!1;try{return e.setFooterStatus(String(t??``),n)}catch{return!1}},closeModal(){if(typeof e.closeModal!=`function`)return!0;try{e.closeModal()}catch{}return!0},async openSession(t){let r=V,i=Array.isArray(t?.folders)?t.folders.filter(e=>typeof e==`string`&&e.trim().length>0).map(e=>e.trim()):[],a=Array.isArray(t?.roots)?t.roots.filter(e=>typeof e==`string`&&e.trim().length>0).map(e=>e.trim()):[],o=String(t?.cwd??``).trim(),c=[...new Set([...i,...a])],d=o||c[0]||``;if(!d)return{ok:!1,error:`openSession 需要 cwd / folders / roots(绝对路径)`};if(!e.isReady())return{ok:!1,error:`尚未连接到服务器(还没有快照)`};let f=c.filter(e=>e!==d).slice(0,7),p=new Set([...e.listProjects?.()??[],...e.grantedPaths?.(r)??[]]);for(let t of[d,...f])if(!p.has(t)){if(!(e.confirm&&await e.confirm({path:t}).catch(()=>!1)))return{ok:!1,error:`用户拒绝了该目录的访问:${t}`};e.grantPath?.(t,r)}if(e.getCwd()!==d&&(e.send({type:`set_cwd`,path:d}),!await s(()=>e.getCwd()===d)))return{ok:!1,error:`切换工作目录失败或超时:${d}`};(f.length>0||e.getWorkspaceRoots().length>0)&&e.send({type:`set_workspace_roots`,roots:f});let m=e.getConversationId()??void 0;if(t?.newChat!==!1&&(m=await P(e.send,n)??void 0,!m||!await s(()=>e.getConversationId()===m)))return{ok:!1,error:`Conversation creation failed or timed out`};let h=String(t?.model??``).trim();if(h){if(!l(h))return{ok:!1,error:`未知模型:${h}(先调 models.list() 取可用列表)`};if(await u(h),e.getConversationId()!==m)return{ok:!1,error:`Conversation changed`}}let g=String(t?.prompt??``).trim();return!m||!e.isReady()?{ok:!1,error:`Conversation unavailable`}:(g&&(e.setView(`chat`),e.send({type:`prompt`,text:g,targetConversationId:m})),{ok:!0,...m?{sessionId:m}:{}})},sessions:{list:()=>e.listSessions(),async open(t){let n=V,r=String(t??``).trim();if(!r)return{ok:!1,error:`sessions.open 需要一个会话 id(先调 list)`};if(!e.isReady())return{ok:!1,error:`尚未连接到服务器(还没有快照)`};let i=e.listSessions().find(e=>e.id===r);if(!i)return{ok:!1,error:`找不到会话:${r}`};if(i.cwd&&i.cwd!==e.getCwd()){if(!new Set([...e.listProjects?.()??[],...e.grantedPaths?.(n)??[]]).has(i.cwd)){if(!(e.confirm&&await e.confirm({path:i.cwd}).catch(()=>!1)))return{ok:!1,error:`用户拒绝了该目录的访问:${i.cwd}`};e.grantPath?.(i.cwd,n)}if(e.send({type:`set_cwd`,path:i.cwd}),!await s(()=>e.getCwd()===i.cwd))return{ok:!1,error:`切换工作目录失败或超时:${i.cwd}`}}let a=e.getConversationId();return i.kind===`elsewhere`&&i.owner?(e.send({type:i.independent===!1?`open_shared_conversation`:`take_over_conversation`,owner:i.owner,id:i.conversationId??i.id}),await s(()=>e.getConversationId()===(i.conversationId??i.id)&&(i.independent!==!1||e.getConversationOwner?.()===i.owner))?{ok:!0,sessionId:e.getConversationId()??void 0}:{ok:!1,error:`打开并接入会话超时:${i.title}`}):(i.kind===`running`?e.send({type:`switch_conversation`,id:i.id}):e.send({type:`switch_session`,path:i.id}),await s(()=>i.kind===`running`?e.getConversationId()===i.id&&!e.getConversationOwner?.():e.getConversationId()!==a)?{ok:!0,sessionId:e.getConversationId()??void 0}:{ok:!1,error:`切换会话超时:${i.title}`})}},async reloadCatalog(t,n){let i=String(t??``).trim();if(!i)return{ok:!1,error:`reloadCatalog 需要一个目录来源(http(s) URL 或本地文件路径)`};if(!e.isReady())return{ok:!1,error:`尚未连接到服务器(还没有快照)`};let a=r();return new Promise(t=>{let r=setTimeout(()=>{$.delete(a),t({ok:!1,error:`目录同步超时(服务端未在等待窗口内回执)`})},Math.max(1e3,Number(e.catalogTimeoutMs??18e4)));$.set(a,e=>{clearTimeout(r),t(e)}),e.send({type:`plugin_catalog_sync`,requestId:a,source:i,...n?.install?{install:!0}:{},...n?.replace?{replace:!0}:{}})})},onUiAction(e,t){return H(B,String(e??``).trim(),t)},onTopbarAction(e,t){return H(B,String(e??``).trim(),t)},async pageCall(t){let n=String(t?.op??``).trim();if(!n)return{ok:!1,error:`pageCall 需要一个动作名(op)`};let r=window.__piBrowser;if(r?.version===1&&typeof r.pageCall==`function`)try{return await r.pageCall({...t,op:n,timeoutMs:t.timeoutMs??3e4})}catch(e){return{ok:!1,error:e instanceof Error?e.message:String(e)}}if(i())return{ok:!1,error:`此桌面版尚未提供原生浏览器桥;请升级到支持 AI Browser 的桌面版,或在系统浏览器中使用 page-picker 扩展。/ Native browser bridge unavailable; upgrade the desktop app or use page-picker in a regular browser.`};let a=await he(e.bridgeWaitMs??3e3);if(!a)return{ok:!1,error:`浏览器扩展的页面桥没就绪:确认已安装并启用 page-picker 扩展、本页地址已绑定,然后刷新本页`};try{let e=await a.call({op:n,...t.args===void 0?{}:{args:t.args},...t.target?{to:t.target}:{},...t.timeoutMs?{timeoutMs:t.timeoutMs}:{}});return e===void 0?{ok:!0}:{ok:!0,result:e}}catch(e){return{ok:!1,error:e instanceof Error?e.message:String(e)}}},dom:{anchors(){let e=e=>{try{return document.querySelector(`[data-pi-anchor="${e}"]`)}catch{return null}};return{app:e(`app`),topbar:e(`topbar`),composer:e(`composer`)}}},dialogs:{async select(t){try{let n=e.select;if(typeof n!=`function`)return{ok:!1};let r=Array.isArray(t?.options)?t.options:[],i=await n({title:String(t?.title??``),options:r.filter(e=>typeof e==`object`&&!!e&&typeof e.label==`string`).map(e=>({label:String(e.label),...typeof e.description==`string`?{description:e.description}:{}})),...t?.multi?{multi:!0}:{}});return!i||typeof i!=`object`||i.ok!==!0?{ok:!1,...i&&typeof i==`object`&&typeof i.error==`string`?{error:i.error}:{}}:{ok:!0,selected:Array.isArray(i.selected)?i.selected.filter(e=>typeof e==`string`):[]}}catch{return{ok:!1}}},async confirm(t){let n=String(t?.title??``),r=typeof t?.detail==`string`?t.detail:``;try{if(typeof e.dialogConfirm==`function`)try{return await e.dialogConfirm({title:n,...r?{detail:r}:{}})===!0}catch{}if(typeof window<`u`&&typeof window.confirm==`function`)try{return window.confirm(r?`${n}\n\n${r}`:n)}catch{return!1}return!1}catch{return!1}},async input(t){try{let n=e.input;if(typeof n!=`function`)return{ok:!1};let r=await n({title:String(t?.title??``),...typeof t?.placeholder==`string`?{placeholder:t.placeholder}:{},...typeof t?.initial==`string`?{initial:t.initial}:{}});return!r||typeof r!=`object`||r.ok!==!0?{ok:!1}:typeof r.value==`string`?{ok:!0,value:r.value}:{ok:!0}}catch{return{ok:!1}}}},async notifyAction(t){let n=String(t?.text??``),r=(Array.isArray(t?.actions)?t.actions:[]).filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`&&typeof e.label==`string`);try{if(typeof e.notifyAction==`function`){let t=await e.notifyAction({text:n,actions:r});return typeof t==`string`?t:null}}catch{return null}try{typeof window<`u`&&typeof window.dispatchEvent==`function`&&window.dispatchEvent(new CustomEvent(xe,{detail:{text:n}}))}catch{}return null},shortcuts:{register:(e,t)=>Ee(String(e??``),t)},searchProviders:{register:e=>De(e),list:()=>q()},composerProviders:{register:e=>Oe(e),list:()=>ke()},ttsProviders:{list:()=>ae()},openImagePreview:y,imageOcrProviders:{register:e=>ce(e,B),list:()=>le().map(({id:e,label:t,labelEn:n})=>({id:e,label:t,labelEn:n}))},onTheme:e=>Pe(e),onLocale:e=>Fe(e),onViewChange:e=>Ie(e),listProjects:()=>e.listProjects?.()??[],pickDirectory:t=>e.pickDirectory?e.pickDirectory(t):Promise.resolve({ok:!1,canceled:!0}),pickModel:t=>e.pickModel?e.pickModel(t):Promise.resolve({ok:!1,canceled:!0}),openFileContextMenu:t=>e.openFileContextMenu?.(t),setCostFormatter:e=>te(e),setCostCurrency:e=>ee(e),getCostCurrency:()=>g()}}function _e(e){try{let t=window;e?t[F]=e:delete t[F]}catch{}}var z=new Map,B=null;async function ve(e,t){let n=B;B=e;try{return await t()}finally{B=n}}var V=void 0;function ye(e,t){let n=V;V=e;try{return t()}finally{V=n}}function H(e,t,n){if(!t||typeof n!=`function`)return()=>{};let r=e?`${e}:${t}`:t,i=z.get(r);i||(i=new Set,z.set(r,i));let a=i;return a.add(n),()=>{a.delete(n),a.size===0&&z.delete(r)}}async function be(e,t,n,r){let i=i=>{let a=z.get(i);if(!a||a.size===0)return!1;for(let i of[...a])try{ye(e,()=>i(n,r?.value,r?.target))}catch(n){console.error(`[plugin:${e}] 顶栏动作 ${t} 抛错:`,n)}return!0};if(i(`${e}:${t}`)||i(t))return!0;if(r?.loadBundle&&await r.loadBundle(e).catch(()=>!1)){let n=Date.now()+Math.max(100,Number(r.waitMs??1500));for(;;){if(i(`${e}:${t}`)||i(t))return!0;if(Date.now()>=n)break;await new Promise(e=>setTimeout(e,100))}}return!1}var xe=`pi-web-ui:toast`,U=new Map,W=!1;function Se(e){let t=e.split(`+`).map(e=>e.trim().toLowerCase()).filter(e=>e.length>0);if(t.length===0)return null;let n=!1,r=!1,i=!1,a=!1;for(let e of t.slice(0,-1))if(e===`ctrl`||e===`control`)n=!0;else if(e===`shift`)r=!0;else if(e===`alt`||e===`option`)i=!0;else if(e===`meta`||e===`cmd`||e===`command`||e===`win`||e===`super`)a=!0;else return null;let o=t[t.length-1]??``;return!o||[`ctrl`,`control`,`shift`,`alt`,`option`,`meta`,`cmd`,`command`,`win`,`super`].includes(o)?null:{combo:`${n?`ctrl+`:``}${r?`shift+`:``}${i?`alt+`:``}${a?`meta+`:``}${o}`,key:o,ctrl:n,shift:r,alt:i,meta:a}}function Ce(){try{if(typeof document>`u`)return!1;let e=document.activeElement;if(!e)return!1;let t=(e.tagName||``).toUpperCase();return!!(t===`INPUT`||t===`TEXTAREA`||t===`SELECT`||e.isContentEditable)}catch{return!1}}function G(e){try{if(Ce())return;let t=`${e.ctrlKey?`ctrl+`:``}${e.shiftKey?`shift+`:``}${e.altKey?`alt+`:``}${e.metaKey?`meta+`:``}${(e.key??``).toLowerCase()}`,n=U.get(t);if(!n||n.size===0)return;for(let e of[...n])try{e()}catch(e){console.error(`[plugin-host] 快捷键处理器抛错:`,e)}}catch{}}function we(){if(!W)try{if(typeof window>`u`||typeof window.addEventListener!=`function`)return;window.addEventListener(`keydown`,G),W=!0}catch{}}function Te(){if(!(U.size>0||!W))try{window.removeEventListener(`keydown`,G)}catch{}finally{W=!1}}function Ee(e,t){if(typeof t!=`function`)return()=>{};let n=Se(e);if(!n)return()=>{};let r=U.get(n.combo);r||(r=new Set,U.set(n.combo,r));let i=r;return i.add(t),we(),()=>{i.delete(t),i.size===0&&U.delete(n.combo),Te()}}var K=new Map;function De(e){let t=String(e?.id??``).trim();if(!t||typeof e?.search!=`function`)return()=>{};let n={id:t,label:String(e.label??t),search:e.search};return K.set(t,n),()=>{K.get(t)===n&&K.delete(t)}}function q(){return[...K.values()].map(e=>({id:e.id,label:e.label}))}var J=new Map;function Oe(e){let t=String(e?.id??``).trim();if(!t||typeof e?.search!=`function`)return()=>{};let n={id:t,label:String(e.label??t),search:e.search};return J.set(t,n),()=>{J.get(t)===n&&J.delete(t)}}function ke(){return[...J.values()].map(e=>({id:e.id,label:e.label}))}function Ae(e){return J.get(String(e??``))}function je(e){return K.get(String(e??``))}var Y=new Set,X=new Set,Z=new Set,Q=new Set;function Me(e){return Q.add(e),()=>{Q.delete(e)}}function Ne(e){for(let t of Q)try{t(e)}catch(e){console.error(`[plugin-host] onModelChange 处理器抛错:`,e)}}function Pe(e){return typeof e==`function`?(Y.add(e),()=>{Y.delete(e)}):()=>{}}function Fe(e){return typeof e==`function`?(X.add(e),()=>{X.delete(e)}):()=>{}}function Ie(e){return typeof e==`function`?(Z.add(e),()=>{Z.delete(e)}):()=>{}}function Le(e){let t=String(e??``);for(let e of Y)try{e(t)}catch(e){console.error(`[plugin-host] onTheme 处理器抛错:`,e)}}function Re(e){let t=String(e??``);for(let e of X)try{e(t)}catch(e){console.error(`[plugin-host] onLocale 处理器抛错:`,e)}}function ze(e){let t=String(e??``);for(let e of Z)try{e(t)}catch(e){console.error(`[plugin-host] onViewChange 处理器抛错:`,e)}}var $=new Map;function Be(e){let t=$.get(e.requestId);if(t){if($.delete(e.requestId),!e.ok){t({ok:!1,error:e.error??`目录同步失败`});return}t({ok:!0,...e.entries?{entries:e.entries}:{},...e.installed?{installed:e.installed}:{}})}}export{y as C,re as E,se as S,_ as T,le as _,ze as a,oe as b,_e as c,Be as d,be as f,j as g,pe as h,Le as i,ke as l,me as m,Re as n,Ae as o,ve as p,Ne as r,je as s,ge as t,q as u,ue as v,ie as w,ae as x,de as y};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./app-globals-CBEscsYP.js";var t=new Set;function n(e){return t.add(e),()=>{t.delete(e)}}function r(e){for(let n of t)try{n(e)}catch(e){console.error(`[remote-ssh-client] listener error:`,e)}}function i(e,t,n,r){return`ssh://${e}@${t}:${n}${r.startsWith(`/`)?r:`/${r}`}`}function a(e){return!!(e&&e.startsWith(`ssh://`))}function o(e){if(!a(e))return null;let t=/^ssh:\/\/([^@]+)@([^:]+):(\d+)(\/.*)$/.exec(e);return t?{username:t[1],host:t[2],port:parseInt(t[3],10),remotePath:t[4]}:null}var s=1;function c(t){let r=`probe_${Date.now()}_${s++}`;return new Promise(i=>{let a=n(e=>{e.type===`remote_ssh_probe_result`&&e.reqId===r&&(a(),i({ok:e.ok,connectionId:e.connectionId,error:e.error,system:e.system,tools:e.tools,packageManager:e.packageManager,suggestedInstall:e.suggestedInstall,hostTrust:e.hostTrust}))});e({type:`remote_ssh_probe`,reqId:r,params:t})||(a(),i({ok:!1,error:`WebSocket 连接不可用,请稍候重试`}))})}function l(t,r){let i=`listdir_${Date.now()}_${s++}`;return new Promise(a=>{let o=n(e=>{e.type===`remote_ssh_list_dir_result`&&e.reqId===i&&(o(),a({ok:e.ok,connectionId:e.connectionId,path:e.path,parentPath:e.parentPath,items:e.items,error:e.error}))});e({type:`remote_ssh_list_dir`,reqId:i,connectionId:t,path:r})||(o(),a({ok:!1,connectionId:t,path:r||`/`,items:[],error:`WebSocket 连接不可用`}))})}function u(t,r){let i=`install_${Date.now()}_${s++}`;return new Promise(a=>{let o=n(e=>{e.type===`remote_ssh_install_result`&&e.reqId===i&&(o(),a({ok:e.ok,connectionId:e.connectionId,tool:e.tool,output:e.output,error:e.error}))});e({type:`remote_ssh_install_tools`,reqId:i,connectionId:t,tools:r})||(o(),a({ok:!1,connectionId:t,tool:r[0]||``,error:`WebSocket 连接不可用`}))})}function d(){let t=`profiles_${Date.now()}_${s++}`;return new Promise(r=>{let i=n(e=>{e.type===`remote_ssh_profiles_result`&&e.reqId===t&&(i(),r(e.profiles))});e({type:`remote_ssh_list_profiles`,reqId:t})||(i(),r([]))})}function f(t){e({type:`remote_ssh_delete_profile`,name:t})}function p(t){let r=`trust_${Date.now()}_${s++}`;return new Promise(i=>{let a=n(e=>{e.type===`remote_ssh_trust_host_result`&&e.reqId===r&&(a(),i({ok:e.ok,error:e.error}))});e({type:`remote_ssh_trust_host`,reqId:r,...t})||(a(),i({ok:!1,error:`WebSocket 连接不可用`}))})}export{o as a,c,a as i,d as l,r as n,u as o,i as r,l as s,f as t,p as u};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Bn as t,Fn as n,Nn as r,Pn as i,i as a}from"./app-globals-CBEscsYP.js";import{i as o}from"./react-CR5VJ85Q.js";var s=e(o(),1),c=`pi-web-ui:theme`,l=`flow-ink`,u=`theme-stylesheet`,d=Date.now().toString(36),f=0,p=3,m=0,h=new WeakMap,g=0,_=`pi-web-ui:theme-change`;function v(){try{let e=localStorage.getItem(c);if(e===`none`)return null;if(e&&e!==`dark`)return e}catch{}return l}function y(e){try{e===null?localStorage.setItem(c,`none`):localStorage.setItem(c,e)}catch{}}function b(e){return i(`/themes/${encodeURIComponent(e)}.css?v=${d}.${f}`)}function x(){if(typeof document>`u`)return!1;let e=document.getElementById(u),t=e?h.get(e):void 0;return!!t&&t.loaded!==null&&t.loaded===t.href}function S(e,t={}){if(t.reload&&(f++,m=0),typeof document<`u`&&(e?document.documentElement.dataset.theme=e:delete document.documentElement.dataset.theme),!e){document.getElementById(u)?.remove(),m=0,window.dispatchEvent(new CustomEvent(_));return}let n=document.getElementById(u);n||(n=document.createElement(`link`),n.id=u,n.rel=`stylesheet`,m=0,document.head.appendChild(n));let i=b(e),a=h.get(n);if(a&&a.href===i)return;let o=n,s=++g,c={href:i,loaded:null,seq:s};h.set(o,c);let l=r(i);l?o.crossOrigin=l:o.removeAttribute(`crossorigin`),o.href=i,o.onload=()=>{let e=h.get(o);e&&e.seq===s&&(e.loaded=i,m=0,window.dispatchEvent(new CustomEvent(_)))},o.onerror=()=>{let t=h.get(o);if(!t||t.seq!==s||t.loaded===i||m>=p)return;let n=400*2**m++;window.setTimeout(()=>{let t=h.get(o);t&&t.seq===s&&(f++,S(e))},n)}}async function C(){try{let e=await fetch(t(n(`/api/themes`)));if(!e.ok)return[];let r=await e.json();return Array.isArray(r.themes)?r.themes:[]}catch{return[]}}function w(){let[e,t]=(0,s.useState)([]),[n,r]=(0,s.useState)(()=>v()),i=a(`status`)===`open`;(0,s.useEffect)(()=>{let e=!1;return C().then(n=>{e||t(n)}),()=>{e=!0}},[i]);let o=(0,s.useCallback)(()=>{C().then(t)},[]);return(0,s.useEffect)(()=>{i&&!x()?S(n,{reload:!0}):S(n),y(n)},[n,i]),{themes:e,theme:n,switchTheme:e=>r(e),reloadThemes:o}}function T(){let e=getComputedStyle(document.documentElement),t=(t,n)=>e.getPropertyValue(t).trim()||n;return{background:t(`--term-bg`,`#0b0d12`),foreground:t(`--term-fg`,`#e6e8ef`),cursor:t(`--term-cursor`,`#8b5cf6`),cursorAccent:t(`--term-cursor-accent`,`#0b0d12`),selectionBackground:t(`--term-selection`,`rgba(139, 92, 246, 0.35)`),black:t(`--term-black`,`#1a1d26`),red:t(`--term-red`,`#f87171`),green:t(`--term-green`,`#34d399`),yellow:t(`--term-yellow`,`#fbbf24`),blue:t(`--term-blue`,`#60a5fa`),magenta:t(`--term-magenta`,`#c084fc`),cyan:t(`--term-cyan`,`#22d3ee`),white:t(`--term-white`,`#e6e8ef`),brightBlack:t(`--term-bright-black`,`#6b7284`),brightRed:t(`--term-bright-red`,`#f87171`),brightGreen:t(`--term-bright-green`,`#34d399`),brightYellow:t(`--term-bright-yellow`,`#fbbf24`),brightBlue:t(`--term-bright-blue`,`#60a5fa`),brightMagenta:t(`--term-bright-magenta`,`#c084fc`),brightCyan:t(`--term-bright-cyan`,`#22d3ee`),brightWhite:t(`--term-bright-white`,`#ffffff`)}}export{w as a,v as i,S as n,T as r,_ as t};
|
package/web/dist/index.html
CHANGED
|
@@ -21,23 +21,23 @@
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
</script>
|
|
24
|
-
<script type="module" crossorigin src="./assets/index-
|
|
24
|
+
<script type="module" crossorigin src="./assets/index-BlCxbqqr.js"></script>
|
|
25
25
|
<link rel="modulepreload" crossorigin href="./assets/rolldown-runtime-hePW80VL.js">
|
|
26
26
|
<link rel="modulepreload" crossorigin href="./assets/react-CR5VJ85Q.js">
|
|
27
|
-
<link rel="modulepreload" crossorigin href="./assets/app-globals-
|
|
27
|
+
<link rel="modulepreload" crossorigin href="./assets/app-globals-CBEscsYP.js">
|
|
28
28
|
<link rel="modulepreload" crossorigin href="./assets/shortcut-stack-hhrDyRBn.js">
|
|
29
29
|
<link rel="modulepreload" crossorigin href="./assets/uuid-BzDIGCwP.js">
|
|
30
|
-
<link rel="modulepreload" crossorigin href="./assets/Dropdown-
|
|
31
|
-
<link rel="modulepreload" crossorigin href="./assets/theme-
|
|
32
|
-
<link rel="modulepreload" crossorigin href="./assets/desktop-
|
|
30
|
+
<link rel="modulepreload" crossorigin href="./assets/Dropdown-kj_NIj6e.js">
|
|
31
|
+
<link rel="modulepreload" crossorigin href="./assets/theme-CpQk_Agp.js">
|
|
32
|
+
<link rel="modulepreload" crossorigin href="./assets/desktop-C6D9a8HZ.js">
|
|
33
33
|
<link rel="modulepreload" crossorigin href="./assets/composer-bridge-CImnjDHq.js">
|
|
34
|
-
<link rel="modulepreload" crossorigin href="./assets/plugin-host-
|
|
35
|
-
<link rel="modulepreload" crossorigin href="./assets/HintTip-
|
|
36
|
-
<link rel="modulepreload" crossorigin href="./assets/remote-ssh-client-
|
|
34
|
+
<link rel="modulepreload" crossorigin href="./assets/plugin-host-VWBcq-LQ.js">
|
|
35
|
+
<link rel="modulepreload" crossorigin href="./assets/HintTip-DFhoclDw.js">
|
|
36
|
+
<link rel="modulepreload" crossorigin href="./assets/remote-ssh-client-C2eab5Kw.js">
|
|
37
37
|
<link rel="modulepreload" crossorigin href="./assets/markdown-BggnuQ4H.js">
|
|
38
38
|
<link rel="stylesheet" crossorigin href="./assets/markdown-C8LL_u4z.css">
|
|
39
|
-
<link rel="stylesheet" crossorigin href="./assets/index-
|
|
40
|
-
<meta name="pi-web-build-id" content="
|
|
39
|
+
<link rel="stylesheet" crossorigin href="./assets/index-DB55rbKC.css">
|
|
40
|
+
<meta name="pi-web-build-id" content="20261112T05452">
|
|
41
41
|
</head>
|
|
42
42
|
<body>
|
|
43
43
|
<div id="root"></div>
|
package/web/dist/sw.js
CHANGED
|
@@ -1,297 +0,0 @@
|
|
|
1
|
-
import { constants } from "node:fs";
|
|
2
|
-
import { access, readFile, writeFile } from "node:fs/promises";
|
|
3
|
-
import { homedir } from "node:os";
|
|
4
|
-
import { createRemoteSdkOperations } from "./remote-ssh-service.js";
|
|
5
|
-
import { isAbsolute, join, resolve as nodeResolve } from "node:path";
|
|
6
|
-
import { Type } from "typebox";
|
|
7
|
-
import { defineTool, generateDiffString, generateUnifiedPatch, withFileMutationQueue, } from "@earendil-works/pi-coding-agent";
|
|
8
|
-
import { pick } from "./i18n.js";
|
|
9
|
-
import { EDIT_SOFT_TOOL_NAME } from "./tool-manager.js";
|
|
10
|
-
export const SOFT_EDIT_TOOL_NAME = EDIT_SOFT_TOOL_NAME;
|
|
11
|
-
const replaceEditSchema = Type.Object({
|
|
12
|
-
oldText: Type.String({
|
|
13
|
-
description: "Text to replace. Loose matching: each non-empty line must match by trimmed content, so leading-indentation (spaces/tabs) differences are ignored. " +
|
|
14
|
-
"Prefer whole lines/blocks.",
|
|
15
|
-
}),
|
|
16
|
-
newText: Type.String({
|
|
17
|
-
description: "Replacement text (written verbatim).",
|
|
18
|
-
}),
|
|
19
|
-
}, {});
|
|
20
|
-
const editSoftSchema = Type.Object({
|
|
21
|
-
path: Type.String({
|
|
22
|
-
description: "Path of the file to edit (relative or absolute).",
|
|
23
|
-
}),
|
|
24
|
-
edits: Type.Array(replaceEditSchema, {
|
|
25
|
-
description: "One or more targeted replacements, matched against the original file (not incrementally); " +
|
|
26
|
-
"do not include overlapping/nested edits.",
|
|
27
|
-
}),
|
|
28
|
-
}, {});
|
|
29
|
-
function isSingleEditInput(value) {
|
|
30
|
-
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
31
|
-
return false;
|
|
32
|
-
const e = value;
|
|
33
|
-
return typeof e.oldText === "string" && typeof e.newText === "string";
|
|
34
|
-
}
|
|
35
|
-
function prepareSoftEditArguments(input) {
|
|
36
|
-
if (!input || typeof input !== "object")
|
|
37
|
-
return input;
|
|
38
|
-
const args = input;
|
|
39
|
-
if (typeof args.edits === "string") {
|
|
40
|
-
try {
|
|
41
|
-
const parsed = JSON.parse(args.edits);
|
|
42
|
-
if (Array.isArray(parsed))
|
|
43
|
-
args.edits = parsed;
|
|
44
|
-
else if (isSingleEditInput(parsed))
|
|
45
|
-
args.edits = [parsed];
|
|
46
|
-
}
|
|
47
|
-
catch { }
|
|
48
|
-
}
|
|
49
|
-
else if (isSingleEditInput(args.edits)) {
|
|
50
|
-
args.edits = [args.edits];
|
|
51
|
-
}
|
|
52
|
-
const legacy = args;
|
|
53
|
-
if (typeof legacy.oldText === "string" && typeof legacy.newText === "string") {
|
|
54
|
-
const edits = Array.isArray(legacy.edits) ? [...legacy.edits] : [];
|
|
55
|
-
edits.push({ oldText: legacy.oldText, newText: legacy.newText });
|
|
56
|
-
const { oldText: _o, newText: _n, ...rest } = legacy;
|
|
57
|
-
return { ...rest, edits };
|
|
58
|
-
}
|
|
59
|
-
return args;
|
|
60
|
-
}
|
|
61
|
-
function splitBom(content) {
|
|
62
|
-
return content.startsWith("\uFEFF") ? { bom: "\uFEFF", text: content.slice(1) } : { bom: "", text: content };
|
|
63
|
-
}
|
|
64
|
-
function detectLineEnding(content) {
|
|
65
|
-
const crlfIdx = content.indexOf("\r\n");
|
|
66
|
-
const lfIdx = content.indexOf("\n");
|
|
67
|
-
if (lfIdx === -1)
|
|
68
|
-
return "\n";
|
|
69
|
-
if (crlfIdx === -1)
|
|
70
|
-
return "\n";
|
|
71
|
-
return crlfIdx < lfIdx ? "\r\n" : "\n";
|
|
72
|
-
}
|
|
73
|
-
function normalizeToLF(text) {
|
|
74
|
-
return text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
75
|
-
}
|
|
76
|
-
function restoreLineEndings(text, ending) {
|
|
77
|
-
return ending === "\r\n" ? text.replace(/\n/g, "\r\n") : text;
|
|
78
|
-
}
|
|
79
|
-
const UNICODE_SPACES = /[\u00A0\u2000-\u200A\u202F\u205F\u3000]/g;
|
|
80
|
-
function normalizeShellPath(p) {
|
|
81
|
-
if (!p.startsWith("/") || p.startsWith("//") || p.includes("\\"))
|
|
82
|
-
return p;
|
|
83
|
-
const m = p.match(/^\/(?:mnt\/|cygdrive\/)?([a-z])(?:\/(.*))?$/i);
|
|
84
|
-
if (!m)
|
|
85
|
-
return p;
|
|
86
|
-
return `${m[1].toUpperCase()}:\\${(m[2] ?? "").replaceAll("/", "\\")}`;
|
|
87
|
-
}
|
|
88
|
-
function resolveToCwd(filePath, cwd) {
|
|
89
|
-
let p = filePath.replace(UNICODE_SPACES, " ");
|
|
90
|
-
if (p.startsWith("@"))
|
|
91
|
-
p = p.slice(1);
|
|
92
|
-
if (process.platform === "win32")
|
|
93
|
-
p = normalizeShellPath(p);
|
|
94
|
-
const home = homedir();
|
|
95
|
-
if (p === "~")
|
|
96
|
-
return home;
|
|
97
|
-
if (p.startsWith("~/"))
|
|
98
|
-
return join(home, p.slice(2));
|
|
99
|
-
return isAbsolute(p) ? nodeResolve(p) : nodeResolve(cwd, p);
|
|
100
|
-
}
|
|
101
|
-
function splitLineUnits(text) {
|
|
102
|
-
const units = [];
|
|
103
|
-
const re = /[^\n]*\n|[^\n]+/g;
|
|
104
|
-
let offset = 0;
|
|
105
|
-
let m;
|
|
106
|
-
while ((m = re.exec(text)) !== null) {
|
|
107
|
-
const chunk = m[0];
|
|
108
|
-
const newline = chunk.endsWith("\n") ? "\n" : "";
|
|
109
|
-
const raw = newline ? chunk.slice(0, -1) : chunk;
|
|
110
|
-
units.push({ raw, newline, start: offset, end: offset + chunk.length, core: raw.trim() });
|
|
111
|
-
offset += chunk.length;
|
|
112
|
-
}
|
|
113
|
-
return units;
|
|
114
|
-
}
|
|
115
|
-
export function oldTextCores(oldTextLF) {
|
|
116
|
-
const parts = oldTextLF.split("\n");
|
|
117
|
-
if (parts.length > 0 && parts[parts.length - 1] === "")
|
|
118
|
-
parts.pop();
|
|
119
|
-
return parts.map((p) => p.trim());
|
|
120
|
-
}
|
|
121
|
-
export function fragmentLineEnds(cores, units) {
|
|
122
|
-
const isMidLineFragment = (core) => {
|
|
123
|
-
if (core === "")
|
|
124
|
-
return false;
|
|
125
|
-
if (units.some((u) => u.core === core))
|
|
126
|
-
return false;
|
|
127
|
-
return units.some((u) => {
|
|
128
|
-
const idx = u.raw.indexOf(core);
|
|
129
|
-
return idx > 0 && idx + core.length < u.raw.length;
|
|
130
|
-
});
|
|
131
|
-
};
|
|
132
|
-
const ends = [];
|
|
133
|
-
if (cores.length > 0 && isMidLineFragment(cores[0]))
|
|
134
|
-
ends.push(0);
|
|
135
|
-
if (cores.length > 1 && isMidLineFragment(cores[cores.length - 1]))
|
|
136
|
-
ends.push(1);
|
|
137
|
-
return ends;
|
|
138
|
-
}
|
|
139
|
-
export function isMisalignedMultilineFragment(content, start, oldTextLF) {
|
|
140
|
-
if (!oldTextLF.includes("\n"))
|
|
141
|
-
return false;
|
|
142
|
-
const end = start + oldTextLF.length;
|
|
143
|
-
const startsAtLineStart = start === 0 || content[start - 1] === "\n";
|
|
144
|
-
const endsAtLineBoundary = end === content.length || content[end] === "\n" || content[end - 1] === "\n";
|
|
145
|
-
return !(startsAtLineStart && endsAtLineBoundary);
|
|
146
|
-
}
|
|
147
|
-
class SoftEditMatchError extends Error {
|
|
148
|
-
constructor(message) {
|
|
149
|
-
super(message);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
function locateReplacement(normalizedContent, oldTextLF, newTextLF, path, editIndex, lang = "en") {
|
|
153
|
-
if (oldTextLF.length === 0) {
|
|
154
|
-
throw new SoftEditMatchError(pick(lang, `edits[${editIndex}].oldText 在 ${path} 中不能为空。`, `edits[${editIndex}].oldText must not be empty in ${path}.`, "editsoft.oldtext.empty", { editIndex, path }));
|
|
155
|
-
}
|
|
156
|
-
const exactIdx = normalizedContent.indexOf(oldTextLF);
|
|
157
|
-
const exactMisaligned = exactIdx !== -1 && isMisalignedMultilineFragment(normalizedContent, exactIdx, oldTextLF);
|
|
158
|
-
if (exactIdx !== -1 && !exactMisaligned) {
|
|
159
|
-
const occurrences = normalizedContent.split(oldTextLF).length - 1;
|
|
160
|
-
if (occurrences > 1) {
|
|
161
|
-
throw new SoftEditMatchError(pick(lang, `在 ${path} 中找到 ${occurrences} 处 edits[${editIndex}].oldText。每个 oldText 必须唯一,请提供更多上下文。`, `Found ${occurrences} occurrences of edits[${editIndex}].oldText in ${path}. Each oldText must be unique. Please provide more context to make it unique.`, "editsoft.exact.not.unique", { path, occurrences, editIndex }));
|
|
162
|
-
}
|
|
163
|
-
return { start: exactIdx, end: exactIdx + oldTextLF.length, insertText: newTextLF };
|
|
164
|
-
}
|
|
165
|
-
const cores = oldTextCores(oldTextLF);
|
|
166
|
-
if (cores.length === 0) {
|
|
167
|
-
throw new SoftEditMatchError(pick(lang, `edits[${editIndex}].oldText 在 ${path} 中实际为空。`, `edits[${editIndex}].oldText is effectively empty in ${path}.`, "editsoft.oldtext.blank", { editIndex, path }));
|
|
168
|
-
}
|
|
169
|
-
const units = splitLineUnits(normalizedContent);
|
|
170
|
-
const k = cores.length;
|
|
171
|
-
const starts = [];
|
|
172
|
-
for (let i = 0; i + k <= units.length; i++) {
|
|
173
|
-
let ok = true;
|
|
174
|
-
for (let j = 0; j < k; j++) {
|
|
175
|
-
if (units[i + j].core !== cores[j]) {
|
|
176
|
-
ok = false;
|
|
177
|
-
break;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
if (ok)
|
|
181
|
-
starts.push(i);
|
|
182
|
-
}
|
|
183
|
-
if (starts.length === 0) {
|
|
184
|
-
if (exactMisaligned || fragmentLineEnds(cores, units).length > 0) {
|
|
185
|
-
throw new SoftEditMatchError(pick(lang, `在 ${path} 中找不到该文本:edits[${editIndex}].oldText 跨越多行但首/尾没有落在行边界上(首行或末行只是文件中某行的一部分),而本工具按**整行**匹配。请让 oldText 的每一行都是完整行——行首缩进可以省略,但行内容必须完整。`, `Could not find the text in ${path}: edits[${editIndex}].oldText spans multiple lines but its start/end do not fall on line boundaries (its first or last line is only part of a file line), and this tool matches whole lines. Make every line of oldText a complete line — leading indentation may be omitted, but the line content must be complete.`, "editsoft.fragment.not.supported", { path, editIndex }));
|
|
186
|
-
}
|
|
187
|
-
throw new SoftEditMatchError(pick(lang, `在 ${path} 中找不到该文本(精确或忽略缩进均未命中)。oldText 必须与文件的行内容一致;行首空白差异会被忽略,但实际内容必须完全相同。`, `Could not find the text (exact or indentation-insensitive) in ${path}. The oldText must match the file's line content; leading-whitespace differences are ignored, but the actual content must be identical.`, "editsoft.match.not.found", { path }));
|
|
188
|
-
}
|
|
189
|
-
if (starts.length > 1) {
|
|
190
|
-
throw new SoftEditMatchError(pick(lang, `在 ${path} 中找到 ${starts.length} 处忽略缩进的 edits[${editIndex}].oldText。文本必须唯一,请提供更多上下文。`, `Found ${starts.length} indentation-insensitive occurrences of edits[${editIndex}].oldText in ${path}. The text must be unique. Please provide more context to make it unique.`, "editsoft.match.not.unique", { path, "starts.length": starts.length, editIndex }));
|
|
191
|
-
}
|
|
192
|
-
const li = starts[0];
|
|
193
|
-
const ri = li + k;
|
|
194
|
-
const spanStart = units[li].start;
|
|
195
|
-
const spanEnd = units[ri - 1].end;
|
|
196
|
-
const lastNewline = units[ri - 1].newline;
|
|
197
|
-
let insertText = newTextLF;
|
|
198
|
-
if (lastNewline === "\n" && !insertText.endsWith("\n"))
|
|
199
|
-
insertText += "\n";
|
|
200
|
-
return { start: spanStart, end: spanEnd, insertText };
|
|
201
|
-
}
|
|
202
|
-
export function applySoftEdits(normalizedContent, edits, path, lang = "en") {
|
|
203
|
-
const replacements = [];
|
|
204
|
-
for (let i = 0; i < edits.length; i++) {
|
|
205
|
-
const oldTextLF = normalizeToLF(edits[i].oldText);
|
|
206
|
-
const newTextLF = normalizeToLF(edits[i].newText);
|
|
207
|
-
replacements.push(locateReplacement(normalizedContent, oldTextLF, newTextLF, path, i, lang));
|
|
208
|
-
}
|
|
209
|
-
const sorted = [...replacements].sort((a, b) => a.start - b.start);
|
|
210
|
-
for (let i = 1; i < sorted.length; i++) {
|
|
211
|
-
if (sorted[i - 1].end > sorted[i].start) {
|
|
212
|
-
throw new SoftEditMatchError(pick(lang, `在 ${path} 中的 edits 重叠。请合并为一个 edit 或定位到不相交的区域。`, `edits overlap in ${path}. Merge them into one edit or target disjoint regions.`, "editsoft.edits.overlap", { path }));
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
let result = normalizedContent;
|
|
216
|
-
for (let i = sorted.length - 1; i >= 0; i--) {
|
|
217
|
-
const r = sorted[i];
|
|
218
|
-
result = result.slice(0, r.start) + r.insertText + result.slice(r.end);
|
|
219
|
-
}
|
|
220
|
-
if (result === normalizedContent) {
|
|
221
|
-
throw new SoftEditMatchError(pick(lang, `${path} 没有变化。替换产生了完全相同的内容。`, `No changes made to ${path}. The replacement produced identical content.`, "editsoft.result.identical", { path }));
|
|
222
|
-
}
|
|
223
|
-
return { baseContent: normalizedContent, newContent: result };
|
|
224
|
-
}
|
|
225
|
-
export function makeEditSoftTool(fallbackCwd, getLang) {
|
|
226
|
-
return defineTool({
|
|
227
|
-
name: SOFT_EDIT_TOOL_NAME,
|
|
228
|
-
label: "Edit (indentation-insensitive)",
|
|
229
|
-
description: "Edit a single file with text replacement tolerant of indentation: oldText matches by trimmed line content, " +
|
|
230
|
-
"so leading-whitespace drift (common in JS/JSON) does not fail the edit.",
|
|
231
|
-
promptSnippet: "edit a file when whitespace/indentation makes the built-in edit fail",
|
|
232
|
-
promptGuidelines: [
|
|
233
|
-
"Use edit_soft when edit rejects oldText on an indentation/spacing mismatch",
|
|
234
|
-
"Keep edits[].oldText as small as possible while still being unique; merge nearby changes into one edit",
|
|
235
|
-
],
|
|
236
|
-
parameters: editSoftSchema,
|
|
237
|
-
prepareArguments: prepareSoftEditArguments,
|
|
238
|
-
async execute(_toolCallId, input, signal, _onUpdate, ctx) {
|
|
239
|
-
const lang = getLang?.() ?? "en";
|
|
240
|
-
const { path, edits } = input;
|
|
241
|
-
if (!Array.isArray(edits) || edits.length === 0) {
|
|
242
|
-
throw new Error(pick(lang, "edit_soft 输入无效:edits 必须包含至少一个替换。", "edit_soft input is invalid. edits must contain at least one replacement.", "editsoft.input.no.edits"));
|
|
243
|
-
}
|
|
244
|
-
const cwd = typeof ctx?.cwd === "string" ? ctx.cwd : fallbackCwd;
|
|
245
|
-
const absolutePath = resolveToCwd(path, cwd);
|
|
246
|
-
const remoteOps = createRemoteSdkOperations(cwd);
|
|
247
|
-
return withFileMutationQueue(absolutePath, async () => {
|
|
248
|
-
const throwIfAborted = () => {
|
|
249
|
-
if (signal?.aborted)
|
|
250
|
-
throw new Error(pick(lang, "操作已中止", "Operation aborted", "editsoft.operation.aborted"));
|
|
251
|
-
};
|
|
252
|
-
throwIfAborted();
|
|
253
|
-
try {
|
|
254
|
-
if (remoteOps) {
|
|
255
|
-
await remoteOps.edit.access(absolutePath);
|
|
256
|
-
}
|
|
257
|
-
else {
|
|
258
|
-
await access(absolutePath, constants.R_OK | constants.W_OK);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
catch (error) {
|
|
262
|
-
throwIfAborted();
|
|
263
|
-
const errorMessage = error instanceof Error && "code" in error ? `Error code: ${error.code}` : String(error);
|
|
264
|
-
throw new Error(pick(lang, `无法编辑文件:${path}。${errorMessage}。`, `Could not edit file: ${path}. ${errorMessage}.`, "editsoft.file.access.failed", { path, errorMessage }));
|
|
265
|
-
}
|
|
266
|
-
throwIfAborted();
|
|
267
|
-
const buffer = remoteOps ? await remoteOps.edit.readFile(absolutePath) : await readFile(absolutePath);
|
|
268
|
-
const rawContent = buffer.toString("utf-8");
|
|
269
|
-
throwIfAborted();
|
|
270
|
-
const { bom, text: content } = splitBom(rawContent);
|
|
271
|
-
const originalEnding = detectLineEnding(content);
|
|
272
|
-
const normalizedContent = normalizeToLF(content);
|
|
273
|
-
const { baseContent, newContent } = applySoftEdits(normalizedContent, edits, path, lang);
|
|
274
|
-
throwIfAborted();
|
|
275
|
-
const finalContent = bom + restoreLineEndings(newContent, originalEnding);
|
|
276
|
-
if (remoteOps) {
|
|
277
|
-
await remoteOps.edit.writeFile(absolutePath, finalContent);
|
|
278
|
-
}
|
|
279
|
-
else {
|
|
280
|
-
await writeFile(absolutePath, finalContent, "utf-8");
|
|
281
|
-
}
|
|
282
|
-
throwIfAborted();
|
|
283
|
-
const diffResult = generateDiffString(baseContent, newContent);
|
|
284
|
-
const patch = generateUnifiedPatch(path, baseContent, newContent);
|
|
285
|
-
return {
|
|
286
|
-
content: [
|
|
287
|
-
{
|
|
288
|
-
type: "text",
|
|
289
|
-
text: pick(lang, `已在 ${path} 中替换 ${edits.length} 个块(忽略缩进匹配)。`, `Successfully replaced ${edits.length} block(s) in ${path} (indentation-insensitive).`, "editsoft.replace.done", { path, "edits.length": edits.length }),
|
|
290
|
-
},
|
|
291
|
-
],
|
|
292
|
-
details: { diff: diffResult.diff, patch, firstChangedLine: diffResult.firstChangedLine },
|
|
293
|
-
};
|
|
294
|
-
});
|
|
295
|
-
},
|
|
296
|
-
});
|
|
297
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Sn as t,Ut as n,in as r,mn as i,on as a,t as o,tn as s,wn as c,yt as l}from"./app-globals-CZjFtI4F.js";import{i as u,t as d}from"./react-CR5VJ85Q.js";import{At as f,Bt as p,Lt as m,z as h}from"./index-D_AGu4Zv.js";var g=e(u(),1),_=d();function v(e,t){let n=Math.max(0,Date.now()-e),r=Math.floor(n/6e4);if(r<1)return t(`bgTaskJustNow`);if(r<60)return t(`bgTaskMinutes`,{n:r});let i=Math.floor(r/60);return i<24?t(`bgTaskHours`,{n:i}):t(`bgTaskDays`,{n:Math.floor(i/24)})}function y({servers:e,onClose:u,plugins:d=[],epoch:y=0,send:b,onUiAction:x,autoCleanupMin:S=0}){let C=c(),{locale:w}=t(),[T,E]=(0,g.useState)(new Set),D=e=>E(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n});(0,g.useEffect)(()=>{o({type:`list_bg_servers`})},[]);let O=(0,g.useMemo)(()=>(m(p(d),{locale:w,t:e=>C(e)})[`tasks.panel`]??[]).filter(e=>!e.hidden&&e.source!==`host`&&e.kind!==`divider`),[d,w,C]);return(0,_.jsxs)(f,{className:`bg-task-modal`,onClose:u,showCloseButton:!1,children:[(0,_.jsxs)(`div`,{className:`bg-task-head`,children:[(0,_.jsxs)(`span`,{className:`bg-task-title`,children:[(0,_.jsx)(l,{}),` `,C(`bgTasks`),e.length>0&&(0,_.jsx)(`em`,{className:`bg-task-count`,children:e.length})]}),(0,_.jsxs)(`div`,{className:`bg-task-head-actions`,children:[(0,_.jsx)(`button`,{type:`button`,className:`btn bg-task-head-btn`,title:C(`bgTaskRefresh`),onClick:()=>o({type:`list_bg_servers`}),children:(0,_.jsx)(n,{})}),(0,_.jsx)(`button`,{type:`button`,className:`btn bg-task-head-btn`,title:C(`close`),onClick:u,children:(0,_.jsx)(i,{})})]})]}),e.length===0?(0,_.jsxs)(`div`,{className:`bg-task-empty`,children:[(0,_.jsx)(l,{}),(0,_.jsx)(`span`,{children:C(`bgTasksEmpty`)}),(0,_.jsx)(`small`,{children:C(`bgTasksDesc`)})]}):(0,_.jsx)(`ul`,{className:`bg-task-list`,children:e.map(e=>{let t=!!e.taskId,n=e.taskId??String(e.port);return(0,_.jsxs)(`li`,{className:`bg-task-item`,children:[(0,_.jsx)(`span`,{className:`bg-task-icon`,title:t?e.plugin:C(`bgTaskPort`)}),(0,_.jsxs)(`div`,{className:`bg-task-info`,children:[(0,_.jsxs)(`div`,{className:`bg-task-line1`,children:[t?(0,_.jsxs)(`span`,{className:`bg-task-port`,title:e.taskId,children:[`🧩 `,e.plugin]}):(0,_.jsxs)(`span`,{className:`bg-task-port`,children:[`:`,e.port]}),e.name&&(0,_.jsx)(`span`,{className:`bg-task-name`,children:e.name})]}),(0,_.jsxs)(`div`,{className:`bg-task-line2`,children:[!t&&(0,_.jsxs)(`span`,{children:[C(`bgTaskPid`),` `,e.pid]}),(0,_.jsxs)(`span`,{children:[C(`bgTaskSince`),` `,v(e.since,C)]}),t&&e.status&&(0,_.jsx)(`span`,{className:`bg-task-status`,children:e.status})]}),e.command&&(0,_.jsxs)(`button`,{type:`button`,className:`bg-task-cmd ${T.has(n)?`open`:``}`,title:`${C(`bgTaskCommand`)}: ${e.command}`,onClick:()=>D(n),children:[(0,_.jsx)(r,{}),(0,_.jsx)(`code`,{children:e.command})]})]}),!t&&(0,_.jsx)(`button`,{type:`button`,className:`btn bg-task-keep`,title:e.keep?C(`bgTaskKeepOn`):C(`bgTaskKeep`),"aria-pressed":!!e.keep,onClick:()=>o({type:`set_bg_keep`,port:e.port??0,keep:!e.keep}),children:e.keep?`📌`:`📍`}),(0,_.jsxs)(`button`,{type:`button`,className:`btn bg-task-stop`,title:C(`bgTaskStop`),onClick:()=>o(t?{type:`kill_background_server`,taskId:e.taskId}:{type:`kill_background_server`,port:e.port}),children:[(0,_.jsx)(s,{}),(0,_.jsx)(`span`,{children:C(`bgTaskStop`)})]})]},n)})}),O.map(e=>{let t=d.find(t=>t.id===e.source.slice(7));return e.kind===`view`?t?(0,_.jsx)(`div`,{children:(0,_.jsx)(h,{plugin:t,epoch:y,send:b??(()=>{})})},e.id):null:(0,_.jsx)(`button`,{type:`button`,className:`btn`,title:e.hint??e.label,onClick:()=>x?.(e),children:e.label},e.id)}),(0,_.jsxs)(`div`,{className:`bg-task-foot`,children:[(0,_.jsxs)(`div`,{className:`bg-task-cleanup-bar`,children:[(0,_.jsxs)(`label`,{className:`bg-task-cleanup-field`,title:C(`bgTaskCleanupHint`),children:[(0,_.jsx)(`span`,{className:`bg-task-cleanup-label`,children:C(`bgTaskCleanup`)}),(0,_.jsxs)(`select`,{className:`bg-task-cleanup-select`,value:String(S),onChange:e=>o({type:`set_settings`,bgAutoCleanupMin:Number(e.target.value)}),children:[(0,_.jsx)(`option`,{value:`0`,children:C(`bgTaskCleanupOff`)}),[15,30,60,120].map(e=>(0,_.jsx)(`option`,{value:String(e),children:C(`bgTaskCleanupMinutes`,{n:e})},e))]})]}),(0,_.jsxs)(`button`,{type:`button`,className:`btn bg-task-clean-btn`,title:C(`bgTaskCleanNowHint`),onClick:()=>o({type:`clean_bg_leftovers`}),children:[(0,_.jsx)(a,{}),(0,_.jsx)(`span`,{children:C(`bgTaskCleanNow`)})]})]}),(0,_.jsxs)(`div`,{className:`bg-task-actions-bar`,children:[(0,_.jsxs)(`button`,{type:`button`,className:`btn bg-task-refresh-btn`,title:C(`bgTaskRefresh`),onClick:()=>o({type:`list_bg_servers`}),children:[(0,_.jsx)(n,{}),(0,_.jsx)(`span`,{children:C(`bgTaskRefresh`)})]}),(0,_.jsxs)(`button`,{type:`button`,className:`btn bg-task-stopall`,disabled:e.length===0,title:C(`bgTaskStopAll`),onClick:()=>o({type:`kill_background_servers`}),children:[(0,_.jsx)(s,{}),(0,_.jsx)(`span`,{children:C(`bgTaskStopAll`)})]})]})]})]})}export{y as BgTasksModal};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$ as t,A as n,An as r,Cn as i,H as a,Ht as o,Pn as s,Pt as ee,Qt as te,Sn as ne,Ut as c,Z as l,fn as u,gt as d,kt as f,mn as p,on as m,pt as h,wn as g,xt as re,zn as _}from"./app-globals-CZjFtI4F.js";import{i as v,t as ie}from"./react-CR5VJ85Q.js";import{K as y,Xt as b,bt as x,v as S}from"./index-D_AGu4Zv.js";import{t as C}from"./DeviceExecutionSettings-BoX7-0h7.js";import{n as w,t as ae}from"./GroupWorkItems-BIvZtr10.js";var T=e(v(),1);async function E(e,t){let n=t.sleep??(e=>new Promise(t=>setTimeout(t,e))),r=Date.now()+(t.timeoutMs??18e5),i=e;if(!i||typeof i.id!=`string`||typeof i.fromBootId!=`string`)throw Error(`Invalid Hub upgrade response`);for(;;){if(t.isCurrent&&!t.isCurrent())throw new DOMException(`Hub upgrade view closed`,`AbortError`);if(i.id!==e.id)throw Error(`Hub upgrade job changed`);if(i.state===`failed`)throw Error(i.error||`Hub upgrade failed`);if(i.state===`succeeded`){if(!i.targetVersion||i.version!==i.targetVersion||!i.bootId||i.bootId===e.fromBootId)throw Error(`Hub upgrade result does not match the new version and process`);return i}if(i.state!==`queued`&&i.state!==`running`)throw Error(`Invalid Hub upgrade state`);if(Date.now()>=r)throw Error(`Hub upgrade timed out; inspect the Hub upgrade log`);if(await n(1500),t.isCurrent&&!t.isCurrent())throw new DOMException(`Hub upgrade view closed`,`AbortError`);try{i=await t.poll(e.id)}catch(e){let t=e.status;if(t&&t<500)throw e}}}var D=ie();function O(e){return!!e&&`mount`in e&&typeof e.mount==`function`}function k({plugin:e,epoch:t,onManageGroups:n}){let a=r(i()),[o,s]=(0,T.useState)(null),[ee,te]=(0,T.useState)(!1),[ne,c]=(0,T.useState)(0),{id:l,name:u,version:d,hasClient:f,error:p,isolated:m}=e??{},h=(0,T.useMemo)(()=>l?{id:l,name:u??l,version:d,hasClient:f??!1,error:p,isolated:m}:void 0,[l,u,d,f,p,m]);(0,T.useEffect)(()=>{let e=!1;if(s(null),te(!1),h&&!h.error&&h.hasClient)return y(h,t,{retry:ne>0}).then(t=>{e||(O(t)?s({info:h,module:t}):te(!0))}),()=>{e=!0}},[h,t,ne]);let g=!h||!h.hasClient;return(0,D.jsxs)(`section`,{className:`dc-card`,"aria-label":a?`外部渠道配置`:`External channel settings`,children:[(0,D.jsxs)(`header`,{className:`dc-card-header`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h2`,{children:a?`GitHub / 飞书渠道`:`GitHub / Feishu channels`}),(0,D.jsx)(`p`,{children:a?`将外部事件映射到群组,由群组 AI 分派任务并跟进工单。`:`Map external events to a group. Its AI delegates tasks and follows up on work items.`})]}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:n,children:a?`管理群组与 AI`:`Manage groups & AI`})]}),g?(0,D.jsx)(`p`,{role:`status`,children:a?`内置渠道模块暂不可用,请重新加载页面或重启主程序。`:`The built-in channel module is temporarily unavailable. Reload this page or restart the application.`}):h.error?(0,D.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:h.error}):ee?(0,D.jsxs)(`div`,{className:`dc-notice is-error`,role:`alert`,children:[(0,D.jsx)(`span`,{children:a?`渠道配置界面加载失败。`:`Channel settings failed to load.`}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>c(e=>e+1),children:a?`重试`:`Retry`})]}):o?(0,D.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,minWidth:0,height:`min(72vh, 900px)`,minHeight:`360px`},children:(0,D.jsx)(S,{entry:o})}):(0,D.jsx)(`p`,{role:`status`,children:a?`正在加载渠道配置…`:`Loading channel settings…`})]})}function A({href:e,children:t}){let n=g(),[r,i]=(0,T.useState)(!1),[a,o]=(0,T.useState)(!1);return(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`a`,{className:`dc-button`,href:e,target:`_blank`,rel:`noopener noreferrer`,onClick:t=>{let n=window.piDesktop;n?.openHub&&(t.preventDefault(),!a&&(o(!0),i(!1),n.openHub(e).then(e=>i(!e),()=>i(!0)).finally(()=>o(!1))))},"aria-busy":a,children:t}),r&&(0,D.jsxs)(`span`,{role:`alert`,children:[n(`deviceHubNetworkError`),` `,(0,D.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,children:e})]})]})}function j(e){if(!M(e.host)||!Number.isInteger(e.port)||e.port<1024||e.port>65535||e.publicUrl.length>2048||/[\s\u0000-\u001f\u007f]/.test(e.publicUrl))return!1;try{let t=new URL(e.publicUrl);return[`http:`,`https:`].includes(t.protocol)&&!!t.hostname&&!t.username&&!t.password&&!t.search&&!t.hash&&t.pathname===`/`&&![`0.0.0.0`,`[::]`].includes(t.hostname)}catch{return!1}}function M(e){if(e===`localhost`)return!0;if(/^(?:\d{1,3}\.){3}\d{1,3}$/.test(e))return e.split(`.`).every(e=>String(Number(e))===e&&Number(e)<=255);if(!e.includes(`:`)||!/^[0-9a-fA-F:.]+$/.test(e))return!1;try{return new URL(`http://[${e}]/`).hostname.startsWith(`[`)}catch{return!1}}function oe(e){try{let t=new URL(e);return[`http:`,`https:`].includes(t.protocol)&&[`localhost`,`127.0.0.1`,`[::1]`].includes(t.hostname)}catch{return!1}}var N=`https://raw.githubusercontent.com/xing-shuyin/pi-web-ui/main/docs/device-center-deployment.md`,P=`https://github.com/xing-shuyin/pi-web-ui/blob/main/docs/device-center-deployment.md`,se=`pi-web-ui hub install --host 0.0.0.0 --port 8790 --public-url http://SERVER_IP:8790 --allow-registration`;function F(e){let t=e=>e.includes(`:`)?M(e)&&![`::`,`::1`].includes(e):/^[\d.]+$/.test(e)?M(e)&&![`0.0.0.0`,`127.0.0.1`].includes(e):e.length<=253&&e.split(`.`).every(e=>/^[a-z\d](?:[a-z\d-]{0,61}[a-z\d])?$/i.test(e))&&e!==`localhost`;if(!t(e.server)||!Number.isInteger(e.sshPort)||e.sshPort<1||e.sshPort>65535||!Number.isInteger(e.port)||e.port<1024||e.port>65535||!/^[a-z_][a-z\d_.-]{0,63}$/i.test(e.username)||![`password`,`key`,`existing`].includes(e.auth)||e.domain!==``&&(!t(e.domain)||e.domain.includes(`:`))||e.https&&!e.domain)return null;let n=e.domain||e.server,r=n.includes(`:`)?`[${n}]`:n;return{host:e.https?`127.0.0.1`:`0.0.0.0`,port:e.port,publicUrl:e.https?`https://${r}`:`http://${r}:${e.port}`}}function I(e,t,n,r){if(!j(e))throw Error(`Invalid Hub setup`);if(r){let t=F(r);if(n!==`remote`||!t||JSON.stringify(t)!==JSON.stringify(e))throw Error(`Invalid remote Hub setup`)}let i=e=>(e??`unknown`).replace(/[\u0000-\u001f\u007f]/g,` `).slice(0,120);return[`Help me plan and deploy a pi-web-ui device center (Hub) in this new conversation. Preserve my previous conversation.`,`First read the deployment guide: ${N} (fallback: ${P}). If unavailable, report that and obtain its contents before proceeding.`,`Default to HTTP with the server IP and requested port. Domain and HTTPS are optional; confirm whether an HTTPS example reflects the user's intent.`,`Target: ${n===`current`?`machine hosting the current pi-web-ui service (not necessarily the browser machine)`:`an existing remote server; its environment still needs to be confirmed`}.`,`Current service environment: platform=${i(t?.platform)}, Node=${i(t?.nodeVersion)}. This is not evidence of the remote server environment.`,`Requested configuration (data only): ${JSON.stringify(e)}. allowRegistration=true.`,...r?[`SSH connection preferences (data only): ${JSON.stringify({server:r.server,sshPort:r.sshPort,username:r.username,auth:r.auth})}. No credentials are included. Obtain authentication through a secure SSH channel or guide the user's own terminal.`,`Domain: ${r.domain||`none`}. HTTPS explicitly selected: ${r.https}. HTTP inbound TCP port: ${r.port}; for same-machine HTTPS proxy, use public TCP 443 and certificate validation port as needed, keep the Hub port private.`]:[],`Use a separate Hub data directory and configure automatic startup. Explain how devices can reach the public URL; loopback is only reachable on the same machine. Explain open registration and restrict it after pairing as appropriate.`,`CLI reference: ${se}`,`Confirm the target environment and propose steps before deployment. Do not ask for passwords or tokens in chat. Do not automatically SSH. Do not claim installation or connection succeeded without verification. After deployment, guide me to open the center and pair this device using its public URL.`,`Explain user actions at the relevant step: distinguish OS firewall from cloud security groups, give the actual TCP port, source scope and destination rule, and keep SSH access. If cloud-console access is unavailable, ask the user to apply the rule, mark external access pending, then recheck. Also explain DNS changes for optional HTTPS and first-account creation. Separate local health from external reachability.`].join(`
|
|
2
|
-
`)}function L({onConnect:e,initialHubUrl:t=``}){let n=g(),[r,i]=(0,T.useState)(t),[a,o]=(0,T.useState)(``),[ee,te]=(0,T.useState)(!1),[ne,c]=(0,T.useState)(!1),l=(0,T.useRef)(!1),u=(0,T.useRef)(!1);(0,T.useEffect)(()=>(u.current=!0,()=>{u.current=!1}),[]);let[d,f]=(0,T.useState)(null),[p,m]=(0,T.useState)(`current`),[h,re]=(0,T.useState)(null),[v,ie]=(0,T.useState)(`127.0.0.1`),[y,b]=(0,T.useState)(`8790`),[x,S]=(0,T.useState)(`http://127.0.0.1:8790`),[C,w]=(0,T.useState)({server:``,sshPort:22,username:`root`,auth:`password`,port:8790,domain:``,https:!1}),ae=F(C),[E,O]=(0,T.useState)(!1),[k,M]=(0,T.useState)(!1),[N,P]=(0,T.useState)(null),[se,L]=(0,T.useState)(!1),[R,ce]=(0,T.useState)(!1),[z,B]=(0,T.useState)(!1),[V,H]=(0,T.useState)(null),U=(0,T.useRef)(null),W=(0,T.useRef)(!1),G=oe(window.location.origin);(0,T.useEffect)(()=>()=>U.current?.abort(),[]);let K=async()=>{if(W.current)return;U.current?.abort();let e=new AbortController;U.current=e,L(!1),ce(!1),B(!1);try{let t=await fetch(_(s(`/api/device-center/setup`)),{credentials:`same-origin`,signal:e.signal});if(!t.ok)throw Error();let n=await t.json();if(!n||typeof n.platform!=`string`||typeof n.nodeVersion!=`string`||typeof n.dataDir!=`string`||typeof n.cliPath!=`string`||!j({host:`127.0.0.1`,port:n.defaultPort,publicUrl:n.defaultPublicUrl}))throw Error();if(e.signal.aborted)return;re(n),n.installation?.installed?(ie(n.installation.host??`127.0.0.1`),b(String(n.installation.port)),S(n.installation.publicUrl??``),i(n.installation.publicUrl??``)):h||(b(String(n.defaultPort)),S(n.defaultPublicUrl))}catch{e.signal.aborted||(L(!0),B(!0))}finally{e.signal.aborted||ce(!0)}},q=async()=>{let e={host:v,port:Number(y),publicUrl:x};if(W.current||!G||!h||!R||z||h.busy||h.installation?.installed||!j(e))return;W.current=!0,U.current?.abort(),O(!0),L(!1),o(``);let t=new AbortController;U.current=t;try{let n=await fetch(_(s(`/api/device-center/setup`)),{credentials:`same-origin`,method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({...e,allowRegistration:!0}),signal:t.signal});if(n.status===409){re(e=>e&&{...e,busy:!0}),W.current=!1,O(!1),await K();return}if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(typeof e.error==`string`?e.error.slice(0,4096):`HTTP ${n.status}`)}let r=await n.json();if(!j({...e,publicUrl:r.publicUrl})||typeof r.output!=`string`)throw Error();t.signal.aborted||H(r)}catch(e){t.signal.aborted||(L(!0),o(e instanceof Error?e.message.slice(0,4096):``))}finally{W.current=!1,t.signal.aborted||O(!1)}},le=async()=>{if(W.current||!G||!h||!R||z||h.busy||E||k)return;W.current=!0,U.current?.abort(),M(!0),L(!1),o(``),P(null);let e=new AbortController;U.current=e;try{let t=await fetch(_(s(`/api/device-center/setup/update`)),{credentials:`same-origin`,method:`POST`,headers:{"Content-Type":`application/json`},signal:e.signal});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(typeof e.error==`string`?e.error.slice(0,4096):`HTTP ${t.status}`)}let r=await t.json();e.signal.aborted||(P(r.output||n(`deviceSetupUpdateSuccess`)),await K())}catch(t){e.signal.aborted||(L(!0),o(t instanceof Error?t.message.slice(0,4096):``))}finally{W.current=!1,e.signal.aborted||M(!1)}},J=h?.installation,ue=!!J?.installed,de=ue&&J.running&&J.owned,Y=p===`remote`?ae:{host:v,port:Number(y),publicUrl:x},X=!!Y&&j(Y);return(0,D.jsxs)(`section`,{className:`dc-onboarding`,children:[(0,D.jsx)(`h3`,{children:n(`deviceSetupWelcome`)}),(0,D.jsx)(`p`,{children:n(`deviceSetupIntro`)}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[(0,D.jsx)(`button`,{className:`dc-button`,disabled:E,"aria-pressed":d===`connect`,onClick:()=>f(`connect`),children:n(`deviceSetupConnect`)}),(0,D.jsx)(`button`,{className:`dc-button`,disabled:E,"aria-pressed":d===`create`,onClick:()=>{f(`create`),!h&&G&&K()},children:n(`deviceSetupCreate`)})]}),d===`connect`&&(0,D.jsxs)(`form`,{onSubmit:t=>{t.preventDefault(),e(r.trim())},children:[(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceHubHubUrl`)}),(0,D.jsx)(`input`,{type:`url`,required:!0,maxLength:2048,value:r,onChange:e=>i(e.target.value),placeholder:`https://hub.example.com`})]}),(0,D.jsx)(`button`,{className:`dc-button is-primary`,disabled:!j({host:`localhost`,port:8790,publicUrl:r.trim()}),children:n(`deviceSetupPair`)})]}),d===`create`&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupTarget`)}),(0,D.jsxs)(`select`,{disabled:E,value:p,onChange:e=>m(e.target.value),children:[(0,D.jsx)(`option`,{value:`current`,children:n(`deviceSetupCurrent`)}),(0,D.jsx)(`option`,{value:`remote`,children:n(`deviceSetupRemote`)})]})]}),(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`p`,{children:n(p===`current`?`deviceSetupCurrentHint`:`deviceSetupRemoteHint`)}),p===`current`&&(0,D.jsxs)(`div`,{className:`dc-setup-plan`,children:[(0,D.jsx)(`strong`,{children:n(`deviceSetupPlan`)}),(0,D.jsx)(`p`,{children:n(`deviceSetupPlanHint`)}),h&&(0,D.jsxs)(`dl`,{children:[(0,D.jsx)(`dt`,{children:n(`deviceSetupEnvironment`)}),(0,D.jsxs)(`dd`,{children:[h.platform,` · Node `,h.nodeVersion]}),(0,D.jsx)(`dt`,{children:n(`deviceSetupDataDir`)}),(0,D.jsx)(`dd`,{children:h.dataDir}),(0,D.jsx)(`dt`,{children:n(`deviceSetupCli`)}),(0,D.jsx)(`dd`,{children:h.cliPath})]}),!G&&(0,D.jsx)(`p`,{role:`status`,children:n(`deviceSetupLocalOnly`)}),(0,D.jsx)(`p`,{children:n(`deviceSetupBackground`)}),ue&&(0,D.jsxs)(`div`,{role:`status`,children:[(0,D.jsx)(`h4`,{children:n(de?`deviceSetupRestored`:`deviceSetupUnhealthy`)}),(0,D.jsx)(`p`,{children:J.publicUrl}),de&&X&&J.publicUrl?(0,D.jsxs)(`div`,{className:`dc-actions`,children:[(0,D.jsx)(A,{href:J.publicUrl,children:n(`deviceHubOpenHub`)}),(0,D.jsx)(`button`,{className:`dc-button`,onClick:()=>e(J.publicUrl),children:n(`deviceSetupPair`)}),G&&(0,D.jsx)(`button`,{className:`dc-button`,disabled:E||k,onClick:()=>void le(),children:n(k?`deviceSetupUpdating`:`deviceSetupUpdate`)})]}):(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`p`,{children:n(`deviceSetupRecovery`)}),(0,D.jsx)(`pre`,{className:`dc-setup-output`,children:`pi-web-ui hub status --json
|
|
3
|
-
pi-web-ui hub --help`}),G&&(0,D.jsx)(`button`,{className:`dc-button is-primary`,disabled:E||k,onClick:()=>void le(),children:n(k?`deviceSetupUpdating`:`deviceSetupUpdate`)})]}),N&&(0,D.jsx)(`pre`,{className:`dc-setup-output`,children:N.slice(0,16e3)})]}),h?.busy&&(0,D.jsx)(`p`,{role:`status`,children:n(`deviceSetupBusy`)}),G&&(0,D.jsx)(`button`,{className:`dc-button`,disabled:E||!R,onClick:()=>void K(),children:n(R?`deviceSetupRetry`:`deviceHubWorking`)})]}),p===`remote`?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`div`,{className:`dc-setup-fields`,children:[(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupServer`)}),(0,D.jsx)(`input`,{autoComplete:`off`,maxLength:253,placeholder:`203.0.113.10`,value:C.server,onChange:e=>w({...C,server:e.target.value.trim()})})]}),(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupSshPort`)}),(0,D.jsx)(`input`,{type:`number`,min:1,max:65535,value:C.sshPort,onChange:e=>w({...C,sshPort:Number(e.target.value)})})]}),(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupUsername`)}),(0,D.jsx)(`input`,{autoComplete:`off`,maxLength:64,value:C.username,onChange:e=>w({...C,username:e.target.value})})]}),(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupAuth`)}),(0,D.jsxs)(`select`,{value:C.auth,onChange:e=>w({...C,auth:e.target.value}),children:[(0,D.jsx)(`option`,{value:`password`,children:n(`deviceSetupAuthPassword`)}),(0,D.jsx)(`option`,{value:`key`,children:n(`deviceSetupAuthKey`)}),(0,D.jsx)(`option`,{value:`existing`,children:n(`deviceSetupAuthExisting`)})]})]}),(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupServicePort`)}),(0,D.jsx)(`input`,{type:`number`,min:1024,max:65535,value:C.port,onChange:e=>w({...C,port:Number(e.target.value)})})]})]}),(0,D.jsx)(`p`,{children:n(`deviceSetupCredentialHint`)}),(0,D.jsxs)(`details`,{children:[(0,D.jsx)(`summary`,{children:n(`deviceSetupOptionalTls`)}),(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupDomain`)}),(0,D.jsx)(`input`,{maxLength:253,placeholder:`hub.example.com`,value:C.domain,onChange:e=>w({...C,domain:e.target.value.trim()})})]}),(0,D.jsxs)(`label`,{children:[(0,D.jsx)(`input`,{type:`checkbox`,checked:C.https,onChange:e=>w({...C,https:e.target.checked})}),` `,n(`deviceSetupEnableHttps`)]}),(0,D.jsx)(`p`,{children:n(`deviceSetupTlsHint`)})]}),(0,D.jsxs)(`p`,{children:[(0,D.jsx)(`strong`,{children:n(`deviceSetupPreview`)}),` `,ae?.publicUrl??n(`deviceSetupPreviewEmpty`)]}),(0,D.jsxs)(`div`,{className:`dc-setup-plan`,children:[(0,D.jsx)(`strong`,{children:n(`deviceSetupUserActions`)}),(0,D.jsx)(`p`,{children:n(`deviceSetupCloudPorts`).replace(`{ports}`,C.https?`443 / 80`:String(C.port))}),(0,D.jsx)(`p`,{children:n(`deviceSetupSourceScope`)}),(0,D.jsx)(`p`,{children:n(`deviceSetupAfterStart`)})]}),(0,D.jsx)(`a`,{href:`https://github.com/xing-shuyin/pi-web-ui/blob/main/docs/device-center-deployment.md`,target:`_blank`,rel:`noopener noreferrer`,children:n(`deviceSetupGuide`)})]}):(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`div`,{className:`dc-setup-fields`,children:[(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupHost`)}),(0,D.jsx)(`input`,{disabled:E||!!V,maxLength:253,value:v,onChange:e=>ie(e.target.value)})]}),(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceSetupPort`)}),(0,D.jsx)(`input`,{disabled:E||!!V,type:`number`,min:1024,max:65535,value:y,onChange:e=>b(e.target.value)})]}),(0,D.jsxs)(`label`,{className:`dc-field`,children:[(0,D.jsx)(`span`,{children:n(`deviceHubHubUrl`)}),(0,D.jsx)(`input`,{disabled:E||!!V,maxLength:2048,value:x,onChange:e=>S(e.target.value)})]})]}),(0,D.jsx)(`p`,{className:`dc-setup-warning`,children:n(`deviceSetupReachable`)})]}),(0,D.jsx)(`p`,{children:n(`deviceSetupRegistration`)}),!X&&(0,D.jsx)(`p`,{role:`alert`,children:n(p===`remote`?`deviceSetupRemoteInvalid`:`deviceSetupInvalid`)}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[p===`current`&&!V&&!ue&&(0,D.jsx)(`button`,{className:`dc-button is-primary`,disabled:E||!G||!h||!R||z||!!h.busy||!X,onClick:()=>void q(),children:n(E?`deviceSetupInstalling`:`deviceSetupInstall`)}),(0,D.jsx)(`button`,{className:`dc-button`,disabled:E||ee||!X,onClick:()=>{if(!X||!Y||l.current)return;l.current=!0,te(!0),c(!1);let e=e=>{l.current=!1,u.current&&(te(!1),c(!e))},t=window.__piWebUiHost;try{t?.startChat({newChat:!0,prompt:I(Y,h,p,p===`remote`?C:void 0),onResult:e})||e(!1)}catch{e(!1)}},children:n(p===`remote`?`deviceSetupStartAi`:`deviceSetupAi`)})]}),(0,D.jsx)(`p`,{children:n(`deviceSetupAiHint`)}),ee&&(0,D.jsx)(`p`,{role:`status`,children:n(`deviceSetupAiCreating`)}),ne&&(0,D.jsx)(`p`,{role:`alert`,children:n(`deviceSetupAiFailed`)})]})]}),se&&(0,D.jsxs)(`div`,{role:`alert`,children:[(0,D.jsx)(`p`,{children:n(`deviceSetupFailed`)}),a&&(0,D.jsx)(`pre`,{className:`dc-setup-output`,children:a})]}),V&&(0,D.jsxs)(`div`,{role:`status`,children:[(0,D.jsx)(`h4`,{children:n(`deviceSetupSuccess`)}),(0,D.jsx)(`pre`,{className:`dc-setup-output`,children:V.output.slice(0,16e3)}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[(0,D.jsx)(A,{href:V.publicUrl,children:n(`deviceHubOpenHub`)}),(0,D.jsx)(`button`,{className:`dc-button is-primary`,onClick:()=>e(V.publicUrl),children:n(`deviceSetupPair`)})]})]})]})}var R=`pi-web-ui:device-groups-changed`;function ce(e){window.dispatchEvent(new CustomEvent(`pi-web-ui:device-group-open`,{detail:{roomId:e}}))}async function z(e,t,n){let r=await fetch(_(s(`/api/device-center/${e}`)),{method:n?`POST`:`GET`,credentials:`same-origin`,signal:t,...n?{headers:{"Content-Type":`application/json`},body:JSON.stringify(n)}:{}}),i=await r.json().catch(()=>({}));if(!r.ok)throw Error(i.error||i.message||`Request failed (${r.status})`);return i}function B({bindingKey:e=``}){return(0,D.jsx)(V,{},e)}function V(){let{locale:e}=ne(),t=r(e),[i,a]=(0,T.useState)([]),[s,ee]=(0,T.useState)([]),[te,d]=(0,T.useState)(!0),[h,g]=(0,T.useState)(``),[re,_]=(0,T.useState)(``),[v,ie]=(0,T.useState)(0),[y,b]=(0,T.useState)(!1),[x,S]=(0,T.useState)(``),[C,E]=(0,T.useState)([]),[O,k]=(0,T.useState)(``),[A,j]=(0,T.useState)(null),[M,oe]=(0,T.useState)([]),[N,P]=(0,T.useState)(``),[se,F]=(0,T.useState)(null),[I,L]=(0,T.useState)(``),[B,V]=(0,T.useState)(!1),[H,U]=(0,T.useState)(null),W=i.find(e=>e.id===H?.roomId),G=(0,T.useRef)(0),K=(0,T.useRef)(null),q=(0,T.useRef)(null);function le(){++G.current,K.current?.abort(),ie(e=>e+1)}function J(){q.current?.abort();let e=new AbortController;return q.current=e,e}(0,T.useEffect)(()=>()=>q.current?.abort(),[]),(0,T.useEffect)(()=>{let e=++G.current,t=new AbortController;K.current=t;async function n(){try{let[n,r]=await Promise.all([z(`rooms`,t.signal),z(`bots`,t.signal)]);if(G.current!==e||t.signal.aborted)return;let i=Array.isArray(n.rooms)?n.rooms:[];a(i),U(e=>e&&i.some(t=>t.id===e.roomId)?e:null),ee(Array.isArray(r.bots)?r.bots:[]),g(``)}catch(n){G.current===e&&!t.signal.aborted&&g(n instanceof Error?n.message:String(n))}finally{G.current===e&&!t.signal.aborted&&d(!1)}}return n(),()=>{t.abort()}},[v]),(0,T.useEffect)(()=>{let e=()=>le();return window.addEventListener(R,e),()=>window.removeEventListener(R,e)},[]);async function ue(e){if(e.preventDefault(),!x.trim()||B)return;V(!0),g(``),_(``);let n=J();try{let e=C.includes(O)?O:``,r=await z(`rooms`,n.signal,{name:x.trim(),botIds:C,...e?{primaryBotId:e}:{}});if(n.signal.aborted)return;a(e=>[...e.filter(e=>e.id!==r.room.id),r.room]),b(!1),S(``),E([]),k(``),_(t?`群聊创建成功`:`Group created successfully`),window.dispatchEvent(new CustomEvent(R))}catch(e){n.signal.aborted||g(e instanceof Error?e.message:String(e))}finally{n.signal.aborted||V(!1)}}function de(e){j(e.id),oe([...e.botIds]),P(e.primaryBotId??``),F(null),b(!1),g(``),_(``)}async function Y(e){if(B)return;V(!0),g(``),_(``);let n=J();try{let r=M.includes(N)?N:null,i=await z(`rooms/${encodeURIComponent(e)}/members`,n.signal,{botIds:M,primaryBotId:r});if(n.signal.aborted)return;a(t=>t.map(t=>t.id===e?i.room:t)),j(null),_(t?`成员设置已保存`:`Members updated successfully`),window.dispatchEvent(new CustomEvent(R))}catch(e){n.signal.aborted||g(e instanceof Error?e.message:String(e))}finally{n.signal.aborted||V(!1)}}async function X(e){if(!I.trim()||B)return;V(!0),g(``),_(``);let n=J();try{if(await z(`rooms/${encodeURIComponent(e)}/rename`,n.signal,{name:I.trim()}),n.signal.aborted)return;a(t=>t.map(t=>t.id===e?{...t,name:I.trim()}:t)),F(null),_(t?`群聊名称已更新`:`Group renamed successfully`),window.dispatchEvent(new CustomEvent(R))}catch(e){n.signal.aborted||g(e instanceof Error?e.message:String(e))}finally{n.signal.aborted||V(!1)}}async function Z(e){if(B||!window.confirm(t?`确定删除群聊“${e.name}”?`:`Are you sure you want to delete "${e.name}"?`))return;V(!0),g(``),_(``);let n=J();try{if(await z(`rooms/${encodeURIComponent(e.id)}/delete`,n.signal,{}),n.signal.aborted)return;U(t=>t?.roomId===e.id?null:t),a(t=>t.filter(t=>t.id!==e.id)),A===e.id&&j(null),se===e.id&&F(null),_(t?`群聊已删除`:`Group deleted successfully`),window.dispatchEvent(new CustomEvent(R))}catch(e){n.signal.aborted||g(e instanceof Error?e.message:String(e))}finally{n.signal.aborted||V(!1)}}return(0,D.jsxs)(`section`,{className:`dc-card`,"aria-label":t?`群聊列表`:`Group list`,children:[(0,D.jsxs)(`div`,{className:`dc-card-header`,children:[(0,D.jsx)(`span`,{className:`dc-icon`,children:(0,D.jsx)(u,{"aria-hidden":!0})}),(0,D.jsxs)(`div`,{children:[(0,D.jsxs)(`h2`,{children:[t?`群聊列表`:`Group List`,` · `,i.length]}),(0,D.jsx)(`p`,{children:t?`管理群聊与成员 Bot,在此配置协作群组或直接进入聊天。`:`Manage groups and member Bots. Configure collaboration groups or open chats here.`})]}),(0,D.jsxs)(`div`,{className:`dc-actions`,style:{marginInlineStart:`auto`},children:[(0,D.jsxs)(`button`,{type:`button`,className:`dc-button is-primary`,disabled:B,onClick:()=>{b(e=>!e),j(null),F(null),S(``),E([]),k(``)},children:[(0,D.jsx)(o,{"aria-hidden":!0}),t?`新建群聊`:`Create Group`]}),(0,D.jsx)(`button`,{type:`button`,className:`dc-icon-button`,"aria-label":t?`刷新群聊`:`Refresh groups`,onClick:le,children:(0,D.jsx)(c,{})})]})]}),h&&(0,D.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:h}),re&&(0,D.jsxs)(`p`,{className:`dc-notice is-success`,role:`status`,children:[(0,D.jsx)(n,{"aria-hidden":!0}),re]}),y&&(0,D.jsxs)(`form`,{className:`dc-card`,style:{marginBottom:`16px`,background:`var(--bg)`,border:`1px solid var(--border)`},onSubmit:ue,children:[(0,D.jsxs)(`div`,{className:`dg-heading`,style:{marginBottom:`12px`},children:[(0,D.jsx)(`h3`,{children:t?`新建群聊`:`Create Group`}),(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>b(!1),disabled:B,children:[(0,D.jsx)(p,{"aria-hidden":!0}),t?`关闭`:`Close`]})]}),(0,D.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`12px`},children:[(0,D.jsx)(`label`,{htmlFor:`dg-manager-new-name`,children:t?`群名称`:`Group Name`}),(0,D.jsx)(`input`,{id:`dg-manager-new-name`,type:`text`,required:!0,maxLength:80,value:x,placeholder:t?`输入群名称,如:研发协作群`:`Enter group name`,onChange:e=>S(e.target.value),disabled:B,style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`}})]}),(0,D.jsxs)(`div`,{style:{marginBottom:`12px`},children:[(0,D.jsx)(`label`,{style:{display:`block`,marginBottom:`6px`,fontSize:`12px`,color:`var(--text-dim)`},children:t?`选择成员 Bot`:`Select Member Bots`}),(0,D.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`6px`,maxHeight:`160px`,overflowY:`auto`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`8px`,background:`var(--bg-elev)`},children:s.length===0?(0,D.jsx)(`p`,{style:{margin:0,fontSize:`12px`,color:`var(--text-faint)`},children:t?`暂无可用 Bot,请先创建 Bot。`:`No Bots available. Please create a Bot first.`}):s.map(e=>(0,D.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,cursor:`pointer`,fontSize:`12px`},children:[(0,D.jsx)(`input`,{type:`checkbox`,checked:C.includes(e.id),disabled:B||!e.enabled,onChange:t=>{E(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}}),(0,D.jsxs)(`span`,{children:[(0,D.jsx)(`strong`,{children:e.name}),(0,D.jsxs)(`small`,{style:{color:`var(--text-faint)`,marginInlineStart:`6px`},children:[e.online?t?`在线`:`Online`:t?`离线`:`Offline`,e.enabled?``:t?` · 已禁用`:` · Disabled`]})]})]},e.id))})]}),C.length>0&&(0,D.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`16px`},children:[(0,D.jsx)(`label`,{htmlFor:`dg-manager-new-primary`,children:t?`原主 Bot(Router 未启用时)`:`Legacy primary Bot (when Router is disabled)`}),(0,D.jsxs)(`select`,{id:`dg-manager-new-primary`,value:C.includes(O)?O:``,onChange:e=>k(e.target.value),disabled:B,style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`},children:[(0,D.jsx)(`option`,{value:``,children:t?`不设置(需 @ Bot)`:`None (mention a Bot)`}),s.filter(e=>C.includes(e.id)).map(e=>(0,D.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[(0,D.jsxs)(`button`,{type:`submit`,className:`dc-button is-primary`,disabled:B||!x.trim(),children:[(0,D.jsx)(n,{"aria-hidden":!0}),B?t?`创建中…`:`Creating…`:t?`创建群聊`:`Create`]}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>b(!1),disabled:B,children:t?`取消`:`Cancel`})]})]}),A&&(0,D.jsxs)(`div`,{className:`dc-card`,style:{marginBottom:`16px`,background:`var(--bg)`,border:`1px solid var(--border)`},children:[(0,D.jsxs)(`div`,{className:`dg-heading`,style:{marginBottom:`12px`},children:[(0,D.jsxs)(`h3`,{children:[t?`管理成员`:`Manage Members`,` · `,i.find(e=>e.id===A)?.name]}),(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>j(null),disabled:B,children:[(0,D.jsx)(p,{"aria-hidden":!0}),t?`关闭`:`Close`]})]}),(0,D.jsxs)(`div`,{style:{marginBottom:`12px`},children:[(0,D.jsx)(`label`,{style:{display:`block`,marginBottom:`6px`,fontSize:`12px`,color:`var(--text-dim)`},children:t?`选择成员 Bot`:`Select Member Bots`}),(0,D.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`6px`,maxHeight:`160px`,overflowY:`auto`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`8px`,background:`var(--bg-elev)`},children:s.length===0?(0,D.jsx)(`p`,{style:{margin:0,fontSize:`12px`,color:`var(--text-faint)`},children:t?`暂无可用 Bot`:`No Bots available`}):s.map(e=>(0,D.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,cursor:`pointer`,fontSize:`12px`},children:[(0,D.jsx)(`input`,{type:`checkbox`,checked:M.includes(e.id),disabled:B,onChange:t=>{oe(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}}),(0,D.jsxs)(`span`,{children:[(0,D.jsx)(`strong`,{children:e.name}),(0,D.jsxs)(`small`,{style:{color:`var(--text-faint)`,marginInlineStart:`6px`},children:[e.online?t?`在线`:`Online`:t?`离线`:`Offline`,e.enabled?``:t?` · 已禁用`:` · Disabled`]})]})]},e.id))})]}),!i.find(e=>e.id===A)?.router?.enabled&&(0,D.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`16px`},children:[(0,D.jsx)(`label`,{htmlFor:`dg-manager-edit-primary`,children:t?`原主 Bot(Router 未启用时)`:`Legacy primary Bot (when Router is disabled)`}),(0,D.jsxs)(`select`,{id:`dg-manager-edit-primary`,value:M.includes(N)?N:``,onChange:e=>P(e.target.value),disabled:B,style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`},children:[(0,D.jsx)(`option`,{value:``,children:t?`不设置(需 @ Bot)`:`None (mention a Bot)`}),s.filter(e=>M.includes(e.id)).map(e=>(0,D.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[(0,D.jsxs)(`button`,{type:`button`,className:`dc-button is-primary`,disabled:B,onClick:()=>void Y(A),children:[(0,D.jsx)(n,{"aria-hidden":!0}),B?t?`保存中…`:`Saving…`:t?`保存成员设置`:`Save Members`]}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>j(null),disabled:B,children:t?`取消`:`Cancel`})]})]}),te&&(0,D.jsx)(`p`,{role:`status`,children:t?`加载中…`:`Loading…`}),!te&&i.length===0&&(0,D.jsx)(`p`,{style:{color:`var(--text-faint)`,fontSize:`13px`,padding:`12px 0`},children:t?`还没有群聊,点击上方“新建群聊”开始协作。`:`No groups yet. Click 'Create Group' above to get started.`}),(0,D.jsx)(`div`,{className:`dd-list`,children:i.map(e=>{let r=se===e.id,i=s.filter(t=>e.botIds.includes(t.id)),a=s.find(t=>t.id===e.primaryBotId);return(0,D.jsxs)(`div`,{className:`dd-device`,style:r?{flexWrap:`wrap`}:void 0,children:[(0,D.jsx)(`span`,{className:`dc-device-icon`,children:(0,D.jsx)(u,{"aria-hidden":!0})}),(0,D.jsxs)(`div`,{className:`dd-identity`,style:{flex:1,minWidth:`200px`},children:[(0,D.jsx)(`strong`,{children:e.name}),(0,D.jsxs)(`span`,{style:{display:`flex`,gap:`8px`,flexWrap:`wrap`,alignItems:`center`},children:[(0,D.jsx)(`span`,{children:t?`${e.botIds.length} 个 Bot${i.length?`: ${i.map(e=>e.name).join(`, `)}`:``}`:`${e.botIds.length} Bots${i.length?`: ${i.map(e=>e.name).join(`, `)}`:``}`}),e.router?.enabled&&(0,D.jsxs)(`span`,{children:[`AI Router · `,e.router.deviceId,` · `,e.router.model,` · `,e.router.thinkingLevel]}),!e.router?.enabled&&a&&(0,D.jsx)(`span`,{style:{color:`var(--accent)`},children:t?`[主 Bot: ${a.name}]`:`[Primary: ${a.name}]`})]})]}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[(0,D.jsxs)(`button`,{type:`button`,className:`dc-button is-primary`,title:t?`打开聊天`:`Open chat`,onClick:()=>ce(e.id),children:[(0,D.jsx)(f,{"aria-hidden":!0}),t?`打开聊天`:`Open chat`]}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button`,"aria-expanded":H?.roomId===e.id&&H.kind===`router`,onClick:()=>U({roomId:e.id,kind:`router`}),children:`AI Router`}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button`,"aria-expanded":H?.roomId===e.id&&H.kind===`work`,onClick:()=>U({roomId:e.id,kind:`work`}),children:t?`工单与运行`:`Work items & runs`}),(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,title:t?`管理成员`:`Manage members`,onClick:()=>de(e),children:[(0,D.jsx)(u,{"aria-hidden":!0}),t?`管理成员`:`Members`]}),(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,title:t?`重命名`:`Rename`,onClick:()=>{r?F(null):(F(e.id),L(e.name))},children:[(0,D.jsx)(l,{"aria-hidden":!0}),t?`重命名`:`Rename`]}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button is-danger`,title:t?`删除群聊`:`Delete group`,disabled:B,onClick:()=>void Z(e),children:(0,D.jsx)(m,{"aria-hidden":!0})})]}),r&&(0,D.jsxs)(`form`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,width:`100%`,paddingTop:`8px`,paddingBottom:`4px`},onSubmit:t=>{t.preventDefault(),X(e.id)},children:[(0,D.jsx)(`input`,{type:`text`,maxLength:80,autoFocus:!0,disabled:B,value:I,onChange:e=>L(e.target.value),placeholder:t?`输入新群名称`:`Enter new name`,style:{flex:1,minWidth:`180px`,background:`var(--bg)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`12px`}}),(0,D.jsxs)(`button`,{type:`submit`,className:`dc-button is-primary`,disabled:B||!I.trim(),children:[(0,D.jsx)(n,{"aria-hidden":!0}),t?`保存`:`Save`]}),(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:B,onClick:()=>F(null),children:[(0,D.jsx)(p,{"aria-hidden":!0}),t?`取消`:`Cancel`]})]})]},e.id)})}),W&&H&&(0,D.jsxs)(`section`,{className:`dc-card`,"aria-label":t?`群组设置`:`Group settings`,children:[(0,D.jsxs)(`div`,{className:`dg-heading`,children:[(0,D.jsx)(`h3`,{children:W.name}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[(0,D.jsx)(`button`,{type:`button`,className:`dc-button${H.kind===`router`?` is-primary`:``}`,"aria-pressed":H.kind===`router`,onClick:()=>U({roomId:W.id,kind:`router`}),children:`AI Router`}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button${H.kind===`work`?` is-primary`:``}`,"aria-pressed":H.kind===`work`,onClick:()=>U({roomId:W.id,kind:`work`}),children:t?`工单与运行`:`Work items & runs`}),(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>U(null),children:[(0,D.jsx)(p,{"aria-hidden":!0}),t?`关闭`:`Close`]})]})]}),H.kind===`router`?(0,D.jsx)(w,{roomId:W.id,router:W.router,disabled:B,onSaved:le},W.id):(0,D.jsx)(ae,{roomId:W.id,disabled:B},W.id)]})]})}var H=class extends Error{status;constructor(e,t){super(t),this.status=e}};function U(e){try{let t=new URL(e);return[`http:`,`https:`].includes(t.protocol)&&!t.username&&!t.password?t.href:null}catch{return null}}function W(){let e=g(),t=i().startsWith(`zh`),[n,r]=(0,T.useState)(null),[a,o]=(0,T.useState)(!1),[te,ne]=(0,T.useState)(!1),[l,u]=(0,T.useState)(!1),[d,f]=(0,T.useState)(!1),p=(0,T.useRef)(0),m=(0,T.useRef)(null);async function h(e,t){if(m.current)return;let n=++p.current,i=new AbortController;m.current=i,o(!0),ne(!1);try{let a=await fetch(_(s(`/api/device-desktop/local/${e}`)),{method:t?`POST`:`GET`,credentials:`same-origin`,signal:i.signal,...t?{headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}:{}});if(p.current!==n||i.signal.aborted)return;if(a.status===403){u(!0),r(null);return}if(!a.ok)throw Error(`Request failed`);let o=await a.json();if(p.current!==n||i.signal.aborted)return;if(e===`permissions`){if(typeof o?.screen!=`boolean`||typeof o?.accessibility!=`boolean`)throw Error(`Invalid permission status`);r(e=>e&&{...e,permissions:{supported:!0,screen:o.screen,accessibility:o.accessibility}}),f(!0)}else{if(typeof o?.os!=`string`||typeof o.enabled!=`boolean`||typeof o.environmentEnabled!=`boolean`||typeof o.supported!=`boolean`)throw Error(`Invalid desktop status`);r(o)}}catch{p.current===n&&!i.signal.aborted&&ne(!0)}finally{p.current===n&&!i.signal.aborted&&(m.current=null,o(!1))}}return(0,T.useEffect)(()=>(h(`status`),()=>{p.current++,m.current?.abort(),m.current=null}),[]),(0,D.jsxs)(`section`,{className:`dc-card`,"aria-label":t?`本机远程桌面`:`Local remote desktop`,"aria-busy":a,children:[(0,D.jsxs)(`div`,{className:`dc-card-header`,children:[(0,D.jsx)(`span`,{className:`dc-icon`,children:(0,D.jsx)(ee,{"aria-hidden":!0})}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h2`,{children:t?`本机远程桌面`:`Local remote desktop`}),(0,D.jsx)(`p`,{children:t?`管理这台设备的远程桌面与系统权限,无需连接设备中心。`:`Manage remote desktop and system permissions on this device, even while the device center is offline.`})]})]}),l?(0,D.jsx)(`p`,{role:`status`,children:t?`请在设备本机打开此页面以管理远程桌面权限。`:`Open this page on the device itself to manage remote desktop permissions.`}):(0,D.jsxs)(D.Fragment,{children:[n&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`div`,{className:`dc-permission-row`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h3`,{id:`dc-desktop-label`,children:t?`启用远程桌面`:`Enable remote desktop`}),(0,D.jsx)(`p`,{children:n.enabled?t?`已启用`:`Enabled`:t?`未启用`:`Disabled`})]}),(0,D.jsx)(`button`,{type:`button`,className:`dc-toggle${n.enabled?` is-on`:``}`,role:`switch`,"aria-checked":n.enabled,"aria-labelledby":`dc-desktop-label`,disabled:a||n.environmentEnabled||!n.supported&&!n.enabled,onClick:()=>void h(`enable`,{enabled:!n.enabled}),children:(0,D.jsx)(`span`,{className:`dc-toggle-thumb`})})]}),!n.supported&&(0,D.jsx)(`p`,{children:t?`这台设备暂不支持远程桌面。`:`Remote desktop is currently unavailable on this device.`}),n.environmentEnabled&&(0,D.jsx)(`p`,{children:t?`远程桌面由本机服务设置保持启用。`:`Remote desktop is kept enabled by the service settings on this device.`}),n.os===`darwin`&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`p`,{children:t?`点击下方按钮发起系统授权,请在这台 Mac 的系统设置中确认。授权后可能需要重启服务。`:`Use the buttons below to request system permission, then confirm in System Settings on this Mac. You may need to restart the service afterward.`}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[(0,D.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:a||n.permissions?.supported===!1,onClick:()=>void h(`permissions`,{kind:`screen`}),children:t?`授予屏幕录制权限`:`Grant screen recording permission`}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:a||n.permissions?.supported===!1,onClick:()=>void h(`permissions`,{kind:`control`}),children:t?`授予远程控制权限`:`Grant remote control permission`})]}),n.permissions?.screen===!0&&(0,D.jsx)(`p`,{children:t?`屏幕录制:已授权`:`Screen recording: granted`}),n.permissions?.accessibility===!0&&(0,D.jsx)(`p`,{children:t?`远程控制:已授权`:`Remote control: granted`}),d&&(0,D.jsx)(`p`,{role:`status`,children:t?`已发起授权请求,请确认系统设置后刷新状态。`:`Permission requested. Confirm in System Settings, then refresh the status.`})]})]}),te&&(0,D.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:t?`无法更新本机远程桌面设置,请重试。`:`Unable to update local remote desktop settings. Please retry.`}),(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:a,onClick:()=>void h(`status`),children:[(0,D.jsx)(c,{"aria-hidden":!0}),a?e(`deviceHubWorking`):t?`刷新远程桌面状态`:`Refresh remote desktop status`]})]})]})}function G({pathCompletions:e=[],plugins:o=[],pluginsEpoch:ne=0}){let l=g(),f=r(i()),[p,m]=(0,T.useState)(`devices`),[v,ie]=(0,T.useState)(null),[y,S]=(0,T.useState)(``),[w,ae]=(0,T.useState)(``),[O,j]=(0,T.useState)(null),[M,oe]=(0,T.useState)(Date.now()),[N,P]=(0,T.useState)(null),[se,F]=(0,T.useState)(``),[I,R]=(0,T.useState)(``),[ce,z]=(0,T.useState)(``),[V,G]=(0,T.useState)(!1),K=(0,T.useRef)(!1),[q,le]=(0,T.useState)(!1),[J,ue]=(0,T.useState)(!0),de=(0,T.useRef)(!1),Y=(0,T.useRef)(0),X=(0,T.useRef)(new Set),Z=(0,T.useRef)(!1),fe=(0,T.useRef)(!1),pe=(0,T.useRef)(null),me=(0,T.useRef)(l);me.current=l,(0,T.useEffect)(()=>{let e=e=>{let t=e;t.detail?.deviceId&&pe.current?.deviceId===t.detail.deviceId&&(ie(e=>e&&{...e,remark:t.detail.remark}),pe.current&&(pe.current.remark=t.detail.remark))};return window.addEventListener(`pi-web-ui:device-remark-updated`,e),()=>window.removeEventListener(`pi-web-ui:device-remark-updated`,e)},[]);async function he(e,t){let n=new AbortController;X.current.add(n);try{let r=await fetch(_(s(`/api/device-center/${e}`)),{method:t?`POST`:`GET`,credentials:`same-origin`,signal:n.signal,...t?{headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}:{}}),i=await r.json().catch(()=>({}));if(!r.ok)throw new H(r.status,typeof i.error==`string`?i.error:me.current(`deviceHubRequestFailed`,{status:r.status}));return i}finally{X.current.delete(n)}}function Q(e){return de.current&&Y.current===e}function ge(e){return e instanceof H&&e.status===403?(le(!0),me.current(`deviceHubLocalOnly`)):e instanceof Error?e.message:me.current(`deviceHubNetworkError`)}function _e(e){pe.current=e,ie(e),fe.current||(ae(e.name),S(e.hubUrl??``))}async function ve(){let e=Y.current;try{let t=await he(`status`);if(!Q(e)||Z.current)return;_e(t),R(``),le(!1)}catch(t){Q(e)&&R(ge(t))}finally{Q(e)&&ue(!1)}}(0,T.useEffect)(()=>{de.current=!0;let e=!1,t,n=async()=>{await ve(),!e&&de.current&&(t=setTimeout(n,5e3))};return n(),()=>{e=!0,de.current=!1,Y.current++,clearTimeout(t);for(let e of X.current)e.abort()}},[]),(0,T.useEffect)(()=>{if(!O)return;let e=Y.current,t=!1,n,r=setInterval(()=>oe(Date.now()),1e3),i=async()=>{if(!(t||!Q(e)||Date.now()>=O.expiresAt)){try{let n=await he(`poll`,{});if(t||!Q(e))return;if(n.paired){let n=await he(`status`);if(t||!Q(e))return;fe.current=!1,_e(n),j(null),F(``),z(``);return}F(``)}catch(n){!t&&Q(e)&&F(`${me.current(`deviceHubPollError`)} ${ge(n)}`)}!t&&Q(e)&&(n=setTimeout(i,2e3))}};return n=setTimeout(i,2e3),()=>{t=!0,clearTimeout(n),clearInterval(r)}},[O]);async function ye(){if(Z.current)return;let e=U(y.trim());if(!e){F(l(`deviceHubInvalidUrl`));return}if(!w.trim()||w.trim().length>80){F(l(`deviceHubInvalidName`));return}let t=++Y.current;Z.current=!0,P(`pair`),F(``),z(``),j(null);try{let n=await he(`pair`,{hubUrl:e,name:w.trim()});if(!Q(t))return;if(!n.code||!Number.isFinite(n.expiresAt)||!U(n.hubUrl))throw Error(l(`deviceHubPairError`));oe(Date.now()),j(n)}catch(e){Q(t)&&F(`${l(`deviceHubPairError`)} ${ge(e)}`)}finally{Q(t)&&(Z.current=!1,P(null))}}async function be(){let e=pe.current;if(!e?.deviceId||Z.current)return;let t=++Y.current;Z.current=!0,P(`permission`),F(``),z(``),_e({...e,allowExecution:!e.allowExecution});try{await he(`execution`,{allowExecution:!e.allowExecution}),Q(t)&&z(l(`deviceHubSaved`))}catch(n){Q(t)&&(_e(e),F(`${l(`deviceHubPermissionError`)} ${ge(n)}`))}finally{Q(t)&&(Z.current=!1,P(null))}}async function xe(){let e=pe.current;if(!e?.deviceId||Z.current||!window.confirm(l(`deviceHubDisconnectConfirm`,{name:e.name})))return;let t=++Y.current;Z.current=!0,P(`disconnect`),F(``),z(``);try{if(await he(`disconnect`,{}),!Q(t))return;fe.current=!1,_e({name:e.name,allowExecution:!1,connected:!1}),j(null)}catch(e){Q(t)&&F(`${l(`deviceHubDisconnectError`)} ${ge(e)}`)}finally{Q(t)&&(Z.current=!1,P(null))}}async function Se(){if(K.current||N||!$||!v?.hubUrl||!window.confirm(l(`deviceHubConfirmUpgrade`)))return;let e=Y.current;K.current=!0,G(!0),F(``),z(``);try{let t=await he(`upgrade-hub`,{});if(!t.ok)throw Error(`Hub upgrade was not accepted`);await E(t.job,{isCurrent:()=>Q(e),poll:async e=>(await he(`upgrade-hub-status`,{id:e})).job}),Q(e)&&(z(l(`deviceHubUpgradeSuccess`)),await ve())}catch(t){Q(e)&&F(t instanceof Error?t.message:l(`deviceHubNetworkError`))}finally{K.current=!1,Q(e)&&G(!1)}}async function Ce(){if(!O)return;let e=Y.current;try{await navigator.clipboard.writeText(O.code),Q(e)&&z(l(`deviceHubCopied`))}catch{Q(e)&&F(l(`deviceHubCopyFailed`))}}let $=!!v?.deviceId,we=U($?v?.hubUrl??``:O?.hubUrl??``),Te=Math.max(0,Math.ceil(((O?.expiresAt??0)-M)/1e3)),Ee=`${Math.floor(Te/60)}:${String(Te%60).padStart(2,`0`)}`,De=we?(0,D.jsxs)(A,{href:we,children:[(0,D.jsx)(t,{"aria-hidden":!0}),l(`deviceHubOpenHub`)]}):null;return(0,D.jsxs)(`section`,{className:`dc-page`,"aria-label":l(`deviceHubTitle`),children:[(0,D.jsxs)(`header`,{className:`dc-header`,children:[(0,D.jsxs)(`div`,{className:`dc-heading`,children:[(0,D.jsxs)(`span`,{className:`dc-eyebrow`,children:[(0,D.jsx)(ee,{"aria-hidden":!0}),l(`deviceHubTitle`)]}),(0,D.jsx)(`h1`,{children:l(`deviceHubTitle`)}),(0,D.jsx)(`p`,{children:l(`deviceHubSubtitle`)})]}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[$&&De,(0,D.jsxs)(`span`,{className:`dc-status ${$?v?.connected?`is-online`:`is-offline`:`is-unpaired`}`,children:[(0,D.jsx)(`span`,{className:`dc-status-dot`}),l($?v?.connected?`deviceHubOnline`:`deviceHubOffline`:`deviceHubUnpaired`)]})]})]}),(0,D.jsxs)(`div`,{className:`dc-layout`,children:[(0,D.jsx)(`nav`,{className:`dc-sidebar`,"aria-label":f?`设备与协作导航`:`Devices and collaboration`,children:[[`devices`,ee,f?`设备与连接`:`Devices & connections`],[`groups`,u,f?`群组与工单`:`Groups & work items`],[`channels`,d,f?`外部渠道`:`External channels`]].map(([e,t,n])=>(0,D.jsxs)(`button`,{type:`button`,className:`dc-nav-item${p===e?` is-active`:``}`,"aria-pressed":p===e,onClick:()=>m(e),children:[(0,D.jsx)(t,{"aria-hidden":!0}),n]},e))}),(0,D.jsxs)(`main`,{className:`dc-content`,children:[J&&(0,D.jsxs)(`div`,{className:`dc-loading`,role:`status`,children:[(0,D.jsx)(c,{"aria-hidden":!0}),l(`deviceHubLoading`)]}),(q||I)&&(0,D.jsxs)(`div`,{className:`dc-notice is-error`,role:`alert`,children:[(0,D.jsx)(`span`,{children:q?l(`deviceHubLocalOnly`):`${l(`deviceHubStatusError`)} ${I}`}),(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>void ve(),children:[(0,D.jsx)(c,{"aria-hidden":!0}),l(`deviceHubRetry`)]})]}),se&&!q&&(0,D.jsx)(`div`,{className:`dc-notice is-error`,role:`alert`,children:se}),ce&&(0,D.jsxs)(`div`,{className:`dc-notice is-success`,role:`status`,children:[(0,D.jsx)(n,{"aria-hidden":!0}),ce]}),p!==`devices`&&(!$||q)&&(0,D.jsxs)(`section`,{className:`dc-card`,children:[(0,D.jsx)(`h2`,{children:p===`groups`?f?`群组与工单`:`Groups & work items`:f?`外部渠道`:`External channels`}),(0,D.jsx)(`p`,{children:f?`先连接设备中心,再创建群组、配置群组 AI 并接入外部渠道。`:`Connect to a device hub before creating groups, configuring group AI, and connecting external channels.`}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button is-primary`,onClick:()=>m(`devices`),children:f?`前往设备连接`:`Connect a device`})]}),p===`groups`&&$&&!q&&(0,D.jsx)(B,{},`groups:${v?.hubUrl??``}:${v?.deviceId??``}`),p===`channels`&&$&&!q&&(0,D.jsx)(k,{plugin:o.find(e=>e.id===`superagent`),epoch:ne,onManageGroups:()=>m(`groups`)},`channels:${v?.hubUrl??``}:${v?.deviceId??``}`),p===`devices`&&(0,D.jsxs)(D.Fragment,{children:[!$&&(v||q)&&(0,D.jsx)(L,{initialHubUrl:y,onConnect:e=>{if(q){z(l(`deviceHubLocalOnly`));return}fe.current=!0,S(e)}}),v&&!q&&!$&&(0,D.jsxs)(`section`,{className:`dc-card`,children:[(0,D.jsxs)(`div`,{className:`dc-card-header`,children:[(0,D.jsx)(`span`,{className:`dc-icon`,children:(0,D.jsx)(re,{"aria-hidden":!0})}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h2`,{children:l(`deviceHubPairTitle`)}),(0,D.jsx)(`p`,{children:l(`deviceHubPairHint`)})]})]}),(0,D.jsx)(`ol`,{className:`dc-steps`,children:[`deviceHubStepDetails`,`deviceHubStepApprove`,`deviceHubStepWait`].map((e,t)=>(0,D.jsxs)(`li`,{className:O?t===0?`is-complete`:`is-active`:t===0?`is-active`:``,children:[(0,D.jsx)(`span`,{className:`dc-step-number`,children:O&&t===0?(0,D.jsx)(n,{"aria-hidden":!0}):t+1}),(0,D.jsx)(`span`,{children:l(e)})]},e))}),(0,D.jsxs)(`form`,{className:`dc-form`,onSubmit:e=>{e.preventDefault(),ye()},children:[(0,D.jsxs)(`div`,{className:`dc-field`,children:[(0,D.jsx)(`label`,{htmlFor:`dc-hub-url`,children:l(`deviceHubHubUrl`)}),(0,D.jsx)(`input`,{id:`dc-hub-url`,type:`url`,autoComplete:`url`,required:!0,placeholder:l(`deviceHubHubPlaceholder`),value:y,disabled:!!O||!!N,onChange:e=>{fe.current=!0,S(e.target.value)}})]}),(0,D.jsxs)(`div`,{className:`dc-field`,children:[(0,D.jsx)(`label`,{htmlFor:`dc-device-name`,children:l(`deviceHubName`)}),(0,D.jsx)(`input`,{id:`dc-device-name`,maxLength:80,required:!0,autoComplete:`off`,placeholder:l(`deviceHubNamePlaceholder`),value:w,disabled:!!O||!!N,onChange:e=>{fe.current=!0,ae(e.target.value)}})]}),!O&&(0,D.jsx)(`div`,{className:`dc-actions`,children:(0,D.jsxs)(`button`,{className:`dc-button is-primary`,type:`submit`,disabled:!!N,children:[(0,D.jsx)(re,{"aria-hidden":!0}),l(N?`deviceHubWorking`:`deviceHubGetCode`)]})})]}),O&&(0,D.jsxs)(`div`,{className:`dc-pairing`,children:[(0,D.jsx)(`span`,{className:`dc-code-label`,children:l(`deviceHubCode`)}),(0,D.jsxs)(`div`,{className:`dc-code-row`,children:[(0,D.jsx)(`code`,{className:`dc-code`,children:O.code}),(0,D.jsx)(`button`,{className:`dc-icon-button`,type:`button`,"aria-label":l(`deviceHubCopy`),onClick:()=>void Ce(),children:(0,D.jsx)(a,{"aria-hidden":!0})})]}),(0,D.jsx)(`div`,{className:`dc-pair-meta`,children:l(Te?`deviceHubExpires`:`deviceHubExpired`,{time:Ee})}),(0,D.jsxs)(`div`,{className:`dc-actions`,children:[De,(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:!!N,onClick:()=>{++Y.current,j(null),F(``),z(``)},children:[(0,D.jsx)(c,{"aria-hidden":!0}),l(`deviceHubNewCode`)]})]}),Te>0&&(0,D.jsxs)(`p`,{className:`dc-progress`,role:`status`,children:[(0,D.jsx)(c,{"aria-hidden":!0}),l(`deviceHubWaiting`)]})]})]}),$&&v&&!q&&(0,D.jsxs)(`section`,{className:`dc-card`,children:[(0,D.jsxs)(`div`,{className:`dc-device-summary`,children:[(0,D.jsx)(`span`,{className:`dc-device-icon`,children:(0,D.jsx)(ee,{"aria-hidden":!0})}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h2`,{children:v.remark?.trim()||v.name}),(0,D.jsx)(`p`,{children:v.remark?.trim()?`${v.name} · ${l(`deviceHubDeviceTitle`)}`:l(`deviceHubDeviceTitle`)})]})]}),(0,D.jsxs)(`dl`,{className:`dc-details`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`dt`,{children:l(`deviceHubDeviceId`)}),(0,D.jsx)(`dd`,{children:v.deviceId})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`dt`,{children:l(`deviceHubHubUrl`)}),(0,D.jsx)(`dd`,{children:v.hubUrl})]})]}),(0,D.jsx)(`div`,{className:`dc-actions`,style:{marginTop:`1rem`},children:(0,D.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:V||!!N,onClick:()=>void Se(),children:[(0,D.jsx)(c,{className:V?`spin`:``,"aria-hidden":!0}),l(V?`deviceHubUpgrading`:`deviceHubUpgradeAction`)]})})]}),$&&v?.hubUrl&&v.deviceId&&!q&&(0,D.jsx)(b,{hubUrl:v.hubUrl,currentDeviceId:v.deviceId},`directory:${v.hubUrl}:${v.deviceId}`),!q&&(0,D.jsx)(x,{pathCompletions:e},`bots:${v?.hubUrl??``}:${v?.deviceId??`unpaired`}`),(0,D.jsx)(W,{}),$&&v&&!q&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`section`,{className:`dc-card`,children:[(0,D.jsxs)(`div`,{className:`dc-card-header`,children:[(0,D.jsx)(`span`,{className:`dc-icon`,children:(0,D.jsx)(te,{"aria-hidden":!0})}),(0,D.jsx)(`div`,{children:(0,D.jsx)(`h2`,{children:l(`deviceHubPermissions`)})})]}),(0,D.jsxs)(`div`,{className:`dc-permission-row`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h3`,{id:`dc-permission-label`,children:l(`deviceHubPermissionLabel`)}),(0,D.jsx)(`p`,{id:`dc-permission-hint`,children:l(`deviceHubPermissionHint`)})]}),(0,D.jsx)(`button`,{type:`button`,className:`dc-toggle${v.allowExecution?` is-on`:``}`,role:`switch`,"aria-checked":v.allowExecution,"aria-labelledby":`dc-permission-label`,"aria-describedby":`dc-permission-hint`,disabled:!!N,onClick:()=>void be(),children:(0,D.jsx)(`span`,{className:`dc-toggle-thumb`})})]}),(0,D.jsx)(`p`,{className:`dc-permission-state`,role:`status`,children:l(N===`permission`?`deviceHubSaving`:v.allowExecution?`deviceHubEnabled`:`deviceHubReadOnly`)})]}),(0,D.jsx)(C,{hubUrl:v?.hubUrl,deviceId:v?.deviceId,onNotice:z}),(0,D.jsxs)(`details`,{className:`dc-advanced`,children:[(0,D.jsx)(`summary`,{children:l(`deviceHubAdvanced`)}),(0,D.jsxs)(`div`,{className:`dc-danger-zone`,children:[(0,D.jsx)(`h3`,{children:l(`deviceHubDisconnect`)}),(0,D.jsx)(`p`,{children:l(`deviceHubDisconnectHint`)}),(0,D.jsx)(`button`,{type:`button`,className:`dc-button is-danger`,disabled:!!N,onClick:()=>void xe(),children:l(N===`disconnect`?`deviceHubWorking`:`deviceHubDisconnect`)})]})]})]}),(0,D.jsxs)(`aside`,{className:`dc-help`,children:[(0,D.jsx)(h,{className:`dc-help-icon`,"aria-hidden":!0}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h3`,{children:l(`deviceHubHelpTitle`)}),(0,D.jsx)(`p`,{children:l(`deviceHubHelpText`)})]})]})]})]})]})]})}export{G as DeviceCenter};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{A as t,Ct as n,K as r,Pn as i,Qt as a,Ut as o,Vt as s,Wt as c,Zt as l,kt as u,mn as d,ot as f,p,wn as m,z as h,zn as g}from"./app-globals-CZjFtI4F.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=m(),[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 r=new AbortController;U.current.add(r);let a=()=>r.abort();n&&(n.aborted?r.abort():n.addEventListener(`abort`,a,{once:!0}));try{let n=await fetch(g(i(`/api/device-center/${e}`)),{method:t?`POST`:`GET`,credentials:`same-origin`,signal:r.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(r)}},[]),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)(o,{className:j?`des-spin`:``})})]}),L&&(0,b.jsxs)(`div`,{className:`des-alert des-alert-error`,role:`alert`,children:[(0,b.jsx)(p,{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)(d,{})})]}),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)(d,{})})]}),(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)(c,{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)(r,{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)(l,{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)(u,{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)(f,{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)(n,{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)(p,{}),` `,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};
|