@seqyuan/annovibe 0.8.121 → 0.8.122
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/.next/BUILD_ID +1 -1
- package/.next/app-path-routes-manifest.json +15 -15
- package/.next/build-manifest.json +2 -2
- package/.next/prerender-manifest.json +3 -3
- package/.next/required-server-files.js +1 -1
- package/.next/required-server-files.json +1 -1
- package/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
- package/.next/server/app/_global-error.html +1 -1
- package/.next/server/app/_global-error.rsc +1 -1
- package/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/.next/server/app/_not-found.html +1 -1
- package/.next/server/app/_not-found.rsc +1 -1
- package/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/api/agent/runtime/route.js +1 -1
- package/.next/server/app/api/internal/runtime/route.js +1 -1
- package/.next/server/app/api/version/route.js +1 -1
- package/.next/server/app/index.html +1 -1
- package/.next/server/app/index.rsc +2 -2
- package/.next/server/app/index.segments/__PAGE__.segment.rsc +2 -2
- package/.next/server/app/index.segments/_full.segment.rsc +2 -2
- package/.next/server/app/index.segments/_head.segment.rsc +1 -1
- package/.next/server/app/index.segments/_index.segment.rsc +1 -1
- package/.next/server/app/index.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/login/page_client-reference-manifest.js +1 -1
- package/.next/server/app/login.html +1 -1
- package/.next/server/app/login.rsc +1 -1
- package/.next/server/app/login.segments/_full.segment.rsc +1 -1
- package/.next/server/app/login.segments/_head.segment.rsc +1 -1
- package/.next/server/app/login.segments/_index.segment.rsc +1 -1
- package/.next/server/app/login.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/login.segments/login/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/login.segments/login.segment.rsc +1 -1
- package/.next/server/app/page.js +2 -2
- package/.next/server/app/page_client-reference-manifest.js +1 -1
- package/.next/server/app/smoke/page_client-reference-manifest.js +1 -1
- package/.next/server/app/smoke/session-stream/page_client-reference-manifest.js +1 -1
- package/.next/server/app/smoke/session-stream.html +1 -1
- package/.next/server/app/smoke/session-stream.rsc +2 -2
- package/.next/server/app/smoke/session-stream.segments/_full.segment.rsc +2 -2
- package/.next/server/app/smoke/session-stream.segments/_head.segment.rsc +1 -1
- package/.next/server/app/smoke/session-stream.segments/_index.segment.rsc +1 -1
- package/.next/server/app/smoke/session-stream.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/smoke/session-stream.segments/smoke/session-stream/__PAGE__.segment.rsc +2 -2
- package/.next/server/app/smoke/session-stream.segments/smoke/session-stream.segment.rsc +1 -1
- package/.next/server/app/smoke/session-stream.segments/smoke.segment.rsc +1 -1
- package/.next/server/app/smoke.html +1 -1
- package/.next/server/app/smoke.rsc +1 -1
- package/.next/server/app/smoke.segments/_full.segment.rsc +1 -1
- package/.next/server/app/smoke.segments/_head.segment.rsc +1 -1
- package/.next/server/app/smoke.segments/_index.segment.rsc +1 -1
- package/.next/server/app/smoke.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/smoke.segments/smoke/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/smoke.segments/smoke.segment.rsc +1 -1
- package/.next/server/app-paths-manifest.json +15 -15
- package/.next/server/chunks/3041.js +5 -5
- package/.next/server/chunks/4584.js +2 -2
- package/.next/server/middleware-build-manifest.js +1 -1
- package/.next/server/middleware.js +3 -3
- package/.next/server/pages/404.html +1 -1
- package/.next/server/pages/500.html +1 -1
- package/.next/server/server-reference-manifest.json +1 -1
- package/.next/static/chunks/5377-1dcfca9d5a1c5694.js +22 -0
- package/.next/static/chunks/app/{page-7673f9b48c531a25.js → page-55978c1ddc84af8a.js} +2 -2
- package/package.json +1 -1
- package/.next/static/chunks/5377-8f8cd2e62855e613.js +0 -22
- /package/.next/static/{RGo27ZXaxOnz4AWGjVXXd → ryv7dcOEsJ2E9qSarLzwD}/_buildManifest.js +0 -0
- /package/.next/static/{RGo27ZXaxOnz4AWGjVXXd → ryv7dcOEsJ2E9qSarLzwD}/_ssgManifest.js +0 -0
package/package.json
CHANGED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[5377],{5377:(e,t,n)=>{n.d(t,{T:()=>W});var r=n(12115);function a(e){return e?.phase==="running_tools"?{kind:"running_tools",tools:(e.activeTools??[]).map(e=>({id:e.id,name:e.name}))}:e?.phase==="streaming"||e?.phase==="compacting"||e?.phase==="idle"?null:{kind:"waiting_model"}}function o(e){if("assistant"!==e.role)return e;let t=e.content;if(!Array.isArray(t))return e;let n=t.map(e=>("object"!=typeof e||null===e||Array.isArray(e)||"toolCall"!==e.type?null:{type:"toolCall",toolCallId:"string"==typeof e.toolCallId?e.toolCallId:"string"==typeof e.id?e.id:"",toolName:"string"==typeof e.toolName?e.toolName:"string"==typeof e.name?e.name:"",input:"object"!=typeof e.input||null===e.input||Array.isArray(e.input)?"object"!=typeof e.arguments||null===e.arguments||Array.isArray(e.arguments)?{}:e.arguments:e.input})??e);return{...e,content:n}}var s=n(32383),l=n(28999);async function i(e,t){if(!t.length)return[];let n=await fetch("/api/images/upload",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,images:t.map(e=>({data:e.data,mimeType:e.mimeType,name:e.name}))})}),r=await n.json().catch(()=>({}));if(!n.ok||r.error)throw Error(r.error??`Upload failed (HTTP ${n.status})`);return(r.uploaded??[]).map((e,n)=>({...e,previewUrl:t[n]?.previewUrl}))}async function u(e,t,n){let r,a=new TextDecoder,o="",s=e=>{if(e.startsWith("id: ")){r=e.slice(4);return}if(!e.startsWith("data: "))return;let n=e.slice(6);if("[DONE]"!==n)try{t(n,r)}catch{}finally{r=void 0}},l=new Promise(e=>{n?.aborted?e():n?.addEventListener("abort",()=>e(),{once:!0})});for(;;){let t=await Promise.race([e.read(),l.then(()=>({done:!0,value:void 0}))]);if(t.done)break;let n=(o+=a.decode(t.value,{stream:!0})).split("\n");for(let e of(o=n.pop()||"",n))s(e)}if(o.trim())for(let e of o.split("\n"))s(e)}var c=n(16865);let d="__annovibeStreamSessions__",p="__annovibeStreamListeners__",m="__annovibeStreamErrorCallbacks__";function f(){let e=globalThis;return e[d]||(e[d]=new Map),e[d]}function g(){let e=globalThis;return e[m]||(e[m]=new Map),e[m]}function h(e){return{sessionId:e,phase:"idle",startedAt:null,lastEventAt:null,lastHeartbeatAt:null,reconnectCount:0,lastSyncReason:null,accumulatedText:"",toolCalls:[],toolResults:[],statusText:null,streamingMessage:null,isStreaming:!1,error:null}}function y(e,t){let n;for(let r of(!(n=globalThis)[p]&&(n[p]=new Map),n[p]).get(e)??[])try{r(t)}catch{}}function w(e){e.textThrottleTimer&&(clearTimeout(e.textThrottleTimer),e.textThrottleTimer=null),e.textDirty&&(e.textDirty=!1,b(e))}function v(e,t=!1){let n=Date.now();if(e.snapshot.lastEventAt=n,!t){e.textDirty=!0,e.textThrottleTimer||(e.textThrottleTimer=setTimeout(()=>{e.textThrottleTimer=null,e.textDirty&&(e.textDirty=!1,b(e))},100));return}w(e),b(e)}function b(e,t){let n=Date.now(),r=function(e){let t=[];for(let n of e.toolCalls.values())t.push({type:"toolCall",toolCallId:n.toolCallId,toolName:n.toolName,input:n.input??{}});let n=e.accumulatedText.trim();return n&&t.push({type:"text",text:n}),t}(e),a=(t??e.snapshot.phase)==="active";e.snapshot={...e.snapshot,phase:t??e.snapshot.phase,lastEventAt:n,accumulatedText:e.accumulatedText,toolCalls:[...e.toolCalls.values()],toolResults:[...e.toolResults.values()],statusText:a?function(e){if(e.activeToolId){let t=e.toolCalls.get(e.activeToolId);if(t){let e=Math.max(0,Math.floor((Date.now()-t.startedAt)/1e3));return`Running ${t.toolName||"tool"}… (${e}s)`}}return e.accumulatedText.trim()?"Generating response…":e.toolCalls.size>0?"Finishing tool results…":null}(e):e.snapshot.statusText,streamingMessage:a&&r.length>0?{role:"assistant",content:r}:null,isStreaming:a},y(e.snapshot.sessionId,{type:"snapshot-updated",snapshot:e.snapshot})}function T(e){C(e),e.idleCheckTimer=setInterval(()=>{if("connected"!==e.connectionState)return;let t=Math.max(e.snapshot.lastEventAt??0,e.snapshot.lastHeartbeatAt??0);if(Date.now()-t>=18e4){k(e),w(e);let t="Stream idle timeout — no activity for 180s.";e.snapshot={...e.snapshot,phase:"error",isStreaming:!1,streamingMessage:null,statusText:null,error:t},C(e),y(e.snapshot.sessionId,{type:"error",snapshot:e.snapshot});let n=g().get(e.snapshot.sessionId);if(n)try{n(e.snapshot.sessionId,t)}catch{}}},1e4)}function C(e){e.idleCheckTimer&&(clearInterval(e.idleCheckTimer),e.idleCheckTimer=null)}function k(e){e.toolProgressTimer&&(clearInterval(e.toolProgressTimer),e.toolProgressTimer=null)}function I(e){let t=f(),n=t.get(e);return n||(n={snapshot:h(e),accumulatedText:"",toolCalls:new Map,toolResults:new Map,toolProgressTimer:null,activeToolId:null,textThrottleTimer:null,textDirty:!1,connectionState:"idle",idleCheckTimer:null},t.set(e,n)),n}function S(e,t){let n=g();return n.set(e,t),()=>{n.get(e)===t&&n.delete(e)}}function _(e){let t=f(),n=t.get(e);n&&(k(n),C(n),w(n)),t.delete(e)}function x(e){let t=f().get(e);t&&(t.snapshot={...t.snapshot,reconnectCount:t.snapshot.reconnectCount+1,lastSyncReason:"sse-reconnect",lastEventAt:Date.now()},v(t,!0))}let M="__annovibeSessionMessageCache__";function E(){let e=globalThis;if(!e[M]){var t;let n={entries:new Map,cleanupTimer:null};e[M]=n,(t=n).cleanupTimer||(t.cleanupTimer=setInterval(()=>{let e=Date.now();for(let[n,r]of t.entries)e-r.loadedAt>72e5&&t.entries.delete(n)},6e4))}return e[M]}function A(e){let t=E(),n=t.entries.get(e);return n?Date.now()-n.loadedAt>72e5?(t.entries.delete(e),null):(n.loadedAt=Date.now(),{...n,messages:[...n.messages],entryIds:[...n.entryIds]}):null}function $(e,t,n,r,a){let o=E(),s=o.entries.get(e);if(!s)return;let l=new Set(s.entryIds),i=[],u=[];for(let e=0;e<t.length;e++){let r=n[e];r&&!l.has(r)&&(i.push(t[e]),u.push(r))}0!==i.length&&o.entries.set(e,{...s,messages:[...i,...s.messages],entryIds:[...u,...s.entryIds],hasMore:r,loadedMessagesCount:a,loadedAt:Date.now()})}function R(e){E().entries.delete(e)}var D=n(14755);function L(e,t){switch(t.type){case"start":return{isStreaming:!0,streamingMessage:null};case"update":return{isStreaming:!0,streamingMessage:t.message};case"end":case"reset":return{isStreaming:!1,streamingMessage:null};default:return e}}function N(){return"u"<typeof document||"hidden"!==document.visibilityState}function P(e,t){return new DOMException(e,t)}function U(){return"u">typeof crypto&&"function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,11)}-${Math.random().toString(36).slice(2,11)}`}let j=["read","bash","grep","find","ls"];function O(e,t){return e.trim()||0!==t?`text:${e}|images:${t}`:null}function F(e){return"string"==typeof e?O(e,0):Array.isArray(e)?O(e.filter(e=>!!e&&"object"==typeof e&&"text"===e.type&&"string"==typeof e.text).map(e=>e.text).join("\n"),e.filter(e=>!!e&&"object"==typeof e&&"image"===e.type).length):null}function H(e){let t=new Map;for(let n of e){let e="user"!==n.role?null:F(n.content);e&&t.set(e,(t.get(e)??0)+1)}return t}function K(e,t,n){return e.sessionId===t&&(!e.leafId||n.includes(e.leafId))}function W(e){let{session:t,newSessionCwd:n,planMode:d=!1,onAgentEnd:p,onSessionCreated:m,onSessionForked:g,modelsRefreshKey:b,onBranchDataChange:M,onPlanModeState:W}=e,J=null===t&&null!==n,[B,q]=(0,r.useState)(null),[z,G]=(0,r.useState)(!J),[V,Y]=(0,r.useState)(null),[Q,X]=(0,r.useState)(null),[Z,ee]=(0,r.useState)([]),[et,en]=(0,r.useState)([]),[er,ea]=(0,r.useState)(0),[eo,es]=(0,r.useState)(!1),[el,ei]=(0,r.useState)(0),[eu,ec]=(0,r.useReducer)(L,{isStreaming:!1,streamingMessage:null}),[ed,ep]=(0,r.useState)(!1),[em,ef]=(0,r.useState)({}),[eg,eh]=(0,r.useState)([]),[ey,ew]=(0,r.useState)({}),[ev,eb]=(0,r.useState)({}),[eT,eC]=(0,r.useState)(null),[ek,eI]=(0,r.useState)("full"),[eS,e_]=(0,r.useState)([...D.SN]),[ex,eM]=(0,r.useState)("auto"),[eE,eA]=(0,r.useState)(null),[e$,eR]=(0,r.useState)(null),[eD,eL]=(0,r.useState)(null),[eN,eP]=(0,r.useState)(null),[eU,ej]=(0,r.useState)(null),[eO,eF]=(0,r.useState)(null),[eH,eK]=(0,r.useState)(!1),[eW,eJ]=(0,r.useState)(null),[eB,eq]=(0,r.useState)(null),[ez,eG]=(0,r.useState)(null),eV=(0,r.useRef)(null),eY=(0,r.useRef)(t?.id??null),eQ=(0,r.useRef)(!1),eX=(0,r.useRef)(null),eZ=(0,r.useRef)(null),e0=(0,r.useRef)(null),e1=(0,r.useRef)(!1),e3=(0,r.useRef)(null),e4=(0,r.useRef)(!1),e5=(0,r.useRef)(null),e2=(0,r.useRef)(null),e6=(0,r.useRef)(new Map),e7=(0,r.useRef)(new Map),e8=(0,r.useRef)(null),e9=(0,r.useRef)([]),te=(0,r.useRef)(null),tt=(0,r.useRef)(0),tn=(0,r.useRef)(!1),tr=(0,r.useRef)(0),ta=(0,r.useRef)(!1),to=(0,r.useRef)(!1),ts=(0,r.useRef)(0),tl=(0,r.useRef)(null),ti=(0,r.useRef)(null),tu=(0,r.useRef)(null),tc=(0,r.useRef)(!1);(0,r.useEffect)(()=>{e8.current=Q},[Q]);let td=e.setNewSessionModel??eC,tp=e.setToolPreset??eI,tm=e.setMemoryTools??e_,tf=eU??B?.context.model??eO??null,tg=J?eT:tf,th=(0,r.useCallback)(()=>d?j:(0,D.tE)(ek,eS),[eS,d,ek]),ty=(0,r.useCallback)(e=>e?.length?e.map((e,t)=>{let n=`Attachment ${t+1}: ${e.fileName} (${e.mimeType||"application/octet-stream"}, ${e.size} bytes)`;if(e.extractedText){let t=e.truncated?"\n[The extracted text was truncated before sending.]":"";return`${n}
|
|
2
|
-
${t}
|
|
3
|
-
${e.extractedText}`.trim()}return`${n}
|
|
4
|
-
[Text extraction unavailable: ${e.extractionError??"unsupported file type"}]`}).join("\n\n---\n\n"):"",[]),tw=(0,r.useCallback)(async e=>{let t=await fetch(`/api/agent/${encodeURIComponent(e)}/prepare`,{method:"POST"});if(!t.ok)throw Error((await t.json().catch(()=>({}))).error??`Failed to prepare session (HTTP ${t.status})`)},[]),tv=(()=>{let e={input:0,output:0,cacheRead:0,cacheWrite:0},t=0;for(let n of Z){if("assistant"!==n.role)continue;let r=n.usage;r&&(e.input+=r.input??0,e.output+=r.output??0,e.cacheRead+=r.cacheRead??0,e.cacheWrite+=r.cacheWrite??0,t+=r.cost?.total??0)}return e.input+e.output+e.cacheRead+e.cacheWrite>0?{tokens:e,cost:t}:null})(),tb=(0,r.useRef)(!1),tT=(0,r.useCallback)(async()=>{let e=eY.current;if(!e||tb.current||ta.current)return;tb.current=!0,tn.current=!0;let t=0,n=A(e);t=n?n.loadedMessagesCount:50;try{for(;;)try{let n=await fetch(`/api/sessions/${encodeURIComponent(e)}?limit=100&offset=${t}`);if(!n.ok)break;let r=await n.json();if(eY.current!==e)break;let a=r.context.messages,o=r.context.entryIds??[];if(0===a.length)break;ee(e=>[...a,...e]),en(e=>{let t=[...o,...e];return e9.current=t,t});let s=t+a.length;if(ei(s),tr.current=s,es(r.hasMore??!1),$(e,a,o,r.hasMore??!1,s),t=s,!r.hasMore)break;await new Promise(e=>setTimeout(e,800))}catch{break}}finally{tb.current=!1,ta.current=!0,tn.current=!1}},[]),tC=(0,r.useCallback)(async(e,t=!1,n=!1,r=!1)=>{var a;let o=null;try{if(t&&G(!0),!n&&!eQ.current&&!r){let n=A(e);if(n)return ea(n.totalMessages),es(n.hasMore),ei(n.loadedMessagesCount),ee(n.messages),e9.current=n.entryIds,en(n.entryIds),e8.current=n.leafId,X(n.leafId),tr.current=n.loadedMessagesCount,t&&G(!1),n.hasMore&&!ta.current&&setTimeout(()=>{tT()},1500),null}let s=n?`/api/sessions/${encodeURIComponent(e)}?includeState`:`/api/sessions/${encodeURIComponent(e)}?limit=50&offset=0`,l=ti.current;if(l?.sid===e&&!t)return null;l?.controller.abort(P("Session load superseded","AbortError"));let i=new AbortController;o=i,ti.current={sid:e,controller:i};let u=setTimeout(()=>{i.abort(P("Session load timed out after 30 seconds","TimeoutError"))},3e4),c=await fetch(s,{signal:i.signal}).finally(()=>clearTimeout(u));if(eY.current&&eY.current!==e)return null;if(404===c.status)return t&&(q(null),e8.current=null,X(null),ee([]),Y(null)),null;if(!c.ok)throw Error(`HTTP ${c.status}`);let d=await c.json();n?(ea(d.totalMessages??d.context.messages.length),es(!1)):(ea(d.totalMessages??d.context.messages.length),es(d.hasMore??!1)),ei(d.context.messages.length),q(d),e8.current=d.leafId,X(d.leafId);let p=d.context.messages,m=H(p),f=new Map,g=Date.now();for(let[t,n]of e6.current)if(n.sessionId===e){if(g-n.createdAt>12e4){e6.current.delete(t);continue}if(n.confirmKey){let e=m.get(n.confirmKey)??0,r=f.get(n.confirmKey)??0;e-r>n.confirmCountAtCreate&&(e6.current.delete(t),f.set(n.confirmKey,r+1))}}e7.current=m;let h=d.context.entryIds??[],y=[...e6.current.values()].filter(t=>K(t,e,h)).map(e=>e.message),w=y.length>0?[...p,...y]:p,v=w.length;return!n&&tr.current>v?(ea(d.totalMessages??d.context.messages.length),es(d.hasMore??!1)):(ee(w),e9.current=h,en(h),n?tr.current=v:tr.current=Math.max(tr.current,v),a={sessionId:e,leafId:d.leafId,messages:w,entryIds:h,totalMessages:d.totalMessages??d.context.messages.length,hasMore:!n&&(d.hasMore??!1),loadedMessagesCount:d.context.messages.length},E().entries.set(e,{...a,loadedAt:Date.now()})),ej(e=>{if(!e)return null;let t=d.context.model;return t?.provider===e.provider&&t.modelId===e.modelId?null:e}),Y(null),!d.agentState?.state?.thinkingLevel&&d.context.thinkingLevel&&"off"!==d.context.thinkingLevel&&eM(d.context.thinkingLevel),d.agentState?.state?.planMode&&W?.(d.agentState.state.planMode),d.agentState??null}catch(e){if(e instanceof DOMException&&("AbortError"===e.name||"TimeoutError"===e.name)||e instanceof Error&&/aborted without reason|AbortError|Session load (?:timed out|superseded)/i.test(e.message))return null;return Y(String(e)),null}finally{o&&ti.current?.controller===o&&(ti.current=null),t&&G(!1)}},[W,tT]),tk=(0,r.useRef)(!1),tI=(0,r.useCallback)(async()=>{if(tk.current)return;tk.current=!0;let e=eY.current;if(!e){tk.current=!1;return}try{let t=await fetch(`/api/sessions/${encodeURIComponent(e)}?limit=50&offset=${el}`);if(!t.ok)return;let n=await t.json(),r=n.context.messages,a=n.context.entryIds??[];ee(e=>[...r,...e]),en(e=>{let t=[...a,...e];return e9.current=t,t}),ei(e=>e+r.length),es(n.hasMore??!1),$(e,r,a,n.hasMore??!1,el+r.length)}catch{}finally{tk.current=!1}},[el]),tS=(0,r.useCallback)(async(e,t)=>{try{let n=t?`/api/sessions/${encodeURIComponent(e)}/context?leafId=${encodeURIComponent(t)}`:`/api/sessions/${encodeURIComponent(e)}/context`,r=await fetch(n);if(!r.ok)throw Error(`HTTP ${r.status}`);let a=await r.json(),o=a.context.messages,s=a.context.entryIds??[],l=H(o),i=new Map,u=Date.now();for(let[t,n]of e6.current)if(n.sessionId===e){if(u-n.createdAt>12e4){e6.current.delete(t);continue}if(n.confirmKey){let e=l.get(n.confirmKey)??0,r=i.get(n.confirmKey)??0;e-r>n.confirmCountAtCreate&&(e6.current.delete(t),i.set(n.confirmKey,r+1))}}e7.current=l;let c=[...e6.current.values()].filter(t=>K(t,e,s)).map(e=>e.message);ee(c.length>0?[...o,...c]:o),e9.current=s,en(s)}catch(e){console.error("Failed to load context:",e)}},[]),t_=(0,r.useCallback)(async e=>{try{let t=await (0,s.$)(e,{type:"get_tools"});t&&(tp((0,D.ES)(t)),tm((0,D.IB)(t)))}catch(e){console.error("Failed to load tools:",e)}},[tm,tp]),tx=(0,r.useCallback)((e,t={})=>{eV.current?.close(),eV.current=null;let n=`/api/agent/${encodeURIComponent(e)}/events${t.replay?"?replay=1":""}`;return!function(e){let t=I(e);if("active"===t.snapshot.phase)return v(t,!0),T(t),t.snapshot;let n=Date.now();t.snapshot={...h(e),phase:"active",startedAt:n,lastEventAt:n,isStreaming:!0,streamingMessage:{role:"assistant",content:[]}},T(t),v(t,!0),t.snapshot}(e),new Promise((r,a)=>{let o=!1,s=!1,l=null,i=e=>{if(!o){if(o=!0,clearTimeout(c),e){l?.close(),eV.current===l&&(eV.current=null),a(e);return}r()}},c=setTimeout(()=>{t.requireConnected?i(Error("Timed out waiting for event stream connection")):i()},t.timeoutMs??3e4);eV.current=l=function(e){let{url:t,onEvent:n,onStateChange:r,onFatalError:a,maxReconnectAttempts:o=1/0,reconnectBaseMs:s=1e3,reconnectMaxMs:l=3e4,autoReconnect:i=!0}=e,c="idle",d=new AbortController,p=0,m=null,f=null,g=!1,h=(e,t)=>{t&&(f=t),n(e,t)},y=e=>{c!==e&&(c=e,r?.(e))},w=()=>{null!==m&&(clearTimeout(m),m=null)},v=()=>{if(g)return;if(!i)return void y("error");if(p>=o){y("error"),a?.(Error(`Max reconnect attempts (${o}) reached`));return}let e=Math.min(l,s*2**p);p+=1,y("connecting"),m=setTimeout(()=>{m=null,b()},e)},b=async()=>{if(!g){w(),d=new AbortController,y("connecting");try{let e=await fetch(t,{signal:d.signal,headers:{Accept:"text/event-stream","Cache-Control":"no-cache",...f?{"Last-Event-ID":f}:{}}});if(!e.ok)throw Error(`HTTP ${e.status}: ${e.statusText}`);let n=e.body;if(!n)throw Error("Response has no readable body");let r=n.getReader();if(y("connected"),p=0,await u(r,h,d.signal),d.signal.aborted)try{await r.cancel()}catch{}r.releaseLock(),y("closed"),!g&&i&&v()}catch(e){if(g||e instanceof DOMException&&"AbortError"===e.name)return void y("closed");y("error"),i&&v()}}};return{get state(){return c},connect:()=>{g=!1,p=0,w(),b()},close:()=>{g=!0,w(),d.abort(),y("closed")},get abortController(){return d}}}({url:n,onEvent:t=>{try{let n=JSON.parse(t);if("connected"===n.type&&i(),eY.current!==e)return;eX.current?.(n)}catch{}},onStateChange:t=>{!function(e,t){let n=f().get(e);if(!n)return;let r=n.connectionState;n.connectionState=t,"connected"===t&&"connected"!==r&&(n.snapshot={...n.snapshot,lastEventAt:Date.now(),lastHeartbeatAt:Date.now()},T(n)),"connected"!==t&&"connected"===r&&C(n)}(e,t),"connected"===t&&(s&&(x(e),eZ.current?.(e,"sse_reconnected")),s=!0)},reconnectBaseMs:1e3,reconnectMaxMs:3e4}),l.connect()})},[]),tM=(0,r.useCallback)(async(e,t="manual")=>{if(!e||eY.current!==e)return;let n=tt.current;try{let t=await fetch(`/api/agent/${encodeURIComponent(e)}`),r=await t.json().catch(()=>({}));if(eY.current!==e||tt.current!==n)return;r.running?(eQ.current=!0,ep(!0),eq(a(r.state)),N()&&(!eV.current||"closed"===eV.current.state||"error"===eV.current.state)&&(x(e),tx(e,{replay:!0}))):(eQ.current=!1,eV.current?.close(),eV.current=null,_(e),ep(!1),eq(null),eA(null),ec({type:"end"}),R(e),await tC(e,!1,!1,!0)),r.state?.contextUsage!==void 0&&eR(r.state.contextUsage??null),r.state?.systemPrompt!==void 0&&eL(r.state.systemPrompt??null),r.state?.isCompacting!==void 0&&eK(r.state.isCompacting),r.state?.thinkingLevel!==void 0&&eM(r.state.thinkingLevel??"auto"),r.state?.planMode!==void 0&&W?.(r.state.planMode)}catch{}},[tx,tC,W]);(0,r.useEffect)(()=>{eZ.current=tM},[tM]),(0,r.useEffect)(()=>{eQ.current=ed},[ed]),eX.current=(0,r.useCallback)(e=>{let t=eY.current;switch(t&&function(e,t){let n=I(e),r=Date.now();switch(t.type){case"agent_start":if("active"===n.snapshot.phase)return v(n,!0),n.snapshot;return k(n),n.accumulatedText="",n.toolCalls.clear(),n.toolResults.clear(),n.activeToolId=null,n.snapshot={...h(e),phase:"active",startedAt:r,lastEventAt:r,isStreaming:!0,streamingMessage:{role:"assistant",content:[]}},T(n),v(n,!0),n.snapshot;case"message_update":{let e=t.message;if(!e||"assistant"!==e.role)return n.snapshot;let a=e.content;for(let e of Array.isArray(a)?a:[])"object"==typeof e&&null!==e&&"type"in e&&("text"===e.type?n.accumulatedText=e.text??"":"toolCall"===e.type&&e.toolCallId&&!n.toolCalls.has(e.toolCallId)&&n.toolCalls.set(e.toolCallId,{...e,startedAt:r}));return v(n,!1),n.snapshot}case"tool_execution_start":{let e="string"==typeof t.toolCallId?t.toolCallId:"",a="string"==typeof t.toolName?t.toolName:"tool",o=t.input??{};if(!e)return n.snapshot;let s=n.toolCalls.get(e);return n.toolCalls.set(e,{type:"toolCall",toolCallId:e,toolName:a,input:s?.input??o,startedAt:s?.startedAt??r}),n.activeToolId=e,k(n),n.activeToolId&&(n.toolProgressTimer=setInterval(()=>v(n,!0),1e3)),v(n,!0),n.snapshot}case"tool_execution_end":{let e="string"==typeof t.toolCallId?t.toolCallId:"",a="string"==typeof t.toolName?t.toolName:"tool",o="string"==typeof t.result?t.result:JSON.stringify(t.result??"");if(e){let s=n.toolCalls.get(e);s&&n.toolCalls.set(e,{...s,endedAt:r}),n.toolResults.set(e,{role:"toolResult",toolCallId:e,toolName:a,content:[{type:"text",text:o}],isError:!!t.isError,timestamp:r}),n.activeToolId===e&&(n.activeToolId=null,k(n))}return v(n,!0),n.snapshot}case"message_end":return w(n),v(n,!0),n.snapshot;case"agent_end":{if(w(n),k(n),n.activeToolId=null,!0===t.willRetry)return n.accumulatedText="",n.toolCalls.clear(),n.toolResults.clear(),n.snapshot={...n.snapshot,phase:"active",lastEventAt:r,accumulatedText:"",toolCalls:[],toolResults:[],statusText:null,streamingMessage:null,isStreaming:!0,error:null},T(n),y(e,{type:"snapshot-updated",snapshot:n.snapshot}),n.snapshot;C(n);let a="string"==typeof t.error?t.error:null;return n.snapshot={...n.snapshot,phase:a?"error":"completed",isStreaming:!1,streamingMessage:null,statusText:null,error:a},y(e,a?{type:"error",snapshot:n.snapshot}:{type:"completed",snapshot:n.snapshot}),n.snapshot}case"heartbeat":return n.snapshot={...n.snapshot,lastHeartbeatAt:r},n.snapshot;default:return n.snapshot}}(t,e),e.type){case"prompt_admitted":case"agent_start":eG(null),eQ.current=!0,ep(!0),eq({kind:"waiting_model"}),ec({type:"start"});break;case"agent_end":if(!0===e.willRetry){eQ.current=!0,ep(!0),eq({kind:"waiting_model"});break}eQ.current=!1,eV.current?.close(),eV.current=null,ep(!1),eq(null),eA(null),ec({type:"end"}),t&&(R(t),tC(t,!1,!1,!0),tl.current&&clearTimeout(tl.current),tl.current=setTimeout(()=>{eY.current!==t||eQ.current||(R(t),tC(t,!1,!1,!0))},500),fetch(`/api/agent/${encodeURIComponent(t)}`).then(e=>e.json()).then(e=>{e.state?.contextUsage!==void 0&&eR(e.state.contextUsage??null),e.state?.systemPrompt!==void 0&&eL(e.state.systemPrompt??null),e.state?.isCompacting!==void 0&&eK(e.state.isCompacting)}).catch(()=>{})),p?.();break;case"message_start":case"message_update":{if(!eQ.current)break;let t=e.message;if(t?.role==="user")break;t&&ec({type:"update",message:o(t)}),eq(null);break}case"message_end":{if(!eQ.current)break;let t=e.message,n="string"==typeof e.__entryId?e.__entryId:null;if(t&&"user"!==t.role){"assistant"===t.role&&"error"===t.stopReason&&t.errorMessage?.trim()&&eG(`Model response failed: ${t.errorMessage.trim()}`);let e=o(t);!(n&&e9.current.includes(n))&&(ee(t=>t.some(t=>(function(e,t){let n=e.timestamp,r=t.timestamp;if("number"!=typeof n||"number"!=typeof r||n!==r||e.role!==t.role)return!1;try{return JSON.stringify(e)===JSON.stringify(t)}catch{return!1}})(t,e))?t:[...t,e]),n&&en(e=>{if(e.includes(n))return e;let t=[...e,n];return e9.current=t,t}))}ec({type:"reset"}),eq({kind:"waiting_model"});break}case"replay_gap":t&&(R(t),tC(t,!1,!1,!0));break;case"prompt_done":if(!eQ.current)break;tM(eY.current??"","prompt_done");break;case"prompt_error":{let n="string"==typeof e.error&&e.error.trim()?e.error.trim():"The model request failed before producing a response.";if(eQ.current=!1,ep(!1),eq(null),eA(null),ec({type:"end"}),eV.current?.close(),eV.current=null,t){for(let[e,n]of(_(t),e6.current))n.sessionId===t&&"prompt"===n.kind&&e6.current.delete(e);R(t),tC(t,!1,!1,!0)}eG(`Model request failed: ${n}`),p?.();break}case"tool_execution_start":{let t=e.toolCallId,n=e.toolName,r=e.args,a="bash"===n&&"string"==typeof r?.command?r.command:void 0;eq(e=>{let r=e?.kind==="running_tools"?[...e.tools]:[];return r.some(e=>e.id===t)||r.push({id:t,name:n,args:a}),{kind:"running_tools",tools:r}});break}case"tool_execution_end":{let t=e.toolCallId;eq(e=>{if(e?.kind!=="running_tools")return e;let n=e.tools.filter(e=>e.id!==t);return 0===n.length?{kind:"waiting_model"}:{kind:"running_tools",tools:n}});break}case"auto_retry_start":eG(null),eQ.current=!0,ep(!0),eq({kind:"waiting_model"}),eA({attempt:e.attempt,maxAttempts:e.maxAttempts,errorMessage:e.errorMessage});break;case"auto_retry_end":eA(null),!1===e.success&&"string"==typeof e.finalError&&e.finalError.trim()?eG(`Model response failed after retries: ${e.finalError.trim()}`):!0===e.success&&eG(null);break;case"auto_compaction_start":case"compaction_start":eK(!0),eJ(null);break;case"auto_compaction_end":case"compaction_end":eK(!1),e.errorMessage?eJ(e.errorMessage):!e.aborted&&eY.current&&tC(eY.current)}},[tC,p,tM]);let tE=(0,r.useCallback)(async(e,r,a,o)=>{if(!e.trim()&&!r?.length&&!a?.length||ed)return;tt.current+=1;let u=ty(a),c=e.trim()?u?`${e}
|
|
5
|
-
|
|
6
|
-
Attached document text:
|
|
7
|
-
|
|
8
|
-
${u}`:e:u?`Attached document text:
|
|
9
|
-
|
|
10
|
-
${u}`:"",p=[],f=J?n:t?.cwd??B?.info?.cwd;if(r?.length&&f)try{p=await i(f,r)}catch(e){eG(e instanceof Error?e.message:String(e));return}let g=p.length?p.map(e=>{var t;return{type:"image",path:e.path,mimeType:e.mimeType,name:e.name,source:{type:"url",url:(t=e.path,`/api/files/${(0,l.HG)(t)}?type=read`),media_type:e.mimeType}}}):r?.map(e=>({type:"image",source:{type:"base64",media_type:e.mimeType,data:e.data}})),h={role:"user",content:g?.length?[...c.trim()?[{type:"text",text:c}]:[],...g]:c,timestamp:Date.now()},y=U(),w=J?null:t?.id??null;w&&R(w);let v=e8.current,b=F(h.content);e6.current.set(y,{localId:y,sessionId:w??"__new__",leafId:v,message:h,createdAt:Date.now(),kind:"prompt",confirmKey:b,confirmCountAtCreate:J?0:b?e7.current.get(b)??0:0}),ee(e=>[...e,h]),eG(null),eQ.current=!0,ep(!0),eq({kind:"waiting_model"}),ec({type:"start"}),e4.current=!0;let T=eg.find(e=>e.provider===tf?.provider&&e.id===tf?.modelId)?.input,C=!T||0===T.length||T.includes("image")?r?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType})):void 0;tc.current=!0;try{if(J&&n){eT&&eF(eT);let t=o??th(),r=await fetch("/api/agent/new",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:n,type:"prompt",message:c,toolNames:t,planMode:d,deferPrompt:!0,...C?.length?{images:C}:{},...eT?{provider:eT.provider,modelId:eT.modelId}:{},..."auto"!==ex?{thinkingLevel:ex}:{}})}),a=await r.json().catch(()=>({}));if(!r.ok||a.error||!a.sessionId)throw Error(a.error??`HTTP ${r.status}`);let l=a.sessionId;eY.current=l;let i=e6.current.get(y);i&&(i.sessionId=l),e0.current?.(),e0.current=S(l,()=>{eY.current===l&&(ep(!1),eq(null))}),te.current=l,await tx(l,{requireConnected:!0,timeoutMs:1e4}),await (0,s.$)(l,{type:"prompt",message:c,toolNames:t,planMode:d,...C?.length?{images:C}:{}}),m?.({id:l,path:"",cwd:n,name:void 0,created:new Date().toISOString(),modified:new Date().toISOString(),messageCount:1,firstMessage:e})}else if(t){let e=o??th();await tw(t.id),e0.current?.(),e0.current=S(t.id,()=>{eY.current===t.id&&(ep(!1),eq(null))}),await tx(t.id,{requireConnected:!0,timeoutMs:1e4}),await (0,s.$)(t.id,{type:"prompt",message:c,toolNames:e,planMode:d,leafId:v,...tf?{provider:tf.provider,modelId:tf.modelId}:{},..."auto"!==ex?{thinkingLevel:ex}:{},...C?.length?{images:C}:{}})}}catch(t){let e=eY.current;if(e6.current.delete(y),ee(e=>e.filter(e=>e!==h)),t instanceof s.H&&(409===t.status||"SESSION_BUSY"===t.code)){eG("This session is already running in another tab. Showing that active run instead."),eQ.current=!0,ep(!0),eq({kind:"waiting_model"}),ec({type:"start"}),e&&(eV.current?.close(),eV.current=null,x(e),tx(e,{replay:!0}),eZ.current?.(e,"prompt_conflict"));return}if(console.error("Failed to send message:",t),J&&eY.current){let e=eY.current;eY.current=null,te.current=null,fetch(`/api/sessions/${encodeURIComponent(e)}`,{method:"DELETE"}).catch(()=>{})}eG(t instanceof Error?t.message:String(t)),eV.current?.close(),eV.current=null,e&&_(e),eQ.current=!1,ep(!1),eq(null),ec({type:"end"})}finally{tc.current=!1,"u">typeof document&&"hidden"===document.visibilityState&&!tu.current&&(tu.current=setTimeout(()=>{tu.current=null,"hidden"!==document.visibilityState||tc.current||(eV.current?.close(),eV.current=null)},1e3))}},[J,n,eT,th,ex,t,B?.info?.cwd,ed,tx,m,ty,d,eg,tf,tw]),tA=(0,r.useCallback)(async()=>{let e=eY.current;if(e){eQ.current=!1,eG(null),ep(!1),eq(null),ec({type:"end"}),eV.current?.close(),eV.current=null,_(e),R(e);try{await (0,s.$)(e,{type:"abort"}),await tC(e,!1,!1,!0)}catch(t){console.error("Failed to abort:",t),await tC(e,!1,!1,!0)}}},[tC]),t$=(0,r.useCallback)(async e=>{let t=eY.current;if(t){eP(e);try{let{cancelled:n,newSessionId:r}=await (0,s.$)(t,{type:"fork",entryId:e})??{};!n&&r&&g?.(r)}catch(e){console.error("Fork failed:",e)}finally{eP(null)}}},[g]),tR=(0,r.useCallback)(async e=>{let t=eY.current;t&&(R(t),e8.current=e,X(e),await tS(t,e))},[tS]),tD=(0,r.useCallback)(async e=>{e8.current=e,X(e);let t=eY.current;t&&(R(t),await tS(t,e))},[tS]),tL=(0,r.useCallback)(async(e,t)=>{if(J)return void td({provider:e,modelId:t});let n=eY.current;if(n)try{var r;eG(null);let a=await (0,s.$)(n,{type:"set_model",provider:e,modelId:t}),o={provider:a.provider,modelId:a.id};a.thinkingLevel&&(r=a.thinkingLevel,"auto"===r||"off"===r||"minimal"===r||"low"===r||"medium"===r||"high"===r||"xhigh"===r)&&eM(a.thinkingLevel),ej(o),q(e=>e?{...e,context:{...e.context,model:o}}:e)}catch(t){let e=t instanceof Error?t.message:String(t);console.error("Failed to set model:",t),eG(e)}},[J,td]),tN=(0,r.useCallback)(async()=>{let e=eY.current;if(e&&!eH){eK(!0),eJ(null);try{await (0,s.$)(e,{type:"compact"}),await tC(e,!0)}catch(e){eJ(e instanceof Error?e.message:String(e))}finally{eK(!1)}}},[eH,tC]),tP=(0,r.useCallback)(async(e,t,n)=>{let r=eY.current;if(!r)return;R(r);let a=ty(n),o=e.trim()?a?`${e}
|
|
11
|
-
|
|
12
|
-
Attached document text:
|
|
13
|
-
|
|
14
|
-
${a}`:e:a?`Attached document text:
|
|
15
|
-
|
|
16
|
-
${a}`:"",l=eg.find(e=>e.provider===tf?.provider&&e.id===tf?.modelId)?.input,i=!l||0===l.length||l.includes("image")?t?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType})):void 0,u={role:"user",content:`[steer] ${o}`,timestamp:Date.now()},c=U(),d=O(o,i?.length??0);e6.current.set(c,{localId:c,sessionId:r,leafId:e8.current,message:u,createdAt:Date.now(),kind:"steer",confirmKey:d,confirmCountAtCreate:d?e7.current.get(d)??0:0}),ee(e=>[...e,u]);try{await (0,s.$)(r,{type:"steer",message:o,...i?.length?{images:i}:{}})}catch(e){e6.current.delete(c),console.error("Failed to steer:",e)}},[ty,eg,tf]),tU=(0,r.useCallback)(async(e,t,n)=>{let r=eY.current;if(!r)return;R(r);let a=ty(n),o=e.trim()?a?`${e}
|
|
17
|
-
|
|
18
|
-
Attached document text:
|
|
19
|
-
|
|
20
|
-
${a}`:e:a?`Attached document text:
|
|
21
|
-
|
|
22
|
-
${a}`:"",l=eg.find(e=>e.provider===tf?.provider&&e.id===tf?.modelId)?.input,i=!l||0===l.length||l.includes("image")?t?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType})):void 0,u={role:"user",content:o,timestamp:Date.now()},c=U(),d=O(o,i?.length??0);e6.current.set(c,{localId:c,sessionId:r,leafId:e8.current,message:u,createdAt:Date.now(),kind:"follow_up",confirmKey:d,confirmCountAtCreate:d?e7.current.get(d)??0:0}),ee(e=>[...e,u]);try{await (0,s.$)(r,{type:"follow_up",message:o,...i?.length?{images:i}:{}})}catch(e){e6.current.delete(c),console.error("Failed to follow up:",e)}},[ty,eg,tf]),tj=(0,r.useCallback)(async()=>{let e=eY.current;if(e)try{await (0,s.$)(e,{type:"abort_compaction"})}catch(e){console.error("Failed to abort compaction:",e)}},[]),tO=(0,r.useCallback)(async e=>{if(eM(e),"auto"===e)return;let t=eY.current;if(t)try{await (0,s.$)(t,{type:"set_thinking_level",level:e})}catch(e){console.error("Failed to set thinking level:",e)}},[]),tF=(0,r.useCallback)(async e=>{tp(e);let t=(0,D.tE)(e,eS),n=eY.current;if(n)try{await (0,s.$)(n,{type:"set_tools",toolNames:t})}catch(e){console.error("Failed to set tools:",e)}},[eS,tp]),tH=(0,r.useCallback)(async e=>{tm(e);let t=(0,D.tE)(ek,e),n=eY.current;if(n)try{await (0,s.$)(n,{type:"set_tools",toolNames:t})}catch(e){console.error("Failed to set memory tools:",e)}},[tm,ek]),tK=(0,r.useCallback)((e="smooth")=>{e5.current?.scrollIntoView({behavior:e})},[]),tW=(0,r.useCallback)(()=>{let e=e2.current,t=e3.current;if(!e||!t)return;let n=t.getBoundingClientRect().top-e.getBoundingClientRect().top+e.scrollTop;e.scrollTo({top:n-16,behavior:"smooth"})},[]);return(0,r.useEffect)(()=>{if(t){var e;let n;if(eY.current=t.id,t.id===te.current)return te.current=null,()=>{tl.current&&clearTimeout(tl.current),tl.current=null,eV.current?.close(),eV.current=null,e0.current?.(),e0.current=null};ta.current=!1,tr.current=0;let r=(e=t.id,(n=f().get(e))&&"idle"!==n.snapshot.phase?n.snapshot:null);r?.phase==="active"&&(eQ.current=!0,ep(!0),eq({kind:"waiting_model"}),ec({type:"start"})),(async()=>{let e=await tC(t.id,!0,!0,!0);eY.current===t.id&&(await t_(t.id),e?.running?(eQ.current=!0,ep(!0),eq(a(e.state)),ec({type:"start"}),N()&&tx(t.id,{replay:!0}),e0.current?.(),e0.current=S(t.id,()=>{eY.current===t.id&&eZ.current?.(t.id,"stream_watchdog")})):e&&r?.phase==="active"?(eQ.current=!1,ep(!1),eq(null),ec({type:"end"}),_(t.id)):e||r?.phase!=="active"||eZ.current?.(t.id,"mount_state_load_failed"),e?.state&&(void 0!==e.state.isCompacting&&eK(e.state.isCompacting),void 0!==e.state.contextUsage&&eR(e.state.contextUsage??null),void 0!==e.state.systemPrompt&&eL(e.state.systemPrompt??null),void 0!==e.state.thinkingLevel&&eM(e.state.thinkingLevel??"auto"),void 0!==e.state.planMode&&W?.(e.state.planMode)))})()}return()=>{te.current&&eY.current===te.current||(tl.current&&clearTimeout(tl.current),tl.current=null,ti.current?.controller.abort(P("Session changed","AbortError")),ti.current=null,eV.current?.close(),eV.current=null,e0.current?.(),e0.current=null)}},[tx,tC,t_,M,W,t]),(0,r.useEffect)(()=>{let e=()=>{tu.current&&(clearTimeout(tu.current),tu.current=null)},t=()=>{e();let t=eY.current;t&&tM(t,"foreground")},n=()=>{e(),tu.current=setTimeout(()=>{tu.current=null,"hidden"!==document.visibilityState||tc.current||(eV.current?.close(),eV.current=null)},1e3)},r=()=>{"visible"===document.visibilityState?t():n()};return document.addEventListener("visibilitychange",r),window.addEventListener("focus",t),window.addEventListener("online",t),"hidden"===document.visibilityState&&n(),()=>{e(),document.removeEventListener("visibilitychange",r),window.removeEventListener("focus",t),window.removeEventListener("online",t)}},[tM]),(0,r.useEffect)(()=>{let e=eY.current;if(e)return to.current=!1,(0,c.O)(t=>{let n=t.includes(e),r=to.current;to.current=n,n&&!eQ.current?(R(e),tM(e,"running_feed_start")):!n&&r&&(R(e),eQ.current?tM(e,"running_feed_stop"):tC(e,!1,!1,!0))})},[tC,tM,t?.id]),(0,r.useEffect)(()=>{let e=window.setInterval(()=>{let e=eY.current;e&&(eQ.current?tM(e,"interval"):Date.now()-ts.current>=3e4?(ts.current=Date.now(),R(e),tC(e,!1,!1,!0)):tC(e))},15e3);return()=>window.clearInterval(e)},[tC,tM]),(0,r.useEffect)(()=>{M&&M(B?.tree??[],Q,tD)},[B?.tree,Q,tD,M]),(0,r.useEffect)(()=>{Z.length>0&&!tn.current&&(e4.current?(e4.current=!1,e1.current=!0,tW()):e1.current?eQ.current||tK("smooth"):(e1.current=!0,tK("instant")))},[Z.length,ed,tK,tW]),(0,r.useEffect)(()=>{fetch("/api/models").then(e=>e.json()).then(e=>{if(ef(e.models),e.thinkingLevels&&ew(e.thinkingLevels),e.thinkingLevelMaps&&eb(e.thinkingLevelMaps),e.modelList&&(eh(e.modelList),J&&e.modelList.length>0)){let t=e.defaultModel,n=t&&e.modelList.find(e=>e.id===t.modelId&&e.provider===t.provider);td(n?{provider:n.provider,modelId:n.id}:{provider:e.modelList[0].provider,modelId:e.modelList[0].id})}}).catch(()=>{})},[J,b,td]),(0,r.useEffect)(()=>{if(!eW)return;let e=setTimeout(()=>eJ(null),3e3);return()=>clearTimeout(e)},[eW]),{data:B,loading:z,error:V,activeLeafId:Q,messages:Z,entryIds:et,streamState:eu,agentRunning:ed,modelNames:em,modelList:eg,modelThinkingLevels:ey,modelThinkingLevelMaps:ev,newSessionModel:eT,toolPreset:ek,memoryTools:eS,thinkingLevel:ex,retryInfo:eE,contextUsage:e$,systemPrompt:eD,forkingEntryId:eN,isCompacting:eH,compactError:eW,currentModel:tf,displayModel:tg,sessionStats:tv,agentPhase:eB,agentError:ez,isNew:J,sessionIdRef:eY,sseReaderRef:eV,messagesEndRef:e5,scrollContainerRef:e2,lastUserMsgRef:e3,pendingScrollToUserRef:e4,initialScrollDoneRef:e1,handleSend:tE,handleAbort:tA,handleFork:t$,handleNavigate:tR,handleModelChange:tL,handleCompact:tN,handleSteer:tP,handleFollowUp:tU,handleAbortCompaction:tj,handleToolPresetChange:tF,handleMemoryToolsChange:tH,handleThinkingLevelChange:tO,loadTools:t_,setActiveLeafId:X,setData:q,setMessages:ee,dispatch:ec,setAgentRunning:ep,setForkingEntryId:eP,loadMoreMessages:tI,hasMoreMessages:eo,totalMessages:er,loadedMessagesCount:el,handleAgentEventRef:eX}}},14755:(e,t,n)=>{n.d(t,{ES:()=>p,IB:()=>m,SN:()=>a,tE:()=>f,xG:()=>d});let r="subagent",a=["retain","recall","reflect"],o=[],s=["read","bash","edit","write"],l=["bash","read","edit","write","grep","find","ls"],i=[...l,"kernel_plot_run","kernel_plot_render","kernel_plot_inspect","kernel_plot_stop","kernel_plot_artifacts"],u=[...l,r];function c(e){return[...e].sort().join(",")}function d(e){switch(e){case"none":return o;case"default":return s;case"workbench":return i;case"agent":return u;default:return l}}function p(e){let t=e.filter(e=>e.active).map(e=>e.name),n=t.filter(e=>!a.includes(e)),o=c(t),d=c(n);return""===o?"none":o===c(s)?"default":o===c(l)?"full":o===c(i)?"workbench":o===c(u)?"agent":""===d?"none":d===c(s)?"default":d===c(l)?"full":d===c(i)?"workbench":d===c(u)||t.includes(r)?"agent":"default"}function m(e){return a.filter(t=>e.some(e=>e.active&&e.name===t))}function f(e,t){return[...new Set([...d(e),...t])]}},16865:(e,t,n)=>{n.d(t,{O:()=>w});let r=new Set,a=null,o=null,s=null,l=null,i=null,u=!1,c=!1;function d(e){for(let t of(a=[...new Set(e.filter(e=>"string"==typeof e))],r))try{t(a)}catch{}}async function p(){try{let e=await fetch("/api/agent/running",{cache:"no-store"});if(!e.ok)return;let t=await e.json();Array.isArray(t.runningSessionIds)&&d(t.runningSessionIds)}catch{}}function m(){s||0===r.size||(p(),s=setInterval(()=>{p()},5e3))}function f(){s&&(clearInterval(s),s=null)}function g(){if(!u){if(u=!0,window.__annovibeRunningSessionSubscribe){i=window.__annovibeRunningSessionSubscribe(d);return}if("u"<typeof SharedWorker)return void m();try{(o=new SharedWorker("/running-session-worker.js?v=1",{name:"annovibe-running-sessions-v1",type:"classic"})).port.onmessage=e=>{let t=e.data;"transport"===t.type?m():"running"===t.type&&Array.isArray(t.runningSessionIds)&&(l&&clearTimeout(l),l=null,f(),d(t.runningSessionIds.filter(e=>"string"==typeof e)))},o.onerror=()=>m(),o.port.start(),o.port.postMessage({type:"subscribe"}),l=setTimeout(()=>m(),3e3)}catch{o=null,m()}}}function h(){if(u){if(u=!1,l&&clearTimeout(l),l=null,f(),i?.(),i=null,o){try{o.port.postMessage({type:"disconnect"})}catch{}try{o.port.close()}catch{}}o=null,a=null}}function y(){r.size>0&&g()}function w(e){return r.add(e),a&&e(a),c||(c=!0,window.addEventListener("pagehide",h),window.addEventListener("pageshow",y)),g(),()=>{r.delete(e),0===r.size&&(h(),c&&(c=!1,window.removeEventListener("pagehide",h),window.removeEventListener("pageshow",y)))}}},32383:(e,t,n)=>{n.d(t,{$:()=>a,H:()=>r});class r extends Error{constructor(e,t,n){super(e),this.status=t,this.code=n,this.name="AgentCommandError"}}async function a(e,t){let n=await fetch(`/api/agent/${encodeURIComponent(e)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),a=await n.json().catch(()=>({}));if(!n.ok||a.error)throw new r(a.error??`HTTP ${n.status}`,n.status,a.code);return a.data}}}]);
|
|
File without changes
|
|
File without changes
|