@anvia/studio 0.2.8 → 0.2.10
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.
|
@@ -96,5 +96,5 @@ For more information, see https://radix-ui.com/primitives/docs/components/${t.do
|
|
|
96
96
|
|
|
97
97
|
`)}),n!==void 0&&i.push({label:r.length>0?`Current prompt`:`Prompt`,text:n.text}),i}function HI(e){let t=e.map((e,t)=>({label:UI(e,t,`history`),text:fF(e)||Uy(e)})).filter(e=>e.text.length>0);return t.length===0?[]:[{label:`Conversation history (${t.length})`,text:t.map((e,t)=>`${t+1}. ${e.label}\n${e.text}`).join(`
|
|
98
98
|
|
|
99
|
-
`)}]}function UI(e,t,n){if(My(e)){let t=typeof e.type==`string`?e.type:void 0;if(n===`choice`){if(t===`text`)return`Assistant output`;if(t===`reasoning`)return`Reasoning`}if(t===`reasoning`)return`Reasoning`;if(typeof e.role==`string`)return WI(e.role);if(t!==void 0)return WI(t)}return`${n===void 0?`Item`:`${WI(n)} item`} ${t+1}`}function WI(e){return e.replace(/[_-]+/g,` `).replace(/([a-z0-9])([A-Z])/g,`$1 $2`).trim().replace(/\b\w/g,e=>e.toUpperCase())}function GI(e){let t=e.instructions;return typeof t!=`string`||t.trim().length===0?[]:[{label:`System prompt`,text:t}]}function KI(e){if(e===void 0)return`undefined`;if(e===null)return`null`;if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`)return String(e);try{return JSON.stringify(e,null,2)}catch{return String(e)}}function qI(e){let t=new Map;for(let n of e.observations){let e=Number.isFinite(n.turn)?n.turn:t.size+1;t.set(e,[...t.get(e)??[],n])}return[...t.entries()].sort(([e],[t])=>e-t).map(([e,t])=>({turn:e,observations:t,durationMs:t.reduce((e,t)=>e+(t.durationMs??0),0)}))}function JI(e){let t=new Map;for(let n of e)t.set(n.id,{observation:n,children:[]});let n=[];for(let r of e){let e=t.get(r.id);if(e===void 0)continue;let i=r.parentObservationId,a=i===void 0?void 0:t.get(i);a===void 0?n.push(e):a.children.push(e)}return n}function YI(e,t,n){if(n===`agent`)return{title:`agent.run`,tone:`agent`,startedAt:Py(e.startedAt),durationMs:e.durationMs,firstDeltaMs:cL(e.observations),usage:Ly(e.usage),input:e.input,output:e.output,error:e.error,metadata:XI(e)};if(n.startsWith(`turn:`)){let r=Number(n.slice(5)),i=t.find(e=>e.turn===r);return{title:`turn.${Number.isFinite(r)?r:1}`,tone:`turn`,startedAt:Py(i?.observations[0]?.startedAt??e.startedAt),durationMs:i?.durationMs,firstDeltaMs:cL(i?.observations??[]),usage:mL(i?.observations??[]),input:i?.observations[0]?.input,output:i?.observations.at(-1)?.output,metadata:ZI(r,i?.observations??[])}}if(n.startsWith(`observation:`)){let t=n.slice(12),r=e.observations.find(e=>e.id===t);if(r!==void 0)return{title:sL(r),tone:r.kind,startedAt:Py(r.startedAt),durationMs:r.durationMs,firstDeltaMs:lL(r.metadata),usage:pL(r),input:r.input,output:r.output,error:r.error,metadata:QI(r)}}return{title:e.name??`Agent`,tone:`trace`,startedAt:Py(e.startedAt),durationMs:e.durationMs,firstDeltaMs:cL(e.observations),usage:Ly(e.usage),input:e.input,output:e.output,error:e.error,metadata:XI(e)}}function XI(e){let t=My(e.metadata)?e.metadata:{},n=oL({status:e.status,traceId:e.trace?.traceId??e.id,observationId:e.trace?.observationId,sessionId:e.sessionId,observationCount:e.observationCount,messageCount:aL(t.messages),startedAt:e.startedAt,endedAt:e.endedAt,durationMs:e.durationMs});return oL({...t,status:e.status,traceId:e.trace?.traceId??e.id,observationId:e.trace?.observationId,sessionId:e.sessionId,observationCount:e.observationCount,messageCount:aL(t.messages),startedAt:e.startedAt,endedAt:e.endedAt,durationMs:e.durationMs,trace:My(t.trace)?t.trace:n})}function ZI(e,t){return oL({turn:e,observationCount:t.length,generationCount:t.filter(e=>e.kind===`generation`).length,toolCount:t.filter(e=>e.kind===`tool`).length,agentCount:t.filter(e=>e.kind===`agent`).length,firstDeltaMs:cL(t),status:iL(t),startedAt:t[0]?.startedAt,endedAt:t.at(-1)?.endedAt})}function QI(e){let t=oL({...My(e.metadata)?e.metadata:{},status:e.status,kind:e.kind,turn:e.turn,parentObservationId:e.parentObservationId??null,startedAt:e.startedAt,endedAt:e.endedAt??null,durationMs:e.durationMs});return oL({...t,trace:My(t.trace)?t.trace:oL({status:e.status,kind:e.kind,turn:e.turn,parentObservationId:e.parentObservationId??null,startedAt:e.startedAt,endedAt:e.endedAt??null,durationMs:e.durationMs}),modelInfo:My(t.modelInfo)?t.modelInfo:$I(t),modelCall:My(t.modelCall)?t.modelCall:eL(t),response:My(t.response)?t.response:tL(t),tools:My(t.tools)?t.tools:nL(t),timing:My(t.timing)?t.timing:rL(t)})}function $I(e){let t=oL({provider:e.provider,model:e.model,requestedModel:e.requestedModel,defaultModel:e.defaultModel});return Object.keys(t).length===0?void 0:t}function eL(e){let t=oL({messageCount:e.historyCount,documentCount:e.documentCount,toolCount:e.toolCount,toolNames:e.toolNames,temperature:e.temperature,maxTokens:e.maxTokens,toolChoice:e.toolChoice,hasOutputSchema:e.hasOutputSchema,additionalParamKeys:e.additionalParamKeys}),n=oL({request:Object.keys(t).length===0?void 0:t,providerRequest:e.providerRequest});return Object.keys(n).length===0?void 0:n}function tL(e){let t=oL({messageId:e.messageId,usage:e.usage,providerResponse:e.providerResponse});return Object.keys(t).length===0?void 0:t}function nL(e){let t=oL({count:e.toolCount,names:e.toolNames,toolChoice:e.toolChoice,internalCallId:e.internalCallId,toolCallId:e.toolCallId,skipped:e.skipped,description:e.toolDescription,parameterKeys:e.parameterKeys,requiredParameterKeys:e.requiredParameterKeys,approvalRequired:e.approvalRequired,mcpServerName:e.mcpServerName,argumentBytes:e.argumentBytes,resultBytes:e.resultBytes});return Object.keys(t).length===0?void 0:t}function rL(e){let t=oL({firstDeltaMs:e.firstDeltaMs,durationMs:e.durationMs,startedAt:e.startedAt,endedAt:e.endedAt});return Object.keys(t).length===0?void 0:t}function iL(e){return e.length===0?`empty`:e.some(e=>e.status===`error`)?`error`:e.some(e=>e.status===`running`)?`running`:`success`}function aL(e){return Array.isArray(e)?e.length:void 0}function oL(e){return Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0))}function sL(e){return e.kind===`agent`?e.name:e.kind===`tool`?`tool.${e.name}`:e.name}function cL(e){for(let t of e){let e=lL(t.metadata);if(e!==void 0)return e}}function lL(e){if(!(!My(e)||typeof e.firstDeltaMs!=`number`))return e.firstDeltaMs}function uL(e){switch(e){case`success`:return`bg-primary`;case`error`:return`bg-destructive`;case`running`:return`bg-chart-2`}}function dL(e){switch(e.tone){case`trace`:return(0,H.jsx)(Ve,{"aria-hidden":`true`});case`agent`:return(0,H.jsx)(Xe,{"aria-hidden":`true`});case`turn`:return(0,H.jsx)(Fe,{"aria-hidden":`true`});case`generation`:return(0,H.jsx)(De,{"aria-hidden":`true`});case`tool`:return(0,H.jsx)(it,{"aria-hidden":`true`})}}function fL(e){switch(e){case`trace`:return`bg-primary text-background`;case`agent`:return`bg-chart-2 text-background`;case`turn`:return`bg-chart-4 text-background`;case`generation`:return`bg-chart-1 text-background`;case`tool`:return`bg-chart-5 text-background`}}function pL(e){return!My(e.output)||!My(e.output.usage)?``:hL(e.output.usage)}function mL(e){return e.map(pL).filter(e=>e.length>0).join(` + `)}function hL(e){let t=typeof e.inputTokens==`number`?e.inputTokens:0,n=typeof e.outputTokens==`number`?e.outputTokens:0,r=typeof e.totalTokens==`number`?e.totalTokens:t+n;return r===0?``:`${t} -> ${n} (Σ ${r})`}var gL=`anvia-studio-theme`;function _L(){if(typeof window>`u`)return`dark`;try{let e=window.localStorage.getItem(gL);return e===`light`||e===`dark`?e:`dark`}catch{return`dark`}}function vL(e){typeof document>`u`||(document.documentElement.classList.toggle(`dark`,e===`dark`),document.documentElement.style.colorScheme=e)}function yL(e){try{window.localStorage.setItem(gL,e)}catch{}}var bL=_L();vL(bL);async function xL(e,t){let n=``;try{let t=await e.json();typeof t==`object`&&t&&`error`in t&&typeof t.error==`object`&&t.error!==null&&`message`in t.error&&typeof t.error.message==`string`&&(n=`: ${t.error.message}`)}catch{}return`${t} with HTTP ${e.status}${n}`}function SL(){let e=KP(),[t,n]=(0,v.useState)(),[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(``),[s,c]=(0,v.useState)(``),[l,u]=(0,v.useState)(``),[d,f]=(0,v.useState)(``),[p,m]=(0,v.useState)([]),[h,g]=(0,v.useState)([]),[_,y]=(0,v.useState)([]),[b,x]=(0,v.useState)(),[S,C]=(0,v.useState)([]),[w,T]=(0,v.useState)([]),[E,D]=(0,v.useState)([]),[O,k]=(0,v.useState)(``),[A,j]=(0,v.useState)(`"Hello from Studio"`),[M,N]=(0,v.useState)(``),[P,ee]=(0,v.useState)(``),[F,I]=(0,v.useState)(()=>e.page),[te,ne]=(0,v.useState)(()=>bL),[re,L]=(0,v.useState)(()=>e.knowledgeTab??`static-context`),[R,z]=(0,v.useState)(()=>e.traceId??``),[ie,B]=(0,v.useState)(()=>e.traceSessionId),[ae,V]=(0,v.useState)(),[oe,ce]=(0,v.useState)(`Loading`),[,le]=(0,v.useState)(``),[ue,de]=(0,v.useState)(`idle`),[fe,pe]=(0,v.useState)(()=>new Set),[me,he]=(0,v.useState)(()=>new Set),[ge,ve]=(0,v.useState)(`idle`),[ye,be]=(0,v.useState)(`idle`),[xe,Se]=(0,v.useState)(`idle`),[Ce,we]=(0,v.useState)(),[Te,Ee]=(0,v.useState)(`idle`),[De,Oe]=(0,v.useState)(),[ke,Ae]=(0,v.useState)(`idle`),[je,Me]=(0,v.useState)(),[Ne,Pe]=(0,v.useState)(`idle`),[Fe,Ie]=(0,v.useState)(`idle`),[Le,Re]=(0,v.useState)(`idle`),[Be,Ve]=(0,v.useState)(`idle`),[He,Ue]=(0,v.useState)(`idle`),We=(0,v.useRef)(null),Ge=(0,v.useRef)(null),Ke=(0,v.useRef)(!0);function Je(){let e=Ge.current;e!==null&&(Ke.current=e.scrollHeight-e.scrollTop-e.clientHeight<80)}(0,v.useEffect)(()=>{if(F!==`playground`||E.length===0||!Ke.current)return;let e=window.requestAnimationFrame(()=>{let e=Ge.current;e!==null&&(e.scrollTop=e.scrollHeight)});return()=>window.cancelAnimationFrame(e)},[F,E]);let Ye=(0,v.useCallback)(async()=>{ce(`Loading`),le(``);try{let e=await fetch(`/config`);if(e.status===401){ce(`Authentication required`);return}if(!e.ok)throw Error(`Config failed with HTTP ${e.status}`);let t=await e.json();n(t),i(e=>e||t.agents[0]?.id||``),o(e=>e||t.agents[0]?.id||``),c(e=>e||t.agents[0]?.id||``),u(e=>e||t.pipelines[0]?.id||``),ce(`Connected`)}catch(e){le(Ky(e)),ce(`Config error`)}},[]);(0,v.useEffect)(()=>{Ye()},[Ye]);let Xe=t?.capabilities.sessions?.enabled===!0,Ze=t?.capabilities.traces?.enabled===!0,Qe=t?.capabilities.knowledge?.enabled===!0,$e=t?.capabilities.mcps?.enabled===!0,tt=t?.capabilities.tools?.enabled===!0,nt=t?.capabilities.pipelines?.enabled===!0,rt=t?.agents??[],it=t?.pipelines??[],at=rt.length>0,ot=rt.find(e=>e.id===r)??rt[0]??void 0,st=ot?.quickPrompts??[],ct=E.length>0;(0,v.useEffect)(()=>{vL(te),yL(te)},[te]);let lt=(0,v.useCallback)(async()=>{if(!Xe){m([]);return}try{let e=await fetch(`/sessions?limit=100`);if(!e.ok)throw Error(`Sessions failed with HTTP ${e.status}`);m((await e.json()).sessions)}catch(e){le(Ky(e))}},[Xe]);(0,v.useEffect)(()=>{lt()},[lt]);let ut=(0,v.useCallback)(async e=>{if(!Xe)return y([]),[];be(`loading`);try{let t=new URLSearchParams({limit:`1000`}),n=await fetch(`/sessions/${encodeURIComponent(e)}/logs?${t}`);if(!n.ok)throw Error(`Session logs failed with HTTP ${n.status}`);let r=await n.json();return y(r.logs),r.logs}catch(e){return le(Ky(e)),y([]),[]}finally{be(`idle`)}},[Xe]);async function dt(e){let t=ot?.id??r,n=await fetch(`/sessions`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({agentId:t,title:e,metadata:{source:`anvia-studio`}})});if(!n.ok)throw Error(await xL(n,`Session create failed`));let i=await n.json();return f(i.id),m(e=>[i,...e.filter(e=>e.id!==i.id)]),XP(i.id),await ut(i.id),i}let ft=(0,v.useCallback)(async()=>{if(!Ze){g([]);return}Se(`loading`);try{let e=new URLSearchParams({limit:`50`}),t=await fetch(`/traces?${e.toString()}`);if(!t.ok)throw Error(`Traces failed with HTTP ${t.status}`);let n=await t.json(),r=await Promise.all(n.traces.map(async e=>{let t=await fetch(`/traces/${encodeURIComponent(e.id)}`);if(!t.ok)throw Error(`Trace load failed with HTTP ${t.status}`);return await t.json()}));if(R.length>0&&!r.some(e=>e.id===R)){let e=await fetch(`/traces/${encodeURIComponent(R)}`);if(e.ok){g([await e.json(),...r]);return}}g(r)}catch(e){le(Ky(e))}finally{Se(`idle`)}},[R,Ze]),pt=(0,v.useCallback)(async(e,t={})=>{if(Ze){Se(`loading`);try{let n=new URLSearchParams({limit:`50`,sessionId:e}),r=await fetch(`/traces?${n.toString()}`);if(!r.ok)throw Error(`Session traces failed with HTTP ${r.status}`);let i=await r.json(),a=[...await Promise.all(i.traces.map(async e=>{let t=await fetch(`/traces/${encodeURIComponent(e.id)}`);if(!t.ok)throw Error(`Trace load failed with HTTP ${t.status}`);return await t.json()}))].sort((e,t)=>Date.parse(e.startedAt)-Date.parse(t.startedAt));g(a);let o=a[0]?.id;if(o===void 0){z(``),B(e),t.updatePath!==!1&&QP(e);return}I(`tracing`),z(o),B(e),t.updatePath!==!1&&QP(e)}catch(e){le(Ky(e))}finally{Se(`idle`)}}},[Ze]),mt=(0,v.useCallback)(async e=>{if(!Ze)return[];let t=new URLSearchParams({limit:`100`}),n=await fetch(`/sessions/${encodeURIComponent(e)}/traces?${t}`);return n.ok?(await n.json()).traces:[]},[Ze]);(0,v.useEffect)(()=>{F!==`tracing`||ie!==void 0||ft()},[F,ft,ie]);let ht=(0,v.useCallback)(async()=>{if(!Qe){we(void 0);return}Ee(`loading`);try{let e=await fetch(`/knowledge?limit=25`);if(!e.ok)throw Error(`Knowledge failed with HTTP ${e.status}`);we(await e.json())}catch(e){le(Ky(e))}finally{Ee(`idle`)}},[Qe]);(0,v.useEffect)(()=>{F===`knowledge`&&ht()},[F,ht]);let gt=(0,v.useCallback)(async e=>{if(!$e||e.length===0){Oe(void 0);return}Ae(`loading`);try{let t=await fetch(`/agents/${encodeURIComponent(e)}/mcps`);if(!t.ok)throw Error(`MCPs failed with HTTP ${t.status}`);Oe(await t.json())}catch(e){le(Ky(e)),Oe(void 0)}finally{Ae(`idle`)}},[$e]);(0,v.useEffect)(()=>{F===`mcps`&>(a||r)},[F,gt,a,r]);let _t=(0,v.useCallback)(async e=>{if(!tt||e.length===0){Me(void 0);return}Pe(`loading`);try{let t=await fetch(`/agents/${encodeURIComponent(e)}/tools`);if(!t.ok)throw Error(`Tools failed with HTTP ${t.status}`);Me(await t.json())}catch(e){le(Ky(e)),Me(void 0)}finally{Pe(`idle`)}},[tt]);(0,v.useEffect)(()=>{F===`tools`&&_t(s||r)},[F,_t,r,s]);let vt=(0,v.useCallback)(async e=>{if(!nt||e.length===0)return C([]),[];Re(`loading`);try{let t=new URLSearchParams({limit:`1000`}),n=await fetch(`/pipelines/${encodeURIComponent(e)}/logs?${t}`);if(!n.ok)throw Error(`Pipeline logs failed with HTTP ${n.status}`);let r=await n.json();return C(r.logs),r.logs}catch(e){return le(Ky(e)),C([]),[]}finally{Re(`idle`)}},[nt]),yt=(0,v.useCallback)(async e=>{if(!nt||e.length===0)return T([]),[];Ve(`loading`);try{let t=new URLSearchParams({limit:`50`}),n=await fetch(`/pipelines/${encodeURIComponent(e)}/runs?${t}`);if(!n.ok)throw Error(`Pipeline runs failed with HTTP ${n.status}`);let r=await n.json();return T(r.runs),r.runs}catch(e){return le(Ky(e)),T([]),[]}finally{Ve(`idle`)}},[nt]),bt=(0,v.useCallback)(async e=>{if(!nt||e.length===0){x(void 0),C([]),T([]);return}Ie(`loading`),le(``);try{let t=await fetch(`/pipelines/${encodeURIComponent(e)}`);if(!t.ok)throw Error(`Pipeline load failed with HTTP ${t.status}`);u(e),x(await t.json()),await Promise.all([vt(e),yt(e)])}catch(e){le(Ky(e)),x(void 0)}finally{Ie(`idle`)}},[vt,yt,nt]);(0,v.useEffect)(()=>{if(F!==`pipelines`)return;let e=l||t?.pipelines[0]?.id||``;e.length>0&&bt(e)},[F,t?.pipelines,bt,l]);let xt=(0,v.useCallback)(async(e,t={})=>{if(ue!==`running`){ve(`loading`),le(``);try{let n=await fetch(`/sessions/${encodeURIComponent(e)}`);if(!n.ok)throw Error(`Session load failed with HTTP ${n.status}`);let r=await n.json(),[a]=await Promise.all([mt(r.id),ut(r.id)]);rF(lF(r.transcript)),i(r.agentId),f(r.id),D(OL(r.transcript,a)),t.updatePath!==!1&&(I(`playground`),XP(r.id)),ce(`Connected`)}catch(e){le(Ky(e))}finally{ve(`idle`)}}},[ue,mt,ut]),St=(0,v.useCallback)((e={})=>{ue!==`running`&&(iF(),f(``),y([]),D([]),k(``),I(`playground`),le(``),e.updatePath!==!1&&XP(void 0),requestAnimationFrame(()=>sF(We.current)))},[ue]),Ct=(0,v.useCallback)(e=>{ue===`running`||e===r||(i(e),iF(),f(``),y([]),D([]),k(``),I(`playground`),le(``),XP(void 0),requestAnimationFrame(()=>sF(We.current)))},[ue,r]);async function wt(e){if(ue!==`running`){le(``);try{let t=await fetch(`/sessions/${encodeURIComponent(e.id)}`,{method:`DELETE`});if(!t.ok)throw Error(`Session delete failed with HTTP ${t.status}`);m(t=>t.filter(t=>t.id!==e.id)),g(t=>t.filter(t=>t.sessionId!==e.id)),d===e.id&&(iF(),f(``),y([]),D([]),k(``),F===`playground`&&XP(void 0)),ce(`Connected`)}catch(e){le(Ky(e))}finally{V(void 0)}}}(0,v.useEffect)(()=>{if(!Xe)return;let e=KP();if(I(e.page),L(e.knowledgeTab??`static-context`),z(e.traceId??``),B(e.traceSessionId),e.page===`tracing`&&e.traceSessionId!==void 0){pt(e.traceSessionId,{updatePath:!1});return}e.page!==`playground`||e.sessionId===void 0||e.sessionId===d||xt(e.sessionId,{updatePath:!1})},[d,Xe,xt,pt]),(0,v.useEffect)(()=>{function e(){let e=KP();if(I(e.page),L(e.knowledgeTab??`static-context`),z(e.traceId??``),B(e.traceSessionId),e.page===`tracing`&&e.traceSessionId!==void 0){pt(e.traceSessionId,{updatePath:!1});return}if(e.page===`playground`){if(e.sessionId===void 0){St({updatePath:!1});return}xt(e.sessionId,{updatePath:!1})}}return window.addEventListener(`popstate`,e),()=>window.removeEventListener(`popstate`,e)},[xt,pt,St]);async function Tt(e){let t=e.trim(),n=ot?.id??r;if(!(t.length===0||n.length===0||ue===`running`)){de(`running`),I(`playground`),le(``),k(``),Ke.current=!0,requestAnimationFrame(()=>sF(We.current)),D(e=>[...e,{entryId:cF(),kind:`message`,role:`user`,text:t}]);try{let e=Xe&&d.length===0?(await dt(Gy(t))).id:d,r=Xe?void 0:aF(E),i=await fetch(`/agents/${encodeURIComponent(n)}/runs`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({message:t,...e.length===0?{}:{sessionId:e},...r===void 0?{}:{history:r},stream:!0,metadata:{source:`anvia-studio`}})});if(i.status===401)throw Error(`Authentication required`);if(!i.ok||i.body===null)throw Error(`Run failed with HTTP ${i.status}`);if(await mF(i.body,async e=>{Dt(e)&&await hF()}),await lt(),e.length>0){f(e);let[t]=await Promise.all([mt(e),ut(e)]);D(e=>OL(e,t))}ce(`Connected`)}catch(e){let t=Ky(e);le(t),At(`\n${t}`)}finally{de(`idle`)}}}async function Et(){let e=l||t?.pipelines[0]?.id||``;if(e.length===0||He===`running`)return;let n;try{n=JSON.parse(A)}catch{le(`Pipeline input must be valid JSON`);return}Ue(`running`),N(``),ee(``),le(``);try{let t=await fetch(`/pipelines/${encodeURIComponent(e)}/runs`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({input:n,stream:!0,metadata:{source:`anvia-studio`}})});if(!t.ok||t.body===null)throw Error(await xL(t,`Pipeline run failed`));await mF(t.body,async e=>{if(wL(e)){e.log.runId!==void 0&&ee(t=>t||e.log.runId||``),kt(e.log),await hF();return}if(TL(e)){N(JSON.stringify(e.output,null,2)),await hF();return}if(EL(e))throw Error(JSON.stringify(e.error))}),await Promise.all([vt(e),yt(e)]),ce(`Connected`)}catch(e){le(Ky(e))}finally{Ue(`idle`)}}function Dt(e){return e.type===`text_delta`?(At(e.delta),!0):e.type===`reasoning_delta`?(It(e.delta,e.id),!0):e.type===`tool_call`?(Lt(e.toolCall.function.name,Uy(e.toolCall.function.arguments),e.toolCall.callId??e.toolCall.id),!0):e.type===`tool_result`?(Rt({toolName:e.toolName,callId:e.toolCallId,args:e.args,result:e.result}),!0):e.type===`agent_tool_event`?(zt(e),!0):e.type===`tool_approval_request`||e.type===`tool_approval_result`?(Mt(e.approval),!0):e.type===`tool_question_request`||e.type===`tool_question_result`?(Nt(e.question),!0):e.type===`session_log`?(Ot(e.log),!0):e.type===`final`&&e.trace?.traceId!==void 0?(jt(e.trace.traceId),!0):(e.type===`error`&&le(JSON.stringify(e.error)),!1)}function Ot(e){y(t=>t.some(t=>t.id===e.id)?t:[...t,e].sort((e,t)=>e.sequence-t.sequence))}function kt(e){C(t=>t.some(t=>t.id===e.id)?t:[...t,e].sort((e,t)=>e.sequence-t.sequence))}function At(e){D(t=>{let n=[...t],r=n.at(-1);return r?.kind===`message`&&r.role===`assistant`?n[n.length-1]={...r,text:`${r.text}${e}`}:n.push({entryId:cF(),kind:`message`,role:`assistant`,text:e}),n})}function jt(e){D(t=>{let n=[...t];for(let t=n.length-1;t>=0;--t){let r=n[t];if(r?.kind===`message`&&r.role===`assistant`){n[t]={...r,traceId:e};break}}return n})}function Mt(e){D(t=>{let n=[...t],r=dF(n,e.toolName,e.callId);if(r<0)return n.push({entryId:cF(),kind:`tool`,toolName:e.toolName,...e.callId===void 0?{}:{callId:e.callId},approval:{id:e.id,status:e.status,requestedAt:e.requestedAt,...e.resolvedAt===void 0?{}:{resolvedAt:e.resolvedAt},...e.reason===void 0?{}:{reason:e.reason}}}),n;let i=n[r];return i!==void 0&&i.kind===`tool`&&(n[r]={...i,approval:{id:e.id,status:e.status,requestedAt:e.requestedAt,...e.resolvedAt===void 0?{}:{resolvedAt:e.resolvedAt},...e.reason===void 0?{}:{reason:e.reason}}}),n})}function Nt(e){D(t=>{let n=[...t],r=dF(n,e.toolName,e.callId);if(r<0)return n.push({entryId:cF(),kind:`tool`,toolName:e.toolName,...e.callId===void 0?{}:{callId:e.callId},question:{id:e.id,status:e.status,requestedAt:e.requestedAt,...e.answeredAt===void 0?{}:{answeredAt:e.answeredAt},questions:e.questions,...e.answers===void 0?{}:{answers:e.answers}}}),n;let i=n[r];return i!==void 0&&i.kind===`tool`&&(n[r]={...i,question:{id:e.id,status:e.status,requestedAt:e.requestedAt,...e.answeredAt===void 0?{}:{answeredAt:e.answeredAt},questions:e.questions,...e.answers===void 0?{}:{answers:e.answers}}}),n})}async function Pt(e,t){if(!fe.has(e)){pe(t=>new Set(t).add(e)),le(``);try{let n=await fetch(`/approvals/${encodeURIComponent(e)}/decision`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({approved:t})});if(!n.ok)throw Error(`Approval decision failed with HTTP ${n.status}`);Mt(await n.json())}catch(e){le(Ky(e))}finally{pe(t=>{let n=new Set(t);return n.delete(e),n})}}}async function Ft(e,t){if(!me.has(e)){he(t=>new Set(t).add(e)),le(``);try{let n=await fetch(`/questions/${encodeURIComponent(e)}/answer`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({answers:t})});if(!n.ok)throw Error(`Question answer failed with HTTP ${n.status}`);Nt(await n.json())}catch(e){le(Ky(e))}finally{he(t=>{let n=new Set(t);return n.delete(e),n})}}}function It(e,t){D(n=>{let r=[...n],i=r.at(-1);return i?.kind===`reasoning`&&(i.reasoningId??``)===(t??``)?r[r.length-1]={...i,text:`${i.text}${e}`}:r.push({entryId:cF(),kind:`reasoning`,...t===void 0?{}:{reasoningId:t},text:e}),r})}function Lt(e,t,n){D(r=>[...r,{entryId:cF(),kind:`tool`,toolName:e,...n===void 0?{}:{callId:n},...t.length===0?{}:{args:t}}])}function Rt(e){D(t=>{let n=[...t],r=uF(n,e.toolName,e.callId);if(r>=0){let t=n[r];if(t!==void 0&&t.kind===`tool`)return n[r]={...t,args:t.args??e.args,result:e.result},n}return n.push({entryId:cF(),kind:`tool`,toolName:e.toolName,...e.callId===void 0?{}:{callId:e.callId},args:e.args,result:e.result}),n})}function zt(e){let t=Bt(e);t!==void 0&&D(n=>{let r=[...n],i=uF(r,e.toolName,e.toolCallId);if(i<0)return r.push({entryId:cF(),kind:`tool`,toolName:e.toolName,...e.toolCallId===void 0?{}:{callId:e.toolCallId},childEvents:[t]}),r;let a=r[i];if(a===void 0||a.kind!==`tool`)return r;let o=[...a.childEvents??[]];return Vt(o,t),r[i]={...a,childEvents:o},r})}function Bt(e){let t=e.event;if(t.type===`text_delta`)return{kind:`message`,agentId:e.agentId,...e.agentName===void 0?{}:{agentName:e.agentName},text:t.delta};if(t.type===`reasoning_delta`)return{kind:`reasoning`,agentId:e.agentId,...e.agentName===void 0?{}:{agentName:e.agentName},...t.id===void 0?{}:{reasoningId:t.id},text:t.delta};if(t.type===`tool_call`)return{kind:`tool`,agentId:e.agentId,...e.agentName===void 0?{}:{agentName:e.agentName},toolName:t.toolCall.function.name,...t.toolCall.callId===void 0&&t.toolCall.id===void 0?{}:{callId:t.toolCall.callId??t.toolCall.id},args:Uy(t.toolCall.function.arguments)};if(t.type===`tool_result`)return{kind:`tool`,agentId:e.agentId,...e.agentName===void 0?{}:{agentName:e.agentName},toolName:t.toolName,...t.toolCallId===void 0?{}:{callId:t.toolCallId},args:t.args,result:t.result};if(t.type===`error`)return{kind:`message`,agentId:e.agentId,...e.agentName===void 0?{}:{agentName:e.agentName},text:`Error: ${Ky(t.error)}`}}function Vt(e,t){if(t.kind===`message`){let n=e.at(-1);n?.kind===`message`&&n.agentId===t.agentId?e[e.length-1]={...n,text:`${n.text}${t.text}`}:e.push(t);return}if(t.kind===`reasoning`){let n=e.at(-1);n?.kind===`reasoning`&&n.agentId===t.agentId&&(n.reasoningId??``)===(t.reasoningId??``)?e[e.length-1]={...n,text:`${n.text}${t.text}`}:e.push(t);return}let n=Ht(e,t);if(n<0){e.push(t);return}let r=e[n];r?.kind===`tool`&&(e[n]={...r,...r.args!==void 0||t.args===void 0?{}:{args:t.args},...t.result===void 0?{}:{result:t.result}})}function Ht(e,t){for(let n=e.length-1;n>=0;--n){let r=e[n];if(!(r?.kind!==`tool`||r.agentId!==t.agentId||r.toolName!==t.toolName||r.result!==void 0)&&(t.callId===void 0||r.callId===t.callId))return n}return-1}function Ut(e){k(oF(e)),sF(e.currentTarget)}function Wt(e){e.key!==`Enter`||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),Tt(O))}function Gt(e){if(!(e===`playground`&&!at)){if(I(e),e===`pipelines`){let e=l||it[0]?.id||``;e.length>0&&(u(e),bt(e))}if(e===`tracing`){z(``),B(void 0),JP(`tracing`);return}if(e===`knowledge`){z(``),B(void 0),YP(re);return}if(z(``),B(void 0),e===`playground`&&d.length>0){XP(d);return}JP(e)}}function Kt(e){I(`knowledge`),L(e),z(``),B(void 0),YP(e)}(0,v.useEffect)(()=>{if(t===void 0||at||F!==`playground`)return;let e=nt?`pipelines`:Xe?`sessions`:Ze?`tracing`:`agents`;if(iF(),f(``),y([]),D([]),k(``),I(e),JP(e),e===`pipelines`){let e=l||it[0]?.id||``;e.length>0&&(u(e),bt(e))}},[F,t,at,bt,it,nt,l,Xe,Ze]);function qt(e){if(I(`tracing`),z(e),B(void 0),e.length===0){JP(`tracing`);return}ZP(e)}return(0,H.jsxs)(`div`,{className:`grid h-[100dvh] min-h-0 overflow-hidden bg-background text-foreground lg:grid-cols-[228px_minmax(0,1fr)]`,children:[(0,H.jsxs)(`aside`,{className:`flex h-[100dvh] min-h-0 flex-col overflow-hidden bg-sidebar text-sidebar-foreground`,children:[(0,H.jsx)(`div`,{className:`flex h-15 items-center px-4`,children:(0,H.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2.5`,children:[(0,H.jsx)(`img`,{className:`h-7 w-7 shrink-0 object-contain`,src:WP,alt:``}),(0,H.jsx)(`span`,{className:`min-w-0 truncate`,children:(0,H.jsx)(`span`,{className:`anvia-wordmark text-[1.08rem] font-semibold tracking-normal text-sidebar-foreground`,children:`Anvia Studio`})})]})}),(0,H.jsxs)(`nav`,{className:`grid gap-0.5 px-3 py-3`,"aria-label":`Main`,children:[(0,H.jsx)(`div`,{className:`px-2.5 pb-1.5 font-mono text-[10px] font-semibold uppercase tracking-[0.18em] text-muted-foreground`,children:`Workspace`}),(0,H.jsx)(gF,{active:F===`playground`,icon:`message`,label:`Chat`,disabled:!at,onClick:()=>Gt(`playground`)}),(0,H.jsx)(gF,{active:F===`pipelines`,icon:`workflow`,label:`Pipelines`,disabled:!nt,onClick:()=>Gt(`pipelines`)}),(0,H.jsx)(gF,{active:F===`sessions`,icon:`list`,label:`Sessions`,onClick:()=>Gt(`sessions`)}),(0,H.jsx)(gF,{active:F===`tracing`,icon:`activity`,label:`Traces`,onClick:()=>Gt(`tracing`)})]}),(0,H.jsxs)(`nav`,{className:`grid gap-0.5 px-3 py-3`,"aria-label":`Studio`,children:[(0,H.jsx)(`div`,{className:`px-2.5 pb-1.5 font-mono text-[10px] font-semibold uppercase tracking-[0.18em] text-muted-foreground`,children:`Inspect`}),(0,H.jsx)(gF,{active:F===`agents`,icon:`bot`,label:`Studio`,onClick:()=>Gt(`agents`)}),(0,H.jsx)(gF,{active:F===`tools`,icon:`wrench`,label:`Tools`,onClick:()=>Gt(`tools`)}),(0,H.jsx)(gF,{active:F===`mcps`,icon:`plug`,label:`MCPs`,onClick:()=>Gt(`mcps`)}),(0,H.jsx)(gF,{active:F===`knowledge`,icon:`database`,label:`Knowledge`,onClick:()=>Gt(`knowledge`)})]}),(0,H.jsxs)(`nav`,{className:`grid min-h-0 gap-0.5 overflow-auto px-3 py-3`,"aria-label":`Recent sessions`,children:[(0,H.jsx)(`div`,{className:`px-2.5 pb-1.5 font-mono text-[10px] font-semibold uppercase tracking-[0.18em] text-muted-foreground`,children:`Recent`}),p.slice(0,8).map(e=>(0,H.jsxs)(`div`,{className:Qn(`group grid min-h-7 min-w-0 grid-cols-[minmax(0,1fr)_36px] items-center gap-1 rounded-lg pr-1 transition duration-200 hover:bg-sidebar-accent/80 focus-within:bg-sidebar-accent/80`,e.id===d&&`bg-sidebar-accent`),children:[(0,H.jsx)(er,{className:Qn(`grid h-auto min-h-7 min-w-0 justify-start rounded-lg border-0 bg-transparent px-2.5 py-0.5 text-left text-sidebar-foreground/72 shadow-none hover:bg-transparent hover:text-sidebar-foreground`,e.id===d&&`text-sidebar-accent-foreground`),type:`button`,variant:`ghost`,onClick:()=>void xt(e.id),children:(0,H.jsx)(`span`,{className:`min-w-0 truncate text-xs font-medium`,children:e.title??`Untitled chat`})}),(0,H.jsxs)(`div`,{className:`relative grid h-7 min-w-0 place-items-end`,children:[(0,H.jsx)(`time`,{className:`grid h-6 min-w-6 place-items-center self-center justify-self-end rounded-lg px-1.5 font-mono text-[10px] font-medium tabular-nums text-muted-foreground group-hover:opacity-0 group-focus-within:opacity-0`,children:Ny(e.updatedAt)}),(0,H.jsx)(er,{"aria-label":`Delete ${e.title??`Untitled chat`}`,className:`absolute right-0 top-1/2 hidden h-6 min-h-6 w-6 -translate-y-1/2 border-0 bg-transparent p-0 text-muted-foreground opacity-70 shadow-none hover:bg-transparent hover:text-destructive hover:opacity-100 group-hover:grid group-focus-within:grid [&_svg]:h-3.5 [&_svg]:w-3.5`,size:`icon`,type:`button`,variant:`ghost`,disabled:ue===`running`,onClick:()=>V(e),children:(0,H.jsx)(se,{"aria-hidden":`true`})})]})]},e.id))]}),(0,H.jsxs)(`div`,{className:`mt-auto px-3 py-3`,children:[(0,H.jsxs)(`nav`,{className:`grid gap-1`,"aria-label":`Anvia links`,children:[(0,H.jsx)(CL,{href:`https://anvia.dev/docs`,label:`Anvia Docs`}),(0,H.jsx)(CL,{href:`https://anvia.dev`,label:`Anvia Web`})]}),(0,H.jsx)(`span`,{className:`sr-only`,"aria-live":`polite`,children:oe})]})]}),(0,H.jsxs)(`main`,{className:`grid h-[100dvh] min-w-0 grid-rows-[52px_minmax(0,1fr)] overflow-hidden bg-background/80`,children:[(0,H.jsx)(`header`,{className:`grid min-h-13 bg-background/88 backdrop-blur`,children:(0,H.jsxs)(`div`,{className:`grid min-h-13 grid-cols-[minmax(0,1fr)_auto] items-center gap-3 py-0 pl-0 pr-6`,children:[(0,H.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 text-sm font-medium`,children:[(0,H.jsx)(`span`,{className:`text-primary`,children:F===`playground`?`Agents`:`Studio`}),(0,H.jsx)(`span`,{className:`text-muted-foreground`,children:`/`}),(0,H.jsx)(`span`,{className:`truncate`,children:ot?.name??ot?.id??`Agent`})]}),(0,H.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,H.jsx)(er,{"aria-label":te===`dark`?`Switch to light theme`:`Switch to dark theme`,className:`h-8 min-h-8 w-8 border-transparent bg-transparent p-0 text-muted-foreground hover:bg-muted hover:text-foreground`,title:te===`dark`?`Switch to light theme`:`Switch to dark theme`,type:`button`,variant:`secondary`,size:`icon`,onClick:()=>ne(e=>e===`dark`?`light`:`dark`),children:te===`dark`?(0,H.jsx)(et,{"aria-hidden":`true`}):(0,H.jsx)(ze,{"aria-hidden":`true`})}),(0,H.jsx)(er,{className:`h-8 min-h-8 border-transparent bg-transparent px-3 font-mono text-xs text-muted-foreground hover:bg-muted hover:text-foreground`,type:`button`,variant:`secondary`,onClick:()=>Gt(`sessions`),children:`Sessions`}),(0,H.jsxs)(er,{className:`h-8 min-h-8 gap-1.5 rounded-lg border-0 bg-primary px-3 font-mono text-xs text-primary-foreground hover:bg-primary/90`,type:`button`,onClick:()=>St(),children:[(0,H.jsx)(qe,{"aria-hidden":`true`}),`New session`]})]})]})}),F===`playground`?(0,H.jsxs)(`section`,{className:`grid h-full min-h-0 min-w-0 max-h-full max-w-full grid-cols-[minmax(0,1fr)_minmax(0,460px)] overflow-hidden bg-background/45 max-xl:grid-cols-1`,children:[(0,H.jsx)(`div`,{className:`grid min-h-0 min-w-0 pb-6 pr-6`,children:(0,H.jsxs)(`div`,{className:`grid h-full min-h-0 min-w-0 grid-rows-[minmax(0,1fr)_auto] overflow-hidden rounded-lg border border-border/80 bg-card/70 p-2 shadow-sm`,children:[(0,H.jsx)(`section`,{className:`min-h-0 overflow-y-auto overflow-x-hidden px-4 py-4 [scrollbar-gutter:stable]`,ref:Ge,onScroll:Je,children:(0,H.jsxs)(`div`,{className:`mx-auto grid min-h-full w-full max-w-235 content-start items-start gap-6 pb-8`,children:[ct?null:(0,H.jsx)(`div`,{className:`grid min-h-96 place-items-center text-sm font-medium text-muted-foreground`,children:(0,H.jsxs)(`div`,{className:`grid max-w-xl gap-4 text-center`,children:[(0,H.jsx)(`div`,{className:`mx-auto h-px w-28 bg-primary/45`}),(0,H.jsx)(`h1`,{className:`m-0 text-4xl font-semibold leading-tight text-foreground text-balance`,children:`What should this agent work on?`}),(0,H.jsx)(`p`,{className:`m-0 text-base leading-7 text-muted-foreground text-pretty`,children:`Choose a prompt below or write a task. Studio will stream the response, tool calls, approvals, and trace data here.`})]})}),E.map(e=>(0,H.jsx)(ON,{entry:e,decidingApprovals:fe,answeringQuestions:me,onApprovalDecision:(e,t)=>void Pt(e,t),onQuestionAnswer:(e,t)=>void Ft(e,t),onOpenTrace:qt},e.entryId))]})}),(0,H.jsxs)(`form`,{className:`grid gap-3 bg-gradient-to-t from-card via-card/95 to-card/0 px-4 pb-4 pt-2`,onSubmit:e=>{e.preventDefault(),Tt(O)},children:[ct||st.length===0?null:(0,H.jsx)(`div`,{className:`mx-auto grid w-full max-w-235 grid-cols-3 gap-2 max-md:grid-cols-1`,children:st.map(e=>(0,H.jsx)(er,{className:`h-auto min-h-16 justify-start whitespace-normal rounded-lg border border-border/80 bg-card/85 px-3 py-2.5 text-left text-sm font-medium leading-5 text-foreground shadow-sm hover:border-primary/45 hover:bg-primary/10 hover:text-primary`,type:`button`,variant:`ghost`,disabled:ue===`running`||r.length===0,onClick:()=>void Tt(e),children:(0,H.jsx)(`span`,{className:`min-w-0 whitespace-normal wrap-break-words`,children:e})},e))}),(0,H.jsxs)(`div`,{className:`mx-auto grid w-full max-w-235 gap-2 rounded-lg border border-border/80 bg-card/95 p-2.5 shadow-xl shadow-black/35 backdrop-blur focus-within:border-primary focus-within:ring-2 focus-within:ring-primary/25`,children:[(0,H.jsx)(Bl,{className:`min-h-16 min-w-0 resize-none rounded-lg border-0 bg-transparent px-3 py-3 text-[15px] leading-7 text-foreground shadow-none outline-none ring-0 placeholder:text-muted-foreground/70 focus:border-transparent focus:ring-0`,ref:We,rows:1,value:O,onChange:Ut,onKeyDown:Wt,placeholder:`Ask anything...`}),(0,H.jsxs)(`div`,{className:`flex min-w-0 items-center justify-between gap-2`,children:[(0,H.jsx)(`div`,{}),(0,H.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[rt.length>1?(0,H.jsxs)(Ll,{value:ot?.id??r,onValueChange:Ct,disabled:ue===`running`,children:[(0,H.jsx)(zl,{"aria-label":`Select agent`,className:`hidden h-8 min-h-8 w-auto max-w-64 gap-2 border-0 bg-transparent px-2 py-1 font-mono text-xs font-medium text-muted-foreground shadow-none hover:bg-accent hover:text-accent-foreground sm:flex`,children:(0,H.jsx)(Rl,{placeholder:`Agent`})}),(0,H.jsx)(q,{align:`end`,children:rt.map(e=>(0,H.jsx)(J,{value:e.id,children:e.name??e.id},e.id))})]}):(0,H.jsx)(`span`,{className:`hidden max-w-60 truncate rounded-lg px-2 py-1 font-mono text-xs font-medium text-muted-foreground sm:block`,children:ot?.name??ot?.id??`Agent`}),(0,H.jsx)(er,{"aria-label":ue===`running`?`Running`:`Send message`,className:`h-9 min-h-9 w-9 rounded-lg border-primary bg-primary text-primary-foreground hover:bg-primary/90`,size:`icon`,type:`submit`,disabled:ue===`running`||r.length===0,children:(0,H.jsx)(_e,{})})]})]})]})]})]})}),(0,H.jsx)(LN,{logs:_,selectedSessionId:d,loading:ye===`loading`})]}):null,F===`tracing`?(0,H.jsx)(mI,{agents:rt,traces:h,tracesEnabled:Ze,traceLoadState:xe,selectedTraceId:R,traceSessionDetailId:ie,onRefresh:()=>void ft(),onSelectTrace:qt,onShowSessionTraces:e=>void pt(e)}):null,F===`sessions`?(0,H.jsx)(zP,{agents:rt,sessions:p,sessionsEnabled:Xe,sessionLoadState:ge,selectedSessionId:d,onOpenSession:e=>void xt(e),onViewSessionTracing:e=>void pt(e),onDeleteSession:V}):null,F===`agents`?(0,H.jsx)(Ul,{agents:rt,selectedAgentId:r}):null,F===`tools`?(0,H.jsx)(vF,{agents:rt,selectedAgentId:s||ot?.id||r,summary:je,enabled:tt,loading:Ne===`loading`,onSelectAgent:e=>{c(e),_t(e)}}):null,F===`pipelines`?(0,H.jsx)(tN,{pipelines:it,selectedPipelineId:l,detail:b,logs:S,activeRunId:P,runs:w,enabled:nt,detailLoading:Fe===`loading`,logsLoading:Le===`loading`,runsLoading:Be===`loading`,runState:He,runInput:A,runOutput:M,theme:te,onSelectPipeline:e=>{u(e),N(``),ee(``),bt(e)},onRunInputChange:j,onRun:()=>void Et()}):null,F===`mcps`?(0,H.jsx)(Cb,{agents:rt,selectedAgentId:a||ot?.id||r,summary:De,enabled:$e,loading:ke===`loading`,onSelectAgent:e=>{o(e),gt(e)}}):null,F===`knowledge`?(0,H.jsx)(rb,{activeTab:re,enabled:Qe,summary:Ce,loading:Te===`loading`,onOpenTrace:qt,onRefresh:()=>void ht(),onSelectTab:Kt}):null]}),(0,H.jsx)(BP,{session:ae,onOpenChange:e=>{e||V(void 0)},onConfirm:e=>void wt(e)})]})}function CL(e){return(0,H.jsxs)(`a`,{className:`flex h-8 min-h-8 items-center justify-between rounded-lg px-2 font-mono text-[11px] font-semibold text-sidebar-foreground/62 transition duration-200 hover:bg-sidebar-accent hover:text-sidebar-foreground`,href:e.href,target:`_blank`,rel:`noreferrer`,children:[(0,H.jsx)(`span`,{children:e.label}),(0,H.jsx)(he,{"aria-hidden":`true`,className:`h-3 w-3 text-muted-foreground`})]})}function wL(e){return DL(e)&&e.type===`pipeline_log`&&DL(e.log)}function TL(e){return DL(e)&&e.type===`pipeline_final`&&`output`in e}function EL(e){return DL(e)&&e.type===`error`}function DL(e){return typeof e==`object`&&!!e}function OL(e,t){let n=[...t].sort((e,t)=>Date.parse(e.startedAt)-Date.parse(t.startedAt)).map(e=>e.id),r=0,i,a=e.map(e=>e.kind===`message`&&e.role===`assistant`?kL(e):e);function o(){if(i===void 0)return;let e=n[r];r+=1,e!==void 0&&(a[i]={...a[i],traceId:e}),i=void 0}for(let[e,t]of a.entries()){if(t.kind===`message`&&t.role===`user`){o();continue}t.kind===`message`&&t.role===`assistant`&&(i=e)}return o(),a}function kL(e){let{traceId:t,...n}=e;return n}var AL=document.getElementById(`anvia-ui`);AL!==null&&(0,at.createRoot)(AL).render((0,H.jsx)(SL,{}));
|
|
100
|
-
//# sourceMappingURL=index-
|
|
99
|
+
`)}]}function UI(e,t,n){if(My(e)){let t=typeof e.type==`string`?e.type:void 0;if(n===`choice`){if(t===`text`)return`Assistant output`;if(t===`reasoning`)return`Reasoning`}if(t===`reasoning`)return`Reasoning`;if(typeof e.role==`string`)return WI(e.role);if(t!==void 0)return WI(t)}return`${n===void 0?`Item`:`${WI(n)} item`} ${t+1}`}function WI(e){return e.replace(/[_-]+/g,` `).replace(/([a-z0-9])([A-Z])/g,`$1 $2`).trim().replace(/\b\w/g,e=>e.toUpperCase())}function GI(e){let t=e.instructions;return typeof t!=`string`||t.trim().length===0?[]:[{label:`System prompt`,text:t}]}function KI(e){if(e===void 0)return`undefined`;if(e===null)return`null`;if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`)return String(e);try{return JSON.stringify(e,null,2)}catch{return String(e)}}function qI(e){let t=new Map;for(let n of e.observations){let e=Number.isFinite(n.turn)?n.turn:t.size+1;t.set(e,[...t.get(e)??[],n])}return[...t.entries()].sort(([e],[t])=>e-t).map(([e,t])=>({turn:e,observations:t,durationMs:t.reduce((e,t)=>e+(t.durationMs??0),0)}))}function JI(e){let t=new Map;for(let n of e)t.set(n.id,{observation:n,children:[]});let n=[];for(let r of e){let e=t.get(r.id);if(e===void 0)continue;let i=r.parentObservationId,a=i===void 0?void 0:t.get(i);a===void 0?n.push(e):a.children.push(e)}return n}function YI(e,t,n){if(n===`agent`)return{title:`agent.run`,tone:`agent`,startedAt:Py(e.startedAt),durationMs:e.durationMs,firstDeltaMs:cL(e.observations),usage:Ly(e.usage),input:e.input,output:e.output,error:e.error,metadata:XI(e)};if(n.startsWith(`turn:`)){let r=Number(n.slice(5)),i=t.find(e=>e.turn===r);return{title:`turn.${Number.isFinite(r)?r:1}`,tone:`turn`,startedAt:Py(i?.observations[0]?.startedAt??e.startedAt),durationMs:i?.durationMs,firstDeltaMs:cL(i?.observations??[]),usage:mL(i?.observations??[]),input:i?.observations[0]?.input,output:i?.observations.at(-1)?.output,metadata:ZI(r,i?.observations??[])}}if(n.startsWith(`observation:`)){let t=n.slice(12),r=e.observations.find(e=>e.id===t);if(r!==void 0)return{title:sL(r),tone:r.kind,startedAt:Py(r.startedAt),durationMs:r.durationMs,firstDeltaMs:lL(r.metadata),usage:pL(r),input:r.input,output:r.output,error:r.error,metadata:QI(r)}}return{title:e.name??`Agent`,tone:`trace`,startedAt:Py(e.startedAt),durationMs:e.durationMs,firstDeltaMs:cL(e.observations),usage:Ly(e.usage),input:e.input,output:e.output,error:e.error,metadata:XI(e)}}function XI(e){let t=My(e.metadata)?e.metadata:{},n=oL({status:e.status,traceId:e.trace?.traceId??e.id,observationId:e.trace?.observationId,sessionId:e.sessionId,observationCount:e.observationCount,messageCount:aL(t.messages),startedAt:e.startedAt,endedAt:e.endedAt,durationMs:e.durationMs});return oL({...t,status:e.status,traceId:e.trace?.traceId??e.id,observationId:e.trace?.observationId,sessionId:e.sessionId,observationCount:e.observationCount,messageCount:aL(t.messages),startedAt:e.startedAt,endedAt:e.endedAt,durationMs:e.durationMs,trace:My(t.trace)?t.trace:n})}function ZI(e,t){return oL({turn:e,observationCount:t.length,generationCount:t.filter(e=>e.kind===`generation`).length,toolCount:t.filter(e=>e.kind===`tool`).length,agentCount:t.filter(e=>e.kind===`agent`).length,firstDeltaMs:cL(t),status:iL(t),startedAt:t[0]?.startedAt,endedAt:t.at(-1)?.endedAt})}function QI(e){let t=oL({...My(e.metadata)?e.metadata:{},status:e.status,kind:e.kind,turn:e.turn,parentObservationId:e.parentObservationId??null,startedAt:e.startedAt,endedAt:e.endedAt??null,durationMs:e.durationMs});return oL({...t,trace:My(t.trace)?t.trace:oL({status:e.status,kind:e.kind,turn:e.turn,parentObservationId:e.parentObservationId??null,startedAt:e.startedAt,endedAt:e.endedAt??null,durationMs:e.durationMs}),modelInfo:My(t.modelInfo)?t.modelInfo:$I(t),modelCall:My(t.modelCall)?t.modelCall:eL(t),response:My(t.response)?t.response:tL(t),tools:My(t.tools)?t.tools:nL(t),timing:My(t.timing)?t.timing:rL(t)})}function $I(e){let t=oL({provider:e.provider,model:e.model,requestedModel:e.requestedModel,defaultModel:e.defaultModel});return Object.keys(t).length===0?void 0:t}function eL(e){let t=oL({messageCount:e.historyCount,documentCount:e.documentCount,toolCount:e.toolCount,toolNames:e.toolNames,temperature:e.temperature,maxTokens:e.maxTokens,toolChoice:e.toolChoice,hasOutputSchema:e.hasOutputSchema,additionalParamKeys:e.additionalParamKeys}),n=oL({request:Object.keys(t).length===0?void 0:t,providerRequest:e.providerRequest});return Object.keys(n).length===0?void 0:n}function tL(e){let t=oL({messageId:e.messageId,usage:e.usage,providerResponse:e.providerResponse});return Object.keys(t).length===0?void 0:t}function nL(e){let t=oL({count:e.toolCount,names:e.toolNames,toolChoice:e.toolChoice,internalCallId:e.internalCallId,toolCallId:e.toolCallId,skipped:e.skipped,description:e.toolDescription,parameterKeys:e.parameterKeys,requiredParameterKeys:e.requiredParameterKeys,approvalRequired:e.approvalRequired,mcpServerName:e.mcpServerName,argumentBytes:e.argumentBytes,resultBytes:e.resultBytes});return Object.keys(t).length===0?void 0:t}function rL(e){let t=oL({firstDeltaMs:e.firstDeltaMs,durationMs:e.durationMs,startedAt:e.startedAt,endedAt:e.endedAt});return Object.keys(t).length===0?void 0:t}function iL(e){return e.length===0?`empty`:e.some(e=>e.status===`error`)?`error`:e.some(e=>e.status===`running`)?`running`:`success`}function aL(e){return Array.isArray(e)?e.length:void 0}function oL(e){return Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0))}function sL(e){return e.kind===`agent`?e.name:e.kind===`tool`?`tool.${e.name}`:e.name}function cL(e){for(let t of e){let e=lL(t.metadata);if(e!==void 0)return e}}function lL(e){if(!(!My(e)||typeof e.firstDeltaMs!=`number`))return e.firstDeltaMs}function uL(e){switch(e){case`success`:return`bg-primary`;case`error`:return`bg-destructive`;case`running`:return`bg-chart-2`}}function dL(e){switch(e.tone){case`trace`:return(0,H.jsx)(Ve,{"aria-hidden":`true`});case`agent`:return(0,H.jsx)(Xe,{"aria-hidden":`true`});case`turn`:return(0,H.jsx)(Fe,{"aria-hidden":`true`});case`generation`:return(0,H.jsx)(De,{"aria-hidden":`true`});case`tool`:return(0,H.jsx)(it,{"aria-hidden":`true`})}}function fL(e){switch(e){case`trace`:return`bg-primary text-background`;case`agent`:return`bg-chart-2 text-background`;case`turn`:return`bg-chart-4 text-background`;case`generation`:return`bg-chart-1 text-background`;case`tool`:return`bg-chart-5 text-background`}}function pL(e){return!My(e.output)||!My(e.output.usage)?``:hL(e.output.usage)}function mL(e){return e.map(pL).filter(e=>e.length>0).join(` + `)}function hL(e){let t=typeof e.inputTokens==`number`?e.inputTokens:0,n=typeof e.outputTokens==`number`?e.outputTokens:0,r=typeof e.totalTokens==`number`?e.totalTokens:t+n;return r===0?``:`${t} -> ${n} (Σ ${r})`}var gL=`anvia-studio-theme`;function _L(){if(typeof window>`u`)return`dark`;try{let e=window.localStorage.getItem(gL);return e===`light`||e===`dark`?e:`dark`}catch{return`dark`}}function vL(e){typeof document>`u`||(document.documentElement.classList.toggle(`dark`,e===`dark`),document.documentElement.style.colorScheme=e)}function yL(e){try{window.localStorage.setItem(gL,e)}catch{}}var bL=_L();vL(bL);async function xL(e,t){let n=``;try{let t=await e.json();typeof t==`object`&&t&&`error`in t&&typeof t.error==`object`&&t.error!==null&&`message`in t.error&&typeof t.error.message==`string`&&(n=`: ${t.error.message}`)}catch{}return`${t} with HTTP ${e.status}${n}`}function SL(){let e=KP(),[t,n]=(0,v.useState)(),[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(``),[s,c]=(0,v.useState)(``),[l,u]=(0,v.useState)(``),[d,f]=(0,v.useState)(``),[p,m]=(0,v.useState)([]),[h,g]=(0,v.useState)([]),[_,y]=(0,v.useState)([]),[b,x]=(0,v.useState)(),[S,C]=(0,v.useState)([]),[w,T]=(0,v.useState)([]),[E,D]=(0,v.useState)([]),[O,k]=(0,v.useState)(``),[A,j]=(0,v.useState)(`"Hello from Studio"`),[M,N]=(0,v.useState)(``),[P,ee]=(0,v.useState)(``),[F,I]=(0,v.useState)(()=>e.page),[te,ne]=(0,v.useState)(()=>bL),[re,L]=(0,v.useState)(()=>e.knowledgeTab??`static-context`),[R,z]=(0,v.useState)(()=>e.traceId??``),[ie,B]=(0,v.useState)(()=>e.traceSessionId),[ae,V]=(0,v.useState)(),[oe,ce]=(0,v.useState)(`Loading`),[,le]=(0,v.useState)(``),[ue,de]=(0,v.useState)(`idle`),[fe,pe]=(0,v.useState)(()=>new Set),[me,he]=(0,v.useState)(()=>new Set),[ge,ve]=(0,v.useState)(`idle`),[ye,be]=(0,v.useState)(`idle`),[xe,Se]=(0,v.useState)(`idle`),[Ce,we]=(0,v.useState)(),[Te,Ee]=(0,v.useState)(`idle`),[De,Oe]=(0,v.useState)(),[ke,Ae]=(0,v.useState)(`idle`),[je,Me]=(0,v.useState)(),[Ne,Pe]=(0,v.useState)(`idle`),[Fe,Ie]=(0,v.useState)(`idle`),[Le,Re]=(0,v.useState)(`idle`),[Be,Ve]=(0,v.useState)(`idle`),[He,Ue]=(0,v.useState)(`idle`),We=(0,v.useRef)(null),Ge=(0,v.useRef)(null),Ke=(0,v.useRef)(!0);function Je(){let e=Ge.current;e!==null&&(Ke.current=e.scrollHeight-e.scrollTop-e.clientHeight<80)}(0,v.useEffect)(()=>{if(F!==`playground`||E.length===0||!Ke.current)return;let e=window.requestAnimationFrame(()=>{let e=Ge.current;e!==null&&(e.scrollTop=e.scrollHeight)});return()=>window.cancelAnimationFrame(e)},[F,E]);let Ye=(0,v.useCallback)(async()=>{ce(`Loading`),le(``);try{let e=await fetch(`/config`);if(e.status===401){ce(`Authentication required`);return}if(!e.ok)throw Error(`Config failed with HTTP ${e.status}`);let t=await e.json();n(t),i(e=>e||t.agents[0]?.id||``),o(e=>e||t.agents[0]?.id||``),c(e=>e||t.agents[0]?.id||``),u(e=>e||t.pipelines[0]?.id||``),ce(`Connected`)}catch(e){le(Ky(e)),ce(`Config error`)}},[]);(0,v.useEffect)(()=>{Ye()},[Ye]);let Xe=t?.capabilities.sessions?.enabled===!0,Ze=t?.capabilities.traces?.enabled===!0,Qe=t?.capabilities.knowledge?.enabled===!0,$e=t?.capabilities.mcps?.enabled===!0,tt=t?.capabilities.tools?.enabled===!0,nt=t?.capabilities.pipelines?.enabled===!0,rt=t?.agents??[],it=t?.pipelines??[],at=rt.length>0,ot=rt.find(e=>e.id===r)??rt[0]??void 0,st=ot?.quickPrompts??[],ct=E.length>0;(0,v.useEffect)(()=>{vL(te),yL(te)},[te]);let lt=(0,v.useCallback)(async()=>{if(!Xe){m([]);return}try{let e=await fetch(`/sessions?limit=100`);if(!e.ok)throw Error(`Sessions failed with HTTP ${e.status}`);m((await e.json()).sessions)}catch(e){le(Ky(e))}},[Xe]);(0,v.useEffect)(()=>{lt()},[lt]);let ut=(0,v.useCallback)(async e=>{if(!Xe)return y([]),[];be(`loading`);try{let t=new URLSearchParams({limit:`1000`}),n=await fetch(`/sessions/${encodeURIComponent(e)}/logs?${t}`);if(!n.ok)throw Error(`Session logs failed with HTTP ${n.status}`);let r=await n.json();return y(r.logs),r.logs}catch(e){return le(Ky(e)),y([]),[]}finally{be(`idle`)}},[Xe]);async function dt(e){let t=ot?.id??r,n=await fetch(`/sessions`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({agentId:t,title:e,metadata:{source:`anvia-studio`}})});if(!n.ok)throw Error(await xL(n,`Session create failed`));let i=await n.json();return f(i.id),m(e=>[i,...e.filter(e=>e.id!==i.id)]),XP(i.id),await ut(i.id),i}let ft=(0,v.useCallback)(async()=>{if(!Ze){g([]);return}Se(`loading`);try{let e=new URLSearchParams({limit:`50`}),t=await fetch(`/traces?${e.toString()}`);if(!t.ok)throw Error(`Traces failed with HTTP ${t.status}`);let n=await t.json(),r=await Promise.all(n.traces.map(async e=>{let t=await fetch(`/traces/${encodeURIComponent(e.id)}`);if(!t.ok)throw Error(`Trace load failed with HTTP ${t.status}`);return await t.json()}));if(R.length>0&&!r.some(e=>e.id===R)){let e=await fetch(`/traces/${encodeURIComponent(R)}`);if(e.ok){g([await e.json(),...r]);return}}g(r)}catch(e){le(Ky(e))}finally{Se(`idle`)}},[R,Ze]),pt=(0,v.useCallback)(async(e,t={})=>{if(Ze){Se(`loading`);try{let n=new URLSearchParams({limit:`50`,sessionId:e}),r=await fetch(`/traces?${n.toString()}`);if(!r.ok)throw Error(`Session traces failed with HTTP ${r.status}`);let i=await r.json(),a=[...await Promise.all(i.traces.map(async e=>{let t=await fetch(`/traces/${encodeURIComponent(e.id)}`);if(!t.ok)throw Error(`Trace load failed with HTTP ${t.status}`);return await t.json()}))].sort((e,t)=>Date.parse(e.startedAt)-Date.parse(t.startedAt));g(a);let o=a[0]?.id;if(o===void 0){z(``),B(e),t.updatePath!==!1&&QP(e);return}I(`tracing`),z(o),B(e),t.updatePath!==!1&&QP(e)}catch(e){le(Ky(e))}finally{Se(`idle`)}}},[Ze]),mt=(0,v.useCallback)(async e=>{if(!Ze)return[];let t=new URLSearchParams({limit:`100`}),n=await fetch(`/sessions/${encodeURIComponent(e)}/traces?${t}`);return n.ok?(await n.json()).traces:[]},[Ze]);(0,v.useEffect)(()=>{F!==`tracing`||ie!==void 0||ft()},[F,ft,ie]);let ht=(0,v.useCallback)(async()=>{if(!Qe){we(void 0);return}Ee(`loading`);try{let e=await fetch(`/knowledge?limit=25`);if(!e.ok)throw Error(`Knowledge failed with HTTP ${e.status}`);we(await e.json())}catch(e){le(Ky(e))}finally{Ee(`idle`)}},[Qe]);(0,v.useEffect)(()=>{F===`knowledge`&&ht()},[F,ht]);let gt=(0,v.useCallback)(async e=>{if(!$e||e.length===0){Oe(void 0);return}Ae(`loading`);try{let t=await fetch(`/agents/${encodeURIComponent(e)}/mcps`);if(!t.ok)throw Error(`MCPs failed with HTTP ${t.status}`);Oe(await t.json())}catch(e){le(Ky(e)),Oe(void 0)}finally{Ae(`idle`)}},[$e]);(0,v.useEffect)(()=>{F===`mcps`&>(a||r)},[F,gt,a,r]);let _t=(0,v.useCallback)(async e=>{if(!tt||e.length===0){Me(void 0);return}Pe(`loading`);try{let t=await fetch(`/agents/${encodeURIComponent(e)}/tools`);if(!t.ok)throw Error(`Tools failed with HTTP ${t.status}`);Me(await t.json())}catch(e){le(Ky(e)),Me(void 0)}finally{Pe(`idle`)}},[tt]);(0,v.useEffect)(()=>{F===`tools`&&_t(s||r)},[F,_t,r,s]);let vt=(0,v.useCallback)(async e=>{if(!nt||e.length===0)return C([]),[];Re(`loading`);try{let t=new URLSearchParams({limit:`1000`}),n=await fetch(`/pipelines/${encodeURIComponent(e)}/logs?${t}`);if(!n.ok)throw Error(`Pipeline logs failed with HTTP ${n.status}`);let r=await n.json();return C(r.logs),r.logs}catch(e){return le(Ky(e)),C([]),[]}finally{Re(`idle`)}},[nt]),yt=(0,v.useCallback)(async e=>{if(!nt||e.length===0)return T([]),[];Ve(`loading`);try{let t=new URLSearchParams({limit:`50`}),n=await fetch(`/pipelines/${encodeURIComponent(e)}/runs?${t}`);if(!n.ok)throw Error(`Pipeline runs failed with HTTP ${n.status}`);let r=await n.json();return T(r.runs),r.runs}catch(e){return le(Ky(e)),T([]),[]}finally{Ve(`idle`)}},[nt]),bt=(0,v.useCallback)(async e=>{if(!nt||e.length===0){x(void 0),C([]),T([]);return}Ie(`loading`),le(``);try{let t=await fetch(`/pipelines/${encodeURIComponent(e)}`);if(!t.ok)throw Error(`Pipeline load failed with HTTP ${t.status}`);u(e),x(await t.json()),await Promise.all([vt(e),yt(e)])}catch(e){le(Ky(e)),x(void 0)}finally{Ie(`idle`)}},[vt,yt,nt]);(0,v.useEffect)(()=>{if(F!==`pipelines`)return;let e=l||t?.pipelines[0]?.id||``;e.length>0&&bt(e)},[F,t?.pipelines,bt,l]);let xt=(0,v.useCallback)(async(e,t={})=>{if(ue!==`running`){ve(`loading`),le(``);try{let n=await fetch(`/sessions/${encodeURIComponent(e)}`);if(!n.ok)throw Error(`Session load failed with HTTP ${n.status}`);let r=await n.json(),[a]=await Promise.all([mt(r.id),ut(r.id)]);rF(lF(r.transcript)),i(r.agentId),f(r.id),D(OL(r.transcript,a)),t.updatePath!==!1&&(I(`playground`),XP(r.id)),ce(`Connected`)}catch(e){le(Ky(e))}finally{ve(`idle`)}}},[ue,mt,ut]),St=(0,v.useCallback)((e={})=>{ue!==`running`&&(iF(),f(``),y([]),D([]),k(``),I(`playground`),le(``),e.updatePath!==!1&&XP(void 0),requestAnimationFrame(()=>sF(We.current)))},[ue]),Ct=(0,v.useCallback)(e=>{ue===`running`||e===r||(i(e),iF(),f(``),y([]),D([]),k(``),I(`playground`),le(``),XP(void 0),requestAnimationFrame(()=>sF(We.current)))},[ue,r]);async function wt(e){if(ue!==`running`){le(``);try{let t=await fetch(`/sessions/${encodeURIComponent(e.id)}`,{method:`DELETE`});if(!t.ok)throw Error(`Session delete failed with HTTP ${t.status}`);m(t=>t.filter(t=>t.id!==e.id)),g(t=>t.filter(t=>t.sessionId!==e.id)),d===e.id&&(iF(),f(``),y([]),D([]),k(``),F===`playground`&&XP(void 0)),ce(`Connected`)}catch(e){le(Ky(e))}finally{V(void 0)}}}(0,v.useEffect)(()=>{if(!Xe)return;let e=KP();if(I(e.page),L(e.knowledgeTab??`static-context`),z(e.traceId??``),B(e.traceSessionId),e.page===`tracing`&&e.traceSessionId!==void 0){pt(e.traceSessionId,{updatePath:!1});return}e.page!==`playground`||e.sessionId===void 0||e.sessionId===d||xt(e.sessionId,{updatePath:!1})},[d,Xe,xt,pt]),(0,v.useEffect)(()=>{function e(){let e=KP();if(I(e.page),L(e.knowledgeTab??`static-context`),z(e.traceId??``),B(e.traceSessionId),e.page===`tracing`&&e.traceSessionId!==void 0){pt(e.traceSessionId,{updatePath:!1});return}if(e.page===`playground`){if(e.sessionId===void 0){St({updatePath:!1});return}xt(e.sessionId,{updatePath:!1})}}return window.addEventListener(`popstate`,e),()=>window.removeEventListener(`popstate`,e)},[xt,pt,St]);async function Tt(e){let t=e.trim(),n=ot?.id??r;if(!(t.length===0||n.length===0||ue===`running`)){de(`running`),I(`playground`),le(``),k(``),Ke.current=!0,requestAnimationFrame(()=>sF(We.current)),D(e=>[...e,{entryId:cF(),kind:`message`,role:`user`,text:t}]);try{let e=Xe&&d.length===0?(await dt(Gy(t))).id:d,r=Xe?void 0:aF(E),i=await fetch(`/agents/${encodeURIComponent(n)}/runs`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({message:t,...e.length===0?{}:{sessionId:e},...r===void 0?{}:{history:r},stream:!0,metadata:{source:`anvia-studio`}})});if(i.status===401)throw Error(`Authentication required`);if(!i.ok||i.body===null)throw Error(`Run failed with HTTP ${i.status}`);if(await mF(i.body,async e=>{Dt(e)&&await hF()}),await lt(),e.length>0){f(e);let[t]=await Promise.all([mt(e),ut(e)]);D(e=>OL(e,t))}ce(`Connected`)}catch(e){let t=Ky(e);le(t),At(`\n${t}`)}finally{de(`idle`)}}}async function Et(){let e=l||t?.pipelines[0]?.id||``;if(e.length===0||He===`running`)return;let n;try{n=JSON.parse(A)}catch{le(`Pipeline input must be valid JSON`);return}Ue(`running`),N(``),ee(``),le(``);try{let t=await fetch(`/pipelines/${encodeURIComponent(e)}/runs`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({input:n,stream:!0,metadata:{source:`anvia-studio`}})});if(!t.ok||t.body===null)throw Error(await xL(t,`Pipeline run failed`));await mF(t.body,async e=>{if(wL(e)){e.log.runId!==void 0&&ee(t=>t||e.log.runId||``),kt(e.log),await hF();return}if(TL(e)){N(JSON.stringify(e.output,null,2)),await hF();return}if(EL(e))throw Error(JSON.stringify(e.error))}),await Promise.all([vt(e),yt(e)]),ce(`Connected`)}catch(e){le(Ky(e))}finally{Ue(`idle`)}}function Dt(e){return e.type===`text_delta`?(At(e.delta),!0):e.type===`reasoning_delta`?(It(e.delta,e.id),!0):e.type===`tool_call`?(Lt(e.toolCall.function.name,Uy(e.toolCall.function.arguments),e.toolCall.callId??e.toolCall.id),!0):e.type===`tool_result`?(Rt({toolName:e.toolName,callId:e.toolCallId,args:e.args,result:e.result,...e.structuredResult===void 0?{}:{structuredResult:e.structuredResult}}),!0):e.type===`agent_tool_event`?(zt(e),!0):e.type===`tool_approval_request`||e.type===`tool_approval_result`?(Mt(e.approval),!0):e.type===`tool_question_request`||e.type===`tool_question_result`?(Nt(e.question),!0):e.type===`session_log`?(Ot(e.log),!0):e.type===`final`&&e.trace?.traceId!==void 0?(jt(e.trace.traceId),!0):(e.type===`error`&&le(JSON.stringify(e.error)),!1)}function Ot(e){y(t=>t.some(t=>t.id===e.id)?t:[...t,e].sort((e,t)=>e.sequence-t.sequence))}function kt(e){C(t=>t.some(t=>t.id===e.id)?t:[...t,e].sort((e,t)=>e.sequence-t.sequence))}function At(e){D(t=>{let n=[...t],r=n.at(-1);return r?.kind===`message`&&r.role===`assistant`?n[n.length-1]={...r,text:`${r.text}${e}`}:n.push({entryId:cF(),kind:`message`,role:`assistant`,text:e}),n})}function jt(e){D(t=>{let n=[...t];for(let t=n.length-1;t>=0;--t){let r=n[t];if(r?.kind===`message`&&r.role===`assistant`){n[t]={...r,traceId:e};break}}return n})}function Mt(e){D(t=>{let n=[...t],r=dF(n,e.toolName,e.callId);if(r<0)return n.push({entryId:cF(),kind:`tool`,toolName:e.toolName,...e.callId===void 0?{}:{callId:e.callId},approval:{id:e.id,status:e.status,requestedAt:e.requestedAt,...e.resolvedAt===void 0?{}:{resolvedAt:e.resolvedAt},...e.reason===void 0?{}:{reason:e.reason}}}),n;let i=n[r];return i!==void 0&&i.kind===`tool`&&(n[r]={...i,approval:{id:e.id,status:e.status,requestedAt:e.requestedAt,...e.resolvedAt===void 0?{}:{resolvedAt:e.resolvedAt},...e.reason===void 0?{}:{reason:e.reason}}}),n})}function Nt(e){D(t=>{let n=[...t],r=dF(n,e.toolName,e.callId);if(r<0)return n.push({entryId:cF(),kind:`tool`,toolName:e.toolName,...e.callId===void 0?{}:{callId:e.callId},question:{id:e.id,status:e.status,requestedAt:e.requestedAt,...e.answeredAt===void 0?{}:{answeredAt:e.answeredAt},questions:e.questions,...e.answers===void 0?{}:{answers:e.answers}}}),n;let i=n[r];return i!==void 0&&i.kind===`tool`&&(n[r]={...i,question:{id:e.id,status:e.status,requestedAt:e.requestedAt,...e.answeredAt===void 0?{}:{answeredAt:e.answeredAt},questions:e.questions,...e.answers===void 0?{}:{answers:e.answers}}}),n})}async function Pt(e,t){if(!fe.has(e)){pe(t=>new Set(t).add(e)),le(``);try{let n=await fetch(`/approvals/${encodeURIComponent(e)}/decision`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({approved:t})});if(!n.ok)throw Error(`Approval decision failed with HTTP ${n.status}`);Mt(await n.json())}catch(e){le(Ky(e))}finally{pe(t=>{let n=new Set(t);return n.delete(e),n})}}}async function Ft(e,t){if(!me.has(e)){he(t=>new Set(t).add(e)),le(``);try{let n=await fetch(`/questions/${encodeURIComponent(e)}/answer`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({answers:t})});if(!n.ok)throw Error(`Question answer failed with HTTP ${n.status}`);Nt(await n.json())}catch(e){le(Ky(e))}finally{he(t=>{let n=new Set(t);return n.delete(e),n})}}}function It(e,t){D(n=>{let r=[...n],i=r.at(-1);return i?.kind===`reasoning`&&(i.reasoningId??``)===(t??``)?r[r.length-1]={...i,text:`${i.text}${e}`}:r.push({entryId:cF(),kind:`reasoning`,...t===void 0?{}:{reasoningId:t},text:e}),r})}function Lt(e,t,n){D(r=>[...r,{entryId:cF(),kind:`tool`,toolName:e,...n===void 0?{}:{callId:n},...t.length===0?{}:{args:t}}])}function Rt(e){D(t=>{let n=[...t],r=uF(n,e.toolName,e.callId);if(r>=0){let t=n[r];if(t!==void 0&&t.kind===`tool`)return n[r]={...t,args:t.args??e.args,result:e.result,...e.structuredResult===void 0?{}:{structuredResult:e.structuredResult}},n}return n.push({entryId:cF(),kind:`tool`,toolName:e.toolName,...e.callId===void 0?{}:{callId:e.callId},args:e.args,result:e.result,...e.structuredResult===void 0?{}:{structuredResult:e.structuredResult}}),n})}function zt(e){let t=Bt(e);t!==void 0&&D(n=>{let r=[...n],i=uF(r,e.toolName,e.toolCallId);if(i<0)return r.push({entryId:cF(),kind:`tool`,toolName:e.toolName,...e.toolCallId===void 0?{}:{callId:e.toolCallId},childEvents:[t]}),r;let a=r[i];if(a===void 0||a.kind!==`tool`)return r;let o=[...a.childEvents??[]];return Vt(o,t),r[i]={...a,childEvents:o},r})}function Bt(e){let t=e.event;if(t.type===`text_delta`)return{kind:`message`,agentId:e.agentId,...e.agentName===void 0?{}:{agentName:e.agentName},text:t.delta};if(t.type===`reasoning_delta`)return{kind:`reasoning`,agentId:e.agentId,...e.agentName===void 0?{}:{agentName:e.agentName},...t.id===void 0?{}:{reasoningId:t.id},text:t.delta};if(t.type===`tool_call`)return{kind:`tool`,agentId:e.agentId,...e.agentName===void 0?{}:{agentName:e.agentName},toolName:t.toolCall.function.name,...t.toolCall.callId===void 0&&t.toolCall.id===void 0?{}:{callId:t.toolCall.callId??t.toolCall.id},args:Uy(t.toolCall.function.arguments)};if(t.type===`tool_result`)return{kind:`tool`,agentId:e.agentId,...e.agentName===void 0?{}:{agentName:e.agentName},toolName:t.toolName,...t.toolCallId===void 0?{}:{callId:t.toolCallId},args:t.args,result:t.result,...t.structuredResult===void 0?{}:{structuredResult:t.structuredResult}};if(t.type===`error`)return{kind:`message`,agentId:e.agentId,...e.agentName===void 0?{}:{agentName:e.agentName},text:`Error: ${Ky(t.error)}`}}function Vt(e,t){if(t.kind===`message`){let n=e.at(-1);n?.kind===`message`&&n.agentId===t.agentId?e[e.length-1]={...n,text:`${n.text}${t.text}`}:e.push(t);return}if(t.kind===`reasoning`){let n=e.at(-1);n?.kind===`reasoning`&&n.agentId===t.agentId&&(n.reasoningId??``)===(t.reasoningId??``)?e[e.length-1]={...n,text:`${n.text}${t.text}`}:e.push(t);return}let n=Ht(e,t);if(n<0){e.push(t);return}let r=e[n];r?.kind===`tool`&&(e[n]={...r,...r.args!==void 0||t.args===void 0?{}:{args:t.args},...t.result===void 0?{}:{result:t.result}})}function Ht(e,t){for(let n=e.length-1;n>=0;--n){let r=e[n];if(!(r?.kind!==`tool`||r.agentId!==t.agentId||r.toolName!==t.toolName||r.result!==void 0)&&(t.callId===void 0||r.callId===t.callId))return n}return-1}function Ut(e){k(oF(e)),sF(e.currentTarget)}function Wt(e){e.key!==`Enter`||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),Tt(O))}function Gt(e){if(!(e===`playground`&&!at)){if(I(e),e===`pipelines`){let e=l||it[0]?.id||``;e.length>0&&(u(e),bt(e))}if(e===`tracing`){z(``),B(void 0),JP(`tracing`);return}if(e===`knowledge`){z(``),B(void 0),YP(re);return}if(z(``),B(void 0),e===`playground`&&d.length>0){XP(d);return}JP(e)}}function Kt(e){I(`knowledge`),L(e),z(``),B(void 0),YP(e)}(0,v.useEffect)(()=>{if(t===void 0||at||F!==`playground`)return;let e=nt?`pipelines`:Xe?`sessions`:Ze?`tracing`:`agents`;if(iF(),f(``),y([]),D([]),k(``),I(e),JP(e),e===`pipelines`){let e=l||it[0]?.id||``;e.length>0&&(u(e),bt(e))}},[F,t,at,bt,it,nt,l,Xe,Ze]);function qt(e){if(I(`tracing`),z(e),B(void 0),e.length===0){JP(`tracing`);return}ZP(e)}return(0,H.jsxs)(`div`,{className:`grid h-[100dvh] min-h-0 overflow-hidden bg-background text-foreground lg:grid-cols-[228px_minmax(0,1fr)]`,children:[(0,H.jsxs)(`aside`,{className:`flex h-[100dvh] min-h-0 flex-col overflow-hidden bg-sidebar text-sidebar-foreground`,children:[(0,H.jsx)(`div`,{className:`flex h-15 items-center px-4`,children:(0,H.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2.5`,children:[(0,H.jsx)(`img`,{className:`h-7 w-7 shrink-0 object-contain`,src:WP,alt:``}),(0,H.jsx)(`span`,{className:`min-w-0 truncate`,children:(0,H.jsx)(`span`,{className:`anvia-wordmark text-[1.08rem] font-semibold tracking-normal text-sidebar-foreground`,children:`Anvia Studio`})})]})}),(0,H.jsxs)(`nav`,{className:`grid gap-0.5 px-3 py-3`,"aria-label":`Main`,children:[(0,H.jsx)(`div`,{className:`px-2.5 pb-1.5 font-mono text-[10px] font-semibold uppercase tracking-[0.18em] text-muted-foreground`,children:`Workspace`}),(0,H.jsx)(gF,{active:F===`playground`,icon:`message`,label:`Chat`,disabled:!at,onClick:()=>Gt(`playground`)}),(0,H.jsx)(gF,{active:F===`pipelines`,icon:`workflow`,label:`Pipelines`,disabled:!nt,onClick:()=>Gt(`pipelines`)}),(0,H.jsx)(gF,{active:F===`sessions`,icon:`list`,label:`Sessions`,onClick:()=>Gt(`sessions`)}),(0,H.jsx)(gF,{active:F===`tracing`,icon:`activity`,label:`Traces`,onClick:()=>Gt(`tracing`)})]}),(0,H.jsxs)(`nav`,{className:`grid gap-0.5 px-3 py-3`,"aria-label":`Studio`,children:[(0,H.jsx)(`div`,{className:`px-2.5 pb-1.5 font-mono text-[10px] font-semibold uppercase tracking-[0.18em] text-muted-foreground`,children:`Inspect`}),(0,H.jsx)(gF,{active:F===`agents`,icon:`bot`,label:`Studio`,onClick:()=>Gt(`agents`)}),(0,H.jsx)(gF,{active:F===`tools`,icon:`wrench`,label:`Tools`,onClick:()=>Gt(`tools`)}),(0,H.jsx)(gF,{active:F===`mcps`,icon:`plug`,label:`MCPs`,onClick:()=>Gt(`mcps`)}),(0,H.jsx)(gF,{active:F===`knowledge`,icon:`database`,label:`Knowledge`,onClick:()=>Gt(`knowledge`)})]}),(0,H.jsxs)(`nav`,{className:`grid min-h-0 gap-0.5 overflow-auto px-3 py-3`,"aria-label":`Recent sessions`,children:[(0,H.jsx)(`div`,{className:`px-2.5 pb-1.5 font-mono text-[10px] font-semibold uppercase tracking-[0.18em] text-muted-foreground`,children:`Recent`}),p.slice(0,8).map(e=>(0,H.jsxs)(`div`,{className:Qn(`group grid min-h-7 min-w-0 grid-cols-[minmax(0,1fr)_36px] items-center gap-1 rounded-lg pr-1 transition duration-200 hover:bg-sidebar-accent/80 focus-within:bg-sidebar-accent/80`,e.id===d&&`bg-sidebar-accent`),children:[(0,H.jsx)(er,{className:Qn(`grid h-auto min-h-7 min-w-0 justify-start rounded-lg border-0 bg-transparent px-2.5 py-0.5 text-left text-sidebar-foreground/72 shadow-none hover:bg-transparent hover:text-sidebar-foreground`,e.id===d&&`text-sidebar-accent-foreground`),type:`button`,variant:`ghost`,onClick:()=>void xt(e.id),children:(0,H.jsx)(`span`,{className:`min-w-0 truncate text-xs font-medium`,children:e.title??`Untitled chat`})}),(0,H.jsxs)(`div`,{className:`relative grid h-7 min-w-0 place-items-end`,children:[(0,H.jsx)(`time`,{className:`grid h-6 min-w-6 place-items-center self-center justify-self-end rounded-lg px-1.5 font-mono text-[10px] font-medium tabular-nums text-muted-foreground group-hover:opacity-0 group-focus-within:opacity-0`,children:Ny(e.updatedAt)}),(0,H.jsx)(er,{"aria-label":`Delete ${e.title??`Untitled chat`}`,className:`absolute right-0 top-1/2 hidden h-6 min-h-6 w-6 -translate-y-1/2 border-0 bg-transparent p-0 text-muted-foreground opacity-70 shadow-none hover:bg-transparent hover:text-destructive hover:opacity-100 group-hover:grid group-focus-within:grid [&_svg]:h-3.5 [&_svg]:w-3.5`,size:`icon`,type:`button`,variant:`ghost`,disabled:ue===`running`,onClick:()=>V(e),children:(0,H.jsx)(se,{"aria-hidden":`true`})})]})]},e.id))]}),(0,H.jsxs)(`div`,{className:`mt-auto px-3 py-3`,children:[(0,H.jsxs)(`nav`,{className:`grid gap-1`,"aria-label":`Anvia links`,children:[(0,H.jsx)(CL,{href:`https://anvia.dev/docs`,label:`Anvia Docs`}),(0,H.jsx)(CL,{href:`https://anvia.dev`,label:`Anvia Web`})]}),(0,H.jsx)(`span`,{className:`sr-only`,"aria-live":`polite`,children:oe})]})]}),(0,H.jsxs)(`main`,{className:`grid h-[100dvh] min-w-0 grid-rows-[52px_minmax(0,1fr)] overflow-hidden bg-background/80`,children:[(0,H.jsx)(`header`,{className:`grid min-h-13 bg-background/88 backdrop-blur`,children:(0,H.jsxs)(`div`,{className:`grid min-h-13 grid-cols-[minmax(0,1fr)_auto] items-center gap-3 py-0 pl-0 pr-6`,children:[(0,H.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 text-sm font-medium`,children:[(0,H.jsx)(`span`,{className:`text-primary`,children:F===`playground`?`Agents`:`Studio`}),(0,H.jsx)(`span`,{className:`text-muted-foreground`,children:`/`}),(0,H.jsx)(`span`,{className:`truncate`,children:ot?.name??ot?.id??`Agent`})]}),(0,H.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,H.jsx)(er,{"aria-label":te===`dark`?`Switch to light theme`:`Switch to dark theme`,className:`h-8 min-h-8 w-8 border-transparent bg-transparent p-0 text-muted-foreground hover:bg-muted hover:text-foreground`,title:te===`dark`?`Switch to light theme`:`Switch to dark theme`,type:`button`,variant:`secondary`,size:`icon`,onClick:()=>ne(e=>e===`dark`?`light`:`dark`),children:te===`dark`?(0,H.jsx)(et,{"aria-hidden":`true`}):(0,H.jsx)(ze,{"aria-hidden":`true`})}),(0,H.jsx)(er,{className:`h-8 min-h-8 border-transparent bg-transparent px-3 font-mono text-xs text-muted-foreground hover:bg-muted hover:text-foreground`,type:`button`,variant:`secondary`,onClick:()=>Gt(`sessions`),children:`Sessions`}),(0,H.jsxs)(er,{className:`h-8 min-h-8 gap-1.5 rounded-lg border-0 bg-primary px-3 font-mono text-xs text-primary-foreground hover:bg-primary/90`,type:`button`,onClick:()=>St(),children:[(0,H.jsx)(qe,{"aria-hidden":`true`}),`New session`]})]})]})}),F===`playground`?(0,H.jsxs)(`section`,{className:`grid h-full min-h-0 min-w-0 max-h-full max-w-full grid-cols-[minmax(0,1fr)_minmax(0,460px)] overflow-hidden bg-background/45 max-xl:grid-cols-1`,children:[(0,H.jsx)(`div`,{className:`grid min-h-0 min-w-0 pb-6 pr-6`,children:(0,H.jsxs)(`div`,{className:`grid h-full min-h-0 min-w-0 grid-rows-[minmax(0,1fr)_auto] overflow-hidden rounded-lg border border-border/80 bg-card/70 p-2 shadow-sm`,children:[(0,H.jsx)(`section`,{className:`min-h-0 overflow-y-auto overflow-x-hidden px-4 py-4 [scrollbar-gutter:stable]`,ref:Ge,onScroll:Je,children:(0,H.jsxs)(`div`,{className:`mx-auto grid min-h-full w-full max-w-235 content-start items-start gap-6 pb-8`,children:[ct?null:(0,H.jsx)(`div`,{className:`grid min-h-96 place-items-center text-sm font-medium text-muted-foreground`,children:(0,H.jsxs)(`div`,{className:`grid max-w-xl gap-4 text-center`,children:[(0,H.jsx)(`div`,{className:`mx-auto h-px w-28 bg-primary/45`}),(0,H.jsx)(`h1`,{className:`m-0 text-4xl font-semibold leading-tight text-foreground text-balance`,children:`What should this agent work on?`}),(0,H.jsx)(`p`,{className:`m-0 text-base leading-7 text-muted-foreground text-pretty`,children:`Choose a prompt below or write a task. Studio will stream the response, tool calls, approvals, and trace data here.`})]})}),E.map(e=>(0,H.jsx)(ON,{entry:e,decidingApprovals:fe,answeringQuestions:me,onApprovalDecision:(e,t)=>void Pt(e,t),onQuestionAnswer:(e,t)=>void Ft(e,t),onOpenTrace:qt},e.entryId))]})}),(0,H.jsxs)(`form`,{className:`grid gap-3 bg-gradient-to-t from-card via-card/95 to-card/0 px-4 pb-4 pt-2`,onSubmit:e=>{e.preventDefault(),Tt(O)},children:[ct||st.length===0?null:(0,H.jsx)(`div`,{className:`mx-auto grid w-full max-w-235 grid-cols-3 gap-2 max-md:grid-cols-1`,children:st.map(e=>(0,H.jsx)(er,{className:`h-auto min-h-16 justify-start whitespace-normal rounded-lg border border-border/80 bg-card/85 px-3 py-2.5 text-left text-sm font-medium leading-5 text-foreground shadow-sm hover:border-primary/45 hover:bg-primary/10 hover:text-primary`,type:`button`,variant:`ghost`,disabled:ue===`running`||r.length===0,onClick:()=>void Tt(e),children:(0,H.jsx)(`span`,{className:`min-w-0 whitespace-normal wrap-break-words`,children:e})},e))}),(0,H.jsxs)(`div`,{className:`mx-auto grid w-full max-w-235 gap-2 rounded-lg border border-border/80 bg-card/95 p-2.5 shadow-xl shadow-black/35 backdrop-blur focus-within:border-primary focus-within:ring-2 focus-within:ring-primary/25`,children:[(0,H.jsx)(Bl,{className:`min-h-16 min-w-0 resize-none rounded-lg border-0 bg-transparent px-3 py-3 text-[15px] leading-7 text-foreground shadow-none outline-none ring-0 placeholder:text-muted-foreground/70 focus:border-transparent focus:ring-0`,ref:We,rows:1,value:O,onChange:Ut,onKeyDown:Wt,placeholder:`Ask anything...`}),(0,H.jsxs)(`div`,{className:`flex min-w-0 items-center justify-between gap-2`,children:[(0,H.jsx)(`div`,{}),(0,H.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[rt.length>1?(0,H.jsxs)(Ll,{value:ot?.id??r,onValueChange:Ct,disabled:ue===`running`,children:[(0,H.jsx)(zl,{"aria-label":`Select agent`,className:`hidden h-8 min-h-8 w-auto max-w-64 gap-2 border-0 bg-transparent px-2 py-1 font-mono text-xs font-medium text-muted-foreground shadow-none hover:bg-accent hover:text-accent-foreground sm:flex`,children:(0,H.jsx)(Rl,{placeholder:`Agent`})}),(0,H.jsx)(q,{align:`end`,children:rt.map(e=>(0,H.jsx)(J,{value:e.id,children:e.name??e.id},e.id))})]}):(0,H.jsx)(`span`,{className:`hidden max-w-60 truncate rounded-lg px-2 py-1 font-mono text-xs font-medium text-muted-foreground sm:block`,children:ot?.name??ot?.id??`Agent`}),(0,H.jsx)(er,{"aria-label":ue===`running`?`Running`:`Send message`,className:`h-9 min-h-9 w-9 rounded-lg border-primary bg-primary text-primary-foreground hover:bg-primary/90`,size:`icon`,type:`submit`,disabled:ue===`running`||r.length===0,children:(0,H.jsx)(_e,{})})]})]})]})]})]})}),(0,H.jsx)(LN,{logs:_,selectedSessionId:d,loading:ye===`loading`})]}):null,F===`tracing`?(0,H.jsx)(mI,{agents:rt,traces:h,tracesEnabled:Ze,traceLoadState:xe,selectedTraceId:R,traceSessionDetailId:ie,onRefresh:()=>void ft(),onSelectTrace:qt,onShowSessionTraces:e=>void pt(e)}):null,F===`sessions`?(0,H.jsx)(zP,{agents:rt,sessions:p,sessionsEnabled:Xe,sessionLoadState:ge,selectedSessionId:d,onOpenSession:e=>void xt(e),onViewSessionTracing:e=>void pt(e),onDeleteSession:V}):null,F===`agents`?(0,H.jsx)(Ul,{agents:rt,selectedAgentId:r}):null,F===`tools`?(0,H.jsx)(vF,{agents:rt,selectedAgentId:s||ot?.id||r,summary:je,enabled:tt,loading:Ne===`loading`,onSelectAgent:e=>{c(e),_t(e)}}):null,F===`pipelines`?(0,H.jsx)(tN,{pipelines:it,selectedPipelineId:l,detail:b,logs:S,activeRunId:P,runs:w,enabled:nt,detailLoading:Fe===`loading`,logsLoading:Le===`loading`,runsLoading:Be===`loading`,runState:He,runInput:A,runOutput:M,theme:te,onSelectPipeline:e=>{u(e),N(``),ee(``),bt(e)},onRunInputChange:j,onRun:()=>void Et()}):null,F===`mcps`?(0,H.jsx)(Cb,{agents:rt,selectedAgentId:a||ot?.id||r,summary:De,enabled:$e,loading:ke===`loading`,onSelectAgent:e=>{o(e),gt(e)}}):null,F===`knowledge`?(0,H.jsx)(rb,{activeTab:re,enabled:Qe,summary:Ce,loading:Te===`loading`,onOpenTrace:qt,onRefresh:()=>void ht(),onSelectTab:Kt}):null]}),(0,H.jsx)(BP,{session:ae,onOpenChange:e=>{e||V(void 0)},onConfirm:e=>void wt(e)})]})}function CL(e){return(0,H.jsxs)(`a`,{className:`flex h-8 min-h-8 items-center justify-between rounded-lg px-2 font-mono text-[11px] font-semibold text-sidebar-foreground/62 transition duration-200 hover:bg-sidebar-accent hover:text-sidebar-foreground`,href:e.href,target:`_blank`,rel:`noreferrer`,children:[(0,H.jsx)(`span`,{children:e.label}),(0,H.jsx)(he,{"aria-hidden":`true`,className:`h-3 w-3 text-muted-foreground`})]})}function wL(e){return DL(e)&&e.type===`pipeline_log`&&DL(e.log)}function TL(e){return DL(e)&&e.type===`pipeline_final`&&`output`in e}function EL(e){return DL(e)&&e.type===`error`}function DL(e){return typeof e==`object`&&!!e}function OL(e,t){let n=[...t].sort((e,t)=>Date.parse(e.startedAt)-Date.parse(t.startedAt)).map(e=>e.id),r=0,i,a=e.map(e=>e.kind===`message`&&e.role===`assistant`?kL(e):e);function o(){if(i===void 0)return;let e=n[r];r+=1,e!==void 0&&(a[i]={...a[i],traceId:e}),i=void 0}for(let[e,t]of a.entries()){if(t.kind===`message`&&t.role===`user`){o();continue}t.kind===`message`&&t.role===`assistant`&&(i=e)}return o(),a}function kL(e){let{traceId:t,...n}=e;return n}var AL=document.getElementById(`anvia-ui`);AL!==null&&(0,at.createRoot)(AL).render((0,H.jsx)(SL,{}));
|
|
100
|
+
//# sourceMappingURL=index-DfSrZD9A.js.map
|