claude-simple 0.2.24 → 0.2.25
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/README.md +20 -0
- package/client.js +20 -3
- package/dist/app.0.2.25.min.js +1164 -0
- package/dist/index.html +2 -2
- package/dist/style.0.2.25.min.css +1753 -0
- package/package.json +1 -1
- package/public/api.js +1 -0
- package/public/chat.js +213 -8
- package/public/router.js +5 -0
- package/public/settings.js +312 -63
- package/public/shell/notes.js +5 -2
- package/public/shell/session-list.js +50 -2
- package/public/shell/session-nav.js +45 -12
- package/public/state.js +3 -2
- package/public/style.css +126 -0
- package/public/ui.min.css +1 -1
- package/src/agent-env.js +211 -0
- package/src/agents/claude.js +10 -3
- package/src/agents/grok.js +24 -0
- package/src/agents/models.js +30 -1
- package/src/agents/sessions.js +12 -2
- package/src/app.js +450 -14
- package/src/collab.js +248 -0
- package/src/runtime/external-session-sync.js +106 -0
- package/src/runtime/protocol.js +3 -2
- package/dist/app.0.2.24.min.js +0 -1104
- package/dist/style.0.2.24.min.css +0 -1627
package/dist/app.0.2.24.min.js
DELETED
|
@@ -1,1104 +0,0 @@
|
|
|
1
|
-
var Gr=Object.defineProperty;var R=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(s){throw n=[s],s}};var is=(e,t)=>{for(var n in t)Gr(e,n,{get:t[n],enumerable:!0})};function Kr(){pa||(pa=!0,queueMicrotask(()=>{pa=!1,ha()}))}function ko(e){for(let t of e)(t._isComputed?Gt:zt).add(t);ma>0||rs||(zr==="microtask"?Kr():ha())}function So(e,t,n,s){let a=new Set(n);for(let i of n)i._subs.delete(t);n.clear(),s?.forEach(i=>i?.()),s?.splice(0);let o=[wt,Mn,da];[wt,Mn,da]=[t,n,s];try{return e()}catch(i){for(let d of a)d._subs.add(t),n.add(d);throw i}finally{[wt,Mn,da]=o}}var wt,Mn,ma,da,Gt,zt,rs,En,ua,zr,pa,ha,$o,$,ba,Ce,ae,Le,In,Jr,p,g,Lo,r,fa,Vr,Oe,Tn,Qr,ls,Yr,qc,Eo,Fc,Uc,To,Mo=R(()=>{wt=null,Mn=null,ma=0,da=null,Gt=new Set,zt=new Set,rs=!1,En=1e4,ua={flushes:0,runs:0,lastFlushRuns:0},zr="sync",pa=!1;ha=()=>{if(rs)return;rs=!0;let e=0;ua.flushes++;try{for(;Gt.size||zt.size;){for(;Gt.size;){let t=Gt.values().next().value;if(Gt.delete(t),++e>En)throw new Error(`mini-react: reactive update loop exceeded ${En} runs`);t()}if(zt.size){let t=zt.values().next().value;if(zt.delete(t),++e>En)throw new Error(`mini-react: reactive update loop exceeded ${En} runs`);t()}}}finally{ua.runs+=e,ua.lastFlushRuns=e,e>En&&(Gt.clear(),zt.clear()),rs=!1}};$o=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),Mn?.add(this)),this._v}set value(e){this._eq(e,this._v)||(this._v=e,ko(this._subs))}peek(){return this._v}},$=(e,{equals:t}={})=>new $o(e,t);ba=e=>{let t=new $o(void 0),n=new Set,s=!0,a=!1,o=l=>{if(!s||a)return t._v;s=!1;try{let c=So(e,i,n,null),u=c!==t._v;u&&(t._v=c),u&&l&&ko(t._subs)}catch(c){s=!0,console.error("[computed]",c)}return t._v},i=()=>{s||a||(s=!0,t._subs.size&&o(!0))};i._isComputed=!0;let d=()=>o(!1);return Object.defineProperty(t,"value",{get(){return wt&&(t._subs.add(wt),Mn?.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(i);n.clear()}},t},Ce=e=>{let t=new Set,n=[],s=()=>{try{let a=So(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=>{ma++;try{e()}finally{--ma===0&&ha()}},Le=(e,t)=>{let n=e.peek(),s=!1;return Ce(()=>{let a=e.value;s&&t(a,n),s=!0,n=a})},In=e=>Ce(()=>{let t=new AbortController;return Promise.resolve(e(t.signal)).catch(n=>{n?.name!=="AbortError"&&console.error("[asyncEffect]",n)}),()=>t.abort()}),Jr={"&":"&","<":"<",">":">",'"':"""},p=e=>String(e??"").replace(/[&<>"]/g,t=>Jr[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 i=s.target.closest(a);i&&o(s,i)}})},{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(i=>i!==o))},off:(n,s)=>{e.has(n)&&e.set(n,e.get(n).filter(([a])=>a!==s))}}})(),Lo=(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,i=(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"?i(`${u}|${C.join("/")}`,()=>h(...C)):h;return}}if(e["*"]){let u=e["*"];d.value=typeof u=="function"?i("*",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())}}},r=e=>document.getElementById(e),fa=()=>typeof navigator>"u"||navigator.onLine!==!1,Vr=e=>new Promise(t=>setTimeout(t,e)),Oe=e=>e===void 0?"undefined":e===null||typeof e!="object"?JSON.stringify(e):e instanceof Date?`Date(${e.toJSON()})`:Array.isArray(e)?`[${e.map(Oe).join(",")}]`:`{${Object.keys(e).sort().map(t=>`${JSON.stringify(t)}:${Oe(e[t])}`).join(",")}}`,Tn=(e,t)=>{if(!t)return!0;if(typeof t=="function")return t(e);if(t.queryKey){let n=Oe(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))},Qr=e=>{try{return JSON.stringify(e),!0}catch{return!1}},ls=(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,i)=>ls(e[i],o));return a.every((o,i)=>o===e[i])?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]=ls(e[a],t[a])}return n.every(a=>s[a]===e[a])?e:s},Yr=({staleTime:e=3e4,gcTime:t=3e5,retry:n=2,retryDelay:s=1e3,refetchOnWindowFocus:a=!1,refetchOnReconnect:o=!0}={})=>{let i=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},U=m=>{m.gcTimer&&clearTimeout(m.gcTimer),m.gcTimer=null},ke=m=>{U(m),!m.observers&&Number.isFinite(m.options.gcTime)&&(m.gcTimer=setTimeout(()=>{!m.observers&&!m.promise&&(i.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()=>{fa()&&await _(m,{force:!0}).catch(()=>{}),ne(m)},b))},N=(m,b=Oe(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 i.set(b,k),k},S=m=>{if(!m?.queryKey)throw new TypeError("query: queryKey is required");let b=Oe(m.queryKey),w=i.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(!fa())return m.state.fetchStatus.value="paused",Promise.reject(new Error("Query paused while offline"));U(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 G=async(D,z)=>{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 Vr(typeof z=="function"?z(D,X):z),G(D-1,typeof z=="number"?z*2:z)}},Y=G(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:ls(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([...i.values()].filter(b=>Tn(b,m)&&b.observers).map(b=>_(b,{force:!0}).catch(()=>{}))),M={query(m){let b=S(m);b.observers++,U(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 i.get(Oe(m))?.state.data.peek()},getQueryState(m){let b=i.get(Oe(m));return b&&x(b)},setQueryData(m,b,{tags:w}={}){let k=i.get(Oe(m))??S({queryKey:m,tags:w}),G=typeof b=="function"?b(k.state.data.peek()):b,Y=k.options.structuralSharing===!1?G:ls(k.state.data.peek(),G);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 i.values())Tn(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 i.values())Tn(b,m)&&b.ctrl?.abort()},removeQueries(m){for(let b of[...i.values()])Tn(b,m)&&(b.ctrl?.abort(),U(b),J(b),i.delete(b.hash))},mutate({mutationFn:m,variables:b,optimistic:w,invalidate:k,onMutate:G,onSuccess:Y,onError:D,networkMode:z="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 la=M.getQueryData(Ie.queryKey);X.push([Ie.queryKey,la]),M.setQueryData(Ie.queryKey,ca=>Ie.updater(ca))}),Ln=async()=>{let Wt=await G?.(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[la,ca]of X)M.setQueryData(la,ca);throw await D?.(Ie,b,Wt),h({type:"mutation-error",error:Ie}),Ie}};return!fa()&&z==="offlineFirst"?(Q.push(Ln),h({type:"mutation-queued"}),Promise.resolve({queued:!0})):Ln()},infiniteQuery({queryKey:m,queryFn:b,initialPageParam:w=0,getNextPageParam:k,...G}){let[Y,D]=M.query({queryKey:m,...G,queryFn:async z=>({pages:[await b({...z,pageParam:w})],pageParams:[w]})});return[Y,{...D,fetchNextPage:async()=>{let z=Y.data.peek()??{pages:[],pageParams:[]},X=k?.(z.pages.at(-1),z.pages);if(X==null)return;let yt=await b({queryKey:m,pageParam:X,signal:new AbortController().signal});return M.setQueryData(m,{pages:[...z.pages,yt],pageParams:[...z.pageParams,X]}),yt}}]},dehydrate({shouldDehydrate:m=w=>w.state.status.peek()==="success",version:b=1}={}){return{version:b,timestamp:Date.now(),queries:[...i.values()].filter(m).filter(w=>Qr(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=i.get(Oe(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,G=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,G().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:G,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 i.values())Tn(k,w)&&C(k);se(w)},()=>{c?.close(),c=null})},subscribe(m){return d.add(m),()=>d.delete(m)},getDebugSnapshot(){return[...i.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 G=Oe(w);return M.fetchQuery({queryKey:w,...k,queryFn:async({signal:Y})=>{let D=new Headers(b.headers),z=l.get(G);z?.etag&&D.set("If-None-Match",z.etag);let X=await fetch(m,{...b,headers:D,signal:Y});if(X.status===304&&z)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 Ln=i.get(G);Ln&&(Ln.options.staleTime=Number(yt)*1e3)}return l.set(G,{etag:X.headers.get("etag")}),X.json()}})},destroy(){u=!0;for(let m of i.values())m.ctrl?.abort(),U(m),J(m);c?.close(),d.clear()}},Q=[],rt=()=>{a&&se()},xt=()=>{for(o&&se();Q.length;)Q.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},qc=Yr(),Eo=({cache:e=!0,ttl:t=3e4,retry:n=2,retryDelay:s=1e3,store:a=null,dedupe:o=!0}={})=>{let i=new Map,d=new Map,l=new Map,c=(h,x)=>{if(a)return a.get(h);let v=i.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});i.set(h,{data:x,ts:Date.now()})};return{get:(h,x,v={})=>{let C=v.ttl??t,U=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=>(U&&(l.get(h)??0)===N&&await u(h,M,C),M)).catch(M=>{if(_>0&&M?.name!=="AbortError")return new Promise(Q=>setTimeout(Q,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(!U)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 i.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?i.clear():i.delete(h)}}},Fc=new TextEncoder,Uc=new TextDecoder,To=(e,t="kv")=>{let n=null,s=()=>n?Promise.resolve(n):new Promise((o,i)=>{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=>i(l.target.error)}),a=async(o,i)=>{let d=await s();return new Promise((l,c)=>{let u=d.transaction(t,o),h=i(u.objectStore(t));h.onsuccess=()=>l(h.result),h.onerror=()=>c(h.error)})};return{async get(o){let i=await a("readonly",d=>d.get(o));if(i){if(i.expires&&Date.now()>i.expires){this.delete(o);return}return i.val}},async set(o,i,{ttl:d}={}){await a("readwrite",l=>l.put({val:i,expires:d?Date.now()+d:null},o))},delete:o=>a("readwrite",i=>i.delete(o)),clear:()=>a("readwrite",o=>o.clear()),keys:()=>a("readonly",o=>o.getAllKeys())}}});var O=R(()=>{Mo()});var Ho={};is(Ho,{AGENT_DEFAULT_MODEL:()=>No,AGENT_LABELS:()=>te,AGENT_MODELS:()=>ga,LOW_TURN_THRESHOLD:()=>va,activityHits:()=>Be,activityLoading:()=>Ve,addCustomModel:()=>Cn,agentFilter:()=>de,agentFilters:()=>$t,agentsMeta:()=>kt,chatDensity:()=>Qe,collapsedFolders:()=>Jt,ctx:()=>f,currentAgent:()=>I,currentEffort:()=>ie,currentModel:()=>P,currentPermission:()=>Ee,currentProject:()=>E,currentTab:()=>W,expandedFolders:()=>Kt,favoritesOnly:()=>Ae,filesPath:()=>K,filesRoot:()=>ce,filteredSessions:()=>ct,getCustomModels:()=>ds,getDefaultEffort:()=>lt,getDefaultModel:()=>Fe,getEffortsForModel:()=>An,getModelsForAgent:()=>Xe,getSavedModel:()=>Do,getSessionMeta:()=>Vt,gitRoot:()=>be,hubMachineReady:()=>qe,hubMode:()=>A,isProcessing:()=>he,machinesList:()=>V,metaKey:()=>oe,projectGroups:()=>St,removeCustomModel:()=>ka,selectedMachineId:()=>j,sessionDisplayTitle:()=>Ye,sessionFilter:()=>fe,sessionMetaMap:()=>T,sessionSearch:()=>me,sessionSort:()=>Io,sessionsData:()=>B,setAgent:()=>Ue,setChatDensity:()=>ya,setCurrentModel:()=>le,setSelectedMachine:()=>ge,showHiddenOnly:()=>je,sidebarView:()=>Je,timeRange:()=>cs,viewingFile:()=>re,workspacesData:()=>ee,wsStatus:()=>Ke});function Ao(){try{let e=JSON.parse(localStorage.getItem(Co)||"{}");return e&&typeof e=="object"?e:{}}catch{return{}}}function jo(e,t=f.sessionId,n=f.machineId){if(!t)return"";let s=(e||"claude").toLowerCase();return`${n||""}:${s}:${t}`}function Do(e,t=f.sessionId,n=f.machineId){let s=jo(e,t,n);if(!s)return null;let a=Ao()[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=jo(t,n,s);if(o){let i=Ao();i[o]=a,localStorage.setItem(Co,JSON.stringify(i))}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 Vt(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=(Vt(e.agent,e.sessionId,e.machineId).title||"").trim();return s||e.display||e.sessionId?.slice(0,8)||"Session"}function ya(e){let t=["clean","normal","full"].includes(e)?e:"normal";Qe.value=t,localStorage.setItem("chatDensity",t),document.getElementById("messages")?.setAttribute("data-density",t)}function Zr(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 wa(){try{let e=localStorage.getItem(_o);if(!e)return{};let t=JSON.parse(e);return t&&typeof t=="object"?t:{}}catch{return{}}}function Po(e){localStorage.setItem(_o,JSON.stringify(e))}function ds(e){let t=(e||"claude").toLowerCase(),n=wa()[t];return Array.isArray(n)?n.filter(Boolean).map(String):[]}function Cn(e,t){let n=(e||"claude").toLowerCase(),s=String(t||"").trim();if(!s)return!1;let a=wa(),o=Array.isArray(a[n])?[...a[n]]:[];return o.includes(s)||o.push(s),a[n]=o,Po(a),!0}function ka(e,t){let n=(e||"claude").toLowerCase(),s=String(t||"").trim(),a=wa(),o=Array.isArray(a[n])?a[n].filter(i=>i!==s):[];return a[n]=o,Po(a),!0}function Xe(e){let t=(e||"claude").toLowerCase(),n=kt.peek()?.defaults?.[t],s=n?.models?.length?n.models.map(Zr).filter(Boolean):(ga[t]||ga.claude).map(i=>({...i})),a=ds(t),o=new Set(s.map(i=>i.value));for(let i of a){if(o.has(i)){s=s.map(d=>{if(d.value!==i)return d;let l=String(d.label||d.value);return{...d,custom:!0,label:l.includes("\u2605")?l:`${l} \u2605`}});continue}o.add(i),s.push({value:i,label:`${i} \u2605`,custom:!0})}return s}function Fe(e){let t=(e||"claude").toLowerCase(),n=kt.peek()?.defaults?.[t];return n?.model?String(n.model):No[t]||Xe(t)[0]?.value||"claude-sonnet-4-5"}function An(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(i=>i.value===t);return o?.defaultEffort?String(o.defaultEffort):n==="grok"?"low":n==="gemini"&&String(t||"").match(/-(low|medium|high)$/i)?.[1]?.toLowerCase()||""}function Ue(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=Do(t);s?P.value=s:le(Fe(t),t);let a=lt(t,P.peek());a?ie.value=a:t!=="grok"&&t!=="gemini"&&(ie.value="")}function el(e,t){return!t||t==="all"?!0:(e.agent||"claude")===t}function tl(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 xa(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,Io,Kt,Jt,K,re,E,W,he,Ke,Co,Xr,I,P,ie,Ee,ce,be,kt,Je,de,$t,cs,Be,Ve,T,Ae,je,va,Qe,A,V,j,qe,f,te,ga,No,_o,ct,St,q=R(()=>{O();B=$([]),ee=$([]),fe=$(null),me=$(""),Io=$("time"),Kt=$(new Set),Jt=$(new Set),K=$(""),re=$(null),E=$(null),W=$("chat"),he=$(!1),Ke=$("idle"),Co="modelBySession",Xr=localStorage.getItem("agent")||"claude";I=$(Xr),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[]}})()),cs=$(localStorage.getItem("timeRange")||"14"),Be=$(null),Ve=$(!1),T=$({}),Ae=$(localStorage.getItem("favoritesOnly")==="1"),je=$(localStorage.getItem("showHiddenOnly")==="1"),va=2,Qe=$(localStorage.getItem("chatDensity")||"normal"),A=$(!1),V=$([]),j=$(null),qe=$(!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"},ga={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"}]},No={claude:"claude-sonnet-4-5",codex:"gpt-5.4",grok:"grok-4.5",gemini:"gemini-3.7-flash-high",cursor:"auto"};_o="customModelsByAgent";ct=ba(()=>{let e=me.value.toLowerCase().trim(),t=Io.value,n=de.value,s=$t.value,a=Ae.value,o=je.value,i=T.value,d=Be.value,l=d?.results?.length&&e?xa(d.results):xa(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"):el(u,n))),o?l=l.filter(u=>u&&i?.[oe(u.agent,u.sessionId,u.machineId)]?.hidden):l=l.filter(u=>u&&!i?.[oe(u.agent,u.sessionId,u.machineId)]?.hidden),a&&(l=l.filter(u=>u&&i?.[oe(u.agent,u.sessionId,u.machineId)]?.favorite)),e&&!(d?.results&&d.q===e)&&(l=l.filter(u=>u&&tl(u,e))),l=[...l].sort((u,h)=>{let x=i?.[oe(u.agent,u.sessionId,u.machineId)]?.favorite?1:0,v=i?.[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=ba(()=>{let e=xa(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 jn(e={}){return e.machineId!==void 0?e.machineId:f.machineId||j.peek()||null}function sl(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=jn(a),i={"Content-Type":"application/json",...f.token?{Authorization:`Bearer ${f.token}`}:{}};A.peek()&&o&&!sl(t)&&(i["X-Machine-Id"]=o);let d=a.etag===!0?`${f.token||""}:${o||""}:${t}`:a.etag||null;if(e.toUpperCase()==="GET"&&d){let u=Ro.get(d);u&&(i["If-None-Match"]=u)}let l=async()=>{let u=await fetch(t,{method:e,signal:s,headers:i,...n!==void 0?{body:JSON.stringify(n)}:{}});if(u.status===304)return $a;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&&Ro.set(d,x)}return h};if(e.toUpperCase()!=="GET"||s||a.dedupe===!1)return l();let c=`${f.token||""}:${o||""}:${t}`;return nl.get(c,l)}function Qt(e){return f.ws?.readyState===WebSocket.OPEN?(f.ws.send(JSON.stringify(e)),!0):(e?.type==="ping"||e?.type==="pong"||e?.type==="subscribe"||us.push(e),!1)}function Oo(){for(;us.length&&f.ws?.readyState===WebSocket.OPEN;)f.ws.send(JSON.stringify(us.shift()))}function Bo(){us.length=0}function qo(e={}){let t=new URLSearchParams(e);f.token&&t.set("token",f.token);let n=jn();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=jn();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 nl,Ro,$a,us,ue=R(()=>{q();O();nl=Eo({cache:!1,dedupe:!0,retry:0}),Ro=new Map,$a=Symbol("not-modified");us=[]});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 Dn(){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 zo(){xe(),Dn();let e=window.visualViewport;e&&(e.addEventListener("resize",Dn),e.addEventListener("scroll",Dn)),window.addEventListener("resize",()=>{Dn(),xe()}),window.addEventListener("orientationchange",()=>{setTimeout(()=>{Dn(),xe()},250)})}var en=R(()=>{});function Et(){try{let e=localStorage.getItem(Ko);return e?JSON.parse(e):null}catch{return null}}function Sa(e){try{let n={...Et()||{},...e,updatedAt:Date.now()};localStorage.setItem(Ko,JSON.stringify(n))}catch{}}var Ko,ps=R(()=>{Ko="lastSessionContext"});async function La(){if(Nn&&!(typeof navigator>"u"||!navigator.wakeLock?.request)&&document.visibilityState==="visible"&&!Tt)try{Tt=await navigator.wakeLock.request("screen"),Tt.addEventListener("release",()=>{Tt=null,Nn&&document.visibilityState==="visible"&&setTimeout(()=>{La().catch(()=>{})},500)})}catch{Tt=null}}async function Jo(){let e=Tt;if(Tt=null,!!e)try{await e.release()}catch{}}function Vo(e){Nn=!!e,Nn?La().catch(()=>{}):Jo().catch(()=>{})}function Qo(){typeof document>"u"||document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"&&Nn?La().catch(()=>{}):document.visibilityState==="hidden"&&Jo().catch(()=>{})})}var Tt,Nn,Yo=R(()=>{Tt=null,Nn=!1});function F(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 F(Number(t));let n=Date.parse(t);return Number.isNaN(n)?null:n}return null}function tn(e){let t=F(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=R(()=>{O();q()});function il(e){let t=F(e);if(t==null)return"";let n=new Date(t);return Number.isNaN(n.getTime())?"":n.toLocaleString()}function Xo(){let e=r("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 ti(){let e=r("notifications-menu"),t=r("btn-notifications"),n=r("topbar");if(!e||!t||!n)return;let s=t.getBoundingClientRect(),a=n.getBoundingClientRect(),o=Math.min(416,window.innerWidth-16),i=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(i)}px`,e.style.width=`${Math.round(o)}px`}function _n(){let e=r("notifications-menu-list"),t=r("notifications-menu-empty");if(!(!e||!t)){if(!$e.length){e.innerHTML="",t.classList.remove("hidden"),Xo();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(il(n.createdAt))}</span>
|
|
21
|
-
</div>
|
|
22
|
-
</div>
|
|
23
|
-
</div>
|
|
24
|
-
</button>`).join(""),Xo()}}function It(){r("notifications-menu")?.classList.add("hidden"),r("notifications-backdrop")?.classList.add("hidden"),r("btn-notifications")?.setAttribute("aria-expanded","false")}function rl(){ti(),r("notifications-menu")?.classList.remove("hidden"),r("notifications-backdrop")?.classList.remove("hidden"),r("btn-notifications")?.setAttribute("aria-expanded","true")}function ni(){let e=r("notifications-menu");e&&(e.classList.contains("hidden")?rl():It())}function Zo(e){let t=new Map;for(let n of e||[])n?.id&&t.set(String(n.id),n);$e=[...t.values()].sort((n,s)=>(F(s.createdAt)||0)-(F(n.createdAt)||0)),Mt=$e.reduce((n,s)=>n+(s.unread?1:0),0),_n()}async function fs(){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),_n()}catch{$e=[],Mt=0,_n()}}async function ei(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),_n()}function ll(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 si(e){if(!e?.id)return;if($e.find(n=>n.id===e.id)){Zo([e,...$e.filter(n=>n.id!==e.id)]);return}Zo([e,...$e]),ll(e)}function ai(e={}){Ea=typeof e.openSession=="function"?e.openSession:null,_n(),fs(),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 ei()}),g.on("click","[data-notification-id]",async(t,n)=>{let s=n.dataset.notificationId;s&&(await ei([s]),It(),!(!Ea||!n.dataset.notificationSession)&&Ea(n.dataset.notificationSession,n.dataset.notificationCwd||null,null,n.dataset.notificationAgent||"claude",n.dataset.notificationMachine||null))}),document.addEventListener("click",t=>{let n=r("notifications-menu"),s=r("btn-notifications"),a=t.target;!n||n.classList.contains("hidden")||n.contains(a)||s?.contains(a)||It()}),window.addEventListener("resize",()=>{r("notifications-menu")&&!r("notifications-menu").classList.contains("hidden")&&ti()})}var $e,Mt,Ea,Ta=R(()=>{O();ue();an();$e=[],Mt=0,Ea=null});function dl(){let e=document.getElementById("mermaid-zoom-overlay");if(e)return e;e=document.createElement("div"),e.id="mermaid-zoom-overlay",e.className="mermaid-zoom-overlay hidden",e.setAttribute("role","dialog"),e.setAttribute("aria-modal","true"),e.setAttribute("aria-label","Mermaid diagram enlarged"),e.innerHTML='<button type="button" class="mermaid-zoom-close" aria-label="\u5173\u95ED\u653E\u5927\u56FE">\xD7</button><div class="mermaid-zoom-canvas"></div>',document.body.appendChild(e);let t=()=>e.classList.add("hidden");return e.addEventListener("click",n=>{(n.target===e||n.target.closest(".mermaid-zoom-close"))&&t()}),ii||(ii=!0,document.addEventListener("keydown",n=>{n.key==="Escape"&&t()})),e}function ri(e){let t=e.querySelector("svg");if(!t)return;let n=dl(),s=n.querySelector(".mermaid-zoom-canvas");s.innerHTML=t.outerHTML;let a=s.querySelector("svg");a?.removeAttribute("width"),a?.removeAttribute("height"),n.classList.remove("hidden")}function ul(){let e=globalThis.mermaid;return!e||oi||(e.initialize({startOnLoad:!1,securityLevel:"strict",theme:document.documentElement.dataset.theme==="dark"?"dark":"default",flowchart:{htmlLabels:!1}}),oi=!0),e}function pl(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 ms(e){let t=ul();!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=pl(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 i=`mermaid-diagram-${++cl}`;Promise.resolve(t.parse(a)).then(()=>t.render(i,a)).then(({svg:d,bindFunctions:l})=>{o.innerHTML=d,l?.(o),o.tabIndex=0,o.title="\u70B9\u51FB\u653E\u5927\u56FE\u8868",o.addEventListener("click",c=>{c.target.closest("a")||ri(o)}),o.addEventListener("keydown",c=>{(c.key==="Enter"||c.key===" ")&&(c.preventDefault(),ri(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 oi,cl,ii,Ma=R(()=>{oi=!1,cl=0,ii=!1});function fl(e){return e.parentElement?.closest("pre, code, .mermaid-diagram, .katex, script, style")}function Ia(e,t){let n=[{re:/\\\[([\s\S]+?)\\\]/g,display:!0},{re:/\$\$([\s\S]+?)\$\$/g,display:!0},{re:/\\\(([\s\S]+?)\\\)/g,display:!1},{re:/(?<!\\)\$([^$\n]|\\\$)+?(?<!\s)(?<!\\)\$/g,display:!1}],s=null;for(let a of n){a.re.lastIndex=t;let o=a.re.exec(e);if(!o||s&&o.index>=s.match.index)continue;let i=o[0],d=i.startsWith("\\[")||i.startsWith("\\(")||i.startsWith("$$")?i.slice(2,-2):i.slice(1,-1);d.trim()&&(s={match:o,body:d,display:a.display})}return s}function ml(e){let t=e.nodeValue||"",n=0,s=Ia(t,n);if(!s||typeof globalThis.katex?.renderToString!="function")return;let a=document.createDocumentFragment();for(;s;){s.match.index>n&&a.append(document.createTextNode(t.slice(n,s.match.index)));let o;try{o=globalThis.katex.renderToString(s.body.trim(),{displayMode:s.display,throwOnError:!1,strict:"warn"})}catch{a.append(document.createTextNode(s.match[0])),n=s.match.index+s.match[0].length,s=Ia(t,n);continue}let i=document.createElement(s.display?"div":"span");i.className=s.display?"math-display":"math-inline",i.innerHTML=o,a.append(i),n=s.match.index+s.match[0].length,s=Ia(t,n)}n<t.length&&a.append(document.createTextNode(t.slice(n))),e.replaceWith(a)}function li(e){if(!e||typeof globalThis.katex?.renderToString!="function")return;let t=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),n=[];for(;t.nextNode();)fl(t.currentNode)||n.push(t.currentNode);n.forEach(ml)}var ci=R(()=>{});function on(e){return String(e??"").replace(hl,(t,n)=>`
|
|
26
|
-
|
|
27
|
-
> \u26A0\uFE0F \u539F\u59CB\u8BB0\u5F55\u5DF2\u622A\u65AD\uFF08${n} bytes\uFF09
|
|
28
|
-
|
|
29
|
-
`)}var hl,hs=R(()=>{hl=/(?:<|\[)\s*(?:…\s*)?truncated\s+([\d,]+)\s+bytes\s*(?:>|\])/gi});function bl(){return te[I.peek()]||"Assistant"}function hi(e){return e.scrollHeight-e.scrollTop-e.clientHeight<80}function Me(e,t){e&&(t||hi(e))&&(e.scrollTop=e.scrollHeight)}function bi(e=f.sessionId,t=f.agent,n=f.machineId){return e?`${n||""}:${t||"claude"}:${e}`:""}function gl(e={}){let t=bi(e.sessionId,e.agent,e.machineId);if(!t)return 0;try{return Number(JSON.parse(localStorage.getItem(Ca)||"{}")[t])||0}catch{return 0}}function xl(e){let t=Number(e?.hubSeq)||0;if(!t)return!0;let n=bi(e.sessionId||f.sessionId,e.agent||f.agent,f.machineId);if(!n)return!0;let s={};try{s=JSON.parse(localStorage.getItem(Ca)||"{}")||{}}catch{}let a=Number(s[n])||0;if(t<=a)return!1;s[n]=t;let o=Object.keys(s);o.length>500&&o.sort((i,d)=>Number(s[d])-Number(s[i])).slice(500).forEach(i=>delete s[i]);try{localStorage.setItem(Ca,JSON.stringify(s))}catch{}return!0}function mt({sessionId:e=f.sessionId,agent:t=f.agent,machineId:n=f.machineId}={}){return e?`${n||""}:${t||"claude"}:${e}`:null}function un(e){let t=mt(e),n=r("chat-input");!t||!n||(n.value?Ct.set(t,n.value):Ct.delete(t))}function pn(e){let t=r("chat-input");t&&(t.value=Ct.get(mt(e))||"",cn(t),ln(t.value))}function fn(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(`
|
|
30
|
-
|
|
31
|
-
`))}function mn(){he.peek()&&(he.value=!1,pt())}function vl(){di||(di=!0,document.addEventListener("visibilitychange",()=>{if(document.visibilityState==="visible"&&(De=400,rn({probe:!0}),f.ws?.readyState===WebSocket.OPEN&&f.sessionId))try{f.ws.send(JSON.stringify({type:"subscribe",sessionId:f.sessionId}))}catch{}}),window.addEventListener("online",()=>{De=400,rn({force:!0})}),window.addEventListener("pageshow",e=>{e.persisted?rn({force:!0}):rn({probe:!0})}),window.addEventListener("focus",()=>rn({probe:!0})),navigator.connection?.addEventListener?.("change",()=>{De=400,rn({probe:!0})}))}function Bn(){let e=r("conn-dot");if(!e)return;let t=Ke.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 rn(e={}){let t=f.ws?.readyState;if(e.force){De=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&&(De=Math.min(De,800),st({quiet:!0}))}function yl(){tt||(Ke.value=typeof navigator<"u"&&navigator.onLine===!1?"offline":"reconnecting",Bn(),tt=setTimeout(()=>{tt=null,st({quiet:!0})},De),De=Math.min(Math.round(De*1.8),15e3))}function gi(){gs&&(clearInterval(gs),gs=null)}function wl(e,t){gi(),gs=setInterval(()=>{if(!(t!==Hn||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()&&Ke.peek()==="open";Vo(e)}function kl(){De=400,tt&&(clearTimeout(tt),tt=null),vs=!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={}){vl(),tt&&(clearTimeout(tt),tt=null),e.quiet&&(vs=!0);let t=f.machineId||(typeof localStorage<"u"?localStorage.getItem("machineId"):null);ui!==t&&(Bo(),ui=t);let n=++Hn;try{f.ws?.close()}catch{}Ke.value="connecting",Bn();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),f.agent&&a.set("agent",f.agent);let o=gl();o&&a.set("lastSeq",String(o));let i=new WebSocket(`${s}://${location.host}/ws/chat?${a}`);f.ws=i,i.addEventListener("open",()=>{if(n===Hn){if(De=1e3,et=Date.now(),Ke.value="open",Bn(),f.sessionId)try{i.send(JSON.stringify({type:"subscribe",sessionId:f.sessionId}))}catch{}Oo(),wl(i,n),pt(),xs&&!vs&&L(t?`\u5DF2\u91CD\u8FDE \xB7 ${t}`:"\u5DF2\u91CD\u8FDE"),xs=!1,vs=!1}}),i.addEventListener("message",d=>{if(n!==Hn)return;let l;try{l=JSON.parse(d.data)}catch{return}if(xl(l)){if(l.type==="pong"){et=Date.now();return}if(l.type==="ping"){if(et=Date.now(),i.readyState===WebSocket.OPEN)try{i.send(JSON.stringify({type:"pong"}))}catch{}return}if(l.type==="run-status"){l.running?he.value=!0:he.peek()&&(he.value=!1,xi()),pt();return}vi(l)}}),i.addEventListener("close",()=>{n===Hn&&(gi(),xs=!0,Ke.value=typeof navigator<"u"&&navigator.onLine===!1?"offline":"reconnecting",Bn(),yl())}),i.addEventListener("error",()=>{})}function xi(){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=r("chat-input");s&&(s.value=n.text,cn(s)),setTimeout(()=>{if(n.key!==mt()||he.peek()){Ct.set(n.key,n.text);return}qn()},0)}function Rn(){he.value=!1,pt(),xi()}function vi(e){if(!(e?.sessionId&&f.sessionId&&e.sessionId!==f.sessionId)){if(e.type==="batch"&&Array.isArray(e.items)){for(let t of e.items)vi(t);return}if(e.type==="session-created"){let t=P.peek();f.sessionId=e.sessionId,e.agent&&e.agent!==I.peek()&&Ue(e.agent),le(t,e.agent||I.peek(),e.sessionId),document.dispatchEvent(new CustomEvent("sessions-changed"));return}if(e.type==="notification"&&e.notification){si(e.notification);return}if(e.type==="result"){On(),Pn(),Ne();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),dn(n)}e.is_error||L("\u2713 Done"),Rn();return}if(e.type==="complete"){On(),Pn(),Ne(),!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")),Rn();return}if(e.type==="error"){On(),Pn(),At("error","Error",e.message),Rn();return}if(e.type==="shell-start"){f.shellBubble=null;return}if(e.type==="shell-output"){f.shellBubble||(f.shellBubble=Ol(e.stream==="stderr"?"shell-err":"shell")),Bl(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:""}`),Rn();return}if(e.type==="assistant"){Pn();for(let t of e.message?.content||[])t.type==="text"&&t.text?(Ne(),At("assistant",bl(),t.text,{ts:e.ts||Date.now()})):t.type==="tool_use"&&_a(t,{ts:e.ts||Date.now()});return}if(e.type==="assistant_stream_start"){yi(e.ts);return}if(e.type==="assistant_delta"){$l(e.data||"");return}if(e.type==="assistant_stream_end"){Pn();return}if(e.type==="thought_stream_start"){wi();return}if(e.type==="thought_delta"){Sl(e.data||"");return}if(e.type==="thought_stream_end"){On();return}if(e.type==="status"){let t=r("stream-status");if(t)t.textContent=e.message||"";else{let n=r("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&&r(`perm-${t}`)?.remove();return}(e.type==="permission_request"||e.request_id&&e.tool_name)&&Ul(e)}}function yi(e){let t=r("messages");if(!t||(Ne(),On(),Ge&&t.contains(Ge)))return;let n=ks(e||Date.now()),s=$s(e||Date.now());t.insertAdjacentHTML("beforeend",`
|
|
32
|
-
<div class="msg-row assistant px-2 live-stream" data-ts="${p(s)}">
|
|
33
|
-
<div class="max-w-[88%] rounded-2xl rounded-tl-sm px-3 py-2 text-sm bg-base-200 break-words md">
|
|
34
|
-
<div class="msg-stream-body whitespace-pre-wrap"></div>
|
|
35
|
-
</div>
|
|
36
|
-
${n?`<div class="msg-ts" title="${p(s)}">${p(n)}</div>`:""}
|
|
37
|
-
</div>`),Ge=t.lastElementChild,Te=Ge.querySelector(".msg-stream-body"),r("stream-status")?.remove(),Me(t,!0)}function $l(e){e&&(Te||yi(Date.now()),Te&&(Te.textContent+=e,Me(r("messages"),!0)))}function Pn(){if(!Ge||!Te){Ge=null,Te=null;return}let e=Te.textContent||"";e.trim()?(Te.classList.remove("whitespace-pre-wrap"),Te.classList.add("md"),Te.innerHTML=ws(e),Ei(Ge)):Ge.remove(),Ge=null,Te=null,r("stream-status")?.remove()}function wi(){let e=r("messages");e&&(ut&&e.contains(ut)||(e.insertAdjacentHTML("beforeend",`
|
|
38
|
-
<div class="msg-row assistant px-2 thought-stream">
|
|
39
|
-
<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">
|
|
40
|
-
<div class="font-medium text-base-content/35 mb-0.5">thinking\u2026</div>
|
|
41
|
-
<div class="thought-body font-mono whitespace-pre-wrap max-h-24 overflow-y-auto opacity-80"></div>
|
|
42
|
-
</div>
|
|
43
|
-
</div>`),ut=e.lastElementChild,ze=ut.querySelector(".thought-body"),Me(e,!0)))}function Sl(e){e&&(ze||wi(),ze&&(ze.textContent+=e,ze.scrollTop=ze.scrollHeight,Me(r("messages"),!0)))}function On(){if(ut&&ze){let e=(ze.textContent||"").length;ut.innerHTML=`
|
|
44
|
-
<div class="text-[10px] text-base-content/30 px-1 select-none">\u{1F4AD} thought ${e?`(${e} chars)`:""}</div>`}ut=null,ze=null}function El(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,Ue(a),le(Fe(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?`
|
|
45
|
-
Available: ${l}`:""}`),!0}let a=Ll[s.toLowerCase()]||s,o=I.peek()||"claude",i=Xe(o).some(d=>d.value===a);return i||Cn(o,a),le(a),L(`Model set to ${a}${i?"":" (saved as custom \u2605)"}`),document.dispatchEvent(new CustomEvent("agent-changed")),!0}case"effort":{let a=An(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 bn(),f.sessionId=null,f.lastUsage=null,L("Cleared \xB7 new session"),!0;case"usage":return Tl(),!0;case"help":return L(`Available slash commands:
|
|
46
|
-
/agent [claude|codex|grok|gemini|cursor]
|
|
47
|
-
/model [haiku|sonnet|opus|<model-id>]
|
|
48
|
-
/effort [low|medium|high|xhigh|max]
|
|
49
|
-
/usage
|
|
50
|
-
/clear
|
|
51
|
-
/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 Tl(){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(`
|
|
52
|
-
`)),Da("\u25C8 /usage \xB7 no session yet");return}L("Loading usage\u2026");try{let a=new URLSearchParams({sessionId:n,agent:e}),i=(await y("GET",`/api/usage?${a}`)).context||{};if(i.model&&(s[1]=`Model: ${i.model}`),i.title&&s.push(`Title: ${i.title}`),i.tokensUsed!=null||i.windowTokens!=null||i.usagePercent!=null){let l=i.tokensUsed!=null?ve(i.tokensUsed):"\u2014",c=i.windowTokens!=null?ve(i.windowTokens):"\u2014",u=i.usagePercent!=null?`${i.usagePercent}%`:"\u2014";s.push(`Context window: ${l} / ${c} (${u})`)}if(i.turnCount!=null&&s.push(`Turns: ${i.turnCount}`),i.toolCallCount!=null&&s.push(`Tools: ${i.toolCallCount}`),i.sessionDurationSeconds!=null){let l=Math.floor(i.sessionDurationSeconds/60),c=Math.round(i.sessionDurationSeconds%60);s.push(`Duration: ${l}m ${c}s`)}if(i.sessionTotals){let l=i.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(i.lastTurn&&!f.lastUsage){let l=i.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)}`:""))}i.note&&s.push(i.note);let d=r("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(`
|
|
53
|
-
`)),(i.tokensUsed!=null||i.windowTokens!=null)&&Na({tokensUsed:i.tokensUsed,windowTokens:i.windowTokens,usagePercent:i.usagePercent,model:i.model||t,turnCount:i.turnCount,toolCallCount:i.toolCallCount}),i.sessionTotals?dn(i.sessionTotals):i.lastTurn?dn(i.lastTurn):f.lastUsage&&dn(f.lastUsage)}catch(a){let o=r("messages");if(o){let i=[...o.children];for(let d=i.length-1;d>=0;d--)if(i[d].textContent==="Loading usage\u2026"){i[d].remove();break}}L(`${s.join(`
|
|
54
|
-
`)}
|
|
55
|
-
(usage fetch failed: ${a.message})`)}}function qn(){let e=r("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=Qt({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="",cn(e),ln(""),ys(),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="",cn(e),ln(""),ys(),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()),cn(e),ln(""),ys(),t.startsWith("/")&&El(t))return;he.value=!0,pt();let n=Date.now();if($i(t))At("shell","$ Shell",t.slice(1).trim(),{ts:n}),Qt({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{Ne(),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),Qt({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 ki(){f.sessionId&&Qt({type:"command",cmd:"turn.interrupt",sessionId:f.sessionId}),nt=nt.filter(e=>e.key!==mt()),Rn()}function ln(e){let t=$i(e),n=r("chat-input"),s=r("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 $i(e){let t=String(e||"").trimStart();return t.startsWith("!")&&!/^!\[[^\]]*\]\([^)]+\)/.test(t)}function Ml(){return typeof window<"u"&&window.matchMedia("(max-width: 640px)").matches,72}function cn(e){e.style.height="auto",e.style.height=Math.min(e.scrollHeight,Ml())+"px"}function ks(e){let t=F(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 $s(e){let t=F(e);return t==null?"":new Date(t).toISOString()}function Al(e,t,n){if(e==="system")return t;let s=ks(n),a=$s(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 jl(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 i=/!\[.*?\]\(.*?\)/.test(t)?ws(t):null,d=t.length>Il,l=d?`<div class="msg-body">${i??p(t.trimEnd())}</div>${s}`:i??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":""}${i?" md":""}"${i?"":' style="white-space:pre-wrap"'}>${l}</div>`;break}case"assistant":{let o=t.length>Cl,i=o?`<div class="msg-body">${ws(t)}</div>${s}`:ws(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":""}">${i}</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 Al(e,a,n)}function At(e,t,n,s={}){let a=r("messages");if(!a)return;let o=F(s.ts)??(e==="system"?null:Date.now());a.insertAdjacentHTML("beforeend",jl(e,n,o)),Ei(a.lastElementChild),Me(a,e==="user")}function L(e){At("system","",e)}async function Dl(e,t){let n=t||`upload-${Date.now()}`,s=await Si(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 i=await o.json();if(!i?.path)throw new Error("upload returned no path");return i.path}function Nl(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 Si(e,t){if(!e||!Aa({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 i=atob(o.replace(/\s/g,"")),d=Uint8Array.from(i,u=>u.charCodeAt(0)),l=Nl(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 _l(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]!==`
|
|
56
|
-
`?`
|
|
57
|
-
`:"")+t+`
|
|
58
|
-
`;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 Aa(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 Pl(e,t){let n=e?.name||t.split("/").pop()||"file";if(Aa(e)){bs+=1;let a=`img${bs}`;return{ref:``,label:a,kind:"image"}}bs+=1;let s=`file${bs}`;return{ref:`[${s}](${t})`,label:s,kind:"file"}}function ys(){for(let e of ft)if(e.previewUrl)try{URL.revokeObjectURL(e.previewUrl)}catch{}ft.length=0,ja()}function hn(){ys()}function ja(){let e=r("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)=>`
|
|
59
|
-
<div class="chat-thumb relative" title="${p(t.ref||t.path)}">
|
|
60
|
-
${t.previewUrl?`<img src="${t.previewUrl}" alt="${p(t.label||"img")}">`:`<span class="chat-thumb-path">${p(t.label||t.name||"file")}</span>`}
|
|
61
|
-
<span class="chat-thumb-label">${p(t.label||t.kind||"")}</span>
|
|
62
|
-
<button type="button" class="chat-thumb-x" data-rm-attach="${n}" aria-label="remove">\u2715</button>
|
|
63
|
-
</div>`).join("")}}async function Hl(e){if(!e)return;let t=e.name||`upload-${Date.now()}`,n=await Si(e,t),s=await Dl(n,t),{ref:a,label:o,kind:i}=Pl(e,s),d="";if(i==="image")try{d=URL.createObjectURL(n)}catch{}return ft.push({path:s,ref:a,label:o,kind:i,name:t,previewUrl:d}),ja(),_l(r("chat-input"),a),s}async function Ss(e){let t=[...e||[]].filter(Boolean);if(!t.length)return;let n=r("chat-input");n&&(n.disabled=!0);try{for(let s of t)try{await Hl(s)}catch(a){L(`\u4E0A\u4F20\u5931\u8D25 ${s.name||"file"}: ${a.message}`)}}finally{n&&(n.disabled=!1,n.focus())}}function Rl(){let e=r("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",()=>Ss(t.files)),t.click()}function Li(){document.addEventListener("paste",async e=>{let t=r("chat-input");if(!t)return;let n=r("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 i=o.filter(l=>Aa(l)),d=i.length?i:o;d.length&&(e.preventDefault(),await Ss(d))}),!pi&&(pi=!0,document.addEventListener("dragover",e=>{let t=r("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=r("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=r("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 Ss(n))}))}function Ze(e){return e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function Da(e){let t=r("messages");t&&(t.insertAdjacentHTML("beforeend",`<div class="token-bar select-none">
|
|
64
|
-
<span class="token-bar-mark">\u25C8</span><span class="token-bar-text">${p(e)}</span>
|
|
65
|
-
</div>`),Me(t))}function dn(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`:"",i=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)}`:"";Da(`\u2191${Ze(t)} \u2193${Ze(n)}${a}${o}${i}${c}${l}`)}function Na(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`),Da(`\u25A3 ${a.join(" \xB7 ")}`)}function bn(){let e=r("messages"),t=r("permission-requests");e&&(e.innerHTML=""),t&&(t.innerHTML=""),f.shellBubble=null,We=null,Ge=Te=null,ut=ze=null}function Ol(e){let t=r("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 Bl(e,t){e&&(e.textContent+=t,Me(e.closest("#messages")))}function ql(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,Qe.peek()==="full"?120:80);return{inputStr:t,preview:s}}function fi(e,{inBatch:t=!1}={}){let{inputStr:n,preview:s}=ql(e);return`<div class="tool-card${t?" tool-batch-item":""} cursor-pointer select-none px-2 py-1">
|
|
66
|
-
<div class="flex items-center gap-1.5 text-xs font-mono">
|
|
67
|
-
<span class="text-warning">\u26A1</span>
|
|
68
|
-
<span class="text-warning font-semibold">${p(e.name||"tool")}</span>
|
|
69
|
-
<span class="text-base-content/50 truncate flex-1">${p(s)}</span>
|
|
70
|
-
<span class="tool-chevron text-[10px] text-base-content/40">\u25B6</span>
|
|
71
|
-
</div>
|
|
72
|
-
<div class="tool-detail">${p(n)}</div>
|
|
73
|
-
</div>`}function Fl(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>
|
|
74
|
-
<span class="font-semibold text-base-content/70">${e.count} tool${e.count===1?"":"s"}</span>
|
|
75
|
-
<span class="text-base-content/40 truncate flex-1">${p(n)}</span>
|
|
76
|
-
<span class="tool-chevron text-[10px] text-base-content/40">\u25B6</span>`)}function Ne(){We=null}function _a(e,t={}){let n=r("messages");if(!n)return;let s=Qe.peek()||"normal",a=F(t.ts);if(s==="clean"){if(!We||!n.contains(We.el)){let l=ks(a),c=$s(a);n.insertAdjacentHTML("beforeend",`
|
|
77
|
-
<div class="msg-row assistant px-2" data-ts="${p(c)}">
|
|
78
|
-
<div class="tool-batch w-full max-w-[96%] px-2 py-1.5">
|
|
79
|
-
<div class="tool-batch-summary flex items-center gap-1.5 text-xs font-mono"></div>
|
|
80
|
-
<div class="tool-batch-list"></div>
|
|
81
|
-
</div>
|
|
82
|
-
${l?`<div class="msg-ts" title="${p(c)}">${p(l)}</div>`:""}
|
|
83
|
-
</div>`),We={el:n.lastElementChild.querySelector(".tool-batch"),names:[],count:0}}We.names.push(e.name||"tool"),We.count++,We.el.querySelector(".tool-batch-list")?.insertAdjacentHTML("beforeend",fi(e,{inBatch:!0})),Fl(We),Me(n);return}We=null;let o=ks(a),i=$s(a);n.insertAdjacentHTML("beforeend",`
|
|
84
|
-
<div class="msg-row assistant px-2" data-ts="${p(i)}">
|
|
85
|
-
<div class="w-full max-w-[96%]">${fi(e)}</div>
|
|
86
|
-
${o?`<div class="msg-ts" title="${p(i)}">${p(o)}</div>`:""}
|
|
87
|
-
</div>`),Me(n)}function Ls(){let e=r("messages");e&&e.setAttribute("data-density",Qe.peek()||"normal")}function Ul(e){let t=e.request_id||e.requestId;if(!t||r(`perm-${t}`))return;let n=e.tool_input?JSON.stringify(e.tool_input).slice(0,200):"";r("permission-requests")?.insertAdjacentHTML("beforeend",`
|
|
88
|
-
<div id="perm-${t}" class="perm-banner mx-3 mb-2 rounded-lg border border-warning/25 bg-warning/8 p-3">
|
|
89
|
-
<div class="text-xs text-warning font-semibold mb-1">\u26A0\uFE0F Permission Required</div>
|
|
90
|
-
<div class="font-mono text-xs text-base-content/60 break-all mb-2">
|
|
91
|
-
<strong class="text-base-content">${p(e.tool_name||"")}</strong> ${p(n)}
|
|
92
|
-
</div>
|
|
93
|
-
<div class="flex gap-2">
|
|
94
|
-
<button class="btn btn-success btn-xs" data-perm-id="${t}" data-perm-allow="1">Allow</button>
|
|
95
|
-
<button class="btn btn-error btn-xs" data-perm-id="${t}" data-perm-allow="0">Deny</button>
|
|
96
|
-
</div>
|
|
97
|
-
</div>`),r("messages").scrollTop=999999}function Wl(){if(mi||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]||"",i=o||"text",d=o?`language-${p(o)}`:"";return`<div class="code-block">
|
|
98
|
-
<div class="code-block-header">
|
|
99
|
-
<span class="code-block-lang">${p(i)}</span>
|
|
100
|
-
<button type="button" class="code-copy" data-copy="1" title="Copy code">Copy</button>
|
|
101
|
-
</div>
|
|
102
|
-
<pre><code class="hljs ${d}">${e(s)}</code></pre>
|
|
103
|
-
</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>`},html(s){return e(s)}};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)}mi=!0}function ws(e){if(typeof marked>"u")return p(e);try{return Wl(),marked.parse(on(e),{breaks:!0,gfm:!0})}catch{return p(e)}}function Gl(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 Ei(e){Gl(e),li(e),ms(e)}function Ti(){Ls(),Qo(),Le(Ke,s=>{Bn(),pt();let a=r("ws-banner"),o=r("ws-banner-text");if(!a)return;if(s==="open"||s==="idle"){a.classList.add("hidden"),o&&(o.textContent="");return}if(s==="connecting"&&!xs){a.classList.add("hidden");return}a.classList.remove("hidden");let i=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=i:a.textContent=i}),Le(E,()=>pt()),g.on("click","#ws-banner-retry",s=>{s.preventDefault(),kl()}),Le(he,s=>{r("send-btn")?.classList.toggle("hidden",s),r("stop-btn")?.classList.toggle("hidden",!s);let a=r("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":ln(a.value||""));let o=r("messages");if(!o)return;let i=r("typing-indicator");s&&!i?(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||(i?.remove(),Ne()),pt()}),Le(Qe,()=>Ls()),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(),qn())}),g.on("submit","#chat-form",s=>{s.preventDefault(),qn()}),g.on("input","#chat-input",(s,a)=>{cn(a),ln(a.value)}),g.on("click","#btn-attach",s=>{s.preventDefault(),Rl()}),g.on("change","#chat-file-input",(s,a)=>{let o=a?.files;o?.length&&Ss(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 i=ft[o];if(i?.previewUrl)try{URL.revokeObjectURL(i.previewUrl)}catch{}let d=r("chat-input");d&&i?.ref&&(d.value=d.value.split(i.ref).join("").replace(/\n{3,}/g,`
|
|
104
|
-
|
|
105
|
-
`),d.dispatchEvent(new Event("input"))),ft.splice(o,1),ja()}),g.on("click","[data-perm-id]",(s,a)=>{Qt({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 i=r("messages"),d=a.getBoundingClientRect().top;if(a.classList.toggle("open"),i){let l=a.getBoundingClientRect().top;i.scrollTop+=l-d}}),g.on("click",".tool-batch",(s,a)=>{if(s.target.closest(".tool-card")&&a.classList.contains("open"))return;let o=r("messages"),i=a.getBoundingClientRect().top;if(a.classList.toggle("open"),o){let d=a.getBoundingClientRect().top;o.scrollTop+=d-i}});let e=r("messages"),t=r("scroll-top-btn"),n=r("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||hi(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 i=a.closest(".msg-card").classList.toggle("open");a.textContent=i?"\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 Hn,tt,De,et,gs,di,xs,ui,vs,Ca,nt,Ct,Ge,Te,ut,ze,Ll,Il,Cl,ft,bs,pi,We,mi,gn=R(()=>{O();q();ue();Yo();Ta();Ma();ci();hs();an();an();Hn=0,tt=null,De=1e3,et=0,gs=null,di=!1,xs=!1,ui=null,vs=!1,Ca="hubStreamCursors",nt=[],Ct=new Map;Ge=null,Te=null,ut=null,ze=null;Ll={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"};Il=200,Cl=500;ft=[],bs=0,pi=!1;We=null;mi=!1});function Ii(e,t){Mi=e,Pa=t,window.addEventListener("hashchange",()=>{if(Ha){Ha=!1;return}Ai(location.hash.slice(1)||"/")}),Le(W,n=>{f.sessionId&&Fn()})}function Ra(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 Ci(){Ai(location.hash.slice(1)||"/")}function Ai(e){let t=Ra(e);if(!t){document.dispatchEvent(new CustomEvent("router:home"));return}let{id:n,tab:s,machineId:a,agent:o}=t;!Mi||!Pa||(n!==f.sessionId?document.dispatchEvent(new CustomEvent("router:session",{detail:{id:n,tab:s,machineId:a,agent:o}})):s&&s!==W.peek()&&Pa(s))}function Oa(e){Ha=!0,location.hash=e}function Fn(){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}`:"";Oa(`/session/${encodeURIComponent(f.sessionId)}/${encodeURIComponent(W.peek())}${t}`)}function ji(){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(W.peek())}${n}`,e.toString()}var Ed,Mi,Pa,Ha,Es=R(()=>{O();q();Ed=Lo({"/":()=>{},"/session/*":()=>{},"/session/*/*":()=>{},"*":()=>{}}),Mi=null,Pa=null,Ha=!1});async function Ms(){try{return await Ts.get("sessions")??null}catch{return null}}async function Di(e){try{await Ts.set("sessions",e,{ttl:zl})}catch{}}async function Ni(){try{return await Ts.get("workspaces")??null}catch{return null}}async function Un(e){try{await Ts.set("workspaces",e,{ttl:3600*1e3})}catch{}}var Ts,zl,Is=R(()=>{O();Ts=To("claude-ui"),zl=300*1e3});function yn(e){if(typeof marked<"u")try{return marked.parse(on(e),{breaks:!0,gfm:!0})}catch{}return p(e).replace(/\n/g,"<br>")}function wn(e){e&&(typeof hljs<"u"&&e.querySelectorAll("pre code").forEach(t=>{try{hljs.highlightElement(t)}catch{}}),ms(e))}async function Ua(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(),i=new TextDecoder,d="",l="message";for(;;){let{done:c,value:u}=await o.read();if(c)break;d+=i.decode(u,{stream:!0});let h=d.split(`
|
|
106
|
-
`);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 Ql(){return`
|
|
107
|
-
<div id="meta-agent-panel" class="meta-agent-panel hidden" aria-hidden="true">
|
|
108
|
-
<div class="meta-agent-backdrop" data-ma-close="1"></div>
|
|
109
|
-
<div class="meta-agent-sheet">
|
|
110
|
-
<header class="meta-agent-header">
|
|
111
|
-
<div class="flex items-center gap-2 min-w-0">
|
|
112
|
-
<span class="text-base font-bold">\u2726 Meta Agent</span>
|
|
113
|
-
<span class="text-[10px] text-base-content/40 hidden sm:inline">\u62A5\u544A \xB7 \u95EE\u7B54 \xB7 VLM \xB7 \u4EE3\u7801</span>
|
|
114
|
-
</div>
|
|
115
|
-
<div class="flex items-center gap-1">
|
|
116
|
-
<button type="button" id="ma-btn-chat" class="btn btn-xs btn-ghost border border-primary/40 text-primary">\u5BF9\u8BDD</button>
|
|
117
|
-
<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>
|
|
118
|
-
<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>
|
|
119
|
-
<button type="button" id="ma-btn-report" class="btn btn-xs btn-ghost border border-base-300">\u62A5\u544A</button>
|
|
120
|
-
<button type="button" id="ma-btn-config" class="btn btn-xs btn-ghost border border-base-300" title="AI \u914D\u7F6E">\u2699</button>
|
|
121
|
-
<button type="button" id="ma-btn-close" class="btn btn-xs btn-ghost" data-ma-close="1">\u2715</button>
|
|
122
|
-
</div>
|
|
123
|
-
</header>
|
|
124
|
-
|
|
125
|
-
<div id="ma-mode-chat" class="meta-agent-body flex flex-col min-h-0 flex-1">
|
|
126
|
-
<div class="flex items-center gap-1 px-2 py-1 border-b border-base-300 flex-shrink-0 overflow-x-auto">
|
|
127
|
-
<button type="button" id="ma-new-chat" class="btn btn-ghost btn-xs">\uFF0B \u65B0\u5BF9\u8BDD</button>
|
|
128
|
-
<button type="button" id="ma-open-history" class="btn btn-ghost btn-xs" title="\u5386\u53F2\u5217\u8868">\u2630 \u5386\u53F2</button>
|
|
129
|
-
<span id="ma-session-title" class="text-[11px] text-base-content/55 truncate flex-1 min-w-0 px-1"></span>
|
|
130
|
-
<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>
|
|
131
|
-
<button type="button" id="ma-quick-today" class="btn btn-ghost btn-xs text-[10px]">\u4ECA\u5929\u505A\u4E86\u5565</button>
|
|
132
|
-
<button type="button" id="ma-quick-projects" class="btn btn-ghost btn-xs text-[10px]">\u9879\u76EE\u6982\u51B5</button>
|
|
133
|
-
</div>
|
|
134
|
-
<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">
|
|
135
|
-
<span id="ma-resume-text" class="flex-1 min-w-0 truncate text-base-content/70"></span>
|
|
136
|
-
<button type="button" id="ma-resume-focus" class="btn btn-primary btn-xs">\u7EE7\u7EED\u804A</button>
|
|
137
|
-
</div>
|
|
138
|
-
<div id="ma-messages" class="flex-1 overflow-y-auto p-3 flex flex-col gap-2"></div>
|
|
139
|
-
<div id="ma-attach-bar" class="hidden px-3 pt-1 flex flex-wrap gap-1"></div>
|
|
140
|
-
<div class="flex gap-2 items-end px-3 py-2 border-t border-base-300 bg-base-200 flex-shrink-0">
|
|
141
|
-
<label class="btn btn-ghost btn-sm px-2 cursor-pointer" title="\u6DFB\u52A0\u56FE\u7247 (VLM)" style="height:40px">
|
|
142
|
-
\u{1F5BC}
|
|
143
|
-
<input type="file" id="ma-image-input" accept="image/*" multiple class="hidden">
|
|
144
|
-
</label>
|
|
145
|
-
<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"
|
|
146
|
-
class="textarea textarea-bordered flex-1 text-sm resize-none leading-relaxed"
|
|
147
|
-
style="min-height:40px;max-height:120px"
|
|
148
|
-
name="meta-agent-message"
|
|
149
|
-
autocomplete="off"
|
|
150
|
-
autocorrect="off"
|
|
151
|
-
autocapitalize="off"
|
|
152
|
-
spellcheck="false"
|
|
153
|
-
data-1p-ignore="true"
|
|
154
|
-
data-lpignore="true"
|
|
155
|
-
data-form-type="other"
|
|
156
|
-
data-bwignore="true"></textarea>
|
|
157
|
-
<button type="button" id="ma-send" class="btn btn-primary btn-sm" style="height:40px">\u53D1\u9001</button>
|
|
158
|
-
</div>
|
|
159
|
-
</div>
|
|
160
|
-
|
|
161
|
-
<div id="ma-mode-history" class="meta-agent-body hidden flex-col min-h-0 flex-1">
|
|
162
|
-
<div class="flex items-center gap-2 px-3 py-2 border-b border-base-300 flex-shrink-0">
|
|
163
|
-
<input id="ma-history-search" type="search" placeholder="\u641C\u7D22\u6807\u9898 / \u9884\u89C8\u2026"
|
|
164
|
-
class="input input-xs input-bordered flex-1 text-xs" autocomplete="off">
|
|
165
|
-
<button type="button" id="ma-history-refresh" class="btn btn-ghost btn-xs">\u21BB</button>
|
|
166
|
-
<button type="button" id="ma-history-new" class="btn btn-primary btn-xs">\uFF0B \u65B0\u5BF9\u8BDD</button>
|
|
167
|
-
</div>
|
|
168
|
-
<div id="ma-history-list" class="flex-1 overflow-y-auto p-2 flex flex-col gap-1"></div>
|
|
169
|
-
<p class="text-[10px] text-base-content/40 px-3 py-2 border-t border-base-300 flex-shrink-0">
|
|
170
|
-
\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
|
|
171
|
-
</p>
|
|
172
|
-
</div>
|
|
173
|
-
|
|
174
|
-
<div id="ma-mode-notes" class="meta-agent-body hidden flex min-h-0 flex-1">
|
|
175
|
-
<div class="w-[44%] min-w-[180px] max-w-[240px] border-r border-base-300 flex flex-col">
|
|
176
|
-
<div class="flex items-center gap-2 px-3 py-2 border-b border-base-300 flex-shrink-0">
|
|
177
|
-
<input id="ma-notes-search" type="search" placeholder="\u641C\u7D22\u8BB0\u4E8B\u2026"
|
|
178
|
-
class="input input-xs input-bordered flex-1 text-xs" autocomplete="off">
|
|
179
|
-
<button type="button" id="ma-notes-refresh" class="btn btn-ghost btn-xs">\u21BB</button>
|
|
180
|
-
<button type="button" id="ma-notes-new" class="btn btn-primary btn-xs">\uFF0B</button>
|
|
181
|
-
</div>
|
|
182
|
-
<div id="ma-notes-list" class="flex-1 overflow-y-auto p-2 flex flex-col gap-1"></div>
|
|
183
|
-
</div>
|
|
184
|
-
<div class="flex-1 min-w-0 flex flex-col">
|
|
185
|
-
<div class="px-3 py-2 border-b border-base-300 text-[11px] text-base-content/45 flex items-center gap-2 flex-wrap">
|
|
186
|
-
<span>\u8BB0\u4E8B\u4FDD\u5B58\u5728 Hub\uFF0C\u53EF\u88AB Meta Agent \u68C0\u7D22\u3002</span>
|
|
187
|
-
<span id="ma-note-links" class="truncate"></span>
|
|
188
|
-
</div>
|
|
189
|
-
<div class="p-3 flex flex-col gap-3 flex-1 overflow-y-auto">
|
|
190
|
-
<label class="form-control">
|
|
191
|
-
<span class="label-text text-xs">\u6807\u9898</span>
|
|
192
|
-
<input id="ma-note-title" class="input input-sm input-bordered text-sm" placeholder="\u4F8B\u5982\uFF1A\u53D1\u5E03\u524D\u9057\u7559\u95EE\u9898">
|
|
193
|
-
</label>
|
|
194
|
-
<label class="form-control flex-1">
|
|
195
|
-
<span class="label-text text-xs">\u5185\u5BB9</span>
|
|
196
|
-
<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>
|
|
197
|
-
</label>
|
|
198
|
-
<div class="flex flex-wrap items-center gap-3 text-xs">
|
|
199
|
-
<label class="flex items-center gap-1 cursor-pointer">
|
|
200
|
-
<input type="checkbox" id="ma-note-pin" class="checkbox checkbox-xs">
|
|
201
|
-
\u7F6E\u9876
|
|
202
|
-
</label>
|
|
203
|
-
<label class="flex items-center gap-1 cursor-pointer">
|
|
204
|
-
<input type="checkbox" id="ma-note-link-project" class="checkbox checkbox-xs">
|
|
205
|
-
\u5173\u8054\u5F53\u524D\u9879\u76EE
|
|
206
|
-
</label>
|
|
207
|
-
<label class="flex items-center gap-1 cursor-pointer">
|
|
208
|
-
<input type="checkbox" id="ma-note-link-session" class="checkbox checkbox-xs">
|
|
209
|
-
\u5173\u8054\u5F53\u524D session
|
|
210
|
-
</label>
|
|
211
|
-
</div>
|
|
212
|
-
<div class="flex items-center justify-between gap-2">
|
|
213
|
-
<span id="ma-note-status" class="text-xs text-base-content/45"></span>
|
|
214
|
-
<div class="flex items-center gap-2">
|
|
215
|
-
<button type="button" id="ma-note-ask" class="btn btn-ghost btn-sm">\u5FEB\u6377\u63D0\u95EE</button>
|
|
216
|
-
<button type="button" id="ma-note-delete" class="btn btn-ghost btn-sm text-error">\u5220\u9664</button>
|
|
217
|
-
<button type="button" id="ma-note-save" class="btn btn-primary btn-sm">\u4FDD\u5B58\u8BB0\u4E8B</button>
|
|
218
|
-
</div>
|
|
219
|
-
</div>
|
|
220
|
-
</div>
|
|
221
|
-
</div>
|
|
222
|
-
</div>
|
|
223
|
-
|
|
224
|
-
<div id="ma-mode-report" class="meta-agent-body hidden flex-col min-h-0 flex-1">
|
|
225
|
-
<div class="flex items-center gap-2 px-3 py-2 border-b border-base-300 flex-shrink-0 flex-wrap">
|
|
226
|
-
<select id="ma-report-days" class="select select-xs select-bordered">
|
|
227
|
-
<option value="1">\u4ECA\u5929</option>
|
|
228
|
-
<option value="3">\u8FD1 3 \u5929</option>
|
|
229
|
-
<option value="7">\u8FD1 7 \u5929</option>
|
|
230
|
-
</select>
|
|
231
|
-
<button type="button" id="ma-gen-report" class="btn btn-primary btn-xs">\u751F\u6210\u62A5\u544A</button>
|
|
232
|
-
<button type="button" id="ma-load-reports" class="btn btn-ghost btn-xs">\u5386\u53F2</button>
|
|
233
|
-
<label class="flex items-center gap-1 text-[11px] ml-auto cursor-pointer select-none">
|
|
234
|
-
<input type="checkbox" id="ma-auto-report" class="checkbox checkbox-xs">
|
|
235
|
-
\u81EA\u52A8\u65E5\u62A5
|
|
236
|
-
</label>
|
|
237
|
-
<select id="ma-auto-hour" class="select select-xs select-bordered w-16" title="\u81EA\u52A8\u751F\u6210\u65F6\u523B">
|
|
238
|
-
${Array.from({length:24},(e,t)=>`<option value="${t}">${String(t).padStart(2,"0")}:00</option>`).join("")}
|
|
239
|
-
</select>
|
|
240
|
-
</div>
|
|
241
|
-
<div id="ma-report-list" class="hidden border-b border-base-300 max-h-28 overflow-y-auto px-2 py-1"></div>
|
|
242
|
-
<div id="ma-report-body" class="flex-1 overflow-y-auto p-4">
|
|
243
|
-
<div class="text-sm text-base-content/45 text-center py-10">
|
|
244
|
-
\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
|
|
245
|
-
</div>
|
|
246
|
-
</div>
|
|
247
|
-
</div>
|
|
248
|
-
|
|
249
|
-
<div id="ma-mode-config" class="meta-agent-body hidden flex-col min-h-0 flex-1 overflow-y-auto p-4 gap-3">
|
|
250
|
-
<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>
|
|
251
|
-
<label class="form-control">
|
|
252
|
-
<span class="label-text text-xs">API URL</span>
|
|
253
|
-
<input id="ma-cfg-url" class="input input-sm input-bordered font-mono text-xs" placeholder="https://api.deepseek.com/chat/completions">
|
|
254
|
-
</label>
|
|
255
|
-
<label class="form-control">
|
|
256
|
-
<span class="label-text text-xs">API Key</span>
|
|
257
|
-
<input id="ma-cfg-key" type="password" class="input input-sm input-bordered" placeholder="\u7559\u7A7A\u5219\u4E0D\u4FEE\u6539">
|
|
258
|
-
</label>
|
|
259
|
-
<label class="form-control">
|
|
260
|
-
<span class="label-text text-xs">\u4E3B\u6A21\u578B</span>
|
|
261
|
-
<input id="ma-cfg-model" class="input input-sm input-bordered font-mono text-xs" placeholder="deepseek-chat">
|
|
262
|
-
</label>
|
|
263
|
-
<div class="divider text-xs my-1">VLM \u591A\u6A21\u6001\uFF08\u53EF\u7559\u7A7A\u5171\u7528\u4E0A\u65B9\uFF09</div>
|
|
264
|
-
<label class="form-control">
|
|
265
|
-
<span class="label-text text-xs">VLM URL</span>
|
|
266
|
-
<input id="ma-cfg-vlm-url" class="input input-sm input-bordered font-mono text-xs" placeholder="\u53EF\u9009">
|
|
267
|
-
</label>
|
|
268
|
-
<label class="form-control">
|
|
269
|
-
<span class="label-text text-xs">VLM Key</span>
|
|
270
|
-
<input id="ma-cfg-vlm-key" type="password" class="input input-sm input-bordered" placeholder="\u53EF\u9009">
|
|
271
|
-
</label>
|
|
272
|
-
<label class="form-control">
|
|
273
|
-
<span class="label-text text-xs">VLM \u6A21\u578B</span>
|
|
274
|
-
<input id="ma-cfg-vlm-model" class="input input-sm input-bordered font-mono text-xs" placeholder="gpt-4o-mini / \u2026">
|
|
275
|
-
</label>
|
|
276
|
-
<label class="form-control">
|
|
277
|
-
<span class="label-text text-xs">System Prompt</span>
|
|
278
|
-
<textarea id="ma-cfg-system" class="textarea textarea-bordered textarea-sm text-xs min-h-[80px]"></textarea>
|
|
279
|
-
</label>
|
|
280
|
-
<div class="flex gap-2">
|
|
281
|
-
<button type="button" id="ma-cfg-save" class="btn btn-primary btn-sm">\u4FDD\u5B58</button>
|
|
282
|
-
<span id="ma-cfg-status" class="text-xs text-base-content/50 self-center"></span>
|
|
283
|
-
</div>
|
|
284
|
-
</div>
|
|
285
|
-
</div>
|
|
286
|
-
</div>`}function ye(e){ht=e;let t=r("ma-mode-chat"),n=r("ma-mode-history"),s=r("ma-mode-notes"),a=r("ma-mode-report"),o=r("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 i=(d,l)=>{let c=r(d);c&&(c.classList.toggle("border-primary/40",l),c.classList.toggle("text-primary",l))};i("ma-btn-chat",e==="chat"),i("ma-btn-history",e==="history"),i("ma-btn-notes",e==="notes"),i("ma-btn-report",e==="report"),e==="history"&&_t(),e==="notes"&&Dt()}function Gn(){let e=r("ma-session-title"),t=r("ma-resume-bar"),n=r("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=Ps(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 Wa(e="chat"){let t=r("meta-agent-panel");if(t){if(t.classList.remove("hidden"),t.setAttribute("aria-hidden","false"),_s=!0,ye(e),e==="chat"){at();let n=localStorage.getItem(bt);!pe&&n?ot(n,{silent:!0}).catch(()=>{localStorage.removeItem(bt)}):Gn()}e==="history"&&at().then(()=>_t()),e==="report"&&Ji(),e==="config"&&Vi(),setTimeout(()=>{ht==="chat"&&r("ma-input")?.focus(),ht==="history"&&r("ma-history-search")?.focus()},50)}}function Ui(){let e=r("meta-agent-panel");e&&(e.classList.add("hidden"),e.setAttribute("aria-hidden","true"),_s=!1)}function Wi(){_s?Ui():Wa(ht==="config"?"chat":ht)}function Z(e,t,n={}){let s=r("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">${yn(t)}</div>`,wn(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||"")}">
|
|
287
|
-
<span class="ma-tool-name">${p(n.name||"tool")}</span>
|
|
288
|
-
<span class="ma-tool-phase">${p(n.phase||"")}</span>
|
|
289
|
-
<pre class="ma-tool-args">${p(JSON.stringify(n.args||{},null,0).slice(0,200))}</pre>
|
|
290
|
-
</div>`),s.appendChild(a),s.scrollTop=s.scrollHeight,a}function Hi(e,t){let n=e?.querySelector(".ma-bubble");n&&(n.innerHTML=yn(t),wn(n),r("ma-messages").scrollTop=r("ma-messages").scrollHeight)}function Gi(e,t,n){let s=r("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 i=a.querySelector(".ma-tool-result");i||(i=document.createElement("pre"),i.className="ma-tool-result",a.appendChild(i)),i.textContent=JSON.stringify(n,null,0).slice(0,500)}}function Yl(e){let t=r("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=`
|
|
291
|
-
<div class="ma-approval-label">\u26A0 Agent \u60F3\u8981\u6267\u884C\u547D\u4EE4\uFF0C\u662F\u5426\u5141\u8BB8\uFF1F</div>
|
|
292
|
-
<pre class="ma-approval-cmd">${p(s)}</pre>
|
|
293
|
-
<div class="ma-approval-actions">
|
|
294
|
-
<button type="button" class="btn btn-xs btn-error" data-approve="0">\u62D2\u7EDD</button>
|
|
295
|
-
<button type="button" class="btn btn-xs btn-success" data-approve="1">\u5141\u8BB8\u6267\u884C</button>
|
|
296
|
-
</div>`,n.querySelectorAll("[data-approve]").forEach(a=>{a.addEventListener("click",async()=>{let o=a.dataset.approve==="1";n.querySelectorAll("button").forEach(i=>{i.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(i){n.querySelector(".ma-approval-label").textContent=`\u786E\u8BA4\u5931\u8D25\uFF1A${i.message}`}})}),t.appendChild(n),t.scrollTop=t.scrollHeight}function Xl(){return Pi+=1,`img${Pi}`}function Zl(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 Ri(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=Xl(),i=`[${o}](${a})`,d=r("ma-input");Zl(d,(d?.value&&!d.value.endsWith(`
|
|
297
|
-
`)&&d.value.length?`
|
|
298
|
-
`:"")+i+`
|
|
299
|
-
`);let l="";try{l=URL.createObjectURL(e)}catch{}return jt.push({path:a,previewUrl:l,label:o,ref:i}),Ga(),{path:a,ref:i,label:o}}function Ga(){let e=r("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)=>`
|
|
300
|
-
<div class="ma-thumb relative" title="${p(t.ref||t.path)}">
|
|
301
|
-
${t.previewUrl?`<img src="${t.previewUrl}" alt="${p(t.label||"img")}">`:`<span class="ma-thumb-path">${p(t.label||"img")}</span>`}
|
|
302
|
-
<span class="ma-thumb-label">${p(t.label||"")}</span>
|
|
303
|
-
<button type="button" class="ma-thumb-x" data-rm-img="${n}">\u2715</button>
|
|
304
|
-
</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=r("ma-input");a&&s?.ref&&(a.value=a.value.split(s.ref).join("").replace(/\n{3,}/g,`
|
|
305
|
-
|
|
306
|
-
`),a.dispatchEvent(new Event("input"))),jt.splice(n,1),Ga()})})}}function Ps(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{Ds=(await y("GET","/api/ai/sessions")).sessions||[]}catch{Ds=[]}return Ds}function zi(){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 Wn(){Nt=null,Fi=null,r("ma-note-title").value="",r("ma-note-content").value="",r("ma-note-pin").checked=!1,r("ma-note-link-project").checked=!!E.peek()?.path,r("ma-note-link-session").checked=!!f.sessionId,r("ma-note-status").textContent="\u65B0\u8BB0\u4E8B",r("ma-note-delete").disabled=!0,r("ma-note-links").textContent=zi().summary||"\u672A\u5173\u8054\u4E0A\u4E0B\u6587"}function Ki(e){Nt=e?.id||null,Fi=e||null,r("ma-note-title").value=e?.title||"",r("ma-note-content").value=e?.content||"",r("ma-note-pin").checked=!!e?.pinned,r("ma-note-link-project").checked=!!e?.cwd,r("ma-note-link-session").checked=!!e?.sessionId,r("ma-note-status").textContent=e?.updatedAt?`\u4E0A\u6B21\u66F4\u65B0 ${Ps(e.updatedAt)}`:"",r("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)}`),r("ma-note-links").textContent=t.join(" \xB7 ")||"\u672A\u5173\u8054\u4E0A\u4E0B\u6587"}function ec(){let e=r("ma-note-title")?.value?.trim()||"",t=r("ma-note-content")?.value?.trim()||"";if(!e&&!t){r("ma-note-status").textContent="\u5148\u9009\u4E00\u6761\u8BB0\u4E8B\u6216\u8F93\u5165\u5185\u5BB9";return}let n=[];r("ma-note-link-project")?.checked&&E.peek()?.path&&n.push(`\u9879\u76EE\u8DEF\u5F84\uFF1A${E.peek().path}`),r("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
|
|
307
|
-
${t}`:"",n.length?n.join(`
|
|
308
|
-
`):"","","\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(`
|
|
309
|
-
`);ye("chat"),r("ma-input").value=s,r("ma-input").dispatchEvent(new Event("input")),r("ma-input").focus()}async function vn(){let e=(qi||"").trim();return Ns=(await y("GET",`/api/ai/notes?limit=80${e?`&q=${encodeURIComponent(e)}`:""}`)).notes||[],Ns}function Dt(){let e=r("ma-notes-list");if(e){if(!Ns.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=Ns.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`
|
|
310
|
-
<button type="button" class="ma-note-item ${n?"active":""}" data-note-id="${p(t.id)}">
|
|
311
|
-
<div class="text-left">
|
|
312
|
-
<div class="font-medium text-xs truncate">${p(t.title||"\u672A\u547D\u540D")}</div>
|
|
313
|
-
<div class="text-[10px] text-base-content/45 mt-0.5 line-clamp-2">${p(t.content||"")}</div>
|
|
314
|
-
<div class="text-[10px] text-base-content/35 mt-1">${p(s)}${s?" \xB7 ":""}${p(Ps(t.updatedAt)||"")}</div>
|
|
315
|
-
</div>
|
|
316
|
-
</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}`);Ki(n),Dt()}catch(n){r("ma-note-status").textContent=n.message}})})}}async function tc(){let e=r("ma-note-title")?.value?.trim()||"",t=r("ma-note-content")?.value?.trim()||"";if(!e||!t){r("ma-note-status").textContent="\u6807\u9898\u548C\u5185\u5BB9\u90FD\u4E0D\u80FD\u4E3A\u7A7A";return}let n=zi(),s={id:Nt||void 0,title:e,content:t,pinned:!!r("ma-note-pin")?.checked,cwd:r("ma-note-link-project")?.checked?n.project:"",sessionId:r("ma-note-link-session")?.checked?n.sessionId:"",agent:r("ma-note-link-session")?.checked?n.agent:""};r("ma-note-status").textContent="\u4FDD\u5B58\u4E2D\u2026";let a=await y("POST","/api/ai/notes",s);Ki(a),await vn(),Dt()}async function nc(){if(!Nt){Wn();return}confirm("\u5220\u9664\u8FD9\u6761\u8BB0\u4E8B\uFF1F\u4E0D\u53EF\u6062\u590D\u3002")&&(await y("DELETE",`/api/ai/notes/${Nt}`),Wn(),await vn(),Dt())}function _t(){let e=r("ma-history-list");if(!e)return;let t=(Bi||"").trim().toLowerCase(),n=Ds;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">
|
|
317
|
-
${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"}
|
|
318
|
-
</div>`;return}e.innerHTML=n.map(s=>{let a=s.id===pe,o=Ps(s.updatedAt)||"",i=s.messageCount||0;return`
|
|
319
|
-
<div class="ma-hist-item ${a?"active":""}" data-hist-id="${p(s.id)}">
|
|
320
|
-
<div class="flex items-start gap-2">
|
|
321
|
-
<button type="button" class="ma-hist-open flex-1 min-w-0 text-left" data-hist-open="${p(s.id)}">
|
|
322
|
-
<div class="font-medium text-xs truncate">${p(s.title||s.id.slice(0,8))}</div>
|
|
323
|
-
<div class="text-[10px] text-base-content/45 mt-0.5 line-clamp-2">${p(s.preview||"\uFF08\u65E0\u9884\u89C8\uFF09")}</div>
|
|
324
|
-
<div class="text-[10px] text-base-content/35 mt-1">${p(o)}${i?` \xB7 ${i} \u6761`:""}${a?" \xB7 \u5F53\u524D":""}</div>
|
|
325
|
-
</button>
|
|
326
|
-
<div class="flex flex-col gap-0.5 flex-shrink-0">
|
|
327
|
-
<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>
|
|
328
|
-
<button type="button" class="btn btn-ghost btn-xs px-1 text-error" data-hist-del="${p(s.id)}" title="\u5220\u9664">\u2715</button>
|
|
329
|
-
</div>
|
|
330
|
-
</div>
|
|
331
|
-
</div>`}).join(""),e.querySelectorAll("[data-hist-open]").forEach(s=>{s.addEventListener("click",async()=>{await ot(s.dataset.histOpen),ye("chat"),r("ma-input")?.focus()})}),e.querySelectorAll("[data-hist-resume]").forEach(s=>{s.addEventListener("click",async a=>{a.stopPropagation(),await ot(s.dataset.histResume),ye("chat"),r("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(i){alert(i.message)}})})}function Oi(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(`
|
|
332
|
-
`)||"[\u2026]"}function sc(e){let t=r("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",Oi(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:Oi(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)Gi(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"),i=o[o.length-1];if(i){i.classList.add("done");let d=i.querySelector(".ma-tool-result");d||(d=document.createElement("pre"),d.className="ma-tool-result",i.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 ac(){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=r("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"),Gn(),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),sc(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"),Gn(),ht==="history"&&_t(),n}catch(n){throw t.silent||Z("error",n.message),n}}async function js(){if(xn)return;let e=r("ma-input"),t=(e?.value||"").trim();if(!t)return;xn=!0,r("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=[],Ga();let n=null,s="";try{await Ua("/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),Gn()},content:a=>{s=a.content||"",n||(n=Z("assistant","")),Hi(n,s)},tool:a=>{a.phase==="start"?Z("tool","",{name:a.name,args:a.args,phase:"start",id:a.id}):Gi(a.id,a.phase,a.result)},approval:a=>Yl(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&&Hi(n,a.content),Gn(),at()},error:a=>{Z("error",a.message||"error")}})}catch(a){Z("error",a.message)}finally{xn=!1,r("ma-send").disabled=!1}}async function oc(){if(xn)return;xn=!0;let e=parseInt(r("ma-report-days")?.value||"1",10),t=r("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>`,r("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 Ua("/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=yn(n),wn(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=yn(a.content),wn(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{xn=!1,r("ma-gen-report").disabled=!1}}async function Ji(){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=r("ma-report-body");s.innerHTML=`
|
|
333
|
-
<div class="text-[10px] text-base-content/40 mb-2">${p(n.title||t)} \xB7 ${p(n.generatedAt||"")}</div>
|
|
334
|
-
<div class="md ma-report-md">${yn(n.markdown)}</div>`,wn(s)}}catch{}}async function ic(){let e=r("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=>`
|
|
335
|
-
<button type="button" class="ma-report-item w-full text-left px-2 py-1 rounded hover:bg-base-200 text-xs"
|
|
336
|
-
data-day="${p(s.day)}">
|
|
337
|
-
<span class="font-semibold">${p(s.day)}</span>
|
|
338
|
-
<span class="text-base-content/45 ml-1">${p(s.title||"")}</span>
|
|
339
|
-
</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=r("ma-report-body");o.innerHTML=`
|
|
340
|
-
<div class="text-[10px] text-base-content/40 mb-2">${p(a.title||a.day)} \xB7 ${p(a.generatedAt||"")}</div>
|
|
341
|
-
<div class="md ma-report-md">${yn(a.markdown)}</div>`,wn(o)}catch(a){r("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 Vi(){try{let e=await y("GET","/api/ai/config");r("ma-cfg-url").value=e.url||"",r("ma-cfg-model").value=e.model||"",r("ma-cfg-key").placeholder=e.hasKey?"\u5DF2\u914D\u7F6E \xB7 \u7559\u7A7A\u4E0D\u4FEE\u6539":"API Key",r("ma-cfg-key").value="",r("ma-cfg-vlm-url").value=e.vlm_url||"",r("ma-cfg-vlm-model").value=e.vlm_model||"",r("ma-cfg-vlm-key").value="",r("ma-cfg-vlm-key").placeholder=e.hasVlmKey?"\u5DF2\u914D\u7F6E \xB7 \u7559\u7A7A\u4E0D\u4FEE\u6539":"\u53EF\u9009",r("ma-cfg-system").value=e.system||"",r("ma-auto-report")&&(r("ma-auto-report").checked=!!e.auto_report),r("ma-auto-hour")&&(r("ma-auto-hour").value=String(e.auto_report_hour??18)),zn(e)}catch(e){r("ma-cfg-status").textContent=e.message}}async function rc(){let e=r("ma-cfg-status");e.textContent="\u4FDD\u5B58\u4E2D\u2026";try{let t={url:r("ma-cfg-url").value.trim(),model:r("ma-cfg-model").value.trim(),vlm_url:r("ma-cfg-vlm-url").value.trim(),vlm_model:r("ma-cfg-vlm-model").value.trim(),system:r("ma-cfg-system").value,auto_report:!!r("ma-auto-report")?.checked,auto_report_hour:parseInt(r("ma-auto-hour")?.value||"18",10)},n=r("ma-cfg-key").value.trim(),s=r("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",r("ma-cfg-key").value="",r("ma-cfg-vlm-key").value="",zn(a)}catch(t){e.textContent=t.message}}function zn(e){if(As&&(clearInterval(As),As=null),!e?.auto_report)return;let t=e.auto_report_hour??18;As=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(Fa!==s&&!(n.getMinutes()>10))try{Fa=s,localStorage.setItem("ai_last_auto_report",s),await Ua("/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),Fa="",localStorage.removeItem("ai_last_auto_report")}},60*1e3)}function Qi(){r("meta-agent-panel")||(document.getElementById("root")?.insertAdjacentHTML("beforeend",Ql()),document.querySelectorAll("[data-ma-close]").forEach(e=>{e.addEventListener("click",Ui)}),r("ma-btn-chat")?.addEventListener("click",()=>ye("chat")),r("ma-btn-history")?.addEventListener("click",async()=>{await at(),ye("history")}),r("ma-btn-notes")?.addEventListener("click",async()=>{await vn(),Nt||Wn(),ye("notes")}),r("ma-open-history")?.addEventListener("click",async()=>{await at(),ye("history")}),r("ma-btn-report")?.addEventListener("click",()=>{ye("report"),Ji()}),r("ma-btn-config")?.addEventListener("click",()=>{ye("config"),Vi()}),r("ma-send")?.addEventListener("click",js),r("ma-input")?.addEventListener("keydown",e=>{(e.metaKey||e.ctrlKey)&&e.key==="Enter"&&(e.preventDefault(),js())}),r("ma-input")?.addEventListener("input",()=>{let e=r("ma-input");e.style.height="auto",e.style.height=Math.min(e.scrollHeight,120)+"px"}),r("ma-new-chat")?.addEventListener("click",()=>{ot(null),ye("chat")}),r("ma-del-session")?.addEventListener("click",ac),r("ma-resume-focus")?.addEventListener("click",()=>{r("ma-input")?.focus()}),r("ma-history-refresh")?.addEventListener("click",async()=>{await at(),_t()}),r("ma-history-new")?.addEventListener("click",()=>{ot(null),ye("chat")}),r("ma-history-search")?.addEventListener("input",e=>{Bi=e.target.value||"",_t()}),r("ma-quick-today")?.addEventListener("click",()=>{ye("chat"),r("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",js()}),r("ma-quick-projects")?.addEventListener("click",()=>{ye("chat"),r("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",js()}),r("ma-gen-report")?.addEventListener("click",oc),r("ma-load-reports")?.addEventListener("click",ic),r("ma-notes-refresh")?.addEventListener("click",async()=>{await vn(),Dt()}),r("ma-notes-new")?.addEventListener("click",()=>{Wn(),Dt(),r("ma-note-title")?.focus()}),r("ma-notes-search")?.addEventListener("input",async e=>{qi=e.target.value||"",await vn(),Dt()}),r("ma-note-save")?.addEventListener("click",async()=>{try{await tc()}catch(e){r("ma-note-status").textContent=e.message}}),r("ma-note-delete")?.addEventListener("click",async()=>{try{await nc()}catch(e){r("ma-note-status").textContent=e.message}}),r("ma-note-ask")?.addEventListener("click",ec),r("ma-cfg-save")?.addEventListener("click",rc),r("ma-auto-report")?.addEventListener("change",async()=>{try{let e=await y("PUT","/api/ai/config",{auto_report:!!r("ma-auto-report").checked,auto_report_hour:parseInt(r("ma-auto-hour")?.value||"18",10)});zn(e)}catch{}}),r("ma-auto-hour")?.addEventListener("change",async()=>{try{let e=await y("PUT","/api/ai/config",{auto_report:!!r("ma-auto-report")?.checked,auto_report_hour:parseInt(r("ma-auto-hour").value||"18",10)});zn(e)}catch{}}),r("ma-image-input")?.addEventListener("change",async e=>{let t=[...e.target.files||[]],n=r("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 Ri(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(!_s||ht!=="chat")return;let t=r("ma-input"),n=r("meta-agent-panel"),s=document.activeElement;if(!n||!s||!n.contains(s))return;let o=[...e.clipboardData?.items||[]].filter(i=>i.type.startsWith("image/"));if(o.length){e.preventDefault(),t&&(t.disabled=!0);try{for(let i of o){let d=i.getAsFile();if(!d)continue;let l=(i.type.split("/")[1]||"png").replace(/[^a-z0-9]/gi,"")||"png";await Ri(d,`paste-${Date.now()}.${l}`)}}catch(i){Z("error",`\u7C98\u8D34\u56FE\u7247\u5931\u8D25: ${i.message}`)}finally{t&&(t.disabled=!1,t.focus())}}}),ot(null,{silent:!0}),Wn())}function Kn(){f.token&&(A.peek()&&!jn()||(at(),vn().catch(()=>{}),y("GET","/api/ai/config").then(zn).catch(()=>{})))}var _s,ht,xn,pe,Se,jt,Pi,As,Fa,Ds,Bi,Ns,qi,Nt,Fi,bt,Jn=R(()=>{O();ue();q();Ma();hs();_s=!1,ht="chat",xn=!1,pe=null,Se=null,jt=[],Pi=0,As=null,Fa=localStorage.getItem("ai_last_auto_report")||"",Ds=[],Bi="",Ns=[],qi="",Nt=null,Fi=null,bt="ma_last_session_id"});function za(e){return Array.isArray(e)?e:e&&Array.isArray(e.results)?e.results:e&&Array.isArray(e.sessions)?e.sessions:[]}function Ht(){let e=za(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 Zi(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 lc(e,t){let n=[],a=new Date(e,t,1).getDay(),i=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<=i;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 er(e,t){let n=new Date(e.getFullYear(),e.getMonth(),e.getDate()).getTime(),s=n+1440*60*1e3;return t.filter(a=>{let o=F(a.updatedAt);return o!=null&&o>=n&&o<s})}function tr(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=r("calendar-grid");if(!t)return;e=za(e??Ht());let n=r("calendar-month-year");if(n){let u=new Date(Hs,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),i=r("stats-total-sessions"),d=r("stats-total-projects"),l=r("stats-total-tokens");i&&(i.textContent=String(s)),d&&(d.textContent=String(a)),l&&(l.textContent=tr(o));let c=lc(Hs,Pt);Vn||(Vn=Zi(new Date)),t.innerHTML=c.map(u=>{let h=u.date,x=Zi(h),C=er(h,e).length,U=h.toDateString()===new Date().toDateString(),ke=x===Vn,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")),U?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`
|
|
342
|
-
<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} ${_}"
|
|
343
|
-
data-cal-date="${x}" title="${h.toDateString()}: ${C} session(s)">
|
|
344
|
-
${se}
|
|
345
|
-
<span class="text-sm font-semibold">${h.getDate()}</span>
|
|
346
|
-
${C>0?`<span class="text-[10px] mt-0.5 opacity-80 font-medium whitespace-nowrap">${C}s</span>`:""}
|
|
347
|
-
</div>`}).join(""),cc(e),Ja()}function cc(e){let t=r("selected-day-title"),n=r("selected-day-sessions");if(!t||!n)return;let[s,a,o]=Vn.split("-").map(Number),i=new Date(s,a-1,o);t.textContent=`Activity on ${i.toLocaleDateString([],{weekday:"short",month:"short",day:"numeric",year:"numeric"})}`,e=za(e);let d=er(i,e),l=d.reduce((u,h)=>u+(Number(h.totalTokens)||0),0),c=r("stats-selected-tokens");if(c&&(c.textContent=tr(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)=>(F(h.updatedAt)||0)-(F(u.updatedAt)||0)),n.innerHTML=d.map(u=>{let h=F(u.updatedAt),x=h!=null?new Date(h).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):"";return`
|
|
348
|
-
<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":""}"
|
|
349
|
-
data-session-id="${p(u.sessionId)}"
|
|
350
|
-
data-session-cwd="${p(u.cwd||"")}"
|
|
351
|
-
data-session-config-dir="${p(u.configDir||"")}"
|
|
352
|
-
data-session-agent="${p(u.agent||"claude")}"
|
|
353
|
-
data-session-machine="${p(u.machineId||"")}">
|
|
354
|
-
<div class="flex-shrink-0">${nn(u.agent)}</div>
|
|
355
|
-
<div class="flex-1 min-w-0">
|
|
356
|
-
<div class="text-xs font-semibold truncate text-base-content/90">${p(Ye(u))}</div>
|
|
357
|
-
<div class="text-[10px] text-base-content/40 truncate mt-0.5">${p(u.projectName||sn(u.cwd)||"No workspace")}</div>
|
|
358
|
-
</div>
|
|
359
|
-
<div class="text-[9px] text-base-content/45 font-mono whitespace-nowrap bg-base-300 px-1.5 py-0.5 rounded">${x}</div>
|
|
360
|
-
</div>`}).join("")}function Rs(e){return`${e.machineId||""}:${e.agent||"claude"}:${e.sessionId}`}function Ka(){try{let e=JSON.parse(localStorage.getItem(sr)||"[]");return Array.isArray(e)?e.filter(t=>t&&t.sessionId):[]}catch{return[]}}function ar(e){try{localStorage.setItem(sr,JSON.stringify(e))}catch{}}function or(e){if(!e?.sessionId)return;let t=Rs(e),n={...e,lastOpenedAt:Date.now()},s=Ka().filter(a=>Rs(a)!==t);s.unshift(n),ar(s.slice(0,nr)),Ja(),Qa()}function ir(e){if(!e?.sessionId)return;let t=Rs(e);ar(Ka().filter(n=>Rs(n)!==t)),Ja(),Qa()}function rr(e){return Ka().sort((t,n)=>(F(n.lastOpenedAt)||0)-(F(t.lastOpenedAt)||0)).slice(0,e)}function Ja(){let e=r("recent-sessions-list");if(!e)return;let t=rr(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`
|
|
361
|
-
<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":""}"
|
|
362
|
-
data-session-id="${p(n.sessionId)}"
|
|
363
|
-
data-session-cwd="${p(n.cwd||"")}"
|
|
364
|
-
data-session-config-dir="${p(n.configDir||"")}"
|
|
365
|
-
data-session-agent="${p(n.agent||"claude")}"
|
|
366
|
-
data-session-machine="${p(n.machineId||"")}">
|
|
367
|
-
<div class="flex-shrink-0">${nn(n.agent)}</div>
|
|
368
|
-
<div class="flex-1 min-w-0">
|
|
369
|
-
<div class="text-xs font-bold truncate text-base-content/95">${p(Ye(n))}</div>
|
|
370
|
-
<div class="text-[10px] text-base-content/40 truncate mt-1">${p(n.projectName||sn(n.cwd)||"No workspace")}</div>
|
|
371
|
-
</div>
|
|
372
|
-
<div class="text-[9px] text-base-content/40 whitespace-nowrap self-start mt-0.5">${s}</div>
|
|
373
|
-
</div>`}).join("")}function Ot(){let e=r("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=""),r("recent-menu-backdrop")?.classList.add("hidden")}function Va(){let e=r("recent-menu"),t=r("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=r("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 i=Math.max(160,window.innerHeight-a-12);e.style.maxHeight=`${Math.min(i,Math.round(window.innerHeight*.7))}px`}function dc(){let e=r("recent-menu");e&&(Qa(),e.classList.remove("hidden"),e.classList.add("recent-menu-open"),Va(),r("recent-menu-backdrop")?.classList.remove("hidden"))}function lr(){let e=r("recent-menu");e&&(e.classList.contains("hidden")?dc():Ot())}function Qa(){let e=r("recent-menu-list"),t=r("recent-menu-empty"),n=r("recent-menu-count");if(!e)return;let s=rr(nr);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),i=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`
|
|
374
|
-
<div class="recent-menu-item w-full text-left px-2 py-1.5 rounded-md flex items-start gap-2
|
|
375
|
-
${i?"bg-primary/15 text-primary":"hover:bg-base-200"}">
|
|
376
|
-
<button type="button" class="flex min-w-0 flex-1 items-start gap-2 text-left" aria-label="\u6253\u5F00 ${p(Ye(a))}"
|
|
377
|
-
data-session-id="${p(a.sessionId)}"
|
|
378
|
-
data-session-cwd="${p(a.cwd||"")}"
|
|
379
|
-
data-session-config-dir="${p(a.configDir||"")}"
|
|
380
|
-
data-session-agent="${p(a.agent||"claude")}"
|
|
381
|
-
data-session-machine="${p(a.machineId||"")}">
|
|
382
|
-
<span class="flex-shrink-0 mt-0.5">${nn(a.agent)}</span>
|
|
383
|
-
<span class="flex-1 min-w-0">
|
|
384
|
-
<span class="block text-xs font-semibold truncate leading-snug">${p(Ye(a))}</span>
|
|
385
|
-
<span class="block text-[10px] text-base-content/40 truncate mt-0.5">${p(a.projectName||sn(a.cwd)||"\u2014")}</span>
|
|
386
|
-
</span>
|
|
387
|
-
<span class="flex flex-col items-end gap-0.5 flex-shrink-0 self-start">
|
|
388
|
-
<span class="text-[9px] text-base-content/40 whitespace-nowrap">${p(o)}</span>
|
|
389
|
-
${d}
|
|
390
|
-
${i?'<span class="text-[9px] opacity-70">\u5F53\u524D</span>':""}
|
|
391
|
-
</span>
|
|
392
|
-
</button>
|
|
393
|
-
<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"
|
|
394
|
-
title="\u4ECE\u6700\u8FD1\u4F1A\u8BDD\u79FB\u9664" aria-label="\u4ECE\u6700\u8FD1\u4F1A\u8BDD\u79FB\u9664 ${p(Ye(a))}"
|
|
395
|
-
data-dismiss-recent-session="${p(a.sessionId)}"
|
|
396
|
-
data-dismiss-recent-agent="${p(a.agent||"claude")}"
|
|
397
|
-
data-dismiss-recent-machine="${p(a.machineId||"")}">\xD7</button>
|
|
398
|
-
</div>`}).join("")}function cr(e){Vn=e}function Ya(e){Pt+=e,Pt<0?(Pt=11,Hs--):Pt>11&&(Pt=0,Hs++)}var Hs,Pt,Vn,nr,sr,Xa=R(()=>{O();q();an();Hs=new Date().getFullYear(),Pt=new Date().getMonth(),Vn=null;nr=15,sr="recentSessionsV1"});var hr={};is(hr,{loadAgentsMeta:()=>$n,loadAllSessions:()=>_e,loadMemoryTab:()=>Us,loadWorkspaces:()=>kn,mdToHtml:()=>mr,openMemoryFile:()=>no,promptCustomModel:()=>Bs,refreshEffortSelect:()=>Os,refreshModelSelect:()=>Pe,renderProjectGroups:()=>pr,renderSessionList:()=>eo,renderTimeline:()=>fr,runActivitySearch:()=>qs,scheduleActivitySearch:()=>Fs,sessionItemHtml:()=>Za,syncSidebarChrome:()=>to});function dr(e){return Array.isArray(e)?e:e&&Array.isArray(e.results)?e.results:e&&Array.isArray(e.sessions)?e.sessions:[]}function uc({hubIndex:e=!1}={}){let t=new URLSearchParams;t.set("limit","2000"),e&&A.peek()&&t.set("index","1");let n=t.toString();return n?`/api/sessions?${n}`:"/api/sessions"}async function _e({waitFresh:e=!0,hubIndex:t=!1}={}){let n=dr(await Ms());if(n.length){let a=j.peek();if(A.peek()&&a){let o=n.filter(i=>!i.machineId||i.machineId===a);B.value=o.length?o:n}else B.value=n}let s=async()=>{let a=uc({hubIndex:t}),o=await y("GET",a,void 0,void 0,{etag:!0});if(o===$a)return B.peek();let i=dr(o);return B.value=i,Di(i),i};if(e||!n.length)try{await s()}catch(a){if(!n.length){let o=r("session-list");o&&(o.innerHTML=`<div class="px-3 py-3 text-xs text-error">${p(a.message)}</div>`)}}else s().catch(()=>{})}async function kn({waitFresh:e=!0}={}){let t=await Ni();t&&(ee.value=t);let n=async()=>{let s=await y("GET","/api/workspaces");ee.value=s,Un(s)};if(e||!t)try{await n()}catch{}else n().catch(()=>{})}function Za(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),i=!!s.favorite,d=!!s.hidden,l=!!(s.notes&&String(s.notes).trim()),c=Number(e.turnCount)||0,u=c>0&&c<=va,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}
|
|
399
|
-
(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
|
|
400
|
-
${n?"border-primary bg-primary/5":"border-transparent"} ${i?"session-fav":""} ${d?"session-hidden-row":""} ${u?"session-thin":""}"
|
|
401
|
-
data-session-id="${p(e.sessionId)}"
|
|
402
|
-
data-session-cwd="${p(e.cwd||"")}"
|
|
403
|
-
data-session-config-dir="${p(e.configDir||"")}"
|
|
404
|
-
data-session-agent="${p(e.agent||"claude")}"
|
|
405
|
-
data-session-machine="${p(e.machineId||"")}"
|
|
406
|
-
data-session-display="${p(e.display||"")}">
|
|
407
|
-
<div class="flex items-start gap-1.5">
|
|
408
|
-
<button type="button" class="session-fav-btn flex-shrink-0 leading-none mt-0.5 ${i?"is-fav":""}"
|
|
409
|
-
data-fav-toggle="1"
|
|
410
|
-
data-fav-session-id="${p(e.sessionId)}"
|
|
411
|
-
data-fav-session-agent="${p(e.agent||"claude")}"
|
|
412
|
-
data-fav-session-machine="${p(e.machineId||"")}"
|
|
413
|
-
title="${i?"Unfavorite":"Favorite"}">${i?"\u2605":"\u2606"}</button>
|
|
414
|
-
${nn(e.agent)}
|
|
415
|
-
<div class="min-w-0 flex-1">
|
|
416
|
-
<div class="session-title-wrap flex items-center gap-1 min-w-0"
|
|
417
|
-
data-rename-session-id="${p(e.sessionId)}"
|
|
418
|
-
data-rename-session-agent="${p(e.agent||"claude")}"
|
|
419
|
-
data-rename-session-machine="${p(e.machineId||"")}"
|
|
420
|
-
data-rename-session-display="${p(e.display||"")}">
|
|
421
|
-
<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":""}"
|
|
422
|
-
title="${p(C)}">${p(o)}</div>
|
|
423
|
-
<button type="button" class="session-rename-btn flex-shrink-0"
|
|
424
|
-
data-rename-session="1"
|
|
425
|
-
title="Rename session">\u270E</button>
|
|
426
|
-
<button type="button" class="session-hide-btn flex-shrink-0 ${d?"is-hidden":""}"
|
|
427
|
-
data-hide-toggle="1"
|
|
428
|
-
data-hide-session-id="${p(e.sessionId)}"
|
|
429
|
-
data-hide-session-agent="${p(e.agent||"claude")}"
|
|
430
|
-
data-hide-session-machine="${p(e.machineId||"")}"
|
|
431
|
-
title="${d?"Unhide session":"Hide session"}">${d?"\u{1F441}":"\u{1F648}"}</button>
|
|
432
|
-
</div>
|
|
433
|
-
${h}
|
|
434
|
-
${x||v?`<div class="flex items-center gap-1 mt-0.5 flex-wrap">${v}${x}</div>`:""}
|
|
435
|
-
</div>
|
|
436
|
-
<span class="text-[9px] text-base-content/30 flex-shrink-0 mt-0.5">${tn(e.updatedAt)}</span>
|
|
437
|
-
</div>
|
|
438
|
-
</div>`}async function $n(){try{let e=await y("GET","/api/agents");return kt.value=e,Pe(),e}catch(e){return console.warn("[agents] failed to load model list",e),null}}function Os(){let e=r("sel-effort");if(!e)return;let t=I.peek()||"claude",n=P.peek(),s=An(t,n),a=ie.peek()||"";if(!a){let i=lt(t,n);i&&s.includes(i)&&(a=i,ie.value=i)}let o=['<option value="">effort: off</option>'].concat(s.map(i=>`<option value="${p(i)}" ${i===a?"selected":""}>${p(i)}</option>`));if(e.innerHTML=o.join(""),a&&!s.includes(a)){let i=lt(t,n);i&&s.includes(i)?(ie.value=i,e.value=i):(ie.value="",e.value="")}else e.value=a}function Pe(){let e=r("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=Fe(t)||n[0]?.value;le(o),e.value=o,s=o}let a=r("sel-agent");a&&(a.value=t),Os()}function Bs({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&&ds(t).includes(n)&&ka(t,n),Cn(t,o),le(o),Pe())}function pr(e){if(!Array.isArray(e)||!e.length)return`<div class="px-3 py-6 text-center text-xs text-base-content/40">
|
|
439
|
-
No projects in this range.<br>
|
|
440
|
-
<span class="text-base-content/30">Try \u201CAll\u201D time or another agent.</span>
|
|
441
|
-
</div>`;let t=Kt.value,n=Jt.value,s=!!me.value.trim(),a=e[0]?.cwd||"(no path)";return e.map(o=>{let i=o.cwd||"(no path)",d=!1;n.has(i)?d=!1:t.has(i)?d=!0:d=s||i===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=`
|
|
442
|
-
<div class="project-header px-2.5 py-2 cursor-pointer hover:bg-base-300/80 select-none border-b border-base-300/40"
|
|
443
|
-
data-folder="${p(i)}" data-project-cwd="${p(o.cwd||"")}" data-project-machine="${p(o.machineId||"")}">
|
|
444
|
-
<div class="flex items-center gap-1.5">
|
|
445
|
-
<span class="text-[10px] text-base-content/40 w-3 flex-shrink-0">${d?"\u25BE":"\u25B8"}</span>
|
|
446
|
-
<span class="text-[12px] font-semibold truncate flex-1" title="${p(o.cwd||"")}">${p(o.projectName)}</span>
|
|
447
|
-
${l}
|
|
448
|
-
<span class="text-[9px] text-base-content/30 flex-shrink-0">${tn(o.updatedAt)}</span>
|
|
449
|
-
</div>
|
|
450
|
-
</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=>Za(v)).join("")}${h}</div>`:"";return c+x}).join("")}function fr(e){if(!Array.isArray(e)||!e.length)return`<div class="px-3 py-6 text-center text-xs text-base-content/40">
|
|
451
|
-
No recent activity.<br>
|
|
452
|
-
<span class="text-base-content/30">Widen the time range or clear filters.</span>
|
|
453
|
-
</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])=>`
|
|
454
|
-
<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>
|
|
455
|
-
${s.map(a=>Za(a,{showProject:!0})).join("")}
|
|
456
|
-
`).join("")}function eo(){let e=Je.value,t=Array.isArray(ct.value)?ct.value:[],n=Array.isArray(St.value)?St.value:[];return e==="timeline"?fr(t):pr(n)}function to(){document.querySelectorAll("[data-view]").forEach(o=>{let i=o.dataset.view===Je.peek();o.classList.toggle("bg-primary/15",i),o.classList.toggle("text-primary",i),o.classList.toggle("font-medium",i),o.classList.toggle("text-base-content/50",!i)}),document.querySelectorAll("[data-agent-filter]").forEach(o=>{o.classList.toggle("active",o.dataset.agentFilter===de.peek())});let e=r("time-range");e&&e.value!==cs.peek()&&(e.value=cs.peek());let t=r("search-status");if(!t)return;let n=Be.peek(),s=Array.isArray(n?.results)?n.results:null,a=(me.peek()||"").trim();if(Ve.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(),i=St.peek(),d=Array.isArray(o)?o.length:0,l=Array.isArray(i)?i.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 qs(e){let t=(e||"").trim();if(!t){Be.value=null,Ve.value=!1;return}Ve.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&&(Be.value={q:t.toLowerCase(),results:s.results||[],deep:!0})}catch(n){me.peek().trim()===t&&(Be.value={q:t.toLowerCase(),results:[],error:n.message})}finally{Ve.value=!1}}function Fs(e){clearTimeout(ur);let t=(e||"").trim();if(!t){Be.value=null,Ve.value=!1;return}ur=setTimeout(()=>qs(t),350)}function mr(e){if(!e)return"";if(typeof marked>"u")return`<pre class="whitespace-pre-wrap text-xs">${p(e)}</pre>`;try{return marked.parse(on(e),{breaks:!0,gfm:!0})}catch{return`<pre class="whitespace-pre-wrap text-xs">${p(e)}</pre>`}}async function Us(){let e=r("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>
|
|
457
|
-
<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 no(e,t){let n=r("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">${mr(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 ur,Bt=R(()=>{O();q();ue();Is();an();hs();ur=null});function br(e,t){Ws=e||"",Gs=t||""}async function gr(e){let t=r("project-notes-bar");if(t)try{let n=await y("GET",`/api/projects/notes?root=${encodeURIComponent(e)}`);Ws=n.goal||"",Gs=n.notes||"",Sn(),t.style.display="flex"}catch(n){console.error("Error fetching project notes:",n),t.style.display="none"}}function Sn(){let e=r("project-notes-bar");if(!e)return;let t=Ws||"No goal yet \u2014 click Edit",n=Gs||"";e.innerHTML=`
|
|
458
|
-
<div class="flex items-start gap-2 w-full">
|
|
459
|
-
<div class="flex-1 min-w-0">
|
|
460
|
-
<div class="truncate">
|
|
461
|
-
<span class="font-bold text-base-content/40 uppercase mr-1">Goal:</span>
|
|
462
|
-
<span id="project-goal-text" class="text-base-content/80 cursor-pointer hover:underline" title="Click to edit">${p(t)}</span>
|
|
463
|
-
</div>
|
|
464
|
-
${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>'}
|
|
465
|
-
</div>
|
|
466
|
-
<button id="btn-edit-project-notes" class="btn btn-ghost btn-xs px-1.5 hover:bg-base-300 flex-shrink-0">Edit</button>
|
|
467
|
-
</div>
|
|
468
|
-
`}function xr(){let e=r("project-notes-bar");e&&(e.innerHTML=`
|
|
469
|
-
<div class="flex flex-col gap-1.5 w-full">
|
|
470
|
-
<div class="flex items-center gap-2">
|
|
471
|
-
<span class="text-[10px] font-bold text-base-content/40 uppercase w-12 flex-shrink-0">Goal</span>
|
|
472
|
-
<input id="project-goal-input" type="text" class="input input-xs input-bordered flex-1 text-xs"
|
|
473
|
-
placeholder="One-line project goal\u2026" value="${p(Ws)}">
|
|
474
|
-
</div>
|
|
475
|
-
<div class="flex items-start gap-2">
|
|
476
|
-
<span class="text-[10px] font-bold text-base-content/40 uppercase w-12 flex-shrink-0 mt-1">Notes</span>
|
|
477
|
-
<textarea id="project-notes-input" rows="2" class="textarea textarea-xs textarea-bordered flex-1 text-xs leading-snug"
|
|
478
|
-
placeholder="Longer project notes (stack, links, status\u2026)">${p(Gs)}</textarea>
|
|
479
|
-
</div>
|
|
480
|
-
<div class="flex items-center gap-1 justify-end">
|
|
481
|
-
<button id="btn-save-project-notes" class="btn btn-primary btn-xs px-2">Save</button>
|
|
482
|
-
<button id="btn-cancel-project-notes" class="btn btn-ghost btn-xs px-2">Cancel</button>
|
|
483
|
-
</div>
|
|
484
|
-
</div>
|
|
485
|
-
`,r("project-goal-input")?.focus())}async function Qn(){try{let e=await y("GET","/api/sessions/meta");T.value=e||{}}catch(e){console.warn("session meta load failed",e)}}function He(){let e=r("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=Vt(n,t),a=(s.notes||"").trim(),o=!!s.favorite,i=!!s.hidden,l=(s.title||"").trim()||t.slice(0,8);e.style.display="flex",e.innerHTML=`
|
|
486
|
-
<div class="flex-1 min-w-0 flex items-center gap-2">
|
|
487
|
-
<button type="button" class="session-fav-btn ${o?"is-fav":""}" data-fav-toggle="1"
|
|
488
|
-
data-fav-session-id="${p(t)}" data-fav-session-agent="${p(n)}"
|
|
489
|
-
title="${o?"Unfavorite":"Favorite"}">${o?"\u2605":"\u2606"}</button>
|
|
490
|
-
<span id="session-title-display"
|
|
491
|
-
class="session-title-inline max-w-[40%] truncate font-semibold text-base-content/85"
|
|
492
|
-
title="${p(l)}">${p(l)}</span>
|
|
493
|
-
<button type="button" class="session-rename-btn flex-shrink-0 opacity-70 hover:opacity-100"
|
|
494
|
-
data-rename-bar="1" title="Rename session">\u270E</button>
|
|
495
|
-
<button type="button" class="session-hide-btn flex-shrink-0 ${i?"is-hidden":""}"
|
|
496
|
-
data-hide-toggle="1"
|
|
497
|
-
data-hide-session-id="${p(t)}"
|
|
498
|
-
data-hide-session-agent="${p(n)}"
|
|
499
|
-
title="${i?"Unhide session":"Hide session"}">${i?"\u{1F441}":"\u{1F648}"}</button>
|
|
500
|
-
<span class="font-bold text-base-content/40 uppercase flex-shrink-0">Note:</span>
|
|
501
|
-
<span class="truncate text-base-content/70 ${a?"":"italic text-base-content/40"}"
|
|
502
|
-
id="session-notes-text" title="${p(a||"Add a note for this session")}">${p(a||"No session note")}</span>
|
|
503
|
-
</div>
|
|
504
|
-
<button id="btn-edit-session-notes" class="btn btn-ghost btn-xs px-1.5">Note</button>
|
|
505
|
-
`}function vr(){let e=r("session-notes-bar");if(!e||!f.sessionId)return;let t=f.agent||I.peek()||"claude",n=Vt(t,f.sessionId);e.innerHTML=`
|
|
506
|
-
<input id="session-notes-input" type="text" class="input input-xs input-bordered flex-1 text-xs"
|
|
507
|
-
placeholder="Note for this session\u2026" value="${p(n.notes||"")}">
|
|
508
|
-
<button id="btn-save-session-notes" class="btn btn-primary btn-xs px-2">Save</button>
|
|
509
|
-
<button id="btn-cancel-session-notes" class="btn btn-ghost btn-xs px-2">Cancel</button>
|
|
510
|
-
`;let s=r("session-notes-input");s?.focus(),s?.select()}function zs(){return{favorite:!1,notes:"",title:"",hidden:!1}}function Ks(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 yr(e){return!e?.favorite&&!e?.hidden&&!(e?.notes||"").trim()&&!(e?.title||"").trim()}async function wr(e,t,{machineId:n}={}){let s=n||f.machineId||null,a=oe(t,e,s),o=T.peek()?.[a]||zs(),i=!o.favorite;T.value={...T.peek(),[a]:{...o,favorite:i,updatedAt:Date.now()}};try{let d=await y("PUT","/api/sessions/meta",{sessionId:e,agent:t,favorite:i,machineId:s||void 0},void 0,{machineId:s||void 0});T.value={...T.peek(),[a]:Ks(o,{favorite:d.favorite??i,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&&He()}async function kr(e,t,{machineId:n}={}){if(!e)return!1;let s=n||f.machineId||null,a=oe(t,e,s),o=T.peek()?.[a]||zs(),i=!o.hidden;T.value={...T.peek(),[a]:{...o,hidden:i,updatedAt:Date.now()}};try{let d=await y("PUT","/api/sessions/meta",{sessionId:e,agent:t,hidden:i,machineId:s||void 0},void 0,{machineId:s||void 0}),l=Ks(o,{favorite:d.favorite,notes:d.notes,title:d.title,hidden:d.hidden??i});if(yr(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&&He(),!0}async function so(e,t,n,{machineId:s}={}){let a=s||f.machineId||null,o=oe(t,e,a),i=T.peek()?.[o]||zs();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]:Ks(i,{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 pc(e,t,n,{machineId:s}={}){if(!e)return!1;let a=s||f.machineId||null,o=oe(t,e,a),i=T.peek()?.[o]||zs(),d=String(n||"").trim().slice(0,200);T.value={...T.peek(),[o]:{...i,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=Ks(i,{favorite:l.favorite,notes:l.notes,title:l.title!==void 0?l.title:d,hidden:l.hidden});if(yr(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]:i},alert(`Rename failed: ${l.message}`),!1}return f.sessionId===e&&He(),!0}function ao({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 i=(Vt(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"
|
|
511
|
-
value="${p(i)}"
|
|
512
|
-
placeholder="Session name (empty = original)"
|
|
513
|
-
maxlength="200"
|
|
514
|
-
data-rename-input="1"
|
|
515
|
-
data-rename-session-id="${p(e)}"
|
|
516
|
-
data-rename-session-agent="${p(t)}"
|
|
517
|
-
data-rename-session-machine="${p(n||"")}"
|
|
518
|
-
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:i;if(a.className=l,!x){a.innerHTML=d;return}await pc(e,t,v,{machineId:n}),document.querySelectorAll(".session-rename-input").forEach(C=>C.remove()),f.sessionId===e&&He(),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 Ws,Gs,Yn=R(()=>{O();q();ue();Ws="",Gs=""});var Lr={};is(Lr,{closeMachineMenu:()=>Ut,enterMachine:()=>io,hideMachinePicker:()=>Vs,refreshMachinesList:()=>qt,renderMachineMenuList:()=>Xn,renderMachinePickerList:()=>Js,showMachinePicker:()=>Ft,startMachinePolling:()=>oo,syncTopbarMachine:()=>gt});async function qt(){try{let e=await y("GET","/api/machines");V.value=Array.isArray(e)?e:[]}catch{try{let e=await Yt();e?.machines&&(V.value=e.machines)}catch{}}return V.peek()||[]}function Js(){let e=r("machine-picker-list"),t=r("machine-picker-empty");if(!e)return;let n=V.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`
|
|
519
|
-
<button type="button" class="machine-pick-card w-full text-left px-4 py-3 rounded-xl border border-base-300
|
|
520
|
-
hover:border-primary hover:bg-primary/5 transition-colors ${a?"":"opacity-50"}"
|
|
521
|
-
data-pick-machine="${p(s.id)}" ${a?"":"disabled"}>
|
|
522
|
-
<div class="flex items-center gap-2">
|
|
523
|
-
<span class="w-2 h-2 rounded-full flex-shrink-0 ${a?"bg-success":"bg-error"}"></span>
|
|
524
|
-
<span class="font-semibold text-sm font-mono">${p(s.id)}</span>
|
|
525
|
-
</div>
|
|
526
|
-
${o?`<div class="text-xs text-base-content/45 mt-1 pl-4">${p(o)}</div>`:""}
|
|
527
|
-
</button>`}).join("")}function Ft(){let e=r("machine-picker");if(!e)return;e.classList.remove("hidden"),xe(),qe.value=!1,Js();let t=r("machine-picker-status");if(t){let n=(V.peek()||[]).filter(s=>s.online!==!1).length;t.textContent=`${n} online`}}function Vs(){r("machine-picker")?.classList.add("hidden"),xe(),qe.value=!0}function Ut(){r("machine-menu")?.classList.add("hidden")}function Xn(){let e=r("machine-menu-list"),t=r("machine-menu-empty");if(!e)return;let n=V.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,i=a.id===s,d=[a.hostname,a.platform].filter(Boolean).join(" \xB7 "),l=a.connectedAt?new Date(a.connectedAt).toLocaleTimeString():"";return`
|
|
528
|
-
<button type="button"
|
|
529
|
-
class="machine-menu-item w-full text-left px-2 py-1.5 rounded-md text-xs
|
|
530
|
-
${i?"bg-primary/15 text-primary":"hover:bg-base-200"}
|
|
531
|
-
${o?"":"opacity-50"}"
|
|
532
|
-
data-pick-machine="${p(a.id)}"
|
|
533
|
-
${o?"":"disabled"}>
|
|
534
|
-
<div class="flex items-center gap-1.5">
|
|
535
|
-
<span class="w-1.5 h-1.5 rounded-full flex-shrink-0 ${o?"bg-success":"bg-error"}"></span>
|
|
536
|
-
<span class="font-mono font-semibold truncate flex-1">${p(a.id)}</span>
|
|
537
|
-
${i?'<span class="text-[9px] opacity-70">\u5F53\u524D</span>':""}
|
|
538
|
-
<span class="text-[9px] ${o?"text-success":"text-error"}">${o?"online":"offline"}</span>
|
|
539
|
-
</div>
|
|
540
|
-
${d||l?`<div class="text-[10px] text-base-content/40 pl-3.5 mt-0.5 truncate">${p(d)}${l?" \xB7 "+p(l):""}</div>`:""}
|
|
541
|
-
</button>`}).join("")}function gt(){let e=r("machine-menu-wrap"),t=r("topbar-machine-label"),n=r("topbar-machine-dot");if(!A.peek()){e?.classList.add("hidden");return}e?.classList.remove("hidden");let s=j.peek()||"",o=(V.peek()||[]).find(d=>d.id===s),i=o?o.online!==!1:!1;t&&(t.textContent=s||"\u9009\u62E9\u673A\u5668"),n&&(n.classList.toggle("bg-success",!!s&&i),n.classList.toggle("bg-warning",!!s&&!i),n.classList.toggle("bg-base-content/30",!s)),Xn()}function oo(){$r||($r=setInterval(async()=>{if(!A.peek()||!f.token)return;await qt(),gt();let e=j.peek();if(e){let t=(V.peek()||[]).find(n=>n.id===e);if(t&&t.online===!1){let n=r("topbar-machine-label");n&&(n.textContent=`${e} (offline)`)}}},15e3)),Sr||(Sr=setInterval(()=>{document.visibilityState!=="visible"||!A.peek()||!f.token||!j.peek()||_e({waitFresh:!1,hubIndex:!0}).catch(()=>{})},2e3))}async function io(e,{forceReload:t=!1}={}){if(!e)return;let n=j.peek(),s=n&&n!==e;if(ge(e),Vs(),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:i,filesPath:d}=await Promise.resolve().then(()=>(q(),Ho));o.value="",i.value="",d.value=""}catch{}if(s){let{goHome:o}=await Promise.resolve().then(()=>(es(),Er));o()}}let a=r("topbar-project");a&&!E.peek()&&(a.textContent=`Machine \xB7 ${e}`),Kn(),await Promise.all([_e(),kn(),Qn(),$n().catch(()=>{})]),qe.value=!0}var $r,Sr,Zn=R(()=>{O();q();ue();Bt();Yn();Jn();en();$r=null,Sr=null});var Er={};is(Er,{goHome:()=>Xs,openProject:()=>ro,resumeSession:()=>Re,switchTab:()=>it});function Ys(e){for(let t of["files-machine-hint","git-machine-hint"]){let n=r(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 ro(e){un(),fn(),hn(),mn();let t=e?.path||"";ae(()=>{E.value=e,fe.value=t,t&&(ce.value=t,be.value=t,K.value="",re.value=null)}),f.sessionId=null,r("topbar-project").textContent=t||"Project";let n=r("files-root-input");n&&t&&(n.value=t);let s=r("git-root-input");s&&t&&(s.value=t),Ys(e?.machineId||j.peek()||f.machineId),r("welcome").classList.add("hidden");let a=r("project-view");a.classList.remove("hidden"),a.style.display="flex",bn(),pn({sessionId:null}),st(),it("chat")}function Xs(){un(),fn(),hn(),mn(),E.value=null,fe.value=null,ce.value="",be.value="",K.value="",re.value=null,f.sessionId=null,pn({sessionId:null}),Ys(null),document.documentElement.classList.remove("boot-restore");let e=r("topbar-project");e&&(e.textContent="Select a session");let t=r("welcome");t&&(t.classList.remove("hidden"),t.style.display="",Rt(Ht()));let n=r("project-view");n&&(n.classList.add("hidden"),n.style.display="none"),Oa("/")}async function Re(e,t,n,s,a,o={}){let i=o.tab&&["chat","files","git","shell","memory"].includes(o.tab)?o.tab:"chat",d=o.skipHistory??(i!=="chat"&&i!=="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(un(),fn(),hn(),mn(),x&&x!==f.machineId){ge(x);try{f.ws?.close()}catch{}f.ws=null,Promise.resolve().then(()=>(Zn(),Lr)).then(({syncTopbarMachine:S})=>S()).catch(()=>{}),Promise.resolve().then(()=>(Bt(),hr)).then(({loadAllSessions:S})=>S()).catch(()=>{})}f.sessionId=e,f.configDir=C,f.agent=h,Ue(h),Pe(),pn({sessionId:e,agent:h,machineId:x});let U=v;Tr(U,x,e),st(),U&&y("POST","/api/resolve-path",{path:U},void 0,{machineId:x||void 0}).then(S=>{f.sessionId!==e||!S?.path||S.path===U||(U=S.path,Tr(U,x,e),Sa({sessionId:e,cwd:U}))}).catch(()=>{}),bn(),it(i);{let S=B.peek();B.value=Array.isArray(S)?[...S]:[]}Sa({sessionId:e,cwd:U||v,configDir:C,agent:h,machineId:x,tab:i}),or({sessionId:e,cwd:U||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(r("messages").innerHTML="",!S.length){L(`${ke} \xB7 ${e.slice(0,8)}\u2026 \u2014 no history`);return}Ne();let M=40,Q=0,rt=()=>{if(f.sessionId!==e)return;let xt=Math.min(Q+M,S.length);for(;Q<xt;Q++){let b=S[Q],w=F(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")&&Ne();let G=typeof b.content=="string"?b.content:Array.isArray(b.content)?b.content.map(Y=>Y?.text||"").filter(Boolean).join(`
|
|
542
|
-
`):String(b.content??"");G&&At(b.role==="user"?"user":"assistant",b.role==="user"?"You":ke,G,{ts:w})}else k==="tool_use"||b.name?_a({name:b.name||"tool",input:b.input??b.arguments??{}},{ts:w}):(k==="token_usage"||b.usage)&&(Ne(),dn(b.usage||b))}if(Q<S.length){requestAnimationFrame(rt);return}Ne(),_&&Na(_);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=Qs.get(J);if(S&&S.msgs?.length&&Date.now()-S.at<fc){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),Q=Array.isArray(M)?M:M?.messages||[];!Q.length&&h&&(M=await se(null),Q=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};Q.length?Qs.set(J,{msgs:Q,context:rt,meta:xt,at:Date.now()}):Qs.delete(J),ne(Q,rt,xt)}catch(_){if(f.sessionId!==e)return;Qs.delete(J),r("messages").innerHTML="",L(`${ke} \xB7 ${e.slice(0,8)}\u2026 (history unavailable: ${_.message})`)}};d?N().catch(()=>{}):(await new Promise(S=>requestAnimationFrame(S)),N().catch(()=>{})),Fn(),He()}function Tr(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,K.value="",re.value=null}),r("topbar-project").textContent=t?`${e} @${t}`:e;let a=r("files-root-input");a&&(a.value=e);let o=r("git-root-input");o&&(o.value=e),Ys(t),r("welcome")?.classList.add("hidden");let i=r("project-view");i&&(i.classList.remove("hidden"),i.style.display="flex",i.style.flexDirection="column",i.style.flex="1",i.style.minHeight="0",i.style.overflow="hidden")}else{r("welcome")?.classList.add("hidden");let s=r("project-view");s&&(s.classList.remove("hidden"),s.style.display="flex",s.style.flexDirection="column",s.style.flex="1",s.style.minHeight="0"),Ys(t)}}function it(e){W.value=e}var Qs,fc,es=R(()=>{O();q();ue();ps();gn();Es();Bt();Yn();Xa();Qs=new Map,fc=180*1e3});q();ue();O();q();ue();var Xt=null;function Fo(){return window.matchMedia("(display-mode: standalone)").matches||window.navigator.standalone===!0||document.referrer.includes("android-app://")}function al(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 ol(){if(!("serviceWorker"in navigator)||!window.isSecureContext)return!1;let e=location.hostname;return e==="localhost"||e==="127.0.0.1"||e==="::1"?!0:al(e)?!1:location.protocol==="https:"}function Uo(){document.getElementById("btn-pwa-install")?.classList.remove("hidden")}function Wo(){Fo()&&document.documentElement.classList.add("pwa-standalone"),window.addEventListener("beforeinstallprompt",n=>{n.preventDefault(),Xt=n,document.dispatchEvent(new CustomEvent("pwa-installable")),Uo()}),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(!Fo()&&(e||/Android/i.test(navigator.userAgent))&&requestAnimationFrame(()=>Uo()),!ol()){"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 Go(){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();ps();gn();Es();O();ue();q();Is();function _i(){document.getElementById("root").insertAdjacentHTML("beforeend",`
|
|
543
|
-
<dialog id="modal-settings" class="modal">
|
|
544
|
-
<div class="modal-box max-w-lg">
|
|
545
|
-
<h3 class="font-bold text-base mb-4">Settings</h3>
|
|
546
|
-
<div id="ws-list" class="flex flex-col gap-2 mb-4"></div>
|
|
547
|
-
<div class="border-t border-base-300 pt-4">
|
|
548
|
-
<div class="text-xs uppercase tracking-wider text-base-content/50 mb-2">Add workspace</div>
|
|
549
|
-
<div class="flex gap-2 mb-2">
|
|
550
|
-
<input id="ws-new-name" type="text" placeholder="Name (e.g. personal)" class="input input-sm input-bordered flex-1">
|
|
551
|
-
<input id="ws-new-dir" type="text" placeholder="~/.claude-personal" class="input input-sm input-bordered flex-[2]">
|
|
552
|
-
<button id="ws-add-btn" class="btn btn-primary btn-sm">Add</button>
|
|
553
|
-
</div>
|
|
554
|
-
<div id="ws-error" class="alert alert-error text-xs py-1.5 hidden"></div>
|
|
555
|
-
</div>
|
|
556
|
-
<div id="mcp-token-settings" class="border-t border-base-300 pt-4 mt-4">
|
|
557
|
-
<div class="flex items-center justify-between gap-2 mb-2">
|
|
558
|
-
<div>
|
|
559
|
-
<div class="text-xs uppercase tracking-wider text-base-content/50">MCP access token</div>
|
|
560
|
-
<p class="text-[11px] text-base-content/45 mt-0.5">The token is shown once. Set its expiry before generating.</p>
|
|
561
|
-
</div>
|
|
562
|
-
<select id="mcp-token-expiry" class="select select-xs select-bordered">
|
|
563
|
-
<option value="86400">24 hours</option>
|
|
564
|
-
<option value="604800">7 days</option>
|
|
565
|
-
<option value="2592000">30 days</option>
|
|
566
|
-
</select>
|
|
567
|
-
</div>
|
|
568
|
-
<button id="mcp-token-generate" class="btn btn-sm btn-primary w-full">Generate MCP token</button>
|
|
569
|
-
<div id="mcp-token-result" class="hidden mt-2">
|
|
570
|
-
<textarea id="mcp-token-value" readonly class="textarea textarea-bordered textarea-xs w-full h-20 font-mono"></textarea>
|
|
571
|
-
<button id="mcp-token-copy" class="btn btn-ghost btn-xs mt-1">Copy token</button>
|
|
572
|
-
</div>
|
|
573
|
-
<div id="mcp-token-error" class="alert alert-error text-xs py-1.5 hidden mt-2"></div>
|
|
574
|
-
</div>
|
|
575
|
-
<div class="modal-action">
|
|
576
|
-
<form method="dialog"><button class="btn btn-ghost btn-sm">Close</button></form>
|
|
577
|
-
</div>
|
|
578
|
-
</div>
|
|
579
|
-
<form method="dialog" class="modal-backdrop"><button>close</button></form>
|
|
580
|
-
</dialog>`),Cs(),document.getElementById("ws-add-btn").addEventListener("click",Ba),document.getElementById("ws-new-name").addEventListener("keydown",e=>{e.key==="Enter"&&Ba()}),document.getElementById("ws-new-dir").addEventListener("keydown",e=>{e.key==="Enter"&&Ba()}),document.getElementById("mcp-token-generate").addEventListener("click",Jl),document.getElementById("mcp-token-copy").addEventListener("click",Vl)}function Cs(){let e=r("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=>`
|
|
581
|
-
<div class="flex items-center gap-2 px-3 py-2 bg-base-200 rounded-lg">
|
|
582
|
-
<div class="flex-1 min-w-0">
|
|
583
|
-
<div class="text-sm font-medium">${p(n.name)}</div>
|
|
584
|
-
<div class="text-xs font-mono text-base-content/50 truncate">${p(n.configDir)}</div>
|
|
585
|
-
</div>
|
|
586
|
-
${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>'}
|
|
587
|
-
</div>`).join(""),e.querySelectorAll("[data-ws-delete]").forEach(n=>{n.addEventListener("click",()=>Kl(n.dataset.wsDelete))})}async function Ba(){let e=r("ws-new-name").value.trim(),t=r("ws-new-dir").value.trim(),n=r("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],Un(ee.peek()),r("ws-new-name").value="",r("ws-new-dir").value="",Cs()}catch(s){n.textContent=s.message,n.classList.remove("hidden")}}async function Kl(e){try{await y("DELETE",`/api/workspaces/${e}`),ee.value=ee.peek().filter(t=>t.id!==e),Un(ee.peek()),Cs()}catch(t){alert(t.message)}}function qa(){Cs();let e=r("mcp-token-settings");e&&(e.style.display=A.peek()?"":"none"),r("modal-settings")?.showModal()}async function Jl(){let e=r("mcp-token-result"),t=r("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(r("mcp-token-expiry").value),a=await y("POST",`/api/mcp/tokens?machine=${encodeURIComponent(n)}`,{expiresInSeconds:s});r("mcp-token-value").value=a.token||"",e.classList.remove("hidden")}catch(s){t.textContent=s.message,t.classList.remove("hidden")}}async function Vl(){let e=r("mcp-token-value")?.value;if(e)try{await navigator.clipboard.writeText(e)}catch{r("mcp-token-value")?.select(),document.execCommand("copy")}}Jn();Ta();q();var Yi=()=>`
|
|
588
|
-
<div id="auth-screen" class="${f.token?"hidden":""} flex items-center justify-center h-full p-4" ${f.token?'style="display:none"':""}>
|
|
589
|
-
<div class="card bg-base-200 border border-base-300 w-full max-w-sm shadow-xl">
|
|
590
|
-
<div class="card-body gap-3 p-8">
|
|
591
|
-
<h1 class="text-xl font-bold">\u{1F916} Agent UI</h1>
|
|
592
|
-
<p id="auth-subtitle" class="text-sm text-base-content/60 mb-1">Claude \xB7 Codex \xB7 Grok \xB7 Gemini \xB7 Cursor</p>
|
|
593
|
-
<form id="auth-form" class="flex flex-col gap-3" autocomplete="on" action="#">
|
|
594
|
-
<label class="form-control">
|
|
595
|
-
<div class="label py-1"><span class="label-text text-xs uppercase tracking-wide">Username</span></div>
|
|
596
|
-
<input id="auth-username" type="text" class="input input-bordered input-sm" placeholder="username" autocomplete="username">
|
|
597
|
-
</label>
|
|
598
|
-
<label class="form-control">
|
|
599
|
-
<div class="label py-1"><span class="label-text text-xs uppercase tracking-wide">Password</span></div>
|
|
600
|
-
<input id="auth-password" type="password" class="input input-bordered input-sm" placeholder="\u2022\u2022\u2022\u2022\u2022\u2022" autocomplete="current-password">
|
|
601
|
-
</label>
|
|
602
|
-
<button type="submit" id="auth-btn" class="btn btn-primary btn-sm mt-1" data-mode="login">Sign In</button>
|
|
603
|
-
</form>
|
|
604
|
-
<div id="auth-error" class="alert alert-error text-xs py-2 hidden"></div>
|
|
605
|
-
</div>
|
|
606
|
-
</div>
|
|
607
|
-
</div>`,Xi=(e={})=>{let t=!!e.restoreSession,n=f.token?"":"hidden",s=f.token?"display:flex":"display:none";return`
|
|
608
|
-
<div id="sidebar-overlay" class="hidden fixed inset-0 bg-black/50 z-[9]" aria-hidden="true"></div>
|
|
609
|
-
<div id="app" class="${n} flex-col flex-1 overflow-hidden" style="${s}">
|
|
610
|
-
<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">
|
|
611
|
-
<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>
|
|
612
|
-
<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>
|
|
613
|
-
<span class="text-base-300 hidden sm:inline">/</span>
|
|
614
|
-
<div id="machine-menu-wrap" class="relative hidden flex-shrink-0">
|
|
615
|
-
<button type="button" id="btn-machine-menu" class="btn btn-ghost btn-xs border border-base-300 font-mono gap-1 max-w-[11rem]"
|
|
616
|
-
title="\u673A\u5668\u5217\u8868 / \u5207\u6362">
|
|
617
|
-
<span id="topbar-machine-dot" class="w-1.5 h-1.5 rounded-full bg-success flex-shrink-0"></span>
|
|
618
|
-
<span id="topbar-machine-label" class="truncate">\u673A\u5668</span>
|
|
619
|
-
<span class="text-[10px] opacity-50">\u25BE</span>
|
|
620
|
-
</button>
|
|
621
|
-
<div id="machine-menu" class="hidden absolute left-0 top-full mt-1 z-50 w-72 max-h-80 overflow-y-auto
|
|
622
|
-
rounded-lg border border-base-300 bg-base-100 shadow-xl p-2">
|
|
623
|
-
<div class="flex items-center justify-between px-1 pb-1.5 mb-1 border-b border-base-300">
|
|
624
|
-
<span class="text-[10px] uppercase tracking-wide text-base-content/45 font-semibold">Machines</span>
|
|
625
|
-
<button type="button" id="btn-refresh-machines-menu" class="btn btn-ghost btn-xs px-1 text-[10px]">\u21BB</button>
|
|
626
|
-
</div>
|
|
627
|
-
<div id="machine-menu-list" class="flex flex-col gap-1"></div>
|
|
628
|
-
<p id="machine-menu-empty" class="text-xs text-base-content/40 px-1 py-2 hidden">\u6682\u65E0\u673A\u5668\u5728\u7EBF</p>
|
|
629
|
-
</div>
|
|
630
|
-
</div>
|
|
631
|
-
<div id="recent-menu-wrap" class="relative flex-shrink-0">
|
|
632
|
-
<button type="button" id="btn-recent-sessions" class="btn btn-ghost btn-xs border border-base-300 gap-1 min-h-8 px-2"
|
|
633
|
-
title="\u6700\u8FD1\u4F1A\u8BDD / \u5FEB\u901F\u8DF3\u8F6C" aria-haspopup="listbox" aria-expanded="false">
|
|
634
|
-
<span>\u6700\u8FD1</span>
|
|
635
|
-
<span class="text-[10px] opacity-50">\u25BE</span>
|
|
636
|
-
</button>
|
|
637
|
-
</div>
|
|
638
|
-
<div id="notifications-wrap" class="relative flex-shrink-0">
|
|
639
|
-
<button type="button" id="btn-notifications" class="btn btn-ghost btn-xs border border-base-300 gap-1 min-h-8 px-2"
|
|
640
|
-
title="\u901A\u77E5" aria-haspopup="dialog" aria-expanded="false">
|
|
641
|
-
<span>\u{1F514}</span>
|
|
642
|
-
<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>
|
|
643
|
-
</button>
|
|
644
|
-
</div>
|
|
645
|
-
<span id="topbar-project" class="text-sm text-base-content/50 flex-1 truncate min-w-0">Select a session</span>
|
|
646
|
-
<span id="conn-dot" class="w-2 h-2 rounded-full bg-base-content/30 flex-shrink-0" title="\u8FDE\u63A5\u72B6\u6001"></span>
|
|
647
|
-
<div class="flex gap-2 topbar-actions">
|
|
648
|
-
<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>
|
|
649
|
-
<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>
|
|
650
|
-
<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">
|
|
651
|
-
<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>
|
|
652
|
-
</button>
|
|
653
|
-
<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">
|
|
654
|
-
<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>
|
|
655
|
-
</button>
|
|
656
|
-
<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>
|
|
657
|
-
<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>
|
|
658
|
-
<button id="btn-logout" class="btn btn-ghost btn-xs border border-base-300">Sign out</button>
|
|
659
|
-
</div>
|
|
660
|
-
</div>
|
|
661
|
-
<!-- Fixed panel + backdrop: siblings of topbar so flex layout never clips them -->
|
|
662
|
-
<div id="recent-menu-backdrop" class="hidden fixed inset-0 z-[55] bg-black/40" aria-hidden="true"></div>
|
|
663
|
-
<div id="recent-menu" class="hidden fixed z-[60] w-80 max-h-[min(24rem,70vh)] overflow-y-auto
|
|
664
|
-
rounded-lg border border-base-300 bg-base-100 shadow-xl p-2"
|
|
665
|
-
role="listbox" aria-label="\u6700\u8FD1\u4F1A\u8BDD">
|
|
666
|
-
<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]">
|
|
667
|
-
<span class="text-[10px] uppercase tracking-wide text-base-content/45 font-semibold">\u6700\u8FD1\u4F1A\u8BDD</span>
|
|
668
|
-
<span id="recent-menu-count" class="text-[10px] text-base-content/35 font-mono"></span>
|
|
669
|
-
</div>
|
|
670
|
-
<div id="recent-menu-list" class="flex flex-col gap-0.5"></div>
|
|
671
|
-
<p id="recent-menu-empty" class="text-xs text-base-content/40 px-1 py-2 hidden">\u6682\u65E0\u6700\u8FD1\u4F1A\u8BDD</p>
|
|
672
|
-
</div>
|
|
673
|
-
<div id="notifications-backdrop" class="hidden fixed inset-0 z-[55] bg-black/40" aria-hidden="true"></div>
|
|
674
|
-
<div id="notifications-menu" class="hidden fixed z-[60] w-[min(26rem,calc(100vw-1rem))] max-h-[min(30rem,75vh)] overflow-y-auto
|
|
675
|
-
rounded-lg border border-base-300 bg-base-100 shadow-xl p-2"
|
|
676
|
-
role="dialog" aria-label="\u901A\u77E5\u4E2D\u5FC3">
|
|
677
|
-
<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]">
|
|
678
|
-
<span class="text-[10px] uppercase tracking-wide text-base-content/45 font-semibold">\u901A\u77E5</span>
|
|
679
|
-
<button type="button" id="btn-notifications-read-all" class="btn btn-ghost btn-xs px-1 text-[10px]">\u5168\u90E8\u5DF2\u8BFB</button>
|
|
680
|
-
</div>
|
|
681
|
-
<div id="notifications-menu-list" class="flex flex-col gap-1"></div>
|
|
682
|
-
<p id="notifications-menu-empty" class="text-xs text-base-content/40 px-1 py-2 hidden">\u6682\u65E0\u901A\u77E5</p>
|
|
683
|
-
</div>
|
|
684
|
-
<!-- Hub: only when no remembered machine (or last one offline) -->
|
|
685
|
-
<div id="machine-picker" class="hidden fixed inset-0 z-[60] bg-base-100 flex items-center justify-center p-4">
|
|
686
|
-
<div class="w-full max-w-md">
|
|
687
|
-
<h2 class="text-xl font-bold mb-1">\u9009\u62E9\u673A\u5668</h2>
|
|
688
|
-
<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>
|
|
689
|
-
<div id="machine-picker-list" class="flex flex-col gap-2 mb-4"></div>
|
|
690
|
-
<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>
|
|
691
|
-
<div class="flex items-center gap-2">
|
|
692
|
-
<button id="btn-refresh-machines" class="btn btn-ghost btn-sm border border-base-300">\u21BB \u5237\u65B0</button>
|
|
693
|
-
<span id="machine-picker-status" class="text-xs text-base-content/40"></span>
|
|
694
|
-
</div>
|
|
695
|
-
</div>
|
|
696
|
-
</div>
|
|
697
|
-
<div class="flex flex-1 overflow-hidden relative">
|
|
698
|
-
<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">
|
|
699
|
-
<div class="flex items-center justify-between px-3 py-2 border-b border-base-300 flex-shrink-0">
|
|
700
|
-
<span class="text-xs uppercase tracking-wider text-base-content/50 font-medium">Projects</span>
|
|
701
|
-
<div class="flex items-center gap-1">
|
|
702
|
-
<span id="session-filter-badge" class="hidden text-[10px] text-primary cursor-pointer">\xD7 filter</span>
|
|
703
|
-
<button id="sidebar-refresh" class="btn btn-ghost btn-xs px-1 text-[10px] text-base-content/40" title="Refresh">\u21BB</button>
|
|
704
|
-
</div>
|
|
705
|
-
</div>
|
|
706
|
-
<div id="ws-tabs" class="flex overflow-x-auto border-b border-base-300 flex-shrink-0" style="scrollbar-width:none"></div>
|
|
707
|
-
<div class="px-2 py-1.5 border-b border-base-300 flex-shrink-0 relative">
|
|
708
|
-
<div class="flex gap-1.5">
|
|
709
|
-
<input id="session-search" type="text" placeholder="Search projects & recent work\u2026"
|
|
710
|
-
class="input input-xs input-bordered flex-1 min-w-0 text-xs" autocomplete="off">
|
|
711
|
-
<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>
|
|
712
|
-
</div>
|
|
713
|
-
<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">
|
|
714
|
-
<div class="text-[10px] uppercase tracking-wide text-base-content/45 mb-1.5">Agents \xB7 multi-select</div>
|
|
715
|
-
<div class="grid grid-cols-2 gap-1 text-xs">
|
|
716
|
-
<label><input type="checkbox" data-agent-option="claude"> Claude</label>
|
|
717
|
-
<label><input type="checkbox" data-agent-option="codex"> Codex</label>
|
|
718
|
-
<label><input type="checkbox" data-agent-option="grok"> Grok</label>
|
|
719
|
-
<label><input type="checkbox" data-agent-option="gemini"> Gemini</label>
|
|
720
|
-
<label><input type="checkbox" data-agent-option="cursor"> Cursor</label>
|
|
721
|
-
</div>
|
|
722
|
-
<div class="mt-2 pt-2 border-t border-base-300 flex gap-3 text-xs">
|
|
723
|
-
<label><input id="filter-favorites" type="checkbox"> Favorites</label>
|
|
724
|
-
<label><input id="filter-hidden" type="checkbox"> Hidden</label>
|
|
725
|
-
<button id="filter-clear" type="button" class="ml-auto text-primary">Clear</button>
|
|
726
|
-
</div>
|
|
727
|
-
</div>
|
|
728
|
-
<div id="search-status" class="hidden text-[10px] text-base-content/40 px-0.5"></div>
|
|
729
|
-
</div>
|
|
730
|
-
<div id="session-list" class="overflow-y-auto flex-1"></div>
|
|
731
|
-
<div class="sidebar-mobile-actions hidden border-t border-base-300 px-2 py-2 flex-shrink-0">
|
|
732
|
-
<button type="button" class="btn btn-primary btn-sm flex-1" data-sidebar-action="new">\uFF0B \u65B0\u4F1A\u8BDD</button>
|
|
733
|
-
<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>
|
|
734
|
-
<button type="button" class="btn btn-ghost btn-sm px-2" data-sidebar-action="settings" aria-label="\u8BBE\u7F6E">\u2699\uFE0F</button>
|
|
735
|
-
<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>
|
|
736
|
-
</div>
|
|
737
|
-
</aside>
|
|
738
|
-
<div class="flex flex-col flex-shrink-0 relative" style="width:12px">
|
|
739
|
-
<div id="sidebar-resize" class="absolute inset-0 bg-transparent hover:bg-primary/30 transition-colors cursor-col-resize"></div>
|
|
740
|
-
<button id="sidebar-toggle" title="\u6536\u8D77\u4FA7\u680F" aria-label="\u6536\u8D77\u4FA7\u680F" aria-controls="sidebar" aria-expanded="true"
|
|
741
|
-
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"
|
|
742
|
-
style="left:0;top:50%;transform:translateY(-50%)">\u25C0</button>
|
|
743
|
-
</div>
|
|
744
|
-
<div id="main" class="flex-1 flex flex-col overflow-hidden min-w-0">
|
|
745
|
-
<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"}">
|
|
746
|
-
<div class="max-w-4xl w-full text-center flex flex-col items-center gap-2 mt-2 md:mt-4">
|
|
747
|
-
<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>
|
|
748
|
-
<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>
|
|
749
|
-
<div class="flex gap-2 mt-0.5">
|
|
750
|
-
<button id="btn-new-session-welcome" class="btn btn-primary btn-sm shadow-md">\uFF0B New Session</button>
|
|
751
|
-
<button id="btn-meta-agent-welcome" class="btn btn-outline btn-primary btn-sm">\u2726 Meta Agent</button>
|
|
752
|
-
</div>
|
|
753
|
-
</div>
|
|
754
|
-
|
|
755
|
-
<!-- Stats Banner -->
|
|
756
|
-
<div class="max-w-4xl w-full grid grid-cols-2 md:grid-cols-4 gap-4 text-center select-none mt-1">
|
|
757
|
-
<div class="bg-base-200 border border-base-300 rounded-2xl p-3 shadow-md flex flex-col justify-center items-center">
|
|
758
|
-
<span class="text-[10px] uppercase tracking-wider text-base-content/40 font-bold">Total Sessions</span>
|
|
759
|
-
<span id="stats-total-sessions" class="text-xl md:text-2xl font-extrabold text-primary mt-0.5">0</span>
|
|
760
|
-
</div>
|
|
761
|
-
<div class="bg-base-200 border border-base-300 rounded-2xl p-3 shadow-md flex flex-col justify-center items-center">
|
|
762
|
-
<span class="text-[10px] uppercase tracking-wider text-base-content/40 font-bold">Active Projects</span>
|
|
763
|
-
<span id="stats-total-projects" class="text-xl md:text-2xl font-extrabold text-accent mt-0.5">0</span>
|
|
764
|
-
</div>
|
|
765
|
-
<div class="bg-base-200 border border-base-300 rounded-2xl p-3 shadow-md flex flex-col justify-center items-center">
|
|
766
|
-
<span class="text-[10px] uppercase tracking-wider text-base-content/40 font-bold">Total Tokens</span>
|
|
767
|
-
<span id="stats-total-tokens" class="text-xl md:text-2xl font-extrabold text-secondary mt-0.5">0</span>
|
|
768
|
-
</div>
|
|
769
|
-
<div class="bg-base-200 border border-base-300 rounded-2xl p-3 shadow-md flex flex-col justify-center items-center">
|
|
770
|
-
<span class="text-[10px] uppercase tracking-wider text-base-content/40 font-bold">Selected Day Tokens</span>
|
|
771
|
-
<span id="stats-selected-tokens" class="text-xl md:text-2xl font-extrabold text-success mt-0.5">0</span>
|
|
772
|
-
</div>
|
|
773
|
-
</div>
|
|
774
|
-
<div class="max-w-4xl w-full grid grid-cols-1 md:grid-cols-12 gap-5 items-start text-left">
|
|
775
|
-
<!-- Calendar Card -->
|
|
776
|
-
<div class="card bg-base-200 border border-base-300 md:col-span-7 shadow-xl">
|
|
777
|
-
<div class="card-body p-4">
|
|
778
|
-
<div class="flex items-center justify-between mb-3">
|
|
779
|
-
<button id="btn-cal-prev" class="btn btn-ghost btn-sm text-base font-bold">\u25C0</button>
|
|
780
|
-
<h3 id="calendar-month-year" class="text-base font-extrabold text-base-content select-none"></h3>
|
|
781
|
-
<button id="btn-cal-next" class="btn btn-ghost btn-sm text-base font-bold">\u25B6</button>
|
|
782
|
-
</div>
|
|
783
|
-
|
|
784
|
-
<div class="grid grid-cols-7 gap-2 text-center text-[10px] font-bold text-base-content/40 mb-1">
|
|
785
|
-
<div>Sun</div><div>Mon</div><div>Tue</div><div>Wed</div><div>Thu</div><div>Fri</div><div>Sat</div>
|
|
786
|
-
</div>
|
|
787
|
-
|
|
788
|
-
<div id="calendar-grid" class="grid grid-cols-7 gap-2">
|
|
789
|
-
<!-- JS Rendered -->
|
|
790
|
-
</div>
|
|
791
|
-
</div>
|
|
792
|
-
</div>
|
|
793
|
-
|
|
794
|
-
<!-- Details Card -->
|
|
795
|
-
<div class="card bg-base-200 border border-base-300 md:col-span-5 shadow-xl min-h-[290px] flex flex-col">
|
|
796
|
-
<div class="card-body p-4 flex flex-col flex-1">
|
|
797
|
-
<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>
|
|
798
|
-
<div id="selected-day-sessions" class="flex-1 overflow-y-auto flex flex-col gap-2 max-h-[250px]">
|
|
799
|
-
<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>
|
|
800
|
-
</div>
|
|
801
|
-
</div>
|
|
802
|
-
</div>
|
|
803
|
-
</div>
|
|
804
|
-
|
|
805
|
-
<!-- Recent Sessions Section -->
|
|
806
|
-
<div class="max-w-4xl w-full border-t border-base-300/60 pt-4 mt-1 text-left">
|
|
807
|
-
<h3 class="text-xs font-bold uppercase tracking-wider text-base-content/50 mb-3 select-none">Recent Workspaces & Sessions</h3>
|
|
808
|
-
<div id="recent-sessions-list" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3">
|
|
809
|
-
<!-- JS Rendered -->
|
|
810
|
-
</div>
|
|
811
|
-
</div>
|
|
812
|
-
</div>
|
|
813
|
-
<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":""}">
|
|
814
|
-
<div class="flex bg-base-200 border-b border-base-300 flex-shrink-0 overflow-x-auto" style="scrollbar-width:none">
|
|
815
|
-
<button class="px-4 py-2.5 text-sm border-b-2 flex-shrink-0 text-primary border-primary" data-tab="chat">Chat</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="files">Files</button>
|
|
817
|
-
<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>
|
|
818
|
-
<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>
|
|
819
|
-
<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>
|
|
820
|
-
</div>
|
|
821
|
-
<div id="tab-chat" class="flex flex-col flex-1 overflow-hidden relative">
|
|
822
|
-
<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>
|
|
823
|
-
<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>
|
|
824
|
-
<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">
|
|
825
|
-
<span id="ws-banner-text"></span>
|
|
826
|
-
<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>
|
|
827
|
-
</div>
|
|
828
|
-
<div id="messages" class="flex-1 overflow-y-auto p-3 flex flex-col gap-2"></div>
|
|
829
|
-
<div id="scroll-nav" class="absolute right-3 bottom-24 flex flex-col gap-1.5 z-10">
|
|
830
|
-
<button id="scroll-top-btn" class="scroll-fab hidden" title="Jump to top">\u2191</button>
|
|
831
|
-
<button id="scroll-bottom-btn" class="scroll-fab hidden" title="Jump to bottom">\u2193</button>
|
|
832
|
-
</div>
|
|
833
|
-
<div id="permission-requests"></div>
|
|
834
|
-
<form id="chat-form" autocomplete="off" action="#" class="flex flex-col flex-shrink-0">
|
|
835
|
-
<div id="chat-composer" class="flex flex-col border-t border-base-300 bg-base-200 flex-shrink-0">
|
|
836
|
-
<div id="chat-attach-bar" class="hidden flex flex-wrap gap-1.5 px-3 pt-2"></div>
|
|
837
|
-
<div id="chat-opts" class="hidden flex items-center gap-1.5 px-3 pt-2 flex-wrap" inert>
|
|
838
|
-
<select id="sel-agent" class="select select-xs select-bordered text-xs font-semibold" title="Agent">
|
|
839
|
-
<option value="claude">Claude</option>
|
|
840
|
-
<option value="codex">Codex</option>
|
|
841
|
-
<option value="grok">Grok</option>
|
|
842
|
-
<option value="gemini">Gemini</option>
|
|
843
|
-
<option value="cursor">Cursor</option>
|
|
844
|
-
</select>
|
|
845
|
-
<select id="sel-convert-agent" class="select select-xs select-bordered text-xs font-semibold" title="Convert session to another agent">
|
|
846
|
-
<option value="" disabled selected>Convert to...</option>
|
|
847
|
-
<option value="claude">Convert to Claude</option>
|
|
848
|
-
<option value="codex">Convert to Codex</option>
|
|
849
|
-
<option value="grok">Convert to Grok</option>
|
|
850
|
-
</select>
|
|
851
|
-
<div class="flex items-center gap-0.5">
|
|
852
|
-
<select id="sel-model" class="select select-xs select-bordered font-mono text-xs max-w-[11rem]" title="Model">
|
|
853
|
-
<option value="claude-sonnet-4-5">sonnet-4-5</option>
|
|
854
|
-
<option value="claude-sonnet-4-6">sonnet-4-6</option>
|
|
855
|
-
<option value="claude-opus-4-5">opus-4-5</option>
|
|
856
|
-
<option value="claude-haiku-4-5">haiku-4-5</option>
|
|
857
|
-
</select>
|
|
858
|
-
<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>
|
|
859
|
-
<button type="button" id="btn-model-edit" class="btn btn-ghost btn-xs px-1.5" title="Edit current model id">\u270E</button>
|
|
860
|
-
</div>
|
|
861
|
-
<select id="sel-effort" class="select select-xs select-bordered text-xs" title="Effort">
|
|
862
|
-
<option value="">effort: off</option>
|
|
863
|
-
<option value="low">low</option>
|
|
864
|
-
<option value="medium">medium</option>
|
|
865
|
-
<option value="high">high</option>
|
|
866
|
-
<option value="xhigh">xhigh</option>
|
|
867
|
-
<option value="max">max</option>
|
|
868
|
-
</select>
|
|
869
|
-
<select id="sel-permission" class="select select-xs select-bordered text-xs" title="Permissions">
|
|
870
|
-
<option value="default">perms: default</option>
|
|
871
|
-
<option value="acceptEdits">acceptEdits</option>
|
|
872
|
-
<option value="auto">auto</option>
|
|
873
|
-
<option value="plan">plan</option>
|
|
874
|
-
<option value="bypassPermissions" selected>\u26A0 bypass all</option>
|
|
875
|
-
</select>
|
|
876
|
-
<select id="sel-density" class="select select-xs select-bordered text-xs" title="Chat density \u2014 how tools are shown">
|
|
877
|
-
<option value="clean">density: clean</option>
|
|
878
|
-
<option value="normal">density: normal</option>
|
|
879
|
-
<option value="full">density: full</option>
|
|
880
|
-
</select>
|
|
881
|
-
</div>
|
|
882
|
-
<div id="composer-row" class="px-3 pt-2 pb-2">
|
|
883
|
-
<div class="composer-surface">
|
|
884
|
-
<textarea id="chat-input" rows="1" placeholder="\u95EE\u70B9\u4EC0\u4E48\u2026"
|
|
885
|
-
class="chat-input w-full text-sm resize-none leading-relaxed"
|
|
886
|
-
name="q"
|
|
887
|
-
enterkeyhint="send"
|
|
888
|
-
inputmode="text"
|
|
889
|
-
autocomplete="off"
|
|
890
|
-
autocorrect="off"
|
|
891
|
-
autocapitalize="sentences"
|
|
892
|
-
spellcheck="false"
|
|
893
|
-
data-1p-ignore="true"
|
|
894
|
-
data-lpignore="true"
|
|
895
|
-
data-form-type="other"
|
|
896
|
-
data-bwignore="true"></textarea>
|
|
897
|
-
<div class="composer-actions">
|
|
898
|
-
<div class="composer-tools">
|
|
899
|
-
<button type="button" id="btn-opts" class="composer-icon-btn" title="Options" aria-label="Options">\u2699</button>
|
|
900
|
-
<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>
|
|
901
|
-
<input type="file" id="chat-file-input" class="hidden" multiple accept="image/*,*/*" tabindex="-1">
|
|
902
|
-
</div>
|
|
903
|
-
<div class="composer-submit">
|
|
904
|
-
<span class="composer-hint">Enter \u53D1\u9001</span>
|
|
905
|
-
<button type="submit" id="send-btn" class="composer-send-btn">Send</button>
|
|
906
|
-
<button type="button" id="stop-btn" class="composer-stop-btn hidden" aria-label="\u505C\u6B62\u751F\u6210">\u25A0</button>
|
|
907
|
-
</div>
|
|
908
|
-
</div>
|
|
909
|
-
</div>
|
|
910
|
-
</div>
|
|
911
|
-
</div>
|
|
912
|
-
</form>
|
|
913
|
-
</div>
|
|
914
|
-
<div id="tab-files" class="hidden flex-col flex-1 overflow-hidden">
|
|
915
|
-
<div class="flex items-center gap-2 px-3 py-1.5 border-b border-base-300 flex-shrink-0 bg-base-200">
|
|
916
|
-
<span class="text-xs text-base-content/40 flex-shrink-0">Root</span>
|
|
917
|
-
<span id="files-machine-hint" class="hidden text-[10px] font-mono font-semibold text-primary flex-shrink-0"></span>
|
|
918
|
-
<input id="files-root-input" type="text" placeholder="Absolute path on the target machine"
|
|
919
|
-
class="input input-xs flex-1 font-mono text-xs bg-transparent border-0 focus:outline-none px-1" autocomplete="off">
|
|
920
|
-
<button id="files-root-btn" class="btn btn-ghost btn-xs text-xs">Go</button>
|
|
921
|
-
</div>
|
|
922
|
-
<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>
|
|
923
|
-
<div id="files-area" class="flex-1 overflow-y-auto"></div>
|
|
924
|
-
</div>
|
|
925
|
-
<div id="tab-shell" class="hidden flex-col flex-1 overflow-hidden bg-[#0d1117]">
|
|
926
|
-
<div class="flex items-center gap-2 px-3 py-1.5 border-b border-base-300 bg-base-200 flex-shrink-0">
|
|
927
|
-
<span class="text-xs text-base-content/40 font-mono flex-1" id="term-cwd"></span>
|
|
928
|
-
<button id="term-keyboard" class="btn btn-ghost btn-xs text-xs text-base-content/60" type="button">Keyboard</button>
|
|
929
|
-
<button id="term-reconnect" class="btn btn-ghost btn-xs text-xs text-base-content/40">Reconnect</button>
|
|
930
|
-
</div>
|
|
931
|
-
<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">
|
|
932
|
-
<button class="term-key" type="button" data-term-key="ctrl-c">Ctrl+C</button>
|
|
933
|
-
<button class="term-key" type="button" data-term-key="escape">Esc</button>
|
|
934
|
-
<button class="term-key" type="button" data-term-key="tab">Tab</button>
|
|
935
|
-
<button class="term-key" type="button" data-term-key="up">\u2191</button>
|
|
936
|
-
<button class="term-key" type="button" data-term-key="down">\u2193</button>
|
|
937
|
-
<button class="term-key" type="button" data-term-key="left">\u2190</button>
|
|
938
|
-
<button class="term-key" type="button" data-term-key="right">\u2192</button>
|
|
939
|
-
</div>
|
|
940
|
-
<div id="terminal-container" class="flex-1 p-2 overflow-hidden"></div>
|
|
941
|
-
<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">
|
|
942
|
-
<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">
|
|
943
|
-
<button class="term-mobile-send" type="submit">\u53D1\u9001</button>
|
|
944
|
-
</form>
|
|
945
|
-
</div>
|
|
946
|
-
<div id="tab-git" class="hidden flex-col flex-1 overflow-hidden">
|
|
947
|
-
<div class="flex items-center gap-2 px-3 py-1.5 border-b border-base-300 flex-shrink-0 bg-base-200">
|
|
948
|
-
<span class="text-xs text-base-content/40 flex-shrink-0">Root</span>
|
|
949
|
-
<span id="git-machine-hint" class="hidden text-[10px] font-mono font-semibold text-primary flex-shrink-0"></span>
|
|
950
|
-
<input id="git-root-input" type="text" placeholder="Absolute path on the target machine"
|
|
951
|
-
class="input input-xs flex-1 font-mono text-xs bg-transparent border-0 focus:outline-none px-1" autocomplete="off">
|
|
952
|
-
<button id="git-root-btn" class="btn btn-ghost btn-xs text-xs">Go</button>
|
|
953
|
-
</div>
|
|
954
|
-
<div id="git-area" class="flex-1 overflow-y-auto"></div>
|
|
955
|
-
</div>
|
|
956
|
-
<div id="tab-memory" class="hidden flex-col flex-1 overflow-hidden">
|
|
957
|
-
<div class="flex items-center gap-2 px-3 py-1.5 border-b border-base-300 flex-shrink-0 bg-base-200">
|
|
958
|
-
<span class="text-xs text-base-content/40 flex-shrink-0">\u{1F9E0} Agent memory</span>
|
|
959
|
-
<span class="flex-1"></span>
|
|
960
|
-
<button id="memory-refresh" class="btn btn-ghost btn-xs text-xs">Refresh</button>
|
|
961
|
-
</div>
|
|
962
|
-
<div id="memory-area" class="flex-1 overflow-y-auto text-sm"></div>
|
|
963
|
-
</div>
|
|
964
|
-
</div>
|
|
965
|
-
</div>
|
|
966
|
-
</div>
|
|
967
|
-
</div>
|
|
968
|
-
<dialog id="modal-new-session" class="modal">
|
|
969
|
-
<div class="modal-box max-w-sm">
|
|
970
|
-
<h3 class="font-bold text-base mb-4">\uFF0B New Session</h3>
|
|
971
|
-
<div class="flex flex-col gap-3">
|
|
972
|
-
<label class="form-control">
|
|
973
|
-
<div class="label py-1"><span class="label-text text-xs uppercase tracking-wide">Agent</span></div>
|
|
974
|
-
<select id="new-session-agent" class="select select-bordered select-sm">
|
|
975
|
-
<option value="claude">Claude Code</option>
|
|
976
|
-
<option value="codex">OpenAI Codex</option>
|
|
977
|
-
<option value="grok">Grok</option>
|
|
978
|
-
<option value="gemini">Google Gemini (agy)</option>
|
|
979
|
-
<option value="cursor">Cursor Agent</option>
|
|
980
|
-
</select>
|
|
981
|
-
</label>
|
|
982
|
-
<label class="form-control" id="new-session-machine-wrap" style="display:none">
|
|
983
|
-
<div class="label py-1"><span class="label-text text-xs uppercase tracking-wide">Machine (edge server)</span></div>
|
|
984
|
-
<select id="new-session-machine" class="select select-bordered select-sm"></select>
|
|
985
|
-
</label>
|
|
986
|
-
<label class="form-control">
|
|
987
|
-
<div class="label py-1"><span class="label-text text-xs uppercase tracking-wide">Working Directory</span></div>
|
|
988
|
-
<input id="new-session-path" type="text" class="input input-bordered input-sm font-mono"
|
|
989
|
-
placeholder="~/projects/my-app" autocomplete="off">
|
|
990
|
-
</label>
|
|
991
|
-
<label class="form-control" id="new-session-ws-wrap">
|
|
992
|
-
<div class="label py-1"><span class="label-text text-xs uppercase tracking-wide">Claude Workspace</span></div>
|
|
993
|
-
<select id="new-session-workspace" class="select select-bordered select-sm"></select>
|
|
994
|
-
</label>
|
|
995
|
-
<div id="new-session-error" class="alert alert-error text-xs py-2 hidden"></div>
|
|
996
|
-
</div>
|
|
997
|
-
<div class="modal-action">
|
|
998
|
-
<button id="new-session-cancel" class="btn btn-ghost btn-sm">Cancel</button>
|
|
999
|
-
<button id="new-session-start" class="btn btn-primary btn-sm">Start</button>
|
|
1000
|
-
</div>
|
|
1001
|
-
</div>
|
|
1002
|
-
<form method="dialog" class="modal-backdrop"><button>close</button></form>
|
|
1003
|
-
</dialog>`};Xa();Bt();es();O();q();ue();Is();ps();Bt();Yn();Jn();es();Zn();en();async function Zs(e={}){r("auth-screen").style.display="none";let t=r("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&&(V.value=n.machines)):A.value=!1;let s=e.deepLink||null,a=Et();if(!!(s?.id||(location.hash||"").startsWith("#/session/"))){let d=r("welcome");d&&(d.classList.add("hidden"),d.style.display="none");let l=r("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),Vs(),qe.value=!0,Kn());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));oo(),gt();let c=Promise.all([_e({waitFresh:!1}),kn({waitFresh:!1}),Qn().catch(()=>{}),$n().catch(()=>{})]);if(s?.id){let h=B.peek().find(x=>x.sessionId===s.id)||(a?.sessionId===s.id?a:null);await Re(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,!(V.peek()||[]).length){Ft(),c.catch(()=>{});return}Ft(),c.catch(()=>{});return}await c;let u=r("topbar-project");u&&u.textContent==="Select a session"&&(u.textContent=`Machine \xB7 ${d}`);return}Kn();let i=Promise.all([_e({waitFresh:!1}),kn({waitFresh:!1}),Qn().catch(()=>{}),$n().catch(()=>{})]);if(s?.id){await Ms().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 Re(s.id,d?.cwd||null,d?.configDir||null,s.agent||d?.agent||null,null,{tab:s.tab||"chat"}),i.catch(()=>{});return}await i}Yn();Zn();O();q();ue();gn();Bt();es();Zn();en();function Mr(){let e=r("sidebar");e&&(e.classList.add("open"),r("sidebar-overlay").classList.remove("hidden"),r("hamburger")?.setAttribute("aria-expanded","true"),xe(),setTimeout(()=>r("session-search")?.focus({preventScroll:!0}),180))}function ts(){let e=r("sidebar");e&&(e.classList.remove("open"),r("sidebar-overlay").classList.add("hidden"),r("hamburger")?.setAttribute("aria-expanded","false"),xe(),r("hamburger")?.focus({preventScroll:!0}))}function Ir(){window.innerWidth<=640&&ts()}function Cr(){let e=r("sidebar-toggle"),t=r("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 Ar(){let e=r("sidebar-resize"),t=r("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 lo(e){document.documentElement.setAttribute("data-theme",e),localStorage.setItem("theme",e);let t=r("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 co(){let e=document.documentElement.getAttribute("data-theme")||"dark";lo(e==="dark"?"light":"dark")}function uo(){let e=r("new-session-agent");e&&(e.value=I.peek()||"claude");let t=r("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=r("new-session-machine-wrap"),s=r("new-session-machine");if(n&&s)if(A.peek()){n.style.display="";let a=V.peek()||[],o=j.peek()||"";s.innerHTML=a.length?a.map(i=>`<option value="${p(i.id)}">${p(i.id)}${i.hostname?" \u2014 "+p(i.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);po(),r("new-session-path").value=E.peek()?.path||"",r("new-session-error").classList.add("hidden"),r("modal-new-session").showModal(),setTimeout(()=>r("new-session-path").focus(),50)}function po(){let e=r("new-session-agent")?.value||"claude",t=r("new-session-ws-wrap");t&&(t.style.display=e==="claude"?"":"none")}async function fo(){let e=r("new-session-path").value.trim(),t=r("new-session-agent")?.value||"claude",n=t==="claude"?r("new-session-workspace").value:null,s=r("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()||r("new-session-machine")?.value||V.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");r("modal-new-session").close();let o=a.path.split("/").filter(Boolean).pop()||a.path;un(),fn(),hn(),mn(),f.sessionId=null,f.configDir=n||null,f.agent=t,Ue(t),le(Fe(t)||P.peek()),Pe(),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,K.value="",re.value=null}),r("topbar-project").textContent=a.path;let i=r("files-root-input");i&&(i.value=a.path);let d=r("git-root-input");d&&(d.value=a.path),r("welcome").classList.add("hidden");let l=r("project-view");l.classList.remove("hidden"),l.style.display="flex",bn(),pn({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 mc(){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">
|
|
1004
|
-
<li>\u70B9\u5E95\u90E8\u5206\u4EAB\u6309\u94AE <strong>\u5206\u4EAB</strong>\uFF08\u65B9\u6846+\u5411\u4E0A\u7BAD\u5934\uFF09</li>
|
|
1005
|
-
<li>\u4E0B\u6ED1\u627E\u5230\u5E76\u70B9 <strong>\u6DFB\u52A0\u5230\u4E3B\u5C4F\u5E55</strong></li>
|
|
1006
|
-
<li>\u786E\u8BA4\u540D\u79F0\u540E\u70B9 <strong>\u6DFB\u52A0</strong></li>
|
|
1007
|
-
</ol>
|
|
1008
|
-
<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>
|
|
1009
|
-
<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">
|
|
1010
|
-
<li>\u70B9\u53F3\u4E0A\u89D2\u83DC\u5355 <strong>\u22EE</strong></li>
|
|
1011
|
-
<li>\u9009\u62E9 <strong>\u5B89\u88C5\u5E94\u7528</strong> \u6216 <strong>\u6DFB\u52A0\u5230\u4E3B\u5C4F\u5E55</strong></li>
|
|
1012
|
-
</ol>
|
|
1013
|
-
<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>
|
|
1014
|
-
<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=`
|
|
1015
|
-
<div class="modal-box max-w-sm">
|
|
1016
|
-
<h3 class="font-bold text-base mb-3">\u5B89\u88C5\u5230\u4E3B\u5C4F\u5E55</h3>
|
|
1017
|
-
${n}
|
|
1018
|
-
<div class="modal-action">
|
|
1019
|
-
<form method="dialog"><button class="btn btn-sm">\u77E5\u9053\u4E86</button></form>
|
|
1020
|
-
</div>
|
|
1021
|
-
</div>
|
|
1022
|
-
<form method="dialog" class="modal-backdrop"><button>close</button></form>`,s.showModal()}async function ho(){let e=r("auth-screen");e&&(e.classList.remove("hidden"),e.style.display="flex");let t=r("app");t&&(t.classList.add("hidden"),t.style.display="none");let n=r("auth-btn"),s,a=new AbortController,o=setTimeout(()=>a.abort(),8e3);try{s=await y("GET","/api/auth/status",void 0,a.signal)}catch(i){console.warn("[auth status]",i);let d=r("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?(r("auth-subtitle").textContent="Create your account to get started",n.textContent="Create Account",n.dataset.mode="register"):n.dataset.mode="login"}async function mo(){let e=r("auth-username").value.trim(),t=r("auth-password").value,n=r("auth-error");n.classList.add("hidden");try{let s=await y("POST",`/api/auth/${r("auth-btn").dataset.mode||"login"}`,{username:e,password:t});f.token=s.token,localStorage.setItem("token",s.token),Zs()}catch(s){n.textContent=s.message,n.classList.remove("hidden")}}function bo(){return f.token?/^#\/session\//.test(location.hash||""):!1}function jr(e={}){if(lo(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??bo(),n=document.getElementById("root");if(n.style.cssText="display:flex;flex-direction:column;flex:1;height:100%",n.innerHTML=Yi()+Xi({restoreSession:t}),t){let l=r("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=r("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
|
|
1023
|
-
${(h.id===null?!u:u===h.configDir)?"border-primary text-primary":"border-transparent text-base-content/50 hover:text-base-content"}"
|
|
1024
|
-
data-ws-tab="${p(h.configDir||"")}">
|
|
1025
|
-
${p(h.name)}
|
|
1026
|
-
</button>`).join("")}),Ce(()=>{ct.value,St.value,Je.value,Ve.value,Be.value,T.value;let l=r("session-list");l&&(l.querySelector(".session-rename-input")||(l.innerHTML=eo(),to()))}),Ce(()=>{B.value,de.value,j.value,A.value;let l=r("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=r("session-filter-badge");c&&(c.style.display=l?"inline":"none",c.title=l||"")}),Ce(()=>{let l=E.value;if(l&&l.path)gr(l.path);else{let c=r("project-notes-bar");c&&(c.style.display="none")}}),Le(W,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=r("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=r(`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"&&Us(),l==="shell"&&requestAnimationFrame(()=>{document.dispatchEvent(new CustomEvent("shell-tab-shown"))}),xe()}),Ar(),Cr(),ai({openSession:Re});let s=null;document.addEventListener("sessions-changed",()=>{s&&clearTimeout(s),s=setTimeout(()=>{s=null,_e({waitFresh:!1})},1200)}),document.addEventListener("router:home",Xs),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 Re(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",Xs),g.on("click","#btn-share-session",async(l,c)=>{let u=ji();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",mo),g.on("submit","#auth-form",l=>{l.preventDefault(),mo()}),g.on("keydown","#auth-username, #auth-password",l=>{l.key==="Enter"&&mo()}),g.on("click","#hamburger",()=>r("sidebar").classList.contains("open")?ts():Mr()),g.on("click","#sidebar-overlay",ts),document.addEventListener("keydown",l=>{l.key==="Escape"&&window.innerWidth<=640&&r("sidebar")?.classList.contains("open")&&(l.preventDefault(),ts())}),g.on("input","#session-search",(l,c)=>{me.value=c.value,Fs(c.value)}),g.on("click","#sidebar-filter-toggle",()=>{let l=r("sidebar-filter-menu");if(!l)return;let c=l.classList.toggle("hidden");r("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}),r("filter-favorites")&&(r("filter-favorites").checked=!1),r("filter-hidden")&&(r("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",()=>{_e(),me.peek().trim()&&qs(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()&&Fs(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;ro({id:h,name:h,path:u}),L(`Project \xB7 ${u}`)}),g.on("click","#btn-pwa-install",async()=>{await Go()||mc()}),document.addEventListener("pwa-installable",()=>{document.getElementById("btn-pwa-install")?.classList.remove("hidden")}),g.on("click","#btn-settings",qa),g.on("click","#btn-meta-agent",()=>Wi()),g.on("click","#btn-meta-agent-welcome",()=>Wa("chat")),g.on("click","#btn-theme",co),g.on("click","[data-sidebar-action]",(l,c)=>{let u=c.dataset.sidebarAction;u==="new"&&uo(),u==="theme"&&co(),u==="settings"&&qa(),u==="logout"&&(f.token=null,localStorage.removeItem("token"),ge(null),qe.value=!1,location.reload())}),g.on("click","#btn-cal-prev",()=>{Ya(-1),Rt(Ht())}),g.on("click","#btn-cal-next",()=>{Ya(1),Rt(Ht())}),g.on("click","[data-cal-date]",(l,c)=>{cr(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")||(Re(c.dataset.sessionId,c.dataset.sessionCwd||null,c.dataset.sessionConfigDir||null,c.dataset.sessionAgent||"claude",c.dataset.sessionMachine||null),Ir())}),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&&ao({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;ao({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(Kt.peek()),C=new Set(Jt.peek());x?(v.delete(u),C.add(u)):(v.add(u),C.delete(u)),ae(()=>{Kt.value=v,Jt.value=C})}),g.on("click","#memory-refresh",Us),g.on("click","[data-memory-file]",l=>no(l.dataset.memoryFile,l.dataset.memoryAgent)),g.on("click","[data-tab]",(l,c)=>it(c.dataset.tab));let a=async(l,c)=>{let u=r(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",()=>{r("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,Ue(h),le(Fe(h)||P.peek()),r("sel-permission").value=Ee.peek(),Pe(),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 _e(),await Re(v.targetSessionId,E.peek()?.path||null,null,v.targetAgent),Fn()):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),Os()}),g.on("click","#btn-model-add",()=>Bs({editCurrent:!1})),g.on("click","#btn-model-edit",()=>Bs({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)=>{ya(c.value),L(`Density \u2192 ${c.value} (applies to new tool calls; reload session to re-group history)`)}),document.addEventListener("agent-changed",Pe),g.on("click","#btn-new-session, #btn-new-session-welcome",uo),g.on("click","#new-session-cancel",()=>r("modal-new-session").close()),g.on("click","#new-session-start",fo),g.on("change","#new-session-agent",po),g.on("keydown","#new-session-path",l=>{l.key==="Enter"&&fo()}),g.on("click","#send-btn",qn),g.on("click","#stop-btn",ki),g.on("click","#btn-logout",()=>{f.token=null,localStorage.removeItem("token"),ge(null),qe.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 io(u,{forceReload:!0}),fs()});let o=async()=>{let l=r("machine-picker-status");if(l&&(l.textContent="\u5237\u65B0\u4E2D\u2026"),await qt(),Js(),Xn(),gt(),l){let c=(V.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(),Ot(),It();let c=r("machine-menu");c&&(c.classList.contains("hidden")?(await qt(),Xn(),c.classList.remove("hidden")):c.classList.add("hidden"))}),g.on("click","#btn-recent-sessions",l=>{l.preventDefault(),l.stopPropagation(),Ut(),It(),lr();let c=!r("recent-menu")?.classList.contains("hidden"),u=r("btn-recent-sessions");u&&u.setAttribute("aria-expanded",c?"true":"false")}),g.on("click","#recent-menu-backdrop",l=>{l.preventDefault(),l.stopPropagation(),Ot(),r("btn-recent-sessions")?.setAttribute("aria-expanded","false")}),document.addEventListener("click",l=>{let c=r("machine-menu-wrap");c&&!c.contains(l.target)&&Ut();let u=r("recent-menu"),h=r("btn-recent-sessions"),x=l.target;if(u&&!u.classList.contains("hidden")){if(u.contains(x)||h?.contains(x))return;Ot(),h?.setAttribute("aria-expanded","false")}}),g.on("click","#btn-notifications",l=>{l.preventDefault(),l.stopPropagation(),Ut(),Ot(),ni()}),window.addEventListener("resize",()=>{r("recent-menu")&&!r("recent-menu").classList.contains("hidden")&&Va()}),g.on("click","#recent-menu [data-session-id]",()=>{Ot(),r("btn-recent-sessions")?.setAttribute("aria-expanded","false")}),g.on("click","[data-dismiss-recent-session]",(l,c)=>{l.preventDefault(),l.stopPropagation(),ir({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",()=>{xr()}),g.on("click","#btn-cancel-project-notes",()=>{Sn()});let i=async()=>{let l=r("project-goal-input")?.value?.trim()??"",c=r("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});br(h.goal||"",h.notes||""),Sn()}catch(h){alert(`Error saving project notes: ${h.message}`)}};g.on("click","#btn-save-project-notes",i),g.on("keydown","#project-goal-input",l=>{l.key==="Enter"&&i(),l.key==="Escape"&&Sn()}),g.on("keydown","#project-notes-input",l=>{l.key==="Escape"&&Sn()}),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)),wr(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)),kr(c.dataset.hideSessionId,c.dataset.hideSessionAgent||"claude",{machineId:u||null})}),g.on("click","#btn-edit-session-notes, #session-notes-text",()=>{vr()}),g.on("click","#btn-cancel-session-notes",()=>He()),g.on("click","#btn-save-session-notes",async()=>{let l=r("session-notes-input")?.value?.trim()||"";if(!f.sessionId)return;let c=f.agent||I.peek()||"claude";await so(f.sessionId,c,l)&&He()}),g.on("keydown","#session-notes-input",async l=>{if(l.key==="Escape"&&He(),l.key==="Enter"){let c=l.target.value.trim();if(!f.sessionId)return;let u=f.agent||I.peek()||"claude";await so(f.sessionId,u,c)&&He()}}),g.on("click","#btn-fav-filter",()=>{let l=!Ae.peek();Ae.value=l,localStorage.setItem("favoritesOnly",l?"1":"0"),r("btn-fav-filter")?.classList.toggle("active",l),l&&je.peek()&&(je.value=!1,localStorage.setItem("showHiddenOnly","0"),r("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"),r("btn-hidden-filter")?.classList.toggle("active",l),l&&Ae.peek()&&(Ae.value=!1,localStorage.setItem("favoritesOnly","0"),r("btn-fav-filter")?.classList.remove("active"))}),Pe(),Ce(()=>{A.value,j.value,f.token&&fs()}),r("sel-permission").value=Ee.peek(),Ls();let d=r("sel-density");d&&(d.value=Qe.peek()||"normal"),document.querySelectorAll("[data-agent-option]").forEach(l=>{l.checked=$t.peek().includes(l.dataset.agentOption)}),r("filter-favorites")&&(r("filter-favorites").checked=Ae.peek()),r("filter-hidden")&&(r("filter-hidden").checked=je.peek()),document.querySelectorAll("[data-agent-filter]").forEach(l=>{l.classList.toggle("active",l.dataset.agentFilter===de.peek())}),r("btn-fav-filter")?.classList.toggle("active",Ae.peek()),r("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)})}gn();O();q();ue();function hc(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 bc(e){let t=(e||"").split("/").pop()||"",n=t.lastIndexOf(".");return n>=0?t.slice(n+1).toLowerCase():""}function Dr(e){let t=bc(e);return t==="docx"||t==="pptx"||t==="xlsx"||t==="pdf"?t:null}function gc(e){return e==null?"":e>1024*1024?`${(e/(1024*1024)).toFixed(1)} MB`:e>1024?`${(e/1024).toFixed(1)} KB`:`${e} B`}function xc(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 go=new Map;function ea(e){if(go.has(e))return go.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 go.set(e,t),t}function vc(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 yc(e){!e||typeof hljs>"u"||e.querySelectorAll("pre code.file-preview-code").forEach(t=>{try{delete t.dataset.highlighted,hljs.highlightElement(t)}catch{}})}function ns(e,t,n){let s=gc(t);return`
|
|
1027
|
-
<div class="flex items-center gap-2 px-4 py-1.5 border-b border-base-300 flex-shrink-0 bg-base-200">
|
|
1028
|
-
<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>
|
|
1029
|
-
<button type="button" class="btn btn-ghost btn-xs" data-download-path="${p(e)}">\u2193 Download</button>
|
|
1030
|
-
</div>`}function wc(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=>`
|
|
1031
|
-
<div class="flex items-center gap-2 px-4 py-1.5 hover:bg-base-300 group"
|
|
1032
|
-
${t.isDir?`data-dir-path="${p(t.path)}"`:`data-file-path="${p(t.path)}"`}>
|
|
1033
|
-
<span class="cursor-pointer flex-shrink-0">${t.isDir?"\u{1F4C1}":hc(t.name)}</span>
|
|
1034
|
-
<span class="text-sm flex-1 truncate cursor-pointer ${t.isDir?"text-primary":""}">${p(t.name)}</span>
|
|
1035
|
-
${t.isDir?"":`
|
|
1036
|
-
<button type="button" class="file-row-action btn btn-ghost btn-xs px-1.5 text-base-content/50 hover:text-base-content"
|
|
1037
|
-
data-download-path="${p(t.path)}" title="Download" aria-label="Download">\u2193</button>
|
|
1038
|
-
<button type="button" class="file-row-action btn btn-ghost btn-xs px-1.5 text-error/60 hover:text-error"
|
|
1039
|
-
data-delete-path="${p(t.path)}" title="Delete" aria-label="Delete">\u2715</button>`}
|
|
1040
|
-
</div>`).join(""))}function kc(e,t,n){let s=/[\x00-\x08\x0e-\x1f]/.test(t.slice(0,512)),a=vc(e),o=a?`language-${p(a)}`:"",i=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 ns(e,n,s?"binary":a||"text")+i}async function $c(e){if(await ea("/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 Sc(e){if(await ea("/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,i)=>`<button type="button" class="office-sheet-tab${i===0?" active":""}" data-sheet-idx="${i}">${p(o)}</button>`).join(""),a=n.map((o,i)=>{let d=t.Sheets[o],l;try{l=XLSX.utils.sheet_to_html(d,{id:`xlsx-sheet-${i}`,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${i===0?"":" hidden"}" data-sheet-pane="${i}">${l}</div>`}).join("");return`
|
|
1041
|
-
<div class="office-preview office-xlsx flex flex-col flex-1 min-h-0 overflow-hidden">
|
|
1042
|
-
<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>
|
|
1043
|
-
<div class="office-sheet-body flex-1 overflow-auto p-2">${a}</div>
|
|
1044
|
-
</div>`}function Lc(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 i of o){let d=[];for(s.lastIndex=0;(a=s.exec(i))!==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 Ec(e){if(await ea("/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 i=parseInt(a.match(/slide(\d+)/i)?.[1]||"0",10),d=parseInt(o.match(/slide(\d+)/i)?.[1]||"0",10);return i-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"),i=Lc(o),d=i.length?i.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(`
|
|
1045
|
-
<article class="office-slide-card">
|
|
1046
|
-
<header class="office-slide-num">Slide ${a+1}</header>
|
|
1047
|
-
<div class="office-slide-body">${d}</div>
|
|
1048
|
-
</article>`)}return`
|
|
1049
|
-
<div class="office-preview office-pptx overflow-auto flex-1 p-3 space-y-3">
|
|
1050
|
-
<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>
|
|
1051
|
-
${s.join("")}
|
|
1052
|
-
</div>`}async function Tc(){if(await ea("/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 Mc(e){let n=await(await Tc()).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(`
|
|
1053
|
-
<figure class="office-pdf-figure">
|
|
1054
|
-
<figcaption class="office-pdf-cap">Page ${d} / ${s}</figcaption>
|
|
1055
|
-
${x.outerHTML}
|
|
1056
|
-
</figure>`)}let i=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`
|
|
1057
|
-
<div class="office-preview office-pdf overflow-auto flex-1 p-3 space-y-3">
|
|
1058
|
-
<p class="text-xs text-base-content/50 px-1">PDF preview \xB7 ${s} page(s)</p>
|
|
1059
|
-
${i}
|
|
1060
|
-
${o.join("")}
|
|
1061
|
-
</div>`}async function Ic(e,t,n){let s=Dr(e),a={docx:"Word",pptx:"PowerPoint",xlsx:"Excel",pdf:"PDF"},o=xc(t),i;if(s==="docx")i=await $c(o);else if(s==="xlsx")i=await Sc(o);else if(s==="pptx")i=await Ec(o);else if(s==="pdf")i=await Mc(o);else throw new Error("Unsupported office type");return ns(e,n,a[s]||s)+i}function Cc(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 i of s)o=o?`${o}/${i}`:i,a+=` <span class="text-base-content/40">/</span> <span class="cursor-pointer text-primary hover:underline" data-dir-path="${p(o)}">${p(i)}</span>`;return t&&(a+=` <span class="text-base-content/40">/</span> <span>${p(n.at(-1))}</span>`),a}function Ac(){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=K.peek(),a=e?.id||"_",o=[...n.files],i=!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}`),i=!0;break}}if(!i){let d=K.peek();K.value=d+"\0",K.value=d}}),n.click()}async function jc(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"}),i=`/api/projects/${s}/file?${o}`;try{let d=await fetch(i,{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?${qo({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 Dc(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)}`),K.value=K.peek()+" ",K.value=K.peek().trimEnd()}catch(a){alert(`Delete failed: ${a.message}`)}}async function Nc(e,t,n,s){let a=n.size??(typeof n.content=="string"?n.content.length:0),o=Dr(t);if(o&&n.encoding==="base64"){e.innerHTML=ns(t,a,o)+`<div class="p-4 text-xs text-base-content/40">Parsing ${o.toUpperCase()}\u2026</div>`;try{let i=await Ic(t,n.content,a);if(s.aborted)return;e.innerHTML=i}catch(i){if(s.aborted)return;e.innerHTML=ns(t,a,o)+`<div class="p-4 text-xs text-error">Preview failed: ${p(i.message)} \u2014 <button class="text-primary hover:underline" data-download-path="${p(t)}">Download</button></div>`}return}if(n.encoding==="base64"){e.innerHTML=ns(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=kc(t,n.content||"",a),yc(e)}function Nr(){Ce(()=>{let e=r("files-breadcrumb");if(!e)return;let t=re.value!==null;e.innerHTML=`
|
|
1062
|
-
${Cc(re.value??K.value,t)}
|
|
1063
|
-
<div class="flex-1"></div>
|
|
1064
|
-
${t?"":'<button id="btn-upload" class="btn btn-ghost btn-xs text-base-content/50 hover:text-base-content">\u2191 Upload</button>'}`}),In(async e=>{let t=W.value,n=E.value,s=(ce.value||n?.path||"").trim(),a=re.value,o=K.value,i=r("files-area");if(!i||t!=="files")return;if(!s){i.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||"_";i.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 Nc(i,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){i.innerHTML=`<div class="p-4 text-xs text-error">${p(l?.error||"Invalid directory listing")}</div>`;return}i.innerHTML=wc(c)}catch(l){!e.aborted&&l?.name!=="AbortError"&&(i.innerHTML=`<div class="p-4 text-xs text-error">${p(l.message)}</div>`)}}),g.on("click","[data-dir-path]",(e,t)=>{re.value=null,K.value=t.dataset.dirPath}),g.on("click","[data-file-path]",(e,t)=>{re.value=t.dataset.filePath}),g.on("click","#btn-upload",()=>Ac()),g.on("click","[data-download-path]",(e,t)=>{e.preventDefault(),e.stopPropagation();let n=t.dataset.downloadPath;n&&jc(E.peek(),n)}),g.on("click","[data-delete-path]",(e,t)=>{e.preventDefault(),e.stopPropagation();let n=t.dataset.deletePath;n&&Dc(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)})})}O();q();ue();var _r=$(!1);function _c(e){return e?e.split(`
|
|
1065
|
-
`).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(`
|
|
1066
|
-
`):'<span class="text-base-content/40">No commits</span>'}function Pc(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`
|
|
1067
|
-
<div class="px-4 py-2 text-xs text-base-content/50 border-b border-base-300">
|
|
1068
|
-
Branch: <span class="text-success font-semibold">${p(e.branch)}</span>
|
|
1069
|
-
</div>
|
|
1070
|
-
${e.files.length?e.files.map(n=>`
|
|
1071
|
-
<div class="flex items-center gap-3 px-4 py-1 text-sm">
|
|
1072
|
-
<span class="font-mono text-xs w-5 flex-shrink-0 ${t[n.status]||"text-success"}">${p(n.status)}</span>
|
|
1073
|
-
<span class="break-all">${p(n.file)}</span>
|
|
1074
|
-
</div>`).join(""):'<div class="px-4 py-2 text-sm text-base-content/50">Working tree clean</div>'}
|
|
1075
|
-
<div class="border-t border-base-300 p-4">
|
|
1076
|
-
<div class="flex gap-4 text-xs mb-3">
|
|
1077
|
-
<span id="diff-unstaged" class="cursor-pointer text-primary">Unstaged</span>
|
|
1078
|
-
<span id="diff-staged" class="cursor-pointer text-base-content/50">Staged</span>
|
|
1079
|
-
</div>
|
|
1080
|
-
<div id="diff-content" class="font-mono text-xs overflow-auto max-h-[30vh] whitespace-pre"></div>
|
|
1081
|
-
</div>
|
|
1082
|
-
<div class="border-t border-base-300">
|
|
1083
|
-
<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">
|
|
1084
|
-
<span class="uppercase tracking-wider font-medium">Git Graph</span>
|
|
1085
|
-
<span id="git-graph-chevron" class="text-[10px]">\u25B6</span>
|
|
1086
|
-
</div>
|
|
1087
|
-
<div id="git-graph-panel" class="hidden px-4 pb-4">
|
|
1088
|
-
<div id="git-graph-content" class="git-graph overflow-x-auto max-h-[35vh] overflow-y-auto">
|
|
1089
|
-
<span class="text-base-content/40">Loading\u2026</span>
|
|
1090
|
-
</div>
|
|
1091
|
-
</div>
|
|
1092
|
-
</div>`}function Hc(e){return e.split(`
|
|
1093
|
-
`).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(`
|
|
1094
|
-
`)}function Pr(){In(async e=>{let t=W.value,n=E.value,s=be.value||n?.path,a=r("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 i=await y("GET",`/api/projects/${o}/git/status?root=${encodeURIComponent(s)}`,void 0,e);e.aborted||(a.innerHTML=Pc(i))}catch(i){!e.aborted&&i?.name!=="AbortError"&&(a.innerHTML=`<div class="p-4 text-xs text-error">${p(i?.message??String(i))}</div>`)}}),In(async e=>{let t=E.value,n=be.value||t?.path,s=_r.value,a=r("diff-content");if(!a||!n)return;let o=t?.id||"_";try{let i=await y("GET",`/api/projects/${o}/git/diff?root=${encodeURIComponent(n)}${s?"&staged=true":""}`,void 0,e);e.aborted||(a.innerHTML=i?.diff?Hc(i.diff):'<span class="text-base-content/40">No changes</span>')}catch(i){!e.aborted&&i?.name!=="AbortError"&&(a.innerHTML=`<span class="text-error">${p(i?.message??String(i))}</span>`)}}),g.on("click","#diff-unstaged, #diff-staged",(e,t)=>{let n=t.id==="diff-staged";_r.value=n,r("diff-unstaged").className=`cursor-pointer ${n?"text-base-content/50":"text-primary"}`,r("diff-staged").className=`cursor-pointer ${n?"text-primary":"text-base-content/50"}`}),g.on("click","#git-graph-toggle",()=>{let e=r("git-graph-panel"),t=r("git-graph-chevron"),n=e.classList.toggle("hidden");t.textContent=n?"\u25B6":"\u25BC",n||Rc()})}function Rc(){let e=E.peek(),t=be.peek()||e?.path,n=r("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?_c(a.graph):'<span class="text-base-content/40">No commits</span>'}).catch(a=>{n.innerHTML=`<span class="text-error">${p(a.message)}</span>`})}O();q();var we=null,H=null,na=null,os=!1,sa=null,Br=null,ss=0,as=null,xo=!1,Hr=!1,Rr={"ctrl-c":"",escape:"\x1B",tab:" ",up:"\x1B[A",down:"\x1B[B",left:"\x1B[D",right:"\x1B[C"};function vo(e){we&&we.readyState===WebSocket.OPEN&&we.send(JSON.stringify({type:"input",data:e}))}function Oc(){return window.matchMedia("(max-width: 640px), (hover: none) and (pointer: coarse)").matches}function aa(){if(Oc()){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 qr(){if(H)return;let e=r("terminal-container");if(!e)return;if(typeof Terminal>"u"){setTimeout(qr,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"&&(na=new FitAddon.FitAddon,H.loadAddon(na)),H.open(e),ta(),H.onData(n=>{vo(n)}),e.addEventListener("pointerdown",()=>aa(),{passive:!0}),e.addEventListener("touchend",()=>aa(),{passive:!0}),window.addEventListener("resize",()=>{ta(),oa()});let t=window.visualViewport;if(t){let n=0,s=()=>{n&&cancelAnimationFrame(n),n=requestAnimationFrame(()=>{n=0,W.peek()==="shell"&&(ta(),oa())})};t.addEventListener("resize",s),t.addEventListener("scroll",s)}}function ta(){try{na&&H&&na.fit()}catch{}}function oa(){we&&we.readyState===WebSocket.OPEN&&H&&we.send(JSON.stringify({type:"resize",cols:H.cols,rows:H.rows}))}function Fr(){return f.machineId||j.peek()||null}function ia(e){as&&(clearTimeout(as),as=null),xo=!0;let t=++ss;if(we){try{we.close()}catch{}we=null}os=!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 i=Fr();A.peek()&&i&&o.set("machine",i),sa=e||null,Br=i,we=new WebSocket(`${n}://${location.host}/ws/shell?${o}`),we.addEventListener("open",()=>{t===ss&&(os=!0,H?.write(`\x1B[32mConnected to interactive terminal\x1B[0m\r
|
|
1095
|
-
`),oa())}),we.addEventListener("message",d=>{if(t!==ss)return;let l;try{l=JSON.parse(d.data)}catch{return}l.type==="output"?H?.write(l.data):l.type==="exit"?H?.write(`\r
|
|
1096
|
-
\x1B[33m[process exited: ${l.code}]\x1B[0m\r
|
|
1097
|
-
`):l.type==="error"&&H?.write(`\r
|
|
1098
|
-
\x1B[31m[error: ${l.data||l.message||""}]\x1B[0m\r
|
|
1099
|
-
`)}),we.addEventListener("close",()=>{t===ss&&(os=!1,H?.write(`\r
|
|
1100
|
-
\x1B[33m[disconnected]\x1B[0m\r
|
|
1101
|
-
`),!(!xo||W.peek()!=="shell")&&(H?.write(`\x1B[33m[reconnecting\u2026]\x1B[0m\r
|
|
1102
|
-
`),as=setTimeout(()=>{as=null,ia(sa)},1500)))}),we.addEventListener("error",()=>{t===ss&&H?.write(`\r
|
|
1103
|
-
\x1B[31m[WebSocket error]\x1B[0m\r
|
|
1104
|
-
`)})}function Or(){let e=E.peek()?.path,t=r("term-cwd");t&&(t.textContent=e||"~"),H||qr(),requestAnimationFrame(()=>{requestAnimationFrame(()=>{ta();let n=Fr();!os||sa!==(e||null)||Br!==n?(H?.clear(),ia(e)):oa()})})}function Ur(){Hr||(Hr=!0,document.getElementById("term-keyboard")?.addEventListener("click",aa),document.getElementById("term-mobile-composer")?.addEventListener("submit",e=>{e.preventDefault();let t=document.getElementById("term-mobile-input");t&&(vo(`${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||!Rr[t]||(vo(Rr[t]),aa())})),document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"&&(W.peek()!=="shell"||!xo||os||ia(sa))}),Le(W,e=>{e==="shell"&&Or()}),document.addEventListener("shell-tab-shown",()=>{W.peek()==="shell"&&Or()}),document.getElementById("term-reconnect")?.addEventListener("click",()=>{H?.clear(),ia(E.peek()?.path)})}gn();Jn();Es();en();function yo(){let e=document.documentElement;e.classList.add("boot-ready"),e.classList.remove("boot-pending")}function ra(){document.documentElement.classList.remove("boot-restore")}var wo=Ra(location.hash.slice(1)||"/"),Wr=bo()||!!(f.token&&wo?.id);jr({restoreSession:Wr});zo();Ti();Nr();Pr();_i();Ur();Li();Qi();Ii(Re,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")),Wr){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 Zs({hub:s,deepLink:wo}),wo?.id||(Ci(),(location.hash||"").startsWith("#/session/")||ra()),requestAnimationFrame(()=>{requestAnimationFrame(yo)})}catch(t){console.error("[boot]",t),f.token=null,localStorage.removeItem("token"),ra(),await ho(),yo()}else{ra();try{await ho()}catch(t){console.error("[boot auth]",t)}finally{yo()}}})();document.addEventListener("router:home",()=>{ra()});Wo();
|