claude-simple 0.2.14 → 0.2.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/addon-fit.min.js +0 -0
- package/dist/app.0.2.16.min.js +1101 -0
- package/dist/index.html +2 -2
- package/dist/style.0.2.16.min.css +1618 -0
- package/dist/xterm.min.css +0 -0
- package/dist/xterm.min.js +0 -0
- package/package.json +1 -1
- package/public/index.html +2 -2
- package/public/mermaid.js +18 -2
- package/public/shell/session-nav.js +4 -0
- package/public/sw.js +3 -3
- package/dist/app.0.2.9.min.js +0 -1084
- package/dist/style.0.2.9.min.css +0 -1598
|
@@ -0,0 +1,1101 @@
|
|
|
1
|
+
var _r=Object.defineProperty;var K=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(s){throw n=[s],s}};var as=(e,t)=>{for(var n in t)_r(e,n,{get:t[n],enumerable:!0})};function Hr(){da||(da=!0,queueMicrotask(()=>{da=!1,fa()}))}function xo(e){for(let t of e)(t._isComputed?Gt:Kt).add(t);pa>0||os||(Pr==="microtask"?Hr():fa())}function yo(e,t,n,s){let a=new Set(n);for(let r of n)r._subs.delete(t);n.clear(),s?.forEach(r=>r?.()),s?.splice(0);let o=[wt,En,la];[wt,En,la]=[t,n,s];try{return e()}catch(r){for(let d of a)d._subs.add(t),n.add(d);throw r}finally{[wt,En,la]=o}}var wt,En,pa,la,Gt,Kt,os,Sn,ca,Pr,da,fa,vo,$,ma,Ce,ae,Le,Tn,Rr,p,g,wo,i,ua,Br,He,Ln,Or,is,qr,Lc,ko,Ec,Tc,$o,So=K(()=>{wt=null,En=null,pa=0,la=null,Gt=new Set,Kt=new Set,os=!1,Sn=1e4,ca={flushes:0,runs:0,lastFlushRuns:0},Pr="sync",da=!1;fa=()=>{if(os)return;os=!0;let e=0;ca.flushes++;try{for(;Gt.size||Kt.size;){for(;Gt.size;){let t=Gt.values().next().value;if(Gt.delete(t),++e>Sn)throw new Error(`mini-react: reactive update loop exceeded ${Sn} runs`);t()}if(Kt.size){let t=Kt.values().next().value;if(Kt.delete(t),++e>Sn)throw new Error(`mini-react: reactive update loop exceeded ${Sn} runs`);t()}}}finally{ca.runs+=e,ca.lastFlushRuns=e,e>Sn&&(Gt.clear(),Kt.clear()),os=!1}};vo=class{constructor(e,t){this._v=e,this._subs=new Set,this._eq=t??((n,s)=>n===s)}get value(){return wt&&(this._subs.add(wt),En?.add(this)),this._v}set value(e){this._eq(e,this._v)||(this._v=e,xo(this._subs))}peek(){return this._v}},$=(e,{equals:t}={})=>new vo(e,t);ma=e=>{let t=new vo(void 0),n=new Set,s=!0,a=!1,o=l=>{if(!s||a)return t._v;s=!1;try{let c=yo(e,r,n,null),u=c!==t._v;u&&(t._v=c),u&&l&&xo(t._subs)}catch(c){s=!0,console.error("[computed]",c)}return t._v},r=()=>{s||a||(s=!0,t._subs.size&&o(!0))};r._isComputed=!0;let d=()=>o(!1);return Object.defineProperty(t,"value",{get(){return wt&&(t._subs.add(wt),En?.add(t)),d()},set(){throw new TypeError("Cannot assign to a computed signal")}}),t.dispose=()=>{if(!a){a=!0;for(let l of n)l._subs.delete(r);n.clear()}},t},Ce=e=>{let t=new Set,n=[],s=()=>{try{let a=yo(e,s,t,n);typeof a=="function"&&n.push(a)}catch(a){console.error("[effect]",a)}};return s(),()=>{for(let a of t)a._subs.delete(s);t.clear(),n.forEach(a=>a?.()),n.splice(0)}},ae=e=>{pa++;try{e()}finally{--pa===0&&fa()}},Le=(e,t)=>{let n=e.peek(),s=!1;return Ce(()=>{let a=e.value;s&&t(a,n),s=!0,n=a})},Tn=e=>Ce(()=>{let t=new AbortController;return Promise.resolve(e(t.signal)).catch(n=>{n?.name!=="AbortError"&&console.error("[asyncEffect]",n)}),()=>t.abort()}),Rr={"&":"&","<":"<",">":">",'"':"""},p=e=>String(e??"").replace(/[&<>"]/g,t=>Rr[t]),g=(()=>{let e=new Map,t=n=>{e.has(n)||(e.set(n,[]),document.addEventListener(n,s=>{ae(()=>{for(let[a,o]of e.get(n)){let r=s.target.closest(a);r&&o(s,r)}})},{capture:!0}))};return{on:(n,s,a)=>{t(n);let o=[s,a];return e.get(n).push(o),()=>e.set(n,e.get(n).filter(r=>r!==o))},off:(n,s)=>{e.has(n)&&e.set(n,e.get(n).filter(([a])=>a!==s))}}})(),wo=(e,{keepAlive:t=!1}={})=>{let n=$(location.hash.slice(1)||"/"),s=!1,a=()=>{n.value=location.hash.slice(1)||"/"};window.addEventListener("hashchange",a);let o=t?new Map:null,r=(c,u)=>{if(!t)return u();if(o.has(c))return o.get(c);let h=u();return o.set(c,h),h},d=$(void 0),l=Ce(()=>{let c=n.value;for(let[u,h]of Object.entries(e)){if(u==="*")continue;let x=new RegExp("^"+u.replace(/:\w+/g,"([^/]+)")+"$"),v=c.match(x);if(v){let C=v.slice(1);d.value=typeof h=="function"?r(`${u}|${C.join("/")}`,()=>h(...C)):h;return}}if(e["*"]){let u=e["*"];d.value=typeof u=="function"?r("*",u):u;return}d.value=null});return{current:n,route:d,navigate:c=>{s||(location.hash=c)},match:c=>{let u=n.value.match(new RegExp("^"+c.replace(/:\w+/g,"([^/]+)")+"$"));return u?u.slice(1):null},invalidate:c=>{if(o){if(c===void 0){o.clear();return}for(let u of[...o.keys()])(u===c||u.startsWith(`${c}|`))&&o.delete(u)}},dispose:()=>{s||(s=!0,window.removeEventListener("hashchange",a),l(),o?.clear())}}},i=e=>document.getElementById(e),ua=()=>typeof navigator>"u"||navigator.onLine!==!1,Br=e=>new Promise(t=>setTimeout(t,e)),He=e=>e===void 0?"undefined":e===null||typeof e!="object"?JSON.stringify(e):e instanceof Date?`Date(${e.toJSON()})`:Array.isArray(e)?`[${e.map(He).join(",")}]`:`{${Object.keys(e).sort().map(t=>`${JSON.stringify(t)}:${He(e[t])}`).join(",")}}`,Ln=(e,t)=>{if(!t)return!0;if(typeof t=="function")return t(e);if(t.queryKey){let n=He(t.queryKey);if(t.exact?e.hash!==n:!e.hash.startsWith(n.slice(0,-1)))return!1}return!t.tags||t.tags.some(n=>e.tags.has(n))},Or=e=>{try{return JSON.stringify(e),!0}catch{return!1}},is=(e,t)=>{if(Object.is(e,t))return e;if(!e||!t||typeof e!="object"||typeof t!="object")return t;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return t;let a=t.map((o,r)=>is(e[r],o));return a.every((o,r)=>o===e[r])?e:a}if(Array.isArray(e)||Array.isArray(t)||Object.getPrototypeOf(e)!==Object.prototype||Object.getPrototypeOf(t)!==Object.prototype)return t;let n=Object.keys(t);if(n.length!==Object.keys(e).length)return t;let s={};for(let a of n){if(!(a in e))return t;s[a]=is(e[a],t[a])}return n.every(a=>s[a]===e[a])?e:s},qr=({staleTime:e=3e4,gcTime:t=3e5,retry:n=2,retryDelay:s=1e3,refetchOnWindowFocus:a=!1,refetchOnReconnect:o=!0}={})=>{let r=new Map,d=new Set,l=new Map,c=null,u=!1,h=m=>{for(let b of d)b(m)},x=m=>m.state,v=m=>!m.invalidated&&Date.now()-m.state.updatedAt.peek()<m.options.staleTime,C=m=>{m.invalidated=!0,m.state.isStale.value=!0},F=m=>{m.gcTimer&&clearTimeout(m.gcTimer),m.gcTimer=null},ke=m=>{F(m),!m.observers&&Number.isFinite(m.options.gcTime)&&(m.gcTimer=setTimeout(()=>{!m.observers&&!m.promise&&(r.delete(m.hash),h({type:"gc",key:m.key}))},m.options.gcTime))},J=m=>{m.pollTimer&&clearTimeout(m.pollTimer),m.pollTimer=null},ne=m=>{J(m);let b=typeof m.options.refetchInterval=="function"?m.options.refetchInterval(m):m.options.refetchInterval;m.observers&&Number.isFinite(b)&&b>0&&(m.pollTimer=setTimeout(async()=>{ua()&&await _(m,{force:!0}).catch(()=>{}),ne(m)},b))},N=(m,b=He(m.queryKey))=>{let w={staleTime:e,gcTime:t,retry:n,retryDelay:s,...m},k={hash:b,key:m.queryKey,queryFn:m.queryFn,options:w,tags:new Set(m.tags??[]),observers:0,invalidated:!0,promise:null,ctrl:null,version:0,gcTimer:null,pollTimer:null,state:{data:$(m.initialData),error:$(null),status:$(m.initialData===void 0?"idle":"success"),fetchStatus:$("idle"),updatedAt:$(m.initialData===void 0?0:Date.now()),isStale:$(!0)}};return r.set(b,k),k},S=m=>{if(!m?.queryKey)throw new TypeError("query: queryKey is required");let b=He(m.queryKey),w=r.get(b)??N(m,b);m.queryFn&&(w.queryFn=m.queryFn),w.options={...w.options,...m};for(let k of m.tags??[])w.tags.add(k);return w},_=(m,{force:b=!1}={})=>{if(!m.queryFn)return Promise.reject(new TypeError(`query ${m.hash} has no queryFn`));if(!b&&v(m))return Promise.resolve(m.state.data.peek());if(m.promise)return m.promise;if(!ua())return m.state.fetchStatus.value="paused",Promise.reject(new Error("Query paused while offline"));F(m);let w=++m.version,k=new AbortController;m.ctrl=k,ae(()=>{m.state.data.peek()===void 0&&(m.state.status.value="pending"),m.state.fetchStatus.value="fetching",m.state.error.value=null}),h({type:"fetch",key:m.key});let W=async(D,G)=>{try{return await m.queryFn({queryKey:m.key,signal:k.signal,meta:m.options.meta})}catch(X){if(k.signal.aborted||X?.name==="AbortError"||D<=0||m.options.retry===!1)throw X;return await Br(typeof G=="function"?G(D,X):G),W(D-1,typeof G=="number"?G*2:G)}},Y=W(m.options.retry??n,m.options.retryDelay??s).then(D=>(m.version===w&&!k.signal.aborted&&ae(()=>{m.state.data.value=m.options.structuralSharing===!1?D:is(m.state.data.peek(),D),m.state.status.value="success",m.state.fetchStatus.value="idle",m.state.updatedAt.value=Date.now(),m.state.isStale.value=!1,m.invalidated=!1}),h({type:"success",key:m.key}),D)).catch(D=>{throw m.version===w&&!k.signal.aborted&&ae(()=>{m.state.error.value=D,m.state.status.value=m.state.data.peek()===void 0?"error":"success",m.state.fetchStatus.value="idle"}),k.signal.aborted||h({type:"error",key:m.key,error:D}),D}).finally(()=>{m.promise===Y&&(m.promise=null,m.ctrl=null,ke(m))});return m.promise=Y,Y},se=m=>Promise.all([...r.values()].filter(b=>Ln(b,m)&&b.observers).map(b=>_(b,{force:!0}).catch(()=>{}))),M={query(m){let b=S(m);b.observers++,F(b),ne(b),m.enabled!==!1&&(!v(b)||m.refetchOnMount)&&_(b).catch(()=>{});let w=()=>{b.observers=Math.max(0,b.observers-1),ke(b),ne(b)};return[x(b),{refetch:()=>_(b,{force:!0}),invalidate:()=>M.invalidateQueries({queryKey:b.key,exact:!0}),setData:k=>M.setQueryData(b.key,k),cancel:()=>M.cancelQueries({queryKey:b.key,exact:!0}),dispose:w}]},prefetchQuery(m){let b=S(m);return _(b)},fetchQuery(m){let b=S(m);return _(b)},getQueryData(m){return r.get(He(m))?.state.data.peek()},getQueryState(m){let b=r.get(He(m));return b&&x(b)},setQueryData(m,b,{tags:w}={}){let k=r.get(He(m))??S({queryKey:m,tags:w}),W=typeof b=="function"?b(k.state.data.peek()):b,Y=k.options.structuralSharing===!1?W:is(k.state.data.peek(),W);ae(()=>{k.state.data.value=Y,k.state.status.value="success",k.state.error.value=null,k.state.updatedAt.value=Date.now(),k.state.isStale.value=!1}),k.invalidated=!1;for(let D of w??[])k.tags.add(D);return h({type:"set",key:k.key}),c&&c.postMessage({type:"invalidate",hash:k.hash}),Y},invalidateQueries(m){for(let b of r.values())Ln(b,m)&&C(b);return h({type:"invalidate",filter:m}),c&&c.postMessage({type:"invalidate",filter:m}),se(m)},cancelQueries(m){for(let b of r.values())Ln(b,m)&&b.ctrl?.abort()},removeQueries(m){for(let b of[...r.values()])Ln(b,m)&&(b.ctrl?.abort(),F(b),J(b),r.delete(b.hash))},mutate({mutationFn:m,variables:b,optimistic:w,invalidate:k,onMutate:W,onSuccess:Y,onError:D,networkMode:G="online"}={}){if(typeof m!="function")return Promise.reject(new TypeError("mutate: mutationFn is required"));let X=[],yt=Wt=>(Array.isArray(Wt)?Wt:[Wt]).filter(Boolean).forEach(Ie=>{let ia=M.getQueryData(Ie.queryKey);X.push([Ie.queryKey,ia]),M.setQueryData(Ie.queryKey,ra=>Ie.updater(ra))}),$n=async()=>{let Wt=await W?.(b,{client:M});w&&yt(typeof w=="function"?w(b):w);try{let Ie=await m(b);return await Y?.(Ie,b,Wt),k&&await M.invalidateQueries(k),h({type:"mutation-success"}),Ie}catch(Ie){for(let[ia,ra]of X)M.setQueryData(ia,ra);throw await D?.(Ie,b,Wt),h({type:"mutation-error",error:Ie}),Ie}};return!ua()&&G==="offlineFirst"?(V.push($n),h({type:"mutation-queued"}),Promise.resolve({queued:!0})):$n()},infiniteQuery({queryKey:m,queryFn:b,initialPageParam:w=0,getNextPageParam:k,...W}){let[Y,D]=M.query({queryKey:m,...W,queryFn:async G=>({pages:[await b({...G,pageParam:w})],pageParams:[w]})});return[Y,{...D,fetchNextPage:async()=>{let G=Y.data.peek()??{pages:[],pageParams:[]},X=k?.(G.pages.at(-1),G.pages);if(X==null)return;let yt=await b({queryKey:m,pageParam:X,signal:new AbortController().signal});return M.setQueryData(m,{pages:[...G.pages,yt],pageParams:[...G.pageParams,X]}),yt}}]},dehydrate({shouldDehydrate:m=w=>w.state.status.peek()==="success",version:b=1}={}){return{version:b,timestamp:Date.now(),queries:[...r.values()].filter(m).filter(w=>Or(w.state.data.peek())).map(w=>({key:w.key,data:w.state.data.peek(),updatedAt:w.state.updatedAt.peek(),staleTime:w.options.staleTime,tags:[...w.tags]}))}},hydrate(m,{version:b=1}={}){if(!m||m.version!==b||!Array.isArray(m.queries))return!1;for(let w of m.queries){let k=r.get(He(w.key))??S({queryKey:w.key,staleTime:w.staleTime,tags:w.tags});ae(()=>{k.state.data.value=w.data,k.state.status.value="success",k.state.updatedAt.value=w.updatedAt,k.state.isStale.value=Date.now()-w.updatedAt>=k.options.staleTime}),k.invalidated=k.state.isStale.peek()}return h({type:"hydrate"}),!0},persist({storage:m=typeof localStorage>"u"?null:localStorage,key:b="mini-react-query",version:w=1}={}){if(!m)throw new Error("persist: a storage adapter is required");let k=!1,W=async()=>{let D=JSON.stringify(M.dehydrate({version:w}));return m.set?m.set(b,D):m.setItem(b,D)},Y=M.subscribe(()=>{k||(k=!0,queueMicrotask(()=>{k=!1,W().catch(()=>{})}))});return{restore:async()=>{let D=await(m.get?m.get(b):m.getItem(b));return D?M.hydrate(JSON.parse(D),{version:w}):!1},save:W,dispose:Y}},sync(m="mini-react-query"){return typeof BroadcastChannel>"u"?()=>{}:(c?.close(),c=new BroadcastChannel(m),c.onmessage=b=>{if(b.data?.type!=="invalidate")return;let w=b.data.hash?k=>k.hash===b.data.hash:b.data.filter;for(let k of r.values())Ln(k,w)&&C(k);se(w)},()=>{c?.close(),c=null})},subscribe(m){return d.add(m),()=>d.delete(m)},getDebugSnapshot(){return[...r.values()].map(m=>({key:m.key,observers:m.observers,status:m.state.status.peek(),fetchStatus:m.state.fetchStatus.peek(),updatedAt:m.state.updatedAt.peek(),stale:m.state.isStale.peek(),tags:[...m.tags]}))},async fetchJSON(m,b={},{queryKey:w=["GET",m,b.body??null],...k}={}){let W=He(w);return M.fetchQuery({queryKey:w,...k,queryFn:async({signal:Y})=>{let D=new Headers(b.headers),G=l.get(W);G?.etag&&D.set("If-None-Match",G.etag);let X=await fetch(m,{...b,headers:D,signal:Y});if(X.status===304&&G)return M.getQueryData(w);if(!X.ok)throw new Error(`HTTP ${X.status}`);let yt=X.headers.get("cache-control")?.match(/max-age=(\d+)/)?.[1];if(yt){let $n=r.get(W);$n&&($n.options.staleTime=Number(yt)*1e3)}return l.set(W,{etag:X.headers.get("etag")}),X.json()}})},destroy(){u=!0;for(let m of r.values())m.ctrl?.abort(),F(m),J(m);c?.close(),d.clear()}},V=[],rt=()=>{a&&se()},xt=()=>{for(o&&se();V.length;)V.shift()().catch(()=>{})};typeof window<"u"&&(window.addEventListener("focus",rt),window.addEventListener("online",xt));let vt=M.destroy;return M.destroy=()=>{u||(typeof window<"u"&&(window.removeEventListener("focus",rt),window.removeEventListener("online",xt)),vt())},M},Lc=qr(),ko=({cache:e=!0,ttl:t=3e4,retry:n=2,retryDelay:s=1e3,store:a=null,dedupe:o=!0}={})=>{let r=new Map,d=new Map,l=new Map,c=(h,x)=>{if(a)return a.get(h);let v=r.get(h);return v&&Date.now()-v.ts<x?v.data:void 0},u=async(h,x,v)=>{if(a)return a.set(h,x,{ttl:v});r.set(h,{data:x,ts:Date.now()})};return{get:(h,x,v={})=>{let C=v.ttl??t,F=e&&v.cache!==!1&&C!==0,ke=v.dedupe??o;if(ke&&d.has(h))return d.get(h);let J=()=>{let N=l.get(h)??0,S=(_,se)=>Promise.resolve(x()).then(async M=>(F&&(l.get(h)??0)===N&&await u(h,M,C),M)).catch(M=>{if(_>0&&M?.name!=="AbortError")return new Promise(V=>setTimeout(V,se)).then(()=>S(_-1,se*2));throw M});return S(v.retry??n,s)},ne=N=>(ke&&(d.set(h,N),N.finally(()=>{d.get(h)===N&&d.delete(h)}).catch(()=>{})),N);if(!F)return ne(J());if(!a){let N=c(h,C);return N!==void 0?Promise.resolve(N):ne(J())}return ne(Promise.resolve(c(h,C)).then(N=>N!==void 0?N:J()))},invalidate:h=>{if(h!==void 0)l.set(h,(l.get(h)??0)+1);else{for(let x of r.keys())l.set(x,(l.get(x)??0)+1);for(let x of d.keys())l.set(x,(l.get(x)??0)+1)}if(a)return h===void 0?a.clear():a.delete(h);h===void 0?r.clear():r.delete(h)}}},Ec=new TextEncoder,Tc=new TextDecoder,$o=(e,t="kv")=>{let n=null,s=()=>n?Promise.resolve(n):new Promise((o,r)=>{let d=indexedDB.open(e,1);d.onupgradeneeded=l=>l.target.result.createObjectStore(t),d.onsuccess=l=>{n=l.target.result,o(n)},d.onerror=l=>r(l.target.error)}),a=async(o,r)=>{let d=await s();return new Promise((l,c)=>{let u=d.transaction(t,o),h=r(u.objectStore(t));h.onsuccess=()=>l(h.result),h.onerror=()=>c(h.error)})};return{async get(o){let r=await a("readonly",d=>d.get(o));if(r){if(r.expires&&Date.now()>r.expires){this.delete(o);return}return r.val}},async set(o,r,{ttl:d}={}){await a("readwrite",l=>l.put({val:r,expires:d?Date.now()+d:null},o))},delete:o=>a("readwrite",r=>r.delete(o)),clear:()=>a("readwrite",o=>o.clear()),keys:()=>a("readonly",o=>o.getAllKeys())}}});var R=K(()=>{So()});var Do={};as(Do,{AGENT_DEFAULT_MODEL:()=>Co,AGENT_LABELS:()=>te,AGENT_MODELS:()=>ha,LOW_TURN_THRESHOLD:()=>ga,activityHits:()=>Re,activityLoading:()=>Qe,addCustomModel:()=>Mn,agentFilter:()=>de,agentFilters:()=>$t,agentsMeta:()=>kt,chatDensity:()=>Ve,collapsedFolders:()=>Jt,ctx:()=>f,currentAgent:()=>I,currentEffort:()=>ie,currentModel:()=>P,currentPermission:()=>Ee,currentProject:()=>E,currentTab:()=>U,expandedFolders:()=>zt,favoritesOnly:()=>Ae,filesPath:()=>z,filesRoot:()=>ce,filteredSessions:()=>ct,getCustomModels:()=>ls,getDefaultEffort:()=>lt,getDefaultModel:()=>Oe,getEffortsForModel:()=>In,getModelsForAgent:()=>Xe,getSavedModel:()=>Io,getSessionMeta:()=>Qt,gitRoot:()=>be,hubMachineReady:()=>Be,hubMode:()=>A,isProcessing:()=>he,machinesList:()=>Q,metaKey:()=>oe,projectGroups:()=>St,removeCustomModel:()=>ya,selectedMachineId:()=>j,sessionDisplayTitle:()=>Ye,sessionFilter:()=>fe,sessionMetaMap:()=>T,sessionSearch:()=>me,sessionSort:()=>Lo,sessionsData:()=>B,setAgent:()=>qe,setChatDensity:()=>xa,setCurrentModel:()=>le,setSelectedMachine:()=>ge,showHiddenOnly:()=>je,sidebarView:()=>Je,timeRange:()=>rs,viewingFile:()=>re,workspacesData:()=>ee,wsStatus:()=>ze});function To(){try{let e=JSON.parse(localStorage.getItem(Eo)||"{}");return e&&typeof e=="object"?e:{}}catch{return{}}}function Mo(e,t=f.sessionId,n=f.machineId){if(!t)return"";let s=(e||"claude").toLowerCase();return`${n||""}:${s}:${t}`}function Io(e,t=f.sessionId,n=f.machineId){let s=Mo(e,t,n);if(!s)return null;let a=To()[s];return typeof a=="string"&&a.trim()?a:null}function le(e,t=I.peek(),n=f.sessionId,s=f.machineId){let a=String(e||"").trim();if(!a)return;let o=Mo(t,n,s);if(o){let r=To();r[o]=a,localStorage.setItem(Eo,JSON.stringify(r))}P.value=a}function ge(e){let t=e||null;j.value=t,f.machineId=t,t?localStorage.setItem("machineId",t):localStorage.removeItem("machineId")}function oe(e,t,n){let s=`${e||"claude"}:${t}`;return n||f?.machineId?`${n||f.machineId}:${s}`:s}function Qt(e,t,n){return T.peek()?.[oe(e,t,n)]||{favorite:!1,notes:"",title:"",hidden:!1}}function Ye(e,{preferSnippet:t=!1}={}){if(!e)return"Session";if(t&&e.snippet)return e.snippet;let s=(Qt(e.agent,e.sessionId,e.machineId).title||"").trim();return s||e.display||e.sessionId?.slice(0,8)||"Session"}function xa(e){let t=["clean","normal","full"].includes(e)?e:"normal";Ve.value=t,localStorage.setItem("chatDensity",t),document.getElementById("messages")?.setAttribute("data-density",t)}function Ur(e){return e?typeof e=="string"?{value:e,label:e}:e.value?{value:String(e.value),label:e.label||e.value,...Array.isArray(e.efforts)&&e.efforts.length?{efforts:e.efforts.map(String)}:{},...e.defaultEffort?{defaultEffort:String(e.defaultEffort)}:{}}:null:null}function va(){try{let e=localStorage.getItem(Ao);if(!e)return{};let t=JSON.parse(e);return t&&typeof t=="object"?t:{}}catch{return{}}}function jo(e){localStorage.setItem(Ao,JSON.stringify(e))}function ls(e){let t=(e||"claude").toLowerCase(),n=va()[t];return Array.isArray(n)?n.filter(Boolean).map(String):[]}function Mn(e,t){let n=(e||"claude").toLowerCase(),s=String(t||"").trim();if(!s)return!1;let a=va(),o=Array.isArray(a[n])?[...a[n]]:[];return o.includes(s)||o.push(s),a[n]=o,jo(a),!0}function ya(e,t){let n=(e||"claude").toLowerCase(),s=String(t||"").trim(),a=va(),o=Array.isArray(a[n])?a[n].filter(r=>r!==s):[];return a[n]=o,jo(a),!0}function Xe(e){let t=(e||"claude").toLowerCase(),n=kt.peek()?.defaults?.[t],s=n?.models?.length?n.models.map(Ur).filter(Boolean):(ha[t]||ha.claude).map(r=>({...r})),a=ls(t),o=new Set(s.map(r=>r.value));for(let r of a){if(o.has(r)){s=s.map(d=>{if(d.value!==r)return d;let l=String(d.label||d.value);return{...d,custom:!0,label:l.includes("\u2605")?l:`${l} \u2605`}});continue}o.add(r),s.push({value:r,label:`${r} \u2605`,custom:!0})}return s}function Oe(e){let t=(e||"claude").toLowerCase(),n=kt.peek()?.defaults?.[t];return n?.model?String(n.model):Co[t]||Xe(t)[0]?.value||"claude-sonnet-4-5"}function In(e,t){let s=Xe(e).find(o=>o.value===t);if(s?.efforts?.length)return s.efforts;let a=kt.peek()?.defaults?.[(e||"claude").toLowerCase()];return a?.efforts?.length?a.efforts.map(String):["low","medium","high","xhigh","max"]}function lt(e,t){let n=(e||"claude").toLowerCase(),s=kt.peek()?.defaults?.[n];if(s?.effortDefault)return String(s.effortDefault);let o=Xe(n).find(r=>r.value===t);return o?.defaultEffort?String(o.defaultEffort):n==="grok"?"low":n==="gemini"&&String(t||"").match(/-(low|medium|high)$/i)?.[1]?.toLowerCase()||""}function qe(e){let t=(e||"claude").toLowerCase();I.value=t,localStorage.setItem("agent",t),Ee.value="bypassPermissions";let n=typeof document>"u"?null:document.getElementById("sel-permission");n&&(n.value=Ee.peek());let s=Io(t);s?P.value=s:le(Oe(t),t);let a=lt(t,P.peek());a?ie.value=a:t!=="grok"&&t!=="gemini"&&(ie.value="")}function Wr(e,t){return!t||t==="all"?!0:(e.agent||"claude")===t}function Gr(e,t){if(!t)return!0;let n=T.value?.[oe(e.agent,e.sessionId,e.machineId)];return[e.display,e.cwd,e.projectName,e.agent,e.sessionId,e.snippet,e.machineId,n?.notes,n?.title].filter(Boolean).join(" ").toLowerCase().includes(t)}function ba(e){return Array.isArray(e)?e:e&&Array.isArray(e.results)?e.results:e&&Array.isArray(e.sessions)?e.sessions:[]}var B,ee,fe,me,Lo,zt,Jt,z,re,E,U,he,ze,Eo,Fr,I,P,ie,Ee,ce,be,kt,Je,de,$t,rs,Re,Qe,T,Ae,je,ga,Ve,A,Q,j,Be,f,te,ha,Co,Ao,ct,St,O=K(()=>{R();B=$([]),ee=$([]),fe=$(null),me=$(""),Lo=$("time"),zt=$(new Set),Jt=$(new Set),z=$(""),re=$(null),E=$(null),U=$("chat"),he=$(!1),ze=$("idle"),Eo="modelBySession",Fr=localStorage.getItem("agent")||"claude";I=$(Fr),P=$("claude-sonnet-4-5"),ie=$(""),Ee=$("bypassPermissions"),ce=$(""),be=$(""),kt=$(null),Je=$(localStorage.getItem("sidebarView")||"projects"),de=$(localStorage.getItem("agentFilter")||"all"),$t=$((()=>{try{let e=JSON.parse(localStorage.getItem("agentFilters")||"[]");return Array.isArray(e)?e.filter(Boolean):[]}catch{return[]}})()),rs=$(localStorage.getItem("timeRange")||"14"),Re=$(null),Qe=$(!1),T=$({}),Ae=$(localStorage.getItem("favoritesOnly")==="1"),je=$(localStorage.getItem("showHiddenOnly")==="1"),ga=2,Ve=$(localStorage.getItem("chatDensity")||"normal"),A=$(!1),Q=$([]),j=$(null),Be=$(!1),f={token:localStorage.getItem("token"),sessionId:null,agent:null,machineId:null,ws:null,shellBubble:null,configDir:null};te={claude:"Claude",codex:"Codex",grok:"Grok",gemini:"Gemini",cursor:"Cursor"},ha={claude:[{value:"claude-sonnet-4-5",label:"sonnet-4-5"},{value:"claude-sonnet-4-6",label:"sonnet-4-6"},{value:"claude-opus-4-5",label:"opus-4-5"},{value:"claude-haiku-4-5",label:"haiku-4-5"}],codex:[{value:"gpt-5.4",label:"gpt-5.4"},{value:"gpt-5.3",label:"gpt-5.3"},{value:"gpt-5.2",label:"gpt-5.2"},{value:"o3",label:"o3"},{value:"o4-mini",label:"o4-mini"},{value:"codex-mini-latest",label:"codex-mini"}],grok:[{value:"grok-4.5",label:"grok-4.5"},{value:"grok-4",label:"grok-4"},{value:"grok-3",label:"grok-3"},{value:"grok-3-mini",label:"grok-3-mini"}],gemini:[{value:"gemini-3.7-flash-high",label:"Gemini 3.7 Flash (High)"},{value:"gemini-3.7-flash-medium",label:"Gemini 3.7 Flash (Medium)"},{value:"gemini-3.7-flash-low",label:"Gemini 3.7 Flash (Low)"},{value:"gemini-3.6-flash-high",label:"Gemini 3.6 Flash (High)"},{value:"gemini-3.6-flash-medium",label:"Gemini 3.6 Flash (Medium)"},{value:"gemini-3.6-flash-low",label:"Gemini 3.6 Flash (Low)"},{value:"gemini-3.5-flash-high",label:"Gemini 3.5 Flash (High)"},{value:"gemini-3.5-flash-medium",label:"Gemini 3.5 Flash (Medium)"},{value:"gemini-3.5-flash-low",label:"Gemini 3.5 Flash (Low)"},{value:"gemini-3.1-pro-high",label:"Gemini 3.1 Pro (High)"},{value:"gemini-3.1-pro-low",label:"Gemini 3.1 Pro (Low)"}],cursor:[{value:"auto",label:"Auto"},{value:"gpt-5.3-codex",label:"GPT-5.3 Codex"},{value:"composer-2.5",label:"Composer 2.5"}]},Co={claude:"claude-sonnet-4-5",codex:"gpt-5.4",grok:"grok-4.5",gemini:"gemini-3.7-flash-high",cursor:"auto"};Ao="customModelsByAgent";ct=ma(()=>{let e=me.value.toLowerCase().trim(),t=Lo.value,n=de.value,s=$t.value,a=Ae.value,o=je.value,r=T.value,d=Re.value,l=d?.results?.length&&e?ba(d.results):ba(B.value),c=j.value;return A.value&&c&&(l=l.filter(u=>u&&(!u.machineId||u.machineId===c))),l=l.filter(u=>u&&(s.length?s.includes(u.agent||"claude"):Wr(u,n))),o?l=l.filter(u=>u&&r?.[oe(u.agent,u.sessionId,u.machineId)]?.hidden):l=l.filter(u=>u&&!r?.[oe(u.agent,u.sessionId,u.machineId)]?.hidden),a&&(l=l.filter(u=>u&&r?.[oe(u.agent,u.sessionId,u.machineId)]?.favorite)),e&&!(d?.results&&d.q===e)&&(l=l.filter(u=>u&&Gr(u,e))),l=[...l].sort((u,h)=>{let x=r?.[oe(u.agent,u.sessionId,u.machineId)]?.favorite?1:0,v=r?.[oe(h.agent,h.sessionId,h.machineId)]?.favorite?1:0;return x!==v?v-x:t==="project"&&(u.cwd||"").localeCompare(h.cwd||"")||h.updatedAt-u.updatedAt}),!e&&!a?l.slice(0,120):l}),St=ma(()=>{let e=ba(ct.value),t=new Map;for(let n of e){if(!n)continue;let s=n.machineId?`${n.machineId}::${n.cwd||"(no path)"}`:n.cwd||"(no path)";t.has(s)||t.set(s,{cwd:n.cwd||null,machineId:n.machineId||null,projectName:n.projectName||(n.cwd?n.cwd.split("/").filter(Boolean).pop():"(no path)"),updatedAt:0,agents:{},sessions:[],latest:null});let a=t.get(s);a.sessions.push(n),a.agents[n.agent||"claude"]=(a.agents[n.agent||"claude"]||0)+1,(n.updatedAt||0)>a.updatedAt&&(a.updatedAt=n.updatedAt,a.latest=n)}return[...t.values()].sort((n,s)=>s.updatedAt-n.updatedAt)})});function Cn(e={}){return e.machineId!==void 0?e.machineId:f.machineId||j.peek()||null}function zr(e){let t=e.split("?")[0];return t==="/api/hub"||t==="/api/machines"||t==="/api/notifications"||t==="/api/notifications/read"||t==="/api/ai/notes"||t.startsWith("/api/ai/notes/")||t.startsWith("/api/auth/")}async function y(e,t,n,s,a={}){let o=Cn(a),r={"Content-Type":"application/json",...f.token?{Authorization:`Bearer ${f.token}`}:{}};A.peek()&&o&&!zr(t)&&(r["X-Machine-Id"]=o);let d=a.etag===!0?`${f.token||""}:${o||""}:${t}`:a.etag||null;if(e.toUpperCase()==="GET"&&d){let u=No.get(d);u&&(r["If-None-Match"]=u)}let l=async()=>{let u=await fetch(t,{method:e,signal:s,headers:r,...n!==void 0?{body:JSON.stringify(n)}:{}});if(u.status===304)return wa;let h=await u.json().catch(()=>({}));if(!u.ok)throw new Error(h.error||`HTTP ${u.status}`);if(d){let x=u.headers.get("ETag");x&&No.set(d,x)}return h};if(e.toUpperCase()!=="GET"||s||a.dedupe===!1)return l();let c=`${f.token||""}:${o||""}:${t}`;return Kr.get(c,l)}function Vt(e){return f.ws?.readyState===WebSocket.OPEN?(f.ws.send(JSON.stringify(e)),!0):(e?.type==="ping"||e?.type==="pong"||e?.type==="subscribe"||cs.push(e),!1)}function _o(){for(;cs.length&&f.ws?.readyState===WebSocket.OPEN;)f.ws.send(JSON.stringify(cs.shift()))}function Po(){cs.length=0}function Ho(e={}){let t=new URLSearchParams(e);f.token&&t.set("token",f.token);let n=Cn();return A.peek()&&n&&t.set("machine",n),t.toString()}function dt(e={}){let t={...e};f.token&&(t.Authorization=`Bearer ${f.token}`);let n=Cn();return A.peek()&&n&&(t["X-Machine-Id"]=n),t}async function Yt(){try{let e=await fetch("/api/hub");if(!e.ok)return A.value=!1,!1;let t=await e.json();if(t?.hub)return A.value=!0,t}catch{}return A.value=!1,!1}var Kr,No,wa,cs,ue=K(()=>{O();R();Kr=ko({cache:!1,dedupe:!0,retry:0}),No=new Map,wa=Symbol("not-modified");cs=[]});function Lt(e,t){e&&(t?e.setAttribute("inert",""):e.removeAttribute("inert"))}function Zt(e){return!e||e.classList.contains("hidden")?!0:e.style.display==="none"}function xe(){let e=typeof window<"u"&&window.matchMedia("(max-width: 640px)").matches,t=document.getElementById("sidebar");if(t){let s=!e||t.classList.contains("open");Lt(t,!s)}Lt(document.getElementById("welcome"),Zt(document.getElementById("welcome"))),Lt(document.getElementById("auth-screen"),Zt(document.getElementById("auth-screen"))),Lt(document.getElementById("chat-opts"),Zt(document.getElementById("chat-opts"))),Lt(document.getElementById("machine-picker"),Zt(document.getElementById("machine-picker")));for(let s of["files","git","shell","memory"]){let a=document.getElementById(`tab-${s}`);Lt(a,Zt(a))}let n=document.getElementById("tab-chat");n&&Lt(n,Zt(n))}function An(){let e=window.visualViewport,t=document.documentElement;if(!e)return;let n=e.height<window.innerHeight-80;t.classList.toggle("vv-keyboard",n),t.style.setProperty("--vvh",`${Math.round(e.height)}px`),t.style.setProperty("--vv-top",`${Math.round(e.offsetTop)}px`)}function Fo(){xe(),An();let e=window.visualViewport;e&&(e.addEventListener("resize",An),e.addEventListener("scroll",An)),window.addEventListener("resize",()=>{An(),xe()}),window.addEventListener("orientationchange",()=>{setTimeout(()=>{An(),xe()},250)})}var en=K(()=>{});function Et(){try{let e=localStorage.getItem(Uo);return e?JSON.parse(e):null}catch{return null}}function ka(e){try{let n={...Et()||{},...e,updatedAt:Date.now()};localStorage.setItem(Uo,JSON.stringify(n))}catch{}}var Uo,ds=K(()=>{Uo="lastSessionContext"});async function $a(){if(jn&&!(typeof navigator>"u"||!navigator.wakeLock?.request)&&document.visibilityState==="visible"&&!Tt)try{Tt=await navigator.wakeLock.request("screen"),Tt.addEventListener("release",()=>{Tt=null,jn&&document.visibilityState==="visible"&&setTimeout(()=>{$a().catch(()=>{})},500)})}catch{Tt=null}}async function Wo(){let e=Tt;if(Tt=null,!!e)try{await e.release()}catch{}}function Go(e){jn=!!e,jn?$a().catch(()=>{}):Wo().catch(()=>{})}function Ko(){typeof document>"u"||document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"&&jn?$a().catch(()=>{}):document.visibilityState==="hidden"&&Wo().catch(()=>{})})}var Tt,jn,zo=K(()=>{Tt=null,jn=!1});function q(e){if(e==null||e==="")return null;if(typeof e=="number")return!Number.isFinite(e)||e<=0?null:e<1e12?Math.round(e*1e3):Math.round(e);if(typeof e=="string"){let t=e.trim();if(/^\d+(\.\d+)?$/.test(t))return q(Number(t));let n=Date.parse(t);return Number.isNaN(n)?null:n}return null}function tn(e){let t=q(e);if(t==null)return"";let n=Date.now()-t;return n<0?new Date(t).toLocaleDateString():n<6e4?"just now":n<36e5?`${Math.floor(n/6e4)}m ago`:n<864e5?`${Math.floor(n/36e5)}h ago`:n<7*864e5?`${Math.floor(n/864e5)}d ago`:new Date(t).toLocaleDateString()}function nn(e,t=!0){let n=e||"claude",a={claude:"bg-orange-500/15 text-orange-400",codex:"bg-emerald-500/15 text-emerald-400",grok:"bg-sky-500/15 text-sky-400",gemini:"bg-violet-500/15 text-violet-400",cursor:"bg-amber-500/15 text-amber-400"}[n]||"bg-base-300 text-base-content/50",o=t?n==="claude"?"CC":n==="codex"?"CX":n==="grok"?"GX":n==="gemini"?"GM":n==="cursor"?"CU":n.slice(0,2).toUpperCase():te[n]||n;return`<span class="text-[9px] px-1 py-0.5 rounded font-mono font-semibold flex-shrink-0 ${a}" title="${p(te[n]||n)}">${o}</span>`}function sn(e){if(!e)return"";let t="",n=e.split("/").filter(Boolean);return n.length<=3?e:"\u2026/"+n.slice(-2).join("/")}var an=K(()=>{R();O()});function Vr(e){let t=q(e);if(t==null)return"";let n=new Date(t);return Number.isNaN(n.getTime())?"":n.toLocaleString()}function Jo(){let e=i("notifications-badge");if(e){if(!Mt){e.classList.add("hidden"),e.textContent="0";return}e.classList.remove("hidden"),e.textContent=Mt>99?"99+":String(Mt)}}function Yo(){let e=i("notifications-menu"),t=i("btn-notifications"),n=i("topbar");if(!e||!t||!n)return;let s=t.getBoundingClientRect(),a=n.getBoundingClientRect(),o=Math.min(416,window.innerWidth-16),r=Math.max(8,Math.min(window.innerWidth-o-8,s.right-o));e.style.top=`${Math.round(a.bottom+8)}px`,e.style.left=`${Math.round(r)}px`,e.style.width=`${Math.round(o)}px`}function Dn(){let e=i("notifications-menu-list"),t=i("notifications-menu-empty");if(!(!e||!t)){if(!$e.length){e.innerHTML="",t.classList.remove("hidden"),Jo();return}t.classList.add("hidden"),e.innerHTML=$e.map(n=>`
|
|
2
|
+
<button type="button"
|
|
3
|
+
class="w-full text-left rounded-lg border px-3 py-2 transition-colors hover:bg-base-200/70 ${n.unread?"border-primary/35 bg-primary/5":"border-base-300 bg-base-100"}"
|
|
4
|
+
data-notification-id="${p(n.id)}"
|
|
5
|
+
data-notification-session="${p(n.sessionId||"")}"
|
|
6
|
+
data-notification-agent="${p(n.agent||"claude")}"
|
|
7
|
+
data-notification-cwd="${p(n.cwd||"")}"
|
|
8
|
+
data-notification-machine="${p(n.machineId||"")}">
|
|
9
|
+
<div class="flex items-start gap-2">
|
|
10
|
+
<span class="text-sm leading-5">\u{1F514}</span>
|
|
11
|
+
<div class="min-w-0 flex-1">
|
|
12
|
+
<div class="flex items-center gap-2">
|
|
13
|
+
<span class="text-xs font-semibold truncate">${p(n.title||"Session done")}</span>
|
|
14
|
+
${n.unread?'<span class="inline-block w-2 h-2 rounded-full bg-primary flex-shrink-0"></span>':""}
|
|
15
|
+
</div>
|
|
16
|
+
${n.body?`<div class="text-[11px] text-base-content/55 mt-0.5 line-clamp-2">${p(n.body)}</div>`:""}
|
|
17
|
+
<div class="flex items-center gap-2 mt-1 text-[10px] text-base-content/35">
|
|
18
|
+
${n.projectName?`<span class="font-mono truncate">${p(n.projectName)}</span>`:""}
|
|
19
|
+
${n.machineId?`<span class="px-1 py-0.5 rounded bg-base-300 text-base-content/55 font-mono">${p(n.machineId)}</span>`:""}
|
|
20
|
+
<span>${p(Vr(n.createdAt))}</span>
|
|
21
|
+
</div>
|
|
22
|
+
</div>
|
|
23
|
+
</div>
|
|
24
|
+
</button>`).join(""),Jo()}}function It(){i("notifications-menu")?.classList.add("hidden"),i("notifications-backdrop")?.classList.add("hidden"),i("btn-notifications")?.setAttribute("aria-expanded","false")}function Yr(){Yo(),i("notifications-menu")?.classList.remove("hidden"),i("notifications-backdrop")?.classList.remove("hidden"),i("btn-notifications")?.setAttribute("aria-expanded","true")}function Xo(){let e=i("notifications-menu");e&&(e.classList.contains("hidden")?Yr():It())}function Qo(e){let t=new Map;for(let n of e||[])n?.id&&t.set(String(n.id),n);$e=[...t.values()].sort((n,s)=>(q(s.createdAt)||0)-(q(n.createdAt)||0)),Mt=$e.reduce((n,s)=>n+(s.unread?1:0),0),Dn()}async function us(){try{let e=await y("GET","/api/notifications?limit=80");$e=Array.isArray(e?.notifications)?e.notifications:[],Mt=Number(e?.unreadCount)||$e.reduce((t,n)=>t+(n.unread?1:0),0),Dn()}catch{$e=[],Mt=0,Dn()}}async function Vo(e=null){let t=await y("POST","/api/notifications/read",e?.length?{ids:e}:{});$e=Array.isArray(t?.notifications)?t.notifications:$e.map(n=>!e||e.includes(n.id)?{...n,unread:!1}:n),Mt=Number(t?.unreadCount)||$e.reduce((n,s)=>n+(s.unread?1:0),0),Dn()}function Xr(e){if(!(typeof Notification>"u")&&document.visibilityState!=="visible"&&Notification.permission==="granted")try{let t=new Notification(e.title||"Session done",{body:e.body||e.projectName||e.sessionId||"",tag:e.id});t.onclick=()=>{window.focus(),t.close()}}catch{}}function Zo(e){if(!e?.id)return;if($e.find(n=>n.id===e.id)){Qo([e,...$e.filter(n=>n.id!==e.id)]);return}Qo([e,...$e]),Xr(e)}function ei(e={}){Sa=typeof e.openSession=="function"?e.openSession:null,Dn(),us(),typeof Notification<"u"&&Notification.permission==="default"&&document.addEventListener("click",()=>{try{Notification.requestPermission().catch(()=>{})}catch{}},{once:!0}),g.on("click","#notifications-backdrop",t=>{t.preventDefault(),t.stopPropagation(),It()}),g.on("click","#btn-notifications-read-all",async t=>{t.preventDefault(),t.stopPropagation(),await Vo()}),g.on("click","[data-notification-id]",async(t,n)=>{let s=n.dataset.notificationId;s&&(await Vo([s]),It(),!(!Sa||!n.dataset.notificationSession)&&Sa(n.dataset.notificationSession,n.dataset.notificationCwd||null,null,n.dataset.notificationAgent||"claude",n.dataset.notificationMachine||null))}),document.addEventListener("click",t=>{let n=i("notifications-menu"),s=i("btn-notifications"),a=t.target;!n||n.classList.contains("hidden")||n.contains(a)||s?.contains(a)||It()}),window.addEventListener("resize",()=>{i("notifications-menu")&&!i("notifications-menu").classList.contains("hidden")&&Yo()})}var $e,Mt,Sa,La=K(()=>{R();ue();an();$e=[],Mt=0,Sa=null});function el(){let e=globalThis.mermaid;return!e||ti||(e.initialize({startOnLoad:!1,securityLevel:"strict",theme:document.documentElement.dataset.theme==="dark"?"dark":"default",flowchart:{htmlLabels:!1}}),ti=!0),e}function tl(e){let t=String(e||"").replace(/\r\n?/g,`
|
|
25
|
+
`).trim();return t=t.replace(/^```(?:mermaid)?\s*/i,"").replace(/\s*```$/,"").trim(),t=t.replace(/^mermaid\s*\n/i,""),t=t.replace(/^graph\s+(TD|TB|BT|RL|LR)\b/i,"flowchart $1"),t}function ps(e){let t=el();!t||!e||e.querySelectorAll("pre code.language-mermaid, pre code.lang-mermaid").forEach(n=>{if(n.dataset.mermaidHandled)return;let s=n.closest("pre"),a=tl(n.textContent);if(!s||!a)return;n.dataset.mermaidHandled="1";let o=document.createElement("div");o.className="mermaid-diagram",o.setAttribute("role","img"),o.setAttribute("aria-label","Mermaid diagram"),s.replaceWith(o);let r=`mermaid-diagram-${++Zr}`;Promise.resolve(t.parse(a)).then(()=>t.render(r,a)).then(({svg:d,bindFunctions:l})=>{o.innerHTML=d,l?.(o)}).catch(d=>{o.replaceWith(s),delete n.dataset.mermaidHandled,s.classList.add("mermaid-error"),s.title=`Mermaid render failed: ${d?.message||"invalid diagram"}`})})}var ti,Zr,Ea=K(()=>{ti=!1,Zr=0});function nl(){return te[I.peek()]||"Assistant"}function ri(e){return e.scrollHeight-e.scrollTop-e.clientHeight<80}function Me(e,t){e&&(t||ri(e))&&(e.scrollTop=e.scrollHeight)}function mt({sessionId:e=f.sessionId,agent:t=f.agent,machineId:n=f.machineId}={}){return e?`${n||""}:${t||"claude"}:${e}`:null}function cn(e){let t=mt(e),n=i("chat-input");!t||!n||(n.value?Ct.set(t,n.value):Ct.delete(t))}function dn(e){let t=i("chat-input");t&&(t.value=Ct.get(mt(e))||"",rn(t),on(t.value))}function un(e){let t=mt(e);if(!t)return;let n=nt.filter(a=>a.key===t);if(!n.length)return;nt=nt.filter(a=>a.key!==t);let s=Ct.get(t)||"";Ct.set(t,[s,...n.map(a=>a.text)].filter(Boolean).join(`
|
|
26
|
+
|
|
27
|
+
`))}function pn(){he.peek()&&(he.value=!1,pt())}function sl(){ni||(ni=!0,document.addEventListener("visibilitychange",()=>{if(document.visibilityState==="visible"&&(Ge=400,fs({probe:!0}),f.ws?.readyState===WebSocket.OPEN&&f.sessionId))try{f.ws.send(JSON.stringify({type:"subscribe",sessionId:f.sessionId}))}catch{}}),window.addEventListener("online",()=>{Ge=400,fs({force:!0})}),window.addEventListener("pageshow",e=>{e.persisted?fs({force:!0}):fs({probe:!0})}))}function Rn(){let e=i("conn-dot");if(!e)return;let t=ze.peek();e.classList.remove("bg-success","bg-warning","bg-error","bg-base-content/30","animate-pulse"),t==="open"?(e.classList.add("bg-success"),e.title="\u5DF2\u8FDE\u63A5"):t==="connecting"||t==="reconnecting"?(e.classList.add("bg-warning","animate-pulse"),e.title=t==="connecting"?"\u8FDE\u63A5\u4E2D\u2026":"\u91CD\u8FDE\u4E2D\u2026"):t==="offline"?(e.classList.add("bg-error"),e.title="\u79BB\u7EBF"):(e.classList.add("bg-base-content/30"),e.title="\u672A\u8FDE\u63A5")}function fs(e={}){let t=f.ws?.readyState;if(e.force){Ge=400,st({quiet:!0});return}if(t===WebSocket.OPEN){if(e.probe&&et&&Date.now()-et>45e3)try{f.ws.close()}catch{}else if(e.probe&&f.ws.readyState===WebSocket.OPEN)try{f.ws.send(JSON.stringify({type:"ping"}))}catch{}return}t!==WebSocket.CONNECTING&&(Ge=Math.min(Ge,800),st({quiet:!0}))}function al(){tt||(ze.value=typeof navigator<"u"&&navigator.onLine===!1?"offline":"reconnecting",Rn(),tt=setTimeout(()=>{tt=null,st({quiet:!0})},Ge),Ge=Math.min(Math.round(Ge*1.8),15e3))}function li(){hs&&(clearInterval(hs),hs=null)}function ol(e,t){li(),hs=setInterval(()=>{if(!(t!==_n||e.readyState!==WebSocket.OPEN)){if(et&&Date.now()-et>7e4){try{e.close()}catch{}return}if(!(typeof document<"u"&&document.visibilityState==="hidden")&&et&&Date.now()-et>4e4)try{e.send(JSON.stringify({type:"ping"}))}catch{}}},3e4)}function pt(){let e=he.peek()||!!E.peek()&&ze.peek()==="open";Go(e)}function il(){Ge=400,tt&&(clearTimeout(tt),tt=null),gs=!1;let e=f.ws?.readyState;if(e===WebSocket.OPEN||e===WebSocket.CONNECTING)try{f.ws?.close()}catch{}st({quiet:!1}),L("\u6B63\u5728\u91CD\u65B0\u8FDE\u63A5\u5E76\u540C\u6B65\u2026")}function st(e={}){sl(),tt&&(clearTimeout(tt),tt=null),e.quiet&&(gs=!0);let t=f.machineId||(typeof localStorage<"u"?localStorage.getItem("machineId"):null);si!==t&&(Po(),si=t);let n=++_n;try{f.ws?.close()}catch{}ze.value="connecting",Rn();let s=location.protocol==="https:"?"wss":"ws",a=new URLSearchParams;f.token&&a.set("token",f.token),t&&a.set("machine",t),f.sessionId&&a.set("sessionId",f.sessionId);let o=new WebSocket(`${s}://${location.host}/ws/chat?${a}`);f.ws=o,o.addEventListener("open",()=>{if(n===_n){if(Ge=1e3,et=Date.now(),ze.value="open",Rn(),f.sessionId)try{o.send(JSON.stringify({type:"subscribe",sessionId:f.sessionId}))}catch{}_o(),ol(o,n),pt(),bs&&!gs&&L(t?`\u5DF2\u91CD\u8FDE \xB7 ${t}`:"\u5DF2\u91CD\u8FDE"),bs=!1,gs=!1}}),o.addEventListener("message",r=>{if(n!==_n)return;let d;try{d=JSON.parse(r.data)}catch{return}if(d.type==="pong"){et=Date.now();return}if(d.type==="ping"){if(et=Date.now(),o.readyState===WebSocket.OPEN)try{o.send(JSON.stringify({type:"pong"}))}catch{}return}if(d.type==="run-status"){d.running?he.value=!0:he.peek()&&(he.value=!1,ci()),pt();return}di(d)}),o.addEventListener("close",()=>{n===_n&&(li(),bs=!0,ze.value=typeof navigator<"u"&&navigator.onLine===!1?"offline":"reconnecting",Rn(),al())}),o.addEventListener("error",()=>{})}function ci(){if(!nt.length||he.peek())return;let e=mt(),t=nt.findIndex(a=>a.key===e);if(t<0)return;let[n]=nt.splice(t,1),s=i("chat-input");s&&(s.value=n.text,rn(s)),setTimeout(()=>{if(n.key!==mt()||he.peek()){Ct.set(n.key,n.text);return}Bn()},0)}function Pn(){he.value=!1,pt(),ci()}function di(e){if(!(e?.sessionId&&f.sessionId&&e.sessionId!==f.sessionId)){if(e.type==="batch"&&Array.isArray(e.items)){for(let t of e.items)di(t);return}if(e.type==="session-created"){let t=P.peek();f.sessionId=e.sessionId,e.agent&&e.agent!==I.peek()&&qe(e.agent),le(t,e.agent||I.peek(),e.sessionId),document.dispatchEvent(new CustomEvent("sessions-changed"));return}if(e.type==="notification"&&e.notification){Zo(e.notification);return}if(e.type==="result"){Hn(),Nn(),De();let t=e.usage;if(t){let n={input_tokens:t.inputTokens??t.input_tokens,output_tokens:t.outputTokens??t.output_tokens,cache_read_input_tokens:t.cacheReadInputTokens??t.cache_read_input_tokens,cache_creation_input_tokens:t.cacheCreationInputTokens??t.cache_creation_input_tokens,total_tokens:t.totalTokens??t.total_tokens,reasoning_tokens:t.reasoningTokens??t.reasoning_tokens,costUSD:t.costUSD??t.cost_usd};f.lastUsage=n,f.sessionId&&(f.lastUsageSessionId=f.sessionId),ln(n)}e.is_error||L("\u2713 Done"),Pn();return}if(e.type==="complete"){Hn(),Nn(),De(),!e.aborted&&e.agent==="claude"?L("\u2713 Done"):!e.aborted&&e.agent&&e.agent!=="claude"&&!e.error||(!e.aborted&&!e.agent?L("\u2713 Done"):e.aborted&&L("\u5DF2\u505C\u6B62")),Pn();return}if(e.type==="error"){Hn(),Nn(),At("error","Error",e.message),Pn();return}if(e.type==="shell-start"){f.shellBubble=null;return}if(e.type==="shell-output"){f.shellBubble||(f.shellBubble=$l(e.stream==="stderr"?"shell-err":"shell")),Sl(f.shellBubble,e.data);return}if(e.type==="shell-exit"){f.shellBubble=null,L(e.code===0?"\u2713 Exit 0":`\u2717 Exit ${e.code}${e.error?": "+e.error:""}`),Pn();return}if(e.type==="assistant"){Nn();for(let t of e.message?.content||[])t.type==="text"&&t.text?(De(),At("assistant",nl(),t.text,{ts:e.ts||Date.now()})):t.type==="tool_use"&&Aa(t,{ts:e.ts||Date.now()});return}if(e.type==="assistant_stream_start"){ui(e.ts);return}if(e.type==="assistant_delta"){rl(e.data||"");return}if(e.type==="assistant_stream_end"){Nn();return}if(e.type==="thought_stream_start"){pi();return}if(e.type==="thought_delta"){ll(e.data||"");return}if(e.type==="thought_stream_end"){Hn();return}if(e.type==="status"){let t=i("stream-status");if(t)t.textContent=e.message||"";else{let n=i("messages");n&&e.message&&(n.insertAdjacentHTML("beforeend",`<div id="stream-status" class="text-center text-[10px] text-base-content/35 py-0.5">${p(e.message)}</div>`),Me(n))}return}if(e.type==="permission_resolved"){let t=e.requestId||e.request_id;t&&i(`perm-${t}`)?.remove();return}(e.type==="permission_request"||e.request_id&&e.tool_name)&&Tl(e)}}function ui(e){let t=i("messages");if(!t||(De(),Hn(),Ue&&t.contains(Ue)))return;let n=ys(e||Date.now()),s=ws(e||Date.now());t.insertAdjacentHTML("beforeend",`
|
|
28
|
+
<div class="msg-row assistant px-2 live-stream" data-ts="${p(s)}">
|
|
29
|
+
<div class="max-w-[88%] rounded-2xl rounded-tl-sm px-3 py-2 text-sm bg-base-200 break-words md">
|
|
30
|
+
<div class="msg-stream-body whitespace-pre-wrap"></div>
|
|
31
|
+
</div>
|
|
32
|
+
${n?`<div class="msg-ts" title="${p(s)}">${p(n)}</div>`:""}
|
|
33
|
+
</div>`),Ue=t.lastElementChild,Te=Ue.querySelector(".msg-stream-body"),i("stream-status")?.remove(),Me(t,!0)}function rl(e){e&&(Te||ui(Date.now()),Te&&(Te.textContent+=e,Me(i("messages"),!0)))}function Nn(){if(!Ue||!Te){Ue=null,Te=null;return}let e=Te.textContent||"";e.trim()?(Te.classList.remove("whitespace-pre-wrap"),Te.classList.add("md"),Te.innerHTML=vs(e),gi(Ue)):Ue.remove(),Ue=null,Te=null,i("stream-status")?.remove()}function pi(){let e=i("messages");e&&(ut&&e.contains(ut)||(e.insertAdjacentHTML("beforeend",`
|
|
34
|
+
<div class="msg-row assistant px-2 thought-stream">
|
|
35
|
+
<div class="max-w-[88%] rounded-lg border border-base-300/60 bg-base-200/50 px-2.5 py-1.5 text-[11px] text-base-content/45">
|
|
36
|
+
<div class="font-medium text-base-content/35 mb-0.5">thinking\u2026</div>
|
|
37
|
+
<div class="thought-body font-mono whitespace-pre-wrap max-h-24 overflow-y-auto opacity-80"></div>
|
|
38
|
+
</div>
|
|
39
|
+
</div>`),ut=e.lastElementChild,We=ut.querySelector(".thought-body"),Me(e,!0)))}function ll(e){e&&(We||pi(),We&&(We.textContent+=e,We.scrollTop=We.scrollHeight,Me(i("messages"),!0)))}function Hn(){if(ut&&We){let e=(We.textContent||"").length;ut.innerHTML=`
|
|
40
|
+
<div class="text-[10px] text-base-content/30 px-1 select-none">\u{1F4AD} thought ${e?`(${e} chars)`:""}</div>`}ut=null,We=null}function dl(e){let[t,...n]=e.slice(1).trim().split(/\s+/),s=n.join(" ");switch(t.toLowerCase()){case"agent":{if(!s)return L(`Current agent: ${I.peek()} \xB7 agents: claude | codex | grok | gemini | cursor`),!0;let a=s.toLowerCase();return["claude","codex","grok","gemini","cursor"].includes(a)?(a!==I.peek()?(f.sessionId=null,qe(a),le(Oe(a)),document.dispatchEvent(new CustomEvent("agent-changed")),L(`Agent \u2192 ${te[a]} \xB7 model ${P.peek()} \xB7 new session`)):L(`Agent already ${te[a]}`),!0):(L(`Unknown agent "${s}" \xB7 valid: claude | codex | grok | gemini | cursor`),!0)}case"model":{if(!s){let d=I.peek(),l=Xe(d).map(c=>c.value).join(" | ");return L(`Current model: ${P.peek()} (${d})${l?`
|
|
41
|
+
Available: ${l}`:""}`),!0}let a=cl[s.toLowerCase()]||s,o=I.peek()||"claude",r=Xe(o).some(d=>d.value===a);return r||Mn(o,a),le(a),L(`Model set to ${a}${r?"":" (saved as custom \u2605)"}`),document.dispatchEvent(new CustomEvent("agent-changed")),!0}case"effort":{let a=In(I.peek(),P.peek());return s?a.includes(s.toLowerCase())?(ie.value=s.toLowerCase(),L(`Effort set to ${s.toLowerCase()}`),!0):(L(`Unknown effort level "${s}" \xB7 valid: ${a.join(" | ")}`),!0):(L(`Current effort: ${ie.peek()||"(default)"} \xB7 levels: ${a.join(" | ")}`),!0)}case"clear":return mn(),f.sessionId=null,f.lastUsage=null,L("Cleared \xB7 new session"),!0;case"usage":return ul(),!0;case"help":return L(`Available slash commands:
|
|
42
|
+
/agent [claude|codex|grok|gemini|cursor]
|
|
43
|
+
/model [haiku|sonnet|opus|<model-id>]
|
|
44
|
+
/effort [low|medium|high|xhigh|max]
|
|
45
|
+
/usage
|
|
46
|
+
/clear
|
|
47
|
+
/help`),!0;default:return!1}}function ve(e){if(e==null||Number.isNaN(Number(e)))return"\u2014";let t=Number(e);return t>=1e6?`${(t/1e6).toFixed(2)}M`:t>=1e3?`${(t/1e3).toFixed(1)}k`:String(Math.round(t))}async function ul(){let e=I.peek()||"claude",t=P.peek()||"\u2014",n=f.sessionId,s=[`Agent: ${te[e]||e}`,`Model: ${t}`,`Session: ${n?n.slice(0,8)+"\u2026":"(new \u2014 send a message first)"}`];if(f.lastUsage&&(!n||f.lastUsageSessionId===n)){let a=f.lastUsage;s.push(`Last turn: \u2191${ve(a.input_tokens)} \u2193${ve(a.output_tokens)}`+(a.cache_read_input_tokens?` \xB7 ${ve(a.cache_read_input_tokens)} cached`:"")+(a.reasoning_tokens?` \xB7 ${ve(a.reasoning_tokens)} reason`:"")+(a.total_tokens?` \xB7 \u03A3${ve(a.total_tokens)}`:"")+(a.costUSD!=null?` \xB7 $${Number(a.costUSD).toFixed(4)}`:""))}if(!n){L(s.join(`
|
|
48
|
+
`)),Ia("\u25C8 /usage \xB7 no session yet");return}L("Loading usage\u2026");try{let a=new URLSearchParams({sessionId:n,agent:e}),r=(await y("GET",`/api/usage?${a}`)).context||{};if(r.model&&(s[1]=`Model: ${r.model}`),r.title&&s.push(`Title: ${r.title}`),r.tokensUsed!=null||r.windowTokens!=null||r.usagePercent!=null){let l=r.tokensUsed!=null?ve(r.tokensUsed):"\u2014",c=r.windowTokens!=null?ve(r.windowTokens):"\u2014",u=r.usagePercent!=null?`${r.usagePercent}%`:"\u2014";s.push(`Context window: ${l} / ${c} (${u})`)}if(r.turnCount!=null&&s.push(`Turns: ${r.turnCount}`),r.toolCallCount!=null&&s.push(`Tools: ${r.toolCallCount}`),r.sessionDurationSeconds!=null){let l=Math.floor(r.sessionDurationSeconds/60),c=Math.round(r.sessionDurationSeconds%60);s.push(`Duration: ${l}m ${c}s`)}if(r.sessionTotals){let l=r.sessionTotals;s.push(`Session totals: \u2191${ve(l.input_tokens)} \u2193${ve(l.output_tokens)}`+(l.cache_read_input_tokens?` \xB7 ${ve(l.cache_read_input_tokens)} cached`:"")+(l.total_tokens?` \xB7 \u03A3${ve(l.total_tokens)}`:"")+(l.costUSD?` \xB7 $${Number(l.costUSD).toFixed(4)}`:""))}if(r.lastTurn&&!f.lastUsage){let l=r.lastTurn;s.push(`Last completed turn: \u2191${ve(l.input_tokens)} \u2193${ve(l.output_tokens)}`+(l.cache_read_input_tokens?` \xB7 ${ve(l.cache_read_input_tokens)} cached`:"")+(l.costUSD!=null?` \xB7 $${Number(l.costUSD).toFixed(4)}`:""))}r.note&&s.push(r.note);let d=i("messages");if(d){let l=[...d.children];for(let c=l.length-1;c>=0;c--)if(l[c].textContent==="Loading usage\u2026"){l[c].remove();break}}L(s.join(`
|
|
49
|
+
`)),(r.tokensUsed!=null||r.windowTokens!=null)&&Ca({tokensUsed:r.tokensUsed,windowTokens:r.windowTokens,usagePercent:r.usagePercent,model:r.model||t,turnCount:r.turnCount,toolCallCount:r.toolCallCount}),r.sessionTotals?ln(r.sessionTotals):r.lastTurn?ln(r.lastTurn):f.lastUsage&&ln(f.lastUsage)}catch(a){let o=i("messages");if(o){let r=[...o.children];for(let d=r.length-1;d>=0;d--)if(r[d].textContent==="Loading usage\u2026"){r[d].remove();break}}L(`${s.join(`
|
|
50
|
+
`)}
|
|
51
|
+
(usage fetch failed: ${a.message})`)}}function Bn(){let e=i("chat-input"),t=e?.value.trim();if(!t||!E.peek())return;if(he.peek()){if(I.peek()==="grok"&&f.sessionId){let s="grok",a=ie.peek()||lt(s,P.peek())||"low",o=Vt({type:"command",cmd:"turn.start",agent:s,command:t,sessionId:f.sessionId,options:{agent:s,cwd:E.peek().path,sessionId:f.sessionId,configDir:f.configDir,model:P.peek(),effort:a,...Ee.peek()&&{permissionMode:Ee.peek()},...Ee.peek()==="bypassPermissions"&&{allowDangerouslySkipPermissions:!0}}});e.value="",rn(e),on(""),xs(),L(o?"\u5DF2\u52A0\u5165 Grok \u670D\u52A1\u7AEF\u961F\u5217\uFF0C\u5237\u65B0\u9875\u9762\u4E0D\u4F1A\u4E22\u5931":"\u8FDE\u63A5\u672A\u5C31\u7EEA\uFF0C\u6D88\u606F\u5C06\u5728\u91CD\u8FDE\u540E\u53D1\u9001");return}nt.push({key:mt(),text:t}),e.value="",rn(e),on(""),xs(),L(`\u5DF2\u6392\u961F\u4E0B\u4E00\u6761\uFF0C\u5F53\u524D\u56DE\u590D\u7ED3\u675F\u540E\u53D1\u9001\uFF1A${t.length>80?t.slice(0,80)+"\u2026":t}`);return}if(e.value="",Ct.delete(mt()),rn(e),on(""),xs(),t.startsWith("/")&&dl(t))return;he.value=!0,pt();let n=Date.now();if(mi(t))At("shell","$ Shell",t.slice(1).trim(),{ts:n}),Vt({type:"command",cmd:"shell.exec",command:t.slice(1).trim(),cwd:E.peek().path})||L("\u8FDE\u63A5\u672A\u5C31\u7EEA\uFF0C\u547D\u4EE4\u5DF2\u5165\u961F\uFF0C\u91CD\u8FDE\u540E\u53D1\u9001");else{De(),At("user","You",t,{ts:n});let s=I.peek()||"claude",a=ie.peek()||lt(s,P.peek())||(s==="grok"?"low":""),o=Ee.peek();f.sessionId&&le(P.peek(),s,f.sessionId),Vt({type:"command",cmd:"turn.start",agent:s,command:t,sessionId:f.sessionId,options:{agent:s,cwd:E.peek().path,sessionId:f.sessionId,configDir:f.configDir,model:P.peek(),...a&&{effort:a},...o&&{permissionMode:o},...o==="bypassPermissions"&&{allowDangerouslySkipPermissions:!0}}})||L("\u8FDE\u63A5\u672A\u5C31\u7EEA\uFF0C\u6D88\u606F\u5DF2\u5165\u961F\uFF0C\u91CD\u8FDE\u540E\u53D1\u9001")}}function fi(){f.sessionId&&Vt({type:"command",cmd:"turn.interrupt",sessionId:f.sessionId}),nt=nt.filter(e=>e.key!==mt()),Pn()}function on(e){let t=mi(e),n=i("chat-input"),s=i("send-btn");if(!n||!s)return;n.classList.toggle("textarea-warning",t),n.style.fontFamily=t?"monospace":"",s.classList.toggle("btn-warning",t),s.classList.toggle("btn-primary",!t),s.textContent=t?"Run":"Send";let a=te[I.peek()]||"agent",o=typeof window<"u"&&window.matchMedia("(max-width: 640px)").matches;t?n.placeholder=o?"Shell \u547D\u4EE4\u2026":"Shell command (without !)\u2026":n.placeholder=o?`\u95EE ${a}\u2026`:`Ask ${a}\u2026 or !cmd for shell`}function mi(e){let t=String(e||"").trimStart();return t.startsWith("!")&&!/^!\[[^\]]*\]\([^)]+\)/.test(t)}function pl(){return typeof window<"u"&&window.matchMedia("(max-width: 640px)").matches,72}function rn(e){e.style.height="auto",e.style.height=Math.min(e.scrollHeight,pl())+"px"}function ys(e){let t=q(e);if(t==null)return"";let n=new Date(t);if(Number.isNaN(n.getTime()))return"";let s=new Date,a=n.toDateString()===s.toDateString(),o=n.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1});return a?o:`${n.toLocaleDateString(void 0,{month:"numeric",day:"numeric"})} ${o}`}function ws(e){let t=q(e);return t==null?"":new Date(t).toISOString()}function hl(e,t,n){if(e==="system")return t;let s=ys(n),a=ws(n),o=s?`<div class="msg-ts" title="${p(a)}">${p(s)}</div>`:"";return`<div class="msg-row ${e==="user"?"user":e==="shell"||e==="shell-err"?"assistant":e} px-2" data-ts="${p(a)}">${t}${o}</div>`}function bl(e,t,n){let s='<button class="msg-expand-btn text-[10px] text-primary/70 mt-1.5 block cursor-pointer hover:text-primary">\u25BC Show more</button>',a;switch(e){case"user":{let r=/!\[.*?\]\(.*?\)/.test(t)?vs(t):null,d=t.length>fl,l=d?`<div class="msg-body">${r??p(t.trimEnd())}</div>${s}`:r??p(t.trimEnd());a=`<div class="max-w-[80%] rounded-2xl rounded-tr-sm px-3 py-2 text-sm bg-primary/15 border border-primary/20 text-base-content break-words${d?" msg-card":""}${r?" md":""}"${r?"":' style="white-space:pre-wrap"'}>${l}</div>`;break}case"assistant":{let o=t.length>ml,r=o?`<div class="msg-body">${vs(t)}</div>${s}`:vs(t);a=`<div class="max-w-[min(92%,52rem)] rounded-2xl rounded-tl-sm px-3.5 py-2.5 text-sm bg-base-200 border border-base-300/40 break-words md leading-relaxed${o?" msg-card":""}">${r}</div>`;break}case"error":a=`<div class="max-w-[88%] rounded-2xl rounded-tl-sm px-3 py-2 text-sm bg-error/10 border border-error/20 text-error break-words" style="white-space:pre-wrap">${p(t)}</div>`;break;case"shell":case"shell-err":a=`<div class="w-full max-w-[96%] rounded-lg code-surface px-3 py-2 text-sm font-mono ${e==="shell-err"?"text-error":""} break-words" style="white-space:pre-wrap">${p(t)}</div>`;break;case"system":return`<div class="text-center text-[11px] text-base-content/30 py-0.5 select-none">${p(t)}</div>`;default:a=`<div class="rounded-lg px-3 py-2 text-sm bg-base-300 break-words" style="white-space:pre-wrap">${p(t)}</div>`}return hl(e,a,n)}function At(e,t,n,s={}){let a=i("messages");if(!a)return;let o=q(s.ts)??(e==="system"?null:Date.now());a.insertAdjacentHTML("beforeend",bl(e,n,o)),gi(a.lastElementChild),Me(a,e==="user")}function L(e){At("system","",e)}async function gl(e,t){let n=t||`upload-${Date.now()}`,s=await hi(e,n),a=dt({"x-filename":n});delete a["Content-Type"],s?.type&&!a["Content-Type"]&&!a["content-type"]&&(a["Content-Type"]=s.type);let o=await fetch("/api/upload-image",{method:"POST",headers:a,body:s});if(!o.ok){let d=await o.json().catch(()=>({}));throw new Error(d.error||`Upload failed: ${o.status}`)}let r=await o.json();if(!r?.path)throw new Error("upload returned no path");return r.path}function xl(e,t){return e.length>=8&&e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71?"image/png":e.length>=3&&e[0]===255&&e[1]===216&&e[2]===255?"image/jpeg":e.length>=6&&String.fromCharCode(...e.slice(0,6))==="GIF87a"?"image/gif":e.length>=12&&String.fromCharCode(...e.slice(8,12))==="WEBP"?"image/webp":t||"image/png"}async function hi(e,t){if(!e||!Ta({type:e.type,name:t}))return e;let n;try{n=(await e.slice(0,80).text()).trim()}catch{return e}if(!/^(?:data:image\/[a-z0-9.+-]+;base64,|iVBORw0KGgo|\/9j\/|R0lGOD|UklGR)/i.test(n))return e;let s;try{s=(await e.text()).trim()}catch{return e}let o=/^data:image\/[a-z0-9.+-]+;base64,([a-z0-9+/=\s]+)$/i.exec(s)?.[1]||s;if(!o||!/^[a-z0-9+/=\s]+$/i.test(o)||o.length%4===1)return e;try{let r=atob(o.replace(/\s/g,"")),d=Uint8Array.from(r,u=>u.charCodeAt(0)),l=xl(d,e.type);return l===(e.type||"image/png")&&!/^(image\/png|image\/jpeg|image\/gif|image\/webp)$/.test(l)?e:d.length>=3&&(d[0]===137&&d[1]===80&&d[2]===78||d[0]===255&&d[1]===216&&d[2]===255||String.fromCharCode(...d.slice(0,6))==="GIF87a"||String.fromCharCode(...d.slice(8,12))==="WEBP")?new Blob([d],{type:l}):e}catch{return e}}function vl(e,t){if(!e)return;let n=e.selectionStart??e.value.length,s=e.selectionEnd??e.value.length,o=(n>0&&e.value[n-1]!==`
|
|
52
|
+
`?`
|
|
53
|
+
`:"")+t+`
|
|
54
|
+
`;e.value=e.value.slice(0,n)+o+e.value.slice(s),e.selectionStart=e.selectionEnd=n+o.length,e.dispatchEvent(new Event("input"))}function Ta(e){return e?e.type&&e.type.startsWith("image/")?!0:/\.(png|jpe?g|gif|webp|bmp|svg|heic|heif|avif)$/i.test(e.name||""):!1}function yl(e,t){let n=e?.name||t.split("/").pop()||"file";if(Ta(e)){ms+=1;let a=`img${ms}`;return{ref:``,label:a,kind:"image"}}ms+=1;let s=`file${ms}`;return{ref:`[${s}](${t})`,label:s,kind:"file"}}function xs(){for(let e of ft)if(e.previewUrl)try{URL.revokeObjectURL(e.previewUrl)}catch{}ft.length=0,Ma()}function fn(){xs()}function Ma(){let e=i("chat-attach-bar");if(e){if(!ft.length){e.classList.add("hidden"),e.innerHTML="";return}e.classList.remove("hidden"),e.innerHTML=ft.map((t,n)=>`
|
|
55
|
+
<div class="chat-thumb relative" title="${p(t.ref||t.path)}">
|
|
56
|
+
${t.previewUrl?`<img src="${t.previewUrl}" alt="${p(t.label||"img")}">`:`<span class="chat-thumb-path">${p(t.label||t.name||"file")}</span>`}
|
|
57
|
+
<span class="chat-thumb-label">${p(t.label||t.kind||"")}</span>
|
|
58
|
+
<button type="button" class="chat-thumb-x" data-rm-attach="${n}" aria-label="remove">\u2715</button>
|
|
59
|
+
</div>`).join("")}}async function wl(e){if(!e)return;let t=e.name||`upload-${Date.now()}`,n=await hi(e,t),s=await gl(n,t),{ref:a,label:o,kind:r}=yl(e,s),d="";if(r==="image")try{d=URL.createObjectURL(n)}catch{}return ft.push({path:s,ref:a,label:o,kind:r,name:t,previewUrl:d}),Ma(),vl(i("chat-input"),a),s}async function ks(e){let t=[...e||[]].filter(Boolean);if(!t.length)return;let n=i("chat-input");n&&(n.disabled=!0);try{for(let s of t)try{await wl(s)}catch(a){L(`\u4E0A\u4F20\u5931\u8D25 ${s.name||"file"}: ${a.message}`)}}finally{n&&(n.disabled=!1,n.focus())}}function kl(){let e=i("chat-file-input");if(e){e.value="",e.click();return}let t=document.createElement("input");t.type="file",t.accept="image/*,*/*",t.multiple=!0,t.addEventListener("change",()=>ks(t.files)),t.click()}function bi(){document.addEventListener("paste",async e=>{let t=i("chat-input");if(!t)return;let n=i("chat-composer");if(!(n&&(n.contains(document.activeElement)||document.activeElement===t))&&document.activeElement!==t)return;let a=[...e.clipboardData?.items||[]],o=[];for(let l of a)if(l.kind==="file"){let c=l.getAsFile();c&&o.push(c)}let r=o.filter(l=>Ta(l)),d=r.length?r:o;d.length&&(e.preventDefault(),await ks(d))}),!ai&&(ai=!0,document.addEventListener("dragover",e=>{let t=i("chat-composer");!t||!e.dataTransfer?.types?.includes("Files")||!t.contains(e.target)&&e.target!==t||(e.preventDefault(),t.classList.add("chat-drop-active"))}),document.addEventListener("dragleave",e=>{let t=i("chat-composer");t&&(e.target===t||t.contains(e.target))&&(t.contains(e.relatedTarget)||t.classList.remove("chat-drop-active"))}),document.addEventListener("drop",async e=>{let t=i("chat-composer");if(!t||(t.classList.remove("chat-drop-active"),!t.contains(e.target)&&e.target!==t))return;let n=[...e.dataTransfer?.files||[]];n.length&&(e.preventDefault(),await ks(n))}))}function Ze(e){return e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function Ia(e){let t=i("messages");t&&(t.insertAdjacentHTML("beforeend",`<div class="token-bar select-none">
|
|
60
|
+
<span class="token-bar-mark">\u25C8</span><span class="token-bar-text">${p(e)}</span>
|
|
61
|
+
</div>`),Me(t))}function ln(e){if(!e)return;let t=e.input_tokens??e.inputTokens??0,n=e.output_tokens??e.outputTokens??0,s=e.total_tokens??e.totalTokens??t+n,a=e.cache_read_input_tokens??e.cachedReadTokens?` \xB7 ${Ze(e.cache_read_input_tokens??e.cachedReadTokens)} cached`:"",o=e.cache_creation_input_tokens??e.cacheCreationInputTokens?` \xB7 ${Ze(e.cache_creation_input_tokens??e.cacheCreationInputTokens)} cache-write`:"",r=e.reasoning_tokens??e.reasoningTokens?` \xB7 ${Ze(e.reasoning_tokens??e.reasoningTokens)} reason`:"",d=e.costUSD??e.cost_usd,l=d!=null?` \xB7 $${Number(d).toFixed(4)}`:"",c=s?` \xB7 \u03A3${Ze(s)}`:"";Ia(`\u2191${Ze(t)} \u2193${Ze(n)}${a}${o}${r}${c}${l}`)}function Ca(e){if(!e)return;let t=e.tokensUsed??e.contextTokensUsed,n=e.windowTokens??e.contextWindowTokens,s=e.usagePercent??e.contextWindowUsage;if(t==null&&n==null&&s==null)return;let a=[];t!=null&&n!=null?a.push(`context ${Ze(t)} / ${Ze(n)}`):t!=null&&a.push(`context ${Ze(t)}`),s!=null&&a.push(`${s}%`),e.model&&a.push(e.model),e.turnCount!=null&&a.push(`${e.turnCount} turns`),e.toolCallCount!=null&&a.push(`${e.toolCallCount} tools`),Ia(`\u25A3 ${a.join(" \xB7 ")}`)}function mn(){let e=i("messages"),t=i("permission-requests");e&&(e.innerHTML=""),t&&(t.innerHTML=""),f.shellBubble=null,Fe=null,Ue=Te=null,ut=We=null}function $l(e){let t=i("messages");if(!t)return null;let n=e==="shell-err"?" text-error":"";return t.insertAdjacentHTML("beforeend",`<div class="mx-2 rounded-lg code-surface px-3 py-2 text-sm font-mono${n} whitespace-pre-wrap break-words"></div>`),Me(t),t.lastElementChild}function Sl(e,t){e&&(e.textContent+=t,Me(e.closest("#messages")))}function Ll(e){let t=typeof e.input=="object"?JSON.stringify(e.input,null,2):String(e.input||""),s=((typeof e.input=="object"?Object.values(e.input).find(a=>typeof a=="string"&&a.trim()):t)||"").replace(/\n/g," ").slice(0,Ve.peek()==="full"?120:80);return{inputStr:t,preview:s}}function oi(e,{inBatch:t=!1}={}){let{inputStr:n,preview:s}=Ll(e);return`<div class="tool-card${t?" tool-batch-item":""} cursor-pointer select-none px-2 py-1">
|
|
62
|
+
<div class="flex items-center gap-1.5 text-xs font-mono">
|
|
63
|
+
<span class="text-warning">\u26A1</span>
|
|
64
|
+
<span class="text-warning font-semibold">${p(e.name||"tool")}</span>
|
|
65
|
+
<span class="text-base-content/50 truncate flex-1">${p(s)}</span>
|
|
66
|
+
<span class="tool-chevron text-[10px] text-base-content/40">\u25B6</span>
|
|
67
|
+
</div>
|
|
68
|
+
<div class="tool-detail">${p(n)}</div>
|
|
69
|
+
</div>`}function El(e){let t=[...new Set(e.names)],n=t.slice(0,4).join(", ")+(t.length>4?"\u2026":""),s=e.el.querySelector(".tool-batch-summary");s&&(s.innerHTML=`<span class="text-warning">\u26A1</span>
|
|
70
|
+
<span class="font-semibold text-base-content/70">${e.count} tool${e.count===1?"":"s"}</span>
|
|
71
|
+
<span class="text-base-content/40 truncate flex-1">${p(n)}</span>
|
|
72
|
+
<span class="tool-chevron text-[10px] text-base-content/40">\u25B6</span>`)}function De(){Fe=null}function Aa(e,t={}){let n=i("messages");if(!n)return;let s=Ve.peek()||"normal",a=q(t.ts);if(s==="clean"){if(!Fe||!n.contains(Fe.el)){let l=ys(a),c=ws(a);n.insertAdjacentHTML("beforeend",`
|
|
73
|
+
<div class="msg-row assistant px-2" data-ts="${p(c)}">
|
|
74
|
+
<div class="tool-batch w-full max-w-[96%] px-2 py-1.5">
|
|
75
|
+
<div class="tool-batch-summary flex items-center gap-1.5 text-xs font-mono"></div>
|
|
76
|
+
<div class="tool-batch-list"></div>
|
|
77
|
+
</div>
|
|
78
|
+
${l?`<div class="msg-ts" title="${p(c)}">${p(l)}</div>`:""}
|
|
79
|
+
</div>`),Fe={el:n.lastElementChild.querySelector(".tool-batch"),names:[],count:0}}Fe.names.push(e.name||"tool"),Fe.count++,Fe.el.querySelector(".tool-batch-list")?.insertAdjacentHTML("beforeend",oi(e,{inBatch:!0})),El(Fe),Me(n);return}Fe=null;let o=ys(a),r=ws(a);n.insertAdjacentHTML("beforeend",`
|
|
80
|
+
<div class="msg-row assistant px-2" data-ts="${p(r)}">
|
|
81
|
+
<div class="w-full max-w-[96%]">${oi(e)}</div>
|
|
82
|
+
${o?`<div class="msg-ts" title="${p(r)}">${p(o)}</div>`:""}
|
|
83
|
+
</div>`),Me(n)}function $s(){let e=i("messages");e&&e.setAttribute("data-density",Ve.peek()||"normal")}function Tl(e){let t=e.request_id||e.requestId;if(!t||i(`perm-${t}`))return;let n=e.tool_input?JSON.stringify(e.tool_input).slice(0,200):"";i("permission-requests")?.insertAdjacentHTML("beforeend",`
|
|
84
|
+
<div id="perm-${t}" class="perm-banner mx-3 mb-2 rounded-lg border border-warning/25 bg-warning/8 p-3">
|
|
85
|
+
<div class="text-xs text-warning font-semibold mb-1">\u26A0\uFE0F Permission Required</div>
|
|
86
|
+
<div class="font-mono text-xs text-base-content/60 break-all mb-2">
|
|
87
|
+
<strong class="text-base-content">${p(e.tool_name||"")}</strong> ${p(n)}
|
|
88
|
+
</div>
|
|
89
|
+
<div class="flex gap-2">
|
|
90
|
+
<button class="btn btn-success btn-xs" data-perm-id="${t}" data-perm-allow="1">Allow</button>
|
|
91
|
+
<button class="btn btn-error btn-xs" data-perm-id="${t}" data-perm-allow="0">Deny</button>
|
|
92
|
+
</div>
|
|
93
|
+
</div>`),i("messages").scrollTop=999999}function Ml(){if(ii||typeof marked>"u")return;let e=s=>String(s??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">"),t=(s,a)=>{let o=String(a||"").trim().split(/\s+/)[0]||"",r=o||"text",d=o?`language-${p(o)}`:"";return`<div class="code-block">
|
|
94
|
+
<div class="code-block-header">
|
|
95
|
+
<span class="code-block-lang">${p(r)}</span>
|
|
96
|
+
<button type="button" class="code-copy" data-copy="1" title="Copy code">Copy</button>
|
|
97
|
+
</div>
|
|
98
|
+
<pre><code class="hljs ${d}">${e(s)}</code></pre>
|
|
99
|
+
</div>`},n={code(s,a){return s&&typeof s=="object"&&s.text!=null?t(s.text,s.lang||a):t(s,a)},table(s,a){return s&&typeof s=="object"&&!Array.isArray(s)&&s.header?!1:`<div class="table-wrap"><table><thead>${s}</thead><tbody>${a}</tbody></table></div>`}};try{if(typeof marked.use=="function")marked.use({gfm:!0,breaks:!0,renderer:n});else if(typeof marked.setOptions=="function"){let s=new marked.Renderer;s.code=n.code,s.table=n.table,marked.setOptions({gfm:!0,breaks:!0,renderer:s})}}catch(s){console.warn("[md] marked setup failed",s)}ii=!0}function vs(e){if(typeof marked>"u")return p(e);try{return Ml(),marked.parse(String(e??""),{breaks:!0,gfm:!0})}catch{return p(e)}}function Il(e){!e||typeof hljs>"u"||(e.querySelectorAll("pre code:not(.hljs)").forEach(t=>{try{hljs.highlightElement(t)}catch{}}),e.querySelectorAll("pre code.hljs").forEach(t=>{t.classList.add("hljs")}))}function gi(e){Il(e),ps(e)}function xi(){$s(),Ko(),Le(ze,s=>{Rn(),pt();let a=i("ws-banner"),o=i("ws-banner-text");if(!a)return;if(s==="open"||s==="idle"){a.classList.add("hidden"),o&&(o.textContent="");return}if(s==="connecting"&&!bs){a.classList.add("hidden");return}a.classList.remove("hidden");let r=s==="offline"?"\u7F51\u7EDC\u5DF2\u65AD\u5F00\uFF0C\u6062\u590D\u540E\u4F1A\u81EA\u52A8\u91CD\u8FDE":s==="connecting"?"\u6B63\u5728\u8FDE\u63A5\u2026":"\u8FDE\u63A5\u4E2D\u65AD\uFF0C\u6B63\u5728\u91CD\u8FDE\u2026\uFF08\u7184\u5C4F\u6216\u5207\u7F51\u65F6\u5E38\u89C1\uFF09";o?o.textContent=r:a.textContent=r}),Le(E,()=>pt()),g.on("click","#btn-refresh-conn, #ws-banner-retry",s=>{s.preventDefault(),il()}),Le(he,s=>{i("send-btn")?.classList.toggle("hidden",s),i("stop-btn")?.classList.toggle("hidden",!s);let a=i("chat-input");a&&(a.disabled=!1,s?a.placeholder="\u56DE\u590D\u4E2D\u2026 \u53EF\u5148\u5199\u597D\u4E0B\u4E00\u6761\uFF0C\u7ED3\u675F\u540E\u81EA\u52A8\u53D1\u9001 \xB7 \u6216\u70B9 \u25A0 \u505C\u6B62":on(a.value||""));let o=i("messages");if(!o)return;let r=i("typing-indicator");s&&!r?(o.insertAdjacentHTML("beforeend",'<div id="typing-indicator" class="flex justify-start px-2"><div class="flex items-center gap-1.5 rounded-2xl rounded-tl-sm px-3 py-2 bg-base-200 text-xs text-base-content/40"><span class="dot"></span><span class="dot"></span><span class="dot"></span></div></div>'),Me(o)):s||(r?.remove(),De()),pt()}),Le(Ve,()=>$s()),g.on("keydown","#chat-input",s=>{if(s.key!=="Enter")return;let a=s.metaKey||s.ctrlKey,o=window.matchMedia("(max-width: 640px)").matches&&!s.shiftKey&&!a;(a||o)&&(s.preventDefault(),Bn())}),g.on("submit","#chat-form",s=>{s.preventDefault(),Bn()}),g.on("input","#chat-input",(s,a)=>{rn(a),on(a.value)}),g.on("click","#btn-attach",s=>{s.preventDefault(),kl()}),g.on("change","#chat-file-input",(s,a)=>{let o=a?.files;o?.length&&ks(o),a&&(a.value="")}),g.on("click","[data-rm-attach]",(s,a)=>{s.preventDefault(),s.stopPropagation();let o=parseInt(a.dataset.rmAttach,10);if(Number.isNaN(o)||o<0||o>=ft.length)return;let r=ft[o];if(r?.previewUrl)try{URL.revokeObjectURL(r.previewUrl)}catch{}let d=i("chat-input");d&&r?.ref&&(d.value=d.value.split(r.ref).join("").replace(/\n{3,}/g,`
|
|
100
|
+
|
|
101
|
+
`),d.dispatchEvent(new Event("input"))),ft.splice(o,1),Ma()}),g.on("click","[data-perm-id]",(s,a)=>{Vt({type:"command",cmd:"approval.respond",requestId:a.dataset.permId,allow:a.dataset.permAllow==="1",sessionId:f.sessionId}),a.closest(".perm-banner")?.remove()}),g.on("click",".tool-card",(s,a)=>{let o=a.closest(".tool-batch");if(o&&!o.classList.contains("open")&&!a.classList.contains("tool-batch-item"))return;s.stopPropagation();let r=i("messages"),d=a.getBoundingClientRect().top;if(a.classList.toggle("open"),r){let l=a.getBoundingClientRect().top;r.scrollTop+=l-d}}),g.on("click",".tool-batch",(s,a)=>{if(s.target.closest(".tool-card")&&a.classList.contains("open"))return;let o=i("messages"),r=a.getBoundingClientRect().top;if(a.classList.toggle("open"),o){let d=a.getBoundingClientRect().top;o.scrollTop+=d-r}});let e=i("messages"),t=i("scroll-top-btn"),n=i("scroll-bottom-btn");if(e&&t&&n){let s=()=>{let a=e.scrollHeight-e.clientHeight>200;t.classList.toggle("hidden",!a||e.scrollTop<200),n.classList.toggle("hidden",!a||ri(e))};e.addEventListener("scroll",s,{passive:!0}),new ResizeObserver(s).observe(e),new MutationObserver(s).observe(e,{childList:!0,subtree:!0}),t.addEventListener("click",()=>e.scrollTo({top:0,behavior:"smooth"})),n.addEventListener("click",()=>e.scrollTo({top:e.scrollHeight,behavior:"smooth"})),s()}g.on("click",".msg-expand-btn",(s,a)=>{s.stopPropagation();let r=a.closest(".msg-card").classList.toggle("open");a.textContent=r?"\u25B2 Show less":"\u25BC Show more"}),g.on("click",".code-copy",async(s,a)=>{s.preventDefault(),s.stopPropagation();let d=a.closest(".code-block")?.querySelector("pre code")?.textContent??"";try{await navigator.clipboard.writeText(d),a.textContent="Copied",a.classList.add("copied"),setTimeout(()=>{a.textContent="Copy",a.classList.remove("copied")},1400)}catch{a.textContent="Failed",setTimeout(()=>{a.textContent="Copy"},1400)}})}var _n,tt,Ge,et,hs,ni,bs,si,gs,nt,Ct,Ue,Te,ut,We,cl,fl,ml,ft,ms,ai,Fe,ii,hn=K(()=>{R();O();ue();zo();La();Ea();an();an();_n=0,tt=null,Ge=1e3,et=0,hs=null,ni=!1,bs=!1,si=null,gs=!1,nt=[],Ct=new Map;Ue=null,Te=null,ut=null,We=null;cl={haiku:"claude-haiku-4-5",sonnet:"claude-sonnet-4-6",opus:"claude-opus-4-5",sonnet4:"claude-sonnet-4-6",haiku4:"claude-haiku-4-5"};fl=200,ml=500;ft=[],ms=0,ai=!1;Fe=null;ii=!1});function yi(e,t){vi=e,ja=t,window.addEventListener("hashchange",()=>{if(Da){Da=!1;return}ki(location.hash.slice(1)||"/")}),Le(U,n=>{f.sessionId&&On()})}function Na(e){let[t,n=""]=String(e||"").split("?",2),s=t.match(/^\/session\/([^/]+)(?:\/([^/]+))?$/);if(!s)return null;let a=new URLSearchParams(n);try{return{id:decodeURIComponent(s[1]),tab:s[2]?decodeURIComponent(s[2]):null,machineId:a.get("machine")||null,agent:a.get("agent")||null}}catch{return null}}function wi(){ki(location.hash.slice(1)||"/")}function ki(e){let t=Na(e);if(!t){document.dispatchEvent(new CustomEvent("router:home"));return}let{id:n,tab:s,machineId:a,agent:o}=t;!vi||!ja||(n!==f.sessionId?document.dispatchEvent(new CustomEvent("router:session",{detail:{id:n,tab:s,machineId:a,agent:o}})):s&&s!==U.peek()&&ja(s))}function _a(e){Da=!0,location.hash=e}function On(){if(!f.sessionId)return;let e=new URLSearchParams;f.machineId&&e.set("machine",f.machineId),f.agent&&e.set("agent",f.agent);let t=e.size?`?${e}`:"";_a(`/session/${encodeURIComponent(f.sessionId)}/${encodeURIComponent(U.peek())}${t}`)}function $i(){if(!f.sessionId)return null;let e=new URL(location.href),t=new URLSearchParams;f.machineId&&t.set("machine",f.machineId),f.agent&&t.set("agent",f.agent);let n=t.size?`?${t}`:"";return e.hash=`/session/${encodeURIComponent(f.sessionId)}/${encodeURIComponent(U.peek())}${n}`,e.toString()}var id,vi,ja,Da,Ss=K(()=>{R();O();id=wo({"/":()=>{},"/session/*":()=>{},"/session/*/*":()=>{},"*":()=>{}}),vi=null,ja=null,Da=!1});async function Es(){try{return await Ls.get("sessions")??null}catch{return null}}async function Si(e){try{await Ls.set("sessions",e,{ttl:Cl})}catch{}}async function Li(){try{return await Ls.get("workspaces")??null}catch{return null}}async function qn(e){try{await Ls.set("workspaces",e,{ttl:3600*1e3})}catch{}}var Ls,Cl,Ts=K(()=>{R();Ls=$o("claude-ui"),Cl=300*1e3});function xn(e){if(typeof marked<"u")try{return marked.parse(String(e??""),{breaks:!0,gfm:!0})}catch{}return p(e).replace(/\n/g,"<br>")}function vn(e){e&&(typeof hljs<"u"&&e.querySelectorAll("pre code").forEach(t=>{try{hljs.highlightElement(t)}catch{}}),ps(e))}async function Ba(e,t,n){let s=dt({"Content-Type":"application/json"}),a=await fetch(e,{method:"POST",headers:s,body:JSON.stringify(t||{})});if(!a.ok){let c=await a.json().catch(()=>({}));throw new Error(c.error||`HTTP ${a.status}`)}let o=a.body.getReader(),r=new TextDecoder,d="",l="message";for(;;){let{done:c,value:u}=await o.read();if(c)break;d+=r.decode(u,{stream:!0});let h=d.split(`
|
|
102
|
+
`);d=h.pop()||"";for(let x of h)if(x.startsWith("event:"))l=x.slice(6).trim();else if(x.startsWith("data:")){let v=x.slice(5).trim();if(!v)continue;let C;try{C=JSON.parse(v)}catch{continue}n[l]?.(C),n.any?.(l,C),l="message"}else x.trim()===""&&(l="message")}}function Nl(){return`
|
|
103
|
+
<div id="meta-agent-panel" class="meta-agent-panel hidden" aria-hidden="true">
|
|
104
|
+
<div class="meta-agent-backdrop" data-ma-close="1"></div>
|
|
105
|
+
<div class="meta-agent-sheet">
|
|
106
|
+
<header class="meta-agent-header">
|
|
107
|
+
<div class="flex items-center gap-2 min-w-0">
|
|
108
|
+
<span class="text-base font-bold">\u2726 Meta Agent</span>
|
|
109
|
+
<span class="text-[10px] text-base-content/40 hidden sm:inline">\u62A5\u544A \xB7 \u95EE\u7B54 \xB7 VLM \xB7 \u4EE3\u7801</span>
|
|
110
|
+
</div>
|
|
111
|
+
<div class="flex items-center gap-1">
|
|
112
|
+
<button type="button" id="ma-btn-chat" class="btn btn-xs btn-ghost border border-primary/40 text-primary">\u5BF9\u8BDD</button>
|
|
113
|
+
<button type="button" id="ma-btn-history" class="btn btn-xs btn-ghost border border-base-300" title="\u5386\u53F2\u5BF9\u8BDD">\u5386\u53F2</button>
|
|
114
|
+
<button type="button" id="ma-btn-notes" class="btn btn-xs btn-ghost border border-base-300" title="\u5DE5\u4F5C\u8BB0\u4E8B">\u8BB0\u4E8B</button>
|
|
115
|
+
<button type="button" id="ma-btn-report" class="btn btn-xs btn-ghost border border-base-300">\u62A5\u544A</button>
|
|
116
|
+
<button type="button" id="ma-btn-config" class="btn btn-xs btn-ghost border border-base-300" title="AI \u914D\u7F6E">\u2699</button>
|
|
117
|
+
<button type="button" id="ma-btn-close" class="btn btn-xs btn-ghost" data-ma-close="1">\u2715</button>
|
|
118
|
+
</div>
|
|
119
|
+
</header>
|
|
120
|
+
|
|
121
|
+
<div id="ma-mode-chat" class="meta-agent-body flex flex-col min-h-0 flex-1">
|
|
122
|
+
<div class="flex items-center gap-1 px-2 py-1 border-b border-base-300 flex-shrink-0 overflow-x-auto">
|
|
123
|
+
<button type="button" id="ma-new-chat" class="btn btn-ghost btn-xs">\uFF0B \u65B0\u5BF9\u8BDD</button>
|
|
124
|
+
<button type="button" id="ma-open-history" class="btn btn-ghost btn-xs" title="\u5386\u53F2\u5217\u8868">\u2630 \u5386\u53F2</button>
|
|
125
|
+
<span id="ma-session-title" class="text-[11px] text-base-content/55 truncate flex-1 min-w-0 px-1"></span>
|
|
126
|
+
<button type="button" id="ma-del-session" class="btn btn-ghost btn-xs text-error" title="\u5220\u9664\u5F53\u524D\u4F1A\u8BDD">\u{1F5D1}</button>
|
|
127
|
+
<button type="button" id="ma-quick-today" class="btn btn-ghost btn-xs text-[10px]">\u4ECA\u5929\u505A\u4E86\u5565</button>
|
|
128
|
+
<button type="button" id="ma-quick-projects" class="btn btn-ghost btn-xs text-[10px]">\u9879\u76EE\u6982\u51B5</button>
|
|
129
|
+
</div>
|
|
130
|
+
<div id="ma-resume-bar" class="hidden px-3 py-1.5 border-b border-primary/30 bg-primary/10 text-[11px] flex items-center gap-2 flex-shrink-0">
|
|
131
|
+
<span id="ma-resume-text" class="flex-1 min-w-0 truncate text-base-content/70"></span>
|
|
132
|
+
<button type="button" id="ma-resume-focus" class="btn btn-primary btn-xs">\u7EE7\u7EED\u804A</button>
|
|
133
|
+
</div>
|
|
134
|
+
<div id="ma-messages" class="flex-1 overflow-y-auto p-3 flex flex-col gap-2"></div>
|
|
135
|
+
<div id="ma-attach-bar" class="hidden px-3 pt-1 flex flex-wrap gap-1"></div>
|
|
136
|
+
<div class="flex gap-2 items-end px-3 py-2 border-t border-base-300 bg-base-200 flex-shrink-0">
|
|
137
|
+
<label class="btn btn-ghost btn-sm px-2 cursor-pointer" title="\u6DFB\u52A0\u56FE\u7247 (VLM)" style="height:40px">
|
|
138
|
+
\u{1F5BC}
|
|
139
|
+
<input type="file" id="ma-image-input" accept="image/*" multiple class="hidden">
|
|
140
|
+
</label>
|
|
141
|
+
<textarea id="ma-input" rows="1" placeholder="\u7EE7\u7EED\u63D0\u95EE\u2026 (\u2318\u21B5 \u53D1\u9001) \xB7 \u5386\u53F2\u4F1A\u8BDD\u4F1A\u5E26\u7740\u4E0A\u4E0B\u6587"
|
|
142
|
+
class="textarea textarea-bordered flex-1 text-sm resize-none leading-relaxed"
|
|
143
|
+
style="min-height:40px;max-height:120px"
|
|
144
|
+
name="meta-agent-message"
|
|
145
|
+
autocomplete="off"
|
|
146
|
+
autocorrect="off"
|
|
147
|
+
autocapitalize="off"
|
|
148
|
+
spellcheck="false"
|
|
149
|
+
data-1p-ignore="true"
|
|
150
|
+
data-lpignore="true"
|
|
151
|
+
data-form-type="other"
|
|
152
|
+
data-bwignore="true"></textarea>
|
|
153
|
+
<button type="button" id="ma-send" class="btn btn-primary btn-sm" style="height:40px">\u53D1\u9001</button>
|
|
154
|
+
</div>
|
|
155
|
+
</div>
|
|
156
|
+
|
|
157
|
+
<div id="ma-mode-history" class="meta-agent-body hidden flex-col min-h-0 flex-1">
|
|
158
|
+
<div class="flex items-center gap-2 px-3 py-2 border-b border-base-300 flex-shrink-0">
|
|
159
|
+
<input id="ma-history-search" type="search" placeholder="\u641C\u7D22\u6807\u9898 / \u9884\u89C8\u2026"
|
|
160
|
+
class="input input-xs input-bordered flex-1 text-xs" autocomplete="off">
|
|
161
|
+
<button type="button" id="ma-history-refresh" class="btn btn-ghost btn-xs">\u21BB</button>
|
|
162
|
+
<button type="button" id="ma-history-new" class="btn btn-primary btn-xs">\uFF0B \u65B0\u5BF9\u8BDD</button>
|
|
163
|
+
</div>
|
|
164
|
+
<div id="ma-history-list" class="flex-1 overflow-y-auto p-2 flex flex-col gap-1"></div>
|
|
165
|
+
<p class="text-[10px] text-base-content/40 px-3 py-2 border-t border-base-300 flex-shrink-0">
|
|
166
|
+
\u70B9\u51FB\u4F1A\u8BDD\u53EF\u67E5\u770B\u5B8C\u6574\u8BB0\u5F55\uFF1B\u53D1\u9001\u65B0\u6D88\u606F\u5373 resume\uFF08\u4FDD\u7559 tool / VLM \u4E0A\u4E0B\u6587\uFF09\u3002
|
|
167
|
+
</p>
|
|
168
|
+
</div>
|
|
169
|
+
|
|
170
|
+
<div id="ma-mode-notes" class="meta-agent-body hidden flex min-h-0 flex-1">
|
|
171
|
+
<div class="w-[44%] min-w-[180px] max-w-[240px] border-r border-base-300 flex flex-col">
|
|
172
|
+
<div class="flex items-center gap-2 px-3 py-2 border-b border-base-300 flex-shrink-0">
|
|
173
|
+
<input id="ma-notes-search" type="search" placeholder="\u641C\u7D22\u8BB0\u4E8B\u2026"
|
|
174
|
+
class="input input-xs input-bordered flex-1 text-xs" autocomplete="off">
|
|
175
|
+
<button type="button" id="ma-notes-refresh" class="btn btn-ghost btn-xs">\u21BB</button>
|
|
176
|
+
<button type="button" id="ma-notes-new" class="btn btn-primary btn-xs">\uFF0B</button>
|
|
177
|
+
</div>
|
|
178
|
+
<div id="ma-notes-list" class="flex-1 overflow-y-auto p-2 flex flex-col gap-1"></div>
|
|
179
|
+
</div>
|
|
180
|
+
<div class="flex-1 min-w-0 flex flex-col">
|
|
181
|
+
<div class="px-3 py-2 border-b border-base-300 text-[11px] text-base-content/45 flex items-center gap-2 flex-wrap">
|
|
182
|
+
<span>\u8BB0\u4E8B\u4FDD\u5B58\u5728 Hub\uFF0C\u53EF\u88AB Meta Agent \u68C0\u7D22\u3002</span>
|
|
183
|
+
<span id="ma-note-links" class="truncate"></span>
|
|
184
|
+
</div>
|
|
185
|
+
<div class="p-3 flex flex-col gap-3 flex-1 overflow-y-auto">
|
|
186
|
+
<label class="form-control">
|
|
187
|
+
<span class="label-text text-xs">\u6807\u9898</span>
|
|
188
|
+
<input id="ma-note-title" class="input input-sm input-bordered text-sm" placeholder="\u4F8B\u5982\uFF1A\u53D1\u5E03\u524D\u9057\u7559\u95EE\u9898">
|
|
189
|
+
</label>
|
|
190
|
+
<label class="form-control flex-1">
|
|
191
|
+
<span class="label-text text-xs">\u5185\u5BB9</span>
|
|
192
|
+
<textarea id="ma-note-content" class="textarea textarea-bordered text-sm min-h-[220px]" placeholder="\u8BB0\u5F55\u51B3\u7B56\u3001\u98CE\u9669\u3001\u5F85\u529E\u3001\u6392\u67E5\u7EBF\u7D22\u2026"></textarea>
|
|
193
|
+
</label>
|
|
194
|
+
<div class="flex flex-wrap items-center gap-3 text-xs">
|
|
195
|
+
<label class="flex items-center gap-1 cursor-pointer">
|
|
196
|
+
<input type="checkbox" id="ma-note-pin" class="checkbox checkbox-xs">
|
|
197
|
+
\u7F6E\u9876
|
|
198
|
+
</label>
|
|
199
|
+
<label class="flex items-center gap-1 cursor-pointer">
|
|
200
|
+
<input type="checkbox" id="ma-note-link-project" class="checkbox checkbox-xs">
|
|
201
|
+
\u5173\u8054\u5F53\u524D\u9879\u76EE
|
|
202
|
+
</label>
|
|
203
|
+
<label class="flex items-center gap-1 cursor-pointer">
|
|
204
|
+
<input type="checkbox" id="ma-note-link-session" class="checkbox checkbox-xs">
|
|
205
|
+
\u5173\u8054\u5F53\u524D session
|
|
206
|
+
</label>
|
|
207
|
+
</div>
|
|
208
|
+
<div class="flex items-center justify-between gap-2">
|
|
209
|
+
<span id="ma-note-status" class="text-xs text-base-content/45"></span>
|
|
210
|
+
<div class="flex items-center gap-2">
|
|
211
|
+
<button type="button" id="ma-note-ask" class="btn btn-ghost btn-sm">\u5FEB\u6377\u63D0\u95EE</button>
|
|
212
|
+
<button type="button" id="ma-note-delete" class="btn btn-ghost btn-sm text-error">\u5220\u9664</button>
|
|
213
|
+
<button type="button" id="ma-note-save" class="btn btn-primary btn-sm">\u4FDD\u5B58\u8BB0\u4E8B</button>
|
|
214
|
+
</div>
|
|
215
|
+
</div>
|
|
216
|
+
</div>
|
|
217
|
+
</div>
|
|
218
|
+
</div>
|
|
219
|
+
|
|
220
|
+
<div id="ma-mode-report" class="meta-agent-body hidden flex-col min-h-0 flex-1">
|
|
221
|
+
<div class="flex items-center gap-2 px-3 py-2 border-b border-base-300 flex-shrink-0 flex-wrap">
|
|
222
|
+
<select id="ma-report-days" class="select select-xs select-bordered">
|
|
223
|
+
<option value="1">\u4ECA\u5929</option>
|
|
224
|
+
<option value="3">\u8FD1 3 \u5929</option>
|
|
225
|
+
<option value="7">\u8FD1 7 \u5929</option>
|
|
226
|
+
</select>
|
|
227
|
+
<button type="button" id="ma-gen-report" class="btn btn-primary btn-xs">\u751F\u6210\u62A5\u544A</button>
|
|
228
|
+
<button type="button" id="ma-load-reports" class="btn btn-ghost btn-xs">\u5386\u53F2</button>
|
|
229
|
+
<label class="flex items-center gap-1 text-[11px] ml-auto cursor-pointer select-none">
|
|
230
|
+
<input type="checkbox" id="ma-auto-report" class="checkbox checkbox-xs">
|
|
231
|
+
\u81EA\u52A8\u65E5\u62A5
|
|
232
|
+
</label>
|
|
233
|
+
<select id="ma-auto-hour" class="select select-xs select-bordered w-16" title="\u81EA\u52A8\u751F\u6210\u65F6\u523B">
|
|
234
|
+
${Array.from({length:24},(e,t)=>`<option value="${t}">${String(t).padStart(2,"0")}:00</option>`).join("")}
|
|
235
|
+
</select>
|
|
236
|
+
</div>
|
|
237
|
+
<div id="ma-report-list" class="hidden border-b border-base-300 max-h-28 overflow-y-auto px-2 py-1"></div>
|
|
238
|
+
<div id="ma-report-body" class="flex-1 overflow-y-auto p-4">
|
|
239
|
+
<div class="text-sm text-base-content/45 text-center py-10">
|
|
240
|
+
\u70B9\u51FB\u300C\u751F\u6210\u62A5\u544A\u300D\u6C47\u603B\u4F1A\u8BDD\u4E0E\u9879\u76EE\u6D3B\u52A8\uFF0C\u6216\u5728\u5BF9\u8BDD\u91CC\u95EE\u300C\u6211\u4ECA\u5929\u505A\u4E86\u4EC0\u4E48\u300D\u3002
|
|
241
|
+
</div>
|
|
242
|
+
</div>
|
|
243
|
+
</div>
|
|
244
|
+
|
|
245
|
+
<div id="ma-mode-config" class="meta-agent-body hidden flex-col min-h-0 flex-1 overflow-y-auto p-4 gap-3">
|
|
246
|
+
<p class="text-xs text-base-content/50">OpenAI \u517C\u5BB9 API\uFF08DeepSeek / OpenAI / \u672C\u5730\u7F51\u5173\u7B49\uFF09\u3002Key \u4FDD\u5B58\u5728\u670D\u52A1\u7AEF <code>.ai_config.json</code>\u3002</p>
|
|
247
|
+
<label class="form-control">
|
|
248
|
+
<span class="label-text text-xs">API URL</span>
|
|
249
|
+
<input id="ma-cfg-url" class="input input-sm input-bordered font-mono text-xs" placeholder="https://api.deepseek.com/chat/completions">
|
|
250
|
+
</label>
|
|
251
|
+
<label class="form-control">
|
|
252
|
+
<span class="label-text text-xs">API Key</span>
|
|
253
|
+
<input id="ma-cfg-key" type="password" class="input input-sm input-bordered" placeholder="\u7559\u7A7A\u5219\u4E0D\u4FEE\u6539">
|
|
254
|
+
</label>
|
|
255
|
+
<label class="form-control">
|
|
256
|
+
<span class="label-text text-xs">\u4E3B\u6A21\u578B</span>
|
|
257
|
+
<input id="ma-cfg-model" class="input input-sm input-bordered font-mono text-xs" placeholder="deepseek-chat">
|
|
258
|
+
</label>
|
|
259
|
+
<div class="divider text-xs my-1">VLM \u591A\u6A21\u6001\uFF08\u53EF\u7559\u7A7A\u5171\u7528\u4E0A\u65B9\uFF09</div>
|
|
260
|
+
<label class="form-control">
|
|
261
|
+
<span class="label-text text-xs">VLM URL</span>
|
|
262
|
+
<input id="ma-cfg-vlm-url" class="input input-sm input-bordered font-mono text-xs" placeholder="\u53EF\u9009">
|
|
263
|
+
</label>
|
|
264
|
+
<label class="form-control">
|
|
265
|
+
<span class="label-text text-xs">VLM Key</span>
|
|
266
|
+
<input id="ma-cfg-vlm-key" type="password" class="input input-sm input-bordered" placeholder="\u53EF\u9009">
|
|
267
|
+
</label>
|
|
268
|
+
<label class="form-control">
|
|
269
|
+
<span class="label-text text-xs">VLM \u6A21\u578B</span>
|
|
270
|
+
<input id="ma-cfg-vlm-model" class="input input-sm input-bordered font-mono text-xs" placeholder="gpt-4o-mini / \u2026">
|
|
271
|
+
</label>
|
|
272
|
+
<label class="form-control">
|
|
273
|
+
<span class="label-text text-xs">System Prompt</span>
|
|
274
|
+
<textarea id="ma-cfg-system" class="textarea textarea-bordered textarea-sm text-xs min-h-[80px]"></textarea>
|
|
275
|
+
</label>
|
|
276
|
+
<div class="flex gap-2">
|
|
277
|
+
<button type="button" id="ma-cfg-save" class="btn btn-primary btn-sm">\u4FDD\u5B58</button>
|
|
278
|
+
<span id="ma-cfg-status" class="text-xs text-base-content/50 self-center"></span>
|
|
279
|
+
</div>
|
|
280
|
+
</div>
|
|
281
|
+
</div>
|
|
282
|
+
</div>`}function ye(e){ht=e;let t=i("ma-mode-chat"),n=i("ma-mode-history"),s=i("ma-mode-notes"),a=i("ma-mode-report"),o=i("ma-mode-config");for(let[d,l]of[[t,"chat"],[n,"history"],[s,"notes"],[a,"report"],[o,"config"]]){if(!d)continue;let c=e===l;d.classList.toggle("hidden",!c),d.classList.toggle("flex",c)}let r=(d,l)=>{let c=i(d);c&&(c.classList.toggle("border-primary/40",l),c.classList.toggle("text-primary",l))};r("ma-btn-chat",e==="chat"),r("ma-btn-history",e==="history"),r("ma-btn-notes",e==="notes"),r("ma-btn-report",e==="report"),e==="history"&&_t(),e==="notes"&&Dt()}function Un(){let e=i("ma-session-title"),t=i("ma-resume-bar"),n=i("ma-resume-text");if(!pe){e&&(e.textContent="\u65B0\u5BF9\u8BDD"),t?.classList.add("hidden");return}let s=Se?.title||pe.slice(0,8),a=Ns(Se?.updatedAt);if(e&&(e.textContent=a?`${s} \xB7 ${a}`:s),t&&n){t.classList.remove("hidden");let o=Se?.messageCount;n.textContent=o?`\u5DF2\u52A0\u8F7D\u5386\u53F2 \xB7 ${o} \u6761\u6D88\u606F \xB7 \u53D1\u9001\u5373\u53EF\u7EE7\u7EED`:"\u5DF2\u52A0\u8F7D\u5386\u53F2\u4F1A\u8BDD \xB7 \u53D1\u9001\u5373\u53EF\u7EE7\u7EED"}}function Oa(e="chat"){let t=i("meta-agent-panel");if(t){if(t.classList.remove("hidden"),t.setAttribute("aria-hidden","false"),Ds=!0,ye(e),e==="chat"){at();let n=localStorage.getItem(bt);!pe&&n?ot(n,{silent:!0}).catch(()=>{localStorage.removeItem(bt)}):Un()}e==="history"&&at().then(()=>_t()),e==="report"&&Bi(),e==="config"&&Oi(),setTimeout(()=>{ht==="chat"&&i("ma-input")?.focus(),ht==="history"&&i("ma-history-search")?.focus()},50)}}function Ni(){let e=i("meta-agent-panel");e&&(e.classList.add("hidden"),e.setAttribute("aria-hidden","true"),Ds=!1)}function _i(){Ds?Ni():Oa(ht==="config"?"chat":ht)}function Z(e,t,n={}){let s=i("ma-messages");if(!s)return null;let a=document.createElement("div");return a.className=`ma-msg ma-msg-${e}`,e==="user"?a.innerHTML=`<div class="ma-bubble user">${p(t)}</div>`:e==="assistant"?(a.innerHTML=`<div class="ma-bubble assistant md">${xn(t)}</div>`,vn(a)):e==="error"?a.innerHTML=`<div class="ma-bubble error">${p(t)}</div>`:e==="system"?a.innerHTML=`<div class="ma-sys">${p(t)}</div>`:e==="tool"&&(a.innerHTML=`<div class="ma-tool" data-tool-id="${p(n.id||"")}">
|
|
283
|
+
<span class="ma-tool-name">${p(n.name||"tool")}</span>
|
|
284
|
+
<span class="ma-tool-phase">${p(n.phase||"")}</span>
|
|
285
|
+
<pre class="ma-tool-args">${p(JSON.stringify(n.args||{},null,0).slice(0,200))}</pre>
|
|
286
|
+
</div>`),s.appendChild(a),s.scrollTop=s.scrollHeight,a}function Mi(e,t){let n=e?.querySelector(".ma-bubble");n&&(n.innerHTML=xn(t),vn(n),i("ma-messages").scrollTop=i("ma-messages").scrollHeight)}function Pi(e,t,n){let s=i("ma-messages");if(!s)return;let a=s.querySelector(`[data-tool-id="${CSS.escape(e)}"]`);if(!a)return;a.classList.toggle("done",t==="done"),a.classList.toggle("error",t==="error");let o=a.querySelector(".ma-tool-phase");if(o&&(o.textContent=t),n&&t!=="start"){let r=a.querySelector(".ma-tool-result");r||(r=document.createElement("pre"),r.className="ma-tool-result",a.appendChild(r)),r.textContent=JSON.stringify(n,null,0).slice(0,500)}}function _l(e){let t=i("ma-messages");if(!t)return;let n=document.createElement("div");n.className="ma-approval",n.dataset.approvalId=e.id;let s=e.args?.command??"";n.innerHTML=`
|
|
287
|
+
<div class="ma-approval-label">\u26A0 Agent \u60F3\u8981\u6267\u884C\u547D\u4EE4\uFF0C\u662F\u5426\u5141\u8BB8\uFF1F</div>
|
|
288
|
+
<pre class="ma-approval-cmd">${p(s)}</pre>
|
|
289
|
+
<div class="ma-approval-actions">
|
|
290
|
+
<button type="button" class="btn btn-xs btn-error" data-approve="0">\u62D2\u7EDD</button>
|
|
291
|
+
<button type="button" class="btn btn-xs btn-success" data-approve="1">\u5141\u8BB8\u6267\u884C</button>
|
|
292
|
+
</div>`,n.querySelectorAll("[data-approve]").forEach(a=>{a.addEventListener("click",async()=>{let o=a.dataset.approve==="1";n.querySelectorAll("button").forEach(r=>{r.disabled=!0}),n.querySelector(".ma-approval-label").textContent=o?"\u2713 \u5DF2\u5141\u8BB8\uFF0C\u6B63\u5728\u6267\u884C\u2026":"\u2717 \u5DF2\u62D2\u7EDD";try{await y("POST","/api/ai/approve",{id:e.id,approved:o})}catch(r){n.querySelector(".ma-approval-label").textContent=`\u786E\u8BA4\u5931\u8D25\uFF1A${r.message}`}})}),t.appendChild(n),t.scrollTop=t.scrollHeight}function Pl(){return Ti+=1,`img${Ti}`}function Hl(e,t){if(!e)return;let n=e.selectionStart??e.value.length,s=e.selectionEnd??e.value.length;e.value=e.value.slice(0,n)+t+e.value.slice(s),e.selectionStart=e.selectionEnd=n+t.length,e.dispatchEvent(new Event("input"))}async function Ii(e,t){let n=dt({"x-filename":t||`paste-${Date.now()}.png`});delete n["Content-Type"];let s=await fetch("/api/upload-image",{method:"POST",headers:n,body:e});if(!s.ok){let c=await s.json().catch(()=>({}));throw new Error(c.error||`Upload failed: ${s.status}`)}let{path:a}=await s.json();if(!a)throw new Error("upload returned no path");let o=Pl(),r=`[${o}](${a})`,d=i("ma-input");Hl(d,(d?.value&&!d.value.endsWith(`
|
|
293
|
+
`)&&d.value.length?`
|
|
294
|
+
`:"")+r+`
|
|
295
|
+
`);let l="";try{l=URL.createObjectURL(e)}catch{}return jt.push({path:a,previewUrl:l,label:o,ref:r}),qa(),{path:a,ref:r,label:o}}function qa(){let e=i("ma-attach-bar");if(e){if(!jt.length){e.classList.add("hidden"),e.innerHTML="";return}e.classList.remove("hidden"),e.innerHTML=jt.map((t,n)=>`
|
|
296
|
+
<div class="ma-thumb relative" title="${p(t.ref||t.path)}">
|
|
297
|
+
${t.previewUrl?`<img src="${t.previewUrl}" alt="${p(t.label||"img")}">`:`<span class="ma-thumb-path">${p(t.label||"img")}</span>`}
|
|
298
|
+
<span class="ma-thumb-label">${p(t.label||"")}</span>
|
|
299
|
+
<button type="button" class="ma-thumb-x" data-rm-img="${n}">\u2715</button>
|
|
300
|
+
</div>`).join(""),e.querySelectorAll("[data-rm-img]").forEach(t=>{t.addEventListener("click",()=>{let n=parseInt(t.dataset.rmImg,10),s=jt[n];if(s?.previewUrl)try{URL.revokeObjectURL(s.previewUrl)}catch{}let a=i("ma-input");a&&s?.ref&&(a.value=a.value.split(s.ref).join("").replace(/\n{3,}/g,`
|
|
301
|
+
|
|
302
|
+
`),a.dispatchEvent(new Event("input"))),jt.splice(n,1),qa()})})}}function Ns(e){if(!e)return"";let t=new Date(e);if(Number.isNaN(t.getTime()))return"";let n=String(t.getMonth()+1).padStart(2,"0"),s=String(t.getDate()).padStart(2,"0"),a=String(t.getHours()).padStart(2,"0"),o=String(t.getMinutes()).padStart(2,"0");return`${n}-${s} ${a}:${o}`}async function at(){try{As=(await y("GET","/api/ai/sessions")).sessions||[]}catch{As=[]}return As}function Hi(){let e=E.peek(),t=f.sessionId?`${f.agent||I.peek()||"claude"}:${f.sessionId.slice(0,8)}`:"";return{project:e?.path||"",sessionId:f.sessionId||"",agent:f.agent||I.peek()||"claude",summary:[e?.name?`\u9879\u76EE ${e.name}`:"",t?`\u4F1A\u8BDD ${t}`:""].filter(Boolean).join(" \xB7 ")}}function Fn(){Nt=null,Di=null,i("ma-note-title").value="",i("ma-note-content").value="",i("ma-note-pin").checked=!1,i("ma-note-link-project").checked=!!E.peek()?.path,i("ma-note-link-session").checked=!!f.sessionId,i("ma-note-status").textContent="\u65B0\u8BB0\u4E8B",i("ma-note-delete").disabled=!0,i("ma-note-links").textContent=Hi().summary||"\u672A\u5173\u8054\u4E0A\u4E0B\u6587"}function Ri(e){Nt=e?.id||null,Di=e||null,i("ma-note-title").value=e?.title||"",i("ma-note-content").value=e?.content||"",i("ma-note-pin").checked=!!e?.pinned,i("ma-note-link-project").checked=!!e?.cwd,i("ma-note-link-session").checked=!!e?.sessionId,i("ma-note-status").textContent=e?.updatedAt?`\u4E0A\u6B21\u66F4\u65B0 ${Ns(e.updatedAt)}`:"",i("ma-note-delete").disabled=!e?.id;let t=[];e?.cwd&&t.push(`\u9879\u76EE ${e.cwd.split("/").pop()}`),e?.sessionId&&t.push(`\u4F1A\u8BDD ${e.agent||"claude"}:${e.sessionId.slice(0,8)}`),i("ma-note-links").textContent=t.join(" \xB7 ")||"\u672A\u5173\u8054\u4E0A\u4E0B\u6587"}function Rl(){let e=i("ma-note-title")?.value?.trim()||"",t=i("ma-note-content")?.value?.trim()||"";if(!e&&!t){i("ma-note-status").textContent="\u5148\u9009\u4E00\u6761\u8BB0\u4E8B\u6216\u8F93\u5165\u5185\u5BB9";return}let n=[];i("ma-note-link-project")?.checked&&E.peek()?.path&&n.push(`\u9879\u76EE\u8DEF\u5F84\uFF1A${E.peek().path}`),i("ma-note-link-session")?.checked&&f.sessionId&&n.push(`\u5173\u8054\u4F1A\u8BDD\uFF1A${f.agent||I.peek()||"claude"} / ${f.sessionId}`);let s=["\u57FA\u4E8E\u4E0B\u9762\u8FD9\u6761\u5DE5\u4F5C\u8BB0\u4E8B\u56DE\u7B54\uFF0C\u5E76\u7ED3\u5408\u76F8\u5173\u4F1A\u8BDD\u4E0E\u9879\u76EE\u4E0A\u4E0B\u6587\uFF1A",`\u6807\u9898\uFF1A${e||"\u672A\u547D\u540D"}`,t?`\u5185\u5BB9\uFF1A
|
|
303
|
+
${t}`:"",n.length?n.join(`
|
|
304
|
+
`):"","","\u8BF7\u5148\u603B\u7ED3\u8FD9\u6761\u8BB0\u4E8B\u7684\u6838\u5FC3\uFF0C\u518D\u7ED9\u51FA\u4E0B\u4E00\u6B65\u5EFA\u8BAE\u548C\u53EF\u80FD\u98CE\u9669\u3002"].filter(Boolean).join(`
|
|
305
|
+
`);ye("chat"),i("ma-input").value=s,i("ma-input").dispatchEvent(new Event("input")),i("ma-input").focus()}async function gn(){let e=(ji||"").trim();return js=(await y("GET",`/api/ai/notes?limit=80${e?`&q=${encodeURIComponent(e)}`:""}`)).notes||[],js}function Dt(){let e=i("ma-notes-list");if(e){if(!js.length){e.innerHTML='<div class="text-center text-xs text-base-content/40 py-10">\u8FD8\u6CA1\u6709\u8BB0\u4E8B\u3002</div>';return}e.innerHTML=js.map(t=>{let n=t.id===Nt,s=[t.scope==="project"?"\u9879\u76EE":t.scope==="session"?"\u4F1A\u8BDD":"\u901A\u7528",t.pinned?"\u7F6E\u9876":""].filter(Boolean).join(" \xB7 ");return`
|
|
306
|
+
<button type="button" class="ma-note-item ${n?"active":""}" data-note-id="${p(t.id)}">
|
|
307
|
+
<div class="text-left">
|
|
308
|
+
<div class="font-medium text-xs truncate">${p(t.title||"\u672A\u547D\u540D")}</div>
|
|
309
|
+
<div class="text-[10px] text-base-content/45 mt-0.5 line-clamp-2">${p(t.content||"")}</div>
|
|
310
|
+
<div class="text-[10px] text-base-content/35 mt-1">${p(s)}${s?" \xB7 ":""}${p(Ns(t.updatedAt)||"")}</div>
|
|
311
|
+
</div>
|
|
312
|
+
</button>`}).join(""),e.querySelectorAll("[data-note-id]").forEach(t=>{t.addEventListener("click",async()=>{try{let n=await y("GET",`/api/ai/notes/${t.dataset.noteId}`);Ri(n),Dt()}catch(n){i("ma-note-status").textContent=n.message}})})}}async function Bl(){let e=i("ma-note-title")?.value?.trim()||"",t=i("ma-note-content")?.value?.trim()||"";if(!e||!t){i("ma-note-status").textContent="\u6807\u9898\u548C\u5185\u5BB9\u90FD\u4E0D\u80FD\u4E3A\u7A7A";return}let n=Hi(),s={id:Nt||void 0,title:e,content:t,pinned:!!i("ma-note-pin")?.checked,cwd:i("ma-note-link-project")?.checked?n.project:"",sessionId:i("ma-note-link-session")?.checked?n.sessionId:"",agent:i("ma-note-link-session")?.checked?n.agent:""};i("ma-note-status").textContent="\u4FDD\u5B58\u4E2D\u2026";let a=await y("POST","/api/ai/notes",s);Ri(a),await gn(),Dt()}async function Ol(){if(!Nt){Fn();return}confirm("\u5220\u9664\u8FD9\u6761\u8BB0\u4E8B\uFF1F\u4E0D\u53EF\u6062\u590D\u3002")&&(await y("DELETE",`/api/ai/notes/${Nt}`),Fn(),await gn(),Dt())}function _t(){let e=i("ma-history-list");if(!e)return;let t=(Ai||"").trim().toLowerCase(),n=As;if(t&&(n=n.filter(s=>`${s.title||""} ${s.preview||""} ${s.id||""}`.toLowerCase().includes(t))),!n.length){e.innerHTML=`<div class="text-center text-xs text-base-content/40 py-10">
|
|
313
|
+
${t?"\u6CA1\u6709\u5339\u914D\u7684\u4F1A\u8BDD":"\u8FD8\u6CA1\u6709\u5386\u53F2\u5BF9\u8BDD\u3002\u53D1\u4E00\u6761\u6D88\u606F\u540E\u4F1A\u51FA\u73B0\u5728\u8FD9\u91CC\u3002"}
|
|
314
|
+
</div>`;return}e.innerHTML=n.map(s=>{let a=s.id===pe,o=Ns(s.updatedAt)||"",r=s.messageCount||0;return`
|
|
315
|
+
<div class="ma-hist-item ${a?"active":""}" data-hist-id="${p(s.id)}">
|
|
316
|
+
<div class="flex items-start gap-2">
|
|
317
|
+
<button type="button" class="ma-hist-open flex-1 min-w-0 text-left" data-hist-open="${p(s.id)}">
|
|
318
|
+
<div class="font-medium text-xs truncate">${p(s.title||s.id.slice(0,8))}</div>
|
|
319
|
+
<div class="text-[10px] text-base-content/45 mt-0.5 line-clamp-2">${p(s.preview||"\uFF08\u65E0\u9884\u89C8\uFF09")}</div>
|
|
320
|
+
<div class="text-[10px] text-base-content/35 mt-1">${p(o)}${r?` \xB7 ${r} \u6761`:""}${a?" \xB7 \u5F53\u524D":""}</div>
|
|
321
|
+
</button>
|
|
322
|
+
<div class="flex flex-col gap-0.5 flex-shrink-0">
|
|
323
|
+
<button type="button" class="btn btn-ghost btn-xs px-1" data-hist-resume="${p(s.id)}" title="\u6253\u5F00\u5E76\u7EE7\u7EED">\u21B5</button>
|
|
324
|
+
<button type="button" class="btn btn-ghost btn-xs px-1 text-error" data-hist-del="${p(s.id)}" title="\u5220\u9664">\u2715</button>
|
|
325
|
+
</div>
|
|
326
|
+
</div>
|
|
327
|
+
</div>`}).join(""),e.querySelectorAll("[data-hist-open]").forEach(s=>{s.addEventListener("click",async()=>{await ot(s.dataset.histOpen),ye("chat"),i("ma-input")?.focus()})}),e.querySelectorAll("[data-hist-resume]").forEach(s=>{s.addEventListener("click",async a=>{a.stopPropagation(),await ot(s.dataset.histResume),ye("chat"),i("ma-input")?.focus()})}),e.querySelectorAll("[data-hist-del]").forEach(s=>{s.addEventListener("click",async a=>{a.stopPropagation();let o=s.dataset.histDel;if(confirm("\u5220\u9664\u8BE5\u5386\u53F2\u4F1A\u8BDD\uFF1F\u4E0D\u53EF\u6062\u590D\u3002"))try{await y("DELETE",`/api/ai/sessions/${o}`),pe===o&&(pe=null,Se=null,localStorage.removeItem(bt),ot(null)),await at(),_t()}catch(r){alert(r.message)}})})}function Ci(e){return typeof e=="string"?e:Array.isArray(e)&&e.map(t=>typeof t=="string"?t:t?.type==="text"?t.text||"":t?.type==="image_url"?"[\u56FE\u7247]":"").filter(Boolean).join(`
|
|
328
|
+
`)||"[\u2026]"}function ql(e){let t=i("ma-messages");if(t){if(t.innerHTML="",!e?.length){Z("system","\u6B64\u4F1A\u8BDD\u6682\u65E0\u6D88\u606F\u3002");return}for(let n of e){if(n.role==="user"){Z("user",Ci(n.content));continue}if(n.role==="assistant"){if(n.tool_calls?.length)for(let s of n.tool_calls){let a=s.function?.name||s.name||"tool",o={};try{o=JSON.parse(s.function?.arguments||s.arguments||"{}")}catch{}Z("tool","",{name:a,args:o,phase:"history",id:s.id||a})}n.content&&Z("assistant",typeof n.content=="string"?n.content:Ci(n.content));continue}if(n.role==="tool"){let s=n.content;try{s=JSON.parse(n.content)}catch{}let a=n.tool_call_id||"";if(a)Pi(a,"done",s);else{Z("tool","",{name:"tool_result",args:{},phase:"done",id:`tr_${Math.random().toString(36).slice(2,8)}`});let o=t.querySelectorAll(".ma-tool"),r=o[o.length-1];if(r){r.classList.add("done");let d=r.querySelector(".ma-tool-result");d||(d=document.createElement("pre"),d.className="ma-tool-result",r.appendChild(d)),d.textContent=typeof s=="string"?s.slice(0,500):JSON.stringify(s,null,0).slice(0,500)}}}}t.scrollTop=t.scrollHeight}}async function Fl(){if(!pe){await ot(null);return}if(confirm("\u5220\u9664\u5F53\u524D Meta Agent \u4F1A\u8BDD\uFF1F\u6B64\u64CD\u4F5C\u4E0D\u53EF\u6062\u590D\u3002"))try{await y("DELETE",`/api/ai/sessions/${pe}`),pe=null,Se=null,localStorage.removeItem(bt),await at(),await ot(null),ht==="history"&&_t()}catch(e){Z("error",e.message)}}async function ot(e,t={}){if(!e){pe=null,Se=null,localStorage.removeItem(bt);let n=i("ma-messages");return n&&(n.innerHTML=""),Z("system","\u65B0\u5BF9\u8BDD \u2014 \u8D34\u56FE \u2192 [imgN](\u8DEF\u5F84)\uFF1B\u9700\u8981\u770B\u56FE\u65F6\u8C03\u7528 VLM\u3002\u5386\u53F2\u5728\u300C\u5386\u53F2\u300D\u9875\uFF0C\u53EF\u968F\u65F6 resume\u3002"),Un(),null}try{let n=await y("GET",`/api/ai/sessions/${e}`);return pe=n.id,Se={id:n.id,title:n.title,updatedAt:n.updatedAt,messageCount:(n.messages||[]).length},localStorage.setItem(bt,n.id),ql(n.messages||[]),t.silent||Z("system","\u2191 \u5386\u53F2\u5DF2\u52A0\u8F7D\u3002\u5728\u4E0B\u65B9\u7EE7\u7EED\u8F93\u5165\u5373\u53EF resume\uFF08\u670D\u52A1\u7AEF\u4FDD\u7559\u5B8C\u6574 tool / VLM \u4E0A\u4E0B\u6587\uFF09\u3002"),Un(),ht==="history"&&_t(),n}catch(n){throw t.silent||Z("error",n.message),n}}async function Cs(){if(bn)return;let e=i("ma-input"),t=(e?.value||"").trim();if(!t)return;bn=!0,i("ma-send").disabled=!0,Z("user",t),e.value="",e.style.height="";for(let a of jt)if(a.previewUrl)try{URL.revokeObjectURL(a.previewUrl)}catch{}jt=[],qa();let n=null,s="";try{await Ba("/api/ai/chat",{message:t,sessionId:pe},{session:a=>{pe=a.id,Se={...Se||{},id:a.id,title:a.title||Se?.title||t.slice(0,40),updatedAt:Date.now()},localStorage.setItem(bt,a.id),Un()},content:a=>{s=a.content||"",n||(n=Z("assistant","")),Mi(n,s)},tool:a=>{a.phase==="start"?Z("tool","",{name:a.name,args:a.args,phase:"start",id:a.id}):Pi(a.id,a.phase,a.result)},approval:a=>_l(a),done:a=>{a.sessionId&&(pe=a.sessionId,localStorage.setItem(bt,a.sessionId)),(a.title||a.sessionId)&&(Se={id:pe,title:a.title||Se?.title||"\u5BF9\u8BDD",updatedAt:Date.now(),messageCount:(Se?.messageCount||0)+2}),a.content&&n&&Mi(n,a.content),Un(),at()},error:a=>{Z("error",a.message||"error")}})}catch(a){Z("error",a.message)}finally{bn=!1,i("ma-send").disabled=!1}}async function Ul(){if(bn)return;bn=!0;let e=parseInt(i("ma-report-days")?.value||"1",10),t=i("ma-report-body");t.innerHTML=`<div class="text-sm text-base-content/50 py-6 text-center">\u6B63\u5728\u6C47\u603B\u8FD1 ${e} \u5929\u6D3B\u52A8\u2026</div>`,i("ma-gen-report").disabled=!0;let n="",s=document.createElement("div");s.className="ma-report-tools flex flex-col gap-1 mb-3";try{await Ba("/api/ai/report",{days:e},{content:a=>{n=a.content||"",t.innerHTML="",t.appendChild(s);let o=document.createElement("div");o.className="md ma-report-md",o.innerHTML=xn(n),vn(o),t.appendChild(o)},tool:a=>{if(a.phase==="start"){let o=document.createElement("div");o.className="ma-tool",o.dataset.toolId=a.id||a.name,o.innerHTML=`<span class="ma-tool-name">${p(a.name)}</span> <span class="ma-tool-phase">start</span>`,s.appendChild(o)}else{let o=s.querySelector(`[data-tool-id="${CSS.escape(a.id||a.name)}"]`);o&&(o.classList.add(a.phase==="error"?"error":"done"),o.querySelector(".ma-tool-phase").textContent=a.phase)}},done:a=>{if(a.content){t.innerHTML="",t.appendChild(s);let o=document.createElement("div");o.className="md ma-report-md",o.innerHTML=xn(a.content),vn(o),t.appendChild(o)}},error:a=>{t.innerHTML=`<div class="alert alert-error text-sm">${p(a.message)}</div>`}})}catch(a){t.innerHTML=`<div class="alert alert-error text-sm">${p(a.message)}</div>`}finally{bn=!1,i("ma-gen-report").disabled=!1}}async function Bi(){try{let e=new Date,t=`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`,n=await y("GET",`/api/ai/reports/${t}`);if(n?.markdown){let s=i("ma-report-body");s.innerHTML=`
|
|
329
|
+
<div class="text-[10px] text-base-content/40 mb-2">${p(n.title||t)} \xB7 ${p(n.generatedAt||"")}</div>
|
|
330
|
+
<div class="md ma-report-md">${xn(n.markdown)}</div>`,vn(s)}}catch{}}async function Wl(){let e=i("ma-report-list");try{let t=await y("GET","/api/ai/reports");e.classList.remove("hidden");let n=t.reports||[];if(!n.length){e.innerHTML='<div class="text-xs text-base-content/40 px-2 py-1">\u6682\u65E0\u5386\u53F2\u62A5\u544A</div>';return}e.innerHTML=n.map(s=>`
|
|
331
|
+
<button type="button" class="ma-report-item w-full text-left px-2 py-1 rounded hover:bg-base-200 text-xs"
|
|
332
|
+
data-day="${p(s.day)}">
|
|
333
|
+
<span class="font-semibold">${p(s.day)}</span>
|
|
334
|
+
<span class="text-base-content/45 ml-1">${p(s.title||"")}</span>
|
|
335
|
+
</button>`).join(""),e.querySelectorAll("[data-day]").forEach(s=>{s.addEventListener("click",async()=>{try{let a=await y("GET",`/api/ai/reports/${s.dataset.day}`),o=i("ma-report-body");o.innerHTML=`
|
|
336
|
+
<div class="text-[10px] text-base-content/40 mb-2">${p(a.title||a.day)} \xB7 ${p(a.generatedAt||"")}</div>
|
|
337
|
+
<div class="md ma-report-md">${xn(a.markdown)}</div>`,vn(o)}catch(a){i("ma-report-body").innerHTML=`<div class="alert alert-error text-sm">${p(a.message)}</div>`}})})}catch(t){e.classList.remove("hidden"),e.innerHTML=`<div class="text-xs text-error px-2">${p(t.message)}</div>`}}async function Oi(){try{let e=await y("GET","/api/ai/config");i("ma-cfg-url").value=e.url||"",i("ma-cfg-model").value=e.model||"",i("ma-cfg-key").placeholder=e.hasKey?"\u5DF2\u914D\u7F6E \xB7 \u7559\u7A7A\u4E0D\u4FEE\u6539":"API Key",i("ma-cfg-key").value="",i("ma-cfg-vlm-url").value=e.vlm_url||"",i("ma-cfg-vlm-model").value=e.vlm_model||"",i("ma-cfg-vlm-key").value="",i("ma-cfg-vlm-key").placeholder=e.hasVlmKey?"\u5DF2\u914D\u7F6E \xB7 \u7559\u7A7A\u4E0D\u4FEE\u6539":"\u53EF\u9009",i("ma-cfg-system").value=e.system||"",i("ma-auto-report")&&(i("ma-auto-report").checked=!!e.auto_report),i("ma-auto-hour")&&(i("ma-auto-hour").value=String(e.auto_report_hour??18)),Wn(e)}catch(e){i("ma-cfg-status").textContent=e.message}}async function Gl(){let e=i("ma-cfg-status");e.textContent="\u4FDD\u5B58\u4E2D\u2026";try{let t={url:i("ma-cfg-url").value.trim(),model:i("ma-cfg-model").value.trim(),vlm_url:i("ma-cfg-vlm-url").value.trim(),vlm_model:i("ma-cfg-vlm-model").value.trim(),system:i("ma-cfg-system").value,auto_report:!!i("ma-auto-report")?.checked,auto_report_hour:parseInt(i("ma-auto-hour")?.value||"18",10)},n=i("ma-cfg-key").value.trim(),s=i("ma-cfg-vlm-key").value.trim();n&&(t.key=n),s&&(t.vlm_key=s);let a=await y("PUT","/api/ai/config",t);e.textContent=a.hasKey?"\u5DF2\u4FDD\u5B58 \u2713":"\u5DF2\u4FDD\u5B58\uFF08\u672A\u8BBE\u7F6E Key\uFF09",i("ma-cfg-key").value="",i("ma-cfg-vlm-key").value="",Wn(a)}catch(t){e.textContent=t.message}}function Wn(e){if(Is&&(clearInterval(Is),Is=null),!e?.auto_report)return;let t=e.auto_report_hour??18;Is=setInterval(async()=>{if(!f.token)return;let n=new Date;if(n.getHours()!==t)return;let s=`${n.getFullYear()}-${String(n.getMonth()+1).padStart(2,"0")}-${String(n.getDate()).padStart(2,"0")}`;if(Ra!==s&&!(n.getMinutes()>10))try{Ra=s,localStorage.setItem("ai_last_auto_report",s),await Ba("/api/ai/report",{days:e.auto_report_days||1},{done:()=>{console.info("[meta-agent] auto report saved for",s)},error:a=>console.warn("[meta-agent] auto report",a.message)})}catch(a){console.warn("[meta-agent] auto report failed",a),Ra="",localStorage.removeItem("ai_last_auto_report")}},60*1e3)}function qi(){i("meta-agent-panel")||(document.getElementById("root")?.insertAdjacentHTML("beforeend",Nl()),document.querySelectorAll("[data-ma-close]").forEach(e=>{e.addEventListener("click",Ni)}),i("ma-btn-chat")?.addEventListener("click",()=>ye("chat")),i("ma-btn-history")?.addEventListener("click",async()=>{await at(),ye("history")}),i("ma-btn-notes")?.addEventListener("click",async()=>{await gn(),Nt||Fn(),ye("notes")}),i("ma-open-history")?.addEventListener("click",async()=>{await at(),ye("history")}),i("ma-btn-report")?.addEventListener("click",()=>{ye("report"),Bi()}),i("ma-btn-config")?.addEventListener("click",()=>{ye("config"),Oi()}),i("ma-send")?.addEventListener("click",Cs),i("ma-input")?.addEventListener("keydown",e=>{(e.metaKey||e.ctrlKey)&&e.key==="Enter"&&(e.preventDefault(),Cs())}),i("ma-input")?.addEventListener("input",()=>{let e=i("ma-input");e.style.height="auto",e.style.height=Math.min(e.scrollHeight,120)+"px"}),i("ma-new-chat")?.addEventListener("click",()=>{ot(null),ye("chat")}),i("ma-del-session")?.addEventListener("click",Fl),i("ma-resume-focus")?.addEventListener("click",()=>{i("ma-input")?.focus()}),i("ma-history-refresh")?.addEventListener("click",async()=>{await at(),_t()}),i("ma-history-new")?.addEventListener("click",()=>{ot(null),ye("chat")}),i("ma-history-search")?.addEventListener("input",e=>{Ai=e.target.value||"",_t()}),i("ma-quick-today")?.addEventListener("click",()=>{ye("chat"),i("ma-input").value="\u6839\u636E\u6211\u6700\u8FD1\u7684\u4F1A\u8BDD\uFF0C\u603B\u7ED3\u4ECA\u5929\u6211\u505A\u4E86\u4EC0\u4E48\uFF1F\u6309\u9879\u76EE\u5217\u51FA\u4EAE\u70B9\u4E0E\u672A\u5B8C\u6210\u4E8B\u9879\u3002",Cs()}),i("ma-quick-projects")?.addEventListener("click",()=>{ye("chat"),i("ma-input").value="\u5217\u51FA\u6700\u8FD1 14 \u5929\u6D3B\u8DC3\u7684\u9879\u76EE\uFF0C\u6BCF\u4E2A\u9879\u76EE\u4E00\u53E5\u8BDD\u8BF4\u660E\u6700\u8FD1\u5728\u505A\u4EC0\u4E48\u3002",Cs()}),i("ma-gen-report")?.addEventListener("click",Ul),i("ma-load-reports")?.addEventListener("click",Wl),i("ma-notes-refresh")?.addEventListener("click",async()=>{await gn(),Dt()}),i("ma-notes-new")?.addEventListener("click",()=>{Fn(),Dt(),i("ma-note-title")?.focus()}),i("ma-notes-search")?.addEventListener("input",async e=>{ji=e.target.value||"",await gn(),Dt()}),i("ma-note-save")?.addEventListener("click",async()=>{try{await Bl()}catch(e){i("ma-note-status").textContent=e.message}}),i("ma-note-delete")?.addEventListener("click",async()=>{try{await Ol()}catch(e){i("ma-note-status").textContent=e.message}}),i("ma-note-ask")?.addEventListener("click",Rl),i("ma-cfg-save")?.addEventListener("click",Gl),i("ma-auto-report")?.addEventListener("change",async()=>{try{let e=await y("PUT","/api/ai/config",{auto_report:!!i("ma-auto-report").checked,auto_report_hour:parseInt(i("ma-auto-hour")?.value||"18",10)});Wn(e)}catch{}}),i("ma-auto-hour")?.addEventListener("change",async()=>{try{let e=await y("PUT","/api/ai/config",{auto_report:!!i("ma-auto-report")?.checked,auto_report_hour:parseInt(i("ma-auto-hour").value||"18",10)});Wn(e)}catch{}}),i("ma-image-input")?.addEventListener("change",async e=>{let t=[...e.target.files||[]],n=i("ma-input");n&&(n.disabled=!0);try{for(let s of t)if(s.type.startsWith("image/")){if(s.size>12*1024*1024){Z("error",`${s.name} \u8FC7\u5927 (>12MB)`);continue}await Ii(s,s.name||`upload-${Date.now()}.png`)}}catch(s){Z("error",`\u56FE\u7247\u4E0A\u4F20\u5931\u8D25: ${s.message}`)}finally{e.target.value="",n&&(n.disabled=!1,n.focus())}}),document.addEventListener("paste",async e=>{if(!Ds||ht!=="chat")return;let t=i("ma-input"),n=i("meta-agent-panel"),s=document.activeElement;if(!n||!s||!n.contains(s))return;let o=[...e.clipboardData?.items||[]].filter(r=>r.type.startsWith("image/"));if(o.length){e.preventDefault(),t&&(t.disabled=!0);try{for(let r of o){let d=r.getAsFile();if(!d)continue;let l=(r.type.split("/")[1]||"png").replace(/[^a-z0-9]/gi,"")||"png";await Ii(d,`paste-${Date.now()}.${l}`)}}catch(r){Z("error",`\u7C98\u8D34\u56FE\u7247\u5931\u8D25: ${r.message}`)}finally{t&&(t.disabled=!1,t.focus())}}}),ot(null,{silent:!0}),Fn())}function Gn(){f.token&&(A.peek()&&!Cn()||(at(),gn().catch(()=>{}),y("GET","/api/ai/config").then(Wn).catch(()=>{})))}var Ds,ht,bn,pe,Se,jt,Ti,Is,Ra,As,Ai,js,ji,Nt,Di,bt,Kn=K(()=>{R();ue();O();Ea();Ds=!1,ht="chat",bn=!1,pe=null,Se=null,jt=[],Ti=0,Is=null,Ra=localStorage.getItem("ai_last_auto_report")||"",As=[],Ai="",js=[],ji="",Nt=null,Di=null,bt="ma_last_session_id"});function Fa(e){return Array.isArray(e)?e:e&&Array.isArray(e.results)?e.results:e&&Array.isArray(e.sessions)?e.sessions:[]}function Ht(){let e=Fa(B.peek()),t=j.peek();A.peek()&&t&&(e=e.filter(s=>s&&(!s.machineId||s.machineId===t)));let n=de.peek();return n&&n!=="all"&&(e=e.filter(s=>s&&(s.agent||"claude")===n)),e}function Wi(e){let t=e.getFullYear(),n=String(e.getMonth()+1).padStart(2,"0"),s=String(e.getDate()).padStart(2,"0");return`${t}-${n}-${s}`}function Kl(e,t){let n=[],a=new Date(e,t,1).getDay(),r=new Date(e,t+1,0).getDate(),d=new Date(e,t,0).getDate();for(let c=a-1;c>=0;c--)n.push({date:new Date(e,t-1,d-c),isCurrentMonth:!1});for(let c=1;c<=r;c++)n.push({date:new Date(e,t,c),isCurrentMonth:!0});let l=7-n.length%7;if(l<7)for(let c=1;c<=l;c++)n.push({date:new Date(e,t+1,c),isCurrentMonth:!1});return n}function Gi(e,t){let n=new Date(e.getFullYear(),e.getMonth(),e.getDate()).getTime(),s=n+1440*60*1e3;return t.filter(a=>{let o=q(a.updatedAt);return o!=null&&o>=n&&o<s})}function Ki(e){return e==null||isNaN(e)?"0":e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function Rt(e){let t=i("calendar-grid");if(!t)return;e=Fa(e??Ht());let n=i("calendar-month-year");if(n){let u=new Date(_s,Pt,1);n.textContent=u.toLocaleDateString([],{month:"long",year:"numeric"})}let s=e.length,a=new Set(e.map(u=>u.cwd).filter(Boolean)).size,o=e.reduce((u,h)=>u+(Number(h.totalTokens)||0),0),r=i("stats-total-sessions"),d=i("stats-total-projects"),l=i("stats-total-tokens");r&&(r.textContent=String(s)),d&&(d.textContent=String(a)),l&&(l.textContent=Ki(o));let c=Kl(_s,Pt);zn||(zn=Wi(new Date)),t.innerHTML=c.map(u=>{let h=u.date,x=Wi(h),C=Gi(h,e).length,F=h.toDateString()===new Date().toDateString(),ke=x===zn,J="",ne="text-base-content/65",N="border border-transparent",S="cursor-default",_=u.isCurrentMonth?"":"opacity-25";C>0?(S="cursor-pointer",C<=2?(J="bg-primary/15",ne="text-primary font-bold",N="border border-primary/30"):C<=5?(J="bg-primary/30",ne="text-primary font-bold",N="border border-primary/50"):(J="bg-primary/60",ne="text-primary-content font-bold",N="border border-primary/80")):(J="bg-base-300/25",u.isCurrentMonth&&(S="hover:bg-base-300/50")),F?N="border-2 border-primary":ke&&(N="border-2 border-accent");let se=h.getDate()===1?`<span class="absolute top-0.5 left-1 text-[8px] opacity-60 uppercase">${h.toLocaleDateString([],{month:"short"})}</span>`:"";return`
|
|
338
|
+
<div class="aspect-square rounded-xl flex flex-col items-center justify-center p-2 relative transition-all min-h-[50px] md:min-h-[60px] ${J} ${ne} ${N} ${S} ${_}"
|
|
339
|
+
data-cal-date="${x}" title="${h.toDateString()}: ${C} session(s)">
|
|
340
|
+
${se}
|
|
341
|
+
<span class="text-sm font-semibold">${h.getDate()}</span>
|
|
342
|
+
${C>0?`<span class="text-[10px] mt-0.5 opacity-80 font-medium whitespace-nowrap">${C}s</span>`:""}
|
|
343
|
+
</div>`}).join(""),zl(e),Wa()}function zl(e){let t=i("selected-day-title"),n=i("selected-day-sessions");if(!t||!n)return;let[s,a,o]=zn.split("-").map(Number),r=new Date(s,a-1,o);t.textContent=`Activity on ${r.toLocaleDateString([],{weekday:"short",month:"short",day:"numeric",year:"numeric"})}`,e=Fa(e);let d=Gi(r,e),l=d.reduce((u,h)=>u+(Number(h.totalTokens)||0),0),c=i("stats-selected-tokens");if(c&&(c.textContent=Ki(l)),!d.length){n.innerHTML='<div class="text-center text-xs text-base-content/40 my-auto py-6">No sessions active on this day</div>';return}d.sort((u,h)=>(q(h.updatedAt)||0)-(q(u.updatedAt)||0)),n.innerHTML=d.map(u=>{let h=q(u.updatedAt),x=h!=null?new Date(h).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):"";return`
|
|
344
|
+
<div class="flex items-center gap-2.5 p-2.5 rounded-lg bg-base-300/40 hover:bg-base-300 border border-base-300/50 cursor-pointer text-left transition-all ${f.sessionId===u.sessionId?"border-primary bg-primary/5":""}"
|
|
345
|
+
data-session-id="${p(u.sessionId)}"
|
|
346
|
+
data-session-cwd="${p(u.cwd||"")}"
|
|
347
|
+
data-session-config-dir="${p(u.configDir||"")}"
|
|
348
|
+
data-session-agent="${p(u.agent||"claude")}"
|
|
349
|
+
data-session-machine="${p(u.machineId||"")}">
|
|
350
|
+
<div class="flex-shrink-0">${nn(u.agent)}</div>
|
|
351
|
+
<div class="flex-1 min-w-0">
|
|
352
|
+
<div class="text-xs font-semibold truncate text-base-content/90">${p(Ye(u))}</div>
|
|
353
|
+
<div class="text-[10px] text-base-content/40 truncate mt-0.5">${p(u.projectName||sn(u.cwd)||"No workspace")}</div>
|
|
354
|
+
</div>
|
|
355
|
+
<div class="text-[9px] text-base-content/45 font-mono whitespace-nowrap bg-base-300 px-1.5 py-0.5 rounded">${x}</div>
|
|
356
|
+
</div>`}).join("")}function Ps(e){return`${e.machineId||""}:${e.agent||"claude"}:${e.sessionId}`}function Ua(){try{let e=JSON.parse(localStorage.getItem(Ji)||"[]");return Array.isArray(e)?e.filter(t=>t&&t.sessionId):[]}catch{return[]}}function Qi(e){try{localStorage.setItem(Ji,JSON.stringify(e))}catch{}}function Vi(e){if(!e?.sessionId)return;let t=Ps(e),n={...e,lastOpenedAt:Date.now()},s=Ua().filter(a=>Ps(a)!==t);s.unshift(n),Qi(s.slice(0,zi)),Wa(),Ka()}function Yi(e){if(!e?.sessionId)return;let t=Ps(e);Qi(Ua().filter(n=>Ps(n)!==t)),Wa(),Ka()}function Xi(e){return Ua().sort((t,n)=>(q(n.lastOpenedAt)||0)-(q(t.lastOpenedAt)||0)).slice(0,e)}function Wa(){let e=i("recent-sessions-list");if(!e)return;let t=Xi(6);if(!t.length){e.innerHTML='<div class="col-span-full text-center text-xs text-base-content/40 py-4">No recent sessions</div>';return}e.innerHTML=t.map(n=>{let s=tn(n.updatedAt);return`
|
|
357
|
+
<div class="flex items-center gap-2.5 p-3 rounded-xl bg-base-200 hover:bg-base-300 border border-base-300/80 cursor-pointer text-left transition-all ${f.sessionId===n.sessionId?"border-primary bg-primary/5":""}"
|
|
358
|
+
data-session-id="${p(n.sessionId)}"
|
|
359
|
+
data-session-cwd="${p(n.cwd||"")}"
|
|
360
|
+
data-session-config-dir="${p(n.configDir||"")}"
|
|
361
|
+
data-session-agent="${p(n.agent||"claude")}"
|
|
362
|
+
data-session-machine="${p(n.machineId||"")}">
|
|
363
|
+
<div class="flex-shrink-0">${nn(n.agent)}</div>
|
|
364
|
+
<div class="flex-1 min-w-0">
|
|
365
|
+
<div class="text-xs font-bold truncate text-base-content/95">${p(Ye(n))}</div>
|
|
366
|
+
<div class="text-[10px] text-base-content/40 truncate mt-1">${p(n.projectName||sn(n.cwd)||"No workspace")}</div>
|
|
367
|
+
</div>
|
|
368
|
+
<div class="text-[9px] text-base-content/40 whitespace-nowrap self-start mt-0.5">${s}</div>
|
|
369
|
+
</div>`}).join("")}function Bt(){let e=i("recent-menu");e&&(e.classList.add("hidden"),e.classList.remove("recent-menu-open"),e.style.top="",e.style.left="",e.style.right="",e.style.width="",e.style.maxHeight=""),i("recent-menu-backdrop")?.classList.add("hidden")}function Ga(){let e=i("recent-menu"),t=i("topbar");if(!e||!t)return;let n=t.getBoundingClientRect(),a=Math.round(n.bottom+6),o=window.matchMedia("(max-width: 640px)").matches?8:null;if(e.style.top=`${a}px`,o!=null)e.style.left=`${o}px`,e.style.right=`${o}px`;else{let l=i("btn-recent-sessions")?.getBoundingClientRect();if(l){let c=Math.min(320,window.innerWidth-16),u=l.left;u+c>window.innerWidth-8&&(u=window.innerWidth-c-8),u<8&&(u=8),e.style.left=`${Math.round(u)}px`,e.style.right="auto",e.style.width=`${c}px`}}let r=Math.max(160,window.innerHeight-a-12);e.style.maxHeight=`${Math.min(r,Math.round(window.innerHeight*.7))}px`}function Jl(){let e=i("recent-menu");e&&(Ka(),e.classList.remove("hidden"),e.classList.add("recent-menu-open"),Ga(),i("recent-menu-backdrop")?.classList.remove("hidden"))}function Zi(){let e=i("recent-menu");e&&(e.classList.contains("hidden")?Jl():Bt())}function Ka(){let e=i("recent-menu-list"),t=i("recent-menu-empty"),n=i("recent-menu-count");if(!e)return;let s=Xi(zi);if(n&&(n.textContent=s.length?`${s.length}`:""),!s.length){e.innerHTML="",t?.classList.remove("hidden");return}t?.classList.add("hidden"),e.innerHTML=s.map(a=>{let o=tn(a.updatedAt),r=f.sessionId===a.sessionId&&(!a.machineId||!f.machineId||a.machineId===f.machineId),d=a.machineId?`<span class="text-[9px] font-mono text-base-content/35 truncate max-w-[4.5rem]" title="${p(a.machineId)}">@${p(a.machineId)}</span>`:"";return`
|
|
370
|
+
<div class="recent-menu-item w-full text-left px-2 py-1.5 rounded-md flex items-start gap-2
|
|
371
|
+
${r?"bg-primary/15 text-primary":"hover:bg-base-200"}">
|
|
372
|
+
<button type="button" class="flex min-w-0 flex-1 items-start gap-2 text-left" aria-label="\u6253\u5F00 ${p(Ye(a))}"
|
|
373
|
+
data-session-id="${p(a.sessionId)}"
|
|
374
|
+
data-session-cwd="${p(a.cwd||"")}"
|
|
375
|
+
data-session-config-dir="${p(a.configDir||"")}"
|
|
376
|
+
data-session-agent="${p(a.agent||"claude")}"
|
|
377
|
+
data-session-machine="${p(a.machineId||"")}">
|
|
378
|
+
<span class="flex-shrink-0 mt-0.5">${nn(a.agent)}</span>
|
|
379
|
+
<span class="flex-1 min-w-0">
|
|
380
|
+
<span class="block text-xs font-semibold truncate leading-snug">${p(Ye(a))}</span>
|
|
381
|
+
<span class="block text-[10px] text-base-content/40 truncate mt-0.5">${p(a.projectName||sn(a.cwd)||"\u2014")}</span>
|
|
382
|
+
</span>
|
|
383
|
+
<span class="flex flex-col items-end gap-0.5 flex-shrink-0 self-start">
|
|
384
|
+
<span class="text-[9px] text-base-content/40 whitespace-nowrap">${p(o)}</span>
|
|
385
|
+
${d}
|
|
386
|
+
${r?'<span class="text-[9px] opacity-70">\u5F53\u524D</span>':""}
|
|
387
|
+
</span>
|
|
388
|
+
</button>
|
|
389
|
+
<button type="button" class="recent-remove btn btn-ghost btn-xs min-h-7 h-7 w-7 px-0 flex-shrink-0 text-base-content/45 hover:text-error"
|
|
390
|
+
title="\u4ECE\u6700\u8FD1\u4F1A\u8BDD\u79FB\u9664" aria-label="\u4ECE\u6700\u8FD1\u4F1A\u8BDD\u79FB\u9664 ${p(Ye(a))}"
|
|
391
|
+
data-dismiss-recent-session="${p(a.sessionId)}"
|
|
392
|
+
data-dismiss-recent-agent="${p(a.agent||"claude")}"
|
|
393
|
+
data-dismiss-recent-machine="${p(a.machineId||"")}">\xD7</button>
|
|
394
|
+
</div>`}).join("")}function er(e){zn=e}function za(e){Pt+=e,Pt<0?(Pt=11,_s--):Pt>11&&(Pt=0,_s++)}var _s,Pt,zn,zi,Ji,Ja=K(()=>{R();O();an();_s=new Date().getFullYear(),Pt=new Date().getMonth(),zn=null;zi=15,Ji="recentSessionsV1"});var ir={};as(ir,{loadAgentsMeta:()=>wn,loadAllSessions:()=>Ke,loadMemoryTab:()=>qs,loadWorkspaces:()=>yn,mdToHtml:()=>or,openMemoryFile:()=>Xa,promptCustomModel:()=>Rs,refreshEffortSelect:()=>Hs,refreshModelSelect:()=>Ne,renderProjectGroups:()=>sr,renderSessionList:()=>Va,renderTimeline:()=>ar,runActivitySearch:()=>Bs,scheduleActivitySearch:()=>Os,sessionItemHtml:()=>Qa,syncSidebarChrome:()=>Ya});function tr(e){return Array.isArray(e)?e:e&&Array.isArray(e.results)?e.results:e&&Array.isArray(e.sessions)?e.sessions:[]}function Ql(){let e=new URLSearchParams;e.set("limit","2000");let t=e.toString();return t?`/api/sessions?${t}`:"/api/sessions"}async function Ke({waitFresh:e=!0}={}){let t=tr(await Es());if(t.length){let s=j.peek();if(A.peek()&&s){let a=t.filter(o=>!o.machineId||o.machineId===s);B.value=a.length?a:t}else B.value=t}let n=async()=>{let s=Ql(),a=await y("GET",s,void 0,void 0,{etag:!0});if(a===wa)return B.peek();let o=tr(a);return B.value=o,Si(o),o};if(e||!t.length)try{await n()}catch(s){if(!t.length){let a=i("session-list");a&&(a.innerHTML=`<div class="px-3 py-3 text-xs text-error">${p(s.message)}</div>`)}}else n().catch(()=>{})}async function yn({waitFresh:e=!0}={}){let t=await Li();t&&(ee.value=t);let n=async()=>{let s=await y("GET","/api/workspaces");ee.value=s,qn(s)};if(e||!t)try{await n()}catch{}else n().catch(()=>{})}function Qa(e,{showProject:t=!1}={}){let n=f.sessionId===e.sessionId&&(f.agent||I.peek())===(e.agent||"claude"),s=T.peek()?.[oe(e.agent,e.sessionId,e.machineId)]||{},a=!!(s.title&&String(s.title).trim()),o=e.snippet&&me.peek()?e.snippet:Ye(e),r=!!s.favorite,d=!!s.hidden,l=!!(s.notes&&String(s.notes).trim()),c=Number(e.turnCount)||0,u=c>0&&c<=ga,h=t?`<div class="text-[10px] text-base-content/40 font-mono truncate" title="${p(e.cwd||"")}">${p(e.projectName||sn(e.cwd)||"\u2014")}</div>`:"",x=[u?`<span class="session-thin-badge" title="Only ${c} turn${c===1?"":"s"}">thin\xB7${c}</span>`:"",a?`<span class="session-renamed-badge" title="Custom name (original: ${p(e.display||"")})">renamed</span>`:"",d?'<span class="session-hidden-badge" title="Hidden">hidden</span>':"",l?`<span class="session-note-dot" title="${p(s.notes)}">\u{1F4DD}</span>`:""].filter(Boolean).join(""),v=e.machineId?`<span class="text-[9px] px-1 py-0.5 rounded bg-base-300 text-base-content/50 font-mono flex-shrink-0" title="Machine">${p(e.machineId)}</span>`:"",C=a?`${o}
|
|
395
|
+
(original: ${e.display||e.sessionId})`:e.display||"";return`<div class="session-row px-2.5 py-1.5 cursor-pointer hover:bg-base-300 border-l-2
|
|
396
|
+
${n?"border-primary bg-primary/5":"border-transparent"} ${r?"session-fav":""} ${d?"session-hidden-row":""} ${u?"session-thin":""}"
|
|
397
|
+
data-session-id="${p(e.sessionId)}"
|
|
398
|
+
data-session-cwd="${p(e.cwd||"")}"
|
|
399
|
+
data-session-config-dir="${p(e.configDir||"")}"
|
|
400
|
+
data-session-agent="${p(e.agent||"claude")}"
|
|
401
|
+
data-session-machine="${p(e.machineId||"")}"
|
|
402
|
+
data-session-display="${p(e.display||"")}">
|
|
403
|
+
<div class="flex items-start gap-1.5">
|
|
404
|
+
<button type="button" class="session-fav-btn flex-shrink-0 leading-none mt-0.5 ${r?"is-fav":""}"
|
|
405
|
+
data-fav-toggle="1"
|
|
406
|
+
data-fav-session-id="${p(e.sessionId)}"
|
|
407
|
+
data-fav-session-agent="${p(e.agent||"claude")}"
|
|
408
|
+
data-fav-session-machine="${p(e.machineId||"")}"
|
|
409
|
+
title="${r?"Unfavorite":"Favorite"}">${r?"\u2605":"\u2606"}</button>
|
|
410
|
+
${nn(e.agent)}
|
|
411
|
+
<div class="min-w-0 flex-1">
|
|
412
|
+
<div class="session-title-wrap flex items-center gap-1 min-w-0"
|
|
413
|
+
data-rename-session-id="${p(e.sessionId)}"
|
|
414
|
+
data-rename-session-agent="${p(e.agent||"claude")}"
|
|
415
|
+
data-rename-session-machine="${p(e.machineId||"")}"
|
|
416
|
+
data-rename-session-display="${p(e.display||"")}">
|
|
417
|
+
<div class="session-title-text text-[11px] leading-snug truncate flex-1 min-w-0 ${n?"text-primary font-medium":"text-base-content/85"} ${a?"session-title-renamed":""}"
|
|
418
|
+
title="${p(C)}">${p(o)}</div>
|
|
419
|
+
<button type="button" class="session-rename-btn flex-shrink-0"
|
|
420
|
+
data-rename-session="1"
|
|
421
|
+
title="Rename session">\u270E</button>
|
|
422
|
+
<button type="button" class="session-hide-btn flex-shrink-0 ${d?"is-hidden":""}"
|
|
423
|
+
data-hide-toggle="1"
|
|
424
|
+
data-hide-session-id="${p(e.sessionId)}"
|
|
425
|
+
data-hide-session-agent="${p(e.agent||"claude")}"
|
|
426
|
+
data-hide-session-machine="${p(e.machineId||"")}"
|
|
427
|
+
title="${d?"Unhide session":"Hide session"}">${d?"\u{1F441}":"\u{1F648}"}</button>
|
|
428
|
+
</div>
|
|
429
|
+
${h}
|
|
430
|
+
${x||v?`<div class="flex items-center gap-1 mt-0.5 flex-wrap">${v}${x}</div>`:""}
|
|
431
|
+
</div>
|
|
432
|
+
<span class="text-[9px] text-base-content/30 flex-shrink-0 mt-0.5">${tn(e.updatedAt)}</span>
|
|
433
|
+
</div>
|
|
434
|
+
</div>`}async function wn(){try{let e=await y("GET","/api/agents");return kt.value=e,Ne(),e}catch(e){return console.warn("[agents] failed to load model list",e),null}}function Hs(){let e=i("sel-effort");if(!e)return;let t=I.peek()||"claude",n=P.peek(),s=In(t,n),a=ie.peek()||"";if(!a){let r=lt(t,n);r&&s.includes(r)&&(a=r,ie.value=r)}let o=['<option value="">effort: off</option>'].concat(s.map(r=>`<option value="${p(r)}" ${r===a?"selected":""}>${p(r)}</option>`));if(e.innerHTML=o.join(""),a&&!s.includes(a)){let r=lt(t,n);r&&s.includes(r)?(ie.value=r,e.value=r):(ie.value="",e.value="")}else e.value=a}function Ne(){let e=i("sel-model");if(!e)return;let t=I.peek()||"claude",n=Xe(t),s=P.peek();if(s&&!n.some(o=>o.value===s)&&(n=[{value:s,label:`${s} \u2605`,custom:!0},...n]),e.innerHTML=n.map(o=>`<option value="${p(o.value)}" ${o.value===s?"selected":""}>${p(o.label)}</option>`).join(""),n.some(o=>o.value===s))e.value=s;else{let o=Oe(t)||n[0]?.value;le(o),e.value=o,s=o}let a=i("sel-agent");a&&(a.value=t),Hs()}function Rs({editCurrent:e=!1}={}){let t=I.peek()||"claude",n=e&&P.peek()||"",s=e?`Edit model id for ${t}:`:`Add model id for ${t} (saved in this browser):`,a=window.prompt(s,n);if(a==null)return;let o=a.trim();o&&(e&&n&&n!==o&&ls(t).includes(n)&&ya(t,n),Mn(t,o),le(o),Ne())}function sr(e){if(!Array.isArray(e)||!e.length)return`<div class="px-3 py-6 text-center text-xs text-base-content/40">
|
|
435
|
+
No projects in this range.<br>
|
|
436
|
+
<span class="text-base-content/30">Try \u201CAll\u201D time or another agent.</span>
|
|
437
|
+
</div>`;let t=zt.value,n=Jt.value,s=!!me.value.trim(),a=e[0]?.cwd||"(no path)";return e.map(o=>{let r=o.cwd||"(no path)",d=!1;n.has(r)?d=!1:t.has(r)?d=!0:d=s||r===a||e.length<=3;let l=o.machineId?`<span class="text-[9px] font-mono text-base-content/40 flex-shrink-0">@${p(o.machineId)}</span>`:"",c=`
|
|
438
|
+
<div class="project-header px-2.5 py-2 cursor-pointer hover:bg-base-300/80 select-none border-b border-base-300/40"
|
|
439
|
+
data-folder="${p(r)}" data-project-cwd="${p(o.cwd||"")}" data-project-machine="${p(o.machineId||"")}">
|
|
440
|
+
<div class="flex items-center gap-1.5">
|
|
441
|
+
<span class="text-[10px] text-base-content/40 w-3 flex-shrink-0">${d?"\u25BE":"\u25B8"}</span>
|
|
442
|
+
<span class="text-[12px] font-semibold truncate flex-1" title="${p(o.cwd||"")}">${p(o.projectName)}</span>
|
|
443
|
+
${l}
|
|
444
|
+
<span class="text-[9px] text-base-content/30 flex-shrink-0">${tn(o.updatedAt)}</span>
|
|
445
|
+
</div>
|
|
446
|
+
</div>`,u=o.sessions.slice(0,40),h=o.sessions.length>40?`<div class="px-3 py-1 text-[10px] text-base-content/30">+${o.sessions.length-40} more</div>`:"",x=d?`<div class="pb-1 border-b border-base-300/30">${u.map(v=>Qa(v)).join("")}${h}</div>`:"";return c+x}).join("")}function ar(e){if(!Array.isArray(e)||!e.length)return`<div class="px-3 py-6 text-center text-xs text-base-content/40">
|
|
447
|
+
No recent activity.<br>
|
|
448
|
+
<span class="text-base-content/30">Widen the time range or clear filters.</span>
|
|
449
|
+
</div>`;let t=new Map;for(let n of e){let a=(n.updatedAt?new Date(n.updatedAt):new Date).toLocaleDateString(void 0,{weekday:"short",month:"short",day:"numeric"});t.has(a)||t.set(a,[]),t.get(a).push(n)}return[...t.entries()].map(([n,s])=>`
|
|
450
|
+
<div class="px-2.5 pt-2.5 pb-1 text-[10px] uppercase tracking-wide text-base-content/35 font-medium sticky top-0 bg-base-200/95 backdrop-blur-sm z-[1]">${p(n)}</div>
|
|
451
|
+
${s.map(a=>Qa(a,{showProject:!0})).join("")}
|
|
452
|
+
`).join("")}function Va(){let e=Je.value,t=Array.isArray(ct.value)?ct.value:[],n=Array.isArray(St.value)?St.value:[];return e==="timeline"?ar(t):sr(n)}function Ya(){document.querySelectorAll("[data-view]").forEach(o=>{let r=o.dataset.view===Je.peek();o.classList.toggle("bg-primary/15",r),o.classList.toggle("text-primary",r),o.classList.toggle("font-medium",r),o.classList.toggle("text-base-content/50",!r)}),document.querySelectorAll("[data-agent-filter]").forEach(o=>{o.classList.toggle("active",o.dataset.agentFilter===de.peek())});let e=i("time-range");e&&e.value!==rs.peek()&&(e.value=rs.peek());let t=i("search-status");if(!t)return;let n=Re.peek(),s=Array.isArray(n?.results)?n.results:null,a=(me.peek()||"").trim();if(Qe.peek())t.classList.remove("hidden"),t.textContent="Searching content\u2026";else if(a&&s)t.classList.remove("hidden"),t.textContent=`${s.length} hit${s.length===1?"":"s"}${n.deep===!1?"":" (incl. content)"}`;else if(a)t.classList.remove("hidden"),t.textContent="Local filter only \u2014 type to deep-search";else{let o=ct.peek(),r=St.peek(),d=Array.isArray(o)?o.length:0,l=Array.isArray(r)?r.length:0;t.classList.remove("hidden"),t.textContent=Je.peek()==="projects"?`${l} project${l===1?"":"s"} \xB7 ${d} session${d===1?"":"s"}`:`${d} recent session${d===1?"":"s"}`}}async function Bs(e){let t=(e||"").trim();if(!t){Re.value=null,Qe.value=!1;return}Qe.value=!0;try{let n=new URLSearchParams({q:t,days:"0",limit:"50",deep:"1"});de.peek()&&de.peek()!=="all"&&n.set("agent",de.peek());let s=await y("GET",`/api/activity?${n}`);me.peek().trim()===t&&(Re.value={q:t.toLowerCase(),results:s.results||[],deep:!0})}catch(n){me.peek().trim()===t&&(Re.value={q:t.toLowerCase(),results:[],error:n.message})}finally{Qe.value=!1}}function Os(e){clearTimeout(nr);let t=(e||"").trim();if(!t){Re.value=null,Qe.value=!1;return}nr=setTimeout(()=>Bs(t),350)}function or(e){if(!e)return"";if(typeof marked>"u")return`<pre class="whitespace-pre-wrap text-xs">${p(e)}</pre>`;try{return marked.parse(String(e),{breaks:!0,gfm:!0})}catch{return`<pre class="whitespace-pre-wrap text-xs">${p(e)}</pre>`}}async function qs(){let e=i("memory-area");if(e){if(!f.sessionId){e.innerHTML='<div class="p-4 text-xs text-base-content/40">Open or resume a session to view its memory.</div>';return}e.innerHTML='<div class="p-4 text-xs text-base-content/40">Loading\u2026</div>';try{let t=f.agent||I.peek()||"claude",n=new URLSearchParams({agent:t}),a=(await y("GET",`/api/sessions/${f.sessionId}/memory?${n}`)).files||[];if(!a.length){e.innerHTML='<div class="p-4 text-base-content/40 text-xs">No memory files available for this agent/session.</div>';return}e.innerHTML=`<div class="p-3 text-[11px] text-base-content/45">${p(t)} \xB7 ${a.length} memory file${a.length===1?"":"s"} \xB7 click to open</div>
|
|
453
|
+
<div class="px-3 pb-4 flex flex-col gap-1">${a.map(o=>`<button type="button" class="memory-file text-left px-3 py-2 rounded-lg border border-base-300 hover:border-primary hover:bg-primary/5" data-memory-file="${p(o.id)}" data-memory-agent="${p(t)}"><span class="font-mono text-xs">${p(o.name)}</span><span class="ml-2 text-[10px] text-base-content/40">${p(o.scope||"")}</span></button>`).join("")}<div id="memory-file-content"></div></div>`}catch(t){e.innerHTML=`<div class="p-4 text-error text-xs">${p(t?.message??String(t))}</div>`}}}async function Xa(e,t){let n=i("memory-file-content");if(!(!n||!f.sessionId||!e)){n.innerHTML='<div class="p-3 text-xs text-base-content/40">Loading file\u2026</div>';try{let s=new URLSearchParams({agent:t||f.agent||I.peek()||"claude",file:e}),a=await y("GET",`/api/sessions/${f.sessionId}/memory/file?${s}`);n.innerHTML=`<div class="mt-2 border border-base-300 rounded-lg overflow-hidden"><div class="px-3 py-1.5 bg-base-300/50 text-xs font-mono">${p(a.name)}</div><div class="px-3 py-2 md">${or(a.content)}</div></div>`}catch(s){n.innerHTML=`<div class="mt-2 p-3 text-error text-xs">${p(s?.message??String(s))}</div>`}}}var nr,Ot=K(()=>{R();O();ue();Ts();an();nr=null});function rr(e,t){Fs=e||"",Us=t||""}async function lr(e){let t=i("project-notes-bar");if(t)try{let n=await y("GET",`/api/projects/notes?root=${encodeURIComponent(e)}`);Fs=n.goal||"",Us=n.notes||"",kn(),t.style.display="flex"}catch(n){console.error("Error fetching project notes:",n),t.style.display="none"}}function kn(){let e=i("project-notes-bar");if(!e)return;let t=Fs||"No goal yet \u2014 click Edit",n=Us||"";e.innerHTML=`
|
|
454
|
+
<div class="flex items-start gap-2 w-full">
|
|
455
|
+
<div class="flex-1 min-w-0">
|
|
456
|
+
<div class="truncate">
|
|
457
|
+
<span class="font-bold text-base-content/40 uppercase mr-1">Goal:</span>
|
|
458
|
+
<span id="project-goal-text" class="text-base-content/80 cursor-pointer hover:underline" title="Click to edit">${p(t)}</span>
|
|
459
|
+
</div>
|
|
460
|
+
${n?`<div class="mt-0.5 text-base-content/55 line-clamp-2 whitespace-pre-wrap" id="project-notes-text" title="${p(n)}"><span class="font-bold text-base-content/35 uppercase mr-1">Notes:</span>${p(n)}</div>`:'<div class="mt-0.5 text-base-content/35 italic text-[11px]" id="project-notes-text">No project notes</div>'}
|
|
461
|
+
</div>
|
|
462
|
+
<button id="btn-edit-project-notes" class="btn btn-ghost btn-xs px-1.5 hover:bg-base-300 flex-shrink-0">Edit</button>
|
|
463
|
+
</div>
|
|
464
|
+
`}function cr(){let e=i("project-notes-bar");e&&(e.innerHTML=`
|
|
465
|
+
<div class="flex flex-col gap-1.5 w-full">
|
|
466
|
+
<div class="flex items-center gap-2">
|
|
467
|
+
<span class="text-[10px] font-bold text-base-content/40 uppercase w-12 flex-shrink-0">Goal</span>
|
|
468
|
+
<input id="project-goal-input" type="text" class="input input-xs input-bordered flex-1 text-xs"
|
|
469
|
+
placeholder="One-line project goal\u2026" value="${p(Fs)}">
|
|
470
|
+
</div>
|
|
471
|
+
<div class="flex items-start gap-2">
|
|
472
|
+
<span class="text-[10px] font-bold text-base-content/40 uppercase w-12 flex-shrink-0 mt-1">Notes</span>
|
|
473
|
+
<textarea id="project-notes-input" rows="2" class="textarea textarea-xs textarea-bordered flex-1 text-xs leading-snug"
|
|
474
|
+
placeholder="Longer project notes (stack, links, status\u2026)">${p(Us)}</textarea>
|
|
475
|
+
</div>
|
|
476
|
+
<div class="flex items-center gap-1 justify-end">
|
|
477
|
+
<button id="btn-save-project-notes" class="btn btn-primary btn-xs px-2">Save</button>
|
|
478
|
+
<button id="btn-cancel-project-notes" class="btn btn-ghost btn-xs px-2">Cancel</button>
|
|
479
|
+
</div>
|
|
480
|
+
</div>
|
|
481
|
+
`,i("project-goal-input")?.focus())}async function Jn(){try{let e=await y("GET","/api/sessions/meta");T.value=e||{}}catch(e){console.warn("session meta load failed",e)}}function _e(){let e=i("session-notes-bar");if(!e)return;let t=f.sessionId,n=f.agent||I.peek()||"claude";if(!t){e.style.display="none",e.innerHTML="";return}if(e.querySelector(".session-rename-input"))return;let s=Qt(n,t),a=(s.notes||"").trim(),o=!!s.favorite,r=!!s.hidden,l=(s.title||"").trim()||t.slice(0,8);e.style.display="flex",e.innerHTML=`
|
|
482
|
+
<div class="flex-1 min-w-0 flex items-center gap-2">
|
|
483
|
+
<button type="button" class="session-fav-btn ${o?"is-fav":""}" data-fav-toggle="1"
|
|
484
|
+
data-fav-session-id="${p(t)}" data-fav-session-agent="${p(n)}"
|
|
485
|
+
title="${o?"Unfavorite":"Favorite"}">${o?"\u2605":"\u2606"}</button>
|
|
486
|
+
<span id="session-title-display"
|
|
487
|
+
class="session-title-inline max-w-[40%] truncate font-semibold text-base-content/85"
|
|
488
|
+
title="${p(l)}">${p(l)}</span>
|
|
489
|
+
<button type="button" class="session-rename-btn flex-shrink-0 opacity-70 hover:opacity-100"
|
|
490
|
+
data-rename-bar="1" title="Rename session">\u270E</button>
|
|
491
|
+
<button type="button" class="session-hide-btn flex-shrink-0 ${r?"is-hidden":""}"
|
|
492
|
+
data-hide-toggle="1"
|
|
493
|
+
data-hide-session-id="${p(t)}"
|
|
494
|
+
data-hide-session-agent="${p(n)}"
|
|
495
|
+
title="${r?"Unhide session":"Hide session"}">${r?"\u{1F441}":"\u{1F648}"}</button>
|
|
496
|
+
<span class="font-bold text-base-content/40 uppercase flex-shrink-0">Note:</span>
|
|
497
|
+
<span class="truncate text-base-content/70 ${a?"":"italic text-base-content/40"}"
|
|
498
|
+
id="session-notes-text" title="${p(a||"Add a note for this session")}">${p(a||"No session note")}</span>
|
|
499
|
+
</div>
|
|
500
|
+
<button id="btn-edit-session-notes" class="btn btn-ghost btn-xs px-1.5">Note</button>
|
|
501
|
+
`}function dr(){let e=i("session-notes-bar");if(!e||!f.sessionId)return;let t=f.agent||I.peek()||"claude",n=Qt(t,f.sessionId);e.innerHTML=`
|
|
502
|
+
<input id="session-notes-input" type="text" class="input input-xs input-bordered flex-1 text-xs"
|
|
503
|
+
placeholder="Note for this session\u2026" value="${p(n.notes||"")}">
|
|
504
|
+
<button id="btn-save-session-notes" class="btn btn-primary btn-xs px-2">Save</button>
|
|
505
|
+
<button id="btn-cancel-session-notes" class="btn btn-ghost btn-xs px-2">Cancel</button>
|
|
506
|
+
`;let s=i("session-notes-input");s?.focus(),s?.select()}function Ws(){return{favorite:!1,notes:"",title:"",hidden:!1}}function Gs(e,t){return{favorite:t.favorite!==void 0?!!t.favorite:!!e.favorite,notes:t.notes!==void 0?String(t.notes||""):String(e.notes||""),title:t.title!==void 0?String(t.title||"").trim():String(e.title||"").trim(),hidden:t.hidden!==void 0?!!t.hidden:!!e.hidden,updatedAt:Date.now()}}function ur(e){return!e?.favorite&&!e?.hidden&&!(e?.notes||"").trim()&&!(e?.title||"").trim()}async function pr(e,t,{machineId:n}={}){let s=n||f.machineId||null,a=oe(t,e,s),o=T.peek()?.[a]||Ws(),r=!o.favorite;T.value={...T.peek(),[a]:{...o,favorite:r,updatedAt:Date.now()}};try{let d=await y("PUT","/api/sessions/meta",{sessionId:e,agent:t,favorite:r,machineId:s||void 0},void 0,{machineId:s||void 0});T.value={...T.peek(),[a]:Gs(o,{favorite:d.favorite??r,notes:d.notes,title:d.title,hidden:d.hidden})}}catch(d){T.value={...T.peek(),[a]:o},alert(`Favorite failed: ${d.message}`)}f.sessionId===e&&_e()}async function fr(e,t,{machineId:n}={}){if(!e)return!1;let s=n||f.machineId||null,a=oe(t,e,s),o=T.peek()?.[a]||Ws(),r=!o.hidden;T.value={...T.peek(),[a]:{...o,hidden:r,updatedAt:Date.now()}};try{let d=await y("PUT","/api/sessions/meta",{sessionId:e,agent:t,hidden:r,machineId:s||void 0},void 0,{machineId:s||void 0}),l=Gs(o,{favorite:d.favorite,notes:d.notes,title:d.title,hidden:d.hidden??r});if(ur(l)){let c={...T.peek()};delete c[a],T.value=c}else T.value={...T.peek(),[a]:l}}catch(d){return T.value={...T.peek(),[a]:o},alert(`Hide failed: ${d.message}`),!1}return f.sessionId===e&&_e(),!0}async function Za(e,t,n,{machineId:s}={}){let a=s||f.machineId||null,o=oe(t,e,a),r=T.peek()?.[o]||Ws();try{let d=await y("PUT","/api/sessions/meta",{sessionId:e,agent:t,notes:n,machineId:a||void 0},void 0,{machineId:a||void 0});T.value={...T.peek(),[o]:Gs(r,{favorite:d.favorite,notes:d.notes??n,title:d.title,hidden:d.hidden})}}catch(d){return alert(`Save note failed: ${d.message}`),!1}return!0}async function Vl(e,t,n,{machineId:s}={}){if(!e)return!1;let a=s||f.machineId||null,o=oe(t,e,a),r=T.peek()?.[o]||Ws(),d=String(n||"").trim().slice(0,200);T.value={...T.peek(),[o]:{...r,title:d,updatedAt:Date.now()}};try{let l=await y("PUT","/api/sessions/meta",{sessionId:e,agent:t,title:d,machineId:a||void 0},void 0,{machineId:a||void 0}),c=Gs(r,{favorite:l.favorite,notes:l.notes,title:l.title!==void 0?l.title:d,hidden:l.hidden});if(ur(c)){let u={...T.peek()};delete u[o],T.value=u}else T.value={...T.peek(),[o]:c}}catch(l){return T.value={...T.peek(),[o]:r},alert(`Rename failed: ${l.message}`),!1}return f.sessionId===e&&_e(),!0}function eo({sessionId:e,agent:t="claude",machineId:n=null,fallbackDisplay:s="",mountEl:a}={}){if(!e||!a)return;document.querySelectorAll(".session-rename-input").forEach(x=>{x.dispatchEvent(new CustomEvent("session-rename-cancel",{bubbles:!0}))});let r=(Qt(t,e,n).title||"").trim()||s||e.slice(0,8),d=a.innerHTML,l=a.className;a.classList.add("session-rename-active"),a.innerHTML=`<input type="text" class="session-rename-input input input-xs input-bordered w-full min-w-0 text-xs font-mono"
|
|
507
|
+
value="${p(r)}"
|
|
508
|
+
placeholder="Session name (empty = original)"
|
|
509
|
+
maxlength="200"
|
|
510
|
+
data-rename-input="1"
|
|
511
|
+
data-rename-session-id="${p(e)}"
|
|
512
|
+
data-rename-session-agent="${p(t)}"
|
|
513
|
+
data-rename-session-machine="${p(n||"")}"
|
|
514
|
+
autocomplete="off" spellcheck="false" />`;let c=a.querySelector(".session-rename-input");if(!c)return;let u=!1,h=async x=>{if(u)return;u=!0;let v=x?c.value:r;if(a.className=l,!x){a.innerHTML=d;return}await Vl(e,t,v,{machineId:n}),document.querySelectorAll(".session-rename-input").forEach(C=>C.remove()),f.sessionId===e&&_e(),T.value={...T.peek()}};c.addEventListener("keydown",x=>{x.stopPropagation(),x.key==="Enter"?(x.preventDefault(),h(!0)):x.key==="Escape"&&(x.preventDefault(),h(!1))}),c.addEventListener("click",x=>x.stopPropagation()),c.addEventListener("mousedown",x=>x.stopPropagation()),c.addEventListener("session-rename-cancel",()=>h(!1)),c.addEventListener("blur",()=>{setTimeout(()=>h(!0),0)}),requestAnimationFrame(()=>{c.focus(),c.select()})}var Fs,Us,Qn=K(()=>{R();O();ue();Fs="",Us=""});var hr={};as(hr,{closeMachineMenu:()=>Ut,enterMachine:()=>no,hideMachinePicker:()=>zs,refreshMachinesList:()=>qt,renderMachineMenuList:()=>Vn,renderMachinePickerList:()=>Ks,showMachinePicker:()=>Ft,startMachinePolling:()=>to,syncTopbarMachine:()=>gt});async function qt(){try{let e=await y("GET","/api/machines");Q.value=Array.isArray(e)?e:[]}catch{try{let e=await Yt();e?.machines&&(Q.value=e.machines)}catch{}}return Q.peek()||[]}function Ks(){let e=i("machine-picker-list"),t=i("machine-picker-empty");if(!e)return;let n=Q.peek()||[];if(!n.length){e.innerHTML="",t?.classList.remove("hidden");return}t?.classList.add("hidden"),e.innerHTML=n.map(s=>{let a=s.online!==!1,o=[s.hostname,s.platform].filter(Boolean).join(" \xB7 ");return`
|
|
515
|
+
<button type="button" class="machine-pick-card w-full text-left px-4 py-3 rounded-xl border border-base-300
|
|
516
|
+
hover:border-primary hover:bg-primary/5 transition-colors ${a?"":"opacity-50"}"
|
|
517
|
+
data-pick-machine="${p(s.id)}" ${a?"":"disabled"}>
|
|
518
|
+
<div class="flex items-center gap-2">
|
|
519
|
+
<span class="w-2 h-2 rounded-full flex-shrink-0 ${a?"bg-success":"bg-error"}"></span>
|
|
520
|
+
<span class="font-semibold text-sm font-mono">${p(s.id)}</span>
|
|
521
|
+
</div>
|
|
522
|
+
${o?`<div class="text-xs text-base-content/45 mt-1 pl-4">${p(o)}</div>`:""}
|
|
523
|
+
</button>`}).join("")}function Ft(){let e=i("machine-picker");if(!e)return;e.classList.remove("hidden"),xe(),Be.value=!1,Ks();let t=i("machine-picker-status");if(t){let n=(Q.peek()||[]).filter(s=>s.online!==!1).length;t.textContent=`${n} online`}}function zs(){i("machine-picker")?.classList.add("hidden"),xe(),Be.value=!0}function Ut(){i("machine-menu")?.classList.add("hidden")}function Vn(){let e=i("machine-menu-list"),t=i("machine-menu-empty");if(!e)return;let n=Q.peek()||[],s=j.peek()||"";if(!n.length){e.innerHTML="",t?.classList.remove("hidden");return}t?.classList.add("hidden"),e.innerHTML=n.map(a=>{let o=a.online!==!1,r=a.id===s,d=[a.hostname,a.platform].filter(Boolean).join(" \xB7 "),l=a.connectedAt?new Date(a.connectedAt).toLocaleTimeString():"";return`
|
|
524
|
+
<button type="button"
|
|
525
|
+
class="machine-menu-item w-full text-left px-2 py-1.5 rounded-md text-xs
|
|
526
|
+
${r?"bg-primary/15 text-primary":"hover:bg-base-200"}
|
|
527
|
+
${o?"":"opacity-50"}"
|
|
528
|
+
data-pick-machine="${p(a.id)}"
|
|
529
|
+
${o?"":"disabled"}>
|
|
530
|
+
<div class="flex items-center gap-1.5">
|
|
531
|
+
<span class="w-1.5 h-1.5 rounded-full flex-shrink-0 ${o?"bg-success":"bg-error"}"></span>
|
|
532
|
+
<span class="font-mono font-semibold truncate flex-1">${p(a.id)}</span>
|
|
533
|
+
${r?'<span class="text-[9px] opacity-70">\u5F53\u524D</span>':""}
|
|
534
|
+
<span class="text-[9px] ${o?"text-success":"text-error"}">${o?"online":"offline"}</span>
|
|
535
|
+
</div>
|
|
536
|
+
${d||l?`<div class="text-[10px] text-base-content/40 pl-3.5 mt-0.5 truncate">${p(d)}${l?" \xB7 "+p(l):""}</div>`:""}
|
|
537
|
+
</button>`}).join("")}function gt(){let e=i("machine-menu-wrap"),t=i("topbar-machine-label"),n=i("topbar-machine-dot");if(!A.peek()){e?.classList.add("hidden");return}e?.classList.remove("hidden");let s=j.peek()||"",o=(Q.peek()||[]).find(d=>d.id===s),r=o?o.online!==!1:!1;t&&(t.textContent=s||"\u9009\u62E9\u673A\u5668"),n&&(n.classList.toggle("bg-success",!!s&&r),n.classList.toggle("bg-warning",!!s&&!r),n.classList.toggle("bg-base-content/30",!s)),Vn()}function to(){mr||(mr=setInterval(async()=>{if(!A.peek()||!f.token)return;await qt(),gt();let e=j.peek();if(e){let t=(Q.peek()||[]).find(n=>n.id===e);if(t&&t.online===!1){let n=i("topbar-machine-label");n&&(n.textContent=`${e} (offline)`)}}},15e3))}async function no(e,{forceReload:t=!1}={}){if(!e)return;let n=j.peek(),s=n&&n!==e;if(ge(e),zs(),Ut(),gt(),s||t){try{f.ws?.close()}catch{}f.ws=null,f.sessionId=null,ae(()=>{E.value=null,fe.value=null,re.value=null});try{let{filesRoot:o,gitRoot:r,filesPath:d}=await Promise.resolve().then(()=>(O(),Do));o.value="",r.value="",d.value=""}catch{}if(s){let{goHome:o}=await Promise.resolve().then(()=>(Xn(),br));o()}}let a=i("topbar-project");a&&!E.peek()&&(a.textContent=`Machine \xB7 ${e}`),Gn(),await Promise.all([Ke(),yn(),Jn(),wn().catch(()=>{})]),Be.value=!0}var mr,Yn=K(()=>{R();O();ue();Ot();Qn();Kn();en();mr=null});var br={};as(br,{goHome:()=>Vs,openProject:()=>so,resumeSession:()=>Pe,switchTab:()=>it});function Qs(e){for(let t of["files-machine-hint","git-machine-hint"]){let n=i(t);n&&(e?(n.textContent=`@${e}`,n.classList.remove("hidden"),n.title=`Paths are on machine ${e}`):(n.textContent="",n.classList.add("hidden"),n.title=""))}}function so(e){cn(),un(),fn(),pn();let t=e?.path||"";ae(()=>{E.value=e,fe.value=t,t&&(ce.value=t,be.value=t,z.value="",re.value=null)}),f.sessionId=null,i("topbar-project").textContent=t||"Project";let n=i("files-root-input");n&&t&&(n.value=t);let s=i("git-root-input");s&&t&&(s.value=t),Qs(e?.machineId||j.peek()||f.machineId),i("welcome").classList.add("hidden");let a=i("project-view");a.classList.remove("hidden"),a.style.display="flex",mn(),dn({sessionId:null}),st(),it("chat")}function Vs(){cn(),un(),fn(),pn(),E.value=null,fe.value=null,ce.value="",be.value="",z.value="",re.value=null,f.sessionId=null,dn({sessionId:null}),Qs(null),document.documentElement.classList.remove("boot-restore");let e=i("topbar-project");e&&(e.textContent="Select a session");let t=i("welcome");t&&(t.classList.remove("hidden"),t.style.display="",Rt(Ht()));let n=i("project-view");n&&(n.classList.add("hidden"),n.style.display="none"),_a("/")}async function Pe(e,t,n,s,a,o={}){let r=o.tab&&["chat","files","git","shell","memory"].includes(o.tab)?o.tab:"chat",d=o.skipHistory??(r!=="chat"&&r!=="memory"),l=B.peek().find(S=>S.sessionId===e&&(!a||S.machineId===a||!S.machineId)),c=Et(),u=c?.sessionId===e?c:null,h=s||l?.agent||u?.agent||"claude",x=a||l?.machineId||u?.machineId||j.peek()||null,v=t||l?.cwd||u?.cwd||null,C=n||l?.configDir||u?.configDir||null;if(cn(),un(),fn(),pn(),x&&x!==f.machineId){ge(x);try{f.ws?.close()}catch{}f.ws=null,Promise.resolve().then(()=>(Yn(),hr)).then(({syncTopbarMachine:S})=>S()).catch(()=>{}),Promise.resolve().then(()=>(Ot(),ir)).then(({loadAllSessions:S})=>S()).catch(()=>{})}f.sessionId=e,f.configDir=C,f.agent=h,qe(h),Ne(),dn({sessionId:e,agent:h,machineId:x});let F=v;gr(F,x,e),st(),F&&y("POST","/api/resolve-path",{path:F},void 0,{machineId:x||void 0}).then(S=>{f.sessionId!==e||!S?.path||S.path===F||(F=S.path,gr(F,x,e),ka({sessionId:e,cwd:F}))}).catch(()=>{}),mn(),it(r);{let S=B.peek();B.value=Array.isArray(S)?[...S]:[]}ka({sessionId:e,cwd:F||v,configDir:C,agent:h,machineId:x,tab:r}),Vi({sessionId:e,cwd:F||v,configDir:C,agent:h,machineId:x,display:l?.display||u?.display||"",projectName:l?.projectName||u?.projectName||"",updatedAt:l?.updatedAt||u?.updatedAt||null});let ke=te[h]||h,J=`${x||""}:${h}:${e}`,ne=(S,_,se={})=>{if(f.sessionId!==e)return;if(i("messages").innerHTML="",!S.length){L(`${ke} \xB7 ${e.slice(0,8)}\u2026 \u2014 no history`);return}De();let M=40,V=0,rt=()=>{if(f.sessionId!==e)return;let xt=Math.min(V+M,S.length);for(;V<xt;V++){let b=S[V],w=q(b.ts??b.timestamp),k=b.type||(b.role?"text":null);if(k==="text"||b.role&&b.content!=null&&!b.name){(b.role==="assistant"||b.role==="user")&&De();let W=typeof b.content=="string"?b.content:Array.isArray(b.content)?b.content.map(Y=>Y?.text||"").filter(Boolean).join(`
|
|
538
|
+
`):String(b.content??"");W&&At(b.role==="user"?"user":"assistant",b.role==="user"?"You":ke,W,{ts:w})}else k==="tool_use"||b.name?Aa({name:b.name||"tool",input:b.input??b.arguments??{}},{ts:w}):(k==="token_usage"||b.usage)&&(De(),ln(b.usage||b))}if(V<S.length){requestAnimationFrame(rt);return}De(),_&&Ca(_);let vt=S.filter(b=>b.type==="token_usage").length||S.filter(b=>b.role==="user").length,m=se.truncated?` (showing last ${S.length} of ${se.total||"?"})`:"";L(`\u2500\u2500 ${ke} history \xB7 ${vt} turn${vt!==1?"s":""}${m} \u2500\u2500`)};rt()},N=async()=>{let S=Js.get(J);if(S&&S.msgs?.length&&Date.now()-S.at<Yl){ne(S.msgs,S.context,S.meta);return}L(`Loading ${ke} history\u2026`);try{let _=x||j.peek()||f.machineId||null;if(A.peek()&&!_)throw new Error("\u672A\u9009\u62E9\u673A\u5668\uFF0C\u65E0\u6CD5\u52A0\u8F7D\u5386\u53F2");_&&f.machineId!==_&&ge(_);let se=async vt=>{let m=new URLSearchParams({tail:"0",compact:"1",cache:"prefer"});return vt&&m.set("agent",vt),_&&m.set("machine",_),y("GET",`/api/sessions/${e}/messages?${m}`,void 0,void 0,{machineId:_||void 0,dedupe:!1})},M=await se(h),V=Array.isArray(M)?M:M?.messages||[];!V.length&&h&&(M=await se(null),V=Array.isArray(M)?M:M?.messages||[]);let rt=Array.isArray(M)?null:M?.context||null,xt=Array.isArray(M)?{}:{truncated:M?.truncated,total:M?.total};V.length?Js.set(J,{msgs:V,context:rt,meta:xt,at:Date.now()}):Js.delete(J),ne(V,rt,xt)}catch(_){if(f.sessionId!==e)return;Js.delete(J),i("messages").innerHTML="",L(`${ke} \xB7 ${e.slice(0,8)}\u2026 (history unavailable: ${_.message})`)}};d?N().catch(()=>{}):(await new Promise(S=>requestAnimationFrame(S)),N().catch(()=>{})),On(),_e()}function gr(e,t,n){if(e){let s=e.split("/").filter(Boolean).pop()||e;ae(()=>{E.value={id:s,name:s,path:e,machineId:t},fe.value=e,ce.value=e,be.value=e,z.value="",re.value=null}),i("topbar-project").textContent=t?`${e} @${t}`:e;let a=i("files-root-input");a&&(a.value=e);let o=i("git-root-input");o&&(o.value=e),Qs(t),i("welcome")?.classList.add("hidden");let r=i("project-view");r&&(r.classList.remove("hidden"),r.style.display="flex",r.style.flexDirection="column",r.style.flex="1",r.style.minHeight="0",r.style.overflow="hidden")}else{i("welcome")?.classList.add("hidden");let s=i("project-view");s&&(s.classList.remove("hidden"),s.style.display="flex",s.style.flexDirection="column",s.style.flex="1",s.style.minHeight="0"),Qs(t)}}function it(e){U.value=e}var Js,Yl,Xn=K(()=>{R();O();ue();ds();hn();Ss();Ot();Qn();Ja();Js=new Map,Yl=180*1e3});O();ue();R();O();ue();var Xt=null;function Ro(){return window.matchMedia("(display-mode: standalone)").matches||window.navigator.standalone===!0||document.referrer.includes("android-app://")}function Jr(e){let t=String(e||"").replace(/^\[|\]$/g,"");return!!(/^\d{1,3}(\.\d{1,3}){3}$/.test(t)||t.includes(":")&&/^[0-9a-f:]+$/i.test(t))}function Qr(){if(!("serviceWorker"in navigator)||!window.isSecureContext)return!1;let e=location.hostname;return e==="localhost"||e==="127.0.0.1"||e==="::1"?!0:Jr(e)?!1:location.protocol==="https:"}function Bo(){document.getElementById("btn-pwa-install")?.classList.remove("hidden")}function Oo(){Ro()&&document.documentElement.classList.add("pwa-standalone"),window.addEventListener("beforeinstallprompt",n=>{n.preventDefault(),Xt=n,document.dispatchEvent(new CustomEvent("pwa-installable")),Bo()}),window.addEventListener("appinstalled",()=>{Xt=null,document.getElementById("btn-pwa-install")?.classList.add("hidden")});let e=/iPad|iPhone|iPod/.test(navigator.userAgent)||navigator.platform==="MacIntel"&&navigator.maxTouchPoints>1;if(!Ro()&&(e||/Android/i.test(navigator.userAgent))&&requestAnimationFrame(()=>Bo()),!Qr()){"serviceWorker"in navigator&&navigator.serviceWorker.getRegistrations().then(n=>n.forEach(s=>s.unregister())).catch(()=>{});return}let t=()=>{navigator.serviceWorker.register("/sw.js",{scope:"/"}).then(n=>{n.addEventListener("updatefound",()=>{let s=n.installing;s&&s.addEventListener("statechange",()=>{s.state==="installed"&&navigator.serviceWorker.controller&&console.info("[pwa] New version ready \u2014 reload to apply")})})}).catch(()=>{navigator.serviceWorker.getRegistrations().then(n=>n.forEach(s=>s.unregister())).catch(()=>{})})};document.readyState==="complete"?setTimeout(t,0):window.addEventListener("load",()=>setTimeout(t,0))}async function qo(){if(!Xt)return!1;Xt.prompt();let e=await Xt.userChoice.catch(()=>null);return Xt=null,document.getElementById("btn-pwa-install")?.classList.add("hidden"),e?.outcome==="accepted"}en();ds();hn();Ss();R();ue();O();Ts();function Ei(){document.getElementById("root").insertAdjacentHTML("beforeend",`
|
|
539
|
+
<dialog id="modal-settings" class="modal">
|
|
540
|
+
<div class="modal-box max-w-lg">
|
|
541
|
+
<h3 class="font-bold text-base mb-4">Settings</h3>
|
|
542
|
+
<div id="ws-list" class="flex flex-col gap-2 mb-4"></div>
|
|
543
|
+
<div class="border-t border-base-300 pt-4">
|
|
544
|
+
<div class="text-xs uppercase tracking-wider text-base-content/50 mb-2">Add workspace</div>
|
|
545
|
+
<div class="flex gap-2 mb-2">
|
|
546
|
+
<input id="ws-new-name" type="text" placeholder="Name (e.g. personal)" class="input input-sm input-bordered flex-1">
|
|
547
|
+
<input id="ws-new-dir" type="text" placeholder="~/.claude-personal" class="input input-sm input-bordered flex-[2]">
|
|
548
|
+
<button id="ws-add-btn" class="btn btn-primary btn-sm">Add</button>
|
|
549
|
+
</div>
|
|
550
|
+
<div id="ws-error" class="alert alert-error text-xs py-1.5 hidden"></div>
|
|
551
|
+
</div>
|
|
552
|
+
<div id="mcp-token-settings" class="border-t border-base-300 pt-4 mt-4">
|
|
553
|
+
<div class="flex items-center justify-between gap-2 mb-2">
|
|
554
|
+
<div>
|
|
555
|
+
<div class="text-xs uppercase tracking-wider text-base-content/50">MCP access token</div>
|
|
556
|
+
<p class="text-[11px] text-base-content/45 mt-0.5">The token is shown once. Set its expiry before generating.</p>
|
|
557
|
+
</div>
|
|
558
|
+
<select id="mcp-token-expiry" class="select select-xs select-bordered">
|
|
559
|
+
<option value="86400">24 hours</option>
|
|
560
|
+
<option value="604800">7 days</option>
|
|
561
|
+
<option value="2592000">30 days</option>
|
|
562
|
+
</select>
|
|
563
|
+
</div>
|
|
564
|
+
<button id="mcp-token-generate" class="btn btn-sm btn-primary w-full">Generate MCP token</button>
|
|
565
|
+
<div id="mcp-token-result" class="hidden mt-2">
|
|
566
|
+
<textarea id="mcp-token-value" readonly class="textarea textarea-bordered textarea-xs w-full h-20 font-mono"></textarea>
|
|
567
|
+
<button id="mcp-token-copy" class="btn btn-ghost btn-xs mt-1">Copy token</button>
|
|
568
|
+
</div>
|
|
569
|
+
<div id="mcp-token-error" class="alert alert-error text-xs py-1.5 hidden mt-2"></div>
|
|
570
|
+
</div>
|
|
571
|
+
<div class="modal-action">
|
|
572
|
+
<form method="dialog"><button class="btn btn-ghost btn-sm">Close</button></form>
|
|
573
|
+
</div>
|
|
574
|
+
</div>
|
|
575
|
+
<form method="dialog" class="modal-backdrop"><button>close</button></form>
|
|
576
|
+
</dialog>`),Ms(),document.getElementById("ws-add-btn").addEventListener("click",Pa),document.getElementById("ws-new-name").addEventListener("keydown",e=>{e.key==="Enter"&&Pa()}),document.getElementById("ws-new-dir").addEventListener("keydown",e=>{e.key==="Enter"&&Pa()}),document.getElementById("mcp-token-generate").addEventListener("click",jl),document.getElementById("mcp-token-copy").addEventListener("click",Dl)}function Ms(){let e=i("ws-list");if(!e)return;let t=ee.peek();if(!t.length){e.innerHTML='<div class="text-xs text-base-content/40">No workspaces configured</div>';return}e.innerHTML=t.map(n=>`
|
|
577
|
+
<div class="flex items-center gap-2 px-3 py-2 bg-base-200 rounded-lg">
|
|
578
|
+
<div class="flex-1 min-w-0">
|
|
579
|
+
<div class="text-sm font-medium">${p(n.name)}</div>
|
|
580
|
+
<div class="text-xs font-mono text-base-content/50 truncate">${p(n.configDir)}</div>
|
|
581
|
+
</div>
|
|
582
|
+
${t.length>1?`<button class="btn btn-ghost btn-xs text-error" data-ws-delete="${p(n.id)}">\u2715</button>`:'<span class="text-[10px] text-base-content/30">default</span>'}
|
|
583
|
+
</div>`).join(""),e.querySelectorAll("[data-ws-delete]").forEach(n=>{n.addEventListener("click",()=>Al(n.dataset.wsDelete))})}async function Pa(){let e=i("ws-new-name").value.trim(),t=i("ws-new-dir").value.trim(),n=i("ws-error");if(n.classList.add("hidden"),!e||!t){n.textContent="Name and path are required",n.classList.remove("hidden");return}try{let s=await y("POST","/api/workspaces",{name:e,configDir:t});ee.value=[...ee.peek(),s],qn(ee.peek()),i("ws-new-name").value="",i("ws-new-dir").value="",Ms()}catch(s){n.textContent=s.message,n.classList.remove("hidden")}}async function Al(e){try{await y("DELETE",`/api/workspaces/${e}`),ee.value=ee.peek().filter(t=>t.id!==e),qn(ee.peek()),Ms()}catch(t){alert(t.message)}}function Ha(){Ms();let e=i("mcp-token-settings");e&&(e.style.display=A.peek()?"":"none"),i("modal-settings")?.showModal()}async function jl(){let e=i("mcp-token-result"),t=i("mcp-token-error");e?.classList.add("hidden"),t?.classList.add("hidden");let n=j.peek();if(!n){t.textContent="\u8BF7\u9009\u62E9\u4E00\u53F0\u5728\u7EBF\u673A\u5668\u540E\u518D\u751F\u6210 Token\u3002",t.classList.remove("hidden");return}try{let s=Number(i("mcp-token-expiry").value),a=await y("POST",`/api/mcp/tokens?machine=${encodeURIComponent(n)}`,{expiresInSeconds:s});i("mcp-token-value").value=a.token||"",e.classList.remove("hidden")}catch(s){t.textContent=s.message,t.classList.remove("hidden")}}async function Dl(){let e=i("mcp-token-value")?.value;if(e)try{await navigator.clipboard.writeText(e)}catch{i("mcp-token-value")?.select(),document.execCommand("copy")}}Kn();La();O();var Fi=()=>`
|
|
584
|
+
<div id="auth-screen" class="${f.token?"hidden":""} flex items-center justify-center h-full p-4" ${f.token?'style="display:none"':""}>
|
|
585
|
+
<div class="card bg-base-200 border border-base-300 w-full max-w-sm shadow-xl">
|
|
586
|
+
<div class="card-body gap-3 p-8">
|
|
587
|
+
<h1 class="text-xl font-bold">\u{1F916} Agent UI</h1>
|
|
588
|
+
<p id="auth-subtitle" class="text-sm text-base-content/60 mb-1">Claude \xB7 Codex \xB7 Grok \xB7 Gemini \xB7 Cursor</p>
|
|
589
|
+
<form id="auth-form" class="flex flex-col gap-3" autocomplete="on" action="#">
|
|
590
|
+
<label class="form-control">
|
|
591
|
+
<div class="label py-1"><span class="label-text text-xs uppercase tracking-wide">Username</span></div>
|
|
592
|
+
<input id="auth-username" type="text" class="input input-bordered input-sm" placeholder="username" autocomplete="username">
|
|
593
|
+
</label>
|
|
594
|
+
<label class="form-control">
|
|
595
|
+
<div class="label py-1"><span class="label-text text-xs uppercase tracking-wide">Password</span></div>
|
|
596
|
+
<input id="auth-password" type="password" class="input input-bordered input-sm" placeholder="\u2022\u2022\u2022\u2022\u2022\u2022" autocomplete="current-password">
|
|
597
|
+
</label>
|
|
598
|
+
<button type="submit" id="auth-btn" class="btn btn-primary btn-sm mt-1" data-mode="login">Sign In</button>
|
|
599
|
+
</form>
|
|
600
|
+
<div id="auth-error" class="alert alert-error text-xs py-2 hidden"></div>
|
|
601
|
+
</div>
|
|
602
|
+
</div>
|
|
603
|
+
</div>`,Ui=(e={})=>{let t=!!e.restoreSession,n=f.token?"":"hidden",s=f.token?"display:flex":"display:none";return`
|
|
604
|
+
<div id="sidebar-overlay" class="hidden fixed inset-0 bg-black/50 z-[9]" aria-hidden="true"></div>
|
|
605
|
+
<div id="app" class="${n} flex-col flex-1 overflow-hidden" style="${s}">
|
|
606
|
+
<div id="topbar" class="flex items-center gap-2 px-3 bg-base-200 border-b border-base-300 flex-shrink-0" style="height:44px">
|
|
607
|
+
<button id="hamburger" class="btn btn-ghost btn-sm px-2 text-lg" aria-label="\u6253\u5F00\u9879\u76EE\u4E0E\u4F1A\u8BDD\u4FA7\u680F" aria-controls="sidebar" aria-expanded="false">\u2630</button>
|
|
608
|
+
<span id="btn-home" class="font-semibold text-sm hidden sm:inline cursor-pointer hover:text-primary transition-colors select-none">\u{1F916} Agent UI</span>
|
|
609
|
+
<span class="text-base-300 hidden sm:inline">/</span>
|
|
610
|
+
<div id="machine-menu-wrap" class="relative hidden flex-shrink-0">
|
|
611
|
+
<button type="button" id="btn-machine-menu" class="btn btn-ghost btn-xs border border-base-300 font-mono gap-1 max-w-[11rem]"
|
|
612
|
+
title="\u673A\u5668\u5217\u8868 / \u5207\u6362">
|
|
613
|
+
<span id="topbar-machine-dot" class="w-1.5 h-1.5 rounded-full bg-success flex-shrink-0"></span>
|
|
614
|
+
<span id="topbar-machine-label" class="truncate">\u673A\u5668</span>
|
|
615
|
+
<span class="text-[10px] opacity-50">\u25BE</span>
|
|
616
|
+
</button>
|
|
617
|
+
<div id="machine-menu" class="hidden absolute left-0 top-full mt-1 z-50 w-72 max-h-80 overflow-y-auto
|
|
618
|
+
rounded-lg border border-base-300 bg-base-100 shadow-xl p-2">
|
|
619
|
+
<div class="flex items-center justify-between px-1 pb-1.5 mb-1 border-b border-base-300">
|
|
620
|
+
<span class="text-[10px] uppercase tracking-wide text-base-content/45 font-semibold">Machines</span>
|
|
621
|
+
<button type="button" id="btn-refresh-machines-menu" class="btn btn-ghost btn-xs px-1 text-[10px]">\u21BB</button>
|
|
622
|
+
</div>
|
|
623
|
+
<div id="machine-menu-list" class="flex flex-col gap-1"></div>
|
|
624
|
+
<p id="machine-menu-empty" class="text-xs text-base-content/40 px-1 py-2 hidden">\u6682\u65E0\u673A\u5668\u5728\u7EBF</p>
|
|
625
|
+
</div>
|
|
626
|
+
</div>
|
|
627
|
+
<div id="recent-menu-wrap" class="relative flex-shrink-0">
|
|
628
|
+
<button type="button" id="btn-recent-sessions" class="btn btn-ghost btn-xs border border-base-300 gap-1 min-h-8 px-2"
|
|
629
|
+
title="\u6700\u8FD1\u4F1A\u8BDD / \u5FEB\u901F\u8DF3\u8F6C" aria-haspopup="listbox" aria-expanded="false">
|
|
630
|
+
<span>\u6700\u8FD1</span>
|
|
631
|
+
<span class="text-[10px] opacity-50">\u25BE</span>
|
|
632
|
+
</button>
|
|
633
|
+
</div>
|
|
634
|
+
<div id="notifications-wrap" class="relative flex-shrink-0">
|
|
635
|
+
<button type="button" id="btn-notifications" class="btn btn-ghost btn-xs border border-base-300 gap-1 min-h-8 px-2"
|
|
636
|
+
title="\u901A\u77E5" aria-haspopup="dialog" aria-expanded="false">
|
|
637
|
+
<span>\u{1F514}</span>
|
|
638
|
+
<span id="notifications-badge" class="hidden inline-flex min-w-5 h-5 px-1 items-center justify-center rounded-full bg-error text-error-content text-[10px] font-bold">0</span>
|
|
639
|
+
</button>
|
|
640
|
+
</div>
|
|
641
|
+
<span id="topbar-project" class="text-sm text-base-content/50 flex-1 truncate min-w-0">Select a session</span>
|
|
642
|
+
<span id="conn-dot" class="w-2 h-2 rounded-full bg-base-content/30 flex-shrink-0" title="\u8FDE\u63A5\u72B6\u6001"></span>
|
|
643
|
+
<div class="flex gap-2 topbar-actions">
|
|
644
|
+
<button id="btn-share-session" class="btn btn-ghost btn-xs border border-base-300" title="\u590D\u5236\u5F53\u524D\u4F1A\u8BDD\u5206\u4EAB\u94FE\u63A5">\u5206\u4EAB</button>
|
|
645
|
+
<button id="btn-refresh-conn" class="btn btn-ghost btn-xs border border-base-300" title="\u91CD\u65B0\u8FDE\u63A5\u5E76\u540C\u6B65">\u21BB</button>
|
|
646
|
+
<button id="btn-pwa-install" class="btn btn-ghost btn-xs border border-base-300 hidden" title="\u5B89\u88C5\u5230\u4E3B\u5C4F\u5E55">\u5B89\u88C5</button>
|
|
647
|
+
<button id="btn-meta-agent" class="btn btn-ghost btn-xs border border-primary/40 text-primary topbar-icon-btn" title="Meta Agent \u2014 \u62A5\u544A / \u95EE\u7B54 / VLM" aria-label="\u6253\u5F00 Meta Agent">
|
|
648
|
+
<svg class="topbar-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" aria-hidden="true"><path d="m12 2 1.6 6.4L20 10l-6.4 1.6L12 18l-1.6-6.4L4 10l6.4-1.6L12 2Z"/><path d="m19 16 .7 2.3L22 19l-2.3.7L19 22l-.7-2.3L16 19l2.3-.7L19 16Z"/></svg><span class="topbar-icon-label">Agent</span>
|
|
649
|
+
</button>
|
|
650
|
+
<button id="btn-new-session" class="btn btn-ghost btn-xs border border-base-300 topbar-icon-btn" title="New session" aria-label="\u65B0\u5EFA\u4F1A\u8BDD">
|
|
651
|
+
<svg class="topbar-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" aria-hidden="true"><circle cx="12" cy="12" r="8"/><path d="M12 8v8M8 12h8"/></svg><span class="topbar-icon-label">New</span>
|
|
652
|
+
</button>
|
|
653
|
+
<button id="btn-theme" class="btn btn-ghost btn-xs border border-base-300 topbar-icon-btn" title="\u5207\u6362\u4E3B\u9898" aria-label="\u5207\u6362\u4E3B\u9898"><svg class="topbar-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" aria-hidden="true"><path d="M20 15.5A8 8 0 0 1 8.5 4 8 8 0 1 0 20 15.5Z"/></svg></button>
|
|
654
|
+
<button id="btn-settings" class="btn btn-ghost btn-xs border border-base-300 topbar-icon-btn" title="\u8BBE\u7F6E" aria-label="\u8BBE\u7F6E"><svg class="topbar-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" aria-hidden="true"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.7 1.7 0 0 0 .34 1.88l.06.06-2.12 2.12-.06-.06A1.7 1.7 0 0 0 15.74 18a1.7 1.7 0 0 0-1.02 1.56V20h-3v-.44A1.7 1.7 0 0 0 10.7 18a1.7 1.7 0 0 0-1.88.34l-.06.06-2.12-2.12.06-.06A1.7 1.7 0 0 0 7.04 14.3 1.7 1.7 0 0 0 5.5 13.28H5v-3h.5a1.7 1.7 0 0 0 1.54-1.02A1.7 1.7 0 0 0 6.7 7.38l-.06-.06L8.76 5.2l.06.06A1.7 1.7 0 0 0 10.7 5a1.7 1.7 0 0 0 1.02-1.56V3h3v.44A1.7 1.7 0 0 0 15.74 5a1.7 1.7 0 0 0 1.88-.34l.06-.06 2.12 2.12-.06.06a1.7 1.7 0 0 0-.34 1.88 1.7 1.7 0 0 0 1.56 1.02h.5v3h-.5A1.7 1.7 0 0 0 19.4 15Z"/></svg></button>
|
|
655
|
+
<button id="btn-logout" class="btn btn-ghost btn-xs border border-base-300">Sign out</button>
|
|
656
|
+
</div>
|
|
657
|
+
</div>
|
|
658
|
+
<!-- Fixed panel + backdrop: siblings of topbar so flex layout never clips them -->
|
|
659
|
+
<div id="recent-menu-backdrop" class="hidden fixed inset-0 z-[55] bg-black/40" aria-hidden="true"></div>
|
|
660
|
+
<div id="recent-menu" class="hidden fixed z-[60] w-80 max-h-[min(24rem,70vh)] overflow-y-auto
|
|
661
|
+
rounded-lg border border-base-300 bg-base-100 shadow-xl p-2"
|
|
662
|
+
role="listbox" aria-label="\u6700\u8FD1\u4F1A\u8BDD">
|
|
663
|
+
<div class="flex items-center justify-between px-1 pb-1.5 mb-1 border-b border-base-300 sticky top-0 bg-base-100 z-[1]">
|
|
664
|
+
<span class="text-[10px] uppercase tracking-wide text-base-content/45 font-semibold">\u6700\u8FD1\u4F1A\u8BDD</span>
|
|
665
|
+
<span id="recent-menu-count" class="text-[10px] text-base-content/35 font-mono"></span>
|
|
666
|
+
</div>
|
|
667
|
+
<div id="recent-menu-list" class="flex flex-col gap-0.5"></div>
|
|
668
|
+
<p id="recent-menu-empty" class="text-xs text-base-content/40 px-1 py-2 hidden">\u6682\u65E0\u6700\u8FD1\u4F1A\u8BDD</p>
|
|
669
|
+
</div>
|
|
670
|
+
<div id="notifications-backdrop" class="hidden fixed inset-0 z-[55] bg-black/40" aria-hidden="true"></div>
|
|
671
|
+
<div id="notifications-menu" class="hidden fixed z-[60] w-[min(26rem,calc(100vw-1rem))] max-h-[min(30rem,75vh)] overflow-y-auto
|
|
672
|
+
rounded-lg border border-base-300 bg-base-100 shadow-xl p-2"
|
|
673
|
+
role="dialog" aria-label="\u901A\u77E5\u4E2D\u5FC3">
|
|
674
|
+
<div class="flex items-center justify-between px-1 pb-1.5 mb-1 border-b border-base-300 sticky top-0 bg-base-100 z-[1]">
|
|
675
|
+
<span class="text-[10px] uppercase tracking-wide text-base-content/45 font-semibold">\u901A\u77E5</span>
|
|
676
|
+
<button type="button" id="btn-notifications-read-all" class="btn btn-ghost btn-xs px-1 text-[10px]">\u5168\u90E8\u5DF2\u8BFB</button>
|
|
677
|
+
</div>
|
|
678
|
+
<div id="notifications-menu-list" class="flex flex-col gap-1"></div>
|
|
679
|
+
<p id="notifications-menu-empty" class="text-xs text-base-content/40 px-1 py-2 hidden">\u6682\u65E0\u901A\u77E5</p>
|
|
680
|
+
</div>
|
|
681
|
+
<!-- Hub: only when no remembered machine (or last one offline) -->
|
|
682
|
+
<div id="machine-picker" class="hidden fixed inset-0 z-[60] bg-base-100 flex items-center justify-center p-4">
|
|
683
|
+
<div class="w-full max-w-md">
|
|
684
|
+
<h2 class="text-xl font-bold mb-1">\u9009\u62E9\u673A\u5668</h2>
|
|
685
|
+
<p class="text-sm text-base-content/55 mb-4">\u9996\u6B21\u4F7F\u7528\u6216\u4E0A\u6B21\u9009\u62E9\u7684\u673A\u5668\u4E0D\u5728\u7EBF\u65F6\u9700\u8981\u9009\u62E9\u3002\u4E4B\u540E\u4F1A\u8BB0\u4F4F\u4F60\u7684\u9009\u62E9\uFF0C\u4E5F\u53EF\u968F\u65F6\u5728\u9876\u680F\u5207\u6362\u3002</p>
|
|
686
|
+
<div id="machine-picker-list" class="flex flex-col gap-2 mb-4"></div>
|
|
687
|
+
<p id="machine-picker-empty" class="text-sm text-base-content/40 hidden">\u6682\u65E0\u5728\u7EBF\u673A\u5668\u3002\u8BF7\u5728\u4E1A\u52A1\u673A\u4E0A\u8FD0\u884C <code class="text-xs">npm run client</code> \u540E\u70B9\u5237\u65B0\u3002</p>
|
|
688
|
+
<div class="flex items-center gap-2">
|
|
689
|
+
<button id="btn-refresh-machines" class="btn btn-ghost btn-sm border border-base-300">\u21BB \u5237\u65B0</button>
|
|
690
|
+
<span id="machine-picker-status" class="text-xs text-base-content/40"></span>
|
|
691
|
+
</div>
|
|
692
|
+
</div>
|
|
693
|
+
</div>
|
|
694
|
+
<div class="flex flex-1 overflow-hidden relative">
|
|
695
|
+
<aside id="sidebar" class="bg-base-200 border-r border-base-300 flex flex-col flex-shrink-0 overflow-hidden" style="width:280px;min-width:180px;max-width:520px" aria-label="\u9879\u76EE\u4E0E\u4F1A\u8BDD" tabindex="-1">
|
|
696
|
+
<div class="flex items-center justify-between px-3 py-2 border-b border-base-300 flex-shrink-0">
|
|
697
|
+
<span class="text-xs uppercase tracking-wider text-base-content/50 font-medium">Projects</span>
|
|
698
|
+
<div class="flex items-center gap-1">
|
|
699
|
+
<span id="session-filter-badge" class="hidden text-[10px] text-primary cursor-pointer">\xD7 filter</span>
|
|
700
|
+
<button id="sidebar-refresh" class="btn btn-ghost btn-xs px-1 text-[10px] text-base-content/40" title="Refresh">\u21BB</button>
|
|
701
|
+
</div>
|
|
702
|
+
</div>
|
|
703
|
+
<div id="ws-tabs" class="flex overflow-x-auto border-b border-base-300 flex-shrink-0" style="scrollbar-width:none"></div>
|
|
704
|
+
<div class="px-2 py-1.5 border-b border-base-300 flex-shrink-0 relative">
|
|
705
|
+
<div class="flex gap-1.5">
|
|
706
|
+
<input id="session-search" type="text" placeholder="Search projects & recent work\u2026"
|
|
707
|
+
class="input input-xs input-bordered flex-1 min-w-0 text-xs" autocomplete="off">
|
|
708
|
+
<button id="sidebar-filter-toggle" type="button" class="btn btn-ghost btn-xs border border-base-300 px-2" title="\u7B5B\u9009\u9879\u76EE" aria-expanded="false">\u2699</button>
|
|
709
|
+
</div>
|
|
710
|
+
<div id="sidebar-filter-menu" class="hidden absolute left-2 right-2 top-[calc(100%-.25rem)] z-30 rounded-lg border border-base-300 bg-base-100 p-2 shadow-xl">
|
|
711
|
+
<div class="text-[10px] uppercase tracking-wide text-base-content/45 mb-1.5">Agents \xB7 multi-select</div>
|
|
712
|
+
<div class="grid grid-cols-2 gap-1 text-xs">
|
|
713
|
+
<label><input type="checkbox" data-agent-option="claude"> Claude</label>
|
|
714
|
+
<label><input type="checkbox" data-agent-option="codex"> Codex</label>
|
|
715
|
+
<label><input type="checkbox" data-agent-option="grok"> Grok</label>
|
|
716
|
+
<label><input type="checkbox" data-agent-option="gemini"> Gemini</label>
|
|
717
|
+
<label><input type="checkbox" data-agent-option="cursor"> Cursor</label>
|
|
718
|
+
</div>
|
|
719
|
+
<div class="mt-2 pt-2 border-t border-base-300 flex gap-3 text-xs">
|
|
720
|
+
<label><input id="filter-favorites" type="checkbox"> Favorites</label>
|
|
721
|
+
<label><input id="filter-hidden" type="checkbox"> Hidden</label>
|
|
722
|
+
<button id="filter-clear" type="button" class="ml-auto text-primary">Clear</button>
|
|
723
|
+
</div>
|
|
724
|
+
</div>
|
|
725
|
+
<div id="search-status" class="hidden text-[10px] text-base-content/40 px-0.5"></div>
|
|
726
|
+
</div>
|
|
727
|
+
<div id="session-list" class="overflow-y-auto flex-1"></div>
|
|
728
|
+
<div class="sidebar-mobile-actions hidden border-t border-base-300 px-2 py-2 flex-shrink-0">
|
|
729
|
+
<button type="button" class="btn btn-primary btn-sm flex-1" data-sidebar-action="new">\uFF0B \u65B0\u4F1A\u8BDD</button>
|
|
730
|
+
<button type="button" class="btn btn-ghost btn-sm px-2" data-sidebar-action="theme" aria-label="\u5207\u6362\u6DF1\u8272\u6216\u6D45\u8272\u4E3B\u9898">\u{1F319}</button>
|
|
731
|
+
<button type="button" class="btn btn-ghost btn-sm px-2" data-sidebar-action="settings" aria-label="\u8BBE\u7F6E">\u2699\uFE0F</button>
|
|
732
|
+
<button type="button" class="btn btn-ghost btn-sm px-2 text-error" data-sidebar-action="logout" aria-label="\u9000\u51FA\u767B\u5F55">\u21E5</button>
|
|
733
|
+
</div>
|
|
734
|
+
</aside>
|
|
735
|
+
<div class="flex flex-col flex-shrink-0 relative" style="width:12px">
|
|
736
|
+
<div id="sidebar-resize" class="absolute inset-0 bg-transparent hover:bg-primary/30 transition-colors cursor-col-resize"></div>
|
|
737
|
+
<button id="sidebar-toggle" title="\u6536\u8D77\u4FA7\u680F" aria-label="\u6536\u8D77\u4FA7\u680F" aria-controls="sidebar" aria-expanded="true"
|
|
738
|
+
class="absolute z-10 flex items-center justify-center w-5 h-8 bg-base-200 border border-base-300 rounded-r-md text-[10px] text-base-content/40 hover:text-base-content cursor-pointer"
|
|
739
|
+
style="left:0;top:50%;transform:translateY(-50%)">\u25C0</button>
|
|
740
|
+
</div>
|
|
741
|
+
<div id="main" class="flex-1 flex flex-col overflow-hidden min-w-0">
|
|
742
|
+
<div id="welcome" class="${t?"hidden flex-1 flex-col items-center justify-start overflow-y-auto p-4 md:p-6 gap-5":"flex-1 flex flex-col items-center justify-start overflow-y-auto p-4 md:p-6 gap-5"}">
|
|
743
|
+
<div class="max-w-4xl w-full text-center flex flex-col items-center gap-2 mt-2 md:mt-4">
|
|
744
|
+
<h2 class="text-3xl font-extrabold tracking-tight bg-gradient-to-r from-primary to-accent bg-clip-text text-transparent select-none">\u{1F916} Agent UI</h2>
|
|
745
|
+
<p class="text-sm text-base-content/65 max-w-md">Claude \xB7 Codex \xB7 Grok \xB7 Gemini \u2014 Select a session from the sidebar or click a day on the calendar to view activity.</p>
|
|
746
|
+
<div class="flex gap-2 mt-0.5">
|
|
747
|
+
<button id="btn-new-session-welcome" class="btn btn-primary btn-sm shadow-md">\uFF0B New Session</button>
|
|
748
|
+
<button id="btn-meta-agent-welcome" class="btn btn-outline btn-primary btn-sm">\u2726 Meta Agent</button>
|
|
749
|
+
</div>
|
|
750
|
+
</div>
|
|
751
|
+
|
|
752
|
+
<!-- Stats Banner -->
|
|
753
|
+
<div class="max-w-4xl w-full grid grid-cols-2 md:grid-cols-4 gap-4 text-center select-none mt-1">
|
|
754
|
+
<div class="bg-base-200 border border-base-300 rounded-2xl p-3 shadow-md flex flex-col justify-center items-center">
|
|
755
|
+
<span class="text-[10px] uppercase tracking-wider text-base-content/40 font-bold">Total Sessions</span>
|
|
756
|
+
<span id="stats-total-sessions" class="text-xl md:text-2xl font-extrabold text-primary mt-0.5">0</span>
|
|
757
|
+
</div>
|
|
758
|
+
<div class="bg-base-200 border border-base-300 rounded-2xl p-3 shadow-md flex flex-col justify-center items-center">
|
|
759
|
+
<span class="text-[10px] uppercase tracking-wider text-base-content/40 font-bold">Active Projects</span>
|
|
760
|
+
<span id="stats-total-projects" class="text-xl md:text-2xl font-extrabold text-accent mt-0.5">0</span>
|
|
761
|
+
</div>
|
|
762
|
+
<div class="bg-base-200 border border-base-300 rounded-2xl p-3 shadow-md flex flex-col justify-center items-center">
|
|
763
|
+
<span class="text-[10px] uppercase tracking-wider text-base-content/40 font-bold">Total Tokens</span>
|
|
764
|
+
<span id="stats-total-tokens" class="text-xl md:text-2xl font-extrabold text-secondary mt-0.5">0</span>
|
|
765
|
+
</div>
|
|
766
|
+
<div class="bg-base-200 border border-base-300 rounded-2xl p-3 shadow-md flex flex-col justify-center items-center">
|
|
767
|
+
<span class="text-[10px] uppercase tracking-wider text-base-content/40 font-bold">Selected Day Tokens</span>
|
|
768
|
+
<span id="stats-selected-tokens" class="text-xl md:text-2xl font-extrabold text-success mt-0.5">0</span>
|
|
769
|
+
</div>
|
|
770
|
+
</div>
|
|
771
|
+
<div class="max-w-4xl w-full grid grid-cols-1 md:grid-cols-12 gap-5 items-start text-left">
|
|
772
|
+
<!-- Calendar Card -->
|
|
773
|
+
<div class="card bg-base-200 border border-base-300 md:col-span-7 shadow-xl">
|
|
774
|
+
<div class="card-body p-4">
|
|
775
|
+
<div class="flex items-center justify-between mb-3">
|
|
776
|
+
<button id="btn-cal-prev" class="btn btn-ghost btn-sm text-base font-bold">\u25C0</button>
|
|
777
|
+
<h3 id="calendar-month-year" class="text-base font-extrabold text-base-content select-none"></h3>
|
|
778
|
+
<button id="btn-cal-next" class="btn btn-ghost btn-sm text-base font-bold">\u25B6</button>
|
|
779
|
+
</div>
|
|
780
|
+
|
|
781
|
+
<div class="grid grid-cols-7 gap-2 text-center text-[10px] font-bold text-base-content/40 mb-1">
|
|
782
|
+
<div>Sun</div><div>Mon</div><div>Tue</div><div>Wed</div><div>Thu</div><div>Fri</div><div>Sat</div>
|
|
783
|
+
</div>
|
|
784
|
+
|
|
785
|
+
<div id="calendar-grid" class="grid grid-cols-7 gap-2">
|
|
786
|
+
<!-- JS Rendered -->
|
|
787
|
+
</div>
|
|
788
|
+
</div>
|
|
789
|
+
</div>
|
|
790
|
+
|
|
791
|
+
<!-- Details Card -->
|
|
792
|
+
<div class="card bg-base-200 border border-base-300 md:col-span-5 shadow-xl min-h-[290px] flex flex-col">
|
|
793
|
+
<div class="card-body p-4 flex flex-col flex-1">
|
|
794
|
+
<h3 id="selected-day-title" class="card-title text-xs font-bold uppercase tracking-wider text-base-content/50 mb-3 select-none">Daily Activity</h3>
|
|
795
|
+
<div id="selected-day-sessions" class="flex-1 overflow-y-auto flex flex-col gap-2 max-h-[250px]">
|
|
796
|
+
<div class="text-center text-xs text-base-content/40 my-auto py-6">Select a date on the calendar to view its sessions.</div>
|
|
797
|
+
</div>
|
|
798
|
+
</div>
|
|
799
|
+
</div>
|
|
800
|
+
</div>
|
|
801
|
+
|
|
802
|
+
<!-- Recent Sessions Section -->
|
|
803
|
+
<div class="max-w-4xl w-full border-t border-base-300/60 pt-4 mt-1 text-left">
|
|
804
|
+
<h3 class="text-xs font-bold uppercase tracking-wider text-base-content/50 mb-3 select-none">Recent Workspaces & Sessions</h3>
|
|
805
|
+
<div id="recent-sessions-list" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3">
|
|
806
|
+
<!-- JS Rendered -->
|
|
807
|
+
</div>
|
|
808
|
+
</div>
|
|
809
|
+
</div>
|
|
810
|
+
<div id="project-view" class="${t?"flex flex-col flex-1 overflow-hidden min-h-0":"hidden flex-col flex-1 overflow-hidden min-h-0"}" style="${t?"display:flex;flex-direction:column;flex:1;min-height:0":""}">
|
|
811
|
+
<div class="flex bg-base-200 border-b border-base-300 flex-shrink-0 overflow-x-auto" style="scrollbar-width:none">
|
|
812
|
+
<button class="px-4 py-2.5 text-sm border-b-2 flex-shrink-0 text-primary border-primary" data-tab="chat">Chat</button>
|
|
813
|
+
<button class="px-4 py-2.5 text-sm border-b-2 flex-shrink-0 text-base-content/50 border-transparent" data-tab="files">Files</button>
|
|
814
|
+
<button class="px-4 py-2.5 text-sm border-b-2 flex-shrink-0 text-base-content/50 border-transparent" data-tab="git">Git</button>
|
|
815
|
+
<button class="px-4 py-2.5 text-sm border-b-2 flex-shrink-0 text-base-content/50 border-transparent" data-tab="shell">Shell</button>
|
|
816
|
+
<button class="px-4 py-2.5 text-sm border-b-2 flex-shrink-0 text-base-content/50 border-transparent" data-tab="memory">\u{1F9E0} Memory</button>
|
|
817
|
+
</div>
|
|
818
|
+
<div id="tab-chat" class="flex flex-col flex-1 overflow-hidden relative">
|
|
819
|
+
<div id="project-notes-bar" class="bg-base-200 border-b border-base-300 px-3 py-1.5 text-xs flex flex-col gap-1" style="display:none"></div>
|
|
820
|
+
<div id="session-notes-bar" class="bg-base-200/80 border-b border-base-300 px-3 py-1 text-xs flex justify-between items-center gap-2" style="display:none"></div>
|
|
821
|
+
<div id="ws-banner" class="hidden px-3 py-1.5 text-[11px] text-center bg-warning/15 text-warning border-b border-warning/20 flex items-center justify-center gap-2">
|
|
822
|
+
<span id="ws-banner-text"></span>
|
|
823
|
+
<button type="button" id="ws-banner-retry" class="btn btn-ghost btn-xs h-6 min-h-0 px-2 text-warning border border-warning/30">\u91CD\u8FDE</button>
|
|
824
|
+
</div>
|
|
825
|
+
<div id="messages" class="flex-1 overflow-y-auto p-3 flex flex-col gap-2"></div>
|
|
826
|
+
<div id="scroll-nav" class="absolute right-3 bottom-24 flex flex-col gap-1.5 z-10">
|
|
827
|
+
<button id="scroll-top-btn" class="scroll-fab hidden" title="Jump to top">\u2191</button>
|
|
828
|
+
<button id="scroll-bottom-btn" class="scroll-fab hidden" title="Jump to bottom">\u2193</button>
|
|
829
|
+
</div>
|
|
830
|
+
<div id="permission-requests"></div>
|
|
831
|
+
<form id="chat-form" autocomplete="off" action="#" class="flex flex-col flex-shrink-0">
|
|
832
|
+
<div id="chat-composer" class="flex flex-col border-t border-base-300 bg-base-200 flex-shrink-0">
|
|
833
|
+
<div id="chat-attach-bar" class="hidden flex flex-wrap gap-1.5 px-3 pt-2"></div>
|
|
834
|
+
<div id="chat-opts" class="hidden flex items-center gap-1.5 px-3 pt-2 flex-wrap" inert>
|
|
835
|
+
<select id="sel-agent" class="select select-xs select-bordered text-xs font-semibold" title="Agent">
|
|
836
|
+
<option value="claude">Claude</option>
|
|
837
|
+
<option value="codex">Codex</option>
|
|
838
|
+
<option value="grok">Grok</option>
|
|
839
|
+
<option value="gemini">Gemini</option>
|
|
840
|
+
<option value="cursor">Cursor</option>
|
|
841
|
+
</select>
|
|
842
|
+
<select id="sel-convert-agent" class="select select-xs select-bordered text-xs font-semibold" title="Convert session to another agent">
|
|
843
|
+
<option value="" disabled selected>Convert to...</option>
|
|
844
|
+
<option value="claude">Convert to Claude</option>
|
|
845
|
+
<option value="codex">Convert to Codex</option>
|
|
846
|
+
<option value="grok">Convert to Grok</option>
|
|
847
|
+
</select>
|
|
848
|
+
<div class="flex items-center gap-0.5">
|
|
849
|
+
<select id="sel-model" class="select select-xs select-bordered font-mono text-xs max-w-[11rem]" title="Model">
|
|
850
|
+
<option value="claude-sonnet-4-5">sonnet-4-5</option>
|
|
851
|
+
<option value="claude-sonnet-4-6">sonnet-4-6</option>
|
|
852
|
+
<option value="claude-opus-4-5">opus-4-5</option>
|
|
853
|
+
<option value="claude-haiku-4-5">haiku-4-5</option>
|
|
854
|
+
</select>
|
|
855
|
+
<button type="button" id="btn-model-add" class="btn btn-ghost btn-xs px-1.5 font-mono" title="Add / set custom model id">+</button>
|
|
856
|
+
<button type="button" id="btn-model-edit" class="btn btn-ghost btn-xs px-1.5" title="Edit current model id">\u270E</button>
|
|
857
|
+
</div>
|
|
858
|
+
<select id="sel-effort" class="select select-xs select-bordered text-xs" title="Effort">
|
|
859
|
+
<option value="">effort: off</option>
|
|
860
|
+
<option value="low">low</option>
|
|
861
|
+
<option value="medium">medium</option>
|
|
862
|
+
<option value="high">high</option>
|
|
863
|
+
<option value="xhigh">xhigh</option>
|
|
864
|
+
<option value="max">max</option>
|
|
865
|
+
</select>
|
|
866
|
+
<select id="sel-permission" class="select select-xs select-bordered text-xs" title="Permissions">
|
|
867
|
+
<option value="default">perms: default</option>
|
|
868
|
+
<option value="acceptEdits">acceptEdits</option>
|
|
869
|
+
<option value="auto">auto</option>
|
|
870
|
+
<option value="plan">plan</option>
|
|
871
|
+
<option value="bypassPermissions" selected>\u26A0 bypass all</option>
|
|
872
|
+
</select>
|
|
873
|
+
<select id="sel-density" class="select select-xs select-bordered text-xs" title="Chat density \u2014 how tools are shown">
|
|
874
|
+
<option value="clean">density: clean</option>
|
|
875
|
+
<option value="normal">density: normal</option>
|
|
876
|
+
<option value="full">density: full</option>
|
|
877
|
+
</select>
|
|
878
|
+
</div>
|
|
879
|
+
<div id="composer-row" class="px-3 pt-2 pb-2">
|
|
880
|
+
<div class="composer-surface">
|
|
881
|
+
<textarea id="chat-input" rows="1" placeholder="\u95EE\u70B9\u4EC0\u4E48\u2026"
|
|
882
|
+
class="chat-input w-full text-sm resize-none leading-relaxed"
|
|
883
|
+
name="q"
|
|
884
|
+
enterkeyhint="send"
|
|
885
|
+
inputmode="text"
|
|
886
|
+
autocomplete="off"
|
|
887
|
+
autocorrect="off"
|
|
888
|
+
autocapitalize="sentences"
|
|
889
|
+
spellcheck="false"
|
|
890
|
+
data-1p-ignore="true"
|
|
891
|
+
data-lpignore="true"
|
|
892
|
+
data-form-type="other"
|
|
893
|
+
data-bwignore="true"></textarea>
|
|
894
|
+
<div class="composer-actions">
|
|
895
|
+
<div class="composer-tools">
|
|
896
|
+
<button type="button" id="btn-opts" class="composer-icon-btn" title="Options" aria-label="Options">\u2699</button>
|
|
897
|
+
<button type="button" id="btn-attach" class="composer-icon-btn" title="\u6DFB\u52A0\u56FE\u7247 / \u6587\u4EF6" aria-label="\u6DFB\u52A0\u56FE\u7247 / \u6587\u4EF6">\u{1F4CE}</button>
|
|
898
|
+
<input type="file" id="chat-file-input" class="hidden" multiple accept="image/*,*/*" tabindex="-1">
|
|
899
|
+
</div>
|
|
900
|
+
<div class="composer-submit">
|
|
901
|
+
<span class="composer-hint">Enter \u53D1\u9001</span>
|
|
902
|
+
<button type="submit" id="send-btn" class="composer-send-btn">Send</button>
|
|
903
|
+
<button type="button" id="stop-btn" class="composer-stop-btn hidden" aria-label="\u505C\u6B62\u751F\u6210">\u25A0</button>
|
|
904
|
+
</div>
|
|
905
|
+
</div>
|
|
906
|
+
</div>
|
|
907
|
+
</div>
|
|
908
|
+
</div>
|
|
909
|
+
</form>
|
|
910
|
+
</div>
|
|
911
|
+
<div id="tab-files" class="hidden flex-col flex-1 overflow-hidden">
|
|
912
|
+
<div class="flex items-center gap-2 px-3 py-1.5 border-b border-base-300 flex-shrink-0 bg-base-200">
|
|
913
|
+
<span class="text-xs text-base-content/40 flex-shrink-0">Root</span>
|
|
914
|
+
<span id="files-machine-hint" class="hidden text-[10px] font-mono font-semibold text-primary flex-shrink-0"></span>
|
|
915
|
+
<input id="files-root-input" type="text" placeholder="Absolute path on the target machine"
|
|
916
|
+
class="input input-xs flex-1 font-mono text-xs bg-transparent border-0 focus:outline-none px-1" autocomplete="off">
|
|
917
|
+
<button id="files-root-btn" class="btn btn-ghost btn-xs text-xs">Go</button>
|
|
918
|
+
</div>
|
|
919
|
+
<div id="files-breadcrumb" class="flex items-center flex-wrap gap-1 px-4 py-2 border-b border-base-300 text-xs text-base-content/60 flex-shrink-0"></div>
|
|
920
|
+
<div id="files-area" class="flex-1 overflow-y-auto"></div>
|
|
921
|
+
</div>
|
|
922
|
+
<div id="tab-shell" class="hidden flex-col flex-1 overflow-hidden bg-[#0d1117]">
|
|
923
|
+
<div class="flex items-center gap-2 px-3 py-1.5 border-b border-base-300 bg-base-200 flex-shrink-0">
|
|
924
|
+
<span class="text-xs text-base-content/40 font-mono flex-1" id="term-cwd"></span>
|
|
925
|
+
<button id="term-keyboard" class="btn btn-ghost btn-xs text-xs text-base-content/60" type="button">Keyboard</button>
|
|
926
|
+
<button id="term-reconnect" class="btn btn-ghost btn-xs text-xs text-base-content/40">Reconnect</button>
|
|
927
|
+
</div>
|
|
928
|
+
<div id="term-mobile-keys" class="hidden items-center gap-1 px-2 py-1 border-b border-slate-700 bg-[#161b22] flex-shrink-0" aria-label="Terminal shortcuts">
|
|
929
|
+
<button class="term-key" type="button" data-term-key="ctrl-c">Ctrl+C</button>
|
|
930
|
+
<button class="term-key" type="button" data-term-key="escape">Esc</button>
|
|
931
|
+
<button class="term-key" type="button" data-term-key="tab">Tab</button>
|
|
932
|
+
<button class="term-key" type="button" data-term-key="up">\u2191</button>
|
|
933
|
+
<button class="term-key" type="button" data-term-key="down">\u2193</button>
|
|
934
|
+
<button class="term-key" type="button" data-term-key="left">\u2190</button>
|
|
935
|
+
<button class="term-key" type="button" data-term-key="right">\u2192</button>
|
|
936
|
+
</div>
|
|
937
|
+
<div id="terminal-container" class="flex-1 p-2 overflow-hidden"></div>
|
|
938
|
+
<form id="term-mobile-composer" class="hidden items-center gap-2 px-2 py-2 border-t border-slate-700 bg-[#161b22] flex-shrink-0">
|
|
939
|
+
<input id="term-mobile-input" class="term-mobile-input" type="text" placeholder="\u8F93\u5165\u547D\u4EE4\u2026" autocomplete="off" autocapitalize="off" autocorrect="off" spellcheck="false" inputmode="text" enterkeyhint="send" aria-label="Terminal command">
|
|
940
|
+
<button class="term-mobile-send" type="submit">\u53D1\u9001</button>
|
|
941
|
+
</form>
|
|
942
|
+
</div>
|
|
943
|
+
<div id="tab-git" class="hidden flex-col flex-1 overflow-hidden">
|
|
944
|
+
<div class="flex items-center gap-2 px-3 py-1.5 border-b border-base-300 flex-shrink-0 bg-base-200">
|
|
945
|
+
<span class="text-xs text-base-content/40 flex-shrink-0">Root</span>
|
|
946
|
+
<span id="git-machine-hint" class="hidden text-[10px] font-mono font-semibold text-primary flex-shrink-0"></span>
|
|
947
|
+
<input id="git-root-input" type="text" placeholder="Absolute path on the target machine"
|
|
948
|
+
class="input input-xs flex-1 font-mono text-xs bg-transparent border-0 focus:outline-none px-1" autocomplete="off">
|
|
949
|
+
<button id="git-root-btn" class="btn btn-ghost btn-xs text-xs">Go</button>
|
|
950
|
+
</div>
|
|
951
|
+
<div id="git-area" class="flex-1 overflow-y-auto"></div>
|
|
952
|
+
</div>
|
|
953
|
+
<div id="tab-memory" class="hidden flex-col flex-1 overflow-hidden">
|
|
954
|
+
<div class="flex items-center gap-2 px-3 py-1.5 border-b border-base-300 flex-shrink-0 bg-base-200">
|
|
955
|
+
<span class="text-xs text-base-content/40 flex-shrink-0">\u{1F9E0} Agent memory</span>
|
|
956
|
+
<span class="flex-1"></span>
|
|
957
|
+
<button id="memory-refresh" class="btn btn-ghost btn-xs text-xs">Refresh</button>
|
|
958
|
+
</div>
|
|
959
|
+
<div id="memory-area" class="flex-1 overflow-y-auto text-sm"></div>
|
|
960
|
+
</div>
|
|
961
|
+
</div>
|
|
962
|
+
</div>
|
|
963
|
+
</div>
|
|
964
|
+
</div>
|
|
965
|
+
<dialog id="modal-new-session" class="modal">
|
|
966
|
+
<div class="modal-box max-w-sm">
|
|
967
|
+
<h3 class="font-bold text-base mb-4">\uFF0B New Session</h3>
|
|
968
|
+
<div class="flex flex-col gap-3">
|
|
969
|
+
<label class="form-control">
|
|
970
|
+
<div class="label py-1"><span class="label-text text-xs uppercase tracking-wide">Agent</span></div>
|
|
971
|
+
<select id="new-session-agent" class="select select-bordered select-sm">
|
|
972
|
+
<option value="claude">Claude Code</option>
|
|
973
|
+
<option value="codex">OpenAI Codex</option>
|
|
974
|
+
<option value="grok">Grok</option>
|
|
975
|
+
<option value="gemini">Google Gemini (agy)</option>
|
|
976
|
+
<option value="cursor">Cursor Agent</option>
|
|
977
|
+
</select>
|
|
978
|
+
</label>
|
|
979
|
+
<label class="form-control" id="new-session-machine-wrap" style="display:none">
|
|
980
|
+
<div class="label py-1"><span class="label-text text-xs uppercase tracking-wide">Machine (edge server)</span></div>
|
|
981
|
+
<select id="new-session-machine" class="select select-bordered select-sm"></select>
|
|
982
|
+
</label>
|
|
983
|
+
<label class="form-control">
|
|
984
|
+
<div class="label py-1"><span class="label-text text-xs uppercase tracking-wide">Working Directory</span></div>
|
|
985
|
+
<input id="new-session-path" type="text" class="input input-bordered input-sm font-mono"
|
|
986
|
+
placeholder="~/projects/my-app" autocomplete="off">
|
|
987
|
+
</label>
|
|
988
|
+
<label class="form-control" id="new-session-ws-wrap">
|
|
989
|
+
<div class="label py-1"><span class="label-text text-xs uppercase tracking-wide">Claude Workspace</span></div>
|
|
990
|
+
<select id="new-session-workspace" class="select select-bordered select-sm"></select>
|
|
991
|
+
</label>
|
|
992
|
+
<div id="new-session-error" class="alert alert-error text-xs py-2 hidden"></div>
|
|
993
|
+
</div>
|
|
994
|
+
<div class="modal-action">
|
|
995
|
+
<button id="new-session-cancel" class="btn btn-ghost btn-sm">Cancel</button>
|
|
996
|
+
<button id="new-session-start" class="btn btn-primary btn-sm">Start</button>
|
|
997
|
+
</div>
|
|
998
|
+
</div>
|
|
999
|
+
<form method="dialog" class="modal-backdrop"><button>close</button></form>
|
|
1000
|
+
</dialog>`};Ja();Ot();Xn();R();O();ue();Ts();ds();Ot();Qn();Kn();Xn();Yn();en();async function Ys(e={}){i("auth-screen").style.display="none";let t=i("app");t.classList.remove("hidden"),t.style.display="flex",queueMicrotask(xe);let n=e.hub;n===void 0?n=await Yt():n?(A.value=!0,n.machines&&(Q.value=n.machines)):A.value=!1;let s=e.deepLink||null,a=Et();if(!!(s?.id||(location.hash||"").startsWith("#/session/"))){let d=i("welcome");d&&(d.classList.add("hidden"),d.style.display="none");let l=i("project-view");l&&(l.classList.remove("hidden"),l.style.display="flex",l.style.flexDirection="column",l.style.flex="1",l.style.minHeight="0")}if(A.peek()){let d=localStorage.getItem("machineId")||a?.machineId||"";d&&(ge(d),zs(),Be.value=!0,Gn());let l=qt().then(h=>(gt(),d&&!h.some(v=>v.id===d&&v.online!==!1)&&h.length&&(h.some(C=>C.id===d)||(ge(null),Ft())),h));to(),gt();let c=Promise.all([Ke({waitFresh:!1}),yn({waitFresh:!1}),Jn().catch(()=>{}),wn().catch(()=>{})]);if(s?.id){let h=B.peek().find(x=>x.sessionId===s.id)||(a?.sessionId===s.id?a:null);await Pe(s.id,h?.cwd||null,h?.configDir||null,s.agent||h?.agent||null,s.machineId||h?.machineId||d||null,{tab:s.tab||"chat"}),l.catch(()=>{}),c.catch(()=>{});return}if(!d){if(await l,!(Q.peek()||[]).length){Ft(),c.catch(()=>{});return}Ft(),c.catch(()=>{});return}await c;let u=i("topbar-project");u&&u.textContent==="Select a session"&&(u.textContent=`Machine \xB7 ${d}`);return}Gn();let r=Promise.all([Ke({waitFresh:!1}),yn({waitFresh:!1}),Jn().catch(()=>{}),wn().catch(()=>{})]);if(s?.id){await Es().then(l=>{Array.isArray(l)?B.value=l:l&&Array.isArray(l.sessions)&&(B.value=l.sessions)}).catch(()=>{});let d=B.peek().find(l=>l.sessionId===s.id)||(a?.sessionId===s.id?a:null);await Pe(s.id,d?.cwd||null,d?.configDir||null,s.agent||d?.agent||null,null,{tab:s.tab||"chat"}),r.catch(()=>{});return}await r}Qn();Yn();R();O();ue();hn();Ot();Xn();Yn();en();function xr(){let e=i("sidebar");e&&(e.classList.add("open"),i("sidebar-overlay").classList.remove("hidden"),i("hamburger")?.setAttribute("aria-expanded","true"),xe(),setTimeout(()=>i("session-search")?.focus({preventScroll:!0}),180))}function Zn(){let e=i("sidebar");e&&(e.classList.remove("open"),i("sidebar-overlay").classList.add("hidden"),i("hamburger")?.setAttribute("aria-expanded","false"),xe(),i("hamburger")?.focus({preventScroll:!0}))}function vr(){window.innerWidth<=640&&Zn()}function yr(){let e=i("sidebar-toggle"),t=i("sidebar");if(!e||!t)return;let n=localStorage.getItem("sidebarCollapsed")==="1",s=localStorage.getItem("sidebarWidth")||t.style.width||"280px",a=()=>{t.classList.toggle("desktop-collapsed",n),n?(t.style.width="0",t.style.minWidth="0",t.style.overflow="hidden"):(t.style.width=s,t.style.minWidth="",t.style.overflow=""),e.textContent=n?"\u25B6":"\u25C0",e.title=n?"\u5C55\u5F00\u4FA7\u680F":"\u6536\u8D77\u4FA7\u680F",e.setAttribute("aria-label",e.title),e.setAttribute("aria-expanded",n?"false":"true")};a(),e.addEventListener("click",()=>{n=!n,n&&(s=t.style.width||s),localStorage.setItem("sidebarCollapsed",n?"1":"0"),a()})}function wr(){let e=i("sidebar-resize"),t=i("sidebar"),n=!1;e.addEventListener("mousedown",s=>{n=!0,document.body.style.userSelect="none",document.body.style.cursor="col-resize",s.preventDefault()}),document.addEventListener("mousemove",s=>{if(!n)return;let a=Math.min(Math.max(s.clientX,160),520);t.style.width=a+"px",t.style.minWidth=""}),document.addEventListener("mouseup",()=>{if(!n)return;n=!1,document.body.style.userSelect="",document.body.style.cursor="";let s=Math.round(t.getBoundingClientRect().width);s>=160&&localStorage.setItem("sidebarWidth",`${s}px`)})}function ao(e){document.documentElement.setAttribute("data-theme",e),localStorage.setItem("theme",e);let t=i("btn-theme"),n=e==="dark"||e==="night"||e==="black"?"\u{1F319}":"\u2600\uFE0F";t&&(t.textContent=n),document.querySelectorAll('[data-sidebar-action="theme"]').forEach(a=>{a.textContent=n});let s=document.getElementById("hljs-theme");if(s||(s=document.querySelector('link[href*="highlight"][href*="styles"]'),s&&(s.id="hljs-theme")),s){let a=e==="dark"||e==="night"||e==="black";s.href="/vendor/highlight-dark.min.css"}}function oo(){let e=document.documentElement.getAttribute("data-theme")||"dark";ao(e==="dark"?"light":"dark")}function io(){let e=i("new-session-agent");e&&(e.value=I.peek()||"claude");let t=i("new-session-workspace");if(t){let a=ee.peek();t.innerHTML=a.map(o=>`<option value="${p(o.configDir)}">${p(o.name)} \u2014 ${p(o.configDir)}</option>`).join(""),f.configDir&&(t.value=f.configDir)}let n=i("new-session-machine-wrap"),s=i("new-session-machine");if(n&&s)if(A.peek()){n.style.display="";let a=Q.peek()||[],o=j.peek()||"";s.innerHTML=a.length?a.map(r=>`<option value="${p(r.id)}">${p(r.id)}${r.hostname?" \u2014 "+p(r.hostname):""}</option>`).join(""):'<option value="">(no machines online)</option>',o&&(s.value=o),s.disabled=!0}else n.style.display="none",s&&(s.disabled=!1);ro(),i("new-session-path").value=E.peek()?.path||"",i("new-session-error").classList.add("hidden"),i("modal-new-session").showModal(),setTimeout(()=>i("new-session-path").focus(),50)}function ro(){let e=i("new-session-agent")?.value||"claude",t=i("new-session-ws-wrap");t&&(t.style.display=e==="claude"?"":"none")}async function lo(){let e=i("new-session-path").value.trim(),t=i("new-session-agent")?.value||"claude",n=t==="claude"?i("new-session-workspace").value:null,s=i("new-session-error");if(s.classList.add("hidden"),!e){s.textContent="Working directory is required",s.classList.remove("hidden");return}if(A.peek()){let a=j.peek()||i("new-session-machine")?.value||Q.peek()?.[0]?.id;if(!a){s.textContent="\u8BF7\u5148\u9009\u62E9\u4E00\u53F0\u673A\u5668",s.classList.remove("hidden"),Ft();return}ge(a)}try{let a=await y("POST","/api/resolve-path",{path:e});if(!a.isDir)throw new Error("Path is not a directory");i("modal-new-session").close();let o=a.path.split("/").filter(Boolean).pop()||a.path;cn(),un(),fn(),pn(),f.sessionId=null,f.configDir=n||null,f.agent=t,qe(t),le(Oe(t)||P.peek()),Ne(),ae(()=>{E.value={id:o,name:o,path:a.path,machineId:j.peek()||f.machineId},fe.value=a.path,ce.value=a.path,be.value=a.path,z.value="",re.value=null}),i("topbar-project").textContent=a.path;let r=i("files-root-input");r&&(r.value=a.path);let d=i("git-root-input");d&&(d.value=a.path),i("welcome").classList.add("hidden");let l=i("project-view");l.classList.remove("hidden"),l.style.display="flex",mn(),dn({sessionId:null}),st(),it("chat"),L(`New ${te[t]||t} session \xB7 ${a.path}`)}catch(a){s.textContent=a.message,s.classList.remove("hidden")}}function Xl(){let e=/iPad|iPhone|iPod/.test(navigator.userAgent)||navigator.platform==="MacIntel"&&navigator.maxTouchPoints>1,t=/Android/i.test(navigator.userAgent),n;e?n=`<ol class="list-decimal pl-4 space-y-2 text-sm text-base-content/80">
|
|
1001
|
+
<li>\u70B9\u5E95\u90E8\u5206\u4EAB\u6309\u94AE <strong>\u5206\u4EAB</strong>\uFF08\u65B9\u6846+\u5411\u4E0A\u7BAD\u5934\uFF09</li>
|
|
1002
|
+
<li>\u4E0B\u6ED1\u627E\u5230\u5E76\u70B9 <strong>\u6DFB\u52A0\u5230\u4E3B\u5C4F\u5E55</strong></li>
|
|
1003
|
+
<li>\u786E\u8BA4\u540D\u79F0\u540E\u70B9 <strong>\u6DFB\u52A0</strong></li>
|
|
1004
|
+
</ol>
|
|
1005
|
+
<p class="text-xs text-base-content/50 mt-3">\u9700\u7528 <strong>Safari</strong> \u6253\u5F00\u672C\u7AD9\uFF1B\u5FAE\u4FE1/Chrome \u5185\u7F6E\u6D4F\u89C8\u5668\u901A\u5E38\u6CA1\u6709\u300C\u6DFB\u52A0\u5230\u4E3B\u5C4F\u5E55\u300D\u3002</p>
|
|
1006
|
+
<p class="text-xs text-warning/80 mt-2">\u5F53\u524D\u82E5\u662F IP + \u81EA\u7B7E HTTPS\uFF0CSafari \u4ECD\u4F1A\u663E\u793A\u300C\u4E0D\u5B89\u5168\u300D\u3002\u52A0\u5230\u4E3B\u5C4F\u5E55\u53EF\u53BB\u6389\u6D4F\u89C8\u5668\u5916\u58F3\uFF0C\u4F46\u4E0D\u80FD\u53BB\u6389\u7CFB\u7EDF\u8F93\u5165\u6761\u3002\u5F7B\u5E95\u5E72\u51C0\u9700\u8981\u6B63\u5F0F\u57DF\u540D\u8BC1\u4E66\u3002</p>`:t?n=`<ol class="list-decimal pl-4 space-y-2 text-sm text-base-content/80">
|
|
1007
|
+
<li>\u70B9\u53F3\u4E0A\u89D2\u83DC\u5355 <strong>\u22EE</strong></li>
|
|
1008
|
+
<li>\u9009\u62E9 <strong>\u5B89\u88C5\u5E94\u7528</strong> \u6216 <strong>\u6DFB\u52A0\u5230\u4E3B\u5C4F\u5E55</strong></li>
|
|
1009
|
+
</ol>
|
|
1010
|
+
<p class="text-xs text-base-content/50 mt-3">\u82E5\u83DC\u5355\u91CC\u6CA1\u6709\u8BE5\u9879\uFF1A\u8BF7\u7528 <strong>Chrome</strong> \u6253\u5F00\uFF0C\u5E76\u5148\u63A5\u53D7\u672C\u7AD9\u8BC1\u4E66\u63D0\u793A\u3002\u81EA\u7B7E HTTPS \u4E0B\u90E8\u5206\u673A\u578B\u4E0D\u5F39\u51FA\u4E00\u952E\u5B89\u88C5\u3002</p>`:n=`<p class="text-sm text-base-content/80">\u8BF7\u5728\u6D4F\u89C8\u5668\u83DC\u5355\u4E2D\u9009\u62E9 <strong>\u5B89\u88C5\u5E94\u7528 / \u5B89\u88C5\u7F51\u9875\u5E94\u7528 / \u6DFB\u52A0\u5230\u4E3B\u5C4F\u5E55</strong>\u3002</p>
|
|
1011
|
+
<p class="text-xs text-base-content/50 mt-3">Chrome / Edge \u5730\u5740\u680F\u53F3\u4FA7\u6709\u65F6\u4E5F\u4F1A\u51FA\u73B0\u5B89\u88C5\u56FE\u6807\u3002</p>`;let s=document.getElementById("modal-pwa-install");s||(s=document.createElement("dialog"),s.id="modal-pwa-install",s.className="modal",document.body.appendChild(s)),s.innerHTML=`
|
|
1012
|
+
<div class="modal-box max-w-sm">
|
|
1013
|
+
<h3 class="font-bold text-base mb-3">\u5B89\u88C5\u5230\u4E3B\u5C4F\u5E55</h3>
|
|
1014
|
+
${n}
|
|
1015
|
+
<div class="modal-action">
|
|
1016
|
+
<form method="dialog"><button class="btn btn-sm">\u77E5\u9053\u4E86</button></form>
|
|
1017
|
+
</div>
|
|
1018
|
+
</div>
|
|
1019
|
+
<form method="dialog" class="modal-backdrop"><button>close</button></form>`,s.showModal()}async function uo(){let e=i("auth-screen");e&&(e.classList.remove("hidden"),e.style.display="flex");let t=i("app");t&&(t.classList.add("hidden"),t.style.display="none");let n=i("auth-btn"),s,a=new AbortController,o=setTimeout(()=>a.abort(),8e3);try{s=await y("GET","/api/auth/status",void 0,a.signal)}catch(r){console.warn("[auth status]",r);let d=i("auth-error");d&&(d.textContent="\u65E0\u6CD5\u8FDE\u63A5\u670D\u52A1\u5668\u3002\u8BF7\u68C0\u67E5\u7F51\u7EDC\u6216\u670D\u52A1\u5730\u5740\u540E\u91CD\u8BD5\u3002",d.classList.remove("hidden")),n&&(n.dataset.mode="login");return}finally{clearTimeout(o)}s.needsSetup?(i("auth-subtitle").textContent="Create your account to get started",n.textContent="Create Account",n.dataset.mode="register"):n.dataset.mode="login"}async function co(){let e=i("auth-username").value.trim(),t=i("auth-password").value,n=i("auth-error");n.classList.add("hidden");try{let s=await y("POST",`/api/auth/${i("auth-btn").dataset.mode||"login"}`,{username:e,password:t});f.token=s.token,localStorage.setItem("token",s.token),Ys()}catch(s){n.textContent=s.message,n.classList.remove("hidden")}}function po(){return f.token?/^#\/session\//.test(location.hash||""):!1}function kr(e={}){if(ao(localStorage.getItem("theme")||"dark"),!document.getElementById("xterm-css")){let l=document.createElement("link");l.id="xterm-css",l.rel="stylesheet",l.href="/xterm.min.css",document.head.appendChild(l)}if(!document.getElementById("xterm-js")){let l=document.createElement("script");l.id="xterm-js",l.src="/xterm.min.js",document.head.appendChild(l)}if(!document.getElementById("xterm-fit-js")){let l=document.createElement("script");l.id="xterm-fit-js",l.src="/addon-fit.min.js",document.head.appendChild(l)}let t=e.restoreSession??po(),n=document.getElementById("root");if(n.style.cssText="display:flex;flex-direction:column;flex:1;height:100%",n.innerHTML=Fi()+Ui({restoreSession:t}),t){let l=i("session-list");l&&(l.innerHTML='<div class="px-3 py-3 text-[10px] text-base-content/35">Loading sessions\u2026</div>')}Ce(()=>{let l=ee.value,c=i("ws-tabs");if(!c)return;if(l.length<=1){c.innerHTML="";return}let u=fe.peek();c.innerHTML=[{id:null,name:"All"},...l].map(h=>`<button class="px-3 py-1.5 text-[11px] flex-shrink-0 border-b-2 whitespace-nowrap
|
|
1020
|
+
${(h.id===null?!u:u===h.configDir)?"border-primary text-primary":"border-transparent text-base-content/50 hover:text-base-content"}"
|
|
1021
|
+
data-ws-tab="${p(h.configDir||"")}">
|
|
1022
|
+
${p(h.name)}
|
|
1023
|
+
</button>`).join("")}),Ce(()=>{ct.value,St.value,Je.value,Qe.value,Re.value,T.value;let l=i("session-list");l&&(l.querySelector(".session-rename-input")||(l.innerHTML=Va(),Ya()))}),Ce(()=>{B.value,de.value,j.value,A.value;let l=i("welcome");l&&(document.documentElement.classList.contains("boot-restore")||document.documentElement.classList.contains("boot-pending")||l.classList.contains("hidden")||l.style.display==="none"||Rt())}),Le(fe,l=>{let c=i("session-filter-badge");c&&(c.style.display=l?"inline":"none",c.title=l||"")}),Ce(()=>{let l=E.value;if(l&&l.path)lr(l.path);else{let c=i("project-notes-bar");c&&(c.style.display="none")}}),Le(U,l=>{document.querySelectorAll("[data-tab]").forEach(u=>{let h=u.dataset.tab===l;u.classList.toggle("text-primary",h),u.classList.toggle("border-primary",h),u.classList.toggle("text-base-content/50",!h),u.classList.toggle("border-transparent",!h)});let c=i("project-view");c&&!c.classList.contains("hidden")&&(c.style.display="flex",c.style.flexDirection="column",c.style.minHeight="0",c.style.flex="1"),["chat","files","git","shell","memory"].forEach(u=>{let h=i(`tab-${u}`);if(!h)return;let x=u===l;h.classList.toggle("hidden",!x),x?(h.style.display="flex",h.style.flexDirection="column",h.style.flex="1 1 0",h.style.minHeight="0",h.style.overflow="hidden"):h.style.display="none"}),l==="memory"&&qs(),l==="shell"&&requestAnimationFrame(()=>{document.dispatchEvent(new CustomEvent("shell-tab-shown"))}),xe()}),wr(),yr(),ei({openSession:Pe});let s=null;document.addEventListener("sessions-changed",()=>{s&&clearTimeout(s),s=setTimeout(()=>{s=null,Ke({waitFresh:!1})},1200)}),document.addEventListener("router:home",Vs),document.addEventListener("router:session",async({detail:{id:l,tab:c,machineId:u,agent:h}})=>{let x=B.peek().find(C=>C.sessionId===l),v=Et();await Pe(l,x?.cwd||(v?.sessionId===l?v.cwd:null)||null,x?.configDir||(v?.sessionId===l?v.configDir:null)||null,h||x?.agent||(v?.sessionId===l?v.agent:null)||null,u||x?.machineId||(v?.sessionId===l?v.machineId:null)||null,{tab:c||"chat"})}),g.on("click","#btn-home",Vs),g.on("click","#btn-share-session",async(l,c)=>{let u=$i();if(u)try{await navigator.clipboard.writeText(u),c.textContent="\u5DF2\u590D\u5236",setTimeout(()=>{c.textContent="\u5206\u4EAB"},1400)}catch{window.prompt("\u590D\u5236\u4F1A\u8BDD\u94FE\u63A5\uFF1A",u)}}),g.on("click","#auth-btn",co),g.on("submit","#auth-form",l=>{l.preventDefault(),co()}),g.on("keydown","#auth-username, #auth-password",l=>{l.key==="Enter"&&co()}),g.on("click","#hamburger",()=>i("sidebar").classList.contains("open")?Zn():xr()),g.on("click","#sidebar-overlay",Zn),document.addEventListener("keydown",l=>{l.key==="Escape"&&window.innerWidth<=640&&i("sidebar")?.classList.contains("open")&&(l.preventDefault(),Zn())}),g.on("input","#session-search",(l,c)=>{me.value=c.value,Os(c.value)}),g.on("click","#sidebar-filter-toggle",()=>{let l=i("sidebar-filter-menu");if(!l)return;let c=l.classList.toggle("hidden");i("sidebar-filter-toggle")?.setAttribute("aria-expanded",String(!c))}),g.on("change","[data-agent-option]",(l,c)=>{let u=new Set($t.peek());c.checked?u.add(c.dataset.agentOption):u.delete(c.dataset.agentOption);let h=[...u];$t.value=h,localStorage.setItem("agentFilters",JSON.stringify(h)),de.value=h.length===1?h[0]:"all"}),g.on("change","#filter-favorites",(l,c)=>{Ae.value=c.checked,localStorage.setItem("favoritesOnly",c.checked?"1":"0")}),g.on("change","#filter-hidden",(l,c)=>{je.value=c.checked,localStorage.setItem("showHiddenOnly",c.checked?"1":"0")}),g.on("click","#filter-clear",()=>{$t.value=[],de.value="all",Ae.value=!1,je.value=!1,localStorage.setItem("agentFilters","[]"),localStorage.setItem("favoritesOnly","0"),localStorage.setItem("showHiddenOnly","0"),document.querySelectorAll("[data-agent-option]").forEach(l=>{l.checked=!1}),i("filter-favorites")&&(i("filter-favorites").checked=!1),i("filter-hidden")&&(i("filter-hidden").checked=!1)}),g.on("click","#session-filter-badge",()=>{fe.value=null}),g.on("click","[data-ws-tab]",(l,c)=>{fe.value=c.dataset.wsTab||null}),g.on("click","#sidebar-refresh",()=>{Ke(),me.peek().trim()&&Bs(me.peek())}),g.on("click","[data-view]",(l,c)=>{Je.value=c.dataset.view,localStorage.setItem("sidebarView",c.dataset.view)}),g.on("click","[data-agent-filter]",(l,c)=>{de.value=c.dataset.agentFilter,localStorage.setItem("agentFilter",c.dataset.agentFilter),me.peek().trim()&&Os(me.peek())}),g.on("dblclick","[data-project-cwd]",(l,c)=>{let u=c.dataset.projectCwd;if(!u)return;let h=u.split("/").filter(Boolean).pop()||u;so({id:h,name:h,path:u}),L(`Project \xB7 ${u}`)}),g.on("click","#btn-pwa-install",async()=>{await qo()||Xl()}),document.addEventListener("pwa-installable",()=>{document.getElementById("btn-pwa-install")?.classList.remove("hidden")}),g.on("click","#btn-settings",Ha),g.on("click","#btn-meta-agent",()=>_i()),g.on("click","#btn-meta-agent-welcome",()=>Oa("chat")),g.on("click","#btn-theme",oo),g.on("click","[data-sidebar-action]",(l,c)=>{let u=c.dataset.sidebarAction;u==="new"&&io(),u==="theme"&&oo(),u==="settings"&&Ha(),u==="logout"&&(f.token=null,localStorage.removeItem("token"),ge(null),Be.value=!1,location.reload())}),g.on("click","#btn-cal-prev",()=>{za(-1),Rt(Ht())}),g.on("click","#btn-cal-next",()=>{za(1),Rt(Ht())}),g.on("click","[data-cal-date]",(l,c)=>{er(c.dataset.calDate),Rt(Ht())}),g.on("click","[data-session-id]",(l,c)=>{l.target.closest("[data-fav-toggle]")||l.target.closest("[data-hide-toggle]")||l.target.closest("[data-rename-session]")||l.target.closest(".session-rename-input")||l.target.closest(".session-title-wrap.session-rename-active")||(Pe(c.dataset.sessionId,c.dataset.sessionCwd||null,c.dataset.sessionConfigDir||null,c.dataset.sessionAgent||"claude",c.dataset.sessionMachine||null),vr())}),g.on("click","[data-rename-session]",(l,c)=>{l.preventDefault(),l.stopPropagation();let u=c.closest(".session-title-wrap")||c,h=u.dataset.renameSessionId||u.dataset.sessionId;h&&eo({sessionId:h,agent:u.dataset.renameSessionAgent||"claude",machineId:u.dataset.renameSessionMachine||null,fallbackDisplay:u.dataset.renameSessionDisplay||"",mountEl:u})}),g.on("click","[data-rename-bar]",(l,c)=>{if(l.preventDefault(),l.stopPropagation(),!f.sessionId)return;let u=document.getElementById("session-title-display")||c;eo({sessionId:f.sessionId,agent:f.agent||I.peek()||"claude",machineId:f.machineId||null,mountEl:u})}),g.on("click","[data-folder]",(l,c)=>{let u=c.dataset.folder,x=c.querySelector("span")?.textContent.trim()==="\u25BE",v=new Set(zt.peek()),C=new Set(Jt.peek());x?(v.delete(u),C.add(u)):(v.add(u),C.delete(u)),ae(()=>{zt.value=v,Jt.value=C})}),g.on("click","#memory-refresh",qs),g.on("click","[data-memory-file]",l=>Xa(l.dataset.memoryFile,l.dataset.memoryAgent)),g.on("click","[data-tab]",(l,c)=>it(c.dataset.tab));let a=async(l,c)=>{let u=i(l),h=u?.value.trim();if(!h){c.value="";return}try{let x=await y("POST","/api/resolve-path",{path:h});if(x.isDir===!1)throw new Error("Path is not a directory on the target machine");c.value=x.path,u.value=x.path;let v=E.peek();v&&(E.value={...v,path:x.path})}catch(x){u.style.color="oklch(var(--er))",u.title=x.message,setTimeout(()=>{u.style.color="",u.title=""},2e3)}};g.on("click","#files-root-btn",()=>a("files-root-input",ce)),g.on("click","#git-root-btn",()=>a("git-root-input",be)),g.on("keydown","#files-root-input",l=>{l.key==="Enter"&&a("files-root-input",ce)}),g.on("keydown","#git-root-input",l=>{l.key==="Enter"&&a("git-root-input",be)}),g.on("click","#btn-opts",()=>{i("chat-opts").classList.toggle("hidden"),xe()}),g.on("change","#sel-agent",(l,c)=>{let u=I.peek(),h=c.value;u!==h&&(f.sessionId=null,qe(h),le(Oe(h)||P.peek()),i("sel-permission").value=Ee.peek(),Ne(),L(`Agent \u2192 ${te[h]||h} \xB7 model ${P.peek()} \xB7 new session`))}),g.on("change","#sel-convert-agent",async(l,c)=>{let u=c.value;if(!u)return;let h=f.sessionId;if(!h){alert("No active session to convert."),c.value="";return}let x=f.agent||I.peek()||"claude";if(x===u){alert("Cannot convert to the same agent."),c.value="";return}c.disabled=!0,L(`Converting session ${h.slice(0,8)} from ${x} to ${u}...`);try{let v=await y("POST",`/api/sessions/${h}/convert`,{targetAgent:u,sourceAgent:x});v&&v.success?(L(`\u2713 Converted successfully. New session: ${v.targetSessionId.slice(0,8)}`),await Ke(),await Pe(v.targetSessionId,E.peek()?.path||null,null,v.targetAgent),On()):L("Failed to convert session.")}catch(v){L(`Error converting session: ${v.message}`),alert(`Error converting session: ${v.message}`)}finally{c.disabled=!1,c.value=""}}),g.on("change","#sel-model",(l,c)=>{le(c.value),Hs()}),g.on("click","#btn-model-add",()=>Rs({editCurrent:!1})),g.on("click","#btn-model-edit",()=>Rs({editCurrent:!0})),g.on("change","#sel-effort",(l,c)=>{ie.value=c.value}),g.on("change","#sel-permission",(l,c)=>{Ee.value=c.value}),g.on("change","#sel-density",(l,c)=>{xa(c.value),L(`Density \u2192 ${c.value} (applies to new tool calls; reload session to re-group history)`)}),document.addEventListener("agent-changed",Ne),g.on("click","#btn-new-session, #btn-new-session-welcome",io),g.on("click","#new-session-cancel",()=>i("modal-new-session").close()),g.on("click","#new-session-start",lo),g.on("change","#new-session-agent",ro),g.on("keydown","#new-session-path",l=>{l.key==="Enter"&&lo()}),g.on("click","#send-btn",Bn),g.on("click","#stop-btn",fi),g.on("click","#btn-logout",()=>{f.token=null,localStorage.removeItem("token"),ge(null),Be.value=!1,location.reload()}),g.on("click","[data-pick-machine]",async(l,c)=>{let u=c.dataset.pickMachine;if(!u||u===j.peek()){Ut();return}await no(u,{forceReload:!0}),us()});let o=async()=>{let l=i("machine-picker-status");if(l&&(l.textContent="\u5237\u65B0\u4E2D\u2026"),await qt(),Ks(),Vn(),gt(),l){let c=(Q.peek()||[]).filter(u=>u.online!==!1).length;l.textContent=`${c} online`}};g.on("click","#btn-refresh-machines",o),g.on("click","#btn-refresh-machines-menu",async l=>{l.stopPropagation(),await o()}),g.on("click","#btn-machine-menu",async l=>{l.stopPropagation(),Bt(),It();let c=i("machine-menu");c&&(c.classList.contains("hidden")?(await qt(),Vn(),c.classList.remove("hidden")):c.classList.add("hidden"))}),g.on("click","#btn-recent-sessions",l=>{l.preventDefault(),l.stopPropagation(),Ut(),It(),Zi();let c=!i("recent-menu")?.classList.contains("hidden"),u=i("btn-recent-sessions");u&&u.setAttribute("aria-expanded",c?"true":"false")}),g.on("click","#recent-menu-backdrop",l=>{l.preventDefault(),l.stopPropagation(),Bt(),i("btn-recent-sessions")?.setAttribute("aria-expanded","false")}),document.addEventListener("click",l=>{let c=i("machine-menu-wrap");c&&!c.contains(l.target)&&Ut();let u=i("recent-menu"),h=i("btn-recent-sessions"),x=l.target;if(u&&!u.classList.contains("hidden")){if(u.contains(x)||h?.contains(x))return;Bt(),h?.setAttribute("aria-expanded","false")}}),g.on("click","#btn-notifications",l=>{l.preventDefault(),l.stopPropagation(),Ut(),Bt(),Xo()}),window.addEventListener("resize",()=>{i("recent-menu")&&!i("recent-menu").classList.contains("hidden")&&Ga()}),g.on("click","#recent-menu [data-session-id]",()=>{Bt(),i("btn-recent-sessions")?.setAttribute("aria-expanded","false")}),g.on("click","[data-dismiss-recent-session]",(l,c)=>{l.preventDefault(),l.stopPropagation(),Yi({sessionId:c.dataset.dismissRecentSession,agent:c.dataset.dismissRecentAgent||"claude",machineId:c.dataset.dismissRecentMachine||null})}),g.on("click","#btn-edit-project-notes, #project-goal-text, #project-notes-text",()=>{cr()}),g.on("click","#btn-cancel-project-notes",()=>{kn()});let r=async()=>{let l=i("project-goal-input")?.value?.trim()??"",c=i("project-notes-input")?.value?.trim()??"",u=E.peek();if(!(!u||!u.path))try{let h=await y("POST","/api/projects/notes",{root:u.path,goal:l,notes:c});rr(h.goal||"",h.notes||""),kn()}catch(h){alert(`Error saving project notes: ${h.message}`)}};g.on("click","#btn-save-project-notes",r),g.on("keydown","#project-goal-input",l=>{l.key==="Enter"&&r(),l.key==="Escape"&&kn()}),g.on("keydown","#project-notes-input",l=>{l.key==="Escape"&&kn()}),g.on("click","[data-fav-toggle]",(l,c)=>{l.stopPropagation(),l.preventDefault();let u=c.dataset.favSessionMachine||f.machineId;u&&(f.machineId=u,localStorage.setItem("machineId",u)),pr(c.dataset.favSessionId,c.dataset.favSessionAgent||"claude",{machineId:u||null})}),g.on("click","[data-hide-toggle]",(l,c)=>{l.stopPropagation(),l.preventDefault();let u=c.dataset.hideSessionMachine||f.machineId;u&&(f.machineId=u,localStorage.setItem("machineId",u)),fr(c.dataset.hideSessionId,c.dataset.hideSessionAgent||"claude",{machineId:u||null})}),g.on("click","#btn-edit-session-notes, #session-notes-text",()=>{dr()}),g.on("click","#btn-cancel-session-notes",()=>_e()),g.on("click","#btn-save-session-notes",async()=>{let l=i("session-notes-input")?.value?.trim()||"";if(!f.sessionId)return;let c=f.agent||I.peek()||"claude";await Za(f.sessionId,c,l)&&_e()}),g.on("keydown","#session-notes-input",async l=>{if(l.key==="Escape"&&_e(),l.key==="Enter"){let c=l.target.value.trim();if(!f.sessionId)return;let u=f.agent||I.peek()||"claude";await Za(f.sessionId,u,c)&&_e()}}),g.on("click","#btn-fav-filter",()=>{let l=!Ae.peek();Ae.value=l,localStorage.setItem("favoritesOnly",l?"1":"0"),i("btn-fav-filter")?.classList.toggle("active",l),l&&je.peek()&&(je.value=!1,localStorage.setItem("showHiddenOnly","0"),i("btn-hidden-filter")?.classList.remove("active"))}),g.on("click","#btn-hidden-filter",()=>{let l=!je.peek();je.value=l,localStorage.setItem("showHiddenOnly",l?"1":"0"),i("btn-hidden-filter")?.classList.toggle("active",l),l&&Ae.peek()&&(Ae.value=!1,localStorage.setItem("favoritesOnly","0"),i("btn-fav-filter")?.classList.remove("active"))}),Ne(),Ce(()=>{A.value,j.value,f.token&&us()}),i("sel-permission").value=Ee.peek(),$s();let d=i("sel-density");d&&(d.value=Ve.peek()||"normal"),document.querySelectorAll("[data-agent-option]").forEach(l=>{l.checked=$t.peek().includes(l.dataset.agentOption)}),i("filter-favorites")&&(i("filter-favorites").checked=Ae.peek()),i("filter-hidden")&&(i("filter-hidden").checked=je.peek()),document.querySelectorAll("[data-agent-filter]").forEach(l=>{l.classList.toggle("active",l.dataset.agentFilter===de.peek())}),i("btn-fav-filter")?.classList.toggle("active",Ae.peek()),i("btn-hidden-filter")?.classList.toggle("active",je.peek()),document.querySelectorAll("[data-view]").forEach(l=>{let c=l.dataset.view===Je.peek();l.classList.toggle("bg-primary/15",c),l.classList.toggle("text-primary",c),l.classList.toggle("font-medium",c),l.classList.toggle("text-base-content/50",!c)})}hn();R();O();ue();function Zl(e){let t=e.split(".").pop()?.toLowerCase();return{js:"\u{1F4C4}",ts:"\u{1F4C4}",jsx:"\u{1F4C4}",tsx:"\u{1F4C4}",py:"\u{1F40D}",md:"\u{1F4DD}",json:"\u2699\uFE0F",html:"\u{1F310}",css:"\u{1F3A8}",sh:"\u26A1",env:"\u{1F511}",docx:"\u{1F4D8}",pptx:"\u{1F4D9}",xlsx:"\u{1F4D7}",pdf:"\u{1F4D5}"}[t]||"\u{1F4C4}"}function ec(e){let t=(e||"").split("/").pop()||"",n=t.lastIndexOf(".");return n>=0?t.slice(n+1).toLowerCase():""}function $r(e){let t=ec(e);return t==="docx"||t==="pptx"||t==="xlsx"||t==="pdf"?t:null}function tc(e){return e==null?"":e>1024*1024?`${(e/(1024*1024)).toFixed(1)} MB`:e>1024?`${(e/1024).toFixed(1)} KB`:`${e} B`}function nc(e){let t=atob(e),n=new Uint8Array(t.length);for(let s=0;s<t.length;s++)n[s]=t.charCodeAt(s);return n.buffer}var fo=new Map;function Xs(e){if(fo.has(e))return fo.get(e);let t=new Promise((n,s)=>{let a=document.querySelector(`script[data-src="${e}"]`);if(a){if(a.dataset.loaded==="1")return n();a.addEventListener("load",()=>n()),a.addEventListener("error",()=>s(new Error(`Failed to load ${e}`)));return}let o=document.createElement("script");o.src=e,o.async=!0,o.dataset.src=e,o.onload=()=>{o.dataset.loaded="1",n()},o.onerror=()=>s(new Error(`Failed to load ${e}`)),document.head.appendChild(o)});return fo.set(e,t),t}function sc(e){let n=((e||"").split("/").pop()||"").toLowerCase(),s={dockerfile:"dockerfile",makefile:"makefile",gemfile:"ruby",rakefile:"ruby",procfile:"yaml","cmakelists.txt":"cmake"};if(s[n])return s[n];let a=n.includes(".")?n.split(".").pop():"";return{js:"javascript",mjs:"javascript",cjs:"javascript",jsx:"javascript",ts:"typescript",tsx:"typescript",mts:"typescript",cts:"typescript",py:"python",pyw:"python",pyi:"python",rb:"ruby",go:"go",rs:"rust",java:"java",kt:"kotlin",kts:"kotlin",c:"c",h:"c",cpp:"cpp",cc:"cpp",cxx:"cpp",hpp:"cpp",hh:"cpp",cs:"csharp",swift:"swift",php:"php",scala:"scala",sh:"bash",bash:"bash",zsh:"bash",fish:"bash",ps1:"powershell",psm1:"powershell",html:"xml",htm:"xml",xhtml:"xml",xml:"xml",svg:"xml",css:"css",scss:"scss",less:"less",json:"json",jsonc:"json",json5:"json",yml:"yaml",yaml:"yaml",toml:"ini",ini:"ini",conf:"ini",env:"bash",md:"markdown",mdx:"markdown",markdown:"markdown",sql:"sql",graphql:"graphql",gql:"graphql",vue:"xml",svelte:"xml",r:"r",lua:"lua",pl:"perl",pm:"perl",dart:"dart",ex:"elixir",exs:"elixir",erl:"erlang",zig:"zig",nim:"nim",clj:"clojure",cljs:"clojure",diff:"diff",patch:"diff",dockerfile:"dockerfile"}[a]||""}function ac(e){!e||typeof hljs>"u"||e.querySelectorAll("pre code.file-preview-code").forEach(t=>{try{delete t.dataset.highlighted,hljs.highlightElement(t)}catch{}})}function es(e,t,n){let s=tc(t);return`
|
|
1024
|
+
<div class="flex items-center gap-2 px-4 py-1.5 border-b border-base-300 flex-shrink-0 bg-base-200">
|
|
1025
|
+
<span class="text-xs text-base-content/40 flex-1 truncate">${p(e)} \xB7 ${p(s)}${n?` \xB7 <span class="text-primary/70">${p(n)}</span>`:""}</span>
|
|
1026
|
+
<button type="button" class="btn btn-ghost btn-xs" data-download-path="${p(e)}">\u2193 Download</button>
|
|
1027
|
+
</div>`}function oc(e){return!Array.isArray(e)||!e.length?'<div class="p-4 text-xs text-base-content/40">Empty directory</div>':(e.sort((t,n)=>n.isDir-t.isDir||t.name.localeCompare(n.name)),e.map(t=>`
|
|
1028
|
+
<div class="flex items-center gap-2 px-4 py-1.5 hover:bg-base-300 group"
|
|
1029
|
+
${t.isDir?`data-dir-path="${p(t.path)}"`:`data-file-path="${p(t.path)}"`}>
|
|
1030
|
+
<span class="cursor-pointer flex-shrink-0">${t.isDir?"\u{1F4C1}":Zl(t.name)}</span>
|
|
1031
|
+
<span class="text-sm flex-1 truncate cursor-pointer ${t.isDir?"text-primary":""}">${p(t.name)}</span>
|
|
1032
|
+
${t.isDir?"":`
|
|
1033
|
+
<button type="button" class="file-row-action btn btn-ghost btn-xs px-1.5 text-base-content/50 hover:text-base-content"
|
|
1034
|
+
data-download-path="${p(t.path)}" title="Download" aria-label="Download">\u2193</button>
|
|
1035
|
+
<button type="button" class="file-row-action btn btn-ghost btn-xs px-1.5 text-error/60 hover:text-error"
|
|
1036
|
+
data-delete-path="${p(t.path)}" title="Delete" aria-label="Delete">\u2715</button>`}
|
|
1037
|
+
</div>`).join(""))}function ic(e,t,n){let s=/[\x00-\x08\x0e-\x1f]/.test(t.slice(0,512)),a=sc(e),o=a?`language-${p(a)}`:"",r=s?`<div class="p-4 text-xs text-base-content/40">Binary file \u2014 <button class="text-primary hover:underline" data-download-path="${p(e)}">Download</button></div>`:`<pre class="file-preview p-4 font-mono text-xs leading-relaxed overflow-auto flex-1 m-0"><code class="hljs file-preview-code ${o}">${p(t)}</code></pre>`;return es(e,n,s?"binary":a||"text")+r}async function rc(e){if(await Xs("/vendor/mammoth.browser.min.js"),typeof mammoth>"u")throw new Error("mammoth failed to load");let t=await mammoth.convertToHtml({arrayBuffer:e});return`<div class="office-preview office-docx overflow-auto flex-1 p-4 md">${t.messages?.length?`<div class="office-warn text-xs text-warning/80 px-3 py-1">${t.messages.length} conversion note(s)</div>`:""}<div class="office-docx-body">${t.value||'<p class="text-base-content/40">Empty document</p>'}</div></div>`}async function lc(e){if(await Xs("/vendor/xlsx.full.min.js"),typeof XLSX>"u")throw new Error("SheetJS failed to load");let t=XLSX.read(new Uint8Array(e),{type:"array"}),n=t.SheetNames||[];if(!n.length)return'<div class="p-4 text-xs text-base-content/40">Empty workbook</div>';let s=n.map((o,r)=>`<button type="button" class="office-sheet-tab${r===0?" active":""}" data-sheet-idx="${r}">${p(o)}</button>`).join(""),a=n.map((o,r)=>{let d=t.Sheets[o],l;try{l=XLSX.utils.sheet_to_html(d,{id:`xlsx-sheet-${r}`,editable:!1})}catch{l='<p class="text-base-content/40 text-xs p-2">Unable to render this sheet</p>'}return`<div class="office-sheet-pane${r===0?"":" hidden"}" data-sheet-pane="${r}">${l}</div>`}).join("");return`
|
|
1038
|
+
<div class="office-preview office-xlsx flex flex-col flex-1 min-h-0 overflow-hidden">
|
|
1039
|
+
<div class="office-sheet-tabs flex gap-1 px-2 py-1.5 border-b border-base-300 overflow-x-auto flex-shrink-0 bg-base-200">${s}</div>
|
|
1040
|
+
<div class="office-sheet-body flex-1 overflow-auto p-2">${a}</div>
|
|
1041
|
+
</div>`}function cc(e){let t=[],n=/<a:p[\s>][\s\S]*?<\/a:p>/g,s=/<a:t(?:\s[^>]*)?>([\s\S]*?)<\/a:t>/g,a,o=e.match(n)||[e];for(let r of o){let d=[];for(s.lastIndex=0;(a=s.exec(r))!==null;){let l=a[1].replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'");l&&d.push(l)}d.length&&t.push(d.join(""))}return t}async function dc(e){if(await Xs("/vendor/jszip.min.js"),typeof JSZip>"u")throw new Error("JSZip failed to load");let t=await JSZip.loadAsync(e),n=Object.keys(t.files).filter(a=>/^ppt\/slides\/slide\d+\.xml$/i.test(a)).sort((a,o)=>{let r=parseInt(a.match(/slide(\d+)/i)?.[1]||"0",10),d=parseInt(o.match(/slide(\d+)/i)?.[1]||"0",10);return r-d});if(!n.length)return'<div class="p-4 text-xs text-base-content/40">No slides found in this presentation</div>';let s=[];for(let a=0;a<n.length;a++){let o=await t.files[n[a]].async("string"),r=cc(o),d=r.length?r.map(l=>`<p>${p(l)}</p>`).join(""):'<p class="text-base-content/40 italic">\uFF08\u6B64\u9875\u65E0\u53EF\u63D0\u53D6\u6587\u672C / \u53EF\u80FD\u4EE5\u56FE\u7247\u4E3A\u4E3B\uFF09</p>';s.push(`
|
|
1042
|
+
<article class="office-slide-card">
|
|
1043
|
+
<header class="office-slide-num">Slide ${a+1}</header>
|
|
1044
|
+
<div class="office-slide-body">${d}</div>
|
|
1045
|
+
</article>`)}return`
|
|
1046
|
+
<div class="office-preview office-pptx overflow-auto flex-1 p-3 space-y-3">
|
|
1047
|
+
<p class="text-xs text-base-content/50 px-1">\u6587\u672C\u9884\u89C8\uFF08\u7248\u5F0F/\u56FE\u7247\u4E0D\u8FD8\u539F\uFF09\xB7 ${n.length} slide(s)</p>
|
|
1048
|
+
${s.join("")}
|
|
1049
|
+
</div>`}async function uc(){if(await Xs("/vendor/pdf.min.js"),typeof pdfjsLib>"u")throw new Error("pdf.js failed to load");return pdfjsLib.GlobalWorkerOptions.workerSrc="/vendor/pdf.worker.min.js",pdfjsLib}async function pc(e){let n=await(await uc()).getDocument({data:e}).promise,s=n.numPages,a=Math.min(s,40),o=[];for(let d=1;d<=a;d++){let l=await n.getPage(d),c=l.getViewport({scale:1}),u=Math.min(1.5,820/c.width),h=l.getViewport({scale:u}),x=document.createElement("canvas");x.width=Math.floor(h.width),x.height=Math.floor(h.height),x.className="office-pdf-page",x.dataset.page=String(d),await l.render({canvasContext:x.getContext("2d"),viewport:h}).promise,o.push(`
|
|
1050
|
+
<figure class="office-pdf-figure">
|
|
1051
|
+
<figcaption class="office-pdf-cap">Page ${d} / ${s}</figcaption>
|
|
1052
|
+
${x.outerHTML}
|
|
1053
|
+
</figure>`)}let r=s>a?`<p class="text-xs text-base-content/50 px-2">Showing first ${a} of ${s} pages \u2014 download for full file.</p>`:"";return`
|
|
1054
|
+
<div class="office-preview office-pdf overflow-auto flex-1 p-3 space-y-3">
|
|
1055
|
+
<p class="text-xs text-base-content/50 px-1">PDF preview \xB7 ${s} page(s)</p>
|
|
1056
|
+
${r}
|
|
1057
|
+
${o.join("")}
|
|
1058
|
+
</div>`}async function fc(e,t,n){let s=$r(e),a={docx:"Word",pptx:"PowerPoint",xlsx:"Excel",pdf:"PDF"},o=nc(t),r;if(s==="docx")r=await rc(o);else if(s==="xlsx")r=await lc(o);else if(s==="pptx")r=await dc(o);else if(s==="pdf")r=await pc(o);else throw new Error("Unsupported office type");return es(e,n,a[s]||s)+r}function mc(e,t){let n=e?e.split("/"):[],s=t?n.slice(0,-1):n,a='<span class="cursor-pointer text-primary hover:underline" data-dir-path="">root</span>',o="";for(let r of s)o=o?`${o}/${r}`:r,a+=` <span class="text-base-content/40">/</span> <span class="cursor-pointer text-primary hover:underline" data-dir-path="${p(o)}">${p(r)}</span>`;return t&&(a+=` <span class="text-base-content/40">/</span> <span>${p(n.at(-1))}</span>`),a}function hc(){let e=E.peek(),t=ce.peek()||e?.path;if(!t)return;let n=document.createElement("input");n.type="file",n.multiple=!0,n.addEventListener("change",async()=>{let s=z.peek(),a=e?.id||"_",o=[...n.files],r=!1;for(let d of o){let l=s?`${s}/${d.name}`:d.name,c=`/api/projects/${a}/file?root=${encodeURIComponent(t)}&path=${encodeURIComponent(l)}`;try{let u=await fetch(c,{method:"POST",headers:dt(),body:d,duplex:"half"});if(!u.ok){let h=await u.json().catch(()=>({}));throw new Error(h.error||`HTTP ${u.status}`)}}catch(u){alert(`Upload failed (${d.name}): ${u.message}`),r=!0;break}}if(!r){let d=z.peek();z.value=d+"\0",z.value=d}}),n.click()}async function bc(e,t){let n=ce.peek()||e?.path||"";if(!n){alert("No path selected \u2014 set root first");return}let s=e?.id||"_",a=(t||"").split("/").pop()||"download",o=new URLSearchParams({root:n,path:t,download:"true"}),r=`/api/projects/${s}/file?${o}`;try{let d=await fetch(r,{headers:dt(),credentials:"same-origin"});if(!d.ok){let h=await d.json().catch(()=>({}));throw new Error(h.error||`HTTP ${d.status}`)}let l=await d.blob(),c=URL.createObjectURL(l),u=document.createElement("a");u.href=c,u.download=a,u.rel="noopener",u.style.display="none",document.body.appendChild(u),u.click(),u.remove(),setTimeout(()=>URL.revokeObjectURL(c),6e4)}catch(d){try{let l=`/api/projects/${s}/file?${Ho({root:n,path:t,download:"true"})}`,c=document.createElement("a");c.href=l,c.download=a,c.rel="noopener",c.target="_blank",document.body.appendChild(c),c.click(),c.remove()}catch{alert(`Download failed: ${d.message}`)}}}async function gc(e,t){if(!confirm(`Delete "${t.split("/").pop()}"?`))return;let n=ce.peek()||e?.path||"",s=e?.id||"_";try{await y("DELETE",`/api/projects/${s}/file?root=${encodeURIComponent(n)}&path=${encodeURIComponent(t)}`),z.value=z.peek()+" ",z.value=z.peek().trimEnd()}catch(a){alert(`Delete failed: ${a.message}`)}}async function xc(e,t,n,s){let a=n.size??(typeof n.content=="string"?n.content.length:0),o=$r(t);if(o&&n.encoding==="base64"){e.innerHTML=es(t,a,o)+`<div class="p-4 text-xs text-base-content/40">Parsing ${o.toUpperCase()}\u2026</div>`;try{let r=await fc(t,n.content,a);if(s.aborted)return;e.innerHTML=r}catch(r){if(s.aborted)return;e.innerHTML=es(t,a,o)+`<div class="p-4 text-xs text-error">Preview failed: ${p(r.message)} \u2014 <button class="text-primary hover:underline" data-download-path="${p(t)}">Download</button></div>`}return}if(n.encoding==="base64"){e.innerHTML=es(t,a,"binary")+`<div class="p-4 text-xs text-base-content/40">Binary file \u2014 <button class="text-primary hover:underline" data-download-path="${p(t)}">Download</button></div>`;return}e.innerHTML=ic(t,n.content||"",a),ac(e)}function Sr(){Ce(()=>{let e=i("files-breadcrumb");if(!e)return;let t=re.value!==null;e.innerHTML=`
|
|
1059
|
+
${mc(re.value??z.value,t)}
|
|
1060
|
+
<div class="flex-1"></div>
|
|
1061
|
+
${t?"":'<button id="btn-upload" class="btn btn-ghost btn-xs text-base-content/50 hover:text-base-content">\u2191 Upload</button>'}`}),Tn(async e=>{let t=U.value,n=E.value,s=(ce.value||n?.path||"").trim(),a=re.value,o=z.value,r=i("files-area");if(!r||t!=="files")return;if(!s){r.innerHTML='<div class="p-4 text-xs text-base-content/40">No path yet \u2014 open a session (uses that machine's cwd) or type an absolute path and press Go.</div>';return}let d=n?.id||"_";r.innerHTML='<div class="p-4 text-xs text-base-content/40">Loading\u2026</div>';try{if(a!==null){let u=await y("GET",`/api/projects/${d}/file?root=${encodeURIComponent(s)}&path=${encodeURIComponent(a)}`,void 0,e);e.aborted||await xc(r,a,u,e);return}let l=await y("GET",`/api/projects/${d}/files?root=${encodeURIComponent(s)}&path=${encodeURIComponent(o)}`,void 0,e);if(e.aborted)return;let c=Array.isArray(l)?l:Array.isArray(l?.files)?l.files:null;if(!c){r.innerHTML=`<div class="p-4 text-xs text-error">${p(l?.error||"Invalid directory listing")}</div>`;return}r.innerHTML=oc(c)}catch(l){!e.aborted&&l?.name!=="AbortError"&&(r.innerHTML=`<div class="p-4 text-xs text-error">${p(l.message)}</div>`)}}),g.on("click","[data-dir-path]",(e,t)=>{re.value=null,z.value=t.dataset.dirPath}),g.on("click","[data-file-path]",(e,t)=>{re.value=t.dataset.filePath}),g.on("click","#btn-upload",()=>hc()),g.on("click","[data-download-path]",(e,t)=>{e.preventDefault(),e.stopPropagation();let n=t.dataset.downloadPath;n&&bc(E.peek(),n)}),g.on("click","[data-delete-path]",(e,t)=>{e.preventDefault(),e.stopPropagation();let n=t.dataset.deletePath;n&&gc(E.peek(),n)}),g.on("click",".office-sheet-tab",(e,t)=>{let n=t.closest(".office-xlsx");if(!n)return;let s=t.dataset.sheetIdx;n.querySelectorAll(".office-sheet-tab").forEach(a=>a.classList.toggle("active",a===t)),n.querySelectorAll(".office-sheet-pane").forEach(a=>{a.classList.toggle("hidden",a.dataset.sheetPane!==s)})})}R();O();ue();var Lr=$(!1);function vc(e){return e?e.split(`
|
|
1062
|
+
`).map(t=>p(t).replace(/\b([0-9a-f]{7})\b/,'<span class="gh">$1</span>').replace(/\(([^)]*)\)/,'<span style="color:oklch(var(--wa))">($1)</span>')).join(`
|
|
1063
|
+
`):'<span class="text-base-content/40">No commits</span>'}function yc(e){if(!e)return"";if(!e.isGit)return'<div class="p-4 text-sm text-base-content/50">Not a git repository</div>';let t={M:"text-warning",D:"text-error"};return`
|
|
1064
|
+
<div class="px-4 py-2 text-xs text-base-content/50 border-b border-base-300">
|
|
1065
|
+
Branch: <span class="text-success font-semibold">${p(e.branch)}</span>
|
|
1066
|
+
</div>
|
|
1067
|
+
${e.files.length?e.files.map(n=>`
|
|
1068
|
+
<div class="flex items-center gap-3 px-4 py-1 text-sm">
|
|
1069
|
+
<span class="font-mono text-xs w-5 flex-shrink-0 ${t[n.status]||"text-success"}">${p(n.status)}</span>
|
|
1070
|
+
<span class="break-all">${p(n.file)}</span>
|
|
1071
|
+
</div>`).join(""):'<div class="px-4 py-2 text-sm text-base-content/50">Working tree clean</div>'}
|
|
1072
|
+
<div class="border-t border-base-300 p-4">
|
|
1073
|
+
<div class="flex gap-4 text-xs mb-3">
|
|
1074
|
+
<span id="diff-unstaged" class="cursor-pointer text-primary">Unstaged</span>
|
|
1075
|
+
<span id="diff-staged" class="cursor-pointer text-base-content/50">Staged</span>
|
|
1076
|
+
</div>
|
|
1077
|
+
<div id="diff-content" class="font-mono text-xs overflow-auto max-h-[30vh] whitespace-pre"></div>
|
|
1078
|
+
</div>
|
|
1079
|
+
<div class="border-t border-base-300">
|
|
1080
|
+
<div class="flex items-center justify-between px-4 py-2 text-xs text-base-content/50 cursor-pointer select-none" id="git-graph-toggle">
|
|
1081
|
+
<span class="uppercase tracking-wider font-medium">Git Graph</span>
|
|
1082
|
+
<span id="git-graph-chevron" class="text-[10px]">\u25B6</span>
|
|
1083
|
+
</div>
|
|
1084
|
+
<div id="git-graph-panel" class="hidden px-4 pb-4">
|
|
1085
|
+
<div id="git-graph-content" class="git-graph overflow-x-auto max-h-[35vh] overflow-y-auto">
|
|
1086
|
+
<span class="text-base-content/40">Loading\u2026</span>
|
|
1087
|
+
</div>
|
|
1088
|
+
</div>
|
|
1089
|
+
</div>`}function wc(e){return e.split(`
|
|
1090
|
+
`).map(t=>t.startsWith("+")&&!t.startsWith("+++")?`<span class="diff-add">${p(t)}</span>`:t.startsWith("-")&&!t.startsWith("---")?`<span class="diff-del">${p(t)}</span>`:t.startsWith("@@")?`<span class="diff-hunk">${p(t)}</span>`:/^(diff |index |---|[+]{3})/.test(t)?`<span class="diff-head">${p(t)}</span>`:`<span>${p(t)}</span>`).join(`
|
|
1091
|
+
`)}function Er(){Tn(async e=>{let t=U.value,n=E.value,s=be.value||n?.path,a=i("git-area");if(!a||t!=="git")return;if(!s){a.innerHTML='<div class="p-4 text-sm text-base-content/50">Enter a project root above, or open a session with a working directory.</div>';return}let o=n?.id||"_";a.innerHTML='<div class="p-4 text-xs text-base-content/40">Loading\u2026</div>';try{let r=await y("GET",`/api/projects/${o}/git/status?root=${encodeURIComponent(s)}`,void 0,e);e.aborted||(a.innerHTML=yc(r))}catch(r){!e.aborted&&r?.name!=="AbortError"&&(a.innerHTML=`<div class="p-4 text-xs text-error">${p(r?.message??String(r))}</div>`)}}),Tn(async e=>{let t=E.value,n=be.value||t?.path,s=Lr.value,a=i("diff-content");if(!a||!n)return;let o=t?.id||"_";try{let r=await y("GET",`/api/projects/${o}/git/diff?root=${encodeURIComponent(n)}${s?"&staged=true":""}`,void 0,e);e.aborted||(a.innerHTML=r?.diff?wc(r.diff):'<span class="text-base-content/40">No changes</span>')}catch(r){!e.aborted&&r?.name!=="AbortError"&&(a.innerHTML=`<span class="text-error">${p(r?.message??String(r))}</span>`)}}),g.on("click","#diff-unstaged, #diff-staged",(e,t)=>{let n=t.id==="diff-staged";Lr.value=n,i("diff-unstaged").className=`cursor-pointer ${n?"text-base-content/50":"text-primary"}`,i("diff-staged").className=`cursor-pointer ${n?"text-primary":"text-base-content/50"}`}),g.on("click","#git-graph-toggle",()=>{let e=i("git-graph-panel"),t=i("git-graph-chevron"),n=e.classList.toggle("hidden");t.textContent=n?"\u25B6":"\u25BC",n||kc()})}function kc(){let e=E.peek(),t=be.peek()||e?.path,n=i("git-graph-content");if(!t||!n)return;let s=e?.id||"_";n.innerHTML='<span class="text-base-content/40">Loading\u2026</span>',y("GET",`/api/projects/${s}/git/log?root=${encodeURIComponent(t)}`).then(a=>{n.innerHTML=a.graph?vc(a.graph):'<span class="text-base-content/40">No commits</span>'}).catch(a=>{n.innerHTML=`<span class="text-error">${p(a.message)}</span>`})}R();O();var we=null,H=null,ea=null,ss=!1,ta=null,Cr=null,ts=0,ns=null,mo=!1,Tr=!1,Mr={"ctrl-c":"",escape:"\x1B",tab:" ",up:"\x1B[A",down:"\x1B[B",left:"\x1B[D",right:"\x1B[C"};function ho(e){we&&we.readyState===WebSocket.OPEN&&we.send(JSON.stringify({type:"input",data:e}))}function $c(){return window.matchMedia("(max-width: 640px), (hover: none) and (pointer: coarse)").matches}function na(){if($c()){document.getElementById("term-mobile-input")?.focus({preventScroll:!0});return}H?.focus();let e=document.querySelector("#terminal-container .xterm-helper-textarea");e&&(e.focus({preventScroll:!0}),requestAnimationFrame(()=>e.focus({preventScroll:!0})))}function Ar(){if(H)return;let e=i("terminal-container");if(!e)return;if(typeof Terminal>"u"){setTimeout(Ar,100);return}H=new Terminal({cursorBlink:!0,fontFamily:"Fira Code, Courier New, monospace",fontSize:12,theme:{background:"#0d1117",foreground:"#c9d1d9",cursor:"#58a6ff",black:"#0d1117",red:"#ff7b72",green:"#3fb950",yellow:"#d29922",blue:"#58a6ff",magenta:"#bc8cff",cyan:"#39c5cf",white:"#b1bac4",brightBlack:"#484f58",brightRed:"#ffa198",brightGreen:"#56d364",brightYellow:"#e3b341",brightBlue:"#79c0ff",brightMagenta:"#d8b9ff",brightCyan:"#56d4dd",brightWhite:"#ffffff"}}),typeof FitAddon<"u"&&(ea=new FitAddon.FitAddon,H.loadAddon(ea)),H.open(e),Zs(),H.onData(n=>{ho(n)}),e.addEventListener("pointerdown",()=>na(),{passive:!0}),e.addEventListener("touchend",()=>na(),{passive:!0}),window.addEventListener("resize",()=>{Zs(),sa()});let t=window.visualViewport;if(t){let n=0,s=()=>{n&&cancelAnimationFrame(n),n=requestAnimationFrame(()=>{n=0,U.peek()==="shell"&&(Zs(),sa())})};t.addEventListener("resize",s),t.addEventListener("scroll",s)}}function Zs(){try{ea&&H&&ea.fit()}catch{}}function sa(){we&&we.readyState===WebSocket.OPEN&&H&&we.send(JSON.stringify({type:"resize",cols:H.cols,rows:H.rows}))}function jr(){return f.machineId||j.peek()||null}function aa(e){ns&&(clearTimeout(ns),ns=null),mo=!0;let t=++ts;if(we){try{we.close()}catch{}we=null}ss=!1;let n=location.protocol==="https:"?"wss":"ws",s=H?H.cols:80,a=H?H.rows:24,o=new URLSearchParams;f.token&&o.set("token",f.token),e&&o.set("cwd",e),o.set("cols",String(s)),o.set("rows",String(a));let r=jr();A.peek()&&r&&o.set("machine",r),ta=e||null,Cr=r,we=new WebSocket(`${n}://${location.host}/ws/shell?${o}`),we.addEventListener("open",()=>{t===ts&&(ss=!0,H?.write(`\x1B[32mConnected to interactive terminal\x1B[0m\r
|
|
1092
|
+
`),sa())}),we.addEventListener("message",d=>{if(t!==ts)return;let l;try{l=JSON.parse(d.data)}catch{return}l.type==="output"?H?.write(l.data):l.type==="exit"?H?.write(`\r
|
|
1093
|
+
\x1B[33m[process exited: ${l.code}]\x1B[0m\r
|
|
1094
|
+
`):l.type==="error"&&H?.write(`\r
|
|
1095
|
+
\x1B[31m[error: ${l.data||l.message||""}]\x1B[0m\r
|
|
1096
|
+
`)}),we.addEventListener("close",()=>{t===ts&&(ss=!1,H?.write(`\r
|
|
1097
|
+
\x1B[33m[disconnected]\x1B[0m\r
|
|
1098
|
+
`),!(!mo||U.peek()!=="shell")&&(H?.write(`\x1B[33m[reconnecting\u2026]\x1B[0m\r
|
|
1099
|
+
`),ns=setTimeout(()=>{ns=null,aa(ta)},1500)))}),we.addEventListener("error",()=>{t===ts&&H?.write(`\r
|
|
1100
|
+
\x1B[31m[WebSocket error]\x1B[0m\r
|
|
1101
|
+
`)})}function Ir(){let e=E.peek()?.path,t=i("term-cwd");t&&(t.textContent=e||"~"),H||Ar(),requestAnimationFrame(()=>{requestAnimationFrame(()=>{Zs();let n=jr();!ss||ta!==(e||null)||Cr!==n?(H?.clear(),aa(e)):sa()})})}function Dr(){Tr||(Tr=!0,document.getElementById("term-keyboard")?.addEventListener("click",na),document.getElementById("term-mobile-composer")?.addEventListener("submit",e=>{e.preventDefault();let t=document.getElementById("term-mobile-input");t&&(ho(`${t.value}\r`),t.value="",t.focus({preventScroll:!0}))}),document.getElementById("term-mobile-keys")?.addEventListener("pointerdown",e=>{e.target.closest("[data-term-key]")&&e.preventDefault()}),document.getElementById("term-mobile-keys")?.addEventListener("click",e=>{let t=e.target.closest("[data-term-key]")?.dataset.termKey;!t||!Mr[t]||(ho(Mr[t]),na())})),document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"&&(U.peek()!=="shell"||!mo||ss||aa(ta))}),Le(U,e=>{e==="shell"&&Ir()}),document.addEventListener("shell-tab-shown",()=>{U.peek()==="shell"&&Ir()}),document.getElementById("term-reconnect")?.addEventListener("click",()=>{H?.clear(),aa(E.peek()?.path)})}hn();Kn();Ss();en();function bo(){let e=document.documentElement;e.classList.add("boot-ready"),e.classList.remove("boot-pending")}function oa(){document.documentElement.classList.remove("boot-restore")}var go=Na(location.hash.slice(1)||"/"),Nr=po()||!!(f.token&&go?.id);kr({restoreSession:Nr});Fo();xi();Sr();Er();Ei();Dr();bi();qi();yi(Pe,it);(async()=>{let e=Yt();if(f.token)try{let t=document.getElementById("auth-screen"),n=document.getElementById("app");if(t&&(t.style.display="none",t.classList.add("hidden")),n&&(n.style.display="flex",n.classList.remove("hidden")),Nr){document.documentElement.classList.add("boot-restore");let a=document.getElementById("welcome"),o=document.getElementById("project-view");a&&(a.classList.add("hidden"),a.style.display="none"),o&&(o.classList.remove("hidden"),o.style.cssText="display:flex;flex-direction:column;flex:1;min-height:0;overflow:hidden")}let s=await e;await Ys({hub:s,deepLink:go}),go?.id||(wi(),(location.hash||"").startsWith("#/session/")||oa()),requestAnimationFrame(()=>{requestAnimationFrame(bo)})}catch(t){console.error("[boot]",t),f.token=null,localStorage.removeItem("token"),oa(),await uo(),bo()}else{oa();try{await uo()}catch(t){console.error("[boot auth]",t)}finally{bo()}}})();document.addEventListener("router:home",()=>{oa()});Oo();
|