pi-foreman 0.0.0-stage → 0.1.2

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.
@@ -0,0 +1,35 @@
1
+ import{r as i,j as n,b as ou,a as gn,c as Ka,d as iu}from"./react-vendor-DEAzPTfA.js";import{g as xn,i as xt,a as Ze,b as $s,c as Fo,d as Bt,e as au,f as Zr,h as lu,j as cu,u as qa,k as uu,l as du,m as fu,n as pu,o as mu,p as ws,q as gu,r as xu,s as js,t as hu,v as bu,w as Oi,x as Ii,y as vu,z as yu,A as ku,B as Ya,M as ju,C as Xa,D as wu,E as Ja,F as en,G as Cu,H as Sn,I as Ai,J as _n,K as Su,L as fn,N as Nu,O as Eu}from"./chat-vendor-PY5rkhAV.js";import{X as Ds,C as ls,P as pn,T as vt,L as at,a as Mi,b as Tu,S as Ru,c as zs,I as Es,d as Za,e as is,F as Fs,f as _o,R as ko,g as Lo,h as sn,E as Pu,i as Qa,j as el,k as jo,l as Ou,A as $i,m as Iu,n as Au,W as Mu,o as $u,p as Du,M as zu,q as Fu,r as jr,B as Bo,s as _u,t as Lu,u as tl,v as Ho,w as Uo,x as Bu,y as Hu,z as Uu,D as Wu,K as nl,G as cs,H as sl,J as Gu,N as Vu,O as Ku,Q as qu,U as Wo,V as Yu,Y as rl,Z as Xu,_ as Di,$ as Ju,a0 as wo,a1 as Zu,a2 as Qu,a3 as ed,a4 as td,a5 as nd}from"./icons-BRdrcGH3.js";(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const o of document.querySelectorAll('link[rel="modulepreload"]'))r(o);new MutationObserver(o=>{for(const a of o)if(a.type==="childList")for(const l of a.addedNodes)l.tagName==="LINK"&&l.rel==="modulepreload"&&r(l)}).observe(document,{childList:!0,subtree:!0});function s(o){const a={};return o.integrity&&(a.integrity=o.integrity),o.referrerPolicy&&(a.referrerPolicy=o.referrerPolicy),o.crossOrigin==="use-credentials"?a.credentials="include":o.crossOrigin==="anonymous"?a.credentials="omit":a.credentials="same-origin",a}function r(o){if(o.ep)return;o.ep=!0;const a=s(o);fetch(o.href,a)}})();const ol=i.createContext(Date.now());function sd({children:e}){const[t,s]=i.useState(()=>Date.now());return i.useEffect(()=>{const r=setInterval(()=>s(Date.now()),1e3),o=()=>s(Date.now());return window.addEventListener("focus",o),()=>{clearInterval(r),window.removeEventListener("focus",o)}},[]),n.jsx(ol.Provider,{value:t,children:e})}function il(){return i.useContext(ol)}class ur extends Error{status;constructor(t,s){super(s),this.name="ApiRequestError",this.status=t}}const rd="";async function xe(e,t,s,r){const o=await fetch(`${rd}${t}`,{method:e,headers:s===void 0?void 0:{"Content-Type":"application/json"},body:s===void 0?void 0:JSON.stringify(s),...r?.timeoutMs?{signal:AbortSignal.timeout(r.timeoutMs)}:{}}),a=await o.text();let l;try{l=a?JSON.parse(a):null}catch{throw new ur(o.status,`响应不是合法 JSON (HTTP ${o.status}): ${a.slice(0,200)}`)}if(!o.ok){const c=l?.error??`HTTP ${o.status}`;throw new ur(o.status,c)}return l}const un=e=>{const t=new URLSearchParams;for(const[r,o]of Object.entries(e))o!=null&&o!==""&&t.set(r,String(o));const s=t.toString();return s?`?${s}`:""},ie={bootstrap:()=>xe("GET","/api/bootstrap"),usage:()=>xe("GET","/api/usage"),prompts:()=>xe("GET","/api/prompts"),models:()=>xe("GET","/api/models"),providers:()=>xe("GET","/api/auth/providers"),loginStart:(e,t)=>xe("POST","/api/auth/login/start",{providerId:e,authType:t}),loginReply:(e,t)=>xe("POST",`/api/auth/login/${encodeURIComponent(e)}/reply`,{value:t}),loginCancel:e=>xe("POST",`/api/auth/login/${encodeURIComponent(e)}/cancel`,{}),logout:e=>xe("POST","/api/auth/logout",{providerId:e}),reload:()=>xe("POST","/api/reload",{}),createConversation:(e,t)=>xe("POST","/api/conversations",{env:e,...t}),renameConversation:(e,t)=>xe("PATCH",`/api/conversations/${e}`,{title:t}),archiveConversation:(e,t)=>xe("PATCH",`/api/conversations/${e}`,{archived:t}),deleteConversation:e=>xe("DELETE",`/api/conversations/${e}`),loadEntries:(e,t)=>xe("GET",`/api/conversations/${e}/entries${un(t??{})}`),sendMessage:(e,t)=>xe("POST",`/api/conversations/${e}/messages`,{content:t}),abort:e=>xe("POST",`/api/conversations/${e}/abort`),compact:(e,t)=>xe("POST",`/api/conversations/${e}/compact`,t===void 0?{}:{instructions:t}),reset:(e,t)=>xe("POST",`/api/conversations/${e}/reset`,t===void 0?{}:{handoff:t}),fork:(e,t)=>xe("POST",`/api/conversations/${e}/fork`,t===void 0?{}:{atEntryId:t}),configure:(e,t)=>xe("POST",`/api/conversations/${e}/configure`,t),execInConversation:(e,t,s)=>xe("POST",`/api/conversations/${e}/exec`,{command:t,...s}),listContainers:e=>xe("GET",`/api/hosts/${encodeURIComponent(e)}/containers`,void 0,{timeoutMs:3e4}),sshConfigHosts:()=>xe("GET","/api/ssh/config-hosts"),hosts:()=>xe("GET","/api/hosts"),saveHost:(e,t)=>xe("POST","/api/hosts",{name:e,...t}),deleteHost:e=>xe("DELETE",`/api/hosts/${encodeURIComponent(e)}`),trustHost:(e,t)=>xe("POST",`/api/hosts/${encodeURIComponent(e)}/trust`,t===void 0?{}:{lines:t},{timeoutMs:6e4}),resetTrustHost:e=>xe("POST",`/api/hosts/${encodeURIComponent(e)}/trust`,{reset:!0},{timeoutMs:2e4}),environments:()=>xe("GET","/api/environments"),saveEnvironment:(e,t)=>xe("POST","/api/environments",{name:e,...t}),deleteEnvironment:e=>xe("DELETE",`/api/environments/${encodeURIComponent(e)}`),trustEnvironment:(e,t)=>xe("POST",`/api/environments/${encodeURIComponent(e)}/trust`,t===void 0?{}:{lines:t},{timeoutMs:6e4}),deployEnvironment:e=>xe("POST",`/api/environments/${encodeURIComponent(e)}/deploy`,void 0,{timeoutMs:2e5}),probeEnvironment:e=>xe("POST",`/api/environments/${encodeURIComponent(e)}/probe`,void 0,{timeoutMs:3e4}),probeAllEnvironments:()=>xe("POST","/api/environments/probe",void 0,{timeoutMs:6e4}),localSkills:()=>xe("GET","/api/skills/local"),saveWorkspace:(e,t)=>xe("POST",`/api/environments/${encodeURIComponent(e)}/workspaces`,t),deleteWorkspace:(e,t)=>xe("DELETE",`/api/environments/${encodeURIComponent(e)}/workspaces${un({cwd:t})}`),workspaceSkills:(e,t,s=!1)=>xe("GET",`/api/environments/${encodeURIComponent(e)}/workspace-skills${un({cwd:t,refresh:s?1:void 0})}`,void 0,{timeoutMs:25e3}),installWorkspaceSkill:(e,t)=>xe("POST",`/api/environments/${encodeURIComponent(e)}/workspace-skills/install`,t,{timeoutMs:45e3}),removeWorkspaceSkill:(e,t,s)=>xe("DELETE",`/api/environments/${encodeURIComponent(e)}/workspace-skills${un({cwd:t,skill:s})}`,void 0,{timeoutMs:2e4}),listDir:(e,t)=>xe("GET",`/api/fs/${encodeURIComponent(e)}/list${un({path:t})}`),readFile:(e,t,s)=>xe("GET",`/api/fs/${encodeURIComponent(e)}/read${un({path:t,maxLines:s})}`),readFileRaw:(e,t)=>xe("GET",`/api/fs/${encodeURIComponent(e)}/read${un({path:t,raw:1})}`),writeFile:(e,t)=>xe("POST",`/api/fs/${encodeURIComponent(e)}/write`,t,{timeoutMs:3e4}),gitStatus:(e,t)=>xe("GET",`/api/git/${encodeURIComponent(e)}/status${un({cwd:t})}`),gitDiff:(e,t)=>xe("GET",`/api/git/${encodeURIComponent(e)}/diff${un(t??{})}`)};class od{ws=null;status="idle";subs=new Map;lastData=new Map;statusListeners=new Set;reconnectTimer=null;closedByApp=!1;retryDelay=500;url(){return`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/api/ws`}setStatus(t){if(this.status!==t){this.status=t;for(const s of this.statusListeners)s(t)}}getStatus(){return this.status}onStatus(t){return this.statusListeners.add(t),t(this.status),()=>this.statusListeners.delete(t)}ensureConnected(){if(this.ws&&(this.ws.readyState===WebSocket.OPEN||this.ws.readyState===WebSocket.CONNECTING))return;this.closedByApp=!1,this.setStatus("connecting");const t=new WebSocket(this.url());this.ws=t,t.onopen=()=>{this.retryDelay=500,this.setStatus("open");for(const s of this.subs.keys())this.send({type:"sub",channel:s})},t.onmessage=s=>{let r;try{r=JSON.parse(String(s.data))}catch{return}if(r.type==="event"&&typeof r.channel=="string"){this.lastData.set(r.channel,r.data);const o=this.subs.get(r.channel);if(o)for(const a of[...o])a(r.data)}},t.onerror=()=>{this.setStatus("error")},t.onclose=()=>{if(this.ws=null,this.closedByApp){this.setStatus("idle");return}if(this.setStatus("error"),this.subs.size>0&&this.reconnectTimer===null){const s=this.retryDelay;this.retryDelay=Math.min(8e3,Math.round(this.retryDelay*1.6)),this.reconnectTimer=window.setTimeout(()=>{this.reconnectTimer=null,this.subs.size>0&&this.ensureConnected()},s)}}}subscribe(t,s){let r=this.subs.get(t);const o=!r;r||(r=new Set,this.subs.set(t,r)),r.add(s);const a=this.lastData.get(t);return a!==void 0&&s(a),this.ensureConnected(),o&&this.ws?.readyState===WebSocket.OPEN&&this.send({type:"sub",channel:t}),()=>{const l=this.subs.get(t);l&&(l.delete(s),l.size===0&&(this.subs.delete(t),this.lastData.delete(t),this.ws?.readyState===WebSocket.OPEN&&this.send({type:"unsub",channel:t})))}}send(t){if(this.ws?.readyState===WebSocket.OPEN)try{this.ws.send(JSON.stringify(t))}catch{}}}const Qr=new od;function dr(e){const[t,s]=i.useState(null),[r,o]=i.useState(()=>Qr.getStatus()),[a,l]=i.useState(null),[c,f]=i.useState(null);return i.useEffect(()=>Qr.onStatus(o),[]),i.useEffect(()=>{if(!e){s(null),f(null);return}return s(null),f(null),Qr.subscribe(e,u=>{const d=u;s(d),l(Date.now()),f(typeof d?.error=="string"?d.error:null)})},[e]),{data:t,status:e?r:"idle",lastEventAt:a,serverError:c}}const al={data:null,status:"idle",lastEventAt:null,serverError:null};class id{map=new Map;perId=new Map;global=new Set;revision=0;set(t,s){const r=this.map.get(t);if(r&&r.data===s.data&&r.status===s.status&&r.lastEventAt===s.lastEventAt&&r.serverError===s.serverError)return;this.map.set(t,s),this.bump();const o=this.perId.get(t);if(o)for(const a of o)a();for(const a of this.global)a()}delete(t){if(this.map.delete(t)){this.bump();for(const s of this.global)s()}}get(t){return this.map.get(t)??al}has(t){return this.map.has(t)}summaries(){const t=new Map;for(const[s,r]of this.map)t.set(s,{running:r.data?.run.running??!1,...r.data?.agent?.cwd?{cwd:r.data.agent.cwd}:{},status:r.status,lastEventAt:r.lastEventAt,entryCount:r.data?.entries.length??0,toolCount:(r.data?.run.tools.length??0)+(r.data?.run.nestedTools.length??0)});return t}bump(){this.revision++}getRevision(){return this.revision}subscribeGlobal(t){return this.global.add(t),()=>this.global.delete(t)}subscribeId(t,s){let r=this.perId.get(t);return r||(r=new Set,this.perId.set(t,r)),r.add(s),()=>{r.delete(s),r.size===0&&this.perId.delete(t)}}}const Lt=new id;function us(e){const t=i.useCallback(r=>e===null?()=>{}:Lt.subscribeId(e,r),[e]),s=i.useCallback(()=>e===null?al:Lt.get(e),[e]);return i.useSyncExternalStore(t,s,s)}function ad(){const e=i.useCallback(s=>Lt.subscribeGlobal(s),[]),t=i.useCallback(()=>Lt.getRevision(),[]);return i.useSyncExternalStore(e,t,t)}function ld(){return ad(),Lt.summaries()}const cd=new Set(["files"]),ll=i.createContext(null),zi="pi-foreman:active-conv",eo="pi-foreman:dock",Fi="pi-foreman:dock-open";function to(e,t){try{const s=localStorage.getItem(e);return s?JSON.parse(s):t}catch{return t}}function qs(e,t){try{localStorage.setItem(e,JSON.stringify(t))}catch{}}function Jn(e){return e instanceof ur||e instanceof Error?e.message:String(e)}function ud({children:e}){const[t,s]=i.useState(null),[r,o]=i.useState(null),[a,l]=i.useState(0);i.useEffect(()=>{let w=!1;return ie.bootstrap().then(E=>{w||(s(E),o(null))},E=>{w||o(Jn(E))}),()=>{w=!0}},[a]);const c=i.useCallback(()=>l(w=>w+1),[]),[f,u]=i.useState([]),d=i.useCallback(w=>{u(E=>E.filter(O=>O.id!==w))},[]),m=i.useCallback(w=>{const E=`n-${Date.now()}-${Math.random().toString(36).slice(2,7)}`;u(q=>[...q.slice(-4),{...w,id:E}]);const O=w.ttl??(w.tone==="ok"||w.tone==="brand"?4500:8e3);setTimeout(()=>{u(q=>q.filter(de=>de.id!==E))},O)},[]),[k,v]=i.useState(null),[x,y]=i.useState(null),[p,g]=i.useState(null),[j,C]=i.useState(0),h=dr("models");i.useEffect(()=>{let w=!1;return ie.models().then(E=>{w||(v(E),y(null),g(Date.now()))},E=>{w||y(Jn(E))}),()=>{w=!0}},[j]),i.useEffect(()=>{h.data&&(v(h.data),y(null),g(Date.now()))},[h.data]);const b=i.useCallback(()=>C(w=>w+1),[]),N=i.useCallback(async()=>{const w=await ie.reload();b(),c(),m({tone:w.errors.length?"warn":"ok",title:"已热重载 Pi 扩展与配置",detail:`扩展 ${w.discoveredExtensions.length} 个 · 模板 ${w.promptsCount} 个${w.errors.length?` · 警告: ${w.errors[0]}`:""}`})},[m,c,b]),S=t?.prompts??[],[T,P]=i.useState({}),B=i.useCallback((w,E,O)=>{P(q=>({...q,[w]:{provider:E,modelId:O}}))},[]),[L,K]=i.useState({}),A=i.useCallback((w,E)=>{K(O=>({...O,[w]:E}))},[]),[z,M]=i.useState([]),R=i.useCallback(w=>{M(E=>[...E.slice(-39),{execId:w.execId,conversationId:w.conversationId,command:w.command,includeInContext:w.includeInContext,ok:!0,output:"",at:Date.now(),running:!0}])},[]),W=i.useCallback((w,E)=>{M(O=>O.map(q=>q.execId!==w?q:{...q,ok:E.ok,exitCode:E.exitCode??null,output:E.output,truncated:E.truncated,spillPath:E.spillPath,error:E.error,cwd:E.cwd??q.cwd,durationMs:E.durationMs,entryId:E.entryId??null,queued:E.queued,running:!1}))},[]),I=i.useCallback((w,E,O)=>{M(q=>{const de=q.filter(me=>me.conversationId!==w||me.running?!0:!(E.has(me.execId)||me.entryId!==void 0&&me.entryId!==null&&O.has(me.entryId)));return de.length===q.length?q:de})},[]),[_,V]=i.useState(!1),[H,Y]=i.useState("files"),[le,J]=i.useState(null),[se,Z]=i.useState(!1),re=i.useCallback(w=>J(w),[]),we=i.useCallback(()=>J(null),[]),D=i.useCallback(async w=>{const E=le;if(!E)return;const O=w!==void 0?w.trim():(E.handoff??"").trim();Z(!0);try{(await ie.reset(E.conversationId,O||void 0)).ok&&m({tone:"ok",title:`会话 #${E.conversationId} 上下文已清空`,detail:O?"已把交接摘要作为新起点。":"模型现在看不到之前的对话。"}),J(null)}catch(q){m({tone:"bad",title:"重置失败",detail:Jn(q)})}finally{Z(!1)}},[le,m]),[$,ee]=i.useState(null),[G,fe]=i.useState(null),te=i.useRef(void 0),ae=i.useCallback((w,E)=>{fe(E?.loginProvider??null),te.current=E?.refocus,ee(w)},[]),ce=i.useCallback(()=>{ee(null),fe(null);const w=te.current;te.current=void 0,w&&setTimeout(w,0)},[]),je=dr("envs"),$e=i.useMemo(()=>t?.hosts??[],[t?.hosts]),Q=i.useMemo(()=>{const w=new Map;for(const O of t?.envStatus??[])w.set(O.name,O);for(const O of je.data?.envs??[])w.set(O.name,O);const E=t?.environments??[];return E.length>0?E.map(O=>({name:O.name,label:O.label,host:O.host,hostType:O.hostType,runtime:O.runtime,kind:O.kind,cwd:O.cwd,description:O.description,fsGroup:O.fsGroup,workspaces:O.workspaces,config:O.config,...w.has(O.name)?{status:w.get(O.name)}:{}})):[...w.values()].map(O=>({name:O.name,label:O.label,host:O.host??O.name,hostType:O.hostType??"ssh",runtime:O.runtime??"host",kind:O.kind,cwd:O.cwd??null,status:O}))},[t,je.data]),ve=i.useCallback(w=>w?Q.find(E=>E.name===w):void 0,[Q]),ue=i.useCallback(w=>ve(w)?.label??w??"—",[ve]),[Ce,Ae]=i.useState(null),[Ie,X]=i.useState({}),ne=i.useCallback(async w=>{X(E=>({...E,[w]:!0}));try{await ie.probeEnvironment(w),c()}catch(E){m({tone:"bad",title:`${w} 探测失败`,detail:Jn(E)})}finally{X(E=>{const O={...E};return delete O[w],O})}},[m,c]),Pe=i.useCallback(async()=>{X(w=>{const E={...w};for(const O of Q)E[O.name]=!0;return E});try{await ie.probeAllEnvironments(),c()}catch(w){m({tone:"bad",title:"探测失败",detail:Jn(w)})}finally{X({})}},[Q,m,c]),[Ne,Re]=i.useState([]),[He,Ge]=i.useState({}),_e=i.useMemo(()=>{const w=t?.conversations??[],E=new Set(w.map(O=>O.conversationId));return[...w,...Ne.filter(O=>!E.has(O.conversationId))].filter(O=>!He[O.conversationId]?.deleted).map(O=>{const q=He[O.conversationId];return q?.archived!==void 0?{...O,archived:q.archived}:O})},[t,Ne,He]),F=i.useMemo(()=>_e.filter(w=>!w.archived),[_e]),oe=i.useMemo(()=>_e.filter(w=>!!w.archived),[_e]),[he,Se]=i.useState(()=>to(zi,null)),[De,Ve]=i.useState(null),[qe,Xe]=i.useState([]),lt=i.useRef(he);i.useEffect(()=>{lt.current=he},[he]);const $t=i.useRef(F);i.useEffect(()=>{$t.current=F},[F]),i.useEffect(()=>{qs(zi,he)},[he]),i.useEffect(()=>{const w=()=>{Xe(E=>{const O=E.filter(q=>{if(q===lt.current)return!1;const de=Lt.get(q);return!de.data||de.data.run.running});return O.length===E.length?E:O})};return Lt.subscribeGlobal(w)},[]);const ct=i.useCallback((w,E)=>{if(E?.split){Ve(w.conversationId);return}const O=lt.current;O!==null&&O!==w.conversationId&&Lt.get(O).data?.run.running&&Xe(q=>q.includes(O)?q:[...q,O]),Ve(q=>q===w.conversationId?null:q),Se(w.conversationId)},[]),Et=i.useCallback(w=>{Lt.delete(w),Xe(E=>E.filter(O=>O!==w)),Ve(E=>E===w?null:E),Se(E=>E!==w?E:$t.current.filter(q=>q.conversationId!==w&&!q.archived).sort((q,de)=>(de.createdAt??0)-(q.createdAt??0))[0]?.conversationId??null)},[]),hn=i.useCallback((w,E)=>{Re(O=>O.map(q=>q.conversationId===w?{...q,title:E}:q)),c()},[c]),Oe=i.useCallback(async(w,E)=>{const O=E.trim();O&&(await ie.renameConversation(w,O),Re(q=>q.map(de=>de.conversationId===w?{...de,title:O}:de)),c())},[c]),tt=i.useCallback(async(w,E)=>{await ie.archiveConversation(w,E),Ge(O=>({...O,[w]:{...O[w],archived:E}})),E&&Et(w),c(),m({tone:"ok",title:E?`已归档会话 #${w}`:`已恢复会话 #${w}`})},[Et,m,c]),ot=i.useCallback(async w=>{await ie.deleteConversation(w),Ge(E=>({...E,[w]:{...E[w],deleted:!0}})),Re(E=>E.filter(O=>O.conversationId!==w)),Et(w),c(),m({tone:"ok",title:`已删除会话 #${w}`})},[Et,m,c]),[et,Je]=i.useState(!1),[nt,jt]=i.useState(null),ft=i.useCallback(async(w,E,O)=>{Je(!0),jt(null);try{const q=await ie.createConversation(w,{...E?{cwd:E}:{},...O?.trim()?{title:O.trim()}:{}});return Re(de=>[...de,{conversationId:q.conversationId,env:q.env,cwd:q.cwd??void 0,title:q.title,createdAt:Date.now()}]),ct({conversationId:q.conversationId,env:q.env,cwd:q.cwd??void 0}),q.conversationId}catch(q){return jt(Jn(q)),null}finally{Je(!1)}},[ct]),[wt,pt]=i.useState(()=>{const w=to(eo,"files");return cd.has(w)?w:"files"}),[Ct,St]=i.useState(()=>to(Fi,!1)),[an,Tt]=i.useState(!0),mt=i.useCallback(w=>{St(w),qs(Fi,w)},[]),Kt=i.useCallback(w=>{pt(w),qs(eo,w),mt(!0)},[mt]),[Wn,qt]=i.useState(null),ps=i.useCallback((w,E)=>{Y("files"),qt(O=>({env:w,cwd:E,n:(O?.n??0)+1})),mt(!0)},[mt]),Gn=i.useCallback(()=>{Y("git"),pt("files"),qs(eo,"files"),mt(!0)},[mt]),[Rn,Dt]=i.useState(!1),[Vn,Kn]=i.useState(null),[Pn,Yt]=i.useState(null),[Rt,On]=i.useState(!1),[Nt,In]=i.useState(null),[ms,bn]=i.useState(null),[gs,An]=i.useState(null),Mn=i.useCallback((w,E)=>{Kn(w??null),Yt(E??null),Dt(!0)},[]),vn=i.useCallback(w=>{In(w?.edit??null),bn(w?.hostName??null),On(!0)},[]),Us=i.useCallback((w,E)=>{An({env:w,workspace:E})},[]),Ws=i.useCallback(()=>{An(null)},[]),Gs=je.status,qn=i.useMemo(()=>t?.localSkills??[],[t?.localSkills]),Ei=i.useMemo(()=>({bootstrap:t,bootstrapError:r,reloadBootstrap:c,models:k,modelsError:x,modelsLoadedAt:p,reloadModels:b,reloadAll:N,prompts:S,localSkills:qn,modelOverrides:T,setModelOverride:B,thinkingOverrides:L,setThinkingOverride:A,notices:f,notify:m,dismissNotice:d,pendingExecs:z,startPendingExec:R,finishPendingExec:W,prunePendingExecs:I,resetRequest:le,requestReset:re,cancelReset:we,runReset:D,resetting:se,helpOpen:_,setHelpOpen:V,activePicker:$,pickerLoginProvider:G,openPicker:ae,closePicker:ce,filesMode:H,setFilesMode:Y,openFilesGit:Gn,filesJump:Wn,jumpToFiles:ps,hostRows:$e,envs:je,envRows:Q,envByName:ve,envLabel:ue,selectedEnv:Ce,setSelectedEnv:Ae,probingEnvs:Ie,probeEnv:ne,probeAllEnvs:Pe,conversations:F,archivedConversations:oe,activeConvId:he,splitConvId:De,backgroundConvIds:qe,setSplitConvId:Ve,openConversation:ct,closeConversation:Et,renameConversationTitle:Oe,applyAutoTitle:hn,archiveConversation:tt,deleteConversation:ot,createConversation:ft,createError:nt,creating:et,dock:wt,setDock:Kt,dockOpen:Ct,setDockOpen:mt,railOpen:an,setRailOpen:Tt,newConvOpen:Rn,setNewConvOpen:Dt,newConvEnv:Vn,newConvCwd:Pn,openNewConv:Mn,addEnvOpen:Rt,setAddEnvOpen:On,editEnvTarget:Nt,addEnvInitialHost:ms,openAddEnv:vn,workspaceModalTarget:gs,openWorkspaceSettings:Us,closeWorkspaceSettings:Ws,globalStatus:Gs}),[t,r,c,k,x,p,b,N,S,qn,T,B,L,A,f,m,d,z,R,W,I,le,re,we,D,se,_,$,G,ae,ce,H,Gn,Wn,ps,$e,je,Q,ve,ue,Ce,Ie,ne,Pe,F,oe,he,De,qe,ct,Et,Oe,hn,tt,ot,ft,nt,et,wt,Kt,Ct,mt,an,Rn,Vn,Pn,Mn,Rt,Nt,ms,vn,gs,Us,Ws,Gs]);return n.jsx(ll.Provider,{value:Ei,children:e})}function Ye(){const e=i.useContext(ll);if(!e)throw new Error("useApp 必须在 AppStoreProvider 内调用");return e}const cl=48,on=(e,t=0)=>{const s=new Int32Array(e.length);for(let r=0;r<e.length;r++)s[r]=e.charCodeAt(r)-cl-t;return s},wr=e=>{const t=new Int32Array(e.length+1);for(let s=0;s<e.length;s++)t[s+1]=t[s]+e[s];return t},Nn=e=>{const t=new Int32Array(e.length);let s=0;for(let r=0;r<e.length;r++){const o=e.charCodeAt(r)-cl;s+=o>>>1^-(o&1),t[r]=s}return t},dd=384,fd=[],Fn=wr(on("E0500002005282000000002000150000020021820000011200000003022202000300004200120000200420001200021200301200010400162000010000220021010:2192001200220012000220012000200200200400010200040000000000400200108200110100000022010313000162002000020020012020080213000228200000000082000000000120002000120020020040101020300130001001010")),pd=wr(on(":11111111211111119311546544411119731869:671397415686432441111111111161114151214313433415:78311132233313187211117221449443411141111151152226611131111112212518142224214215421421542142424242516171151615616347111111111197911327451111111111111111111113134714133513411111311111111111111111111112444411111342312715245411117:3")),md="@containerabcdefghinlmoprstunderlineviawzccentlignnimatespectuto-colsrowsaglorightnessckdrop-sisbcontrastfiltergrayscalehue-rotateinvertopacityslurrightnessaturateepia-coniclinearpositionradialsizeockurrderttom-belrstxyespacing-xyaretoursorlnt-umnsendspantartainentrasteividerop-shadowurationcorationlay-xyasendillexontromlter-featuresstretchapr-xyayscaleidow-colsrowsue-rotatedentlinesetvert-beringsxyeshadoweiadingftnest-clamp-imageabein-lrstxyskx--b-coniclpositionrsizet-x-y-fromto-fromto-inearfromto-fromto-adialfromto-fromtofromtofromtofromtoblockhinlinew-screenesblockhinlinewbjectpacityrutlinederigin-offsetbelrstxyesrspective-originaceholderioghtng-offsettateundedw-xyz-belrstlreseslr-endspantartaturatecepiahizekewpace-taleroll-xyz-barmpbelrstxyesbelrstxyes-thumbrackadowrink-xyxyartrokeabextora-shadowpckingnsformitionlate-xyz-offsetill-changeoom",gd=(()=>{const e=Fn.length-1,t=new Int32Array(e);for(let o=e-1;o>=0;o--){let a=1,l=o+1;for(let c=Fn[o];c<Fn[o+1];c++)a+=t[l],l+=t[l];t[o]=a}const s=new Int32Array(Fn[e]);let r=0;for(let o=0;o<e;o++){let a=o+1;for(let l=Fn[o];l<Fn[o+1];l++)s[r++]=a,a+=t[a]}return s})(),xd=on("02000000000000900<=0?000B000F00F00ŏI0J0LNPRTVX0000]_a00000000000000000000000rst0000000zŏ00000000000…ŏ000ˆ0000ŏ0000000000—0000000000000000000000000000000000000000000000000000Ë000000000000000000000Þ000000000000000000ð0000000ø0ùúûüýþÿĀāĂ㥹Ć000000000000000000000000000000000000000000ħ0ĨĪ00000000000000000000ļĽ00000Ŭ000000",1),hd=wr(on("123333359346463635126536711576")),bd=on("93203242332583253248325D>E?F@03263243255B:032523853:0325B:8GA032542H<C=12727B:0328432553;D>E?3257D>032585:0325B:;0328B:032"),vd=on("012113445661666666789111:5;;;;;;;;444;;;:62999<1161=62>>?61:21@ABCD4446996:64E:::;:?::64:F114GHHIHHHHIHH1HH1HH1HHHHHH::EEJ4444::EE4444441691;644444114244444:;K6666555555555555555999666664444444444444444444444226?6:66644L9M?D:111::::6DE199"),yd=Nn("020200202020020020020020020020200200200200200200200002020202001003040106000200200200200200200200200200200200200200200200200200200200200200200200200200200200020020020020020020002020200202002002002002002002002002002020002002020020200220200200200200200200200200200200020020020000200020002000200200200020020020002000200200200020020202002020202000200200020022000200200020020002002000200220002002000200W0Z00020020002002020002002000200g0j0002002000200200020020002002000200200020020002000200002000002002002002002000200020000200002002002002002002002020020020200200200200200200200200202020020020020020020020020002002002020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020002002002002002002000200200200200200200200200200020202020002000200020002002002002000020200200"),kd=(()=>{const e=new Int32Array(319).fill(-1),t=Nn("02422242:222222242224222242442222222422222244442242226224222426222422442462222422622222222626222462242622422622422424242422222222422222222242422222222222222222622442224222222222222224424442262222222222222222222226224222424242422224422422422222"),s=Nn("02222222222222222222202222222222222222222222221422222222222222222222222222222222222Y\\222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222221422222222222222222222222222222222222222Ŀł222222222222222222");for(let r=0;r<t.length;r++)e[t[r]]=s[r];return e})(),jd="container |break-after- all auto avoid avoid-page column left page right|break-before- all auto avoid avoid-page column left page right|break-inside-a uto void void-column void-page|box-decoration- clone slice|box- border content| contents flow-root hidden table table-caption table-cell table-column table-column-group table-footer-group table-header-group table-row table-row-group| not-sr-only sr-only|float- end left none right start|clear- both end left none right start|isolat e ion-auto|overflow- auto clip hidden scroll visible|overflow-x- auto clip hidden scroll visible|overflow-y- auto clip hidden scroll visible|overscroll- auto contain none|overscroll-x- auto contain none|overscroll-y- auto contain none| absolute fixed relative static sticky| collapse invisible visible|justify- around baseline between center center-safe end end-safe evenly normal start stretch|justify-items- center center-safe end end-safe normal start stretch|justify-self- auto center center-safe end end-safe start stretch|items- baseline baseline-last center center-safe end end-safe start stretch|self- auto baseline baseline-last center center-safe end end-safe start stretch|place-content- around baseline between center center-safe end end-safe evenly start stretch|place-items- baseline center center-safe end end-safe start stretch|place-self- auto center center-safe end end-safe start stretch| antialiased subpixel-antialiased| italic not-italic|normal-nums |ordinal |slashed-zero | lining-nums oldstyle-nums| proportional-nums tabular-nums| diagonal-fractions stacked-fractions| no-underline overline| capitalize lowercase normal-case uppercase|truncate |whitespace- break-spaces normal nowrap pre pre-line pre-wrap|break- all keep normal words|wrap- anywhere break-word normal|hyphens- auto manual none|mix-blend- color color-burn color-dodge darken difference exclusion hard-light hue lighten luminosity multiply normal overlay plus-darker plus-lighter saturation screen soft-light|table- auto fixed|caption- bottom top|backface- hidden visible|appearance- auto none|scheme- dark light light-dark normal only-dark only-light|field-sizing- content fixed|pointer-events- auto none|resize -none -x -y|snap- align-none center end start|snap- always normal|snap- both none x y|snap- mandatory proximity|touch- auto manipulation none|touch-pan- left right x|touch-pan- down up y|touch-pinch-zoom |select- all auto none text|forced-color-adjust- auto none| normal size| baseline bottom middle sub super text-bottom text-top top| bounce none ping pulse spin| auto square video| auto fr max min px|none | auto full px| fixed local scroll|clip- border content padding text|origin- border content padding| bottom bottom-left bottom-right center left left-bottom left-top right right-bottom right-top top top-left top-right| no-repeat repeat repeat-round repeat-space repeat-x repeat-y| auto contain cover|blend- color color-burn color-dodge darken difference exclusion hard-light hue lighten luminosity multiply normal overlay saturation screen soft-light|to- b bl br l r t tl tr| auto dvh fit full lh lvh max min px screen svh| dashed dotted double hidden none solid| collapse separate|px |auto |full | content none strict| inline-size size|layout |paint |style | around baseline between center center-safe end end-safe evenly normal start stretch| alias all-scroll auto cell col-resize context-menu copy crosshair default e-resize ew-resize grab grabbing help move n-resize ne-resize nesw-resize no-drop none not-allowed ns-resize nw-resize nwse-resize pointer progress row-resize s-resize se-resize sw-resize text vertical-text w-resize wait zoom-in zoom-out| dashed dotted double solid wavy| auto from-font|reverse |initial | in in-out initial linear out| col col-reverse row row-reverse| nowrap wrap wrap-reverse| auto initial none| black bold extrabold extralight light medium normal semibold thin| condensed expanded extra-condensed extra-expanded normal semi-condensed semi-expanded ultra-condensed ultra-expanded|flow- col col-dense dense row row-dense| none subgrid| auto dvh dvw fit full lh lvh lvw max min px screen svh svw| block flex grid table| auto dvw fit full lvw max min px screen svw| loose none normal px relaxed snug tight|through |item | inside outside| decimal disc none| auto px| clip-border clip-content clip-fill clip-padding clip-stroke clip-view no-clip| add exclude intersect subtract| alpha luminance match|origin- border content fill padding stroke view|type- alpha luminance| circle ellipse| closest-corner closest-side farthest-corner farthest-side|at- bottom bottom-left bottom-right center left left-bottom left-top right right-bottom right-top top top-left top-right| dvh fit full lh lvh max min none px screen svh| auto dvh dvw fit full lh lvh lvw max min none px screen svh svw| dvw fit full lvw max min none px screen svw| auto dvh dvw fit full lvh lvw max min none prose px svh svw| auto dvh dvw fit full lvh lvw max min none px screen svh svw| contain cover fill none scale-down| first last none| distant dramatic midrange near none normal|inset | full none|3d | auto smooth|gutter- auto both stable| auto none thin| inner none| auto dvh dvw fit full lvh lvw max min px svh svw|base | center end justify left right start| clip ellipsis| balance nowrap pretty wrap| normal tight tighter wide wider widest| cpu gpu none| 3d flat| all colors none opacity shadow transform| discrete normal| full px| auto dvh dvw fit full lvh lvw max min px screen svh svw| auto contents scroll transform".split("|").map(e=>{const t=e.split(" "),s=t.shift();for(let r=0;r<t.length;r++)t[r]=s+t[r];return t}),_i=Nn("0000000000000000000000000000000000000000000000000000000000000262242:6@200000006:240B428:4422400002046044222426220026642642462026224222824220022400000000\\00N222422242222222224062242222222422226264222422222222222222442804222422222222222222222222220<4<0204260002444020204224422"),wd=Nn("ɠ222222222222222222222222222222222222222222222222222222222222˕4222226>6ʰ22ʷʺʷʺʷ42ʴ2ʓ22>621422ɶ222ɹɼɷɺɷɺ22ɱ42222ɨ2ɧ26622ɘɓ244ƸƵ222]d24242ǖǓƚÄȫ2263ȨȥȨ2222222ǣ222222222222222222ǂƽ2ƾƵ2222222422222ƜƑ22222222222222222222144Ŧţ22Ţş222222222222222222222ĸ2ı68ĦģĦɡŰ4Ġ«®ĝ822ĔđĔ2ē2222622"),Cd=Nn("02222222222222222222222222222222222222222222222222222222222222222202021422222222CF2200GJ021042222WZ222IL0ad2c10h2222U00X202[^2w0000120zy|}€22ƒ†…:22z22222222222G000q†OVI00000{˜2™<40000Œ›@00000G¦§000ª00000000000000021K¬«00®“000000000000000000000–222›HGH_1¸222½2¾2222ÇÊ000­°2±"),ul=new Int32Array(987),dl=new Int32Array(987),fl=new Int32Array(987);let Co="";const So=new Int32Array(1022);{const e=new Map;let t=0,s=0;for(let r=0;r<_i.length;r++)for(const o of jd[Cd[r]]){let a=e.get(o);a===void 0&&(a=t++,e.set(o,a),So[a*2]=Co.length,So[a*2+1]=o.length,Co+=o),ul[s]=_i[r],dl[s]=wd[r],fl[s]=a,s++}}const Sd=Nn("0b2N:222@R>F@286¦2@H2D266226FB22B2>BD\\6N22222Z222D222p"),Nd=wr(on("1::24444432:442:44:44>222222:44:4421322511111311111114")),Ed=Nn("2Š4A;33N=C@H4A;33N=C@<27;83:;8393NQ:3NQʰ222ˉºŴŽ2R2=18cƴÅҜ=cĞÛC1ƈǝȈ:ħ25=11D3A@4=<1;1DEr25;11B3?<6;:371BCn9@7=<8192>2E121@9@EHE@9>2T25511<398454131<=V25511<398454131<=„ƧNž2Đå242L222290000f22500ɛ000ǘ222"),Td=on("ij"),Rd=on("—"),Pd=on("1"),Od="* ** after backdrop before details-content file first-letter first-line marker placeholder selection";var Id={GROUP_COUNT:dd,customValidatorNames:fd,edgeStart:Fn,labelStart:pd,labelText:md,edgeTarget:gd,nodeGroup:xd,nodeVlist:kd,vlistPat:hd,vlistOps:bd,vlistRef:vd,vlistGroup:yd,litAnchor:ul,litGroup:dl,litPool:fl,poolOffsets:So,poolText:Co,adjGid:Sd,adjStart:Nd,adjTgt:Ed,patGid:Td,patTgt:Rd,postfixLookupGroups:Pd,orderSensitiveModifiers:Od};const Ad="line"in new Error,Qt=-1,zn=-1,no=(e,t,s)=>{let r=2166136261;for(let o=t;o<s;o++)r=Math.imul(r^e.charCodeAt(o),16777619);return r},or=(e,t,s)=>{const r=s-t;let o=Math.imul(r,2654435761)^e.charCodeAt(t);if(r>3){const a=r>>2,l=r>>1;o=Math.imul(o^e.charCodeAt(t+1)<<8^e.charCodeAt(t+2)<<16^e.charCodeAt(t+a),2246822507),o=Math.imul(o^e.charCodeAt(t+l)<<8^e.charCodeAt(t+l+a)<<16^e.charCodeAt(s-3),3266489909),o^=e.charCodeAt(s-2)<<8^e.charCodeAt(s-1)<<16;for(let c=t+3,f=s-4;c<t+8&&c<f;c++,f--)o=Math.imul(o^e.charCodeAt(c)^e.charCodeAt(f)<<8,16777619)}return o^o>>>15|0},Md=(e,t,s={})=>{const{GROUP_COUNT:r,edgeStart:o,labelStart:a,labelText:l,edgeTarget:c,nodeGroup:f,nodeVlist:u,vlistPat:d,vlistOps:m,vlistRef:k,vlistGroup:v,litAnchor:x,litGroup:y,litPool:p,poolOffsets:g,poolText:j,adjGid:C,adjStart:h,adjTgt:b,patGid:N,patTgt:S,postfixLookupGroups:T,customValidatorNames:P,orderSensitiveModifiers:B}=e,L=new Int32Array(r).fill(-1);for(let w=0;w<C.length;w++)L[C[w]]=w;let K=0;for(let w=0;w+1<h.length;w++){const E=h[w+1]-h[w];E>K&&(K=E)}let A=32;for(;A<2*(1+K+N.length);)A<<=1;const z=new Int32Array(k.length+1);for(let w=0;w<k.length;w++)z[w+1]=z[w]+d[k[w]+1]-d[k[w]];const M=new Uint8Array(r);for(let w=0;w<T.length;w++)M[T[w]]=1;const R=o.length-1,W=new Uint8Array(R);let I=0,_=!0;for(let w=0;w<x.length;w++){W[x[w]]=1;const E=g[p[w]*2+1];E>I&&(I=E);const O=j.charCodeAt(g[p[w]*2]);(O===91||O===40)&&(_=!1)}let V=1;for(;V<x.length*2;)V<<=1;const H=new Int32Array(V).fill(-1);for(let w=0;w<x.length;w++){const E=g[p[w]*2];let O=(no(j,E,E+g[p[w]*2+1])^Math.imul(x[w],2654435761)|0)&V-1;for(;H[O]!==-1;)O=O+1&V-1;H[O]=w}const Y=(w,E,O,q)=>{let de=(no(E,O,q)^Math.imul(w,2654435761)|0)&V-1;const me=q-O;for(;;){const Me=H[de];if(Me===-1)return-1;if(x[Me]===w&&g[p[Me]*2+1]===me){const Qe=g[p[Me]*2];let Le=!0;for(let ge=0;ge<me;ge++)if(j.charCodeAt(Qe+ge)!==E.charCodeAt(O+ge)){Le=!1;break}if(Le)return y[Me]}de=de+1&V-1}},le=s.cacheSize??8192,J=s.prefix??e.prefix??"",se=J===""?"":J+":",Z=se.length,re=(P??[]).map(w=>{throw new Error("cn: missing validator "+w)}),we=/\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh|cq(w|h|i|b|min|max))|\b(calc|min|max|clamp)\(.+\)|^0$/,D=/^(rgba?|hsla?|hwb|(ok)?(lab|lch)|color-mix)\(.+\)$/,$=/^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/,ee=/^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/;let G=0,fe=-1,te=-1,ae=-1,ce=-1;const je=w=>w>=97&&w<=122||w>=65&&w<=90||w>=48&&w<=57||w===95,$e=w=>/\s/.test(String.fromCharCode(w)),Q=(w,E,O)=>{if(G=0,fe=-1,O-E<3)return;const q=w.charCodeAt(E),de=w.charCodeAt(O-1);if(q===91&&de===93)G=1;else if(q===40&&de===41)G=2;else return;ae=E+1,ce=O-1;let me=E+1;if(je(w.charCodeAt(me))){for(me++;me<O-1;){const Me=w.charCodeAt(me);if(!je(Me)&&Me!==45)break;me++}me<O-2&&w.charCodeAt(me)===58&&(fe=E+1,te=me,ae=me+1)}},ve=(w,E,O,q)=>{if(O-E!==q.length)return!1;for(let de=0;de<q.length;de++)if(w.charCodeAt(E+de)!==q.charCodeAt(de))return!1;return!0},ue=/^\d+(?:\.\d+)?\/\d+(?:\.\d+)?$/,Ce=/^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/,Ae=w=>!!w&&!Number.isNaN(Number(w)),Ie=(w,E,O)=>{if(O-E<11||!ve(w,E,E+10,"@container"))return!1;if(w.charCodeAt(E+10)===47)return O-E>=12;const q=w.charCodeAt(E+11);return q===115&&O-E>=17&&ve(w,E+10,E+16,"-size/")||q===110&&O-E>=19&&ve(w,E+10,E+18,"-normal/")},X=[1,1,1,1,1,1,1,1,2,2,2,2,2,2,2],ne="length|number|number weight|family-name|position percentage|length size bg-size|image url|shadow|length|family-name|position percentage|length size bg-size|image url|shadow|number weight".split("|").map(w=>w.split(" ")),Pe=[2,3,1,0,0,0,4,5,0,0,0,0,0,1,1],Ne=(w,E,O,q)=>{if(w>=10){if(w>=25)return re[w-25](E.slice(O,q));const de=w-10;if(G!==X[de])return!1;if(fe>=0){for(const me of ne[de])if(ve(E,fe,te,me))return!0;return!1}switch(Pe[de]){case 0:return!1;case 1:return!0;case 2:{const me=E.slice(ae,ce);return we.test(me)&&!D.test(me)}case 3:return Ae(E.slice(ae,ce));case 4:return ee.test(E.slice(ae,ce));default:return $.test(E.slice(ae,ce))}}switch(w){case 0:return!0;case 1:return G===0;case 2:return G===1;case 3:return G===2;case 4:return ue.test(E.slice(O,q));case 5:return Ae(E.slice(O,q));case 6:{const de=E.slice(O,q);return!!de&&Number.isInteger(Number(de))}case 7:return q>O&&E.charCodeAt(q-1)===37&&Ae(E.slice(O,q-1));case 8:return Ce.test(E.slice(O,q));default:return Ie(E,O,q)}},Re=new Set(typeof B=="string"?B.split(" "):B),He=(w,E,O,q,de,me)=>{const Me=no(E,O,q)^(de?2654435769:0)|0;let Qe=w.get(Me);if(Qe!==void 0)e:for(let Ee=0;Ee<Qe.length;Ee++){const ze=Qe[Ee];if(!(ze.imp!==de||ze.k.length!==q-O)){for(let st=0;st<ze.k.length;st++)if(ze.k.charCodeAt(st)!==E.charCodeAt(O+st))continue e;return ze.id}}else w.set(Me,Qe=[]);const Le=E.slice(O,q),ge=me(Le);return Qe.push({k:Le,imp:de,id:ge}),ge};let Ge=new Map,_e=new Map,F=2;const oe=4096,he=(w,E)=>{const O=[];let q=0,de=0,me=0;for(let ge=0;ge<w.length;ge++){const Ee=w.charCodeAt(ge);q===0&&de===0&&Ee===58?(O.push(w.slice(me,ge)),me=ge+1):Ee===91?q++:Ee===93?q--:Ee===40?de++:Ee===41&&de--}O.push(w.slice(me));let Me=O[0];if(O.length>1){const ge=[];let Ee=[];for(const ze of O)ze.charCodeAt(0)===91||Re.has(ze)?(Ee.length&&(ge.push(...Ee.sort()),Ee=[]),ge.push(ze)):Ee.push(ze);Ee.length&&ge.push(...Ee.sort()),Me=ge.join(":")}const Qe=E?Me+" !":Me;let Le=_e.get(Qe);return Le===void 0&&_e.set(Qe,Le=F++),Le};let Se=new Map,De=r;const Ve=r+4096,qe=()=>De++,Xe=2097152,lt=8192,$t=new Int32Array(lt),ct=new Array(lt).fill(null),Et=new Int32Array(lt),hn=new Int32Array(lt),Oe=new Uint8Array(lt);let tt=0;const ot=(w,E,O,q,de,me,Me,Qe)=>{let Le=w;if(ct[w]!==null)if(ct[w|1]===null)Le=w|1;else if((tt++&3)===0)Le=w|tt>>2&1;else return;ct[Le]=E.slice(O,q),$t[Le]=de,Et[Le]=me,hn[Le]=Me,Oe[Le]=Qe},et=()=>ct.fill(null);let Je=256,nt=[new Int32Array(Je),new Int32Array(Je),new Int32Array(Je),new Int32Array(Je)],[jt,ft,wt,pt]=nt,Ct=new Uint8Array(Je),St=new Uint8Array(Je);const an=()=>{Je*=2,nt=nt.map(E=>{const O=new Int32Array(Je);return O.set(E),O}),[jt,ft,wt,pt]=nt;const w=new Uint8Array(Je);w.set(Ct),Ct=w,St=new Uint8Array(Je)};let Tt=64,mt=new Int32Array(Tt),Kt=new Int32Array(Tt);const Wn=new Int32Array(r);let qt=2048,ps=21,Gn=new Float64Array(qt),Rn=new Int32Array(qt),Dt=0;const Vn=(w,E)=>{if(w===0&&E<r)return Wn[E]===Dt?1:(Wn[E]=Dt,0);const O=w*2097152+E+1;let q=Math.imul(O,2654435761)>>>ps;for(;Rn[q]===Dt;){if(Gn[q]===O)return 1;q=q+1&qt-1}return Gn[q]=O,Rn[q]=Dt,0},Kn=(w,E,O,q,de)=>{if(O-E>=2&&w.charCodeAt(E)===91&&w.charCodeAt(O-1)===93){let me=-1;for(let Me=E+1;Me<O-1;Me++)if(w.charCodeAt(Me)===58){me=Me;break}return me===-1||me===E+1?Qt:He(Se,w,E+1,me,0,qe)}if(q>=0&&f[q]>=0)return f[q];for(let me=de-1;me>=0;me--){const Me=Kt[me];if(Me>O)continue;const Qe=mt[me],Le=O-Me;if(W[Qe]===1&&Le>0&&Le<=I){const it=w.charCodeAt(Me);if(_===!1||it!==91&&it!==40){const yn=Y(Qe,w,Me,O);if(yn>=0)return yn}}const ge=u[Qe];if(ge<0)continue;const Ee=k[ge],ze=d[Ee],st=d[Ee+1];if(ze===st)continue;Q(w,Me,O);const gt=z[ge]-ze;for(let it=ze;it<st;it++)if(Ne(m[it],w,Me,O))return v[gt+it]}return Qt},Pn=w=>{const E=w.length;let O=0,q=0,de=!1;(F>oe||Ge.size>oe)&&(Ge=new Map,_e=new Map,F=2,et()),De>Ve&&(Se=new Map,De=r,et());let me=0;for(;me<E;){let ge=w.charCodeAt(me);if(ge===32||ge>=9&&ge<=13||ge>=160&&$e(ge)){ge!==32&&(de=!0),me++;continue}const Ee=me;let ze=0;for(;me<E;){if(ge=w.charCodeAt(me),ge<=32){if(ge===32)break;if(ge>=9&&ge<=13){de=!0;break}}else if(ge>=160&&$e(ge)){de=!0;break}ze=Math.imul(ze^ge,16777619),me++}const st=me,gt=st-Ee;O===Je&&an();const it=O++;jt[it]=Ee,ft[it]=st,q+=gt,ze^=Math.imul(gt,2654435761);const yn=ze^ze>>>15|0,Xt=yn&8190;{let Ue=-1;if($t[Xt]===yn&&ct[Xt]!==null&&ct[Xt].length===gt?Ue=Xt:$t[Xt|1]===yn&&ct[Xt|1]!==null&&ct[Xt|1].length===gt&&(Ue=Xt|1),Ue>=0){const zt=ct[Ue];let ln=!0;for(let cn=0;cn<gt;cn++)if(zt.charCodeAt(cn)!==w.charCodeAt(Ee+cn)){ln=!1;break}if(ln){wt[it]=Et[Ue],pt[it]=hn[Ue],Ct[it]=Oe[Ue];continue}}}let Yn=Ee;if(Z!==0){if(st-Ee<=Z||!w.startsWith(se,Ee)){wt[it]=Qt,ot(Xt,w,Ee,st,yn,Qt,0,0);continue}Yn=Ee+Z}let Br=0,Hr=0,xs=-1,Ur=-1;for(let Ue=Yn;Ue<st;Ue++){const zt=w.charCodeAt(Ue);if(Br===0&&Hr===0){if(zt===58){xs=Ue;continue}if(zt===47){Ur=Ue;continue}}zt===91?Br++:zt===93?Br--:zt===40?Hr++:zt===41&&Hr--}const Ti=xs>=Yn?xs+1:Yn;let Pt=Ti,Ot=st,hs=!1,Ri=0;Ot>Pt&&w.charCodeAt(Ot-1)===33?(hs=!0,Ot--):Ot>Pt&&w.charCodeAt(Pt)===33&&(hs=!0,Pt++,Ri=1);let $n=-1;Ur>Ti&&($n=Ur+Ri,$n>=Ot&&($n=-1));let Wr=Pt;Ot-Pt>1&&w.charCodeAt(Pt)===45&&(Wr=Pt+1);let Jt=0,kn=0,Xn=0,Pi=-1,Zt=0;(u[0]>=0||W[0]===1)&&(mt[0]=0,Kt[0]=Wr,Zt=1);let Gr=zn,Vr=0;for(let Ue=Wr;Ue<Ot;Ue++)if(Ue===$n&&(Gr=kn<Xn?zn:Jt,Vr=Zt),Jt!==zn){const zt=w.charCodeAt(Ue);let ln=-1;if(kn<Xn)l.charCodeAt(kn)===zt?(kn++,kn===Xn&&(ln=Jt=Pi)):Jt=zn;else{const cn=o[Jt],Ks=o[Jt+1];let Xr=zn;for(let Dn=cn;Dn<Ks;Dn++){const Jr=a[Dn];if(l.charCodeAt(Jr)===zt){a[Dn+1]-Jr===1?ln=Xr=c[Dn]:(kn=Jr+1,Xn=a[Dn+1],Pi=c[Dn],Xr=Jt);break}}Jt=Xr}if(ln>=0&&(u[ln]>=0||W[ln]===1)&&Ue+1<Ot&&w.charCodeAt(Ue+1)===45){if(Zt===Tt){Tt*=2;const cn=new Int32Array(Tt);cn.set(mt),mt=cn;const Ks=new Int32Array(Tt);Ks.set(Kt),Kt=Ks}mt[Zt]=ln,Kt[Zt]=Ue+2,Zt++}}$n===Ot&&(Gr=kn<Xn?zn:Jt,Vr=Zt);const Kr=kn<Xn?zn:Jt;let It,Vs=!1;if($n>=0)if(Vs=!0,It=Kn(w,Pt,$n,Gr,Vr),It!==Qt&&It<r&&M[It]){const Ue=Kn(w,Pt,Ot,Kr,Zt);Ue!==Qt&&Ue!==It&&(It=Ue,Vs=!1)}else It===Qt&&(It=Kn(w,Pt,Ot,Kr,Zt),Vs=!1);else It=Kn(w,Pt,Ot,Kr,Zt);let qr=0,Yr=0;It===Qt?wt[it]=Qt:(Yr=Vs?1:0,qr=Yn>=xs?hs?1:0:He(Ge,w,Yn,xs,hs?1:0,Ue=>he(Ue,hs)),wt[it]=It,Ct[it]=Yr,pt[it]=qr),ot(Xt,w,Ee,st,yn,It,qr,Yr)}if(O===0)return"";if(O===1)return jt[0]===0&&ft[0]===E?w:w.slice(jt[0],ft[0]);if(O*A>qt){for(;O*A>qt;)qt<<=1,ps--;Gn=new Float64Array(qt),Rn=new Int32Array(qt)}if(F>=Xe||De>=Xe)throw new Error("cn: too many distinct classes in one merge");Dt=Dt+1|0,Dt===0&&(Wn.fill(0),Rn.fill(0),Dt=1);let Me=!1;for(let ge=O-1;ge>=0;ge--){const Ee=wt[ge];if(Ee===Qt){St[ge]=1;continue}const ze=pt[ge];if(Vn(ze,Ee)===1){St[ge]=0,Me=!0;continue}if(St[ge]=1,Ee<r){const st=L[Ee];if(st>=0)for(let gt=h[st];gt<h[st+1];gt++)Vn(ze,b[gt]);if(Ct[ge]&1)for(let gt=0;gt<N.length;gt++)N[gt]===Ee&&Vn(ze,S[gt])}}if(!Me&&!de&&E===q+O-1)return w;let Qe="",Le=0;for(;Le<O;){if(!St[Le]){Le++;continue}const ge=jt[Le];let Ee=ft[Le],ze=Le+1;for(;ze<O&&St[ze]&&jt[ze]===Ee+1&&w.charCodeAt(Ee)===32;)Ee=ft[ze],ze++;Qe.length>0&&(Qe+=" "),Qe+=w.slice(ge,Ee),Le=ze}return Qe},Yt=16384,Rt=new Int32Array(Yt*2);let On=0,Nt=1,In=Object.create(null),ms=Object.create(null),bn=new Map,gs=new Map,An=0,Mn=0;const vn=()=>{On^=Yt,Nt=Nt+1|0,Mn=0},Us=w=>{let E=In[w];if(E!==void 0)return E;const O=or(w,0,w.length),q=(O&16383)+On,de=Rt[q]===(O^Nt)||Rt[q^Yt]===(O^Nt-1);return de&&(E=ms[w],E!==void 0)?(In[w]=E,E):(E=Pn(w),de?(In[w]=E,++An>le&&(An=0,ms=In,In=Object.create(null),vn())):(Rt[q]=O^Nt,++Mn>Yt&&vn()),E)},Ws=w=>{let E=bn.get(w);if(E!==void 0)return E;const O=or(w,0,w.length),q=(O&16383)+On,de=Rt[q]===(O^Nt)||Rt[q^Yt]===(O^Nt-1);return de&&(E=gs.get(w),E!==void 0)?(bn.set(w,E),E):(E=Pn(w),de?(bn.set(w,E),++An>le&&(An=0,gs=bn,bn=new Map,vn())):(Rt[q]=O^Nt,++Mn>Yt&&vn()),E)},Gs=w=>{const E=or(w,0,w.length),O=(E&16383)+On;return Rt[O]===(E^Nt)||Rt[O^Yt]===(E^Nt-1)?!0:(Rt[O]=E^Nt,++Mn>Yt&&vn(),!1)},qn=le===0?Pn:Ad?w=>{const E=bn.get(w);return E!==void 0?E:Ws(w)}:Us;return{merge:function(){return arguments.length===1&&typeof arguments[0]=="string"?qn(arguments[0]):qn(Dd.apply(null,arguments))},mergeString:qn,seenBefore:le===0?()=>!1:Gs,mergeUncached:Pn}},fr=(e,t)=>{if(!e)return"";if(typeof e=="string")return e;let s="";if(typeof e.length=="number"&&(!t||Array.isArray(e))){const r=e;for(let o=0;o<r.length;o++){const a=r[o];if(!a)continue;const l=typeof a=="string"?a:fr(a,t);l&&(s&&(s+=" "),s+=l)}return s}if(t){if(typeof e=="number")return""+e;if(typeof e=="object")for(const r in e)e[r]&&(s&&(s+=" "),s+=r)}return s},$d=(e,t)=>{let s="";for(let r=0;r<e.length;r++){const o=e[r];if(!o)continue;const a=typeof o=="string"?o:fr(o,t);a&&(s&&(s+=" "),s+=a)}return s},Dd=function(){return $d(arguments,!1)},zd=256,Li=16,Fd=1024,so=4096,_d=(e,t)=>{const s=t===void 0?()=>!0:t.seenBefore,r=t===void 0?e:t.mergeUncached;let o=new Map,a=new Map,l=0,c=null,f=null,u=[],d=[],m=0;const k=(g,j,C)=>{f===null&&(f=new Array(so).fill(""),u=new Array(so).fill(""),d=new Array(so).fill(""));const h=or(g,0,g.length)&4094;if(f[h]===g&&u[h]===j)return d[h];if(f[h|1]===g&&u[h|1]===j)return d[h|1];const b=e(C?j+" "+g:g),N=f[h]===""?h:h|(f[h|1]===""?1:m++&1);return f[N]=g,u[N]=j,d[N]=b,b},v=(g,j,C,h)=>{let b=0;if(j){if(j!==g.a0)return!1;b=1}if(C){if(C!==(b===0?g.a0:g.a1))return!1;b++}if(h){if(h!==(b===0?g.a0:b===1?g.a1:g.a2))return!1;b++}return b===g.t},x=(g,j)=>{const C=g.a;let h=0;for(let b=0;b<j.length;b++){const N=j[b];if(N){if(N!==C[h])return!1;h++}}return h===g.t},y=(g,j)=>{const C=g.length,h=c===null?null:c.n;if(!j){if(h!==null&&x(h,g))return c=h,h.r;if(c!==null&&c!==h&&x(c,g))return c.r}let b="",N=-1,S=0,T=!1;for(let L=0;L<C;L++){let K=g[L];if(K){if(typeof K!="string"){if(K=g[L]=fr(K,!0),!K)continue;T=!0}N<0&&(b=K,N=L),S++}}if(S===0)return"";if(S===1)return e(b);if(T){if(h!==null&&x(h,g))return c=h,h.r;if(c!==null&&c!==h&&x(c,g))return c.r}let P=o.get(b);P===void 0&&(P=a.get(b),P!==void 0&&o.set(b,P));let B=null;if(P!==void 0){if(P.skip>0){P.skip--,c=null;let K=b;for(let A=N+1;A<C;A++){const z=g[A];z&&(K+=" "+z)}return k(K,"",!1)}const L=P.e;e:for(let K=0;K<L.length;K++){const A=L[K];if(A.t!==S)continue;const z=A.a;let M=1;for(let R=N+1;R<C;R++){const W=g[R];if(W&&W!==z[M++])continue e}B=A;break}B!==null&&(P.miss=0)}if(B===null){let L=b;const K=[b];for(let z=N+1;z<C;z++){const M=g[z];M&&(L+=" "+M,K.push(M))}if(!s(L))return r(L);B={r:e(L),t:K.length,a0:K[0],a1:K[1],a2:K[2]??"",a:K,n:null},P===void 0?o.set(b,P={e:[],miss:0,skip:0,at:0}):++P.miss>Li&&(P.miss=Li,P.skip=Fd,P.e.length=0,P.at=0);const A=P.e;A.length<zd?A.push(B):(A[P.at]=B,P.at=P.at+1&255),++l>1e3&&(l=0,a=o,o=new Map)}return c!==null&&c!==B&&(c.n=B),c=B,B.r},p=g=>Array.isArray(g)?y(g.slice(),!1):e(fr(g,!0));return function(g,j,C){const h=arguments.length;if((h|1)===3){const S=c;if(S!==null){const T=S.n;if(T!==null&&v(T,g,j,C))return c=T,T.r;if(S!==T&&v(S,g,j,C))return S.r}if(h===2&&typeof j=="string"&&j!==""){const T=o.get(g);if(T!==void 0&&T.skip>0)return T.skip--,c=null,k(j,g,!0)}return y([g,j,C],!0)}if(h===1)return typeof g=="string"?e(g):p(g);const b=c;if(b!==null){const S=b.n;if(S!==null){const T=S.a;let P=0,B=!0;for(let L=0;L<h;L++){const K=arguments[L];if(K){if(K!==T[P]){B=!1;break}P++}}if(B&&P===S.t)return c=S,S.r}if(b!==S){const T=b.a;let P=0,B=!0;for(let L=0;L<h;L++){const K=arguments[L];if(K){if(K!==T[P]){B=!1;break}P++}}if(B&&P===b.t)return b.r}}const N=[];for(let S=0;S<h;S++)N.push(arguments[S]);return y(N,!0)}},Bi=Md(Id),U=_d(Bi.mergeString,Bi),rn="—";function ir(e,t=Date.now()){if(e==null||!Number.isFinite(e))return rn;const s=Math.max(0,t-e);return s<5e3?"刚刚":s<6e4?`${Math.round(s/1e3)}s`:s<36e5?`${Math.floor(s/6e4)}m`:s<864e5?`${Math.floor(s/36e5)}h`:`${Math.floor(s/864e5)}d`}function Ts(e){if(e==null||!Number.isFinite(e)||e<0)return rn;if(e<1e3)return`${Math.round(e)}ms`;const t=e/1e3;return t<10?`${(Math.floor(t*10)/10).toFixed(1)}s`:t<60?`${Math.floor(t)}s`:`${Math.floor(t/60)}m ${String(Math.floor(t%60)).padStart(2,"0")}s`}function Go(e){if(e==null||!Number.isFinite(e))return rn;const t=new Date(e),s=r=>String(r).padStart(2,"0");return`${s(t.getHours())}:${s(t.getMinutes())}:${s(t.getSeconds())}`}function Vo(e){if(e==null||!Number.isFinite(e)||e===0)return rn;const t=new Date(e),s=r=>String(r).padStart(2,"0");return`${t.getFullYear()}-${s(t.getMonth()+1)}-${s(t.getDate())} ${s(t.getHours())}:${s(t.getMinutes())}`}function Cs(e){return e==null||!Number.isFinite(e)?rn:e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:e<1024*1024*1024?`${(e/1024/1024).toFixed(1)} MB`:`${(e/1024/1024/1024).toFixed(2)} GB`}function ts(e){return e==null||!Number.isFinite(e)?rn:e===0?"0":e<1e3?String(e):e<1e6?`${(e/1e3).toFixed(e<1e4?2:1)}k`:`${(e/1e6).toFixed(2)}M`}function Ld(e){return e==null||!Number.isFinite(e)?rn:e<1e3?`${Math.round(e)}ms`:`${(e/1e3).toFixed(2)}s`}function ro(e,t=48){if(!e)return rn;if(e.length<=t)return e;const s=Math.ceil((t-1)/2),r=Math.floor((t-1)/2);return`${e.slice(0,s)}…${e.slice(e.length-r)}`}function Bd(e){if(!e)return"/";const t=e.replace(/\/+$/,""),s=t.lastIndexOf("/");return s<=0?"/":t.slice(0,s)}function Hd(e,t=2){if(e===void 0)return"";if(typeof e=="string")try{return JSON.stringify(JSON.parse(e),null,t)}catch{return e}try{return JSON.stringify(e,null,t)}catch{return String(e)}}function ar(e){if(e==null||!Number.isFinite(e)||e<=0)return rn;if(e>=1e6){const t=e/1e6;return`${Number.isInteger(t)?t:t.toFixed(1)}M`}if(e>=1e3){const t=e/1e3;return`${Number.isInteger(t)?t:t.toFixed(1)}k`}return String(e)}const No={ok:"text-ok",warn:"text-warn",bad:"text-bad",peer:"text-peer",brand:"text-brand",muted:"text-muted-foreground",plain:"text-foreground"},Ud={ok:"bg-ok",warn:"bg-warn",bad:"bg-bad",peer:"bg-peer",brand:"bg-brand",muted:"bg-muted-foreground",plain:"bg-foreground"};function Wd(e,t,s){return!s||e===null?!1:t-e>s}function ss({tone:e,live:t=!1,size:s="md",className:r,title:o}){return n.jsx("span",{"aria-hidden":!0,title:o,className:U("inline-block shrink-0 rounded-full",s==="sm"?"size-1.5":"size-2",Ud[e],t&&"animate-live",e==="muted"&&"opacity-45",r)})}function Gd({status:e,lastEventAt:t,everyMs:s,label:r,className:o,compact:a=!1}){const l=il(),c=e==="open"&&Wd(t,l,s),f=e==="error"?"bad":e==="connecting"||c?"warn":"ok",u=e==="error"?"已断开 · 正在自动重连":e==="connecting"?"连接中":e==="idle"?"未连接":t===null?"已连接":c?`数据陈旧 · 最后更新 ${ir(t,l)}`:`最后更新 ${ir(t,l)}`,d=a&&e==="open"&&t!==null&&!c?ir(t,l):u;return n.jsxs("span",{className:U("inline-flex items-center gap-1.5 text-[10.5px] leading-none whitespace-nowrap",No[f],o),title:r?`${r} · ${u}`:u,children:[n.jsx(ss,{tone:f,size:"sm",live:e==="connecting"||e==="open"}),n.jsx("span",{className:"pg-num",children:d})]})}function wn({title:e,detail:t,tone:s="muted",icon:r,action:o,className:a}){return n.jsxs("div",{className:U("flex flex-col items-center justify-center gap-2 px-6 py-10 text-center",a),children:[r&&n.jsx("span",{className:U("mb-1 flex size-8 items-center justify-center opacity-70",No[s]),children:r}),n.jsx("p",{className:U("text-[12.5px] font-medium",No[s]),children:e}),t&&n.jsx("p",{className:"text-muted-foreground max-w-[38ch] text-[11px] leading-relaxed",children:t}),o&&n.jsx("div",{className:"mt-2",children:o})]})}const Ko={...ou},Hi={};function Ht(e,t){const s=i.useRef(Hi);return s.current===Hi&&(s.current=e(t)),s}const oo=Ko.useInsertionEffect,Vd=oo&&oo!==Ko.useLayoutEffect?oo:e=>e();function ye(e){const t=Ht(Kd).current;return t.next=e,Vd(t.effect),t.trampoline}function Kd(){const e={next:void 0,callback:qd,trampoline:(...t)=>e.callback?.(...t),effect:()=>{e.callback=e.next}};return e}function qd(){}const Yd=()=>{},pe=typeof document<"u"?i.useLayoutEffect:Yd;function Eo(e,t){if(e&&!t)return e;if(!e&&t)return t;if(e||t)return{...e,...t}}const pl={};function Cr(e,t,s,r,o){if(!s&&!r&&!e)return pr(t);let a=pr(e);return t&&(a=lr(a,t)),s&&(a=lr(a,s)),r&&(a=lr(a,r)),a}function Xd(e){if(e.length===0)return pl;if(e.length===1)return pr(e[0]);let t=pr(e[0]);for(let s=1;s<e.length;s+=1)t=lr(t,e[s]);return t}function pr(e){return gl(e)?{...e(pl)}:Jd(e)}function lr(e,t){return gl(t)?t(e):Zd(e,t)}function Jd(e){const t={...e};for(const s in t){const r=t[s];ml(s,r)&&(t[s]=xl(r))}return t}function Zd(e,t){if(!t)return e;for(const s in t){const r=t[s];switch(s){case"style":{e[s]=Eo(e.style,r);break}case"className":{e[s]=hl(e.className,r);break}default:ml(s,r)?e[s]=Qd(e[s],r):e[s]=r}}return e}function ml(e,t){const s=e.charCodeAt(0),r=e.charCodeAt(1),o=e.charCodeAt(2);return s===111&&r===110&&o>=65&&o<=90&&(typeof t=="function"||typeof t>"u")}function gl(e){return typeof e=="function"}function Qd(e,t){return t?e?(...s)=>{const r=s[0];if(bl(r)){const a=r;mr(a);const l=t(...s);return a.baseUIHandlerPrevented||e?.(...s),l}const o=t(...s);return e?.(...s),o}:xl(t):e}function xl(e){return e&&((...t)=>{const s=t[0];return bl(s)&&mr(s),e(...t)})}function mr(e){return e.preventBaseUIHandler=()=>{e.baseUIHandlerPrevented=!0},e}function hl(e,t){return t?e?t+" "+e:t:e}function bl(e){return e!=null&&typeof e=="object"&&"nativeEvent"in e}function ef(e,t){return function(r,...o){const a=new URL(e);return a.searchParams.set("code",r.toString()),o.forEach(l=>a.searchParams.append("args[]",l)),`${t} error #${r}; visit ${a} for the full message.`}}const Mt=ef("https://base-ui.com/production-error","Base UI"),tf=i.createContext(void 0);function nf(e=!1){const t=i.useContext(tf);if(t===void 0&&!e)throw new Error(Mt(16));return t}function sf(e){const{focusableWhenDisabled:t,disabled:s,composite:r=!1,tabIndex:o=0,isNativeButton:a}=e,l=r&&t!==!1,c=r&&t===!1;return{props:i.useMemo(()=>{const u={onKeyDown(d){s&&t&&d.key!=="Tab"&&d.preventDefault()}};return r||(u.tabIndex=o,!a&&s&&(u.tabIndex=t?o:-1)),(a&&(t||l)||!a&&s)&&(u["aria-disabled"]=s),a&&(!t||c)&&(u.disabled=s),u},[r,s,t,l,c,a,o])}}function We(e){return e?.ownerDocument||document}function io(e,t,{detail:s=0,pointerType:r=""}={}){e.dispatchEvent(new(xn(e)).PointerEvent("click",{bubbles:!0,cancelable:!0,composed:!0,detail:s,pointerType:r,shiftKey:t.shiftKey,ctrlKey:t.ctrlKey,altKey:t.altKey,metaKey:t.metaKey}))}function Sr(e={}){const{disabled:t=!1,focusableWhenDisabled:s,tabIndex:r=0,native:o=!0,composite:a}=e,l=i.useRef(null),c=nf(!0),f=a??c!==void 0,{props:u}=sf({focusableWhenDisabled:s,disabled:t,composite:f,tabIndex:r,isNativeButton:o}),d=i.useCallback(()=>{const v=l.current;ao(v)&&f&&t&&u.disabled===void 0&&v.disabled&&(v.disabled=!1)},[t,u.disabled,f]);pe(d,[d]);const m=i.useCallback((v={})=>{const{onClick:x,onMouseDown:y,onKeyUp:p,onKeyDown:g,onPointerDown:j,...C}=v;return Cr({onClick(h){if(t){h.preventDefault();return}x?.(h)},onMouseDown(h){t||y?.(h)},onKeyDown(h){if(t||(mr(h),g?.(h),h.baseUIHandlerPrevented))return;const b=h.target===h.currentTarget,N=h.currentTarget,S=ao(N),T=!o&&rf(N),P=b&&(o?S:!T),B=h.key==="Enter",L=h.key===" ",K=N.getAttribute("role"),A=K?.startsWith("menuitem")||K==="option"||K==="gridcell";if(b&&f&&L){if(h.defaultPrevented&&A)return;h.preventDefault(),(!o||S)&&(h.preventBaseUIHandler(),io(N,h));return}if(!P||o||!L&&!B){b&&T&&L&&h.preventDefault();return}h.defaultPrevented||(h.preventDefault(),B&&(h.preventBaseUIHandler(),io(N,h)))},onKeyUp(h){if(!t){if(mr(h),p?.(h),h.target===h.currentTarget&&o&&f&&ao(h.currentTarget)&&h.key===" "){h.preventDefault();return}h.baseUIHandlerPrevented||h.target===h.currentTarget&&!o&&!f&&!h.defaultPrevented&&h.key===" "&&(h.preventBaseUIHandler(),io(h.currentTarget,h))}},onPointerDown(h){if(t){h.preventDefault();return}j?.(h)}},o?{type:"button"}:{role:"button"},u,C)},[t,u,f,o]),k=ye(v=>{l.current=v,d()});return{getButtonProps:m,buttonRef:k}}function ao(e){return xt(e)&&e.tagName==="BUTTON"}function rf(e){return xt(e)&&e.tagName==="A"&&!!e.href}function Rs(e,t,s,r){const o=Ht(vl).current;return af(o,e,t,s,r)&&yl(o,[e,t,s,r]),o.callback}function of(e){const t=Ht(vl).current;return lf(t,e)&&yl(t,e),t.callback}function vl(){return{callback:null,cleanup:null,refs:[]}}function af(e,t,s,r,o){return e.refs[0]!==t||e.refs[1]!==s||e.refs[2]!==r||e.refs[3]!==o}function lf(e,t){return e.refs.length!==t.length||e.refs.some((s,r)=>s!==t[r])}function yl(e,t){if(e.refs=t,t.every(s=>s==null)){e.callback=null;return}e.callback=s=>{if(e.cleanup&&(e.cleanup(),e.cleanup=null),s!=null){const r=Array(t.length).fill(null);for(let o=0;o<t.length;o+=1){const a=t[o];if(a!=null)switch(typeof a){case"function":{const l=a(s);typeof l=="function"&&(r[o]=l);break}case"object":{a.current=s;break}}}e.cleanup=()=>{for(let o=0;o<t.length;o+=1){const a=t[o];if(a!=null)switch(typeof a){case"function":{const l=r[o];typeof l=="function"?l():a(null);break}case"object":{a.current=null;break}}}}}}}const cf=parseInt(i.version,10);function qo(e){return cf>=e}function Ui(e){if(!i.isValidElement(e))return null;const t=e,s=t.props;return(qo(19)?s?.ref:t.ref)??null}function Nr(){}const uf=Object.freeze([]),bt=Object.freeze({});function df(e,t){const s={};for(const r in e){const o=e[r];if(t?.hasOwnProperty(r)){const a=t[r](o);a!=null&&Object.assign(s,a);continue}o===!0?s[`data-${r.toLowerCase()}`]="":o&&(s[`data-${r.toLowerCase()}`]=o.toString())}return s}function ff(e,t){return typeof e=="function"?e(t):e}function kl(e,t){return typeof e=="function"?e(t):e}function yt(e,t,s={}){let r=t.render;s.enabled!==!1&&(r=xf(r));const o=pf(t,s,r);if(s.enabled===!1)return null;const a=s.state??bt;return hf(e,r,o,a)}function pf(e,t,s){const{className:r,style:o}=e,{state:a=bt,ref:l,props:c,stateAttributesMapping:f,enabled:u=!0}=t,d=u?ff(r,a):void 0,m=u?kl(o,a):void 0,k=u?df(a,f):bt,v=u&&c?mf(c):void 0,x=u?Eo(k,v)??{}:bt;return typeof document<"u"&&(u?Array.isArray(l)?x.ref=of([x.ref,Ui(s),...l]):x.ref=Rs(x.ref,Ui(s),l):Rs(null,null)),u?(d!==void 0&&(x.className=hl(x.className,d)),m!==void 0&&(x.style=Eo(x.style,m)),x):bt}function mf(e){return Array.isArray(e)?Xd(e):Cr(void 0,e)}const gf=Symbol.for("react.lazy");function xf(e){if(e?.$$typeof!==gf)return e;const t=i.Children.toArray(e)[0];return i.isValidElement(t)?t:e}function hf(e,t,s,r){if(t){if(typeof t=="function")return t(s,r);const o=Cr(s,t.props);return o.ref=s.ref,i.cloneElement(t,o)}return bf(e,s)}function bf(e,t){return e==="button"?i.createElement("button",{type:"button",...t,key:t.key}):e==="img"?i.createElement("img",{alt:"",...t,key:t.key}):i.createElement(e,t)}const vf=i.forwardRef(function(t,s){const{render:r,className:o,disabled:a=!1,focusableWhenDisabled:l=!1,nativeButton:c=!0,style:f,...u}=t,{getButtonProps:d,buttonRef:m}=Sr({disabled:a,focusableWhenDisabled:l,native:c});return yt("button",t,{state:{disabled:a},ref:[s,m],props:[u,d]})});function jl(e){var t,s,r="";if(typeof e=="string"||typeof e=="number")r+=e;else if(typeof e=="object")if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(s=jl(e[t]))&&(r&&(r+=" "),r+=s)}else for(s in e)e[s]&&(r&&(r+=" "),r+=s);return r}function yf(){for(var e,t,s=0,r="",o=arguments.length;s<o;s++)(e=arguments[s])&&(t=jl(e))&&(r&&(r+=" "),r+=t);return r}const Wi=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,Gi=yf,wl=(e,t)=>s=>{var r;if(t?.variants==null)return Gi(e,s?.class,s?.className);const{variants:o,defaultVariants:a}=t,l=Object.keys(o).map(u=>{const d=s?.[u],m=a?.[u];if(d===null)return null;const k=Wi(d)||Wi(m);return o[u][k]}),c=s&&Object.entries(s).reduce((u,d)=>{let[m,k]=d;return k===void 0||(u[m]=k),u},{}),f=t==null||(r=t.compoundVariants)===null||r===void 0?void 0:r.reduce((u,d)=>{let{class:m,className:k,...v}=d;return Object.entries(v).every(x=>{let[y,p]=x;return Array.isArray(p)?p.includes({...a,...c}[y]):{...a,...c}[y]===p})?[...u,m,k]:u},[]);return Gi(e,l,f,s?.class,s?.className)},kf=wl("group/button inline-flex shrink-0 items-center justify-center rounded-lg border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/80",outline:"border-border bg-background hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50",secondary:"bg-secondary text-secondary-foreground hover:bg-[color-mix(in_oklch,var(--secondary),var(--foreground)_5%)] aria-expanded:bg-secondary aria-expanded:text-secondary-foreground",ghost:"hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50",destructive:"bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-8 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",xs:"h-6 gap-1 rounded-[min(var(--radius-md),10px)] px-2 text-xs in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3",sm:"h-7 gap-1 rounded-[min(var(--radius-md),12px)] px-2.5 text-[0.8rem] in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5",lg:"h-9 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",icon:"size-8","icon-xs":"size-6 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-lg [&_svg:not([class*='size-'])]:size-3","icon-sm":"size-7 rounded-[min(var(--radius-md),12px)] in-data-[slot=button-group]:rounded-lg","icon-lg":"size-9"}},defaultVariants:{variant:"default",size:"default"}});function ke({className:e,variant:t="default",size:s="default",...r}){return n.jsx(vf,{"data-slot":"button",className:U(kf({variant:t,size:s,className:e})),...r})}const Cl=i.createContext(void 0);function Hn(e){const t=i.useContext(Cl);if(!e&&t===void 0)throw new Error(Mt(27));return t}const Yo="data-starting-style",jf="data-ending-style",wf={[Yo]:""},Cf={[jf]:""},Er={transitionStatus(e){return e==="starting"?wf:e==="ending"?Cf:null}},Sf="data-open",Nf="data-closed",Ef="data-anchor-hidden",Sl="data-popup-open",Tf="data-pressed",Rf={[Sl]:""},Pf={[Sl]:"",[Tf]:""},Of={[Sf]:""},If={[Nf]:""},Af={[Ef]:""},Nl={open(e){return e?Rf:null}},Mf={open(e){return e?Pf:null}},Tr={open(e){return e?Of:If},anchorHidden(e){return e?Af:null}},Xo={...Tr,...Er},$f=i.forwardRef(function(t,s){const{render:r,className:o,style:a,forceRender:l=!1,...c}=t,f=Hn(),u=f.useState("open"),d=f.useState("nested"),m=f.useState("mounted"),k=f.useState("transitionStatus");return yt("div",t,{state:{open:u,transitionStatus:k},ref:[f.context.backdropRef,s],stateAttributesMapping:Xo,props:[{role:"presentation",hidden:!m,style:{userSelect:"none",WebkitUserSelect:"none"}},c],enabled:l||!d})});function Fe(e,t,s,r){let o=!1,a=!1;const l=bt;return{reason:e,event:t??new Event("base-ui"),cancel(){o=!0},allowPropagation(){a=!0},get isCanceled(){return o},get isPropagationAllowed(){return a},trigger:s,...l}}const Rr="none",mn="trigger-press",ut="trigger-hover",cr="trigger-focus",El="outside-press",Tl="close-press",Ps="focus-out",Pr="escape-key",Df="disabled",Jo="imperative-action",Rl=i.forwardRef(function(t,s){const{render:r,className:o,style:a,disabled:l=!1,nativeButton:c=!0,...f}=t,u=Hn(),d=u.useState("open"),{getButtonProps:m,buttonRef:k}=Sr({disabled:l,native:c}),v={disabled:l};function x(y){d&&u.setOpen(!1,Fe(Tl,y.nativeEvent))}return yt("button",t,{state:v,ref:[s,k],props:[{onClick:x},f,m]})});function Pl(){const[,e]=i.useState({});return i.useCallback(()=>{e({})},[])}let Vi=0;function zf(e,t="mui"){const s=i.useRef(void 0),r=Pl(),o=e??s.current;return i.useEffect(()=>{s.current==null&&(Vi+=1,s.current=`${t}-${Vi}`,e==null&&r())},[e,t,r]),o}const Ki=Ko.useId;function Or(e,t){if(Ki!==void 0){const s=Ki();return e??(t?`${t}-${s}`:s)}return zf(e,t)}function _s(e){return Or(e,"base-ui")}const Ff=i.forwardRef(function(t,s){const{render:r,className:o,style:a,id:l,...c}=t,f=Hn(),u=_s(l);return f.useSyncedValueWithCleanup("descriptionElementId",u),yt("p",t,{ref:s,props:[{id:u},c]})});function Zo(e){i.useEffect(e,uf)}const bs=0;class At{static create(){return new At}currentId=bs;start(t,s){this.clear(),this.currentId=setTimeout(()=>{this.currentId=bs,s()},t)}isStarted(){return this.currentId!==bs}clear=()=>{this.currentId!==bs&&(clearTimeout(this.currentId),this.currentId=bs)};disposeEffect=()=>this.clear}function tn(){const e=Ht(At.create).current;return Zo(e.disposeEffect),e}function _f(){return typeof navigator>"u"?{userAgent:"",platform:"",maxTouchPoints:0}:{userAgent:navigator.userAgent,platform:navigator.platform??"",maxTouchPoints:navigator.maxTouchPoints??0}}const{userAgent:Lf,platform:Bf,maxTouchPoints:Hf}=_f(),Ir=Lf.toLowerCase(),Os=Bf.toLowerCase(),Ar=/^i(os$|p)/.test(Os)||Os==="macintel"&&Hf>1,qi="android",To=Os===qi||Ir.includes(qi),Ol=!Ar&&Os.startsWith("mac");Os.startsWith("win");const Uf=Ol||Ar,Un=typeof CSS<"u"&&!!CSS.supports?.("-webkit-backdrop-filter:none");!Un&&Ir.includes("firefox");!Un&&Ir.includes("chrom");const Wf=Uf,Il=/jsdom|happydom/.test(Ir);function Gf(e){e.preventDefault(),e.stopPropagation()}function Vf(e){return"nativeEvent"in e}function gr(e){return e.pointerType===""&&e.isTrusted?!0:To&&e.pointerType?e.type==="click"&&e.buttons===1:e.detail===0&&!e.pointerType}function Al(e){return Il?!1:!To&&e.width===0&&e.height===0||e.type==="pointerdown"&&e.width===1&&e.height===1&&e.pressure===0&&e.detail===0&&e.pointerType==="mouse"&&(To||e.buttons===0)||e.width<1&&e.height<1&&e.pressure===0&&e.detail===0&&e.pointerType==="touch"}function Cn(e,t){const s=["mouse","pen"];return t||s.push("",void 0),s.includes(e)}function Kf(e){const t=e.type;return t==="click"||t==="mousedown"||t==="keydown"||t==="keyup"}function _t(e){let t=e.activeElement;for(;t?.shadowRoot?.activeElement!=null;)t=t.shadowRoot.activeElement;return t}function be(e,t){if(!e||!t)return!1;const s=t.getRootNode?.();if(e.contains(t))return!0;if(s&&$s(s)){let r=t;for(;r;){if(e===r)return!0;r=r.parentNode||r.host}}return!1}function Is(e,t){let s=e;for(;s;){if(Ze(s)&&s.matches(t))return s;s=s.assignedSlot??s.parentNode??($s(s)?s.host:null)}return null}function kt(e){return"composedPath"in e?e.composedPath()[0]??e.target:e.target}const Ro="data-base-ui-focusable",Ml="input:not([type='hidden']):not([disabled]),[contenteditable]:not([contenteditable='false']),textarea:not([disabled])",Po="data-trigger-disabled";function xr(e,t){if(!Ze(e))return!1;const s=e;if(t.hasElement(s))return!s.hasAttribute(Po);for(const[,r]of t.entries())if(be(r,s))return!r.hasAttribute(Po);return!1}function lo(e,t){if(t==null)return!1;if("composedPath"in e)return e.composedPath().includes(t);const s=e;return s.target!=null&&t.contains(s.target)}function qf(e){return e.matches("html,body")}function Mr(e){return xt(e)&&e.matches(Ml)}function Yf(e){return Is(e,`button,a[href],[role="button"],select,[tabindex]:not([tabindex="-1"]),${Ml}`)!=null}function Yi(e){return e?e.getAttribute("role")==="combobox"&&Mr(e):!1}function Xf(e){if(!e||Il)return!0;try{return e.matches(":focus-visible")}catch{return!0}}function Xi(e){return e?e.hasAttribute(Ro)?e:e.querySelector(`[${Ro}]`)||e:null}function Jf(e,t){return t!=null&&!Cn(t)?0:typeof e=="function"?e():e}function Bn(e,t,s){const r=Jf(e,s);return typeof r=="number"?r:r?.[t]}function Ji(e){return typeof e=="function"?e():e}function $l(e,t){return t||e==="click"||e==="mousedown"}function Zf(e){return e?.includes("mouse")&&e!=="mousedown"}const Dl=i.createContext({hasProvider:!1,timeoutMs:0,delayRef:{current:0},initialDelayRef:{current:0},timeout:new At,currentIdRef:{current:null},currentContextRef:{current:null}});function Qf(e,t){e.current=t.current}function ep(e){const{children:t,delay:s,timeoutMs:r=0}=e,o=i.useRef(s),a=i.useRef(s),l=i.useRef(null),c=i.useRef(null),f=tn();return pe(()=>{if(a.current=s,!l.current){o.current=s;return}o.current={open:Bn(o.current,"open"),close:Bn(s,"close")}},[s,l,o,a]),n.jsx(Dl.Provider,{value:i.useMemo(()=>({hasProvider:!0,delayRef:o,initialDelayRef:a,currentIdRef:l,timeoutMs:r,currentContextRef:c,timeout:f}),[r,f]),children:t})}function tp(e,t={open:!1}){const{open:s}=t,r=e.useState("floatingId"),o=i.useContext(Dl),{currentIdRef:a,delayRef:l,timeoutMs:c,initialDelayRef:f,currentContextRef:u,hasProvider:d,timeout:m}=o,[k,v]=i.useState(!1),x=i.useRef(s);return pe(()=>{x.current=s},[s]),pe(()=>{function y(){u.current?.setIsInstantPhase(!1),a.current=null,u.current=null,l.current=f.current,m.clear()}if(a.current&&!s&&a.current===r){if(v(!1),c){const p=r;return m.start(c,()=>{e.select("open")||a.current&&a.current!==p||y()}),()=>{(x.current||a.current!==p)&&m.clear()}}y()}},[s,r,a,l,c,f,u,m,e]),pe(()=>{if(!s)return;const y=u.current,p=a.current;m.clear(),u.current={onOpenChange:e.setOpen,setIsInstantPhase:v},a.current=r,l.current={open:0,close:Bn(f.current,"close")},p!==null&&p!==r?(v(!0),y?.setIsInstantPhase(!0),y?.onOpenChange(!1,Fe(Rr))):(v(!1),y?.setIsInstantPhase(!1))},[s,r,e,a,l,f,u,m]),pe(()=>()=>{if(a.current===r){if(u.current=null,!x.current)return;a.current=null,Qf(l,f),m.clear()}},[u,a,l,r,f,m]),i.useMemo(()=>({activeIdRef:a,hasProvider:d,delayRef:l,isInstantPhase:k}),[a,d,l,k])}function Te(e,t,s,r){return e.addEventListener(t,s,r),()=>{e.removeEventListener(t,s,r)}}function nn(...e){return()=>{for(let t=0;t<e.length;t+=1){const s=e[t];s&&s()}}}function dt(e){const t=Ht(np,e).current;return t.next=e,pe(t.effect),t}function np(e){const t={current:e,next:e,effect:()=>{t.current=t.next}};return t}const Ys=null;class sp{callbacks=[];callbacksCount=0;nextId=1;startId=1;isScheduled=!1;tick=t=>{this.isScheduled=!1;const s=this.callbacks,r=this.callbacksCount;if(this.callbacks=[],this.callbacksCount=0,this.startId=this.nextId,r>0)for(let o=0;o<s.length;o+=1)s[o]?.(t)};request(t){const s=this.nextId;return this.nextId+=1,this.callbacks.push(t),this.callbacksCount+=1,(!this.isScheduled||!1)&&(requestAnimationFrame(this.tick),this.isScheduled=!0),s}cancel(t){const s=t-this.startId;s<0||s>=this.callbacks.length||this.callbacks[s]!==null&&(this.callbacks[s]=null,this.callbacksCount-=1)}}let Xs=new sp;class ht{static create(){return new ht}static request(t){return Xs.request(t)}static cancel(t){return Xs.cancel(t)}currentId=Ys;request(t){this.cancel(),this.currentId=Xs.request(()=>{this.currentId=Ys,t()})}cancel=()=>{this.currentId!==Ys&&(Xs.cancel(this.currentId),this.currentId=Ys)};disposeEffect=()=>this.cancel}function Qo(){const e=Ht(ht.create).current;return Zo(e.disposeEffect),e}const rp={clipPath:"inset(50%)",overflow:"hidden",whiteSpace:"nowrap",border:0,padding:0,width:1,height:1,margin:-1},op={...rp,position:"fixed",margin:0,top:0,left:0},as=i.forwardRef(function(t,s){const[r,o]=i.useState();pe(()=>{Wf&&Un&&o("button")},[]);const a={tabIndex:0,role:r};return n.jsx("span",{...t,ref:s,style:op,"aria-hidden":r?void 0:!0,...a,"data-base-ui-focus-guard":""})});function ip(e){return e.visibility==="hidden"||e.visibility==="collapse"}function zl(e,t=e?Fo(e):null){return!e||!e.isConnected||!t||ip(t)?!1:typeof e.checkVisibility=="function"?e.checkVisibility():t.display!=="none"&&t.display!=="contents"}const ap='a[href],button,input,select,textarea,summary,details,iframe,object,embed,[tabindex],[contenteditable]:not([contenteditable="false"]),audio[controls],video[controls]';function lp(e){const t=e.assignedSlot;if(t)return t;if(e.parentElement)return e.parentElement;const s=e.getRootNode();return $s(s)?s.host:null}function Oo(e){for(const t of Array.from(e.children))if(Bt(t)==="summary")return t;return null}function cp(e,t){const s=Oo(t);return!!s&&(e===s||be(s,e))}function Fl(e){const t=e?Bt(e):"";return e!=null&&e.matches(ap)&&(t!=="summary"||e.parentElement!=null&&Bt(e.parentElement)==="details"&&Oo(e.parentElement)===e)&&(t!=="details"||Oo(e)==null)&&(t!=="input"||e.type!=="hidden")}function ei(e){if(!Fl(e)||!e.isConnected||e.matches(":disabled"))return!1;for(let t=e;t;t=lp(t)){const s=t!==e,r=Bt(t)==="slot";if(t.hasAttribute("inert")||s&&Bt(t)==="details"&&!t.open&&!cp(e,t)||t.hasAttribute("hidden")||!r&&!up(t,s))return!1}return!0}function up(e,t){const s=Fo(e);return t?s.display!=="none":zl(e,s)}function _l(e){const t=e.tabIndex;if(t<0){const s=Bt(e);if(s==="details"||s==="audio"||s==="video"||xt(e)&&e.isContentEditable)return 0}return t}function co(e){if(Bt(e)!=="input")return null;const t=e;return t.type==="radio"&&t.name!==""?t:null}function Ll(e,t){const s=co(e);if(!s)return!0;const r=t.find(o=>{const a=co(o);return a?.name===s.name&&a.form===s.form&&a.checked});return r?r===s:t.find(o=>{const a=co(o);return a?.name===s.name&&a.form===s.form})===s}function Bl(e){if(xt(e)&&Bt(e)==="slot"){const t=e.assignedElements({flatten:!0});if(t.length>0)return t}return xt(e)&&e.shadowRoot?Array.from(e.shadowRoot.children):Array.from(e.children)}function ti(e,t){Bl(e).forEach(s=>{Fl(s)&&t.push(s),ti(s,t)})}function Hl(e,t,s){Bl(e).forEach(r=>{xt(r)&&r.matches(t)&&s.push(r),Hl(r,t,s)})}function $r(e){return ei(e)&&_l(e)>=0}function Ul(e){const t=[];return ti(e,t),t.filter(ei)}function Dr(e){const t=Ul(e);return t.filter(s=>_l(s)>=0&&Ll(s,t))}function Wl(e,t){const s=Dr(e),r=s.length;if(r===0)return;const o=_t(We(e)),a=s.indexOf(o),l=a===-1?t===1?0:r-1:a+t;return s[l]}function Gl(e){return Wl(We(e).body,1)||e}function Vl(e){return Wl(We(e).body,-1)||e}function dp(e,t,s){if(!e)return null;const r=[];ti(We(e).body,r);const o=r.indexOf(e);if(o===-1)return null;const a=r.filter(ei);for(let l=1;l<r.length;l+=1){const c=r[(o+t*l+r.length)%r.length];if(!be(s,c)&&$r(c)&&Ll(c,a))return c}return r[o]}function rs(e,t){const s=t||e.currentTarget,r=e.relatedTarget;return!r||!be(s,r)}function fp(e){Dr(e).forEach(s=>{s.dataset.tabindex=s.getAttribute("tabindex")||"",s.setAttribute("tabindex","-1")})}function Zi(e){const t=[];Hl(e,"[data-tabindex]",t),t.forEach(s=>{const r=s.dataset.tabindex;delete s.dataset.tabindex,r?s.setAttribute("tabindex",r):s.removeAttribute("tabindex")})}function En(e,t,s=!0){return e.filter(o=>o.parentId===t).flatMap(o=>[...!s||o.context?.open?[o]:[],...En(e,o.id,s)])}function Qi(e,t){let s=[],r=e.find(o=>o.id===t)?.parentId;for(;r;){const o=e.find(a=>a.id===r);r=o?.parentId,o&&(s=s.concat(o))}return s}function os(e){return`data-base-ui-${e}`}let Js=0;function uo(e,t={}){const{preventScroll:s=!1,sync:r=!1,shouldFocus:o}=t;cancelAnimationFrame(Js);function a(){o&&!o()||e?.focus({preventScroll:s})}if(r)return a(),Nr;const l=requestAnimationFrame(a);return Js=l,()=>{Js===l&&(cancelAnimationFrame(l),Js=0)}}const ea="data-base-ui-inert";let vs=new WeakMap,Zs=new WeakSet,ys=new WeakMap,fo=0;function Kl(e){return e?$s(e)?e.host:Kl(e.parentNode):null}const ta=(e,t)=>t.map(s=>{if(e.contains(s))return s;const r=Kl(s);return e.contains(r)?r:null}).filter(s=>s!=null),na=e=>{const t=new Set;return e.forEach(s=>{let r=s;for(;r&&!t.has(r);)t.add(r),r=r.parentNode}),t},sa=(e,t,s)=>{const r=[],o=a=>{!a||s.has(a)||Array.from(a.children).forEach(l=>{Bt(l)!=="script"&&(t.has(l)?o(l):r.push(l))})};return o(e),r};function pp(e,t,s,{mark:r=!0}){const o=ta(t,e),a=r?sa(t,na(o),new Set(o)):[],l=[],c=[];if(s){const f=ta(t,Array.from(t.querySelectorAll("[aria-live]"))),u=o.concat(f);sa(t,na(u),new Set(u)).forEach(m=>{const k=m.getAttribute("aria-hidden"),v=k!==null&&k!=="false",x=(vs.get(m)||0)+1;vs.set(m,x),l.push(m),x===1&&v&&Zs.add(m),v||m.setAttribute("aria-hidden","true")})}return r&&a.forEach(f=>{const u=(ys.get(f)||0)+1;ys.set(f,u),c.push(f),u===1&&f.setAttribute(ea,"")}),fo+=1,()=>{l.forEach(f=>{const u=(vs.get(f)||0)-1;vs.set(f,u),u||(Zs.has(f)||f.removeAttribute("aria-hidden"),Zs.delete(f))}),r&&c.forEach(f=>{const u=(ys.get(f)||0)-1;ys.set(f,u),u||f.removeAttribute(ea)}),fo-=1,fo||(vs=new WeakMap,Zs=new WeakSet,ys=new WeakMap)}}function ra(e,t={}){const{ariaHidden:s=!1,mark:r=!0}=t,o=We(e[0]).body;return pp(e,o,s,{mark:r})}const mp=500,gp={style:{transition:"none"}},ql="data-base-ui-click-trigger",Yl={fallbackAxisSide:"end"},xp={clipPath:"inset(50%)",position:"fixed",top:0,left:0},Xl=i.createContext(null),Jl=()=>i.useContext(Xl),hp=os("portal");function Zl(e={}){const{ref:t,container:s,componentProps:r=bt,elementProps:o}=e,a=Or(),c=Jl()?.portalNode,[f,u]=i.useState(null),[d,m]=i.useState(null),k=ye(p=>{p!==null&&m(p)}),v=i.useRef(null);pe(()=>{if(s===null){v.current&&(v.current=null,m(null),u(null));return}const p=(s&&(au(s)?s:s.current))??c??document.body;if(p==null){v.current&&(v.current=null,m(null),u(null));return}v.current!==p&&(v.current=p,m(null),u(p))},[s,c]);const x=yt("div",r,{ref:[t,k],props:[{id:a,[hp]:""},o]}),y=f&&x?gn.createPortal(x,f):null;return{node:d,nodeId:i.isValidElement(x)?x.props.id:void 0,subtree:y}}const Ql=i.forwardRef(function(t,s){const{render:r,className:o,style:a,children:l,container:c,portalOwnerRole:f,...u}=t,{node:d,nodeId:m,subtree:k}=Zl({container:c,ref:s,componentProps:t,elementProps:u}),v=i.useRef(null),x=i.useRef(null),y=i.useRef(null),p=i.useRef(null),[g,j]=i.useState(null),C=i.useRef(!1),h=g?.modal,b=g?.open,N=!!g&&!g.modal&&g.open&&!!d;i.useEffect(()=>{if(!d||h)return;function T(P){d&&P.relatedTarget&&rs(P)&&(P.type==="focusin"?C.current&&(Zi(d),C.current=!1):(fp(d),C.current=!0))}return nn(Te(d,"focusin",T,!0),Te(d,"focusout",T,!0))},[d,h]),pe(()=>{!d||b!==!0||!C.current||(Zi(d),C.current=!1)},[b,d]);const S=i.useMemo(()=>({beforeOutsideRef:v,afterOutsideRef:x,beforeInsideRef:y,afterInsideRef:p,portalNode:d,setFocusManagerState:j}),[d]);return n.jsxs(i.Fragment,{children:[k,n.jsxs(Xl.Provider,{value:S,children:[N&&d&&n.jsx(as,{"data-type":"outside",ref:v,onFocus:T=>{if(rs(T,d))y.current?.focus();else{const P=g?g.domReference:null;Vl(P)?.focus()}}}),N&&d&&n.jsx("span",{role:f,"aria-owns":m,style:xp}),d&&gn.createPortal(l,d),N&&d&&n.jsx(as,{"data-type":"outside",ref:x,onFocus:T=>{if(rs(T,d))p.current?.focus();else{const P=g?g.domReference:null;Gl(P)?.focus(),g?.closeOnFocusOut&&g?.onOpenChange(!1,Fe(Ps,T.nativeEvent))}}})]})]})});function ec(){const e=new Map;return{emit(t,s){e.get(t)?.forEach(r=>r(s))},on(t,s){e.has(t)||e.set(t,new Set),e.get(t).add(s)},off(t,s){e.get(t)?.delete(s)}}}class bp{nodesRef={current:[]};events=ec();addNode(t){this.nodesRef.current.push(t)}removeNode(t){const s=this.nodesRef.current.findIndex(r=>r===t);s!==-1&&this.nodesRef.current.splice(s,1)}}const tc=i.createContext(null),nc=i.createContext(null),zr=()=>i.useContext(tc)?.id||null,ds=e=>{const t=i.useContext(nc);return e??t};function vp(e){const t=Or(),s=ds(e),r=zr();return pe(()=>{if(!t)return;const o={id:t,parentId:r};return s?.addNode(o),()=>{s?.removeNode(o)}},[s,t,r]),t}function yp(e){const{children:t,id:s}=e,r=zr();return n.jsx(tc.Provider,{value:i.useMemo(()=>({id:s,parentId:r}),[s,r]),children:t})}function kp(e){const{children:t,externalTree:s}=e,r=Ht(()=>s??new bp).current;return n.jsx(nc.Provider,{value:r,children:t})}function dn(e){return e==null?e:"current"in e?e.current:e}function jp(e,t){const s=xn(kt(e));return e instanceof s.KeyboardEvent?"keyboard":e instanceof s.FocusEvent?t||"keyboard":"pointerType"in e?e.pointerType||(gr(e)?"keyboard":t||"mouse"):"touches"in e?"touch":e instanceof s.MouseEvent?t||(e.detail===0?"keyboard":"mouse"):""}const oa=20;let jn=[];function ni(){jn=jn.filter(e=>e.deref()?.isConnected)}function ia(e){ni(),e&&Bt(e)!=="body"&&(jn.push(new WeakRef(e)),jn.length>oa&&(jn=jn.slice(-oa)))}function aa(){return ni(),jn[jn.length-1]?.deref()}function wp(e){return e?$r(e)?e:Dr(e)[0]||e:null}function la(e){if(e.hasAttribute("tabindex")&&!e.hasAttribute("data-tabindex")||!e.getAttribute("role")?.includes("dialog"))return;const s=Ul(e).filter(o=>{const a=o.getAttribute("data-tabindex")||"";return $r(o)||o.hasAttribute("data-tabindex")&&!a.startsWith("-")}),r=e.getAttribute("tabindex");s.length===0?r!=="0"&&(e.setAttribute("tabindex","0"),e.setAttribute("data-tabindex","0")):(r!=="-1"||e.hasAttribute("data-tabindex")&&e.getAttribute("data-tabindex")!=="-1")&&(e.setAttribute("tabindex","-1"),e.setAttribute("data-tabindex","-1"))}function sc(e){const{context:t,children:s,disabled:r=!1,initialFocus:o=!0,returnFocus:a=!0,explicitReturnFocus:l,restoreFocus:c=!1,modal:f=!0,closeOnFocusOut:u=!0,openInteractionType:d="",nextFocusableElement:m,previousFocusableElement:k,beforeContentFocusGuardRef:v,externalTree:x,getInsideElements:y}=e,p=t.useState("open"),g=t.useState("domReferenceElement"),j=t.useState("floatingElement"),{events:C,dataRef:h}=t.context,b=ye(()=>h.current.floatingContext?.nodeId),N=o===!1,S=Yi(g)&&N,T=dt(o),P=dt(a),B=dt(l),L=dt(d),K=dt(p),A=ds(x),z=Jl(),M=i.useRef(!1),R=i.useRef(!1),W=i.useRef(!1),I=i.useRef(null),_=i.useRef(""),V=i.useRef(""),H=i.useRef(null),Y=i.useRef(null),le=Rs(H,v,z?.beforeInsideRef),J=Rs(Y,z?.afterInsideRef),se=tn(),Z=tn(),re=Qo(),we=z!=null,D=Xi(j),$=ye((te=D)=>te?Dr(te):[]),ee=ye(()=>y?.().filter(te=>te!=null)??[]);i.useEffect(()=>{if(r||!f)return;function te(ce){ce.key==="Tab"&&be(D,_t(We(D)))&&$().length===0&&!S&&Gf(ce)}const ae=We(D);return Te(ae,"keydown",te)},[r,D,f,S,$]),i.useEffect(()=>{if(r||!p)return;const te=We(D);function ae(){W.current=!1}function ce($e){const Q=kt($e),ve=ee(),ue=be(j,Q)||be(g,Q)||be(z?.portalNode,Q)||ve.some(Ce=>Ce===Q||be(Ce,Q));W.current=!ue,V.current=$e.pointerType||"keyboard",Is(Q,`[${ql}]`)&&(R.current=!0,Z.start(0,()=>{R.current=!1}))}function je(){V.current="keyboard"}return nn(Te(te,"pointerdown",ce,!0),Te(te,"pointerup",ae,!0),Te(te,"pointercancel",ae,!0),Te(te,"keydown",je,!0),ae)},[r,j,g,D,p,z,Z,ee]),i.useEffect(()=>{if(r||!u)return;const te=We(D);function ae(){R.current=!0,Z.start(0,()=>{R.current=!1})}function ce(ve){const ue=kt(ve);$r(ue)&&(I.current=ue)}function je(ve){const ue=ve.relatedTarget,Ce=ve.currentTarget,Ae=kt(ve);f&&ue==null&&Ae!=null&&be(j,Ae)&&ia(Ae),queueMicrotask(()=>{const Ie=b(),X=t.context.triggerElements,ne=ee(),Pe=ue?.hasAttribute(os("focus-guard"))&&[H.current,Y.current,z?.beforeInsideRef.current,z?.afterInsideRef.current,z?.beforeOutsideRef.current,z?.afterOutsideRef.current,dn(k),dn(m)].includes(ue),Ne=!(be(g,ue)||be(j,ue)||be(ue,j)||be(z?.portalNode,ue)||ne.some(Re=>Re===ue||be(Re,ue))||X.hasMatchingElement(Re=>be(Re,ue))||Pe||A&&(En(A.nodesRef.current,Ie).find(Re=>be(Re.context?.elements.floating,ue)||be(Re.context?.elements.domReference,ue))||Qi(A.nodesRef.current,Ie).find(Re=>[Re.context?.elements.floating,Xi(Re.context?.elements.floating)].includes(ue)||Re.context?.elements.domReference===ue)));if(Ce===g&&D&&la(D),c&&Ce!==g&&!zl(Ae)&&_t(te)===te.body){if(xt(D)&&(D.focus(),c==="popup")){re.request(()=>{D.focus()});return}const Re=$(),He=I.current,Ge=(He&&Re.includes(He)?He:null)||Re[Re.length-1]||D;xt(Ge)&&Ge.focus()}if(h.current.insideReactTree){h.current.insideReactTree=!1;return}(S||!f)&&ue&&Ne&&!R.current&&(S||ue!==aa())&&(M.current=!0,t.setOpen(!1,Fe(Ps,ve)))})}function $e(){W.current||(h.current.insideReactTree=!0,se.start(0,()=>{h.current.insideReactTree=!1}))}const Q=xt(g)?g:null;if(!(!j&&!Q))return nn(Q&&Te(Q,"focusout",je),Q&&Te(Q,"pointerdown",ae),j&&Te(j,"focusin",ce),j&&Te(j,"focusout",je),j&&z&&Te(j,"focusout",$e,!0))},[r,g,j,D,f,A,z,t,u,c,$,S,b,h,se,Z,re,m,k,ee]),i.useEffect(()=>{if(r||!j||!p)return;const te=Array.from(z?.portalNode?.querySelectorAll(`[${os("portal")}]`)||[]),ce=(A?Qi(A.nodesRef.current,b()):[]).find(Ce=>Yi(Ce.context?.elements.domReference||null))?.context?.elements.domReference,$e=[...[j,...te,H.current,Y.current,z?.beforeOutsideRef.current,z?.afterOutsideRef.current,...ee()],ce,dn(k),dn(m),S?g:null].filter(Ce=>Ce!=null),Q=ra($e,{ariaHidden:f||S,mark:!1}),ve=[j,...te].filter(Ce=>Ce!=null),ue=ra(ve);return()=>{ue(),Q()}},[p,r,g,j,f,z,S,A,b,m,k,ee]),pe(()=>{if(!p||r||!xt(D))return;_.current="",V.current="";const te=We(D),ae=_t(te);queueMicrotask(()=>{const ce=T.current,je=typeof ce=="function"?ce(L.current||""):ce;if(je===void 0||je===!1||be(D,ae))return;let Q=null;const ve=()=>(Q==null&&(Q=$(D)),Q[0]||D);let ue;je===!0||je===null?ue=ve():ue=dn(je),ue=ue||ve();const Ce=be(D,_t(te)),Ae=h.current.openEvent,Ie=Ae?.type==="mousedown"&&gr(Ae);uo(ue,{sync:Ie,preventScroll:ue===D,shouldFocus(){if(!K.current)return!1;if(Ce)return!0;const X=_t(te);return!(X!==ue&&be(D,X))}})})},[r,p,D,$,T,L,K,h]);const G=i.useRef(null);pe(()=>{if(r||!D){G.current=null;return}G.current&&(G.current.cancelled=!0,G.current=null);const te=We(D),ae=_t(te),ce=L.current==null;ia(ae);function je(Q){if(Q.open||(_.current=jp(Q.nativeEvent,V.current)),(Q.reason===Ps&&Q.triggerElement?.hasAttribute(os("focus-guard"))||Q.reason===ut&&Q.nativeEvent.type==="mouseleave")&&(M.current=!0),Q.reason===El)if(Q.nested)M.current=!1;else if(gr(Q.nativeEvent)||Al(Q.nativeEvent))M.current=!1;else{let ve=!1;We(D).createElement("div").focus({get preventScroll(){return ve=!0,!1}}),ve?M.current=!1:M.current=!0}}C.on("openchange",je);function $e(Q){const ve=P.current;let ue=typeof ve=="function"?ve(Q):ve;if(ue===void 0||ue===!1)return null;ue===null&&(ue=!0);const Ce=g?.isConnected?g:null,Ae=ae?.isConnected&&Bt(ae)!=="body"?ae:null;let Ie=ce?Ae||Ce:Ce||Ae;return Ie||(Ie=aa()||null),typeof ue=="boolean"?Ie:dn(ue)||Ie||null}return()=>{C.off("openchange",je);const Q=_t(te),ve=ee(),ue=be(j,Q)||ve.some(ne=>ne===Q||be(ne,Q))||A&&En(A.nodesRef.current,b(),!1).some(ne=>be(ne.context?.elements.floating,Q)),Ce=P.current,Ae=_.current,Ie=$e(Ae),X={cancelled:!1};G.current=X,queueMicrotask(()=>{G.current===X&&(G.current=null);const ne=wp(Ie),Pe=B.current??typeof Ce!="boolean";if(!X.cancelled&&Ce&&!M.current&&xt(ne)&&(!(!Pe&&ne!==Q&&Q!==te.body)||ue)){const Ne={preventScroll:!0};Ae==="keyboard"&&(Ne.focusVisible=!0),ne.focus(Ne)}M.current=!1})}},[r,j,D,P,B,L,C,A,g,b,ee]),pe(()=>{if(!Un||p||!j)return;const te=_t(We(j));!xt(te)||!Mr(te)||be(j,te)&&te.blur()},[p,j]),pe(()=>{if(!(r||!z))return z.setFocusManagerState({modal:f,closeOnFocusOut:u,open:p,onOpenChange:t.setOpen,domReference:g}),()=>{z.setFocusManagerState(null)}},[r,z,f,p,t,u,g]),pe(()=>{if(!(r||!D))return la(D),()=>{queueMicrotask(ni)}},[r,D]);const fe=!r&&(f?!S:!0)&&(we||f);return n.jsxs(i.Fragment,{children:[fe&&n.jsx(as,{"data-type":"inside",ref:le,onFocus:te=>{if(f){const ae=$();uo(ae[ae.length-1])}else z?.portalNode&&(M.current=!1,rs(te,z.portalNode)?Gl(g)?.focus():dn(k??z.beforeOutsideRef)?.focus())}}),s,fe&&n.jsx(as,{"data-type":"inside",ref:J,onFocus:te=>{f?uo($()[0]):z?.portalNode&&(u&&(M.current=!0),rs(te,z.portalNode)?Vl(g)?.focus():dn(m??z.afterOutsideRef)?.focus())}})]})}function Cp(e,t={}){const{enabled:s=!0,event:r="click",toggle:o=!0,ignoreMouse:a=!1,stickIfOpen:l=!0,touchOpenDelay:c=0,reason:f=mn}=t,u=e.context.dataRef,d=i.useRef(void 0),m=Qo(),k=tn(),v=i.useMemo(()=>{function x(p,g,j,C){const h=Fe(f,g,j);p&&C==="touch"&&c>0?k.start(c,()=>{e.setOpen(!0,h)}):e.setOpen(p,h)}function y(p,g,j){const C=u.current.openEvent,h=e.select("domReferenceElement")!==g;return p&&h||!p||!o?!0:C&&(typeof l=="function"?l():l)?!j(C.type):!1}return{onPointerDown(p){d.current=Cn(p.pointerType,!0)&&Al(p.nativeEvent)?"virtual":p.pointerType},onMouseDown(p){const g=d.current,j=p.nativeEvent,C=e.select("open");if(p.button!==0||r==="click"||Cn(g,!0)&&a)return;const h=y(C,p.currentTarget,T=>T==="click"||T==="mousedown"),b=kt(j),N=Mr(b);if(N||g==="virtual"){x(h,j,N?b:p.currentTarget,g);return}const S=p.currentTarget;m.request(()=>{x(h,j,S,g)})},onClick(p){if(r==="mousedown-only")return;const g=d.current;if(r==="mousedown"&&g){d.current=void 0;return}if(Cn(g,!0)&&a)return;const j=e.select("open"),C=y(j,p.currentTarget,h=>h==="click"||h==="mousedown"||h==="keydown"||h==="keyup");x(C,p.nativeEvent,p.currentTarget,g)},onKeyDown(){d.current=void 0}}},[u,r,a,f,e,l,o,m,k,c]);return i.useMemo(()=>s?{reference:v}:bt,[s,v])}function Sp(e,t){let s=null,r=null,o=!1;return{contextElement:e||void 0,getBoundingClientRect(){const a=e?.getBoundingClientRect()||{width:0,height:0,x:0,y:0},l=t.axis==="x"||t.axis==="both",c=t.axis==="y"||t.axis==="both",f=["mouseenter","mousemove"].includes(t.dataRef.current.openEvent?.type||"")&&t.pointerType!=="touch",u=t.axis==="y"?a.width:0,d=t.axis==="x"?a.height:0;let m=a.x,k=a.y;return s==null&&t.x&&l&&(s=a.x-t.x),r==null&&t.y&&c&&(r=a.y-t.y),m-=s||0,k-=r||0,(!o||f)&&(m=l&&t.x!=null?t.x:m,k=c&&t.y!=null?t.y:k),o=!0,{width:u,height:d,x:m,y:k,top:k,right:m+u,bottom:k+d,left:m}}}}function ca(e){return e!=null&&e.clientX!=null}function Np(e,t={}){const{enabled:s=!0,axis:r="both"}=t,o=e.useState("open"),a=e.useState("floatingElement"),l=e.useState("domReferenceElement"),c=e.context.dataRef,f=i.useRef(!1),u=i.useRef(null),[d,m]=i.useState(),[k,v]=i.useState([]),x=ye(C=>{e.set("positionReference",C)}),y=ye((C,h,b)=>{f.current||c.current.openEvent&&!ca(c.current.openEvent)||e.set("positionReference",Sp(b??l,{x:C,y:h,axis:r,dataRef:c,pointerType:d}))}),p=ye(C=>{o?u.current||(y(C.clientX,C.clientY,C.currentTarget),v([])):y(C.clientX,C.clientY,C.currentTarget)}),g=Cn(d)?a:o;i.useEffect(()=>{if(!s){x(l);return}if(!g)return;function C(){u.current?.(),u.current=null}const h=xn(a);function b(N){const S=kt(N);be(a,S)?C():y(N.clientX,N.clientY)}return!c.current.openEvent||ca(c.current.openEvent)?u.current=Te(h,"mousemove",b):x(l),C},[g,s,a,c,l,e,y,x,k]),i.useEffect(()=>()=>{e.set("positionReference",null)},[e]),i.useEffect(()=>{s&&!a&&(f.current=!1)},[s,a]),i.useEffect(()=>{!s&&o&&(f.current=!0)},[s,o]);const j=i.useMemo(()=>{function C(h){m(h.pointerType)}return{onPointerDown:C,onPointerEnter:C,onMouseMove:p,onMouseEnter:p}},[p]);return i.useMemo(()=>s?{reference:j,trigger:j}:{},[s,j])}function Ep(){return!1}function Tp(e){return{escapeKey:typeof e=="boolean"?e:e?.escapeKey??!1,outsidePress:typeof e=="boolean"?e:e?.outsidePress??!0}}function si(e,t={}){const{enabled:s=!0,escapeKey:r=!0,outsidePress:o=!0,outsidePressEvent:a="sloppy",referencePress:l=Ep,bubbles:c,externalTree:f}=t,u=e.useState("open"),d=e.useState("floatingElement"),{dataRef:m,events:k}=e.context,v=ds(f),x=ye(typeof o=="function"?o:()=>!1),y=typeof o=="function"?x:o,p=y!==!1,g=ye(()=>a),{escapeKey:j,outsidePress:C}=Tp(c),h=i.useRef(!1),b=i.useRef(!1),N=i.useRef(!1),S=i.useRef(!1),T=i.useRef(!1),P=i.useRef(""),B=i.useRef(null),L=tn(),K=tn(),A=tn(),z=ye(()=>{K.clear(),m.current.insideReactTree=!1}),M=ye(J=>{const se=m.current.floatingContext?.nodeId;return(v?En(v.nodesRef.current,se):[]).some(re=>re.context?.open&&!re.context.dataRef.current[J])}),R=ye(J=>lo(J,e.select("floatingElement"))||lo(J,e.select("domReferenceElement"))),W=ye(J=>{l()&&e.setOpen(!1,Fe(mn,J.nativeEvent))}),I=ye(J=>{if(!u||!s||!r||J.key!=="Escape")return;const se=Vf(J)?J.nativeEvent:J;if(T.current||se.isComposing||!j&&M("__escapeKeyBubbles"))return;const Z=Fe(Pr,se);e.setOpen(!1,Z),Z.isCanceled||J.preventDefault(),!j&&!Z.isPropagationAllowed&&J.stopPropagation()}),_=ye(()=>{m.current.insideReactTree=!0,K.start(0,z)}),V=ye(J=>{if(!u||!s||J.button!==0)return;const se=kt(J.nativeEvent);be(e.select("floatingElement"),se)&&(h.current||(h.current=!0,b.current=!1))}),H=ye(J=>{!u||!s||(J.defaultPrevented||J.nativeEvent.defaultPrevented)&&h.current&&(b.current=!0)});i.useEffect(()=>{function J(se){se.open||(S.current=!1)}return k.on("openchange",J),()=>{k.off("openchange",J)}},[k]),i.useEffect(()=>z,[z]),i.useEffect(()=>{if(!u||!s)return u||(S.current=!1,T.current=!1,P.current="",B.current=null),z;m.current.__escapeKeyBubbles=j,m.current.__outsidePressBubbles=C;const J=new At,se=We(d);function Z(){A.clear(),T.current=!0}function re(){T.current=!0,A.start(Un?5:0,()=>{T.current=!1})}function we(){N.current=!0,J.start(0,()=>{N.current=!1})}function D(){h.current=!1,b.current=!1}function $(){const X=P.current,ne=X==="pen"||!X?"mouse":X,Pe=g(),Ne=typeof Pe=="function"?Pe():Pe;return typeof Ne=="string"?Ne:Ne[ne]}function ee(X){const ne=$();return ne==="intentional"&&X.type!=="click"||ne==="sloppy"&&X.type==="click"}function G(X){const ne=m.current.floatingContext?.nodeId,Pe=v&&En(v.nodesRef.current,ne).some(Ne=>lo(X,Ne.context?.elements.floating));return R(X)||Pe}function fe(X){if(ee(X)){X.type!=="click"&&!R(X)&&(J.clear(),N.current=!1),z();return}if(m.current.insideReactTree){z();return}const ne=kt(X),Pe=`[${os("inert")}]`,Ne=Ze(ne)?ne.getRootNode():null,Re=Array.from(($s(Ne)?Ne:We(e.select("floatingElement"))).querySelectorAll(Pe)),He=e.context.triggerElements;if(ne&&(He.hasElement(ne)||He.hasMatchingElement(_e=>be(_e,ne))))return;let Ge=Ze(ne)?ne:null;for(;Ge&&!Zr(Ge);){const _e=lu(Ge);if(Zr(_e)||!Ze(_e))break;Ge=_e}if(!(Re.length&&Ze(ne)&&!qf(ne)&&!be(ne,e.select("floatingElement"))&&Re.every(_e=>!be(Ge,_e)))){if(xt(ne)&&!("touches"in X)){const _e=Zr(ne),F=Fo(ne),oe=/auto|scroll/,he=_e||oe.test(F.overflowX),Se=_e||oe.test(F.overflowY),De=he&&ne.clientWidth>0&&ne.scrollWidth>ne.clientWidth,Ve=Se&&ne.clientHeight>0&&ne.scrollHeight>ne.clientHeight,qe=F.direction==="rtl",Xe=Ve&&(qe?X.offsetX<=ne.offsetWidth-ne.clientWidth:X.offsetX>ne.clientWidth),lt=De&&X.offsetY>ne.clientHeight;if(Xe||lt)return}if(!G(X)){if($()==="intentional"){if(X.detail!==0&&!gr(X)&&!S.current)return;if(N.current){J.clear(),N.current=!1;return}}typeof y=="function"&&!y(X)||M("__outsidePressBubbles")||(e.setOpen(!1,Fe(El,X)),z())}}}function te(X){$()!=="sloppy"||X.pointerType==="touch"||!e.select("open")||!s||R(X)||fe(X)}function ae(X){if($()!=="sloppy"||!e.select("open")||!s||R(X))return;const ne=X.touches[0];ne&&(B.current={startTime:Date.now(),startX:ne.clientX,startY:ne.clientY,dismissOnTouchEnd:!1,dismissOnMouseDown:!0},L.start(1e3,()=>{B.current&&(B.current.dismissOnTouchEnd=!1,B.current.dismissOnMouseDown=!1)}))}function ce(X,ne){const Pe=kt(X);if(!Pe)return;const Ne=Te(Pe,X.type,()=>{ne(X),Ne()})}function je(X){P.current="touch",ce(X,ae)}function $e(X){L.clear(),X.type==="pointerdown"&&(X.button===0&&(S.current=!0),P.current=X.pointerType),!(X.type==="mousedown"&&B.current&&!B.current.dismissOnMouseDown)&&ce(X,ne=>{ne.type==="pointerdown"?te(ne):fe(ne)})}function Q(X){if(X.type==="pointercancel"&&(S.current=!1),!h.current)return;const ne=b.current;if(D(),$()==="intentional"){if(X.type==="pointercancel"){ne&&we();return}if(!G(X)){if(ne){we();return}typeof y=="function"&&!y(X)||(J.clear(),N.current=!0,z())}}}function ve(X){if($()!=="sloppy"||!B.current||R(X))return;const ne=X.touches[0];if(!ne)return;const Pe=Math.abs(ne.clientX-B.current.startX),Ne=Math.abs(ne.clientY-B.current.startY),Re=Math.sqrt(Pe*Pe+Ne*Ne);Re>5&&(B.current.dismissOnTouchEnd=!0),Re>10&&(fe(X),L.clear(),B.current=null)}function ue(X){ce(X,ve)}function Ce(X){$()!=="sloppy"||!B.current||R(X)||(B.current.dismissOnTouchEnd&&fe(X),L.clear(),B.current=null)}function Ae(X){ce(X,Ce)}const Ie=nn(r&&nn(Te(se,"keydown",I),Te(se,"compositionstart",Z),Te(se,"compositionend",re)),p&&nn(Te(se,"click",$e,!0),Te(se,"pointerdown",$e,!0),Te(se,"pointerup",Q,!0),Te(se,"pointercancel",Q,!0),Te(se,"mousedown",$e,!0),Te(se,"mouseup",Q,!0),Te(se,"touchstart",je,{capture:!0,passive:!0}),Te(se,"touchmove",ue,{capture:!0,passive:!0}),Te(se,"touchend",Ae,{capture:!0,passive:!0})));return()=>{Ie(),J.clear(),D(),N.current=!1}},[m,d,r,p,y,u,s,j,C,I,z,g,M,R,v,e,L,A]);const Y=i.useMemo(()=>({onKeyDown:I,onPointerDown:W,onClick:W}),[I,W]),le=i.useMemo(()=>({onKeyDown:I,onPointerDown:H,onMouseDown:H,onClickCapture:_,onMouseDownCapture(J){_(),V(J)},onPointerDownCapture(J){_(),V(J)},onMouseUpCapture:_,onTouchEndCapture:_,onTouchMoveCapture:_}),[I,_,V,H]);return i.useMemo(()=>s?{reference:Y,floating:le,trigger:Y}:{},[s,Y,le])}function Rp(e){const{popupStore:t,treatPopupAsFloatingElement:s=!1,floatingRootContext:r,floatingId:o,nested:a,onOpenChange:l}=e,c=t.useState("open"),f=t.useState("activeTriggerElement"),u=t.useState(s?"popupElement":"positionerElement"),d=l;return t.useSyncedValue("floatingId",o),pe(()=>{const m={open:c,floatingId:o,referenceElement:f,floatingElement:u};Ze(f)&&(m.domReferenceElement=f),r.state.positionReference===r.state.referenceElement&&(m.positionReference=f),r.update(m)},[c,o,f,u,r]),r.context.onOpenChange=d,r.context.nested=a,r}function rc(e,t=!1,s=!1,r=!1){const[o,a]=i.useState(e&&t?"idle":void 0),[l,c]=i.useState(e&&!r);return e&&!l&&(c(!0),a("starting")),!e&&l&&o!=="ending"&&!s&&a("ending"),!e&&!l&&o==="ending"&&a(void 0),pe(()=>{if(!e&&l&&o!=="ending"&&s){const f=ht.request(()=>{a("ending")});return()=>{ht.cancel(f)}}},[e,l,o,s]),pe(()=>{if(!e||t||o===void 0)return;const f=ht.request(()=>{a(void 0)});return()=>{ht.cancel(f)}},[t,e,o]),pe(()=>{if(!e||!t)return;e&&l&&o!=="idle"&&a("starting");const f=ht.request(()=>{a("idle")});return()=>{ht.cancel(f)}},[t,e,l,o]),{mounted:l,setMounted:c,transitionStatus:o}}function ua(e,t){return e.getAnimations(t).filter(s=>{const r=s.effect?.getTiming();return r?.duration!==1/0&&r?.iterations!==1/0})}let Qs=null;function Pp(e){if(!Qs){const t=[];Qs=t,queueMicrotask(()=>{Qs=null,gn.flushSync(()=>{for(const s of t)s()})})}Qs.push(e)}function ri(e,t=!1,s=!1){const r=Qo();return ye((o,a=null)=>{r.cancel();const l=dn(e);if(l==null)return;const c=l,f=()=>{if(!s){gn.flushSync(o);return}Pp(()=>{a?.aborted||o()})};if(typeof c.getAnimations!="function"||globalThis.BASE_UI_ANIMATIONS_DISABLED){o();return}function u(){Promise.all(ua(c).map(d=>d.finished.then(Nr))).then(()=>{a?.aborted||f()},()=>{if(a?.aborted)return;if(ua(c).some(m=>m.pending||m.playState!=="finished")){u();return}f()})}if(t){const d=Yo;if(!c.hasAttribute(d)){r.request(u);return}const m=new MutationObserver(()=>{c.hasAttribute(d)||(m.disconnect(),u())});m.observe(c,{attributes:!0,attributeFilter:[d]}),a?.addEventListener("abort",()=>m.disconnect(),{once:!0});return}r.request(u)})}function Ls(e){const{enabled:t=!0,open:s,ref:r,batch:o=!1,onComplete:a}=e,l=ye(a),c=ri(r,s,o);i.useEffect(()=>{if(!t)return;const f=new AbortController;return c(l,f.signal),()=>{f.abort()}},[t,s,l,c])}function Op(e){const{open:t,ref:s,preventUnmountOnClose:r,setPreventUnmountOnClose:o,onUnmount:a,animateInitialOpen:l}=e,c=ye(o),{mounted:f,setMounted:u,transitionStatus:d}=rc(t,!1,!1,l),m=t?!1:r;pe(()=>{t&&c(!1)},[t,c]);const k=i.useRef(f),v=i.useRef(!1),x=Pl(),y=()=>{k.current=!1,u(!1),a()};pe(()=>{k.current=f,v.current&&(v.current=!1,!t&&f&&y())});const p=ye(()=>{if(k.current){if(t){v.current=!0,x();return}y()}});return Ls({enabled:f&&!t&&!m,open:t,ref:s,onComplete(){t||p()}}),{mounted:f,transitionStatus:d,preventUnmountingOnClose:m,forceUnmount:p}}const oi={tabIndex:-1,[Ro]:""};function oc(e){return t=>t==="touch"?e.current:!0}function ii(e,t=!1){const s=Or(),r=zr()!=null,o=Ht(()=>e(s,r)).current;return Rp({popupStore:o,treatPopupAsFloatingElement:t,floatingRootContext:o.state.floatingRootContext,floatingId:s,nested:r,onOpenChange:o.setOpen}),o}function ai({handle:e,store:t}){return pe(()=>e.attachStore(t),[e,t]),null}function da(e){const t=e.context.triggerElements.size;e.select("open")&&e.state.triggerCount!==t&&e.set("triggerCount",t)}function Ip(e,t){const s=i.useRef(null);return ye(r=>{const o=s.current;if(o!==null){if(o.element===r&&o.store===t&&o.id===e)return;s.current=null;const a=o.store;a.context.triggerElements.getById(o.id)===o.element&&(a.context.triggerElements.delete(o.id),da(a))}r!==null&&e!==void 0&&(s.current={store:t,id:e,element:r},t.context.triggerElements.add(e,r),da(t))})}function li(e,t,s,r=!1){let o=e.preventUnmountingOnClose;t?o=!1:r&&(o=!0);const a=s?.id??null;let l=e.activeTriggerId,c=e.activeTriggerElement;return(a||t)&&(l=a,c=s??null),{open:t,preventUnmountingOnClose:o,activeTriggerId:l,activeTriggerElement:c,openedWithoutTrigger:t?s==null:e.openedWithoutTrigger}}function ic(e){let t=!1;return e.preventUnmountOnClose=()=>{t=!0},()=>t}function Ap(e,t,s,r={}){const o=s.reason,a=o===ut,l=t&&o===cr,c=!t&&(o===mn||o===Pr),f=ic(s);if(e.context.onOpenChange?.(t,s),s.isCanceled)return;r.onBeforeDispatch?.(),e.state.floatingRootContext.dispatchOpenChange(t,s);const u=()=>{const d=li(e.state,t,s.trigger,f()),m={...r.extraState,...d};l?m.instantType="focus":c?m.instantType="dismiss":a&&(m.instantType=void 0),e.update(m)};a?gn.flushSync(u):u()}function ac(e,t,s,r){const o=s.useState("isMountedByTrigger",e),a=Ip(e,s),l=ye(f=>{const u=s.select("open"),d=s.select("activeTriggerId");if(d===e){const m={activeTriggerElement:f,...u?r:null};s.update(m);return}if(d==null&&u&&!s.state.openedWithoutTrigger){const m={activeTriggerId:e??null,activeTriggerElement:f,...r};s.update(m)}}),c=ye(f=>{a(f),f&&l(f)});return pe(()=>(c(t.current),()=>c(null)),[c,t,s,e]),pe(()=>{if(o){const f={activeTriggerElement:t.current,...r};s.update(f)}},[o,s,t,...Object.values(r)]),{registerTrigger:c,isMountedByThisTrigger:o}}function ci(e,t={}){const{closeOnActiveTriggerUnmount:s=!1}=t,r=i.useRef(null),o=e.useState("open"),a=e.useState("triggerCount"),l=e.useState("activeTriggerId"),c=e.useState("activeTriggerElement");pe(()=>{if(!o){r.current=null,e.state.triggerCount!==0&&e.set("triggerCount",0),e.state.openedWithoutTrigger&&e.set("openedWithoutTrigger",!1);return}const f=e.context.triggerElements.size,u={};e.state.triggerCount!==f&&(u.triggerCount=f);const d=e.select("activeTriggerId");let m=null;if(d){const k=e.context.triggerElements.getById(d);if(k)r.current=d,k!==e.state.activeTriggerElement&&(u.activeTriggerElement=k);else{for(const[v,x]of e.context.triggerElements.entries())if(x===e.state.activeTriggerElement){u.activeTriggerId=v,u.activeTriggerElement=x,r.current=v;break}u.activeTriggerId===void 0&&(r.current===d?m=d:r.current=null)}}else r.current=null;if(!m&&!d&&!e.state.openedWithoutTrigger&&f===1){const k=e.context.triggerElements.entries().next();if(!k.done){const[v,x]=k.value;u.activeTriggerId=v,u.activeTriggerElement=x,r.current=v}}(u.triggerCount!==void 0||u.activeTriggerId!==void 0||u.activeTriggerElement!==void 0)&&e.update(u),m&&s&&queueMicrotask(()=>{if(e.select("open")&&e.select("activeTriggerId")===m&&!e.context.triggerElements.getById(m)){const k=Fe(Rr);e.setOpen(!1,k),k.isCanceled||e.update({activeTriggerId:null,activeTriggerElement:null})}})},[o,e,a,l,c,s])}function ui(e,t,s,r){const{mounted:o,transitionStatus:a,forceUnmount:l}=Op({open:e,ref:t.context.popupRef,preventUnmountOnClose:t.useState("preventUnmountingOnClose"),setPreventUnmountOnClose:c=>t.set("preventUnmountingOnClose",c),animateInitialOpen:r,onUnmount(){t.update({activeTriggerId:null,activeTriggerElement:null,mounted:!1,preventUnmountingOnClose:!1}),s?.(),t.context.onOpenChangeComplete?.(!1)}});return Ht(()=>(t.set("mounted",o),null)),t.useSyncedValues({mounted:o,transitionStatus:a}),{forceUnmount:l,transitionStatus:a}}function di(e,t){e.useSyncedValues(t),pe(()=>()=>{e.update({activeTriggerProps:bt,inactiveTriggerProps:bt,popupProps:bt})},[e])}function lc(e,t){pe(()=>{!t&&e.state.openMethod!==null&&e.set("openMethod",null)},[t,e]),pe(()=>()=>{e.state.openMethod!==null&&e.set("openMethod",null)},[e])}class fi{idMap=new Map;add(t,s){this.idMap.set(t,s)}delete(t){this.idMap.delete(t)}hasElement(t){for(const s of this.idMap.values())if(s===t)return!0;return!1}hasMatchingElement(t){for(const s of this.idMap.values())if(t(s))return!0;return!1}getById(t){return this.idMap.get(t)}entries(){return this.idMap.entries()}elements(){return this.idMap.values()}get size(){return this.idMap.size}}var po={exports:{}},mo={};var fa;function Mp(){if(fa)return mo;fa=1;var e=Ka();function t(m,k){return m===k&&(m!==0||1/m===1/k)||m!==m&&k!==k}var s=typeof Object.is=="function"?Object.is:t,r=e.useState,o=e.useEffect,a=e.useLayoutEffect,l=e.useDebugValue;function c(m,k){var v=k(),x=r({inst:{value:v,getSnapshot:k}}),y=x[0].inst,p=x[1];return a(function(){y.value=v,y.getSnapshot=k,f(y)&&p({inst:y})},[m,v,k]),o(function(){return f(y)&&p({inst:y}),m(function(){f(y)&&p({inst:y})})},[m]),l(v),v}function f(m){var k=m.getSnapshot;m=m.value;try{var v=k();return!s(m,v)}catch{return!0}}function u(m,k){return k()}var d=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?u:c;return mo.useSyncExternalStore=e.useSyncExternalStore!==void 0?e.useSyncExternalStore:d,mo}var pa;function cc(){return pa||(pa=1,po.exports=Mp()),po.exports}var pi=cc(),go={exports:{}},xo={};var ma;function $p(){if(ma)return xo;ma=1;var e=Ka(),t=cc();function s(u,d){return u===d&&(u!==0||1/u===1/d)||u!==u&&d!==d}var r=typeof Object.is=="function"?Object.is:s,o=t.useSyncExternalStore,a=e.useRef,l=e.useEffect,c=e.useMemo,f=e.useDebugValue;return xo.useSyncExternalStoreWithSelector=function(u,d,m,k,v){var x=a(null);if(x.current===null){var y={hasValue:!1,value:null};x.current=y}else y=x.current;x=c(function(){function g(N){if(!j){if(j=!0,C=N,N=k(N),v!==void 0&&y.hasValue){var S=y.value;if(v(S,N))return h=S}return h=N}if(S=h,r(C,N))return S;var T=k(N);return v!==void 0&&v(S,T)?(C=N,S):(C=N,h=T)}var j=!1,C,h,b=m===void 0?null:m;return[function(){return g(d())},b===null?void 0:function(){return g(b())}]},[d,m,k,v]);var p=o(u,x[0],x[1]);return l(function(){y.hasValue=!0,y.value=p},[p]),f(p),p},xo}var ga;function Dp(){return ga||(ga=1,go.exports=$p()),go.exports}var zp=Dp();const Io=[];let Ao;function Fp(){return Ao}function _p(e){Io.push(e)}function Fr(e){const t=(s,r)=>{const o=Ht(Lp).current;let a;try{Ao=o;for(const l of Io)l.before(o);a=e(s,r);for(const l of Io)l.after(o);o.didInitialize=!0}finally{Ao=void 0}return a};return t.displayName=e.displayName||e.name,t}function uc(e){return i.forwardRef(Fr(e))}function Lp(){return{didInitialize:!1}}const Bp=qo(19),Hp=Bp?Wp:Gp;function dc(e,t,s,r,o){return Hp(e,t,s,r,o)}function Up(e,t,s,r,o){const a=i.useCallback(()=>t(e.getSnapshot(),s,r,o),[e,t,s,r,o]);return pi.useSyncExternalStore(e.subscribe,a,a)}_p({before(e){e.syncIndex=0,e.didInitialize||(e.syncTick=1,e.syncHooks=[],e.didChangeStore=!0,e.getSnapshot=()=>{let t=!1;for(let s=0;s<e.syncHooks.length;s+=1){const r=e.syncHooks[s],o=r.selector(r.store.state,r.a1,r.a2,r.a3);Object.is(r.value,o)||(t=!0,r.value=o)}return t&&(e.syncTick+=1),e.syncTick})},after(e){e.syncHooks.length>0&&(e.didChangeStore&&(e.didChangeStore=!1,e.subscribe=t=>{const s=new Set;for(const o of e.syncHooks)s.add(o.store);const r=[];for(const o of s)r.push(o.subscribe(t));return()=>{for(const o of r)o()}}),pi.useSyncExternalStore(e.subscribe,e.getSnapshot,e.getSnapshot))}});function Wp(e,t,s,r,o){const a=Fp();if(!a)return Up(e,t,s,r,o);const l=a.syncIndex;a.syncIndex+=1;let c;return a.didInitialize?(c=a.syncHooks[l],(c.store!==e||c.selector!==t||!Object.is(c.a1,s)||!Object.is(c.a2,r)||!Object.is(c.a3,o))&&(c.store!==e&&(a.didChangeStore=!0),c.store=e,c.selector=t,c.a1=s,c.a2=r,c.a3=o,c.value=t(e.getSnapshot(),s,r,o))):(c={store:e,selector:t,a1:s,a2:r,a3:o,value:t(e.getSnapshot(),s,r,o)},a.syncHooks.push(c)),c.value}function Gp(e,t,s,r,o){return zp.useSyncExternalStoreWithSelector(e.subscribe,e.getSnapshot,e.getSnapshot,a=>t(a,s,r,o))}class Vp{static create(t){return new this(t)}constructor(t){this.state=t,this.listeners=new Set,this.updateTick=0}subscribe=t=>(this.listeners.add(t),()=>{this.listeners.delete(t)});getSnapshot=()=>this.state;setState(t){if(this.state===t)return;this.state=t,this.updateTick+=1;const s=this.updateTick;for(const r of this.listeners){if(s!==this.updateTick)return;r(t)}}update(t){for(const s in t)if(!Object.is(this.state[s],t[s])){this.setState({...this.state,...t});return}}set(t,s){Object.is(this.state[t],s)||this.setState({...this.state,[t]:s})}notifyAll(){const t={...this.state};this.setState(t)}use(t,s,r,o){return dc(this,t,s,r,o)}}class _r extends Vp{constructor(t,s={},r){super(t),this.context=s,this.selectors=r}useSyncedValue(t,s){i.useDebugValue(t);const r=this;pe(()=>{r.state[t]!==s&&r.set(t,s)},[r,t,s])}useSyncedValueWithCleanup(t,s){const r=this;pe(()=>(r.state[t]!==s&&r.set(t,s),()=>{r.set(t,void 0)}),[r,t,s])}useSyncedValues(t){const s=this,r=Object.values(t);pe(()=>{s.update(t)},[s,...r])}useControlledProp(t,s){i.useDebugValue(t);const r=this,o=s!==void 0;pe(()=>{o&&!Object.is(r.state[t],s)&&r.setState({...r.state,[t]:s})},[r,t,s,o])}select(t,s,r,o){const a=this.selectors[t];return a(this.state,s,r,o)}useState(t,s,r,o){return i.useDebugValue(t),dc(this,this.selectors[t],s,r,o)}useContextCallback(t,s){i.useDebugValue(t);const r=ye(s??Nr);this.context[t]=r}useStateSetter(t){const s=i.useRef(void 0);return s.current===void 0&&(s.current=r=>{this.set(t,r)}),s.current}observe(t,s){let r;typeof t=="function"?r=t:r=this.selectors[t];let o=r(this.state);return s(o,o,this),this.subscribe(a=>{const l=r(a);if(!Object.is(o,l)){const c=o;o=l,s(l,c,this)}})}}const Kp={open:e=>e.open,transitionStatus:e=>e.transitionStatus,domReferenceElement:e=>e.domReferenceElement,referenceElement:e=>e.positionReference??e.referenceElement,floatingElement:e=>e.floatingElement,floatingId:e=>e.floatingId};class qp extends _r{constructor(t){const{syncOnly:s,nested:r,onOpenChange:o,triggerElements:a,...l}=t;super({...l,positionReference:l.referenceElement,domReferenceElement:l.referenceElement},{onOpenChange:o,dataRef:{current:{}},events:ec(),nested:r,triggerElements:a},Kp),this.syncOnly=s}syncOpenEvent=(t,s)=>{(!t||!this.state.open||s!=null&&Kf(s))&&(this.context.dataRef.current.openEvent=t?s:void 0)};dispatchOpenChange=(t,s)=>{this.syncOpenEvent(t,s.event);const r={open:t,reason:s.reason,nativeEvent:s.event,nested:this.context.nested,triggerElement:s.trigger};this.context.events.emit("openchange",r)};setOpen=(t,s)=>{if(this.syncOnly){this.context.onOpenChange?.(t,s);return}this.dispatchOpenChange(t,s),this.context.onOpenChange?.(t,s)}}function mi(e,t,s=!1){return{open:!1,openProp:void 0,mounted:!1,transitionStatus:void 0,floatingRootContext:new qp({open:!1,transitionStatus:void 0,floatingElement:null,referenceElement:null,triggerElements:e,floatingId:t,syncOnly:!0,nested:s,onOpenChange:void 0}),floatingId:t,triggerCount:0,preventUnmountingOnClose:!1,payload:void 0,activeTriggerId:null,activeTriggerElement:null,openedWithoutTrigger:!1,triggerIdProp:void 0,popupElement:null,positionerElement:null,activeTriggerProps:bt,inactiveTriggerProps:bt,popupProps:bt}}const Ss=e=>e.triggerIdProp??e.activeTriggerId,hr=e=>e.openProp??e.open,xa=e=>(e.popupElement?.id??e.floatingId)||void 0;function fc(e,t){return t!==void 0&&hr(e)&&Ss(e)===t}function Yp(e,t){return fc(e,t)?!0:t!==void 0&&hr(e)&&Ss(e)==null&&!e.openedWithoutTrigger&&e.triggerCount===1}const ns={open:hr,mounted:e=>e.mounted,transitionStatus:e=>hr(e)&&!e.mounted?"starting":e.transitionStatus,floatingRootContext:e=>e.floatingRootContext,triggerCount:e=>e.triggerCount,preventUnmountingOnClose:e=>e.preventUnmountingOnClose,payload:e=>e.payload,activeTriggerId:Ss,activeTriggerElement:e=>e.mounted?e.activeTriggerElement:null,popupId:xa,isTriggerActive:(e,t)=>t!==void 0&&Ss(e)===t,isOpenedByTrigger:(e,t)=>fc(e,t),isMountedByTrigger:(e,t)=>t!==void 0&&Ss(e)===t&&e.mounted,triggerProps:(e,t)=>t?e.activeTriggerProps:e.inactiveTriggerProps,triggerPopupId:(e,t)=>Yp(e,t)?xa(e):void 0,popupProps:e=>e.popupProps,popupElement:e=>e.popupElement,positionerElement:e=>e.positionerElement};function pc(e){const t=i.useCallback(r=>e===void 0?Nr:e.subscribeStore(r),[e]),s=i.useCallback(()=>e===void 0?void 0:e.store,[e]);return pi.useSyncExternalStore(t,s,()=>e?.serverStore)}const ho=Ol&&Un;function Xp(e,t={}){const{enabled:s=!0,delay:r}=t,{events:o,dataRef:a}=e.context,l=i.useRef(!1),c=i.useRef(null),f=i.useRef(!0),u=tn();i.useEffect(()=>{const m=e.select("domReferenceElement");if(!s)return;const k=xn(m);function v(){const p=e.select("domReferenceElement");!e.select("open")&&xt(p)&&p===_t(We(p))&&(l.current=!0,c.current=p)}function x(){f.current=!0}function y(){f.current=!1}return nn(Te(k,"blur",v),ho&&Te(k,"keydown",x,!0),ho&&Te(k,"pointerdown",y,!0))},[e,s]),i.useEffect(()=>{if(!s)return;function m(k){if(k.reason===mn||k.reason===Pr){const v=e.select("domReferenceElement");Ze(v)&&(c.current=v,l.current=!0)}}return o.on("openchange",m),()=>{o.off("openchange",m)}},[o,s,e]);const d=i.useMemo(()=>{function m(){l.current=!1,c.current=null}return{onMouseLeave(){m()},onFocus(k){const v=k.currentTarget;if(l.current){if(c.current===v)return;m()}const x=kt(k.nativeEvent);if(Ze(x)){if(ho&&!k.relatedTarget){if(!f.current&&!Mr(x))return}else if(!Xf(x))return}const y=xr(k.relatedTarget,e.context.triggerElements),{nativeEvent:p,currentTarget:g}=k;if(e.select("open")&&y||!r){e.setOpen(!0,Fe(cr,p,g));return}u.start(r,()=>{l.current||e.setOpen(!0,Fe(cr,p,g))})},onBlur(k){m();const v=k.relatedTarget,x=k.nativeEvent,y=Ze(v)&&v.hasAttribute(os("focus-guard"))&&v.getAttribute("data-type")==="outside";u.start(0,()=>{const p=e.select("domReferenceElement"),g=_t(We(p));!v&&g===p||be(a.current.floatingContext?.refs.floating.current,g)||be(p,g)||y||xr(v??g,e.context.triggerElements)||e.setOpen(!1,Fe(cr,x))})}}},[a,r,e,u]);return i.useMemo(()=>s?{reference:d,trigger:d}:{},[s,d])}class gi{pointerType=void 0;interactedInside=!1;handler=void 0;blockMouseMove=!0;performedPointerEventsMutation=!1;pointerEventsScopeElement=null;pointerEventsReferenceElement=null;pointerEventsFloatingElement=null;restTimeoutPending=!1;openChangeTimeout=new At;restTimeout=new At;handleCloseOptions=void 0;static create(){return new gi}dispose=()=>{this.openChangeTimeout.clear(),this.restTimeout.clear()};disposeEffect=()=>this.dispose}const br=new WeakMap;function vr(e){if(!e.performedPointerEventsMutation)return;const t=e.pointerEventsScopeElement;t&&br.get(t)===e&&(e.pointerEventsScopeElement?.style.removeProperty("pointer-events"),e.pointerEventsReferenceElement?.style.removeProperty("pointer-events"),e.pointerEventsFloatingElement?.style.removeProperty("pointer-events"),br.delete(t)),e.performedPointerEventsMutation=!1,e.pointerEventsScopeElement=null,e.pointerEventsReferenceElement=null,e.pointerEventsFloatingElement=null}function mc(e,t){const{scopeElement:s,referenceElement:r,floatingElement:o}=t,a=br.get(s);a&&a!==e&&vr(a),vr(e),e.performedPointerEventsMutation=!0,e.pointerEventsScopeElement=s,e.pointerEventsReferenceElement=r,e.pointerEventsFloatingElement=o,br.set(s,e),s.style.pointerEvents="none",r.style.pointerEvents="auto",o.style.pointerEvents="auto"}function xi(e){const t=e.context.dataRef.current,s=Ht(()=>t.hoverInteractionState??gi.create()).current;return t.hoverInteractionState||(t.hoverInteractionState=s),Zo(t.hoverInteractionState.disposeEffect),t.hoverInteractionState}function gc(e,t={}){const{enabled:s=!0,closeDelay:r=0,nodeId:o}=t,a=e.useState("open"),l=e.useState("floatingElement"),c=e.useState("domReferenceElement"),{dataRef:f}=e.context,u=ds(),d=zr(),m=xi(e),k=tn(),v=ye(()=>$l(f.current.openEvent?.type,m.interactedInside)),x=ye(()=>Zf(f.current.openEvent?.type)),y=ye(()=>{vr(m)});pe(()=>{a||(m.pointerType=void 0,m.restTimeoutPending=!1,m.interactedInside=!1,y())},[a,m,y]),i.useEffect(()=>y,[y]),pe(()=>{if(s&&a&&m.handleCloseOptions?.blockPointerEvents&&x()&&Ze(c)&&l){const p=c,g=l,j=We(l),C=u?.nodesRef.current.find(S=>S.id===d)?.context?.elements.floating;C&&(C.style.pointerEvents="");const h=m.pointerEventsScopeElement!==g?m.pointerEventsScopeElement:null,b=C!==g?C:null,N=m.handleCloseOptions?.getScope?.()??h??b??Is(p,"[data-rootownerid]")??j.body;return mc(m,{scopeElement:N,referenceElement:p,floatingElement:g}),()=>{y()}}},[s,a,c,l,m,x,u,d,y]),i.useEffect(()=>{if(!s)return;function p(){return!!(u&&d&&En(u.nodesRef.current,d).length>0)}function g(S){const T=Bn(r,"close",m.pointerType),P=()=>{e.setOpen(!1,Fe(ut,S)),u?.events.emit("floating.closed",S)};T?m.openChangeTimeout.start(T,P):(m.openChangeTimeout.clear(),P())}function j(S){const T=kt(S);if(!Yf(T)){m.interactedInside=!1;return}m.interactedInside=Is(T,"[aria-haspopup]")!=null}function C(){m.openChangeTimeout.clear(),k.clear(),u?.events.off("floating.closed",b),y()}function h(S){if(p()&&u){u.events.on("floating.closed",b);return}if(xr(S.relatedTarget,e.context.triggerElements))return;const T=f.current.floatingContext?.nodeId??o,P=S.relatedTarget;if(!(u&&T&&Ze(P)&&En(u.nodesRef.current,T,!1).some(L=>be(L.context?.elements.floating,P)))){if(m.handler){m.handler(S);return}y(),x()&&!v()&&g(S)}}function b(S){!u||!d||p()||k.start(0,()=>{u.events.off("floating.closed",b),e.setOpen(!1,Fe(ut,S)),u.events.emit("floating.closed",S)})}const N=l;return nn(N&&Te(N,"mouseenter",C),N&&Te(N,"mouseleave",h),N&&Te(N,"pointerdown",j,!0),()=>{u?.events.off("floating.closed",b)})},[s,l,e,f,r,o,x,v,y,m,u,d,k])}const Jp={current:null};function xc(e,t={}){const{enabled:s=!0,delay:r=0,handleClose:o=null,mouseOnly:a=!1,restMs:l=0,move:c=!0,triggerElementRef:f=Jp,externalTree:u,isActiveTrigger:d=!0,getHandleCloseContext:m,isClosing:k,shouldOpen:v,guardStaleOpen:x=!1}=t,{dataRef:y,events:p}=e.context,g=ds(u),j=xi(e),C=i.useRef(!1),h=dt(o),b=dt(r),N=dt(l),S=dt(s),T=dt(v),P=dt(k),B=ye(()=>$l(y.current.openEvent?.type,j.interactedInside)),L=ye(()=>T.current?.()!==!1),K=ye((M,R,W)=>{const I=e.context.triggerElements;if(I.hasElement(R))return!M||!be(M,R);if(!Ze(W))return!1;const _=W;return I.hasMatchingElement(V=>be(V,_))&&(!M||!be(M,_))}),A=ye(()=>{if(!j.handler)return;We(e.select("domReferenceElement")).removeEventListener("mousemove",j.handler),j.handler=void 0}),z=ye(()=>{vr(j)});return d&&(j.handleCloseOptions=o?.__options),i.useEffect(()=>A,[A]),i.useEffect(()=>{if(!s)return;function M(R){R.open?C.current=!1:(C.current=R.reason===ut,A(),j.openChangeTimeout.clear(),j.restTimeout.clear(),j.blockMouseMove=!0,j.restTimeoutPending=!1)}return p.on("openchange",M),()=>{p.off("openchange",M)}},[s,p,j,A]),i.useEffect(()=>{if(!s)return;function M(H,Y=!0){const le=Bn(b.current,"close",j.pointerType);le?j.openChangeTimeout.start(le,()=>{e.setOpen(!1,Fe(ut,H)),g?.events.emit("floating.closed",H)}):Y&&(j.openChangeTimeout.clear(),e.setOpen(!1,Fe(ut,H)),g?.events.emit("floating.closed",H))}const R=f.current??(d?e.select("domReferenceElement"):null);if(!Ze(R))return;function W(H){if(j.openChangeTimeout.clear(),j.blockMouseMove=!1,a&&!Cn(j.pointerType))return;const Y=Ji(N.current),le=Bn(b.current,"open",j.pointerType),J=kt(H),se=H.currentTarget??null,Z=e.select("domReferenceElement");let re=se;if(Ze(J)&&!e.context.triggerElements.hasElement(J)){for(const ce of e.context.triggerElements.elements())if(be(ce,J)){re=ce;break}}Ze(se)&&Ze(Z)&&!e.context.triggerElements.hasElement(se)&&be(se,Z)&&(re=Z);const we=re==null?!1:K(Z,re,J),D=e.select("open"),$=P.current?.()??e.select("transitionStatus")==="ending",ee=!D&&$&&C.current,G=!we&&Ze(re)&&Ze(Z)&&be(Z,re)&&ee,fe=Y>0&&!le,te=we&&(D||ee)||G,ae=!D||we;if(te){L()&&e.setOpen(!0,Fe(ut,H,re));return}fe||(le?j.openChangeTimeout.start(le,()=>{ae&&L()&&e.setOpen(!0,Fe(ut,H,re))}):ae&&L()&&e.setOpen(!0,Fe(ut,H,re)))}function I(H){if(B()){z();return}A();const Y=e.select("domReferenceElement"),le=We(Y);j.restTimeout.clear(),j.restTimeoutPending=!1;const J=y.current.floatingContext??m?.();if(xr(H.relatedTarget,e.context.triggerElements))return;if(h.current&&J){e.select("open")||j.openChangeTimeout.clear();const Z=f.current;j.handler=h.current({...J,tree:g,x:H.clientX,y:H.clientY,onClose(){z(),A(),S.current&&!B()&&Z===e.select("domReferenceElement")&&M(H,!0)}}),le.addEventListener("mousemove",j.handler),j.handler(H);return}(j.pointerType==="touch"?!be(e.select("floatingElement"),H.relatedTarget):!0)&&M(H)}function _(H){be(R,H.relatedTarget)||(j.openChangeTimeout.clear(),j.restTimeout.clear(),j.restTimeoutPending=!1)}const V=x?Te(R,"mouseout",_):void 0;return c?nn(Te(R,"mousemove",W,{once:!0}),Te(R,"mouseenter",W),Te(R,"mouseleave",I),V):nn(Te(R,"mouseenter",W),Te(R,"mouseleave",I),V)},[A,z,y,b,e,s,h,j,d,K,B,a,c,N,f,g,S,m,P,L,x]),i.useMemo(()=>{if(!s)return;function M(R){j.pointerType=R.pointerType}return{onPointerDown:M,onPointerEnter:M,onMouseMove(R){const{nativeEvent:W}=R,I=R.currentTarget,_=e.select("domReferenceElement"),V=e.select("open"),H=K(_,I,R.target);if(a&&!Cn(j.pointerType))return;if(V&&H&&j.handleCloseOptions?.blockPointerEvents){const J=e.select("floatingElement");if(J){const se=j.handleCloseOptions?.getScope?.()??I.ownerDocument.body;mc(j,{scopeElement:se,referenceElement:I,floatingElement:J})}}const Y=Ji(N.current);if(V&&!H||Y===0||!H&&j.restTimeoutPending&&R.movementX**2+R.movementY**2<2)return;j.restTimeout.clear();function le(){if(j.restTimeoutPending=!1,B())return;const J=e.select("open");!j.blockMouseMove&&(!J||H)&&L()&&e.setOpen(!0,Fe(ut,W,I))}j.pointerType==="touch"?gn.flushSync(()=>{le()}):H&&V?le():(j.restTimeoutPending=!0,j.restTimeout.start(Y,le))}}},[s,j,B,K,a,e,N,L])}const ha=.1,Zp=ha*ha,Be=.5;function er(e,t,s,r,o,a){return r>=t!=a>=t&&e<=(o-s)*(t-r)/(a-r)+s}function tr(e,t,s,r,o,a,l,c,f,u){let d=!1;return er(e,t,s,r,o,a)&&(d=!d),er(e,t,o,a,l,c)&&(d=!d),er(e,t,l,c,f,u)&&(d=!d),er(e,t,f,u,s,r)&&(d=!d),d}function Qp(e,t,s){return e>=s.x&&e<=s.x+s.width&&t>=s.y&&t<=s.y+s.height}function nr(e,t,s,r,o,a){const l=Math.min(s,o),c=Math.max(s,o),f=Math.min(r,a),u=Math.max(r,a);return e>=l&&e<=c&&t>=f&&t<=u}function hc(e={}){const{blockPointerEvents:t=!1}=e,s=new At,r=({x:o,y:a,placement:l,elements:c,onClose:f,nodeId:u,tree:d})=>{const m=l?.split("-")[0];let k=!1,v=null,x=null,y=typeof performance<"u"?performance.now():0;function p(j,C){const h=performance.now(),b=h-y;if(v===null||x===null||b===0)return v=j,x=C,y=h,!1;const N=j-v,S=C-x,T=N*N+S*S,P=b*b*Zp;return v=j,x=C,y=h,T<P}function g(){s.clear(),f()}return function(C){s.clear();const h=c.domReference,b=c.floating;if(!h||!b||m==null||o==null||a==null)return;const{clientX:N,clientY:S}=C,T=kt(C),P=C.type==="mouseleave",B=be(b,T),L=be(h,T);if(B&&(k=!0,!P))return;if(L&&(k=!1,!P)){k=!0;return}if(P&&Ze(C.relatedTarget)&&be(b,C.relatedTarget))return;function K(){return!!(d&&En(d.nodesRef.current,u).length>0)}function A(){K()||g()}if(K())return;const z=h.getBoundingClientRect(),M=b.getBoundingClientRect(),R=o>M.right-M.width/2,W=a>M.bottom-M.height/2,I=M.width>z.width,_=M.height>z.height,V=(I?z:M).left,H=(I?z:M).right,Y=(_?z:M).top,le=(_?z:M).bottom;if(m==="top"&&a>=z.bottom-1||m==="bottom"&&a<=z.top+1||m==="left"&&o>=z.right-1||m==="right"&&o<=z.left+1){A();return}let J=!1;switch(m){case"top":J=nr(N,S,V,z.top+1,H,M.bottom-1);break;case"bottom":J=nr(N,S,V,M.top+1,H,z.bottom-1);break;case"left":J=nr(N,S,M.right-1,le,z.left+1,Y);break;case"right":J=nr(N,S,z.right-1,le,M.left+1,Y);break}if(J)return;if(k&&!Qp(N,S,z)){A();return}if(!P&&p(N,S)){A();return}let se=!1;switch(m){case"top":{const Z=I?Be/2:Be*4,re=I||R?o+Z:o-Z,we=I?o-Z:R?o+Z:o-Z,D=a+Be+1,$=R||I?M.bottom-Be:M.top,ee=R?I?M.bottom-Be:M.top:M.bottom-Be;se=tr(N,S,re,D,we,D,M.left,$,M.right,ee);break}case"bottom":{const Z=I?Be/2:Be*4,re=I||R?o+Z:o-Z,we=I?o-Z:R?o+Z:o-Z,D=a-Be,$=R||I?M.top+Be:M.bottom,ee=R?I?M.top+Be:M.bottom:M.top+Be;se=tr(N,S,re,D,we,D,M.left,$,M.right,ee);break}case"left":{const Z=_?Be/2:Be*4,re=_||W?a+Z:a-Z,we=_?a-Z:W?a+Z:a-Z,D=o+Be+1,$=W||_?M.right-Be:M.left,ee=W?_?M.right-Be:M.left:M.right-Be;se=tr(N,S,$,M.top,ee,M.bottom,D,re,D,we);break}case"right":{const Z=_?Be/2:Be*4,re=_||W?a+Z:a-Z,we=_?a-Z:W?a+Z:a-Z,D=o-Be,$=W||_?M.left+Be:M.right,ee=W?_?M.left+Be:M.right:M.left+Be;se=tr(N,S,D,re,D,we,$,M.top,ee,M.bottom);break}}se?k||s.start(40,A):A()}};return r.__options={...e,blockPointerEvents:t},r}const bc=i.createContext(void 0);function em(){const e=i.useContext(bc);if(e===void 0)throw new Error(Mt(26));return e}const tm="ArrowUp",nm="ArrowDown",sm="ArrowLeft",rm="ArrowRight",om="Home",im="End",vc=new Set([tm,nm,sm,rm,om,im]),am="--nested-dialogs",lm="data-nested-dialog-open",cm={...Tr,...Er,nestedDialogOpen(e){return e?{[lm]:""}:null}},um=i.forwardRef(function(t,s){const{render:r,className:o,style:a,finalFocus:l,initialFocus:c,...f}=t,u=Hn(),d=u.useState("descriptionElementId"),m=u.useState("disablePointerDismissal"),k=u.useState("floatingRootContext"),v=u.useState("popupProps"),x=u.useState("modal"),y=u.useState("mounted"),p=u.useState("nested"),g=u.useState("nestedOpenDialogCount"),j=u.useState("open"),C=u.useState("openMethod"),h=u.useState("titleElementId"),b=u.useState("transitionStatus"),N=u.useState("role"),S=k.useState("floatingId");em(),Ls({open:j,ref:u.context.popupRef,onComplete(){j&&u.context.onOpenChangeComplete?.(!0)}});const T=c===void 0?oc(u.context.popupRef):c,P=g>0,B=u.useStateSetter("popupElement"),K=yt("div",t,{state:{open:j,nested:p,transitionStatus:b,nestedDialogOpen:P},props:[v,{id:S,"aria-labelledby":h,"aria-describedby":d,role:N,...oi,hidden:!y,onKeyDown(A){vc.has(A.key)&&A.stopPropagation()},style:{[am]:g}},f],ref:[s,u.context.popupRef,B],stateAttributesMapping:cm});return n.jsx(sc,{context:k,openInteractionType:C,disabled:!y,closeOnFocusOut:!m,initialFocus:T,returnFocus:l,modal:x!==!1,restoreFocus:"popup",children:K})});function yc(e){return qo(19)?e:e?"true":void 0}const kc=i.forwardRef(function(t,s){const{cutout:r,...o}=t;let a;if(r){const l=r.getBoundingClientRect();a=`polygon(0% 0%,100% 0%,100% 100%,0% 100%,0% 0%,${l.left}px ${l.top}px,${l.left}px ${l.bottom}px,${l.right}px ${l.bottom}px,${l.right}px ${l.top}px,${l.left}px ${l.top}px)`}return n.jsx("div",{ref:s,role:"presentation","data-base-ui-inert":"",...o,style:{position:"fixed",inset:0,userSelect:"none",WebkitUserSelect:"none",clipPath:a}})}),dm=i.forwardRef(function(t,s){const{keepMounted:r=!1,...o}=t,a=Hn(),l=a.useState("mounted"),c=a.useState("modal"),f=a.useState("open");return l||r?n.jsx(bc.Provider,{value:r,children:n.jsxs(Ql,{ref:s,...o,children:[l&&c===!0&&n.jsx(kc,{ref:a.context.internalBackdropRef,inert:yc(!f)}),t.children]})}):null});let ba={},va={},ya="";function Lr(e,t){return cu(e)?e:t}function ka(e,t,s){return/hidden|clip/.test(e.getComputedStyle(Lr(t,s)).overflowY)}function fm(e){if(typeof document>"u")return!1;const t=We(e);return xn(t).innerWidth-t.documentElement.clientWidth>0}function pm(e){if(!(typeof CSS<"u"&&CSS.supports&&CSS.supports("scrollbar-gutter","stable"))||typeof document>"u")return!1;const s=We(e),r=s.documentElement,o=s.body,a=Lr(r,o),l=a.style.overflowY,c=r.style.scrollbarGutter;r.style.scrollbarGutter="stable",a.style.overflowY="scroll";const f=a.offsetWidth;a.style.overflowY="hidden";const u=a.offsetWidth;return a.style.overflowY=l,r.style.scrollbarGutter=c,f===u}function mm(e){const t=We(e),s=t.documentElement,r=t.body,o=Lr(s,r),a={overflowY:o.style.overflowY,overflowX:o.style.overflowX};return Object.assign(o.style,{overflowY:"hidden",overflowX:"hidden"}),()=>{Object.assign(o.style,a)}}function gm(e){const t=We(e),s=t.documentElement,r=t.body,o=xn(s);let a=0,l=0,c=!1;const f=ht.create();if(Un&&(o.visualViewport?.scale??1)!==1)return()=>{};function u(){const v=o.getComputedStyle(s),x=o.getComputedStyle(r),g=(v.scrollbarGutter||"").includes("both-edges")?"stable both-edges":"stable";a=s.scrollTop,l=s.scrollLeft,ba={scrollbarGutter:s.style.scrollbarGutter,overflowY:s.style.overflowY,overflowX:s.style.overflowX},ya=s.style.scrollBehavior,va={position:r.style.position,height:r.style.height,width:r.style.width,boxSizing:r.style.boxSizing,overflowY:r.style.overflowY,overflowX:r.style.overflowX,scrollBehavior:r.style.scrollBehavior};const j=s.scrollHeight>s.clientHeight,C=s.scrollWidth>s.clientWidth,h=v.overflowY==="scroll"||x.overflowY==="scroll",b=v.overflowX==="scroll"||x.overflowX==="scroll",N=Math.max(0,o.innerWidth-r.clientWidth),S=Math.max(0,o.innerHeight-r.clientHeight),T=parseFloat(x.marginTop)+parseFloat(x.marginBottom),P=parseFloat(x.marginLeft)+parseFloat(x.marginRight),B=Lr(s,r);if(c=pm(e),c){s.style.scrollbarGutter=g,B.style.overflowY="hidden",B.style.overflowX="hidden";return}Object.assign(s.style,{scrollbarGutter:g,overflowY:"hidden",overflowX:"hidden"}),(j||h)&&(s.style.overflowY="scroll"),(C||b)&&(s.style.overflowX="scroll"),Object.assign(r.style,{position:"relative",height:T||S?`calc(100dvh - ${T+S}px)`:"100dvh",width:P||N?`calc(100vw - ${P+N}px)`:"100vw",boxSizing:"border-box",overflowY:"hidden",overflowX:"hidden",scrollBehavior:"unset"}),r.scrollTop=a,r.scrollLeft=l,s.setAttribute("data-base-ui-scroll-locked",""),s.style.scrollBehavior="unset"}function d(){Object.assign(s.style,ba),Object.assign(r.style,va),c||(s.scrollTop=a,s.scrollLeft=l,s.removeAttribute("data-base-ui-scroll-locked"),s.style.scrollBehavior=ya)}function m(){d(),f.request(u)}u();const k=Te(o,"resize",m);return()=>{f.cancel(),d(),typeof o.removeEventListener=="function"&&k()}}class xm{lockCount=0;restore=null;timeoutLock=At.create();timeoutUnlock=At.create();acquire(t){return this.lockCount+=1,this.lockCount===1&&this.restore===null&&this.timeoutLock.start(0,()=>this.lock(t)),this.release}release=()=>{this.lockCount-=1,this.lockCount===0&&this.restore&&this.timeoutUnlock.start(0,this.unlock)};unlock=()=>{this.lockCount===0&&this.restore&&(this.restore?.(),this.restore=null)};lock(t){if(this.lockCount===0||this.restore!==null)return;const s=We(t),r=s.documentElement,o=s.body,a=xn(r);if(ka(a,r,o)){const c=new a.MutationObserver(()=>{ka(a,r,o)||(c.disconnect(),this.restore=null,this.lock(t))}),f={attributes:!0};c.observe(r,f),c.observe(o,f),this.restore=()=>c.disconnect();return}const l=Ar||!fm(t);this.restore=l?mm(t):gm(t)}}const hm=new xm;function jc(e=!0,t=null){pe(()=>{if(e)return hm.acquire(t)},[e,t])}function bm({store:e,parentContext:t,isDrawer:s}){const r=e.useState("open"),o=e.useState("mounted"),a=e.useState("disablePointerDismissal"),l=e.useState("modal"),c=e.useState("popupElement"),f=e.useState("floatingRootContext"),[u,d]=i.useState(0),[m,k]=i.useState(0),v=u===0,x=si(f,{outsidePressEvent(){return e.context.internalBackdropRef.current||e.context.backdropRef.current?"intentional":{mouse:l==="trap-focus"?"sloppy":"intentional",touch:"sloppy"}},outsidePress(y){if(!e.context.outsidePressEnabledRef.current||"button"in y&&y.button!==0)return!1;if("touches"in y){if(y.type==="touchend"){if(y.changedTouches.length!==1||y.touches.length!==0)return!1}else if(y.touches.length!==1)return!1}const p=kt(y);if(v&&!a){if(l){const g=e.context.internalBackdropRef.current,j=e.context.backdropRef.current;return g||j?g===p||j===p||be(p,c)&&!p?.hasAttribute("data-base-ui-portal"):!0}return!0}return!1},escapeKey:v});return jc(r&&l===!0,c),e.useContextCallback("onNestedDialogOpen",(y,p)=>{!e.select("open")&&!e.select("mounted")||(d(y),k(p))}),pe(()=>{!r&&!o&&(d(0),k(0))},[r,o]),pe(()=>(t?.onNestedDialogOpen&&r&&t.onNestedDialogOpen(u+1,m+(s?1:0)),()=>{t?.onNestedDialogOpen&&r&&t.onNestedDialogOpen(0,0)}),[s,r,u,m,t]),di(e,{activeTriggerProps:x.reference,inactiveTriggerProps:x.trigger,popupProps:x.floating,nestedOpenDialogCount:u,nestedOpenDrawerCount:m}),null}const vm={...ns,modal:e=>e.modal,nested:e=>e.nested,nestedOpenDialogCount:e=>e.nestedOpenDialogCount,nestedOpenDrawerCount:e=>e.nestedOpenDrawerCount,disablePointerDismissal:e=>e.disablePointerDismissal,openMethod:e=>e.openMethod,descriptionElementId:e=>e.descriptionElementId,titleElementId:e=>e.titleElementId,viewportElement:e=>e.viewportElement,role:e=>e.role};class ym extends _r{constructor(t,s,r){const o=new fi,a=km(t,o,s,r);super(a,jm(o),vm)}setOpen=(t,s)=>{s.preventUnmountOnClose=()=>{this.set("preventUnmountingOnClose",!0)},!t&&s.trigger==null&&this.state.activeTriggerId!=null&&(s.trigger=this.state.activeTriggerElement??void 0),this.context.onOpenChange?.(t,s),!s.isCanceled&&(this.state.floatingRootContext.dispatchOpenChange(t,s),this.update(li(this.state,t,s.trigger)))}}function km(e,t,s,r=!1){return{...mi(t,s,r),modal:!0,disablePointerDismissal:!1,viewportElement:null,descriptionElementId:void 0,titleElementId:void 0,openMethod:null,nested:!1,nestedOpenDialogCount:0,nestedOpenDrawerCount:0,role:"dialog",...e}}function jm(e){return{popupRef:i.createRef(),backdropRef:i.createRef(),internalBackdropRef:i.createRef(),outsidePressEnabledRef:{current:!0},triggerElements:e,onOpenChange:void 0,onOpenChangeComplete:void 0}}function wm(e,t){const{children:s,open:r,defaultOpen:o=!1,onOpenChange:a,onOpenChangeComplete:l,disablePointerDismissal:c=!1,modal:f=!0,actionsRef:u,handle:d,triggerId:m,defaultTriggerId:k=null}=t,v=e==="drawer",x=f,y=c,p="dialog",g=Hn(!0),j=g!=null,C={modal:x,disablePointerDismissal:y,nested:j,role:p},h=ii((B,L)=>new ym({open:o,openProp:r,activeTriggerId:k,triggerIdProp:m,...C},B,L),!0);h.useControlledProp("openProp",r),h.useControlledProp("triggerIdProp",m),h.useSyncedValues(C),h.useContextCallback("onOpenChange",a),h.useContextCallback("onOpenChangeComplete",l);const b=h.useState("open"),N=h.useState("mounted"),S=h.useState("payload");lc(h,b),ci(h);const{forceUnmount:T}=ui(b,h);i.useImperativeHandle(u,()=>({unmount:T,close:()=>h.setOpen(!1,Fe(Jo))}),[T,h]);const P=b||N||d!=null;return n.jsxs(Cl.Provider,{value:h,children:[d&&n.jsx(ai,{handle:d,store:h}),P&&n.jsx(bm,{store:h,parentContext:g?.context,isDrawer:v}),typeof s=="function"?s({payload:S}):s]})}const Cm=Fr(function(t){return wm("dialog",t)}),Sm=i.forwardRef(function(t,s){const{render:r,className:o,style:a,id:l,...c}=t,f=Hn(),u=_s(l);return f.useSyncedValueWithCleanup("titleElementId",u),yt("h2",t,{ref:s,props:[{id:u},c]})});function Nm(e){const t=i.useRef(""),s=i.useCallback(o=>{o.defaultPrevented||(t.current=o.pointerType,e(o,o.pointerType))},[e]);return{onClick:i.useCallback(o=>{if(o.detail===0){e(o,"keyboard");return}"pointerType"in o?e(o,o.pointerType):e(o,t.current),t.current=""},[e]),onPointerDown:s}}function Em(e,t){const s=ye((a,l)=>{(typeof e=="function"?e():e)||t(l||(Ar?"touch":""))}),{onClick:r,onPointerDown:o}=Nm(s);return i.useMemo(()=>({onClick:r,onPointerDown:o}),[r,o])}function Ut({...e}){return n.jsx(Cm,{"data-slot":"dialog",...e})}function Tm({...e}){return n.jsx(dm,{"data-slot":"dialog-portal",...e})}function Rm({className:e,...t}){return n.jsx($f,{"data-slot":"dialog-overlay",className:U("fixed inset-0 isolate z-50 bg-black/10 duration-100 supports-backdrop-filter:backdrop-blur-xs data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0",e),...t})}function Wt({className:e,children:t,showCloseButton:s=!0,...r}){return n.jsxs(Tm,{children:[n.jsx(Rm,{}),n.jsxs(um,{"data-slot":"dialog-content",className:U("fixed top-1/2 left-1/2 z-50 grid w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-4 rounded-xl bg-popover p-4 text-sm text-popover-foreground ring-1 ring-foreground/10 duration-100 outline-none sm:max-w-sm data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",e),...r,children:[t,s&&n.jsxs(Rl,{"data-slot":"dialog-close",render:n.jsx(ke,{variant:"ghost",className:"absolute top-2 right-2",size:"icon-sm"}),children:[n.jsx(Ds,{}),n.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function Gt({className:e,...t}){return n.jsx("div",{"data-slot":"dialog-header",className:U("flex flex-col gap-2",e),...t})}function hi({className:e,showCloseButton:t=!1,children:s,...r}){return n.jsxs("div",{"data-slot":"dialog-footer",className:U("-mx-4 -mb-4 flex flex-col-reverse gap-2 rounded-b-xl border-t bg-muted/50 p-4 sm:flex-row sm:justify-end",e),...r,children:[s,t&&n.jsx(Rl,{render:n.jsx(ke,{variant:"outline"}),children:"Close"})]})}function Vt({className:e,...t}){return n.jsx(Sm,{"data-slot":"dialog-title",className:U("font-heading text-base leading-none font-medium",e),...t})}function Tn({className:e,...t}){return n.jsx(Ff,{"data-slot":"dialog-description",className:U("text-sm text-muted-foreground *:[a]:underline *:[a]:underline-offset-3 *:[a]:hover:text-foreground",e),...t})}function rt({children:e,htmlFor:t,hint:s,className:r}){return n.jsxs("label",{htmlFor:t,className:U("text-muted-foreground mb-1 flex items-baseline gap-1.5 text-[10.5px] font-semibold tracking-[0.1em] uppercase",r),children:[e,s&&n.jsx("span",{className:"normal-case tracking-normal opacity-70",children:s})]})}const wc="w-full rounded-md border border-input bg-transparent px-2.5 py-1.5 text-[12.5px] text-foreground transition-colors outline-none placeholder:text-muted-foreground/55 focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/35 disabled:cursor-not-allowed disabled:opacity-50 dark:bg-input/25",Ke=i.forwardRef(function({className:t,...s},r){return n.jsx("input",{ref:r,className:U(wc,t),...s})});function As({className:e,children:t,...s}){return n.jsxs("div",{className:"relative",children:[n.jsx("select",{className:U(wc,"bg-surface-2 dark:bg-input/40 cursor-pointer appearance-none pr-7",e),...s,children:t}),n.jsx(ls,{className:"text-muted-foreground pointer-events-none absolute top-1/2 right-2 size-3.5 -translate-y-1/2"})]})}function Ns({children:e,className:t}){return n.jsx("p",{className:U("text-muted-foreground/75 mt-1 text-[10.5px] leading-snug",t),children:e})}function Pm(){const{newConvOpen:e,setNewConvOpen:t,newConvEnv:s,newConvCwd:r,envRows:o,createConversation:a,creating:l,createError:c,conversations:f}=Ye(),[u,d]=i.useState(""),[m,k]=i.useState(""),[v,x]=i.useState("");i.useEffect(()=>{if(!e)return;const S=s??o[0]?.name??"";d(S),k(r??""),x("")},[e,s,r,o]);const y=o.find(S=>S.name===u),p=y?.workspaces??[],g=y?.cwd??y?.status?.cwd??"",j=m.trim()||g,C=p.find(S=>S.cwd===j.replace(/\/+$/,""))??p[0],h=y?.status?!y.status.ok:!1,b=f.filter(S=>S.env===u).length,N=async()=>{if(!u||l)return;await a(u,m.trim()||void 0,v.trim()||void 0)!==null&&t(!1)};return n.jsx(Ut,{open:e,onOpenChange:S=>t(S),children:n.jsxs(Wt,{className:"sm:max-w-md",children:[n.jsxs(Gt,{children:[n.jsxs(Vt,{className:"flex items-center gap-2",children:[n.jsx(pn,{className:"text-brand size-4"}),"新建会话"]}),n.jsx(Tn,{className:"text-[11.5px] leading-relaxed",children:"每个会话绑定一个环境,agent 的工具调用全部在那个环境里执行。 在别的会话里跑着的任务切走后也会继续,左栏会显示运行中。"})]}),n.jsxs("div",{className:"flex flex-col gap-3",children:[n.jsxs("div",{children:[n.jsx(rt,{htmlFor:"nc-env",children:"环境"}),n.jsxs(As,{id:"nc-env",value:u,onChange:S=>d(S.target.value),children:[o.length===0&&n.jsx("option",{value:"",children:"没有可用环境"}),o.map(S=>n.jsxs("option",{value:S.name,children:[S.label," · ",S.runtime==="docker"?"容器":"主机",S.status&&!S.status.ok?"(离线)":""]},S.name))]}),y&&n.jsxs(Ns,{className:"flex items-center gap-1.5",children:[n.jsx(ss,{tone:h?"bad":y.status?"ok":"warn",size:"sm"}),h?n.jsx("span",{className:"text-bad",children:y.status?.error??"离线"}):y.status?.opMs!==void 0?n.jsxs("span",{className:"pg-num",children:["往返 ",Math.round(y.status.opMs),"ms",y.status.latencyGrade?` · ${y.status.latencyGrade}`:"",y.status.os?` · ${y.status.os}/${y.status.arch??"?"}`:""]}):n.jsx("span",{children:"尚未探测"}),b>0&&n.jsxs("span",{className:"opacity-70",children:["· 已有 ",b," 个会话"]})]})]}),n.jsxs("div",{children:[n.jsx(rt,{htmlFor:"nc-cwd",hint:"(可选)",children:"工作目录"}),p.length>0&&n.jsx("div",{className:"mb-1.5 flex flex-wrap gap-1",children:p.map(S=>{const T=(m.trim()||g)===S.cwd;return n.jsx("button",{type:"button",onClick:()=>k(S.cwd),className:U("rounded border px-2 py-0.5 font-mono text-[10.5px] transition-colors",T?"border-brand bg-brand/12 text-foreground":"border-line bg-surface-2/60 text-muted-foreground hover:text-foreground"),title:S.cwd,children:S.name||S.cwd},S.cwd)})}),n.jsx(Ke,{id:"nc-cwd",value:m,onChange:S=>k(S.target.value),placeholder:g||"/path/on/remote",className:"pg-num font-mono"}),n.jsx(Ns,{children:C?.model?n.jsxs(n.Fragment,{children:["将继承目录默认模型 ",n.jsxs("code",{className:"pg-num text-foreground/80",children:[C.model.provider,"/",C.model.modelId]}),C.thinkingLevel?` (${C.thinkingLevel})`:""]}):g?n.jsxs(n.Fragment,{children:["留空则用默认目录 ",n.jsx("code",{className:"pg-num text-foreground/70",children:g})]}):"该环境没有配置默认目录,建议填一个绝对路径"})]}),n.jsxs("div",{children:[n.jsx(rt,{htmlFor:"nc-title",hint:"(可选)",children:"标签标题"}),n.jsx(Ke,{id:"nc-title",value:v,onChange:S=>x(S.target.value),placeholder:y?.label??"环境名"}),n.jsx(Ns,{children:"留空则发出第一条消息时自动起名;之后可用 /name 改。"})]}),h&&n.jsxs("p",{className:"text-warn bg-warn/8 border-warn/25 flex items-start gap-1.5 rounded border px-2 py-1.5 text-[11px] leading-snug",children:[n.jsx(vt,{className:"mt-px size-3 shrink-0"}),"这个环境现在探测不通。会话还是能建,但发出去的消息不会有回应, 直到远端恢复。"]}),c&&n.jsxs("p",{className:"text-bad bg-bad/8 border-bad/25 flex items-start gap-1.5 rounded border px-2 py-1.5 text-[11px] leading-snug",children:[n.jsx(vt,{className:"mt-px size-3 shrink-0"}),c]})]}),n.jsxs(hi,{children:[n.jsx(ke,{variant:"ghost",size:"sm",onClick:()=>t(!1),disabled:l,children:"取消"}),n.jsxs(ke,{size:"sm",onClick:N,disabled:!u||l,className:U("gap-1.5",!u||l?"":"bg-brand text-primary-foreground hover:bg-brand/85"),children:[l?n.jsx(at,{className:"size-3.5 animate-spin"}):n.jsx(pn,{className:"size-3.5"}),l?"创建中":"创建并打开"]})]})]})})}const Ft="sshcfg:";function Zn(e){return e.toLowerCase().replace(/[^a-z0-9_-]+/g,"-").replace(/^[^a-z0-9]+|-+$/g,"").slice(0,32)}const ja=[{kind:"local-host",title:"本机",subtitle:"直接在这台机器上运行 agent",icon:Tu},{kind:"ssh-host",title:"远端主机",subtitle:"通过 SSH 连接,agent 的工具在那台机器上执行",icon:Ru},{kind:"ssh-docker",title:"远端容器",subtitle:"SSH 到主机后进入 Docker 容器执行",icon:zs}],Om=/^[a-z0-9][a-z0-9_-]{0,31}$/;function Im(e,t){const s={};for(const r of e.split(/\r?\n/)){const o=r.trim();if(!o||o.startsWith("#"))continue;const a=o.indexOf("=");if(a<=0)continue;const l=o.slice(0,a).trim(),c=o.slice(a+1).trim();l&&(s[l]=c)}return t&&(s.GIT_CONFIG_NOSYSTEM="1"),Object.keys(s).length>0?s:void 0}function Am(e){if(!e)return{text:"",noSystemGit:!1};const t=e.GIT_CONFIG_NOSYSTEM==="1";return{text:Object.entries(e).filter(([r])=>r!=="GIT_CONFIG_NOSYSTEM").map(([r,o])=>`${r}=${o}`).join(`
2
+ `),noSystemGit:t}}function Mm(){const{addEnvOpen:e,setAddEnvOpen:t,editEnvTarget:s,addEnvInitialHost:r,hostRows:o,reloadBootstrap:a,setSelectedEnv:l,probeEnv:c,bootstrap:f,notify:u}=Ye(),d=!!s,m=f?.localOnly??!0,[k,v]=i.useState("ssh-host"),[x,y]=i.useState(""),[p,g]=i.useState("__new__"),[j,C]=i.useState(""),[h,b]=i.useState(""),[N,S]=i.useState(""),[T,P]=i.useState(""),[B,L]=i.useState(""),[K,A]=i.useState(""),[z,M]=i.useState(""),[R,W]=i.useState(""),[I,_]=i.useState(""),[V,H]=i.useState(""),[Y,le]=i.useState(""),[J,se]=i.useState(""),[Z,re]=i.useState(""),[we,D]=i.useState(!1),[$,ee]=i.useState([]),[G,fe]=i.useState(!1),[te,ae]=i.useState(null),[ce,je]=i.useState(null),$e=i.useRef(!1),[Q,ve]=i.useState(null),ue=async()=>{const F=K.trim();if(!Ie||!F){ve(null);return}if(p==="__new__"||p.startsWith(Ft)||p==="local"){ve(null);return}ve({state:"checking"});try{const oe=await ie.listContainers(p),he=oe.containers.find(Se=>Se.name===F||Se.id===F||Se.id.startsWith(F));ve(he?{state:"ok",detail:`${he.name} · ${he.status}`}:{state:"missing",detail:oe.containers.map(Se=>Se.name).slice(0,6).join(" / ")})}catch(oe){ve({state:"error",detail:oe instanceof Error?oe.message:String(oe)})}};i.useEffect(()=>{ve(null)},[K,p,k]);const Ce=i.useMemo(()=>o.filter(F=>F.type==="ssh"),[o]),Ae=k==="ssh-host"||k==="ssh-docker",Ie=k==="ssh-docker",X=Om.test(x.trim()),ne=X&&(!Ie||!!K.trim())&&(Ae?!!p:!0),Pe=i.useMemo(()=>{if(!p.startsWith(Ft))return null;const F=p.slice(Ft.length);return $.find(oe=>oe.alias===F)??{alias:F}},[p,$]);i.useEffect(()=>{if(!e||!m){e||ee([]);return}let F=!1;return ie.sshConfigHosts().then(oe=>{F||ee(oe.hosts??[])}).catch(()=>{F||ee([])}),()=>{F=!0}},[e,m]),i.useEffect(()=>{if(!e){$e.current=!1;return}if($e.current)return;if($e.current=!0,je(null),ae(null),s){v(s.kind),y(s.name);const oe=o.find(Se=>Se.name===s.host);s.hostType==="ssh"?(g(oe?oe.name:"__new__"),C(s.host),b(oe?.config?.host??s.config?.host??""),S(oe?.config?.user??s.config?.user??""),P(oe?.config?.port?String(oe.config.port):s.config?.port?String(s.config.port):""),L(oe?.config?.identityFile??s.config?.identityFile??"")):(g("local"),C(""),b(""),S(""),P(""),L("")),A(s.config?.container??""),M(s.config?.containerUser??""),W(s.cwd??s.config?.cwd??""),_(s.config?.binDir??""),H(s.config?.daemonPath??""),le(s.fsGroup??s.config?.fsGroup??""),se(s.description??s.config?.description??"");const he=Am(s.config?.shellEnv);re(he.text),D(he.noSystemGit);return}const F=r?o.find(oe=>oe.name===r):void 0;F?.type==="local"?(v("local-host"),g("local")):F?.type==="ssh"?(v("ssh-docker"),g(F.name)):(v("local-host"),g("local")),y(""),C(""),b(""),S(""),P(""),L(""),A(""),M(""),W(""),_(""),H(""),le(""),se(""),re(""),D(!1)},[e,s,r,o,Ce]);const Ne=async F=>{if(p.startsWith(Ft)){const oe=p.slice(Ft.length),he=Ce.find(qe=>qe.config?.host===oe&&!qe.config?.user&&!qe.config?.port&&!qe.config?.identityFile);if(he)return g(he.name),he.name;let Se=Zn(oe)||Zn(F??"")||"ssh-host";Se==="local"&&(Se="ssh-host");const De=new Set(o.map(qe=>qe.name));let Ve=Se;if(De.has(Ve))for(let qe=2;qe<100;qe++){const Xe=`${Se.slice(0,28)}-${qe}`;if(!De.has(Xe)){Ve=Xe;break}}return await ie.saveHost(Ve,{type:"ssh",host:oe}),g(Ve),Ve}if(p==="__new__"){const oe=h.trim();if(!oe)throw new Error("请先填写新 SSH 主机地址(Host / IP / SSH Alias)");const he=j.trim();let Se=Zn(he||(F??"")||oe)||"ssh-host";Se==="local"&&(Se="ssh-host");const De=new Set(o.map(Xe=>Xe.name));let Ve=Se;if(!he&&De.has(Ve))for(let Xe=2;Xe<100;Xe++){const lt=`${Se.slice(0,28)}-${Xe}`;if(!De.has(lt)){Ve=lt;break}}const qe={type:"ssh",host:oe,user:N.trim()||void 0,port:T.trim()?Number(T):void 0,identityFile:B.trim()||void 0};return await ie.saveHost(Ve,qe),g(Ve),Ve}return p},Re=async F=>{F.preventDefault(),je(null),fe(!0),ae("正在保存配置…");try{const oe=x.trim(),Se={hostName:Ae?await Ne(oe):"local",runtime:Ie?"docker":"host",container:Ie?K.trim():void 0,containerUser:Ie&&z.trim()?z.trim():void 0,cwd:R.trim()||void 0,binDir:I.trim()||void 0,daemonPath:V.trim()||void 0,fsGroup:Y.trim()||void 0,description:J.trim()||void 0,shellEnv:Im(Z,we),probe:!1};if(await ie.saveEnvironment(oe,Se),a(),l(oe),!d&&Ie){ae("正在向容器部署 pi-env 守护进程…");try{await ie.deployEnvironment(oe)}catch(De){u({tone:"warn",title:`环境 ${oe} 已保存,但容器守护自动部署未完成`,detail:`${De instanceof Error?De.message:String(De)}(可在环境菜单中点击“部署”)`})}}ae(null),t(!1),c(oe)}catch(oe){ae(null),je(oe instanceof Error?oe.message:String(oe))}finally{fe(!1)}},He=Ae&&(p==="__new__"||p.startsWith(Ft)||Ce.some(F=>F.name===p))?p:"__new__",Ge=F=>{if(v(F),F==="local-host"){g("local");return}if(!(p==="__new__"||p.startsWith(Ft)||Ce.some(he=>he.name===p)))if(Ce.length>0)g(Ce[0].name);else if($.length>0){const he=$[0].alias;if(g(`${Ft}${he}`),!d&&!x.trim()){const Se=Zn(he);Se&&y(Se)}}else g("__new__")},_e=F=>{if(g(F),!d&&F.startsWith(Ft)&&!x.trim()){const oe=F.slice(Ft.length),he=Zn(oe);he&&y(he)}};return n.jsx(Ut,{open:e,onOpenChange:F=>!F&&t(!1),children:n.jsxs(Wt,{className:"flex max-h-[88vh] w-[560px] max-w-[calc(100vw-2rem)] flex-col gap-0 p-0 sm:max-w-[560px]",children:[n.jsx(Gt,{className:"border-line border-b px-5 py-3 text-left",children:n.jsx(Vt,{className:"text-[15px] font-semibold",children:d?`编辑环境 · ${s?.name}`:"添加环境"})}),ce&&n.jsxs("div",{className:"border-bad/35 bg-bad/10 text-bad mx-5 mt-3 flex items-start gap-1.5 rounded-md border px-2.5 py-2 text-xs break-words",children:[n.jsx(Mi,{className:"mt-px size-3.5 shrink-0"}),n.jsx("span",{className:"min-w-0",children:ce})]}),!m&&n.jsx("div",{className:"border-warn/40 bg-warn/10 text-warn mx-5 mt-3 rounded-md border px-2.5 py-2 text-xs",children:"服务不是以本机回环地址启动,写配置可能被安全策略拒绝。"}),n.jsxs("form",{onSubmit:Re,className:"flex min-h-0 flex-1 flex-col",children:[n.jsxs("div",{className:"pg-scroll-y min-h-0 flex-1 space-y-4 px-5 py-4",children:[!d&&n.jsxs("div",{children:[n.jsx("div",{className:"border-line-strong grid grid-cols-3 overflow-hidden rounded-lg border",children:ja.map(F=>{const oe=F.icon,he=k===F.kind;return n.jsxs("button",{type:"button",onClick:()=>Ge(F.kind),"aria-pressed":he,className:U("flex h-9 items-center justify-center gap-1.5 text-[12px] transition-colors",he?"bg-surface-3 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"),children:[n.jsx(oe,{className:"size-3.5"}),F.title]},F.kind)})}),n.jsx("p",{className:"text-muted-foreground mt-1.5 text-[12px]",children:ja.find(F=>F.kind===k)?.subtitle})]}),n.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[n.jsxs("div",{children:[n.jsx(rt,{className:"mb-1",children:"环境代号"}),n.jsx(Ke,{value:x,onChange:F=>y(F.target.value.toLowerCase()),onBlur:()=>y(F=>Zn(F)),placeholder:"api-box",disabled:d,autoFocus:!d,"aria-invalid":x.length>0&&!X}),x.length>0&&!X&&n.jsx("p",{className:"text-bad mt-1 text-[11px]",children:"仅限小写字母、数字、- 和 _,以字母或数字开头,最多 32 位"})]}),n.jsxs("div",{children:[n.jsxs(rt,{className:"mb-1",children:["工作目录 ",n.jsx("span",{className:"text-muted-foreground/60 font-normal",children:"选填"})]}),n.jsx(Ke,{value:R,onChange:F=>W(F.target.value),placeholder:"/workspace/app",className:"pg-num font-mono"})]})]}),Ae&&n.jsxs("div",{className:"space-y-2",children:[n.jsxs(rt,{className:"mb-1 flex items-center gap-1",children:["SSH 主机",n.jsx("span",{title:"首次连接时会扫描并确认主机指纹,然后自动探测连通性",className:"text-muted-foreground/60 inline-flex",children:n.jsx(Es,{className:"size-3"})})]}),n.jsxs(As,{value:He,onChange:F=>_e(F.target.value),children:[Ce.length>0&&n.jsx("optgroup",{label:"已保存的主机",children:Ce.map(F=>n.jsxs("option",{value:F.name,children:[F.label," (",F.name,")"]},F.name))}),$.length>0&&n.jsx("optgroup",{label:"复用 ~/.ssh/config",children:$.map(F=>{const oe=`${F.user?`${F.user}@`:""}${F.hostName??""}`;return n.jsxs("option",{value:`${Ft}${F.alias}`,children:[F.alias,oe?` (${oe})`:""]},F.alias)})}),n.jsx("option",{value:"__new__",children:"其他主机…"})]}),Pe&&n.jsxs("p",{className:"text-muted-foreground pg-num truncate text-[11px]",title:"连接参数、私钥与跳板机由 ssh 自动解析",children:[Pe.user?`${Pe.user}@`:"",Pe.hostName??Pe.alias,Pe.port?`:${Pe.port}`:"",Pe.proxyJump?` · ProxyJump ${Pe.proxyJump}`:""]}),He==="__new__"&&n.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[n.jsx("div",{className:"col-span-2",children:n.jsx(Ke,{value:h,onChange:F=>b(F.target.value),placeholder:"主机地址 / IP / ssh 别名","aria-label":"主机地址",required:!0})}),n.jsx(Ke,{value:N,onChange:F=>S(F.target.value),placeholder:"用户名(选填)","aria-label":"用户名"}),n.jsx(Ke,{value:T,onChange:F=>P(F.target.value),placeholder:"端口(默认 22)","aria-label":"端口"}),n.jsx(Ke,{value:j,onChange:F=>C(F.target.value),placeholder:"主机别名(选填,留空用环境代号)","aria-label":"主机别名",className:"col-span-2"})]})]}),Ie&&n.jsxs("div",{children:[n.jsx(rt,{className:"mb-1",children:"容器"}),n.jsxs("div",{className:"relative",children:[n.jsx(Ke,{value:K,onChange:F=>A(F.target.value),onBlur:()=>void ue(),placeholder:"my-dev-container",className:"pg-num pr-8 font-mono","aria-invalid":Q?.state==="missing"}),n.jsxs("span",{className:"absolute top-1/2 right-2.5 -translate-y-1/2",children:[Q?.state==="checking"&&n.jsx(at,{className:"text-muted-foreground size-3.5 animate-spin"}),Q?.state==="ok"&&n.jsx(Za,{className:"text-ok size-3.5"}),Q?.state==="missing"&&n.jsx(Mi,{className:"text-bad size-3.5"})]})]}),Q&&Q.state!=="checking"&&n.jsxs("p",{className:U("mt-1 text-[11px]",Q.state==="ok"?"text-ok":Q.state==="missing"?"text-bad":"text-muted-foreground"),title:Q.detail,children:[Q.state==="ok"&&`已找到 · ${Q.detail}`,Q.state==="missing"&&`主机上没有这个容器${Q.detail?`,现有:${Q.detail}`:""}`,Q.state==="error"&&`无法列出容器:${Q.detail}`]})]}),n.jsxs("details",{className:"group border-line rounded-lg border px-3 py-2",children:[n.jsxs("summary",{className:"text-muted-foreground hover:text-foreground flex cursor-pointer list-none items-center gap-1.5 text-[12px] font-medium select-none",children:[n.jsx(is,{className:"size-3.5 transition-transform group-open:rotate-90"}),"高级选项"]}),n.jsxs("div",{className:"mt-3 grid grid-cols-2 gap-x-3 gap-y-3",children:[Ie&&n.jsxs("div",{children:[n.jsx(rt,{className:"mb-1",children:"容器内运行用户"}),n.jsx(Ke,{value:z,onChange:F=>M(F.target.value),placeholder:"root"})]}),n.jsxs("div",{children:[n.jsx(rt,{className:"mb-1",children:"环境说明"}),n.jsx(Ke,{value:J,onChange:F=>se(F.target.value),placeholder:"供 ask_peer 参考"})]}),n.jsxs("div",{children:[n.jsx(rt,{className:"mb-1",children:"共享目录组"}),n.jsx(Ke,{value:Y,onChange:F=>le(F.target.value),placeholder:"同组环境共享写锁"})]}),n.jsxs("div",{children:[n.jsx(rt,{className:"mb-1",children:"守护进程路径"}),n.jsx(Ke,{value:V,onChange:F=>H(F.target.value),placeholder:Ie?"/opt/pi-foreman/pi-env":"自动探测",className:"pg-num font-mono"})]}),n.jsxs("div",{children:[n.jsx(rt,{className:"mb-1",children:"附加 PATH"}),n.jsx(Ke,{value:I,onChange:F=>_(F.target.value),placeholder:"/usr/local/bin",className:"pg-num font-mono"})]}),Ae&&He==="__new__"&&n.jsxs("div",{children:[n.jsx(rt,{className:"mb-1",children:"私钥"}),n.jsx(Ke,{value:B,onChange:F=>L(F.target.value),placeholder:"~/.ssh/id_ed25519",className:"pg-num font-mono"})]}),n.jsxs("div",{className:"col-span-2",children:[n.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[n.jsxs(rt,{className:"mb-0",children:["环境变量 ",n.jsx("span",{className:"text-muted-foreground/60 font-normal",children:"每行 KEY=VALUE"})]}),n.jsxs("label",{className:"text-muted-foreground flex cursor-pointer items-center gap-1.5 text-[11px]",children:[n.jsx("input",{type:"checkbox",checked:we,onChange:F=>D(F.target.checked)}),"忽略系统 Git 配置"]})]}),n.jsx("textarea",{value:Z,onChange:F=>re(F.target.value),rows:2,placeholder:"NODE_ENV=development",className:"border-input text-foreground focus-visible:border-ring focus-visible:ring-ring/35 w-full rounded-md border bg-transparent px-2.5 py-1.5 font-mono text-xs outline-none focus-visible:ring-2 dark:bg-input/25"})]})]})]})]}),n.jsxs("div",{className:"border-line flex h-13 shrink-0 items-center gap-3 border-t px-5",children:[te&&n.jsxs("span",{className:"text-muted-foreground flex min-w-0 items-center gap-1.5 text-[11px]",children:[n.jsx(at,{className:"size-3 animate-spin"}),n.jsx("span",{className:"truncate",children:te})]}),n.jsx("span",{className:"flex-1"}),n.jsx(ke,{type:"button",variant:"ghost",size:"sm",onClick:()=>t(!1),disabled:G,children:"取消"}),n.jsx(ke,{type:"submit",size:"sm",disabled:G||!ne,children:G?"处理中…":d?"保存":"创建环境"})]})]})]})})}function Mo(e,t){const s=[];for(const r of e){if(r.archived||r.conversationId===t)continue;const o=r.title?.trim();!o||o===r.env||o.startsWith(`${r.env}:`)||s.push({conversationId:r.conversationId,env:r.env,title:o})}return s}const $m=/(^|\s)@([^\s@,。;:!?、]+)/g;function Dm(e){const t=new Set;for(const s of e.matchAll($m)){const r=s[2].replace(/[.,!?;:]+$/,"");r&&t.add(r)}return[...t]}function zm(e,t){const s=e.indexOf("/"),r=s===-1?void 0:e.slice(0,s),o=s===-1?e:e.slice(s+1),a=t.filter(c=>c.title===o&&(!r||c.env===r));if(a.length===1)return{ok:!0,target:a[0]};const l=c=>c.map(f=>`@${f.env}/${f.title}`).join(" / ");if(a.length===0){const c=t.filter(u=>u.title===o);if(c.length>0)return{ok:!1,error:`环境 ${r??"?"} 下没有 @${o};可用:${l(c)}`};const f=t.map(u=>`@${u.title}`).join(" ");return{ok:!1,error:`没有名为 "${o}" 的会话。先在那个会话里用 /name 命名${f?`;现在可 @:${f}`:""}`}}return{ok:!1,error:`@${o} 有 ${a.length} 个同名会话,请用 @环境/标题 指定:${l(a)}`}}function Cc(e,t,s){const r=Dm(e);if(r.length===0)return{ok:!0,text:e,targets:[]};const o=[],a=[];for(const l of r){const c=zm(l,t);if(!c.ok)return c;if(c.target.env===s)return{ok:!1,error:`@${c.target.title} 和当前会话同在环境 ${s},直接在这里提问即可(ask_peer 只跨环境)`};o.push(c.target),a.push(`[@${c.target.title} = 环境 "${c.target.env}" 的会话 #${c.target.conversationId}]`)}return a.push("[以上 @名字 是另一个环境里正在运行的会话。请调用 ask_peer 工具(传 targetConversationId)向其提问,并把回答直接告诉我。]"),{ok:!0,text:`${e}
3
+
4
+ ──
5
+ ${a.join(`
6
+ `)}`,targets:o}}const Ms=["off","minimal","low","medium","high","xhigh","max"],bi=[{name:"login",args:"[provider]",summary:"登录模型 Provider(复用 ~/.pi/agent/auth.json)",kind:"picker"},{name:"logout",args:"[provider]",summary:"退出指定 Provider 登录",kind:"picker"},{name:"model",args:"[provider/id]",summary:"切换本会话的模型(支持跨 Provider)",kind:"picker"},{name:"thinking",args:"[级别]",summary:"设置思考强度",kind:"picker"},{name:"reload",summary:"热重载本地 Pi 扩展与模板",kind:"immediate"},{name:"new",args:"[环境]",summary:"新建会话",kind:"immediate"},{name:"resume",summary:"搜索并切换历史会话",kind:"picker"},{name:"name",args:"<名字>",summary:"给当前会话命名,之后可在别的会话里用 @名字 向它提问",kind:"prefix"},{name:"fork",summary:"从最新一条记录分叉出新会话",kind:"immediate"},{name:"compact",args:"[说明]",summary:"压缩上下文(异步任务)",kind:"prefix"},{name:"reset",args:"[交接摘要]",summary:"清空上下文(破坏性,需确认)",kind:"prefix",destructive:!0},{name:"abort",summary:"中止当前运行",kind:"immediate"},{name:"cd",args:"<路径>",summary:"改本会话的工作目录",kind:"prefix"},{name:"instructions",args:"<文本>",summary:"改本会话的系统指令",kind:"prefix"},{name:"exec",args:"<命令…>",summary:"直接在远端跑一条命令(!命令 进上下文 / !!命令 仅展示)",kind:"prefix"},{name:"skill",args:"<名称> [说明]",summary:"使用指定 Skill 处理当前任务",kind:"prefix"},{name:"ask",args:"<@名字> <问题…>",summary:"让本会话向 @ 的会话提问(等价于在消息里直接写 @名字)",kind:"prefix"},{name:"diff",summary:"打开文件面板的 git 视图",kind:"immediate"},{name:"usage",summary:"累计 token 摘要(按模型前三)",kind:"immediate"},{name:"help",summary:"显示命令列表",kind:"immediate"}],bo=new Set(bi.map(e=>e.name)),Fm=/^\/([A-Za-z][A-Za-z0-9._-]*)(?=\s|$)\s*([\s\S]*)$/;function Sc(e){const t=e.trimStart();if(t.startsWith("!!")&&t.length>2)return{name:"exec-local",args:t.slice(2).trim()};if(t.startsWith("!")&&t.length>1)return{name:"exec-ctx",args:t.slice(1).trim()};const s=Fm.exec(t);return s?{name:s[1],args:s[2].trim()}:null}function Nc(e){return Sc(e)!==null}function wa(e){return e instanceof Error?e.message:String(e)}const _m=[];function Lm(e,t,s={}){const r=Ye(),o=qa(),a=i.useRef(r);i.useEffect(()=>{a.current=r});const l=r.models?.models??_m,c=r.prompts,f=i.useRef(s.refocus);i.useEffect(()=>{f.current=s.refocus});const u=i.useCallback(x=>{setTimeout(()=>{o.composer.setText(`/${x} `,{origin:"external"}),f.current?.()},0)},[o]),d=i.useCallback(async(x,y)=>{const p=a.current,g=x.toLowerCase(),j=y.trim(),C=p.prompts.find(b=>b.name.toLowerCase()===g);if(C&&!bo.has(g)){const b=j?`${C.body}
7
+
8
+ ${j}`:C.body;await ie.sendMessage(e,b);return}if(!bo.has(g)){p.notify({tone:"bad",title:`未知命令 /${x}`,detail:"输入 /help 查看全部命令"});return}const h=b=>j?!1:(p.notify({tone:"warn",title:`/${g} 缺少参数`,detail:`用法:/${g} ${b}`}),!0);try{switch(g){case"help":p.setHelpOpen(!0);return;case"usage":{const b=await ie.usage(),N=b.totals,S=[...b.models].sort((T,P)=>P.totalTokens-T.totalTokens).slice(0,3);p.notify({tone:"brand",title:`累计 ${ts(N.totalTokens)} tokens${N.cost>0?` · 费用 ${N.cost.toFixed(2)}`:""}`,detail:[...S.map(T=>`${T.key} ${ts(T.totalTokens)}`),"上下文占用见输入框底部的 ctx 指示"].join(" · ")});return}case"diff":p.openFilesGit();return;case"login":p.openPicker("login",{...j?{loginProvider:j}:{},refocus:f.current});return;case"logout":{if(!j){p.openPicker("login",{refocus:f.current});return}await ie.logout(j),p.reloadModels(),p.notify({tone:"ok",title:`已退出 ${j} 登录`});return}case"reload":await p.reloadAll();return;case"new":p.openNewConv(j||t);return;case"resume":p.openPicker("resume",{refocus:f.current});return;case"name":{if(h("<会话标题>"))return;await p.renameConversationTitle(e,j),p.notify({tone:"ok",title:`会话已命名为 ${j}`,detail:"现在可以在别的会话里用 @"+j+" 向它提问"});return}case"abort":{const b=await ie.abort(e);p.notify({tone:b.ok?"ok":"warn",title:b.ok?`已请求中止会话 #${e}`:"中止请求未被接受"});return}case"compact":{const b=await ie.compact(e,j||void 0);p.notify({tone:b.ok?"brand":"bad",title:b.ok?"已发起上下文压缩":"压缩未被接受",detail:b.taskId!==void 0?`任务 #${b.taskId}`:void 0});return}case"skill":{if(h("<Skill名称> [补充说明]"))return;const[b,...N]=j.split(/\s+/),S=N.join(" ").trim(),T=S?`请先使用 read_skill 或 read 工具读取 Skill "${b}" 的完整规范并严格按其步骤执行:${S}`:`请先使用 read_skill 或 read 工具读取 Skill "${b}" 的完整说明,再结合当前上下文应用它。`;await ie.sendMessage(e,T);return}case"model":{if(!j){p.openPicker("model",{refocus:f.current});return}const b=p.models?.models??[],N=Bm(b,j);if(!N){p.notify({tone:"bad",title:`找不到已登录模型 "${j}"`,detail:"可输入 /model 打开列表,或 /login 登录新 Provider。"});return}const S=await ie.configure(e,{provider:N.provider,modelId:N.id,setAsDefault:!0});S.ok&&p.setModelOverride(e,N.provider,N.id),p.notify({tone:S.ok?"ok":"bad",title:S.ok?`已切换到 ${N.provider}/${N.id}`:"切换模型失败",detail:S.ok?"下一次生成生效":"服务端返回 ok=false"});return}case"thinking":{if(!j){p.openPicker("thinking",{refocus:f.current});return}const b=j.toLowerCase();if(!Ms.includes(b)){p.notify({tone:"bad",title:`无效的思考级别「${j}」`,detail:`可选:${Ms.join(" / ")}`});return}const N=await ie.configure(e,{thinkingLevel:b});N.ok&&p.setThinkingOverride(e,b),p.notify({tone:N.ok?"ok":"bad",title:N.ok?`思考级别已设为 ${b}`:"设置思考级别失败",detail:N.ok?"下一次生成生效":"服务端返回 ok=false"});return}case"ask":{if(h("<@名字> <问题…>"))return;const b=j.search(/\s/),N=(b===-1?j:j.slice(0,b)).replace(/^@/,""),S=b===-1?"":j.slice(b+1).trim();if(!S){p.notify({tone:"warn",title:"/ask 缺少问题",detail:"用法:/ask @名字 <问题>"});return}const T=Cc(`@${N} ${S}`,Mo(p.conversations,e),t);if(!T.ok){p.notify({tone:"warn",title:"无法解析 @会话",detail:T.error});return}await ie.sendMessage(e,T.text);return}case"exec-ctx":case"exec-local":case"exec":{if(h("<要执行的命令>"))return;const b=g==="exec-ctx",N=`exec-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;p.startPendingExec({execId:N,conversationId:e,command:j,includeInContext:b});try{const S=await ie.execInConversation(e,j,{includeInContext:b,execId:N});p.finishPendingExec(N,S),S.ok?S.queued&&p.notify({tone:"brand",title:"命令输出已排队,将在当前轮结束后进入上下文"}):p.notify({tone:"bad",title:`命令失败(退出码 ${S.exitCode??"?"})`,detail:S.error})}catch(S){const T=wa(S);p.finishPendingExec(N,{ok:!1,command:j,output:"",error:T,includeInContext:b}),p.notify({tone:"bad",title:"命令执行失败",detail:T})}return}case"fork":{const b=await ie.fork(e);if(!b.ok||b.conversationId===void 0){p.notify({tone:"bad",title:"分叉失败"});return}p.openConversation({conversationId:b.conversationId,env:b.env??t,title:`分叉自 #${e}`}),p.notify({tone:"ok",title:`已分叉出会话 #${b.conversationId}`});return}case"reset":p.requestReset({conversationId:e,envLabel:p.envLabel(t),...j?{handoff:j}:{}});return;case"cd":{if(h("<绝对路径>"))return;const b=await ie.configure(e,{cwd:j});p.reloadBootstrap(),p.notify({tone:b.ok?"ok":"bad",title:b.ok?`工作目录已改为 ${j}`:"修改工作目录失败",detail:b.ok?"后续工具调用与文件面板已同步到新目录。":"服务端返回 ok=false"});return}case"instructions":{if(h("<系统指令文本>"))return;const b=await ie.configure(e,{instructions:j});p.notify({tone:b.ok?"ok":"bad",title:b.ok?"系统指令已更新":"更新系统指令失败"});return}}}catch(b){p.notify({tone:"bad",title:`/${g} 执行失败`,detail:wa(b)})}},[e,t]),m=i.useCallback(async x=>{const y=Sc(x);return y?(await d(y.name,y.args),!0):!1},[d]),k=i.useMemo(()=>{const x=[];for(const y of bi){const p=y.args?`/${y.name} ${y.args}`:`/${y.name}`;y.kind==="prefix"?x.push({id:y.name,description:`${y.summary} · ${p}`,execute:()=>u(y.name)}):x.push({id:y.name,description:y.summary,execute:()=>{d(y.name,""),f.current?.()}})}for(const y of c)bo.has(y.name.toLowerCase())||x.push({id:y.name,description:`[模板] ${y.description}`,execute:()=>{d(y.name,""),f.current?.()}});return x},[d,u,c,l.length]),v=uu({commands:k,removeOnExecute:!0});return{adapter:v.adapter,action:v.action,runText:m,isCommand:Nc}}function Bm(e,t){const s=t.trim().toLowerCase();if(s.includes("/")){const[r,...o]=s.split("/"),a=o.join("/"),l=e.find(c=>c.provider.toLowerCase()===r&&c.id.toLowerCase()===a);return l||e.find(c=>c.provider.toLowerCase()===r&&c.id.toLowerCase().includes(a))}return e.find(r=>r.id.toLowerCase()===s)??e.find(r=>r.id.toLowerCase().includes(s)||r.name.toLowerCase().includes(s))}function Hm(){const{workspaceModalTarget:e,closeWorkspaceSettings:t,envLabel:s,models:r,reloadBootstrap:o,notify:a}=Ye(),l=!!e,c=e?.env??"",f=e?.workspace,u=!f||f.implicit===!0,[d,m]=i.useState(""),[k,v]=i.useState(""),[x,y]=i.useState(""),[p,g]=i.useState(""),[j,C]=i.useState(""),[h,b]=i.useState(!1),[N,S]=i.useState(!1),[T,P]=i.useState(null);i.useEffect(()=>{if(!e)return;const A=e.workspace;P(null),b(!1),m(A?.cwd??""),v(A?.name??""),y(A?.model?.provider&&A?.model?.modelId?`${A.model.provider}::${A.model.modelId}`:""),g(A?.thinkingLevel??""),C(A?.instructions??"")},[e]);const B=i.useMemo(()=>r?.models??[],[r?.models]),L=async A=>{if(A.preventDefault(),!(!c||!d.trim())){S(!0),P(null);try{const[z,...M]=x.split("::"),R=M.join("::"),W={cwd:d.trim(),...k.trim()?{name:k.trim()}:{},...z&&R?{model:{provider:z,modelId:R}}:{},...p?{thinkingLevel:p}:{},...f?.skills?.length?{skills:f.skills}:{},...f?.disabledSkills?.length?{disabledSkills:f.disabledSkills}:{},...j.trim()?{instructions:j.trim()}:{},applyToOpen:h};await ie.saveWorkspace(c,W),o(),a({tone:"ok",title:`已保存目录配置 ${W.name||W.cwd}`}),t()}catch(z){P(z instanceof Error?z.message:String(z))}finally{S(!1)}}},K=async()=>{if(!(!c||!f||f.implicit)){S(!0);try{await ie.deleteWorkspace(c,f.cwd),o(),a({tone:"warn",title:`已移除目录 ${f.name||f.cwd}`}),t()}catch(A){P(A instanceof Error?A.message:String(A))}finally{S(!1)}}};return n.jsx(Ut,{open:l,onOpenChange:A=>!A&&t(),children:n.jsxs(Wt,{className:"max-h-[90vh] overflow-y-auto sm:max-w-xl",children:[n.jsxs(Gt,{children:[n.jsxs(Vt,{className:"flex items-center gap-2",children:[n.jsx(Fs,{className:"text-brand size-4"}),u?`在 ${s(c)} 添加目录`:`目录设置 · ${f?.name||f?.cwd}`]}),n.jsx(Tn,{children:"配置该目录的默认模型、思考强度与系统指令。Skills 在右侧 Dock 的「Skills」页里管理。"})]}),T&&n.jsx("div",{className:"border-bad/35 bg-bad/10 text-bad rounded-lg border px-3 py-2 text-xs break-all",children:T}),n.jsxs("form",{onSubmit:L,className:"space-y-4",children:[n.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[n.jsxs("div",{children:[n.jsx(rt,{children:"目录路径 (cwd)"}),n.jsx(Ke,{value:d,onChange:A=>m(A.target.value),placeholder:"/workspace/project",required:!0,disabled:!!(f&&!f.implicit),className:"font-mono"})]}),n.jsxs("div",{children:[n.jsx(rt,{children:"显示名称(选填)"}),n.jsx(Ke,{value:k,onChange:A=>v(A.target.value),placeholder:"例如 api / web"})]})]}),n.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[n.jsxs("div",{children:[n.jsxs(rt,{className:"flex items-center gap-1",children:[n.jsx(_o,{className:"size-3"})," 目录默认模型"]}),n.jsxs(As,{value:x,onChange:A=>y(A.target.value),children:[n.jsx("option",{value:"",children:"继承全局默认模型"}),B.map(A=>n.jsxs("option",{value:`${A.provider}::${A.id}`,children:[A.provider,"/",A.id]},`${A.provider}::${A.id}`))]})]}),n.jsxs("div",{children:[n.jsx(rt,{children:"思考强度"}),n.jsxs(As,{value:p,onChange:A=>g(A.target.value),children:[n.jsx("option",{value:"",children:"默认"}),Ms.map(A=>n.jsx("option",{value:A,children:A},A))]})]})]}),!u&&(x||p)&&n.jsxs("label",{className:"text-muted-foreground flex cursor-pointer items-center gap-2 text-xs",children:[n.jsx("input",{type:"checkbox",checked:h,onChange:A=>b(A.target.checked)}),"同时把新模型/思考强度应用到该目录下当前已打开的会话"]}),n.jsxs("details",{className:"group border-line rounded-lg border px-3 py-2 text-xs",children:[n.jsxs("summary",{className:"text-muted-foreground hover:text-foreground flex cursor-pointer list-none items-center gap-1.5 font-medium",children:[n.jsx(is,{className:"size-3.5 transition-transform group-open:rotate-90"}),"目录专属系统指令(选填)"]}),n.jsxs("div",{className:"mt-2",children:[n.jsx("textarea",{value:j,onChange:A=>C(A.target.value),rows:3,placeholder:"例如:此目录为 Go 核心服务,修改后必须运行 go test ./...",className:"border-input text-foreground focus-visible:border-ring focus-visible:ring-ring/35 w-full rounded-md border bg-transparent px-2.5 py-1.5 text-xs outline-none focus-visible:ring-2 dark:bg-input/25"}),n.jsx(Ns,{children:"会注入本目录下所有会话的上下文中。"})]})]}),n.jsxs("div",{className:"flex items-center justify-between gap-2 pt-1",children:[f&&!f.implicit?n.jsx(ke,{type:"button",size:"sm",variant:"destructive",onClick:()=>void K(),disabled:N,children:"移除目录"}):n.jsx("span",{}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx(ke,{type:"button",variant:"ghost",onClick:t,children:"取消"}),n.jsx(ke,{type:"submit",variant:"default",disabled:N||!d.trim(),children:N?"保存中…":"保存目录设置"})]})]})]})]})})}function Um({className:e,...t}){return n.jsx("textarea",{"data-slot":"textarea",className:U("flex field-sizing-content min-h-16 w-full rounded-lg border border-input bg-transparent px-2.5 py-2 text-base transition-colors outline-none placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40",e),...t})}const Wm={immediate:"直接执行",prefix:"带参数",picker:"键盘 Picker"};function Gm(){const{helpOpen:e,setHelpOpen:t,prompts:s}=Ye();return n.jsx(Ut,{open:e,onOpenChange:r=>t(r),children:n.jsxs(Wt,{className:"sm:max-w-xl",children:[n.jsxs(Gt,{children:[n.jsxs(Vt,{className:"flex items-center gap-2",children:[n.jsx(zs,{className:"text-brand size-4"}),"斜杠命令(原生 Pi 体验)"]}),n.jsxs(Tn,{className:"text-[11.5px] leading-relaxed",children:["输入 ",n.jsx("code",{className:"pg-num bg-surface-3 rounded px-1 font-mono",children:"/命令"})," 或按"," ",n.jsx("code",{className:"pg-num bg-surface-3 rounded px-1 font-mono",children:"/"})," 弹出菜单;"," ",n.jsx("code",{className:"pg-num bg-surface-3 rounded px-1 font-mono",children:"!ls -la"})," 执行并带入模型上下文,"," ",n.jsx("code",{className:"pg-num bg-surface-3 rounded px-1 font-mono",children:"!!ls -la"})," 仅在聊天流中展示输出。"]})]}),n.jsx("div",{className:"border-line -mx-1 max-h-[52vh] overflow-y-auto rounded-md border",children:n.jsx("table",{className:"w-full border-separate border-spacing-0 text-[11.5px]",children:n.jsx("tbody",{children:bi.map(r=>n.jsxs("tr",{children:[n.jsx("td",{className:"border-line w-44 border-b px-2.5 py-1.5 align-top",children:n.jsxs("span",{className:U("pg-num font-mono font-medium",r.destructive?"text-bad":"text-brand"),children:["/",r.name,r.args?n.jsxs("span",{className:"text-muted-foreground/70",children:[" ",r.args]}):""]})}),n.jsxs("td",{className:"border-line border-b px-2.5 py-1.5 align-top",children:[n.jsx("span",{className:"text-foreground/85",children:r.summary}),n.jsx("span",{className:"text-muted-foreground/55 ml-1.5 text-[10px]",children:Wm[r.kind]})]})]},r.name))})})}),n.jsxs("p",{className:"text-muted-foreground text-[10.5px] leading-relaxed",children:[n.jsx("b",{className:"text-foreground/80 font-semibold",children:"/thinking"})," 档位按当前模型真实能力过滤(全集:",n.jsx("span",{className:"pg-num ml-1 font-mono",children:Ms.join(" · ")}),")。",s.length>0&&` 已自动加载 ${s.length} 个 ~/.pi/agent/prompts/*.md 模板。`]}),n.jsx(hi,{children:n.jsx(ke,{variant:"outline",size:"sm",onClick:()=>t(!1),children:"知道了"})})]})})}function Vm(){const{resetRequest:e,cancelReset:t,runReset:s,resetting:r}=Ye(),[o,a]=i.useState("");return i.useEffect(()=>{e&&a(e.handoff??"")},[e]),n.jsx(Ut,{open:e!==null,onOpenChange:l=>{!l&&!r&&t()},children:n.jsxs(Wt,{className:"sm:max-w-md",children:[n.jsxs(Gt,{children:[n.jsxs(Vt,{className:"text-bad flex items-center gap-2",children:[n.jsx(vt,{className:"size-4"}),"清空会话上下文"]}),n.jsxs(Tn,{className:"text-[11.5px] leading-relaxed",children:["即将重置 ",e&&n.jsxs(n.Fragment,{children:[n.jsx("b",{className:"text-foreground/90",children:e.envLabel})," 的会话 ",n.jsxs("span",{className:"pg-num",children:["#",e.conversationId]})]}),"。"]})]}),n.jsxs("div",{className:"flex flex-col gap-2.5",children:[n.jsxs("p",{className:"text-bad bg-bad/8 border-bad/25 flex items-start gap-2 rounded border px-2.5 py-2 text-[11.5px] leading-relaxed",children:[n.jsx(ko,{className:"mt-px size-3.5 shrink-0"}),n.jsx("span",{children:"这个操作不可撤销。模型会失去这个会话里的全部上下文;磁盘上的文件不受影响。"})]}),n.jsxs("div",{children:[n.jsx(rt,{htmlFor:"reset-handoff",hint:"(可选)",children:"交接摘要"}),n.jsx(Um,{id:"reset-handoff",value:o,onChange:l=>a(l.target.value),rows:4,placeholder:"填了就会作为重置后的第一条上下文交给 agent 继续干;留空从零开始。",className:"min-h-20 text-[12px]"}),n.jsx(Ns,{children:"可用 /reset <摘要> 预填。"})]})]}),n.jsxs(hi,{children:[n.jsx(ke,{variant:"ghost",size:"sm",onClick:t,disabled:r,children:"取消"}),n.jsxs(ke,{variant:"destructive",size:"sm",onClick:()=>void s(o),disabled:r,className:"gap-1.5",children:[r?n.jsx(at,{className:"size-3.5 animate-spin"}):n.jsx(ko,{className:"size-3.5"}),r?"清空中":"确认清空"]})]})]})})}const Km={ok:{bar:"bg-ok",text:"text-ok",icon:sn},bad:{bar:"bg-bad",text:"text-bad",icon:Lo},warn:{bar:"bg-warn",text:"text-warn",icon:vt},brand:{bar:"bg-brand",text:"text-brand",icon:Es},peer:{bar:"bg-peer",text:"text-peer",icon:Es}};function qm(){const{notices:e,dismissNotice:t}=Ye();return e.length===0?null:n.jsx("div",{className:"pointer-events-none fixed right-3 bottom-3 z-50 flex w-[22rem] max-w-[calc(100vw-1.5rem)] flex-col gap-1.5",role:"status","aria-live":"polite",children:e.map(s=>{const r=Km[s.tone],o=r.icon;return n.jsxs("div",{className:U("bg-popover border-line-strong pointer-events-auto relative overflow-hidden","animate-rise rounded-lg border pl-3 shadow-[0_16px_40px_-16px_rgba(0,0,0,0.85)]","motion-reduce:animate-none"),children:[n.jsx("span",{className:U("absolute inset-y-0 left-0 w-0.5",r.bar)}),n.jsxs("div",{className:"flex items-start gap-2 py-2 pr-2",children:[n.jsx(o,{className:U("mt-px size-3.5 shrink-0",r.text)}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsx("p",{className:"text-foreground/90 text-[11.5px] leading-snug font-medium break-words",children:s.title}),s.detail&&n.jsx("p",{className:"text-muted-foreground mt-0.5 text-[10.5px] leading-snug break-words",children:s.detail})]}),n.jsx("button",{type:"button",onClick:()=>t(s.id),"aria-label":"关闭提示",className:"text-muted-foreground/50 hover:bg-surface-3 hover:text-foreground -mt-0.5 flex size-4 shrink-0 items-center justify-center rounded transition-colors",children:n.jsx(Ds,{className:"size-3"})})]})]},s.id)})})}const Ec=i.createContext(void 0);function Bs(e){const t=i.useContext(Ec);if(t===void 0&&!e)throw new Error(Mt(47));return t}const Ym={...ns,disabled:e=>e.disabled,instantType:e=>e.instantType==="trigger-change"&&!ns.open(e)?void 0:e.instantType,openMethod:e=>e.openMethod,openChangeReason:e=>e.openChangeReason,isPressOpenedByTrigger:(e,t)=>e.openChangeReason===mn&&ns.isOpenedByTrigger(e,t),isTouchPressOpen:(e,t)=>t&&e.openMethod==="touch"&&e.openChangeReason===mn,hasTriggerFocusGuards:(e,t)=>ns.isOpenedByTrigger(e,t)&&!e.focusManagerModal,modal:e=>e.modal,titleElementId:e=>e.titleElementId,descriptionElementId:e=>e.descriptionElementId,openOnHover:e=>e.openOnHover,closeDelay:e=>e.closeDelay,adaptiveOrigin:e=>e.adaptiveOrigin};class Xm extends _r{constructor(t,s,r){const o=new fi;super(Jm(t,o,s,r),Zm(o),Ym)}setOpen=(t,s)=>{const r=s.reason===ut,o=s.reason===mn&&s.event.detail===0,a=!t&&(s.reason===Pr||s.reason==null),l=ic(s),c=this.select("activeTriggerId");if(!t&&s.reason===Tl&&s.trigger==null&&c!=null&&(s.trigger=this.context.triggerElements.getById(c)??this.select("activeTriggerElement")??void 0),this.context.onOpenChange?.(t,s),s.isCanceled)return;this.state.floatingRootContext.dispatchOpenChange(t,s);const f=()=>{const d=li(this.state,t,s.trigger,l());d.openChangeReason=s.reason,this.update(d)};r?(this.context.stickIfOpen=!0,this.context.stickIfOpenTimeout.start(mp,()=>{this.context.stickIfOpen=!1}),gn.flushSync(f)):f();let u;o?u="click":a?u="dismiss":s.reason===Ps&&(u="focus"),this.set("instantType",u)}}function Jm(e,t,s,r=!1){const o={...mi(t,s,r),disabled:!1,modal:!1,focusManagerModal:!1,instantType:void 0,openMethod:null,openChangeReason:null,titleElementId:void 0,descriptionElementId:void 0,openOnHover:!1,closeDelay:0,adaptiveOrigin:void 0,...e};return o.open&&e?.mounted===void 0&&(o.mounted=!0),o}function Zm(e){return{popupRef:i.createRef(),onOpenChange:void 0,onOpenChangeComplete:void 0,triggerFocusTargetRef:i.createRef(),beforeTriggerFocusGuardRef:i.createRef(),beforeContentFocusGuardRef:i.createRef(),stickIfOpenTimeout:new At,stickIfOpen:!0,triggerElements:e}}const Ca=Fr(function({props:t}){const{children:s,open:r,defaultOpen:o=!1,onOpenChange:a,onOpenChangeComplete:l,modal:c=!1,handle:f,triggerId:u,defaultTriggerId:d=null}=t,m=eg(f,{modal:c,open:o,openProp:r,activeTriggerId:d,triggerIdProp:u});m.useControlledProp("openProp",r),m.useControlledProp("triggerIdProp",u);const k=m.useState("open"),v=m.useState("mounted"),x=m.useState("payload");m.useContextCallback("onOpenChange",a),m.useContextCallback("onOpenChangeComplete",l),lc(m,k),ci(m);const{forceUnmount:y}=ui(k,m,()=>{m.context.stickIfOpen=!0,m.set("openChangeReason",null)});m.useSyncedValues({modal:c}),i.useEffect(()=>{k||m.context.stickIfOpenTimeout.clear()},[m,k]),i.useImperativeHandle(t.actionsRef,()=>({unmount:y,close:()=>m.setOpen(!1,Fe(Jo))}),[y,m]);const p=k||v||f!=null;return n.jsxs(Ec.Provider,{value:m,children:[f&&n.jsx(ai,{handle:f,store:m}),p&&n.jsx(tg,{store:m,modal:c}),typeof s=="function"?s({payload:x}):s]})});function Qm(e){return Bs(!0)?n.jsx(Ca,{props:e}):n.jsx(kp,{children:n.jsx(Ca,{props:e})})}function eg(e,t){const s=ii((r,o)=>new Xm(t,r,o));return i.useEffect(()=>s.context.stickIfOpenTimeout.disposeEffect(),[s]),s}function tg({store:e,modal:t}){const s=e.useState("floatingRootContext"),r=si(s,{outsidePressEvent:{mouse:t==="trap-focus"?"sloppy":"intentional",touch:"sloppy"}}),o=r.reference,a=r.floating;return di(e,{activeTriggerProps:o,inactiveTriggerProps:o,popupProps:a}),null}const ng=300;function sg(e,t){function s(a,l,c){const f=a.currentTarget;gn.flushSync(()=>{e.setOpen(!1,Fe(Ps,a.nativeEvent,f))}),dp(f.isConnected?f:t.current,l,c)?.focus()}function r(a){s(a,-1,e.select("positionerElement"))}function o(a){const l=e.select("positionerElement");l&&rs(a,l)?e.context.beforeContentFocusGuardRef.current?.focus():s(a,1,l)}return{handlePreFocusGuardFocus:r,handleFocusTargetFocus:o}}const rg=uc(function(t,s){const{render:r,className:o,style:a,disabled:l=!1,nativeButton:c=!0,handle:f,payload:u,openOnHover:d=!1,delay:m=ng,closeDelay:k=0,id:v,...x}=t,y=Bs(!0),g=pc(f)??y;if(!g)throw new Error(Mt(74));const j=_s(v),C=g.useState("isTriggerActive",j),h=g.useState("floatingRootContext"),b=g.useState("isOpenedByTrigger",j),N=g.useState("triggerPopupId",j),S=i.useRef(null),{registerTrigger:T,isMountedByThisTrigger:P}=ac(j,S,g,{payload:u,disabled:l,openOnHover:d,closeDelay:k}),B=g.useState("isPressOpenedByTrigger",j),L=g.useState("isTouchPressOpen",d),K=g.useState("hasTriggerFocusGuards",j),A=xc(h,{enabled:!l&&d&&!L,mouseOnly:!0,move:!1,handleClose:hc(),restMs:m,delay:{close:k},triggerElementRef:S,isActiveTrigger:C,isClosing:()=>g.select("transitionStatus")==="ending"}),z=ye(()=>g.context.stickIfOpen),M=Cp(h,{stickIfOpen:z}),R=Em(()=>g.select("open"),Z=>{g.set("openMethod",Z)}),W=g.useState("triggerProps",P),{getButtonProps:I,buttonRef:_}=Sr({disabled:l,native:c}),V={open(Z){return B?Mf.open(Z):Nl.open(Z)}},{handlePreFocusGuardFocus:H,handleFocusTargetFocus:Y}=sg(g,S),J=yt("button",t,{state:{disabled:l,open:b},ref:[_,s,T,S],props:[M.reference,A,W,R,{[ql]:"",id:j,"aria-haspopup":"dialog","aria-expanded":b,"aria-controls":N},x,I],stateAttributesMapping:V}),se=n.jsx(i.Fragment,{children:J},j);return K?n.jsxs(i.Fragment,{children:[n.jsx(as,{ref:g.context.beforeTriggerFocusGuardRef,onFocus:H}),se,n.jsx(as,{ref:g.context.triggerFocusTargetRef,onFocus:Y})]}):se}),Tc=i.createContext(void 0);function og(){const e=i.useContext(Tc);if(e===void 0)throw new Error(Mt(45));return e}const ig=i.forwardRef(function(t,s){const{keepMounted:r=!1,...o}=t;return Bs().useState("mounted")||r?n.jsx(Tc.Provider,{value:r,children:n.jsx(Ql,{ref:s,...o})}):null}),Rc=i.createContext(void 0);function ag(){const e=i.useContext(Rc);if(!e)throw new Error(Mt(46));return e}function lg(e){const{nodeId:t,externalTree:s,rootContext:r}=e,o=r.useState("referenceElement"),a=r.useState("floatingElement"),l=r.useState("domReferenceElement"),c=r.useState("open"),f=r.useState("floatingId"),[u,d]=i.useState(null),m=i.useRef(null),k=ds(s),v=i.useMemo(()=>({reference:o,floating:a,domReference:l}),[o,a,l]),x=du({...e,elements:{...v,...u&&{reference:u}}}),y=i.useCallback(C=>{const h=Ze(C)?{getBoundingClientRect:()=>C.getBoundingClientRect(),getClientRects:()=>C.getClientRects(),contextElement:C}:C;d(h),x.refs.setReference(h)},[x.refs]),p=i.useMemo(()=>({...x.refs,setPositionReference:y,domReference:m}),[x.refs,y]),g=i.useMemo(()=>({...x.elements,domReference:l}),[x.elements,l]),j=i.useMemo(()=>({...x,dataRef:r.context.dataRef,open:c,onOpenChange:r.setOpen,events:r.context.events,floatingId:f,refs:p,elements:g,nodeId:t,rootStore:r}),[x,p,g,t,r,c,f]);return pe(()=>{l&&(m.current=l)},[l]),pe(()=>{r.context.dataRef.current.floatingContext=j;const C=k?.nodesRef.current.find(h=>h.id===t);C&&(C.context=j)}),i.useMemo(()=>({...x,context:j,refs:p,elements:g,rootStore:r}),[x,p,g,j,r])}const cg=i.createContext(void 0);function ug(){return i.useContext(cg)?.direction??"ltr"}const dg=e=>({name:"arrow",options:e,async fn(t){const{x:s,y:r,placement:o,rects:a,platform:l,elements:c,middlewareData:f}=t,{element:u,padding:d=0}=fu(e,t)||{};if(u==null)return{};const m=pu(d),k={x:s,y:r},v=mu(o),x=gu(v),y=await l.getDimensions(u),p=v==="y",g=p?"top":"left",j=p?"bottom":"right",C=p?"clientHeight":"clientWidth",h=a.reference[x]+a.reference[v]-k[v]-a.floating[x],b=k[v]-a.reference[v],N=c.floating[C]||a.floating[x],S=h/2-b/2,T=N/2-y[x]/2-1,P=Math.min(m[g],T),B=Math.min(m[j],T),L=P,K=N-y[x]-B,A=N/2-y[x]/2+S,z=xu(L,A,K),M=!f.arrow&&ws(o)!=null&&A!==z&&a.reference[x]/2-(A<L?P:B)-y[x]/2<0,R=M?A<L?A-L:A-K:0;return{[v]:k[v]+R,data:{[v]:z,centerOffset:A-z-R,...M&&{alignmentOffset:R}},reset:M}}}),fg=(e,t)=>{const{name:s,fn:r}=dg(e);return{name:s,fn:r,options:[e,t]}},pg={name:"hide",async fn(e){const{width:t,height:s,x:r,y:o}=e.rects.reference,a=t===0&&s===0&&r===0&&o===0,l=await e.platform.detectOverflow(e,{elementContext:"reference"});return{data:{referenceHidden:l.top-s>=0||l.right-t>=0||l.bottom-s>=0||l.left-t>=0||a}}}},mg={sideX:"left",sideY:"top"},gg="--available-width",xg="--available-height",hg="--anchor-width",bg="--anchor-height",vg="--transform-origin",Sa=gg,Na=xg;function Pc(e,t,s){const r=e==="inline-start"||e==="inline-end";return{top:"top",right:r?s?"inline-start":"inline-end":"right",bottom:"bottom",left:r?s?"inline-end":"inline-start":"left"}[t]}function Ea(e,t,s){const{rects:r,placement:o}=e;return{side:Pc(t,js(o),s),align:ws(o)||"center",anchor:{width:r.reference.width,height:r.reference.height},positioner:{width:r.floating.width,height:r.floating.height}}}function Oc(e){return yg(e,lg)}function yg(e,t){const{anchor:s,positionMethod:r="absolute",side:o="bottom",sideOffset:a=0,align:l="center",alignOffset:c=0,collisionBoundary:f,collisionPadding:u=5,sticky:d=!1,arrowPadding:m=5,disableAnchorTracking:k=!1,inline:v,keepMounted:x=!1,floatingRootContext:y,mounted:p,collisionAvoidance:g,shift:j,nodeId:C,adaptiveOrigin:h,lazyFlip:b=!1,externalTree:N}=e,S=g.side||"flip",T=g.align||"flip",P=g.fallbackAxisSide||"end",B=j?.crossAxis??!1,L=j?.rootBoundary,K=typeof s=="function"?s:void 0,A=ye(K),z=K?A:s,M=dt(s),R=dt(p),I=ug()==="rtl",[_,V]=i.useState(null);!p&&_!==null&&V(null);const H=b==="placement",Y=_?js(_):null,le=_&&H?ws(_)||"center":null,J=Y||{top:"top",right:"right",bottom:"bottom",left:"left","inline-end":I?"left":"right","inline-start":I?"right":"left"}[o],se=le||l,Z=se==="center"?J:`${J}-${se}`;let re=u;typeof re=="number"?re={top:re,right:re,bottom:re,left:re}:re&&(re={top:re.top||0,right:re.right||0,bottom:re.bottom||0,left:re.left||0});const we=1,D=o==="bottom"?we:0,$=o==="top"?we:0,ee=o==="right"?we:0,G=o==="left"?we:0,fe={boundary:f==="clipping-ancestors"?"clippingAncestors":f,padding:re},te=i.useRef(null),ae=dt(a),ce=dt(c),je=typeof a!="function"?a:0,$e=typeof c!="function"?c:0,Q=[];v&&Q.push(v),Q.push(vu(Oe=>{const tt=Ea(Oe,o,I),ot=typeof ae.current=="function"?ae.current(tt):ae.current,et=typeof ce.current=="function"?ce.current(tt):ce.current;return{mainAxis:ot,crossAxis:et,alignmentAxis:et}},[je,$e,I,o]));const ve=T==="none"&&S!=="shift",ue=!ve&&(d||B||S==="shift"),Ce=S==="none"?null:hu({...fe,padding:{top:re.top+we+D,right:re.right+we+G,bottom:re.bottom+we+$,left:re.left+we+ee},mainAxis:!B&&S==="flip",crossAxis:T==="flip"?"alignment":!1,fallbackAxisSideDirection:P}),Ae=ve?null:yu({...fe,rootBoundary:L,mainAxis:T!=="none",crossAxis:ue,limiter:d||B?void 0:ku(Oe=>{if(!te.current)return{};const{width:tt,height:ot}=te.current.getBoundingClientRect(),et=Oi(js(Oe.placement)),Je=et==="y"?tt:ot,nt=et==="y"?re.left+re.right:re.top+re.bottom;return{offset:Je/2+nt/2}})},[fe,d,B,L,re,T]);S==="shift"||T==="shift"||se==="center"?Q.push(Ae,Ce):Q.push(Ce,Ae),Q.push(bu({...fe,apply({elements:{floating:Oe},availableWidth:tt,availableHeight:ot,rects:et}){if(!R.current)return;const Je=Oe.style;Je.setProperty(Sa,`${tt}px`),Je.setProperty(Na,`${ot}px`);const nt=xn(Oe).devicePixelRatio||1,{x:jt,y:ft,width:wt,height:pt}=et.reference,Ct=(Math.round((jt+wt)*nt)-Math.round(jt*nt))/nt,St=(Math.round((ft+pt)*nt)-Math.round(ft*nt))/nt;Je.setProperty(hg,`${Ct}px`),Je.setProperty(bg,`${St}px`)}}),fg(Oe=>({element:te.current||We(Oe.elements.floating).createElement("div"),padding:te.current?m:0}),[m]),{name:"transformOrigin",fn(Oe){const{elements:{floating:tt},middlewareData:ot,placement:et,platform:Je,rects:nt,y:jt}=Oe,ft=js(et),wt=ws(et),pt=Oi(ft)==="y",Ct=te.current,St=typeof a=="function"?a(Ea(Oe,o,I)):a;let an;if(!Ct&&wt&&Math.abs(pt?ot.shift?.x||0:ot.shift?.y||0)<=1)an=wt==="start"===(pt&&Je.isRTL?.(tt)===!0)?"100%":"0%";else{const mt=pt?ot.arrow?.x||0:ot.arrow?.y||0,Kt=pt?Ct?.clientWidth||0:Ct?.clientHeight||0;an=`${mt+Kt/2}px`}let Tt=ft==="top"||ft==="left"?`calc(100% + ${St}px)`:`${-St}px`;return ue&&pt&&Math.abs(ot.shift?.y||0)>St&&(Tt=`${nt.reference.y+nt.reference.height/2-jt}px`),tt.style.setProperty(vg,pt?`${an} ${Tt}`:`${Tt} ${an}`),{}}},pg,h),pe(()=>{!p&&y&&y.update({referenceElement:null,floatingElement:null,domReferenceElement:null,positionReference:null})},[p,y]);const Ie=i.useMemo(()=>({ancestorScroll:!k,elementResize:!k&&typeof ResizeObserver<"u",layoutShift:!k&&typeof IntersectionObserver<"u"}),[k]),{refs:X,elements:ne,x:Pe,y:Ne,middlewareData:Re,update:He,placement:Ge,context:_e,isPositioned:F,floatingStyles:oe}=t({rootContext:y,open:x?p:void 0,placement:Z,middleware:Q,strategy:r,whileElementsMounted:x?void 0:(...Oe)=>Ii(...Oe,Ie),nodeId:C,externalTree:N}),{sideX:he,sideY:Se}=Re.adaptiveOrigin||mg,De=F?r:"fixed",Ve=i.useMemo(()=>{let Oe;return F?h?Oe={position:De,[he]:Pe,[Se]:Ne}:Oe={...oe,position:De}:Oe={position:De,top:0,left:0},Oe[Sa]="100vw",Oe[Na]="100vh",F||(Oe.opacity=0),Oe},[h,De,he,Pe,Se,Ne,oe,F]),qe=i.useRef(null);pe(()=>{if(!p)return;const Oe=M.current,tt=typeof Oe=="function"?Oe():Oe,et=(Ta(tt)?tt.current:tt)||null||null;et!==qe.current&&(X.setPositionReference(et),qe.current=et)},[p,X,z,M]),i.useEffect(()=>{if(!p)return;const Oe=M.current;typeof Oe!="function"&&Ta(Oe)&&Oe.current!==qe.current&&(X.setPositionReference(Oe.current),qe.current=Oe.current)},[p,X,z,M]),i.useEffect(()=>{if(x&&p&&ne.reference&&ne.floating)return Ii(ne.reference,ne.floating,He,Ie)},[x,p,ne,He,Ie]);const Xe=js(Ge),lt=Pc(o,Xe,I),$t=ws(Ge)||"center",ct=!!Re.hide?.referenceHidden;pe(()=>{b&&p&&F&&(Xe!==J||H&&$t!==se)&&V(Ge)},[b,H,p,F,Ge,Xe,$t,J,se]);const Et=i.useMemo(()=>({position:"absolute",top:Re.arrow?.y,left:Re.arrow?.x}),[Re.arrow]),hn=Re.arrow?.centerOffset!==0;return i.useMemo(()=>({positionerStyles:Ve,arrowStyles:Et,arrowRef:te,arrowUncentered:hn,side:lt,align:$t,physicalSide:Xe,anchorHidden:ct,refs:X,context:_e,isPositioned:F,update:He}),[Ve,Et,te,hn,lt,$t,Xe,ct,X,_e,F,He])}function Ta(e){return e!=null&&"current"in e}function kg(e){const{store:t,domReference:s,positionerElement:r,open:o}=e,a=i.useRef(null),l=i.useRef(null),c=ri(r);pe(()=>{o||(l.current?.abort(),l.current=null,t.state.instantType==="trigger-change"&&t.set("instantType",void 0))},[o,t]),pe(()=>{const f=s,u=a.current;if(f&&(a.current=f),!u||!f||f===u||!t.select("open"))return;t.set("instantType",void 0);const d=new AbortController;return l.current=d,c(()=>{t.select("open")&&t.set("instantType","trigger-change")},d.signal),()=>{d.abort()}},[s,c,t])}function vi(e){return e==="starting"?gp:bt}function Ic(e,t,{styles:s,transitionStatus:r,props:o,refs:a,hidden:l,inert:c=!1}){const f={...s};return c&&(f.pointerEvents="none"),yt("div",e,{state:t,ref:a,props:[{role:"presentation",hidden:l,style:f},vi(r),o],stateAttributesMapping:Tr})}const jg=20;function wg(e,t,s,r){const[o,a]=i.useState(!1);pe(()=>{if(!e||!t||s==null){a(!1);return}const l=We(s).documentElement.clientWidth,c=s.offsetWidth;a(l>0&&c>0&&c>=l-jg)},[e,t,s]),jc(e&&(!t||o),r)}const Cg=i.forwardRef(function(t,s){const{render:r,className:o,style:a,anchor:l,positionMethod:c,side:f,align:u,sideOffset:d,alignOffset:m,collisionBoundary:k="clipping-ancestors",collisionPadding:v,arrowPadding:x,sticky:y,disableAnchorTracking:p=!1,collisionAvoidance:g=Yl,...j}=t,C=Bs(),h=og(),b=vp(),N=C.useState("floatingRootContext"),S=C.useState("mounted"),T=C.useState("open"),P=C.useState("openChangeReason"),B=C.useState("activeTriggerElement"),L=C.useState("modal"),K=C.useState("openMethod"),A=C.useState("positionerElement"),z=C.useState("instantType"),M=C.useState("transitionStatus"),R=C.useState("adaptiveOrigin"),W=Oc({anchor:l,floatingRootContext:N,positionMethod:c,mounted:S,side:f,sideOffset:d,align:u,alignOffset:m,arrowPadding:x,collisionBoundary:k,collisionPadding:v,sticky:y,disableAnchorTracking:p,keepMounted:h,nodeId:b,collisionAvoidance:g,adaptiveOrigin:R}),I=N.useState("domReferenceElement");kg({store:C,domReference:I,positionerElement:A,open:T});const _=L===!0&&P!==ut;wg(T&&_,K==="touch",A,B);const V=C.useStateSetter("positionerElement"),H={open:T,side:W.side,align:W.align,anchorHidden:W.anchorHidden,instant:z},Y=Ic(t,H,{styles:W.positionerStyles,transitionStatus:M,props:j,refs:[s,V],hidden:!S,inert:!T});return n.jsxs(Rc.Provider,{value:W,children:[S&&_&&n.jsx(kc,{inert:yc(!T),cutout:B}),n.jsx(yp,{id:b,children:Y})]})}),Sg=i.createContext(void 0);function Ng(e){return i.useContext(Sg)}const Eg=i.createContext(void 0);function Tg(){const[e,t]=i.useState(0),s=ye(()=>(t(o=>o+1),()=>{t(o=>Math.max(0,o-1))}));return{context:i.useMemo(()=>({register:s}),[s]),hasClosePart:e>0}}const Rg=i.forwardRef(function(t,s){const{render:r,className:o,style:a,initialFocus:l,finalFocus:c,...f}=t,u=Bs(),d=ag(),m=Ng()!=null,{context:k,hasClosePart:v}=Tg(),x=u.useState("open"),y=u.useState("openMethod"),p=u.useState("instantType"),g=u.useState("transitionStatus"),j=u.useState("popupProps"),C=u.useState("titleElementId"),h=u.useState("descriptionElementId"),b=u.useState("modal"),N=u.useState("mounted"),S=u.useState("openChangeReason"),T=u.useState("activeTriggerElement"),P=u.useState("floatingRootContext"),B=P.useState("floatingId"),L=u.useState("disabled"),K=u.useState("openOnHover"),A=u.useState("closeDelay");Ls({open:x,ref:u.context.popupRef,onComplete(){x&&u.context.onOpenChangeComplete?.(!0)}}),gc(P,{enabled:K&&!L,closeDelay:A});const z=l===void 0?oc(u.context.popupRef):l,M=b!==!1&&v;u.useSyncedValue("focusManagerModal",M);const R=u.useStateSetter("popupElement"),W={open:x,side:d.side,align:d.align,instant:p,transitionStatus:g},I=yt("div",t,{state:W,ref:[s,u.context.popupRef,R],props:[j,{id:B,role:"dialog",...oi,"aria-labelledby":C,"aria-describedby":h,onKeyDown(_){m&&vc.has(_.key)&&_.stopPropagation()}},vi(g),f],stateAttributesMapping:Xo});return n.jsx(sc,{context:P,openInteractionType:y,modal:M,disabled:!N||S===ut,initialFocus:z,returnFocus:c,restoreFocus:"popup",getInsideElements:()=>[u.context.beforeTriggerFocusGuardRef.current],previousFocusableElement:xt(T)?T:void 0,nextFocusableElement:u.context.triggerFocusTargetRef,beforeContentFocusGuardRef:u.context.beforeContentFocusGuardRef,children:n.jsx(Eg.Provider,{value:k,children:I})})});function Ac({...e}){return n.jsx(Qm,{"data-slot":"popover",...e})}function Mc({...e}){return n.jsx(rg,{"data-slot":"popover-trigger",...e})}function $c({className:e,align:t="start",side:s="bottom",sideOffset:r=6,alignOffset:o=0,children:a,...l}){return n.jsx(ig,{children:n.jsx(Cg,{align:t,alignOffset:o,side:s,sideOffset:r,className:"isolate z-50",children:n.jsx(Rg,{"data-slot":"popover-content",className:U("bg-popover text-popover-foreground ring-foreground/12","origin-(--transform-origin) w-fit rounded-lg ring-1 outline-none","data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95","data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95","data-[side=bottom]:slide-in-from-top-2 data-[side=top]:slide-in-from-bottom-2","shadow-[0_12px_36px_-12px_rgba(0,0,0,0.18)] dark:shadow-[0_12px_40px_-12px_rgba(0,0,0,0.75)]",e),...l,children:a})})})}const Pg={"local-host":"本机","local-docker":"容器","ssh-host":"SSH","ssh-docker":"容器"};function Og(e){const t=e.config;if(e.kind==="local-host")return"本机宿主机";if(e.kind==="local-docker")return`docker:${t?.container??e.name}`;const s=[t?.user?`${t.user}@`:"",t?.host??e.host].join("");return e.kind==="ssh-docker"?`${s} ▸ ${t?.container??e.name}`:t?.port?`${s}:${t.port}`:s}function Ig(e){let t=e.replace(/^RemoteError\s*\[[^\]]*\]:\s*/i,"").replace(/\d{4}[/-]\d\d[/-]\d\d\s+\d\d:\d\d(:\d\d)?\s*/g,"").replace(/^ssh\s+\S+\s+failed\s+with\s+/i,"").replace(/^ssh-docker\s+连接失败\s*/i,"").replace(/connect ws failed!\s*/i,"").replace(/\s+/g," ").trim();const s=/exit(?: code)?\s+(\d+)/i.exec(e),r=s?`exit ${s[1]}`:"";t=t.replace(/^\(exit \d+\):\s*/i,"").replace(/^exit code \d+:\s*/i,"").replace(/^:\s*/,"").trim();const a=[r,t].filter(Boolean).join(" · ");return a.length>72?`${a.slice(0,71)}…`:a}function Ra(e){const t=e.title?.trim();return!t||t===e.env||t.startsWith(`${e.env}:`)?"未命名会话":t}function Ag(){const{envRows:e,envs:t,setSelectedEnv:s,openNewConv:r,conversations:o,archivedConversations:a,archiveConversation:l,deleteConversation:c,openConversation:f,bootstrapError:u,reloadBootstrap:d,openAddEnv:m,openWorkspaceSettings:k,probingEnvs:v,probeEnv:x,activeConvId:y,notify:p,jumpToFiles:g}=Ye(),j=ld(),[C,h]=i.useState({}),[b,N]=i.useState(!1),[S,T]=i.useState(null),[P,B]=i.useState(null),[L,K]=i.useState(null),[A,z]=i.useState(null),[M,R]=i.useState(null),W=i.useMemo(()=>[...e].sort((D,$)=>D.kind==="local-host"&&$.kind!=="local-host"?-1:$.kind==="local-host"&&D.kind!=="local-host"?1:D.label.localeCompare($.label)),[e]),I=i.useMemo(()=>y===null?null:o.find(D=>D.conversationId===y)?.env??null,[y,o]),_=i.useMemo(()=>{const D=new Map;for(const $ of o){const ee=D.get($.env)??[];ee.push($),D.set($.env,ee)}for(const $ of D.values())$.sort((ee,G)=>(G.createdAt??0)-(ee.createdAt??0));return D},[o]),V=(D,$)=>h(ee=>({...ee,[D]:!$})),H=async(D,$)=>{R(`conv:${D}`);try{await l(D,$),z(ee=>ee===D?null:ee)}catch(ee){p({tone:"bad",title:$?"归档会话失败":"取消归档失败",detail:ee instanceof Error?ee.message:String(ee)})}finally{R(null)}},Y=async D=>{R(`conv:${D}`);try{await c(D),z(null)}catch($){p({tone:"bad",title:"删除会话失败",detail:$ instanceof Error?$.message:String($)})}finally{R(null)}},le=(D,$)=>{const ee=!!$?.isArchived,G=y===D.conversationId,fe=M===`conv:${D.conversationId}`,te=W.find(ce=>ce.name===D.env)?.label??D.env,ae=j.get(D.conversationId)?.running??!1;return A===D.conversationId?n.jsxs("div",{className:"border-bad/30 bg-bad/8 flex h-7 items-center justify-between gap-1.5 rounded-md border px-2 text-[11px]",children:[n.jsxs("span",{className:"text-bad truncate font-medium",children:["删除 #",D.conversationId,"?"]}),n.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[n.jsx("button",{type:"button",disabled:fe,onClick:()=>void Y(D.conversationId),className:"bg-bad/15 text-bad hover:bg-bad/25 rounded px-1.5 py-0.5 font-medium disabled:opacity-50",children:fe?"…":"确认"}),n.jsx("button",{type:"button",onClick:()=>z(null),className:"text-muted-foreground hover:text-foreground rounded px-1 py-0.5",children:"取消"})]})]},D.conversationId):n.jsxs("div",{className:U("group/conv flex h-7 items-center gap-1 rounded-md pr-1 pl-10 transition-colors",G?"bg-surface-2 text-foreground":"text-foreground/75 hover:bg-surface-2/60 hover:text-foreground",ee&&"opacity-70"),"aria-current":G?"page":void 0,children:[n.jsxs("button",{type:"button",onClick:()=>{s(D.env),f(D)},className:"flex h-full min-w-0 flex-1 items-center gap-1.5 text-left",title:`${Ra(D)} (#${D.conversationId}${D.cwd?` · ${D.cwd}`:""})`,children:[$?.showEnvTag&&n.jsx("span",{className:"bg-surface-3 text-muted-foreground max-w-16 shrink-0 truncate rounded px-1 py-px text-[9.5px]",children:te}),ae&&n.jsx(ss,{tone:"ok",live:!0,size:"sm",className:"shrink-0"}),n.jsx("span",{className:U("truncate text-[13px]",ae&&"text-foreground"),children:Ra(D)})]}),n.jsx("span",{className:"pg-num shrink-0 text-[11px] text-muted-foreground/70 tabular-nums group-hover/conv:hidden group-focus-within/conv:hidden",children:D.createdAt?ir(D.createdAt):`#${D.conversationId}`}),n.jsxs("div",{className:"hidden shrink-0 items-center gap-0.5 group-hover/conv:flex group-focus-within/conv:flex",children:[!ee&&n.jsx("button",{type:"button",onClick:ce=>{ce.stopPropagation(),f(D,{split:!0})},title:"在右侧分屏打开","aria-label":"在右侧分屏打开",className:"text-muted-foreground hover:bg-surface-3 hover:text-foreground rounded p-0.5",children:n.jsx(Iu,{className:"size-3.5"})}),n.jsx("button",{type:"button",disabled:fe,onClick:ce=>{ce.stopPropagation(),H(D.conversationId,!ee)},title:ee?"恢复会话":"归档会话","aria-label":ee?"恢复会话":"归档会话",className:"text-muted-foreground hover:bg-surface-3 hover:text-foreground rounded p-0.5 disabled:opacity-50",children:ee?n.jsx(Au,{className:"size-3.5"}):n.jsx($i,{className:"size-3.5"})}),n.jsx("button",{type:"button",disabled:fe,onClick:ce=>{ce.stopPropagation(),z(D.conversationId)},title:"删除会话","aria-label":"删除会话",className:"text-muted-foreground hover:bg-bad/15 hover:text-bad rounded p-0.5 disabled:opacity-50",children:n.jsx(jo,{className:"size-3.5"})})]})]},D.conversationId)},J=async D=>{R(`trust-host:${D}`);try{const $=await ie.trustHost(D);$.accepted?p({tone:"ok",title:`主机 ${D} 已信任`}):B({host:D,lines:$.lines??[],fingerprints:$.fingerprints??[]})}catch($){p({tone:"bad",title:"扫描 host key 失败",detail:$ instanceof Error?$.message:String($)})}finally{R(null)}},se=async D=>{R(`reset-trust:${D}`);try{await ie.resetTrustHost(D),p({tone:"ok",title:`已重置 ${D} 的主机密钥,正在重新连接…`})}catch($){p({tone:"bad",title:"重置主机密钥失败",detail:$ instanceof Error?$.message:String($)})}finally{R(null)}},Z=async()=>{if(P){B(D=>D&&{...D,loading:!0});try{await ie.trustHost(P.host,P.lines),p({tone:"ok",title:`已信任 ${P.host}`}),B(null)}catch(D){p({tone:"bad",title:"写入 known_hosts 失败",detail:D instanceof Error?D.message:String(D)}),B($=>$&&{...$,loading:!1})}}},re=async D=>{T(null),R(`deploy:${D}`);try{const $=await ie.deployEnvironment(D);p({tone:"ok",title:`${D} 部署完成`,detail:`${$.mode} · ${$.path}`}),await x(D)}catch($){p({tone:"bad",title:`${D} 部署失败`,detail:$ instanceof Error?$.message:String($)})}finally{R(null)}},we=async D=>{R(`delete:${D}`);try{const $=await ie.deleteEnvironment(D);K(null),T(null),p({tone:"warn",title:`已删除环境 ${D}`,detail:$.orphanConversations?`保留了 ${$.orphanConversations} 条历史会话记录`:void 0}),d()}catch($){p({tone:"bad",title:`删除 ${D} 失败`,detail:$ instanceof Error?$.message:String($)})}finally{R(null)}};return n.jsxs("div",{className:"flex h-full flex-col",children:[n.jsx("div",{className:"px-2 pt-2 pb-1",children:n.jsxs(ke,{size:"sm",variant:"outline",className:"w-full justify-start gap-2",onClick:()=>r(null),children:[n.jsx(pn,{className:"size-3.5"}),"新建会话"]})}),n.jsxs("div",{className:"border-line flex h-7 shrink-0 items-center justify-between border-b pr-2 pl-3",children:[n.jsx("span",{className:"text-muted-foreground text-[11px] font-medium tracking-wide uppercase",children:"环境"}),n.jsx("button",{type:"button",onClick:()=>m(),title:"添加宿主机或容器环境","aria-label":"添加环境",className:"text-muted-foreground hover:text-foreground flex size-5 items-center justify-center rounded transition-colors",children:n.jsx(pn,{className:"size-4"})})]}),n.jsxs("div",{className:"pg-scroll-y flex-1 space-y-2 px-2 py-2",children:[u&&n.jsxs("div",{className:"border-bad/35 bg-bad/10 text-bad rounded-lg border p-2.5 text-xs",children:[n.jsxs("div",{children:["服务配置加载失败:",u]}),n.jsx("button",{onClick:d,className:"mt-1 underline",children:"重试"})]}),t.data?.error&&n.jsxs("div",{className:"border-warn/35 bg-warn/10 text-warn rounded-lg border p-2.5 text-xs",children:["环境通道警告:",t.data.error]}),e.length===0&&!u&&n.jsxs("div",{className:"border-line text-muted-foreground rounded-lg border border-dashed p-4 text-center text-xs",children:["还没有配置任何执行环境",n.jsx("div",{className:"mt-2",children:n.jsxs(ke,{size:"xs",variant:"default",onClick:()=>m(),children:[n.jsx(pn,{className:"h-3 w-3"})," 添加第一个环境"]})})]}),(()=>{const D=new Set;return W.map($=>{const ee=$.status,G=_.get($.name)??[],fe=I===$.name,te=C[$.name]??fe,ae=!!v[$.name],ce=ee===void 0||ae?"muted":ee.ok?ee.latencyGrade==="可用"||ee.latencyGrade==="偏慢"?"warn":"ok":"bad",je=ae?"连接中…":ee===void 0?"未探测":ee.ok?`${ee.latencyGrade??""}${ee.opMs!==void 0?` · ${Ld(ee.opMs)}`:""}`:ee.error??"离线",$e=ee?.cwd??$.cwd,Q=!!(ee?.error&&/密钥已变更|HAS CHANGED/i.test(ee.error)),ve=!!(ee?.error&&/尚未信任 host key|not trusted/i.test(ee.error)),ue=ee&&!ee.ok&&ee.error?Ig(ee.error):"",Ce=`${$.host}:${ue}`,Ae=!!ue&&!D.has(Ce);Ae&&D.add(Ce);const Ie=ue?W.filter(Ne=>Ne.host===$.host&&Ne.status&&!Ne.status.ok).length:0,[X,ne]=$.label.split(" ▸ "),Pe=[`${$.label} · ${Pg[$.kind]}`,Og($),$e?`cwd ${$e}`:null,je].filter(Boolean).join(`
9
+ `);return n.jsxs("div",{className:"group/env",children:[n.jsxs("div",{className:"flex h-7 items-center gap-0.5 rounded-md pr-1 hover:bg-surface-2/60",children:[n.jsx("button",{type:"button",onClick:()=>V($.name,te),className:"text-muted-foreground/70 hover:text-foreground flex size-5 shrink-0 items-center justify-center rounded transition-colors",title:te?"收起":"展开会话","aria-label":te?"收起":"展开会话",children:n.jsx(is,{className:U("size-4 transition-transform",te&&"rotate-90")})}),n.jsxs("button",{type:"button",onClick:()=>{s($.name),V($.name,te)},className:"flex h-7 min-w-0 flex-1 items-center gap-1.5 text-left",title:Pe,children:[n.jsx(ss,{tone:ce,live:ae,size:"sm",title:je}),n.jsxs("span",{className:"truncate text-[13px]",children:[n.jsx("span",{className:U("font-medium",fe?"text-foreground":"text-foreground/85"),children:X}),ne&&n.jsxs("span",{className:"text-muted-foreground font-normal",children:[" · ",ne]})]})]}),n.jsxs(Ac,{open:S===$.name,onOpenChange:Ne=>T(Ne?$.name:null),children:[n.jsx(Mc,{className:"text-muted-foreground hover:bg-surface-3 hover:text-foreground flex size-5 shrink-0 items-center justify-center rounded transition-colors lg:opacity-0 lg:group-hover/env:opacity-100",title:"环境操作","aria-label":"环境操作",children:n.jsx(Pu,{className:"size-4"})}),n.jsxs($c,{align:"end",className:"w-40 p-1 text-xs",children:[n.jsxs("button",{type:"button",onClick:()=>{T(null),m({edit:$})},className:"hover:bg-surface-2 flex w-full items-center gap-2 rounded px-2 py-1.5 text-left",children:[n.jsx(Qa,{className:"size-3.5"}),"编辑配置"]}),($.runtime==="docker"||$.hostType==="ssh")&&n.jsxs("button",{type:"button",onClick:()=>void re($.name),disabled:M===`deploy:${$.name}`,className:"hover:bg-surface-2 flex w-full items-center gap-2 rounded px-2 py-1.5 text-left",children:[n.jsx(el,{className:"size-3.5"}),"部署守护进程"]}),n.jsxs("button",{type:"button",onClick:()=>void x($.name),disabled:ae,className:"hover:bg-surface-2 flex w-full items-center gap-2 rounded px-2 py-1.5 text-left",children:[n.jsx(ss,{tone:ce,size:"sm"}),"重新探测"]}),n.jsx("div",{className:"border-line my-1 border-t"}),L===$.name?n.jsxs("div",{className:"flex items-center gap-1 px-1 py-1",children:[n.jsx("button",{type:"button",onClick:()=>void we($.name),disabled:M===`delete:${$.name}`,className:"bg-bad/15 text-bad hover:bg-bad/25 flex-1 rounded px-2 py-1 text-center font-medium",children:"确认删除"}),n.jsx("button",{type:"button",onClick:()=>K(null),className:"text-muted-foreground hover:text-foreground rounded px-1.5 py-1",children:"取消"})]}):n.jsxs("button",{type:"button",onClick:()=>K($.name),className:"text-bad hover:bg-bad/10 flex w-full items-center gap-2 rounded px-2 py-1.5 text-left",children:[n.jsx(jo,{className:"size-3.5"}),"删除环境"]})]})]})]}),Ae&&n.jsxs("div",{className:"text-bad/90 flex h-7 items-center gap-2 pr-2 pl-7 text-[11px]",children:[n.jsxs("span",{className:"min-w-0 truncate",title:ee?.error,children:[ue,Ie>1&&n.jsxs("span",{className:"text-muted-foreground ml-1.5",children:["· 主机 ",$.host," 下 ",Ie," 个环境离线"]})]}),n.jsx("span",{className:"flex-1"}),$.hostType==="ssh"&&Q&&n.jsx("button",{onClick:()=>void se($.host),disabled:M===`reset-trust:${$.host}`,className:"shrink-0 font-medium underline hover:opacity-80 disabled:opacity-40",children:"重置密钥"}),$.hostType==="ssh"&&!Q&&ve&&n.jsx("button",{onClick:()=>void J($.host),disabled:M===`trust-host:${$.host}`,className:"shrink-0 font-medium underline hover:opacity-80 disabled:opacity-40",children:"信任密钥"}),n.jsx("button",{onClick:()=>void x($.name),disabled:ae,className:"shrink-0 font-medium underline hover:opacity-80 disabled:opacity-40",children:"重试"})]}),P?.host===$.host&&n.jsxs("div",{className:"border-warn/35 bg-warn/10 mb-1 ml-6 rounded-md border p-2 text-[11px]",children:[n.jsxs("div",{className:"text-warn font-medium",children:["确认信任 ",$.host," 的主机指纹:"]}),n.jsx("pre",{className:"text-muted-foreground mt-1 overflow-x-auto font-mono text-[10px]",children:P.fingerprints.join(`
10
+ `)}),n.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5",children:[n.jsx(ke,{size:"xs",variant:"default",onClick:Z,disabled:P.loading,children:P.loading?"写入中…":"确认信任"}),n.jsx(ke,{size:"xs",variant:"ghost",onClick:()=>B(null),children:"取消"})]})]}),te&&n.jsx("div",{className:"space-y-px",children:(()=>{const Ne=$.workspaces&&$.workspaces.length>0?$.workspaces:$.cwd?[{cwd:$.cwd.replace(/\/+$/,"")||"/",name:$.cwd.split("/").filter(Boolean).pop()||"/",implicit:!0}]:[],Re=F=>{const oe=(F??"").trim();return oe?oe==="/"?"/":oe.replace(/\/+$/,"")||"/":""},He=new Map;for(const F of Ne)He.set(F.cwd,[]);const Ge=[];for(const F of G){const oe=Re(F.cwd||$.cwd||void 0),he=Ne.find(De=>De.cwd===oe);if(he){He.get(he.cwd).push(F);continue}let Se=null;for(const De of Ne){const Ve=De.cwd==="/"?"/":`${De.cwd}/`;oe.startsWith(Ve)&&(!Se||De.cwd.length>Se.cwd.length)&&(Se=De)}Se?He.get(Se.cwd).push(F):Ge.push(F)}const _e=Ne.length>1;return n.jsxs(n.Fragment,{children:[Ne.map(F=>{const oe=He.get(F.cwd)??[],he=F.name||F.cwd.split("/").filter(Boolean).pop()||"/";return n.jsxs("div",{className:"space-y-px",children:[n.jsxs("div",{className:"group/ws flex h-7 items-center gap-1.5 rounded-md pr-1 pl-7 hover:bg-surface-2/60",children:[n.jsx(Fs,{className:"text-muted-foreground/70 size-4 shrink-0"}),n.jsx("button",{type:"button",onClick:()=>g($.name,F.cwd),className:"text-muted-foreground min-w-0 flex-1 truncate text-left text-[12px] hover:text-foreground",title:`${F.cwd} · 点击在文件面板打开${F.model?`
11
+ 模型: ${F.model.provider}/${F.model.modelId}`:""}`,children:_e?he:$.cwd??he}),_e&&F.model?.modelId&&n.jsx("span",{className:"bg-surface-3 text-muted-foreground max-w-20 shrink-0 truncate rounded px-1 py-px font-mono text-[9.5px]",title:`${F.model.provider}/${F.model.modelId}`,children:F.model.modelId}),n.jsx("button",{type:"button",onClick:()=>k($.name,F),className:"text-muted-foreground hover:text-foreground flex size-5 shrink-0 items-center justify-center rounded opacity-0 group-hover/ws:opacity-100",title:"目录设置(模型 / 思考强度 / 指令)",children:n.jsx(Ou,{className:"size-3.5"})}),n.jsx("button",{type:"button",onClick:()=>r($.name,F.cwd),className:"text-muted-foreground hover:text-foreground flex size-5 shrink-0 items-center justify-center rounded opacity-0 group-hover/ws:opacity-100",title:`在 ${he} 新建会话`,children:n.jsx(pn,{className:"size-3.5"})})]}),n.jsx("div",{className:"space-y-px",children:oe.map(Se=>le(Se))})]},F.cwd)}),Ge.length>0&&n.jsx("div",{className:"space-y-px [&>div]:pl-7",children:Ge.map(F=>le(F))}),(_e||!$.cwd)&&n.jsxs("button",{type:"button",onClick:()=>k($.name),className:"text-muted-foreground/70 hover:text-foreground flex h-7 w-full items-center gap-1 rounded-md pr-2 pl-7 text-left text-[12px] opacity-0 transition-opacity group-hover/env:opacity-100",children:[n.jsx(pn,{className:"size-3.5"}),"添加目录…"]})]})})()})]},$.name)})})(),a.length>0&&n.jsxs("div",{className:"border-line/70 space-y-px border-t pt-2",children:[n.jsxs("button",{type:"button",onClick:()=>N(D=>!D),className:"text-muted-foreground hover:text-foreground flex h-7 w-full items-center gap-1.5 rounded-md px-1 text-left text-[12px] transition-colors",children:[n.jsx(is,{className:U("size-4 transition-transform",b&&"rotate-90")}),n.jsx($i,{className:"size-3.5"}),n.jsx("span",{children:"已归档"}),n.jsx("span",{className:"pg-num ml-auto pr-1 text-[11px] tabular-nums text-muted-foreground/70",children:a.length})]}),b&&n.jsx("div",{className:"space-y-px [&>div]:pl-7",children:[...a].sort((D,$)=>($.createdAt??0)-(D.createdAt??0)).map(D=>le(D,{isArchived:!0,showEnvTag:!0}))})]})]})]})}const Dc="pi-foreman:theme",yr=new Set;function zc(){try{const e=localStorage.getItem(Dc);if(e==="light"||e==="dark"||e==="system")return e}catch{}return"system"}function Fc(e){return e==="dark"||e==="light"?e:typeof window<"u"&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function $o(e){const t=Fc(e);return typeof document<"u"&&(document.documentElement.classList.toggle("dark",t==="dark"),document.documentElement.style.colorScheme=t),t}let Ln=zc(),Pa=!1;function _c(){Pa||(Pa=!0,Ln=zc(),$o(Ln),typeof window<"u"&&window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",()=>{if(Ln==="system"){$o("system");for(const t of yr)t()}}))}function Oa(e){Ln=e;try{localStorage.setItem(Dc,e)}catch{}$o(e);for(const t of yr)t()}function Mg(){const[,e]=i.useState(0);i.useEffect(()=>{_c();const r=()=>e(o=>o+1);return yr.add(r),()=>{yr.delete(r)}},[]);const t=i.useCallback(r=>Oa(r),[]),s=i.useCallback(()=>{const r=["system","light","dark"],o=r.indexOf(Ln);Oa(r[(o+1)%r.length])},[]);return{theme:Ln,resolved:Fc(Ln),setTheme:t,cycleTheme:s}}function $g(){const{globalStatus:e}=Ye(),{theme:t,cycleTheme:s}=Mg(),r=e==="error",o=e==="connecting",a=t==="light"?Du:t==="dark"?zu:Fu,l=r?"与 foreman serve 断开":o?"正在重连 foreman serve":"已连接 foreman serve";return n.jsxs("div",{className:"border-line flex items-center gap-1 border-t px-2 py-1.5",children:[n.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-1.5 px-1",title:l,children:[r?n.jsx(Mu,{className:"size-3 shrink-0 text-bad"}):n.jsx($u,{className:U("size-3 shrink-0",o?"text-warn":"text-ok")}),(r||o)&&n.jsx("span",{className:U("truncate text-[10.5px]",r?"text-bad":"text-warn"),children:r?"断开":"重连中"})]}),n.jsx("button",{type:"button",onClick:s,title:t==="system"?"主题:跟随系统":t==="light"?"主题:浅色":"主题:深色","aria-label":"切换主题",className:"text-muted-foreground hover:bg-surface-2 hover:text-foreground flex size-6 shrink-0 items-center justify-center rounded transition-colors",children:n.jsx(a,{className:"size-3.5"})})]})}function Dg(){const{envRows:e,conversations:t,openConversation:s,openNewConv:r}=Ye(),o=[...t].sort((l,c)=>(c.createdAt??0)-(l.createdAt??0)).slice(0,6),a=t.length===0;return n.jsxs("div",{className:"flex min-h-0 flex-1 flex-col items-center justify-center gap-6 px-8",children:[n.jsxs("div",{className:"flex flex-col items-center gap-2 text-center",children:[n.jsx("span",{className:"border-line-strong bg-surface-2 flex size-11 items-center justify-center rounded-xl border",children:n.jsx(pn,{className:"size-5"})}),n.jsx("h2",{className:"text-foreground mt-1 text-[15px] font-semibold tracking-tight",children:a?"还没有会话":"选一个会话继续"}),n.jsx("p",{className:"text-muted-foreground max-w-[46ch] text-[12px] leading-relaxed",children:a?"选一个环境开始;会话发出第一条消息时会自动起名。":"从左栏选,或从下面最近的会话开始。"})]}),!a&&n.jsx("ul",{className:"border-line divide-line w-full max-w-xl divide-y overflow-hidden rounded-md border",children:o.map(l=>n.jsx("li",{children:n.jsx("button",{type:"button",onClick:()=>s(l),className:"bg-surface-2/40 hover:bg-surface-2 flex w-full items-center gap-2.5 px-3 py-2 text-left transition-colors",children:n.jsx("span",{className:"text-foreground/90 min-w-0 flex-1 truncate text-[11.5px]",children:l.title||`会话 #${l.conversationId}`})})},l.conversationId))}),e.length>0&&n.jsx("div",{className:"flex flex-wrap justify-center gap-1.5",children:e.map(l=>{const c=l.status?!l.status.ok:!1;return n.jsxs("button",{type:"button",onClick:()=>r(l.name),className:"border-line bg-surface-2/60 hover:border-line-strong hover:bg-surface-2 flex items-center gap-1.5 rounded-md border px-2.5 py-1.5 text-[11.5px] transition-all duration-150",children:[n.jsx(ss,{tone:l.status===void 0?"muted":c?"bad":"ok",size:"sm"}),n.jsx("span",{className:"text-foreground/90",children:l.label})]},l.name)})})]})}function zg({conversationId:e}){const{data:t,status:s,lastEventAt:r,serverError:o}=dr(`conv:${e}`);return i.useEffect(()=>{Lt.set(e,{data:t,status:s,lastEventAt:r,serverError:o})},[e,t,s,r,o]),i.useEffect(()=>()=>Lt.delete(e),[e]),null}function Fg({ids:e}){return n.jsx(n.Fragment,{children:e.map(t=>n.jsx(zg,{conversationId:t},t))})}function _g(e,t,s){const r=new Map,o=new Set;for(const d of e)if(d.kind==="toolResult"&&d.toolResult&&r.set(d.toolResult.callId,d.toolResult),d.kind==="exec"&&d.data&&typeof d.data=="object"){const m=d.data.execId;typeof m=="string"&&m&&o.add(m)}const a=new Map;for(const d of t?.tools??[])a.set(d.callId,d);const l=[],c=e.length?e[e.length-1].id:void 0;for(const d of e)switch(d.kind){case"user":{if(!d.text)break;l.push({id:`e${d.id}`,role:"user",content:[{type:"text",text:d.text}],...d.at?{createdAt:new Date(d.at)}:{}});break}case"assistant":{const m=[];d.thinking&&m.push({type:"reasoning",text:d.thinking}),d.text&&m.push({type:"text",text:d.text});for(const x of d.toolCalls??[]){const y=r.get(x.id),p=a.get(x.id),g={type:"tool-call",toolCallId:x.id,toolName:x.name,args:x.args,argsText:Hg(x.args)};x.argsError&&(g.argsText=x.argsError),y?(g.result=y.text,g.isError=y.isError,y.diff?g.artifact={diff:y.diff,durationMs:y.durationMs}:y.durationMs!==void 0&&(g.artifact={durationMs:y.durationMs})):p?(g.isPreliminary=!0,g.artifact={live:!0,status:p.status,output:p.output,droppedBytes:p.droppedBytes,droppedLines:p.droppedLines,diff:p.diff}):g.isPreliminary=!0,m.push(g)}if(m.length===0)break;const v=d.id===c&&t?.running?{type:"running"}:d.errorMessage?{type:"incomplete",reason:"error",error:d.errorMessage}:{type:"complete",reason:"stop"};l.push({id:`e${d.id}`,role:"assistant",content:m,status:v,...d.at?{createdAt:new Date(d.at)}:{},...d.model||d.provider?{metadata:{custom:Bg({model:d.model,provider:d.provider,durationMs:d.durationMs})}}:{}});break}case"toolResult":break;case"compaction":case"reset":{l.push({id:`e${d.id}`,role:"system",content:[{type:"data-pi-context",data:{kind:d.kind,text:d.text??"",raw:d.data??null}}],...d.at?{createdAt:new Date(d.at)}:{}});break}case"exec":{if(!d.data||typeof d.data!="object")break;l.push({id:`e${d.id}`,role:"system",content:[{type:"data-pi-exec",data:d.data}],...d.at?{createdAt:new Date(d.at)}:{}});break}case"system":case"other":default:{if(!d.text)break;l.push({id:`e${d.id}`,role:"system",content:[{type:"data-pi-context",data:{kind:d.kind,text:d.text,raw:d.data??null}}],...d.at?{createdAt:new Date(d.at)}:{}})}}for(const d of s??[])o.has(d.execId)||l.push({id:`pending-${d.execId}`,role:"system",content:[{type:"data-pi-exec",data:d}],createdAt:new Date(d.at)});const f=t?.generation?.text,u=t?.generation?.thinking;if(t?.running&&(f||u)){const d=[];u&&d.push({type:"reasoning",text:u}),f&&d.push({type:"text",text:f}),d.length&&l.push({id:`live-generation-${t.runTaskId??"x"}`,role:"assistant",content:d,status:{type:"running"}})}return l}function Lg(e){return typeof e=="string"?e:Array.isArray(e)?e.map(t=>{if(!t||typeof t!="object")return"";const s=t;return s.type==="text"&&typeof s.text=="string"?s.text:""}).filter(Boolean).join(`
12
+ `):""}function Bg(e){const t={};for(const[s,r]of Object.entries(e))r!==void 0&&(t[s]=r);return t}function Hg(e){try{return JSON.stringify(e??{})}catch{return"{}"}}const yi=({copiedDuration:e=3e3}={})=>{const[t,s]=i.useState(!1),r=i.useRef(void 0),o=i.useRef(0);return i.useEffect(()=>()=>{o.current+=1,r.current!==void 0&&(clearTimeout(r.current),r.current=void 0,s(!1))},[]),{isCopied:t,copyToClipboard:l=>{if(!l||typeof navigator>"u"||!navigator.clipboard)return;const c=o.current;navigator.clipboard.writeText(l).then(()=>{c===o.current&&(r.current!==void 0&&clearTimeout(r.current),s(!0),r.current=setTimeout(()=>{r.current=void 0,s(!1)},e))},()=>{})}}},Lc=i.createContext(void 0);function Hs(e){const t=i.useContext(Lc);if(t===void 0&&!e)throw new Error(Mt(72));return t}const Ug={...ns,disabled:e=>e.disabled,instantType:e=>e.instantType,isInstantPhase:e=>e.isInstantPhase,trackCursorAxis:e=>e.trackCursorAxis,disableHoverablePopup:e=>e.disableHoverablePopup,lastOpenChangeReason:e=>e.openChangeReason,closeOnClick:e=>e.closeOnClick,appliedTriggerProps:(e,t)=>t?e.activeTriggerProps:void 0,closeDelay:e=>e.closeDelay,adaptiveOrigin:e=>e.adaptiveOrigin};class Wg extends _r{constructor(t,s,r){const o=new fi;super(Gg(t,o,s,r),Vg(o),Ug)}setOpen=(t,s)=>{Ap(this,t,s,{extraState:{openChangeReason:s.reason}})};cancelPendingOpen(t){this.state.floatingRootContext.dispatchOpenChange(!1,Fe(mn,t))}}function Gg(e,t,s,r=!1){return{...mi(t,s,r),disabled:!1,instantType:void 0,isInstantPhase:!1,trackCursorAxis:"none",disableHoverablePopup:!1,openChangeReason:null,closeOnClick:!0,closeDelay:0,adaptiveOrigin:void 0,...e}}function Vg(e){return{popupRef:i.createRef(),onOpenChange:void 0,onOpenChangeComplete:void 0,triggerElements:e}}const Kg=Fr(function(t){const{disabled:s=!1,defaultOpen:r=!1,open:o,disableHoverablePopup:a=!1,trackCursorAxis:l="none",actionsRef:c,onOpenChange:f,onOpenChangeComplete:u,handle:d,triggerId:m,defaultTriggerId:k=null,children:v}=t,x=ii((L,K)=>new Wg({open:r,openProp:o,activeTriggerId:k,triggerIdProp:m},L,K));x.useControlledProp("openProp",o),x.useControlledProp("triggerIdProp",m),x.useContextCallback("onOpenChange",f),x.useContextCallback("onOpenChangeComplete",u);const y=x.useState("open"),p=!s&&y,g=x.useState("activeTriggerId"),j=x.useState("mounted"),C=x.useState("payload");x.useSyncedValues({trackCursorAxis:l,disableHoverablePopup:a,disabled:s}),ci(x,{closeOnActiveTriggerUnmount:!0});const{forceUnmount:h,transitionStatus:b}=ui(p,x),N=x.useState("isInstantPhase"),S=x.useState("instantType"),T=x.useState("lastOpenChangeReason"),P=i.useRef(null);pe(()=>{y&&s&&x.setOpen(!1,Fe(Df))},[y,s,x]),pe(()=>{b==="ending"&&T===Rr||b!=="ending"&&N?(S!=="delay"&&(P.current=S),x.set("instantType","delay")):P.current!==null&&(x.set("instantType",P.current),P.current=null)},[b,N,T,S,x]),pe(()=>{p&&g==null&&x.set("payload",void 0)},[x,g,p]),i.useImperativeHandle(c,()=>({unmount:h,close:()=>x.setOpen(!1,Fe(Jo))}),[h,x]);const B=p||j||!s&&l!=="none";return n.jsxs(Lc.Provider,{value:x,children:[d&&n.jsx(ai,{handle:d,store:x}),B&&n.jsx(qg,{store:x,disabled:s,trackCursorAxis:l}),typeof v=="function"?v({payload:C}):v]})});function qg({store:e,disabled:t,trackCursorAxis:s}){const r=e.useState("floatingRootContext"),o=si(r,{enabled:!t,referencePress:()=>e.select("closeOnClick")}),a=Np(r,{enabled:!t&&s!=="none",axis:s==="none"?void 0:s}),l=i.useMemo(()=>Cr(a.reference,o.reference),[a.reference,o.reference]);return di(e,{activeTriggerProps:l,inactiveTriggerProps:l,popupProps:o.floating??bt}),null}const Bc=i.createContext(void 0);function Yg(){return i.useContext(Bc)}const Xg=600,Ia="data-base-ui-tooltip-trigger";function Aa(e){const t=kt(e);return Ze(t)?t:null}const Jg=uc(function(t,s){const{render:r,className:o,style:a,handle:l,payload:c,disabled:f,delay:u,closeOnClick:d=!0,closeDelay:m,id:k,...v}=t,x=Hs(!0),p=pc(l)??x;if(!p)throw new Error(Mt(82));const g=_s(k),j=p.useState("isTriggerActive",g),C=p.useState("isOpenedByTrigger",g),h=p.useState("floatingRootContext"),b=i.useRef(null),N=m??0,{registerTrigger:S,isMountedByThisTrigger:T}=ac(g,b,p,{payload:c,closeOnClick:d,closeDelay:N}),P=Yg(),{activeIdRef:B,delayRef:L,isInstantPhase:K,hasProvider:A}=tp(h,{open:C}),z=xi(h);p.useSyncedValue("isInstantPhase",K);const M=p.useState("disabled"),R=f??M,W=dt(R),I=p.useState("trackCursorAxis"),_=p.useState("disableHoverablePopup"),V=i.useRef(!1),H=tn(),Y=i.useRef(void 0);function le(){return A&&B.current!=null?0:u??P??Xg}function J(G){const fe=b.current;if(!fe||!G)return!1;const te=Is(G,`[${Ia}]`);return te!==null&&te!==fe&&be(fe,te)}function se(G){const fe=J(G);return V.current=fe,fe&&(z.openChangeTimeout.clear(),z.restTimeout.clear(),z.restTimeoutPending=!1,H.clear()),fe}const Z=xc(h,{enabled:!R,mouseOnly:!0,move:!1,handleClose:!_&&I!=="both"?hc():null,restMs:le,delay(){return m==null&&A?{close:Bn(L.current,"close")}:{close:N}},triggerElementRef:b,isActiveTrigger:j,isClosing:()=>p.select("transitionStatus")==="ending",shouldOpen(){return!V.current}}),re=Xp(h,{enabled:!R}).reference,we=G=>{const fe=V.current,te=Aa(G),ae=se(te),ce=b.current,je=ce&&te&&be(ce,te);if(ae&&p.select("open")&&p.select("lastOpenChangeReason")===ut){p.setOpen(!1,Fe(ut,G));return}if(fe&&!ae&&je&&!W.current&&!p.select("open")&&ce&&Cn(Y.current)){const $e=()=>{!V.current&&!W.current&&!p.select("open")&&p.setOpen(!0,Fe(ut,G,ce))},Q=le();Q===0?(H.clear(),$e()):H.start(Q,$e)}},D=p.useState("appliedTriggerProps",T||I!=="none");return yt("button",t,{state:{open:C},ref:[s,S,b],props:[Z,re,D,{onMouseOver(G){we(G.nativeEvent)},onFocus(G){J(Aa(G.nativeEvent))&&G.preventBaseUIHandler()},onMouseLeave(){V.current=!1,H.clear(),Y.current=void 0},onPointerEnter(G){Y.current=G.pointerType},onPointerDown(G){Y.current=G.pointerType,p.set("closeOnClick",d),d&&!p.select("open")&&p.cancelPendingOpen(G.nativeEvent)},onClick(G){d&&!p.select("open")&&p.cancelPendingOpen(G.nativeEvent)},id:g,[Po]:R?"":void 0,[Ia]:R?void 0:""},v],stateAttributesMapping:Nl})}),Hc=i.createContext(void 0);function Zg(){const e=i.useContext(Hc);if(e===void 0)throw new Error(Mt(70));return e}const Qg=i.forwardRef(function(t,s){const{children:r,container:o,className:a,render:l,style:c,...f}=t,{node:u,subtree:d}=Zl({container:o,ref:s,componentProps:t,elementProps:f});return!d&&!u?null:n.jsxs(i.Fragment,{children:[d,u&&gn.createPortal(r,u)]})}),ex=i.forwardRef(function(t,s){const{keepMounted:r=!1,...o}=t;return Hs().useState("mounted")||r?n.jsx(Hc.Provider,{value:r,children:n.jsx(Qg,{ref:s,...o})}):null}),Uc=i.createContext(void 0);function Wc(){const e=i.useContext(Uc);if(e===void 0)throw new Error(Mt(71));return e}const tx=i.forwardRef(function(t,s){const{render:r,className:o,anchor:a,positionMethod:l="absolute",side:c="top",align:f="center",sideOffset:u=0,alignOffset:d=0,collisionBoundary:m="clipping-ancestors",collisionPadding:k=5,arrowPadding:v=5,sticky:x=!1,disableAnchorTracking:y=!1,collisionAvoidance:p=Yl,style:g,...j}=t,C=Hs(),h=Zg(),b=C.useState("open"),N=C.useState("mounted"),S=C.useState("trackCursorAxis"),T=C.useState("disableHoverablePopup"),P=C.useState("floatingRootContext"),B=C.useState("instantType"),L=C.useState("transitionStatus"),K=C.useState("adaptiveOrigin"),A=Oc({anchor:a,positionMethod:l,floatingRootContext:P,mounted:N,side:c,sideOffset:u,align:f,alignOffset:d,collisionBoundary:m,collisionPadding:k,sticky:x,arrowPadding:v,disableAnchorTracking:y,keepMounted:h,collisionAvoidance:p,adaptiveOrigin:K}),z=i.useMemo(()=>({open:b,side:A.side,align:A.align,anchorHidden:A.anchorHidden,instant:S!=="none"?"tracking-cursor":B}),[b,A.side,A.align,A.anchorHidden,S,B]),M=Ic(t,z,{styles:A.positionerStyles,transitionStatus:L,props:j,refs:[s,C.useStateSetter("positionerElement")],hidden:!N,inert:!b||S==="both"||T});return n.jsx(Uc.Provider,{value:A,children:M})}),nx=i.forwardRef(function(t,s){const{render:r,className:o,style:a,...l}=t,c=Hs(),{side:f,align:u}=Wc(),d=c.useState("open"),m=c.useState("instantType"),k=c.useState("transitionStatus"),v=c.useState("popupProps"),x=c.useState("floatingRootContext"),y=c.useState("disabled"),p=c.useState("closeDelay");Ls({open:d,ref:c.context.popupRef,onComplete(){d&&c.context.onOpenChangeComplete?.(!0)}}),gc(x,{enabled:!y,closeDelay:p});const g=c.useStateSetter("popupElement");return yt("div",t,{state:{open:d,side:f,align:u,instant:m,transitionStatus:k},ref:[s,c.context.popupRef,g],props:[oi,v,vi(k),l],stateAttributesMapping:Xo})}),sx=i.forwardRef(function(t,s){const{render:r,className:o,style:a,...l}=t,c=Hs(),{arrowRef:f,side:u,align:d,arrowUncentered:m,arrowStyles:k}=Wc(),v=c.useState("open"),x=c.useState("instantType");return yt("div",t,{state:{open:v,side:u,align:d,uncentered:m,instant:x},ref:[s,f],props:[{style:k,"aria-hidden":!0},l],stateAttributesMapping:Tr})}),rx=function(t){const{delay:s,closeDelay:r,timeout:o=400}=t,a=i.useMemo(()=>({open:s,close:r}),[s,r]);return n.jsx(Bc.Provider,{value:s,children:n.jsx(ep,{delay:a,timeoutMs:o,children:t.children})})};function ox({delay:e=0,...t}){return n.jsx(rx,{"data-slot":"tooltip-provider",delay:e,...t})}function ix({...e}){return n.jsx(Kg,{"data-slot":"tooltip",...e})}function ax({...e}){return n.jsx(Jg,{"data-slot":"tooltip-trigger",...e})}function lx({className:e,side:t="top",sideOffset:s=4,align:r="center",alignOffset:o=0,children:a,...l}){return n.jsx(ex,{children:n.jsx(tx,{align:r,alignOffset:o,side:t,sideOffset:s,className:"isolate z-50",children:n.jsxs(nx,{"data-slot":"tooltip-content",className:U("z-50 inline-flex w-fit max-w-xs origin-(--transform-origin) items-center gap-1.5 rounded-md bg-foreground px-3 py-1.5 text-xs text-background has-data-[slot=kbd]:pr-1.5 data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 **:data-[slot=kbd]:relative **:data-[slot=kbd]:isolate **:data-[slot=kbd]:z-50 **:data-[slot=kbd]:rounded-sm data-[state=delayed-open]:animate-in data-[state=delayed-open]:fade-in-0 data-[state=delayed-open]:zoom-in-95 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",e),...l,children:[a,n.jsx(sx,{className:"z-50 size-2.5 translate-y-[calc(-50%-2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground data-[side=bottom]:top-1 data-[side=inline-end]:top-1/2! data-[side=inline-end]:-left-1 data-[side=inline-end]:-translate-y-1/2 data-[side=inline-start]:top-1/2! data-[side=inline-start]:-right-1 data-[side=inline-start]:-translate-y-1/2 data-[side=left]:top-1/2! data-[side=left]:-right-1 data-[side=left]:-translate-y-1/2 data-[side=right]:top-1/2! data-[side=right]:-left-1 data-[side=right]:-translate-y-1/2 data-[side=top]:-bottom-2.5"})]})})})}const Gc=i.forwardRef(({children:e,tooltip:t,side:s="bottom",className:r,...o},a)=>n.jsx(ox,{children:n.jsxs(ix,{children:[n.jsxs(ax,{render:n.jsx(ke,{variant:"ghost",size:"icon",...o,className:U("aui-button-icon size-6 p-1 active:scale-90",r),ref:a}),children:[e,n.jsx("span",{className:"aui-sr-only sr-only",children:t})]}),n.jsx(lx,{side:s,children:t})]})}));Gc.displayName="TooltipIconButton";const cx=(e,t)=>e!==void 0&&t!==void 0&&Object.keys(e).length===Object.keys(t).length&&Object.keys(t).every(s=>e[s]===t[s]),Ma=e=>{const[t,s]=i.useState(e);return e!==t&&!cx(t,e)?(s(e),e):t},ux=({components:e,componentsByLanguage:t})=>{const s=Ma(e),r=Ma(t),o=i.useMemo(()=>s?{...$a,...Ya(s)}:$a,[s]);return n.jsx(ju,{remarkPlugins:[Xa],className:"aui-md text-foreground/95 text-[13.5px] leading-[1.65]",components:o,componentsByLanguage:r,defer:!0})},ki=i.memo(ux),dx=({language:e,code:t})=>{const{isCopied:s,copyToClipboard:r}=yi(),o=()=>{!t||s||r(t)};return n.jsxs("div",{className:"aui-code-header-root border-border/50 bg-muted/50 mt-2 flex items-center justify-between rounded-t-lg border border-b-0 px-3 py-1 text-[11px]",children:[n.jsx("span",{className:"aui-code-header-language text-muted-foreground font-medium lowercase",children:e}),n.jsxs(Gc,{tooltip:"Copy",onClick:o,children:[!s&&n.jsx(jr,{className:"animate-in zoom-in-75 fade-in duration-150"}),s&&n.jsx(sn,{className:"animate-in zoom-in-50 fade-in duration-200 ease-out"})]})]})},$a=Ya({h1:({className:e,...t})=>n.jsx("h1",{className:U("aui-md-h1 mt-4 mb-1.5 scroll-m-20 text-[15.5px] font-semibold first:mt-0 last:mb-0",e),...t}),h2:({className:e,...t})=>n.jsx("h2",{className:U("aui-md-h2 mt-3.5 mb-1.5 scroll-m-20 text-[14.5px] font-semibold first:mt-0 last:mb-0",e),...t}),h3:({className:e,...t})=>n.jsx("h3",{className:U("aui-md-h3 mt-3 mb-1 scroll-m-20 text-[13.5px] font-semibold first:mt-0 last:mb-0",e),...t}),h4:({className:e,...t})=>n.jsx("h4",{className:U("aui-md-h4 mt-2.5 mb-1 scroll-m-20 text-[13.5px] font-medium first:mt-0 last:mb-0",e),...t}),h5:({className:e,...t})=>n.jsx("h5",{className:U("aui-md-h5 mt-2 mb-1 text-[13px] font-semibold first:mt-0 last:mb-0",e),...t}),h6:({className:e,...t})=>n.jsx("h6",{className:U("aui-md-h6 mt-2 mb-1 text-[13px] font-medium first:mt-0 last:mb-0",e),...t}),p:({className:e,...t})=>n.jsx("p",{className:U("aui-md-p my-2 leading-[1.65] first:mt-0 last:mb-0",e),...t}),a:({className:e,...t})=>n.jsx("a",{className:U("aui-md-a text-primary hover:text-primary/80 underline underline-offset-2",e),...t}),blockquote:({className:e,...t})=>n.jsx("blockquote",{className:U("aui-md-blockquote border-muted-foreground/30 text-muted-foreground my-2 border-s-2 ps-3",e),...t}),ul:({className:e,...t})=>n.jsx("ul",{className:U("aui-md-ul marker:text-muted-foreground my-2 ms-4.5 list-disc [&>li]:mt-0.5",e),...t}),ol:({className:e,...t})=>n.jsx("ol",{className:U("aui-md-ol marker:text-muted-foreground my-2 ms-4.5 list-decimal [&>li]:mt-0.5",e),...t}),hr:({className:e,...t})=>n.jsx("hr",{className:U("aui-md-hr border-muted-foreground/20 my-2.5",e),...t}),table:({className:e,...t})=>n.jsx("div",{className:"aui-md-table-wrapper my-2 overflow-x-auto",children:n.jsx("table",{className:U("aui-md-table w-full border-separate border-spacing-0 text-[12.5px]",e),...t})}),th:({className:e,...t})=>n.jsx("th",{className:U("aui-md-th bg-muted px-2.5 py-1 text-start font-medium first:rounded-ss-lg last:rounded-se-lg [[align=center]]:text-center [[align=right]]:text-right",e),...t}),td:({className:e,...t})=>n.jsx("td",{className:U("aui-md-td border-muted-foreground/20 border-s border-b px-2.5 py-1 text-start last:border-e [[align=center]]:text-center [[align=right]]:text-right",e),...t}),tr:({className:e,...t})=>n.jsx("tr",{className:U("aui-md-tr m-0 border-b p-0 first:border-t [&:last-child>td:first-child]:rounded-es-lg [&:last-child>td:last-child]:rounded-ee-lg",e),...t}),li:({className:e,...t})=>n.jsx("li",{className:U("aui-md-li leading-[1.65]",e),...t}),strong:({className:e,...t})=>n.jsx("strong",{className:U("aui-md-strong font-semibold",e),...t}),sup:({className:e,...t})=>n.jsx("sup",{className:U("aui-md-sup [&>a]:text-xs [&>a]:no-underline",e),...t}),pre:({className:e,...t})=>n.jsx("pre",{className:U("aui-md-pre border-border/50 bg-muted/30 overflow-x-auto rounded-t-none rounded-b-lg border border-t-0 p-2.5 text-[12px] leading-[1.55]",e),...t}),code:function({className:t,...s}){const r=wu();return n.jsx("code",{className:U(!r&&"aui-md-inline-code bg-muted rounded px-1 py-px font-mono text-[0.88em]",t),...s})},CodeHeader:dx}),fx=typeof globalThis.window<"u",px=fx?i.useLayoutEffect:i.useEffect;function mx({controlled:e,default:t,name:s,state:r="value"}){const{current:o}=i.useRef(e!==void 0),[a,l]=i.useState(()=>t),c=o&&e!==void 0?e:a,f=i.useCallback(u=>{o||l(u)},[]);return[c,f]}function gx(e){const{open:t,defaultOpen:s=!1,onOpenChange:r,disabled:o}=e,[a,l]=mx({controlled:t,default:s,name:"Collapsible",state:"open"}),{mounted:c,setMounted:f,transitionStatus:u}=rc(a,!0,!0),d=_s(),[m,k]=i.useState(),v=m===null?void 0:m??d,x=ye(y=>{const p=!a,g=Fe(mn,y.nativeEvent);r(p,g),!g.isCanceled&&l(p)});return i.useMemo(()=>({defaultPanelId:d,disabled:o,handleTrigger:x,mounted:c,open:a,panelId:v,setMounted:f,setOpen:l,setPanelIdState:k,transitionStatus:u}),[d,o,x,c,a,v,f,l,k,u])}const Vc=i.createContext(void 0);function Kc(){const e=i.useContext(Vc);if(e===void 0)throw new Error(Mt(15));return e}const xx="data-open",hx="data-closed",sr=Yo,bx="data-panel-open",vx={[xx]:""},yx={[hx]:""},kx={open(e){return e?{[bx]:""}:null}},jx={open(e){return e?vx:yx}},qc={...jx,...Er},wx=i.forwardRef(function(t,s){const{render:r,className:o,defaultOpen:a=!1,disabled:l=!1,onOpenChange:c,open:f,style:u,...d}=t,m=ye(c),k=gx({open:f,defaultOpen:a,onOpenChange:m,disabled:l}),v=i.useMemo(()=>({open:k.open,disabled:k.disabled,transitionStatus:k.transitionStatus}),[k.open,k.disabled,k.transitionStatus]),x=i.useMemo(()=>({...k,onOpenChange:m,state:v}),[k,m,v]),y=yt("div",t,{state:v,ref:s,props:d,stateAttributesMapping:qc});return n.jsx(Vc.Provider,{value:x,children:y})}),Cx={...kx,...Er},Sx=i.forwardRef(function(t,s){const{panelId:r,open:o,handleTrigger:a,state:l,disabled:c}=Kc(),{className:f,disabled:u=c,render:d,nativeButton:m=!0,style:k,...v}=t,{getButtonProps:x,buttonRef:y}=Sr({disabled:u,native:m});return yt("button",t,{state:l,ref:[s,y],props:[{"aria-controls":o?r:void 0,"aria-expanded":o,onClick:a},v,x],stateAttributesMapping:Cx})}),Qn={height:void 0,width:void 0};function Nx(e){const{externalRef:t,hiddenUntilFound:s,id:r,keepMounted:o,mounted:a,onOpenChange:l,open:c,setMounted:f,setOpen:u,transitionStatus:d}=e,m=i.useRef(null),k=i.useRef(null),[v,x]=i.useState(Qn),y=i.useRef(Qn),p=i.useRef(!1),g=i.useRef(c),j=i.useRef(!1),[C,h]=i.useState(!1),b=i.useRef(null),N=Rs(t,m),S=dt(c),T=ri(m),P=!c&&!a,B=C?"idle":d,L=c&&(g.current||j.current),K=!c&&a&&k.current==="css-animation"&&v.height===void 0&&v.width===void 0?y.current:v,A=s&&P&&k.current!=="css-animation",z=ye((_,V=!0)=>{V&&(y.current=_),x(_)}),M=ye(()=>{b.current?.(),b.current=null}),R=ye(_=>{M(),b.current=()=>{b.current=null,_()}}),W=ye(()=>{c&&a&&k.current==="css-animation"&&(j.current=!0)});pe(()=>{!C||d==="starting"||h(!1)},[C,d]),i.useEffect(()=>()=>{W(),M()},[W,M]),pe(()=>{c||(g.current=!1,j.current=!1);const _=m.current;if(!_)return;!c&&b.current&&M();const V=Ex(_,L);if(k.current=V,c&&d==="idle"&&g.current&&V==="css-animation"){y.current=es(_);return}if(c&&d==="starting"){const le=p.current;if(p.current=!1,V==="none"){z(es(_)),h(!0);return}if(V==="css-transition"){const Z=Tx(_);if(z(es(_)),!le)return Z;const re=rr(_,"transition-duration","0s");return R(re),h(!0),Z}z(es(_));const J=rr(_,"animation-name","none");if(!le){J();return}const se=rr(_,"animation-duration","0s");J(),R(se),h(!0);return}if(!c&&a&&(d==="idle"||d==="starting")){if(V==="none"){z(Qn,!1),f(!1);return}z(es(_));return}if(d!=="ending")return;if(V==="none"){f(!1);return}const H=es(_);if(!(H.height>0||H.width>0)){f(!1);return}z(H),V==="css-animation"&&rr(_,"animation-name","none")()},[a,c,M,z,f,R,L,d]),Ls({enabled:c&&a&&B==="idle",open:!0,ref:m,onComplete(){c&&z(Qn,!1)}}),i.useEffect(()=>{if(c||!a||B!=="ending")return;if(!m.current){f(!1),z(Qn,!1);return}const V=new AbortController;let H=-1;function Y(){S.current||(f(!1),z(Qn,!1))}return H=ht.request(()=>{T(Y,V.signal)}),()=>{ht.cancel(H),V.abort()}},[S,a,c,B,T,z,f]),pe(()=>{const _=m.current;!_||!s||!P||_.setAttribute("hidden","until-found")},[P,s]),i.useEffect(function(){const V=m.current;if(!V)return;const H=At.create();let Y=-1;const le=(Z,re)=>{H.start(0,()=>{S.current||(Y=ht.request(()=>{S.current||(Z&&(p.current=!1),re&&V.setAttribute(sr,""),V.setAttribute("hidden","until-found"))}))})},se=Te(V,"beforematch",Z=>{const re=Fe(Rr,Z);if(l(!0,re),re.isCanceled){le(!1,!1);return}p.current=!0;const we=V.hasAttribute(sr);V.removeAttribute(sr),u(!0),le(!0,we)});return()=>{H.clear(),ht.cancel(Y),se()}},[S,l,u]);const I=o||s||a||c;return{height:K.height,props:{...A?{[sr]:""}:void 0,hidden:P,id:r},ref:N,shouldPreventOpenAnimation:L,shouldRender:I,transitionStatus:B,width:K.width}}function es(e){return{height:e.scrollHeight,width:e.scrollWidth}}function Ex(e,t){const s=xn(e).getComputedStyle(e),r=(s.animationName.split(",").map(a=>a.trim()).some(a=>a!==""&&a!=="none")||t)&&Da(s.animationDuration),o=Da(s.transitionDuration);return r&&o||o?"css-transition":r?"css-animation":"none"}function Da(e){return e.split(",").map(t=>t.trim()).some(t=>t!==""&&Number.parseFloat(t)>0)}function rr(e,t,s){const r=e.style.getPropertyValue(t),o=e.style.getPropertyPriority(t);return e.style.setProperty(t,s),()=>{if(r===""){e.style.removeProperty(t);return}e.style.setProperty(t,r,o)}}function Tx(e){const t={"justify-content":e.style.justifyContent,"align-items":e.style.alignItems,"align-content":e.style.alignContent,"justify-items":e.style.justifyItems};Object.keys(t).forEach(o=>{e.style.setProperty(o,"initial","important")});function s(){Object.entries(t).forEach(([o,a])=>{if(a===""){e.style.removeProperty(o);return}e.style.setProperty(o,a)})}const r=ht.request(s);return()=>{ht.cancel(r),s()}}const Rx="--collapsible-panel-height",Px="--collapsible-panel-width",Ox=i.forwardRef(function(t,s){const{className:r,hiddenUntilFound:o,keepMounted:a,render:l,id:c,style:f,...u}=t,{defaultPanelId:d,mounted:m,onOpenChange:k,open:v,setMounted:x,setPanelIdState:y,setOpen:p,state:g,transitionStatus:j}=Kc(),C=o??!1,h=a??!1,b=c||void 0,N=b??d;pe(()=>(y(W=>b??(W===null?void 0:W)),()=>{y(W=>W===b?null:W)}),[b,y]);const{height:S,props:T,ref:P,shouldPreventOpenAnimation:B,shouldRender:L,transitionStatus:K,width:A}=Nx({externalRef:s,hiddenUntilFound:C,id:N,keepMounted:h,mounted:m,onOpenChange:k,open:v,setMounted:x,setOpen:p,transitionStatus:j}),z={...g,transitionStatus:K},M=kl(f,z),R=yt("div",{...t,style:void 0},{state:z,ref:P,props:[T,{style:{[Rx]:S===void 0?"auto":`${S}px`,[Px]:A===void 0?"auto":`${A}px`}},u,M?{style:M}:void 0,B?{style:{animationName:"none"}}:void 0],stateAttributesMapping:qc});return L?R:null}),Yc=i.forwardRef(function(t,s){return n.jsx(wx,{ref:s,"data-slot":"collapsible",...t})});function Xc({...e}){return n.jsx(Sx,{"data-slot":"collapsible-trigger",...e})}function Jc({...e}){return n.jsx(Ox,{"data-slot":"collapsible-content",...e})}const Zc=200,ji=i.createContext(!1),Ix=wl("aui-reasoning-root mb-4 w-full",{variants:{variant:{outline:"rounded-lg border px-3 py-2",ghost:"",muted:"bg-muted/50 rounded-lg px-3 py-2"}},defaultVariants:{variant:"outline"}}),Ax=i.forwardRef(function({className:t,variant:s,open:r,onOpenChange:o,defaultOpen:a=!1,streaming:l,onAnimationStart:c,children:f,...u},d){const[m]=i.useState(a),[k,v]=i.useState(null),x=r!==void 0,y=x?r:k??(l||m),p=l===!0&&y,g=i.useRef(l);px(()=>{g.current!==l&&(g.current=l,!x&&k===null&&!m&&c?.())},[l,x,k,m,c]);const j=i.useCallback(C=>{c?.(),x||v(C),o?.(C)},[c,x,o]);return n.jsx(Yc,{ref:d,"data-slot":"reasoning-root","data-variant":s,open:y,onOpenChange:j,className:U("group/reasoning-root",Ix({variant:s,className:t})),style:{"--animation-duration":`${Zc}ms`},...u,children:n.jsx(ji.Provider,{value:p,children:f})})});function Do({side:e="bottom",className:t,...s}){return e==="top"?n.jsx("div",{"data-slot":"reasoning-fade",className:U("aui-reasoning-fade pointer-events-none absolute inset-x-0 top-0 z-10 h-8","bg-[linear-gradient(to_bottom,var(--color-background),transparent)]","group-data-[variant=muted]/reasoning-root:bg-[linear-gradient(to_bottom,color-mix(in_oklab,var(--color-muted)_50%,var(--color-background)),transparent)]","fade-in-0 animate-in","animation-duration-(--animation-duration)",t),...s}):n.jsx("div",{"data-slot":"reasoning-fade",className:U("aui-reasoning-fade pointer-events-none absolute inset-x-0 bottom-0 z-10 h-8","bg-[linear-gradient(to_top,var(--color-background),transparent)]","group-data-[variant=muted]/reasoning-root:bg-[linear-gradient(to_top,color-mix(in_oklab,var(--color-muted)_50%,var(--color-background)),transparent)]","fade-in-0 animate-in","animation-duration-(--animation-duration)",t),...s})}function wi({active:e,duration:t,label:s="Reasoning",className:r,...o}){const a=t?` (${t}s)`:"";return n.jsxs(Xc,{"data-slot":"reasoning-trigger",className:U("aui-reasoning-trigger group/trigger text-muted-foreground hover:text-foreground flex max-w-[75%] origin-left items-center gap-2 py-1.5 text-sm transition-[color,scale] active:scale-[0.98]",r),...o,children:[n.jsx(Bo,{"data-slot":"reasoning-trigger-icon",className:"aui-reasoning-trigger-icon size-4 shrink-0"}),n.jsxs("span",{"data-slot":"reasoning-trigger-label",className:U("aui-reasoning-trigger-label-wrapper inline-block leading-none tabular-nums",e&&"shimmer motion-reduce:animate-none"),children:[s,a]}),n.jsx(ls,{"data-slot":"reasoning-trigger-chevron",className:U("aui-reasoning-trigger-chevron mt-0.5 size-4 shrink-0","transition-transform duration-(--animation-duration) ease-[cubic-bezier(0.32,0.72,0,1)] motion-reduce:transition-none","-rotate-90","group-data-open/trigger:rotate-0","group-data-panel-open/trigger:rotate-0")})]})}function Ci({className:e,children:t,...s}){const r=i.useContext(ji);return n.jsxs(Jc,{"data-slot":"reasoning-content",className:U("aui-reasoning-content text-muted-foreground relative overflow-hidden text-sm outline-none","group/collapsible-content ease-[cubic-bezier(0.32,0.72,0,1)] motion-reduce:animate-none","data-closed:animate-collapsible-up","data-open:animate-collapsible-down","data-closed:fill-mode-forwards","data-closed:pointer-events-none","[--tw-duration:var(--animation-duration)]",e),...s,children:[n.jsx(Do,{side:"top"}),t,r?n.jsx(Do,{}):null]})}function Si({className:e,children:t,...s}){const r=i.useContext(ji),o=i.useRef(null),a=i.useRef(null);return i.useEffect(()=>{if(!r)return;const l=o.current,c=a.current;if(!l||!c)return;let f=!0,u=l.scrollTop,d=l.scrollHeight;const m=()=>Math.abs(l.scrollHeight-l.scrollTop-l.clientHeight)<=1||l.scrollHeight<=l.clientHeight,k=()=>{f&&(l.scrollTop=l.scrollHeight)},v=()=>{m()?f=!0:l.scrollTop<u&&l.scrollHeight===d&&(f=!1),u=l.scrollTop,d=l.scrollHeight};k(),l.addEventListener("scroll",v);const x=new ResizeObserver(k);return x.observe(c),()=>{l.removeEventListener("scroll",v),x.disconnect()}},[r]),n.jsx("div",{ref:o,"data-slot":"reasoning-text",className:U("aui-reasoning-text relative z-0 max-h-64 overflow-y-auto ps-6 pt-2 pb-2 leading-relaxed text-pretty","transform-gpu transition-[transform,opacity] ease-[cubic-bezier(0.32,0.72,0,1)]","motion-reduce:animate-none","group-data-open/collapsible-content:animate-in","group-data-closed/collapsible-content:animate-out","group-data-open/collapsible-content:fade-in-0","group-data-closed/collapsible-content:fade-out-0","group-data-open/collapsible-content:slide-in-from-top-4","group-data-closed/collapsible-content:slide-out-to-top-4","group-data-open/collapsible-content:blur-in-[2px]","group-data-closed/collapsible-content:blur-out-[2px]","group-data-open/collapsible-content:animation-duration-(--animation-duration)","group-data-closed/collapsible-content:animation-duration-(--animation-duration)",e),...s,children:n.jsx("div",{ref:a,className:"aui-reasoning-text-content space-y-4",children:t})})}const Ni=i.forwardRef(function({onAnimationStart:t,...s},r){const o=i.useRef(null),a=Ja(o,Zc),l=i.useCallback(()=>{a(),t?.()},[a,t]),c=i.useCallback(f=>{if(o.current=f,typeof r=="function"){const u=r(f);if(typeof u=="function")return()=>{o.current=null,u()}}else r&&(r.current=f)},[r]);return n.jsx(Ax,{ref:c,onAnimationStart:l,...s})}),Mx=()=>n.jsx(ki,{}),$x=({children:e,startIndex:t,endIndex:s})=>{const r=en(o=>{if(o.message.status?.type!=="running")return!1;for(let a=t;a<=s;a++)if(o.message.parts[a]?.status.type==="running")return!0;return!1});return n.jsxs(Ni,{streaming:r,children:[n.jsx(wi,{active:r}),n.jsx(Ci,{"aria-busy":r,children:n.jsx(Si,{children:e})})]})},fs=i.memo(Mx);fs.displayName="Reasoning";fs.Root=Ni;fs.Trigger=wi;fs.Content=Ci;fs.Text=Si;fs.Fade=Do;const Dx=i.memo($x);Dx.displayName="ReasoningGroup";function zx(e){return e?e.split(`
13
+ `).map(t=>{if(t.length===0)return{kind:"ctx",num:"",text:""};const s=t[0],r=t.slice(1);if(r.trim()==="...")return{kind:"skip"};const o=/^(\s*\d+) ?(.*)$/.exec(r);return{kind:s==="+"?"add":s==="-"?"del":"ctx",num:o?o[1].trim():"",text:o?o[2]:r}}):[]}const Fx={add:"bg-diff-add/12 text-diff-add",del:"bg-diff-del/12 text-diff-del",ctx:"text-muted-foreground"},_x={add:"+",del:"−",ctx:" "};function Lx({text:e,className:t}){const s=i.useMemo(()=>zx(e),[e]);return s.length===0?n.jsx("p",{className:"text-muted-foreground px-3 py-2 text-[11px]",children:"没有可显示的差异内容"}):n.jsx("div",{className:U("pg-scroll-y font-mono text-[11.5px] leading-[1.65]",t),children:n.jsx("table",{className:"w-full border-separate border-spacing-0",children:n.jsx("tbody",{children:s.map((r,o)=>r.kind==="skip"?n.jsx("tr",{children:n.jsx("td",{colSpan:3,className:"bg-surface-2 text-muted-foreground/70 px-2 py-0.5 text-center text-[10px] tracking-widest",children:"··· 未改动的行已省略 ···"})},o):n.jsxs("tr",{className:U("group/row",Fx[r.kind]),children:[n.jsx("td",{className:U("w-6 select-none px-1 text-right align-top opacity-60",r.kind==="add"&&"text-diff-add",r.kind==="del"&&"text-diff-del"),title:r.kind==="add"?"新文件行号":(r.kind==="del","旧文件行号"),children:r.num}),n.jsx("td",{className:"w-4 select-none px-0.5 text-center align-top font-semibold opacity-70",children:_x[r.kind]}),n.jsx("td",{className:"whitespace-pre-wrap break-all pr-2 align-top",children:r.text||" "})]},o))})})})}function Bx(e){if(!e)return[];const t=[];let s=0,r=0;for(const o of e.split(`
14
+ `)){const a=/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@(.*)$/.exec(o);if(a){s=Number(a[1]),r=Number(a[2]),t.push({kind:"hunk",header:o,oldStart:s,newStart:r});continue}if(o.startsWith("+++")||o.startsWith("---")||o.startsWith("diff ")||o.startsWith("index ")){t.push({kind:"meta",text:o});continue}o.startsWith("+")?t.push({kind:"add",oldNum:"",newNum:String(r++),text:o.slice(1)}):o.startsWith("-")?t.push({kind:"del",oldNum:String(s++),newNum:"",text:o.slice(1)}):t.push({kind:"ctx",oldNum:String(s++),newNum:String(r++),text:o.replace(/^ /,"")})}return t}function Qc({patch:e,className:t}){const s=i.useMemo(()=>Bx(e),[e]);return s.length===0?n.jsx("p",{className:"text-muted-foreground px-3 py-2 text-[11px]",children:"补丁为空"}):n.jsx("div",{className:U("pg-scroll-y font-mono text-[11.5px] leading-[1.65]",t),children:n.jsx("table",{className:"w-full border-separate border-spacing-0",children:n.jsx("tbody",{children:s.map((r,o)=>{if(r.kind==="meta")return n.jsx("tr",{children:n.jsx("td",{colSpan:3,className:"text-muted-foreground/70 bg-surface-2 px-2 py-0.5 text-[10.5px] break-all",children:r.text})},o);if(r.kind==="hunk")return n.jsx("tr",{children:n.jsx("td",{colSpan:3,className:"bg-brand/10 text-brand border-y border-brand/20 px-2 py-0.5 text-[10.5px]",children:r.header})},o);const a=r.kind==="add"?"bg-diff-add/12 text-diff-add":r.kind==="del"?"bg-diff-del/12 text-diff-del":"text-muted-foreground";return n.jsxs("tr",{className:a,children:[n.jsx("td",{className:"w-8 select-none px-1 text-right align-top opacity-50",children:r.oldNum}),n.jsx("td",{className:"w-8 select-none px-1 text-right align-top opacity-50",children:r.newNum}),n.jsxs("td",{className:"whitespace-pre-wrap break-all pr-2 align-top",children:[n.jsx("span",{className:"mr-1 inline-block w-2 select-none text-center opacity-70",children:r.kind==="add"?"+":r.kind==="del"?"−":" "}),r.text||" "]})]},o)})})})})}function Hx({diff:e,className:t}){const[s,r]=i.useState("text"),o=e.patch.trim().length>0,a=e.text.trim().length>0,l=s==="patch"&&o?"patch":a?"text":"patch",c=i.useMemo(()=>Ux(e),[e]);return n.jsxs("div",{className:U("border-line-strong bg-background/40 overflow-hidden rounded-md border",t),children:[n.jsxs("div",{className:"bg-surface-2 border-line flex items-center gap-2 border-b px-2 py-1",children:[n.jsxs("span",{className:"pg-num text-diff-add text-[10.5px] font-semibold",children:["+",c.add]}),n.jsxs("span",{className:"pg-num text-diff-del text-[10.5px] font-semibold",children:["−",c.del]}),e.firstChangedLine!==void 0&&n.jsxs("span",{className:"text-muted-foreground pg-num text-[10.5px]",children:["首个改动在第 ",e.firstChangedLine," 行"]}),n.jsx("div",{className:"flex-1"}),a&&o&&n.jsx("div",{className:"flex overflow-hidden rounded border border-line",children:["text","patch"].map(f=>n.jsx("button",{type:"button",onClick:()=>r(f),className:U("px-1.5 py-0.5 text-[10px] transition-colors",l===f?"bg-brand/20 text-brand":"text-muted-foreground hover:bg-surface-3 hover:text-foreground"),children:f==="text"?"行号":"补丁"},f))})]}),l==="patch"?n.jsx(Qc,{patch:e.patch,className:"max-h-72"}):n.jsx(Lx,{text:e.text,className:"max-h-72"}),n.jsx("p",{className:"text-muted-foreground/70 border-line bg-surface-2/50 border-t px-2 py-1 text-[10px] leading-snug",children:"这是 edit 工具自报的改动,不代表工作树的真实状态 —— 要确认请用文件面板的 git diff。"})]})}function Ux(e){const t=e.text||e.patch;let s=0,r=0;for(const o of t.split(`
15
+ `))o.startsWith("+")&&!o.startsWith("+++")?s++:o.startsWith("-")&&!o.startsWith("---")&&r++;return{add:s,del:r}}const Wx={M:"modified",A:"added",D:"deleted",R:"renamed",C:"copied","?":"untracked",U:"other",T:"modified"},Gx={modified:{label:"M",title:"修改",className:"text-warn bg-warn/12"},added:{label:"A",title:"新增",className:"text-diff-add bg-diff-add/12"},deleted:{label:"D",title:"删除",className:"text-diff-del bg-diff-del/12"},renamed:{label:"R",title:"重命名",className:"text-ok bg-ok/12"},copied:{label:"C",title:"复制",className:"text-ok bg-ok/12"},untracked:{label:"U",title:"未跟踪",className:"text-diff-add bg-surface-3"},other:{label:"!",title:"冲突",className:"text-bad bg-bad/12"}};function Vx(e){const t=[],s=[];let r,o,a=0,l=0;for(const c of e.split(`
16
+ `)){if(!c.trim())continue;if(c.startsWith("## ")){const k=c.slice(3),v=/^(.+?)(?:\.\.\.(.+?))?(?:\s+\[(.+)\])?$/.exec(k);if(v){r=v[1],o=v[2];const x=v[3]??"";a=Number(/ahead (\d+)/.exec(x)?.[1]??0),l=Number(/behind (\d+)/.exec(x)?.[1]??0)}else r=k;continue}const f=/^([ MADRCU?!T]{2})\s+(.+)$/.exec(c);if(!f){s.push(c);continue}const u=f[1],d=f[2],m=u[1]!==" "?u[1]:u[0];t.push({path:d,state:Wx[m]??"other",xy:u.trim()||"??"})}return{...r?{branch:r}:{},...o?{upstream:o}:{},ahead:a,behind:l,entries:t,raw:s}}const Kx=({text:e,className:t,dense:s=!1})=>{const r=i.useMemo(()=>[Xa],[]);return n.jsx("div",{className:U("text-foreground/90 text-[12.5px] leading-relaxed","[&_h1]:text-[15px] [&_h1]:font-semibold [&_h2]:text-[13.5px] [&_h2]:font-semibold [&_h3]:text-[12.5px] [&_h3]:font-semibold","[&_h1]:mt-3 [&_h1]:mb-1.5 [&_h2]:mt-3 [&_h2]:mb-1.5 [&_h3]:mt-2.5 [&_h3]:mb-1","[&_h1]:first:mt-0 [&_h2]:first:mt-0 [&_h3]:first:mt-0","[&_p]:my-1.5 [&_p]:first:mt-0 [&_p]:last:mb-0","[&_ul]:my-1.5 [&_ul]:ms-4 [&_ul]:list-disc [&_ol]:my-1.5 [&_ol]:ms-4 [&_ol]:list-decimal","[&_li]:my-0.5 [&_li]:marker:text-muted-foreground","[&_a]:text-brand [&_a]:underline [&_a]:underline-offset-2 [&_a]:hover:opacity-80","[&_strong]:text-foreground [&_strong]:font-semibold","[&_blockquote]:border-line-strong [&_blockquote]:text-muted-foreground [&_blockquote]:my-2 [&_blockquote]:border-s-2 [&_blockquote]:ps-3","[&_hr]:border-line [&_hr]:my-3","[&_code]:bg-surface-3 [&_code]:rounded [&_code]:px-1 [&_code]:py-px [&_code]:font-mono [&_code]:text-[0.92em]","[&_pre]:bg-background/60 [&_pre]:border-line [&_pre]:my-2 [&_pre]:overflow-x-auto [&_pre]:rounded-lg [&_pre]:border [&_pre]:p-2.5","[&_pre_code]:bg-transparent [&_pre_code]:p-0 [&_pre_code]:text-[11.5px] [&_pre_code]:leading-relaxed","[&_table]:border-line [&_table]:my-2 [&_table]:w-full [&_table]:border-collapse [&_table]:text-[11.5px]","[&_th]:bg-surface-2 [&_th]:border-line [&_th]:border [&_th]:px-2 [&_th]:py-1 [&_th]:text-left [&_th]:font-semibold","[&_td]:border-line [&_td]:border [&_td]:px-2 [&_td]:py-1",s&&"text-[12px] [&_pre_code]:text-[11px]",t),children:n.jsx(Cu,{remarkPlugins:r,children:e})})},qx=i.memo(Kx),za=180;function Yx(e){if(!e||typeof e!="object")return{};const t=e;return t.live===!0?{live:t}:{done:t}}function eu(e){const t=e.toLowerCase();return/(^|[^a-z])(bash|shell|exec|command|run)([^a-z]|$)/.test(t)||t.includes("terminal")}function Xx(e){const t=e.toLowerCase();return eu(t)?zs:t.includes("ask")||t.includes("peer")?_u:t.includes("edit")||t.includes("patch")||t.includes("replace")?Lu:t.includes("write")||t.includes("create")?tl:t.includes("read")||t.includes("cat")||t.includes("view")?Ho:t.includes("grep")||t.includes("search")||t.includes("find")?Uo:t.includes("glob")||t.includes("list")||t.includes("ls")||t.includes("tree")?Bu:t.includes("task")||t.includes("agent")||t.includes("spawn")?Hu:Uu}const Jx=["command","cmd","path","filePath","file_path","filename","target","pattern","regex","query","url","peerEnv","toEnv","question","description","name"];function Zx(e){if(!e)return"";for(const s of Jx){const r=e[s];if(typeof r=="string"&&r.trim())return ro(r.trim(),90)}for(const s of Object.values(e))if(typeof s=="string"&&s.trim())return ro(s.trim(),90);const t=Object.keys(e);return t.length>0?ro(t.join(", "),60):""}function vo(e,t){if(!e)return["",0];const s=e.split(`
17
+ `);return s.length<=t?[e,0]:[s.slice(-t).join(`
18
+ `),s.length-t]}function Qx(e){const t=i.useRef(null),[s,r]=i.useState(null);return i.useEffect(()=>{if(!e){t.current=null,r(null);return}t.current===null&&(t.current=Date.now()),r(Date.now()-t.current);const o=setInterval(()=>{t.current!==null&&r(Date.now()-t.current)},500);return()=>clearInterval(o)},[e]),s}function eh(e){const t=i.useRef(null),s=i.useRef(!0);return i.useEffect(()=>{const r=t.current;if(!r)return;const o=()=>{s.current=r.scrollHeight-r.scrollTop-r.clientHeight<24};return r.addEventListener("scroll",o,{passive:!0}),()=>r.removeEventListener("scroll",o)},[]),i.useEffect(()=>{const r=t.current;r&&s.current&&(r.scrollTop=r.scrollHeight)},[e]),t}const Fa=400,th=({toolName:e,args:t,argsText:s,result:r,isError:o,isPreliminary:a,artifact:l})=>{const{live:c,done:f}=i.useMemo(()=>Yx(l),[l]),[u,d]=i.useState(!1),[m,k]=i.useState(!1),v=i.useRef(null),x=Ja(v,za),y=c!==void 0,p=Qx(y),g=f?.durationMs,j=Xx(e),C=i.useMemo(()=>Zx(t),[t]),h=i.useCallback(le=>{x(),d(le)},[x]),b=eu(e),N=i.useRef(!1);i.useEffect(()=>{N.current||(f?.diff||c?.diff||y&&b||o)&&(N.current=!0,d(!0))},[f?.diff,c?.diff,y,b,o]);const S=c?.output??"",[T,P]=i.useMemo(()=>m?[S,0]:vo(S,Fa),[S,m]),B=eh(T),L=typeof r=="string"?r:"",[K,A]=i.useMemo(()=>vo(L,Fa),[L]),[z,M]=i.useMemo(()=>!u&&!y&&b&&L.trim()?vo(L,6):["",0],[u,y,b,L]),[R,W]=i.useState(!1),I=c?.droppedBytes??0,_=c?.droppedLines??0,V=f?.diff??c?.diff,H=i.useMemo(()=>{if(!s)return!1;try{return JSON.parse(s),!1}catch{return Object.keys(t??{}).length===0}},[s,t]),Y=o?"before:bg-bad":y?"before:bg-brand":V?"before:bg-diff-add":"before:bg-line-strong";return n.jsxs(Yc,{ref:v,open:u,onOpenChange:h,style:{"--animation-duration":`${za}ms`},className:U("border-line bg-surface/60 group/tool relative my-1.5 w-full overflow-hidden rounded-md border","before:absolute before:inset-y-0 before:left-0 before:w-0.5 before:content-['']",Y,o&&"border-bad/30 bg-bad/[0.04]",y&&"border-brand/30"),children:[n.jsxs(Xc,{className:U("hover:bg-surface-2/70 flex w-full items-center gap-2 py-1.5 pr-2 pl-2.5 text-left","transition-colors duration-150"),children:[n.jsx("span",{className:"relative flex size-3.5 shrink-0 items-center justify-center",children:y?n.jsx(at,{className:"text-brand size-3.5 animate-spin [animation-duration:900ms]"}):o?n.jsx(Lo,{className:"text-bad size-3.5"}):n.jsx(sn,{className:"text-ok size-3.5"})}),n.jsx(j,{className:"text-muted-foreground size-3.5 shrink-0"}),n.jsx("span",{className:"text-foreground/90 shrink-0 font-mono text-[11.5px] font-medium",children:e}),C&&n.jsx("span",{className:"text-muted-foreground min-w-0 flex-1 truncate font-mono text-[11px]",title:C,children:C}),!C&&n.jsx("span",{className:"flex-1"}),(I>0||_>0)&&n.jsxs("span",{className:"text-warn flex shrink-0 items-center gap-0.5 text-[10px]",title:"服务端 spill 窗口只保留输出尾部,前面的内容已丢弃",children:[n.jsx(vt,{className:"size-3"}),"已截断"]}),V&&V.lineCount>0&&n.jsxs("span",{className:"text-diff-add pg-num shrink-0 text-[10px]",title:`差异 ${V.lineCount} 行`,children:[V.lineCount," 行"]}),n.jsx("span",{className:"text-muted-foreground pg-num shrink-0 text-[10.5px] tabular-nums",children:y?p!==null?`已运行 ${Ts(p)}`:"运行中":g!==void 0?Ts(g):a?"未完成":""}),n.jsx(ls,{className:U("text-muted-foreground size-3.5 shrink-0 transition-transform ease-[cubic-bezier(0.32,0.72,0,1)] motion-reduce:transition-none","group-data-open/tool:rotate-0 -rotate-90")})]}),z&&n.jsxs("button",{type:"button",onClick:()=>h(!0),className:"border-line/70 bg-background/55 hover:bg-background/85 block w-full border-t px-2.5 py-1.5 text-left transition-colors",title:"点击展开完整命令输出与参数",children:[M>0&&n.jsxs("span",{className:"text-muted-foreground/70 mb-0.5 block text-[10px]",children:["…已省略前 ",M.toLocaleString("zh-CN")," 行(点击展开全部)"]}),n.jsx("pre",{className:"text-foreground/80 overflow-x-auto font-mono text-[11px] leading-[1.5] whitespace-pre-wrap",children:z})]}),n.jsx(Jc,{className:U("overflow-hidden outline-none","ease-[cubic-bezier(0.32,0.72,0,1)] motion-reduce:animate-none","data-closed:animate-collapsible-up data-open:animate-collapsible-down","data-closed:fill-mode-forwards data-closed:pointer-events-none","[--tw-duration:var(--animation-duration)]"),children:n.jsxs("div",{className:"border-line flex flex-col gap-2 border-t p-2.5",children:[n.jsx(nh,{args:t,argsText:s,broken:H}),y&&n.jsxs("section",{className:"flex flex-col gap-1",children:[n.jsx(kr,{tone:"brand",text:`实时输出${c?.status?` · ${c.status}`:""}`,right:T?n.jsx(zo,{text:S,label:"复制当前输出"}):void 0}),T?n.jsxs(n.Fragment,{children:[n.jsx("pre",{ref:B,className:"bg-background/70 border-brand/20 pg-scroll-y text-foreground/85 max-h-56 overflow-x-auto rounded border p-2 font-mono text-[11px] leading-[1.6] whitespace-pre-wrap",children:T}),P>0&&n.jsx(_a,{hidden:P,onExpand:()=>k(!0),expanded:m})]}):n.jsx("p",{className:"text-muted-foreground bg-background/40 border-line rounded border border-dashed px-2 py-1.5 text-[11px]",children:"还没有输出。上游对运行不足 100ms 的命令不推中间态 —— 命令结束后完整输出会落到会话记录里。"})]}),(I>0||_>0)&&n.jsxs("p",{className:"text-warn bg-warn/8 border-warn/25 rounded border px-2 py-1.5 text-[11px] leading-snug",children:["服务端 spill 窗口只保留输出尾部,已丢弃",_>0?` ${_.toLocaleString("zh-CN")} 行`:"",_>0&&I>0?" / ":"",I>0?` ${(I/1024).toFixed(1)} KB`:"","。这里看到的不是全部输出。"]}),V&&n.jsx(Hx,{diff:V}),!y&&L&&n.jsxs("section",{className:"flex flex-col gap-1",children:[n.jsx(kr,{tone:o?"bad":"muted",text:o?"工具报错":"返回给模型的结果",right:n.jsx(zo,{text:L,label:"复制结果"})}),o?n.jsx("pre",{className:"bg-bad/[0.06] border-bad/25 text-bad pg-scroll-y max-h-56 overflow-x-auto rounded border p-2 font-mono text-[11px] leading-[1.6] whitespace-pre-wrap",children:L}):La(L)?n.jsx("div",{className:"bg-background/50 border-line max-h-72 overflow-y-auto rounded border p-2",children:n.jsx(qx,{text:L,dense:!0})}):n.jsx("pre",{className:"bg-background/70 border-line pg-scroll-y text-foreground/85 max-h-56 overflow-x-auto rounded border p-2 font-mono text-[11px] leading-[1.6] whitespace-pre-wrap",children:R?L:K}),!o&&!La(L)&&A>0&&n.jsx(_a,{hidden:A,expanded:R,onExpand:()=>W(!0)})]}),!y&&!L&&a&&n.jsx("p",{className:"text-muted-foreground bg-background/40 border-line rounded border border-dashed px-2 py-1.5 text-[11px]",children:"这个调用没有留下结果 —— 通常是任务被中断或会话被重置。"})]})})]})};function kr({text:e,tone:t="muted",right:s}){return n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:U("text-[10px] font-semibold tracking-[0.12em] uppercase",t==="brand"&&"text-brand",t==="bad"&&"text-bad",t==="muted"&&"text-muted-foreground"),children:e}),n.jsx("span",{className:"bg-line h-px flex-1"}),s]})}function nh({args:e,argsText:t,broken:s}){const[r,o]=i.useState(!1),a=i.useMemo(()=>Hd(e??{}),[e]),l=a.split(`
19
+ `).length,c=r||l<=6?a:a.split(`
20
+ `).slice(0,6).join(`
21
+ `);return s&&t?n.jsxs("section",{className:"flex flex-col gap-1",children:[n.jsx(kr,{text:"参数",tone:"bad"}),n.jsx("p",{className:"text-bad bg-bad/8 border-bad/25 rounded border px-2 py-1.5 font-mono text-[11px] leading-snug break-words",children:t})]}):!e||Object.keys(e).length===0?null:n.jsxs("section",{className:"flex flex-col gap-1",children:[n.jsx(kr,{text:"参数",right:n.jsx(zo,{text:a,label:"复制参数"})}),n.jsx("pre",{className:"bg-background/70 border-line pg-scroll-y text-foreground/80 max-h-56 overflow-x-auto rounded border p-2 font-mono text-[11px] leading-[1.6] whitespace-pre-wrap",children:c}),l>6&&n.jsx("button",{type:"button",onClick:()=>o(f=>!f),className:"text-brand hover:text-brand/80 w-fit text-[10.5px] transition-colors",children:r?"收起":`展开全部 ${l} 行`})]})}function zo({text:e,label:t}){const{isCopied:s,copyToClipboard:r}=yi();return n.jsx("button",{type:"button",onClick:()=>r(e),title:t,"aria-label":t,className:U("flex size-5 shrink-0 items-center justify-center rounded transition-colors",s?"text-ok":"text-muted-foreground hover:bg-surface-3 hover:text-foreground"),children:s?n.jsx(sn,{className:"size-3"}):n.jsx(jr,{className:"size-3"})})}function _a({hidden:e,expanded:t,onExpand:s}){return n.jsx("p",{className:"text-muted-foreground text-[10.5px]",children:t?n.jsx(n.Fragment,{children:"已显示全部内容"}):n.jsxs(n.Fragment,{children:["为保持流畅,这里只显示尾部内容,前面还有"," ",n.jsx("span",{className:"pg-num text-foreground/80",children:e.toLocaleString("zh-CN")})," 行。",n.jsx("button",{type:"button",onClick:s,className:"text-brand hover:text-brand/80 ml-1.5 transition-colors",children:"展开全部"})]})})}function La(e){if(e.length<80)return!1;const t=e.split(`
22
+ `);return t.length>30||e.length/t.length<40||/^[\s$#>]/.test(e)?!1:/[。..!?!?]$|[,,、]\s/.test(e)||/(^|\n)#{1,3}\s/.test(e)}const sh=({status:e})=>{const t=e?.type==="running";return n.jsxs(Ni,{streaming:t,variant:"ghost",className:"mb-2",children:[n.jsx(wi,{active:t,label:t?"正在思考":"思考过程",className:"text-muted-foreground/80 hover:text-muted-foreground text-[11.5px]"}),n.jsx(Ci,{"aria-busy":t,children:n.jsx(Si,{className:"text-muted-foreground max-h-56 text-[11.5px] italic",children:n.jsx(ki,{})})})]})},Ba={compaction:{label:"上下文已压缩",icon:Wu,note:"历史被摘要以腾出上下文窗口,早期细节可能已丢失"},reset:{label:"会话已重置",icon:ko,note:"上下文被清空,此前的对话对模型不再可见"},system:{label:"系统消息",icon:Es,note:""},other:{label:"上下文事件",icon:Es,note:""}},tu=({data:e})=>{const t=e?.kind??"other",s=Ba[t]??Ba.other,r=s.icon,o=en(l=>l.message.createdAt?.getTime()??0),a=e?.text??"";return n.jsxs("div",{className:"group/ctx my-2.5 flex items-center gap-2",role:"note",title:s.note||void 0,children:[n.jsx("span",{className:"bg-line h-px flex-1"}),n.jsxs("span",{className:"text-muted-foreground/70 group-hover/ctx:text-muted-foreground flex items-center gap-1.5 text-[10px] tracking-[0.08em] uppercase transition-colors",children:[n.jsx(r,{className:"size-3"}),s.label,n.jsx("span",{className:"pg-num normal-case opacity-60",children:Go(o)})]}),n.jsx("span",{className:"bg-line h-px flex-1"}),a&&n.jsx("span",{className:"sr-only",children:a})]})},ks=12,nu=({data:e})=>{const[t,s]=i.useState(!1),[r,o]=i.useState(!1),{isCopied:a,copyToClipboard:l}=yi();if(!e)return null;const c=!!e.running,f=e.output??"",u=f?f.split(`
23
+ `):[],d=!r&&u.length>ks?u.length-ks:0,m=d>0?u.slice(-ks).join(`
24
+ `):f,k=e.exitCode;return n.jsxs("div",{className:U("border-line bg-surface/65 relative my-2 overflow-hidden rounded-md border","before:absolute before:inset-y-0 before:left-0 before:w-0.5 before:content-['']",c?"border-brand/35 before:bg-brand":e.ok?"before:bg-ok/70":"border-bad/35 bg-bad/[0.04] before:bg-bad"),children:[n.jsxs("div",{role:"button",tabIndex:0,onClick:()=>s(v=>!v),onKeyDown:v=>{(v.key==="Enter"||v.key===" ")&&(v.preventDefault(),s(x=>!x))},className:"hover:bg-surface-2/60 flex cursor-pointer items-center gap-2 py-1.5 pr-2 pl-2.5 text-left transition-colors select-none",children:[n.jsx("span",{className:"flex size-3.5 shrink-0 items-center justify-center",children:c?n.jsx(at,{className:"text-brand size-3.5 animate-spin [animation-duration:900ms]"}):e.ok?n.jsx(sn,{className:"text-ok size-3.5"}):n.jsx(Lo,{className:"text-bad size-3.5"})}),n.jsx(zs,{className:"text-muted-foreground size-3.5 shrink-0"}),n.jsxs("span",{className:"text-foreground min-w-0 flex-1 truncate font-mono text-[11.5px] font-medium",title:e.cwd?`${e.cwd}$ ${e.command}`:`$ ${e.command}`,children:["$ ",e.command]}),n.jsx("span",{className:U("shrink-0 rounded px-1.5 py-px text-[9.5px] font-medium",e.includeInContext?"bg-brand/12 text-brand":"bg-surface-2 text-muted-foreground"),title:e.includeInContext?"命令输出已写入模型上下文 (!)":"仅本地展示,未进入模型上下文 (!!)",children:e.includeInContext?"! 上下文":"!! 仅输出"}),e.queued&&n.jsx("span",{className:"text-warn shrink-0 text-[10px]",children:"待入上下文"}),!c&&k!==void 0&&k!==null&&k!==0&&n.jsxs("span",{className:"text-bad pg-num shrink-0 font-mono text-[10px]",children:["exit ",k]}),e.durationMs!==void 0&&n.jsx("span",{className:"text-muted-foreground/75 pg-num shrink-0 text-[10px] tabular-nums",children:Ts(e.durationMs)}),f&&n.jsx("button",{type:"button",onClick:v=>{v.stopPropagation(),l(f)},title:"复制命令输出","aria-label":"复制命令输出",className:U("flex size-5 shrink-0 items-center justify-center rounded transition-colors",a?"text-ok":"text-muted-foreground hover:bg-surface-3 hover:text-foreground"),children:a?n.jsx(sn,{className:"size-3"}):n.jsx(jr,{className:"size-3"})}),n.jsx(ls,{className:U("text-muted-foreground size-3.5 shrink-0 transition-transform",t&&"-rotate-90")})]}),!t&&n.jsx("div",{className:"border-line space-y-1.5 border-t px-2.5 py-2",children:c?n.jsx("p",{className:"text-muted-foreground font-mono text-[11px]",children:"正在远端执行…"}):n.jsxs(n.Fragment,{children:[f?n.jsx("pre",{className:"bg-background/70 border-line pg-scroll-y text-foreground/85 max-h-72 overflow-x-auto rounded border p-2 font-mono text-[11px] leading-[1.55] whitespace-pre-wrap",children:m}):e.error?null:n.jsx("p",{className:"text-muted-foreground/70 font-mono text-[11px]",children:"(无输出)"}),d>0&&n.jsxs("button",{type:"button",onClick:()=>o(!0),className:"text-brand hover:text-brand/80 text-[10.5px] transition-colors",children:["展开全部 ",u.length.toLocaleString("zh-CN")," 行(已省略前 ",d.toLocaleString("zh-CN")," 行)"]}),r&&u.length>ks&&n.jsxs("button",{type:"button",onClick:()=>o(!1),className:"text-muted-foreground hover:text-foreground text-[10.5px] transition-colors",children:["收起至尾部 ",ks," 行"]}),e.error&&n.jsx("p",{className:"text-bad bg-bad/8 border-bad/25 rounded border px-2 py-1 font-mono text-[11px] break-words",children:e.error}),e.truncated&&n.jsxs("p",{className:"text-muted-foreground text-[10px]",children:["输出较长,仅保留尾部",e.spillPath?`(完整日志:${e.spillPath})`:""]})]})})]})},rh=({text:e,status:t})=>n.jsxs("p",{className:"text-foreground/95 text-[13.5px] leading-[1.6] whitespace-pre-wrap break-words",children:[e,t?.type==="running"&&n.jsx("span",{className:"text-muted-foreground/60 ml-1 animate-pulse",children:"·"})]}),oh={Text:rh},ih={data:{by_name:{"pi-context":tu,"pi-exec":nu}}},ah={Text:ki,Reasoning:sh,tools:{Fallback:th},data:{by_name:{"pi-context":tu,"pi-exec":nu}}},lh=i.memo(function(){const t=en(r=>r.message.createdAt?.getTime()??0),s=en(r=>r.message.id);return n.jsx("div",{className:"my-3 flex justify-end",children:n.jsx(Sn.Root,{id:s,title:t?Go(t):void 0,className:U("group/user border-line bg-background relative my-0 max-w-[78%] scroll-mt-2 rounded-xl rounded-br-md border px-3.5 py-2","shadow-[0_4px_6px_rgba(0,0,0,0.02)] dark:shadow-none","animate-rise motion-reduce:animate-none"),children:n.jsx(Sn.Parts,{components:oh})})})}),ch=i.memo(function(){const t=en(c=>c.message.createdAt?.getTime()??0),s=en(c=>{const f=c.message.metadata.custom?.model;return typeof f=="string"?f:void 0}),r=en(c=>c.message.status?.type??"complete"),o=r==="running",a=r==="incomplete",l=en(c=>c.message.status?.type==="incomplete"?c.message.status.error:null);return n.jsxs(Sn.Root,{className:U("group/msg relative my-2.5","animate-rise motion-reduce:animate-none"),children:[o&&n.jsxs("div",{className:"text-brand/85 mb-1 flex items-center gap-1.5 text-[11px]",children:[n.jsx("span",{className:"bg-brand size-1.5 animate-pulse rounded-full"}),n.jsx("span",{children:"生成中…"})]}),n.jsx("div",{children:n.jsx(Sn.Parts,{components:ah})}),l!=null&&Ha(l)&&n.jsx(dh,{}),l!=null&&!Ha(l)&&n.jsx(fh,{error:l}),a&&l==null&&n.jsx("p",{className:"text-muted-foreground/70 mt-1 text-[11px] italic",children:"这一轮没有正常结束(可能被中止,或触发了长度/内容过滤)"}),!o&&n.jsxs("div",{className:"text-muted-foreground/60 mt-1 flex items-center gap-2 text-[10.5px] opacity-0 transition-opacity duration-150 group-hover/msg:opacity-100 focus-within:opacity-100",children:[n.jsx(uh,{}),s&&n.jsx("span",{className:"pg-num truncate",title:s,children:s}),t>0&&n.jsx("span",{className:"pg-num",children:Go(t)})]})]})});function uh(){return n.jsx(Ai.Root,{hideWhenRunning:!0,className:"flex items-center gap-0.5",children:n.jsxs(Ai.Copy,{className:U("flex size-5 items-center justify-center rounded transition-colors","text-muted-foreground hover:bg-surface-3 hover:text-foreground"),title:"复制消息",children:[n.jsx(Sn.If,{copied:!0,children:n.jsx(sn,{className:"text-ok size-3"})}),n.jsx(Sn.If,{copied:!1,children:n.jsx(jr,{className:"size-3"})})]})})}function Ha(e){const t=typeof e=="string"?e:e&&typeof e=="object"&&"message"in e?String(e.message):"";return/^(aborted|cancel|中断|中止)/i.test(t.trim())}function dh(){return n.jsx("p",{className:"text-muted-foreground/80 mt-1.5 text-[12px]",children:"已停止生成。"})}function fh({error:e}){const t=i.useMemo(()=>{if(typeof e=="string")return e;if(e&&typeof e=="object"){const s=e;if(typeof s.message=="string")return s.message;if(typeof s.error=="string")return s.error;try{return JSON.stringify(e)}catch{return String(e)}}return String(e??"未知错误")},[e]);return n.jsx("p",{role:"alert",className:"text-bad bg-bad/8 border-bad/25 mt-1.5 rounded border px-2 py-1.5 text-[11.5px] leading-snug break-words",children:t})}const ph=i.memo(function(){return n.jsx(Sn.Root,{className:"my-0",children:n.jsx(Sn.Parts,{components:ih})})});function mh(e,t,s,r){if(t)return t;if(s?.modelId)return s;if(e)for(let o=e.length-1;o>=0;o--){const a=e[o];if(a.kind==="assistant"&&a.model)return{provider:a.provider,modelId:a.model}}return{provider:r?.provider??void 0,modelId:r?.modelId??void 0}}function gh({conversationId:e,entries:t,agentModel:s,ghost:r=!1}){const{models:o,modelsError:a,modelsLoadedAt:l,reloadModels:c,notify:f,modelOverrides:u,setModelOverride:d,openPicker:m}=Ye(),[k,v]=i.useState(!1),[x,y]=i.useState(null),p=o?.models??[],g=i.useMemo(()=>mh(t,u[e],s,o?.defaultModel),[t,u,e,s,o?.defaultModel]),j=p.find(b=>b.id===g.modelId&&(!g.provider||b.provider===g.provider)),C=i.useMemo(()=>{const b=new Map;for(const N of p){const S=b.get(N.provider)??[];S.push(N),b.set(N.provider,S)}return[...b.entries()]},[p]),h=async b=>{if(b.id===g.modelId&&b.provider===g.provider){v(!1);return}y(`${b.provider}/${b.id}`);try{(await ie.configure(e,{provider:b.provider,modelId:b.id,setAsDefault:!0})).ok&&(d(e,b.provider,b.id),f({tone:"ok",title:`已切换到 ${b.provider}/${b.id}`,detail:"下一次生成生效"}),v(!1))}catch(N){f({tone:"bad",title:"切换模型失败",detail:N instanceof Error?N.message:String(N)})}finally{y(null)}};return n.jsxs(Ac,{open:k,onOpenChange:v,children:[n.jsxs(Mc,{className:U("group/model flex h-6 min-w-0 max-w-60 shrink-0 items-center gap-1.5 rounded-md px-2 text-[11px] transition-colors",r?"text-muted-foreground hover:bg-surface-3":"border-line bg-surface-2/60 hover:border-brand/40 hover:bg-surface-2 border"),title:j?`${j.provider}/${j.id}
25
+ 上下文 ${ar(j.contextWindow)} · 最大输出 ${ar(j.maxTokens)}`:g.modelId?`${g.provider??""}/${g.modelId}`:"未登录模型(点击 /login)","aria-label":"切换模型",children:[n.jsx(_o,{className:"text-muted-foreground size-3 shrink-0"}),n.jsx("span",{className:"text-foreground/85 min-w-0 truncate",children:g.modelId?`${g.provider?`${g.provider}/`:""}${g.modelId}`:a?"模型目录不可用":"未登录模型"}),n.jsx(ls,{className:U("text-muted-foreground/60 size-3 shrink-0 transition-transform duration-200",k&&"rotate-180")})]}),n.jsxs($c,{align:"start",side:r?"top":"bottom",className:"w-[24rem] p-0",children:[n.jsxs("div",{className:"border-line flex items-center gap-2 border-b px-2.5 py-1.5",children:[n.jsx("span",{className:"text-muted-foreground text-[10px] font-semibold tracking-[0.14em] uppercase",children:"模型(跨 Provider)"}),n.jsx("span",{className:"flex-1"}),n.jsxs("button",{type:"button",onClick:()=>{v(!1),m("login")},className:"text-brand hover:bg-brand/10 flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px]",children:[n.jsx(nl,{className:"size-2.5"}),"管理登录"]}),n.jsx("button",{type:"button",onClick:c,title:"重新拉取模型目录","aria-label":"重新拉取模型目录",className:"text-muted-foreground hover:bg-surface-3 hover:text-foreground flex size-5 items-center justify-center rounded transition-colors",children:n.jsx(cs,{className:"size-3"})})]}),a&&n.jsxs("p",{className:"text-bad bg-bad/8 flex items-start gap-1.5 px-2.5 py-2 text-[11px] leading-snug",children:[n.jsx(vt,{className:"mt-px size-3 shrink-0"}),n.jsx("span",{className:"min-w-0 flex-1",children:a})]}),!a&&p.length===0&&n.jsxs("div",{className:"flex flex-col items-center gap-2 px-3 py-4 text-center",children:[n.jsx("p",{className:"text-muted-foreground text-[11px]",children:l?"还没有已登录的 Provider 模型":"正在加载模型目录…"}),n.jsx("button",{type:"button",onClick:()=>{v(!1),m("login")},className:"bg-brand text-primary-foreground rounded px-2.5 py-1 text-[11px] font-medium",children:"立即登录 Provider (/login)"})]}),C.length>0&&n.jsx("div",{className:"pg-scroll-y max-h-80 overflow-y-auto p-1",children:C.map(([b,N])=>n.jsxs("div",{className:"mb-1.5 last:mb-0",children:[n.jsxs("div",{className:"text-muted-foreground/70 px-2 py-0.5 text-[9.5px] font-semibold tracking-wider uppercase",children:[b," · ",N.length]}),n.jsx("ul",{children:N.map(S=>{const T=S.id===g.modelId&&S.provider===g.provider,P=x===`${S.provider}/${S.id}`;return n.jsx("li",{children:n.jsxs("button",{type:"button",onClick:()=>h(S),disabled:x!==null,className:U("flex w-full items-start gap-2 rounded-md px-2 py-1.5 text-left transition-colors",T?"bg-brand/12":"hover:bg-surface-2"),children:[n.jsx("span",{className:"mt-0.5 flex size-3 shrink-0 items-center justify-center",children:P?n.jsx(at,{className:"text-brand size-3 animate-spin"}):T?n.jsx(sn,{className:"text-brand size-3"}):null}),n.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[n.jsxs("span",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:U("truncate text-[11.5px] font-medium",T?"text-brand":"text-foreground/90"),children:S.name}),S.reasoning&&n.jsx(Bo,{className:"text-muted-foreground/70 size-2.5"}),S.vision&&n.jsx(sl,{className:"text-muted-foreground/70 size-2.5"})]}),n.jsxs("span",{className:"text-muted-foreground/70 pg-num flex items-center gap-1.5 font-mono text-[10px]",children:[n.jsx("span",{className:"truncate",children:S.id}),n.jsx("span",{className:"opacity-40",children:"·"}),n.jsx("span",{children:ar(S.contextWindow)})]})]})]})},`${S.provider}:${S.id}`)})})]},b))}),n.jsxs("p",{className:"text-muted-foreground/75 border-line bg-surface-2/60 border-t px-2.5 py-1.5 text-[10px] leading-snug",children:["也可以在输入框直接敲 ",n.jsx("code",{className:"pg-num",children:"/model"})," 或 ",n.jsx("code",{className:"pg-num",children:"/login"})," 全键盘切换。"]})]})]})}function xh(e){for(let t=(e?.length??0)-1;t>=0;t--){const s=e[t];if(s.kind==="assistant"&&s.usage)return s}}function hh({conversationId:e}){const{models:t}=Ye(),s=us(e).data,r=i.useMemo(()=>{const l=xh(s?.entries),c=l?.usage;if(!l||!c)return null;const f=(c.input??0)+(c.cacheRead??0)+(c.cacheWrite??0),d=t?.models.find(x=>x.id===l.model&&(!l.provider||x.provider===l.provider))?.contextWindow,m=d&&d>0?f/d:void 0,k=s?.usage?.totals?.totalTokens,v=f>0?(c.cacheRead??0)/f:0;return{prompt:f,ctxWindow:d,pct:m,total:k,cacheHit:v}},[s,t]);if(!r)return null;const o=r.pct===void 0?"text-muted-foreground":r.pct>=.85?"text-bad":r.pct>=.5?"text-warn":"text-muted-foreground",a=[`上下文 ${ts(r.prompt)}${r.ctxWindow?` / ${ts(r.ctxWindow)}`:""}(模型未报告窗口大小)`,r.total!==void 0?`本会话累计 ${ts(r.total)} tokens`:null,`缓存命中 ${Math.round(r.cacheHit*100)}%`,r.pct!==void 0&&r.pct>=.75?"接近上限,考虑 /compact":null].filter(Boolean).join(`
26
+ `);return n.jsxs("span",{className:U("flex h-6 shrink-0 items-center gap-1.5 px-2 text-[11px] tabular-nums",r.pct===void 0?"text-muted-foreground":"text-foreground/80"),title:a,children:[n.jsx(Gu,{className:U("size-3 shrink-0",o)}),n.jsx("span",{children:r.pct!==void 0?`上下文 ${Math.round(r.pct*100)}%`:`上下文 ${ts(r.prompt)}`})]})}function bh({conversationId:e,envName:t,offline:s}){const{notify:r,conversations:o}=Ye(),a=us(e).data,l=qa(),c=i.useRef(null),f=Lm(e,t,{refocus:()=>c.current?.focus()}),u=i.useMemo(()=>Mo(o,e),[o,e]),d=i.useMemo(()=>new Map(u.map(T=>[String(T.conversationId),T])),[u]),m=i.useMemo(()=>u.map(T=>({id:String(T.conversationId),type:"session",label:`@${T.title}`,description:`${T.env} · #${T.conversationId}`})),[u]),k=i.useMemo(()=>({serialize(T){const P=d.get(T.id);return P?`@${u.some(L=>L.title===P.title&&L.conversationId!==P.conversationId)?`${P.env}/${P.title}`:P.title}`:`@${T.label}`},parse(T){return[{kind:"text",text:T}]}}),[d,u]),v=Su({items:m,includeModelContextTools:!1,formatter:k}),[x,y]=i.useState(!1),[p,g]=i.useState(null),j=en(T=>T.thread.isRunning),C=en(T=>T.composer.isEmpty),h=f.runText,b=i.useCallback(()=>{const T=l.composer.getState().text;if(!T.trim())return;if(Nc(T)){l.composer.setText("",{origin:"external"}),h(T);return}const P=Cc(T,Mo(o,e),t);if(!P.ok){r({tone:"warn",title:"无法解析 @会话",detail:P.error});return}if(P.targets.length>0){l.composer.setText("",{origin:"external"}),ie.sendMessage(e,P.text).catch(B=>{r({tone:"bad",title:"发送失败",detail:B instanceof Error?B.message:String(B)})});return}l.composer.send()},[l,h,o,e,t,r]),N=i.useRef(b);i.useEffect(()=>{N.current=b},[b]),i.useEffect(()=>{const T=P=>{P.key!=="Enter"||P.shiftKey||P.target===c.current&&(P.defaultPrevented||P.isComposing||(P.preventDefault(),N.current()))};return window.addEventListener("keydown",T),()=>window.removeEventListener("keydown",T)},[]);const S=i.useCallback(async()=>{y(!0),g(null);try{await ie.abort(e)}catch(T){g(T instanceof Error?T.message:String(T))}finally{y(!1)}},[e]);return n.jsxs("div",{className:"flex flex-col gap-1.5",children:[p&&n.jsxs("p",{role:"alert",className:"text-bad bg-bad/8 border-bad/25 rounded border px-2 py-1 text-[11px]",children:["中止失败:",p]}),n.jsx(fn.TriggerPopoverRoot,{children:n.jsxs("div",{className:"relative",children:[n.jsxs(fn.TriggerPopover,{char:"/",adapter:f.adapter,"aria-label":"斜杠命令",className:U("border-line-strong bg-popover absolute bottom-full left-0 z-30 mb-1.5","w-[min(100%,28rem)] overflow-hidden rounded-lg border","shadow-[0_18px_48px_-18px_rgba(0,0,0,0.85)]","data-open:animate-in data-open:fade-in-0 data-open:slide-in-from-bottom-1","duration-150 motion-reduce:animate-none"),children:[n.jsx(fn.TriggerPopover.Action,{onExecute:f.action.onExecute,removeOnExecute:!0}),n.jsx(Ua,{emptyText:"没有匹配的命令 · 输入 /help 看全部",footer:"!命令 进上下文 · !!命令 仅输出"})]}),n.jsxs(fn.TriggerPopover,{char:"@",adapter:v.adapter,"aria-label":"提及会话",className:U("border-line-strong bg-popover absolute bottom-full left-0 z-30 mb-1.5","w-[min(100%,28rem)] overflow-hidden rounded-lg border","shadow-[0_18px_48px_-18px_rgba(0,0,0,0.85)]","data-open:animate-in data-open:fade-in-0 data-open:slide-in-from-bottom-1","duration-150 motion-reduce:animate-none"),children:[n.jsx(fn.TriggerPopover.Directive,{formatter:v.directive.formatter}),n.jsx(Ua,{emptyText:"没有可 @ 的会话 · 先在目标会话里 /name",footer:"只能 @ 已 /name 命名、且不在当前环境的会话"})]}),n.jsxs(fn.Root,{className:U("border-line bg-background focus-within:border-line-strong relative rounded-xl border","shadow-[0_4px_6px_rgba(0,0,0,0.02)] dark:shadow-[0_1px_0_0_var(--pg-line)_inset]","transition-[color,box-shadow] duration-150",s&&"opacity-70"),children:[n.jsx(fn.Input,{ref:c,rows:1,maxRows:8,autoFocus:!0,submitMode:"none",disabled:s,placeholder:s?"环境离线,暂时无法发送":"发消息,/ 打开命令,@名字 问别的会话,!命令 直跑(!! 仅输出不进上下文)…(Enter 发送)",className:U("text-foreground placeholder:text-muted-foreground/55 w-full resize-none bg-transparent","[scrollbar-width:none] [&::-webkit-scrollbar]:hidden","px-3 pt-2.5 pb-1 text-[12.5px] leading-relaxed outline-none","disabled:cursor-not-allowed")}),n.jsxs("div",{className:"flex items-center gap-1.5 px-2 pb-2",children:[n.jsx(gh,{conversationId:e,entries:a?.entries,agentModel:a?.agent?.model,ghost:!0}),n.jsx("span",{className:"bg-line mx-0.5 h-3 w-px shrink-0","aria-hidden":!0}),n.jsx(hh,{conversationId:e}),n.jsx("span",{className:"flex-1"}),j?n.jsxs(ke,{type:"button",variant:"destructive",size:"xs",onClick:S,disabled:x,className:"gap-1.5",children:[x?n.jsx(at,{className:"size-3 animate-spin"}):n.jsx(Vu,{className:"size-2.5 fill-current"}),x?"中止中":"中止"]}):n.jsx(ke,{type:"button",size:"xs",onClick:b,disabled:s||C,className:"bg-brand text-primary-foreground hover:bg-brand/85 gap-1.5",children:"发送"})]})]})]})})]})}function Ua({emptyText:e,footer:t}){return n.jsx(fn.TriggerPopoverItems,{children:s=>n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"pg-scroll-y max-h-64 overflow-y-auto p-1",children:s.length===0?n.jsx("p",{className:"text-muted-foreground px-2 py-3 text-center text-[11px]",children:e}):s.map((r,o)=>n.jsxs(fn.TriggerPopoverItem,{item:r,index:o,className:U("flex w-full cursor-pointer items-baseline gap-2 rounded-md px-2 py-1.5","text-left outline-none transition-colors","data-[highlighted]:bg-surface-3"),children:[n.jsx("span",{className:"text-brand pg-num shrink-0 font-mono text-[11.5px] font-medium",children:r.label}),r.description&&n.jsx("span",{className:"text-muted-foreground min-w-0 flex-1 truncate text-[10.5px]",children:r.description})]},r.id))}),n.jsxs("div",{className:"border-line bg-surface-2/60 text-muted-foreground/75 flex items-center gap-2 border-t px-2 py-1 text-[10px]",children:[n.jsx("span",{children:"↑↓ 选择"}),n.jsx("span",{className:"opacity-40",children:"·"}),n.jsx("span",{children:"Enter 执行"}),n.jsx("span",{className:"opacity-40",children:"·"}),n.jsx("span",{children:"Esc 关闭"}),n.jsx("span",{className:"flex-1"}),n.jsx("span",{children:t})]})]})})}function vh(){return n.jsx(_n.ScrollToBottom,{className:U("border-line-strong bg-surface-2 text-muted-foreground hover:text-foreground","absolute -top-11 left-1/2 z-10 flex size-7 -translate-x-1/2 items-center justify-center","rounded-full border shadow-lg transition-all duration-150","hover:border-brand/50","disabled:pointer-events-none disabled:opacity-0"),title:"回到底部",children:n.jsx("svg",{viewBox:"0 0 16 16",className:"size-3.5",fill:"none",stroke:"currentColor",strokeWidth:"1.6",children:n.jsx("path",{d:"M8 3v9M4 8.5l4 4 4-4",strokeLinecap:"round",strokeLinejoin:"round"})})})}const Wa=e=>`e${e}`;function yh(e){const t=e??[],s=[];for(let r=0;r<t.length;r++){const o=t[r];if(o.kind!=="user")continue;let a="";for(let l=r+1;l<t.length;l++){const c=t[l];if(c.kind==="user")break;if(c.kind==="assistant"&&c.text?.trim()){a=c.text.trim();break}}s.push({id:o.id,index:s.length,question:o.text?.trim()||"(空消息)",preview:a,at:o.at})}return s}function kh({conversationId:e,rootRef:t}){const s=us(e).data,r=i.useMemo(()=>yh(s?.entries),[s?.entries]),o=i.useRef(null),[a,l]=i.useState(0),[c,f]=i.useState(0),[u,d]=i.useState(null),m=i.useRef(0);i.useEffect(()=>{const p=o.current;if(!p)return;const g=new ResizeObserver(([j])=>l(j.contentRect.height));return g.observe(p),()=>g.disconnect()},[]);const k=i.useCallback(()=>{const p=t.current?.querySelector(".pg-scroll-y");if(!p)return;const g=p.getBoundingClientRect().top,j=p.scrollTop+p.clientHeight>=p.scrollHeight-4;let C=0;for(let h=0;h<r.length;h++){const b=document.getElementById(Wa(r[h].id));b&&b.getBoundingClientRect().top-g<=72&&(C=h)}f(j&&r.length>0?r.length-1:C)},[r,t]);i.useEffect(()=>{const p=t.current?.querySelector(".pg-scroll-y");if(!p)return;const g=()=>{cancelAnimationFrame(m.current),m.current=requestAnimationFrame(k)};return p.addEventListener("scroll",g,{passive:!0}),k(),()=>{cancelAnimationFrame(m.current),p.removeEventListener("scroll",g)}},[k,t]);const v=i.useCallback(p=>{document.getElementById(Wa(p))?.scrollIntoView({block:"start",behavior:"smooth"})},[]);if(r.length<2)return null;const x=Math.max(12,Math.min(28,(a-16)/r.length)),y=r.length-1;return n.jsx("div",{ref:o,className:"flex w-6 shrink-0 flex-col justify-center py-2","aria-label":"问答导航",children:n.jsx("div",{className:"flex flex-col items-center",style:{gap:`${Math.max(0,x-16)}px`},children:r.map((p,g)=>{const j=g===c,C=u===g,h=g/y>.7;return n.jsxs("div",{className:"relative flex h-4 w-4 items-center justify-center",children:[n.jsx("button",{type:"button",onClick:()=>v(p.id),onMouseEnter:()=>d(g),onMouseLeave:()=>d(null),onFocus:()=>d(g),onBlur:()=>d(null),"aria-label":`第 ${g+1} 轮:${p.question.slice(0,40)}`,className:"flex items-center justify-center",children:n.jsx("span",{className:U("rounded-full transition-all duration-150",j?"size-2 bg-foreground/65":C?"size-2 bg-foreground/45":"size-1.5 bg-muted-foreground/40")})}),C&&n.jsxs("div",{className:U("border-line-strong bg-popover absolute left-full z-20 w-72 rounded-lg border p-2.5","shadow-[0_6px_20px_-8px_rgba(0,0,0,0.25)]",h?"bottom-0 ml-2":"top-0 ml-2"),role:"tooltip",children:[n.jsx("p",{className:"text-foreground truncate text-[11.5px] font-semibold",children:p.question}),n.jsx("p",{className:"text-muted-foreground mt-1 line-clamp-3 text-[11px] leading-snug",children:p.preview||"(还没有文本回复)"}),n.jsxs("div",{className:"text-muted-foreground/80 pg-num mt-1.5 flex items-center justify-between gap-2 text-[10px]",children:[n.jsxs("span",{children:[g+1," of ",r.length]}),n.jsx("span",{children:Vo(p.at)})]})]})]},p.id)})})})}const jh={UserMessage:lh,AssistantMessage:ch,SystemMessage:ph};function yo({conversationId:e,isSplit:t=!1}){const{envByName:s,conversations:r,splitConvId:o,setSplitConvId:a,closeConversation:l,notify:c,applyAutoTitle:f,pendingExecs:u,prunePendingExecs:d}=Ye(),m=r.find(I=>I.conversationId===e),k=us(e),v=k.data,x=i.useRef(null),y=m?.env??"",p=s(y),g=p?.status?!p.status.ok:!1,j=t||o!==null,[C,h]=i.useState([]),[b,N]=i.useState(!1),[S,T]=i.useState(!0);i.useEffect(()=>{h([]),N(!1),T(!0)},[e]);const P=i.useMemo(()=>{const I=v?.entries??[];if(C.length===0)return I;const _=new Set(I.map(V=>V.id));return[...C.filter(V=>!_.has(V.id)),...I]},[C,v?.entries]),B=i.useCallback(async()=>{if(b||!S)return;const I=P[0]?.id??v?.before;if(I!==void 0){N(!0);try{const _=await ie.loadEntries(e,{before:I-1,limit:50});_.entries.length>0&&h(V=>{const H=new Set(V.map(Y=>Y.id));return[..._.entries.filter(Y=>!H.has(Y.id)),...V]}),T(_.hasMore&&_.entries.length>0)}catch(_){c({tone:"bad",title:"加载历史消息失败",detail:_ instanceof Error?_.message:String(_)})}finally{N(!1)}}},[b,S,P,v?.before,e,c]),L=i.useMemo(()=>u.filter(I=>I.conversationId===e),[u,e]);i.useEffect(()=>{if(L.length===0)return;const I=new Set,_=new Set;for(const V of P)if(_.add(V.id),V.kind==="exec"&&V.data&&typeof V.data=="object"){const H=V.data.execId;typeof H=="string"&&H&&I.add(H)}d(e,I,_)},[L.length,P,d,e]);const K=i.useMemo(()=>_g(P,v?.run,L),[P,v?.run,L]),[A,z]=i.useState(null),M=i.useCallback(async I=>{z(null);try{const _=await ie.sendMessage(e,Lg(I.content));_.title&&f(e,_.title)}catch(_){const V=_ instanceof Error?_.message:String(_);throw z(V),_}},[e,f]),R=i.useCallback(async()=>{await ie.abort(e)},[e]),W=Nu({messages:K,convertMessage:I=>I,isRunning:v?.run.running??!1,onNew:M,onCancel:R});return n.jsx(Eu,{runtime:W,children:n.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col",children:[j&&n.jsxs("div",{className:"border-line bg-surface/60 flex h-7 shrink-0 items-center gap-2 border-b px-2",children:[n.jsx("span",{className:"text-muted-foreground shrink-0 text-[10px]",children:p?.label??y}),n.jsx("span",{className:"text-foreground/85 min-w-0 flex-1 truncate text-[11px]",children:m?.title||`会话 #${e}`}),n.jsx("button",{type:"button",onClick:()=>t?a(null):l(e),title:t?"关闭分屏":"关闭会话","aria-label":t?"关闭分屏":"关闭会话",className:"text-muted-foreground hover:bg-surface-3 hover:text-foreground flex size-5 items-center justify-center rounded",children:n.jsx(Ds,{className:"size-3"})})]}),k.status==="error"&&!v&&n.jsxs("div",{className:"bg-bad/8 border-bad/25 text-bad flex items-start gap-2 border-b px-3 py-2 text-[11px] leading-snug",children:[n.jsx(vt,{className:"mt-px size-3 shrink-0"}),n.jsxs("span",{className:"min-w-0 flex-1",children:["连不上会话 ",e," 的数据流。",n.jsxs("span",{className:"text-foreground/70",children:[" ","通常是后端没在跑,或者这个会话已经不存在了。"]})]}),n.jsx("button",{type:"button",onClick:()=>l(e),className:"border-bad/35 hover:bg-bad/15 shrink-0 rounded border px-1.5 py-0.5 text-[10.5px] transition-colors",children:"关掉"})]}),k.serverError&&n.jsxs("p",{role:"alert",className:"text-bad bg-bad/8 border-bad/25 flex items-center gap-2 border-b px-3 py-1.5 text-[11px]",children:[n.jsx(vt,{className:"size-3 shrink-0"}),"会话流报错:",k.serverError]}),A&&n.jsxs("p",{role:"alert",className:"text-bad bg-bad/8 border-bad/25 flex items-center gap-2 border-b px-3 py-1.5 text-[11px]",children:[n.jsx(vt,{className:"size-3 shrink-0"}),"发送失败:",A]}),n.jsx(Ch,{run:v?.run}),k.status!=="open"&&n.jsx(Gd,{status:k.status,lastEventAt:k.lastEventAt,className:"bg-surface/85 border-line absolute top-2 right-3 z-10 rounded border px-1.5 py-0.5 backdrop-blur"}),n.jsxs("div",{ref:x,className:"flex min-h-0 min-w-0 flex-1",children:[n.jsx(kh,{conversationId:e,rootRef:x}),n.jsx(_n.Root,{className:"relative flex min-h-0 min-w-0 flex-1 flex-col",children:n.jsxs(_n.Viewport,{className:"pg-scroll-y flex min-h-0 min-w-0 flex-1 flex-col overflow-x-hidden",autoScroll:!0,children:[n.jsxs("div",{className:"mx-auto w-full max-w-3xl flex-1 px-4 pt-2 pb-3",children:[v?.before!==void 0&&S&&n.jsx("div",{className:"mb-3 flex justify-center",children:n.jsxs("button",{type:"button",onClick:()=>void B(),disabled:b,className:"border-line bg-surface-2 text-muted-foreground hover:text-foreground inline-flex items-center gap-1 rounded-full border px-3 py-1 text-[11px] transition-colors disabled:opacity-50",children:[b?n.jsx(at,{className:"size-3 animate-spin"}):n.jsx(Ku,{className:"size-3"}),b?"正在加载…":"加载更早消息"]})}),n.jsx(_n.Empty,{children:n.jsx(Nh,{envLabel:p?.label??y,offline:g,cwd:m?.cwd??p?.cwd??null})}),n.jsx(_n.Messages,{components:jh})]}),n.jsx(_n.ViewportFooter,{className:"sticky bottom-0 mt-auto",children:n.jsxs("div",{className:"relative mx-auto w-full max-w-3xl px-4 pb-3",children:[n.jsx("div",{className:"from-background via-background/95 pointer-events-none absolute inset-x-0 -top-6 h-6 bg-gradient-to-t to-transparent"}),n.jsx(vh,{}),n.jsx(bh,{conversationId:e,envName:y,offline:g})]})})]})})]})]})})}function wh(e){return/^(aborted|cancel)/i.test((e??"").trim())}function Ch({run:e}){const t=il();if(!e)return null;const s=[];e.failure&&!wh(e.failure.reason)&&s.push({tone:"bad",icon:n.jsx(qu,{className:"size-3"}),text:n.jsxs(n.Fragment,{children:["运行失败:",e.failure.reason,e.failure.detail?` —— ${e.failure.detail}`:""]})}),e.compactionFailure&&s.push({tone:"bad",icon:n.jsx(vt,{className:"size-3"}),text:n.jsxs(n.Fragment,{children:["上下文压缩失败(",e.compactionFailure.trigger,"):",e.compactionFailure.error]})});for(const o of e.compactions)s.push({tone:"warn",icon:n.jsx(at,{className:"size-3 animate-spin [animation-duration:900ms]"}),text:n.jsxs(n.Fragment,{children:["正在压缩上下文(",o.trigger,",第 ",o.attempt," 次尝试)",o.blocking?" · 阻塞中":"",o.retryAt&&o.retryAt>t?` · ${Ts(o.retryAt-t)} 后重试`:"",o.retryError?` · 上次失败:${o.retryError}`:""]})});const r=e.generation;if(r&&r.retryError&&s.push({tone:"warn",icon:n.jsx(cs,{className:"size-3"}),text:n.jsxs(n.Fragment,{children:["模型请求第 ",r.attempt," 次重试:",r.retryError,r.retryAt&&r.retryAt>t?` · ${Ts(r.retryAt-t)} 后重试`:""]})}),e.running&&e.tools.length>0){const o=e.tools.filter(a=>a.status==="running").length;s.push({tone:"brand",icon:n.jsx(at,{className:"size-3 animate-spin [animation-duration:900ms]"}),text:n.jsxs(n.Fragment,{children:[o>0?`正在执行 ${o} 个工具`:`${e.tools.length} 个工具槽位`,e.nestedTools.length>0?` · 嵌套 ${e.nestedTools.length}`:"",e.turns!==void 0?` · 第 ${e.turns} 轮`:""]})})}else e.running&&s.length===0&&s.push({tone:"brand",icon:n.jsx(at,{className:"size-3 animate-spin [animation-duration:900ms]"}),text:n.jsxs(n.Fragment,{children:["正在生成",e.turns!==void 0?` · 第 ${e.turns} 轮`:""]})});return s.length===0?null:n.jsx("div",{className:"border-line flex shrink-0 flex-col border-b",children:s.map((o,a)=>n.jsxs("div",{className:U("flex items-center gap-2 px-3 py-1 text-[11px]",o.tone==="bad"&&"text-bad bg-bad/8",o.tone==="warn"&&"text-warn bg-warn/8",o.tone==="brand"&&"text-brand bg-brand/8"),children:[n.jsx("span",{className:"shrink-0",children:o.icon}),n.jsx("span",{className:"min-w-0 flex-1 truncate",children:o.text})]},a))})}const Sh=["报告这个环境的 Python / Node 版本和关键依赖","看一下当前目录的 git 状态,有哪些未提交的改动","概述这个仓库的结构和主要模块"];function Nh({envLabel:e,offline:t,cwd:s}){return n.jsx(wn,{className:"pt-16",tone:t?"bad":"muted",icon:n.jsx(zs,{className:"size-5"}),title:t?`${e} 当前离线`:`${e} 上的新会话`,detail:t?"环境探测失败,发消息会排队但不会有回应。先在左侧环境栏看看错误原因。":n.jsxs(n.Fragment,{children:["这个会话的 agent 跑在 ",n.jsx("span",{className:"text-foreground/80",children:e}),s?n.jsxs(n.Fragment,{children:[" ","的 ",n.jsx("code",{className:"pg-num bg-surface-3 rounded px-1 py-px text-[10.5px]",children:s})]}):null,"。它的工具调用全部在远端执行。"]}),action:t?void 0:n.jsx("div",{className:"flex w-full max-w-md flex-col gap-1.5",children:Sh.map(r=>n.jsx(_n.Suggestion,{prompt:r,send:!1,className:U("border-line bg-surface-2/50 hover:border-brand/40 hover:bg-surface-2","text-muted-foreground hover:text-foreground w-full rounded-md border px-3 py-2","text-left text-[11.5px] transition-all duration-150"),children:r},r))})})}function Eh({env:e,cwd:t,enabledLocalSkills:s,disabledRemoteSkills:r,onEnabledLocalSkillsChange:o,onDisabledRemoteSkillsChange:a,fallbackLocalSkills:l=[],compact:c=!1}){const{notify:f}=Ye(),[u,d]=i.useState(null),[m,k]=i.useState(!1),[v,x]=i.useState(null),[y,p]=i.useState(""),[g,j]=i.useState(""),[C,h]=i.useState(""),b=i.useCallback(async(I=!1)=>{if(!(!e||!t.trim())){k(!0);try{const _=await ie.workspaceSkills(e,t.trim(),I);d(_)}catch{d(null)}finally{k(!1)}}},[e,t]);i.useEffect(()=>{d(null),p(""),j(""),b(!1)},[b]);const N=C.trim().toLowerCase(),S=I=>!N||I.name.toLowerCase().includes(N)||(I.description??"").toLowerCase().includes(N),T=u?.localSkills??l,P=u?.remoteSkills??[],B=T.filter(S),L=P.filter(S),K=P.filter(I=>!r.includes(I.name)).length+s.length,A=I=>{o(s.includes(I)?s.filter(_=>_!==I):[...s,I])},z=I=>{a(r.includes(I)?r.filter(_=>_!==I):[...r,I])},M=async I=>{if(!(!e||!t.trim())){x(`push:${I}`);try{await ie.installWorkspaceSkill(e,{cwd:t.trim(),name:I,fromLocal:I}),o(s.filter(_=>_!==I)),f({tone:"ok",title:`已安装 Skill "${I}" 到目标目录`}),await b(!0)}catch(_){f({tone:"bad",title:"安装 Skill 失败",detail:_ instanceof Error?_.message:String(_)})}finally{x(null)}}},R=async()=>{if(!(!e||!t.trim()||!y.trim()||!g.trim())){x("create-new");try{await ie.installWorkspaceSkill(e,{cwd:t.trim(),name:y.trim(),content:g}),p(""),j(""),f({tone:"ok",title:"已写入新 SKILL.md 到目标目录"}),await b(!0)}catch(I){f({tone:"bad",title:"创建 Skill 失败",detail:I instanceof Error?I.message:String(I)})}finally{x(null)}}},W=async I=>{if(!(!e||!t.trim())){x(`rm:${I}`);try{await ie.removeWorkspaceSkill(e,t.trim(),I),f({tone:"warn",title:`已从目录移除 Skill "${I}"`}),await b(!0)}catch(_){f({tone:"bad",title:"移除 Skill 失败",detail:_ instanceof Error?_.message:String(_)})}finally{x(null)}}};return n.jsxs("div",{className:U("border-line bg-surface/50 space-y-3 rounded-lg border",c?"p-2.5":"p-3"),children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-semibold",children:[n.jsx(Wo,{className:"text-brand size-3.5"}),n.jsx("span",{children:"目录 Skills"}),n.jsxs("span",{className:"text-muted-foreground shrink-0 text-[10px] font-normal",children:["生效 ",K]}),u?.agentsMd&&n.jsxs("span",{className:"bg-ok/15 text-ok inline-flex items-center gap-1 rounded px-1.5 py-px text-[10px] font-normal",children:[n.jsx(Za,{className:"size-2.5"})," 检测到 AGENTS.md"]})]}),n.jsxs(ke,{type:"button",size:"xs",variant:"ghost",onClick:()=>void b(!0),disabled:m||!t.trim(),children:[n.jsx(cs,{className:U("size-3",m&&"animate-spin")}),"扫描目录"]})]}),(T.length>6||P.length>6)&&n.jsx(Ke,{value:C,onChange:I=>h(I.target.value),placeholder:"过滤 Skill…","aria-label":"过滤 Skill",className:"h-6 py-0 text-[11px]"}),u?.remoteError&&n.jsxs("div",{className:"border-warn/35 bg-warn/10 text-warn rounded border px-2 py-1 text-[11px]",children:["远端扫描未完成:",u.remoteError,"(仍可勾选本地个人 Skill)"]}),n.jsxs("div",{className:"space-y-1",children:[n.jsxs("div",{className:"text-muted-foreground text-[10.5px] font-medium",children:["目标目录自带(",n.jsx("code",{children:".agents/skills/"})," · ",n.jsx("code",{children:".pi/skills/"}),")"]}),L.length===0?n.jsx("div",{className:"text-muted-foreground text-[11px]",children:m?"正在扫描…":N?"没有匹配的 Skill":"该目录下暂未发现项目级 Skill"}):n.jsx("div",{className:"space-y-1",children:L.map(I=>{const _=!r.includes(I.name);return n.jsxs("div",{className:"border-line bg-background/60 flex items-center justify-between gap-2 rounded border px-2.5 py-1.5 text-xs",children:[n.jsxs("label",{className:"flex min-w-0 flex-1 cursor-pointer items-start gap-2",children:[n.jsx("input",{type:"checkbox",checked:_,onChange:()=>z(I.name),className:"mt-0.5"}),n.jsxs("div",{className:"min-w-0",children:[n.jsx("div",{className:"font-mono text-[11.5px] font-medium",children:I.name}),I.description&&n.jsx("div",{className:"text-muted-foreground truncate text-[10.5px]",children:I.description})]})]}),n.jsx("button",{type:"button",onClick:()=>void W(I.name),disabled:v===`rm:${I.name}`,className:"text-muted-foreground hover:text-bad shrink-0 p-1",title:"从目标目录删除此 Skill",children:n.jsx(jo,{className:"size-3.5"})})]},I.path)})})]}),n.jsxs("div",{className:"border-line space-y-1 border-t pt-2",children:[n.jsx("div",{className:"text-muted-foreground text-[10.5px] font-medium",children:"本机个人 Skill 库(勾选即零侵入启用,含脚本可点击“安装到目录”)"}),B.length===0?n.jsxs("div",{className:"text-muted-foreground text-[11px]",children:["本机 ",n.jsx("code",{children:"~/.agents/skills"})," 与 ",n.jsx("code",{children:"~/.pi/agent/skills"})," 暂无 Skill"]}):n.jsx("div",{className:U("space-y-1 overflow-y-auto",c?"max-h-72":"max-h-40"),children:B.map(I=>{const _=s.includes(I.name),V=P.some(H=>H.name===I.name);return n.jsxs("div",{className:"border-line bg-background/60 flex items-center justify-between gap-2 rounded border px-2.5 py-1.5 text-xs",children:[n.jsxs("label",{className:"flex min-w-0 flex-1 cursor-pointer items-start gap-2",children:[n.jsx("input",{type:"checkbox",checked:_||V,disabled:V,onChange:()=>A(I.name),className:"mt-0.5"}),n.jsxs("div",{className:"min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:"font-mono text-[11.5px] font-medium",children:I.name}),I.hasScripts&&n.jsx("span",{className:"bg-warn/15 text-warn rounded px-1 py-px text-[9.5px]",children:"含脚本"}),V&&n.jsx("span",{className:"bg-ok/15 text-ok rounded px-1 py-px text-[9.5px]",children:"已在目录中"})]}),I.description&&n.jsx("div",{className:"text-muted-foreground truncate text-[10.5px]",children:I.description})]})]}),!V&&t.trim()&&n.jsxs(ke,{type:"button",size:"xs",variant:"outline",onClick:()=>void M(I.name),disabled:v===`push:${I.name}`,title:"复制到目标目录 .agents/skills/ 以便直接运行脚本",children:[n.jsx(el,{className:"size-3"}),v===`push:${I.name}`?"推送中…":"安装到目录"]})]},I.name)})})]}),n.jsxs("details",{className:"group border-line border-t pt-2 text-xs",children:[n.jsxs("summary",{className:"text-muted-foreground hover:text-foreground flex cursor-pointer list-none items-center gap-1 text-[11px] font-medium",children:[n.jsx(is,{className:"size-3 transition-transform group-open:rotate-90"}),n.jsx(pn,{className:"size-3"})," 新建 Skill 到目标目录"]}),n.jsxs("div",{className:"mt-2 space-y-2",children:[n.jsx(Ke,{value:y,onChange:I=>p(I.target.value),placeholder:"Skill 名称(如 deploy-check)",className:"font-mono"}),n.jsx("textarea",{value:g,onChange:I=>j(I.target.value),rows:4,placeholder:`---
27
+ name: deploy-check
28
+ description: 检查服务部署前置条件
29
+ ---
30
+
31
+ 具体执行步骤…`,className:"border-input text-foreground focus-visible:border-ring focus-visible:ring-ring/35 w-full rounded-md border bg-transparent px-2.5 py-1.5 font-mono text-xs outline-none focus-visible:ring-2 dark:bg-input/25"}),n.jsx("div",{className:"flex justify-end",children:n.jsx(ke,{type:"button",size:"xs",variant:"outline",disabled:v==="create-new"||!y.trim()||!g.trim()||!t.trim(),onClick:()=>void R(),children:v==="create-new"?"写入中…":"写入 .agents/skills/"})})]})]})]})}const Ga=2e3;function Th(){const{envRows:e,conversations:t,activeConvId:s,filesMode:r,bootstrap:o,notify:a,reloadBootstrap:l,openWorkspaceSettings:c,filesJump:f}=Ye(),u=t.find(G=>G.conversationId===s),d=o?.localOnly??!0,[m,k]=i.useState(u?.env??e[0]?.name??""),[v,x]=i.useState(""),[y,p]=i.useState(""),[g,j]=i.useState(null),[C,h]=i.useState(!1),[b,N]=i.useState(0),[S,T]=i.useState(!1),[P,B]=i.useState(""),[L,K]=i.useState(!1),[A,z]=i.useState(null),M=e.find(G=>G.name===m),R=M?.cwd??M?.status?.cwd??"/",[W,I]=i.useState(null),_=G=>{const fe=(G??"").trim();return!fe||fe==="/"?"/":fe.replace(/\/+$/,"")||"/"},V=_(u?.cwd||M?.cwd||v),H=`${m}:${V}`,Y=e.find(G=>G.name===m)?.workspaces?.find(G=>_(G.cwd)===V),le=W?.key===H?W:{skills:Y?.skills??[],disabled:Y?.disabledSkills??[]},J=async G=>{I({key:H,...G});try{await ie.saveWorkspace(m,{cwd:V,...Y?.name?{name:Y.name}:{},...Y?.model?{model:Y.model}:{},...Y?.thinkingLevel?{thinkingLevel:Y.thinkingLevel}:{},...Y?.instructions?{instructions:Y.instructions}:{},...G.skills.length>0?{skills:G.skills}:{},...G.disabled.length>0?{disabledSkills:G.disabled}:{}}),l()}catch(fe){a({tone:"bad",title:"保存 Skills 配置失败",detail:fe instanceof Error?fe.message:String(fe)})}};i.useEffect(()=>{x(R||"/"),p(R||"/"),j(null),h(!1),T(!1),z(null)},[m,R]);const se=u?.env,Z=u?.cwd;i.useEffect(()=>{se&&e.some(G=>G.name===se)&&(k(se),Z&&(x(Z),p(Z),j(null),h(!1)))},[s,Z]),i.useEffect(()=>{f&&(k(f.env),x(f.cwd),p(f.cwd),j(null),h(!1))},[f]),i.useEffect(()=>{if(m)return;const G=se??e[0]?.name;G&&k(G)},[m,se,e]);const re=M?.status?!M.status.ok:!1,we=async G=>{G.preventDefault();const fe=P.trim();if(!fe||L)return;const te=(v||"/").replace(/\/+$/,"")||"/",ae=fe.startsWith("/")?fe:`${te==="/"?"":te}/${fe.replace(/^\/+/,"")}`,ce=ae.split("/").filter(Boolean).pop()??ae;K(!0),z(null);try{await ie.writeFile(m,{path:ae,content:"",createOnly:!0,createParents:!0}),T(!1),B(""),N(je=>je+1),h(!0),j({name:ce,path:ae,kind:"file",isDir:!1,size:0,mtimeMs:Date.now()}),a({tone:"ok",title:`已创建 ${ce}`})}catch(je){z(je instanceof Error?je.message:String(je))}finally{K(!1)}},D=Bd(v),$=D!==v,ee=G=>{x(G),p(G),j(null),h(!1)};return n.jsxs("section",{className:"flex min-h-0 flex-1 flex-col",children:[n.jsxs("div",{className:"border-line flex h-9 shrink-0 items-center gap-1.5 border-b px-2",children:[n.jsx("div",{className:"min-w-0 max-w-[55%]",children:n.jsx(As,{value:m,onChange:G=>k(G.target.value),className:"h-6 py-0 text-[11px]","aria-label":"选择环境",children:e.map(G=>n.jsxs("option",{value:G.name,children:[G.label,G.status&&!G.status.ok?"(离线)":""]},G.name))})}),n.jsx("span",{className:"flex-1"}),r==="files"&&d&&!re&&e.length>0&&n.jsx(ke,{variant:"ghost",size:"icon-xs",onClick:()=>{z(null),T(G=>!G)},title:"在当前目录新建文件","aria-label":"新建文件",className:U("text-muted-foreground hover:text-foreground",S&&"bg-brand/15 text-brand"),children:n.jsx(tl,{className:"size-3"})}),r!=="skills"&&n.jsx(ke,{variant:"ghost",size:"icon-xs",onClick:()=>N(G=>G+1),title:"重新加载","aria-label":"重新加载",className:"text-muted-foreground hover:text-foreground",children:n.jsx(cs,{className:"size-3"})})]}),r==="files"&&n.jsxs("form",{className:"border-line flex shrink-0 items-center gap-1 border-b px-2 py-1.5",onSubmit:G=>{G.preventDefault(),ee(y.trim()||"/")},children:[n.jsx(ke,{type:"button",variant:"ghost",size:"icon-xs",disabled:!$,onClick:()=>ee(D),title:"上一级","aria-label":"上一级",className:"text-muted-foreground hover:text-foreground shrink-0",children:n.jsx(Yu,{className:"size-3"})}),n.jsx(Ke,{value:y,onChange:G=>p(G.target.value),placeholder:"/path/on/remote",className:"pg-num h-6 min-w-0 flex-1 py-0 font-mono text-[11px]","aria-label":"目录路径"}),g?n.jsxs(ke,{type:"button",variant:"ghost",size:"xs",className:"h-6 shrink-0",onClick:()=>{j(null),h(!1)},children:[n.jsx(rl,{className:"size-3"}),"返回"]}):n.jsx(ke,{type:"submit",variant:"ghost",size:"xs",className:"h-6 shrink-0",children:"前往"})]}),r==="files"&&S&&n.jsxs("form",{onSubmit:we,className:"border-line bg-surface-2/60 flex shrink-0 flex-col gap-1.5 border-b p-2",children:[n.jsxs("div",{className:"flex items-center justify-between text-[10.5px]",children:[n.jsx("span",{className:"text-foreground/85 font-medium",children:"新建文件"}),n.jsx("span",{className:"text-muted-foreground truncate font-mono",title:v,children:v})]}),n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx(Ke,{value:P,onChange:G=>B(G.target.value),placeholder:"例如 notes.md 或 dir/app.ts",autoFocus:!0,className:"pg-num h-7 flex-1 py-0 font-mono text-[11px]","aria-label":"新文件路径"}),n.jsx(ke,{type:"submit",size:"xs",className:"h-7 shrink-0",disabled:L||!P.trim(),children:L?"创建中…":"创建"}),n.jsx(ke,{type:"button",variant:"ghost",size:"icon-xs",className:"h-7 w-7 shrink-0",onClick:()=>{T(!1),z(null)},"aria-label":"取消新建",children:n.jsx(Ds,{className:"size-3"})})]}),A&&n.jsx("p",{className:"text-bad text-[10.5px] break-all",children:A})]}),n.jsx("div",{className:"flex min-h-0 flex-1 flex-col",children:e.length===0?n.jsx(wn,{title:"还没有可用环境",detail:"等引导快照或环境流返回后再试。"}):m?re?n.jsx(wn,{tone:"bad",icon:n.jsx(vt,{className:"size-5"}),title:`${M?.label??m} 当前离线`,detail:M?.status?.error??"无法访问远端文件系统。"}):r==="skills"?n.jsxs("div",{className:"pg-scroll-y min-h-0 flex-1 p-2",children:[n.jsxs("button",{type:"button",onClick:()=>c(m,Y??{cwd:V,implicit:!0}),className:"border-line bg-surface-2/50 hover:bg-surface-2 mb-2 flex w-full items-center gap-1.5 rounded-md border px-2 py-1.5 text-left transition-colors",title:"打开目录设置(模型 / 思考强度 / 指令)",children:[n.jsx(Fs,{className:"text-muted-foreground size-3 shrink-0"}),n.jsx("span",{className:"text-muted-foreground shrink-0 text-[10.5px]",children:M?.label??m}),n.jsx("span",{className:"text-muted-foreground/50",children:"·"}),n.jsx("span",{className:"pg-num text-foreground/85 min-w-0 flex-1 truncate text-[10.5px]",children:V}),n.jsx("span",{className:"text-muted-foreground/60 shrink-0 text-[10px]",children:"跟随当前会话"})]}),n.jsx(Eh,{env:m,cwd:V,enabledLocalSkills:le.skills,disabledRemoteSkills:le.disabled,onEnabledLocalSkillsChange:G=>void J({skills:G,disabled:le.disabled}),onDisabledRemoteSkillsChange:G=>void J({skills:le.skills,disabled:G}),fallbackLocalSkills:o?.localSkills,compact:!0},`${m}:${V}`)]}):r==="files"?g?n.jsx(Ph,{env:m,file:g,localOnly:d,initialEdit:C,onSaved:()=>N(G=>G+1),onBack:()=>{j(null),h(!1)}},`${m}:${g.path}`):n.jsx(Rh,{env:m,path:v,onOpenFile:G=>{h(!1),j(G)},onNavigate:ee},`${m}:${v}:${b}`):n.jsx(Ih,{env:m,cwd:v},`${m}:${v}:${b}:${r}`):n.jsx(wn,{title:"正在选择环境…"})})]})}function Rh({env:e,path:t,onOpenFile:s}){const[r,o]=i.useState({loading:!0,data:null,error:null});if(i.useEffect(()=>{let c=!1;return o({loading:!0,data:null,error:null}),ie.listDir(e,t).then(f=>{c||o({loading:!1,data:f,error:null})},f=>{c||o({loading:!1,data:null,error:f instanceof Error?f.message:String(f)})}),()=>{c=!0}},[e,t]),r.loading)return n.jsxs("div",{className:"text-muted-foreground flex items-center gap-2 px-3 py-3 text-[11px]",children:[n.jsx(at,{className:"size-3 animate-spin"}),"正在列出 ",t]});if(r.error)return n.jsx(wn,{tone:"bad",icon:n.jsx(vt,{className:"size-5"}),title:"列目录失败",detail:r.error});const a=r.data;if(!a||!a.ok)return n.jsx(wn,{tone:"bad",icon:n.jsx(vt,{className:"size-5"}),title:"远端返回失败",detail:a?.error??"未知错误"});const l=a.entries??[];return n.jsx("div",{className:"flex min-h-0 flex-1 flex-col",children:n.jsxs("ul",{className:"divide-line pg-scroll-y min-h-0 flex-1 divide-y",children:[l.map(c=>c.isDir?n.jsx(su,{env:e,entry:c,onOpenFile:s},c.path):n.jsx("li",{children:n.jsxs("button",{type:"button",onClick:()=>s(c),className:"hover:bg-surface-2 group/file flex w-full items-center gap-2 px-2.5 py-1.5 text-left transition-colors",children:[n.jsx("span",{className:"w-3 shrink-0"}),c.kind==="symlink"?n.jsx(Ju,{className:"text-peer/70 size-3.5 shrink-0"}):n.jsx(Ho,{className:"text-muted-foreground/70 group-hover/file:text-brand size-3.5 shrink-0 transition-colors"}),n.jsx("span",{className:"text-foreground/85 min-w-0 flex-1 truncate font-mono text-[11.5px]",children:c.name}),n.jsx("span",{className:"text-muted-foreground/55 pg-num shrink-0 text-[10px]",children:Cs(c.size)}),n.jsx("span",{className:"text-muted-foreground/40 pg-num hidden shrink-0 text-[10px] xl:inline",children:Vo(c.mtimeMs)})]})},c.path)),l.length===0&&n.jsx("li",{className:"text-muted-foreground px-3 py-4 text-center text-[11px]",children:"空目录"})]})})}function su({env:e,entry:t,onOpenFile:s,depth:r=0}){const[o,a]=i.useState(!1),[l,c]=i.useState({loading:!1,entries:null,error:null}),f=i.useCallback(()=>{const u=!o;a(u),u&&l.entries===null&&!l.loading&&(c({loading:!0,entries:null,error:null}),ie.listDir(e,t.path).then(d=>{d.ok?c({loading:!1,entries:d.entries??[],error:null}):c({loading:!1,entries:null,error:d.error??"列目录失败"})},d=>{c({loading:!1,entries:null,error:d instanceof Error?d.message:String(d)})}))},[o,l.entries,l.loading,e,t.path]);return n.jsxs("li",{children:[n.jsxs("button",{type:"button",onClick:f,"aria-expanded":o,className:"hover:bg-surface-2 flex w-full items-center gap-1.5 px-2.5 py-1.5 text-left transition-colors",style:{paddingInlineStart:`${10+r*12}px`},children:[l.loading?n.jsx(at,{className:"text-muted-foreground size-3 shrink-0 animate-spin"}):o?n.jsx(ls,{className:"text-muted-foreground/60 size-3 shrink-0"}):n.jsx(is,{className:"text-muted-foreground/60 size-3 shrink-0"}),o?n.jsx(Zu,{className:"text-brand/80 size-3.5 shrink-0"}):n.jsx(Fs,{className:"text-muted-foreground/70 size-3.5 shrink-0"}),n.jsx("span",{className:"text-foreground/85 min-w-0 flex-1 truncate font-mono text-[11.5px]",children:t.name}),n.jsx("span",{className:"text-muted-foreground/40 pg-num hidden shrink-0 text-[10px] xl:inline",children:Vo(t.mtimeMs)})]}),o&&n.jsxs("ul",{className:"divide-line divide-y",children:[l.error&&n.jsx("li",{className:"text-bad bg-bad/8 px-3 py-1.5 text-[10.5px]",style:{paddingInlineStart:`${22+r*12}px`},children:l.error}),l.entries?.map(u=>u.isDir?n.jsx(su,{env:e,entry:u,onOpenFile:s,depth:r+1},u.path):n.jsx("li",{children:n.jsxs("button",{type:"button",onClick:()=>s(u),className:"hover:bg-surface-2 group/file flex w-full items-center gap-2 py-1.5 pr-2.5 text-left transition-colors",style:{paddingInlineStart:`${22+r*12}px`},children:[n.jsx(Ho,{className:"text-muted-foreground/60 group-hover/file:text-brand size-3.5 shrink-0 transition-colors"}),n.jsx("span",{className:"text-foreground/80 min-w-0 flex-1 truncate font-mono text-[11.5px]",children:u.name}),n.jsx("span",{className:"text-muted-foreground/50 pg-num shrink-0 text-[10px]",children:Cs(u.size)})]})},u.path)),l.entries&&l.entries.length===0&&n.jsx("li",{className:"text-muted-foreground/60 py-1.5 text-[10.5px] italic",style:{paddingInlineStart:`${22+r*12}px`},children:"空目录"})]})]})}function Ph({env:e,file:t,localOnly:s=!0,initialEdit:r=!1,onSaved:o,onBack:a}){const{notify:l}=Ye(),[c,f]=i.useState({loading:!r,data:r?{ok:!0,path:t.path,lines:[],truncated:!1}:null,error:null}),[u,d]=i.useState(t.size),[m,k]=i.useState(!1),[v,x]=i.useState(!1),[y,p]=i.useState(""),[g,j]=i.useState(""),[C,h]=i.useState(null),[b,N]=i.useState(!1),[S,T]=i.useState(null),[P,B]=i.useState(!1),[L,K]=i.useState(!1),A=m&&y!==g,z=i.useCallback(async()=>{x(!0),T(null),B(!1);try{const H=await ie.readFileRaw(e,t.path);if(!H.ok){T(H.error??"无法进入编辑模式");return}const Y=H.content??"";j(Y),p(Y),h(H.sha256??null),typeof H.size=="number"&&d(H.size),k(!0)}catch(H){T(H instanceof Error?H.message:String(H))}finally{x(!1)}},[e,t.path]);i.useEffect(()=>{if(r){z();return}let H=!1;return f({loading:!0,data:null,error:null}),ie.readFile(e,t.path,Ga).then(Y=>{H||f({loading:!1,data:Y,error:null})},Y=>{H||f({loading:!1,data:null,error:Y instanceof Error?Y.message:String(Y)})}),()=>{H=!0}},[e,t.path,r,z]);const M=async(H=!1)=>{if(!b){N(!0),T(null),B(!1);try{const Y=await ie.writeFile(e,{path:t.path,content:y,...!H&&C?{expectedSha256:C}:{}});j(y),h(Y.sha256),d(Y.size),f({loading:!1,data:{ok:!0,path:t.path,lines:y===""?[]:y.split(`
32
+ `),truncated:!1},error:null}),o?.(),l({tone:"ok",title:`已保存 ${t.name}`})}catch(Y){Y instanceof ur&&Y.status===409&&B(!0),T(Y instanceof Error?Y.message:String(Y))}finally{N(!1)}}},R=()=>{A&&!window.confirm("当前修改尚未保存,确定放弃更改吗?")||(k(!1),K(!1),T(null),B(!1))},W=()=>{A&&!window.confirm("当前修改尚未保存,确定返回并放弃更改吗?")||a()},I=H=>{if((H.metaKey||H.ctrlKey)&&H.key.toLowerCase()==="s"){H.preventDefault(),M(!1);return}if(H.key==="Tab"){H.preventDefault();const Y=H.currentTarget,le=Y.selectionStart,J=Y.selectionEnd,se=`${y.slice(0,le)} ${y.slice(J)}`;p(se),requestAnimationFrame(()=>{Y.selectionStart=Y.selectionEnd=le+2})}},_=c.data?.lines??[],V=H=>n.jsxs("div",{className:U("flex min-h-0 flex-1 flex-col gap-2",H?"h-[68vh]":"p-2"),children:[S&&n.jsxs("div",{className:"border-bad/35 bg-bad/10 text-bad flex flex-wrap items-center justify-between gap-2 rounded border px-2.5 py-1.5 text-[11px]",children:[n.jsx("span",{className:"min-w-0 flex-1 break-all",children:S}),P&&n.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[n.jsx(ke,{type:"button",size:"xs",variant:"outline",onClick:()=>void z(),children:"重新加载"}),n.jsx(ke,{type:"button",size:"xs",variant:"destructive",onClick:()=>void M(!0),children:"强制覆盖"})]})]}),n.jsx("textarea",{value:y,onChange:Y=>p(Y.target.value),onKeyDown:I,spellCheck:!1,autoFocus:!0,placeholder:"输入文件内容…(Cmd/Ctrl+S 保存)",className:U("border-line bg-background/75 text-foreground/95 focus-visible:border-brand/50 pg-scroll-y min-h-0 w-full flex-1 resize-none rounded-md border p-2.5 font-mono leading-[1.55] outline-none",H?"text-[12.5px]":"text-[11.5px]")}),n.jsxs("div",{className:"text-muted-foreground/75 flex items-center justify-between text-[10px]",children:[n.jsx("span",{children:"Cmd/Ctrl+S 保存 · Tab 插入 2 空格"}),n.jsxs("span",{className:"pg-num",children:[y.split(`
33
+ `).length," 行 · ",Cs(new Blob([y]).size)]})]})]});return n.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[n.jsxs("div",{className:"border-line bg-surface/40 flex shrink-0 items-center gap-1.5 border-b px-2.5 py-1.5",children:[n.jsxs("button",{type:"button",onClick:W,className:"text-muted-foreground hover:text-brand flex items-center gap-1 text-[10.5px] transition-colors",children:[n.jsx(rl,{className:"size-3"}),"返回"]}),n.jsx("span",{className:"text-foreground/85 min-w-0 flex-1 truncate font-mono text-[11px]",title:t.path,children:t.name}),m?n.jsxs(n.Fragment,{children:[A&&n.jsx("span",{className:"text-warn shrink-0 text-[10px]",title:"有未保存更改",children:"● 未保存"}),n.jsx(ke,{type:"button",size:"icon-xs",variant:"ghost",onClick:()=>K(!0),title:"放大弹窗编辑","aria-label":"放大编辑",children:n.jsx(Xu,{className:"size-3"})}),n.jsxs(ke,{type:"button",size:"xs",variant:"default",onClick:()=>void M(!1),disabled:b||!A&&C!==null,className:"h-6 gap-1 px-2 text-[10.5px]",children:[n.jsx(Di,{className:"size-3"}),b?"保存中…":"保存"]}),n.jsx(ke,{type:"button",size:"xs",variant:"ghost",onClick:R,className:"h-6 px-1.5 text-[10.5px]",children:"退出"})]}):n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"text-muted-foreground/60 pg-num shrink-0 text-[10px]",children:Cs(u)}),s&&n.jsxs(ke,{type:"button",size:"xs",variant:"outline",onClick:()=>void z(),disabled:v,className:"h-6 gap-1 px-2 text-[10.5px]",title:"编辑此文件(512 KB 以内文本文件)",children:[n.jsx(Qa,{className:"size-3"}),v?"读取中…":"编辑"]})]})]}),!m&&S&&n.jsxs("div",{className:"border-bad/30 bg-bad/10 text-bad flex items-center justify-between gap-2 border-b px-2.5 py-1.5 text-[11px]",children:[n.jsx("span",{className:"min-w-0 flex-1 break-all",children:S}),n.jsx("button",{type:"button",onClick:()=>T(null),className:"shrink-0 opacity-70 hover:opacity-100",children:n.jsx(Ds,{className:"size-3"})})]}),m?L?n.jsxs("div",{className:"text-muted-foreground flex flex-1 flex-col items-center justify-center gap-2 p-4 text-center text-[11.5px]",children:[n.jsxs("p",{children:["正在放大弹窗中编辑 ",n.jsx("span",{className:"text-foreground font-mono",children:t.name})]}),n.jsx(ke,{type:"button",size:"xs",variant:"outline",onClick:()=>K(!1),children:"切回侧栏继续编辑"})]}):V(!1):n.jsxs(n.Fragment,{children:[c.loading&&n.jsxs("div",{className:"text-muted-foreground flex items-center gap-2 px-3 py-3 text-[11px]",children:[n.jsx(at,{className:"size-3 animate-spin"}),"正在读取…"]}),c.error&&n.jsx(wn,{tone:"bad",icon:n.jsx(vt,{className:"size-5"}),title:"读取失败",detail:c.error}),!c.loading&&!c.error&&c.data&&!c.data.ok&&n.jsx(wn,{tone:"bad",icon:n.jsx(vt,{className:"size-5"}),title:"远端返回失败",detail:c.data.error??"未知错误"}),c.data?.ok&&n.jsxs(n.Fragment,{children:[c.data.truncated&&n.jsxs("p",{className:"text-warn bg-warn/8 border-warn/25 flex items-start gap-1.5 border-b px-2.5 py-1.5 text-[10.5px] leading-snug",children:[n.jsx(vt,{className:"mt-px size-3 shrink-0"}),"只显示前 ",Ga," 行 —— 这是读取上限,不是文件的全部长度 (远端报告 ",Cs(u),")。"]}),n.jsxs("div",{className:"pg-scroll-y min-h-0 flex-1",children:[n.jsx("table",{className:"w-full border-separate border-spacing-0",children:n.jsx("tbody",{children:_.map((H,Y)=>n.jsxs("tr",{className:"group/line hover:bg-surface-2/60",children:[n.jsx("td",{className:"text-muted-foreground/40 bg-surface/40 w-10 min-w-10 select-none px-1.5 py-0 text-right align-top font-mono text-[10px] leading-[1.6]",children:Y+1}),n.jsx("td",{className:"text-foreground/85 px-2 py-0 font-mono text-[11px] leading-[1.6] whitespace-pre-wrap break-all",children:H||" "})]},Y))})}),_.length===0&&n.jsx("p",{className:"text-muted-foreground px-3 py-4 text-center text-[11px] italic",children:"空文件"})]})]})]}),n.jsx(Ut,{open:L&&m,onOpenChange:H=>!H&&K(!1),children:n.jsxs(Wt,{className:"max-h-[90vh] sm:max-w-4xl",children:[n.jsxs(Gt,{className:"flex-row items-center justify-between gap-2 space-y-0 pr-6",children:[n.jsx(Vt,{className:"min-w-0 truncate font-mono text-sm",title:t.path,children:t.path}),n.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[A&&n.jsx("span",{className:"text-warn text-[11px]",children:"● 未保存"}),n.jsxs(ke,{type:"button",size:"xs",variant:"default",onClick:()=>void M(!1),disabled:b||!A&&C!==null,className:"gap-1",children:[n.jsx(Di,{className:"size-3"}),b?"保存中…":"保存"]})]})]}),V(!0)]})})]})}function Oh(e){const t=new Map;for(const s of e.split(`
34
+ `)){const r=s.split(" ");if(r.length<3)continue;const[o,a,...l]=r;let c=l.join(" ").trim();c=c.replace(/\{([^}]*) => ([^}]*)\}/g,(f,u,d)=>`${u?`${u}/`:""}${d}`).replace(/^(.*?) => (.*)$/,"$2"),t.set(c,{add:o==="-"?0:Number(o),del:a==="-"?0:Number(a),binary:o==="-"})}return t}function Ih({env:e,cwd:t}){const[s,r]=i.useState(null),[o,a]=i.useState(null),[l,c]=i.useState(null),[f,u]=i.useState(!0),[d,m]=i.useState(null),k=i.useCallback(()=>{u(!0);const C=ie.gitStatus(e,t).then(b=>{r(b),a(null)},b=>a(b instanceof Error?b.message:String(b))),h=ie.gitDiff(e,{cwd:t,mode:"numstat"}).then(b=>c(b),()=>c(null));Promise.allSettled([C,h]).then(()=>u(!1))},[e,t]);i.useEffect(()=>{k()},[k]);const v=i.useCallback(C=>{m({file:C,exec:null,loading:!0}),ie.gitDiff(e,{cwd:t,mode:"patch",file:C}).then(h=>m(b=>b&&b.file===C?{file:C,exec:h,loading:!1}:b),h=>m(b=>b&&b.file===C?{file:C,exec:{ok:!1,command:`git diff -- ${C}`,output:"",error:h instanceof Error?h.message:String(h)},loading:!1}:b))},[e,t]),x=s?Vx(s.output):null,y=l?.ok?Oh(l.output):new Map,p=x?.entries??[],g=p.reduce((C,h)=>{const b=y.get(h.path);return b&&(C.add+=b.add,C.del+=b.del),C},{add:0,del:0}),j=(C,h)=>{const b=y.get(C);return h==="untracked"||!b||b.binary?n.jsx("span",{className:"w-12"}):n.jsxs("span",{className:"pg-num w-12 shrink-0 text-[10px] tabular-nums",children:[n.jsxs("span",{className:"text-ok",children:["+",b.add]})," ",n.jsxs("span",{className:"text-bad",children:["−",b.del]})]})};return n.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[n.jsxs("div",{className:"border-line bg-surface/40 flex shrink-0 items-center gap-2 border-b px-2.5 py-1.5",children:[n.jsx(wo,{className:"text-muted-foreground/70 size-3 shrink-0"}),x?.branch&&n.jsxs("span",{className:"text-brand bg-brand/12 shrink-0 rounded px-1.5 py-px text-[10px] font-medium",children:[x.branch,(x.ahead>0||x.behind>0)&&n.jsxs("span",{className:"pg-num ml-1 opacity-75",children:[x.ahead>0?`↑${x.ahead}`:"",x.behind>0?`↓${x.behind}`:""]})]}),n.jsx("span",{className:"text-muted-foreground pg-num min-w-0 flex-1 truncate text-[10.5px]",title:t,children:p.length>0?`${p.length} 个文件 · +${g.add} −${g.del}`:t}),n.jsx(ke,{variant:"ghost",size:"icon-xs",onClick:k,disabled:f,title:"刷新 git 状态","aria-label":"刷新 git 状态",className:"text-muted-foreground hover:text-foreground",children:n.jsx(cs,{className:U("size-3",f&&"animate-spin")})})]}),n.jsxs("div",{className:"pg-scroll-y min-h-0 flex-1",children:[o&&n.jsxs("p",{className:"text-bad bg-bad/8 border-bad/25 border-b px-2.5 py-1.5 text-[10.5px]",children:["git status 失败:",o]}),s&&!s.ok&&n.jsxs("p",{className:"text-bad bg-bad/8 border-bad/25 border-b px-2.5 py-1.5 text-[10.5px]",children:[s.error??`git 退出码 ${s.exitCode??"?"}`,s.command&&n.jsxs("span",{className:"pg-num ml-1 opacity-70",children:["$ ",s.command]})]}),p.length>0&&n.jsx("ul",{className:"divide-line divide-y",children:p.map(C=>{const h=Gx[C.state];return n.jsx("li",{children:n.jsxs("button",{type:"button",onClick:()=>v(C.path),className:"hover:bg-surface-2 flex w-full items-center gap-2 px-2.5 py-1.5 text-left transition-colors",title:"点击查看逐行 diff",children:[n.jsx("span",{className:"text-foreground/85 min-w-0 flex-1 truncate font-mono text-[11px]",children:C.path}),j(C.path,C.state),n.jsx("span",{className:U("ml-2 inline-flex w-4 shrink-0 justify-center rounded px-1 py-px font-mono text-[10px] font-bold",h.className),title:h.title,children:h.label})]})},`${C.xy}-${C.path}`)})}),x&&p.length===0&&!f&&!o&&s?.ok&&n.jsx("p",{className:"text-muted-foreground px-3 py-4 text-center text-[11px]",children:"工作树干净,没有未提交的改动。"})]}),n.jsx(Ut,{open:d!==null,onOpenChange:C=>!C&&m(null),children:n.jsxs(Wt,{className:"flex h-[88vh] w-[min(96vw,72rem)] max-w-none flex-col gap-0 p-0 sm:max-w-none",children:[n.jsxs(Gt,{className:"border-line flex-row items-center gap-3 border-b px-4 py-2.5 pr-10 text-left",children:[n.jsx(wo,{className:"text-muted-foreground size-3.5 shrink-0"}),n.jsx(Vt,{className:"min-w-0 flex-1 truncate font-mono text-xs",title:d?.file,children:d?.file}),d?.file&&n.jsx("span",{className:"pg-num shrink-0 text-[11px] tabular-nums",children:j(d.file,p.find(C=>C.path===d.file)?.state??"modified")})]}),n.jsx("div",{className:"pg-scroll-y min-h-0 flex-1",children:d?d.loading?n.jsxs("div",{className:"text-muted-foreground flex items-center gap-2 px-4 py-6 text-[11px]",children:[n.jsx(at,{className:"size-3 animate-spin"})," 正在加载逐行 diff…"]}):d.exec?.ok&&d.exec.output.trim()?n.jsx(Qc,{patch:d.exec.output}):n.jsx("p",{className:"text-muted-foreground px-4 py-6 text-[11px]",children:d.exec&&!d.exec.ok?`${d.exec.error??`git 退出码 ${d.exec.exitCode??"?"}`}`:"没有逐行差异(二进制文件、未跟踪的新文件,或需要先 git add)。"}):null}),d?.exec&&!d.loading&&n.jsx("div",{className:"border-line text-muted-foreground/70 border-t px-4 py-1",children:n.jsx(Ah,{exec:d.exec})})]})})]})}function Ah({exec:e}){return n.jsxs("div",{className:"text-muted-foreground/65 border-line bg-surface/30 pg-num flex flex-wrap items-center gap-x-2 border-t px-2.5 py-1 text-[10px]",children:[e.command&&n.jsxs("span",{className:"min-w-0 flex-1 truncate font-mono",title:e.command,children:["$ ",e.command]}),n.jsxs("span",{className:U("shrink-0",e.exitCode!==0&&"text-bad"),children:["退出码 ",e.exitCode??"—"]}),e.spillPath&&n.jsxs("span",{className:"text-warn shrink-0",title:"输出超过阈值,完整内容已写到远端这个路径",children:["溢出文件 ",e.spillPath]})]})}const Mh=[{id:"files",label:"文件",icon:Fs},{id:"git",label:"git",icon:wo},{id:"skills",label:"Skills",icon:Wo}];function Va({collapsed:e}){const{filesMode:t,setFilesMode:s}=Ye();return n.jsx(n.Fragment,{children:Mh.map(r=>{const o=t===r.id,a=r.icon;return n.jsxs("button",{type:"button",onClick:()=>s(r.id),title:r.label,"aria-label":r.label,"aria-current":o,className:U("flex items-center justify-center rounded transition-colors",e?"size-6":"h-6 gap-1 px-2 whitespace-nowrap",o?"bg-surface-3 text-foreground":"text-muted-foreground hover:bg-surface-3 hover:text-foreground"),children:[n.jsx(a,{className:"size-3.5"}),!e&&n.jsx("span",{className:"text-[11px]",children:r.label})]},r.id)})})}function $h(){const{setDockOpen:e,dockOpen:t}=Ye();return n.jsxs(n.Fragment,{children:[!t&&n.jsxs("div",{className:"border-line bg-surface/60 flex w-9 shrink-0 flex-col items-center gap-1 border-l py-2",children:[n.jsx("button",{type:"button",onClick:()=>e(!0),title:"展开侧栏","aria-label":"展开侧栏",className:"text-muted-foreground hover:bg-surface-3 hover:text-foreground flex size-6 items-center justify-center rounded transition-colors",children:n.jsx(Qu,{className:"size-3.5"})}),n.jsx("span",{className:"bg-line my-1 h-px w-4"}),n.jsx(Va,{collapsed:!0})]}),t&&n.jsxs("aside",{className:U("border-line bg-surface relative z-10 flex shrink-0 flex-col border-l","w-[340px] xl:w-[380px] 2xl:w-[420px]"),"aria-label":"侧栏面板",children:[n.jsxs("div",{className:"border-line flex h-9 shrink-0 items-center gap-1 border-b pr-0 pl-2",children:[n.jsx(Va,{}),n.jsx("span",{className:"flex-1"}),n.jsx("button",{type:"button",onClick:()=>e(!1),title:"收起侧栏","aria-label":"收起侧栏",className:"border-line text-muted-foreground hover:bg-surface-2 hover:text-foreground flex w-8 shrink-0 items-center justify-center self-stretch border-l transition-colors",children:n.jsx(ed,{className:"size-3.5"})})]}),n.jsx("div",{className:"flex min-h-0 flex-1 flex-col",children:n.jsx(Th,{})})]})]})}function Dh(){const{activePicker:e,pickerLoginProvider:t,closePicker:s,models:r,reloadModels:o,reloadAll:a,notify:l}=Ye(),c=e==="login",[f,u]=i.useState(""),[d,m]=i.useState(0),[k,v]=i.useState(null),[x,y]=i.useState(null),[p,g]=i.useState(null),[j,C]=i.useState([]),[h,b]=i.useState(""),[N,S]=i.useState(!1),[T,P]=i.useState(null),B=dr(k?`login:${k}`:null),L=i.useMemo(()=>(r?.providers??[]).filter(R=>R.canLogin||R.loggedIn),[r?.providers]),K=i.useMemo(()=>{const R=f.trim().toLowerCase();return R?L.filter(W=>W.id.toLowerCase().includes(R)||W.name.toLowerCase().includes(R)||(W.extension??"").toLowerCase().includes(R)):L},[L,f]);i.useEffect(()=>{if(c&&(u(""),m(0),v(null),y(null),g(null),C([]),b(""),P(null),t)){const R=L.find(W=>W.id.toLowerCase()===t.toLowerCase());R&&A(R)}},[c,t]),i.useEffect(()=>{const R=B.data;R&&(R.kind==="state"?(g(R.pendingPrompt??null),R.events&&C(R.events)):R.kind==="prompt"&&R.prompt?(g(R.prompt),b(""),S(!1)):R.kind==="event"&&R.event?C(W=>[...W,R.event]):R.kind==="done"?(S(!1),g(null),o(),l({tone:"ok",title:`${x?.name??"Provider"} 登录成功`,detail:"凭据已写入 ~/.pi/agent/auth.json,模型目录已刷新。"}),v(null),y(null)):R.kind==="error"?(S(!1),P(R.error??"登录失败"),v(null)):R.kind==="cancelled"&&(S(!1),v(null),g(null)))},[B.data,x,l,o]);async function A(R){P(null),C([]),g(null),y(R),S(!0);try{const W=R.authTypes.includes("oauth")?"oauth":"api_key",I=await ie.loginStart(R.id,W);v(I.loginId),I.pendingPrompt&&g(I.pendingPrompt),I.events?.length&&C(I.events)}catch(W){P(W instanceof Error?W.message:String(W)),y(null)}finally{S(!1)}}async function z(R){if(!k)return;const W=R??h;S(!0),P(null);try{await ie.loginReply(k,W),g(null),b("")}catch(I){P(I instanceof Error?I.message:String(I)),S(!1)}}async function M(R){P(null);try{await ie.logout(R.id),o(),l({tone:"ok",title:`已退出 ${R.name} 登录`})}catch(W){P(W instanceof Error?W.message:String(W))}}return n.jsx(Ut,{open:c,onOpenChange:R=>{R||(k&&ie.loginCancel(k),s())},children:n.jsxs(Wt,{className:"sm:max-w-lg",children:[n.jsxs(Gt,{children:[n.jsxs(Vt,{className:"flex items-center gap-2",children:[n.jsx(nl,{className:"text-brand size-4"}),x?`登录 ${x.name}`:"Provider 登录管理 (/login)"]}),n.jsxs(Tn,{className:"text-[11.5px]",children:["凭据与原生 ",n.jsx("code",{className:"pg-num",children:"pi"})," CLI 共享 ",n.jsx("code",{className:"pg-num",children:"~/.pi/agent/auth.json"}),"。"]})]}),T&&n.jsx("p",{className:"text-bad bg-bad/8 border-bad/25 rounded border px-2.5 py-1.5 text-[11px]",children:T}),x?n.jsxs("div",{className:"flex flex-col gap-3",children:[j.map((R,W)=>n.jsx("div",{className:"border-line bg-surface-2/60 rounded-md border p-2.5 text-[11.5px]",children:R.type==="auth_url"?n.jsxs("div",{className:"flex flex-col gap-1",children:[n.jsx("span",{className:"text-muted-foreground",children:R.instructions??"请打开链接完成授权:"}),n.jsx("a",{href:R.url,target:"_blank",rel:"noreferrer",className:"text-brand break-all underline",children:R.url})]}):R.type==="device_code"?n.jsxs("div",{className:"flex flex-col gap-1",children:[n.jsxs("span",{children:["打开 ",n.jsx("a",{href:R.verificationUri,target:"_blank",rel:"noreferrer",className:"text-brand underline",children:R.verificationUri})]}),n.jsx("span",{className:"pg-num font-mono text-[15px] font-bold tracking-wider",children:R.userCode})]}):n.jsx("span",{className:"text-foreground/85",children:R.message})},W)),p?p.type==="select"&&p.options?n.jsxs("div",{className:"flex flex-col gap-1.5",children:[n.jsx("p",{className:"text-[12px] font-medium",children:p.message}),p.options.map(R=>n.jsxs(ke,{variant:"outline",size:"sm",onClick:()=>void z(R.id),className:"justify-start",children:[R.label,R.description&&n.jsx("span",{className:"text-muted-foreground ml-2 text-[10.5px]",children:R.description})]},R.id))]}):n.jsxs("form",{className:"flex flex-col gap-2",onSubmit:R=>{R.preventDefault(),z()},children:[n.jsx("label",{className:"text-[12px] font-medium",children:p.message}),n.jsx(Ke,{autoFocus:!0,type:p.type==="secret"?"password":"text",value:h,onChange:R=>b(R.target.value),placeholder:p.placeholder??"",className:"pg-num font-mono"}),n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx(ke,{type:"button",variant:"ghost",size:"sm",onClick:()=>{k&&ie.loginCancel(k),y(null),v(null)},children:"取消"}),n.jsx(ke,{type:"submit",size:"sm",disabled:N||!h.trim(),className:"bg-brand text-primary-foreground",children:N?n.jsx(at,{className:"size-3.5 animate-spin"}):"确认登录"})]})]}):n.jsxs("div",{className:"text-muted-foreground flex items-center gap-2 py-3 text-[11.5px]",children:[n.jsx(at,{className:"size-4 animate-spin"}),"正在进行认证流程…"]})]}):n.jsxs("div",{className:"flex flex-col gap-2",children:[n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsxs("div",{className:"relative flex-1",children:[n.jsx(Uo,{className:"text-muted-foreground/60 absolute top-1/2 left-2.5 size-3.5 -translate-y-1/2"}),n.jsx(Ke,{autoFocus:!0,value:f,onChange:R=>{u(R.target.value),m(0)},onKeyDown:R=>{R.key==="ArrowDown"?(R.preventDefault(),m(W=>Math.min(K.length-1,W+1))):R.key==="ArrowUp"?(R.preventDefault(),m(W=>Math.max(0,W-1))):R.key==="Enter"&&K[d]?.canLogin&&(R.preventDefault(),A(K[d]))},placeholder:"搜索 provider(如 anthropic, openai…)",className:"pl-8 text-[12px]"})]}),n.jsx(ke,{variant:"outline",size:"sm",onClick:()=>void a(),title:"热重载本地扩展",children:n.jsx(cs,{className:"size-3.5"})})]}),n.jsxs("ul",{className:"border-line pg-scroll-y divide-line max-h-72 divide-y overflow-y-auto rounded-md border",children:[K.map((R,W)=>n.jsxs("li",{className:U("flex items-center gap-2 px-3 py-2 text-[11.5px]",W===d?"bg-surface-2":"hover:bg-surface-2/60"),children:[n.jsxs("button",{type:"button",onClick:()=>R.canLogin&&void A(R),disabled:!R.canLogin,className:"flex min-w-0 flex-1 items-center gap-2 text-left",children:[n.jsx("span",{className:"text-foreground/90 font-medium",children:R.name}),n.jsx("span",{className:"text-muted-foreground/65 pg-num font-mono text-[10.5px]",children:R.id}),R.extension&&n.jsxs("span",{className:"bg-brand/12 text-brand rounded px-1.5 py-px text-[9.5px]",children:["扩展 ",R.extension]}),R.loggedIn&&n.jsxs("span",{className:"text-ok bg-ok/12 ml-auto rounded px-1.5 py-px text-[9.5px] font-medium",children:["已登录 · ",R.modelCount," 模型"]})]}),R.loggedIn&&n.jsx("button",{type:"button",onClick:()=>void M(R),title:"退出登录",className:"text-muted-foreground hover:text-bad rounded p-1 transition-colors",children:n.jsx(td,{className:"size-3.5"})})]},R.id)),K.length===0&&n.jsx("li",{className:"text-muted-foreground px-3 py-4 text-center text-[11px]",children:"没有匹配的 Provider"})]})]})]})})}function zh(){const{activePicker:e,closePicker:t,openPicker:s,activeConvId:r,models:o,setModelOverride:a,notify:l}=Ye(),c=e==="model",f=us(r),[u,d]=i.useState(""),[m,k]=i.useState(0),[v,x]=i.useState(!1),y=o?.models??[],p=i.useMemo(()=>{const h=u.trim().toLowerCase();return h?y.filter(b=>`${b.provider}/${b.id}`.toLowerCase().includes(h)||b.name.toLowerCase().includes(h)):y},[y,u]);i.useEffect(()=>{c&&(d(""),k(0))},[c]);const g=f.data?.agent?.model?.provider??o?.defaultModel?.provider,j=f.data?.agent?.model?.modelId??o?.defaultModel?.modelId;async function C(h){if(!(!r||v)){x(!0);try{(await ie.configure(r,{provider:h.provider,modelId:h.id,setAsDefault:!0})).ok&&(a(r,h.provider,h.id),l({tone:"ok",title:`已切换到 ${h.provider}/${h.id}`,detail:"下一次生成生效"}),t())}catch(b){l({tone:"bad",title:"切换模型失败",detail:b instanceof Error?b.message:String(b)})}finally{x(!1)}}}return n.jsx(Ut,{open:c,onOpenChange:h=>{h||t()},children:n.jsxs(Wt,{className:"sm:max-w-lg",children:[n.jsxs(Gt,{children:[n.jsxs(Vt,{className:"flex items-center gap-2",children:[n.jsx(_o,{className:"text-brand size-4"}),"选择模型 (/model)"]}),n.jsx(Tn,{className:"text-[11.5px]",children:"列出全部已登录 Provider 的可用模型。"})]}),n.jsxs("div",{className:"flex flex-col gap-2",children:[n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsxs("div",{className:"relative flex-1",children:[n.jsx(Uo,{className:"text-muted-foreground/60 absolute top-1/2 left-2.5 size-3.5 -translate-y-1/2"}),n.jsx(Ke,{autoFocus:!0,value:u,onChange:h=>{d(h.target.value),k(0)},onKeyDown:h=>{h.key==="ArrowDown"?(h.preventDefault(),k(b=>Math.min(p.length-1,b+1))):h.key==="ArrowUp"?(h.preventDefault(),k(b=>Math.max(0,b-1))):h.key==="Enter"&&p[m]&&(h.preventDefault(),C(p[m]))},placeholder:"模糊搜索 provider/modelId…",className:"pl-8 text-[12px]"})]}),n.jsx(ke,{variant:"outline",size:"sm",onClick:()=>s("login"),children:"/login"})]}),n.jsxs("ul",{className:"border-line pg-scroll-y divide-line max-h-80 divide-y overflow-y-auto rounded-md border",children:[p.map((h,b)=>{const N=h.provider===g&&h.id===j;return n.jsx("li",{children:n.jsxs("button",{type:"button",onClick:()=>void C(h),className:U("flex w-full items-center gap-2 px-3 py-2 text-left text-[11.5px] transition-colors",b===m?"bg-surface-2":"hover:bg-surface-2/60"),children:[n.jsx("span",{className:"flex size-3.5 shrink-0 items-center justify-center",children:N&&n.jsx(sn,{className:"text-brand size-3.5"})}),n.jsx("span",{className:"min-w-0 flex-1",children:n.jsxs("span",{className:"flex items-center gap-1.5",children:[n.jsxs("span",{className:"text-muted-foreground/75 pg-num font-mono text-[10px]",children:[h.provider,"/"]}),n.jsx("span",{className:U("font-mono font-medium",N?"text-brand":"text-foreground/90"),children:h.id}),h.reasoning&&n.jsx(Bo,{className:"text-muted-foreground/70 size-3"}),h.vision&&n.jsx(sl,{className:"text-muted-foreground/70 size-3"})]})}),n.jsx("span",{className:"text-muted-foreground/60 pg-num shrink-0 text-[10px]",children:ar(h.contextWindow)})]})},`${h.provider}/${h.id}`)}),p.length===0&&n.jsx("li",{className:"text-muted-foreground px-3 py-5 text-center text-[11px]",children:y.length===0?"还没有已登录模型,点右上角 /login 登录一个 Provider。":"没有匹配的模型"})]})]})]})})}function Fh(){const{activePicker:e,closePicker:t,activeConvId:s,models:r,thinkingOverrides:o,setThinkingOverride:a,notify:l}=Ye(),c=e==="thinking",f=us(s),u=f.data?.agent?.model?.modelId,d=f.data?.agent?.model?.provider,m=(r?.models??[]).find(g=>g.id===u&&(!d||g.provider===d)),k=m?.supportedThinkingLevels?.length?m.supportedThinkingLevels:[...Ms],v=(s!==null?o[s]:void 0)??f.data?.agent?.thinkingLevel??"medium",[x,y]=i.useState(0);i.useEffect(()=>{if(c){const g=k.indexOf(v);y(g>=0?g:0)}},[c]);async function p(g){s&&(await ie.configure(s,{thinkingLevel:g}),a(s,g),l({tone:"ok",title:`思考级别已设为 ${g}`}),t())}return n.jsx(Ut,{open:c,onOpenChange:g=>{g||t()},children:n.jsxs(Wt,{className:"sm:max-w-sm",children:[n.jsxs(Gt,{children:[n.jsxs(Vt,{className:"flex items-center gap-2",children:[n.jsx(Wo,{className:"text-brand size-4"}),"思考强度 (/thinking)"]}),n.jsx(Tn,{className:"text-[11.5px]",children:m?`当前模型 ${m.provider}/${m.id} 支持以下档位`:"选择当前会话的思考深度"})]}),n.jsx("ul",{tabIndex:0,autoFocus:!0,onKeyDown:g=>{g.key==="ArrowDown"?(g.preventDefault(),y(j=>Math.min(k.length-1,j+1))):g.key==="ArrowUp"?(g.preventDefault(),y(j=>Math.max(0,j-1))):g.key==="Enter"&&k[x]&&(g.preventDefault(),p(k[x]))},className:"border-line divide-line divide-y rounded-md border outline-none",children:k.map((g,j)=>n.jsx("li",{children:n.jsxs("button",{type:"button",onClick:()=>void p(g),className:U("flex w-full items-center gap-2 px-3 py-2 text-left text-[12px]",j===x?"bg-surface-2":"hover:bg-surface-2/60"),children:[n.jsx("span",{className:"flex size-3.5 items-center justify-center",children:g===v&&n.jsx(sn,{className:"text-brand size-3.5"})}),n.jsx("span",{className:U("font-mono",g===v&&"text-brand font-semibold"),children:g})]})},g))})]})})}function _h(){const{activePicker:e,closePicker:t,conversations:s,openConversation:r,envLabel:o}=Ye(),a=e==="resume",[l,c]=i.useState(""),[f,u]=i.useState(0),d=i.useMemo(()=>[...s].sort((v,x)=>(x.createdAt??0)-(v.createdAt??0)),[s]),m=i.useMemo(()=>{const v=l.trim().toLowerCase();return v?d.filter(x=>`#${x.conversationId}`.includes(v)||x.env.toLowerCase().includes(v)||(x.title??"").toLowerCase().includes(v)||(x.cwd??"").toLowerCase().includes(v)):d},[d,l]);i.useEffect(()=>{a&&(c(""),u(0))},[a]);function k(v,x=!1){r({conversationId:v.conversationId,env:v.env,title:v.title??o(v.env),cwd:v.cwd},{split:x}),t()}return n.jsx(Ut,{open:a,onOpenChange:v=>{v||t()},children:n.jsxs(Wt,{className:"sm:max-w-lg",children:[n.jsxs(Gt,{children:[n.jsx(Vt,{children:"切换 / 恢复会话 (/resume)"}),n.jsx(Tn,{className:"text-[11.5px]",children:"Enter 打开为主会话,右侧按钮可在分屏中并排打开。"})]}),n.jsx(Ke,{autoFocus:!0,value:l,onChange:v=>{c(v.target.value),u(0)},onKeyDown:v=>{v.key==="ArrowDown"?(v.preventDefault(),u(x=>Math.min(m.length-1,x+1))):v.key==="ArrowUp"?(v.preventDefault(),u(x=>Math.max(0,x-1))):v.key==="Enter"&&m[f]&&(v.preventDefault(),k(m[f]))},placeholder:"搜索会话 #id、环境名、标题或目录…",className:"text-[12px]"}),n.jsxs("ul",{className:"border-line pg-scroll-y divide-line max-h-72 divide-y overflow-y-auto rounded-md border",children:[m.map((v,x)=>n.jsxs("li",{className:U("flex items-center gap-2 px-3 py-2 text-[11.5px]",x===f?"bg-surface-2":"hover:bg-surface-2/60"),children:[n.jsxs("button",{type:"button",onClick:()=>k(v),className:"flex min-w-0 flex-1 items-center gap-2 text-left",children:[n.jsxs("span",{className:"pg-num text-muted-foreground/65",children:["#",v.conversationId]}),n.jsx("span",{className:"text-foreground/90 min-w-0 flex-1 truncate font-medium",children:v.title||o(v.env)}),n.jsx("span",{className:"text-muted-foreground pg-num shrink-0 text-[10.5px]",children:o(v.env)})]}),n.jsx("button",{type:"button",onClick:()=>k(v,!0),className:"border-line text-muted-foreground hover:text-brand shrink-0 rounded border px-1.5 py-0.5 text-[10px]",children:"分屏"})]},v.conversationId)),m.length===0&&n.jsx("li",{className:"text-muted-foreground px-3 py-4 text-center text-[11px]",children:"没有匹配会话"})]})]})})}function Lh(){const{bootstrap:e,bootstrapError:t,conversations:s,activeConvId:r,splitConvId:o,backgroundConvIds:a,openConversation:l,closeConversation:c,notify:f,railOpen:u,setRailOpen:d,dockOpen:m,setDockOpen:k,openNewConv:v}=Ye();i.useEffect(()=>{const j=window.innerWidth;j<1180&&k(!1),j<900&&d(!1)},[]);const x=i.useRef(null);i.useEffect(()=>{t&&t!==x.current&&(x.current=t,f({tone:"bad",title:"引导快照失败",detail:t}))},[t,f]);const y=i.useRef(!1);i.useEffect(()=>{if(e){if(r!==null&&!s.some(j=>j.conversationId===r)){c(r);return}if(r===null&&!y.current&&s.length>0){y.current=!0;const j=[...s].sort((C,h)=>(h.createdAt??0)-(C.createdAt??0))[0];l(j)}}},[e,s,r,c,l]),i.useEffect(()=>{const j=C=>{!C.altKey||C.metaKey||C.ctrlKey||(C.key==="n"||C.key==="N")&&(C.preventDefault(),v(null))};return window.addEventListener("keydown",j),()=>window.removeEventListener("keydown",j)},[v]);const p=[...new Set([r,o,...a].filter(j=>j!==null))],g=o!==null&&o!==r?o:null;return n.jsxs("div",{className:"bg-background relative flex h-screen flex-col overflow-hidden",children:[n.jsx("div",{"aria-hidden":!0,className:"pg-noise pointer-events-none absolute inset-0 z-0"}),n.jsxs("div",{className:"relative z-10 flex min-h-0 flex-1",children:[u&&n.jsxs("aside",{className:U("border-line bg-sidebar flex shrink-0 flex-col border-r","w-[224px] xl:w-[264px]"),"aria-label":"环境栏",children:[n.jsx("div",{className:"pg-scroll-y min-h-0 flex-1",children:n.jsx(Ag,{})}),n.jsx($g,{})]}),n.jsxs("main",{className:"relative flex min-w-0 flex-1 flex-col overflow-hidden",children:[!u&&n.jsx("button",{type:"button",onClick:()=>d(!0),title:"展开侧栏","aria-label":"展开侧栏",className:"text-muted-foreground hover:bg-surface-2 hover:text-foreground bg-surface/80 border-line absolute top-2 left-2 z-10 flex size-6 items-center justify-center rounded-md border",children:n.jsx(nd,{className:"size-3.5"})}),n.jsx(Fg,{ids:p}),r!==null?g!==null?n.jsxs("div",{className:"divide-line grid min-h-0 flex-1 grid-cols-1 divide-y lg:grid-cols-2 lg:divide-x lg:divide-y-0",children:[n.jsx(yo,{conversationId:r},r),n.jsx(yo,{conversationId:g,isSplit:!0},g)]}):n.jsx(yo,{conversationId:r},r):n.jsx(Dg,{})]}),n.jsx($h,{})]}),n.jsx(Pm,{}),n.jsx(Mm,{}),n.jsx(Hm,{}),n.jsx(Gm,{}),n.jsx(Vm,{}),n.jsx(Dh,{}),n.jsx(zh,{}),n.jsx(Fh,{}),n.jsx(_h,{}),n.jsx(qm,{}),!m&&!u&&n.jsx("span",{className:"text-muted-foreground/40 pointer-events-none fixed bottom-2 left-1/2 z-20 -translate-x-1/2 text-[10px]",children:"Alt+1 文件面板 · Alt+N 新建会话"})]})}function Bh(){return n.jsx(sd,{children:n.jsx(ud,{children:n.jsx(Lh,{})})})}_c();document.documentElement.lang="zh-CN";const ru=document.getElementById("root");if(!ru)throw new Error("找不到 #root 挂载点");iu.createRoot(ru).render(n.jsx(i.StrictMode,{children:n.jsx(Bh,{})}));
35
+ //# sourceMappingURL=index-C32JOM8D.js.map