pi-web-ui 0.115.0 → 0.116.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/bin/pi-web-ui.mjs +21 -1
- package/dist/gh-comment-781.md +5 -0
- package/dist/server/agent-service-daemon.js +84 -2
- package/dist/server/agent-service.js +107 -26
- package/dist/server/client-state.js +17 -2
- package/dist/server/device-center/bot-execution.js +29 -1
- package/dist/server/device-center/collab-service.js +36 -5
- package/dist/server/device-center/collab-tool.js +90 -5
- package/dist/server/device-center/execution-guides.js +2 -2
- package/dist/server/device-center/execution-instructions.js +2 -1
- package/dist/server/device-center/execution-settings.js +138 -25
- package/dist/server/device-center/executor.js +4 -1
- package/dist/server/device-center/file-sync.js +14 -13
- package/dist/server/device-center/group-context-message.js +3 -1
- package/dist/server/device-center/group-context.js +73 -3
- package/dist/server/device-center/hub-conversations.js +58 -3
- package/dist/server/device-center/hub-locks.js +320 -0
- package/dist/server/device-center/hub-page.js +13 -33
- package/dist/server/device-center/hub-webhooks.js +165 -0
- package/dist/server/device-center/hub.js +872 -64
- package/dist/server/device-center/local-hub.js +2 -1
- package/dist/server/device-center/local-page.js +17 -0
- package/dist/server/device-center/local.js +74 -1
- package/dist/server/device-center/partition-log.js +293 -0
- package/dist/server/device-center/runtime.js +49 -0
- package/dist/server/device-center/smoke-preview.js +3 -0
- package/dist/server/device-center/store.js +163 -64
- package/dist/server/device-center/task-scheduler.js +48 -3
- package/dist/server/device-center/transfers.js +41 -15
- package/dist/server/dispatch-domain-handlers.js +14 -3
- package/dist/server/durable/durable-capabilities.js +11 -0
- package/dist/server/engine-probe.js +112 -1
- package/dist/server/global-loader.js +119 -19
- package/dist/server/index.js +133 -16
- package/dist/server/managed.js +2 -0
- package/dist/server/markers/builtins/services.js +123 -0
- package/dist/server/markers/builtins/todo.js +189 -0
- package/dist/server/markers-list-tool.js +34 -0
- package/dist/server/model-admin.js +48 -6
- package/dist/server/model-enrich.js +10 -1
- package/dist/server/orchestrator.js +109 -0
- package/dist/server/plugins.js +64 -7
- package/dist/server/prompt-composer.js +39 -0
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/reasoning-registry.js +207 -0
- package/dist/server/startup-banner.js +35 -0
- package/dist/server/subagents.js +2 -1
- package/dist/server/system-prompt-soul.js +41 -0
- package/dist/server/tool-manager.js +17 -9
- package/dist/server/unauthorized-page.js +319 -0
- package/dist/server/univer-service.js +448 -0
- package/dist/server/universal/drivers/dsh-driver.js +379 -0
- package/dist/test-artifact.md +9 -0
- package/dist/test-preview-modal.md +11 -0
- package/dist/test-report.html +20 -0
- package/docs/architecture-plugins.md +946 -0
- package/docs/device-center.md +6 -0
- package/package.json +2 -1
- package/web/dist/.build-assets.json +1 -1
- package/web/dist/assets/{BgTasksModal-BYzPgmoq.js → BgTasksModal-BDoOpj-F.js} +1 -1
- package/web/dist/assets/{BgTasksModal-ni0VTmAQ.js → BgTasksModal-C0i3O1FT.js} +1 -1
- package/web/dist/assets/{CanvasStudio-BCUeEf25.js → CanvasStudio-B8thymBN.js} +3 -3
- package/web/dist/assets/{CanvasStudio-DNmDNBod.js → CanvasStudio-zSxyIx1R.js} +3 -3
- package/web/dist/assets/DeviceCenter-DfAHKcid.js +3 -0
- package/web/dist/assets/DeviceCenter-ydvOTlzE.js +3 -0
- package/web/dist/assets/DeviceExecutionSettings-q5Ik8oXg.js +1 -0
- package/web/dist/assets/DeviceGroups-CI14_SRb.js +1 -0
- package/web/dist/assets/DeviceGroups-DvsB5IEU.js +1 -0
- package/web/dist/assets/{Dropdown-CGXD0DfT.js → Dropdown-C4LIhshN.js} +1 -1
- package/web/dist/assets/FilePreview-BgGongmv.js +2 -0
- package/web/dist/assets/FilePreview-D4NrhF-U.js +2 -0
- package/web/dist/assets/{GlobalSearchModal-mevF-ySi.js → GlobalSearchModal-BWgU8yPd.js} +1 -1
- package/web/dist/assets/{GlobalSearchModal-qL99FN_F.js → GlobalSearchModal-F7fNimKk.js} +1 -1
- package/web/dist/assets/GroupConversation-Dh71Pdb-.js +17 -0
- package/web/dist/assets/GroupConversation-ZK3nRmNm.js +17 -0
- package/web/dist/assets/{HintTip-LHwkS2jV.js → HintTip-c6d0TJoh.js} +1 -1
- package/web/dist/assets/ModelConfigModal-YVEgyy34.js +2 -0
- package/web/dist/assets/ModelConfigModal-vWtg3srp.js +2 -0
- package/web/dist/assets/{PiSetupModal-DE5-gEtI.js → PiSetupModal-BmMrrgB9.js} +1 -1
- package/web/dist/assets/{ProviderOAuthControls-6UMARucA.js → ProviderOAuthControls-BGSBIKD7.js} +1 -1
- package/web/dist/assets/SCMPanel-B8_EDxNr.js +2 -0
- package/web/dist/assets/SCMPanel-BU58qk3T.js +2 -0
- package/web/dist/assets/SettingsModal-CMUybq3J.js +32 -0
- package/web/dist/assets/SettingsModal-OBmGTh-5.js +32 -0
- package/web/dist/assets/{TerminalPanel-CTp_BZ4S.js → TerminalPanel-0CYvD72B.js} +2 -2
- package/web/dist/assets/{TerminalPanel-CkYxC-Gh.js → TerminalPanel-DDavKvFr.js} +2 -2
- package/web/dist/assets/{TuiOverlayModal-1cRLP8IF.js → TuiOverlayModal-BsA-QTvN.js} +1 -1
- package/web/dist/assets/{TuiOverlayModal-2xlptqWX.js → TuiOverlayModal-DzoVQBuG.js} +1 -1
- package/web/dist/assets/app-globals-CZxzGvIo.js +123 -0
- package/web/dist/assets/{canvas-client-Bye9nSFO.js → canvas-client-CUnXlQYX.js} +1 -1
- package/web/dist/assets/{desktop-kjBoE3Nu.js → desktop-aAKpvKJV.js} +1 -1
- package/web/dist/assets/index-C6DwztqE.css +1 -0
- package/web/dist/assets/index-CuN802Sj.js +93 -0
- package/web/dist/assets/index-EH5Fw9fa.js +93 -0
- package/web/dist/assets/{plugin-host-C8mNgghx.js → plugin-host-BRWib9DF.js} +1 -1
- package/web/dist/assets/{remote-ssh-client-CeP3CLUW.js → remote-ssh-client-CfYSMEZg.js} +1 -1
- package/web/dist/assets/{theme-BXGpyTMh.js → theme-D2l_mLNo.js} +1 -1
- package/web/dist/index.html +10 -10
- package/web/dist/sw.js +1 -1
- package/web/dist/assets/DeviceCenter-BcBhRgL6.js +0 -3
- package/web/dist/assets/DeviceCenter-CmL5FZmt.js +0 -3
- package/web/dist/assets/DeviceGroups-CLdpdnI7.js +0 -1
- package/web/dist/assets/DeviceGroups-CgBaDPrD.js +0 -1
- package/web/dist/assets/FilePreview-B8iqnBjy.js +0 -2
- package/web/dist/assets/FilePreview-BqviZKCN.js +0 -2
- package/web/dist/assets/GroupConversation-B88Yy-lt.js +0 -3
- package/web/dist/assets/GroupConversation-BwP5NVOE.js +0 -3
- package/web/dist/assets/ModelConfigModal-Do3Fe3jH.js +0 -2
- package/web/dist/assets/SCMPanel-Hi6QqC1Q.js +0 -2
- package/web/dist/assets/SCMPanel-ezY_ZtCu.js +0 -2
- package/web/dist/assets/SettingsModal-6HgeEsJ8.js +0 -20
- package/web/dist/assets/SettingsModal-CF-7MwqS.js +0 -20
- package/web/dist/assets/app-globals-DZNa9v8u.js +0 -325
- package/web/dist/assets/index-CsFs_HMb.css +0 -1
- package/web/dist/assets/index-DHeeHS_l.js +0 -85
- package/web/dist/assets/index-DTZch8uz.js +0 -85
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t}from"./react-CR5VJ85Q.js";import{t as n}from"./uuid-BzDIGCwP.js";import{r}from"./desktop-kjBoE3Nu.js";var i=e(t(),1),a=null,o=null,s=null,c=null,l=null;function u(e){c=e}function d(e){l=e}function f(e){return c?(c(e),!0):!1}function p(e){return l?(l(e),!0):!1}function m(e){a=e}function h(e){o=e}function g(e){s=e}function _(){return s?(s(),!0):!1}var v=0,y=null;function ee(e){y=e}function te(){v=Date.now(),y?.(),_()}function ne(){return v}function re(){return!!(a||o)}function b(e){let t=typeof e?.text==`string`?e.text:``,n=Array.isArray(e?.attachments)?e.attachments:[],r=t.trim()!==``,i=n.length>0;return!r&&!i||r&&!a||i&&!o?!1:(i&&o?.(n),r&&a?.(t),!0)}var x=`pi-web-ui:cost-currency`,S=null,C=0,w=new Set;function T(){C+=1;for(let e of[...w])try{e()}catch{}}function ie(e){return w.add(e),()=>{w.delete(e)}}function E(){return C}function ae(e){return!Number.isFinite(e)||e<=0?`0`:e<1e-4?`<0.0001`:e.toFixed(4).replace(/\.?0+$/,``)}function D(){try{if(typeof localStorage<`u`){let e=localStorage.getItem(x);if(typeof e==`string`&&e.trim().length>0)return e.trim().slice(0,8)}}catch{}return`$`}function oe(e){try{if(typeof localStorage<`u`){let t=typeof e==`string`?e.trim().slice(0,8):``;!t||t===`$`?localStorage.removeItem(x):localStorage.setItem(x,t)}}catch{}T()}function se(e){return typeof e==`function`?(S=e,T(),()=>{S===e&&(S=null,T())}):(S=null,T(),()=>{})}function ce(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 O(e,t){let n=typeof e==`number`&&Number.isFinite(e)?e:0,r=D(),i=typeof t?.fixedDigits==`number`?n.toFixed(t.fixedDigits):ae(n);if(S)try{let e=S(n,{defaultSymbol:r,defaultValue:i});if(typeof e==`string`)return ce(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 le(e,t){return(0,i.useSyncExternalStore)(ie,E,E),O(e,t)}var k=new Map,ue=0;function de(e){k.get(e.requestId)?.(e.ok&&e.conversationId?e.conversationId:null)}function A(e,t=8e3){let n=`host-new-chat-${Date.now()}-${++ue}`;return new Promise(r=>{let i=e=>{clearTimeout(a),k.delete(n),r(e)},a=setTimeout(()=>i(null),t);k.set(n,i);try{e({type:`new_chat`,requestId:n})||i(null)}catch{i(null)}})}var j=`__piWebUiHost`,M=e=>new Promise(t=>setTimeout(t,e));async function fe(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 M(100)}}var N=Promise.resolve(),P=0;function pe(e){let t=Math.max(1,Number(e.pollMs??100)),i=Math.max(t,Number(e.timeoutMs??8e3)),a=async e=>{let n=Date.now()+i;for(;;){if(e())return!0;if(Date.now()>=n)return e();await M(t)}},o=()=>{try{let t=e.listModels?.()??[];return Array.isArray(t)?[...t]:[]}catch{return[]}},s=e=>{if(!e)return!0;try{return o().some(t=>t&&t.id===e)}catch{return!1}},c=async t=>{t&&(e.send({type:`set_model`,modelId:t}),typeof e.getCurrentModelId==`function`&&await a(()=>e.getCurrentModelId?.()===t))},l=async(t,n)=>{let r=String(n.cwd??``).trim();if(r&&e.getCwd()!==r&&(!e.send({type:`set_cwd`,path:r})||!await a(()=>e.getCwd()===r))||!e.isReady())return!1;let o=n.newChat===!1?e.getConversationId():await A(e.send,i);if(n.newChat!==!1&&o&&!await a(()=>e.getConversationId()===o)||!o||!e.isReady())return!1;let s=String(n.model??``).trim();return s&&await c(s),!e.isReady()||e.getConversationId()!==o||r&&e.getCwd()!==r?!1:(e.setView(`chat`),e.send({type:`prompt`,text:t,targetConversationId:o}))};return{version:14,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&&!s(r))return!1;let i=async()=>{let e=!1;try{e=await l(n,t??{prompt:n})}finally{try{t?.onResult?.(e)}catch{}}},a;return a=P>0?N.then(i):i(),P++,N=a.then(()=>{P--},()=>{P--}),a.catch(()=>{}),!0},models:{list:()=>o(),active:()=>e.getCurrentModelId?.()??null,onChange:e=>je(e)},compose(e){return re()?b({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}},closeModal(){if(typeof e.closeModal!=`function`)return!0;try{e.closeModal()}catch{}return!0},async openSession(t){let n=L,r=Array.isArray(t?.folders)?t.folders.filter(e=>typeof e==`string`&&e.trim().length>0).map(e=>e.trim()):[],o=Array.isArray(t?.roots)?t.roots.filter(e=>typeof e==`string`&&e.trim().length>0).map(e=>e.trim()):[],l=String(t?.cwd??``).trim(),u=[...new Set([...r,...o])],d=l||u[0]||``;if(!d)return{ok:!1,error:`openSession 需要 cwd / folders / roots(绝对路径)`};if(!e.isReady())return{ok:!1,error:`尚未连接到服务器(还没有快照)`};let f=u.filter(e=>e!==d).slice(0,7),p=new Set([...e.listProjects?.()??[],...e.grantedPaths?.(n)??[]]);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,n)}if(e.getCwd()!==d&&(e.send({type:`set_cwd`,path:d}),!await a(()=>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 A(e.send,i)??void 0,!m||!await a(()=>e.getConversationId()===m)))return{ok:!1,error:`Conversation creation failed or timed out`};let h=String(t?.model??``).trim();if(h){if(!s(h))return{ok:!1,error:`未知模型:${h}(先调 models.list() 取可用列表)`};if(await c(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=L,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 a(()=>e.getCwd()===i.cwd))return{ok:!1,error:`切换工作目录失败或超时:${i.cwd}`}}let o=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 a(()=>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 a(()=>i.kind===`running`?e.getConversationId()===i.id&&!e.getConversationOwner?.():e.getConversationId()!==o)?{ok:!0,sessionId:e.getConversationId()??void 0}:{ok:!1,error:`切换会话超时:${i.title}`})}},async reloadCatalog(t,r){let i=String(t??``).trim();if(!i)return{ok:!1,error:`reloadCatalog 需要一个目录来源(http(s) URL 或本地文件路径)`};if(!e.isReady())return{ok:!1,error:`尚未连接到服务器(还没有快照)`};let a=n();return new Promise(t=>{let n=setTimeout(()=>{$.delete(a),t({ok:!1,error:`目录同步超时(服务端未在等待窗口内回执)`})},Math.max(1e3,Number(e.catalogTimeoutMs??18e4)));$.set(a,e=>{clearTimeout(n),t(e)}),e.send({type:`plugin_catalog_sync`,requestId:a,source:i,...r?.install?{install:!0}:{},...r?.replace?{replace:!0}:{}})})},onUiAction(e,t){return R(I,String(e??``).trim(),t)},onTopbarAction(e,t){return R(I,String(e??``).trim(),t)},async pageCall(t){let n=String(t?.op??``).trim();if(!n)return{ok:!1,error:`pageCall 需要一个动作名(op)`};if(r())return{ok:!1,error:`桌面版(Electron 外壳)不支持 browser_page:窗口里没有 Chrome 扩展运行时。请让用户改用系统浏览器打开同一个 pi-web-ui 地址(网页版)再试。/ The desktop app cannot run browser_page (no Chrome extension runtime); ask the user to open the same pi-web-ui address in a regular browser instead.`};let i=await fe(e.bridgeWaitMs??3e3);if(!i)return{ok:!1,error:`浏览器扩展的页面桥没就绪:确认已安装并启用 page-picker 扩展、本页地址已绑定,然后刷新本页`};try{let e=await i.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(ve,{detail:{text:n}}))}catch{}return null},shortcuts:{register:(e,t)=>Ce(String(e??``),t)},searchProviders:{register:e=>we(e),list:()=>U()},composerProviders:{register:e=>Te(e),list:()=>G()},ttsProviders:{register:e=>Oe(e),list:()=>J()},onTheme:e=>Ne(e),onLocale:e=>Pe(e),onViewChange:e=>Fe(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=>se(e),setCostCurrency:e=>oe(e),getCostCurrency:()=>D()}}function me(e){try{let t=window;e?t[j]=e:delete t[j]}catch{}}var F=new Map,I=null;async function he(e,t){let n=I;I=e;try{return await t()}finally{I=n}}var L=void 0;function ge(e,t){let n=L;L=e;try{return t()}finally{L=n}}function R(e,t,n){if(!t||typeof n!=`function`)return()=>{};let r=e?`${e}:${t}`:t,i=F.get(r);i||(i=new Set,F.set(r,i));let a=i;return a.add(n),()=>{a.delete(n),a.size===0&&F.delete(r)}}async function _e(e,t,n,r){let i=i=>{let a=F.get(i);if(!a||a.size===0)return!1;for(let i of[...a])try{ge(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 ve=`pi-web-ui:toast`,z=new Map,B=!1;function ye(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 be(){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 V(e){try{if(be())return;let t=`${e.ctrlKey?`ctrl+`:``}${e.shiftKey?`shift+`:``}${e.altKey?`alt+`:``}${e.metaKey?`meta+`:``}${(e.key??``).toLowerCase()}`,n=z.get(t);if(!n||n.size===0)return;for(let e of[...n])try{e()}catch(e){console.error(`[plugin-host] 快捷键处理器抛错:`,e)}}catch{}}function xe(){if(!B)try{if(typeof window>`u`||typeof window.addEventListener!=`function`)return;window.addEventListener(`keydown`,V),B=!0}catch{}}function Se(){if(!(z.size>0||!B))try{window.removeEventListener(`keydown`,V)}catch{}finally{B=!1}}function Ce(e,t){if(typeof t!=`function`)return()=>{};let n=ye(e);if(!n)return()=>{};let r=z.get(n.combo);r||(r=new Set,z.set(n.combo,r));let i=r;return i.add(t),xe(),()=>{i.delete(t),i.size===0&&z.delete(n.combo),Se()}}var H=new Map;function we(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 H.set(t,n),()=>{H.get(t)===n&&H.delete(t)}}function U(){return[...H.values()].map(e=>({id:e.id,label:e.label}))}var W=new Map;function Te(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 W.set(t,n),()=>{W.get(t)===n&&W.delete(t)}}function G(){return[...W.values()].map(e=>({id:e.id,label:e.label}))}function Ee(e){return W.get(String(e??``))}function De(e){return H.get(String(e??``))}var K=new Map,q=new Set;function Oe(e){let t=String(e?.id??``).trim();if(!t||typeof e?.play!=`function`)return()=>{};let n={id:t,label:String(e.label??t),labelEn:e.labelEn?String(e.labelEn):void 0,play:e.play,getVoices:e.getVoices};K.set(t,n);for(let e of q)try{e()}catch{}return()=>{if(K.get(t)===n){K.delete(t);for(let e of q)try{e()}catch{}}}}function J(){return[...K.values()].map(e=>({id:e.id,label:e.label,labelEn:e.labelEn}))}function ke(e){return K.get(String(e??``))}function Ae(e){return q.add(e),()=>{q.delete(e)}}var Y=new Set,X=new Set,Z=new Set,Q=new Set;function je(e){return Q.add(e),()=>{Q.delete(e)}}function Me(e){for(let t of Q)try{t(e)}catch(e){console.error(`[plugin-host] onModelChange 处理器抛错:`,e)}}function Ne(e){return typeof e==`function`?(Y.add(e),()=>{Y.delete(e)}):()=>{}}function Pe(e){return typeof e==`function`?(X.add(e),()=>{X.delete(e)}):()=>{}}function Fe(e){return typeof e==`function`?(Z.add(e),()=>{Z.delete(e)}):()=>{}}function Ie(e){let t=String(e??``);for(let e of Y)try{e(t)}catch(e){console.error(`[plugin-host] onTheme 处理器抛错:`,e)}}function Le(e){let t=String(e??``);for(let e of X)try{e(t)}catch(e){console.error(`[plugin-host] onLocale 处理器抛错:`,e)}}function Re(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 ze(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{ee as A,f as C,g as D,m as E,u as O,ne as S,h as T,de as _,Re as a,b,ke as c,U as d,J as f,he as g,_e as h,Ie as i,p as j,d as k,me as l,ze as m,Le as n,Ee as o,Ae as p,Me as r,De as s,pe as t,G as u,O as v,te as w,_ as x,le as y};
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t}from"./react-CR5VJ85Q.js";import{t as n}from"./uuid-BzDIGCwP.js";import{r}from"./desktop-aAKpvKJV.js";var i=e(t(),1),a=null,o=null,s=null,c=null,l=null;function u(e){c=e}function d(e){l=e}function f(e){return c?(c(e),!0):!1}function p(e){return l?(l(e),!0):!1}function m(e){a=e}function h(e){o=e}function g(e){s=e}function _(){return s?(s(),!0):!1}var v=0,y=null;function ee(e){y=e}function te(){v=Date.now(),y?.(),_()}function ne(){return v}function re(){return!!(a||o)}function b(e){let t=typeof e?.text==`string`?e.text:``,n=Array.isArray(e?.attachments)?e.attachments:[],r=t.trim()!==``,i=n.length>0;return!r&&!i||r&&!a||i&&!o?!1:(i&&o?.(n),r&&a?.(t),!0)}var x=`pi-web-ui:cost-currency`,S=null,C=0,w=new Set;function T(){C+=1;for(let e of[...w])try{e()}catch{}}function ie(e){return w.add(e),()=>{w.delete(e)}}function E(){return C}function ae(e){return!Number.isFinite(e)||e<=0?`0`:e<1e-4?`<0.0001`:e.toFixed(4).replace(/\.?0+$/,``)}function D(){try{if(typeof localStorage<`u`){let e=localStorage.getItem(x);if(typeof e==`string`&&e.trim().length>0)return e.trim().slice(0,8)}}catch{}return`$`}function oe(e){try{if(typeof localStorage<`u`){let t=typeof e==`string`?e.trim().slice(0,8):``;!t||t===`$`?localStorage.removeItem(x):localStorage.setItem(x,t)}}catch{}T()}function se(e){return typeof e==`function`?(S=e,T(),()=>{S===e&&(S=null,T())}):(S=null,T(),()=>{})}function ce(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 O(e,t){let n=typeof e==`number`&&Number.isFinite(e)?e:0,r=D(),i=typeof t?.fixedDigits==`number`?n.toFixed(t.fixedDigits):ae(n);if(S)try{let e=S(n,{defaultSymbol:r,defaultValue:i});if(typeof e==`string`)return ce(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 le(e,t){return(0,i.useSyncExternalStore)(ie,E,E),O(e,t)}var k=new Map,ue=0;function de(e){k.get(e.requestId)?.(e.ok&&e.conversationId?e.conversationId:null)}function A(e,t=8e3){let n=`host-new-chat-${Date.now()}-${++ue}`;return new Promise(r=>{let i=e=>{clearTimeout(a),k.delete(n),r(e)},a=setTimeout(()=>i(null),t);k.set(n,i);try{e({type:`new_chat`,requestId:n})||i(null)}catch{i(null)}})}var j=`__piWebUiHost`,M=e=>new Promise(t=>setTimeout(t,e));async function fe(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 M(100)}}var N=Promise.resolve(),P=0;function pe(e){let t=Math.max(1,Number(e.pollMs??100)),i=Math.max(t,Number(e.timeoutMs??8e3)),a=async e=>{let n=Date.now()+i;for(;;){if(e())return!0;if(Date.now()>=n)return e();await M(t)}},o=()=>{try{let t=e.listModels?.()??[];return Array.isArray(t)?[...t]:[]}catch{return[]}},s=e=>{if(!e)return!0;try{return o().some(t=>t&&t.id===e)}catch{return!1}},c=async t=>{t&&(e.send({type:`set_model`,modelId:t}),typeof e.getCurrentModelId==`function`&&await a(()=>e.getCurrentModelId?.()===t))},l=async(t,n)=>{let r=String(n.cwd??``).trim();if(r&&e.getCwd()!==r&&(!e.send({type:`set_cwd`,path:r})||!await a(()=>e.getCwd()===r))||!e.isReady())return!1;let o=n.newChat===!1?e.getConversationId():await A(e.send,i);if(n.newChat!==!1&&o&&!await a(()=>e.getConversationId()===o)||!o||!e.isReady())return!1;let s=String(n.model??``).trim();return s&&await c(s),!e.isReady()||e.getConversationId()!==o||r&&e.getCwd()!==r?!1:(e.setView(`chat`),e.send({type:`prompt`,text:t,targetConversationId:o}))};return{version:14,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&&!s(r))return!1;let i=async()=>{let e=!1;try{e=await l(n,t??{prompt:n})}finally{try{t?.onResult?.(e)}catch{}}},a;return a=P>0?N.then(i):i(),P++,N=a.then(()=>{P--},()=>{P--}),a.catch(()=>{}),!0},models:{list:()=>o(),active:()=>e.getCurrentModelId?.()??null,onChange:e=>je(e)},compose(e){return re()?b({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}},closeModal(){if(typeof e.closeModal!=`function`)return!0;try{e.closeModal()}catch{}return!0},async openSession(t){let n=L,r=Array.isArray(t?.folders)?t.folders.filter(e=>typeof e==`string`&&e.trim().length>0).map(e=>e.trim()):[],o=Array.isArray(t?.roots)?t.roots.filter(e=>typeof e==`string`&&e.trim().length>0).map(e=>e.trim()):[],l=String(t?.cwd??``).trim(),u=[...new Set([...r,...o])],d=l||u[0]||``;if(!d)return{ok:!1,error:`openSession 需要 cwd / folders / roots(绝对路径)`};if(!e.isReady())return{ok:!1,error:`尚未连接到服务器(还没有快照)`};let f=u.filter(e=>e!==d).slice(0,7),p=new Set([...e.listProjects?.()??[],...e.grantedPaths?.(n)??[]]);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,n)}if(e.getCwd()!==d&&(e.send({type:`set_cwd`,path:d}),!await a(()=>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 A(e.send,i)??void 0,!m||!await a(()=>e.getConversationId()===m)))return{ok:!1,error:`Conversation creation failed or timed out`};let h=String(t?.model??``).trim();if(h){if(!s(h))return{ok:!1,error:`未知模型:${h}(先调 models.list() 取可用列表)`};if(await c(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=L,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 a(()=>e.getCwd()===i.cwd))return{ok:!1,error:`切换工作目录失败或超时:${i.cwd}`}}let o=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 a(()=>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 a(()=>i.kind===`running`?e.getConversationId()===i.id&&!e.getConversationOwner?.():e.getConversationId()!==o)?{ok:!0,sessionId:e.getConversationId()??void 0}:{ok:!1,error:`切换会话超时:${i.title}`})}},async reloadCatalog(t,r){let i=String(t??``).trim();if(!i)return{ok:!1,error:`reloadCatalog 需要一个目录来源(http(s) URL 或本地文件路径)`};if(!e.isReady())return{ok:!1,error:`尚未连接到服务器(还没有快照)`};let a=n();return new Promise(t=>{let n=setTimeout(()=>{$.delete(a),t({ok:!1,error:`目录同步超时(服务端未在等待窗口内回执)`})},Math.max(1e3,Number(e.catalogTimeoutMs??18e4)));$.set(a,e=>{clearTimeout(n),t(e)}),e.send({type:`plugin_catalog_sync`,requestId:a,source:i,...r?.install?{install:!0}:{},...r?.replace?{replace:!0}:{}})})},onUiAction(e,t){return R(I,String(e??``).trim(),t)},onTopbarAction(e,t){return R(I,String(e??``).trim(),t)},async pageCall(t){let n=String(t?.op??``).trim();if(!n)return{ok:!1,error:`pageCall 需要一个动作名(op)`};if(r())return{ok:!1,error:`桌面版(Electron 外壳)不支持 browser_page:窗口里没有 Chrome 扩展运行时。请让用户改用系统浏览器打开同一个 pi-web-ui 地址(网页版)再试。/ The desktop app cannot run browser_page (no Chrome extension runtime); ask the user to open the same pi-web-ui address in a regular browser instead.`};let i=await fe(e.bridgeWaitMs??3e3);if(!i)return{ok:!1,error:`浏览器扩展的页面桥没就绪:确认已安装并启用 page-picker 扩展、本页地址已绑定,然后刷新本页`};try{let e=await i.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(ve,{detail:{text:n}}))}catch{}return null},shortcuts:{register:(e,t)=>Ce(String(e??``),t)},searchProviders:{register:e=>we(e),list:()=>U()},composerProviders:{register:e=>Te(e),list:()=>G()},ttsProviders:{register:e=>Oe(e),list:()=>J()},onTheme:e=>Ne(e),onLocale:e=>Pe(e),onViewChange:e=>Fe(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=>se(e),setCostCurrency:e=>oe(e),getCostCurrency:()=>D()}}function me(e){try{let t=window;e?t[j]=e:delete t[j]}catch{}}var F=new Map,I=null;async function he(e,t){let n=I;I=e;try{return await t()}finally{I=n}}var L=void 0;function ge(e,t){let n=L;L=e;try{return t()}finally{L=n}}function R(e,t,n){if(!t||typeof n!=`function`)return()=>{};let r=e?`${e}:${t}`:t,i=F.get(r);i||(i=new Set,F.set(r,i));let a=i;return a.add(n),()=>{a.delete(n),a.size===0&&F.delete(r)}}async function _e(e,t,n,r){let i=i=>{let a=F.get(i);if(!a||a.size===0)return!1;for(let i of[...a])try{ge(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 ve=`pi-web-ui:toast`,z=new Map,B=!1;function ye(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 be(){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 V(e){try{if(be())return;let t=`${e.ctrlKey?`ctrl+`:``}${e.shiftKey?`shift+`:``}${e.altKey?`alt+`:``}${e.metaKey?`meta+`:``}${(e.key??``).toLowerCase()}`,n=z.get(t);if(!n||n.size===0)return;for(let e of[...n])try{e()}catch(e){console.error(`[plugin-host] 快捷键处理器抛错:`,e)}}catch{}}function xe(){if(!B)try{if(typeof window>`u`||typeof window.addEventListener!=`function`)return;window.addEventListener(`keydown`,V),B=!0}catch{}}function Se(){if(!(z.size>0||!B))try{window.removeEventListener(`keydown`,V)}catch{}finally{B=!1}}function Ce(e,t){if(typeof t!=`function`)return()=>{};let n=ye(e);if(!n)return()=>{};let r=z.get(n.combo);r||(r=new Set,z.set(n.combo,r));let i=r;return i.add(t),xe(),()=>{i.delete(t),i.size===0&&z.delete(n.combo),Se()}}var H=new Map;function we(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 H.set(t,n),()=>{H.get(t)===n&&H.delete(t)}}function U(){return[...H.values()].map(e=>({id:e.id,label:e.label}))}var W=new Map;function Te(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 W.set(t,n),()=>{W.get(t)===n&&W.delete(t)}}function G(){return[...W.values()].map(e=>({id:e.id,label:e.label}))}function Ee(e){return W.get(String(e??``))}function De(e){return H.get(String(e??``))}var K=new Map,q=new Set;function Oe(e){let t=String(e?.id??``).trim();if(!t||typeof e?.play!=`function`)return()=>{};let n={id:t,label:String(e.label??t),labelEn:e.labelEn?String(e.labelEn):void 0,play:e.play,getVoices:e.getVoices};K.set(t,n);for(let e of q)try{e()}catch{}return()=>{if(K.get(t)===n){K.delete(t);for(let e of q)try{e()}catch{}}}}function J(){return[...K.values()].map(e=>({id:e.id,label:e.label,labelEn:e.labelEn}))}function ke(e){return K.get(String(e??``))}function Ae(e){return q.add(e),()=>{q.delete(e)}}var Y=new Set,X=new Set,Z=new Set,Q=new Set;function je(e){return Q.add(e),()=>{Q.delete(e)}}function Me(e){for(let t of Q)try{t(e)}catch(e){console.error(`[plugin-host] onModelChange 处理器抛错:`,e)}}function Ne(e){return typeof e==`function`?(Y.add(e),()=>{Y.delete(e)}):()=>{}}function Pe(e){return typeof e==`function`?(X.add(e),()=>{X.delete(e)}):()=>{}}function Fe(e){return typeof e==`function`?(Z.add(e),()=>{Z.delete(e)}):()=>{}}function Ie(e){let t=String(e??``);for(let e of Y)try{e(t)}catch(e){console.error(`[plugin-host] onTheme 处理器抛错:`,e)}}function Le(e){let t=String(e??``);for(let e of X)try{e(t)}catch(e){console.error(`[plugin-host] onLocale 处理器抛错:`,e)}}function Re(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 ze(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{ee as A,f as C,g as D,m as E,u as O,ne as S,h as T,de as _,Re as a,b,ke as c,U as d,J as f,he as g,_e as h,Ie as i,p as j,d as k,me as l,ze as m,Le as n,Ee as o,Ae as p,Me as r,De as s,pe as t,G as u,O as v,te as w,_ as x,le as y};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./app-globals-
|
|
1
|
+
import{t as e}from"./app-globals-CZxzGvIo.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}))});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})}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};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Dn as t,Tn as n,i as r}from"./app-globals-CZxzGvIo.js";import{i}from"./react-CR5VJ85Q.js";var a=e(i(),1),o=`pi-web-ui:theme`,s=`dark`,c=`theme-stylesheet`,l=Date.now().toString(36),u=0,d=3,f=0,p=`pi-web-ui:theme-change`;function m(){try{let e=localStorage.getItem(o);if(e&&e!==s)return e}catch{}return null}function h(e){try{e?localStorage.setItem(o,e):localStorage.removeItem(o)}catch{}}function g(e){return`${t(`/themes/${encodeURIComponent(e)}.css`)}?v=${l}.${u}`}function _(e,t={}){t.reload&&(u++,f=0),typeof document<`u`&&(e?document.documentElement.dataset.theme=e:delete document.documentElement.dataset.theme);let n=document.getElementById(c);if(!e){n?.remove(),window.dispatchEvent(new CustomEvent(p));return}n||(n=document.createElement(`link`),n.id=c,n.rel=`stylesheet`,document.head.appendChild(n));let r=n;r.href=g(e),r.onload=()=>{f=0,window.dispatchEvent(new CustomEvent(p))},r.onerror=()=>{if(f>=d)return;let t=400*2**f++;window.setTimeout(()=>{document.getElementById(c)===r&&(u++,r.href=g(e))},t)}}async function v(){try{let e=await fetch(n(t(`/api/themes`)));if(!e.ok)return[];let r=await e.json();return Array.isArray(r.themes)?r.themes:[]}catch{return[]}}function y(){let[e,t]=(0,a.useState)([]),[n,i]=(0,a.useState)(()=>m()),o=r(`status`)===`open`;(0,a.useEffect)(()=>{let e=!1;return v().then(n=>{e||t(n)}),()=>{e=!0}},[o]);let c=(0,a.useCallback)(()=>{v().then(t)},[]);return(0,a.useEffect)(()=>{_(n,{reload:o}),h(n)},[n,o]),{themes:e,theme:n,switchTheme:e=>i(e===s?null:e),reloadThemes:c}}function b(){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{y as a,m as i,_ as n,b as r,p as t};
|
package/web/dist/index.html
CHANGED
|
@@ -21,22 +21,22 @@
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
</script>
|
|
24
|
-
<script type="module" crossorigin src="./assets/index-
|
|
24
|
+
<script type="module" crossorigin src="./assets/index-EH5Fw9fa.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-CZxzGvIo.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-
|
|
33
|
-
<link rel="modulepreload" crossorigin href="./assets/plugin-host-
|
|
34
|
-
<link rel="modulepreload" crossorigin href="./assets/HintTip-
|
|
35
|
-
<link rel="modulepreload" crossorigin href="./assets/remote-ssh-client-
|
|
30
|
+
<link rel="modulepreload" crossorigin href="./assets/Dropdown-C4LIhshN.js">
|
|
31
|
+
<link rel="modulepreload" crossorigin href="./assets/theme-D2l_mLNo.js">
|
|
32
|
+
<link rel="modulepreload" crossorigin href="./assets/desktop-aAKpvKJV.js">
|
|
33
|
+
<link rel="modulepreload" crossorigin href="./assets/plugin-host-BRWib9DF.js">
|
|
34
|
+
<link rel="modulepreload" crossorigin href="./assets/HintTip-c6d0TJoh.js">
|
|
35
|
+
<link rel="modulepreload" crossorigin href="./assets/remote-ssh-client-CfYSMEZg.js">
|
|
36
36
|
<link rel="modulepreload" crossorigin href="./assets/markdown-BggnuQ4H.js">
|
|
37
37
|
<link rel="stylesheet" crossorigin href="./assets/markdown-C8LL_u4z.css">
|
|
38
|
-
<link rel="stylesheet" crossorigin href="./assets/index-
|
|
39
|
-
<meta name="pi-web-build-id" content="
|
|
38
|
+
<link rel="stylesheet" crossorigin href="./assets/index-C6DwztqE.css">
|
|
39
|
+
<meta name="pi-web-build-id" content="20261104T17521">
|
|
40
40
|
</head>
|
|
41
41
|
<body>
|
|
42
42
|
<div id="root"></div>
|
package/web/dist/sw.js
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* risk serving stale theme/plugin code or caching anything sensitive.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
const BUILD_ID = "
|
|
25
|
+
const BUILD_ID = "20261104T17521";
|
|
26
26
|
const STATIC_CACHE = BUILD_ID.startsWith("__") ? "pi-web-ui-static-dev" : `pi-web-ui-static-${BUILD_ID}`;
|
|
27
27
|
const SHELL_CACHE = "pi-web-ui-shell-v1";
|
|
28
28
|
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{At as t,B as n,Ft as r,Kt as i,L as a,Lt as o,O as s,Sn as c,Tt as l,Z as u,_n as ee,dt as d,gn as f,p,sn as m,vt as h,wn as te}from"./app-globals-DZNa9v8u.js";import{i as g,t as _}from"./react-CR5VJ85Q.js";import{Rt as v,T as ne,_t as y}from"./index-DTZch8uz.js";import{DeviceGroups as b}from"./DeviceGroups-CgBaDPrD.js";var x=e(g(),1),S=_();function re({href:e,children:t}){let n=ee(),[r,i]=(0,x.useState)(!1),[a,o]=(0,x.useState)(!1);return(0,S.jsxs)(S.Fragment,{children:[(0,S.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,S.jsxs)(`span`,{role:`alert`,children:[n(`deviceHubNetworkError`),` `,(0,S.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,children:e})]})]})}function C(e){if(!w(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 w(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 T(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 E=`https://raw.githubusercontent.com/xing-shuyin/pi-web-ui/main/docs/device-center-deployment.md`,D=`https://github.com/xing-shuyin/pi-web-ui/blob/main/docs/device-center-deployment.md`,O=`pi-web-ui hub install --host 0.0.0.0 --port 8790 --public-url http://SERVER_IP:8790 --allow-registration`;function k(e){let t=e=>e.includes(`:`)?w(e)&&![`::`,`::1`].includes(e):/^[\d.]+$/.test(e)?w(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 A(e,t,n,r){if(!C(e))throw Error(`Invalid Hub setup`);if(r){let t=k(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: ${E} (fallback: ${D}). 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: ${O}`,`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 j({onConnect:e,initialHubUrl:t=``}){let n=ee(),[r,i]=(0,x.useState)(t),[a,o]=(0,x.useState)(``),[s,l]=(0,x.useState)(!1),[u,d]=(0,x.useState)(!1),f=(0,x.useRef)(!1),p=(0,x.useRef)(!1);(0,x.useEffect)(()=>(p.current=!0,()=>{p.current=!1}),[]);let[m,h]=(0,x.useState)(null),[g,_]=(0,x.useState)(`current`),[v,ne]=(0,x.useState)(null),[y,b]=(0,x.useState)(`127.0.0.1`),[w,E]=(0,x.useState)(`8790`),[D,O]=(0,x.useState)(`http://127.0.0.1:8790`),[j,M]=(0,x.useState)({server:``,sshPort:22,username:`root`,auth:`password`,port:8790,domain:``,https:!1}),ie=k(j),[N,P]=(0,x.useState)(!1),[F,I]=(0,x.useState)(!1),[L,ae]=(0,x.useState)(!1),[oe,R]=(0,x.useState)(!1),[z,B]=(0,x.useState)(null),V=(0,x.useRef)(null),H=(0,x.useRef)(!1),U=T(window.location.origin);(0,x.useEffect)(()=>()=>V.current?.abort(),[]);let W=async()=>{if(H.current)return;V.current?.abort();let e=new AbortController;V.current=e,I(!1),ae(!1),R(!1);try{let t=await fetch(c(te(`/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`||!C({host:`127.0.0.1`,port:n.defaultPort,publicUrl:n.defaultPublicUrl}))throw Error();if(e.signal.aborted)return;ne(n),n.installation?.installed?(b(n.installation.host??`127.0.0.1`),E(String(n.installation.port)),O(n.installation.publicUrl??``),i(n.installation.publicUrl??``)):v||(E(String(n.defaultPort)),O(n.defaultPublicUrl))}catch{e.signal.aborted||(I(!0),R(!0))}finally{e.signal.aborted||ae(!0)}},G=async()=>{let e={host:y,port:Number(w),publicUrl:D};if(H.current||!U||!v||!L||oe||v.busy||v.installation?.installed||!C(e))return;H.current=!0,V.current?.abort(),P(!0),I(!1),o(``);let t=new AbortController;V.current=t;try{let n=await fetch(c(te(`/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){ne(e=>e&&{...e,busy:!0}),H.current=!1,P(!1),await W();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(!C({...e,publicUrl:r.publicUrl})||typeof r.output!=`string`)throw Error();t.signal.aborted||B(r)}catch(e){t.signal.aborted||(I(!0),o(e instanceof Error?e.message.slice(0,4096):``))}finally{H.current=!1,t.signal.aborted||P(!1)}},K=v?.installation,q=!!K?.installed,J=q&&K.running&&K.owned,Y=g===`remote`?ie:{host:y,port:Number(w),publicUrl:D},X=!!Y&&C(Y);return(0,S.jsxs)(`section`,{className:`dc-onboarding`,children:[(0,S.jsx)(`h3`,{children:n(`deviceSetupWelcome`)}),(0,S.jsx)(`p`,{children:n(`deviceSetupIntro`)}),(0,S.jsxs)(`div`,{className:`dc-actions`,children:[(0,S.jsx)(`button`,{className:`dc-button`,disabled:N,"aria-pressed":m===`connect`,onClick:()=>h(`connect`),children:n(`deviceSetupConnect`)}),(0,S.jsx)(`button`,{className:`dc-button`,disabled:N,"aria-pressed":m===`create`,onClick:()=>{h(`create`),!v&&U&&W()},children:n(`deviceSetupCreate`)})]}),m===`connect`&&(0,S.jsxs)(`form`,{onSubmit:t=>{t.preventDefault(),e(r.trim())},children:[(0,S.jsxs)(`label`,{className:`dc-field`,children:[(0,S.jsx)(`span`,{children:n(`deviceHubHubUrl`)}),(0,S.jsx)(`input`,{type:`url`,required:!0,maxLength:2048,value:r,onChange:e=>i(e.target.value),placeholder:`https://hub.example.com`})]}),(0,S.jsx)(`button`,{className:`dc-button is-primary`,disabled:!C({host:`localhost`,port:8790,publicUrl:r.trim()}),children:n(`deviceSetupPair`)})]}),m===`create`&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`label`,{className:`dc-field`,children:[(0,S.jsx)(`span`,{children:n(`deviceSetupTarget`)}),(0,S.jsxs)(`select`,{disabled:N,value:g,onChange:e=>_(e.target.value),children:[(0,S.jsx)(`option`,{value:`current`,children:n(`deviceSetupCurrent`)}),(0,S.jsx)(`option`,{value:`remote`,children:n(`deviceSetupRemote`)})]})]}),(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`p`,{children:n(g===`current`?`deviceSetupCurrentHint`:`deviceSetupRemoteHint`)}),g===`current`&&(0,S.jsxs)(`div`,{className:`dc-setup-plan`,children:[(0,S.jsx)(`strong`,{children:n(`deviceSetupPlan`)}),(0,S.jsx)(`p`,{children:n(`deviceSetupPlanHint`)}),v&&(0,S.jsxs)(`dl`,{children:[(0,S.jsx)(`dt`,{children:n(`deviceSetupEnvironment`)}),(0,S.jsxs)(`dd`,{children:[v.platform,` · Node `,v.nodeVersion]}),(0,S.jsx)(`dt`,{children:n(`deviceSetupDataDir`)}),(0,S.jsx)(`dd`,{children:v.dataDir}),(0,S.jsx)(`dt`,{children:n(`deviceSetupCli`)}),(0,S.jsx)(`dd`,{children:v.cliPath})]}),!U&&(0,S.jsx)(`p`,{role:`status`,children:n(`deviceSetupLocalOnly`)}),(0,S.jsx)(`p`,{children:n(`deviceSetupBackground`)}),q&&(0,S.jsxs)(`div`,{role:`status`,children:[(0,S.jsx)(`h4`,{children:n(J?`deviceSetupRestored`:`deviceSetupUnhealthy`)}),(0,S.jsx)(`p`,{children:K.publicUrl}),J&&X&&K.publicUrl?(0,S.jsxs)(`div`,{className:`dc-actions`,children:[(0,S.jsx)(re,{href:K.publicUrl,children:n(`deviceHubOpenHub`)}),(0,S.jsx)(`button`,{className:`dc-button`,onClick:()=>e(K.publicUrl),children:n(`deviceSetupPair`)})]}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`p`,{children:n(`deviceSetupRecovery`)}),(0,S.jsx)(`pre`,{className:`dc-setup-output`,children:`pi-web-ui hub status --json
|
|
3
|
-
pi-web-ui hub --help`})]})]}),v?.busy&&(0,S.jsx)(`p`,{role:`status`,children:n(`deviceSetupBusy`)}),U&&(0,S.jsx)(`button`,{className:`dc-button`,disabled:N||!L,onClick:()=>void W(),children:n(L?`deviceSetupRetry`:`deviceHubWorking`)})]}),g===`remote`?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`dc-setup-fields`,children:[(0,S.jsxs)(`label`,{className:`dc-field`,children:[(0,S.jsx)(`span`,{children:n(`deviceSetupServer`)}),(0,S.jsx)(`input`,{autoComplete:`off`,maxLength:253,placeholder:`203.0.113.10`,value:j.server,onChange:e=>M({...j,server:e.target.value.trim()})})]}),(0,S.jsxs)(`label`,{className:`dc-field`,children:[(0,S.jsx)(`span`,{children:n(`deviceSetupSshPort`)}),(0,S.jsx)(`input`,{type:`number`,min:1,max:65535,value:j.sshPort,onChange:e=>M({...j,sshPort:Number(e.target.value)})})]}),(0,S.jsxs)(`label`,{className:`dc-field`,children:[(0,S.jsx)(`span`,{children:n(`deviceSetupUsername`)}),(0,S.jsx)(`input`,{autoComplete:`off`,maxLength:64,value:j.username,onChange:e=>M({...j,username:e.target.value})})]}),(0,S.jsxs)(`label`,{className:`dc-field`,children:[(0,S.jsx)(`span`,{children:n(`deviceSetupAuth`)}),(0,S.jsxs)(`select`,{value:j.auth,onChange:e=>M({...j,auth:e.target.value}),children:[(0,S.jsx)(`option`,{value:`password`,children:n(`deviceSetupAuthPassword`)}),(0,S.jsx)(`option`,{value:`key`,children:n(`deviceSetupAuthKey`)}),(0,S.jsx)(`option`,{value:`existing`,children:n(`deviceSetupAuthExisting`)})]})]}),(0,S.jsxs)(`label`,{className:`dc-field`,children:[(0,S.jsx)(`span`,{children:n(`deviceSetupServicePort`)}),(0,S.jsx)(`input`,{type:`number`,min:1024,max:65535,value:j.port,onChange:e=>M({...j,port:Number(e.target.value)})})]})]}),(0,S.jsx)(`p`,{children:n(`deviceSetupCredentialHint`)}),(0,S.jsxs)(`details`,{children:[(0,S.jsx)(`summary`,{children:n(`deviceSetupOptionalTls`)}),(0,S.jsxs)(`label`,{className:`dc-field`,children:[(0,S.jsx)(`span`,{children:n(`deviceSetupDomain`)}),(0,S.jsx)(`input`,{maxLength:253,placeholder:`hub.example.com`,value:j.domain,onChange:e=>M({...j,domain:e.target.value.trim()})})]}),(0,S.jsxs)(`label`,{children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:j.https,onChange:e=>M({...j,https:e.target.checked})}),` `,n(`deviceSetupEnableHttps`)]}),(0,S.jsx)(`p`,{children:n(`deviceSetupTlsHint`)})]}),(0,S.jsxs)(`p`,{children:[(0,S.jsx)(`strong`,{children:n(`deviceSetupPreview`)}),` `,ie?.publicUrl??n(`deviceSetupPreviewEmpty`)]}),(0,S.jsxs)(`div`,{className:`dc-setup-plan`,children:[(0,S.jsx)(`strong`,{children:n(`deviceSetupUserActions`)}),(0,S.jsx)(`p`,{children:n(`deviceSetupCloudPorts`).replace(`{ports}`,j.https?`443 / 80`:String(j.port))}),(0,S.jsx)(`p`,{children:n(`deviceSetupSourceScope`)}),(0,S.jsx)(`p`,{children:n(`deviceSetupAfterStart`)})]}),(0,S.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,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`dc-setup-fields`,children:[(0,S.jsxs)(`label`,{className:`dc-field`,children:[(0,S.jsx)(`span`,{children:n(`deviceSetupHost`)}),(0,S.jsx)(`input`,{disabled:N||!!z,maxLength:253,value:y,onChange:e=>b(e.target.value)})]}),(0,S.jsxs)(`label`,{className:`dc-field`,children:[(0,S.jsx)(`span`,{children:n(`deviceSetupPort`)}),(0,S.jsx)(`input`,{disabled:N||!!z,type:`number`,min:1024,max:65535,value:w,onChange:e=>E(e.target.value)})]}),(0,S.jsxs)(`label`,{className:`dc-field`,children:[(0,S.jsx)(`span`,{children:n(`deviceHubHubUrl`)}),(0,S.jsx)(`input`,{disabled:N||!!z,maxLength:2048,value:D,onChange:e=>O(e.target.value)})]})]}),(0,S.jsx)(`p`,{className:`dc-setup-warning`,children:n(`deviceSetupReachable`)})]}),(0,S.jsx)(`p`,{children:n(`deviceSetupRegistration`)}),!X&&(0,S.jsx)(`p`,{role:`alert`,children:n(g===`remote`?`deviceSetupRemoteInvalid`:`deviceSetupInvalid`)}),(0,S.jsxs)(`div`,{className:`dc-actions`,children:[g===`current`&&!z&&!q&&(0,S.jsx)(`button`,{className:`dc-button is-primary`,disabled:N||!U||!v||!L||oe||!!v.busy||!X,onClick:()=>void G(),children:n(N?`deviceSetupInstalling`:`deviceSetupInstall`)}),(0,S.jsx)(`button`,{className:`dc-button`,disabled:N||s||!X,onClick:()=>{if(!X||!Y||f.current)return;f.current=!0,l(!0),d(!1);let e=e=>{f.current=!1,p.current&&(l(!1),d(!e))},t=window.__piWebUiHost;try{t?.startChat({newChat:!0,prompt:A(Y,v,g,g===`remote`?j:void 0),onResult:e})||e(!1)}catch{e(!1)}},children:n(g===`remote`?`deviceSetupStartAi`:`deviceSetupAi`)})]}),(0,S.jsx)(`p`,{children:n(`deviceSetupAiHint`)}),s&&(0,S.jsx)(`p`,{role:`status`,children:n(`deviceSetupAiCreating`)}),u&&(0,S.jsx)(`p`,{role:`alert`,children:n(`deviceSetupAiFailed`)})]})]}),F&&(0,S.jsxs)(`div`,{role:`alert`,children:[(0,S.jsx)(`p`,{children:n(`deviceSetupFailed`)}),a&&(0,S.jsx)(`pre`,{className:`dc-setup-output`,children:a})]}),z&&(0,S.jsxs)(`div`,{role:`status`,children:[(0,S.jsx)(`h4`,{children:n(`deviceSetupSuccess`)}),(0,S.jsx)(`pre`,{className:`dc-setup-output`,children:z.output.slice(0,16e3)}),(0,S.jsxs)(`div`,{className:`dc-actions`,children:[(0,S.jsx)(re,{href:z.publicUrl,children:n(`deviceHubOpenHub`)}),(0,S.jsx)(`button`,{className:`dc-button is-primary`,onClick:()=>e(z.publicUrl),children:n(`deviceSetupPair`)})]})]})]})}var M={maxActiveTasks:4,maxWaitingTasks:32};function ie(e){let t={settings:{...M},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=typeof r.maxActiveTasks==`number`&&Number.isFinite(r.maxActiveTasks)?Math.max(1,Math.min(16,r.maxActiveTasks)):M.maxActiveTasks,a=typeof r.maxWaitingTasks==`number`&&Number.isFinite(r.maxWaitingTasks)?Math.max(0,Math.min(128,r.maxWaitingTasks)):M.maxWaitingTasks,o=Array.isArray(n.running)?n.running:[],s=Array.isArray(n.waiting)?n.waiting:[],c=Array.isArray(n.blocked)?n.blocked:[];return{settings:{maxActiveTasks:i,maxWaitingTasks:a},activeCount:typeof n.activeCount==`number`?n.activeCount:o.length,waitingCount:typeof n.waitingCount==`number`?n.waitingCount:s.length,blockedCount:typeof n.blockedCount==`number`?n.blockedCount:c.length,running:o,waiting:s,blocked:c}}function N({hubUrl:e,deviceId:t,onNotice:n}){let l=ee(),[u,d]=(0,x.useState)(null),[f,h]=(0,x.useState)(M.maxActiveTasks),[g,_]=(0,x.useState)(M.maxWaitingTasks),[v,ne]=(0,x.useState)(!1),[y,b]=(0,x.useState)(!1),[re,C]=(0,x.useState)(null),[w,T]=(0,x.useState)(null),[E,D]=(0,x.useState)(null),O=(0,x.useRef)(!0),k=(0,x.useRef)(0),A=(0,x.useRef)(new Set),j=(0,x.useRef)(!1),N=(0,x.useRef)(!1),P=`${e??``}:${t??``}`,F=(0,x.useCallback)(async(e,t,n)=>{let r=new AbortController;A.current.add(r);let i=()=>r.abort();n&&(n.aborted?r.abort():n.addEventListener(`abort`,i,{once:!0}));try{let n=await fetch(c(te(`/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}),i=await n.json().catch(()=>({}));if(!n.ok){let e=typeof i.error==`string`?i.error:`HTTP ${n.status}`;throw Error(e)}return i}finally{n&&n.removeEventListener(`abort`,i),A.current.delete(r)}},[]),I=(0,x.useCallback)(async(e=!1)=>{if(!O.current||j.current)return;j.current=!0;let t=k.current;e||ne(!0);try{let e=await F(`execution-queue`);if(!O.current||t!==k.current)return;let n=ie(e);d(n),T(null),N.current||=(h(n.settings.maxActiveTasks),_(n.settings.maxWaitingTasks),!0)}catch(e){if(!O.current||t!==k.current)return;e.name!==`AbortError`&&T(e.message)}finally{j.current=!1,O.current&&t===k.current&&!e&&ne(!1)}},[F]);(0,x.useEffect)(()=>{O.current=!0,k.current++;for(let e of A.current)e.abort();A.current.clear(),j.current=!1,N.current=!1,d(null),T(null),D(null),I(!1);let e=setInterval(()=>{I(!0)},3e3);return()=>{O.current=!1,k.current++;for(let e of A.current)e.abort();A.current.clear(),clearInterval(e)}},[P,I]);let L=async e=>{e.preventDefault();let t=k.current;b(!0),T(null),D(null);try{let e=await F(`execution-settings`,{maxActiveTasks:Number(f),maxWaitingTasks:Number(g)});if(!O.current||t!==k.current)return;e?.settings&&(h(e.settings.maxActiveTasks??M.maxActiveTasks),_(e.settings.maxWaitingTasks??M.maxWaitingTasks)),D(l(`deviceExecSavedNotice`)),n?.(l(`deviceExecSavedNotice`)),await I(!0)}catch(e){if(!O.current||t!==k.current)return;e.name!==`AbortError`&&T(e.message)}finally{O.current&&t===k.current&&b(!1)}},ae=async(e,t)=>{let r=k.current;C(e),T(null);try{if(await F(`execution-queue/cancel`,{taskId:e,attemptId:t}),!O.current||r!==k.current)return;n?.(l(`deviceExecTaskCancelled`)),await I(!0)}catch(e){if(!O.current||r!==k.current)return;e.name!==`AbortError`&&T(e.message)}finally{O.current&&r===k.current&&C(null)}},oe=e=>{switch(e){case`max_concurrency_reached`:return l(`deviceExecReasonMaxConcurrency`);case`bot_busy`:return l(`deviceExecReasonBotBusy`);case`workspace_conflict`:return l(`deviceExecReasonWorkspaceConflict`);case`workspace_blocked`:return l(`deviceExecReasonWorkspaceBlocked`);case`room_fairness_yield`:return l(`deviceExecReasonFairness`);default:return e}},R=u?.settings?.maxActiveTasks??M.maxActiveTasks,z=u?.settings?.maxWaitingTasks??M.maxWaitingTasks;return(0,S.jsxs)(`div`,{className:`des-container`,children:[(0,S.jsxs)(`div`,{className:`des-header`,children:[(0,S.jsxs)(`div`,{className:`des-header-left`,children:[(0,S.jsx)(`h3`,{className:`des-title`,children:l(`deviceExecTitle`)}),(0,S.jsx)(`p`,{className:`des-subtitle`,children:l(`deviceExecSubtitle`)})]}),(0,S.jsx)(`button`,{type:`button`,className:`des-refresh-btn`,onClick:()=>void I(!1),disabled:v,title:l(`deviceExecRefresh`),children:(0,S.jsx)(o,{className:v?`des-spin`:``})})]}),w&&(0,S.jsxs)(`div`,{className:`des-alert des-alert-error`,role:`alert`,children:[(0,S.jsx)(p,{className:`des-alert-icon`}),(0,S.jsx)(`div`,{className:`des-alert-text`,children:w}),(0,S.jsx)(`button`,{type:`button`,className:`des-alert-close`,onClick:()=>T(null),children:(0,S.jsx)(m,{})})]}),E&&(0,S.jsxs)(`div`,{className:`des-alert des-alert-success`,role:`status`,children:[(0,S.jsx)(s,{className:`des-alert-icon`}),(0,S.jsx)(`div`,{className:`des-alert-text`,children:E}),(0,S.jsx)(`button`,{type:`button`,className:`des-alert-close`,onClick:()=>D(null),children:(0,S.jsx)(m,{})})]}),(0,S.jsxs)(`div`,{className:`des-stats-row`,children:[(0,S.jsxs)(`div`,{className:`des-stat-card`,children:[(0,S.jsxs)(`div`,{className:`des-stat-label`,children:[(0,S.jsx)(r,{className:`des-stat-icon is-running`}),` `,l(`deviceExecRunning`)]}),(0,S.jsxs)(`div`,{className:`des-stat-value`,children:[u?.activeCount??0,` `,(0,S.jsxs)(`span`,{className:`des-stat-sub`,children:[`/ `,R]})]})]}),(0,S.jsxs)(`div`,{className:`des-stat-card`,children:[(0,S.jsxs)(`div`,{className:`des-stat-label`,children:[(0,S.jsx)(a,{className:`des-stat-icon is-waiting`}),` `,l(`deviceExecQueued`)]}),(0,S.jsxs)(`div`,{className:`des-stat-value`,children:[u?.waitingCount??0,` `,(0,S.jsxs)(`span`,{className:`des-stat-sub`,children:[`/ `,z]})]})]}),(0,S.jsxs)(`div`,{className:`des-stat-card`,children:[(0,S.jsxs)(`div`,{className:`des-stat-label`,children:[(0,S.jsx)(i,{className:`des-stat-icon is-blocked`}),` `,l(`deviceExecBlocked`)]}),(0,S.jsx)(`div`,{className:`des-stat-value${(u?.blockedCount??0)>0?` is-warn`:``}`,children:u?.blockedCount??0})]})]}),(0,S.jsxs)(`form`,{className:`des-form-card`,onSubmit:e=>void L(e),children:[(0,S.jsx)(`h4`,{className:`des-form-title`,children:l(`deviceExecQuotaTitle`)}),(0,S.jsxs)(`div`,{className:`des-fields-row`,children:[(0,S.jsxs)(`div`,{className:`des-field`,children:[(0,S.jsx)(`label`,{htmlFor:`des-max-active`,className:`des-label`,children:l(`deviceExecMaxActive`)}),(0,S.jsx)(`input`,{id:`des-max-active`,type:`number`,min:1,max:16,className:`des-input`,value:f,onChange:e=>h(parseInt(e.target.value,10)||1),required:!0}),(0,S.jsx)(`span`,{className:`des-hint`,children:l(`deviceExecMaxActiveHint`)})]}),(0,S.jsxs)(`div`,{className:`des-field`,children:[(0,S.jsx)(`label`,{htmlFor:`des-max-waiting`,className:`des-label`,children:l(`deviceExecMaxWaiting`)}),(0,S.jsx)(`input`,{id:`des-max-waiting`,type:`number`,min:0,max:128,className:`des-input`,value:g,onChange:e=>_(parseInt(e.target.value,10)||0),required:!0}),(0,S.jsx)(`span`,{className:`des-hint`,children:l(`deviceExecMaxWaitingHint`)})]})]}),(0,S.jsxs)(`div`,{className:`des-form-actions`,children:[(0,S.jsx)(`button`,{type:`button`,className:`des-btn des-btn-secondary`,disabled:y,onClick:()=>{h(R),_(z)},children:l(`deviceExecReset`)}),(0,S.jsx)(`button`,{type:`submit`,className:`des-btn des-btn-primary`,disabled:y,children:l(y?`deviceExecSaving`:`deviceExecSave`)})]})]}),u&&u.blocked&&u.blocked.length>0&&(0,S.jsxs)(`div`,{className:`des-section des-blocked-section`,children:[(0,S.jsxs)(`h4`,{className:`des-section-title is-danger`,children:[(0,S.jsx)(p,{}),` `,l(`deviceExecBlockedTitle`)]}),(0,S.jsx)(`p`,{className:`des-section-desc`,children:l(`deviceExecBlockedDesc`)}),(0,S.jsx)(`div`,{className:`des-table-wrap`,children:(0,S.jsxs)(`table`,{className:`des-table`,children:[(0,S.jsx)(`thead`,{children:(0,S.jsxs)(`tr`,{children:[(0,S.jsx)(`th`,{children:`Task ID`}),(0,S.jsx)(`th`,{children:`Room ID`}),(0,S.jsx)(`th`,{children:`Bot ID`}),(0,S.jsx)(`th`,{children:l(`deviceExecReason`)})]})}),(0,S.jsx)(`tbody`,{children:u.blocked.map(e=>(0,S.jsxs)(`tr`,{className:`des-row-blocked`,children:[(0,S.jsxs)(`td`,{className:`des-mono`,children:[e.taskId.slice(0,8),`...`]}),(0,S.jsx)(`td`,{children:e.roomId}),(0,S.jsx)(`td`,{children:e.botId}),(0,S.jsx)(`td`,{children:(0,S.jsx)(`span`,{className:`des-badge is-danger`,children:e.reason})})]},`${e.taskId}-${e.attemptId}`))})]})})]}),(0,S.jsxs)(`div`,{className:`des-section`,children:[(0,S.jsxs)(`h4`,{className:`des-section-title`,children:[(0,S.jsx)(r,{}),` `,l(`deviceExecActiveTasks`),` (`,u?.running?.length??0,`)`]}),u&&u.running&&u.running.length>0?(0,S.jsx)(`div`,{className:`des-table-wrap`,children:(0,S.jsxs)(`table`,{className:`des-table`,children:[(0,S.jsx)(`thead`,{children:(0,S.jsxs)(`tr`,{children:[(0,S.jsx)(`th`,{children:`Task ID`}),(0,S.jsx)(`th`,{children:`Room ID`}),(0,S.jsx)(`th`,{children:`Bot ID`}),(0,S.jsx)(`th`,{children:l(`deviceExecQueuedTime`)})]})}),(0,S.jsx)(`tbody`,{children:u.running.map(e=>(0,S.jsxs)(`tr`,{children:[(0,S.jsxs)(`td`,{className:`des-mono`,title:e.taskId,children:[e.taskId.slice(0,8),`...`]}),(0,S.jsx)(`td`,{children:e.roomId}),(0,S.jsx)(`td`,{children:e.botId}),(0,S.jsx)(`td`,{children:new Date(e.startedAt).toLocaleTimeString()})]},`${e.taskId}-${e.attemptId}`))})]})}):(0,S.jsx)(`div`,{className:`des-empty`,children:l(`deviceExecNoActive`)})]}),(0,S.jsxs)(`div`,{className:`des-section`,children:[(0,S.jsxs)(`h4`,{className:`des-section-title`,children:[(0,S.jsx)(a,{}),` `,l(`deviceExecWaitingQueue`),` (`,u?.waiting?.length??0,`)`]}),u&&u.waiting&&u.waiting.length>0?(0,S.jsx)(`div`,{className:`des-table-wrap`,children:(0,S.jsxs)(`table`,{className:`des-table`,children:[(0,S.jsx)(`thead`,{children:(0,S.jsxs)(`tr`,{children:[(0,S.jsx)(`th`,{children:l(`deviceExecPosition`)}),(0,S.jsx)(`th`,{children:`Task ID`}),(0,S.jsx)(`th`,{children:`Room ID`}),(0,S.jsx)(`th`,{children:`Bot ID`}),(0,S.jsx)(`th`,{children:l(`deviceExecReason`)}),(0,S.jsx)(`th`,{children:l(`deviceExecQueuedTime`)}),(0,S.jsx)(`th`,{children:l(`deviceExecActions`)})]})}),(0,S.jsx)(`tbody`,{children:u.waiting.map(e=>(0,S.jsxs)(`tr`,{children:[(0,S.jsx)(`td`,{children:(0,S.jsxs)(`span`,{className:`des-pos-badge`,children:[`#`,e.queuePosition]})}),(0,S.jsxs)(`td`,{className:`des-mono`,title:e.taskId,children:[e.taskId.slice(0,8),`...`]}),(0,S.jsx)(`td`,{children:e.roomId}),(0,S.jsx)(`td`,{children:e.botId}),(0,S.jsx)(`td`,{children:(0,S.jsxs)(`div`,{className:`des-reason-cell`,children:[(0,S.jsx)(`span`,{className:`des-badge des-badge-${e.blockReason}`,children:oe(e.blockReason)}),(0,S.jsx)(`span`,{className:`des-reason-detail`,children:e.blockReasonDetail})]})}),(0,S.jsx)(`td`,{children:new Date(e.queuedAt).toLocaleTimeString()}),(0,S.jsx)(`td`,{children:(0,S.jsx)(`button`,{type:`button`,className:`des-btn des-btn-danger-sm`,disabled:re===e.taskId,onClick:()=>void ae(e.taskId,e.attemptId),children:re===e.taskId?l(`deviceExecCancelling`):l(`deviceExecCancel`)})})]},`${e.taskId}-${e.attemptId}`))})]})}):(0,S.jsx)(`div`,{className:`des-empty`,children:l(`deviceExecNoWaiting`)})]})]})}var P=class extends Error{status;constructor(e,t){super(t),this.status=e}};function F(e){try{let t=new URL(e);return[`http:`,`https:`].includes(t.protocol)&&!t.username&&!t.password?t.href:null}catch{return null}}function I(){let e=ee(),n=f().startsWith(`zh`),[r,i]=(0,x.useState)(null),[a,s]=(0,x.useState)(!1),[l,u]=(0,x.useState)(!1),[d,p]=(0,x.useState)(!1),[m,h]=(0,x.useState)(!1),g=(0,x.useRef)(0),_=(0,x.useRef)(null);async function v(e,t){if(_.current)return;let n=++g.current,r=new AbortController;_.current=r,s(!0),u(!1);try{let a=await fetch(c(te(`/api/device-desktop/local/${e}`)),{method:t?`POST`:`GET`,credentials:`same-origin`,signal:r.signal,...t?{headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}:{}});if(g.current!==n||r.signal.aborted)return;if(a.status===403){p(!0),i(null);return}if(!a.ok)throw Error(`Request failed`);let o=await a.json();if(g.current!==n||r.signal.aborted)return;if(e===`permissions`){if(typeof o?.screen!=`boolean`||typeof o?.accessibility!=`boolean`)throw Error(`Invalid permission status`);i(e=>e&&{...e,permissions:{supported:!0,screen:o.screen,accessibility:o.accessibility}}),h(!0)}else{if(typeof o?.os!=`string`||typeof o.enabled!=`boolean`||typeof o.environmentEnabled!=`boolean`||typeof o.supported!=`boolean`)throw Error(`Invalid desktop status`);i(o)}}catch{g.current===n&&!r.signal.aborted&&u(!0)}finally{g.current===n&&!r.signal.aborted&&(_.current=null,s(!1))}}return(0,x.useEffect)(()=>(v(`status`),()=>{g.current++,_.current?.abort(),_.current=null}),[]),(0,S.jsxs)(`section`,{className:`dc-card`,"aria-label":n?`本机远程桌面`:`Local remote desktop`,"aria-busy":a,children:[(0,S.jsxs)(`div`,{className:`dc-card-header`,children:[(0,S.jsx)(`span`,{className:`dc-icon`,children:(0,S.jsx)(t,{"aria-hidden":!0})}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h2`,{children:n?`本机远程桌面`:`Local remote desktop`}),(0,S.jsx)(`p`,{children:n?`管理这台设备的远程桌面与系统权限,无需连接设备中心。`:`Manage remote desktop and system permissions on this device, even while the device center is offline.`})]})]}),d?(0,S.jsx)(`p`,{role:`status`,children:n?`请在设备本机打开此页面以管理远程桌面权限。`:`Open this page on the device itself to manage remote desktop permissions.`}):(0,S.jsxs)(S.Fragment,{children:[r&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`dc-permission-row`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h3`,{id:`dc-desktop-label`,children:n?`启用远程桌面`:`Enable remote desktop`}),(0,S.jsx)(`p`,{children:r.enabled?n?`已启用`:`Enabled`:n?`未启用`:`Disabled`})]}),(0,S.jsx)(`button`,{type:`button`,className:`dc-toggle${r.enabled?` is-on`:``}`,role:`switch`,"aria-checked":r.enabled,"aria-labelledby":`dc-desktop-label`,disabled:a||r.environmentEnabled||!r.supported&&!r.enabled,onClick:()=>void v(`enable`,{enabled:!r.enabled}),children:(0,S.jsx)(`span`,{className:`dc-toggle-thumb`})})]}),!r.supported&&(0,S.jsx)(`p`,{children:n?`这台设备暂不支持远程桌面。`:`Remote desktop is currently unavailable on this device.`}),r.environmentEnabled&&(0,S.jsx)(`p`,{children:n?`远程桌面由本机服务设置保持启用。`:`Remote desktop is kept enabled by the service settings on this device.`}),r.os===`darwin`&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`p`,{children:n?`点击下方按钮发起系统授权,请在这台 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,S.jsxs)(`div`,{className:`dc-actions`,children:[(0,S.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:a||r.permissions?.supported===!1,onClick:()=>void v(`permissions`,{kind:`screen`}),children:n?`授予屏幕录制权限`:`Grant screen recording permission`}),(0,S.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:a||r.permissions?.supported===!1,onClick:()=>void v(`permissions`,{kind:`control`}),children:n?`授予远程控制权限`:`Grant remote control permission`})]}),r.permissions?.screen===!0&&(0,S.jsx)(`p`,{children:n?`屏幕录制:已授权`:`Screen recording: granted`}),r.permissions?.accessibility===!0&&(0,S.jsx)(`p`,{children:n?`远程控制:已授权`:`Remote control: granted`}),m&&(0,S.jsx)(`p`,{role:`status`,children:n?`已发起授权请求,请确认系统设置后刷新状态。`:`Permission requested. Confirm in System Settings, then refresh the status.`})]})]}),l&&(0,S.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:n?`无法更新本机远程桌面设置,请重试。`:`Unable to update local remote desktop settings. Please retry.`}),(0,S.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:a,onClick:()=>void v(`status`),children:[(0,S.jsx)(o,{"aria-hidden":!0}),a?e(`deviceHubWorking`):n?`刷新远程桌面状态`:`Refresh remote desktop status`]})]})]})}function L({pathCompletions:e=[]}){let r=ee(),a=ne(),[f,p]=(0,x.useState)(a.revision?`groups`:`overview`);(0,x.useEffect)(()=>{a.revision&&p(`groups`)},[a.revision]);let[m,g]=(0,x.useState)(null),[_,C]=(0,x.useState)(``),[w,T]=(0,x.useState)(``),[E,D]=(0,x.useState)(null),[O,k]=(0,x.useState)(Date.now()),[A,M]=(0,x.useState)(null),[ie,L]=(0,x.useState)(``),[ae,oe]=(0,x.useState)(``),[R,z]=(0,x.useState)(``),[B,V]=(0,x.useState)(!1),[H,U]=(0,x.useState)(!0),W=(0,x.useRef)(!1),G=(0,x.useRef)(0),K=(0,x.useRef)(new Set),q=(0,x.useRef)(!1),J=(0,x.useRef)(!1),Y=(0,x.useRef)(null),X=(0,x.useRef)(r);X.current=r;async function Z(e,t){let n=new AbortController;K.current.add(n);try{let r=await fetch(c(te(`/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 P(r.status,typeof i.error==`string`?i.error:X.current(`deviceHubRequestFailed`,{status:r.status}));return i}finally{K.current.delete(n)}}function Q(e){return W.current&&G.current===e}function se(e){return e instanceof P&&e.status===403?(V(!0),X.current(`deviceHubLocalOnly`)):e instanceof Error?e.message:X.current(`deviceHubNetworkError`)}function ce(e){Y.current=e,g(e),J.current||(T(e.name),C(e.hubUrl??``))}async function le(){let e=G.current;try{let t=await Z(`status`);if(!Q(e)||q.current)return;ce(t),oe(``),V(!1)}catch(t){Q(e)&&oe(se(t))}finally{Q(e)&&U(!1)}}(0,x.useEffect)(()=>{W.current=!0;let e=!1,t,n=async()=>{await le(),!e&&W.current&&(t=setTimeout(n,5e3))};return n(),()=>{e=!0,W.current=!1,G.current++,clearTimeout(t);for(let e of K.current)e.abort()}},[]),(0,x.useEffect)(()=>{if(!E)return;let e=G.current,t=!1,n,r=setInterval(()=>k(Date.now()),1e3),i=async()=>{if(!(t||!Q(e)||Date.now()>=E.expiresAt)){try{let n=await Z(`poll`,{});if(t||!Q(e))return;if(n.paired){let n=await Z(`status`);if(t||!Q(e))return;J.current=!1,ce(n),D(null),L(``),z(``);return}L(``)}catch(n){!t&&Q(e)&&L(`${X.current(`deviceHubPollError`)} ${se(n)}`)}!t&&Q(e)&&(n=setTimeout(i,2e3))}};return n=setTimeout(i,2e3),()=>{t=!0,clearTimeout(n),clearInterval(r)}},[E]);async function ue(){if(q.current)return;let e=F(_.trim());if(!e){L(r(`deviceHubInvalidUrl`));return}if(!w.trim()||w.trim().length>80){L(r(`deviceHubInvalidName`));return}let t=++G.current;q.current=!0,M(`pair`),L(``),z(``),D(null);try{let n=await Z(`pair`,{hubUrl:e,name:w.trim()});if(!Q(t))return;if(!n.code||!Number.isFinite(n.expiresAt)||!F(n.hubUrl))throw Error(r(`deviceHubPairError`));k(Date.now()),D(n)}catch(e){Q(t)&&L(`${r(`deviceHubPairError`)} ${se(e)}`)}finally{Q(t)&&(q.current=!1,M(null))}}async function de(){let e=Y.current;if(!e?.deviceId||q.current)return;let t=++G.current;q.current=!0,M(`permission`),L(``),z(``),ce({...e,allowExecution:!e.allowExecution});try{await Z(`execution`,{allowExecution:!e.allowExecution}),Q(t)&&z(r(`deviceHubSaved`))}catch(n){Q(t)&&(ce(e),L(`${r(`deviceHubPermissionError`)} ${se(n)}`))}finally{Q(t)&&(q.current=!1,M(null))}}async function fe(){let e=Y.current;if(!e?.deviceId||q.current||!window.confirm(r(`deviceHubDisconnectConfirm`,{name:e.name})))return;let t=++G.current;q.current=!0,M(`disconnect`),L(``),z(``);try{if(await Z(`disconnect`,{}),!Q(t))return;J.current=!1,ce({name:e.name,allowExecution:!1,connected:!1}),D(null)}catch(e){Q(t)&&L(`${r(`deviceHubDisconnectError`)} ${se(e)}`)}finally{Q(t)&&(q.current=!1,M(null))}}async function pe(){if(!E)return;let e=G.current;try{await navigator.clipboard.writeText(E.code),Q(e)&&z(r(`deviceHubCopied`))}catch{Q(e)&&L(r(`deviceHubCopyFailed`))}}let $=!!m?.deviceId,me=F($?m?.hubUrl??``:E?.hubUrl??``),he=Math.max(0,Math.ceil(((E?.expiresAt??0)-O)/1e3)),ge=`${Math.floor(he/60)}:${String(he%60).padStart(2,`0`)}`,_e=me?(0,S.jsxs)(re,{href:me,children:[(0,S.jsx)(u,{"aria-hidden":!0}),r(`deviceHubOpenHub`)]}):null;return(0,S.jsxs)(`section`,{className:`dc-page`,"aria-label":r(`deviceHubTitle`),children:[(0,S.jsxs)(`header`,{className:`dc-header`,children:[(0,S.jsxs)(`div`,{className:`dc-heading`,children:[(0,S.jsxs)(`span`,{className:`dc-eyebrow`,children:[(0,S.jsx)(t,{"aria-hidden":!0}),r(`deviceHubTitle`)]}),(0,S.jsx)(`h1`,{children:r(`deviceHubTitle`)}),(0,S.jsx)(`p`,{children:r(`deviceHubSubtitle`)})]}),(0,S.jsxs)(`div`,{className:`dc-actions`,children:[$&&_e,(0,S.jsxs)(`span`,{className:`dc-status ${$?m?.connected?`is-online`:`is-offline`:`is-unpaired`}`,children:[(0,S.jsx)(`span`,{className:`dc-status-dot`}),r($?m?.connected?`deviceHubOnline`:`deviceHubOffline`:`deviceHubUnpaired`)]})]})]}),(0,S.jsxs)(`div`,{className:`dc-layout`,children:[(0,S.jsxs)(`nav`,{className:`dc-sidebar`,"aria-label":r(`deviceHubTitle`),children:[(0,S.jsxs)(`button`,{type:`button`,className:`dc-nav-item${f===`overview`?` is-active`:``}`,"aria-current":f===`overview`?`page`:void 0,onClick:()=>p(`overview`),children:[(0,S.jsx)(t,{"aria-hidden":!0}),r(`deviceHubOverview`)]}),(0,S.jsxs)(`button`,{type:`button`,className:`dc-nav-item${f===`groups`?` is-active`:``}`,"aria-current":f===`groups`?`page`:void 0,onClick:()=>p(`groups`),children:[(0,S.jsx)(l,{"aria-hidden":!0}),r(`deviceHubGroups`)]}),(0,S.jsxs)(`button`,{type:`button`,className:`dc-nav-item${f===`settings`?` is-active`:``}`,"aria-current":f===`settings`?`page`:void 0,onClick:()=>p(`settings`),children:[(0,S.jsx)(h,{"aria-hidden":!0}),r(`deviceHubSettings`)]})]}),(0,S.jsxs)(`main`,{className:`dc-content`,children:[H&&(0,S.jsxs)(`div`,{className:`dc-loading`,role:`status`,children:[(0,S.jsx)(o,{"aria-hidden":!0}),r(`deviceHubLoading`)]}),(B||ae)&&(0,S.jsxs)(`div`,{className:`dc-notice is-error`,role:`alert`,children:[(0,S.jsx)(`span`,{children:B?r(`deviceHubLocalOnly`):`${r(`deviceHubStatusError`)} ${ae}`}),(0,S.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>void le(),children:[(0,S.jsx)(o,{"aria-hidden":!0}),r(`deviceHubRetry`)]})]}),ie&&!B&&(0,S.jsx)(`div`,{className:`dc-notice is-error`,role:`alert`,children:ie}),R&&(0,S.jsxs)(`div`,{className:`dc-notice is-success`,role:`status`,children:[(0,S.jsx)(s,{"aria-hidden":!0}),R]}),!$&&(m||B)&&f===`overview`&&(0,S.jsx)(j,{initialHubUrl:_,onConnect:e=>{if(B){z(r(`deviceHubLocalOnly`));return}J.current=!0,C(e),p(`settings`)}}),!B&&f===`overview`&&(0,S.jsxs)(`section`,{className:`dc-card`,children:[(0,S.jsx)(`h3`,{children:r(`deviceSetupNext`)}),(0,S.jsx)(`p`,{children:r(`deviceSetupNextHint`)}),(0,S.jsx)(`button`,{className:`dc-button is-primary`,onClick:()=>p(`groups`),children:r(`deviceSetupManage`)})]}),f===`settings`&&(0,S.jsx)(I,{}),m&&!B&&!$&&f===`settings`&&(0,S.jsxs)(`section`,{className:`dc-card`,children:[(0,S.jsxs)(`div`,{className:`dc-card-header`,children:[(0,S.jsx)(`span`,{className:`dc-icon`,children:(0,S.jsx)(h,{"aria-hidden":!0})}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h2`,{children:r(`deviceHubPairTitle`)}),(0,S.jsx)(`p`,{children:r(`deviceHubPairHint`)})]})]}),(0,S.jsx)(`ol`,{className:`dc-steps`,children:[`deviceHubStepDetails`,`deviceHubStepApprove`,`deviceHubStepWait`].map((e,t)=>(0,S.jsxs)(`li`,{className:E?t===0?`is-complete`:`is-active`:t===0?`is-active`:``,children:[(0,S.jsx)(`span`,{className:`dc-step-number`,children:E&&t===0?(0,S.jsx)(s,{"aria-hidden":!0}):t+1}),(0,S.jsx)(`span`,{children:r(e)})]},e))}),(0,S.jsxs)(`form`,{className:`dc-form`,onSubmit:e=>{e.preventDefault(),ue()},children:[(0,S.jsxs)(`div`,{className:`dc-field`,children:[(0,S.jsx)(`label`,{htmlFor:`dc-hub-url`,children:r(`deviceHubHubUrl`)}),(0,S.jsx)(`input`,{id:`dc-hub-url`,type:`url`,autoComplete:`url`,required:!0,placeholder:r(`deviceHubHubPlaceholder`),value:_,disabled:!!E||!!A,onChange:e=>{J.current=!0,C(e.target.value)}})]}),(0,S.jsxs)(`div`,{className:`dc-field`,children:[(0,S.jsx)(`label`,{htmlFor:`dc-device-name`,children:r(`deviceHubName`)}),(0,S.jsx)(`input`,{id:`dc-device-name`,maxLength:80,required:!0,autoComplete:`off`,placeholder:r(`deviceHubNamePlaceholder`),value:w,disabled:!!E||!!A,onChange:e=>{J.current=!0,T(e.target.value)}})]}),!E&&(0,S.jsx)(`div`,{className:`dc-actions`,children:(0,S.jsxs)(`button`,{className:`dc-button is-primary`,type:`submit`,disabled:!!A,children:[(0,S.jsx)(h,{"aria-hidden":!0}),r(A?`deviceHubWorking`:`deviceHubGetCode`)]})})]}),E&&(0,S.jsxs)(`div`,{className:`dc-pairing`,children:[(0,S.jsx)(`span`,{className:`dc-code-label`,children:r(`deviceHubCode`)}),(0,S.jsxs)(`div`,{className:`dc-code-row`,children:[(0,S.jsx)(`code`,{className:`dc-code`,children:E.code}),(0,S.jsx)(`button`,{className:`dc-icon-button`,type:`button`,"aria-label":r(`deviceHubCopy`),onClick:()=>void pe(),children:(0,S.jsx)(n,{"aria-hidden":!0})})]}),(0,S.jsx)(`div`,{className:`dc-pair-meta`,children:r(he?`deviceHubExpires`:`deviceHubExpired`,{time:ge})}),(0,S.jsxs)(`div`,{className:`dc-actions`,children:[_e,(0,S.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:!!A,onClick:()=>{++G.current,D(null),L(``),z(``)},children:[(0,S.jsx)(o,{"aria-hidden":!0}),r(`deviceHubNewCode`)]})]}),he>0&&(0,S.jsxs)(`p`,{className:`dc-progress`,role:`status`,children:[(0,S.jsx)(o,{"aria-hidden":!0}),r(`deviceHubWaiting`)]})]})]}),$&&m&&!B&&(0,S.jsxs)(S.Fragment,{children:[f===`overview`&&(0,S.jsxs)(`section`,{className:`dc-card`,children:[(0,S.jsxs)(`div`,{className:`dc-device-summary`,children:[(0,S.jsx)(`span`,{className:`dc-device-icon`,children:(0,S.jsx)(t,{"aria-hidden":!0})}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h2`,{children:m.name}),(0,S.jsx)(`p`,{children:r(`deviceHubDeviceTitle`)})]})]}),(0,S.jsxs)(`dl`,{className:`dc-details`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`dt`,{children:r(`deviceHubDeviceId`)}),(0,S.jsx)(`dd`,{children:m.deviceId})]}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`dt`,{children:r(`deviceHubHubUrl`)}),(0,S.jsx)(`dd`,{children:m.hubUrl})]})]})]}),f===`settings`&&(0,S.jsxs)(`section`,{className:`dc-card`,children:[(0,S.jsxs)(`div`,{className:`dc-card-header`,children:[(0,S.jsx)(`span`,{className:`dc-icon`,children:(0,S.jsx)(i,{"aria-hidden":!0})}),(0,S.jsx)(`div`,{children:(0,S.jsx)(`h2`,{children:r(`deviceHubPermissions`)})})]}),(0,S.jsxs)(`div`,{className:`dc-permission-row`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h3`,{id:`dc-permission-label`,children:r(`deviceHubPermissionLabel`)}),(0,S.jsx)(`p`,{id:`dc-permission-hint`,children:r(`deviceHubPermissionHint`)})]}),(0,S.jsx)(`button`,{type:`button`,className:`dc-toggle${m.allowExecution?` is-on`:``}`,role:`switch`,"aria-checked":m.allowExecution,"aria-labelledby":`dc-permission-label`,"aria-describedby":`dc-permission-hint`,disabled:!!A,onClick:()=>void de(),children:(0,S.jsx)(`span`,{className:`dc-toggle-thumb`})})]}),(0,S.jsx)(`p`,{className:`dc-permission-state`,role:`status`,children:r(A===`permission`?`deviceHubSaving`:m.allowExecution?`deviceHubEnabled`:`deviceHubReadOnly`)})]}),f===`settings`&&(0,S.jsxs)(`details`,{className:`dc-advanced`,children:[(0,S.jsx)(`summary`,{children:r(`deviceHubAdvanced`)}),(0,S.jsxs)(`div`,{className:`dc-danger-zone`,children:[(0,S.jsx)(`h3`,{children:r(`deviceHubDisconnect`)}),(0,S.jsx)(`p`,{children:r(`deviceHubDisconnectHint`)}),(0,S.jsx)(`button`,{type:`button`,className:`dc-button is-danger`,disabled:!!A,onClick:()=>void fe(),children:r(A===`disconnect`?`deviceHubWorking`:`deviceHubDisconnect`)})]})]})]}),$&&m?.hubUrl&&m.deviceId&&!B&&f!==`groups`&&(0,S.jsx)(v,{hubUrl:m.hubUrl,currentDeviceId:m.deviceId},`directory:${m.hubUrl}:${m.deviceId}`),!B&&(f===`settings`||f===`groups`)&&(0,S.jsx)(y,{pathCompletions:e},`bots:${m?.hubUrl??``}:${m?.deviceId??`unpaired`}`),f===`settings`&&(0,S.jsx)(N,{hubUrl:m?.hubUrl,deviceId:m?.deviceId,onNotice:z}),f===`groups`&&(0,S.jsx)(b,{navigation:a}),(0,S.jsxs)(`aside`,{className:`dc-help`,children:[(0,S.jsx)(d,{className:`dc-help-icon`,"aria-hidden":!0}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h3`,{children:r(`deviceHubHelpTitle`)}),(0,S.jsx)(`p`,{children:r(`deviceHubHelpText`)})]})]})]})]})]})}export{L as DeviceCenter};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{At as t,B as n,Ft as r,Kt as i,L as a,Lt as o,O as s,Sn as c,Tt as l,Z as u,_n as ee,dt as d,gn as f,p,sn as m,vt as h,wn as te}from"./app-globals-DZNa9v8u.js";import{i as g,t as _}from"./react-CR5VJ85Q.js";import{Rt as v,T as ne,_t as y}from"./index-DHeeHS_l.js";import{DeviceGroups as b}from"./DeviceGroups-CLdpdnI7.js";var x=e(g(),1),S=_();function re({href:e,children:t}){let n=ee(),[r,i]=(0,x.useState)(!1),[a,o]=(0,x.useState)(!1);return(0,S.jsxs)(S.Fragment,{children:[(0,S.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,S.jsxs)(`span`,{role:`alert`,children:[n(`deviceHubNetworkError`),` `,(0,S.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,children:e})]})]})}function C(e){if(!w(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 w(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 T(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 E=`https://raw.githubusercontent.com/xing-shuyin/pi-web-ui/main/docs/device-center-deployment.md`,D=`https://github.com/xing-shuyin/pi-web-ui/blob/main/docs/device-center-deployment.md`,O=`pi-web-ui hub install --host 0.0.0.0 --port 8790 --public-url http://SERVER_IP:8790 --allow-registration`;function k(e){let t=e=>e.includes(`:`)?w(e)&&![`::`,`::1`].includes(e):/^[\d.]+$/.test(e)?w(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 A(e,t,n,r){if(!C(e))throw Error(`Invalid Hub setup`);if(r){let t=k(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: ${E} (fallback: ${D}). 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: ${O}`,`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 j({onConnect:e,initialHubUrl:t=``}){let n=ee(),[r,i]=(0,x.useState)(t),[a,o]=(0,x.useState)(``),[s,l]=(0,x.useState)(!1),[u,d]=(0,x.useState)(!1),f=(0,x.useRef)(!1),p=(0,x.useRef)(!1);(0,x.useEffect)(()=>(p.current=!0,()=>{p.current=!1}),[]);let[m,h]=(0,x.useState)(null),[g,_]=(0,x.useState)(`current`),[v,ne]=(0,x.useState)(null),[y,b]=(0,x.useState)(`127.0.0.1`),[w,E]=(0,x.useState)(`8790`),[D,O]=(0,x.useState)(`http://127.0.0.1:8790`),[j,M]=(0,x.useState)({server:``,sshPort:22,username:`root`,auth:`password`,port:8790,domain:``,https:!1}),ie=k(j),[N,P]=(0,x.useState)(!1),[F,I]=(0,x.useState)(!1),[L,ae]=(0,x.useState)(!1),[oe,R]=(0,x.useState)(!1),[z,B]=(0,x.useState)(null),V=(0,x.useRef)(null),H=(0,x.useRef)(!1),U=T(window.location.origin);(0,x.useEffect)(()=>()=>V.current?.abort(),[]);let W=async()=>{if(H.current)return;V.current?.abort();let e=new AbortController;V.current=e,I(!1),ae(!1),R(!1);try{let t=await fetch(c(te(`/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`||!C({host:`127.0.0.1`,port:n.defaultPort,publicUrl:n.defaultPublicUrl}))throw Error();if(e.signal.aborted)return;ne(n),n.installation?.installed?(b(n.installation.host??`127.0.0.1`),E(String(n.installation.port)),O(n.installation.publicUrl??``),i(n.installation.publicUrl??``)):v||(E(String(n.defaultPort)),O(n.defaultPublicUrl))}catch{e.signal.aborted||(I(!0),R(!0))}finally{e.signal.aborted||ae(!0)}},G=async()=>{let e={host:y,port:Number(w),publicUrl:D};if(H.current||!U||!v||!L||oe||v.busy||v.installation?.installed||!C(e))return;H.current=!0,V.current?.abort(),P(!0),I(!1),o(``);let t=new AbortController;V.current=t;try{let n=await fetch(c(te(`/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){ne(e=>e&&{...e,busy:!0}),H.current=!1,P(!1),await W();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(!C({...e,publicUrl:r.publicUrl})||typeof r.output!=`string`)throw Error();t.signal.aborted||B(r)}catch(e){t.signal.aborted||(I(!0),o(e instanceof Error?e.message.slice(0,4096):``))}finally{H.current=!1,t.signal.aborted||P(!1)}},K=v?.installation,q=!!K?.installed,J=q&&K.running&&K.owned,Y=g===`remote`?ie:{host:y,port:Number(w),publicUrl:D},X=!!Y&&C(Y);return(0,S.jsxs)(`section`,{className:`dc-onboarding`,children:[(0,S.jsx)(`h3`,{children:n(`deviceSetupWelcome`)}),(0,S.jsx)(`p`,{children:n(`deviceSetupIntro`)}),(0,S.jsxs)(`div`,{className:`dc-actions`,children:[(0,S.jsx)(`button`,{className:`dc-button`,disabled:N,"aria-pressed":m===`connect`,onClick:()=>h(`connect`),children:n(`deviceSetupConnect`)}),(0,S.jsx)(`button`,{className:`dc-button`,disabled:N,"aria-pressed":m===`create`,onClick:()=>{h(`create`),!v&&U&&W()},children:n(`deviceSetupCreate`)})]}),m===`connect`&&(0,S.jsxs)(`form`,{onSubmit:t=>{t.preventDefault(),e(r.trim())},children:[(0,S.jsxs)(`label`,{className:`dc-field`,children:[(0,S.jsx)(`span`,{children:n(`deviceHubHubUrl`)}),(0,S.jsx)(`input`,{type:`url`,required:!0,maxLength:2048,value:r,onChange:e=>i(e.target.value),placeholder:`https://hub.example.com`})]}),(0,S.jsx)(`button`,{className:`dc-button is-primary`,disabled:!C({host:`localhost`,port:8790,publicUrl:r.trim()}),children:n(`deviceSetupPair`)})]}),m===`create`&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`label`,{className:`dc-field`,children:[(0,S.jsx)(`span`,{children:n(`deviceSetupTarget`)}),(0,S.jsxs)(`select`,{disabled:N,value:g,onChange:e=>_(e.target.value),children:[(0,S.jsx)(`option`,{value:`current`,children:n(`deviceSetupCurrent`)}),(0,S.jsx)(`option`,{value:`remote`,children:n(`deviceSetupRemote`)})]})]}),(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`p`,{children:n(g===`current`?`deviceSetupCurrentHint`:`deviceSetupRemoteHint`)}),g===`current`&&(0,S.jsxs)(`div`,{className:`dc-setup-plan`,children:[(0,S.jsx)(`strong`,{children:n(`deviceSetupPlan`)}),(0,S.jsx)(`p`,{children:n(`deviceSetupPlanHint`)}),v&&(0,S.jsxs)(`dl`,{children:[(0,S.jsx)(`dt`,{children:n(`deviceSetupEnvironment`)}),(0,S.jsxs)(`dd`,{children:[v.platform,` · Node `,v.nodeVersion]}),(0,S.jsx)(`dt`,{children:n(`deviceSetupDataDir`)}),(0,S.jsx)(`dd`,{children:v.dataDir}),(0,S.jsx)(`dt`,{children:n(`deviceSetupCli`)}),(0,S.jsx)(`dd`,{children:v.cliPath})]}),!U&&(0,S.jsx)(`p`,{role:`status`,children:n(`deviceSetupLocalOnly`)}),(0,S.jsx)(`p`,{children:n(`deviceSetupBackground`)}),q&&(0,S.jsxs)(`div`,{role:`status`,children:[(0,S.jsx)(`h4`,{children:n(J?`deviceSetupRestored`:`deviceSetupUnhealthy`)}),(0,S.jsx)(`p`,{children:K.publicUrl}),J&&X&&K.publicUrl?(0,S.jsxs)(`div`,{className:`dc-actions`,children:[(0,S.jsx)(re,{href:K.publicUrl,children:n(`deviceHubOpenHub`)}),(0,S.jsx)(`button`,{className:`dc-button`,onClick:()=>e(K.publicUrl),children:n(`deviceSetupPair`)})]}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`p`,{children:n(`deviceSetupRecovery`)}),(0,S.jsx)(`pre`,{className:`dc-setup-output`,children:`pi-web-ui hub status --json
|
|
3
|
-
pi-web-ui hub --help`})]})]}),v?.busy&&(0,S.jsx)(`p`,{role:`status`,children:n(`deviceSetupBusy`)}),U&&(0,S.jsx)(`button`,{className:`dc-button`,disabled:N||!L,onClick:()=>void W(),children:n(L?`deviceSetupRetry`:`deviceHubWorking`)})]}),g===`remote`?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`dc-setup-fields`,children:[(0,S.jsxs)(`label`,{className:`dc-field`,children:[(0,S.jsx)(`span`,{children:n(`deviceSetupServer`)}),(0,S.jsx)(`input`,{autoComplete:`off`,maxLength:253,placeholder:`203.0.113.10`,value:j.server,onChange:e=>M({...j,server:e.target.value.trim()})})]}),(0,S.jsxs)(`label`,{className:`dc-field`,children:[(0,S.jsx)(`span`,{children:n(`deviceSetupSshPort`)}),(0,S.jsx)(`input`,{type:`number`,min:1,max:65535,value:j.sshPort,onChange:e=>M({...j,sshPort:Number(e.target.value)})})]}),(0,S.jsxs)(`label`,{className:`dc-field`,children:[(0,S.jsx)(`span`,{children:n(`deviceSetupUsername`)}),(0,S.jsx)(`input`,{autoComplete:`off`,maxLength:64,value:j.username,onChange:e=>M({...j,username:e.target.value})})]}),(0,S.jsxs)(`label`,{className:`dc-field`,children:[(0,S.jsx)(`span`,{children:n(`deviceSetupAuth`)}),(0,S.jsxs)(`select`,{value:j.auth,onChange:e=>M({...j,auth:e.target.value}),children:[(0,S.jsx)(`option`,{value:`password`,children:n(`deviceSetupAuthPassword`)}),(0,S.jsx)(`option`,{value:`key`,children:n(`deviceSetupAuthKey`)}),(0,S.jsx)(`option`,{value:`existing`,children:n(`deviceSetupAuthExisting`)})]})]}),(0,S.jsxs)(`label`,{className:`dc-field`,children:[(0,S.jsx)(`span`,{children:n(`deviceSetupServicePort`)}),(0,S.jsx)(`input`,{type:`number`,min:1024,max:65535,value:j.port,onChange:e=>M({...j,port:Number(e.target.value)})})]})]}),(0,S.jsx)(`p`,{children:n(`deviceSetupCredentialHint`)}),(0,S.jsxs)(`details`,{children:[(0,S.jsx)(`summary`,{children:n(`deviceSetupOptionalTls`)}),(0,S.jsxs)(`label`,{className:`dc-field`,children:[(0,S.jsx)(`span`,{children:n(`deviceSetupDomain`)}),(0,S.jsx)(`input`,{maxLength:253,placeholder:`hub.example.com`,value:j.domain,onChange:e=>M({...j,domain:e.target.value.trim()})})]}),(0,S.jsxs)(`label`,{children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:j.https,onChange:e=>M({...j,https:e.target.checked})}),` `,n(`deviceSetupEnableHttps`)]}),(0,S.jsx)(`p`,{children:n(`deviceSetupTlsHint`)})]}),(0,S.jsxs)(`p`,{children:[(0,S.jsx)(`strong`,{children:n(`deviceSetupPreview`)}),` `,ie?.publicUrl??n(`deviceSetupPreviewEmpty`)]}),(0,S.jsxs)(`div`,{className:`dc-setup-plan`,children:[(0,S.jsx)(`strong`,{children:n(`deviceSetupUserActions`)}),(0,S.jsx)(`p`,{children:n(`deviceSetupCloudPorts`).replace(`{ports}`,j.https?`443 / 80`:String(j.port))}),(0,S.jsx)(`p`,{children:n(`deviceSetupSourceScope`)}),(0,S.jsx)(`p`,{children:n(`deviceSetupAfterStart`)})]}),(0,S.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,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`dc-setup-fields`,children:[(0,S.jsxs)(`label`,{className:`dc-field`,children:[(0,S.jsx)(`span`,{children:n(`deviceSetupHost`)}),(0,S.jsx)(`input`,{disabled:N||!!z,maxLength:253,value:y,onChange:e=>b(e.target.value)})]}),(0,S.jsxs)(`label`,{className:`dc-field`,children:[(0,S.jsx)(`span`,{children:n(`deviceSetupPort`)}),(0,S.jsx)(`input`,{disabled:N||!!z,type:`number`,min:1024,max:65535,value:w,onChange:e=>E(e.target.value)})]}),(0,S.jsxs)(`label`,{className:`dc-field`,children:[(0,S.jsx)(`span`,{children:n(`deviceHubHubUrl`)}),(0,S.jsx)(`input`,{disabled:N||!!z,maxLength:2048,value:D,onChange:e=>O(e.target.value)})]})]}),(0,S.jsx)(`p`,{className:`dc-setup-warning`,children:n(`deviceSetupReachable`)})]}),(0,S.jsx)(`p`,{children:n(`deviceSetupRegistration`)}),!X&&(0,S.jsx)(`p`,{role:`alert`,children:n(g===`remote`?`deviceSetupRemoteInvalid`:`deviceSetupInvalid`)}),(0,S.jsxs)(`div`,{className:`dc-actions`,children:[g===`current`&&!z&&!q&&(0,S.jsx)(`button`,{className:`dc-button is-primary`,disabled:N||!U||!v||!L||oe||!!v.busy||!X,onClick:()=>void G(),children:n(N?`deviceSetupInstalling`:`deviceSetupInstall`)}),(0,S.jsx)(`button`,{className:`dc-button`,disabled:N||s||!X,onClick:()=>{if(!X||!Y||f.current)return;f.current=!0,l(!0),d(!1);let e=e=>{f.current=!1,p.current&&(l(!1),d(!e))},t=window.__piWebUiHost;try{t?.startChat({newChat:!0,prompt:A(Y,v,g,g===`remote`?j:void 0),onResult:e})||e(!1)}catch{e(!1)}},children:n(g===`remote`?`deviceSetupStartAi`:`deviceSetupAi`)})]}),(0,S.jsx)(`p`,{children:n(`deviceSetupAiHint`)}),s&&(0,S.jsx)(`p`,{role:`status`,children:n(`deviceSetupAiCreating`)}),u&&(0,S.jsx)(`p`,{role:`alert`,children:n(`deviceSetupAiFailed`)})]})]}),F&&(0,S.jsxs)(`div`,{role:`alert`,children:[(0,S.jsx)(`p`,{children:n(`deviceSetupFailed`)}),a&&(0,S.jsx)(`pre`,{className:`dc-setup-output`,children:a})]}),z&&(0,S.jsxs)(`div`,{role:`status`,children:[(0,S.jsx)(`h4`,{children:n(`deviceSetupSuccess`)}),(0,S.jsx)(`pre`,{className:`dc-setup-output`,children:z.output.slice(0,16e3)}),(0,S.jsxs)(`div`,{className:`dc-actions`,children:[(0,S.jsx)(re,{href:z.publicUrl,children:n(`deviceHubOpenHub`)}),(0,S.jsx)(`button`,{className:`dc-button is-primary`,onClick:()=>e(z.publicUrl),children:n(`deviceSetupPair`)})]})]})]})}var M={maxActiveTasks:4,maxWaitingTasks:32};function ie(e){let t={settings:{...M},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=typeof r.maxActiveTasks==`number`&&Number.isFinite(r.maxActiveTasks)?Math.max(1,Math.min(16,r.maxActiveTasks)):M.maxActiveTasks,a=typeof r.maxWaitingTasks==`number`&&Number.isFinite(r.maxWaitingTasks)?Math.max(0,Math.min(128,r.maxWaitingTasks)):M.maxWaitingTasks,o=Array.isArray(n.running)?n.running:[],s=Array.isArray(n.waiting)?n.waiting:[],c=Array.isArray(n.blocked)?n.blocked:[];return{settings:{maxActiveTasks:i,maxWaitingTasks:a},activeCount:typeof n.activeCount==`number`?n.activeCount:o.length,waitingCount:typeof n.waitingCount==`number`?n.waitingCount:s.length,blockedCount:typeof n.blockedCount==`number`?n.blockedCount:c.length,running:o,waiting:s,blocked:c}}function N({hubUrl:e,deviceId:t,onNotice:n}){let l=ee(),[u,d]=(0,x.useState)(null),[f,h]=(0,x.useState)(M.maxActiveTasks),[g,_]=(0,x.useState)(M.maxWaitingTasks),[v,ne]=(0,x.useState)(!1),[y,b]=(0,x.useState)(!1),[re,C]=(0,x.useState)(null),[w,T]=(0,x.useState)(null),[E,D]=(0,x.useState)(null),O=(0,x.useRef)(!0),k=(0,x.useRef)(0),A=(0,x.useRef)(new Set),j=(0,x.useRef)(!1),N=(0,x.useRef)(!1),P=`${e??``}:${t??``}`,F=(0,x.useCallback)(async(e,t,n)=>{let r=new AbortController;A.current.add(r);let i=()=>r.abort();n&&(n.aborted?r.abort():n.addEventListener(`abort`,i,{once:!0}));try{let n=await fetch(c(te(`/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}),i=await n.json().catch(()=>({}));if(!n.ok){let e=typeof i.error==`string`?i.error:`HTTP ${n.status}`;throw Error(e)}return i}finally{n&&n.removeEventListener(`abort`,i),A.current.delete(r)}},[]),I=(0,x.useCallback)(async(e=!1)=>{if(!O.current||j.current)return;j.current=!0;let t=k.current;e||ne(!0);try{let e=await F(`execution-queue`);if(!O.current||t!==k.current)return;let n=ie(e);d(n),T(null),N.current||=(h(n.settings.maxActiveTasks),_(n.settings.maxWaitingTasks),!0)}catch(e){if(!O.current||t!==k.current)return;e.name!==`AbortError`&&T(e.message)}finally{j.current=!1,O.current&&t===k.current&&!e&&ne(!1)}},[F]);(0,x.useEffect)(()=>{O.current=!0,k.current++;for(let e of A.current)e.abort();A.current.clear(),j.current=!1,N.current=!1,d(null),T(null),D(null),I(!1);let e=setInterval(()=>{I(!0)},3e3);return()=>{O.current=!1,k.current++;for(let e of A.current)e.abort();A.current.clear(),clearInterval(e)}},[P,I]);let L=async e=>{e.preventDefault();let t=k.current;b(!0),T(null),D(null);try{let e=await F(`execution-settings`,{maxActiveTasks:Number(f),maxWaitingTasks:Number(g)});if(!O.current||t!==k.current)return;e?.settings&&(h(e.settings.maxActiveTasks??M.maxActiveTasks),_(e.settings.maxWaitingTasks??M.maxWaitingTasks)),D(l(`deviceExecSavedNotice`)),n?.(l(`deviceExecSavedNotice`)),await I(!0)}catch(e){if(!O.current||t!==k.current)return;e.name!==`AbortError`&&T(e.message)}finally{O.current&&t===k.current&&b(!1)}},ae=async(e,t)=>{let r=k.current;C(e),T(null);try{if(await F(`execution-queue/cancel`,{taskId:e,attemptId:t}),!O.current||r!==k.current)return;n?.(l(`deviceExecTaskCancelled`)),await I(!0)}catch(e){if(!O.current||r!==k.current)return;e.name!==`AbortError`&&T(e.message)}finally{O.current&&r===k.current&&C(null)}},oe=e=>{switch(e){case`max_concurrency_reached`:return l(`deviceExecReasonMaxConcurrency`);case`bot_busy`:return l(`deviceExecReasonBotBusy`);case`workspace_conflict`:return l(`deviceExecReasonWorkspaceConflict`);case`workspace_blocked`:return l(`deviceExecReasonWorkspaceBlocked`);case`room_fairness_yield`:return l(`deviceExecReasonFairness`);default:return e}},R=u?.settings?.maxActiveTasks??M.maxActiveTasks,z=u?.settings?.maxWaitingTasks??M.maxWaitingTasks;return(0,S.jsxs)(`div`,{className:`des-container`,children:[(0,S.jsxs)(`div`,{className:`des-header`,children:[(0,S.jsxs)(`div`,{className:`des-header-left`,children:[(0,S.jsx)(`h3`,{className:`des-title`,children:l(`deviceExecTitle`)}),(0,S.jsx)(`p`,{className:`des-subtitle`,children:l(`deviceExecSubtitle`)})]}),(0,S.jsx)(`button`,{type:`button`,className:`des-refresh-btn`,onClick:()=>void I(!1),disabled:v,title:l(`deviceExecRefresh`),children:(0,S.jsx)(o,{className:v?`des-spin`:``})})]}),w&&(0,S.jsxs)(`div`,{className:`des-alert des-alert-error`,role:`alert`,children:[(0,S.jsx)(p,{className:`des-alert-icon`}),(0,S.jsx)(`div`,{className:`des-alert-text`,children:w}),(0,S.jsx)(`button`,{type:`button`,className:`des-alert-close`,onClick:()=>T(null),children:(0,S.jsx)(m,{})})]}),E&&(0,S.jsxs)(`div`,{className:`des-alert des-alert-success`,role:`status`,children:[(0,S.jsx)(s,{className:`des-alert-icon`}),(0,S.jsx)(`div`,{className:`des-alert-text`,children:E}),(0,S.jsx)(`button`,{type:`button`,className:`des-alert-close`,onClick:()=>D(null),children:(0,S.jsx)(m,{})})]}),(0,S.jsxs)(`div`,{className:`des-stats-row`,children:[(0,S.jsxs)(`div`,{className:`des-stat-card`,children:[(0,S.jsxs)(`div`,{className:`des-stat-label`,children:[(0,S.jsx)(r,{className:`des-stat-icon is-running`}),` `,l(`deviceExecRunning`)]}),(0,S.jsxs)(`div`,{className:`des-stat-value`,children:[u?.activeCount??0,` `,(0,S.jsxs)(`span`,{className:`des-stat-sub`,children:[`/ `,R]})]})]}),(0,S.jsxs)(`div`,{className:`des-stat-card`,children:[(0,S.jsxs)(`div`,{className:`des-stat-label`,children:[(0,S.jsx)(a,{className:`des-stat-icon is-waiting`}),` `,l(`deviceExecQueued`)]}),(0,S.jsxs)(`div`,{className:`des-stat-value`,children:[u?.waitingCount??0,` `,(0,S.jsxs)(`span`,{className:`des-stat-sub`,children:[`/ `,z]})]})]}),(0,S.jsxs)(`div`,{className:`des-stat-card`,children:[(0,S.jsxs)(`div`,{className:`des-stat-label`,children:[(0,S.jsx)(i,{className:`des-stat-icon is-blocked`}),` `,l(`deviceExecBlocked`)]}),(0,S.jsx)(`div`,{className:`des-stat-value${(u?.blockedCount??0)>0?` is-warn`:``}`,children:u?.blockedCount??0})]})]}),(0,S.jsxs)(`form`,{className:`des-form-card`,onSubmit:e=>void L(e),children:[(0,S.jsx)(`h4`,{className:`des-form-title`,children:l(`deviceExecQuotaTitle`)}),(0,S.jsxs)(`div`,{className:`des-fields-row`,children:[(0,S.jsxs)(`div`,{className:`des-field`,children:[(0,S.jsx)(`label`,{htmlFor:`des-max-active`,className:`des-label`,children:l(`deviceExecMaxActive`)}),(0,S.jsx)(`input`,{id:`des-max-active`,type:`number`,min:1,max:16,className:`des-input`,value:f,onChange:e=>h(parseInt(e.target.value,10)||1),required:!0}),(0,S.jsx)(`span`,{className:`des-hint`,children:l(`deviceExecMaxActiveHint`)})]}),(0,S.jsxs)(`div`,{className:`des-field`,children:[(0,S.jsx)(`label`,{htmlFor:`des-max-waiting`,className:`des-label`,children:l(`deviceExecMaxWaiting`)}),(0,S.jsx)(`input`,{id:`des-max-waiting`,type:`number`,min:0,max:128,className:`des-input`,value:g,onChange:e=>_(parseInt(e.target.value,10)||0),required:!0}),(0,S.jsx)(`span`,{className:`des-hint`,children:l(`deviceExecMaxWaitingHint`)})]})]}),(0,S.jsxs)(`div`,{className:`des-form-actions`,children:[(0,S.jsx)(`button`,{type:`button`,className:`des-btn des-btn-secondary`,disabled:y,onClick:()=>{h(R),_(z)},children:l(`deviceExecReset`)}),(0,S.jsx)(`button`,{type:`submit`,className:`des-btn des-btn-primary`,disabled:y,children:l(y?`deviceExecSaving`:`deviceExecSave`)})]})]}),u&&u.blocked&&u.blocked.length>0&&(0,S.jsxs)(`div`,{className:`des-section des-blocked-section`,children:[(0,S.jsxs)(`h4`,{className:`des-section-title is-danger`,children:[(0,S.jsx)(p,{}),` `,l(`deviceExecBlockedTitle`)]}),(0,S.jsx)(`p`,{className:`des-section-desc`,children:l(`deviceExecBlockedDesc`)}),(0,S.jsx)(`div`,{className:`des-table-wrap`,children:(0,S.jsxs)(`table`,{className:`des-table`,children:[(0,S.jsx)(`thead`,{children:(0,S.jsxs)(`tr`,{children:[(0,S.jsx)(`th`,{children:`Task ID`}),(0,S.jsx)(`th`,{children:`Room ID`}),(0,S.jsx)(`th`,{children:`Bot ID`}),(0,S.jsx)(`th`,{children:l(`deviceExecReason`)})]})}),(0,S.jsx)(`tbody`,{children:u.blocked.map(e=>(0,S.jsxs)(`tr`,{className:`des-row-blocked`,children:[(0,S.jsxs)(`td`,{className:`des-mono`,children:[e.taskId.slice(0,8),`...`]}),(0,S.jsx)(`td`,{children:e.roomId}),(0,S.jsx)(`td`,{children:e.botId}),(0,S.jsx)(`td`,{children:(0,S.jsx)(`span`,{className:`des-badge is-danger`,children:e.reason})})]},`${e.taskId}-${e.attemptId}`))})]})})]}),(0,S.jsxs)(`div`,{className:`des-section`,children:[(0,S.jsxs)(`h4`,{className:`des-section-title`,children:[(0,S.jsx)(r,{}),` `,l(`deviceExecActiveTasks`),` (`,u?.running?.length??0,`)`]}),u&&u.running&&u.running.length>0?(0,S.jsx)(`div`,{className:`des-table-wrap`,children:(0,S.jsxs)(`table`,{className:`des-table`,children:[(0,S.jsx)(`thead`,{children:(0,S.jsxs)(`tr`,{children:[(0,S.jsx)(`th`,{children:`Task ID`}),(0,S.jsx)(`th`,{children:`Room ID`}),(0,S.jsx)(`th`,{children:`Bot ID`}),(0,S.jsx)(`th`,{children:l(`deviceExecQueuedTime`)})]})}),(0,S.jsx)(`tbody`,{children:u.running.map(e=>(0,S.jsxs)(`tr`,{children:[(0,S.jsxs)(`td`,{className:`des-mono`,title:e.taskId,children:[e.taskId.slice(0,8),`...`]}),(0,S.jsx)(`td`,{children:e.roomId}),(0,S.jsx)(`td`,{children:e.botId}),(0,S.jsx)(`td`,{children:new Date(e.startedAt).toLocaleTimeString()})]},`${e.taskId}-${e.attemptId}`))})]})}):(0,S.jsx)(`div`,{className:`des-empty`,children:l(`deviceExecNoActive`)})]}),(0,S.jsxs)(`div`,{className:`des-section`,children:[(0,S.jsxs)(`h4`,{className:`des-section-title`,children:[(0,S.jsx)(a,{}),` `,l(`deviceExecWaitingQueue`),` (`,u?.waiting?.length??0,`)`]}),u&&u.waiting&&u.waiting.length>0?(0,S.jsx)(`div`,{className:`des-table-wrap`,children:(0,S.jsxs)(`table`,{className:`des-table`,children:[(0,S.jsx)(`thead`,{children:(0,S.jsxs)(`tr`,{children:[(0,S.jsx)(`th`,{children:l(`deviceExecPosition`)}),(0,S.jsx)(`th`,{children:`Task ID`}),(0,S.jsx)(`th`,{children:`Room ID`}),(0,S.jsx)(`th`,{children:`Bot ID`}),(0,S.jsx)(`th`,{children:l(`deviceExecReason`)}),(0,S.jsx)(`th`,{children:l(`deviceExecQueuedTime`)}),(0,S.jsx)(`th`,{children:l(`deviceExecActions`)})]})}),(0,S.jsx)(`tbody`,{children:u.waiting.map(e=>(0,S.jsxs)(`tr`,{children:[(0,S.jsx)(`td`,{children:(0,S.jsxs)(`span`,{className:`des-pos-badge`,children:[`#`,e.queuePosition]})}),(0,S.jsxs)(`td`,{className:`des-mono`,title:e.taskId,children:[e.taskId.slice(0,8),`...`]}),(0,S.jsx)(`td`,{children:e.roomId}),(0,S.jsx)(`td`,{children:e.botId}),(0,S.jsx)(`td`,{children:(0,S.jsxs)(`div`,{className:`des-reason-cell`,children:[(0,S.jsx)(`span`,{className:`des-badge des-badge-${e.blockReason}`,children:oe(e.blockReason)}),(0,S.jsx)(`span`,{className:`des-reason-detail`,children:e.blockReasonDetail})]})}),(0,S.jsx)(`td`,{children:new Date(e.queuedAt).toLocaleTimeString()}),(0,S.jsx)(`td`,{children:(0,S.jsx)(`button`,{type:`button`,className:`des-btn des-btn-danger-sm`,disabled:re===e.taskId,onClick:()=>void ae(e.taskId,e.attemptId),children:re===e.taskId?l(`deviceExecCancelling`):l(`deviceExecCancel`)})})]},`${e.taskId}-${e.attemptId}`))})]})}):(0,S.jsx)(`div`,{className:`des-empty`,children:l(`deviceExecNoWaiting`)})]})]})}var P=class extends Error{status;constructor(e,t){super(t),this.status=e}};function F(e){try{let t=new URL(e);return[`http:`,`https:`].includes(t.protocol)&&!t.username&&!t.password?t.href:null}catch{return null}}function I(){let e=ee(),n=f().startsWith(`zh`),[r,i]=(0,x.useState)(null),[a,s]=(0,x.useState)(!1),[l,u]=(0,x.useState)(!1),[d,p]=(0,x.useState)(!1),[m,h]=(0,x.useState)(!1),g=(0,x.useRef)(0),_=(0,x.useRef)(null);async function v(e,t){if(_.current)return;let n=++g.current,r=new AbortController;_.current=r,s(!0),u(!1);try{let a=await fetch(c(te(`/api/device-desktop/local/${e}`)),{method:t?`POST`:`GET`,credentials:`same-origin`,signal:r.signal,...t?{headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}:{}});if(g.current!==n||r.signal.aborted)return;if(a.status===403){p(!0),i(null);return}if(!a.ok)throw Error(`Request failed`);let o=await a.json();if(g.current!==n||r.signal.aborted)return;if(e===`permissions`){if(typeof o?.screen!=`boolean`||typeof o?.accessibility!=`boolean`)throw Error(`Invalid permission status`);i(e=>e&&{...e,permissions:{supported:!0,screen:o.screen,accessibility:o.accessibility}}),h(!0)}else{if(typeof o?.os!=`string`||typeof o.enabled!=`boolean`||typeof o.environmentEnabled!=`boolean`||typeof o.supported!=`boolean`)throw Error(`Invalid desktop status`);i(o)}}catch{g.current===n&&!r.signal.aborted&&u(!0)}finally{g.current===n&&!r.signal.aborted&&(_.current=null,s(!1))}}return(0,x.useEffect)(()=>(v(`status`),()=>{g.current++,_.current?.abort(),_.current=null}),[]),(0,S.jsxs)(`section`,{className:`dc-card`,"aria-label":n?`本机远程桌面`:`Local remote desktop`,"aria-busy":a,children:[(0,S.jsxs)(`div`,{className:`dc-card-header`,children:[(0,S.jsx)(`span`,{className:`dc-icon`,children:(0,S.jsx)(t,{"aria-hidden":!0})}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h2`,{children:n?`本机远程桌面`:`Local remote desktop`}),(0,S.jsx)(`p`,{children:n?`管理这台设备的远程桌面与系统权限,无需连接设备中心。`:`Manage remote desktop and system permissions on this device, even while the device center is offline.`})]})]}),d?(0,S.jsx)(`p`,{role:`status`,children:n?`请在设备本机打开此页面以管理远程桌面权限。`:`Open this page on the device itself to manage remote desktop permissions.`}):(0,S.jsxs)(S.Fragment,{children:[r&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`dc-permission-row`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h3`,{id:`dc-desktop-label`,children:n?`启用远程桌面`:`Enable remote desktop`}),(0,S.jsx)(`p`,{children:r.enabled?n?`已启用`:`Enabled`:n?`未启用`:`Disabled`})]}),(0,S.jsx)(`button`,{type:`button`,className:`dc-toggle${r.enabled?` is-on`:``}`,role:`switch`,"aria-checked":r.enabled,"aria-labelledby":`dc-desktop-label`,disabled:a||r.environmentEnabled||!r.supported&&!r.enabled,onClick:()=>void v(`enable`,{enabled:!r.enabled}),children:(0,S.jsx)(`span`,{className:`dc-toggle-thumb`})})]}),!r.supported&&(0,S.jsx)(`p`,{children:n?`这台设备暂不支持远程桌面。`:`Remote desktop is currently unavailable on this device.`}),r.environmentEnabled&&(0,S.jsx)(`p`,{children:n?`远程桌面由本机服务设置保持启用。`:`Remote desktop is kept enabled by the service settings on this device.`}),r.os===`darwin`&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`p`,{children:n?`点击下方按钮发起系统授权,请在这台 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,S.jsxs)(`div`,{className:`dc-actions`,children:[(0,S.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:a||r.permissions?.supported===!1,onClick:()=>void v(`permissions`,{kind:`screen`}),children:n?`授予屏幕录制权限`:`Grant screen recording permission`}),(0,S.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:a||r.permissions?.supported===!1,onClick:()=>void v(`permissions`,{kind:`control`}),children:n?`授予远程控制权限`:`Grant remote control permission`})]}),r.permissions?.screen===!0&&(0,S.jsx)(`p`,{children:n?`屏幕录制:已授权`:`Screen recording: granted`}),r.permissions?.accessibility===!0&&(0,S.jsx)(`p`,{children:n?`远程控制:已授权`:`Remote control: granted`}),m&&(0,S.jsx)(`p`,{role:`status`,children:n?`已发起授权请求,请确认系统设置后刷新状态。`:`Permission requested. Confirm in System Settings, then refresh the status.`})]})]}),l&&(0,S.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:n?`无法更新本机远程桌面设置,请重试。`:`Unable to update local remote desktop settings. Please retry.`}),(0,S.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:a,onClick:()=>void v(`status`),children:[(0,S.jsx)(o,{"aria-hidden":!0}),a?e(`deviceHubWorking`):n?`刷新远程桌面状态`:`Refresh remote desktop status`]})]})]})}function L({pathCompletions:e=[]}){let r=ee(),a=ne(),[f,p]=(0,x.useState)(a.revision?`groups`:`overview`);(0,x.useEffect)(()=>{a.revision&&p(`groups`)},[a.revision]);let[m,g]=(0,x.useState)(null),[_,C]=(0,x.useState)(``),[w,T]=(0,x.useState)(``),[E,D]=(0,x.useState)(null),[O,k]=(0,x.useState)(Date.now()),[A,M]=(0,x.useState)(null),[ie,L]=(0,x.useState)(``),[ae,oe]=(0,x.useState)(``),[R,z]=(0,x.useState)(``),[B,V]=(0,x.useState)(!1),[H,U]=(0,x.useState)(!0),W=(0,x.useRef)(!1),G=(0,x.useRef)(0),K=(0,x.useRef)(new Set),q=(0,x.useRef)(!1),J=(0,x.useRef)(!1),Y=(0,x.useRef)(null),X=(0,x.useRef)(r);X.current=r;async function Z(e,t){let n=new AbortController;K.current.add(n);try{let r=await fetch(c(te(`/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 P(r.status,typeof i.error==`string`?i.error:X.current(`deviceHubRequestFailed`,{status:r.status}));return i}finally{K.current.delete(n)}}function Q(e){return W.current&&G.current===e}function se(e){return e instanceof P&&e.status===403?(V(!0),X.current(`deviceHubLocalOnly`)):e instanceof Error?e.message:X.current(`deviceHubNetworkError`)}function ce(e){Y.current=e,g(e),J.current||(T(e.name),C(e.hubUrl??``))}async function le(){let e=G.current;try{let t=await Z(`status`);if(!Q(e)||q.current)return;ce(t),oe(``),V(!1)}catch(t){Q(e)&&oe(se(t))}finally{Q(e)&&U(!1)}}(0,x.useEffect)(()=>{W.current=!0;let e=!1,t,n=async()=>{await le(),!e&&W.current&&(t=setTimeout(n,5e3))};return n(),()=>{e=!0,W.current=!1,G.current++,clearTimeout(t);for(let e of K.current)e.abort()}},[]),(0,x.useEffect)(()=>{if(!E)return;let e=G.current,t=!1,n,r=setInterval(()=>k(Date.now()),1e3),i=async()=>{if(!(t||!Q(e)||Date.now()>=E.expiresAt)){try{let n=await Z(`poll`,{});if(t||!Q(e))return;if(n.paired){let n=await Z(`status`);if(t||!Q(e))return;J.current=!1,ce(n),D(null),L(``),z(``);return}L(``)}catch(n){!t&&Q(e)&&L(`${X.current(`deviceHubPollError`)} ${se(n)}`)}!t&&Q(e)&&(n=setTimeout(i,2e3))}};return n=setTimeout(i,2e3),()=>{t=!0,clearTimeout(n),clearInterval(r)}},[E]);async function ue(){if(q.current)return;let e=F(_.trim());if(!e){L(r(`deviceHubInvalidUrl`));return}if(!w.trim()||w.trim().length>80){L(r(`deviceHubInvalidName`));return}let t=++G.current;q.current=!0,M(`pair`),L(``),z(``),D(null);try{let n=await Z(`pair`,{hubUrl:e,name:w.trim()});if(!Q(t))return;if(!n.code||!Number.isFinite(n.expiresAt)||!F(n.hubUrl))throw Error(r(`deviceHubPairError`));k(Date.now()),D(n)}catch(e){Q(t)&&L(`${r(`deviceHubPairError`)} ${se(e)}`)}finally{Q(t)&&(q.current=!1,M(null))}}async function de(){let e=Y.current;if(!e?.deviceId||q.current)return;let t=++G.current;q.current=!0,M(`permission`),L(``),z(``),ce({...e,allowExecution:!e.allowExecution});try{await Z(`execution`,{allowExecution:!e.allowExecution}),Q(t)&&z(r(`deviceHubSaved`))}catch(n){Q(t)&&(ce(e),L(`${r(`deviceHubPermissionError`)} ${se(n)}`))}finally{Q(t)&&(q.current=!1,M(null))}}async function fe(){let e=Y.current;if(!e?.deviceId||q.current||!window.confirm(r(`deviceHubDisconnectConfirm`,{name:e.name})))return;let t=++G.current;q.current=!0,M(`disconnect`),L(``),z(``);try{if(await Z(`disconnect`,{}),!Q(t))return;J.current=!1,ce({name:e.name,allowExecution:!1,connected:!1}),D(null)}catch(e){Q(t)&&L(`${r(`deviceHubDisconnectError`)} ${se(e)}`)}finally{Q(t)&&(q.current=!1,M(null))}}async function pe(){if(!E)return;let e=G.current;try{await navigator.clipboard.writeText(E.code),Q(e)&&z(r(`deviceHubCopied`))}catch{Q(e)&&L(r(`deviceHubCopyFailed`))}}let $=!!m?.deviceId,me=F($?m?.hubUrl??``:E?.hubUrl??``),he=Math.max(0,Math.ceil(((E?.expiresAt??0)-O)/1e3)),ge=`${Math.floor(he/60)}:${String(he%60).padStart(2,`0`)}`,_e=me?(0,S.jsxs)(re,{href:me,children:[(0,S.jsx)(u,{"aria-hidden":!0}),r(`deviceHubOpenHub`)]}):null;return(0,S.jsxs)(`section`,{className:`dc-page`,"aria-label":r(`deviceHubTitle`),children:[(0,S.jsxs)(`header`,{className:`dc-header`,children:[(0,S.jsxs)(`div`,{className:`dc-heading`,children:[(0,S.jsxs)(`span`,{className:`dc-eyebrow`,children:[(0,S.jsx)(t,{"aria-hidden":!0}),r(`deviceHubTitle`)]}),(0,S.jsx)(`h1`,{children:r(`deviceHubTitle`)}),(0,S.jsx)(`p`,{children:r(`deviceHubSubtitle`)})]}),(0,S.jsxs)(`div`,{className:`dc-actions`,children:[$&&_e,(0,S.jsxs)(`span`,{className:`dc-status ${$?m?.connected?`is-online`:`is-offline`:`is-unpaired`}`,children:[(0,S.jsx)(`span`,{className:`dc-status-dot`}),r($?m?.connected?`deviceHubOnline`:`deviceHubOffline`:`deviceHubUnpaired`)]})]})]}),(0,S.jsxs)(`div`,{className:`dc-layout`,children:[(0,S.jsxs)(`nav`,{className:`dc-sidebar`,"aria-label":r(`deviceHubTitle`),children:[(0,S.jsxs)(`button`,{type:`button`,className:`dc-nav-item${f===`overview`?` is-active`:``}`,"aria-current":f===`overview`?`page`:void 0,onClick:()=>p(`overview`),children:[(0,S.jsx)(t,{"aria-hidden":!0}),r(`deviceHubOverview`)]}),(0,S.jsxs)(`button`,{type:`button`,className:`dc-nav-item${f===`groups`?` is-active`:``}`,"aria-current":f===`groups`?`page`:void 0,onClick:()=>p(`groups`),children:[(0,S.jsx)(l,{"aria-hidden":!0}),r(`deviceHubGroups`)]}),(0,S.jsxs)(`button`,{type:`button`,className:`dc-nav-item${f===`settings`?` is-active`:``}`,"aria-current":f===`settings`?`page`:void 0,onClick:()=>p(`settings`),children:[(0,S.jsx)(h,{"aria-hidden":!0}),r(`deviceHubSettings`)]})]}),(0,S.jsxs)(`main`,{className:`dc-content`,children:[H&&(0,S.jsxs)(`div`,{className:`dc-loading`,role:`status`,children:[(0,S.jsx)(o,{"aria-hidden":!0}),r(`deviceHubLoading`)]}),(B||ae)&&(0,S.jsxs)(`div`,{className:`dc-notice is-error`,role:`alert`,children:[(0,S.jsx)(`span`,{children:B?r(`deviceHubLocalOnly`):`${r(`deviceHubStatusError`)} ${ae}`}),(0,S.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:()=>void le(),children:[(0,S.jsx)(o,{"aria-hidden":!0}),r(`deviceHubRetry`)]})]}),ie&&!B&&(0,S.jsx)(`div`,{className:`dc-notice is-error`,role:`alert`,children:ie}),R&&(0,S.jsxs)(`div`,{className:`dc-notice is-success`,role:`status`,children:[(0,S.jsx)(s,{"aria-hidden":!0}),R]}),!$&&(m||B)&&f===`overview`&&(0,S.jsx)(j,{initialHubUrl:_,onConnect:e=>{if(B){z(r(`deviceHubLocalOnly`));return}J.current=!0,C(e),p(`settings`)}}),!B&&f===`overview`&&(0,S.jsxs)(`section`,{className:`dc-card`,children:[(0,S.jsx)(`h3`,{children:r(`deviceSetupNext`)}),(0,S.jsx)(`p`,{children:r(`deviceSetupNextHint`)}),(0,S.jsx)(`button`,{className:`dc-button is-primary`,onClick:()=>p(`groups`),children:r(`deviceSetupManage`)})]}),f===`settings`&&(0,S.jsx)(I,{}),m&&!B&&!$&&f===`settings`&&(0,S.jsxs)(`section`,{className:`dc-card`,children:[(0,S.jsxs)(`div`,{className:`dc-card-header`,children:[(0,S.jsx)(`span`,{className:`dc-icon`,children:(0,S.jsx)(h,{"aria-hidden":!0})}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h2`,{children:r(`deviceHubPairTitle`)}),(0,S.jsx)(`p`,{children:r(`deviceHubPairHint`)})]})]}),(0,S.jsx)(`ol`,{className:`dc-steps`,children:[`deviceHubStepDetails`,`deviceHubStepApprove`,`deviceHubStepWait`].map((e,t)=>(0,S.jsxs)(`li`,{className:E?t===0?`is-complete`:`is-active`:t===0?`is-active`:``,children:[(0,S.jsx)(`span`,{className:`dc-step-number`,children:E&&t===0?(0,S.jsx)(s,{"aria-hidden":!0}):t+1}),(0,S.jsx)(`span`,{children:r(e)})]},e))}),(0,S.jsxs)(`form`,{className:`dc-form`,onSubmit:e=>{e.preventDefault(),ue()},children:[(0,S.jsxs)(`div`,{className:`dc-field`,children:[(0,S.jsx)(`label`,{htmlFor:`dc-hub-url`,children:r(`deviceHubHubUrl`)}),(0,S.jsx)(`input`,{id:`dc-hub-url`,type:`url`,autoComplete:`url`,required:!0,placeholder:r(`deviceHubHubPlaceholder`),value:_,disabled:!!E||!!A,onChange:e=>{J.current=!0,C(e.target.value)}})]}),(0,S.jsxs)(`div`,{className:`dc-field`,children:[(0,S.jsx)(`label`,{htmlFor:`dc-device-name`,children:r(`deviceHubName`)}),(0,S.jsx)(`input`,{id:`dc-device-name`,maxLength:80,required:!0,autoComplete:`off`,placeholder:r(`deviceHubNamePlaceholder`),value:w,disabled:!!E||!!A,onChange:e=>{J.current=!0,T(e.target.value)}})]}),!E&&(0,S.jsx)(`div`,{className:`dc-actions`,children:(0,S.jsxs)(`button`,{className:`dc-button is-primary`,type:`submit`,disabled:!!A,children:[(0,S.jsx)(h,{"aria-hidden":!0}),r(A?`deviceHubWorking`:`deviceHubGetCode`)]})})]}),E&&(0,S.jsxs)(`div`,{className:`dc-pairing`,children:[(0,S.jsx)(`span`,{className:`dc-code-label`,children:r(`deviceHubCode`)}),(0,S.jsxs)(`div`,{className:`dc-code-row`,children:[(0,S.jsx)(`code`,{className:`dc-code`,children:E.code}),(0,S.jsx)(`button`,{className:`dc-icon-button`,type:`button`,"aria-label":r(`deviceHubCopy`),onClick:()=>void pe(),children:(0,S.jsx)(n,{"aria-hidden":!0})})]}),(0,S.jsx)(`div`,{className:`dc-pair-meta`,children:r(he?`deviceHubExpires`:`deviceHubExpired`,{time:ge})}),(0,S.jsxs)(`div`,{className:`dc-actions`,children:[_e,(0,S.jsxs)(`button`,{type:`button`,className:`dc-button`,disabled:!!A,onClick:()=>{++G.current,D(null),L(``),z(``)},children:[(0,S.jsx)(o,{"aria-hidden":!0}),r(`deviceHubNewCode`)]})]}),he>0&&(0,S.jsxs)(`p`,{className:`dc-progress`,role:`status`,children:[(0,S.jsx)(o,{"aria-hidden":!0}),r(`deviceHubWaiting`)]})]})]}),$&&m&&!B&&(0,S.jsxs)(S.Fragment,{children:[f===`overview`&&(0,S.jsxs)(`section`,{className:`dc-card`,children:[(0,S.jsxs)(`div`,{className:`dc-device-summary`,children:[(0,S.jsx)(`span`,{className:`dc-device-icon`,children:(0,S.jsx)(t,{"aria-hidden":!0})}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h2`,{children:m.name}),(0,S.jsx)(`p`,{children:r(`deviceHubDeviceTitle`)})]})]}),(0,S.jsxs)(`dl`,{className:`dc-details`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`dt`,{children:r(`deviceHubDeviceId`)}),(0,S.jsx)(`dd`,{children:m.deviceId})]}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`dt`,{children:r(`deviceHubHubUrl`)}),(0,S.jsx)(`dd`,{children:m.hubUrl})]})]})]}),f===`settings`&&(0,S.jsxs)(`section`,{className:`dc-card`,children:[(0,S.jsxs)(`div`,{className:`dc-card-header`,children:[(0,S.jsx)(`span`,{className:`dc-icon`,children:(0,S.jsx)(i,{"aria-hidden":!0})}),(0,S.jsx)(`div`,{children:(0,S.jsx)(`h2`,{children:r(`deviceHubPermissions`)})})]}),(0,S.jsxs)(`div`,{className:`dc-permission-row`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h3`,{id:`dc-permission-label`,children:r(`deviceHubPermissionLabel`)}),(0,S.jsx)(`p`,{id:`dc-permission-hint`,children:r(`deviceHubPermissionHint`)})]}),(0,S.jsx)(`button`,{type:`button`,className:`dc-toggle${m.allowExecution?` is-on`:``}`,role:`switch`,"aria-checked":m.allowExecution,"aria-labelledby":`dc-permission-label`,"aria-describedby":`dc-permission-hint`,disabled:!!A,onClick:()=>void de(),children:(0,S.jsx)(`span`,{className:`dc-toggle-thumb`})})]}),(0,S.jsx)(`p`,{className:`dc-permission-state`,role:`status`,children:r(A===`permission`?`deviceHubSaving`:m.allowExecution?`deviceHubEnabled`:`deviceHubReadOnly`)})]}),f===`settings`&&(0,S.jsxs)(`details`,{className:`dc-advanced`,children:[(0,S.jsx)(`summary`,{children:r(`deviceHubAdvanced`)}),(0,S.jsxs)(`div`,{className:`dc-danger-zone`,children:[(0,S.jsx)(`h3`,{children:r(`deviceHubDisconnect`)}),(0,S.jsx)(`p`,{children:r(`deviceHubDisconnectHint`)}),(0,S.jsx)(`button`,{type:`button`,className:`dc-button is-danger`,disabled:!!A,onClick:()=>void fe(),children:r(A===`disconnect`?`deviceHubWorking`:`deviceHubDisconnect`)})]})]})]}),$&&m?.hubUrl&&m.deviceId&&!B&&f!==`groups`&&(0,S.jsx)(v,{hubUrl:m.hubUrl,currentDeviceId:m.deviceId},`directory:${m.hubUrl}:${m.deviceId}`),!B&&(f===`settings`||f===`groups`)&&(0,S.jsx)(y,{pathCompletions:e},`bots:${m?.hubUrl??``}:${m?.deviceId??`unpaired`}`),f===`settings`&&(0,S.jsx)(N,{hubUrl:m?.hubUrl,deviceId:m?.deviceId,onNotice:z}),f===`groups`&&(0,S.jsx)(b,{navigation:a}),(0,S.jsxs)(`aside`,{className:`dc-help`,children:[(0,S.jsx)(d,{className:`dc-help-icon`,"aria-hidden":!0}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h3`,{children:r(`deviceHubHelpTitle`)}),(0,S.jsx)(`p`,{children:r(`deviceHubHelpText`)})]})]})]})]})]})}export{L as DeviceCenter};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{At as t,It as n,Sn as r,Tt as i,Vt as a,an as o,bn as s,hn as c,wn as l}from"./app-globals-DZNa9v8u.js";import{i as u,r as d,t as f}from"./react-CR5VJ85Q.js";import{t as p}from"./shortcut-stack-hhrDyRBn.js";import{_t as ee}from"./index-DHeeHS_l.js";import{r as te,t as ne}from"./group-view-state-CGCzYF8k.js";var m=e(u(),1),h=d(),g=f(),re={zh:{groups:`群聊`,manage:`管理成员`,save:`保存设置`,create:`建群`,name:`群名称`,devices:`选择 Bot(设备仅承载 Bot)`,empty:`还没有群聊,创建一个群开始协作。`,choose:`选择一个群聊`,open:`打开聊天`,online:`在线`,offline:`离线`,cancel:`取消`,loading:`加载中…`,rebind:`设备绑定已失效或已解除,请在设备设置中重新绑定。`,forbidden:`本机访问被拒绝,请检查本机登录状态与访问权限。`,failed:`请求失败`,searchPlaceholder:`搜索群或任务…`,matchedBot:`Bot: `,matchedTask:`任务: `},en:{groups:`Groups`,manage:`Manage members`,save:`Save settings`,create:`Create group`,name:`Group name`,devices:`Select Bots (devices host Bots)`,empty:`No groups yet. Create a group to collaborate.`,choose:`Select a group`,open:`Open chat`,online:`Online`,offline:`Offline`,cancel:`Cancel`,loading:`Loading…`,rebind:`The device binding has expired or was removed. Bind again in device settings.`,forbidden:`Local access denied. Check your local sign-in and access permissions.`,failed:`Request failed`,searchPlaceholder:`Search groups or tasks…`,matchedBot:`Bot: `,matchedTask:`Task: `}},_=class extends Error{status;code;constructor(e,t,n){super(n),this.status=e,this.code=t}};async function v(e,t,n){let i=await fetch(r(l(`/api/device-center/${e}`)),{method:n?`POST`:`GET`,credentials:`same-origin`,signal:t,...n?{headers:{"Content-Type":`application/json`},body:JSON.stringify(n)}:{}}),a=await i.json().catch(()=>({}));if(!i.ok)throw new _(i.status,a.code??``,typeof a.error==`string`?a.error:String(i.status));return a}function y(e){window.dispatchEvent(new CustomEvent(`pi-web-ui:device-group-open`,{detail:{roomId:e}}))}function b({onClose:e}){let{locale:t}=c(),n=re[s(t)?`zh`:`en`];return p(()=>{document.querySelector(`dialog[open]`)||e()}),(0,h.createPortal)((0,g.jsx)(`div`,{className:`modal-backdrop`,onClick:e,children:(0,g.jsx)(`div`,{className:`device-group-create-dialog`,role:`dialog`,"aria-modal":`true`,"aria-label":n.create,onClick:e=>e.stopPropagation(),children:(0,g.jsx)(x,{createOnly:!0,onClose:e})})}),document.body)}function x({active:e=!0,navigation:r,createOnly:l=!1,onClose:u}){let{locale:d}=c(),f=re[s(d)?`zh`:`en`],[p,h]=(0,m.useState)([]),[b,x]=(0,m.useState)([]),[S,ie]=(0,m.useState)(``),[C,w]=(0,m.useState)(null),[T,E]=(0,m.useState)(!0),[ae,D]=(0,m.useState)(``),[oe,O]=(0,m.useState)(!1),[k,A]=(0,m.useState)(l),[j,M]=(0,m.useState)(!1),[N,P]=(0,m.useState)(!1),[F,I]=(0,m.useState)(``),[L,R]=(0,m.useState)([]),[z,B]=(0,m.useState)(``),[V,H]=(0,m.useState)(!1),[se,U]=(0,m.useState)(0),[W,ce]=(0,m.useState)(``),[le,ue]=(0,m.useState)([]),G=(0,m.useRef)(new ne),K=(0,m.useRef)(null),q=(0,m.useRef)(void 0),J=(0,m.useRef)(0),Y=(0,m.useRef)(null),X=(0,m.useRef)(f);X.current=f;function de(e){let t=X.current;if(e instanceof _){if(e.status===409&&/^(REPAIR_REQUIRED|NOT_PAIRED|DEVICE_CHANGED)$/.test(e.code)||e.status===403&&/binding|credential|unpaired|revoked|not_bound|hub_forbidden/i.test(e.code))return t.rebind;if(e.status===403)return t.forbidden}return`${t.failed}: ${e instanceof Error?e.message:String(e)}`}function Z(){Y.current?.abort(),Y.current=null,H(!1)}function Q(e,t=!1){++J.current,Z(),ie(e),w(null),A(!1),M(t),O(!1),B(``),K.current=t?e:null,R([]),E(!0),D(``),U(e=>e+1)}function fe(){++J.current,Z(),A(!0),O(!1),B(``),M(!1),K.current=null,w(null),R([]),I(``),D(``),U(e=>e+1)}(0,m.useEffect)(()=>{let t=++J.current,n=null,r=!1,i=()=>J.current===t;async function a(){if(!e||document.visibilityState===`hidden`||r)return;r=!0;let t=new AbortController;n=t;try{let[e,n,r]=await Promise.all([v(`bots`,t.signal),v(`rooms`,t.signal),j&&S?v(`rooms/${encodeURIComponent(S)}`,t.signal):Promise.resolve(null)]);if(!i()||t.signal.aborted)return;if(h(e.bots),x(n.rooms),w(r),r?.tasks){ue(r.tasks);for(let e of r.tasks)e.status===`completed`?G.current.onTaskCompleted(e.roomId,e.id):e.status===`failed`&&G.current.onTaskFailed(e.roomId,e.id)}r&&K.current===r.room.id&&(K.current=null,R(r.room.botIds),B(r.room.primaryBotId??``)),D(``)}catch(e){i()&&!t.signal.aborted&&D(de(e))}finally{t.abort(),r=!1,i()&&E(!1)}}a();let o=window.setInterval(()=>void a(),3e3),s=()=>{document.visibilityState===`hidden`?n?.abort():a()};return document.addEventListener(`visibilitychange`,s),()=>{++J.current,n?.abort(),clearInterval(o),document.removeEventListener(`visibilitychange`,s)}},[e,S,j,se]),(0,m.useEffect)(()=>()=>Y.current?.abort(),[]),(0,m.useEffect)(()=>{e||Z()},[e]),(0,m.useEffect)(()=>{e&&r&&r.revision!==q.current&&(q.current=r.revision,r.create?fe():r.roomId&&Q(r.roomId,r.manage))},[e,r?.revision]);async function pe(){if(!e||Y.current||(k?!F.trim():!C))return;let t=new AbortController;Y.current=t,H(!0),D(``),O(!1);let n=L.includes(z)?z:``,r=k,i=C?.room.id;try{let{room:e}=await v(r?`rooms`:`rooms/${encodeURIComponent(i)}/members`,t.signal,{...r?{name:F.trim()}:{},botIds:L,...z&&L.includes(z)?{primaryBotId:z}:!r&&C?.room.primaryBotId?{primaryBotId:null}:{}});if(t.signal.aborted||Y.current!==t)return;if((e.primaryBotId??``)!==n)throw Error(s(d)?`中心未保存主 Bot 设置,请更新群组所属的设备中心(Hub)后重试。`:`The Hub did not save the primary Bot setting. Update the group's Hub and retry.`);O(!0),x(t=>[...t.filter(t=>t.id!==e.id),e]),ie(e.id),w({room:e}),A(!1),M(!r),I(``),R(r?[]:e.botIds),B(e.primaryBotId??``),U(e=>e+1),window.dispatchEvent(new CustomEvent(`pi-web-ui:device-groups-changed`)),r&&(y(e.id),l&&u?.())}catch(e){!t.signal.aborted&&Y.current===t&&D(de(e))}finally{Y.current===t&&(Y.current=null,H(!1))}}let $=b.find(e=>e.id===S);return(0,g.jsxs)(`section`,{className:`dg-root`,"aria-label":f.groups,children:[!l&&(0,g.jsxs)(`div`,{className:`dc-card dg-sidebar`,children:[(0,g.jsxs)(`div`,{className:`dg-heading`,children:[(0,g.jsxs)(`h2`,{children:[(0,g.jsx)(o,{}),` `,f.groups]}),(0,g.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:fe,children:[(0,g.jsx)(n,{}),` `,f.create]})]}),(0,g.jsx)(`div`,{className:`dg-search-bar`,style:{padding:`0 10px 8px 10px`},children:(0,g.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`6px`,background:`var(--bg)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`4px 8px`},children:[(0,g.jsx)(a,{style:{color:`var(--text-dim)`,flex:`none`}}),(0,g.jsx)(`input`,{type:`search`,value:W,onChange:e=>ce(e.target.value),placeholder:f.searchPlaceholder,style:{border:`none`,background:`transparent`,color:`var(--text)`,width:`100%`,fontSize:`12px`,outline:`none`}})]})}),(0,g.jsx)(`div`,{className:`dg-rooms`,children:te(W,b,le).map(t=>{let n=b.find(e=>e.id===t.roomId);if(!n)return null;let r=G.current.getPendingInteractionsCount(n.id);return(0,g.jsxs)(`button`,{className:`dc-button dg-room`,type:`button`,"aria-current":n.id===S?`page`:void 0,disabled:!e,onClick:()=>{Q(n.id),y(n.id)},children:[(0,g.jsx)(i,{}),(0,g.jsxs)(`span`,{style:{flex:1,minWidth:0,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,textAlign:`left`},children:[n.name,t.matchedBy===`bot_id`&&(0,g.jsxs)(`small`,{style:{display:`block`,color:`var(--text-dim)`,fontSize:`11px`},children:[f.matchedBot,` `,W]}),t.matchedBy===`task_title`&&t.matchedTask&&(0,g.jsxs)(`small`,{style:{display:`block`,color:`var(--accent)`,fontSize:`11px`},children:[f.matchedTask,` `,t.matchedTask.title]}),t.matchedBy===`task_id`&&t.matchedTask&&(0,g.jsxs)(`small`,{style:{display:`block`,color:`var(--text-dim)`,fontSize:`11px`},children:[`ID: `,t.matchedTask.id.slice(0,8)]})]}),r>0&&(0,g.jsx)(`span`,{style:{flex:`none`,background:`var(--accent)`,color:`var(--accent-contrast, #fff)`,borderRadius:`10px`,padding:`1px 6px`,fontSize:`11px`,fontWeight:`bold`},children:r})]},t.matchedTask?`${n.id}:${t.matchedTask.id}`:n.id)})}),!T&&!b.length&&(0,g.jsx)(`p`,{className:`dg-empty`,children:f.empty})]}),(0,g.jsxs)(`div`,{className:`dc-card dg-chat`,children:[oe&&(0,g.jsx)(`p`,{role:`status`,children:s(d)?`已保存成员和主 Bot 设置。`:`Members and primary Bot settings saved.`}),ae&&(0,g.jsx)(`p`,{className:`dc-error`,role:`alert`,children:ae}),T&&(0,g.jsx)(`p`,{role:`status`,children:f.loading}),k||j?(0,g.jsxs)(`form`,{className:`dg-create`,onSubmit:e=>{e.preventDefault(),pe()},children:[(0,g.jsx)(`h2`,{children:k?f.create:f.manage}),k&&(0,g.jsxs)(`div`,{className:`dc-field`,children:[(0,g.jsx)(`label`,{htmlFor:`device-group-name`,children:f.name}),(0,g.jsx)(`input`,{id:`device-group-name`,value:F,onChange:e=>I(e.target.value),disabled:V||!e})]}),(0,g.jsxs)(`fieldset`,{disabled:V||!e||j&&!C,children:[(0,g.jsx)(`legend`,{children:f.devices}),p.map(e=>(0,g.jsxs)(`label`,{className:`dg-device`,children:[(0,g.jsx)(`input`,{type:`checkbox`,disabled:!e.enabled&&!L.includes(e.id),checked:L.includes(e.id),onChange:t=>R(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}),(0,g.jsx)(t,{}),(0,g.jsxs)(`span`,{children:[e.name,` · `,e.id,` · `,e.deviceId,` · `,e.online?f.online:f.offline]})]},e.id))]}),(0,g.jsxs)(`div`,{className:`dc-field`,children:[(0,g.jsx)(`label`,{htmlFor:`device-group-primary-bot`,children:s(d)?`主 Bot`:`Primary Bot`}),(0,g.jsxs)(`select`,{id:`device-group-primary-bot`,value:L.includes(z)?z:``,disabled:V||!e||j&&!C,onChange:e=>B(e.target.value),children:[(0,g.jsx)(`option`,{value:``,children:s(d)?`不设置(需 @ Bot)`:`None (mention a Bot)`}),p.filter(e=>e.enabled&&L.includes(e.id)).map(e=>(0,g.jsxs)(`option`,{value:e.id,children:[e.name,` · `,e.id]},e.id))]}),(0,g.jsx)(`p`,{children:s(d)?`未 @ Bot 的消息自动发送给主 Bot。`:`Messages without a Bot mention go to the primary Bot.`})]}),(0,g.jsxs)(`div`,{className:`dc-actions`,children:[(0,g.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:V||!e||N,onClick:()=>P(!0),children:[(0,g.jsx)(n,{}),` `,s(d)?`新建 Bot`:`Create Bot`]}),(0,g.jsx)(`button`,{className:`dc-button`,type:`submit`,disabled:V||!e||(k?!F.trim():!C),children:k?f.create:f.save}),(0,g.jsx)(`button`,{className:`dc-button`,type:`button`,onClick:()=>{Z(),K.current=null,l&&u?.(),A(!1),M(!1),D(``)},children:f.cancel})]})]}):$?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`div`,{className:`dg-title`,children:(0,g.jsxs)(`h2`,{children:[(0,g.jsx)(o,{}),` `,$.name]})}),(0,g.jsxs)(`div`,{className:`dc-actions`,children:[(0,g.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:()=>y($.id),children:[(0,g.jsx)(i,{}),f.open]}),(0,g.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:()=>Q($.id,!0),children:[(0,g.jsx)(o,{}),f.manage]})]})]}):(0,g.jsx)(`p`,{className:`dg-empty`,children:f.choose})]}),N&&(0,g.jsx)(ee,{createOnly:!0,onCancel:()=>P(!1),onCreated:(e,t)=>{P(!1),t&&e.enabled?(h(t=>[...t.filter(t=>t.id!==e.id),e]),R(t=>[...new Set([...t,e.id])])):D(s(d)?`Bot 已保存;请启用并同步到中心后,再加入群组。`:`Bot saved. Enable and sync it to the hub before adding it to the group.`)}})]})}export{b as DeviceGroupCreateDialog,x as DeviceGroups};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{At as t,It as n,Sn as r,Tt as i,Vt as a,an as o,bn as s,hn as c,wn as l}from"./app-globals-DZNa9v8u.js";import{i as u,r as d,t as f}from"./react-CR5VJ85Q.js";import{t as p}from"./shortcut-stack-hhrDyRBn.js";import{_t as ee}from"./index-DTZch8uz.js";import{r as te,t as ne}from"./group-view-state-CGCzYF8k.js";var m=e(u(),1),h=d(),g=f(),re={zh:{groups:`群聊`,manage:`管理成员`,save:`保存设置`,create:`建群`,name:`群名称`,devices:`选择 Bot(设备仅承载 Bot)`,empty:`还没有群聊,创建一个群开始协作。`,choose:`选择一个群聊`,open:`打开聊天`,online:`在线`,offline:`离线`,cancel:`取消`,loading:`加载中…`,rebind:`设备绑定已失效或已解除,请在设备设置中重新绑定。`,forbidden:`本机访问被拒绝,请检查本机登录状态与访问权限。`,failed:`请求失败`,searchPlaceholder:`搜索群或任务…`,matchedBot:`Bot: `,matchedTask:`任务: `},en:{groups:`Groups`,manage:`Manage members`,save:`Save settings`,create:`Create group`,name:`Group name`,devices:`Select Bots (devices host Bots)`,empty:`No groups yet. Create a group to collaborate.`,choose:`Select a group`,open:`Open chat`,online:`Online`,offline:`Offline`,cancel:`Cancel`,loading:`Loading…`,rebind:`The device binding has expired or was removed. Bind again in device settings.`,forbidden:`Local access denied. Check your local sign-in and access permissions.`,failed:`Request failed`,searchPlaceholder:`Search groups or tasks…`,matchedBot:`Bot: `,matchedTask:`Task: `}},_=class extends Error{status;code;constructor(e,t,n){super(n),this.status=e,this.code=t}};async function v(e,t,n){let i=await fetch(r(l(`/api/device-center/${e}`)),{method:n?`POST`:`GET`,credentials:`same-origin`,signal:t,...n?{headers:{"Content-Type":`application/json`},body:JSON.stringify(n)}:{}}),a=await i.json().catch(()=>({}));if(!i.ok)throw new _(i.status,a.code??``,typeof a.error==`string`?a.error:String(i.status));return a}function y(e){window.dispatchEvent(new CustomEvent(`pi-web-ui:device-group-open`,{detail:{roomId:e}}))}function b({onClose:e}){let{locale:t}=c(),n=re[s(t)?`zh`:`en`];return p(()=>{document.querySelector(`dialog[open]`)||e()}),(0,h.createPortal)((0,g.jsx)(`div`,{className:`modal-backdrop`,onClick:e,children:(0,g.jsx)(`div`,{className:`device-group-create-dialog`,role:`dialog`,"aria-modal":`true`,"aria-label":n.create,onClick:e=>e.stopPropagation(),children:(0,g.jsx)(x,{createOnly:!0,onClose:e})})}),document.body)}function x({active:e=!0,navigation:r,createOnly:l=!1,onClose:u}){let{locale:d}=c(),f=re[s(d)?`zh`:`en`],[p,h]=(0,m.useState)([]),[b,x]=(0,m.useState)([]),[S,ie]=(0,m.useState)(``),[C,w]=(0,m.useState)(null),[T,E]=(0,m.useState)(!0),[ae,D]=(0,m.useState)(``),[oe,O]=(0,m.useState)(!1),[k,A]=(0,m.useState)(l),[j,M]=(0,m.useState)(!1),[N,P]=(0,m.useState)(!1),[F,I]=(0,m.useState)(``),[L,R]=(0,m.useState)([]),[z,B]=(0,m.useState)(``),[V,H]=(0,m.useState)(!1),[se,U]=(0,m.useState)(0),[W,ce]=(0,m.useState)(``),[le,ue]=(0,m.useState)([]),G=(0,m.useRef)(new ne),K=(0,m.useRef)(null),q=(0,m.useRef)(void 0),J=(0,m.useRef)(0),Y=(0,m.useRef)(null),X=(0,m.useRef)(f);X.current=f;function de(e){let t=X.current;if(e instanceof _){if(e.status===409&&/^(REPAIR_REQUIRED|NOT_PAIRED|DEVICE_CHANGED)$/.test(e.code)||e.status===403&&/binding|credential|unpaired|revoked|not_bound|hub_forbidden/i.test(e.code))return t.rebind;if(e.status===403)return t.forbidden}return`${t.failed}: ${e instanceof Error?e.message:String(e)}`}function Z(){Y.current?.abort(),Y.current=null,H(!1)}function Q(e,t=!1){++J.current,Z(),ie(e),w(null),A(!1),M(t),O(!1),B(``),K.current=t?e:null,R([]),E(!0),D(``),U(e=>e+1)}function fe(){++J.current,Z(),A(!0),O(!1),B(``),M(!1),K.current=null,w(null),R([]),I(``),D(``),U(e=>e+1)}(0,m.useEffect)(()=>{let t=++J.current,n=null,r=!1,i=()=>J.current===t;async function a(){if(!e||document.visibilityState===`hidden`||r)return;r=!0;let t=new AbortController;n=t;try{let[e,n,r]=await Promise.all([v(`bots`,t.signal),v(`rooms`,t.signal),j&&S?v(`rooms/${encodeURIComponent(S)}`,t.signal):Promise.resolve(null)]);if(!i()||t.signal.aborted)return;if(h(e.bots),x(n.rooms),w(r),r?.tasks){ue(r.tasks);for(let e of r.tasks)e.status===`completed`?G.current.onTaskCompleted(e.roomId,e.id):e.status===`failed`&&G.current.onTaskFailed(e.roomId,e.id)}r&&K.current===r.room.id&&(K.current=null,R(r.room.botIds),B(r.room.primaryBotId??``)),D(``)}catch(e){i()&&!t.signal.aborted&&D(de(e))}finally{t.abort(),r=!1,i()&&E(!1)}}a();let o=window.setInterval(()=>void a(),3e3),s=()=>{document.visibilityState===`hidden`?n?.abort():a()};return document.addEventListener(`visibilitychange`,s),()=>{++J.current,n?.abort(),clearInterval(o),document.removeEventListener(`visibilitychange`,s)}},[e,S,j,se]),(0,m.useEffect)(()=>()=>Y.current?.abort(),[]),(0,m.useEffect)(()=>{e||Z()},[e]),(0,m.useEffect)(()=>{e&&r&&r.revision!==q.current&&(q.current=r.revision,r.create?fe():r.roomId&&Q(r.roomId,r.manage))},[e,r?.revision]);async function pe(){if(!e||Y.current||(k?!F.trim():!C))return;let t=new AbortController;Y.current=t,H(!0),D(``),O(!1);let n=L.includes(z)?z:``,r=k,i=C?.room.id;try{let{room:e}=await v(r?`rooms`:`rooms/${encodeURIComponent(i)}/members`,t.signal,{...r?{name:F.trim()}:{},botIds:L,...z&&L.includes(z)?{primaryBotId:z}:!r&&C?.room.primaryBotId?{primaryBotId:null}:{}});if(t.signal.aborted||Y.current!==t)return;if((e.primaryBotId??``)!==n)throw Error(s(d)?`中心未保存主 Bot 设置,请更新群组所属的设备中心(Hub)后重试。`:`The Hub did not save the primary Bot setting. Update the group's Hub and retry.`);O(!0),x(t=>[...t.filter(t=>t.id!==e.id),e]),ie(e.id),w({room:e}),A(!1),M(!r),I(``),R(r?[]:e.botIds),B(e.primaryBotId??``),U(e=>e+1),window.dispatchEvent(new CustomEvent(`pi-web-ui:device-groups-changed`)),r&&(y(e.id),l&&u?.())}catch(e){!t.signal.aborted&&Y.current===t&&D(de(e))}finally{Y.current===t&&(Y.current=null,H(!1))}}let $=b.find(e=>e.id===S);return(0,g.jsxs)(`section`,{className:`dg-root`,"aria-label":f.groups,children:[!l&&(0,g.jsxs)(`div`,{className:`dc-card dg-sidebar`,children:[(0,g.jsxs)(`div`,{className:`dg-heading`,children:[(0,g.jsxs)(`h2`,{children:[(0,g.jsx)(o,{}),` `,f.groups]}),(0,g.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:fe,children:[(0,g.jsx)(n,{}),` `,f.create]})]}),(0,g.jsx)(`div`,{className:`dg-search-bar`,style:{padding:`0 10px 8px 10px`},children:(0,g.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`6px`,background:`var(--bg)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`4px 8px`},children:[(0,g.jsx)(a,{style:{color:`var(--text-dim)`,flex:`none`}}),(0,g.jsx)(`input`,{type:`search`,value:W,onChange:e=>ce(e.target.value),placeholder:f.searchPlaceholder,style:{border:`none`,background:`transparent`,color:`var(--text)`,width:`100%`,fontSize:`12px`,outline:`none`}})]})}),(0,g.jsx)(`div`,{className:`dg-rooms`,children:te(W,b,le).map(t=>{let n=b.find(e=>e.id===t.roomId);if(!n)return null;let r=G.current.getPendingInteractionsCount(n.id);return(0,g.jsxs)(`button`,{className:`dc-button dg-room`,type:`button`,"aria-current":n.id===S?`page`:void 0,disabled:!e,onClick:()=>{Q(n.id),y(n.id)},children:[(0,g.jsx)(i,{}),(0,g.jsxs)(`span`,{style:{flex:1,minWidth:0,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,textAlign:`left`},children:[n.name,t.matchedBy===`bot_id`&&(0,g.jsxs)(`small`,{style:{display:`block`,color:`var(--text-dim)`,fontSize:`11px`},children:[f.matchedBot,` `,W]}),t.matchedBy===`task_title`&&t.matchedTask&&(0,g.jsxs)(`small`,{style:{display:`block`,color:`var(--accent)`,fontSize:`11px`},children:[f.matchedTask,` `,t.matchedTask.title]}),t.matchedBy===`task_id`&&t.matchedTask&&(0,g.jsxs)(`small`,{style:{display:`block`,color:`var(--text-dim)`,fontSize:`11px`},children:[`ID: `,t.matchedTask.id.slice(0,8)]})]}),r>0&&(0,g.jsx)(`span`,{style:{flex:`none`,background:`var(--accent)`,color:`var(--accent-contrast, #fff)`,borderRadius:`10px`,padding:`1px 6px`,fontSize:`11px`,fontWeight:`bold`},children:r})]},t.matchedTask?`${n.id}:${t.matchedTask.id}`:n.id)})}),!T&&!b.length&&(0,g.jsx)(`p`,{className:`dg-empty`,children:f.empty})]}),(0,g.jsxs)(`div`,{className:`dc-card dg-chat`,children:[oe&&(0,g.jsx)(`p`,{role:`status`,children:s(d)?`已保存成员和主 Bot 设置。`:`Members and primary Bot settings saved.`}),ae&&(0,g.jsx)(`p`,{className:`dc-error`,role:`alert`,children:ae}),T&&(0,g.jsx)(`p`,{role:`status`,children:f.loading}),k||j?(0,g.jsxs)(`form`,{className:`dg-create`,onSubmit:e=>{e.preventDefault(),pe()},children:[(0,g.jsx)(`h2`,{children:k?f.create:f.manage}),k&&(0,g.jsxs)(`div`,{className:`dc-field`,children:[(0,g.jsx)(`label`,{htmlFor:`device-group-name`,children:f.name}),(0,g.jsx)(`input`,{id:`device-group-name`,value:F,onChange:e=>I(e.target.value),disabled:V||!e})]}),(0,g.jsxs)(`fieldset`,{disabled:V||!e||j&&!C,children:[(0,g.jsx)(`legend`,{children:f.devices}),p.map(e=>(0,g.jsxs)(`label`,{className:`dg-device`,children:[(0,g.jsx)(`input`,{type:`checkbox`,disabled:!e.enabled&&!L.includes(e.id),checked:L.includes(e.id),onChange:t=>R(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}),(0,g.jsx)(t,{}),(0,g.jsxs)(`span`,{children:[e.name,` · `,e.id,` · `,e.deviceId,` · `,e.online?f.online:f.offline]})]},e.id))]}),(0,g.jsxs)(`div`,{className:`dc-field`,children:[(0,g.jsx)(`label`,{htmlFor:`device-group-primary-bot`,children:s(d)?`主 Bot`:`Primary Bot`}),(0,g.jsxs)(`select`,{id:`device-group-primary-bot`,value:L.includes(z)?z:``,disabled:V||!e||j&&!C,onChange:e=>B(e.target.value),children:[(0,g.jsx)(`option`,{value:``,children:s(d)?`不设置(需 @ Bot)`:`None (mention a Bot)`}),p.filter(e=>e.enabled&&L.includes(e.id)).map(e=>(0,g.jsxs)(`option`,{value:e.id,children:[e.name,` · `,e.id]},e.id))]}),(0,g.jsx)(`p`,{children:s(d)?`未 @ Bot 的消息自动发送给主 Bot。`:`Messages without a Bot mention go to the primary Bot.`})]}),(0,g.jsxs)(`div`,{className:`dc-actions`,children:[(0,g.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:V||!e||N,onClick:()=>P(!0),children:[(0,g.jsx)(n,{}),` `,s(d)?`新建 Bot`:`Create Bot`]}),(0,g.jsx)(`button`,{className:`dc-button`,type:`submit`,disabled:V||!e||(k?!F.trim():!C),children:k?f.create:f.save}),(0,g.jsx)(`button`,{className:`dc-button`,type:`button`,onClick:()=>{Z(),K.current=null,l&&u?.(),A(!1),M(!1),D(``)},children:f.cancel})]})]}):$?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`div`,{className:`dg-title`,children:(0,g.jsxs)(`h2`,{children:[(0,g.jsx)(o,{}),` `,$.name]})}),(0,g.jsxs)(`div`,{className:`dc-actions`,children:[(0,g.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:()=>y($.id),children:[(0,g.jsx)(i,{}),f.open]}),(0,g.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:()=>Q($.id,!0),children:[(0,g.jsx)(o,{}),f.manage]})]})]}):(0,g.jsx)(`p`,{className:`dg-empty`,children:f.choose})]}),N&&(0,g.jsx)(ee,{createOnly:!0,onCancel:()=>P(!1),onCreated:(e,t)=>{P(!1),t&&e.enabled?(h(t=>[...t.filter(t=>t.id!==e.id),e]),R(t=>[...new Set([...t,e.id])])):D(s(d)?`Bot 已保存;请启用并同步到中心后,再加入群组。`:`Bot saved. Enable and sync it to the hub before adding it to the group.`)}})]})}export{b as DeviceGroupCreateDialog,x as DeviceGroups};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Dt as t,J as n,O as r,Q as i,R as a,Sn as ee,St as te,V as ne,X as re,Z as ie,_n as ae,ln as oe,sn as se,t as ce,un as le,vt as ue,wn as de,yt as fe,zt as pe}from"./app-globals-DZNa9v8u.js";import{i as o,t as s}from"./react-CR5VJ85Q.js";import{K as me,U as he,ct as ge,dt as _e,pt as ve}from"./index-DHeeHS_l.js";var c=e(o(),1),l=`未命名章节`;function u(e){return String(e??``).trim().replace(/[\s\u3000]+/g,`-`).replace(/[^\p{L}\p{N}_-]+/gu,`-`).replace(/-{2,}/g,`-`).replace(/^-+|-+$/g,``).slice(0,80)||`section`}function ye(e){let t=new Map;return e.map(({level:e,label:n})=>{let r=String(n??``).replace(/\s+/g,` `).trim(),i=u(r||l),a=(t.get(i)??0)+1;return t.set(i,a),{level:e,id:a===1?i:`${i}-${a}`,label:r||l}})}function d(e){return e.length>=2}var f=s(),p=5e3,be=`pi-web-ui:preview-toc`;function m({file:e,content:o,onAddLines:s,onAttach:l,onClose:u,uiFilePreviewToolbar:m,onUiAction:xe}){let v=ae(),[y,Se]=(0,c.useState)(null),[b,Ce]=(0,c.useState)(!1),[x,S]=(0,c.useState)(null),[we,Te]=(0,c.useState)(!1),[Ee,De]=(0,c.useState)(!1),[C,w]=(0,c.useState)(!1),[T,E]=(0,c.useState)(``),[D,O]=(0,c.useState)(!0),[k,A]=(0,c.useState)(!0),[j,Oe]=(0,c.useState)(!1),M=(0,c.useRef)(!1),[N,ke]=(0,c.useState)(!0),[P,Ae]=(0,c.useState)(!1),[F,je]=(0,c.useState)(100),I=(0,c.useRef)(0),L=(0,c.useRef)(!1),R=(0,c.useRef)(null),[Me,z]=(0,c.useState)(!1),[Ne,B]=(0,c.useState)(!1),V=(0,c.useRef)(!1),H=(0,c.useRef)(null);(0,c.useEffect)(()=>()=>{R.current&&clearTimeout(R.current),H.current&&clearTimeout(H.current)},[]),(0,c.useEffect)(()=>{Ce(!0),Se(null),S(null),w(!1),E(``),O(!0),A(!0),Oe(!1),M.current=!1,V.current=!1,z(!1),B(!1),H.current&&clearTimeout(H.current),ce({type:`read_file`,path:e.path})},[e.path]),(0,c.useEffect)(()=>{o&&o.path===e.path&&(Se(o),C||E(o.text),Ce(!1),V.current&&(V.current=!1,H.current&&clearTimeout(H.current),z(!1),B(!1),w(!1),E(o.text),M.current&&(h(e.name)&&O(!0),_(e.name)&&A(!0)),S(null)))},[o,C,e.path]),(0,c.useEffect)(()=>{let e=e=>{if(e.key===`Escape`){G();return}if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`s`&&C){e.preventDefault(),Ve();return}let t=e.target,n=t&&(t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.isContentEditable);(e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`a`&&!n&&(e.preventDefault(),Le())};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[u,y,C,T]),(0,c.useEffect)(()=>{let e=()=>{L.current=!1,Te(!1)};return window.addEventListener(`mouseup`,e),()=>window.removeEventListener(`mouseup`,e)},[]);let U=(0,c.useMemo)(()=>{if(!y)return[];let e=y.text.split(`
|
|
2
|
-
`);return e.length>0&&e[e.length-1]===``&&e.pop(),e.slice(0,p)},[y]),Pe=y?.lines??0,Fe=Pe>p,Ie=(e,t)=>{if(t){let t=I.current>0?I.current:e;S({start:Math.min(t,e),end:Math.max(t,e)})}else I.current=e,S({start:e,end:e})},Le=()=>{U.length!==0&&(I.current=1,S({start:1,end:U.length}))},Re=()=>{x&&(s(e.path,e.name,x.start,x.end),De(!0),R.current&&clearTimeout(R.current),R.current=setTimeout(()=>De(!1),1400))},W=y!==null&&y.kind===`text`&&!y.binary&&!y.truncated&&!g(e.name),ze=()=>{V.current=!1,H.current&&clearTimeout(H.current),z(!1),B(!1),E(y?.text??``),w(!1),M.current&&(h(e.name)&&O(!0),_(e.name)&&A(!0))},Be=()=>{if(C){if(T!==(y?.text??``)&&!window.confirm(v(`discardFileChanges`)))return;ze();return}W&&y&&(M.current=h(e.name)&&D||_(e.name)&&k,h(e.name)&&O(!1),_(e.name)&&A(!1),S(null),E(y.text),w(!0))},Ve=()=>{C&&y&&W&&ce({type:`write_file`,path:e.path,text:T})&&(V.current=!0,B(!1),z(!0),H.current&&clearTimeout(H.current),H.current=setTimeout(()=>{V.current=!1,z(!1),B(!0)},5e3))},G=()=>{(!C||T===(y?.text??``)||window.confirm(v(`discardFileChanges`)))&&u()},He=e=>{je(Math.min(200,Math.max(50,e)))},Ue=x?x.end-x.start+1:0,K=y?.binary??!1,We=y?.truncated??!1,q=y?.kind??`text`,Ge=h(e.name)||g(e.name),Ke=_(e.name),qe=g(e.name),J=Ge&&D&&!C&&q===`text`&&!K,Y=Ke&&k&&!C&&q===`text`&&!K,[X,Je]=(0,c.useState)(()=>{try{return localStorage.getItem(be)===`1`}catch{return!1}});(0,c.useEffect)(()=>{try{localStorage.setItem(be,X?`1`:`0`)}catch{}},[X]);let[Z,Ye]=(0,c.useState)([]),[Xe,Ze]=(0,c.useState)(``),Q=(0,c.useRef)(null);(0,c.useEffect)(()=>{let e=Q.current;if(!e||!J){Ye([]);return}let t=[...e.querySelectorAll(`h1, h2, h3, h4, h5, h6`)],n=ye(t.map(e=>({level:Number(e.tagName.slice(1)),label:e.textContent??``})));t.forEach((e,t)=>{e.id||=n[t].id}),Ye(n)},[J,y?.text,e.path]),(0,c.useEffect)(()=>{let e=Q.current;if(!e||!X||!d(Z))return;let t=Z.map(t=>e.querySelector(`#${CSS.escape(t.id)}`)).filter(e=>e!==null);if(t.length===0)return;let n=new IntersectionObserver(e=>{let t=e.filter(e=>e.isIntersecting).sort((e,t)=>e.boundingClientRect.top-t.boundingClientRect.top)[0];t?.target.id&&Ze(t.target.id)},{rootMargin:`0px 0px -70% 0px`});for(let e of t)n.observe(e);return()=>n.disconnect()},[Z,X]);let Qe={"host:fp-md":Ge&&q===`text`&&!K&&y?(0,f.jsx)(`button`,{type:`button`,className:`fp-attach markdown ${D?`on`:``}`,"data-tip":v(D?`showMarkdownSource`:`showMarkdownPreview`),disabled:C,onClick:()=>O(e=>!e),children:D?(0,f.jsx)(i,{}):(0,f.jsx)(a,{})}):null,"host:fp-toc":J&&d(Z)?(0,f.jsx)(`button`,{type:`button`,className:`fp-attach toc ${X?`on`:``}`,"data-tip":v(X?`previewTocHide`:`previewTocShow`),onClick:()=>Je(e=>!e),children:(0,f.jsx)(fe,{})}):null,"host:fp-html":Ke&&q===`text`&&!K&&y?(0,f.jsx)(`button`,{type:`button`,className:`fp-attach html ${k?`on`:``}`,"data-tip":v(k?`showHtmlSource`:`showHtmlPreview`),disabled:C,onClick:()=>A(e=>!e),children:k?(0,f.jsx)(a,{}):(0,f.jsx)(i,{})}):null,"host:fp-edit":q===`text`&&!K&&y?(0,f.jsx)(`button`,{type:`button`,className:`fp-attach edit ${C?`on`:``}`,"data-tip":v(We?`fileEditTruncated`:C?`exitEditFile`:`editFile`),disabled:!W&&!C,onClick:Be,children:(0,f.jsx)(re,{})}):null,"host:fp-wrap":q===`text`&&!K&&!J&&!Y?(0,f.jsx)(`button`,{type:`button`,className:`fp-attach wrap ${N?`on`:``}`,"data-tip":v(N?`disableWrap`:`enableWrap`),onClick:()=>ke(e=>!e),children:(0,f.jsx)(ne,{})}):null,"host:fp-zoom":q===`text`&&y?(0,f.jsxs)(`span`,{className:`fp-zoom`,children:[(0,f.jsx)(`button`,{type:`button`,className:`fp-attach zoom-out`,"data-tip":v(`zoomOut`),disabled:F<=50,onClick:()=>He(F-10),children:(0,f.jsx)(le,{})}),(0,f.jsxs)(`button`,{type:`button`,className:`fp-zoom-val`,title:v(`resetZoom`),onClick:()=>je(100),children:[F,`%`]}),(0,f.jsx)(`button`,{type:`button`,className:`fp-attach zoom-in`,"data-tip":v(`zoomIn`),disabled:F>=200,onClick:()=>He(F+10),children:(0,f.jsx)(oe,{})})]}):null,"host:fp-download":(0,f.jsx)(`button`,{type:`button`,className:`fp-attach download`,"data-tip":v(`downloadFile`),onClick:()=>void _e(e.path,e.name),children:(0,f.jsx)(n,{})}),"host:fp-ref":(0,f.jsx)(`button`,{type:`button`,className:`fp-attach ref`,"data-tip":v(`referenceTip`),onClick:()=>l(e.path,e.name,`reference`),children:(0,f.jsx)(ue,{})}),"host:fp-full":(0,f.jsx)(`button`,{type:`button`,className:`fp-attach full ${P?`on`:``}`,"data-tip":v(P?`exitFullscreen`:`fullscreen`),onClick:()=>Ae(e=>!e),children:P?(0,f.jsx)(t,{}):(0,f.jsx)(te,{})}),"host:fp-close":null},$e=m===void 0?[`host:fp-md`,`host:fp-toc`,`host:fp-html`,`host:fp-edit`,`host:fp-wrap`,`host:fp-zoom`,`host:fp-download`,`host:fp-ref`,`host:fp-full`].map(e=>({id:e,source:`host`})):m.filter(e=>!e.hidden&&e.id!==`host:fp-close`),$=e=>ee(de(`/api/file?clientId=${encodeURIComponent(me())}&path=${encodeURIComponent(e)}`)),et=e=>{let t=e.split(`/`).map(e=>encodeURIComponent(e)).join(`/`),n=/^[A-Za-z]:([\\/]|$)/.test(e)||e.startsWith(`/`)?`/api/preview/__abs__/${t}`:`/api/preview/${t}`;return ee(de(`${n}?clientId=${encodeURIComponent(me())}${j?`&allowJs=1`:``}`))};return(0,f.jsx)(`div`,{className:`fp-overlay ${P?`fullscreen`:``}`,onMouseDown:e=>{e.target===e.currentTarget&&G()},children:(0,f.jsxs)(`div`,{className:`fp ${P?`fullscreen`:``} ${qe?`is-ppt`:``}`,style:{"--fp-zoom":F/100},children:[(0,f.jsxs)(`div`,{className:`fp-head`,onDoubleClick:e=>{let t=e.target;t&&!t.closest(`button, a, input`)&&Ae(e=>!e)},children:[(0,f.jsx)(`span`,{className:`fp-name`,title:e.path,children:e.name}),(0,f.jsx)(`span`,{className:`fp-path`,children:e.path}),(0,f.jsxs)(`span`,{className:`fp-meta`,children:[y&&q===`text`&&!K&&v(`fileLines`,{n:Pe}),y&&` · ${ge(y.size)}`]}),(0,f.jsx)(`span`,{className:`fp-head-actions`,children:he($e,Qe,xe)}),(0,f.jsx)(`button`,{type:`button`,className:`fp-close`,title:v(`close`),"aria-label":v(`close`),onClick:G,children:(0,f.jsx)(se,{})})]}),We&&q===`text`&&!K&&(0,f.jsx)(`div`,{className:`fp-notice`,children:g(e.name)?v(`previewLinesTruncated`,{n:U.length}):v(`previewTruncated`)}),b&&!y&&(0,f.jsx)(`div`,{className:`fp-empty`,children:v(`loading`)}),!b&&q===`none`&&!K&&(0,f.jsx)(`div`,{className:`fp-empty`,children:v(`previewNotSupported`)}),!b&&q===`image`&&(0,f.jsx)(`div`,{className:`fp-media-wrap clickable`,onClick:G,title:v(`clickToCloseImage`),children:(0,f.jsx)(`img`,{className:`fp-media fp-media-clickable`,src:$(e.path),alt:e.name,onClick:G,title:v(`clickToCloseImage`)})}),!b&&q===`video`&&(0,f.jsx)(`div`,{className:`fp-media-wrap`,children:(0,f.jsx)(`video`,{className:`fp-media`,src:$(e.path),controls:!0,preload:`metadata`})}),!b&&q===`audio`&&(0,f.jsx)(`div`,{className:`fp-media-wrap fp-audio-wrap`,children:(0,f.jsxs)(`div`,{className:`fp-audio-card`,children:[(0,f.jsx)(`div`,{className:`fp-audio-icon`,"aria-hidden":`true`,children:`🎵`}),(0,f.jsxs)(`div`,{className:`fp-audio-info`,children:[(0,f.jsx)(`div`,{className:`fp-audio-name`,title:e.name,children:e.name}),y?.size?(0,f.jsx)(`div`,{className:`fp-audio-size`,children:ge(y.size)}):null]}),(0,f.jsx)(`audio`,{className:`fp-audio-element`,src:$(e.path),controls:!0,autoPlay:!0,preload:`metadata`})]})}),!b&&Y&&y&&(0,f.jsxs)(`div`,{className:`fp-html`,children:[(0,f.jsxs)(`div`,{className:`fp-html-bar`,children:[(0,f.jsx)(`span`,{className:`fp-html-hint`,title:v(j?`htmlJsOnTip`:`htmlJsOffTip`),children:v(j?`htmlJsOn`:`htmlJsOff`)}),(0,f.jsx)(`button`,{type:`button`,className:`fp-html-js ${j?`on`:``}`,"data-tip":v(j?`htmlDisableJs`:`htmlEnableJs`),onClick:()=>Oe(e=>!e),children:v(j?`htmlDisableJs`:`htmlEnableJs`)}),(0,f.jsxs)(`a`,{className:`fp-html-btn fp-html-external`,href:et(e.path),target:`_blank`,rel:`noopener noreferrer`,title:v(`openInNewTab`),children:[(0,f.jsx)(ie,{}),(0,f.jsx)(`span`,{children:v(`openInNewTab`)})]})]}),(0,f.jsx)(`iframe`,{className:`fp-html-frame`,src:et(e.path),title:e.name,sandbox:j?`allow-scripts`:``,referrerPolicy:`no-referrer`},j?`js`:`nojs`)]}),!b&&J&&y&&(0,f.jsx)(`div`,{className:g(e.name)?`fp-markdown msg-text fp-office`:`fp-markdown msg-text`,children:(0,f.jsxs)(`div`,{className:X&&d(Z)?`fp-toc-layout`:void 0,children:[X&&d(Z)&&(0,f.jsx)(`nav`,{className:`fp-toc`,"aria-label":v(`previewTocLabel`),children:Z.map(e=>(0,f.jsx)(`a`,{className:`l${Math.min(e.level,6)}${e.id===Xe?` on`:``}`,href:`#${e.id}`,title:e.label,onClick:t=>{t.preventDefault(),Q.current?.querySelector(`#${CSS.escape(e.id)}`)?.scrollIntoView({behavior:`smooth`,block:`start`})},children:e.label},e.id))}),(0,f.jsx)(`div`,{className:`fp-markdown-zoom`,ref:Q,children:(0,f.jsx)(ve,{text:y.text})})]})}),!b&&K&&q!==`image`&&q!==`video`&&y&&(0,f.jsxs)(`div`,{className:`fp-hex-wrap`,children:[(0,f.jsxs)(`div`,{className:`fp-notice`,children:[v(`binaryFile`),y.truncated&&v(`binaryHexTruncated`)]}),(0,f.jsx)(`pre`,{className:`fp-hex`,children:y.text})]}),!b&&C&&q===`text`&&!K&&y&&(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`textarea`,{className:`fp-editor ${N?``:`no-wrap`}`,value:T,onChange:e=>E(e.target.value),wrap:N?`soft`:`off`,spellCheck:!1,autoFocus:!0}),Ne&&(0,f.jsx)(`div`,{className:`fp-notice`,role:`alert`,children:v(`saveResultUnknown`)})]}),!b&&!J&&!Y&&!C&&q===`text`&&!K&&y&&U.length===0&&(0,f.jsx)(`div`,{className:`fp-empty`,children:v(`emptyFile`)}),!b&&!J&&!Y&&!C&&q===`text`&&!K&&U.length>0&&(0,f.jsxs)(`div`,{className:`fp-code ${we?`dragging`:``} ${N?``:`no-wrap`}`,onMouseDown:e=>{e.button===0&&e.preventDefault()},children:[U.map((e,t)=>{let n=t+1,r=x!==null&&n>=x.start&&n<=x.end;return(0,f.jsxs)(`div`,{className:`fp-line ${r?`sel`:``}`,onMouseDown:e=>{e.button===0&&(Ie(n,e.shiftKey),L.current=!0,Te(!0))},onMouseEnter:()=>{L.current&&Ie(n,!0)},children:[(0,f.jsx)(`span`,{className:`fp-num`,children:n}),(0,f.jsx)(`span`,{className:`fp-code-text`,children:e})]},n)}),Fe&&(0,f.jsx)(`div`,{className:`fp-lines-note`,children:v(`previewLinesTruncated`,{n:p})})]}),(C||!J&&!Y&&q===`text`)&&(0,f.jsx)(`div`,{className:`fp-foot`,children:C?(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`span`,{className:`fp-hint`,children:v(`editFile`)}),(0,f.jsxs)(`div`,{className:`fp-actions`,children:[(0,f.jsx)(`button`,{type:`button`,className:`btn`,onClick:Be,children:v(`cancel`)}),(0,f.jsxs)(`button`,{type:`button`,className:`btn primary`,disabled:Me||T===(y?.text??``),onClick:Ve,children:[(0,f.jsx)(pe,{}),` `,v(`saveFile`)]})]})]}):(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`span`,{className:`fp-hint`,children:x?v(`selectedRange`,{n:Ue,start:x.start,end:x.end}):v(`selectLinesHint`)}),(0,f.jsxs)(`div`,{className:`fp-actions`,children:[(0,f.jsx)(`button`,{type:`button`,className:`btn`,disabled:U.length===0,onClick:Le,children:v(`selectAll`)}),(0,f.jsx)(`button`,{type:`button`,className:`btn`,disabled:!x,onClick:()=>S(null),children:v(`clearSelection`)}),(0,f.jsxs)(`button`,{type:`button`,className:`btn primary`,disabled:!x||K,onClick:Re,children:[Ee?(0,f.jsx)(r,{}):null,v(Ee?`addedToChat`:`addToChat`)]})]})]})})]})})}function h(e){let t=e.toLowerCase();return t.endsWith(`.md`)||t.endsWith(`.markdown`)}function g(e){let t=e.toLowerCase();return t.endsWith(`.docx`)||t.endsWith(`.xlsx`)||t.endsWith(`.xlsm`)||t.endsWith(`.pptx`)||t.endsWith(`.pptm`)||t.endsWith(`.ppsx`)||t.endsWith(`.potx`)}function _(e){let t=e.toLowerCase();return t.endsWith(`.html`)||t.endsWith(`.htm`)||t.endsWith(`.xhtml`)}export{m as FilePreview};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Dt as t,J as n,O as r,Q as i,R as a,Sn as ee,St as te,V as ne,X as re,Z as ie,_n as ae,ln as oe,sn as se,t as ce,un as le,vt as ue,wn as de,yt as fe,zt as pe}from"./app-globals-DZNa9v8u.js";import{i as o,t as s}from"./react-CR5VJ85Q.js";import{K as me,U as he,ct as ge,dt as _e,pt as ve}from"./index-DTZch8uz.js";var c=e(o(),1),l=`未命名章节`;function u(e){return String(e??``).trim().replace(/[\s\u3000]+/g,`-`).replace(/[^\p{L}\p{N}_-]+/gu,`-`).replace(/-{2,}/g,`-`).replace(/^-+|-+$/g,``).slice(0,80)||`section`}function ye(e){let t=new Map;return e.map(({level:e,label:n})=>{let r=String(n??``).replace(/\s+/g,` `).trim(),i=u(r||l),a=(t.get(i)??0)+1;return t.set(i,a),{level:e,id:a===1?i:`${i}-${a}`,label:r||l}})}function d(e){return e.length>=2}var f=s(),p=5e3,be=`pi-web-ui:preview-toc`;function m({file:e,content:o,onAddLines:s,onAttach:l,onClose:u,uiFilePreviewToolbar:m,onUiAction:xe}){let v=ae(),[y,Se]=(0,c.useState)(null),[b,Ce]=(0,c.useState)(!1),[x,S]=(0,c.useState)(null),[we,Te]=(0,c.useState)(!1),[Ee,De]=(0,c.useState)(!1),[C,w]=(0,c.useState)(!1),[T,E]=(0,c.useState)(``),[D,O]=(0,c.useState)(!0),[k,A]=(0,c.useState)(!0),[j,Oe]=(0,c.useState)(!1),M=(0,c.useRef)(!1),[N,ke]=(0,c.useState)(!0),[P,Ae]=(0,c.useState)(!1),[F,je]=(0,c.useState)(100),I=(0,c.useRef)(0),L=(0,c.useRef)(!1),R=(0,c.useRef)(null),[Me,z]=(0,c.useState)(!1),[Ne,B]=(0,c.useState)(!1),V=(0,c.useRef)(!1),H=(0,c.useRef)(null);(0,c.useEffect)(()=>()=>{R.current&&clearTimeout(R.current),H.current&&clearTimeout(H.current)},[]),(0,c.useEffect)(()=>{Ce(!0),Se(null),S(null),w(!1),E(``),O(!0),A(!0),Oe(!1),M.current=!1,V.current=!1,z(!1),B(!1),H.current&&clearTimeout(H.current),ce({type:`read_file`,path:e.path})},[e.path]),(0,c.useEffect)(()=>{o&&o.path===e.path&&(Se(o),C||E(o.text),Ce(!1),V.current&&(V.current=!1,H.current&&clearTimeout(H.current),z(!1),B(!1),w(!1),E(o.text),M.current&&(h(e.name)&&O(!0),_(e.name)&&A(!0)),S(null)))},[o,C,e.path]),(0,c.useEffect)(()=>{let e=e=>{if(e.key===`Escape`){G();return}if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`s`&&C){e.preventDefault(),Ve();return}let t=e.target,n=t&&(t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.isContentEditable);(e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`a`&&!n&&(e.preventDefault(),Le())};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[u,y,C,T]),(0,c.useEffect)(()=>{let e=()=>{L.current=!1,Te(!1)};return window.addEventListener(`mouseup`,e),()=>window.removeEventListener(`mouseup`,e)},[]);let U=(0,c.useMemo)(()=>{if(!y)return[];let e=y.text.split(`
|
|
2
|
-
`);return e.length>0&&e[e.length-1]===``&&e.pop(),e.slice(0,p)},[y]),Pe=y?.lines??0,Fe=Pe>p,Ie=(e,t)=>{if(t){let t=I.current>0?I.current:e;S({start:Math.min(t,e),end:Math.max(t,e)})}else I.current=e,S({start:e,end:e})},Le=()=>{U.length!==0&&(I.current=1,S({start:1,end:U.length}))},Re=()=>{x&&(s(e.path,e.name,x.start,x.end),De(!0),R.current&&clearTimeout(R.current),R.current=setTimeout(()=>De(!1),1400))},W=y!==null&&y.kind===`text`&&!y.binary&&!y.truncated&&!g(e.name),ze=()=>{V.current=!1,H.current&&clearTimeout(H.current),z(!1),B(!1),E(y?.text??``),w(!1),M.current&&(h(e.name)&&O(!0),_(e.name)&&A(!0))},Be=()=>{if(C){if(T!==(y?.text??``)&&!window.confirm(v(`discardFileChanges`)))return;ze();return}W&&y&&(M.current=h(e.name)&&D||_(e.name)&&k,h(e.name)&&O(!1),_(e.name)&&A(!1),S(null),E(y.text),w(!0))},Ve=()=>{C&&y&&W&&ce({type:`write_file`,path:e.path,text:T})&&(V.current=!0,B(!1),z(!0),H.current&&clearTimeout(H.current),H.current=setTimeout(()=>{V.current=!1,z(!1),B(!0)},5e3))},G=()=>{(!C||T===(y?.text??``)||window.confirm(v(`discardFileChanges`)))&&u()},He=e=>{je(Math.min(200,Math.max(50,e)))},Ue=x?x.end-x.start+1:0,K=y?.binary??!1,We=y?.truncated??!1,q=y?.kind??`text`,Ge=h(e.name)||g(e.name),Ke=_(e.name),qe=g(e.name),J=Ge&&D&&!C&&q===`text`&&!K,Y=Ke&&k&&!C&&q===`text`&&!K,[X,Je]=(0,c.useState)(()=>{try{return localStorage.getItem(be)===`1`}catch{return!1}});(0,c.useEffect)(()=>{try{localStorage.setItem(be,X?`1`:`0`)}catch{}},[X]);let[Z,Ye]=(0,c.useState)([]),[Xe,Ze]=(0,c.useState)(``),Q=(0,c.useRef)(null);(0,c.useEffect)(()=>{let e=Q.current;if(!e||!J){Ye([]);return}let t=[...e.querySelectorAll(`h1, h2, h3, h4, h5, h6`)],n=ye(t.map(e=>({level:Number(e.tagName.slice(1)),label:e.textContent??``})));t.forEach((e,t)=>{e.id||=n[t].id}),Ye(n)},[J,y?.text,e.path]),(0,c.useEffect)(()=>{let e=Q.current;if(!e||!X||!d(Z))return;let t=Z.map(t=>e.querySelector(`#${CSS.escape(t.id)}`)).filter(e=>e!==null);if(t.length===0)return;let n=new IntersectionObserver(e=>{let t=e.filter(e=>e.isIntersecting).sort((e,t)=>e.boundingClientRect.top-t.boundingClientRect.top)[0];t?.target.id&&Ze(t.target.id)},{rootMargin:`0px 0px -70% 0px`});for(let e of t)n.observe(e);return()=>n.disconnect()},[Z,X]);let Qe={"host:fp-md":Ge&&q===`text`&&!K&&y?(0,f.jsx)(`button`,{type:`button`,className:`fp-attach markdown ${D?`on`:``}`,"data-tip":v(D?`showMarkdownSource`:`showMarkdownPreview`),disabled:C,onClick:()=>O(e=>!e),children:D?(0,f.jsx)(i,{}):(0,f.jsx)(a,{})}):null,"host:fp-toc":J&&d(Z)?(0,f.jsx)(`button`,{type:`button`,className:`fp-attach toc ${X?`on`:``}`,"data-tip":v(X?`previewTocHide`:`previewTocShow`),onClick:()=>Je(e=>!e),children:(0,f.jsx)(fe,{})}):null,"host:fp-html":Ke&&q===`text`&&!K&&y?(0,f.jsx)(`button`,{type:`button`,className:`fp-attach html ${k?`on`:``}`,"data-tip":v(k?`showHtmlSource`:`showHtmlPreview`),disabled:C,onClick:()=>A(e=>!e),children:k?(0,f.jsx)(a,{}):(0,f.jsx)(i,{})}):null,"host:fp-edit":q===`text`&&!K&&y?(0,f.jsx)(`button`,{type:`button`,className:`fp-attach edit ${C?`on`:``}`,"data-tip":v(We?`fileEditTruncated`:C?`exitEditFile`:`editFile`),disabled:!W&&!C,onClick:Be,children:(0,f.jsx)(re,{})}):null,"host:fp-wrap":q===`text`&&!K&&!J&&!Y?(0,f.jsx)(`button`,{type:`button`,className:`fp-attach wrap ${N?`on`:``}`,"data-tip":v(N?`disableWrap`:`enableWrap`),onClick:()=>ke(e=>!e),children:(0,f.jsx)(ne,{})}):null,"host:fp-zoom":q===`text`&&y?(0,f.jsxs)(`span`,{className:`fp-zoom`,children:[(0,f.jsx)(`button`,{type:`button`,className:`fp-attach zoom-out`,"data-tip":v(`zoomOut`),disabled:F<=50,onClick:()=>He(F-10),children:(0,f.jsx)(le,{})}),(0,f.jsxs)(`button`,{type:`button`,className:`fp-zoom-val`,title:v(`resetZoom`),onClick:()=>je(100),children:[F,`%`]}),(0,f.jsx)(`button`,{type:`button`,className:`fp-attach zoom-in`,"data-tip":v(`zoomIn`),disabled:F>=200,onClick:()=>He(F+10),children:(0,f.jsx)(oe,{})})]}):null,"host:fp-download":(0,f.jsx)(`button`,{type:`button`,className:`fp-attach download`,"data-tip":v(`downloadFile`),onClick:()=>void _e(e.path,e.name),children:(0,f.jsx)(n,{})}),"host:fp-ref":(0,f.jsx)(`button`,{type:`button`,className:`fp-attach ref`,"data-tip":v(`referenceTip`),onClick:()=>l(e.path,e.name,`reference`),children:(0,f.jsx)(ue,{})}),"host:fp-full":(0,f.jsx)(`button`,{type:`button`,className:`fp-attach full ${P?`on`:``}`,"data-tip":v(P?`exitFullscreen`:`fullscreen`),onClick:()=>Ae(e=>!e),children:P?(0,f.jsx)(t,{}):(0,f.jsx)(te,{})}),"host:fp-close":null},$e=m===void 0?[`host:fp-md`,`host:fp-toc`,`host:fp-html`,`host:fp-edit`,`host:fp-wrap`,`host:fp-zoom`,`host:fp-download`,`host:fp-ref`,`host:fp-full`].map(e=>({id:e,source:`host`})):m.filter(e=>!e.hidden&&e.id!==`host:fp-close`),$=e=>ee(de(`/api/file?clientId=${encodeURIComponent(me())}&path=${encodeURIComponent(e)}`)),et=e=>{let t=e.split(`/`).map(e=>encodeURIComponent(e)).join(`/`),n=/^[A-Za-z]:([\\/]|$)/.test(e)||e.startsWith(`/`)?`/api/preview/__abs__/${t}`:`/api/preview/${t}`;return ee(de(`${n}?clientId=${encodeURIComponent(me())}${j?`&allowJs=1`:``}`))};return(0,f.jsx)(`div`,{className:`fp-overlay ${P?`fullscreen`:``}`,onMouseDown:e=>{e.target===e.currentTarget&&G()},children:(0,f.jsxs)(`div`,{className:`fp ${P?`fullscreen`:``} ${qe?`is-ppt`:``}`,style:{"--fp-zoom":F/100},children:[(0,f.jsxs)(`div`,{className:`fp-head`,onDoubleClick:e=>{let t=e.target;t&&!t.closest(`button, a, input`)&&Ae(e=>!e)},children:[(0,f.jsx)(`span`,{className:`fp-name`,title:e.path,children:e.name}),(0,f.jsx)(`span`,{className:`fp-path`,children:e.path}),(0,f.jsxs)(`span`,{className:`fp-meta`,children:[y&&q===`text`&&!K&&v(`fileLines`,{n:Pe}),y&&` · ${ge(y.size)}`]}),(0,f.jsx)(`span`,{className:`fp-head-actions`,children:he($e,Qe,xe)}),(0,f.jsx)(`button`,{type:`button`,className:`fp-close`,title:v(`close`),"aria-label":v(`close`),onClick:G,children:(0,f.jsx)(se,{})})]}),We&&q===`text`&&!K&&(0,f.jsx)(`div`,{className:`fp-notice`,children:g(e.name)?v(`previewLinesTruncated`,{n:U.length}):v(`previewTruncated`)}),b&&!y&&(0,f.jsx)(`div`,{className:`fp-empty`,children:v(`loading`)}),!b&&q===`none`&&!K&&(0,f.jsx)(`div`,{className:`fp-empty`,children:v(`previewNotSupported`)}),!b&&q===`image`&&(0,f.jsx)(`div`,{className:`fp-media-wrap clickable`,onClick:G,title:v(`clickToCloseImage`),children:(0,f.jsx)(`img`,{className:`fp-media fp-media-clickable`,src:$(e.path),alt:e.name,onClick:G,title:v(`clickToCloseImage`)})}),!b&&q===`video`&&(0,f.jsx)(`div`,{className:`fp-media-wrap`,children:(0,f.jsx)(`video`,{className:`fp-media`,src:$(e.path),controls:!0,preload:`metadata`})}),!b&&q===`audio`&&(0,f.jsx)(`div`,{className:`fp-media-wrap fp-audio-wrap`,children:(0,f.jsxs)(`div`,{className:`fp-audio-card`,children:[(0,f.jsx)(`div`,{className:`fp-audio-icon`,"aria-hidden":`true`,children:`🎵`}),(0,f.jsxs)(`div`,{className:`fp-audio-info`,children:[(0,f.jsx)(`div`,{className:`fp-audio-name`,title:e.name,children:e.name}),y?.size?(0,f.jsx)(`div`,{className:`fp-audio-size`,children:ge(y.size)}):null]}),(0,f.jsx)(`audio`,{className:`fp-audio-element`,src:$(e.path),controls:!0,autoPlay:!0,preload:`metadata`})]})}),!b&&Y&&y&&(0,f.jsxs)(`div`,{className:`fp-html`,children:[(0,f.jsxs)(`div`,{className:`fp-html-bar`,children:[(0,f.jsx)(`span`,{className:`fp-html-hint`,title:v(j?`htmlJsOnTip`:`htmlJsOffTip`),children:v(j?`htmlJsOn`:`htmlJsOff`)}),(0,f.jsx)(`button`,{type:`button`,className:`fp-html-js ${j?`on`:``}`,"data-tip":v(j?`htmlDisableJs`:`htmlEnableJs`),onClick:()=>Oe(e=>!e),children:v(j?`htmlDisableJs`:`htmlEnableJs`)}),(0,f.jsxs)(`a`,{className:`fp-html-btn fp-html-external`,href:et(e.path),target:`_blank`,rel:`noopener noreferrer`,title:v(`openInNewTab`),children:[(0,f.jsx)(ie,{}),(0,f.jsx)(`span`,{children:v(`openInNewTab`)})]})]}),(0,f.jsx)(`iframe`,{className:`fp-html-frame`,src:et(e.path),title:e.name,sandbox:j?`allow-scripts`:``,referrerPolicy:`no-referrer`},j?`js`:`nojs`)]}),!b&&J&&y&&(0,f.jsx)(`div`,{className:g(e.name)?`fp-markdown msg-text fp-office`:`fp-markdown msg-text`,children:(0,f.jsxs)(`div`,{className:X&&d(Z)?`fp-toc-layout`:void 0,children:[X&&d(Z)&&(0,f.jsx)(`nav`,{className:`fp-toc`,"aria-label":v(`previewTocLabel`),children:Z.map(e=>(0,f.jsx)(`a`,{className:`l${Math.min(e.level,6)}${e.id===Xe?` on`:``}`,href:`#${e.id}`,title:e.label,onClick:t=>{t.preventDefault(),Q.current?.querySelector(`#${CSS.escape(e.id)}`)?.scrollIntoView({behavior:`smooth`,block:`start`})},children:e.label},e.id))}),(0,f.jsx)(`div`,{className:`fp-markdown-zoom`,ref:Q,children:(0,f.jsx)(ve,{text:y.text})})]})}),!b&&K&&q!==`image`&&q!==`video`&&y&&(0,f.jsxs)(`div`,{className:`fp-hex-wrap`,children:[(0,f.jsxs)(`div`,{className:`fp-notice`,children:[v(`binaryFile`),y.truncated&&v(`binaryHexTruncated`)]}),(0,f.jsx)(`pre`,{className:`fp-hex`,children:y.text})]}),!b&&C&&q===`text`&&!K&&y&&(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`textarea`,{className:`fp-editor ${N?``:`no-wrap`}`,value:T,onChange:e=>E(e.target.value),wrap:N?`soft`:`off`,spellCheck:!1,autoFocus:!0}),Ne&&(0,f.jsx)(`div`,{className:`fp-notice`,role:`alert`,children:v(`saveResultUnknown`)})]}),!b&&!J&&!Y&&!C&&q===`text`&&!K&&y&&U.length===0&&(0,f.jsx)(`div`,{className:`fp-empty`,children:v(`emptyFile`)}),!b&&!J&&!Y&&!C&&q===`text`&&!K&&U.length>0&&(0,f.jsxs)(`div`,{className:`fp-code ${we?`dragging`:``} ${N?``:`no-wrap`}`,onMouseDown:e=>{e.button===0&&e.preventDefault()},children:[U.map((e,t)=>{let n=t+1,r=x!==null&&n>=x.start&&n<=x.end;return(0,f.jsxs)(`div`,{className:`fp-line ${r?`sel`:``}`,onMouseDown:e=>{e.button===0&&(Ie(n,e.shiftKey),L.current=!0,Te(!0))},onMouseEnter:()=>{L.current&&Ie(n,!0)},children:[(0,f.jsx)(`span`,{className:`fp-num`,children:n}),(0,f.jsx)(`span`,{className:`fp-code-text`,children:e})]},n)}),Fe&&(0,f.jsx)(`div`,{className:`fp-lines-note`,children:v(`previewLinesTruncated`,{n:p})})]}),(C||!J&&!Y&&q===`text`)&&(0,f.jsx)(`div`,{className:`fp-foot`,children:C?(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`span`,{className:`fp-hint`,children:v(`editFile`)}),(0,f.jsxs)(`div`,{className:`fp-actions`,children:[(0,f.jsx)(`button`,{type:`button`,className:`btn`,onClick:Be,children:v(`cancel`)}),(0,f.jsxs)(`button`,{type:`button`,className:`btn primary`,disabled:Me||T===(y?.text??``),onClick:Ve,children:[(0,f.jsx)(pe,{}),` `,v(`saveFile`)]})]})]}):(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`span`,{className:`fp-hint`,children:x?v(`selectedRange`,{n:Ue,start:x.start,end:x.end}):v(`selectLinesHint`)}),(0,f.jsxs)(`div`,{className:`fp-actions`,children:[(0,f.jsx)(`button`,{type:`button`,className:`btn`,disabled:U.length===0,onClick:Le,children:v(`selectAll`)}),(0,f.jsx)(`button`,{type:`button`,className:`btn`,disabled:!x,onClick:()=>S(null),children:v(`clearSelection`)}),(0,f.jsxs)(`button`,{type:`button`,className:`btn primary`,disabled:!x||K,onClick:Re,children:[Ee?(0,f.jsx)(r,{}):null,v(Ee?`addedToChat`:`addToChat`)]})]})]})})]})})}function h(e){let t=e.toLowerCase();return t.endsWith(`.md`)||t.endsWith(`.markdown`)}function g(e){let t=e.toLowerCase();return t.endsWith(`.docx`)||t.endsWith(`.xlsx`)||t.endsWith(`.xlsm`)||t.endsWith(`.pptx`)||t.endsWith(`.pptm`)||t.endsWith(`.ppsx`)||t.endsWith(`.potx`)}function _(e){let t=e.toLowerCase();return t.endsWith(`.html`)||t.endsWith(`.htm`)||t.endsWith(`.xhtml`)}export{m as FilePreview};
|