keel-agent 0.124.0 → 0.125.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/dist/packages/keel/src/adapters/sdk/prompt-render.js +5 -2
- package/dist/packages/keel/src/app/core-engine.js +16 -0
- package/dist/packages/keel/src/app/engine-dismiss.js +44 -0
- package/dist/packages/keel/src/app/session-registry.js +7 -1
- package/dist/packages/keel/src/app/subagent-runtime.js +8 -1
- package/dist/packages/keel/src/tool-catalog.js +5 -5
- package/dist/server/core-settings-adapter.js +48 -13
- package/dist/server/device-center/bot-chat.js +25 -0
- package/dist/server/device-center/bot-home.js +6 -0
- package/dist/server/device-center/bot-prompt.js +110 -0
- package/dist/server/device-center/bots.js +12 -0
- package/dist/server/device-center/execution-system-prompt.js +28 -13
- package/dist/server/device-center/local.js +126 -2
- package/dist/server/index.js +1 -0
- package/dist/server/universal/universal-session.js +8 -1
- package/package.json +1 -1
- package/web/dist/.build-assets.json +1 -1
- package/web/dist/assets/{BgTasksModal-D9NVLipp.js → BgTasksModal-B58Pn34o.js} +1 -1
- package/web/dist/assets/{BgTasksModal-CeowQkSk.js → BgTasksModal-DlRMULTX.js} +1 -1
- package/web/dist/assets/{BottomDock-DnXJHyg7.js → BottomDock-ix2rdS6N.js} +1 -1
- package/web/dist/assets/{CanvasStudio-D_RAeDdS.js → CanvasStudio-BRCkVMbW.js} +1 -1
- package/web/dist/assets/{CanvasStudio-BRWqZIVu.js → CanvasStudio-Cjxb3q3B.js} +1 -1
- package/web/dist/assets/{DeviceCenter-USAoAkin.js → DeviceCenter-BWMmB-CF.js} +1 -1
- package/web/dist/assets/{DeviceCenter-d49w4XXm.js → DeviceCenter-DfLlGGBZ.js} +1 -1
- package/web/dist/assets/{DeviceExecutionSettings-2hoZaBQ0.js → DeviceExecutionSettings-BjduyZOy.js} +1 -1
- package/web/dist/assets/DeviceGroupSection-B98LzFoj.js +7 -0
- package/web/dist/assets/DeviceGroupSection-BD3CKMFH.js +7 -0
- package/web/dist/assets/{DeviceGroups-BPE61M6w.js → DeviceGroups-C_lcfK5h.js} +1 -1
- package/web/dist/assets/DeviceGroups-ob27f-Ha.js +1 -0
- package/web/dist/assets/{Dropdown-DAiTWOzs.js → Dropdown-C8yx9mqF.js} +1 -1
- package/web/dist/assets/{FilePreview-CtSZWiJB.js → FilePreview-OxK_pI6p.js} +1 -1
- package/web/dist/assets/{FilePreview-xePo9QMY.js → FilePreview-inPVGc1j.js} +1 -1
- package/web/dist/assets/{GlobalSearchModal-CQhENYtf.js → GlobalSearchModal-3g1PplIg.js} +1 -1
- package/web/dist/assets/GlobalSearchModal-DG-HC0vV.js +1 -0
- package/web/dist/assets/{GroupConversation-DXDC1d3x.js → GroupConversation-BJnwTtT2.js} +2 -2
- package/web/dist/assets/{GroupConversation-CFv2RYwI.js → GroupConversation-Clt5o_lo.js} +1 -1
- package/web/dist/assets/{GroupWorkItems-BeZvaxV9.js → GroupWorkItems-7yTbAr_f.js} +1 -1
- package/web/dist/assets/{ModelConfigModal-drDDlawe.js → ModelConfigModal-CNnEGfep.js} +1 -1
- package/web/dist/assets/{ModelConfigModal-BI6ekcG4.js → ModelConfigModal-CYqDNXap.js} +1 -1
- package/web/dist/assets/{NativeCliPanel-B029dN9l.js → NativeCliPanel-B407C4qC.js} +1 -1
- package/web/dist/assets/{NativeCliPanel-BsehkHXc.js → NativeCliPanel-CVbFXUSf.js} +1 -1
- package/web/dist/assets/{PiSetupModal-D46ea4Wb.js → PiSetupModal-CrjDf0j6.js} +1 -1
- package/web/dist/assets/{ProviderOAuthControls-t8myaqZa.js → ProviderOAuthControls-Crhc6icP.js} +1 -1
- package/web/dist/assets/{SCMPanel-DUrKyvGV.js → SCMPanel-DuRJx0nl.js} +1 -1
- package/web/dist/assets/{SCMPanel-BKgGm9au.js → SCMPanel-rUAKnxBo.js} +1 -1
- package/web/dist/assets/SettingsModal-B3Q5EoVC.js +29 -0
- package/web/dist/assets/{SettingsModal-Bn0GTNgo.js → SettingsModal-CnJsUyvi.js} +1 -1
- package/web/dist/assets/{TermXterm-2oOzNy1G.js → TermXterm-BDLmWqim.js} +1 -1
- package/web/dist/assets/{TermXterm-D_VbvSyY.js → TermXterm-DhbhRp0B.js} +1 -1
- package/web/dist/assets/{TerminalPanel-CJ4ykxfy.js → TerminalPanel-D6oMxabb.js} +1 -1
- package/web/dist/assets/{TerminalPanel-mTL87sXL.js → TerminalPanel-Ds_hnvxz.js} +1 -1
- package/web/dist/assets/{ThemeMarketModal-B55xZq9j.js → ThemeMarketModal-5lH7k1in.js} +1 -1
- package/web/dist/assets/{ThemeMarketModal-EahvoJAf.js → ThemeMarketModal-WSOd5c6j.js} +1 -1
- package/web/dist/assets/{TuiOverlayModal-B2B5yRVf.js → TuiOverlayModal-Dh_HsAvo.js} +1 -1
- package/web/dist/assets/{TuiOverlayModal-C1uwsm1r.js → TuiOverlayModal-dKDCTdt8.js} +1 -1
- package/web/dist/assets/{api-client-CGqoOWHJ.js → api-client-BbDlV0jR.js} +1 -1
- package/web/dist/assets/{canvas-client-LIotRrYf.js → canvas-client-OwhfLxJx.js} +1 -1
- package/web/dist/assets/{desktop-BHN7gNP2.js → desktop-D1lGoY5p.js} +1 -1
- package/web/dist/assets/{fi-DjvtEEnZ.js → fi-CcqqfamG.js} +6 -6
- package/web/dist/assets/index-BQb8EOhk.js +410 -0
- package/web/dist/assets/index-Dbv9RJwm.js +410 -0
- package/web/dist/assets/index-xAdOV6os.css +1 -0
- package/web/dist/assets/{plugin-host-VdvQxFkv.js → plugin-host-DjGRLyyK.js} +1 -1
- package/web/dist/assets/{theme-DGfXszyo.js → theme-Dl8KLbt-.js} +1 -1
- package/web/dist/assets/use-copy-feedback-B3di-fnu.js +1 -0
- package/web/dist/index.html +11 -10
- package/web/dist/sw.js +1 -1
- package/web/dist/assets/DeviceGroupSection-CRdMGDwE.js +0 -7
- package/web/dist/assets/GlobalSearchModal-DpHvykpb.js +0 -1
- package/web/dist/assets/SettingsModal-ComFBXCj.js +0 -29
- package/web/dist/assets/index-4-PoF3xB.css +0 -1
- package/web/dist/assets/index-CXTnvcJF.js +0 -409
- package/web/dist/assets/index-Y0yKgBrc.js +0 -409
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$ as t,$t as n,A as r,B as i,Bt as a,C as o,E as s,En as c,Et as l,Fn as u,Ft as d,G as f,H as p,Ht as m,I as h,J as g,L as _,Lt as v,N as y,O as b,P as x,Pt as S,Q as C,R as w,Rn as T,Rt as E,V as D,Vt as O,W as k,X as A,Yt as j,Z as M,Zt as N,_ as P,a as F,an as I,at as L,b as R,cn as ee,ct as z,d as te,dn as B,en as V,et as ne,ft as re,i as ie,it as ae,k as oe,kn as H,ln as se,m as ce,mt as le,nn as ue,nt as de,on as fe,ot as pe,pt as me,q as he,rt as ge,sn as _e,t as ve,tt as ye,u as be,ut as xe,vn as U,vt as Se,wt as Ce,xt as we,yt as Te,z as Ee,zt as De}from"./fi-CcqqfamG.js";import{i as Oe,r as ke,t as Ae}from"./react-CR5VJ85Q.js";import{t as je}from"./shortcut-stack-hhrDyRBn.js";import{a as Me,n as Ne,t as Pe}from"./api-client-BbDlV0jR.js";import{t as Fe}from"./uuid-BzDIGCwP.js";import{n as Ie}from"./Dropdown-C8yx9mqF.js";import{i as Le,o as Re,t as W}from"./app-globals-wu8LLlnA.js";import{d as ze}from"./context-menu-state-CEfR7_Lz.js";import{n as Be}from"./use-copy-feedback-B3di-fnu.js";function Ve(e,t,n=`Device`){let r=e=>typeof e==`string`?e.trim().slice(0,256):``,i=r(e),a=r(t);return a&&i&&a!==i?`${a} · ${i}`:a||i||n}function G(e){if(e.transport===`p2p`)return e.relayed===!0?`turn`:e.route===`peer`?`peer`:`p2p`;if(e.transport===`lan`||e.transport===`hub`)return e.transport}function He(e,t){switch(e){case`lan`:return t(`desktop.lan`);case`p2p`:return t(`desktop.p2p`);case`turn`:return`TURN`;case`peer`:return t(`connected`);case`hub`:return t(`desktop.hub`);case`current`:return t(`desktop.currentConnection`);default:return t(`desktop.connecting`)}}function K(){return c().match(/\/(?:device|device-lan)\/([a-z0-9][a-z0-9-]{0,62})\/__relay\/[a-f0-9]{64}\/$/)?.[1]}async function Ue(e,t,n){let r=K();if(!r)return;let i=J;if(q)return;let a=await fetch(u(H(`/api/device-center/chat-status`)),{credentials:`same-origin`,signal:n?AbortSignal.any([n,AbortSignal.timeout(15e3)]):AbortSignal.timeout(15e3)});if(!a.ok)throw Error(`Device status unavailable`);let o=await a.json();n?.aborted||J!==i||q||await X(r,typeof o.hubUrl==`string`?o.hubUrl:``,!0,e,!1,Ve(o.name,o.remark,t))}function We(e){return e.local===!0&&!K()}var q=null,J=0,Ge=new Set,Ke=()=>Ge.forEach(e=>e()),qe=e=>(Ge.add(e),()=>{Ge.delete(e)}),Je=()=>q;function Ye(e){q?.revision===e.revision&&(q=null,Ke())}function Y(e,t){q?.revision===e.revision&&(q={...q,mode:t},Ke(),t===`preview`&&window.dispatchEvent(new Event(`pi:desktop-open`)))}async function Xe(e,t,n,r,i=!1,a,o=!1){if(n&&(o||e===K()))return{url:new URL(u(H(i?`/desktop-preview`:`/desktop`)),window.location.href).href,transport:`current`,fallbackOrigin:void 0};if(n&&K()){let t=new URL(H(`/__desktop_target`),window.location.href);return t.searchParams.set(`device`,e),t.searchParams.set(`preview`,i?`1`:`0`),{url:t.href,transport:`hub`,fallbackOrigin:void 0}}let s=await fetch(u(H(`/api/device-center/devices/${encodeURIComponent(e)}/open`)),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({preferLan:!0,desktop:n,basePath:new URL(H(`/`),window.location.href).pathname}),credentials:`same-origin`,signal:a?AbortSignal.any([a,AbortSignal.timeout(3e4)]):AbortSignal.timeout(3e4)});if(!s.ok)throw Error(r(`deviceAccessOpenFailed`));let c=await s.json(),l=c.transport===`lan`||c.transport===`p2p`,d=l?new URL(H(c.url),window.location.href):new URL(c.url),f=new URL(t),p=new URL(H(`/device-lan/${e}/__open`),window.location.href),m=l?typeof c.url==`string`&&/^\/device-lan\/[a-z0-9][a-z0-9-]{0,62}\/__open\?ticket=[a-f0-9]{64}$/.test(c.url)&&d.origin===p.origin&&d.pathname===p.pathname:d.hostname===f.hostname&&(d.pathname===`/__device/open`||d.origin===f.origin&&d.pathname===`/device/${encodeURIComponent(e)}/__open`);if(![`http:`,`https:`].includes(d.protocol)||d.username||d.password||!m)throw Error(`Invalid device access URL`);return d.searchParams.delete(`next`),n&&d.searchParams.set(`next`,i?`/desktop-preview`:`/desktop`),{url:d.href,transport:G(c)??`hub`,fallbackOrigin:c.fallbackOrigin}}async function X(e,t,n,r,i=!1,a,o){let s=T();if(s){if(!s.deviceAdapter)throw Error(`Native device access is unavailable`);await s.deviceAdapter.openDevice(e,t);return}if(n&&!i){q={id:e,hubUrl:t,name:a,revision:++J,...o,mode:o?.mode??`preview`},Ke(),window.dispatchEvent(new Event(`pi:desktop-open`));return}if(n&&i&&K()&&window.parent!==window){await Ze(r,e);return}let c=window.piDesktop,l=c?.openHub?null:window.open(`about:blank`,`_blank`);if(!c?.openHub&&!l)throw Error(r(`deviceAccessPopupBlocked`));if(l){try{l.document.open(),l.document.write(`<!doctype html><meta charset="utf-8"><title>${r(`deviceAccessOpening`)}</title><style>html,body{height:100%;margin:0}body{display:grid;place-items:center;background:#0d0e12;color:#9aa1b4;font:14px/1.6 -apple-system,"PingFang SC","Microsoft YaHei",sans-serif}</style><body>${r(`deviceAccessOpening`)}</body>`),l.document.close()}catch{}l.opener=null}try{let i=await Xe(e,t,n,r,!1,void 0,o?.local),a=new URL(i.url);if(c?.openHub){if(i.transport!==`hub`&&(a.searchParams.set(`hub`,new URL(t).origin),typeof i.fallbackOrigin==`string`&&a.searchParams.set(`portal`,i.fallbackOrigin)),!await c.openHub(a.href))throw Error(r(`deviceAccessWindowFailed`))}else l&&l.location.replace(a.href)}catch(e){throw l?.close(),e}}function Ze(e,t){let n=Fe(),r=new URL(H(`/`),window.location.href).origin;return new Promise((i,a)=>{let o=e=>{clearTimeout(l),window.removeEventListener(`message`,c),e?a(Error(e)):i()},s=e(`deviceAccessTabFailed`),c=t=>{t.source===window.parent&&t.origin===r&&t.data?.type===`device-desktop-open-result`&&t.data.requestId===n&&o(t.data.ok===!0?void 0:t.data.error===`popup`?e(`deviceAccessPopupBlocked`):s)},l=setTimeout(()=>o(s),3e4);window.addEventListener(`message`,c),window.parent.postMessage({type:`device-desktop-open`,requestId:n,deviceId:t},r)})}function Qe(e){return B({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`rect`,attr:{width:`8`,height:`8`,x:`3`,y:`3`,rx:`2`},child:[]},{tag:`path`,attr:{d:`M7 11v4a2 2 0 0 0 2 2h4`},child:[]},{tag:`rect`,attr:{width:`8`,height:`8`,x:`13`,y:`13`,rx:`2`},child:[]}]})(e)}function $e(e){return B({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M18 8V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v7a2 2 0 0 0 2 2h8`},child:[]},{tag:`path`,attr:{d:`M10 19v-3.96 3.15`},child:[]},{tag:`path`,attr:{d:`M7 19h5`},child:[]},{tag:`rect`,attr:{width:`6`,height:`10`,x:`16`,y:`12`,rx:`2`},child:[]}]})(e)}function et(e){return B({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M14 9a2 2 0 0 1-2 2H6l-4 4V4a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2z`},child:[]},{tag:`path`,attr:{d:`M18 9h2a2 2 0 0 1 2 2v11l-4-4h-6a2 2 0 0 1-2-2v-1`},child:[]}]})(e)}function tt(e){return B({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M10 17H7l-4 4v-7`},child:[]},{tag:`path`,attr:{d:`M14 17h1`},child:[]},{tag:`path`,attr:{d:`M14 3h1`},child:[]},{tag:`path`,attr:{d:`M19 3a2 2 0 0 1 2 2`},child:[]},{tag:`path`,attr:{d:`M21 14v1a2 2 0 0 1-2 2`},child:[]},{tag:`path`,attr:{d:`M21 9v1`},child:[]},{tag:`path`,attr:{d:`M3 9v1`},child:[]},{tag:`path`,attr:{d:`M5 3a2 2 0 0 0-2 2`},child:[]},{tag:`path`,attr:{d:`M9 3h1`},child:[]}]})(e)}function nt(e){return B({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`m5 8 6 6`},child:[]},{tag:`path`,attr:{d:`m4 14 6-6 2-3`},child:[]},{tag:`path`,attr:{d:`M2 5h12`},child:[]},{tag:`path`,attr:{d:`M7 2h1`},child:[]},{tag:`path`,attr:{d:`m22 22-5-10-5 10`},child:[]},{tag:`path`,attr:{d:`M14 18h6`},child:[]}]})(e)}function rt(e){return B({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M20 17a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-3.9a2 2 0 0 1-1.69-.9l-.81-1.2a2 2 0 0 0-1.67-.9H8a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2Z`},child:[]},{tag:`path`,attr:{d:`M2 8v11a2 2 0 0 0 2 2h14`},child:[]}]})(e)}function it(e){return B({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M20 10a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1h-2.5a1 1 0 0 1-.8-.4l-.9-1.2A1 1 0 0 0 15 3h-2a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z`},child:[]},{tag:`path`,attr:{d:`M20 21a1 1 0 0 0 1-1v-3a1 1 0 0 0-1-1h-2.9a1 1 0 0 1-.88-.55l-.42-.85a1 1 0 0 0-.92-.6H13a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z`},child:[]},{tag:`path`,attr:{d:`M3 5a2 2 0 0 0 2 2h3`},child:[]},{tag:`path`,attr:{d:`M3 3v13a2 2 0 0 0 2 2h3`},child:[]}]})(e)}function at(e){return B({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M10 2v7.527a2 2 0 0 1-.211.896L4.72 20.55a1 1 0 0 0 .9 1.45h12.76a1 1 0 0 0 .9-1.45l-5.069-10.127A2 2 0 0 1 14 9.527V2`},child:[]},{tag:`path`,attr:{d:`M8.5 2h7`},child:[]},{tag:`path`,attr:{d:`M7 16h10`},child:[]}]})(e)}function ot(e){return B({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`m16.24 7.76-1.804 5.411a2 2 0 0 1-1.265 1.265L7.76 16.24l1.804-5.411a2 2 0 0 1 1.265-1.265z`},child:[]},{tag:`circle`,attr:{cx:`12`,cy:`12`,r:`10`},child:[]}]})(e)}var Z=Ae(),st=new Set([`svg`,`g`,`path`,`circle`,`rect`,`line`,`polyline`,`polygon`,`ellipse`,`use`,`defs`,`clipPath`,`linearGradient`,`radialGradient`,`stop`]),ct=new Set(`viewBox.xmlns.d.fill.stroke.stroke-width.stroke-linecap.stroke-linejoin.stroke-dasharray.opacity.x.y.x1.y1.x2.y2.cx.cy.r.rx.ry.width.height.points.offset.stop-color.stop-opacity.fill-opacity.stroke-opacity.stroke-miterlimit.fill-rule.clip-rule.vector-effect.preserveAspectRatio.transform.clip-path.id.href.xlink:href.xmlns:xlink.gradientUnits.gradientTransform`.split(`.`)),lt=new Set([`script`,`style`,`title`,`desc`,`foreignobject`]),ut=new Set([...st].map(e=>e.toLowerCase())),dt=new Set([...ct].map(e=>e.toLowerCase()));function ft(e){return ut.has(e.toLowerCase())}function pt(e){return dt.has(e.toLowerCase())}function mt(e){if(typeof e!=`string`)return null;let t=e.trim();if(!t||t.length>8192||!/^<svg[\s>]/.test(t.startsWith(`<?xml`)?t.slice(t.indexOf(`?>`)+2).trimStart():t))return null;if(typeof DOMParser>`u`)return/<script[\s>]/i.test(t)||/\son\w+\s*=/i.test(t)||/javascript\s*:/i.test(t)?null:t;let n=new DOMParser().parseFromString(t,`image/svg+xml`);if(n.querySelector(`parsererror`))return null;let r=n.documentElement;if(r.tagName.toLowerCase()!==`svg`)return null;let i=e=>{for(let t of Array.from(e.children)){let e=t.tagName.toLowerCase();if(!ft(e)){lt.has(e)?t.remove():(i(t),t.replaceWith(...t.childNodes));continue}for(let e of Array.from(t.attributes)){let n=e.name.toLowerCase();(!pt(n)||/^on/i.test(n)||/^(javascript|data|vbscript):/i.test(e.value.trim()))&&t.removeAttribute(e.name)}i(t)}};for(let e of Array.from(r.attributes)){let t=e.name.toLowerCase();(!pt(t)||/^on/i.test(t))&&r.removeAttribute(e.name)}return i(r),new XMLSerializer().serializeToString(r)}function ht({icon:e,iconSvg:t,className:n}){let r=mt(t);return r?(0,Z.jsx)(`span`,{className:n??`plugin-icon-svg`,"aria-hidden":!0,dangerouslySetInnerHTML:{__html:r}}):e?(0,Z.jsx)(`span`,{className:n?`${n} plugin-icon-glyph`:`plugin-icon-glyph`,"aria-hidden":!0,children:e}):null}function gt(e,t){e&&W({type:`open_bot_chat`,botId:e,...t?.fresh?{fresh:!0}:{}})}function _t(){window.dispatchEvent(new CustomEvent(`pi-web-ui:device-group-open`,{detail:{}}))}function vt(e,t,n,r){return e.flatMap(e=>[{providerId:`host:group-devices`,providerLabel:r(`newChat`),title:e.name,hint:e.id,text:`@${e.name} · ${r(`newChat`)}`},...t.filter(t=>t.botId===e.id&&t.status!==`closed`&&!t.stale).map(t=>({providerId:`host:group-conversations`,providerLabel:r(`deviceGroupMentionContinue`),title:`${e.name} · ${t.name||r(`groupDeliveriesUntitledConversation`)}`,hint:t.id,text:`@${e.name} · ${r(`deviceGroupMentionContinuePrefix`)}${t.name||r(`groupDeliveriesUntitledConversation`)}`}))].filter(t=>`${t.title} ${t.providerLabel} ${e.id}`.toLocaleLowerCase().includes(n.toLocaleLowerCase())))}function yt(e){return`@${e.name}(${e.id})`}function bt(e){return e.replace(/@([^\s()]+)\([a-f0-9-]{8,}\)/g,`@$1`)}function xt(e,t){let n=bt(e),r=n.match(/^@([^\s()]+)\s*(.*)$/);return r?{botPrefix:`@${r[1]}`,summary:r[2].trim()||n}:{botPrefix:t?`@${t}`:``,summary:n}}function St(e,t){if(!e.includes(`Device task failed`))return bt(e);let n=e.match(/Device task failed\s*\[phase=([^;]+);\s*category=([^\]]+)\]\.\s*(.*)/s);if(!n)return bt(e);let[,r,i,a]=n,o={model:t(`deviceGroupFailurePhaseModel`),tool:t(`deviceGroupFailurePhaseTool`),approval:t(`deviceGroupFailurePhaseApproval`),connection:t(`deviceGroupFailurePhaseConnection`),handshake:t(`deviceGroupFailurePhaseHandshake`),init:t(`deviceGroupFailurePhaseInit`),switch_session:t(`deviceGroupFailurePhaseSwitchSession`),new_chat:t(`deviceGroupFailurePhaseNewChat`)}[r]||r,s=a.trim();return[t(`deviceGroupFailureTitle`,{phase:o}),`>`,t(`deviceGroupFailureMeta`,{phase:r,category:i}),`>`,`> ${s||t(`deviceGroupFailureDetailFallback`)}`].join(`
|
|
2
|
+
`)}function Ct(e,t){return[...new Set(t.filter(t=>e.includes(yt(t))).map(e=>e.id))]}function wt(e,t,n,r){let i=new Map,a=[],o=new Map(n.map(e=>[e.id,e]));for(let e of t?.bots??[])o.set(e.id,{...o.get(e.id),...e});let s={queued:r(`groupWorkItemsStatusQueued`),waiting:r(`deviceGroupStatusWaitingDependency`),running:r(`tabRunning`),completed:r(`groupWorkItemsStatusCompleted`),failed:r(`groupWorkItemsStatusFailed`),interrupted:r(`groupWorkItemsStatusInterrupted`)},c=new Map((t?.tasks??[]).map(e=>[e.id,e])),l=new Set,u=(e,t,n)=>{let r=e?o.get(e):void 0,i=r?.deviceName||n||r?.deviceId;return i?`${t} · ${i}`:t};for(let e of t?.messages??[]){let n=`group-message:${e.id}`,d=e.sender.type===`bot`,f=e.text,p=d?St(f,r):bt(f);if(e.sharedFrom){let t=o.get(e.sharedFrom.botId)?.name??e.sharedFrom.botId;p=`${e.sharedFrom.mode===`as_bot`?r(`deviceGroupSharedFromBot`,{bot:t}):r(`deviceGroupSharedFromForward`,{bot:t})}\n\n${p}`}let m=e.replyToMessageId?t?.messages.find(t=>t.id===e.replyToMessageId):void 0;if(m){let e=bt(m.text).replace(/\s+/g,` `).slice(0,120);p=`> ↩ ${m.sender.name}: ${e}\n\n${p}`}if(a.push({id:n,role:d?`assistant`:`user`,timestamp:e.createdAt,content:[{type:`text`,text:p}]}),!d){let t=e.sender.type===`webhook`?` [Webhook]`:``;i.set(n,`${e.sender.name}${t}`);continue}let h=(e.taskIds??[]).map(e=>c.get(e)).filter(t=>!!t&&t.botId===e.sender.id);for(let e of h)e.report&&l.add(e.id);let g=[...new Set(h.map(e=>s[e.status]))].join(` · `),_=t?.room.primaryBotId&&e.sender.id===t.room.primaryBotId?` [${r(`deviceGroupCoordinatorTag`)}]`:``,v=`${u(e.sender.id,e.sender.name,e.sender.sourceDeviceId)}${_}`;i.set(n,g?`${v} · ${g}`:v)}for(let e of t?.tasks??[]){if(l.has(e.id)||e.kind===`result`)continue;let t=`group-task:${e.id}`,n=o.get(e.botId),d=!!(e.parentTaskId||e.sourceBotId&&e.sourceBotId!==e.botId),f=r(`deviceGroupWorkerSubagent`),p=u(e.botId,n?.name??e.botId,e.deviceId),m=e.status===`waiting`?e.dependsOnTaskId?r(`groupConversationWaitingUpstream`):r(`deviceGroupStatusWaitingDependency`):s[e.status]??e.status;i.set(t,d?`${p} [${f}] · ${m}`:`${p} · ${m}`);let h=e.report,g=bt(e.text),_;if(h){if(d){let t=r(`deviceGroupSubagentSummary`);_=[r(`deviceGroupSubagentCompleted`,{bot:n?.name??e.botId}),r(`deviceGroupInstructionLine`,{label:r(`deviceGroupInstructionAssigned`),text:g}),``,`<details>`,`<summary>${t}</summary>`,``,St(h,r),``,`</details>`].join(`
|
|
3
|
+
`)}else _=St(h,r)}else if(e.status===`running`){let t=r(d?`deviceGroupSubagentRunning`:`deviceGroupTaskRunning`),i=e.progress?.phase,a=e.progress?.toolName,o=e.progress?.text?.trim();_=[`⏳ **${t}**${d?` · \`@${n?.name??e.botId}\``:``}`,r(`deviceGroupInstructionLine`,{label:r(d?`deviceGroupInstructionAssigned`:`deviceGroupInstructionGoal`),text:g}),...i?[r(`deviceGroupProgressPhaseLine`,{phase:i,tool:a?` · \`${a}\``:``})]:[],...o?[``,`> ${o}`]:[]].join(`
|
|
4
|
+
`)}else if(e.status===`waiting`){let t=e.dependsOnTaskId?c.get(e.dependsOnTaskId):void 0,i=t?o.get(t.botId)?.name??t.botId:void 0,a=t?xt(t.text,i).summary:e.dependsOnTaskId;_=[`${r(`deviceGroupWaitingUpstreamTitle`)}${d?` · \`@${n?.name??e.botId}\``:``}`,r(`deviceGroupInstructionLine`,{label:r(d?`deviceGroupInstructionAssigned`:`deviceGroupInstructionGoal`),text:g}),...e.dependsOnTaskId?[r(`deviceGroupDependsOnLine`,{dep:`${i?`@${i} · `:``}${a||e.dependsOnTaskId}`})]:[]].join(`
|
|
5
|
+
`)}else _=e.status===`queued`?[`⏱️ **${r(d?`deviceGroupSubagentQueued`:`deviceGroupTaskQueued`)}**${d?` · \`@${n?.name??e.botId}\``:``}`,r(`deviceGroupInstructionLine`,{label:r(d?`deviceGroupInstructionAssigned`:`deviceGroupInstructionGoal`),text:g})].join(`
|
|
6
|
+
`):e.status===`failed`&&d?[r(`deviceGroupSubagentFailed`,{bot:n?.name??e.botId}),r(`deviceGroupInstructionLine`,{label:r(`deviceGroupInstructionAssigned`),text:g}),...h?[``,St(h,r)]:[]].join(`
|
|
7
|
+
`):`${s[e.status]||e.status}\n\n${g}`;a.push({id:t,role:`assistant`,timestamp:e.createdAt,content:[{type:`text`,text:_}]})}return a.sort((e,t)=>(e.timestamp??0)-(t.timestamp??0)),{state:{clientId:`device-group`,cwd:``,sessionId:`device-group:${e}`,conversationId:`device-group:${e}`,rev:0,messages:a,streamingMessage:null,isStreaming:!1,model:null,thinkingLevel:``,availableThinkingLevels:[],queue:{steering:[],followUp:[]},tools:[],version:0,piConfigured:!0,piAgentInstalled:!0,stats:{totalMessages:a.length,tokens:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0},cost:0,contextUsage:{tokens:null,contextWindow:0,percent:null}}},labels:i}}function Tt(e,t,n,r,i){let a=JSON.stringify({roomId:t,text:n,targetBotIds:[...r].sort()});return e?.fingerprint===a?e:{fingerprint:a,key:i()}}function Et(e){let t=e.filter(e=>e.conversationId);if(!t.length)return;let n=t[0].conversationId;if(e.some(e=>e.conversationId!==n))throw Error(`同一条消息只能继续一个对话,请移除其他 @ 目标。 / Continue one conversation per message. Remove other @ targets.`);return n}function Dt(e,t,n){let r=0;for(;r<e.length&&r<t.length&&e[r]===t[r];)r++;let i=e.length,a=t.length;for(;i>r&&a>r&&e[i-1]===t[a-1];)i--,a--;return n.flatMap(e=>{if(e.end<=r)return[e];if(e.start>=i){let t=a-i;return[{...e,start:e.start+t,end:e.end+t}]}return[]})}function Ot(e,t){let n=e;for(let e of[...t].sort((e,t)=>t.start-e.start))n=n.slice(0,e.start)+yt(e.member)+n.slice(e.end);return{text:n,targets:[...new Set(t.map(e=>e.member.id))]}}function kt(e,t,n,r,i){let a=i.filter(i=>t===n?r===`Backspace`?t>i.start&&t<=i.end+ +(e[i.end]===` `):t>=i.start&&t<i.end:t<i.end&&n>i.start);return a.length?{start:Math.min(t,...a.map(e=>e.start)),end:Math.max(n,...a.map(e=>e.end))}:null}var At=new Map,jt=new Map;function Mt(e,t){let n=jt.get(e);if(n)n(t);else{let n=At.get(e)??[];n.some(e=>e.id===t.id)||n.push(t),At.set(e,n)}window.dispatchEvent(new CustomEvent(`pi-web-ui:device-group-open`,{detail:{roomId:e}}))}function Nt(e,t){jt.set(e,t);let n=At.get(e)??[];At.delete(e);for(let e of n)t(e);return()=>{jt.get(e)===t&&jt.delete(e)}}function Pt(e,t,n){let r=`@${n.name}`,i=e.slice(0,t),a=`${i&&!/\s$/.test(i)?` `:``}${r} `;return{text:i+a+e.slice(t),cursor:t+a.length}}var Q=e(Oe(),1);function Ft({botIds:e,roomId:t}){let n=U(),[r,i]=(0,Q.useState)(null),[a,o]=(0,Q.useState)(``),[s,c]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{let e=!1,t,r;async function a(){t=new AbortController;try{let r=async e=>{let r=await fetch(u(H(`/api/device-center/${e}`)),{credentials:`same-origin`,signal:AbortSignal.any([t.signal,AbortSignal.timeout(15e3)])});if(!r.ok)throw Error(n(`deviceGroupMembers.loadFailed`));return r.json()},[a,s]=await Promise.all([r(`chat-status`),r(`bots`)]);if(!a.hubUrl||!Array.isArray(s.bots))throw Error(n(`deviceGroupMembers.invalidBinding`));e||(i({hubUrl:a.hubUrl,deviceId:a.deviceId,bots:s.bots}),o(``))}catch(t){e||o(t instanceof Error?t.message:String(t))}finally{t.abort(),e||(r=setTimeout(a,15e3))}}return a(),()=>{e=!0,t?.abort(),clearTimeout(r)}},[n]);async function d(e,t){if(r&&!s){c(!0);try{await X(e.deviceId,r.hubUrl,t,n,!1,e.name),o(``)}catch(e){o(e instanceof Error?e.message:String(e))}finally{c(!1)}}}return(0,Z.jsxs)(`div`,{className:`dg-side-members`,children:[a&&(0,Z.jsx)(`div`,{className:`dg-side-error`,role:`alert`,children:a}),!r&&!a&&(0,Z.jsx)(`div`,{className:`dg-side-empty`,children:n(`loading`)}),e.length===0&&(0,Z.jsx)(`div`,{className:`dg-side-empty`,children:n(`deviceGroupMembers.empty`)}),r&&e.map(e=>{let i=r.bots.find(t=>t.id===e);return(0,Z.jsx)(`div`,{className:`dg-side-member`,children:(0,Z.jsxs)(`div`,{className:`dg-side-member-name`,title:i?.name||e,children:[(0,Z.jsx)(`span`,{children:i?.name||e}),(0,Z.jsx)(`small`,{children:i?.online?n(`deviceHubOnline`):n(`deviceHubOffline`)}),t&&i&&(0,Z.jsx)(`button`,{type:`button`,className:`dg-side-toggle`,title:n(`deviceGroupMembers.reference`),"aria-label":`${n(`deviceGroupMembers.reference`)} · ${i.name}`,onClick:()=>Mt(t,i),children:(0,Z.jsx)(ce,{"aria-hidden":!0})}),i?.deviceId&&r.deviceId&&i.deviceId!==r.deviceId&&(0,Z.jsxs)(`div`,{className:`dg-side-member-actions`,children:[(0,Z.jsx)(`button`,{type:`button`,className:`dg-side-toggle`,title:n(`deviceDirectory.remoteDesktop`),"aria-label":n(`deviceDirectory.remoteDesktop`),disabled:s||!i?.deviceId,onClick:()=>i&&void d(i,!0),children:(0,Z.jsx)(l,{"aria-hidden":!0})}),(0,Z.jsx)(`button`,{type:`button`,className:`dg-side-toggle`,title:n(`deviceGroupMembers.openDevice`),"aria-label":n(`deviceGroupMembers.openDevice`),disabled:s||!i?.deviceId,onClick:()=>i&&void d(i,!1),children:(0,Z.jsx)(k,{"aria-hidden":!0})})]})]})},e)})]})}async function It(e,t){let n;try{n=JSON.parse(await e.text())}catch{throw Error(`Bot bundle is not valid JSON`)}let r=await Zn(`bot-import`,t??new AbortController().signal,{bundle:n});return window.dispatchEvent(new CustomEvent(`pi-web-ui:device-bots-changed`)),{name:r?.bot?.name??e.name,imported:r?.imported??0,skipped:r?.skipped??0}}function Lt(e,t){let n=e.trim();if(/^ssh:\/\//i.test(n))return n;let r=n.replace(/\\/g,`/`);if(!r)return``;let i=/^(?:[a-z]:\/|\/)/i.test(r)?r:`${t.replace(/\\/g,`/`).replace(/\/$/,``)}/${r}`,a=i.match(/^(?:[a-z]:\/|\/\/[^/]+\/[^/]+\/?|\/)/i)?.[0];if(!a)return r;let o=[];for(let e of i.slice(a.length).split(`/`))e===`..`?o.pop():e&&e!==`.`&&o.push(e);return a.replace(/\/$/,``)+`/`+o.join(`/`)}function Rt(e,t,n){let r=Math.max(8,e.left-8),i=e.bottom+8;return r+t.width>n.width-8&&(r=Math.max(8,e.right+8-t.width)),i+t.height>n.height-8&&(i=Math.max(8,e.top-8-t.height)),{left:r,top:i}}function zt(){return typeof window<`u`&&window.matchMedia?.(`(hover: hover) and (pointer: fine)`)?.matches===!0}var Bt=ke();function Vt(e){let t=(0,Q.useRef)(null),n=(0,Q.useRef)(null),[r,i]=(0,Q.useState)(!1),[a,o]=(0,Q.useState)({left:0,top:0});return(0,Q.useEffect)(()=>{if(!r)return;let e=n.current,i=t.current;if(!e||!i)return;let a=e.getBoundingClientRect(),s=Rt(i.getBoundingClientRect(),a,{width:window.innerWidth,height:window.innerHeight});o(e=>e.left===s.left&&e.top===s.top?e:s)},[r,e]),(0,Q.useEffect)(()=>{if(!r)return;let e=0,a=()=>{cancelAnimationFrame(e),e=requestAnimationFrame(()=>{let e=t.current,r=n.current;if(!e||!r)return;let a=e.getBoundingClientRect();if(a.bottom<0||a.top>window.innerHeight||a.right<0||a.left>window.innerWidth){i(!1);return}let s=Rt(a,r.getBoundingClientRect(),{width:window.innerWidth,height:window.innerHeight});o(e=>e.left===s.left&&e.top===s.top?e:s)})};return window.addEventListener(`scroll`,a,!0),window.addEventListener(`resize`,a),()=>{cancelAnimationFrame(e),window.removeEventListener(`scroll`,a,!0),window.removeEventListener(`resize`,a)}},[r]),{anchorRef:t,show:()=>{let e=t.current?.getBoundingClientRect();e&&(o({left:Math.max(8,e.left-8),top:e.bottom+8}),i(!0))},hide:()=>i(!1),onKeyDown:e=>{e.key===`Escape`&&e.target.blur()},tipPortal:r&&(0,Bt.createPortal)((0,Z.jsx)(`span`,{ref:n,className:`set-tip-bubble open`,role:`tooltip`,style:{position:`fixed`,left:a.left,top:a.top},children:e}),document.body)}}function Ht({text:e}){let{anchorRef:t,show:n,hide:r,onKeyDown:i,tipPortal:a}=Vt(e);return(0,Z.jsxs)(`span`,{ref:t,className:`set-tip`,tabIndex:0,"aria-label":e,onMouseEnter:n,onMouseLeave:r,onFocus:n,onBlur:r,onKeyDown:i,children:[(0,Z.jsx)(ae,{}),a]})}function $({tip:e,children:t,onMouseEnter:n,onMouseLeave:r,onFocus:i,onBlur:a,onKeyDown:o,...s}){let{anchorRef:c,show:l,hide:u,onKeyDown:d,tipPortal:f}=Vt(e);return(0,Z.jsxs)(`button`,{ref:c,type:`button`,"aria-label":s[`aria-label`]??e,...s,onMouseEnter:e=>{l(),n?.(e)},onMouseLeave:e=>{u(),r?.(e)},onFocus:e=>{l(),i?.(e)},onBlur:e=>{u(),a?.(e)},onKeyDown:e=>{d(e),o?.(e)},children:[t,f]})}var Ut=new Set;function Wt(e){return Ut.add(e),()=>{Ut.delete(e)}}function Gt(e){for(let t of Ut)try{t(e)}catch(e){console.error(`[remote-ssh-client] listener error:`,e)}}function Kt(e,t,n,r){return`ssh://${e}@${t}:${n}${r.startsWith(`/`)?r:`/${r}`}`}function qt(e){return!!(e&&e.startsWith(`ssh://`))}function Jt(e){if(!qt(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 Yt=1;function Xt(e,t){let n=`probe_${Date.now()}_${Yt++}`;return new Promise(r=>{let i=Wt(e=>{e.type===`remote_ssh_probe_result`&&e.reqId===n&&(i(),r({ok:e.ok,connectionId:e.connectionId,error:e.error,system:e.system,tools:e.tools,packageManager:e.packageManager,suggestedInstall:e.suggestedInstall,hostTrust:e.hostTrust,profileSaveError:e.profileSaveError}))});W({type:`remote_ssh_probe`,reqId:n,params:e})||(i(),r({ok:!1,error:t(`remoteSshSocketDownRetry`)}))})}function Zt(e,t,n){let r=`listdir_${Date.now()}_${Yt++}`;return new Promise(i=>{let a=Wt(e=>{e.type===`remote_ssh_list_dir_result`&&e.reqId===r&&(a(),i({ok:e.ok,connectionId:e.connectionId,path:e.path,parentPath:e.parentPath,items:e.items,error:e.error}))});W({type:`remote_ssh_list_dir`,reqId:r,connectionId:e,path:n})||(a(),i({ok:!1,connectionId:e,path:n||`/`,items:[],error:t(`remoteSshSocketDown`)}))})}function Qt(e,t,n){let r=`install_${Date.now()}_${Yt++}`;return new Promise(i=>{let a=Wt(e=>{e.type===`remote_ssh_install_result`&&e.reqId===r&&(a(),i({ok:e.ok,connectionId:e.connectionId,tool:e.tool,output:e.output,error:e.error}))});W({type:`remote_ssh_install_tools`,reqId:r,connectionId:e,tools:t})||(a(),i({ok:!1,connectionId:e,tool:t[0]||``,error:n(`remoteSshSocketDown`)}))})}function $t(){let e=`profiles_${Date.now()}_${Yt++}`;return new Promise(t=>{let n=Wt(r=>{r.type===`remote_ssh_profiles_result`&&r.reqId===e&&(n(),t({profiles:r.profiles,localKeys:r.localKeys??[]}))});W({type:`remote_ssh_list_profiles`,reqId:e})||(n(),t({profiles:[],localKeys:[]}))})}function en(e){W({type:`remote_ssh_delete_profile`,name:e})}function tn(e,t){let n=`trust_${Date.now()}_${Yt++}`;return new Promise(r=>{let i=Wt(e=>{e.type===`remote_ssh_trust_host_result`&&e.reqId===n&&(i(),r({ok:e.ok,error:e.error}))});W({type:`remote_ssh_trust_host`,reqId:n,...e})||(i(),r({ok:!1,error:t(`remoteSshSocketDown`)}))})}var nn=`@root`,rn=e=>e.endsWith(`/`)?e:e+`/`;function an(e,t){let n=t.trim(),r=e.replace(/\\/g,`/`);return r.endsWith(`/`)?r+n:(/^[A-Za-z]:$/.test(r),r+`/`+n)}function on(e){let t=e.trim();return!(!t||t===`.`||t===`..`||t.includes(`/`)||t.includes(`\\`))}var sn=e=>{let t=e.endsWith(`/`)&&e!==`/`?e.slice(0,-1):e;if(t===`@root`||t===`/`)return null;let n=t.lastIndexOf(`/`);if(n<0)return/^[A-Za-z]:$/.test(t)?nn:null;if(n===0)return`/`;let r=t.slice(0,n);return/^[A-Za-z]:$/.test(r)?r+`/`:r},cn=`pi-web-ui:project-picker-tab`;function ln(){try{let e=localStorage.getItem(cn);return e===`local`||e===`remote`?e:null}catch{return null}}function un({currentCwd:e,pathCompletions:t,workspaceRoots:r,onClose:i,onSelectDirectory:a,mode:o=`folder`,onCreateProject:s,className:c,backdropClassName:u,role:d,ariaLabel:f,localOnly:p=!1,initialTab:m,portalContainer:h}){let g=U(),_=Re().remoteSsh&&!p,v=Le(`homeDir`),y=Le(`desktopDir`),b=Le(`pathCompletions`),x=Le(`workspaceRoots`),S=t&&t.length>0?t:b??[],w=r&&r.length>0?r:x??[],[T,E]=(0,Q.useState)(()=>_?m===`local`||m===`remote`?m:ln()||(qt(e)?`remote`:`local`):`local`),D=e=>{E(e);try{localStorage.setItem(cn,e)}catch{}};(0,Q.useEffect)(()=>{!_&&T===`remote`&&D(`local`)},[_,T]);let[k,A]=(0,Q.useState)(``),[j,N]=(0,Q.useState)(``),[F,I]=(0,Q.useState)(!1),[ee,z]=(0,Q.useState)(``),[B,V]=(0,Q.useState)(null),[ne,re]=(0,Q.useState)(-1),ie=(0,Q.useRef)(null),ae=(0,Q.useRef)(null),[oe,H]=(0,Q.useState)([]),[se,ce]=(0,Q.useState)(``),[le,ue]=(0,Q.useState)(`22`),[de,fe]=(0,Q.useState)(``),[pe,me]=(0,Q.useState)(`password`),[he,ve]=(0,Q.useState)(``),[xe,Se]=(0,Q.useState)(``),[Ce,we]=(0,Q.useState)([]),[Te,Ee]=(0,Q.useState)(!1),[De,Oe]=(0,Q.useState)(!0),[ke,Ae]=(0,Q.useState)(``),[Me,Ne]=(0,Q.useState)(!1),[Pe,Fe]=(0,Q.useState)(null),[Ie,ze]=(0,Q.useState)(!1),[Be,Ve]=(0,Q.useState)(!1),[G,He]=(0,Q.useState)(null),[K,Ue]=(0,Q.useState)(null),[We,q]=(0,Q.useState)(null),[J,Ge]=(0,Q.useState)(null),[Ke,qe]=(0,Q.useState)([]),[Je,Ye]=(0,Q.useState)(!1),[Y,Xe]=(0,Q.useState)(`/`),[X,Ze]=(0,Q.useState)(`/`),[Qe,$e]=(0,Q.useState)([]),[et,tt]=(0,Q.useState)(!1),[nt,rt]=(0,Q.useState)(!1),[it,at]=(0,Q.useState)(``),[ot,st]=(0,Q.useState)(null),ct=S.filter(e=>e.type===`dir`);(0,Q.useEffect)(()=>{if(qt(e)){let t=Jt(e);t&&(ce(t.host),ue(String(t.port)),fe(t.username),Xe(t.remotePath),Ze(t.remotePath))}else{let t=(e||``).replace(/\\/g,`/`);A(t),N(t)}I(!1),z(``),V(null),re(-1)},[e]),(0,Q.useEffect)(()=>{let e=requestAnimationFrame(()=>{ie.current?.focus()});return()=>cancelAnimationFrame(e)},[T]),je(()=>{F||nt?(I(!1),z(``),V(null),rt(!1),at(``),st(null)):i()}),(0,Q.useEffect)(()=>{if(T!==`local`)return;let e=setTimeout(()=>{W({type:`complete_path`,path:rn(k)})},60);return()=>clearTimeout(e)},[k,T]),(0,Q.useEffect)(()=>{if(T!==`local`||j===k)return;let e=setTimeout(()=>{W({type:`complete_path`,path:j})},150);return()=>clearTimeout(e)},[j,k,T]);let lt=e=>{let t=e.trim();t&&t!==`@root`&&a(t)},ut=e=>{A(e),N(e),re(-1),V(null)},dt=()=>{let e=ee.trim();if(e&&k!==`@root`){if(o===`project`){if(!on(e)){V(g(`invalidProjectName`));return}let t=an(k,e);s?s(t):(W({type:`make_dir`,path:t}),a(t)),I(!1),z(``),V(null),i()}else W({type:`make_dir`,path:`${rn(k)}${e}`}),setTimeout(()=>{W({type:`complete_path`,path:rn(k)})},80),z(``),I(!1)}},ft=e=>{if(e.key===`Escape`)e.stopPropagation(),F?(I(!1),z(``),V(null)):i();else if(e.key===`Enter`&&!e.nativeEvent.isComposing)lt(j);else if(e.key===`Tab`){if(ct.length===0)return;e.preventDefault();let t=ne>=0?(ne+1)%ct.length:0;re(t),N(ct[t].path),A(ct[t].path)}},pt=async t=>{let n=(t?.host??se).trim(),r=t?.port??(parseInt(le,10)||22),i=(t?.username??de).trim();if(!n||!i){Fe(g(`directoryBrowser.missingHost`));return}Ne(!0),Fe(null);let a=await Xt({host:n,port:r,username:i,auth:t?.auth??(pe===`password`?{type:`password`,password:he}:pe===`key`?{type:`key`,privateKeyPath:xe}:{type:`agent`}),saveProfile:De,profileName:t?.profileName||ke.trim()||void 0},g);if(Ne(!1),!a.ok||!a.connectionId){He(a.hostTrust??null),ze(!1),Fe(a.error||g(`directoryBrowser.connectFailed`));return}Ue(a.connectionId),a.profileSaveError&&Fe(a.profileSaveError),q(a.system??null),Ge(a.tools??null),qe(a.suggestedInstall??[]);let o=qt(e)?Jt(e)?.remotePath:null,s=o&&o!==`/`?o:a.system?.homeDir||`/`;Xe(s),Ze(s),ht(a.connectionId,s),$t().then(({profiles:e,localKeys:t})=>{H(e),we(t)})},mt=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{T===`remote`&&$t().then(({profiles:t,localKeys:n})=>{if(H(t),we(n),Se(e=>e||n[0]||``),!mt.current&&!K&&!Me&&qt(e)){let n=Jt(e);if(n){let e=t.find(e=>e.host===n.host&&(e.username===n.username||!n.username)&&(e.port===n.port||!n.port&&e.port===22))||t.find(e=>e.host===n.host&&e.username===n.username)||t.find(e=>e.host===n.host);e&&(mt.current=!0,ce(e.host),ue(String(e.port)),fe(e.username),me(e.authType),e.privateKeyPath&&Se(e.privateKeyPath),pt({host:e.host,port:e.port,username:e.username,profileName:e.name,auth:e.authType===`password`?{type:`password`,password:``}:e.authType===`key`?{type:`key`,privateKeyPath:e.privateKeyPath}:{type:`agent`}}))}}})},[T,e,K,Me]);let ht=async(e,t)=>{tt(!0),Fe(null);let n=await Zt(e,g,t);tt(!1),n.ok?(Xe(n.path),Ze(n.path),$e(n.items)):Fe(n.error||g(`directoryBrowser.readDirFailed`))},gt=async e=>{if(!K)return;Ye(!0),Fe(null);let t=await Qt(K,[e],g);Ye(!1),t.ok?(qe(t=>t.filter(t=>t!==e)),J&&e===`git`&&Ge({...J,git:{installed:!0,version:g(`directoryBrowser.installed`)}})):Fe(t.error||g(`directoryBrowser.installToolFailed`,{tool:e}))},_t=e=>{let t=parseInt(le,10)||22,n=We?.homeDir||`/`,r=(e||``).trim()||Y||`/`;r===`~`?r=n:(r.startsWith(`~/`)||r.startsWith(`~\\`))&&(r=`${n.replace(/\/+$/,``)}/${r.slice(2).replace(/\\/g,`/`)}`),a(Kt(de,se,t,r)),i()},vt=()=>{let e=it.trim();if(!e||!K)return;if(!on(e)){st(g(`invalidProjectName`));return}let t=parseInt(le,10)||22,n=Y.replace(/\/+$/,``)||`/`,r=n===`/`?`/${e}`:`${n}/${e}`,c=Kt(de,se,t,r);if(o===`project`)s?s(c):(W({type:`make_dir`,path:c}),a(c)),rt(!1),at(``),st(null),i();else{W({type:`make_dir`,path:c}),at(``),rt(!1),st(null);let e=K,t=Y;setTimeout(()=>{ht(e,t)},300)}},yt=sn(k),bt=sn(Y),xt=e=>{let t=e.replace(/\\/g,`/`).replace(/\/+$/,``);return/^[A-Za-z]:/.test(t)?t.toLowerCase():t},St=xt(k),Ct=!!k&&k!==`@root`&&St!==xt(e)&&!w.some(e=>xt(e)===St);return(0,Bt.createPortal)((0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:`status-cwd-backdrop ${u??``}`.trim(),onClick:i,onPointerDown:e=>e.stopPropagation(),onMouseDown:e=>e.stopPropagation()}),(0,Z.jsxs)(`div`,{className:`cwd-picker ${c??``}`.trim(),role:d,"aria-label":f,onPointerDown:e=>e.stopPropagation(),onMouseDown:e=>e.stopPropagation(),onWheel:e=>e.stopPropagation(),children:[_?(0,Z.jsxs)(`div`,{className:`cwd-mode-tabs`,children:[(0,Z.jsxs)(`button`,{type:`button`,className:`cwd-mode-tab ${T===`local`?`active`:``}`,onClick:()=>D(`local`),children:[`💻 `,g(`workspaceModeLocal`)]}),(0,Z.jsxs)(`button`,{type:`button`,className:`cwd-mode-tab ${T===`remote`?`active`:``}`,onClick:()=>D(`remote`),children:[`🌐 `,g(`workspaceModeRemote`)]}),(0,Z.jsx)(`button`,{type:`button`,className:`cwd-close`,title:g(`close`),"aria-label":g(`close`),onClick:i,children:(0,Z.jsx)(_e,{})})]}):(0,Z.jsxs)(`div`,{className:`cwd-mode-tabs cwd-mode-tabs-single`,children:[(0,Z.jsxs)(`div`,{className:`cwd-mode-tab active`,style:{cursor:`default`},children:[`💻 `,g(`workspaceModeLocal`)]}),(0,Z.jsx)(`button`,{type:`button`,className:`cwd-close`,title:g(`close`),"aria-label":g(`close`),onClick:i,children:(0,Z.jsx)(_e,{})})]}),T===`local`&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:`cwd-picker-head`,children:(0,Z.jsxs)(`span`,{className:`cwd-picker-title`,title:k===`@root`?g(`computer`):k,children:[k===`@root`?(0,Z.jsx)(ge,{}):(0,Z.jsx)(M,{}),(0,Z.jsx)(`span`,{children:k===`@root`?g(`computer`):k})]})}),(0,Z.jsxs)(`div`,{className:`cwd-toolbar`,role:`toolbar`,"aria-label":g(`projectPickerTitle`),children:[(0,Z.jsx)($,{className:`cwd-jump ${k===`@root`?`active`:``}`,tip:g(`computer`),onClick:()=>ut(`@root`),children:(0,Z.jsx)(ge,{})}),v!==``&&(0,Z.jsx)($,{className:`cwd-jump ${xt(k)===xt(v)?`active`:``}`,tip:`${g(`homeDir`)} ${v}`,onClick:()=>ut(v),children:(0,Z.jsx)(L,{})}),y!==``&&(0,Z.jsx)($,{className:`cwd-jump ${xt(k)===xt(y)?`active`:``}`,tip:`${g(`desktopDir`)} ${y}`,onClick:()=>ut(y),children:(0,Z.jsx)(l,{})}),(0,Z.jsx)(`span`,{className:`cwd-toolbar-sep`,"aria-hidden":`true`}),(0,Z.jsx)($,{className:`cwd-jump tool-up`,tip:yt?`${g(`cwdGoUp`)} · ${yt}`:`${g(`cwdGoUp`)} · ${g(`directoryBrowser.alreadyAtTop`)}`,"aria-disabled":!yt,onClick:()=>{yt&&ut(yt)},children:(0,Z.jsx)(te,{})}),(0,Z.jsx)($,{className:`cwd-jump tool-root`,tip:Ct?g(`addWorkspaceRootHint`):k===`@root`?`${g(`addWorkspaceRoot`)} · ${g(`directoryBrowser.thisPcNotDirectory`)}`:St===xt(e)?`${g(`addWorkspaceRoot`)} · ${g(`directoryBrowser.alreadyCurrentProject`)}`:`${g(`addWorkspaceRoot`)} · ${g(`directoryBrowser.alreadyWorkspaceRoot`)}`,"aria-disabled":!Ct,onClick:()=>{Ct&&W({type:`set_workspace_roots`,roots:[...w,k]})},children:(0,Z.jsx)(P,{})}),(0,Z.jsx)($,{className:`cwd-jump tool-new ${F?`active`:``}`,tip:k===`@root`?`${g(`cwdNewFolder`)} · ${g(`directoryBrowser.cannotCreateHere`)}`:g(F?`cwdCancel`:`cwdNewFolder`),"aria-disabled":k===`@root`,onClick:()=>{k!==`@root`&&(F?(I(!1),z(``),V(null)):(z(``),V(null),I(!0)))},children:(0,Z.jsx)(C,{})}),(0,Z.jsx)(`span`,{className:`cwd-toolbar-spacer`}),(0,Z.jsx)($,{className:`cwd-jump primary tool-pick`,tip:k===`@root`?`${g(`cwdPickCurrent`)} · ${g(`directoryBrowser.thisPcCannotBeWorkspace`)}`:`${g(`cwdPickCurrent`)} · ${k}`,"aria-disabled":k===`@root`,onClick:()=>lt(k),children:(0,Z.jsx)(R,{})})]}),(0,Z.jsxs)(`div`,{className:`cwd-picker-row`,children:[(0,Z.jsx)(`input`,{ref:ie,className:`status-cwd-input cwd-picker-input`,value:j,placeholder:g(`enterPath`),spellCheck:!1,onChange:e=>{N(e.target.value),re(-1)},onKeyDown:ft}),j.trim()!==``&&j!==k&&(0,Z.jsx)($,{className:`cwd-jump tool-enter`,tip:`${g(`cwdEnter`)} · ${j.trim()}`,onClick:()=>{A(j.trim()),re(-1)},children:(0,Z.jsx)(be,{})})]}),(0,Z.jsxs)(`div`,{className:`cwd-list`,children:[yt&&(0,Z.jsx)(`div`,{className:`cwd-item`,children:(0,Z.jsxs)(`button`,{type:`button`,className:`cwd-enter`,title:`${g(`cwdGoUp`)} · ${yt}`,onClick:()=>ut(yt),children:[(0,Z.jsx)(M,{}),(0,Z.jsx)(`span`,{className:`cwd-name`,children:`..`})]})},`..`),ct.length===0&&!yt&&(0,Z.jsx)(`div`,{className:`cwd-empty`,children:g(`cwdEmpty`)}),ct.map(e=>(0,Z.jsxs)(`div`,{className:`cwd-item`,children:[(0,Z.jsxs)(`button`,{type:`button`,className:`cwd-enter`,title:`${g(`cwdEnter`)} ${e.path}`,onClick:()=>{A(e.path),N(e.path),re(-1)},children:[(0,Z.jsx)(M,{}),(0,Z.jsx)(`span`,{className:`cwd-name`,children:e.name})]}),(0,Z.jsx)($,{className:`cwd-jump tool-choose`,tip:`${g(`cwdChoose`)} · ${e.path}`,onClick:()=>lt(e.path),children:(0,Z.jsx)(R,{})})]},e.path))]}),F&&(0,Z.jsxs)(`div`,{className:`cwd-picker-foot`,children:[(0,Z.jsxs)(`div`,{className:`cwd-newrow`,children:[(0,Z.jsx)(`input`,{ref:ae,value:ee,autoFocus:!0,spellCheck:!1,placeholder:g(`cwdNewName`),onChange:e=>{z(e.target.value),B&&V(null)},onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing?(e.preventDefault(),dt()):e.key===`Escape`&&(e.stopPropagation(),I(!1),z(``),V(null))}}),(0,Z.jsx)($,{className:`cwd-jump primary`,tip:g(`cwdCreate`),onClick:dt,children:(0,Z.jsx)(R,{})}),(0,Z.jsx)($,{className:`cwd-jump`,tip:g(`cwdCancel`),onClick:()=>{I(!1),z(``),V(null)},children:(0,Z.jsx)(_e,{})})]}),B&&(0,Z.jsx)(`div`,{className:`project-picker-error`,style:{color:`var(--red)`,fontSize:`11px`,marginTop:`4px`},children:B})]})]}),T===`remote`&&(0,Z.jsx)(`div`,{className:`cwd-ssh-container`,children:K?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`cwd-ssh-probe-box`,children:[(0,Z.jsxs)(`div`,{className:`cwd-ssh-probe-header`,children:[(0,Z.jsxs)(`span`,{children:[`🌐 `,de,`@`,se,` (`,We?.os,` `,We?.arch,`)`]}),(0,Z.jsx)(`button`,{type:`button`,className:`cwd-ssh-profile-del`,onClick:()=>{Ue(null),q(null),Ge(null)},children:g(`sshDisconnect`)})]}),(0,Z.jsxs)(`div`,{style:{display:`flex`,gap:`6px`,flexWrap:`wrap`,fontSize:`10px`},children:[(0,Z.jsxs)(`span`,{className:`cwd-ssh-tool-badge ${J?.git.installed?`ok`:`missing`}`,children:[`Git: `,J?.git.installed?`✓`:`✗`]}),(0,Z.jsxs)(`span`,{className:`cwd-ssh-tool-badge ${J?.node.installed?`ok`:`missing`}`,children:[`Node: `,J?.node.installed?`✓`:`✗`]}),(0,Z.jsxs)(`span`,{className:`cwd-ssh-tool-badge ${J?.bash.installed?`ok`:`missing`}`,children:[`Bash: `,J?.bash.installed?`✓`:`✗`]})]}),Ke.length>0&&(0,Z.jsxs)(`div`,{className:`cwd-ssh-install-box`,children:[(0,Z.jsxs)(`div`,{children:[`⚠️ `,g(`directoryBrowser.remoteToolsMissing`)]}),(0,Z.jsxs)(`div`,{style:{display:`flex`,gap:`6px`,marginTop:`2px`},children:[(0,Z.jsx)(`button`,{type:`button`,className:`cwd-choose-btn primary`,disabled:Je,onClick:()=>void gt(Ke[0]),children:Je?g(`sshInstalling`):`⚡ ${g(`sshInstallTool`)} ${Ke[0]}`}),(0,Z.jsx)(`button`,{type:`button`,className:`cwd-choose-btn`,onClick:()=>qe([]),children:g(`sshSkipAndBrowse`)})]})]})]}),(0,Z.jsx)(`div`,{className:`cwd-picker-head`,children:(0,Z.jsxs)(`span`,{className:`cwd-picker-title`,title:Y,children:[(0,Z.jsx)(ye,{}),(0,Z.jsx)(`span`,{children:Y})]})}),(0,Z.jsxs)(`div`,{className:`cwd-toolbar`,role:`toolbar`,"aria-label":g(`workspaceModeRemote`),children:[(0,Z.jsx)($,{className:`cwd-jump tool-up`,tip:Y===`/`?`${g(`cwdGoUp`)} · ${g(`directoryBrowser.alreadyAtTop`)}`:`${g(`cwdGoUp`)} · ${sn(Y)||`/`}`,"aria-disabled":Y===`/`||et,onClick:()=>{if(et)return;let e=sn(Y);e&&K&&ht(K,e)},children:(0,Z.jsx)(te,{})}),(0,Z.jsx)($,{className:`cwd-jump tool-new ${nt?`active`:``}`,tip:g(nt?`cwdCancel`:`cwdNewFolder`),onClick:()=>rt(e=>!e),children:(0,Z.jsx)(C,{})}),(0,Z.jsx)(`span`,{className:`cwd-toolbar-spacer`})]}),(0,Z.jsxs)(`div`,{className:`cwd-picker-row`,children:[(0,Z.jsx)(`input`,{className:`status-cwd-input cwd-picker-input`,value:X,placeholder:g(`enterPath`),spellCheck:!1,onChange:e=>Ze(e.target.value),onKeyDown:e=>{e.key===`Enter`&&K&&ht(K,X)}}),X.trim()&&X.trim()!==Y&&K&&(0,Z.jsx)($,{className:`cwd-jump tool-enter`,tip:`${g(`cwdEnter`)} · ${X.trim()}`,onClick:()=>void ht(K,X),children:(0,Z.jsx)(be,{})}),(0,Z.jsx)($,{className:`cwd-jump primary tool-pick`,tip:`${g(`sshOpenRemoteWorkspace`)} · ${X.trim()||Y}`,onClick:()=>_t(X.trim()||Y),children:(0,Z.jsx)(R,{})})]}),(0,Z.jsxs)(`div`,{className:`cwd-list`,children:[!et&&bt&&(0,Z.jsx)(`div`,{className:`cwd-item`,children:(0,Z.jsxs)(`button`,{type:`button`,className:`cwd-enter`,title:`${g(`cwdGoUp`)} · ${bt}`,onClick:()=>{K&&ht(K,bt)},children:[(0,Z.jsx)(M,{}),(0,Z.jsx)(`span`,{className:`cwd-name`,children:`..`})]})},`..`),et?(0,Z.jsx)(`div`,{className:`cwd-empty`,children:g(`directoryBrowser.loadingRemoteDir`)}):Qe.length===0?(0,Z.jsx)(`div`,{className:`cwd-empty`,children:g(`cwdEmpty`)}):Qe.map(e=>(0,Z.jsxs)(`div`,{className:`cwd-item`,children:[(0,Z.jsxs)(`button`,{type:`button`,className:`cwd-enter`,title:`${e.type===`dir`?g(`cwdEnter`):``} ${e.path}`,onClick:()=>{e.type===`dir`&&K&&ht(K,e.path)},children:[e.type===`dir`?(0,Z.jsx)(M,{}):(0,Z.jsx)(`span`,{children:`📄`}),(0,Z.jsx)(`span`,{className:`cwd-name`,children:e.name})]}),e.type===`dir`&&(0,Z.jsx)($,{className:`cwd-jump tool-choose`,tip:`${g(`cwdChoose`)} · ${e.path}`,onClick:()=>_t(e.path),children:(0,Z.jsx)(R,{})})]},e.path))]}),K&&nt&&(0,Z.jsxs)(`div`,{className:`cwd-picker-foot`,children:[(0,Z.jsxs)(`div`,{className:`cwd-newrow`,children:[(0,Z.jsx)(`input`,{value:it,autoFocus:!0,spellCheck:!1,placeholder:g(`cwdNewName`),onChange:e=>{at(e.target.value),ot&&st(null)},onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing?(e.preventDefault(),vt()):e.key===`Escape`&&(e.stopPropagation(),rt(!1),at(``),st(null))}}),(0,Z.jsx)($,{className:`cwd-jump primary`,tip:g(`cwdCreate`),onClick:vt,children:(0,Z.jsx)(R,{})}),(0,Z.jsx)($,{className:`cwd-jump`,tip:g(`cwdCancel`),onClick:()=>{rt(!1),at(``),st(null)},children:(0,Z.jsx)(_e,{})})]}),ot&&(0,Z.jsx)(`div`,{className:`project-picker-error`,style:{color:`var(--red)`,fontSize:`11px`,marginTop:`4px`},children:ot})]})]}):(0,Z.jsxs)(`div`,{className:`cwd-ssh-form`,children:[oe.length>0&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`cwd-ssh-profiles-title`,children:[`📋 `,g(`sshSavedProfiles`)]}),oe.map(e=>(0,Z.jsxs)(`div`,{className:`cwd-ssh-profile-card`,onClick:()=>{ce(e.host),ue(String(e.port)),fe(e.username),me(e.authType),e.privateKeyPath&&Se(e.privateKeyPath),pt({host:e.host,port:e.port,username:e.username,profileName:e.name,auth:e.authType===`password`?{type:`password`,password:``}:e.authType===`key`?{type:`key`,privateKeyPath:e.privateKeyPath}:{type:`agent`}})},children:[(0,Z.jsxs)(`div`,{className:`cwd-ssh-profile-meta`,children:[(0,Z.jsxs)(`span`,{className:`cwd-ssh-profile-name`,children:[(0,Z.jsx)(O,{style:{marginRight:`4px`}}),e.name]}),(0,Z.jsxs)(`span`,{className:`cwd-ssh-profile-addr`,children:[e.username,`@`,e.host,`:`,e.port]})]}),(0,Z.jsx)(`button`,{type:`button`,className:`cwd-ssh-profile-del`,title:g(`delete`),onClick:t=>{t.stopPropagation(),confirm(g(`sshDeleteProfileConfirm`))&&(en(e.name),H(t=>t.filter(t=>t.name!==e.name)))},children:(0,Z.jsx)(n,{})})]},e.name))]}),(0,Z.jsxs)(`div`,{className:`cwd-ssh-row`,style:{marginTop:`4px`},children:[(0,Z.jsxs)(`label`,{children:[g(`sshHost`),`:`]}),(0,Z.jsx)(`input`,{className:`cwd-ssh-input`,value:se,placeholder:`192.168.1.100`,onChange:e=>ce(e.target.value)}),(0,Z.jsxs)(`label`,{style:{width:`32px`,textAlign:`right`},children:[g(`sshPort`),`:`]}),(0,Z.jsx)(`input`,{className:`cwd-ssh-input`,style:{width:`45px`,flex:`none`},value:le,onChange:e=>ue(e.target.value)})]}),(0,Z.jsxs)(`div`,{className:`cwd-ssh-row`,children:[(0,Z.jsxs)(`label`,{children:[g(`sshUser`),`:`]}),(0,Z.jsx)(`input`,{className:`cwd-ssh-input`,value:de,placeholder:`root / ubuntu`,onChange:e=>fe(e.target.value)})]}),(0,Z.jsxs)(`div`,{className:`cwd-ssh-row`,children:[(0,Z.jsxs)(`label`,{children:[g(`sshAuthType`),`:`]}),(0,Z.jsxs)(`select`,{className:`cwd-ssh-select`,value:pe,onChange:e=>me(e.target.value),children:[(0,Z.jsx)(`option`,{value:`password`,children:g(`sshPassword`)}),(0,Z.jsx)(`option`,{value:`key`,children:g(`sshKeyPath`)}),(0,Z.jsx)(`option`,{value:`agent`,children:g(`sshAgent`)})]})]}),pe===`password`&&(0,Z.jsxs)(`div`,{className:`cwd-ssh-row`,children:[(0,Z.jsxs)(`label`,{children:[g(`sshPassword`),`:`]}),(0,Z.jsx)(`input`,{type:`password`,className:`cwd-ssh-input`,value:he,placeholder:`••••••••`,onChange:e=>ve(e.target.value)})]}),pe===`key`&&(0,Z.jsx)(Z.Fragment,{children:Ce.length>0?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`cwd-ssh-row`,children:[(0,Z.jsxs)(`label`,{children:[g(`sshKeyPath`),`:`]}),(0,Z.jsxs)(`select`,{className:`cwd-ssh-select`,value:Te||xe&&!Ce.includes(xe)?`__custom__`:xe,onChange:e=>{let t=e.target.value;t===`__custom__`?Ee(!0):(Ee(!1),Se(t))},children:[Ce.map(e=>(0,Z.jsx)(`option`,{value:e,children:e},e)),(0,Z.jsx)(`option`,{value:`__custom__`,children:g(`sshKeyCustom`)})]})]}),(Te||xe&&!Ce.includes(xe))&&(0,Z.jsxs)(`div`,{className:`cwd-ssh-row`,children:[(0,Z.jsx)(`label`,{}),(0,Z.jsx)(`input`,{className:`cwd-ssh-input`,value:xe,placeholder:`~/.ssh/id_ed25519`,onChange:e=>Se(e.target.value)})]})]}):(0,Z.jsxs)(`div`,{className:`cwd-ssh-row`,children:[(0,Z.jsxs)(`label`,{children:[g(`sshKeyPath`),`:`]}),(0,Z.jsx)(`input`,{className:`cwd-ssh-input`,value:xe,placeholder:`~/.ssh/id_ed25519`,onChange:e=>Se(e.target.value)})]})}),(0,Z.jsx)(`div`,{className:`cwd-ssh-row`,style:{fontSize:`11px`,color:`var(--text-dim)`},children:(0,Z.jsxs)(`label`,{style:{width:`auto`},children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:De,onChange:e=>Oe(e.target.checked),style:{marginRight:`4px`}}),g(`sshSaveProfile`)]})}),De&&(0,Z.jsxs)(`div`,{className:`cwd-ssh-row`,children:[(0,Z.jsxs)(`label`,{children:[g(`sshProfileName`),`:`]}),(0,Z.jsx)(`input`,{className:`cwd-ssh-input`,value:ke,placeholder:`my-server`,onChange:e=>Ae(e.target.value)})]}),G&&(0,Z.jsxs)(`div`,{style:{border:`1px solid #d97706`,borderRadius:`8px`,padding:`8px`,marginTop:`6px`},children:[(0,Z.jsx)(`div`,{style:{fontSize:`12px`,fontWeight:600,marginBottom:`4px`},children:G.status===`changed`?g(`directoryBrowser.hostKeyChanged`):g(`directoryBrowser.newHostKey`)}),(0,Z.jsxs)(`div`,{style:{fontSize:`11px`,wordBreak:`break-all`,marginBottom:`4px`},children:[G.host,`:`,G.port,` `,G.algorithm,` `,G.fingerprint]}),(0,Z.jsx)(`div`,{style:{fontSize:`11px`,color:`var(--text-dim)`,marginBottom:`6px`},children:g(`directoryBrowser.fingerprintHint`)}),(0,Z.jsxs)(`label`,{style:{fontSize:`11px`,display:`flex`,gap:`6px`,marginBottom:`6px`},children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:Ie,onChange:e=>ze(e.target.checked)}),(0,Z.jsx)(`span`,{children:g(`directoryBrowser.fingerprintVerified`)})]}),(0,Z.jsxs)(`div`,{style:{display:`flex`,gap:`8px`},children:[(0,Z.jsx)(`button`,{type:`button`,className:`cwd-choose-btn primary`,disabled:!Ie||Be,onClick:async()=>{Ve(!0);let e=await tn({host:G.host,port:G.port,fingerprint:G.fingerprint,replace:G.status===`changed`},g);if(Ve(!1),!e.ok){Fe(e.error||g(`directoryBrowser.trustFailed`));return}He(null),pt()},children:g(`directoryBrowser.trustAndRetry`)}),(0,Z.jsx)(`button`,{type:`button`,className:`cwd-choose-btn`,onClick:()=>{He(null),ze(!1)},children:g(`cancel`)})]})]}),Pe&&(0,Z.jsxs)(`div`,{style:{color:`var(--red)`,fontSize:`11px`,padding:`2px 0`},children:[`⚠️ `,Pe]}),(0,Z.jsx)(`button`,{type:`button`,className:`cwd-choose-btn primary`,style:{marginTop:`4px`},disabled:Me,onClick:()=>void pt(),children:g(Me?`sshConnecting`:`sshConnectAndProbe`)})]})})]})]}),h??document.body)}function dn({open:e,currentCwd:t,pathCompletions:n,workspaceRoots:r,onClose:i,onSelectDirectory:a,onCreateProject:o,mode:s=`project`,localOnly:c,initialTab:l,portalContainer:u}){let d=U();return e?(0,Z.jsx)(un,{portalContainer:u,localOnly:c,initialTab:l,currentCwd:t,pathCompletions:n,workspaceRoots:r,onClose:i,onSelectDirectory:e=>{a(e),i()},onCreateProject:o,mode:s,className:`project-picker`,backdropClassName:`project-picker-backdrop`,role:`dialog`,ariaLabel:d(`projectPickerTitle`)}):null}function fn({cwd:e,onSelectCwd:t,onOpenProjectPicker:n,projects:r=[],workspaceRoots:i,pathCompletions:a,mode:s=`project`,baseCwd:c,onCreateProject:l,className:u=``,placeholder:d,inputId:f,disabled:p=!1,commitOnBlur:m=!1,localOnly:h=!1,onPickerOpenChange:g}){let _=Le(`pathCompletions`),v=Le(`workspaceRoots`),y=a&&a.length>0?a:_??[],b=i&&i.length>0?i:v??[],[x,S]=(0,Q.useState)(!1),[w,T]=(0,Q.useState)(e);(0,Q.useEffect)(()=>T(e),[e]);let[E,D]=(0,Q.useState)(!1),O=(0,Q.useRef)(null),k=U();(0,Q.useEffect)(()=>{let e=e=>{O.current&&!O.current.contains(e.target)&&S(!1)};if(x)return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[x]);let A=[{label:k(`universalPathDirRoot`),value:`.`},{label:k(`universalPathDirWeb`),value:`web`},{label:k(`universalPathDirServer`),value:`server`},{label:k(`universalPathDirTests`),value:`tests`},{label:k(`universalPathDirSrc`),value:`src`},{label:k(`universalPathDirDocs`),value:`docs`}],j=()=>{D(!1),g?.(!1)},N=()=>{p||(n?n():(S(!1),D(!0),g?.(!0)))},P=e&&e!==`.`?e:c||e||`.`;return(0,Z.jsxs)(`div`,{className:`universal-path-picker-root ${u}`,ref:O,children:[(0,Z.jsxs)(`div`,{className:`universal-path-input-group`,children:[(0,Z.jsx)(M,{className:`universal-path-icon`}),(0,Z.jsx)(`input`,{type:`text`,className:`universal-path-input`,value:m?w:e,id:f,disabled:p,onChange:e=>m?T(e.target.value):t(e.target.value),onBlur:()=>{m&&w!==e&&t(w)},onKeyDown:n=>{m&&n.key===`Enter`&&(n.preventDefault(),w!==e&&t(w))},placeholder:d??k(`universalPathPlaceholder`),title:k(`universalPathCwdTitle`,{cwd:e||`.`})}),(0,Z.jsx)(`button`,{type:`button`,className:`universal-path-dropdown-toggle`,disabled:p,onClick:()=>S(!x),title:k(`universalPathDropdownTip`),children:(0,Z.jsx)(o,{})})]}),(0,Z.jsx)($,{className:`universal-path-browse-btn`,tip:k(`projectPickerTitle`),disabled:p,onClick:N,children:(0,Z.jsx)(C,{})}),x&&(0,Z.jsxs)(`div`,{className:`universal-path-menu`,onPointerDown:e=>e.stopPropagation(),onMouseDown:e=>e.stopPropagation(),onWheel:e=>e.stopPropagation(),children:[b.length>0&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:`universal-path-menu-header`,children:`工作区根目录`}),b.map(e=>(0,Z.jsx)(`button`,{type:`button`,className:`universal-path-menu-item`,onClick:()=>{t(e),S(!1)},children:(0,Z.jsx)(`span`,{className:`path-label`,children:e})},e))]}),(0,Z.jsx)(`div`,{className:`universal-path-menu-header`,children:`推荐子目录`}),A.map(e=>(0,Z.jsx)(`button`,{type:`button`,className:`universal-path-menu-item`,onClick:()=>{t(e.value),S(!1)},children:(0,Z.jsx)(`span`,{className:`path-label`,children:e.label})},e.value)),r.length>0&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`universal-path-menu-header`,children:[(0,Z.jsx)(oe,{}),` 最近项目`]}),r.slice(0,6).map(e=>{let n=e.path.split(/[/\\]/).filter(Boolean).pop()||e.path;return(0,Z.jsxs)(`button`,{type:`button`,className:`universal-path-menu-item`,onClick:()=>{t(e.path),S(!1)},title:e.path,children:[(0,Z.jsx)(`span`,{className:`path-title`,children:n}),(0,Z.jsx)(`span`,{className:`path-sub`,children:e.path})]},e.path)})]})]}),!n&&E&&(0,Z.jsx)(dn,{portalContainer:O.current?.closest(`dialog`)??void 0,localOnly:h,open:!0,currentCwd:P,pathCompletions:y,workspaceRoots:b,onClose:j,onSelectDirectory:e=>{t(e),j()},onCreateProject:l?e=>{l(e),j()}:void 0,mode:s})]})}var pn=`pi-web-model-usage`;function mn(e){if(!e||typeof e!=`object`)return{};let t={};for(let[n,r]of Object.entries(e)){let e=typeof r==`number`?Math.floor(r):0;Number.isFinite(e)&&e>0&&(t[n]=e)}return t}function hn(e,t){return t?{...e,[t]:(e[t]??0)+1}:e}function gn(e,t){let n=t;return e.map((e,t)=>({m:e,i:t,count:n[e.id]??0})).sort((e,t)=>t.count-e.count||e.i-t.i).map(e=>e.m)}function _n(){try{let e=localStorage.getItem(pn);return e?mn(JSON.parse(e)):{}}catch{return{}}}function vn(e){try{localStorage.setItem(pn,JSON.stringify(e))}catch{}}function yn(e){let t=hn(_n(),e);return vn(t),t}function bn(e,t){return t?t===e.id||`${e.provider}/${e.id}`===t||t.includes(`/`)&&t.split(`/`)[1]===e.id:!1}function xn(e,t){return(e?t?.find(t=>t.id===e)?.name?.trim():``)||e}function Sn(e,t){return W(t?{type:`clear_default_model`}:{type:`set_default_model`,modelId:e.id})}function Cn(e,t,n,r){let i=e?.trim();if(!i)return null;let a=i.indexOf(`/`),o=a>0?i.slice(0,a):``,s=a>0?i.slice(a+1):i,c=e=>e.includes(`/`)?e.slice(e.indexOf(`/`)+1):e,l=t.find(e=>e.id===i)??t.find(e=>`${e.provider}/${c(e.id)}`===i)??t.find(e=>e.provider===o&&c(e.id)===s)??null,u=l?.provider||o,d=u?r?.[u]:void 0;return{modelName:l?.name||s,modelId:l?c(l.id):s,provider:u,providerLabel:xn(u,n),keyName:d&&d.length>1?d.find(e=>e.active)?.name??null:null}}function wn({models:e,modelsLoading:t=!1,providerKeys:n={},providers:r,defaultModel:i,currentModelId:a,active:o,onEnsureModels:s,loading:c=!1,onRefresh:l,onManageModels:u,onPickModel:f,onToggleDefault:p,isRowActive:h,extraTopRow:g,listRef:_,autoFocusSearch:v=!1,hideTitle:y=!1,bodyStyle:b,scrollStyle:x}){let S=U(),[C,w]=(0,Q.useState)(``),[T,E]=(0,Q.useState)(null),[D,O]=(0,Q.useState)({}),[k,A]=(0,Q.useState)(!1),j=(0,Q.useRef)(s);j.current=s;let M=(0,Q.useRef)(null),N=(0,Q.useCallback)(e=>{M.current=e,_&&(_.current=e)},[_]),P=(0,Q.useMemo)(()=>Cn(a,e,r,n),[a,e,r,n]),F=()=>{w(``),E(null),requestAnimationFrame(()=>{let e=M.current?.querySelector(`.dd-item.active`);e&&typeof e.scrollIntoView==`function`&&e.scrollIntoView({block:`nearest`})})};(0,Q.useEffect)(()=>{if(!o){w(``),E(null),A(!1);return}O(_n()),j.current()},[o]);let I=(0,Q.useMemo)(()=>e.filter(e=>e.enabled!==!1).length,[e]),L=e.some(e=>e.enabled===!1),R=(0,Q.useMemo)(()=>!L||k?e:e.filter(e=>e.enabled!==!1||bn(e,a)),[e,L,k,a]),ee=(0,Q.useMemo)(()=>{let e=C.trim().toLowerCase(),t=R;return T&&(t=t.filter(e=>e.provider===T.provider)),gn(e?t.filter(t=>t.name.toLowerCase().includes(e)||t.id.toLowerCase().includes(e)||t.provider.toLowerCase().includes(e)):t,D)},[R,C,T,D]),z=(0,Q.useMemo)(()=>{let e=new Map;for(let t of R)e.set(t.provider,(e.get(t.provider)??0)+1);let t=[];for(let[r,i]of[...e.entries()].sort((e,t)=>e[0].localeCompare(t[0]))){let e=n[r];if(e&&e.length>1)for(let n of e)t.push({provider:r,count:i,keyName:n.name});else t.push({provider:r,count:i,keyName:null})}return t},[R,n]),te=(0,Q.useMemo)(()=>{let e=[];for(let t of ee){let r=null,i=n[t.provider];if(i&&i.length>1&&(r=i.find(e=>e.active)??i[0],T?.provider===t.provider&&T.keyName)){let e=i.find(e=>e.name===T.keyName);e&&(r=e)}let o=h?h(t,r):bn(t,a)&&(!r||r.active);e.push({model:t,key:r,active:o})}return e},[ee,n,T,h,a]),B=i!==void 0;return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`dd-header dd-header-flex`,children:[!y&&(0,Z.jsx)(`span`,{className:`dd-header-title`,children:S(`availableModels`)}),(0,Z.jsxs)(`div`,{className:`dd-header-actions`,style:y?{marginLeft:`auto`}:void 0,children:[!!i&&(0,Z.jsxs)(`div`,{className:`dd-header-default`,title:S(`defaultModelLabel`,{model:i??``}),children:[(0,Z.jsx)(`span`,{className:`dd-header-default-star`,children:`★`}),(0,Z.jsx)(`span`,{className:`dd-header-default-name`,children:i.includes(`/`)?i.split(`/`).slice(1).join(`/`):i}),(0,Z.jsx)(`button`,{type:`button`,className:`dd-header-default-clear`,title:S(`clearDefaultModel`),onClick:e=>{e.stopPropagation(),W({type:`clear_default_model`})},children:`✕`})]}),L&&(0,Z.jsx)(`button`,{type:`button`,className:`dd-scope-toggle ${k?`active`:``}`,onClick:()=>A(e=>!e),title:k?S(`showEnabledModelsTitle`,{n:I}):S(`showAllModelsTitle`,{n:e.length}),children:k?S(`showEnabledModels`,{n:I}):S(`showAllModels`,{n:e.length})}),(0,Z.jsx)(`button`,{type:`button`,className:`dd-header-btn dd-refresh-btn`,onClick:l,title:S(`refreshModels`),"aria-label":S(`refreshModels`),children:(0,Z.jsx)(d,{className:c||t?`spin`:``})}),u&&(0,Z.jsx)(`button`,{type:`button`,className:`dd-header-btn dd-manage-btn`,onClick:u,title:S(`manageModels`),"aria-label":S(`manageModels`),children:(0,Z.jsx)(m,{})})]})]}),(0,Z.jsxs)(`div`,{className:`dd-search-row`,children:[(0,Z.jsx)(De,{}),(0,Z.jsx)(`input`,{className:`dd-search`,type:`text`,autoFocus:v,placeholder:S(`searchModels`),value:C,onChange:e=>w(e.target.value)})]}),P&&(0,Z.jsxs)(`button`,{type:`button`,className:`dd-current-row`,title:S(`currentModelHint`),onClick:F,children:[(0,Z.jsx)(`span`,{className:`dd-current-tag`,children:S(`currentModelLabel`)}),(0,Z.jsx)(`span`,{className:`dd-current-name`,children:P.modelName}),(0,Z.jsx)(`span`,{className:`dd-current-provider`,title:P.provider,children:P.providerLabel}),P.keyName&&(0,Z.jsx)(`span`,{className:`dd-current-key`,children:P.keyName})]}),(0,Z.jsxs)(`div`,{className:`dd-model-body`,style:b,children:[z.length>1&&(0,Z.jsxs)(`div`,{className:`dd-provider-col`,children:[(0,Z.jsx)(`div`,{className:`dd-provider-head`,children:S(`providers`)}),(0,Z.jsx)(`button`,{type:`button`,className:`dd-provider-item ${T===null?`active`:``}`,onClick:()=>E(null),children:(0,Z.jsx)(`span`,{children:S(`allProviders`)})}),z.map(e=>{let t=T?.provider===e.provider&&T?.keyName===e.keyName;return(0,Z.jsxs)(`button`,{type:`button`,className:`dd-provider-item ${t?`active`:``}`,onClick:()=>E(t?null:{provider:e.provider,keyName:e.keyName}),title:e.keyName?`${xn(e.provider,r)} (${e.provider}) · ${e.keyName}`:`${xn(e.provider,r)} (${e.provider}) · ${e.count}`,children:[(0,Z.jsxs)(`span`,{className:`dd-provider-txt`,children:[(0,Z.jsx)(`span`,{className:`dd-provider-name`,children:xn(e.provider,r)}),e.keyName&&(0,Z.jsx)(`span`,{className:`dd-provider-key`,children:e.keyName})]}),(0,Z.jsx)(`span`,{className:`dd-provider-count`,children:e.count})]},e.keyName?`${e.provider}::${e.keyName}`:e.provider)})]}),(0,Z.jsxs)(`div`,{className:`dd-model-scroll`,ref:N,style:x,children:[(c||t)&&(0,Z.jsx)(`div`,{className:`dd-loading`,children:S(`loading`)}),e.length===0&&!c&&!t&&(0,Z.jsx)(`div`,{className:`dd-loading`,children:S(`noModels`)}),g,ee.length===0&&R.length>0&&(0,Z.jsxs)(`div`,{className:`dd-loading`,children:[(0,Z.jsx)(`div`,{children:S(`noModelMatches`)}),L&&!k&&(0,Z.jsx)(`button`,{type:`button`,className:`dd-scope-switch-link`,onClick:()=>A(!0),children:S(`searchAllModelsHint`,{n:e.length})})]}),te.map(e=>{let t=e.model,n=i!==void 0&&i===t.id;return(0,Z.jsxs)(Ie,{active:e.active,onClick:()=>f(t,e.key),children:[(0,Z.jsxs)(`span`,{className:`dd-model-cell`,children:[(0,Z.jsxs)(`span`,{className:`dd-model-head`,children:[(0,Z.jsx)(`span`,{className:`dd-model-name`,children:t.name}),e.active&&(0,Z.jsx)(`span`,{className:`dd-model-current`,children:S(`currentModelBadge`)})]}),(0,Z.jsxs)(`span`,{className:`dd-model-meta`,children:[(0,Z.jsx)(`span`,{className:`dd-model-provider`,title:t.provider,children:xn(t.provider,r)}),(0,Z.jsx)(`span`,{className:`dd-model-id`,children:t.id.includes(`/`)?t.id.split(`/`).slice(1).join(`/`):t.id}),e.key&&(0,Z.jsxs)(`span`,{className:`dd-model-key ${e.key.active?`active`:``}`,children:[e.key.active?`●`:`○`,` `,e.key.name]}),(D[t.id]??0)>0&&(0,Z.jsx)(`span`,{className:`dd-model-usage`,children:S(`modelUsedCount`,{n:D[t.id]})}),(t.reasoning||t.vision||k&&t.enabled===!1)&&(0,Z.jsxs)(`span`,{className:`dd-model-badges`,children:[t.reasoning&&(0,Z.jsx)(`span`,{className:`dd-model-badge`,children:S(`reasoning`)}),t.vision&&(0,Z.jsx)(`span`,{className:`dd-model-badge`,children:S(`vision`)}),k&&t.enabled===!1&&(0,Z.jsx)(`span`,{className:`dd-model-badge out-of-scope`,children:S(`notInScopeBadge`)})]})]})]}),B&&(p?(0,Z.jsx)(`button`,{type:`button`,className:`dd-star-btn ${n?`active`:``}`,title:S(n?`cancelDefaultTooltip`:`setDefaultTooltip`),onClick:e=>{e.stopPropagation(),p(t,n)},children:n?`★`:`☆`}):(0,Z.jsx)(`span`,{className:`dd-star-btn ${n?`active`:``}`,children:n?`★`:`☆`}))]},e.key?`${t.id}::${e.key.name}`:t.id)})]})]})]})}function Tn({title:e,entries:t,selected:n,onChange:r,disabled:i,pending:a}){let o=U(),s=(0,Q.useId)(),[c,l]=(0,Q.useState)(``),u=new Set(t.map(e=>e.id)),d=n.filter(e=>!u.has(e)),f=[...t,...d.map(e=>({id:e,name:e}))],p=c.trim().toLowerCase(),m=f.filter(e=>[e.name,e.id,e.description,e.path].some(e=>e?.toLowerCase().includes(p))),h=m.filter(e=>u.has(e.id)&&e.status!==`disabled`);return(0,Z.jsxs)(`fieldset`,{className:`dc-bot-catalog`,disabled:i,children:[(0,Z.jsxs)(`legend`,{children:[e,` `,(0,Z.jsxs)(`span`,{className:`dc-bot-count`,children:[n.length,` `,o(`localBotSelected`)]})]}),(0,Z.jsxs)(`div`,{className:`dc-bot-catalog-actions`,children:[(0,Z.jsx)(`input`,{type:`search`,"aria-label":`${o(`localBotSearch`)} ${e}`,placeholder:o(`localBotSearch`),value:c,onChange:e=>l(e.target.value)}),(0,Z.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:a||!h.length,onClick:()=>r([...new Set([...n,...h.map(e=>e.id)])]),children:o(p?`localBotSelectVisible`:`localBotSelectAll`)}),(0,Z.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:!n.length,onClick:()=>r([]),children:o(`localBotClear`)})]}),(0,Z.jsxs)(`div`,{className:`dc-bot-catalog-list`,children:[m.map((e,t)=>(0,Z.jsxs)(`label`,{className:`dc-bot-option${n.includes(e.id)?` is-selected`:``}`,htmlFor:`${s}-${t}`,children:[(0,Z.jsx)(`input`,{id:`${s}-${t}`,type:`checkbox`,checked:n.includes(e.id),disabled:e.status===`disabled`&&!n.includes(e.id),onChange:t=>r(t.target.checked?[...new Set([...n,e.id])]:n.filter(t=>t!==e.id))}),(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(`strong`,{children:e.name}),e.warning===`high_privilege`&&(0,Z.jsx)(`small`,{children:o(`localBotToolHighPrivilege`)}),e.warning===`unsupported_platform`&&(0,Z.jsx)(`small`,{children:o(`localBotToolUnsupportedPlatform`)}),!u.has(e.id)&&(0,Z.jsx)(`small`,{children:o(a?`localBotUnverified`:`localBotUnavailable`)}),e.description&&(0,Z.jsx)(`small`,{className:`dc-bot-option-description`,title:e.description,children:e.description}),e.status===`not_loaded`&&(0,Z.jsx)(`small`,{children:o(`localBotMcpNotLoaded`)}),e.status===`disabled`&&(0,Z.jsx)(`small`,{children:o(`localBotMcpDisabled`)}),e.source&&e.source!==`builtin`&&(0,Z.jsx)(`small`,{className:`dc-bot-option-source`,children:e.source}),e.path&&(0,Z.jsx)(`small`,{className:`dc-bot-option-path`,title:e.path,children:e.path})]})]},e.id)),!m.length&&(0,Z.jsx)(`p`,{children:o(a?`localBotOptionsLoading`:`localBotNoOptions`)})]})]})}var En=e=>e.id.startsWith(`${e.provider}/`)?e.id.slice(e.provider.length+1):e.id;function Dn(e){let[t,n]=(0,Q.useState)(null),[r,i]=(0,Q.useState)(!1),[a,o]=(0,Q.useState)(``),[s,c]=(0,Q.useState)(0);return(0,Q.useEffect)(()=>{if(!e)return;let t=new AbortController;return i(!0),o(``),Ne(`/api/device-center/local-bot-options`,{method:`GET`,credentials:`same-origin`,signal:t.signal}).then(async e=>{let t=await e.json();if(!e.ok)throw Error(t.error||String(e.status));return t}).then(e=>{t.signal.aborted||(n(e),i(!1))}).catch(e=>{t.signal.aborted||(o(e instanceof Error?e.message:String(e)),i(!1))}),()=>t.abort()},[e,s]),{options:t,loading:r,error:a,reload:(0,Q.useCallback)(()=>c(e=>e+1),[])}}var On=[`soul`,`context`,`tools`,`markers`,`skills`,`cwd`,`append`,`plugin_dev`,`execution`,`memory`],kn=new Set([`soul`,`context`,`markers`,`append`,`plugin_dev`]),An=[`soul`,`context`,`tools`,`skills`,`cwd`,`append`,`execution`,`memory`],jn=[`tools`,`skills`,`cwd`,`memory`];function Mn(e){return Array.isArray(e.promptSections)?e.promptSections:e.useGlobalPrompt===!1?[...jn]:[...An]}function Nn({value:e,onChange:t,options:n,optionsLoading:r,optionsError:i,onReloadOptions:a,busy:o=!1,baseCwd:s=``,variant:c=`dialog`,modelPortalTarget:l,modelOpen:u,onModelOpenChange:d,dialogChrome:f}){let p=U(),m=(0,Q.useId)(),[h,g]=(0,Q.useState)(`identity`),[_,v]=(0,Q.useState)(`tools`),[y,b]=(0,Q.useState)(!1),x=u??y,S=(0,Q.useCallback)(e=>{d?d(e):b(e)},[d]),C=(0,Q.useRef)(s||e.cwd);s&&(C.current=s);let[w,T]=(0,Q.useState)(null),[E,D]=(0,Q.useState)(!1),[O,k]=(0,Q.useState)(``),{copied:A,copy:j}=Be({duration:1500}),M=Mn(e);(0,Q.useEffect)(()=>{if(h!==`identity`)return;let t=new AbortController,n=setTimeout(()=>{D(!0),k(``),Me(`/api/device-center/local-bot-prompt-preview`,{body:{id:e.id,systemPrompt:e.systemPrompt,cwd:e.cwd,tools:e.tools,skills:e.skills,promptSections:e.promptSections,useGlobalPrompt:e.useGlobalPrompt},signal:t.signal}).then(e=>{t.signal.aborted||(T(e),D(!1))}).catch(e=>{t.signal.aborted||(k(e instanceof Error?e.message:String(e)),D(!1))})},220);return()=>{clearTimeout(n),t.abort()}},[h,e.id,e.systemPrompt,e.cwd,e.tools,e.skills,e.promptSections,e.useGlobalPrompt]);let N=(0,Q.useCallback)(n=>{let r=n.some(e=>kn.has(e));t({...e,promptSections:n,useGlobalPrompt:r})},[t,e]);je(()=>S(!1),x);let P=n?.models.find(t=>t.provider===e.model?.provider&&En(t)===e.model?.modelId),F=c===`inline`,I=!F&&!!f,L=F?m:`bot`,R=F?`${m}-cwd`:`local-bot-cwd`,ee=F?5:3,z=[[`identity`,p(`localBotIdentity`),void 0],[`runtime`,p(`localBotRuntime`),void 0],[`permissions`,p(`localBotPermissions`),e.tools.length+e.skills.length+e.mcpServers.length]],te=(0,Z.jsx)(`div`,{className:I?`dc-bot-b-nav`:F?`bot-form-tabs`:`dc-bot-tabs`,role:`tablist`,"aria-label":p(`localBotTitle`),children:z.map(([e,t,n],r,i)=>(0,Z.jsxs)(`button`,{type:`button`,role:`tab`,id:`${L}-tab-${e}`,"aria-controls":`${L}-panel-${e}`,"aria-selected":h===e,tabIndex:h===e?0:-1,onClick:()=>g(e),onKeyDown:e=>{let t=r;if(e.key===`ArrowRight`||I&&e.key===`ArrowDown`)t=(r+1)%i.length;else if(e.key===`ArrowLeft`||I&&e.key===`ArrowUp`)t=(r+i.length-1)%i.length;else if(e.key===`Home`)t=0;else if(e.key===`End`)t=i.length-1;else return;e.preventDefault(),g(i[t][0]),document.getElementById(`${L}-tab-${i[t][0]}`)?.focus()},children:[(0,Z.jsx)(`span`,{children:t}),n!==void 0&&n>0&&(0,Z.jsx)(`span`,{style:{fontSize:`11px`,opacity:.65},children:n})]},e))}),B=z.find(([e])=>e===h)?.[1]??p(`localBotIdentity`),V=(0,Z.jsxs)(`div`,{className:F?`bot-form-body`:void 0,children:[(0,Z.jsx)(`div`,{role:`tabpanel`,id:`${L}-panel-identity`,"aria-labelledby":`${L}-tab-identity`,hidden:h!==`identity`,children:(0,Z.jsxs)(`div`,{className:F?`bot-form-stack`:`dc-bot-section`,style:F?void 0:{gap:`12px`},children:[(0,Z.jsxs)(`div`,{className:F?void 0:`dc-bot-row-2`,children:[(0,Z.jsxs)(`label`,{className:F?`bot-form-field`:`dc-field`,children:[(0,Z.jsx)(`span`,{children:p(`localBotName`)}),(0,Z.jsx)(`input`,{required:!0,disabled:o,value:e.name,onChange:n=>t({...e,name:n.target.value})})]}),(0,Z.jsxs)(`label`,{className:F?`bot-form-field`:`dc-field`,children:[(0,Z.jsx)(`span`,{children:p(`localBotDescription`)}),(0,Z.jsx)(`textarea`,{rows:F?2:1,disabled:o,value:e.description,onChange:n=>t({...e,description:n.target.value}),style:F?void 0:{minHeight:`36px`,resize:`none`}})]})]}),(0,Z.jsxs)(`label`,{className:F?`bot-form-field`:`dc-field`,children:[(0,Z.jsx)(`span`,{children:p(`localBotSystemPrompt`)}),(0,Z.jsx)(`textarea`,{rows:ee,className:F?`bot-form-prompt`:`dc-bot-prompt`,spellCheck:!1,disabled:o,value:e.systemPrompt,onChange:n=>t({...e,systemPrompt:n.target.value})})]}),(0,Z.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`6px`},children:[(0,Z.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,justifyContent:`space-between`,gap:`8px`,flexWrap:`wrap`},children:[(0,Z.jsx)(`span`,{style:{fontSize:`12px`,fontWeight:500,color:`var(--text-dim)`},children:p(`localBotPromptComposition`)}),(0,Z.jsxs)(`div`,{style:{display:`inline-flex`,gap:`4px`,flexWrap:`wrap`},children:[(0,Z.jsx)(`button`,{type:`button`,className:`dc-button`,style:{padding:`3px 8px`,fontSize:`11px`},disabled:o,onClick:()=>N([...On]),children:p(`localBotSelectAll`)}),(0,Z.jsx)(`button`,{type:`button`,className:`dc-button`,style:{padding:`3px 8px`,fontSize:`11px`},disabled:o,onClick:()=>N([]),children:p(`localBotPromptPureOnly`)}),(0,Z.jsx)(`button`,{type:`button`,className:`dc-button`,style:{padding:`3px 8px`,fontSize:`11px`},disabled:o,onClick:()=>N([...An]),children:p(`localBotPromptResetDefault`)})]})]}),(0,Z.jsx)(`div`,{className:`dc-bot-chips`,children:On.map(e=>{let t=M.includes(e),n=w?.sections.find(t=>t.id===e),r=`promptTok_${e}`,i=`promptTok_${e}_desc`;return(0,Z.jsxs)(`label`,{className:`dc-bot-chip${t?` is-on`:``}`,title:p(i),children:[(0,Z.jsx)(`input`,{type:`checkbox`,disabled:o,checked:t,onChange:t=>{let n=t.target.checked?[...M,e]:M.filter(t=>t!==e);N(n)}}),(0,Z.jsx)(`span`,{children:p(r)}),n&&(0,Z.jsx)(`span`,{className:`tok dc-bot-chip-tok`,children:n.tokens})]},e)})})]}),(0,Z.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`6px`},children:[(0,Z.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,justifyContent:`space-between`,gap:`8px`},children:[(0,Z.jsxs)(`span`,{style:{fontSize:`12px`,fontWeight:500,color:`var(--text-dim)`},children:[p(`localBotPromptFullPreview`),w?` (≈${w.totalTokens} tokens)`:``]}),(0,Z.jsx)(`button`,{type:`button`,className:`dc-button`,style:{padding:`3px 8px`,fontSize:`11px`},disabled:!w?.full,onClick:()=>{w?.full&&j(w.full)},children:p(A?`localBotPromptCopied`:`localBotPromptCopy`)})]}),O&&(0,Z.jsx)(`small`,{role:`alert`,style:{color:`var(--err-text, #e5534b)`},children:O}),(0,Z.jsx)(`textarea`,{readOnly:!0,rows:F?5:4,className:F?`bot-form-prompt`:`dc-bot-prompt`,spellCheck:!1,value:E&&!w?p(`localBotPromptPreviewLoading`):w?.full??``,style:{width:`100%`,minHeight:F?void 0:`88px`,opacity:E?.75:1,fontFamily:`var(--mono)`,fontSize:`11.5px`,lineHeight:1.5,padding:`8px 10px`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`7px`,color:`var(--text)`}})]})]})}),(0,Z.jsx)(`div`,{role:`tabpanel`,id:`${L}-panel-runtime`,"aria-labelledby":`${L}-tab-runtime`,hidden:h!==`runtime`,children:(0,Z.jsxs)(`div`,{className:F?`bot-form-stack`:`dc-bot-section`,children:[(0,Z.jsxs)(`div`,{className:F?`bot-form-field`:`dc-field`,children:[(0,Z.jsx)(`label`,{htmlFor:R,children:p(`localBotCwd`)}),(0,Z.jsx)(fn,{inputId:R,commitOnBlur:!0,cwd:e.cwd,baseCwd:C.current||e.cwd,projects:n?.projects.map(e=>({...e,lastUsed:0}))??[],disabled:o,onSelectCwd:n=>t({...e,cwd:Lt(n,C.current||e.cwd)})})]}),(0,Z.jsxs)(`div`,{className:F?`bot-form-field`:`dc-field`,children:[(0,Z.jsx)(`span`,{children:p(`localBotModel`)}),(0,Z.jsxs)(`div`,{className:`dc-actions`,children:[(0,Z.jsx)(`button`,{className:`dc-button`,type:`button`,disabled:o,"aria-haspopup":`dialog`,onClick:()=>S(!0),children:e.model?P?.name??`${e.model.provider}/${e.model.modelId}`:p(`localBotInheritModel`)}),e.model&&(0,Z.jsx)(`button`,{className:`dc-button`,type:`button`,disabled:o,onClick:()=>t({...e,model:void 0}),children:p(`localBotInheritModel`)})]}),e.model&&!P&&(0,Z.jsx)(`small`,{children:p(r?`localBotUnverified`:`localBotUnavailable`)})]})]})}),(0,Z.jsxs)(`div`,{role:`tabpanel`,id:`${L}-panel-permissions`,"aria-labelledby":`${L}-tab-permissions`,hidden:h!==`permissions`,children:[(0,Z.jsxs)(`div`,{className:`dc-bot-options-status`,"aria-live":`polite`,children:[r&&(0,Z.jsx)(`span`,{children:p(`localBotOptionsLoading`)}),i&&(0,Z.jsx)(`span`,{role:`alert`,children:i}),(0,Z.jsx)(`button`,{className:`dc-button`,type:`button`,disabled:r||o,onClick:a,children:p(i?`deviceHubRetry`:`localBotReload`)})]}),(0,Z.jsx)(`div`,{className:`dc-bot-catalog-tabs`,role:`tablist`,"aria-label":p(`localBotPermissions`),children:[[`tools`,p(`localBotTools`)],[`skills`,p(`localBotSkills`)],[`mcpServers`,p(`localBotMcpServers`)]].map(([t,n])=>(0,Z.jsxs)(`button`,{type:`button`,role:`tab`,id:`${m}-catalog-tab-${t}`,"aria-controls":`${m}-catalog-${t}`,"aria-selected":_===t,onClick:()=>v(t),children:[n,(0,Z.jsx)(`span`,{children:e[t].length})]},t))}),(0,Z.jsx)(`div`,{className:`dc-bot-permissions`,children:[[`tools`,p(`localBotTools`)],[`skills`,p(`localBotSkills`)],[`mcpServers`,p(`localBotMcpServers`)]].map(([a,s])=>(0,Z.jsx)(`div`,{role:`tabpanel`,id:`${m}-catalog-${a}`,"aria-labelledby":`${m}-catalog-tab-${a}`,hidden:_!==a,children:(0,Z.jsx)(Tn,{title:s,entries:n?.[a]??[],selected:e[a],disabled:o,pending:r||!!i,onChange:n=>t({...e,[a]:n})})},a))})]})]});return(0,Z.jsxs)(Z.Fragment,{children:[I&&f?(0,Z.jsxs)(`div`,{className:`dc-bot-b-shell`,children:[(0,Z.jsxs)(`aside`,{className:`dc-bot-b-rail`,children:[f.railHeader,te,f.railFooter]}),(0,Z.jsxs)(`div`,{className:`dc-bot-b-main`,children:[(0,Z.jsxs)(`header`,{className:`dc-bot-b-head`,children:[(0,Z.jsx)(`strong`,{children:B}),f.closeButton]}),(0,Z.jsxs)(`div`,{className:`dc-bot-b-body`,children:[f.errorBanner,V]}),(0,Z.jsx)(`footer`,{className:`dc-actions dc-bot-b-foot`,children:f.footer})]})]}):(0,Z.jsxs)(`div`,{className:`bot-form${F?` is-inline`:``}`,children:[te,V]}),x&&(0,Bt.createPortal)((0,Z.jsx)(`div`,{className:`modal-backdrop dc-bot-model-backdrop`,onClick:e=>{e.target===e.currentTarget&&S(!1)},children:(0,Z.jsxs)(`div`,{className:`dc-bot-model-modal dd-menu-model`,role:`dialog`,"aria-modal":`true`,"aria-label":p(`localBotModel`),children:[(0,Z.jsxs)(`div`,{className:`dg-heading`,children:[(0,Z.jsx)(`h3`,{children:p(`localBotModel`)}),(0,Z.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>S(!1),children:p(`localBotCancel`)})]}),(0,Z.jsx)(wn,{models:n?.models??[],modelsLoading:r,defaultModel:n?.defaultModel,currentModelId:e.model?`${e.model.provider}/${e.model.modelId}`:null,active:!0,onEnsureModels:()=>{},onRefresh:a,onPickModel:n=>{t({...e,model:{provider:n.provider,modelId:En(n)}}),S(!1)},isRowActive:t=>t.provider===e.model?.provider&&En(t)===e.model.modelId,extraTopRow:(0,Z.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>{t({...e,model:void 0}),S(!1)},children:p(`localBotInheritModel`)}),autoFocusSearch:!0,hideTitle:!0,bodyStyle:{flex:1,minHeight:0},scrollStyle:{overflowY:`auto`,minHeight:0}}),i&&(0,Z.jsx)(`p`,{role:`alert`,children:i})]})}),l??document.body)]})}var Pn=(e=``)=>({name:``,description:``,systemPrompt:``,useGlobalPrompt:!0,cwd:e,tools:[],skills:[],mcpServers:[],enabled:!0});async function Fn(e,t,n){let r=await fetch(u(H(`/api/device-center/${e}`)),{method:n?`POST`:`GET`,credentials:`same-origin`,signal:t,...n?{headers:{"Content-Type":`application/json`},body:JSON.stringify(n)}:{}}),i=await r.json();if(!r.ok)throw Error(i.error||String(r.status));return i}function In({createOnly:e=!1,initialCwd:t,editBot:n,onCreated:r,onFinished:i,onCancel:a}){let o=U(),[s,c]=(0,Q.useState)([]),[l,u]=(0,Q.useState)(null),[d,f]=(0,Q.useState)(()=>n?structuredClone(n):e?Pn(t??``):null),p=()=>{f(null),a?.()},[m,h]=(0,Q.useState)(!1),[g,_]=(0,Q.useState)(``),[v,y]=(0,Q.useState)(``),[b,x]=(0,Q.useState)(null),[S,C]=(0,Q.useState)(``),[w,T]=(0,Q.useState)(!1),[E,D]=(0,Q.useState)(0),[O,k]=(0,Q.useState)(!1),[A,j]=(0,Q.useState)(!1),M=(0,Q.useRef)(null),N=(0,Q.useRef)(null),P=e,F=(0,Q.useRef)(``),I=(0,Q.useRef)(null),L=d!==null,R=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{if(R.current=!1,!L)return;let e=I.current,t=document.activeElement,n=document.body.style.overflow;return document.body.style.overflow=`hidden`,e?.showModal?.(),()=>{e?.close?.(),document.body.style.overflow=n,t?.focus()}},[L]),(0,Q.useEffect)(()=>{if(P)return;let e=new AbortController;return Fn(`local-bots`,e.signal).then(t=>{if(!e.signal.aborted){if(!Array.isArray(t.bots))throw Error(`Invalid Bot list`);c(t.bots)}}).catch(t=>{e.signal.aborted||_(String(t))}),()=>e.abort()},[P]),(0,Q.useEffect)(()=>()=>N.current?.abort(),[]);let ee=async e=>{j(!0),_(``);try{let t=await It(e);y(o(`agentBotsImportReceipt`,{name:t.name,imported:t.imported,skipped:t.skipped})),D(e=>e+1),Fn(`local-bots`,new AbortController().signal).then(e=>{Array.isArray(e.bots)&&c(e.bots)}).catch(()=>{})}catch(e){_(e instanceof Error?e.message:o(`localBotImportFailed`))}finally{j(!1)}},z=d?.cwd;(0,Q.useEffect)(()=>{if(z===void 0)return;let e=new AbortController;return T(!0),C(``),x(null),Fn(z?`local-bot-options?cwd=${encodeURIComponent(z)}`:`local-bot-options`,e.signal).then(t=>{if(e.signal.aborted)return;if(![t.models,t.tools,t.skills,t.mcpServers,t.projects].every(Array.isArray)||!t.defaultCwd||!t.cwd)throw Error(o(`localBotOptionsInvalid`));F.current=t.defaultCwd,x(t);let n=!R.current;R.current=!0,f(e=>e&&{...e,...e.cwd?{}:{cwd:t.cwd},...n&&!e.id?{tools:[...t.defaultTools??[]]}:{}})}).catch(t=>{e.signal.aborted||C(String(t))}).finally(()=>{e.signal.aborted||T(!1)}),()=>e.abort()},[z,E]);async function te(e=!1){if(!d||m)return;let t=new AbortController;N.current=t,h(!0),_(``),y(``);try{let n=await Fn(e?`local-bots/${encodeURIComponent(d.id)}/delete`:`local-bots`,t.signal,e?{revision:d.revision}:d);if(t.signal.aborted)return;c(t=>e?t.filter(e=>e.id!==d.id):[...t.filter(e=>e.id!==n.bot.id),n.bot]),f(null),k(!1),y(n.synced===!1?o(`localBotSyncFailed`):o(`localBotSaved`)),e||r?.(n.bot,n.synced!==!1),i?.(),window.dispatchEvent(new CustomEvent(`pi-web-ui:device-bots-changed`))}catch(e){t.signal.aborted||_(e instanceof Error?e.message:String(e))}finally{t.signal.aborted||h(!1)}}async function B(e){if(!l){u(e),_(``);try{gt(e)}catch(e){_(e instanceof Error?e.message:String(e))}finally{u(null)}}}return(0,Z.jsxs)(`section`,{className:`dc-card dc-bots${P?` is-solo`:``}`,"aria-label":o(`localBotTitle`),children:[(0,Z.jsxs)(`div`,{className:`dg-heading`,children:[(0,Z.jsx)(`h2`,{children:o(`localBotTitle`)}),(0,Z.jsxs)(`div`,{className:`dc-bots-actions`,children:[(0,Z.jsx)(`button`,{className:`dc-button`,type:`button`,disabled:m,onClick:()=>{f(Pn()),_(``),k(!1)},children:o(`localBotCreate`)}),(0,Z.jsx)(`button`,{className:`dc-button`,type:`button`,disabled:m||A,title:o(`localBotImportTip`),onClick:()=>M.current?.click(),children:o(A?`localBotImporting`:`localBotImport`)}),(0,Z.jsx)(`input`,{ref:M,type:`file`,accept:`application/json,.json`,hidden:!0,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t&&ee(t)}})]})]}),(0,Z.jsx)(`p`,{children:o(`localBotHint`)}),g&&!d&&(0,Z.jsx)(`p`,{role:`alert`,children:g}),v&&(0,Z.jsx)(`p`,{role:`status`,children:v}),(0,Z.jsxs)(`div`,{className:`dc-bot-workspace${d?` is-editing`:``}`,children:[(0,Z.jsx)(`div`,{className:`dc-bot-list`,"aria-label":o(`localBotTitle`),children:s.map(e=>(0,Z.jsxs)(`div`,{className:`dc-bot-entry`,children:[(0,Z.jsxs)(`button`,{className:`dc-button dc-bot-item${d?.id===e.id?` is-selected`:``}`,"aria-pressed":d?.id===e.id,disabled:m,onClick:()=>{f(structuredClone(e)),_(``),k(!1)},children:[(0,Z.jsx)(`span`,{className:`dc-bot-avatar`,"aria-hidden":`true`,children:e.name.slice(0,2).toUpperCase()}),(0,Z.jsxs)(`span`,{className:`dc-bot-item-copy`,children:[(0,Z.jsx)(`strong`,{children:e.name}),(0,Z.jsxs)(`small`,{className:e.enabled?`is-enabled`:``,children:[e.enabled?o(`localBotEnabled`):o(`localBotDisabled`),` · r`,e.revision]}),e.cwd.startsWith(`ssh://`)&&(0,Z.jsx)(`small`,{title:e.cwd,children:o(`nativeCliRemoteLocation`,{host:e.cwd.replace(/^ssh:\/\/([^@]+)@([^:/]+).*$/,`$1@$2`)})})]})]}),(0,Z.jsx)(`button`,{type:`button`,className:`dc-bot-chat`,title:o(`botChat`,{name:e.name}),"aria-label":o(`botChat`,{name:e.name}),disabled:m||l!==null,onClick:()=>void B(e.id),children:l===e.id?`…`:o(`botChatShort`)})]},e.id))}),d&&(0,Z.jsx)(`dialog`,{ref:I,className:`dc-bot-drawer`,"aria-label":o(`localBotTitle`),onCancel:e=>{e.preventDefault(),!m&&!O&&p()},onClick:e=>{if(e.target!==e.currentTarget||m)return;let t=e.currentTarget.getBoundingClientRect();(e.clientX<t.left||e.clientX>t.right||e.clientY<t.top||e.clientY>t.bottom)&&p()},children:(0,Z.jsx)(`form`,{className:`dc-bot-editor`,onSubmit:e=>{e.preventDefault(),te()},children:(0,Z.jsx)(Nn,{variant:`dialog`,value:d,onChange:e=>f({...d,...e}),options:b,optionsLoading:w,optionsError:S,onReloadOptions:()=>D(e=>e+1),busy:m,baseCwd:F.current||d.cwd,modelPortalTarget:I.current??document.body,modelOpen:O,onModelOpenChange:k,dialogChrome:{railHeader:(0,Z.jsxs)(`div`,{className:`dc-bot-b-badge`,children:[(0,Z.jsx)(`span`,{className:`dc-bot-avatar`,"aria-hidden":`true`,children:d.name.slice(0,2).toUpperCase()||`B`}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{children:d.name||o(`localBotCreate`)}),d.id&&(0,Z.jsxs)(`small`,{children:[d.id,` · r`,d.revision]})]})]}),railFooter:(0,Z.jsxs)(`div`,{className:`dc-bot-b-rail-foot`,children:[(0,Z.jsxs)(`label`,{className:`dc-bot-enabled`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,role:`switch`,disabled:m,checked:d.enabled,onChange:e=>f({...d,enabled:e.target.checked})}),o(`localBotEnable`)]}),d.id&&(0,Z.jsx)(`button`,{className:`dc-button is-danger`,type:`button`,style:{width:`100%`},disabled:m,onClick:()=>{window.confirm(o(`localBotDeleteConfirm`))&&te(!0)},children:o(`localBotDelete`)})]}),closeButton:(0,Z.jsx)(`button`,{className:`dc-button dc-bot-drawer-close`,type:`button`,"aria-label":o(`localBotCancel`),disabled:m,onClick:p,children:`×`}),errorBanner:g?(0,Z.jsx)(`p`,{className:`dc-bot-error`,role:`alert`,children:g}):void 0,footer:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`button`,{className:`dc-button`,type:`button`,disabled:m,onClick:()=>{p(),k(!1)},children:o(`localBotCancel`)}),(0,Z.jsx)(`button`,{className:`dc-button dc-bot-save`,disabled:m||!d.cwd||!d.name.trim(),children:o(`localBotSave`)})]})}})})})]})]})}function Ln({room:e,onClose:t}){let n=U(),[r,i]=(0,Q.useState)([]),[a,o]=(0,Q.useState)(e.botIds),[s,c]=(0,Q.useState)([]),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(!0),[p,m]=(0,Q.useState)(!1),[h,g]=(0,Q.useState)(``),[_,v]=(0,Q.useState)(0),y=(0,Q.useRef)(null),b=()=>{!p&&!l&&t()};je(b),(0,Q.useEffect)(()=>()=>y.current?.abort(),[]),(0,Q.useEffect)(()=>{let t=new AbortController;return f(!0),Promise.all([Zn(`bots`,t.signal),Zn(`rooms/${encodeURIComponent(e.id)}`,t.signal)]).then(([e,n])=>{t.signal.aborted||(i(e.bots),o(n.room.botIds))}).catch(e=>{t.signal.aborted||g(e instanceof Error?e.message:String(e))}).finally(()=>{t.signal.aborted||f(!1)}),()=>t.abort()},[e.id,_]);async function x(n){if(y.current)return;let r=new AbortController;y.current=r,m(!0),g(``);try{let i=`rooms/${encodeURIComponent(e.id)}`,a=await Zn(i,r.signal);if(r.signal.aborted||(await Zn(`${i}/members`,r.signal,{botIds:[...new Set([...a.room.botIds,...n])]}),r.signal.aborted))return;window.dispatchEvent(new CustomEvent(Un)),t()}catch(e){r.signal.aborted||g(e instanceof Error?e.message:String(e))}finally{y.current=null,r.signal.aborted||m(!1)}}return(0,Bt.createPortal)((0,Z.jsx)(`div`,{className:`modal-backdrop`,onClick:b,children:(0,Z.jsxs)(`div`,{className:`device-group-bot-dialog`,role:`dialog`,"aria-modal":`true`,"aria-label":n(`deviceGroupSectionAddOrCreateBot`),onClick:e=>e.stopPropagation(),children:[(0,Z.jsxs)(`div`,{className:`dg-heading`,children:[(0,Z.jsxs)(`h2`,{children:[n(`deviceGroupSectionAddBot`),` · `,e.name]}),(0,Z.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:p||l,onClick:b,children:n(`close`)})]}),h&&(0,Z.jsx)(`p`,{className:`dc-notice is-error`,role:`alert`,children:h}),(0,Z.jsx)(`p`,{children:n(`deviceGroupBotDialogLead`)}),d?(0,Z.jsx)(`p`,{children:n(`loading`)}):(0,Z.jsxs)(`div`,{className:`dg-bot-choices`,children:[r.filter(e=>e.enabled&&!a.includes(e.id)).map(e=>(0,Z.jsxs)(`label`,{className:`dg-bot-choice`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,disabled:p||l,checked:s.includes(e.id),onChange:t=>c(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}),(0,Z.jsxs)(`span`,{children:[e.name,e.deviceName&&(0,Z.jsx)(`small`,{children:e.deviceName})]})]},e.id)),!r.some(e=>e.enabled&&!a.includes(e.id))&&(0,Z.jsx)(`p`,{children:n(`deviceGroupBotDialogEmpty`)})]}),(0,Z.jsxs)(`div`,{className:`dc-actions`,children:[(0,Z.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:p||l,onClick:()=>{u(!0),g(``)},children:n(`deviceGroupsCreateBot`)}),(0,Z.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:d||p||l||!s.length,onClick:()=>void x(s),children:n(p?`deviceGroupBotDialogAdding`:`deviceGroupBotDialogAddToGroup`)})]}),l&&(0,Z.jsx)(In,{createOnly:!0,onCancel:()=>u(!1),onCreated:(e,t)=>{if(u(!1),v(e=>e+1),!t||!e.enabled){g(n(`deviceGroupBotDialogSaved`));return}x([e.id])}})]})}),document.body)}var Rn=`pi-web-ui:device-groups-changed`;async function zn(e,t,n){return Me(`/api/device-center/${e}`,{body:n,signal:AbortSignal.any([t,AbortSignal.timeout(15e3)]),errorFor:e=>new Pe(e.status,e.error,e.code)})}function Bn({roomId:e,onClose:t,onSaved:n}){let r=U();je(t);let[i,a]=(0,Q.useState)(!0),[o,s]=(0,Q.useState)(``),[c,l]=(0,Q.useState)([]),[u,d]=(0,Q.useState)(new Set),[f,p]=(0,Q.useState)(!1),[m,h]=(0,Q.useState)(`local`),[g,_]=(0,Q.useState)(!1),[v,y]=(0,Q.useState)(``),[b,x]=(0,Q.useState)([]),[S,C]=(0,Q.useState)(``),[w,T]=(0,Q.useState)(!1),E=(0,Q.useRef)(0);(0,Q.useEffect)(()=>{let t=++E.current,n=new AbortController,r=()=>E.current===t&&!n.signal.aborted;return(async()=>{try{let[t,i]=await Promise.all([zn(`bots`,n.signal).catch(()=>({bots:[]})),zn(`shared-bots`,n.signal).then(e=>({...e,ok:!0})).catch(()=>({bots:[],ok:!1}))]);if(!r())return;let a=Array.isArray(t.bots)?t.bots:[],o=Array.isArray(i.bots)?i.bots:[];p(!!i.ok&&o.length>0),d(new Set(a.map(e=>e.id)));let c=new Map;for(let e of a)c.set(e.id,e);for(let e of o)c.has(e.id)||c.set(e.id,e);l([...c.values()]);let u=null,f=`local`;try{u=(await zn(`rooms/${encodeURIComponent(e)}`,n.signal)).room,f=`local`}catch(t){if(t.status!==404)throw t;u=(await zn(`shared-rooms/${encodeURIComponent(e)}`,n.signal)).room,f=`shared`}if(!r()||!u)return;h(u.scope===`shared`?`shared`:f),_(!!u.router?.enabled),y(u.name??``),x([...u.botIds??[]]),C(u.primaryBotId??``),s(``)}catch(e){r()&&s(e instanceof Error?e.message:String(e))}finally{r()&&a(!1)}})(),()=>{n.abort()}},[e]);let D=b.every(e=>u.has(e))?`local`:`shared`,O=!i&&!o&&D!==m;async function k(){if(w||i)return;let a=v.trim();if(!a||b.length===0)return;if(D===`shared`&&!f&&m!==`shared`){s(r(`deviceGroupManagerNoBots`));return}T(!0),s(``);let o=new AbortController;try{let i=D===`shared`?`shared-rooms`:`rooms`;if(D===m){a&&await zn(`${i}/${encodeURIComponent(e)}/rename`,o.signal,{name:a});let r=(await zn(`${i}/${encodeURIComponent(e)}/members`,o.signal,{botIds:b,primaryBotId:b.includes(S)?S:null})).room?.id??e;window.dispatchEvent(new CustomEvent(Rn)),n?.(r),t()}else{let s=(await zn(i,o.signal,{name:a,botIds:b,...b.includes(S)?{primaryBotId:S}:{}})).room?.id;if(!s)throw Error(r(`deviceGroupsFailed`));await zn(`${m===`shared`?`shared-rooms`:`rooms`}/${encodeURIComponent(e)}/delete`,o.signal,{}),window.dispatchEvent(new CustomEvent(Rn)),n?.(s),t()}}catch(e){o.signal.aborted||s(e instanceof Error?e.message:String(e))}finally{T(!1)}}return(0,Bt.createPortal)((0,Z.jsx)(`div`,{className:`modal-backdrop`,onClick:()=>!w&&t(),children:(0,Z.jsxs)(`div`,{className:`dc-card device-group-create-dialog`,role:`dialog`,"aria-modal":`true`,"aria-label":`${r(`edit`)} · ${v||e}`,onClick:e=>e.stopPropagation(),style:{minWidth:`min(480px, 92vw)`},children:[(0,Z.jsxs)(`div`,{className:`dg-heading`,style:{marginBottom:`12px`},children:[(0,Z.jsxs)(`h3`,{children:[r(`edit`),` · `,v||e,m===`shared`?` · ${r(`deviceGroupManagerSharedSuffix`)}`:``]}),(0,Z.jsxs)(`button`,{type:`button`,className:`dc-button`,onClick:t,disabled:w,children:[(0,Z.jsx)(_e,{"aria-hidden":!0}),r(`close`)]})]}),i&&(0,Z.jsx)(`p`,{role:`status`,children:r(`loading`)}),o&&(0,Z.jsx)(`p`,{className:`dc-error`,role:`alert`,children:o}),!i&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`12px`},children:[(0,Z.jsx)(`label`,{htmlFor:`dg-edit-name`,children:r(`deviceGroupManagerNameLabel`)}),(0,Z.jsx)(`input`,{id:`dg-edit-name`,type:`text`,maxLength:80,value:v,onChange:e=>y(e.target.value),disabled:w,placeholder:r(`deviceGroupManagerRenamePlaceholder`),style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`}})]}),(0,Z.jsxs)(`div`,{style:{marginBottom:`12px`},children:[(0,Z.jsx)(`label`,{style:{display:`block`,marginBottom:`6px`,fontSize:`12px`,color:`var(--text-dim)`},children:r(`deviceGroupManagerSelectMembers`)}),(0,Z.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`6px`,maxHeight:`220px`,overflowY:`auto`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`8px`,background:`var(--bg-elev)`},children:c.length===0?(0,Z.jsx)(`p`,{style:{margin:0,fontSize:`12px`,color:`var(--text-faint)`},children:r(`deviceGroupManagerNoBots`)}):c.map(e=>(0,Z.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,cursor:`pointer`,fontSize:`12px`},children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:b.includes(e.id),disabled:w,onChange:t=>{x(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}}),(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(`strong`,{children:e.name}),(0,Z.jsxs)(`small`,{style:{color:`var(--text-faint)`,marginInlineStart:`6px`},children:[e.deviceName??(u.has(e.id)?``:e.deviceId??``),e.online===void 0?``:` · ${e.online?r(`deviceHubOnline`):r(`deviceHubOffline`)}`,e.enabled?``:r(`deviceGroupManagerDisabledSuffix`),u.has(e.id)?``:` · ${r(`deviceGroupManagerSharedSuffix`)}`]})]})]},e.id))})]}),!g&&(0,Z.jsxs)(`div`,{className:`dc-field`,style:{marginBottom:`16px`},children:[(0,Z.jsx)(`label`,{htmlFor:`dg-edit-primary`,children:r(`deviceGroupManagerLegacyPrimary`)}),(0,Z.jsxs)(`select`,{id:`dg-edit-primary`,value:b.includes(S)?S:``,onChange:e=>C(e.target.value),disabled:w,style:{width:`100%`,background:`var(--bg-elev)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`6px 10px`,color:`var(--text)`,fontSize:`13px`},children:[(0,Z.jsx)(`option`,{value:``,children:r(`deviceGroupManagerNoPrimary`)}),c.filter(e=>b.includes(e.id)).map(e=>(0,Z.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),O&&(0,Z.jsx)(`p`,{className:`dc-notice`,role:`status`,children:r(D===`shared`?`deviceGroupManagerMigrateToSharedHint`:`deviceGroupManagerMigrateToLocalHint`)}),(0,Z.jsxs)(`div`,{className:`dc-actions`,children:[(0,Z.jsxs)(`button`,{type:`button`,className:`dc-button is-primary`,disabled:w||!v.trim()||b.length===0,onClick:()=>void k(),children:[(0,Z.jsx)(R,{"aria-hidden":!0}),r(w?`saving`:`deviceGroupManagerSaveMembers`)]}),(0,Z.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:t,disabled:w,children:r(`cancel`)})]})]})]})}),document.body)}var Vn={activity:(0,Z.jsx)(ve,{}),aperture:(0,Z.jsx)(F,{}),branch:(0,Z.jsx)(t,{}),browser:(0,Z.jsx)(ye,{}),chat:(0,Z.jsx)(we,{}),check:(0,Z.jsx)(R,{}),"chevron-up":(0,Z.jsx)(s,{}),clock:(0,Z.jsx)(oe,{}),code:(0,Z.jsx)(r,{}),coins:(0,Z.jsx)(i,{}),copy:(0,Z.jsx)(y,{}),cpu:(0,Z.jsx)(_,{}),cut:(0,Z.jsx)(E,{}),database:(0,Z.jsx)(Ee,{}),dot:(0,Z.jsx)(`span`,{className:`host-icon-char`,children:`●`}),download:(0,Z.jsx)(D,{}),edit:(0,Z.jsx)(p,{}),engine:(0,Z.jsx)(F,{}),eye:(0,Z.jsx)(f,{}),feather:(0,Z.jsx)(he,{}),file:(0,Z.jsx)(g,{}),folder:(0,Z.jsx)(M,{}),folders:(0,Z.jsx)(rt,{}),gauge:(0,Z.jsx)(ve,{}),git:(0,Z.jsx)(t,{}),github:(0,Z.jsx)(ne,{}),globe:(0,Z.jsx)(ye,{}),grid:(0,Z.jsx)(de,{}),hash:(0,Z.jsx)(`span`,{className:`host-icon-char`,children:`#`}),image:(0,Z.jsx)(pe,{}),info:(0,Z.jsx)(z,{}),layers:(0,Z.jsx)(xe,{}),link:(0,Z.jsx)(re,{}),list:(0,Z.jsx)(me,{}),lock:(0,Z.jsx)(le,{}),markdown:(0,Z.jsx)(A,{}),maximize:(0,Z.jsx)(Se,{}),menu:(0,Z.jsx)(Te,{}),minimize:(0,Z.jsx)(Ce,{}),message:(0,Z.jsx)(we,{}),open:(0,Z.jsx)(k,{}),paste:(0,Z.jsx)(b,{}),pin:(0,Z.jsx)(ie,{}),plus:(0,Z.jsx)(S,{}),refresh:(0,Z.jsx)(d,{}),sandbox:(0,Z.jsx)(at,{}),save:(0,Z.jsx)(v,{}),share:(0,Z.jsx)(Qe,{}),search:(0,Z.jsx)(De,{}),send:(0,Z.jsx)(a,{}),settings:(0,Z.jsx)(m,{}),sound:(0,Z.jsx)(fe,{}),sun:(0,Z.jsx)(j,{}),target:(0,Z.jsx)(w,{}),terminal:(0,Z.jsx)(N,{}),text:(0,Z.jsx)(V,{}),trash:(0,Z.jsx)(n,{}),undo:(0,Z.jsx)(h,{}),upload:(0,Z.jsx)(ue,{}),users:(0,Z.jsx)(I,{}),volume:(0,Z.jsx)(fe,{}),wrap:(0,Z.jsx)(x,{}),x:(0,Z.jsx)(_e,{}),zap:(0,Z.jsx)(ee,{}),zoom:(0,Z.jsx)(se,{})};Object.keys(Vn);function Hn(e){if(e.iconSvg)return(0,Z.jsx)(ht,{icon:e.icon,iconSvg:e.iconSvg});if(!e.icon)return null;let t=Vn[e.icon];return t===void 0?/[a-z]/i.test(e.icon)?null:(0,Z.jsx)(`span`,{className:`plugin-icon-glyph`,children:e.icon}):t}var Un=`pi-web-ui:device-groups-changed`,Wn={rename:`deviceGroupManagerRename`,edit:`edit`,clear:`deviceGroupSectionClearMessages`,delete:`deviceGroupSectionDeleteGroup`},Gn={bind:`deviceGroupSectionBind`,running:`deviceGroupSectionRunning`,forbidden:`deviceGroupSectionForbidden`,failed:`deviceGroupSectionFailed`},Kn=class extends Error{status;code;detail;constructor(e,t,n=``){super(`Device group request failed (${e})`),this.status=e,this.code=t,this.detail=n}},qn=[`bot-drafts`],Jn=15e3,Yn=12e4;function Xn(e){return qn.some(t=>e===t||e.startsWith(`${t}/`))}async function Zn(e,t,n){return Me(`/api/device-center/${e}`,{body:n,signal:AbortSignal.any([t,AbortSignal.timeout(Xn(e)?Yn:Jn)]),errorFor:t=>new Kn(t.status,t.code,Xn(e)?t.detail.trim():``)})}function Qn(e){return e instanceof Kn?[`NOT_PAIRED`,`REPAIR_REQUIRED`,`DEVICE_CHANGED`].includes(e.code)?`bind`:[`ROOM_BUSY`,`ROOM_RUNNING`,`TASKS_RUNNING`,`ACTIVE_TASKS`].includes(e.code)?`running`:e.status===403?`forbidden`:`failed`:`failed`}function $n(e,t,n){let r,i=0,a=!1,o=!1,s=()=>{if(o)return;let c=++i;if(r){a=!0;return}let l=new AbortController;r=l,e(l.signal).then(e=>{!o&&c===i&&t(e)},e=>{!o&&c===i&&!l.signal.aborted&&n(e)}).finally(()=>{r=void 0,a&&!o&&(a=!1,s())})};return{refresh:s,pause:()=>{i++,a=!1,r?.abort()},stop:()=>{o=!0,i++,a=!1,r?.abort()}}}function er(e){window.dispatchEvent(new CustomEvent(`pi-web-ui:device-group-open`,{detail:e}))}function tr({active:e=!0,entry:t,selectedRoomId:n,flex:r,onCollapsedChange:i,hideWhenEmpty:a=!1,autoHeight:c=!1}){let l=U(),u=t?.labelExplicit?t.label:l(`deviceGroups`),[d,f]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(null),[h,g]=(0,Q.useState)(null),[_,v]=(0,Q.useState)(()=>new Set);(0,Q.useEffect)(()=>i?.(d),[d,i]);let[y,b]=(0,Q.useState)([]),[x,C]=(0,Q.useState)(null),[w,T]=(0,Q.useState)(!0),[E,D]=(0,Q.useState)(null),[O,k]=(0,Q.useState)(null),[A,j]=(0,Q.useState)(``),[M,N]=(0,Q.useState)(!1),P=(0,Q.useRef)(null),F=(0,Q.useRef)(null),L=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>(L.current=!0,()=>{L.current=!1,F.current?.abort()}),[]),(0,Q.useEffect)(()=>{if(!e)return;let t=!1,n=$n(async e=>{let n=await Zn(`chat-status`,e);if(t=n.roomsReady===!0||!!(n.hubUrl&&n.deviceId),!t)return[];let[r,i]=await Promise.all([Zn(`rooms`,e),Zn(`shared-rooms`,e).catch(()=>({rooms:[]}))]);if(!Array.isArray(r.rooms))throw Error(`Invalid rooms response`);let a=new Set,o=[];for(let e of r.rooms)a.add(e.id),o.push(e.scope?e:{...e,scope:`local`});for(let e of Array.isArray(i.rooms)?i.rooms:[])a.has(e.id)||(a.add(e.id),o.push(e.scope?e:{...e,scope:`shared`}));return o},e=>{C(t),b(e),D(null),T(!1)},e=>{D(Qn(e)),T(!1)});P.current=n;let r=()=>{document.hidden||n.refresh()},i=()=>{document.hidden?n.pause():r()};r();let a=window.setInterval(r,15e3);return window.addEventListener(Un,r),document.addEventListener(`visibilitychange`,i),()=>{n.stop(),P.current=null,window.clearInterval(a),window.removeEventListener(Un,r),document.removeEventListener(`visibilitychange`,i)}},[e]);let R=async(e,t)=>{if(F.current||t===`delete`&&!window.confirm(l(`deviceGroupSectionConfirmDelete`,{name:e.name}))||t===`clear`&&!window.confirm(l(`deviceGroupSectionConfirmClear`,{name:e.name})))return;let n=new AbortController;F.current=n,N(!0),D(null);try{if(await Zn(`${e.scope===`shared`?`shared-rooms`:`rooms`}/${encodeURIComponent(e.id)}/${t}`,n.signal,t===`rename`?{name:A.trim()}:{}),!L.current||n.signal.aborted)return;k(null),window.dispatchEvent(new CustomEvent(Un))}catch(e){L.current&&!n.signal.aborted&&D(Qn(e))}finally{F.current=null,L.current&&N(!1)}},ee=(e,t)=>{e.preventDefault(),e.stopPropagation();let n=[`rename`,`edit`,`clear`,`delete`].map((e,t)=>({id:`host:device-group-${e}`,slot:`contextmenu.project`,source:`host`,label:l(Wn[e]),kind:`action`,action:e,order:t,align:`start`,hidden:!1,userOverrides:[],arrangedBy:[]}));ze({x:e.clientX,y:e.clientY,slot:`contextmenu.project`,target:{id:t.id,kind:`device-group`,label:t.name},entries:n,onHostAction:e=>{F.current||(e.action===`rename`?(k(t.id),j(t.name)):e.action===`edit`?g(t):(e.action===`clear`||e.action===`delete`)&&R(t,e.action))}})};if(x===!1||x===null&&w||a&&y.length===0&&!E)return null;let z=(0,Z.jsxs)(`div`,{className:`lp-section-body dg-side-body`,children:[E&&(0,Z.jsxs)(`div`,{className:`dg-side-error`,role:`status`,children:[l(Gn[E]),E===`bind`?(0,Z.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>er({}),children:l(`deviceGroupSectionOpenDeviceCenter`)}):(0,Z.jsx)(`button`,{type:`button`,className:`dc-button`,onClick:()=>P.current?.refresh(),children:l(`retryNow`)})]}),!E&&y.length===0&&(0,Z.jsx)(`div`,{className:`dg-side-empty`,children:l(w?`loading`:`deviceGroupSectionEmpty`)}),y.map(e=>(0,Z.jsxs)(`div`,{className:`dg-side-item`,children:[(0,Z.jsxs)(`div`,{className:`dg-side-heading`,children:[(0,Z.jsx)(`button`,{type:`button`,className:`dg-side-toggle`,"aria-expanded":_.has(e.id),"aria-label":`${e.name} · ${l(`deviceGroupSectionMembers`)}`,onClick:()=>v(t=>{let n=new Set(t);return n.has(e.id)?n.delete(e.id):n.add(e.id),n}),children:_.has(e.id)?(0,Z.jsx)(s,{}):(0,Z.jsx)(o,{})}),(0,Z.jsxs)(`div`,{role:`button`,tabIndex:0,className:`dg-side-row${n===e.id?` is-selected`:``}`,"aria-current":n===e.id?`page`:void 0,title:e.name,onClick:()=>er({roomId:e.id}),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),er({roomId:e.id}))},onContextMenu:t=>ee(t,e),children:[(0,Z.jsx)(I,{}),(0,Z.jsxs)(`span`,{className:`dg-side-name`,children:[e.name,e.scope===`shared`&&(0,Z.jsx)(`small`,{style:{marginInlineStart:6,opacity:.75},children:l(`deviceGroupManagerSharedSuffix`)})]})]}),(0,Z.jsx)(`button`,{type:`button`,className:`dg-side-toggle`,"aria-label":`${e.name} · ${l(`deviceGroupSectionAddBot`)}`,title:l(`deviceGroupSectionAddOrCreateBot`),onClick:()=>m(e),children:(0,Z.jsx)(S,{})})]}),_.has(e.id)&&(0,Z.jsx)(Ft,{botIds:e.botIds,roomId:e.id}),O===e.id&&(0,Z.jsxs)(`form`,{className:`dg-side-rename`,onSubmit:t=>{t.preventDefault(),A.trim()&&R(e,`rename`)},children:[(0,Z.jsx)(`input`,{className:`dc-input`,"aria-label":l(`deviceGroupManagerNameLabel`),value:A,maxLength:120,autoFocus:!0,disabled:M,onChange:e=>j(e.target.value),onKeyDown:e=>{e.key===`Escape`&&k(null)}}),(0,Z.jsx)(`button`,{type:`submit`,className:`dc-button`,disabled:M||!A.trim(),children:l(`save`)}),(0,Z.jsx)(`button`,{type:`button`,className:`dc-button`,disabled:M,onClick:()=>k(null),children:l(`cancel`)})]})]},e.id))]});return(0,Z.jsxs)(`section`,{className:`lp-section dg-side-section${d?` collapsed`:``}${c?` lp-section-auto`:``}`,"aria-label":u,style:!d&&r!==void 0?{flex:`${r} 1 0px`}:void 0,children:[(0,Z.jsxs)(`div`,{className:`lp-section-header`,children:[(0,Z.jsxs)(`button`,{type:`button`,className:`lp-section-title panel-section-title`,"aria-expanded":!d,title:l(d?`deviceGroupSectionExpand`:`deviceGroupSectionCollapse`),onClick:()=>f(!d),children:[(0,Z.jsxs)(`span`,{className:`lp-section-title-text lp-section-title-chip`,children:[t&&Hn(t),(0,Z.jsx)(`span`,{children:u}),(0,Z.jsxs)(`span`,{className:`lp-section-count`,children:[`(`,y.length,`)`]})]}),(0,Z.jsx)(`span`,{className:`lp-section-chevron`,children:d?(0,Z.jsx)(o,{}):(0,Z.jsx)(s,{})})]}),(0,Z.jsx)(`div`,{className:`lp-section-actions`,children:(0,Z.jsx)(`button`,{type:`button`,className:`lp-section-action`,title:l(`deviceGroupsCreate`),"aria-label":l(`deviceGroupsCreate`),onClick:()=>er({create:!0}),children:(0,Z.jsx)(S,{})})})]}),!d&&z,p&&(0,Z.jsx)(Ln,{room:p,onClose:()=>m(null)}),h&&(0,Z.jsx)(Bn,{roomId:h.id,onClose:()=>g(null)})]})}export{Ue as $,xt as A,it as B,kt as C,Ot as D,Nt as E,gt as F,$e as G,nt as H,_t as I,G as J,Qe as K,ht as L,wt as M,Ct as N,Dt as O,Tt as P,X as Q,ot as R,zt as S,Pt as T,tt as U,rt as V,et as W,Je as X,He as Y,We as Z,qt as _,Hn as a,$ as b,Dn as c,Sn as d,K as et,yn as f,Gt as g,un as h,Zn as i,Ve as it,vt as j,bt as k,wn as l,dn as m,Kn as n,Y as nt,In as o,fn as p,Ye as q,tr as r,qe as rt,Nn as s,Un as t,Xe as tt,bn as u,Jt as v,Et as w,Rt as x,Ht as y,at as z};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Et as t,Pt as n,an as r,vn as i,xt as a,zt as ee}from"./fi-DjvtEEnZ.js";import{i as o,r as s,t as c}from"./react-CR5VJ85Q.js";import{t as l}from"./shortcut-stack-hhrDyRBn.js";import{a as u}from"./api-client-CGqoOWHJ.js";import{o as te}from"./DeviceGroupSection-CRdMGDwE.js";import{r as ne,t as re}from"./group-view-state-CGCzYF8k.js";var d=e(o(),1),f=s(),p=c();function m(e,t){let n=e?.room;if(!n||typeof n.id!=`string`||!n.id||t!==void 0&&n.id!==t||typeof n.name!=`string`||!Array.isArray(n.botIds)||n.botIds.some(e=>typeof e!=`string`))throw Error(`Invalid group detail response`);return e}var h=class extends Error{status;code;constructor(e,t,n){super(n),this.status=e,this.code=t}};async function g(e,t,n){return u(`/api/device-center/${e}`,{body:n,signal:t,errorFor:e=>new h(e.status,e.code,e.error)})}function _(e){window.dispatchEvent(new CustomEvent(`pi-web-ui:device-group-open`,{detail:{roomId:e}}))}function v({onClose:e}){let t=i();return l(()=>{document.querySelector(`dialog[open]`)||e()}),(0,f.createPortal)((0,p.jsx)(`div`,{className:`modal-backdrop`,onClick:e,children:(0,p.jsx)(`div`,{className:`device-group-create-dialog`,role:`dialog`,"aria-modal":`true`,"aria-label":t(`deviceGroupsCreate`),onClick:e=>e.stopPropagation(),children:(0,p.jsx)(y,{createOnly:!0,onClose:e})})}),document.body)}function y({active:e=!0,navigation:o,createOnly:s=!1,onClose:c}){let l=i(),[u,f]=(0,d.useState)([]),[v,y]=(0,d.useState)([]),[b,x]=(0,d.useState)(``),[S,C]=(0,d.useState)(null),[w,T]=(0,d.useState)(!0),[E,D]=(0,d.useState)(``),[ie,O]=(0,d.useState)(!1),[k,A]=(0,d.useState)(s),[j,M]=(0,d.useState)(!1),[N,P]=(0,d.useState)(!1),[F,I]=(0,d.useState)(``),[L,R]=(0,d.useState)([]),[z,B]=(0,d.useState)(``),[V,H]=(0,d.useState)(!1),[ae,U]=(0,d.useState)(0),[W,oe]=(0,d.useState)(``),[se,ce]=(0,d.useState)([]),G=(0,d.useRef)(new re),K=(0,d.useRef)(null),q=(0,d.useRef)(void 0),J=(0,d.useRef)(0),Y=(0,d.useRef)(null),X=(0,d.useRef)(l);X.current=l;function le(e){let t=X.current;if(e instanceof h){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(`deviceGroupsRebind`);if(e.status===403)return t(`deviceGroupsForbidden`)}return`${t(`deviceGroupsFailed`)}: ${e instanceof Error?e.message:String(e)}`}function Z(){Y.current?.abort(),Y.current=null,H(!1)}function Q(e,t=!1){++J.current,Z(),x(e),C(null),A(!1),M(t),O(!1),B(``),K.current=t?e:null,R([]),T(!0),D(``),U(e=>e+1)}function ue(){++J.current,Z(),A(!0),O(!1),B(``),M(!1),K.current=null,C(null),R([]),I(``),D(``),U(e=>e+1)}(0,d.useEffect)(()=>{let t=++J.current,n=null,r=!1,i=()=>J.current===t;async function a(){if(!e||document.visibilityState===`hidden`||r)return;r=!0;let t=new AbortController;n=t;try{let[e,n,r]=await Promise.all([g(`bots`,t.signal),g(`rooms`,t.signal),j&&b?g(`rooms/${encodeURIComponent(b)}`,t.signal).then(e=>m(e,b)):Promise.resolve(null)]);if(!i()||t.signal.aborted)return;if(f(e.bots),y(n.rooms),C(r),r?.tasks){ce(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(le(e))}finally{t.abort(),r=!1,i()&&T(!1)}}a();let ee=window.setInterval(()=>void a(),3e3),o=()=>{document.visibilityState===`hidden`?n?.abort():a()};return document.addEventListener(`visibilitychange`,o),()=>{++J.current,n?.abort(),clearInterval(ee),document.removeEventListener(`visibilitychange`,o)}},[e,b,j,ae]),(0,d.useEffect)(()=>()=>Y.current?.abort(),[]),(0,d.useEffect)(()=>{e||Z()},[e]),(0,d.useEffect)(()=>{e&&o&&o.revision!==q.current&&(q.current=o.revision,o.create?ue():o.roomId&&Q(o.roomId,o.manage))},[e,o?.revision]);async function de(){if(!e||Y.current||(k?!F.trim():!S))return;let t=new AbortController;Y.current=t,H(!0),D(``),O(!1);let n=L.includes(z)?z:``,r=k,i=S?.room.id;try{let e=await g(r?`rooms`:`rooms/${encodeURIComponent(i)}/members`,t.signal,{...r?{name:F.trim()}:{},botIds:L,...z&&L.includes(z)?{primaryBotId:z}:!r&&S?.room.primaryBotId?{primaryBotId:null}:{}});if(t.signal.aborted||Y.current!==t)return;let{room:a}=m(e,r?void 0:i);if((a.primaryBotId??``)!==n)throw Error(l(`deviceGroupsPrimaryBotUnsaved`));O(!0),y(e=>[...e.filter(e=>e.id!==a.id),a]),x(a.id),C({room:a}),A(!1),M(!r),I(``),R(r?[]:a.botIds),B(a.primaryBotId??``),U(e=>e+1),window.dispatchEvent(new CustomEvent(`pi-web-ui:device-groups-changed`)),r&&(_(a.id),s&&c?.())}catch(e){!t.signal.aborted&&Y.current===t&&D(le(e))}finally{Y.current===t&&(Y.current=null,H(!1))}}let $=v.find(e=>e.id===b);return(0,p.jsxs)(`section`,{className:`dg-root`,"aria-label":l(`deviceGroupsHeading`),children:[!s&&(0,p.jsxs)(`div`,{className:`dc-card dg-sidebar`,children:[(0,p.jsxs)(`div`,{className:`dg-heading`,children:[(0,p.jsxs)(`h2`,{children:[(0,p.jsx)(r,{}),` `,l(`deviceGroupsHeading`)]}),(0,p.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:ue,children:[(0,p.jsx)(n,{}),` `,l(`deviceGroupsCreate`)]})]}),(0,p.jsx)(`div`,{className:`dg-search-bar`,style:{padding:`0 10px 8px 10px`},children:(0,p.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`6px`,background:`var(--bg)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`4px 8px`},children:[(0,p.jsx)(ee,{style:{color:`var(--text-dim)`,flex:`none`}}),(0,p.jsx)(`input`,{type:`search`,value:W,onChange:e=>oe(e.target.value),placeholder:l(`deviceGroupsSearchPlaceholder`),style:{border:`none`,background:`transparent`,color:`var(--text)`,width:`100%`,fontSize:`12px`,outline:`none`}})]})}),(0,p.jsx)(`div`,{className:`dg-rooms`,children:ne(W,v,se).map(t=>{let n=v.find(e=>e.id===t.roomId);if(!n)return null;let r=G.current.getPendingInteractionsCount(n.id);return(0,p.jsxs)(`button`,{className:`dc-button dg-room`,type:`button`,"aria-current":n.id===b?`page`:void 0,disabled:!e,onClick:()=>{Q(n.id),_(n.id)},children:[(0,p.jsx)(a,{}),(0,p.jsxs)(`span`,{style:{flex:1,minWidth:0,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,textAlign:`left`},children:[n.name,t.matchedBy===`bot_id`&&(0,p.jsx)(`small`,{style:{display:`block`,color:`var(--text-dim)`,fontSize:`11px`},children:l(`deviceGroupsMatchedBot`,{query:W})}),t.matchedBy===`task_title`&&t.matchedTask&&(0,p.jsx)(`small`,{style:{display:`block`,color:`var(--accent)`,fontSize:`11px`},children:l(`deviceGroupsMatchedTask`,{title:t.matchedTask.title})}),t.matchedBy===`task_id`&&t.matchedTask&&(0,p.jsxs)(`small`,{style:{display:`block`,color:`var(--text-dim)`,fontSize:`11px`},children:[`ID: `,t.matchedTask.id.slice(0,8)]})]}),r>0&&(0,p.jsx)(`span`,{style:{flex:`none`,background:`var(--accent)`,color:`var(--accent-contrast, #fff)`,borderRadius:`10px`,padding:`1px 6px`,fontSize:`11px`,fontWeight:`bold`},children:r})]},t.matchedTask?`${n.id}:${t.matchedTask.id}`:n.id)})}),!w&&!v.length&&(0,p.jsx)(`p`,{className:`dg-empty`,children:l(`deviceGroupsEmpty`)})]}),(0,p.jsxs)(`div`,{className:`dc-card dg-chat`,children:[ie&&(0,p.jsx)(`p`,{role:`status`,children:l(`deviceGroupsSaved`)}),E&&(0,p.jsx)(`p`,{className:`dc-error`,role:`alert`,children:E}),w&&(0,p.jsx)(`p`,{role:`status`,children:l(`loading`)}),k||j?(0,p.jsxs)(`form`,{className:`dg-create`,onSubmit:e=>{e.preventDefault(),de()},children:[(0,p.jsx)(`h2`,{children:l(k?`deviceGroupsCreate`:`deviceGroupManagerManageMembersTitle`)}),k&&(0,p.jsxs)(`div`,{className:`dc-field`,children:[(0,p.jsx)(`label`,{htmlFor:`device-group-name`,children:l(`deviceGroupManagerNameLabel`)}),(0,p.jsx)(`input`,{id:`device-group-name`,value:F,onChange:e=>I(e.target.value),disabled:V||!e})]}),(0,p.jsxs)(`fieldset`,{disabled:V||!e||j&&!S,children:[(0,p.jsx)(`legend`,{children:l(`deviceGroupsDevices`)}),u.map(e=>(0,p.jsxs)(`label`,{className:`dg-device`,children:[(0,p.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,p.jsx)(t,{}),(0,p.jsxs)(`span`,{children:[e.name,` · `,e.id,` · `,e.deviceId,` ·`,` `,e.online?l(`deviceHubOnline`):l(`deviceHubOffline`)]})]},e.id))]}),!S?.room.router?.enabled&&(0,p.jsxs)(`div`,{className:`dc-field`,children:[(0,p.jsx)(`label`,{htmlFor:`device-group-primary-bot`,children:l(`deviceGroupsLegacyPrimaryBot`)}),(0,p.jsxs)(`select`,{id:`device-group-primary-bot`,value:L.includes(z)?z:``,disabled:V||!e||j&&!S,onChange:e=>B(e.target.value),children:[(0,p.jsx)(`option`,{value:``,children:l(`deviceGroupsPrimaryBotNone`)}),u.filter(e=>e.enabled&&L.includes(e.id)).map(e=>(0,p.jsxs)(`option`,{value:e.id,children:[e.name,` · `,e.id]},e.id))]}),(0,p.jsx)(`p`,{children:l(`deviceGroupsPrimaryBotHint`)})]}),S?.room.router?.enabled&&(0,p.jsxs)(`p`,{children:[`AI Router · `,S.room.router.deviceId,` · `,S.room.router.model,` ·`,` `,S.room.router.thinkingLevel]}),(0,p.jsxs)(`div`,{className:`dc-actions`,children:[(0,p.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:V||!e||N,onClick:()=>P(!0),children:[(0,p.jsx)(n,{}),` `,l(`deviceGroupsCreateBot`)]}),(0,p.jsx)(`button`,{className:`dc-button`,type:`submit`,disabled:V||!e||(k?!F.trim():!S),children:l(k?`deviceGroupsCreate`:`deviceExecSave`)}),(0,p.jsx)(`button`,{className:`dc-button`,type:`button`,onClick:()=>{Z(),K.current=null,s&&c?.(),A(!1),M(!1),D(``)},children:l(`cancel`)})]})]}):$?(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(`div`,{className:`dg-title`,children:(0,p.jsxs)(`h2`,{children:[(0,p.jsx)(r,{}),` `,$.name]})}),(0,p.jsxs)(`div`,{className:`dc-actions`,children:[(0,p.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:()=>_($.id),children:[(0,p.jsx)(a,{}),l(`deviceGroupManagerOpenChat`)]}),(0,p.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:()=>Q($.id,!0),children:[(0,p.jsx)(r,{}),l(`deviceGroupManagerManageMembersTitle`)]})]})]}):(0,p.jsx)(`p`,{className:`dg-empty`,children:l(`deviceGroupsChoose`)})]}),N&&(0,p.jsx)(te,{createOnly:!0,onCancel:()=>P(!1),onCreated:(e,t)=>{P(!1),t&&e.enabled?(f(t=>[...t.filter(t=>t.id!==e.id),e]),R(t=>[...new Set([...t,e.id])])):D(l(`deviceGroupsBotSavedHint`))}})]})}export{v as DeviceGroupCreateDialog};
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Et as t,Pt as n,an as r,vn as i,xt as a,zt as ee}from"./fi-CcqqfamG.js";import{i as o,r as s,t as c}from"./react-CR5VJ85Q.js";import{t as l}from"./shortcut-stack-hhrDyRBn.js";import{a as u}from"./api-client-BbDlV0jR.js";import{o as te}from"./DeviceGroupSection-BD3CKMFH.js";import{r as ne,t as re}from"./group-view-state-CGCzYF8k.js";var d=e(o(),1),f=s(),p=c();function m(e,t){let n=e?.room;if(!n||typeof n.id!=`string`||!n.id||t!==void 0&&n.id!==t||typeof n.name!=`string`||!Array.isArray(n.botIds)||n.botIds.some(e=>typeof e!=`string`))throw Error(`Invalid group detail response`);return e}var h=class extends Error{status;code;constructor(e,t,n){super(n),this.status=e,this.code=t}};async function g(e,t,n){return u(`/api/device-center/${e}`,{body:n,signal:t,errorFor:e=>new h(e.status,e.code,e.error)})}function _(e){window.dispatchEvent(new CustomEvent(`pi-web-ui:device-group-open`,{detail:{roomId:e}}))}function v({onClose:e}){let t=i();return l(()=>{document.querySelector(`dialog[open]`)||e()}),(0,f.createPortal)((0,p.jsx)(`div`,{className:`modal-backdrop`,onClick:e,children:(0,p.jsx)(`div`,{className:`device-group-create-dialog`,role:`dialog`,"aria-modal":`true`,"aria-label":t(`deviceGroupsCreate`),onClick:e=>e.stopPropagation(),children:(0,p.jsx)(y,{createOnly:!0,onClose:e})})}),document.body)}function y({active:e=!0,navigation:o,createOnly:s=!1,onClose:c}){let l=i(),[u,f]=(0,d.useState)([]),[v,y]=(0,d.useState)([]),[b,x]=(0,d.useState)(``),[S,C]=(0,d.useState)(null),[w,T]=(0,d.useState)(!0),[E,D]=(0,d.useState)(``),[ie,O]=(0,d.useState)(!1),[k,A]=(0,d.useState)(s),[j,M]=(0,d.useState)(!1),[N,P]=(0,d.useState)(!1),[F,I]=(0,d.useState)(``),[L,R]=(0,d.useState)([]),[z,B]=(0,d.useState)(``),[V,H]=(0,d.useState)(!1),[ae,U]=(0,d.useState)(0),[W,oe]=(0,d.useState)(``),[se,ce]=(0,d.useState)([]),G=(0,d.useRef)(new re),K=(0,d.useRef)(null),q=(0,d.useRef)(void 0),J=(0,d.useRef)(0),Y=(0,d.useRef)(null),X=(0,d.useRef)(l);X.current=l;function le(e){let t=X.current;if(e instanceof h){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(`deviceGroupsRebind`);if(e.status===403)return t(`deviceGroupsForbidden`)}return`${t(`deviceGroupsFailed`)}: ${e instanceof Error?e.message:String(e)}`}function Z(){Y.current?.abort(),Y.current=null,H(!1)}function Q(e,t=!1){++J.current,Z(),x(e),C(null),A(!1),M(t),O(!1),B(``),K.current=t?e:null,R([]),T(!0),D(``),U(e=>e+1)}function ue(){++J.current,Z(),A(!0),O(!1),B(``),M(!1),K.current=null,C(null),R([]),I(``),D(``),U(e=>e+1)}(0,d.useEffect)(()=>{let t=++J.current,n=null,r=!1,i=()=>J.current===t;async function a(){if(!e||document.visibilityState===`hidden`||r)return;r=!0;let t=new AbortController;n=t;try{let[e,n,r]=await Promise.all([g(`bots`,t.signal),g(`rooms`,t.signal),j&&b?g(`rooms/${encodeURIComponent(b)}`,t.signal).then(e=>m(e,b)):Promise.resolve(null)]);if(!i()||t.signal.aborted)return;if(f(e.bots),y(n.rooms),C(r),r?.tasks){ce(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(le(e))}finally{t.abort(),r=!1,i()&&T(!1)}}a();let ee=window.setInterval(()=>void a(),3e3),o=()=>{document.visibilityState===`hidden`?n?.abort():a()};return document.addEventListener(`visibilitychange`,o),()=>{++J.current,n?.abort(),clearInterval(ee),document.removeEventListener(`visibilitychange`,o)}},[e,b,j,ae]),(0,d.useEffect)(()=>()=>Y.current?.abort(),[]),(0,d.useEffect)(()=>{e||Z()},[e]),(0,d.useEffect)(()=>{e&&o&&o.revision!==q.current&&(q.current=o.revision,o.create?ue():o.roomId&&Q(o.roomId,o.manage))},[e,o?.revision]);async function de(){if(!e||Y.current||(k?!F.trim():!S))return;let t=new AbortController;Y.current=t,H(!0),D(``),O(!1);let n=L.includes(z)?z:``,r=k,i=S?.room.id;try{let e=await g(r?`rooms`:`rooms/${encodeURIComponent(i)}/members`,t.signal,{...r?{name:F.trim()}:{},botIds:L,...z&&L.includes(z)?{primaryBotId:z}:!r&&S?.room.primaryBotId?{primaryBotId:null}:{}});if(t.signal.aborted||Y.current!==t)return;let{room:a}=m(e,r?void 0:i);if((a.primaryBotId??``)!==n)throw Error(l(`deviceGroupsPrimaryBotUnsaved`));O(!0),y(e=>[...e.filter(e=>e.id!==a.id),a]),x(a.id),C({room:a}),A(!1),M(!r),I(``),R(r?[]:a.botIds),B(a.primaryBotId??``),U(e=>e+1),window.dispatchEvent(new CustomEvent(`pi-web-ui:device-groups-changed`)),r&&(_(a.id),s&&c?.())}catch(e){!t.signal.aborted&&Y.current===t&&D(le(e))}finally{Y.current===t&&(Y.current=null,H(!1))}}let $=v.find(e=>e.id===b);return(0,p.jsxs)(`section`,{className:`dg-root`,"aria-label":l(`deviceGroupsHeading`),children:[!s&&(0,p.jsxs)(`div`,{className:`dc-card dg-sidebar`,children:[(0,p.jsxs)(`div`,{className:`dg-heading`,children:[(0,p.jsxs)(`h2`,{children:[(0,p.jsx)(r,{}),` `,l(`deviceGroupsHeading`)]}),(0,p.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:ue,children:[(0,p.jsx)(n,{}),` `,l(`deviceGroupsCreate`)]})]}),(0,p.jsx)(`div`,{className:`dg-search-bar`,style:{padding:`0 10px 8px 10px`},children:(0,p.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`6px`,background:`var(--bg)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`4px 8px`},children:[(0,p.jsx)(ee,{style:{color:`var(--text-dim)`,flex:`none`}}),(0,p.jsx)(`input`,{type:`search`,value:W,onChange:e=>oe(e.target.value),placeholder:l(`deviceGroupsSearchPlaceholder`),style:{border:`none`,background:`transparent`,color:`var(--text)`,width:`100%`,fontSize:`12px`,outline:`none`}})]})}),(0,p.jsx)(`div`,{className:`dg-rooms`,children:ne(W,v,se).map(t=>{let n=v.find(e=>e.id===t.roomId);if(!n)return null;let r=G.current.getPendingInteractionsCount(n.id);return(0,p.jsxs)(`button`,{className:`dc-button dg-room`,type:`button`,"aria-current":n.id===b?`page`:void 0,disabled:!e,onClick:()=>{Q(n.id),_(n.id)},children:[(0,p.jsx)(a,{}),(0,p.jsxs)(`span`,{style:{flex:1,minWidth:0,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,textAlign:`left`},children:[n.name,t.matchedBy===`bot_id`&&(0,p.jsx)(`small`,{style:{display:`block`,color:`var(--text-dim)`,fontSize:`11px`},children:l(`deviceGroupsMatchedBot`,{query:W})}),t.matchedBy===`task_title`&&t.matchedTask&&(0,p.jsx)(`small`,{style:{display:`block`,color:`var(--accent)`,fontSize:`11px`},children:l(`deviceGroupsMatchedTask`,{title:t.matchedTask.title})}),t.matchedBy===`task_id`&&t.matchedTask&&(0,p.jsxs)(`small`,{style:{display:`block`,color:`var(--text-dim)`,fontSize:`11px`},children:[`ID: `,t.matchedTask.id.slice(0,8)]})]}),r>0&&(0,p.jsx)(`span`,{style:{flex:`none`,background:`var(--accent)`,color:`var(--accent-contrast, #fff)`,borderRadius:`10px`,padding:`1px 6px`,fontSize:`11px`,fontWeight:`bold`},children:r})]},t.matchedTask?`${n.id}:${t.matchedTask.id}`:n.id)})}),!w&&!v.length&&(0,p.jsx)(`p`,{className:`dg-empty`,children:l(`deviceGroupsEmpty`)})]}),(0,p.jsxs)(`div`,{className:`dc-card dg-chat`,children:[ie&&(0,p.jsx)(`p`,{role:`status`,children:l(`deviceGroupsSaved`)}),E&&(0,p.jsx)(`p`,{className:`dc-error`,role:`alert`,children:E}),w&&(0,p.jsx)(`p`,{role:`status`,children:l(`loading`)}),k||j?(0,p.jsxs)(`form`,{className:`dg-create`,onSubmit:e=>{e.preventDefault(),de()},children:[(0,p.jsx)(`h2`,{children:l(k?`deviceGroupsCreate`:`deviceGroupManagerManageMembersTitle`)}),k&&(0,p.jsxs)(`div`,{className:`dc-field`,children:[(0,p.jsx)(`label`,{htmlFor:`device-group-name`,children:l(`deviceGroupManagerNameLabel`)}),(0,p.jsx)(`input`,{id:`device-group-name`,value:F,onChange:e=>I(e.target.value),disabled:V||!e})]}),(0,p.jsxs)(`fieldset`,{disabled:V||!e||j&&!S,children:[(0,p.jsx)(`legend`,{children:l(`deviceGroupsDevices`)}),u.map(e=>(0,p.jsxs)(`label`,{className:`dg-device`,children:[(0,p.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,p.jsx)(t,{}),(0,p.jsxs)(`span`,{children:[e.name,` · `,e.id,` · `,e.deviceId,` ·`,` `,e.online?l(`deviceHubOnline`):l(`deviceHubOffline`)]})]},e.id))]}),!S?.room.router?.enabled&&(0,p.jsxs)(`div`,{className:`dc-field`,children:[(0,p.jsx)(`label`,{htmlFor:`device-group-primary-bot`,children:l(`deviceGroupsLegacyPrimaryBot`)}),(0,p.jsxs)(`select`,{id:`device-group-primary-bot`,value:L.includes(z)?z:``,disabled:V||!e||j&&!S,onChange:e=>B(e.target.value),children:[(0,p.jsx)(`option`,{value:``,children:l(`deviceGroupsPrimaryBotNone`)}),u.filter(e=>e.enabled&&L.includes(e.id)).map(e=>(0,p.jsxs)(`option`,{value:e.id,children:[e.name,` · `,e.id]},e.id))]}),(0,p.jsx)(`p`,{children:l(`deviceGroupsPrimaryBotHint`)})]}),S?.room.router?.enabled&&(0,p.jsxs)(`p`,{children:[`AI Router · `,S.room.router.deviceId,` · `,S.room.router.model,` ·`,` `,S.room.router.thinkingLevel]}),(0,p.jsxs)(`div`,{className:`dc-actions`,children:[(0,p.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:V||!e||N,onClick:()=>P(!0),children:[(0,p.jsx)(n,{}),` `,l(`deviceGroupsCreateBot`)]}),(0,p.jsx)(`button`,{className:`dc-button`,type:`submit`,disabled:V||!e||(k?!F.trim():!S),children:l(k?`deviceGroupsCreate`:`deviceExecSave`)}),(0,p.jsx)(`button`,{className:`dc-button`,type:`button`,onClick:()=>{Z(),K.current=null,s&&c?.(),A(!1),M(!1),D(``)},children:l(`cancel`)})]})]}):$?(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(`div`,{className:`dg-title`,children:(0,p.jsxs)(`h2`,{children:[(0,p.jsx)(r,{}),` `,$.name]})}),(0,p.jsxs)(`div`,{className:`dc-actions`,children:[(0,p.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:()=>_($.id),children:[(0,p.jsx)(a,{}),l(`deviceGroupManagerOpenChat`)]}),(0,p.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:()=>Q($.id,!0),children:[(0,p.jsx)(r,{}),l(`deviceGroupManagerManageMembersTitle`)]})]})]}):(0,p.jsx)(`p`,{className:`dg-empty`,children:l(`deviceGroupsChoose`)})]}),N&&(0,p.jsx)(te,{createOnly:!0,onCancel:()=>P(!1),onCreated:(e,t)=>{P(!1),t&&e.enabled?(f(t=>[...t.filter(t=>t.id!==e.id),e]),R(t=>[...new Set([...t,e.id])])):D(l(`deviceGroupsBotSavedHint`))}})]})}export{v as DeviceGroupCreateDialog};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Et as t,Pt as n,an as r,vn as i,xt as a,zt as ee}from"./fi-CcqqfamG.js";import{i as o,r as s,t as c}from"./react-CR5VJ85Q.js";import{t as l}from"./shortcut-stack-hhrDyRBn.js";import{a as u}from"./api-client-BbDlV0jR.js";import{o as te}from"./DeviceGroupSection-B98LzFoj.js";import{r as ne,t as re}from"./group-view-state-CGCzYF8k.js";var d=e(o(),1),f=s(),p=c();function m(e,t){let n=e?.room;if(!n||typeof n.id!=`string`||!n.id||t!==void 0&&n.id!==t||typeof n.name!=`string`||!Array.isArray(n.botIds)||n.botIds.some(e=>typeof e!=`string`))throw Error(`Invalid group detail response`);return e}var h=class extends Error{status;code;constructor(e,t,n){super(n),this.status=e,this.code=t}};async function g(e,t,n){return u(`/api/device-center/${e}`,{body:n,signal:t,errorFor:e=>new h(e.status,e.code,e.error)})}function _(e){window.dispatchEvent(new CustomEvent(`pi-web-ui:device-group-open`,{detail:{roomId:e}}))}function v({onClose:e}){let t=i();return l(()=>{document.querySelector(`dialog[open]`)||e()}),(0,f.createPortal)((0,p.jsx)(`div`,{className:`modal-backdrop`,onClick:e,children:(0,p.jsx)(`div`,{className:`device-group-create-dialog`,role:`dialog`,"aria-modal":`true`,"aria-label":t(`deviceGroupsCreate`),onClick:e=>e.stopPropagation(),children:(0,p.jsx)(y,{createOnly:!0,onClose:e})})}),document.body)}function y({active:e=!0,navigation:o,createOnly:s=!1,onClose:c}){let l=i(),[u,f]=(0,d.useState)([]),[v,y]=(0,d.useState)([]),[b,x]=(0,d.useState)(``),[S,C]=(0,d.useState)(null),[w,T]=(0,d.useState)(!0),[E,D]=(0,d.useState)(``),[ie,O]=(0,d.useState)(!1),[k,A]=(0,d.useState)(s),[j,M]=(0,d.useState)(!1),[N,P]=(0,d.useState)(!1),[F,I]=(0,d.useState)(``),[L,R]=(0,d.useState)([]),[z,B]=(0,d.useState)(``),[V,H]=(0,d.useState)(!1),[ae,U]=(0,d.useState)(0),[W,oe]=(0,d.useState)(``),[se,ce]=(0,d.useState)([]),G=(0,d.useRef)(new re),K=(0,d.useRef)(null),q=(0,d.useRef)(void 0),J=(0,d.useRef)(0),Y=(0,d.useRef)(null),X=(0,d.useRef)(l);X.current=l;function le(e){let t=X.current;if(e instanceof h){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(`deviceGroupsRebind`);if(e.status===403)return t(`deviceGroupsForbidden`)}return`${t(`deviceGroupsFailed`)}: ${e instanceof Error?e.message:String(e)}`}function Z(){Y.current?.abort(),Y.current=null,H(!1)}function Q(e,t=!1){++J.current,Z(),x(e),C(null),A(!1),M(t),O(!1),B(``),K.current=t?e:null,R([]),T(!0),D(``),U(e=>e+1)}function ue(){++J.current,Z(),A(!0),O(!1),B(``),M(!1),K.current=null,C(null),R([]),I(``),D(``),U(e=>e+1)}(0,d.useEffect)(()=>{let t=++J.current,n=null,r=!1,i=()=>J.current===t;async function a(){if(!e||document.visibilityState===`hidden`||r)return;r=!0;let t=new AbortController;n=t;try{let[e,n,r]=await Promise.all([g(`bots`,t.signal),g(`rooms`,t.signal),j&&b?g(`rooms/${encodeURIComponent(b)}`,t.signal).then(e=>m(e,b)):Promise.resolve(null)]);if(!i()||t.signal.aborted)return;if(f(e.bots),y(n.rooms),C(r),r?.tasks){ce(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(le(e))}finally{t.abort(),r=!1,i()&&T(!1)}}a();let ee=window.setInterval(()=>void a(),3e3),o=()=>{document.visibilityState===`hidden`?n?.abort():a()};return document.addEventListener(`visibilitychange`,o),()=>{++J.current,n?.abort(),clearInterval(ee),document.removeEventListener(`visibilitychange`,o)}},[e,b,j,ae]),(0,d.useEffect)(()=>()=>Y.current?.abort(),[]),(0,d.useEffect)(()=>{e||Z()},[e]),(0,d.useEffect)(()=>{e&&o&&o.revision!==q.current&&(q.current=o.revision,o.create?ue():o.roomId&&Q(o.roomId,o.manage))},[e,o?.revision]);async function de(){if(!e||Y.current||(k?!F.trim():!S))return;let t=new AbortController;Y.current=t,H(!0),D(``),O(!1);let n=L.includes(z)?z:``,r=k,i=S?.room.id;try{let e=await g(r?`rooms`:`rooms/${encodeURIComponent(i)}/members`,t.signal,{...r?{name:F.trim()}:{},botIds:L,...z&&L.includes(z)?{primaryBotId:z}:!r&&S?.room.primaryBotId?{primaryBotId:null}:{}});if(t.signal.aborted||Y.current!==t)return;let{room:a}=m(e,r?void 0:i);if((a.primaryBotId??``)!==n)throw Error(l(`deviceGroupsPrimaryBotUnsaved`));O(!0),y(e=>[...e.filter(e=>e.id!==a.id),a]),x(a.id),C({room:a}),A(!1),M(!r),I(``),R(r?[]:a.botIds),B(a.primaryBotId??``),U(e=>e+1),window.dispatchEvent(new CustomEvent(`pi-web-ui:device-groups-changed`)),r&&(_(a.id),s&&c?.())}catch(e){!t.signal.aborted&&Y.current===t&&D(le(e))}finally{Y.current===t&&(Y.current=null,H(!1))}}let $=v.find(e=>e.id===b);return(0,p.jsxs)(`section`,{className:`dg-root`,"aria-label":l(`deviceGroupsHeading`),children:[!s&&(0,p.jsxs)(`div`,{className:`dc-card dg-sidebar`,children:[(0,p.jsxs)(`div`,{className:`dg-heading`,children:[(0,p.jsxs)(`h2`,{children:[(0,p.jsx)(r,{}),` `,l(`deviceGroupsHeading`)]}),(0,p.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:ue,children:[(0,p.jsx)(n,{}),` `,l(`deviceGroupsCreate`)]})]}),(0,p.jsx)(`div`,{className:`dg-search-bar`,style:{padding:`0 10px 8px 10px`},children:(0,p.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`6px`,background:`var(--bg)`,border:`1px solid var(--border)`,borderRadius:`6px`,padding:`4px 8px`},children:[(0,p.jsx)(ee,{style:{color:`var(--text-dim)`,flex:`none`}}),(0,p.jsx)(`input`,{type:`search`,value:W,onChange:e=>oe(e.target.value),placeholder:l(`deviceGroupsSearchPlaceholder`),style:{border:`none`,background:`transparent`,color:`var(--text)`,width:`100%`,fontSize:`12px`,outline:`none`}})]})}),(0,p.jsx)(`div`,{className:`dg-rooms`,children:ne(W,v,se).map(t=>{let n=v.find(e=>e.id===t.roomId);if(!n)return null;let r=G.current.getPendingInteractionsCount(n.id);return(0,p.jsxs)(`button`,{className:`dc-button dg-room`,type:`button`,"aria-current":n.id===b?`page`:void 0,disabled:!e,onClick:()=>{Q(n.id),_(n.id)},children:[(0,p.jsx)(a,{}),(0,p.jsxs)(`span`,{style:{flex:1,minWidth:0,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,textAlign:`left`},children:[n.name,t.matchedBy===`bot_id`&&(0,p.jsx)(`small`,{style:{display:`block`,color:`var(--text-dim)`,fontSize:`11px`},children:l(`deviceGroupsMatchedBot`,{query:W})}),t.matchedBy===`task_title`&&t.matchedTask&&(0,p.jsx)(`small`,{style:{display:`block`,color:`var(--accent)`,fontSize:`11px`},children:l(`deviceGroupsMatchedTask`,{title:t.matchedTask.title})}),t.matchedBy===`task_id`&&t.matchedTask&&(0,p.jsxs)(`small`,{style:{display:`block`,color:`var(--text-dim)`,fontSize:`11px`},children:[`ID: `,t.matchedTask.id.slice(0,8)]})]}),r>0&&(0,p.jsx)(`span`,{style:{flex:`none`,background:`var(--accent)`,color:`var(--accent-contrast, #fff)`,borderRadius:`10px`,padding:`1px 6px`,fontSize:`11px`,fontWeight:`bold`},children:r})]},t.matchedTask?`${n.id}:${t.matchedTask.id}`:n.id)})}),!w&&!v.length&&(0,p.jsx)(`p`,{className:`dg-empty`,children:l(`deviceGroupsEmpty`)})]}),(0,p.jsxs)(`div`,{className:`dc-card dg-chat`,children:[ie&&(0,p.jsx)(`p`,{role:`status`,children:l(`deviceGroupsSaved`)}),E&&(0,p.jsx)(`p`,{className:`dc-error`,role:`alert`,children:E}),w&&(0,p.jsx)(`p`,{role:`status`,children:l(`loading`)}),k||j?(0,p.jsxs)(`form`,{className:`dg-create`,onSubmit:e=>{e.preventDefault(),de()},children:[(0,p.jsx)(`h2`,{children:l(k?`deviceGroupsCreate`:`deviceGroupManagerManageMembersTitle`)}),k&&(0,p.jsxs)(`div`,{className:`dc-field`,children:[(0,p.jsx)(`label`,{htmlFor:`device-group-name`,children:l(`deviceGroupManagerNameLabel`)}),(0,p.jsx)(`input`,{id:`device-group-name`,value:F,onChange:e=>I(e.target.value),disabled:V||!e})]}),(0,p.jsxs)(`fieldset`,{disabled:V||!e||j&&!S,children:[(0,p.jsx)(`legend`,{children:l(`deviceGroupsDevices`)}),u.map(e=>(0,p.jsxs)(`label`,{className:`dg-device`,children:[(0,p.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,p.jsx)(t,{}),(0,p.jsxs)(`span`,{children:[e.name,` · `,e.id,` · `,e.deviceId,` ·`,` `,e.online?l(`deviceHubOnline`):l(`deviceHubOffline`)]})]},e.id))]}),!S?.room.router?.enabled&&(0,p.jsxs)(`div`,{className:`dc-field`,children:[(0,p.jsx)(`label`,{htmlFor:`device-group-primary-bot`,children:l(`deviceGroupsLegacyPrimaryBot`)}),(0,p.jsxs)(`select`,{id:`device-group-primary-bot`,value:L.includes(z)?z:``,disabled:V||!e||j&&!S,onChange:e=>B(e.target.value),children:[(0,p.jsx)(`option`,{value:``,children:l(`deviceGroupsPrimaryBotNone`)}),u.filter(e=>e.enabled&&L.includes(e.id)).map(e=>(0,p.jsxs)(`option`,{value:e.id,children:[e.name,` · `,e.id]},e.id))]}),(0,p.jsx)(`p`,{children:l(`deviceGroupsPrimaryBotHint`)})]}),S?.room.router?.enabled&&(0,p.jsxs)(`p`,{children:[`AI Router · `,S.room.router.deviceId,` · `,S.room.router.model,` ·`,` `,S.room.router.thinkingLevel]}),(0,p.jsxs)(`div`,{className:`dc-actions`,children:[(0,p.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:V||!e||N,onClick:()=>P(!0),children:[(0,p.jsx)(n,{}),` `,l(`deviceGroupsCreateBot`)]}),(0,p.jsx)(`button`,{className:`dc-button`,type:`submit`,disabled:V||!e||(k?!F.trim():!S),children:l(k?`deviceGroupsCreate`:`deviceExecSave`)}),(0,p.jsx)(`button`,{className:`dc-button`,type:`button`,onClick:()=>{Z(),K.current=null,s&&c?.(),A(!1),M(!1),D(``)},children:l(`cancel`)})]})]}):$?(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(`div`,{className:`dg-title`,children:(0,p.jsxs)(`h2`,{children:[(0,p.jsx)(r,{}),` `,$.name]})}),(0,p.jsxs)(`div`,{className:`dc-actions`,children:[(0,p.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:()=>_($.id),children:[(0,p.jsx)(a,{}),l(`deviceGroupManagerOpenChat`)]}),(0,p.jsxs)(`button`,{className:`dc-button`,type:`button`,disabled:!e,onClick:()=>Q($.id,!0),children:[(0,p.jsx)(r,{}),l(`deviceGroupManagerManageMembersTitle`)]})]})]}):(0,p.jsx)(`p`,{className:`dg-empty`,children:l(`deviceGroupsChoose`)})]}),N&&(0,p.jsx)(te,{createOnly:!0,onCancel:()=>P(!1),onCreated:(e,t)=>{P(!1),t&&e.enabled?(f(t=>[...t.filter(t=>t.id!==e.id),e]),R(t=>[...new Set([...t,e.id])])):D(l(`deviceGroupsBotSavedHint`))}})]})}export{v as DeviceGroupCreateDialog};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{C as t}from"./fi-
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{C as t}from"./fi-CcqqfamG.js";import{i as n,r,t as i}from"./react-CR5VJ85Q.js";import{t as a}from"./shortcut-stack-hhrDyRBn.js";import{t as o}from"./use-click-outside-CHRhq6cL.js";var s=e(n(),1),c=r(),l=i();function u({align:e,triggerLeft:t,triggerRight:n,menuWidth:r,viewportWidth:i,margin:a=8}){if(r<=0||i<=0)return 0;let o=e===`left`?t:n-r,s=Math.max(a,i-a-r);return Math.round(Math.max(a,Math.min(o,s))-o)}function d({triggerRect:e,menuWidth:t,menuHeight:n,viewportWidth:r,viewportHeight:i,direction:a=`down`,align:o=`right`,gap:s=6,margin:c=8}){if(t<=0||r<=0||i<=0)return{left:Math.round(e.left),top:Math.round(e.bottom+s)};let l=Math.max(c,r-c-t),u=Math.max(c,i-c-n),d=c,f=c,p,m=Math.max(0,e.top-s-c),h=Math.max(0,i-e.bottom-s-c);if(a===`right`)d=e.right+s,d+t>r-c&&e.left-t-s>=c&&(d=e.left-t-s),d=Math.max(c,Math.min(d,l)),f=e.top,f+n>i-c&&(f=i-c-n),f=Math.max(c,Math.min(f,u)),p=Math.max(0,i-2*c);else if(a===`left`)d=e.left-t-s,d<c&&e.right+s+t<=r-c&&(d=e.right+s),d=Math.max(c,Math.min(d,l)),f=e.top,f+n>i-c&&(f=i-c-n),f=Math.max(c,Math.min(f,u)),p=Math.max(0,i-2*c);else if(a===`up`){m>=n?(f=e.top-n-s,p=m):h>=n||h>m?(f=e.bottom+s,p=h):(p=m,f=e.top-Math.min(n,m)-s);let r=Math.max(c,i-c-Math.min(n,p));f=Math.max(c,Math.min(f,r));let a=o===`left`?e.left:e.right-t;d=Math.max(c,Math.min(a,l))}else{h>=n?(f=e.bottom+s,p=h):m>=n?(f=e.top-n-s,p=m):m>h?(f=e.top-Math.min(n,m)-s,p=m):(f=e.bottom+s,p=h);let r=Math.max(c,i-c-Math.min(n,p));f=Math.max(c,Math.min(f,r));let a=o===`left`?e.left:e.right-t;d=Math.max(c,Math.min(a,l))}return{left:Math.round(d),top:Math.round(f),...p===void 0?{}:{maxHeight:Math.round(p)}}}function f({trigger:e,open:n,onOpenChange:r,children:i,align:f=`right`,fit:p=!1,direction:m=`down`,portal:h=!1,tip:g,caret:_=!0,menuClassName:v,triggerClassName:y,onContextMenu:b,dataBarItem:x,menuRef:S,menuStyle:C,className:w}){let T=(0,s.useRef)(null),E=(0,s.useRef)(null),[D,O]=(0,s.useState)(0),[k,A]=(0,s.useState)(null),j=e=>{E.current=e,typeof S==`function`?S(e):S&&`current`in S&&(S.current=e)},M=()=>{let e=T.current,t=E.current;if(!e||!t)return;if(window.innerWidth<=768){D!==0&&O(0);return}let n=t.getBoundingClientRect(),r=e.getBoundingClientRect();if(r.width===0&&r.height===0||n.width===0){D!==0&&O(0);return}if(h){let e=d({triggerRect:r,menuWidth:n.width,menuHeight:n.height,viewportWidth:window.innerWidth,viewportHeight:window.innerHeight,direction:m,align:f,gap:6,margin:8});A(t=>t?.left===e.left&&t?.top===e.top&&t?.maxHeight===e.maxHeight?t:e)}else{let e=n.width,t=u({align:f,triggerLeft:r.left,triggerRight:r.right,menuWidth:e,viewportWidth:window.innerWidth,margin:8});t!==D&&O(t)}};(0,s.useLayoutEffect)(()=>{n?M():(D!==0&&O(0),k!==null&&A(null))}),(0,s.useEffect)(()=>{if(n)return window.addEventListener(`resize`,M),h&&window.addEventListener(`scroll`,M,!0),()=>{window.removeEventListener(`resize`,M),h&&window.removeEventListener(`scroll`,M,!0)}},[n,D,h,m,f]),o(T,()=>r(!1),{enabled:n,ignore:E}),a(()=>r(!1),n);let N=typeof window<`u`&&window.innerWidth<=768?{...C,pointerEvents:`auto`}:{...C,position:`fixed`,left:k?`${k.left}px`:`-9999px`,top:k?`${k.top}px`:`-9999px`,maxHeight:k?.maxHeight==null?C?.maxHeight:C?.maxHeight==null?`${k.maxHeight}px`:`min(${k.maxHeight}px, ${C.maxHeight})`,right:`auto`,bottom:`auto`,pointerEvents:`auto`,visibility:k?`visible`:`hidden`},P=k!=null&&T.current?k.top<T.current.getBoundingClientRect().top:m===`up`;return(0,l.jsxs)(`div`,{className:`dropdown ${f} ${p?`fit`:``} ${m===`up`?`dd-up`:``} ${w??``}`.trim(),ref:T,children:[(0,l.jsxs)(`button`,{type:`button`,className:y??`chip`,onClick:()=>r(!n),onContextMenu:b,"aria-expanded":n,"data-tip":g,"data-bar-item":x,children:[e,_&&(0,l.jsx)(t,{className:`dd-caret ${n?`up`:``}`})]}),n&&(h?(0,c.createPortal)((0,l.jsx)(`div`,{className:`dd-portal-wrapper dropdown ${f} ${p?`fit`:``} ${P?`dd-up`:``}`,style:{position:`fixed`,left:0,top:0,width:`100%`,height:`100%`,pointerEvents:`none`,zIndex:9999},children:(0,l.jsx)(`div`,{className:`dd-menu ${v??``}`,ref:j,style:N,onPointerDown:e=>e.stopPropagation(),onMouseDown:e=>e.stopPropagation(),onWheel:e=>e.stopPropagation(),children:i})}),document.body):(0,l.jsx)(`div`,{className:`dd-menu ${v??``}`,ref:j,onPointerDown:e=>e.stopPropagation(),onMouseDown:e=>e.stopPropagation(),onWheel:e=>e.stopPropagation(),style:D===0?C:{...C,transform:C?.transform?`${C.transform} translateX(${D}px)`:`translateX(${D}px)`},children:i}))]})}function p({active:e,disabled:t=!1,title:n,onClick:r,children:i}){return(0,l.jsx)(`button`,{type:`button`,className:`dd-item ${e?`active`:``}`,disabled:t,title:n,onClick:r,children:i})}export{p as n,f as t};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{A as t,Ct as n,Fn as r,G as i,Lt as a,P as o,U as ee,V as te,W as ne,_t as re,b as ie,ft as ae,kn as oe,ln as se,pt as ce,sn as le,un as ue,vn as de}from"./fi-
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{A as t,Ct as n,Fn as r,G as i,Lt as a,P as o,U as ee,V as te,W as ne,_t as re,b as ie,ft as ae,kn as oe,ln as se,pt as ce,sn as le,un as ue,vn as de}from"./fi-CcqqfamG.js";import{i as s,t as c}from"./react-CR5VJ85Q.js";import{t as fe}from"./overlay-stack-BHdOmj3G.js";import{t as pe}from"./app-globals-wu8LLlnA.js";import{F as me,_t as he,bt as ge,et as _e,nt as ve,u as ye}from"./index-Dbv9RJwm.js";var l=e(s(),1),u=`未命名章节`,be=`previewTocUntitled`;function xe(e){return String(e??``).trim().replace(/[\s\u3000]+/g,`-`).replace(/[^\p{L}\p{N}_-]+/gu,`-`).replace(/-{2,}/g,`-`).replace(/^-+|-+$/g,``).slice(0,80)||`section`}function Se(e,t=u){let n=new Map;return e.map(({level:e,label:r})=>{let i=String(r??``).replace(/\s+/g,` `).trim(),a=xe(i||u),o=(n.get(a)??0)+1;return n.set(a,o),{level:e,id:o===1?a:`${a}-${o}`,label:i||t}})}function d(e){return e.length>=2}var f=c(),Ce=5e3,we=`pi-web-ui:preview-toc`;function p({file:e,files:s,activeIndex:c,onSelectFile:u,composerSessionId:xe,content:p,onAddLines:Te,onAttach:Ee,onClose:De,uiFilePreviewToolbar:Oe,onUiAction:ke}){let _=de(),Ae=fe(),[v,je]=(0,l.useState)(null),[y,Me]=(0,l.useState)(!1),[b,x]=(0,l.useState)(null),[Ne,Pe]=(0,l.useState)(!1),[Fe,Ie]=(0,l.useState)(!1),[S,C]=(0,l.useState)(!1),[w,T]=(0,l.useState)(``),[E,D]=(0,l.useState)(!0),[O,k]=(0,l.useState)(!0),A=(0,l.useRef)(!1),[j,Le]=(0,l.useState)(!0),[M,Re]=(0,l.useState)(!1),[N,ze]=(0,l.useState)(100),P=(0,l.useRef)(0),F=(0,l.useRef)(!1),I=(0,l.useRef)(null),[Be,L]=(0,l.useState)(!1),[Ve,R]=(0,l.useState)(!1),z=(0,l.useRef)(!1),B=(0,l.useRef)(null);(0,l.useEffect)(()=>()=>{I.current&&clearTimeout(I.current),B.current&&clearTimeout(B.current)},[]),(0,l.useEffect)(()=>{Me(!0),je(null),x(null),C(!1),T(``),D(!0),k(!0),A.current=!1,z.current=!1,L(!1),R(!1),B.current&&clearTimeout(B.current),pe({type:`read_file`,path:e.path})},[e.path]),(0,l.useEffect)(()=>{p&&p.path===e.path&&(je(p),S||T(p.text),Me(!1),z.current&&(z.current=!1,B.current&&clearTimeout(B.current),L(!1),R(!1),C(!1),T(p.text),A.current&&(m(e.name)&&D(!0),g(e.name)&&k(!0)),x(null)))},[p,S,e.path]),(0,l.useEffect)(()=>{let e=e=>{if(e.key===`Escape`){e.preventDefault(),U();return}if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`s`&&S){e.preventDefault(),Ye();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(),Ge())};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[De,v,S,w]),(0,l.useEffect)(()=>{let e=()=>{F.current=!1,Pe(!1)};return window.addEventListener(`mouseup`,e),()=>window.removeEventListener(`mouseup`,e)},[]);let V=(0,l.useMemo)(()=>{if(!v)return[];let e=v.text.split(`
|
|
2
2
|
`);return e.length>0&&e[e.length-1]===``&&e.pop(),e.slice(0,Ce)},[v]),He=v?.lines??0,Ue=He>Ce,We=(e,t)=>{if(t){let t=P.current>0?P.current:e;x({start:Math.min(t,e),end:Math.max(t,e)})}else P.current=e,x({start:e,end:e})},Ge=()=>{V.length!==0&&(P.current=1,x({start:1,end:V.length}))},Ke=()=>{b&&(Te(e.path,e.name,b.start,b.end),Ie(!0),I.current&&clearTimeout(I.current),I.current=setTimeout(()=>Ie(!1),1400))},H=v!==null&&v.kind===`text`&&!v.binary&&!v.truncated&&!h(e.name),qe=()=>{z.current=!1,B.current&&clearTimeout(B.current),L(!1),R(!1),T(v?.text??``),C(!1),A.current&&(m(e.name)&&D(!0),g(e.name)&&k(!0))},Je=()=>{if(S){if(w!==(v?.text??``)&&!window.confirm(_(`discardFileChanges`)))return;qe();return}H&&v&&(A.current=m(e.name)&&E||g(e.name)&&O,m(e.name)&&D(!1),g(e.name)&&k(!1),x(null),T(v.text),C(!0))},Ye=()=>{S&&v&&H&&pe({type:`write_file`,path:e.path,text:w})&&(z.current=!0,R(!1),L(!0),B.current&&clearTimeout(B.current),B.current=setTimeout(()=>{z.current=!1,L(!1),R(!0)},5e3))},U=()=>{(!S||w===(v?.text??``)||window.confirm(_(`discardFileChanges`)))&&De()},Xe=e=>{ze(Math.min(200,Math.max(50,e)))},Ze=b?b.end-b.start+1:0,W=v?.binary??!1,Qe=v?.truncated??!1,G=v?.kind??`text`,$e=m(e.name)||h(e.name),K=g(e.name),et=h(e.name),q=$e&&E&&!S&&G===`text`&&!W,J=K&&O&&!S&&G===`text`&&!W,[Y,tt]=(0,l.useState)(()=>{try{return localStorage.getItem(we)===`1`}catch{return!1}});(0,l.useEffect)(()=>{try{localStorage.setItem(we,Y?`1`:`0`)}catch{}},[Y]);let[X,nt]=(0,l.useState)([]),[rt,it]=(0,l.useState)(``),Z=(0,l.useRef)(null);(0,l.useEffect)(()=>{let e=Z.current;if(!e||!q){nt([]);return}let t=[...e.querySelectorAll(`h1, h2, h3, h4, h5, h6`)],n=Se(t.map(e=>({level:Number(e.tagName.slice(1)),label:e.textContent??``})),_(be));t.forEach((e,t)=>{e.id||=n[t].id}),nt(n)},[q,v?.text,e.path,_]),(0,l.useEffect)(()=>{let e=Z.current;if(!e||!Y||!d(X))return;let t=X.map(t=>e.querySelector(`#${CSS.escape(t.id)}`)).filter(e=>e!==null);if(t.length===0)return;let n=new IntersectionObserver(e=>{let t=e.filter(e=>e.isIntersecting).sort((e,t)=>e.boundingClientRect.top-t.boundingClientRect.top)[0];t?.target.id&&it(t.target.id)},{rootMargin:`0px 0px -70% 0px`});for(let e of t)n.observe(e);return()=>n.disconnect()},[X,Y]);let Q=e=>r(oe(`/api/file?clientId=${encodeURIComponent(ve())}&path=${encodeURIComponent(e)}`)),at=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 r(oe(`${n}?clientId=${encodeURIComponent(ve())}&allowJs=1`))},ot={"host:fp-md":$e&&G===`text`&&!W&&v?(0,f.jsx)(`button`,{type:`button`,className:`fp-attach markdown ${E?`on`:``}`,"data-tip":_(E?`showMarkdownSource`:`showMarkdownPreview`),disabled:S,onClick:()=>D(e=>!e),children:E?(0,f.jsx)(i,{}):(0,f.jsx)(t,{})}):null,"host:fp-toc":q&&d(X)?(0,f.jsx)(`button`,{type:`button`,className:`fp-attach toc ${Y?`on`:``}`,"data-tip":_(Y?`previewTocHide`:`previewTocShow`),onClick:()=>tt(e=>!e),children:(0,f.jsx)(ce,{})}):null,"host:fp-html":K&&G===`text`&&!W&&v?(0,f.jsx)(`button`,{type:`button`,className:`fp-attach html ${O?`on`:``}`,"data-tip":_(O?`showHtmlSource`:`showHtmlPreview`),disabled:S,onClick:()=>k(e=>!e),children:O?(0,f.jsx)(t,{}):(0,f.jsx)(i,{})}):null,"host:fp-external":K&&G===`text`&&!W&&v?(0,f.jsx)(`a`,{className:`fp-attach open`,href:at(e.path),target:`_blank`,rel:`noopener noreferrer`,"data-tip":_(`openInNewTab`),"aria-label":_(`openInNewTab`),children:(0,f.jsx)(ne,{})}):null,"host:fp-edit":G===`text`&&!W&&v?(0,f.jsx)(`button`,{type:`button`,className:`fp-attach edit ${S?`on`:``}`,"data-tip":_(Qe?`fileEditTruncated`:S?`exitEditFile`:`editFile`),disabled:!H&&!S,onClick:Je,children:(0,f.jsx)(ee,{})}):null,"host:fp-wrap":G===`text`&&!W&&!q&&!J?(0,f.jsx)(`button`,{type:`button`,className:`fp-attach wrap ${j?`on`:``}`,"data-tip":_(j?`disableWrap`:`enableWrap`),onClick:()=>Le(e=>!e),children:(0,f.jsx)(o,{})}):null,"host:fp-zoom":G===`text`&&v?(0,f.jsxs)(`span`,{className:`fp-zoom`,children:[(0,f.jsx)(`button`,{type:`button`,className:`fp-attach zoom-out`,"data-tip":_(`zoomOut`),disabled:N<=50,onClick:()=>Xe(N-10),children:(0,f.jsx)(ue,{})}),(0,f.jsxs)(`button`,{type:`button`,className:`fp-zoom-val`,title:_(`resetZoom`),onClick:()=>ze(100),children:[N,`%`]}),(0,f.jsx)(`button`,{type:`button`,className:`fp-attach zoom-in`,"data-tip":_(`zoomIn`),disabled:N>=200,onClick:()=>Xe(N+10),children:(0,f.jsx)(se,{})})]}):null,"host:fp-download":(0,f.jsx)(`button`,{type:`button`,className:`fp-attach download`,"data-tip":_(`downloadFile`),onClick:()=>void ge(e.path,e.name),children:(0,f.jsx)(te,{})}),"host:fp-ref":(0,f.jsx)(`button`,{type:`button`,className:`fp-attach ref`,"data-tip":_(`referenceTip`),onClick:()=>Ee(e.path,e.name,`reference`),children:(0,f.jsx)(ae,{})}),"host:fp-full":(0,f.jsx)(`button`,{type:`button`,className:`fp-attach full ${M?`on`:``}`,"data-tip":_(M?`exitFullscreen`:`fullscreen`),onClick:()=>Re(e=>!e),children:M?(0,f.jsx)(n,{}):(0,f.jsx)(re,{})}),"host:fp-close":null},st=Oe===void 0?[`host:fp-md`,`host:fp-toc`,`host:fp-html`,`host:fp-external`,`host:fp-edit`,`host:fp-wrap`,`host:fp-zoom`,`host:fp-download`,`host:fp-ref`,`host:fp-full`].map(e=>({id:e,source:`host`})):Oe.filter(e=>!e.hidden&&e.id!==`host:fp-close`),$=Array.isArray(s)&&s.length>1?s:null,ct=typeof c==`number`?c:0;return!$&&G===`image`&&!y?(0,f.jsx)(ye,{src:Q(e.path),alt:e.name,onClose:U,composerSessionId:xe}):(0,f.jsx)(`div`,{className:`fp-overlay ${M?`fullscreen`:``}`,style:{zIndex:Ae},onMouseDown:e=>{e.target===e.currentTarget&&U()},children:(0,f.jsxs)(`div`,{className:`fp ${M?`fullscreen`:``} ${et?`is-ppt`:``}`,style:{"--fp-zoom":N/100},children:[(0,f.jsxs)(`div`,{className:`fp-head`,onDoubleClick:e=>{let t=e.target;t&&!t.closest(`button, a, input`)&&Re(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:[v&&G===`text`&&!W&&_(`fileLines`,{n:He}),v&&` · ${he(v.size)}`]}),(0,f.jsx)(`span`,{className:`fp-head-actions`,children:me(st,ot,ke)}),(0,f.jsx)(`button`,{type:`button`,className:`fp-close`,title:_(`close`),"aria-label":_(`close`),onClick:U,children:(0,f.jsx)(le,{})})]}),$&&(0,f.jsx)(`div`,{className:`fp-tabs`,role:`tablist`,"aria-label":e.path,children:$.map((e,t)=>(0,f.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":t===ct,className:`fp-tab${t===ct?` on`:``}`,title:e.path,onClick:()=>u?.(t),children:[(0,f.jsx)(`span`,{className:`fp-tab-name`,children:e.name}),(0,f.jsx)(`span`,{className:`fp-tab-index`,children:t+1})]},`${e.path}\u0000${t}`))}),Qe&&G===`text`&&!W&&(0,f.jsx)(`div`,{className:`fp-notice`,children:h(e.name)?_(`previewLinesTruncated`,{n:V.length}):_(`previewTruncated`)}),y&&!v&&(0,f.jsx)(`div`,{className:`fp-empty`,children:_(`loading`)}),!y&&G===`none`&&!W&&(0,f.jsx)(`div`,{className:`fp-empty`,children:_(`previewNotSupported`)}),!y&&G===`image`&&v&&$&&(0,f.jsx)(`div`,{className:`fp-media-wrap`,children:(0,f.jsx)(`img`,{className:`fp-media`,src:Q(e.path),alt:e.name})}),!y&&G===`video`&&(0,f.jsx)(`div`,{className:`fp-media-wrap`,children:(0,f.jsx)(`video`,{className:`fp-media`,src:Q(e.path),controls:!0,preload:`metadata`})}),!y&&G===`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}),v?.size?(0,f.jsx)(`div`,{className:`fp-audio-size`,children:he(v.size)}):null]}),(0,f.jsx)(`audio`,{className:`fp-audio-element`,src:Q(e.path),controls:!0,autoPlay:!0,preload:`metadata`})]})}),!y&&J&&v&&(0,f.jsx)(`div`,{className:`fp-html`,children:(0,f.jsx)(`iframe`,{className:`fp-html-frame`,src:at(e.path),title:e.name,sandbox:`allow-scripts`,referrerPolicy:`no-referrer`})}),!y&&q&&v&&(0,f.jsx)(`div`,{className:h(e.name)?`fp-markdown msg-text fp-office`:`fp-markdown msg-text`,children:(0,f.jsxs)(`div`,{className:Y&&d(X)?`fp-toc-layout`:void 0,children:[Y&&d(X)&&(0,f.jsx)(`nav`,{className:`fp-toc`,"aria-label":_(`previewTocLabel`),children:X.map(e=>(0,f.jsx)(`a`,{className:`l${Math.min(e.level,6)}${e.id===rt?` on`:``}`,href:`#${e.id}`,title:e.label,onClick:t=>{t.preventDefault(),Z.current?.querySelector(`#${CSS.escape(e.id)}`)?.scrollIntoView({behavior:`smooth`,block:`start`})},children:e.label},e.id))}),(0,f.jsx)(`div`,{className:`fp-markdown-zoom`,ref:Z,children:(0,f.jsx)(_e,{text:v.text})})]})}),!y&&W&&G!==`image`&&G!==`video`&&v&&(0,f.jsxs)(`div`,{className:`fp-hex-wrap`,children:[(0,f.jsxs)(`div`,{className:`fp-notice`,children:[_(`binaryFile`),v.truncated&&_(`binaryHexTruncated`)]}),(0,f.jsx)(`pre`,{className:`fp-hex`,children:v.text})]}),!y&&S&&G===`text`&&!W&&v&&(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`textarea`,{className:`fp-editor ${j?``:`no-wrap`}`,value:w,onChange:e=>T(e.target.value),wrap:j?`soft`:`off`,spellCheck:!1,autoFocus:!0}),Ve&&(0,f.jsx)(`div`,{className:`fp-notice`,role:`alert`,children:_(`saveResultUnknown`)})]}),!y&&!q&&!J&&!S&&G===`text`&&!W&&v&&V.length===0&&(0,f.jsx)(`div`,{className:`fp-empty`,children:_(`emptyFile`)}),!y&&!q&&!J&&!S&&G===`text`&&!W&&V.length>0&&(0,f.jsxs)(`div`,{className:`fp-code ${Ne?`dragging`:``} ${j?``:`no-wrap`}`,onMouseDown:e=>{e.button===0&&e.preventDefault()},children:[V.map((e,t)=>{let n=t+1,r=b!==null&&n>=b.start&&n<=b.end;return(0,f.jsxs)(`div`,{className:`fp-line ${r?`sel`:``}`,onMouseDown:e=>{e.button===0&&(We(n,e.shiftKey),F.current=!0,Pe(!0))},onMouseEnter:()=>{F.current&&We(n,!0)},children:[(0,f.jsx)(`span`,{className:`fp-num`,children:n}),(0,f.jsx)(`span`,{className:`fp-code-text`,children:e})]},n)}),Ue&&(0,f.jsx)(`div`,{className:`fp-lines-note`,children:_(`previewLinesTruncated`,{n:Ce})})]}),(S||!q&&!J&&G===`text`)&&(0,f.jsx)(`div`,{className:`fp-foot`,children:S?(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`span`,{className:`fp-hint`,children:_(`editFile`)}),(0,f.jsxs)(`div`,{className:`fp-actions`,children:[(0,f.jsx)(`button`,{type:`button`,className:`btn`,onClick:Je,children:_(`cancel`)}),(0,f.jsxs)(`button`,{type:`button`,className:`btn primary`,disabled:Be||w===(v?.text??``),onClick:Ye,children:[(0,f.jsx)(a,{}),` `,_(`saveFile`)]})]})]}):(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`span`,{className:`fp-hint`,children:b?_(`selectedRange`,{n:Ze,start:b.start,end:b.end}):_(`selectLinesHint`)}),(0,f.jsxs)(`div`,{className:`fp-actions`,children:[(0,f.jsx)(`button`,{type:`button`,className:`btn`,disabled:V.length===0,onClick:Ge,children:_(`selectAll`)}),(0,f.jsx)(`button`,{type:`button`,className:`btn`,disabled:!b,onClick:()=>x(null),children:_(`clearSelection`)}),(0,f.jsxs)(`button`,{type:`button`,className:`btn primary`,disabled:!b||W,onClick:Ke,children:[Fe?(0,f.jsx)(ie,{}):null,_(Fe?`addedToChat`:`addToChat`)]})]})]})})]})})}function m(e){let t=e.toLowerCase();return t.endsWith(`.md`)||t.endsWith(`.markdown`)}function h(e){let t=e.toLowerCase();return t.endsWith(`.docx`)||t.endsWith(`.xlsx`)||t.endsWith(`.xlsm`)||t.endsWith(`.pptx`)||t.endsWith(`.pptm`)||t.endsWith(`.ppsx`)||t.endsWith(`.potx`)}function g(e){let t=e.toLowerCase();return t.endsWith(`.html`)||t.endsWith(`.htm`)||t.endsWith(`.xhtml`)}export{p as FilePreview};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{A as t,Ct as n,Fn as r,G as i,Lt as a,P as o,U as ee,V as te,W as ne,_t as re,b as ie,ft as ae,kn as oe,ln as se,pt as ce,sn as le,un as ue,vn as de}from"./fi-
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{A as t,Ct as n,Fn as r,G as i,Lt as a,P as o,U as ee,V as te,W as ne,_t as re,b as ie,ft as ae,kn as oe,ln as se,pt as ce,sn as le,un as ue,vn as de}from"./fi-CcqqfamG.js";import{i as s,t as c}from"./react-CR5VJ85Q.js";import{t as fe}from"./overlay-stack-BHdOmj3G.js";import{t as pe}from"./app-globals-wu8LLlnA.js";import{F as me,_t as he,bt as ge,et as _e,nt as ve,u as ye}from"./index-BQb8EOhk.js";var l=e(s(),1),u=`未命名章节`,be=`previewTocUntitled`;function xe(e){return String(e??``).trim().replace(/[\s\u3000]+/g,`-`).replace(/[^\p{L}\p{N}_-]+/gu,`-`).replace(/-{2,}/g,`-`).replace(/^-+|-+$/g,``).slice(0,80)||`section`}function Se(e,t=u){let n=new Map;return e.map(({level:e,label:r})=>{let i=String(r??``).replace(/\s+/g,` `).trim(),a=xe(i||u),o=(n.get(a)??0)+1;return n.set(a,o),{level:e,id:o===1?a:`${a}-${o}`,label:i||t}})}function d(e){return e.length>=2}var f=c(),Ce=5e3,we=`pi-web-ui:preview-toc`;function p({file:e,files:s,activeIndex:c,onSelectFile:u,composerSessionId:xe,content:p,onAddLines:Te,onAttach:Ee,onClose:De,uiFilePreviewToolbar:Oe,onUiAction:ke}){let _=de(),Ae=fe(),[v,je]=(0,l.useState)(null),[y,Me]=(0,l.useState)(!1),[b,x]=(0,l.useState)(null),[Ne,Pe]=(0,l.useState)(!1),[Fe,Ie]=(0,l.useState)(!1),[S,C]=(0,l.useState)(!1),[w,T]=(0,l.useState)(``),[E,D]=(0,l.useState)(!0),[O,k]=(0,l.useState)(!0),A=(0,l.useRef)(!1),[j,Le]=(0,l.useState)(!0),[M,Re]=(0,l.useState)(!1),[N,ze]=(0,l.useState)(100),P=(0,l.useRef)(0),F=(0,l.useRef)(!1),I=(0,l.useRef)(null),[Be,L]=(0,l.useState)(!1),[Ve,R]=(0,l.useState)(!1),z=(0,l.useRef)(!1),B=(0,l.useRef)(null);(0,l.useEffect)(()=>()=>{I.current&&clearTimeout(I.current),B.current&&clearTimeout(B.current)},[]),(0,l.useEffect)(()=>{Me(!0),je(null),x(null),C(!1),T(``),D(!0),k(!0),A.current=!1,z.current=!1,L(!1),R(!1),B.current&&clearTimeout(B.current),pe({type:`read_file`,path:e.path})},[e.path]),(0,l.useEffect)(()=>{p&&p.path===e.path&&(je(p),S||T(p.text),Me(!1),z.current&&(z.current=!1,B.current&&clearTimeout(B.current),L(!1),R(!1),C(!1),T(p.text),A.current&&(m(e.name)&&D(!0),g(e.name)&&k(!0)),x(null)))},[p,S,e.path]),(0,l.useEffect)(()=>{let e=e=>{if(e.key===`Escape`){e.preventDefault(),U();return}if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`s`&&S){e.preventDefault(),Ye();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(),Ge())};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[De,v,S,w]),(0,l.useEffect)(()=>{let e=()=>{F.current=!1,Pe(!1)};return window.addEventListener(`mouseup`,e),()=>window.removeEventListener(`mouseup`,e)},[]);let V=(0,l.useMemo)(()=>{if(!v)return[];let e=v.text.split(`
|
|
2
2
|
`);return e.length>0&&e[e.length-1]===``&&e.pop(),e.slice(0,Ce)},[v]),He=v?.lines??0,Ue=He>Ce,We=(e,t)=>{if(t){let t=P.current>0?P.current:e;x({start:Math.min(t,e),end:Math.max(t,e)})}else P.current=e,x({start:e,end:e})},Ge=()=>{V.length!==0&&(P.current=1,x({start:1,end:V.length}))},Ke=()=>{b&&(Te(e.path,e.name,b.start,b.end),Ie(!0),I.current&&clearTimeout(I.current),I.current=setTimeout(()=>Ie(!1),1400))},H=v!==null&&v.kind===`text`&&!v.binary&&!v.truncated&&!h(e.name),qe=()=>{z.current=!1,B.current&&clearTimeout(B.current),L(!1),R(!1),T(v?.text??``),C(!1),A.current&&(m(e.name)&&D(!0),g(e.name)&&k(!0))},Je=()=>{if(S){if(w!==(v?.text??``)&&!window.confirm(_(`discardFileChanges`)))return;qe();return}H&&v&&(A.current=m(e.name)&&E||g(e.name)&&O,m(e.name)&&D(!1),g(e.name)&&k(!1),x(null),T(v.text),C(!0))},Ye=()=>{S&&v&&H&&pe({type:`write_file`,path:e.path,text:w})&&(z.current=!0,R(!1),L(!0),B.current&&clearTimeout(B.current),B.current=setTimeout(()=>{z.current=!1,L(!1),R(!0)},5e3))},U=()=>{(!S||w===(v?.text??``)||window.confirm(_(`discardFileChanges`)))&&De()},Xe=e=>{ze(Math.min(200,Math.max(50,e)))},Ze=b?b.end-b.start+1:0,W=v?.binary??!1,Qe=v?.truncated??!1,G=v?.kind??`text`,$e=m(e.name)||h(e.name),K=g(e.name),et=h(e.name),q=$e&&E&&!S&&G===`text`&&!W,J=K&&O&&!S&&G===`text`&&!W,[Y,tt]=(0,l.useState)(()=>{try{return localStorage.getItem(we)===`1`}catch{return!1}});(0,l.useEffect)(()=>{try{localStorage.setItem(we,Y?`1`:`0`)}catch{}},[Y]);let[X,nt]=(0,l.useState)([]),[rt,it]=(0,l.useState)(``),Z=(0,l.useRef)(null);(0,l.useEffect)(()=>{let e=Z.current;if(!e||!q){nt([]);return}let t=[...e.querySelectorAll(`h1, h2, h3, h4, h5, h6`)],n=Se(t.map(e=>({level:Number(e.tagName.slice(1)),label:e.textContent??``})),_(be));t.forEach((e,t)=>{e.id||=n[t].id}),nt(n)},[q,v?.text,e.path,_]),(0,l.useEffect)(()=>{let e=Z.current;if(!e||!Y||!d(X))return;let t=X.map(t=>e.querySelector(`#${CSS.escape(t.id)}`)).filter(e=>e!==null);if(t.length===0)return;let n=new IntersectionObserver(e=>{let t=e.filter(e=>e.isIntersecting).sort((e,t)=>e.boundingClientRect.top-t.boundingClientRect.top)[0];t?.target.id&&it(t.target.id)},{rootMargin:`0px 0px -70% 0px`});for(let e of t)n.observe(e);return()=>n.disconnect()},[X,Y]);let Q=e=>r(oe(`/api/file?clientId=${encodeURIComponent(ve())}&path=${encodeURIComponent(e)}`)),at=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 r(oe(`${n}?clientId=${encodeURIComponent(ve())}&allowJs=1`))},ot={"host:fp-md":$e&&G===`text`&&!W&&v?(0,f.jsx)(`button`,{type:`button`,className:`fp-attach markdown ${E?`on`:``}`,"data-tip":_(E?`showMarkdownSource`:`showMarkdownPreview`),disabled:S,onClick:()=>D(e=>!e),children:E?(0,f.jsx)(i,{}):(0,f.jsx)(t,{})}):null,"host:fp-toc":q&&d(X)?(0,f.jsx)(`button`,{type:`button`,className:`fp-attach toc ${Y?`on`:``}`,"data-tip":_(Y?`previewTocHide`:`previewTocShow`),onClick:()=>tt(e=>!e),children:(0,f.jsx)(ce,{})}):null,"host:fp-html":K&&G===`text`&&!W&&v?(0,f.jsx)(`button`,{type:`button`,className:`fp-attach html ${O?`on`:``}`,"data-tip":_(O?`showHtmlSource`:`showHtmlPreview`),disabled:S,onClick:()=>k(e=>!e),children:O?(0,f.jsx)(t,{}):(0,f.jsx)(i,{})}):null,"host:fp-external":K&&G===`text`&&!W&&v?(0,f.jsx)(`a`,{className:`fp-attach open`,href:at(e.path),target:`_blank`,rel:`noopener noreferrer`,"data-tip":_(`openInNewTab`),"aria-label":_(`openInNewTab`),children:(0,f.jsx)(ne,{})}):null,"host:fp-edit":G===`text`&&!W&&v?(0,f.jsx)(`button`,{type:`button`,className:`fp-attach edit ${S?`on`:``}`,"data-tip":_(Qe?`fileEditTruncated`:S?`exitEditFile`:`editFile`),disabled:!H&&!S,onClick:Je,children:(0,f.jsx)(ee,{})}):null,"host:fp-wrap":G===`text`&&!W&&!q&&!J?(0,f.jsx)(`button`,{type:`button`,className:`fp-attach wrap ${j?`on`:``}`,"data-tip":_(j?`disableWrap`:`enableWrap`),onClick:()=>Le(e=>!e),children:(0,f.jsx)(o,{})}):null,"host:fp-zoom":G===`text`&&v?(0,f.jsxs)(`span`,{className:`fp-zoom`,children:[(0,f.jsx)(`button`,{type:`button`,className:`fp-attach zoom-out`,"data-tip":_(`zoomOut`),disabled:N<=50,onClick:()=>Xe(N-10),children:(0,f.jsx)(ue,{})}),(0,f.jsxs)(`button`,{type:`button`,className:`fp-zoom-val`,title:_(`resetZoom`),onClick:()=>ze(100),children:[N,`%`]}),(0,f.jsx)(`button`,{type:`button`,className:`fp-attach zoom-in`,"data-tip":_(`zoomIn`),disabled:N>=200,onClick:()=>Xe(N+10),children:(0,f.jsx)(se,{})})]}):null,"host:fp-download":(0,f.jsx)(`button`,{type:`button`,className:`fp-attach download`,"data-tip":_(`downloadFile`),onClick:()=>void ge(e.path,e.name),children:(0,f.jsx)(te,{})}),"host:fp-ref":(0,f.jsx)(`button`,{type:`button`,className:`fp-attach ref`,"data-tip":_(`referenceTip`),onClick:()=>Ee(e.path,e.name,`reference`),children:(0,f.jsx)(ae,{})}),"host:fp-full":(0,f.jsx)(`button`,{type:`button`,className:`fp-attach full ${M?`on`:``}`,"data-tip":_(M?`exitFullscreen`:`fullscreen`),onClick:()=>Re(e=>!e),children:M?(0,f.jsx)(n,{}):(0,f.jsx)(re,{})}),"host:fp-close":null},st=Oe===void 0?[`host:fp-md`,`host:fp-toc`,`host:fp-html`,`host:fp-external`,`host:fp-edit`,`host:fp-wrap`,`host:fp-zoom`,`host:fp-download`,`host:fp-ref`,`host:fp-full`].map(e=>({id:e,source:`host`})):Oe.filter(e=>!e.hidden&&e.id!==`host:fp-close`),$=Array.isArray(s)&&s.length>1?s:null,ct=typeof c==`number`?c:0;return!$&&G===`image`&&!y?(0,f.jsx)(ye,{src:Q(e.path),alt:e.name,onClose:U,composerSessionId:xe}):(0,f.jsx)(`div`,{className:`fp-overlay ${M?`fullscreen`:``}`,style:{zIndex:Ae},onMouseDown:e=>{e.target===e.currentTarget&&U()},children:(0,f.jsxs)(`div`,{className:`fp ${M?`fullscreen`:``} ${et?`is-ppt`:``}`,style:{"--fp-zoom":N/100},children:[(0,f.jsxs)(`div`,{className:`fp-head`,onDoubleClick:e=>{let t=e.target;t&&!t.closest(`button, a, input`)&&Re(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:[v&&G===`text`&&!W&&_(`fileLines`,{n:He}),v&&` · ${he(v.size)}`]}),(0,f.jsx)(`span`,{className:`fp-head-actions`,children:me(st,ot,ke)}),(0,f.jsx)(`button`,{type:`button`,className:`fp-close`,title:_(`close`),"aria-label":_(`close`),onClick:U,children:(0,f.jsx)(le,{})})]}),$&&(0,f.jsx)(`div`,{className:`fp-tabs`,role:`tablist`,"aria-label":e.path,children:$.map((e,t)=>(0,f.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":t===ct,className:`fp-tab${t===ct?` on`:``}`,title:e.path,onClick:()=>u?.(t),children:[(0,f.jsx)(`span`,{className:`fp-tab-name`,children:e.name}),(0,f.jsx)(`span`,{className:`fp-tab-index`,children:t+1})]},`${e.path}\u0000${t}`))}),Qe&&G===`text`&&!W&&(0,f.jsx)(`div`,{className:`fp-notice`,children:h(e.name)?_(`previewLinesTruncated`,{n:V.length}):_(`previewTruncated`)}),y&&!v&&(0,f.jsx)(`div`,{className:`fp-empty`,children:_(`loading`)}),!y&&G===`none`&&!W&&(0,f.jsx)(`div`,{className:`fp-empty`,children:_(`previewNotSupported`)}),!y&&G===`image`&&v&&$&&(0,f.jsx)(`div`,{className:`fp-media-wrap`,children:(0,f.jsx)(`img`,{className:`fp-media`,src:Q(e.path),alt:e.name})}),!y&&G===`video`&&(0,f.jsx)(`div`,{className:`fp-media-wrap`,children:(0,f.jsx)(`video`,{className:`fp-media`,src:Q(e.path),controls:!0,preload:`metadata`})}),!y&&G===`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}),v?.size?(0,f.jsx)(`div`,{className:`fp-audio-size`,children:he(v.size)}):null]}),(0,f.jsx)(`audio`,{className:`fp-audio-element`,src:Q(e.path),controls:!0,autoPlay:!0,preload:`metadata`})]})}),!y&&J&&v&&(0,f.jsx)(`div`,{className:`fp-html`,children:(0,f.jsx)(`iframe`,{className:`fp-html-frame`,src:at(e.path),title:e.name,sandbox:`allow-scripts`,referrerPolicy:`no-referrer`})}),!y&&q&&v&&(0,f.jsx)(`div`,{className:h(e.name)?`fp-markdown msg-text fp-office`:`fp-markdown msg-text`,children:(0,f.jsxs)(`div`,{className:Y&&d(X)?`fp-toc-layout`:void 0,children:[Y&&d(X)&&(0,f.jsx)(`nav`,{className:`fp-toc`,"aria-label":_(`previewTocLabel`),children:X.map(e=>(0,f.jsx)(`a`,{className:`l${Math.min(e.level,6)}${e.id===rt?` on`:``}`,href:`#${e.id}`,title:e.label,onClick:t=>{t.preventDefault(),Z.current?.querySelector(`#${CSS.escape(e.id)}`)?.scrollIntoView({behavior:`smooth`,block:`start`})},children:e.label},e.id))}),(0,f.jsx)(`div`,{className:`fp-markdown-zoom`,ref:Z,children:(0,f.jsx)(_e,{text:v.text})})]})}),!y&&W&&G!==`image`&&G!==`video`&&v&&(0,f.jsxs)(`div`,{className:`fp-hex-wrap`,children:[(0,f.jsxs)(`div`,{className:`fp-notice`,children:[_(`binaryFile`),v.truncated&&_(`binaryHexTruncated`)]}),(0,f.jsx)(`pre`,{className:`fp-hex`,children:v.text})]}),!y&&S&&G===`text`&&!W&&v&&(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`textarea`,{className:`fp-editor ${j?``:`no-wrap`}`,value:w,onChange:e=>T(e.target.value),wrap:j?`soft`:`off`,spellCheck:!1,autoFocus:!0}),Ve&&(0,f.jsx)(`div`,{className:`fp-notice`,role:`alert`,children:_(`saveResultUnknown`)})]}),!y&&!q&&!J&&!S&&G===`text`&&!W&&v&&V.length===0&&(0,f.jsx)(`div`,{className:`fp-empty`,children:_(`emptyFile`)}),!y&&!q&&!J&&!S&&G===`text`&&!W&&V.length>0&&(0,f.jsxs)(`div`,{className:`fp-code ${Ne?`dragging`:``} ${j?``:`no-wrap`}`,onMouseDown:e=>{e.button===0&&e.preventDefault()},children:[V.map((e,t)=>{let n=t+1,r=b!==null&&n>=b.start&&n<=b.end;return(0,f.jsxs)(`div`,{className:`fp-line ${r?`sel`:``}`,onMouseDown:e=>{e.button===0&&(We(n,e.shiftKey),F.current=!0,Pe(!0))},onMouseEnter:()=>{F.current&&We(n,!0)},children:[(0,f.jsx)(`span`,{className:`fp-num`,children:n}),(0,f.jsx)(`span`,{className:`fp-code-text`,children:e})]},n)}),Ue&&(0,f.jsx)(`div`,{className:`fp-lines-note`,children:_(`previewLinesTruncated`,{n:Ce})})]}),(S||!q&&!J&&G===`text`)&&(0,f.jsx)(`div`,{className:`fp-foot`,children:S?(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`span`,{className:`fp-hint`,children:_(`editFile`)}),(0,f.jsxs)(`div`,{className:`fp-actions`,children:[(0,f.jsx)(`button`,{type:`button`,className:`btn`,onClick:Je,children:_(`cancel`)}),(0,f.jsxs)(`button`,{type:`button`,className:`btn primary`,disabled:Be||w===(v?.text??``),onClick:Ye,children:[(0,f.jsx)(a,{}),` `,_(`saveFile`)]})]})]}):(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`span`,{className:`fp-hint`,children:b?_(`selectedRange`,{n:Ze,start:b.start,end:b.end}):_(`selectLinesHint`)}),(0,f.jsxs)(`div`,{className:`fp-actions`,children:[(0,f.jsx)(`button`,{type:`button`,className:`btn`,disabled:V.length===0,onClick:Ge,children:_(`selectAll`)}),(0,f.jsx)(`button`,{type:`button`,className:`btn`,disabled:!b,onClick:()=>x(null),children:_(`clearSelection`)}),(0,f.jsxs)(`button`,{type:`button`,className:`btn primary`,disabled:!b||W,onClick:Ke,children:[Fe?(0,f.jsx)(ie,{}):null,_(Fe?`addedToChat`:`addToChat`)]})]})]})})]})})}function m(e){let t=e.toLowerCase();return t.endsWith(`.md`)||t.endsWith(`.markdown`)}function h(e){let t=e.toLowerCase();return t.endsWith(`.docx`)||t.endsWith(`.xlsx`)||t.endsWith(`.xlsm`)||t.endsWith(`.pptx`)||t.endsWith(`.pptm`)||t.endsWith(`.ppsx`)||t.endsWith(`.potx`)}function g(e){let t=e.toLowerCase();return t.endsWith(`.html`)||t.endsWith(`.htm`)||t.endsWith(`.xhtml`)}export{p as FilePreview};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{At as t,Tn as n,X as r,Z as i,gn as a,sn as ee,vn as te,xt as ne,zt as re}from"./fi-DjvtEEnZ.js";import{i as o,t as s}from"./react-CR5VJ85Q.js";import{i as ie,o as ae,t as c}from"./app-globals-wu8LLlnA.js";import{t as l}from"./composer-bridge-CImnjDHq.js";import{f as oe,s as se,u}from"./plugin-host-VdvQxFkv.js";import{a as ce,c as d,d as le,r as ue}from"./context-menu-state-CEfR7_Lz.js";import{Ft as de,G as fe,w as f}from"./index-CXTnvcJF.js";var p=e(o(),1),m=s(),pe=8e3;function h(e){return e.split(/[\\/]/).filter(Boolean).pop()??e}function me(e,t){return!e||!t||t.startsWith(`/`)||/^[A-Za-z]:[\\/]/.test(t)?t:`${e.replace(/[\\/]+$/,``)}/${t}`}function he(e){return e.kind===`plugin`?`${e.providerId}:${e.action}`:e.path}function ge(e){switch(e.kind){case`session`:return e.title;case`plugin`:return e.title;case`file`:case`folder`:return e.name;default:return h(e.path)}}function _e(e,t,n){let{t:r}=n,i=t.kind===`file`?r(`fileOpenPreview`):t.kind===`folder`?r(`fileEnterDir`):t.kind===`project`?r(`searchMenuSwitchProject`):r(`gsOpen`),a=t.kind===`file`||t.kind===`folder`;return e.map(e=>{if(e.source!==`host`)return e;switch(e.id){case`host:search-open`:return{...e,label:i};case`host:search-open-folder`:return t.kind===`project`?e:{...e,hidden:!0};case`host:search-reveal`:return t.kind===`plugin`?{...e,hidden:!0}:e;case`host:search-pin`:return t.kind===`session`?t.pinned?{...e,label:r(`unpinConversation`)}:e:{...e,hidden:!0};case`host:search-quote`:return t.kind===`session`&&n.conversationRef?e:{...e,hidden:!0};case`host:search-quick-ask`:return n.quickAskReferenceMenus&&t.kind!==`plugin`?e:{...e,hidden:!0};case`host:search-copy-rel`:return a?e:{...e,hidden:!0};case`host:search-copy-path`:return t.kind===`plugin`?{...e,hidden:!0}:e;case`host:search-copy-id`:return t.kind===`session`&&t.sessionId?e:{...e,hidden:!0};default:return e}})}function ve(e,t){return e.toLowerCase().includes(t)}function g({open:e,projects:o,fileSearch:s,sessionSearch:g,uiContextSearch:ye=[],quickAskReferenceMenus:be=!0,onClose:_,onSwitchSession:xe,onSwitchProject:Se,onPreviewFile:Ce,onOpenFolder:v}){let y=te(),{locale:we}=a(),b=ae(),Te=y(`pluginMenuTitle`),x=ie(`cwd`),S=ie(`tabs`),C=!S||S.includes(`search`),Ee=n(we)?`该页面未在此实例启用(PI_WEB_TABS)`:`This tab is not enabled on this instance (PI_WEB_TABS)`,w=(0,p.useRef)(null),[T,De]=(0,p.useState)(``),E=(0,p.useDeferredValue)(T),[D,O]=(0,p.useState)(0),k=(0,p.useRef)(0),A=(0,p.useRef)(null),j=(0,p.useRef)(null),M=(0,p.useRef)(null),N=(0,p.useRef)(null),[P,F]=(0,p.useState)(``),[Oe,I]=(0,p.useState)(!1),L=(0,p.useCallback)(()=>{N.current&&clearTimeout(N.current),N.current=null},[]),R=(0,p.useCallback)(()=>{L(),I(!1)},[L]),z=(0,p.useCallback)(()=>{L(),I(!0),N.current=setTimeout(()=>{N.current=null,I(!1)},pe)},[L]),ke=(0,p.useCallback)(()=>{F(y(`copied`)),M.current&&clearTimeout(M.current),M.current=setTimeout(()=>F(``),1600)},[y]);(0,p.useEffect)(()=>()=>{M.current&&clearTimeout(M.current),L()},[L]),(0,p.useEffect)(()=>{e||d()?.slot===`contextmenu.search`&&ue()},[e]);let[B,Ae]=(0,p.useState)(null);(0,p.useEffect)(()=>{if(!e)return;c({type:`list_sessions`}),c({type:`list_projects`});let t=T.trim();if(t&&C){let e=f();k.current=e,z(),c({type:`search_files`,reqId:e,query:t}),c({type:`search_sessions`,reqId:e,query:t})}requestAnimationFrame(()=>w.current?.select())},[e]),(0,p.useEffect)(()=>{A.current&&clearTimeout(A.current);let e=E.trim();if(!e){R(),Ae(null);return}return A.current=setTimeout(()=>{if(!C){R();return}let t=f();k.current=t,z(),c({type:`search_files`,reqId:t,query:e}),c({type:`search_sessions`,reqId:t,query:e})},300),()=>{A.current&&clearTimeout(A.current)}},[E,C]),(0,p.useEffect)(()=>{s&&s.reqId===k.current&&Ae(s)},[s]);let V=E.trim().toLowerCase(),H=(0,p.useMemo)(()=>!V||!g||g.reqId!==k.current||!g.ok?[]:g.results,[g,V]),U=(0,p.useMemo)(()=>V?o.filter(e=>ve(e.path,V)).slice(0,10):[],[o,V]),W=(0,p.useMemo)(()=>!V||!B||!B.ok?[]:B.results,[B,V]);(0,p.useEffect)(()=>{B&&B.reqId===k.current&&g&&g.reqId===k.current&&k.current!==0&&R()},[B,g,R]);let G=!!B&&B.ok&&B.truncated,[K,q]=(0,p.useState)([]);(0,p.useEffect)(()=>{if(!e)return;let t=E.trim();if(!t){q([]);return}let n=!1,r=[];try{let e=window,t=e.__piWebUiHost?.searchProviders?.list;if(typeof t==`function`){let n=t.call(e.__piWebUiHost);Array.isArray(n)&&(r=n)}else typeof u==`function`&&(r=u())}catch{r=[]}let i=r.filter(e=>e&&typeof e.id==`string`).map(e=>{if(typeof e.search==`function`)return e;try{let t=se(e.id);return t&&typeof t.search==`function`?{...e,search:t.search}:null}catch{return null}}).filter(e=>!!e);if(i.length===0){q([]);return}return Promise.allSettled(i.map(e=>Promise.race([e.search(t),new Promise((e,t)=>setTimeout(()=>t(Error(`timeout`)),3e3))]).then(t=>({provider:e,items:Array.isArray(t)?t:[]}),()=>({provider:e,items:[]})))).then(e=>{if(n)return;let t=[];for(let n of e)if(n.status===`fulfilled`)for(let e of n.value.items){if(!e||typeof e!=`object`)continue;let r=e;typeof r.title==`string`&&typeof r.action==`string`&&t.push({providerId:n.value.provider.id,providerLabel:n.value.provider.label,title:r.title,...typeof r.hint==`string`?{hint:r.hint}:{},action:r.action})}q(t.slice(0,20))}),()=>{n=!0}},[e,E]);let J=(0,p.useMemo)(()=>[...H.map(e=>({kind:`session`,path:e.path,anchors:e.anchors})),...U.map(e=>({kind:`project`,path:e.path})),...W.filter(e=>e.type===`file`).map(e=>({kind:`file`,path:e.path,name:e.name})),...W.filter(e=>e.type===`dir`).map(e=>({kind:`folder`,path:e.path})),...K.map(e=>({kind:`plugin`,providerId:e.providerId,providerLabel:e.providerLabel,title:e.title,action:e.action}))],[H,U,W,K]);(0,p.useEffect)(()=>{O(0)},[E]);let Y=(0,p.useCallback)(e=>{if(e){if(e.kind===`session`)xe(e.path,e.anchors),_();else if(e.kind===`project`){Se(e.path),c({type:`list_sessions`}),c({type:`list_projects`});let t=E.trim();if(t&&C){let e=f();k.current=e,z(),c({type:`search_files`,reqId:e,query:t}),c({type:`search_sessions`,reqId:e,query:t})}}else e.kind===`folder`?(v?.(e.path),_()):e.kind===`plugin`?oe(e.providerId,e.action,e.action).catch(()=>{}):Ce(e.path,e.name)}},[xe,Se,Ce,v,E,C,z]),je=(0,p.useCallback)(e=>{switch(e.kind){case`session`:return{kind:`session`,path:e.path,anchors:e.anchors};case`project`:return{kind:`project`,path:e.path};case`folder`:return{kind:`folder`,path:e.path};case`file`:return{kind:`file`,path:e.path,name:e.name};default:return{kind:`plugin`,providerId:e.providerId,providerLabel:e.providerLabel,title:e.title,action:e.action}}},[]),Me=(0,p.useCallback)(e=>{if(e.kind===`session`)return{kind:`conversation`,sessionFile:e.path};if(e.kind!==`plugin`)return e.kind===`project`?{kind:`directory`,path:e.path}:{kind:e.kind===`folder`?`directory`:`file`,path:me(x,e.path)}},[x]),Ne=(0,p.useCallback)(e=>_e(ye,e,{t:y,conversationRef:b.conversationRef,quickAskReferenceMenus:be}),[ye,b.conversationRef,be,y]),X=(0,p.useCallback)(e=>{let t=j.current;if(!t)return;let n=e=>{de(e).then(e=>{e&&ke()})};switch(e){case`host:search-open`:Y(je(t));return;case`host:search-open-folder`:if(t.kind!==`project`)return;v?.(t.path),_();return;case`host:search-reveal`:if(t.kind===`plugin`)return;c({type:`file_reveal`,path:t.path});return;case`host:search-pin`:if(t.kind!==`session`)return;c({type:`pin_session`,path:t.path,pinned:!t.pinned});return;case`host:search-quote`:if(t.kind!==`session`)return;l({attachments:[{path:``,key:`conv||${t.path}`,name:t.title,mode:`conversation`,sessionPath:t.path}]});return;case`host:search-quick-ask`:{let e=Me(t);e&&fe({reference:e});return}case`host:search-copy-name`:t.kind===`session`||t.kind===`plugin`?n(t.title):t.kind===`project`?n(h(t.path)):n(t.name);return;case`host:search-copy-rel`:(t.kind===`file`||t.kind===`folder`)&&n(t.path);return;case`host:search-copy-path`:t.kind===`session`||t.kind===`project`?n(t.path):(t.kind===`file`||t.kind===`folder`)&&n(me(x,t.path));return;case`host:search-copy-id`:t.kind===`session`&&t.sessionId&&n(t.sessionId);return;default:return}},[Y,x,ke,je,_,v,Me]),Z=(0,p.useCallback)((e,t)=>{e.preventDefault(),e.stopPropagation(),j.current=t;let n=Ne(t);ce(n).length!==0&&le({x:e.clientX,y:e.clientY,slot:`contextmenu.search`,target:{id:he(t),kind:t.kind,label:ge(t)},entries:n,onHostAction:e=>X(e.id)})},[X,Ne]);(0,p.useEffect)(()=>{if(!e)return;let t=e=>{d()||(e.key===`Escape`?(e.preventDefault(),e.stopPropagation(),_()):e.key===`ArrowDown`?(e.preventDefault(),O(e=>Math.max(0,Math.min(e+1,J.length-1)))):e.key===`ArrowUp`?(e.preventDefault(),O(e=>Math.max(e-1,0))):e.key===`Enter`&&(e.preventDefault(),Y(J[D])))};return window.addEventListener(`keydown`,t,!0),()=>window.removeEventListener(`keydown`,t,!0)},[J,D,Y,_,e]);let Pe=H.length+U.length+W.length+K.length,Q=(e,t,n)=>(0,m.jsxs)(`div`,{className:`gs-section-head`,children:[n,(0,m.jsx)(`span`,{children:e}),(0,m.jsx)(`em`,{children:t})]}),$=-1;return e?(0,m.jsx)(`div`,{className:`modal-backdrop gs-backdrop`,onClick:_,children:(0,m.jsxs)(`div`,{className:`gs-modal`,onClick:e=>e.stopPropagation(),children:[(0,m.jsxs)(`div`,{className:`gs-input-row`,children:[(0,m.jsx)(re,{}),(0,m.jsx)(`input`,{ref:w,type:`text`,value:T,placeholder:y(`gsPlaceholder`),onChange:e=>De(e.target.value)}),(0,m.jsx)(`button`,{type:`button`,className:`gs-close`,title:y(`close`),onClick:_,children:(0,m.jsx)(ee,{})})]}),(0,m.jsxs)(`div`,{className:`gs-results`,children:[!V&&(0,m.jsx)(`div`,{className:`gs-empty`,children:y(`gsHint`)}),V&&Pe===0&&!G&&C&&(0,m.jsx)(`div`,{className:`gs-empty`,children:y(Oe?`gsSearching`:`gsNoResults`)}),V&&!C&&(0,m.jsx)(`div`,{className:`gs-empty`,children:Ee}),H.length>0&&(0,m.jsxs)(`div`,{className:`gs-section`,children:[Q(y(`gsSessions`),H.length,(0,m.jsx)(ne,{})),H.map(e=>{$++;let t=$,n=e.displayName||e.name||e.firstMessage?.trim()||(e.path.split(/[\\/]/).pop()||e.path).replace(/\.jsonl$/i,``);return(0,m.jsxs)(`div`,{className:`gs-item-wrap`,onContextMenu:r=>{O(t),Z(r,{kind:`session`,path:e.path,title:n,anchors:e.anchors,pinned:!!e.pinned,...e.sessionId?{sessionId:e.sessionId}:{}})},children:[(0,m.jsxs)(`button`,{type:`button`,className:t===D?`gs-item active`:`gs-item`,onMouseEnter:()=>O(t),onClick:()=>Y({kind:`session`,path:e.path,anchors:e.anchors}),children:[(0,m.jsxs)(`span`,{className:`gs-item-title`,children:[n,(0,m.jsx)(`em`,{className:`gs-item-meta`,children:e.messageCount})]}),(0,m.jsx)(`span`,{className:`gs-item-sub`,children:e.firstMessage})]}),b.conversationRef&&(0,m.jsxs)(`button`,{type:`button`,className:`gs-quote`,title:y(`quoteConversation`),onClick:t=>{t.stopPropagation(),l({attachments:[{path:``,key:`conv||${e.path}`,name:n,mode:`conversation`,sessionPath:e.path}]})},children:[`💬 `,y(`quoteConversationShort`)]})]},e.path)})]}),U.length>0&&(0,m.jsxs)(`div`,{className:`gs-section`,children:[Q(y(`gsProjects`),U.length,(0,m.jsx)(i,{})),U.map(e=>{$++;let t=$,n=x&&e.path===x;return(0,m.jsxs)(`button`,{type:`button`,className:t===D?`gs-item active`:`gs-item`,onMouseEnter:()=>O(t),onContextMenu:n=>{O(t),Z(n,{kind:`project`,path:e.path})},onClick:()=>Y({kind:`project`,path:e.path}),children:[(0,m.jsxs)(`span`,{className:`gs-item-title`,children:[e.path.split(/[\\/]/).pop(),n&&(0,m.jsx)(`em`,{className:`gs-item-meta`,children:y(`gsCurrentProject`)})]}),(0,m.jsx)(`span`,{className:`gs-item-sub`,children:e.path})]},e.path)})]}),(W.length>0||V&&G)&&(0,m.jsxs)(`div`,{className:`gs-section`,children:[Q(y(`gsFiles`),W.length,(0,m.jsx)(r,{})),W.map(e=>{$++;let t=$;return(0,m.jsxs)(`button`,{type:`button`,className:t===D?`gs-item active`:`gs-item`,title:y(`gsOpenPreview`),onMouseEnter:()=>O(t),onContextMenu:n=>{O(t),Z(n,{kind:e.type===`dir`?`folder`:`file`,path:e.path,name:e.name})},onClick:()=>{e.type===`file`?Y({kind:`file`,path:e.path,name:e.name}):Y({kind:`folder`,path:e.path})},children:[(0,m.jsx)(`span`,{className:`gs-item-title`,children:e.name}),(0,m.jsx)(`span`,{className:`gs-item-sub`,children:e.path})]},`${e.type}:${e.path}`)}),G&&(0,m.jsx)(`div`,{className:`gs-truncated`,children:y(`gsTruncated`)})]}),K.length>0&&(0,m.jsxs)(`div`,{className:`gs-section`,children:[Q(Te,K.length,(0,m.jsx)(t,{})),K.map((e,t)=>{$++;let n=$;return(0,m.jsxs)(`button`,{type:`button`,className:n===D?`gs-item active`:`gs-item`,title:e.providerLabel,onMouseEnter:()=>O(n),onContextMenu:t=>{O(n),Z(t,{kind:`plugin`,providerId:e.providerId,providerLabel:e.providerLabel,title:e.title,action:e.action})},onClick:()=>Y({kind:`plugin`,providerId:e.providerId,providerLabel:e.providerLabel,title:e.title,action:e.action}),children:[(0,m.jsx)(`span`,{className:`gs-item-title`,children:e.title}),(0,m.jsx)(`span`,{className:`gs-item-sub`,children:e.hint??e.providerLabel})]},`${e.providerId}:${e.action}:${t}`)})]})]}),(0,m.jsxs)(`div`,{className:`gs-foot`,children:[(0,m.jsxs)(`span`,{children:[`↑↓ `,y(`gsNavigate`)]}),(0,m.jsxs)(`span`,{children:[`Enter `,y(`gsOpen`)]}),(0,m.jsxs)(`span`,{children:[`Esc `,y(`gsCloseHint`)]}),P&&(0,m.jsx)(`span`,{className:`gs-flash`,children:P})]})]})}):null}export{g as GlobalSearchModal};
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{At as t,Tn as n,X as r,Z as i,gn as a,sn as ee,vn as te,xt as ne,zt as re}from"./fi-CcqqfamG.js";import{i as o,t as s}from"./react-CR5VJ85Q.js";import{i as ie,o as ae,t as c}from"./app-globals-wu8LLlnA.js";import{t as l}from"./composer-bridge-CImnjDHq.js";import{f as oe,s as se,u}from"./plugin-host-DjGRLyyK.js";import{a as ce,c as d,d as le,r as ue}from"./context-menu-state-CEfR7_Lz.js";import{Ft as de,G as fe,w as f}from"./index-Dbv9RJwm.js";var p=e(o(),1),m=s(),pe=8e3;function h(e){return e.split(/[\\/]/).filter(Boolean).pop()??e}function me(e,t){return!e||!t||t.startsWith(`/`)||/^[A-Za-z]:[\\/]/.test(t)?t:`${e.replace(/[\\/]+$/,``)}/${t}`}function he(e){return e.kind===`plugin`?`${e.providerId}:${e.action}`:e.path}function ge(e){switch(e.kind){case`session`:return e.title;case`plugin`:return e.title;case`file`:case`folder`:return e.name;default:return h(e.path)}}function _e(e,t,n){let{t:r}=n,i=t.kind===`file`?r(`fileOpenPreview`):t.kind===`folder`?r(`fileEnterDir`):t.kind===`project`?r(`searchMenuSwitchProject`):r(`gsOpen`),a=t.kind===`file`||t.kind===`folder`;return e.map(e=>{if(e.source!==`host`)return e;switch(e.id){case`host:search-open`:return{...e,label:i};case`host:search-open-folder`:return t.kind===`project`?e:{...e,hidden:!0};case`host:search-reveal`:return t.kind===`plugin`?{...e,hidden:!0}:e;case`host:search-pin`:return t.kind===`session`?t.pinned?{...e,label:r(`unpinConversation`)}:e:{...e,hidden:!0};case`host:search-quote`:return t.kind===`session`&&n.conversationRef?e:{...e,hidden:!0};case`host:search-quick-ask`:return n.quickAskReferenceMenus&&t.kind!==`plugin`?e:{...e,hidden:!0};case`host:search-copy-rel`:return a?e:{...e,hidden:!0};case`host:search-copy-path`:return t.kind===`plugin`?{...e,hidden:!0}:e;case`host:search-copy-id`:return t.kind===`session`&&t.sessionId?e:{...e,hidden:!0};default:return e}})}function ve(e,t){return e.toLowerCase().includes(t)}function g({open:e,projects:o,fileSearch:s,sessionSearch:g,uiContextSearch:ye=[],quickAskReferenceMenus:be=!0,onClose:_,onSwitchSession:xe,onSwitchProject:Se,onPreviewFile:Ce,onOpenFolder:v}){let y=te(),{locale:we}=a(),b=ae(),Te=y(`pluginMenuTitle`),x=ie(`cwd`),S=ie(`tabs`),C=!S||S.includes(`search`),Ee=n(we)?`该页面未在此实例启用(PI_WEB_TABS)`:`This tab is not enabled on this instance (PI_WEB_TABS)`,w=(0,p.useRef)(null),[T,De]=(0,p.useState)(``),E=(0,p.useDeferredValue)(T),[D,O]=(0,p.useState)(0),k=(0,p.useRef)(0),A=(0,p.useRef)(null),j=(0,p.useRef)(null),M=(0,p.useRef)(null),N=(0,p.useRef)(null),[P,F]=(0,p.useState)(``),[Oe,I]=(0,p.useState)(!1),L=(0,p.useCallback)(()=>{N.current&&clearTimeout(N.current),N.current=null},[]),R=(0,p.useCallback)(()=>{L(),I(!1)},[L]),z=(0,p.useCallback)(()=>{L(),I(!0),N.current=setTimeout(()=>{N.current=null,I(!1)},pe)},[L]),ke=(0,p.useCallback)(()=>{F(y(`copied`)),M.current&&clearTimeout(M.current),M.current=setTimeout(()=>F(``),1600)},[y]);(0,p.useEffect)(()=>()=>{M.current&&clearTimeout(M.current),L()},[L]),(0,p.useEffect)(()=>{e||d()?.slot===`contextmenu.search`&&ue()},[e]);let[B,Ae]=(0,p.useState)(null);(0,p.useEffect)(()=>{if(!e)return;c({type:`list_sessions`}),c({type:`list_projects`});let t=T.trim();if(t&&C){let e=f();k.current=e,z(),c({type:`search_files`,reqId:e,query:t}),c({type:`search_sessions`,reqId:e,query:t})}requestAnimationFrame(()=>w.current?.select())},[e]),(0,p.useEffect)(()=>{A.current&&clearTimeout(A.current);let e=E.trim();if(!e){R(),Ae(null);return}return A.current=setTimeout(()=>{if(!C){R();return}let t=f();k.current=t,z(),c({type:`search_files`,reqId:t,query:e}),c({type:`search_sessions`,reqId:t,query:e})},300),()=>{A.current&&clearTimeout(A.current)}},[E,C]),(0,p.useEffect)(()=>{s&&s.reqId===k.current&&Ae(s)},[s]);let V=E.trim().toLowerCase(),H=(0,p.useMemo)(()=>!V||!g||g.reqId!==k.current||!g.ok?[]:g.results,[g,V]),U=(0,p.useMemo)(()=>V?o.filter(e=>ve(e.path,V)).slice(0,10):[],[o,V]),W=(0,p.useMemo)(()=>!V||!B||!B.ok?[]:B.results,[B,V]);(0,p.useEffect)(()=>{B&&B.reqId===k.current&&g&&g.reqId===k.current&&k.current!==0&&R()},[B,g,R]);let G=!!B&&B.ok&&B.truncated,[K,q]=(0,p.useState)([]);(0,p.useEffect)(()=>{if(!e)return;let t=E.trim();if(!t){q([]);return}let n=!1,r=[];try{let e=window,t=e.__piWebUiHost?.searchProviders?.list;if(typeof t==`function`){let n=t.call(e.__piWebUiHost);Array.isArray(n)&&(r=n)}else typeof u==`function`&&(r=u())}catch{r=[]}let i=r.filter(e=>e&&typeof e.id==`string`).map(e=>{if(typeof e.search==`function`)return e;try{let t=se(e.id);return t&&typeof t.search==`function`?{...e,search:t.search}:null}catch{return null}}).filter(e=>!!e);if(i.length===0){q([]);return}return Promise.allSettled(i.map(e=>Promise.race([e.search(t),new Promise((e,t)=>setTimeout(()=>t(Error(`timeout`)),3e3))]).then(t=>({provider:e,items:Array.isArray(t)?t:[]}),()=>({provider:e,items:[]})))).then(e=>{if(n)return;let t=[];for(let n of e)if(n.status===`fulfilled`)for(let e of n.value.items){if(!e||typeof e!=`object`)continue;let r=e;typeof r.title==`string`&&typeof r.action==`string`&&t.push({providerId:n.value.provider.id,providerLabel:n.value.provider.label,title:r.title,...typeof r.hint==`string`?{hint:r.hint}:{},action:r.action})}q(t.slice(0,20))}),()=>{n=!0}},[e,E]);let J=(0,p.useMemo)(()=>[...H.map(e=>({kind:`session`,path:e.path,anchors:e.anchors})),...U.map(e=>({kind:`project`,path:e.path})),...W.filter(e=>e.type===`file`).map(e=>({kind:`file`,path:e.path,name:e.name})),...W.filter(e=>e.type===`dir`).map(e=>({kind:`folder`,path:e.path})),...K.map(e=>({kind:`plugin`,providerId:e.providerId,providerLabel:e.providerLabel,title:e.title,action:e.action}))],[H,U,W,K]);(0,p.useEffect)(()=>{O(0)},[E]);let Y=(0,p.useCallback)(e=>{if(e){if(e.kind===`session`)xe(e.path,e.anchors),_();else if(e.kind===`project`){Se(e.path),c({type:`list_sessions`}),c({type:`list_projects`});let t=E.trim();if(t&&C){let e=f();k.current=e,z(),c({type:`search_files`,reqId:e,query:t}),c({type:`search_sessions`,reqId:e,query:t})}}else e.kind===`folder`?(v?.(e.path),_()):e.kind===`plugin`?oe(e.providerId,e.action,e.action).catch(()=>{}):Ce(e.path,e.name)}},[xe,Se,Ce,v,E,C,z]),je=(0,p.useCallback)(e=>{switch(e.kind){case`session`:return{kind:`session`,path:e.path,anchors:e.anchors};case`project`:return{kind:`project`,path:e.path};case`folder`:return{kind:`folder`,path:e.path};case`file`:return{kind:`file`,path:e.path,name:e.name};default:return{kind:`plugin`,providerId:e.providerId,providerLabel:e.providerLabel,title:e.title,action:e.action}}},[]),Me=(0,p.useCallback)(e=>{if(e.kind===`session`)return{kind:`conversation`,sessionFile:e.path};if(e.kind!==`plugin`)return e.kind===`project`?{kind:`directory`,path:e.path}:{kind:e.kind===`folder`?`directory`:`file`,path:me(x,e.path)}},[x]),Ne=(0,p.useCallback)(e=>_e(ye,e,{t:y,conversationRef:b.conversationRef,quickAskReferenceMenus:be}),[ye,b.conversationRef,be,y]),X=(0,p.useCallback)(e=>{let t=j.current;if(!t)return;let n=e=>{de(e).then(e=>{e&&ke()})};switch(e){case`host:search-open`:Y(je(t));return;case`host:search-open-folder`:if(t.kind!==`project`)return;v?.(t.path),_();return;case`host:search-reveal`:if(t.kind===`plugin`)return;c({type:`file_reveal`,path:t.path});return;case`host:search-pin`:if(t.kind!==`session`)return;c({type:`pin_session`,path:t.path,pinned:!t.pinned});return;case`host:search-quote`:if(t.kind!==`session`)return;l({attachments:[{path:``,key:`conv||${t.path}`,name:t.title,mode:`conversation`,sessionPath:t.path}]});return;case`host:search-quick-ask`:{let e=Me(t);e&&fe({reference:e});return}case`host:search-copy-name`:t.kind===`session`||t.kind===`plugin`?n(t.title):t.kind===`project`?n(h(t.path)):n(t.name);return;case`host:search-copy-rel`:(t.kind===`file`||t.kind===`folder`)&&n(t.path);return;case`host:search-copy-path`:t.kind===`session`||t.kind===`project`?n(t.path):(t.kind===`file`||t.kind===`folder`)&&n(me(x,t.path));return;case`host:search-copy-id`:t.kind===`session`&&t.sessionId&&n(t.sessionId);return;default:return}},[Y,x,ke,je,_,v,Me]),Z=(0,p.useCallback)((e,t)=>{e.preventDefault(),e.stopPropagation(),j.current=t;let n=Ne(t);ce(n).length!==0&&le({x:e.clientX,y:e.clientY,slot:`contextmenu.search`,target:{id:he(t),kind:t.kind,label:ge(t)},entries:n,onHostAction:e=>X(e.id)})},[X,Ne]);(0,p.useEffect)(()=>{if(!e)return;let t=e=>{d()||(e.key===`Escape`?(e.preventDefault(),e.stopPropagation(),_()):e.key===`ArrowDown`?(e.preventDefault(),O(e=>Math.max(0,Math.min(e+1,J.length-1)))):e.key===`ArrowUp`?(e.preventDefault(),O(e=>Math.max(e-1,0))):e.key===`Enter`&&(e.preventDefault(),Y(J[D])))};return window.addEventListener(`keydown`,t,!0),()=>window.removeEventListener(`keydown`,t,!0)},[J,D,Y,_,e]);let Pe=H.length+U.length+W.length+K.length,Q=(e,t,n)=>(0,m.jsxs)(`div`,{className:`gs-section-head`,children:[n,(0,m.jsx)(`span`,{children:e}),(0,m.jsx)(`em`,{children:t})]}),$=-1;return e?(0,m.jsx)(`div`,{className:`modal-backdrop gs-backdrop`,onClick:_,children:(0,m.jsxs)(`div`,{className:`gs-modal`,onClick:e=>e.stopPropagation(),children:[(0,m.jsxs)(`div`,{className:`gs-input-row`,children:[(0,m.jsx)(re,{}),(0,m.jsx)(`input`,{ref:w,type:`text`,value:T,placeholder:y(`gsPlaceholder`),onChange:e=>De(e.target.value)}),(0,m.jsx)(`button`,{type:`button`,className:`gs-close`,title:y(`close`),onClick:_,children:(0,m.jsx)(ee,{})})]}),(0,m.jsxs)(`div`,{className:`gs-results`,children:[!V&&(0,m.jsx)(`div`,{className:`gs-empty`,children:y(`gsHint`)}),V&&Pe===0&&!G&&C&&(0,m.jsx)(`div`,{className:`gs-empty`,children:y(Oe?`gsSearching`:`gsNoResults`)}),V&&!C&&(0,m.jsx)(`div`,{className:`gs-empty`,children:Ee}),H.length>0&&(0,m.jsxs)(`div`,{className:`gs-section`,children:[Q(y(`gsSessions`),H.length,(0,m.jsx)(ne,{})),H.map(e=>{$++;let t=$,n=e.displayName||e.name||e.firstMessage?.trim()||(e.path.split(/[\\/]/).pop()||e.path).replace(/\.jsonl$/i,``);return(0,m.jsxs)(`div`,{className:`gs-item-wrap`,onContextMenu:r=>{O(t),Z(r,{kind:`session`,path:e.path,title:n,anchors:e.anchors,pinned:!!e.pinned,...e.sessionId?{sessionId:e.sessionId}:{}})},children:[(0,m.jsxs)(`button`,{type:`button`,className:t===D?`gs-item active`:`gs-item`,onMouseEnter:()=>O(t),onClick:()=>Y({kind:`session`,path:e.path,anchors:e.anchors}),children:[(0,m.jsxs)(`span`,{className:`gs-item-title`,children:[n,(0,m.jsx)(`em`,{className:`gs-item-meta`,children:e.messageCount})]}),(0,m.jsx)(`span`,{className:`gs-item-sub`,children:e.firstMessage})]}),b.conversationRef&&(0,m.jsxs)(`button`,{type:`button`,className:`gs-quote`,title:y(`quoteConversation`),onClick:t=>{t.stopPropagation(),l({attachments:[{path:``,key:`conv||${e.path}`,name:n,mode:`conversation`,sessionPath:e.path}]})},children:[`💬 `,y(`quoteConversationShort`)]})]},e.path)})]}),U.length>0&&(0,m.jsxs)(`div`,{className:`gs-section`,children:[Q(y(`gsProjects`),U.length,(0,m.jsx)(i,{})),U.map(e=>{$++;let t=$,n=x&&e.path===x;return(0,m.jsxs)(`button`,{type:`button`,className:t===D?`gs-item active`:`gs-item`,onMouseEnter:()=>O(t),onContextMenu:n=>{O(t),Z(n,{kind:`project`,path:e.path})},onClick:()=>Y({kind:`project`,path:e.path}),children:[(0,m.jsxs)(`span`,{className:`gs-item-title`,children:[e.path.split(/[\\/]/).pop(),n&&(0,m.jsx)(`em`,{className:`gs-item-meta`,children:y(`gsCurrentProject`)})]}),(0,m.jsx)(`span`,{className:`gs-item-sub`,children:e.path})]},e.path)})]}),(W.length>0||V&&G)&&(0,m.jsxs)(`div`,{className:`gs-section`,children:[Q(y(`gsFiles`),W.length,(0,m.jsx)(r,{})),W.map(e=>{$++;let t=$;return(0,m.jsxs)(`button`,{type:`button`,className:t===D?`gs-item active`:`gs-item`,title:y(`gsOpenPreview`),onMouseEnter:()=>O(t),onContextMenu:n=>{O(t),Z(n,{kind:e.type===`dir`?`folder`:`file`,path:e.path,name:e.name})},onClick:()=>{e.type===`file`?Y({kind:`file`,path:e.path,name:e.name}):Y({kind:`folder`,path:e.path})},children:[(0,m.jsx)(`span`,{className:`gs-item-title`,children:e.name}),(0,m.jsx)(`span`,{className:`gs-item-sub`,children:e.path})]},`${e.type}:${e.path}`)}),G&&(0,m.jsx)(`div`,{className:`gs-truncated`,children:y(`gsTruncated`)})]}),K.length>0&&(0,m.jsxs)(`div`,{className:`gs-section`,children:[Q(Te,K.length,(0,m.jsx)(t,{})),K.map((e,t)=>{$++;let n=$;return(0,m.jsxs)(`button`,{type:`button`,className:n===D?`gs-item active`:`gs-item`,title:e.providerLabel,onMouseEnter:()=>O(n),onContextMenu:t=>{O(n),Z(t,{kind:`plugin`,providerId:e.providerId,providerLabel:e.providerLabel,title:e.title,action:e.action})},onClick:()=>Y({kind:`plugin`,providerId:e.providerId,providerLabel:e.providerLabel,title:e.title,action:e.action}),children:[(0,m.jsx)(`span`,{className:`gs-item-title`,children:e.title}),(0,m.jsx)(`span`,{className:`gs-item-sub`,children:e.hint??e.providerLabel})]},`${e.providerId}:${e.action}:${t}`)})]})]}),(0,m.jsxs)(`div`,{className:`gs-foot`,children:[(0,m.jsxs)(`span`,{children:[`↑↓ `,y(`gsNavigate`)]}),(0,m.jsxs)(`span`,{children:[`Enter `,y(`gsOpen`)]}),(0,m.jsxs)(`span`,{children:[`Esc `,y(`gsCloseHint`)]}),P&&(0,m.jsx)(`span`,{className:`gs-flash`,children:P})]})]})}):null}export{g as GlobalSearchModal};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{At as t,Tn as n,X as r,Z as i,gn as a,sn as ee,vn as te,xt as ne,zt as re}from"./fi-CcqqfamG.js";import{i as o,t as s}from"./react-CR5VJ85Q.js";import{i as ie,o as ae,t as c}from"./app-globals-wu8LLlnA.js";import{t as l}from"./composer-bridge-CImnjDHq.js";import{f as oe,s as se,u}from"./plugin-host-DjGRLyyK.js";import{a as ce,c as d,d as le,r as ue}from"./context-menu-state-CEfR7_Lz.js";import{t as de}from"./use-copy-feedback-B3di-fnu.js";import{G as fe,w as f}from"./index-BQb8EOhk.js";var p=e(o(),1),m=s(),pe=8e3;function h(e){return e.split(/[\\/]/).filter(Boolean).pop()??e}function me(e,t){return!e||!t||t.startsWith(`/`)||/^[A-Za-z]:[\\/]/.test(t)?t:`${e.replace(/[\\/]+$/,``)}/${t}`}function he(e){return e.kind===`plugin`?`${e.providerId}:${e.action}`:e.path}function ge(e){switch(e.kind){case`session`:return e.title;case`plugin`:return e.title;case`file`:case`folder`:return e.name;default:return h(e.path)}}function _e(e,t,n){let{t:r}=n,i=t.kind===`file`?r(`fileOpenPreview`):t.kind===`folder`?r(`fileEnterDir`):t.kind===`project`?r(`searchMenuSwitchProject`):r(`gsOpen`),a=t.kind===`file`||t.kind===`folder`;return e.map(e=>{if(e.source!==`host`)return e;switch(e.id){case`host:search-open`:return{...e,label:i};case`host:search-open-folder`:return t.kind===`project`?e:{...e,hidden:!0};case`host:search-reveal`:return t.kind===`plugin`?{...e,hidden:!0}:e;case`host:search-pin`:return t.kind===`session`?t.pinned?{...e,label:r(`unpinConversation`)}:e:{...e,hidden:!0};case`host:search-quote`:return t.kind===`session`&&n.conversationRef?e:{...e,hidden:!0};case`host:search-quick-ask`:return n.quickAskReferenceMenus&&t.kind!==`plugin`?e:{...e,hidden:!0};case`host:search-copy-rel`:return a?e:{...e,hidden:!0};case`host:search-copy-path`:return t.kind===`plugin`?{...e,hidden:!0}:e;case`host:search-copy-id`:return t.kind===`session`&&t.sessionId?e:{...e,hidden:!0};default:return e}})}function ve(e,t){return e.toLowerCase().includes(t)}function g({open:e,projects:o,fileSearch:s,sessionSearch:g,uiContextSearch:ye=[],quickAskReferenceMenus:be=!0,onClose:_,onSwitchSession:xe,onSwitchProject:Se,onPreviewFile:Ce,onOpenFolder:v}){let y=te(),{locale:we}=a(),b=ae(),Te=y(`pluginMenuTitle`),x=ie(`cwd`),S=ie(`tabs`),C=!S||S.includes(`search`),Ee=n(we)?`该页面未在此实例启用(PI_WEB_TABS)`:`This tab is not enabled on this instance (PI_WEB_TABS)`,w=(0,p.useRef)(null),[T,De]=(0,p.useState)(``),E=(0,p.useDeferredValue)(T),[D,O]=(0,p.useState)(0),k=(0,p.useRef)(0),A=(0,p.useRef)(null),j=(0,p.useRef)(null),M=(0,p.useRef)(null),N=(0,p.useRef)(null),[P,F]=(0,p.useState)(``),[Oe,I]=(0,p.useState)(!1),L=(0,p.useCallback)(()=>{N.current&&clearTimeout(N.current),N.current=null},[]),R=(0,p.useCallback)(()=>{L(),I(!1)},[L]),z=(0,p.useCallback)(()=>{L(),I(!0),N.current=setTimeout(()=>{N.current=null,I(!1)},pe)},[L]),ke=(0,p.useCallback)(()=>{F(y(`copied`)),M.current&&clearTimeout(M.current),M.current=setTimeout(()=>F(``),1600)},[y]);(0,p.useEffect)(()=>()=>{M.current&&clearTimeout(M.current),L()},[L]),(0,p.useEffect)(()=>{e||d()?.slot===`contextmenu.search`&&ue()},[e]);let[B,Ae]=(0,p.useState)(null);(0,p.useEffect)(()=>{if(!e)return;c({type:`list_sessions`}),c({type:`list_projects`});let t=T.trim();if(t&&C){let e=f();k.current=e,z(),c({type:`search_files`,reqId:e,query:t}),c({type:`search_sessions`,reqId:e,query:t})}requestAnimationFrame(()=>w.current?.select())},[e]),(0,p.useEffect)(()=>{A.current&&clearTimeout(A.current);let e=E.trim();if(!e){R(),Ae(null);return}return A.current=setTimeout(()=>{if(!C){R();return}let t=f();k.current=t,z(),c({type:`search_files`,reqId:t,query:e}),c({type:`search_sessions`,reqId:t,query:e})},300),()=>{A.current&&clearTimeout(A.current)}},[E,C]),(0,p.useEffect)(()=>{s&&s.reqId===k.current&&Ae(s)},[s]);let V=E.trim().toLowerCase(),H=(0,p.useMemo)(()=>!V||!g||g.reqId!==k.current||!g.ok?[]:g.results,[g,V]),U=(0,p.useMemo)(()=>V?o.filter(e=>ve(e.path,V)).slice(0,10):[],[o,V]),W=(0,p.useMemo)(()=>!V||!B||!B.ok?[]:B.results,[B,V]);(0,p.useEffect)(()=>{B&&B.reqId===k.current&&g&&g.reqId===k.current&&k.current!==0&&R()},[B,g,R]);let G=!!B&&B.ok&&B.truncated,[K,q]=(0,p.useState)([]);(0,p.useEffect)(()=>{if(!e)return;let t=E.trim();if(!t){q([]);return}let n=!1,r=[];try{let e=window,t=e.__piWebUiHost?.searchProviders?.list;if(typeof t==`function`){let n=t.call(e.__piWebUiHost);Array.isArray(n)&&(r=n)}else typeof u==`function`&&(r=u())}catch{r=[]}let i=r.filter(e=>e&&typeof e.id==`string`).map(e=>{if(typeof e.search==`function`)return e;try{let t=se(e.id);return t&&typeof t.search==`function`?{...e,search:t.search}:null}catch{return null}}).filter(e=>!!e);if(i.length===0){q([]);return}return Promise.allSettled(i.map(e=>Promise.race([e.search(t),new Promise((e,t)=>setTimeout(()=>t(Error(`timeout`)),3e3))]).then(t=>({provider:e,items:Array.isArray(t)?t:[]}),()=>({provider:e,items:[]})))).then(e=>{if(n)return;let t=[];for(let n of e)if(n.status===`fulfilled`)for(let e of n.value.items){if(!e||typeof e!=`object`)continue;let r=e;typeof r.title==`string`&&typeof r.action==`string`&&t.push({providerId:n.value.provider.id,providerLabel:n.value.provider.label,title:r.title,...typeof r.hint==`string`?{hint:r.hint}:{},action:r.action})}q(t.slice(0,20))}),()=>{n=!0}},[e,E]);let J=(0,p.useMemo)(()=>[...H.map(e=>({kind:`session`,path:e.path,anchors:e.anchors})),...U.map(e=>({kind:`project`,path:e.path})),...W.filter(e=>e.type===`file`).map(e=>({kind:`file`,path:e.path,name:e.name})),...W.filter(e=>e.type===`dir`).map(e=>({kind:`folder`,path:e.path})),...K.map(e=>({kind:`plugin`,providerId:e.providerId,providerLabel:e.providerLabel,title:e.title,action:e.action}))],[H,U,W,K]);(0,p.useEffect)(()=>{O(0)},[E]);let Y=(0,p.useCallback)(e=>{if(e){if(e.kind===`session`)xe(e.path,e.anchors),_();else if(e.kind===`project`){Se(e.path),c({type:`list_sessions`}),c({type:`list_projects`});let t=E.trim();if(t&&C){let e=f();k.current=e,z(),c({type:`search_files`,reqId:e,query:t}),c({type:`search_sessions`,reqId:e,query:t})}}else e.kind===`folder`?(v?.(e.path),_()):e.kind===`plugin`?oe(e.providerId,e.action,e.action).catch(()=>{}):Ce(e.path,e.name)}},[xe,Se,Ce,v,E,C,z]),je=(0,p.useCallback)(e=>{switch(e.kind){case`session`:return{kind:`session`,path:e.path,anchors:e.anchors};case`project`:return{kind:`project`,path:e.path};case`folder`:return{kind:`folder`,path:e.path};case`file`:return{kind:`file`,path:e.path,name:e.name};default:return{kind:`plugin`,providerId:e.providerId,providerLabel:e.providerLabel,title:e.title,action:e.action}}},[]),Me=(0,p.useCallback)(e=>{if(e.kind===`session`)return{kind:`conversation`,sessionFile:e.path};if(e.kind!==`plugin`)return e.kind===`project`?{kind:`directory`,path:e.path}:{kind:e.kind===`folder`?`directory`:`file`,path:me(x,e.path)}},[x]),Ne=(0,p.useCallback)(e=>_e(ye,e,{t:y,conversationRef:b.conversationRef,quickAskReferenceMenus:be}),[ye,b.conversationRef,be,y]),X=(0,p.useCallback)(e=>{let t=j.current;if(!t)return;let n=e=>{de(e).then(e=>{e&&ke()})};switch(e){case`host:search-open`:Y(je(t));return;case`host:search-open-folder`:if(t.kind!==`project`)return;v?.(t.path),_();return;case`host:search-reveal`:if(t.kind===`plugin`)return;c({type:`file_reveal`,path:t.path});return;case`host:search-pin`:if(t.kind!==`session`)return;c({type:`pin_session`,path:t.path,pinned:!t.pinned});return;case`host:search-quote`:if(t.kind!==`session`)return;l({attachments:[{path:``,key:`conv||${t.path}`,name:t.title,mode:`conversation`,sessionPath:t.path}]});return;case`host:search-quick-ask`:{let e=Me(t);e&&fe({reference:e});return}case`host:search-copy-name`:t.kind===`session`||t.kind===`plugin`?n(t.title):t.kind===`project`?n(h(t.path)):n(t.name);return;case`host:search-copy-rel`:(t.kind===`file`||t.kind===`folder`)&&n(t.path);return;case`host:search-copy-path`:t.kind===`session`||t.kind===`project`?n(t.path):(t.kind===`file`||t.kind===`folder`)&&n(me(x,t.path));return;case`host:search-copy-id`:t.kind===`session`&&t.sessionId&&n(t.sessionId);return;default:return}},[Y,x,ke,je,_,v,Me]),Z=(0,p.useCallback)((e,t)=>{e.preventDefault(),e.stopPropagation(),j.current=t;let n=Ne(t);ce(n).length!==0&&le({x:e.clientX,y:e.clientY,slot:`contextmenu.search`,target:{id:he(t),kind:t.kind,label:ge(t)},entries:n,onHostAction:e=>X(e.id)})},[X,Ne]);(0,p.useEffect)(()=>{if(!e)return;let t=e=>{d()||(e.key===`Escape`?(e.preventDefault(),e.stopPropagation(),_()):e.key===`ArrowDown`?(e.preventDefault(),O(e=>Math.max(0,Math.min(e+1,J.length-1)))):e.key===`ArrowUp`?(e.preventDefault(),O(e=>Math.max(e-1,0))):e.key===`Enter`&&(e.preventDefault(),Y(J[D])))};return window.addEventListener(`keydown`,t,!0),()=>window.removeEventListener(`keydown`,t,!0)},[J,D,Y,_,e]);let Pe=H.length+U.length+W.length+K.length,Q=(e,t,n)=>(0,m.jsxs)(`div`,{className:`gs-section-head`,children:[n,(0,m.jsx)(`span`,{children:e}),(0,m.jsx)(`em`,{children:t})]}),$=-1;return e?(0,m.jsx)(`div`,{className:`modal-backdrop gs-backdrop`,onClick:_,children:(0,m.jsxs)(`div`,{className:`gs-modal`,onClick:e=>e.stopPropagation(),children:[(0,m.jsxs)(`div`,{className:`gs-input-row`,children:[(0,m.jsx)(re,{}),(0,m.jsx)(`input`,{ref:w,type:`text`,value:T,placeholder:y(`gsPlaceholder`),onChange:e=>De(e.target.value)}),(0,m.jsx)(`button`,{type:`button`,className:`gs-close`,title:y(`close`),onClick:_,children:(0,m.jsx)(ee,{})})]}),(0,m.jsxs)(`div`,{className:`gs-results`,children:[!V&&(0,m.jsx)(`div`,{className:`gs-empty`,children:y(`gsHint`)}),V&&Pe===0&&!G&&C&&(0,m.jsx)(`div`,{className:`gs-empty`,children:y(Oe?`gsSearching`:`gsNoResults`)}),V&&!C&&(0,m.jsx)(`div`,{className:`gs-empty`,children:Ee}),H.length>0&&(0,m.jsxs)(`div`,{className:`gs-section`,children:[Q(y(`gsSessions`),H.length,(0,m.jsx)(ne,{})),H.map(e=>{$++;let t=$,n=e.displayName||e.name||e.firstMessage?.trim()||(e.path.split(/[\\/]/).pop()||e.path).replace(/\.jsonl$/i,``);return(0,m.jsxs)(`div`,{className:`gs-item-wrap`,onContextMenu:r=>{O(t),Z(r,{kind:`session`,path:e.path,title:n,anchors:e.anchors,pinned:!!e.pinned,...e.sessionId?{sessionId:e.sessionId}:{}})},children:[(0,m.jsxs)(`button`,{type:`button`,className:t===D?`gs-item active`:`gs-item`,onMouseEnter:()=>O(t),onClick:()=>Y({kind:`session`,path:e.path,anchors:e.anchors}),children:[(0,m.jsxs)(`span`,{className:`gs-item-title`,children:[n,(0,m.jsx)(`em`,{className:`gs-item-meta`,children:e.messageCount})]}),(0,m.jsx)(`span`,{className:`gs-item-sub`,children:e.firstMessage})]}),b.conversationRef&&(0,m.jsxs)(`button`,{type:`button`,className:`gs-quote`,title:y(`quoteConversation`),onClick:t=>{t.stopPropagation(),l({attachments:[{path:``,key:`conv||${e.path}`,name:n,mode:`conversation`,sessionPath:e.path}]})},children:[`💬 `,y(`quoteConversationShort`)]})]},e.path)})]}),U.length>0&&(0,m.jsxs)(`div`,{className:`gs-section`,children:[Q(y(`gsProjects`),U.length,(0,m.jsx)(i,{})),U.map(e=>{$++;let t=$,n=x&&e.path===x;return(0,m.jsxs)(`button`,{type:`button`,className:t===D?`gs-item active`:`gs-item`,onMouseEnter:()=>O(t),onContextMenu:n=>{O(t),Z(n,{kind:`project`,path:e.path})},onClick:()=>Y({kind:`project`,path:e.path}),children:[(0,m.jsxs)(`span`,{className:`gs-item-title`,children:[e.path.split(/[\\/]/).pop(),n&&(0,m.jsx)(`em`,{className:`gs-item-meta`,children:y(`gsCurrentProject`)})]}),(0,m.jsx)(`span`,{className:`gs-item-sub`,children:e.path})]},e.path)})]}),(W.length>0||V&&G)&&(0,m.jsxs)(`div`,{className:`gs-section`,children:[Q(y(`gsFiles`),W.length,(0,m.jsx)(r,{})),W.map(e=>{$++;let t=$;return(0,m.jsxs)(`button`,{type:`button`,className:t===D?`gs-item active`:`gs-item`,title:y(`gsOpenPreview`),onMouseEnter:()=>O(t),onContextMenu:n=>{O(t),Z(n,{kind:e.type===`dir`?`folder`:`file`,path:e.path,name:e.name})},onClick:()=>{e.type===`file`?Y({kind:`file`,path:e.path,name:e.name}):Y({kind:`folder`,path:e.path})},children:[(0,m.jsx)(`span`,{className:`gs-item-title`,children:e.name}),(0,m.jsx)(`span`,{className:`gs-item-sub`,children:e.path})]},`${e.type}:${e.path}`)}),G&&(0,m.jsx)(`div`,{className:`gs-truncated`,children:y(`gsTruncated`)})]}),K.length>0&&(0,m.jsxs)(`div`,{className:`gs-section`,children:[Q(Te,K.length,(0,m.jsx)(t,{})),K.map((e,t)=>{$++;let n=$;return(0,m.jsxs)(`button`,{type:`button`,className:n===D?`gs-item active`:`gs-item`,title:e.providerLabel,onMouseEnter:()=>O(n),onContextMenu:t=>{O(n),Z(t,{kind:`plugin`,providerId:e.providerId,providerLabel:e.providerLabel,title:e.title,action:e.action})},onClick:()=>Y({kind:`plugin`,providerId:e.providerId,providerLabel:e.providerLabel,title:e.title,action:e.action}),children:[(0,m.jsx)(`span`,{className:`gs-item-title`,children:e.title}),(0,m.jsx)(`span`,{className:`gs-item-sub`,children:e.hint??e.providerLabel})]},`${e.providerId}:${e.action}:${t}`)})]})]}),(0,m.jsxs)(`div`,{className:`gs-foot`,children:[(0,m.jsxs)(`span`,{children:[`↑↓ `,y(`gsNavigate`)]}),(0,m.jsxs)(`span`,{children:[`Enter `,y(`gsOpen`)]}),(0,m.jsxs)(`span`,{children:[`Esc `,y(`gsCloseHint`)]}),P&&(0,m.jsx)(`span`,{className:`gs-flash`,children:P})]})]})}):null}export{g as GlobalSearchModal};
|