@seqyuan/annovibe 0.8.140 → 0.8.142
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 +10 -10
- package/.next/build-manifest.json +3 -3
- package/.next/prerender-manifest.json +3 -3
- package/.next/react-loadable-manifest.json +11 -11
- 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/_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/_not-found/__PAGE__.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 +5 -5
- package/.next/server/app/index.segments/__PAGE__.segment.rsc +5 -5
- package/.next/server/app/index.segments/_full.segment.rsc +5 -5
- 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/_tree.segment.rsc +1 -1
- package/.next/server/app/login.segments/login/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/page.js +13 -13
- 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.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 +4 -4
- package/.next/server/app/smoke/session-stream.segments/_full.segment.rsc +4 -4
- 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 +4 -4
- package/.next/server/app/smoke.html +2 -2
- package/.next/server/app/smoke.rsc +2 -2
- package/.next/server/app/smoke.segments/_full.segment.rsc +2 -2
- package/.next/server/app/smoke.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/smoke.segments/smoke/__PAGE__.segment.rsc +2 -2
- package/.next/server/app-paths-manifest.json +10 -10
- package/.next/server/chunks/1649.js +1 -0
- package/.next/server/chunks/658.js +22 -0
- package/.next/server/chunks/8305.js +2 -2
- package/.next/server/middleware-build-manifest.js +1 -1
- package/.next/server/middleware-react-loadable-manifest.js +1 -1
- package/.next/server/middleware.js +4 -4
- package/.next/server/next-font-manifest.js +1 -1
- package/.next/server/next-font-manifest.json +1 -1
- package/.next/server/pages/404.html +1 -1
- package/.next/server/pages/500.html +1 -1
- package/.next/server/preview-props.json +3 -3
- package/.next/server/server-reference-manifest.json +1 -1
- package/.next/static/chunks/2708.6503b5c105cc1420.js +1 -0
- package/.next/static/chunks/3824-6bb3afa7d2fc5f09.js +22 -0
- package/.next/static/chunks/{5618-8aecfc54df369be5.js → 5618-db41ee0c172d3add.js} +1 -1
- package/.next/static/chunks/app/page-2e0bf200ed41d4f6.js +22 -0
- package/.next/static/chunks/app/smoke/session-stream/{page-9c9a9a2aafa69000.js → page-ce422d02fbbe900d.js} +2 -2
- package/.next/static/chunks/c66d966b.4add33ed4e764123.js +1 -0
- package/.next/static/chunks/{webpack-36fa69ae1e15e7ce.js → webpack-19f3f7824a602f3b.js} +1 -1
- package/package.json +3 -3
- package/.next/server/chunks/7734.js +0 -22
- package/.next/server/chunks/7765.js +0 -1
- package/.next/static/chunks/2170a4aa.4301f7c49f3f0a6e.js +0 -1
- package/.next/static/chunks/2257-a948751c1a3d4608.js +0 -22
- package/.next/static/chunks/8436.cab94b59cca0a8ff.js +0 -1
- package/.next/static/chunks/app/page-b9bbcb2073e77894.js +0 -22
- /package/.next/static/{YRLT_dWnNGA0kvsTREpEW → ZpLecbnV0af9eeGcGwT88}/_buildManifest.js +0 -0
- /package/.next/static/{YRLT_dWnNGA0kvsTREpEW → ZpLecbnV0af9eeGcGwT88}/_ssgManifest.js +0 -0
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[2257],{12257:(e,t,n)=>{n.d(t,{T:()=>Q});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}}let s={isStreaming:!1,streamingMessage:null};function l(){return{role:"assistant",content:[],model:"",provider:"",timestamp:Date.now()}}function i(e,t,n){if(!Number.isInteger(t)||void 0===t||t<0)return e;let r=e.streamingMessage??l(),a=[...r.content],o=n(a[t]);return o?(a[t]=o,{isStreaming:!0,streamingMessage:{...r,content:a}}):e}function u(e){if(e.id||e.toolName)return{...e.id?{id:e.id}:{},...e.toolName?{toolName:e.toolName}:{}};let t=e.partial,n=e.contentIndex;if(!t||!Array.isArray(t.content)||void 0===n)return{};let r=t.content[n];return r&&"toolCall"===r.type?{..."string"==typeof r.id?{id:r.id}:"string"==typeof r.toolCallId?{id:r.toolCallId}:{},..."string"==typeof r.name?{toolName:r.name}:"string"==typeof r.toolName?{toolName:r.toolName}:{}}:{}}function c(e,t){switch(t.type){case"start":return{isStreaming:!0,streamingMessage:null};case"snapshot":return"assistant"===t.message.role?{isStreaming:!0,streamingMessage:t.message}:e;case"delta":var n=t.event;switch(n.type){case"start":return{isStreaming:!0,streamingMessage:e.streamingMessage??l()};case"text_start":return i(e,n.contentIndex,e=>e?.type==="text"?e:{type:"text",text:""});case"text_delta":return i(e,n.contentIndex,e=>({type:"text",text:(e?.type==="text"?e.text:"")+(n.delta??"")}));case"text_end":return i(e,n.contentIndex,e=>({type:"text",text:n.content??(e?.type==="text"?e.text:"")}));case"thinking_start":return i(e,n.contentIndex,e=>e?.type==="thinking"?e:{type:"thinking",thinking:""});case"thinking_delta":return i(e,n.contentIndex,e=>({type:"thinking",thinking:(e?.type==="thinking"?e.thinking:"")+(n.delta??"")}));case"thinking_end":return i(e,n.contentIndex,e=>({type:"thinking",thinking:n.content??(e?.type==="thinking"?e.thinking:"")}));case"toolcall_start":return i(e,n.contentIndex,e=>{let t=u(n);return e?.type==="toolCall"?{...e,...t.id?{toolCallId:t.id}:{},...t.toolName?{toolName:t.toolName}:{},rawInput:e.rawInput??""}:{type:"toolCall",toolCallId:t.id??"",toolName:t.toolName??"tool",input:{},rawInput:""}});case"toolcall_delta":return i(e,n.contentIndex,e=>{let t=u(n),r=e?.type==="toolCall"?e:{type:"toolCall",toolCallId:t.id??"",toolName:t.toolName??"tool",input:{}};return{...r,...t.id?{toolCallId:t.id}:{},...t.toolName?{toolName:t.toolName}:{},rawInput:(r.rawInput??"")+(n.delta??"")}});case"toolcall_end":return i(e,n.contentIndex,()=>({type:"toolCall",toolCallId:n.toolCall?.id??"",toolName:n.toolCall?.name??"tool",input:n.toolCall?.arguments??{}}));default:return e}case"end":case"reset":return s;default:return e}}function d(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function p(e){if("assistant"!==e.role)return null;let t=e.timestamp;return"number"!=typeof t?null:`assistant:${t}`}class m extends Error{constructor(e,t,n){super(e),this.status=t,this.code=n,this.name="AgentCommandError"}}async function f(e,t){let n=await fetch(`/api/agent/${encodeURIComponent(e)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),r=await n.json().catch(()=>({}));if(!n.ok||r.error)throw new m(r.error??`HTTP ${n.status}`,n.status,r.code);return r.data}var g=n(28999);async function h(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 y(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 w=n(16865);let k="__annovibeStreamSessions__",v="__annovibeStreamListeners__",b="__annovibeStreamErrorCallbacks__";function C(){let e=globalThis;return e[k]||(e[k]=new Map),e[k]}function x(){let e=globalThis;return e[b]||(e[b]=new Map),e[b]}function _(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 T(e,t){let n;for(let r of(!(n=globalThis)[v]&&(n[v]=new Map),n[v]).get(e)??[])try{r(t)}catch{}}function I(e){e.textThrottleTimer&&(clearTimeout(e.textThrottleTimer),e.textThrottleTimer=null),e.textDirty&&(e.textDirty=!1,M(e))}function S(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,M(e))},100));return}I(e),M(e)}function M(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},T(e.snapshot.sessionId,{type:"snapshot-updated",snapshot:e.snapshot})}function A(e){E(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){R(e),I(e);let t="Stream idle timeout — no activity for 180s.";e.snapshot={...e.snapshot,phase:"error",isStreaming:!1,streamingMessage:null,statusText:null,error:t},E(e),T(e.snapshot.sessionId,{type:"error",snapshot:e.snapshot});let n=x().get(e.snapshot.sessionId);if(n)try{n(e.snapshot.sessionId,t)}catch{}}},1e4)}function E(e){e.idleCheckTimer&&(clearInterval(e.idleCheckTimer),e.idleCheckTimer=null)}function R(e){e.toolProgressTimer&&(clearInterval(e.toolProgressTimer),e.toolProgressTimer=null)}function $(e){let t=C(),n=t.get(e);return n||(n={snapshot:_(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 N(e,t){let n=x();return n.set(e,t),()=>{n.get(e)===t&&n.delete(e)}}function D(e){let t=C(),n=t.get(e);n&&(R(n),E(n),I(n)),t.delete(e)}function L(e){let t=C().get(e);t&&(t.snapshot={...t.snapshot,reconnectCount:t.snapshot.reconnectCount+1,lastSyncReason:"sse-reconnect",lastEventAt:Date.now()},S(t,!0))}let U="__annovibeSessionMessageCache__";function P(){let e=globalThis;if(!e[U]){var t;let n={entries:new Map,cleanupTimer:null};e[U]=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[U]}function j(e){let t=P(),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 O(e,t,n,r,a){let o=P(),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 F(e){P().entries.delete(e)}var q=n(14755);function H(e){return{steering:e?.steering??[],followUp:e?.followUp??[]}}let B=[500,1500,3e3];function W(e,t){return new DOMException(e,t)}function J(){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)}`}function K(e,t){return e.trim()||0!==t?`text:${e}|images:${t}`:null}function z(e){return"string"==typeof e?K(e,0):Array.isArray(e)?K(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 G(e){let t=new Map;for(let n of e){let e="user"!==n.role?null:z(n.content);e&&t.set(e,(t.get(e)??0)+1)}return t}function V(e,t,n){return e.sessionId===t&&(!e.leafId||n.includes(e.leafId))}function Y(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}}function Q(e){let{session:t,newSessionCwd:n,onAgentEnd:l,onSessionCreated:i,onSessionForked:u,modelsRefreshKey:k,onBranchDataChange:v,chatInputRef:b}=e,x=null===t&&null!==n,[M,U]=(0,r.useState)(null),[Q,X]=(0,r.useState)(!x),[Z,ee]=(0,r.useState)(null),[et,en]=(0,r.useState)(null),[er,ea]=(0,r.useState)([]),[eo,es]=(0,r.useState)([]),[el,ei]=(0,r.useState)(0),[eu,ec]=(0,r.useState)(!1),[ed,ep]=(0,r.useState)(0),[em,ef]=(0,r.useReducer)(c,s),[eg,eh]=(0,r.useState)(!1),[ey,ew]=(0,r.useState)({}),[ek,ev]=(0,r.useState)([]),[eb,eC]=(0,r.useState)({}),[ex,e_]=(0,r.useState)({}),[eT,eI]=(0,r.useState)(null),[eS,eM]=(0,r.useState)("full"),[eA,eE]=(0,r.useState)([...q.SN]),[eR,e$]=(0,r.useState)([]),[eN,eD]=(0,r.useState)(null),[eL,eU]=(0,r.useState)(!1),[eP,ej]=(0,r.useState)("auto"),[eO,eF]=(0,r.useState)(null),[eq,eH]=(0,r.useState)(null),[eB,eW]=(0,r.useState)(null),[eJ,eK]=(0,r.useState)(null),[ez,eG]=(0,r.useState)(null),[eV,eY]=(0,r.useState)(null),[eQ,eX]=(0,r.useState)(!1),[eZ,e0]=(0,r.useState)(null),[e1,e3]=(0,r.useState)(null),[e4,e5]=(0,r.useState)(null),[e2,e6]=(0,r.useState)({steering:[],followUp:[]}),[e8,e7]=(0,r.useState)(null),e9=(0,r.useRef)(null),te=(0,r.useRef)(t?.id??null),{statuses:tt,widgets:tn,dialog:tr,notices:ta,applyFromState:to,handleEvent:ts,respond:tl,dismissNotice:ti}=function({chatInputRef:e,sessionIdRef:t,onError:n,noticeTtlMs:a=8e3}){let[o,s]=(0,r.useState)([]),[l,i]=(0,r.useState)([]),[u,c]=(0,r.useState)(null),[d,p]=(0,r.useState)([]),m=(0,r.useRef)(new Set),g=(0,r.useCallback)(()=>{for(let e of m.current)clearTimeout(e);m.current.clear()},[]);(0,r.useEffect)(()=>g,[g]);let h=(0,r.useCallback)((e,t)=>{let n={id:`${Date.now()}-${Math.random().toString(36).slice(2,8)}`,message:e,type:t};p(e=>[...e,n].slice(-4));let r=setTimeout(()=>{m.current.delete(r),p(e=>e.filter(e=>e.id!==n.id))},a);m.current.add(r)},[a]),y=(0,r.useCallback)(e=>{e&&(Array.isArray(e.extensionStatuses)&&s(e.extensionStatuses),Array.isArray(e.extensionWidgets)&&i(e.extensionWidgets))},[]),w=(0,r.useCallback)(t=>{if("extension_error"===t.type)return h("string"==typeof t.error?t.error:"Extension command failed","error"),!0;if("extension_ui_request"!==t.type)return!1;let n="string"==typeof t.method?t.method:"";if("select"===n||"confirm"===n||"input"===n||"editor"===n)return c({id:String(t.id??""),method:n,title:"string"==typeof t.title?t.title:"",...Array.isArray(t.options)?{options:t.options}:{},..."string"==typeof t.message?{message:t.message}:{},..."string"==typeof t.placeholder?{placeholder:t.placeholder}:{},..."string"==typeof t.prefill?{prefill:t.prefill}:{}}),!0;if("notify"===n){let e="warning"===t.notifyType||"error"===t.notifyType?t.notifyType:"info";return h(String(t.message??""),e),!0}if("setStatus"===n){let e=String(t.statusKey??"");if(!e)return!0;let n="string"==typeof t.statusText?t.statusText:null;return s(t=>{let r=t.filter(t=>t.key!==e);return n?[...r,{key:e,text:n}]:r}),!0}if("setWidget"===n){let e=String(t.widgetKey??"");if(!e)return!0;let n=Array.isArray(t.widgetLines)?t.widgetLines.filter(e=>"string"==typeof e):null;return i(r=>{let a=r.filter(t=>t.key!==e);return n&&n.length>0?[...a,{key:e,lines:n,placement:"string"==typeof t.widgetPlacement?t.widgetPlacement:"aboveEditor"}]:a}),!0}return"dismiss"===n?c(e=>e?.id===t.id?null:e):"set_editor_text"===n&&"string"==typeof t.text?e?.current?.setText?.(t.text):"setTitle"===n&&"string"==typeof t.title&&(document.title=t.title),!0},[e,h]),k=(0,r.useCallback)(async(e,r)=>{let a=t.current;if(c(t=>t?.id===e?null:t),a)try{await f(a,{type:"extension_ui_response",id:e,...r})}catch(e){n(e instanceof Error?e.message:String(e))}},[n,t]);return{statuses:o,widgets:l,dialog:u,notices:d,applyFromState:y,handleEvent:w,respond:k,dismissNotice:(0,r.useCallback)(e=>{p(t=>t.filter(t=>t.id!==e))},[]),reset:(0,r.useCallback)(()=>{g(),s([]),i([]),c(null),p([])},[g])}}({chatInputRef:b,sessionIdRef:te,onError:e7}),tu=(0,r.useRef)(!1),tc=(0,r.useRef)(null),td=(0,r.useRef)(null),tp=(0,r.useRef)(null),tm=(0,r.useRef)(!1),tf=(0,r.useRef)(null),tg=(0,r.useRef)(!1),th=(0,r.useRef)(null),ty=(0,r.useRef)(null),tw=(0,r.useRef)(new Map),tk=(0,r.useRef)(new Map),tv=(0,r.useRef)(new Map),tb=(0,r.useRef)(new Map),tC=(0,r.useRef)(null),tx=(0,r.useRef)([]),t_=(0,r.useRef)(null),tT=(0,r.useRef)(0),tI=(0,r.useRef)(!1),tS=(0,r.useRef)(0),tM=(0,r.useRef)(!1),tA=(0,r.useRef)(!1),tE=(0,r.useRef)(0),tR=(0,r.useRef)(null),t$=(0,r.useRef)(null),tN=(0,r.useRef)(0),tD=(0,r.useRef)(!1),tL=(0,r.useRef)(!1),tU=(0,r.useRef)(""),tP=(0,r.useRef)(null);(0,r.useEffect)(()=>{tC.current=et},[et]),(0,r.useEffect)(()=>{tD.current=em.isStreaming},[em.isStreaming]),(0,r.useEffect)(()=>{tb.current.clear()},[t?.id]);let tj=e.setNewSessionModel??eI,tO=e.setToolPreset??eM,tF=e.setMemoryTools??eE,tq=ez??M?.context.model??eV??null,tH=x?eT:tq,tB=(0,r.useCallback)(()=>(0,q.tE)(eS,eA),[eA,eS]),tW=(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"):"",[]),tJ=(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})`)},[]),tK=(()=>{let e={input:0,output:0,cacheRead:0,cacheWrite:0};for(let t of er){if("assistant"!==t.role)continue;let n=t.usage;n&&(e.input+=n.input??0,e.output+=n.output??0,e.cacheRead+=n.cacheRead??0,e.cacheWrite+=n.cacheWrite??0)}return e.input+e.output+e.cacheRead+e.cacheWrite>0?{tokens:e}:null})(),tz=(0,r.useRef)(!1),tG=(0,r.useCallback)(async()=>{let e=te.current;if(!e||tz.current||tM.current)return;tz.current=!0,tI.current=!0;let t=0,n=j(e);t=n?n.loadedMessagesCount:50;try{for(;;)try{let n=await fetch(`/api/sessions/${encodeURIComponent(e)}?limit=100&offset=${t}&deferThinking=1&deferMedia=1`);if(!n.ok)break;let r=await n.json();if(te.current!==e)break;let a=r.context.messages,o=r.context.entryIds??[];if(0===a.length)break;ea(e=>[...a,...e]),es(e=>{let t=[...o,...e];return tx.current=t,t});let s=t+a.length;if(ep(s),tS.current=s,ec(r.hasMore??!1),O(e,a,o,r.hasMore??!1,s),t=s,!r.hasMore)break;await new Promise(e=>setTimeout(e,800))}catch{break}}finally{tz.current=!1,tM.current=!0,tI.current=!1}},[]),tV=(0,r.useCallback)(async(e,t=!1,n=!1,r=!1)=>{var a;let o=null;try{if(t&&X(!0),!n&&!tu.current&&!r){let n=j(e);if(n)return ei(n.totalMessages),ec(n.hasMore),ep(n.loadedMessagesCount),ea(n.messages),tx.current=n.entryIds,es(n.entryIds),tC.current=n.leafId,en(n.leafId),tS.current=n.loadedMessagesCount,t&&X(!1),n.hasMore&&!tM.current&&setTimeout(()=>{tG()},1500),null}let s=n?`/api/sessions/${encodeURIComponent(e)}?includeState&deferThinking=1&deferMedia=1`:`/api/sessions/${encodeURIComponent(e)}?limit=50&offset=0&deferThinking=1&deferMedia=1`,l=t$.current;if(l?.sid===e&&!t)return null;l?.controller.abort(W("Session load superseded","AbortError"));let i=new AbortController;o=i,t$.current={sid:e,controller:i};let u=setTimeout(()=>{i.abort(W("Session load timed out after 30 seconds","TimeoutError"))},3e4),c=await fetch(s,{signal:i.signal}).finally(()=>clearTimeout(u));if(te.current&&te.current!==e)return null;if(404===c.status)return t&&(U(null),tC.current=null,en(null),ea([]),ee(null)),null;if(!c.ok)throw Error(`HTTP ${c.status}`);let d=await c.json();n?(ei(d.totalMessages??d.context.messages.length),ec(!1)):(ei(d.totalMessages??d.context.messages.length),ec(d.hasMore??!1)),ep(d.context.messages.length),U(d),tC.current=d.leafId,en(d.leafId);let m=d.context.messages,f=G(m),g=new Map,h=Date.now();for(let[t,n]of tw.current)if(n.sessionId===e){if(h-n.createdAt>12e4){tw.current.delete(t);continue}if(n.confirmKey){let e=f.get(n.confirmKey)??0,r=g.get(n.confirmKey)??0;e-r>n.confirmCountAtCreate&&(tw.current.delete(t),g.set(n.confirmKey,r+1))}}tk.current=f;let y=d.context.entryIds??[],w=[...tw.current.values()].filter(t=>V(t,e,y)).map(e=>e.message),k=w.length>0?[...m,...w]:m,v=function(e,t,n){if(0===t.size)return e;let r=!1,a=e.map(e=>{let a=p(e);if(!a)return e;let o=t.get(a);return o?n-o.observedAt>5e3||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}}(o.message,e)?(t.delete(a),e):(r=!0,o.message):e});return r?a:e}(k,tb.current,Date.now()),b=tv.current.get(e);if(b){for(let[e,t]of b)h-t>12e4&&b.delete(e);0===b.size&&tv.current.delete(e)}let C=b?.size?b:null,x=C?new Set(y):null,_=!!C&&!!x&&[...C.keys()].some(e=>!x.has(e));C&&x&&!_&&tv.current.delete(e);let T=v.length;return!n&&(tS.current>T||_)?(ei(d.totalMessages??d.context.messages.length),ec(d.hasMore??!1)):(ea(e=>(function(e,t){if(e.length!==t.length)return t;let n=!1,r=t.map((t,r)=>Y(e[r],t)?e[r]:(n=!0,t));return n?r:e})(e,v)),tx.current=y,es(y),n?tS.current=T:tS.current=Math.max(tS.current,T),a={sessionId:e,leafId:d.leafId,messages:v,entryIds:y,totalMessages:d.totalMessages??d.context.messages.length,hasMore:!n&&(d.hasMore??!1),loadedMessagesCount:d.context.messages.length},P().entries.set(e,{...a,loadedAt:Date.now()})),eG(e=>{if(!e)return null;let t=d.context.model;return t?.provider===e.provider&&t.modelId===e.modelId?null:e}),ee(null),!d.agentState?.state?.thinkingLevel&&d.context.thinkingLevel&&"off"!==d.context.thinkingLevel&&ej(d.context.thinkingLevel),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 ee(String(e)),null}finally{o&&t$.current?.controller===o&&(t$.current=null),t&&X(!1)}},[tG]),tY=(0,r.useRef)(!1),tQ=(0,r.useCallback)(async()=>{if(tY.current)return;tY.current=!0;let e=te.current;if(!e){tY.current=!1;return}try{let t=await fetch(`/api/sessions/${encodeURIComponent(e)}?limit=50&offset=${ed}&deferThinking=1&deferMedia=1`);if(!t.ok)return;let n=await t.json(),r=n.context.messages,a=n.context.entryIds??[];ea(e=>[...r,...e]),es(e=>{let t=[...a,...e];return tx.current=t,t}),ep(e=>e+r.length),ec(n.hasMore??!1),O(e,r,a,n.hasMore??!1,ed+r.length)}catch{}finally{tY.current=!1}},[ed]),tX=(0,r.useCallback)(async e=>{let t=te.current;if(!t)return[];let n=tC.current,r=n?`?leafId=${encodeURIComponent(n)}`:"";try{let n=await fetch(`/api/sessions/${encodeURIComponent(t)}/shadowed${r}`);if(!n.ok)return[];let a=await n.json(),o=a.groups?.find(t=>t.compactionEntryId===e);return o?.messages??[]}catch{return[]}},[]),tZ=(0,r.useCallback)(async(e,t)=>{try{let n=t?`/api/sessions/${encodeURIComponent(e)}/context?leafId=${encodeURIComponent(t)}&deferThinking=1&deferMedia=1`:`/api/sessions/${encodeURIComponent(e)}/context?deferThinking=1&deferMedia=1`,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=G(o),i=new Map,u=Date.now();for(let[t,n]of tw.current)if(n.sessionId===e){if(u-n.createdAt>12e4){tw.current.delete(t);continue}if(n.confirmKey){let e=l.get(n.confirmKey)??0,r=i.get(n.confirmKey)??0;e-r>n.confirmCountAtCreate&&(tw.current.delete(t),i.set(n.confirmKey,r+1))}}tk.current=l;let c=[...tw.current.values()].filter(t=>V(t,e,s)).map(e=>e.message);ea(c.length>0?[...o,...c]:o),tx.current=s,es(s)}catch(e){console.error("Failed to load context:",e)}},[]),t0=(0,r.useCallback)(async e=>{try{let t=await f(e,{type:"get_tools"});t&&(tO((0,q.ES)(t)),tF((0,q.IB)(t)))}catch(e){console.error("Failed to load tools:",e)}},[tF,tO]),t1=(0,r.useCallback)(async e=>{try{let t=await f(e,{type:"get_commands"});e$(Array.isArray(t?.commands)?t.commands:[])}catch{e$([])}},[]),t3=(0,r.useCallback)((e,t={})=>{e9.current?.close(),e9.current=null;let n=`/api/agent/${encodeURIComponent(e)}/events${t.replay?"?replay=1":""}`;return!function(e){let t=$(e);if("active"===t.snapshot.phase)return S(t,!0),A(t),t.snapshot;let n=Date.now();t.snapshot={..._(e),phase:"active",startedAt:n,lastEventAt:n,isStreaming:!0,streamingMessage:{role:"assistant",content:[]}},A(t),S(t,!0),t.snapshot}(e),new Promise((r,a)=>{let o=!1,s=!1,l=null,i=e=>{if(!o){if(o=!0,clearTimeout(u),e){l?.close(),e9.current===l&&(e9.current=null),a(e);return}r()}},u=setTimeout(()=>{t.requireConnected?i(Error("Timed out waiting for event stream connection")):i()},t.timeoutMs??3e4);e9.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,u="idle",c=new AbortController,d=0,p=null,m=null,f=!1,g=(e,t)=>{t&&(m=t),n(e,t)},h=e=>{u!==e&&(u=e,r?.(e))},w=()=>{null!==p&&(clearTimeout(p),p=null)},k=()=>{if(f)return;if(!i)return void h("error");if(d>=o){h("error"),a?.(Error(`Max reconnect attempts (${o}) reached`));return}let e=Math.min(l,s*2**d);d+=1,h("connecting"),p=setTimeout(()=>{p=null,v()},e)},v=async()=>{if(!f){w(),c=new AbortController,h("connecting");try{let e=await fetch(t,{signal:c.signal,headers:{Accept:"text/event-stream","Cache-Control":"no-cache",...m?{"Last-Event-ID":m}:{}}});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(h("connected"),d=0,await y(r,g,c.signal),c.signal.aborted)try{await r.cancel()}catch{}r.releaseLock(),h("closed"),!f&&i&&k()}catch(e){if(f||e instanceof DOMException&&"AbortError"===e.name)return void h("closed");h("error"),i&&k()}}};return{get state(){return u},connect:()=>{f=!1,d=0,w(),v()},close:()=>{f=!0,w(),c.abort(),h("closed")},get abortController(){return c}}}({url:n,onEvent:t=>{try{let n=JSON.parse(t);if("connected"===n.type&&i(),te.current!==e)return;tc.current?.(n)}catch{}},onStateChange:t=>{!function(e,t){let n=C().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()},A(n)),"connected"!==t&&"connected"===r&&E(n)}(e,t),"connected"===t&&(s&&(L(e),td.current?.(e,"sse_reconnected")),s=!0)},reconnectBaseMs:1e3,reconnectMaxMs:3e4}),l.connect()})},[]),t4=(0,r.useCallback)(async(e,t="manual")=>{if(!e||te.current!==e)return;let n=tT.current;try{let t=await fetch(`/api/agent/${encodeURIComponent(e)}`),r=await t.json().catch(()=>({}));if(te.current!==e||tT.current!==n)return;r.running?(tu.current=!0,eh(!0),e5(a(r.state)),e9.current&&"closed"!==e9.current.state&&"error"!==e9.current.state||(L(e),t3(e,{replay:!0}))):(tu.current=!1,e9.current?.close(),e9.current=null,D(e),eh(!1),e5(null),eF(null),ef({type:"end"}),F(e),await tV(e,!1,!1,!0)),r.state?.contextUsage!==void 0&&eH(r.state.contextUsage??null),r.state?.systemPrompt!==void 0&&eW(r.state.systemPrompt??null),r.state?.isCompacting!==void 0&&eX(r.state.isCompacting),r.state?.thinkingLevel!==void 0&&ej(r.state.thinkingLevel??"auto"),r.state?.queuedMessages!==void 0&&e6(H(r.state.queuedMessages)),to(r.state),r.state?.isBashRunning&&(tL.current=!0,eU(!0),eh(!0),e5({kind:"running_tools",tools:[{id:"bash",name:"bash"}]}))}catch{}},[t3,tV,to]);(0,r.useEffect)(()=>{td.current=t4},[t4]),(0,r.useEffect)(()=>{tu.current=eg},[eg]),tc.current=(0,r.useCallback)(e=>{let t=te.current;switch(t&&function(e,t){let n=$(e),r=Date.now();switch(t.type){case"agent_start":if("active"===n.snapshot.phase)return S(n,!0),n.snapshot;return R(n),n.accumulatedText="",n.toolCalls.clear(),n.toolResults.clear(),n.activeToolId=null,n.snapshot={..._(e),phase:"active",startedAt:r,lastEventAt:r,isStreaming:!0,streamingMessage:{role:"assistant",content:[]}},A(n),S(n,!0),n.snapshot;case"message_update":{let e=t.message;if(e?.role==="assistant"){let t=e.content;for(let e of Array.isArray(t)?t:[])"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}))}else{let e=t.assistantMessageEvent;e?.type==="text_delta"?n.accumulatedText+=e.delta??"":e?.type==="text_end"?n.accumulatedText=e.content??n.accumulatedText:(e?.type==="toolcall_start"||e?.type==="toolcall_delta")&&e.id&&!n.toolCalls.has(e.id)&&n.toolCalls.set(e.id,{type:"toolCall",toolCallId:e.id,toolName:e.toolName??"tool",input:{},startedAt:r})}return S(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&&Object.keys(s.input).length>0?s.input:o,startedAt:s?.startedAt??r}),n.activeToolId=e,R(n),n.activeToolId&&(n.toolProgressTimer=setInterval(()=>S(n,!0),1e3)),S(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,R(n))}return S(n,!0),n.snapshot}case"message_end":return I(n),S(n,!0),n.snapshot;case"agent_end":{if(I(n),R(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},A(n),T(e,{type:"snapshot-updated",snapshot:n.snapshot}),n.snapshot;E(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},T(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),"heartbeat"!==e.type&&(tN.current=Date.now()),e.type){case"prompt_admitted":case"agent_start":e7(null),tu.current=!0,eh(!0),e5({kind:"waiting_model"}),ef({type:"start"});break;case"agent_end":if(!0===e.willRetry){tu.current=!0,eh(!0),e5({kind:"waiting_model"});break}if(tu.current=!1,eh(!1),e5(null),eF(null),ef({type:"end"}),t){tR.current&&clearTimeout(tR.current);let e=tT.current,n=0,r=async()=>{if(te.current!==t||tu.current||tT.current!==e)return;F(t),await tV(t,!1,!1,!0);let a=B[n++];void 0===a||te.current!==t||tu.current||tT.current!==e||(tR.current=setTimeout(()=>{tR.current=null,r()},a))};r(),fetch(`/api/agent/${encodeURIComponent(t)}`).then(e=>e.json()).then(e=>{e.state?.contextUsage!==void 0&&eH(e.state.contextUsage??null),e.state?.systemPrompt!==void 0&&eW(e.state.systemPrompt??null),e.state?.isCompacting!==void 0&&eX(e.state.isCompacting)}).catch(()=>{})}l?.();break;case"agent_settled":e5(null),eF(null),tu.current&&(tu.current=!1,eh(!1),ef({type:"end"}));break;case"message_start":case"message_update":{let t=e.message;if(t?.role==="user")break;tu.current||(tu.current=!0,eh(!0),e5({kind:"waiting_model"}));let n=e.assistantMessageEvent;t?.role==="assistant"?ef({type:"snapshot",message:o(t)}):n&&ef({type:"delta",event:n}),e5(null);break}case"message_end":{let n=e.message,r="string"==typeof e.__entryId?e.__entryId:null,a=tu.current;if(n&&"user"!==n.role){"assistant"===n.role&&"error"===n.stopReason&&n.errorMessage?.trim()&&e7(`Model response failed: ${n.errorMessage.trim()}`);let e=o(n),a=p(e);if(a&&tb.current.set(a,{observedAt:Date.now(),message:e}),!(r&&tx.current.includes(r))){if(t&&r){let e=tv.current.get(t)??new Map;e.set(r,Date.now()),tv.current.set(t,e)}ea(t=>t.some(t=>Y(t,e))?t:[...t,e]),r&&es(e=>{if(e.includes(r))return e;let t=[...e,r];return tx.current=t,t})}}a&&(ef({type:"reset"}),e5({kind:"waiting_model"}));break}case"replay_gap":t&&(F(t),tV(t,!1,!1,!0));break;case"prompt_done":if(!tu.current)break;t4(te.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(tu.current=!1,eh(!1),e5(null),eF(null),ef({type:"end"}),e9.current?.close(),e9.current=null,t){for(let[e,n]of(D(t),tw.current))n.sessionId===t&&"prompt"===n.kind&&tw.current.delete(e);F(t),tV(t,!1,!1,!0)}e7(`Model request failed: ${n}`),l?.();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;e5(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_update":{let t=e.toolCallId,n=e.toolName,r=function(e){if(!d(e))return null;let t=e.content;if(!Array.isArray(t))return null;let n=t.filter(e=>d(e)&&"text"===e.type&&"string"==typeof e.text).map(e=>e.text).join("\n").split(/\r?\n/),r="";for(let e=n.length-1;e>=0&&!(r=n[e].trim());e-=1);if(!r)return null;let a=r.replace(/\s+/g," ");return a.length<=500?a:`...${a.slice(-497)}`}(e.partialResult);if(!t)break;e5(e=>{let a=e?.kind==="running_tools"?[...e.tools]:[],o=a.find(e=>e.id===t),s={id:t,name:n||o?.name||"tool",args:o?.args,progress:r??o?.progress};return{kind:"running_tools",tools:[...a.filter(e=>e.id!==t),s]}});break}case"tool_execution_end":{let t=e.toolCallId;e5(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"extension_ui_request":case"extension_error":ts(e);break;case"bash_execution_start":{let t=String(e.command??"");tL.current=!0,eU(!0),eD({command:t,output:""}),eh(!0),e5({kind:"running_tools",tools:[{id:"bash",name:"bash",args:t}]});break}case"bash_execution_update":{let t="string"==typeof e.chunk?e.chunk:"";if(!t)break;tU.current+=t,tP.current||(tP.current=setTimeout(()=>{tP.current=null;let e=tU.current;tU.current="",e&&eD(t=>t?{...t,output:t.output+e}:t)},60));break}case"bash_done":{tP.current&&(clearTimeout(tP.current),tP.current=null),tU.current="",tL.current=!1,eU(!1),eD(null),eh(!1),e5(null);let e=te.current;e&&(F(e),tV(e,!1,!1,!0));break}case"queue_update":e6(H({steering:Array.isArray(e.steering)?e.steering:[],followUp:Array.isArray(e.followUp)?e.followUp:[]}));break;case"auto_retry_start":e7(null),tu.current=!0,eh(!0),e5({kind:"waiting_model"}),eF({attempt:e.attempt,maxAttempts:e.maxAttempts,errorMessage:e.errorMessage});break;case"auto_retry_end":eF(null),!1===e.success&&"string"==typeof e.finalError&&e.finalError.trim()?e7(`Model response failed after retries: ${e.finalError.trim()}`):!0===e.success&&e7(null);break;case"auto_compaction_start":case"compaction_start":eX(!0),e0(null);break;case"auto_compaction_end":case"compaction_end":eX(!1),e.errorMessage?e0(e.errorMessage):!e.aborted&&te.current&&tV(te.current)}},[tV,l,t4,ts]);let t5=(0,r.useCallback)(async(e,r,a,o)=>{if(!e.trim()&&!r?.length&&!a?.length||eg)return;tT.current+=1;let s=tW(a),l=e.trim()?s?`${e}
|
|
5
|
-
|
|
6
|
-
Attached document text:
|
|
7
|
-
|
|
8
|
-
${s}`:e:s?`Attached document text:
|
|
9
|
-
|
|
10
|
-
${s}`:"",u=[],c=x?n:t?.cwd??M?.info?.cwd;if(r?.length&&c)try{u=await h(c,r)}catch(e){e7(e instanceof Error?e.message:String(e));return}let d=u.length?u.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,g.HG)(t)}?type=read`),media_type:e.mimeType}}}):r?.map(e=>({type:"image",source:{type:"base64",media_type:e.mimeType,data:e.data}})),p={role:"user",content:d?.length?[...l.trim()?[{type:"text",text:l}]:[],...d]:l,timestamp:Date.now()},y=J(),w=x?null:t?.id??null;w&&F(w);let k=tC.current,v=z(p.content);tw.current.set(y,{localId:y,sessionId:w??"__new__",leafId:k,message:p,createdAt:Date.now(),kind:"prompt",confirmKey:v,confirmCountAtCreate:x?0:v?tk.current.get(v)??0:0}),ea(e=>[...e,p]),e7(null),tu.current=!0,eh(!0),e5({kind:"waiting_model"}),ef({type:"start"}),tg.current=!0;let C=ek.find(e=>e.provider===tq?.provider&&e.id===tq?.modelId)?.input,_=!C||0===C.length||C.includes("image")?r?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType})):void 0;try{if(x&&n){eT&&eY(eT);let t=o??tB(),r=await fetch("/api/agent/new",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:n,type:"prompt",message:l,toolNames:t,deferPrompt:!0,..._?.length?{images:_}:{},...eT?{provider:eT.provider,modelId:eT.modelId}:{},..."auto"!==eP?{thinkingLevel:eP}:{}})}),a=await r.json().catch(()=>({}));if(!r.ok||a.error||!a.sessionId)throw Error(a.error??`HTTP ${r.status}`);let s=a.sessionId;te.current=s;let u=tw.current.get(y);u&&(u.sessionId=s),tp.current?.(),tp.current=N(s,()=>{te.current===s&&(eh(!1),e5(null))}),t_.current=s,await t3(s,{requireConnected:!0,timeoutMs:1e4}),await f(s,{type:"prompt",message:l,toolNames:t,..._?.length?{images:_}:{}}),i?.({id:s,path:"",cwd:n,name:void 0,created:new Date().toISOString(),modified:new Date().toISOString(),messageCount:1,firstMessage:e})}else if(t){let e=o??tB();await tJ(t.id),tp.current?.(),tp.current=N(t.id,()=>{te.current===t.id&&(eh(!1),e5(null))}),await t3(t.id,{requireConnected:!0,timeoutMs:1e4}),await f(t.id,{type:"prompt",message:l,toolNames:e,leafId:k,...tq?{provider:tq.provider,modelId:tq.modelId}:{},..."auto"!==eP?{thinkingLevel:eP}:{},..._?.length?{images:_}:{}})}}catch(n){let t=te.current;if(tw.current.delete(y),ea(e=>e.filter(e=>e!==p)),n instanceof m&&(409===n.status||"SESSION_BUSY"===n.code)){e7("This session is already running in another tab. Showing that active run instead."),tu.current=!0,eh(!0),e5({kind:"waiting_model"}),ef({type:"start"}),t&&(e9.current?.close(),e9.current=null,L(t),t3(t,{replay:!0}),td.current?.(t,"prompt_conflict"));return}if(console.error("Failed to send message:",n),x&&te.current){let e=te.current;te.current=null,t_.current=null,fetch(`/api/sessions/${encodeURIComponent(e)}`,{method:"DELETE"}).catch(()=>{})}b?.current&&e.trim()&&b.current.insertIfEmpty(e),b?.current&&r?.length&&b.current.addBase64Images?.(r.map(({data:e,mimeType:t})=>({data:e,mimeType:t}))),e7(n instanceof Error?n.message:String(n)),e9.current?.close(),e9.current=null,t&&D(t),tu.current=!1,eh(!1),e5(null),ef({type:"end"})}},[x,n,eT,tB,eP,t,M?.info?.cwd,eg,t3,i,tW,ek,tq,tJ,b]),t2=(0,r.useCallback)(async()=>{let e=te.current;if(!e)return;let t=tL.current;tu.current=!1,eU(!1),eD(null),e7(null),eh(!1),e5(null),ef({type:"end"}),e9.current?.close(),e9.current=null,D(e),F(e);try{await f(e,{type:t?"abort_bash":"abort"}),await tV(e,!1,!1,!0)}catch(t){console.error("Failed to abort:",t),await tV(e,!1,!1,!0)}finally{t&&(tL.current=!1,eU(!1),eD(null))}},[tV]),t6=(0,r.useCallback)(async(e,t)=>{let n=te.current,r=e.trim();if(n&&r){tL.current=!0,eU(!0),e7(null),eD({command:r,output:""}),tu.current=!0,eh(!0),e5({kind:"running_tools",tools:[{id:"bash",name:"bash",args:r}]});try{await f(n,{type:"bash",command:r,excludeFromContext:t})}catch(e){e7(e instanceof Error?e.message:String(e))}finally{tP.current&&(clearTimeout(tP.current),tP.current=null),tU.current="",tL.current=!1,eU(!1),eD(null),tu.current=!1,eh(!1),e5(null),F(n),await tV(n,!1,!1,!0)}}},[tV]),t8=(0,r.useCallback)(async e=>{let t=te.current;if(t){eK(e);try{let{cancelled:n,newSessionId:r}=await f(t,{type:"fork",entryId:e})??{};!n&&r&&u?.(r)}catch(e){console.error("Fork failed:",e)}finally{eK(null)}}},[u]),t7=(0,r.useCallback)(async e=>{let r=te.current,a=M?.info?.cwd??t?.cwd??n??null;if(!r||!a)return{ok:!1,error:"No active session to fork"};if(tu.current)return{ok:!1,error:"Agent is still running"};try{let t=tB(),n=await fetch("/api/agent/new",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:a,type:"prompt",parentSessionId:r,deferPrompt:!0,toolNames:t,...tq?{provider:tq.provider,modelId:tq.modelId}:{},..."auto"!==eP?{thinkingLevel:eP}:{}})}),o=await n.json().catch(()=>({}));if(!n.ok||o.error||!o.sessionId)return{ok:!1,error:o.error??`HTTP ${n.status}`};let s=o.sessionId;try{await f(s,{type:"append_message",message:e,customType:"fork_handoff",display:!0})}catch{}return i?.({id:s,path:"",cwd:a,created:new Date().toISOString(),modified:new Date().toISOString(),messageCount:1,firstMessage:e.slice(0,120),parentSessionId:r}),{ok:!0}}catch(e){return{ok:!1,error:e instanceof Error?e.message:String(e)}}},[M?.info?.cwd,t?.cwd,n,tq,eP,tB,i]),t9=(0,r.useCallback)(async e=>{let t=te.current;t&&(tv.current.delete(t),F(t),tC.current=e,en(e),await tZ(t,e))},[tZ]),ne=(0,r.useCallback)(async e=>{tC.current=e,en(e);let t=te.current;t&&(tv.current.delete(t),F(t),await tZ(t,e))},[tZ]),nt=(0,r.useCallback)(async(e,t)=>{if(x)return void tj({provider:e,modelId:t});let n=te.current;if(n)try{var r;e7(null);let a=await f(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)&&ej(a.thinkingLevel),eG(o),U(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),e7(e)}},[x,tj]),nn=(0,r.useCallback)(async()=>{let e=te.current;if(e&&!eQ){eX(!0),e0(null),e3(null);try{let t=await f(e,{type:"compact"});t?.reducedBy!=null&&e3(`Compacted ~${t.tokensBefore??"?"} → ~${t.tokensAfter??"?"} tokens (−${t.reducedBy})`),await tV(e,!0)}catch(e){e0(e instanceof Error?e.message:String(e))}finally{eX(!1)}}},[eQ,tV]),nr=(0,r.useCallback)(async(e,t,n)=>{let r=te.current;if(!r)return;F(r);let a=tW(n),o=e.trim()?a?`${e}
|
|
11
|
-
|
|
12
|
-
Attached document text:
|
|
13
|
-
|
|
14
|
-
${a}`:e:a?`Attached document text:
|
|
15
|
-
|
|
16
|
-
${a}`:"",s=ek.find(e=>e.provider===tq?.provider&&e.id===tq?.modelId)?.input,l=!s||0===s.length||s.includes("image")?t?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType})):void 0,i={role:"user",content:`[steer] ${o}`,timestamp:Date.now()},u=J(),c=K(o,l?.length??0);tw.current.set(u,{localId:u,sessionId:r,leafId:tC.current,message:i,createdAt:Date.now(),kind:"steer",confirmKey:c,confirmCountAtCreate:c?tk.current.get(c)??0:0}),ea(e=>[...e,i]);try{await f(r,{type:"steer",message:o,...l?.length?{images:l}:{}})}catch(e){tw.current.delete(u),console.error("Failed to steer:",e)}},[tW,ek,tq]),na=(0,r.useCallback)(async(e,t,n)=>{let r=te.current;if(!r)return;F(r);let a=tW(n),o=e.trim()?a?`${e}
|
|
17
|
-
|
|
18
|
-
Attached document text:
|
|
19
|
-
|
|
20
|
-
${a}`:e:a?`Attached document text:
|
|
21
|
-
|
|
22
|
-
${a}`:"",s=ek.find(e=>e.provider===tq?.provider&&e.id===tq?.modelId)?.input,l=!s||0===s.length||s.includes("image")?t?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType})):void 0,i={role:"user",content:o,timestamp:Date.now()},u=J(),c=K(o,l?.length??0);tw.current.set(u,{localId:u,sessionId:r,leafId:tC.current,message:i,createdAt:Date.now(),kind:"follow_up",confirmKey:c,confirmCountAtCreate:c?tk.current.get(c)??0:0}),ea(e=>[...e,i]);try{await f(r,{type:"follow_up",message:o,...l?.length?{images:l}:{}})}catch(e){tw.current.delete(u),console.error("Failed to follow up:",e)}},[tW,ek,tq]),no=(0,r.useCallback)(async()=>{let e=te.current;if(e)try{await f(e,{type:"abort_compaction"})}catch(e){console.error("Failed to abort compaction:",e)}},[]),ns=(0,r.useCallback)(async e=>{if(ej(e),"auto"===e)return;let t=te.current;if(t)try{await f(t,{type:"set_thinking_level",level:e})}catch(e){console.error("Failed to set thinking level:",e)}},[]),nl=(0,r.useCallback)(async e=>{tO(e);let t=(0,q.tE)(e,eA),n=te.current;if(n)try{await f(n,{type:"set_tools",toolNames:t})}catch(e){console.error("Failed to set tools:",e)}},[eA,tO]),ni=(0,r.useCallback)(async e=>{tF(e);let t=(0,q.tE)(eS,e),n=te.current;if(n)try{await f(n,{type:"set_tools",toolNames:t})}catch(e){console.error("Failed to set memory tools:",e)}},[tF,eS]),nu=(0,r.useCallback)((e="smooth")=>{th.current?.scrollIntoView({behavior:e})},[]),nc=(0,r.useCallback)(()=>{let e=ty.current,t=tf.current;if(!e||!t)return;let n=t.getBoundingClientRect().top-e.getBoundingClientRect().top+e.scrollTop;e.scrollTo({top:n-16,behavior:"smooth"})},[]);(0,r.useEffect)(()=>{if(t){var e;let n;if(te.current=t.id,t.id===t_.current)return t_.current=null,()=>{tR.current&&clearTimeout(tR.current),tR.current=null,e9.current?.close(),e9.current=null,tp.current?.(),tp.current=null};tM.current=!1,tS.current=0;let r=(e=t.id,(n=C().get(e))&&"idle"!==n.snapshot.phase?n.snapshot:null);r?.phase==="active"&&(tu.current=!0,eh(!0),e5({kind:"waiting_model"}),ef({type:"start"})),(async()=>{let e=await tV(t.id,!0,!0,!0);te.current===t.id&&(await t0(t.id),t1(t.id),e?.running?(tu.current=!0,eh(!0),e5(a(e.state)),ef({type:"start"}),t3(t.id,{replay:!0}),tp.current?.(),tp.current=N(t.id,()=>{te.current===t.id&&td.current?.(t.id,"stream_watchdog")})):e&&r?.phase==="active"?(tu.current=!1,eh(!1),e5(null),ef({type:"end"}),D(t.id)):e||r?.phase!=="active"||td.current?.(t.id,"mount_state_load_failed"),e?.state&&(void 0!==e.state.isCompacting&&eX(e.state.isCompacting),void 0!==e.state.contextUsage&&eH(e.state.contextUsage??null),void 0!==e.state.systemPrompt&&eW(e.state.systemPrompt??null),void 0!==e.state.queuedMessages&&e6(H(e.state.queuedMessages)),to(e.state),e.state.isBashRunning&&(tL.current=!0,eU(!0),eh(!0),e5({kind:"running_tools",tools:[{id:"bash",name:"bash"}]})),void 0!==e.state.thinkingLevel&&ej(e.state.thinkingLevel??"auto")),e&&!tu.current&&e.state?.contextUsage===void 0&&td.current?.(t.id,"mount_context_usage"))})()}return()=>{t_.current&&te.current===t_.current||(tR.current&&clearTimeout(tR.current),tR.current=null,t$.current?.controller.abort(W("Session changed","AbortError")),t$.current=null,e9.current?.close(),e9.current=null,tp.current?.(),tp.current=null)}},[t3,tV,t0,t1,v,t,to]),(0,r.useEffect)(()=>{let e=()=>{let e=te.current;e&&t4(e,"foreground")},t=()=>{"visible"===document.visibilityState&&e()};return document.addEventListener("visibilitychange",t),window.addEventListener("focus",e),window.addEventListener("online",e),()=>{document.removeEventListener("visibilitychange",t),window.removeEventListener("focus",e),window.removeEventListener("online",e)}},[t4]),(0,r.useEffect)(()=>{let e=te.current;if(e)return tA.current=!1,(0,w.O)(t=>{let n=t.includes(e),r=tA.current;tA.current=n,n&&!tu.current?(F(e),t4(e,"running_feed_start")):!n&&r&&(F(e),tu.current?t4(e,"running_feed_stop"):tV(e,!1,!1,!0))})},[tV,t4,t?.id]),(0,r.useEffect)(()=>{let e=window.setInterval(()=>{let e=te.current;e&&(tu.current?(t4(e,"interval"),tD.current&&Date.now()-tN.current>25e3&&(tN.current=Date.now(),F(e),tV(e,!1,!1,!0))):Date.now()-tE.current>=3e4?(tE.current=Date.now(),F(e),tV(e,!1,!1,!0)):tV(e))},15e3);return()=>window.clearInterval(e)},[tV,t4]),(0,r.useEffect)(()=>{v&&v(M?.tree??[],et,ne)},[M?.tree,et,ne,v]),(0,r.useEffect)(()=>{er.length>0&&!tI.current&&(tg.current?(tg.current=!1,tm.current=!0,nc()):tm.current?tu.current||nu("smooth"):(tm.current=!0,nu("instant")))},[er.length,eg,nu,nc]),(0,r.useEffect)(()=>{fetch("/api/models").then(e=>e.json()).then(e=>{if(ew(e.models),e.thinkingLevels&&eC(e.thinkingLevels),e.thinkingLevelMaps&&e_(e.thinkingLevelMaps),e.modelList&&(ev(e.modelList),x&&e.modelList.length>0)){let t=e.defaultModel,n=t&&e.modelList.find(e=>e.id===t.modelId&&e.provider===t.provider);tj(n?{provider:n.provider,modelId:n.id}:{provider:e.modelList[0].provider,modelId:e.modelList[0].id})}}).catch(()=>{})},[x,k,tj]),(0,r.useEffect)(()=>{if(!eZ)return;let e=setTimeout(()=>e0(null),3e3);return()=>clearTimeout(e)},[eZ]),(0,r.useEffect)(()=>{if(!e1)return;let e=setTimeout(()=>e3(null),6e3);return()=>clearTimeout(e)},[e1]);let nd=(0,r.useCallback)(async()=>{let e=te.current;if(e)try{await f(e,{type:"clear_queue"}),e6({steering:[],followUp:[]})}catch(e){e7(e instanceof Error?e.message:String(e))}},[]);return{data:M,loading:Q,error:Z,activeLeafId:et,messages:er,entryIds:eo,streamState:em,agentRunning:eg,modelNames:ey,modelList:ek,modelThinkingLevels:eb,modelThinkingLevelMaps:ex,newSessionModel:eT,toolPreset:eS,memoryTools:eA,thinkingLevel:eP,retryInfo:eO,queuedMessages:e2,extensionStatuses:tt,extensionWidgets:tn,extensionDialog:tr,extensionNotices:ta,bashLive:eN,bashRunning:eL,contextUsage:eq,systemPrompt:eB,forkingEntryId:eJ,isCompacting:eQ,compactError:eZ,compactInfo:e1,currentModel:tq,displayModel:tH,sessionStats:tK,agentPhase:e4,agentError:e8,isNew:x,sessionIdRef:te,sseReaderRef:e9,messagesEndRef:th,scrollContainerRef:ty,lastUserMsgRef:tf,pendingScrollToUserRef:tg,initialScrollDoneRef:tm,handleSend:t5,handleAbort:t2,handleFork:t8,handleNavigate:t9,handleModelChange:nt,handleCompact:nn,handleSteer:nr,handleFollowUp:na,handleAbortCompaction:no,handleToolPresetChange:nl,handleMemoryToolsChange:ni,handleThinkingLevelChange:ns,handleClearQueue:nd,handleBash:t6,respondToExtensionUi:tl,dismissExtensionNotice:ti,loadTools:t0,loadSlashCommands:t1,slashCommands:eR,setActiveLeafId:en,setData:U,setMessages:ea,dispatch:ef,setAgentRunning:eh,setForkingEntryId:eK,forkToNewSession:t7,loadMoreMessages:tQ,hasMoreMessages:eu,totalMessages:el,loadedMessagesCount:ed,loadShadowedMessages:tX,handleAgentEventRef:tc}}},14755:(e,t,n)=>{n.d(t,{ES:()=>d,IB:()=>p,SN:()=>a,tE:()=>m});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){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 p(e){return a.filter(t=>e.some(e=>e.active&&e.name===t))}function m(e,t){return[...new Set([...function(e){switch(e){case"none":return o;case"default":return s;case"workbench":return i;case"agent":return u;default:return l}}(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)))}}}}]);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8436],{32383:()=>{},83686:()=>{}}]);
|